From: Shan Hai <shan.hai@windriver.com>
To: <benh@kernel.crashing.org>
Cc: linuxppc-dev@lists.ozlabs.org, john.stultz@linaro.org
Subject: Re: [PATCH 0/1] powerpc/vdso: remove redundant locking in update_vsyscall_tz()
Date: Wed, 14 Nov 2012 17:39:15 +0800 [thread overview]
Message-ID: <20121114093914.GA14139@debian.corp.ad.wrs.com> (raw)
In-Reply-To: <20121109015718.GA6124@debian.corp.ad.wrs.com>
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 <shan.hai@windriver.com>
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 <shan.hai@windriver.com>
---
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)
--
1.7.10.4
Best Regards
Shan Hai
> Thanks
> Shan Hai
> From 167eac293b07e0ee201ffe5043ec442d52495a48 Mon Sep 17 00:00:00 2001
> From: Shan Hai <shan.hai@windriver.com>
> 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 <shan.hai@windriver.com>
> ---
> 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)
> --
> 1.7.10.4
>
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev
prev parent reply other threads:[~2012-11-14 9:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-09 1:57 [PATCH 0/1] powerpc/vdso: remove redundant locking in update_vsyscall_tz() Shan Hai
2012-11-14 9:39 ` Shan Hai [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20121114093914.GA14139@debian.corp.ad.wrs.com \
--to=shan.hai@windriver.com \
--cc=benh@kernel.crashing.org \
--cc=john.stultz@linaro.org \
--cc=linuxppc-dev@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox