From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752141AbcFLKCj (ORCPT ); Sun, 12 Jun 2016 06:02:39 -0400 Received: from mail-pa0-f67.google.com ([209.85.220.67]:35696 "EHLO mail-pa0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751278AbcFLKCh (ORCPT ); Sun, 12 Jun 2016 06:02:37 -0400 Date: Sun, 12 Jun 2016 18:02:31 +0800 From: Minfei Huang To: Borislav Petkov Cc: Roman Kagan , linux-kernel@vger.kernel.org, "Denis V. Lunev" , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Andy Lutomirski , Paolo Bonzini Subject: Re: [PATCH] x86:pvclock: add missing barriers Message-ID: <20160612100231.GA22854@localhost> References: <1465409499-23166-1-git-send-email-rkagan@virtuozzo.com> <20160608194509.GE4094@pd.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160608194509.GE4094@pd.tnic> User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/08/16 at 09:45P, Borislav Petkov wrote: > On Wed, Jun 08, 2016 at 09:11:39PM +0300, Roman Kagan wrote: > > Gradual removal of excessive barriers in pvclock reading functions > > (commits 502dfeff239e8313bfbe906ca0a1a6827ac8481b, > > a3eb97bd80134ba07864ca00747466c02118aca1) ended up removing too much: > > although rdtsc is now orderd WRT other loads, there's no protection > > against the compiler reordering the loads of ->version with the loads of > > other fields. > > > > E.g. on my system gcc-5.3.1 generates code which loads ->system_time and > > ->flags outside of the ->version test loop. > > > > (Re)introduce the compiler barriers around accesses to the contents of > > pvclock. While at this, make the function a bit more compact by > > removing unnecessary local variables. > > > > Signed-off-by: Roman Kagan > > Cc: Thomas Gleixner > > Cc: Ingo Molnar > > Cc: "H. Peter Anvin" > > Cc: x86@kernel.org > > Cc: Andy Lutomirski > > Cc: Borislav Petkov > > Cc: Paolo Bonzini > > Cc: stable@vger.kernel.org > > --- > > arch/x86/include/asm/pvclock.h | 17 +++++------------ > > 1 file changed, 5 insertions(+), 12 deletions(-) > > > > diff --git a/arch/x86/include/asm/pvclock.h b/arch/x86/include/asm/pvclock.h > > index fdcc040..65c4de2 100644 > > --- a/arch/x86/include/asm/pvclock.h > > +++ b/arch/x86/include/asm/pvclock.h > > @@ -80,18 +80,11 @@ static __always_inline > > unsigned __pvclock_read_cycles(const struct pvclock_vcpu_time_info *src, > > cycle_t *cycles, u8 *flags) > > { > > - unsigned version; > > - cycle_t ret, offset; > > - u8 ret_flags; > > - > > - version = src->version; > > - > > - offset = pvclock_get_nsec_offset(src); > > - ret = src->system_time + offset; > > - ret_flags = src->flags; > > - > > - *cycles = ret; > > - *flags = ret_flags; > > + unsigned version = src->version; > > + barrier(); > > + *cycles = src->system_time + pvclock_get_nsec_offset(src); > > + *flags = src->flags; > > + barrier(); > > return version; > > I have a similar patchset in my mbox starting here: > > https://lkml.kernel.org/r/1464329832-4638-1-git-send-email-mnghuan@gmail.com > > Care to take a look? Hi, Boris. I had a vocation last several days, and sorry for replying it later. As Roman said in this thread, both his and mine are similar way to fix this inconsistent issue, and I have a wrapper function smp_rmb in my patch which the root function is barriers in x86 as well. Thanks Minfei