Re: [PATCH] x86:pvclock: add missing barriers

From: Roman Kagan
Date: Thu Jun 09 2016 - 06:29:51 EST


On Thu, Jun 09, 2016 at 12:01:13AM +0300, Roman Kagan wrote:
> On Wed, Jun 08, 2016 at 09:45:09PM +0200, Borislav Petkov wrote:
> > On Wed, Jun 08, 2016 at 09:11:39PM +0300, Roman Kagan wrote:
> > > --- 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@xxxxxxxxx
> >
> > Care to take a look?
>
> Just did, thanks for the link.
>
> The difference is whether you want the reader to see consistent view of
> the pvclock data (as in my patch) or also the most up to date one
> (as in Minfei Huang's patch) at the cost of extra lfence instructions
> (on my machine this is 30% slowdown).

Sorry, I should have looked better. Minfei's patch inserts smb_rmb()-s
which on x86 are just barrier()-s, so that patch results in the code
equivalent to mine. So I'll jump onto that thread instead of pursuing
this one.

Roman.