From patchwork Wed Nov 14 09:39:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shan Hai X-Patchwork-Id: 198846 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id 9FAD82C0087 for ; Wed, 14 Nov 2012 20:40:19 +1100 (EST) Received: from mail1.windriver.com (mail1.windriver.com [147.11.146.13]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mail1.windriver.com", Issuer "Intel External Basic Issuing CA 3A" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 813BB2C0087 for ; Wed, 14 Nov 2012 20:39:39 +1100 (EST) Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail1.windriver.com (8.14.5/8.14.3) with ESMTP id qAE9dTDS027505 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Wed, 14 Nov 2012 01:39:29 -0800 (PST) Received: from debian.corp.ad.wrs.com (128.224.162.167) by ALA-HCA.corp.ad.wrs.com (147.11.189.50) with Microsoft SMTP Server (TLS) id 14.2.318.4; Wed, 14 Nov 2012 01:39:28 -0800 Date: Wed, 14 Nov 2012 17:39:15 +0800 From: Shan Hai To: Subject: Re: [PATCH 0/1] powerpc/vdso: remove redundant locking in update_vsyscall_tz() Message-ID: <20121114093914.GA14139@debian.corp.ad.wrs.com> References: <20121109015718.GA6124@debian.corp.ad.wrs.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20121109015718.GA6124@debian.corp.ad.wrs.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [128.224.162.167] Cc: linuxppc-dev@lists.ozlabs.org, john.stultz@linaro.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Fri, Nov 09, 2012 at 09:57:49AM +0800, Shan Hai wrote: > The locking in update_vsyscall_tz() is not only unnecessary because the vdso > code copies the data unproteced in __kernel_gettimeofday() but also > introduces a hard to reproduce race condition between update_vsyscall() > and update_vsyscall_tz(), which causes user space process to loop > forever in vdso code. > > The following patch removes the locking from update_vsyscall_tz(). > > --- > arch/powerpc/kernel/time.c | 5 ----- > 1 file changed, 5 deletions(-) > Hi Ben, Would you please review this one? From 167eac293b07e0ee201ffe5043ec442d52495a48 Mon Sep 17 00:00:00 2001 From: Shan Hai Date: Mon, 5 Nov 2012 18:24:22 +0800 Subject: [PATCH 1/1] powerpc/vdso: remove redundant locking in update_vsyscall_tz() Locking is not only unnecessary because the vdso code copies the data unprotected in __kernel_gettimeofday() but also erroneous because updating the tb_update_count is not atomic and introduces a hard to reproduce race condition between update_vsyscall() and update_vsyscall_tz(), which further causes user space process to loop forever in vdso code. The below scenario describes the race condition, x==0 Boot CPU other CPU proc_P: x==0 timer interrupt update_vsyscall x==1 x++;sync settimeofday update_vsyscall_tz x==2 x++;sync x==3 sync;x++ sync;x++ proc_P: x==3 (loops until x becomes even) Because the ++ operator would be implemented as three instructions and not atomic on powerpc. A similar change was made for x86 in commit 6c260d58634 ("x86: vdso: Remove bogus locking in update_vsyscall_tz") Signed-off-by: Shan Hai --- arch/powerpc/kernel/time.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c index 03b29a6..426141f 100644 --- a/arch/powerpc/kernel/time.c +++ b/arch/powerpc/kernel/time.c @@ -859,13 +859,8 @@ void update_vsyscall(struct timespec *wall_time, struct timespec *wtm, void update_vsyscall_tz(void) { - /* Make userspace gettimeofday spin until we're done. */ - ++vdso_data->tb_update_count; - smp_mb(); vdso_data->tz_minuteswest = sys_tz.tz_minuteswest; vdso_data->tz_dsttime = sys_tz.tz_dsttime; - smp_mb(); - ++vdso_data->tb_update_count; } static void __init clocksource_init(void)