Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-06 Thread Paolo Bonzini
On 09/06/2011 11:28 AM, Avi Kivity wrote: Actually Michael is right. The implementation is correct on x86, though wrong anywhere else (perhaps s390?). On those architectures you do not need rmb() and wmb(). Are we sure? Nothing prevents the guest from using weakly-ordered writes, is there?

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-06 Thread Michael S. Tsirkin
On Tue, Sep 06, 2011 at 12:28:40PM +0300, Avi Kivity wrote: > On 09/06/2011 09:55 AM, Paolo Bonzini wrote: > >On 09/06/2011 05:12 AM, David Gibson wrote: > >>I'm not "fixing ppc". I'm fixing a fundamental flaw in the protocol > >>implementation._So far_ I've only observed the effects on ppc, but

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-06 Thread Avi Kivity
On 09/06/2011 09:55 AM, Paolo Bonzini wrote: On 09/06/2011 05:12 AM, David Gibson wrote: I'm not "fixing ppc". I'm fixing a fundamental flaw in the protocol implementation._So far_ I've only observed the effects on ppc, but that doesn't mean they don't exist. Actually Michael is right. The

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-06 Thread David Gibson
On Tue, Sep 06, 2011 at 08:55:42AM +0200, Paolo Bonzini wrote: > On 09/06/2011 05:12 AM, David Gibson wrote: > >I'm not "fixing ppc". I'm fixing a fundamental flaw in the protocol > >implementation._So far_ I've only observed the effects on ppc, but > >that doesn't mean they don't exist. > > Act

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-05 Thread Paolo Bonzini
On 09/06/2011 05:12 AM, David Gibson wrote: I'm not "fixing ppc". I'm fixing a fundamental flaw in the protocol implementation._So far_ I've only observed the effects on ppc, but that doesn't mean they don't exist. Actually Michael is right. The implementation is correct on x86, though wron

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-05 Thread David Gibson
On Mon, Sep 05, 2011 at 12:19:46PM +0300, Michael S. Tsirkin wrote: > On Mon, Sep 05, 2011 at 02:43:16PM +1000, David Gibson wrote: > > On Sun, Sep 04, 2011 at 12:16:43PM +0300, Michael S. Tsirkin wrote: > > > On Sun, Sep 04, 2011 at 12:46:35AM +1000, David Gibson wrote: > > > > On Fri, Sep 02, 201

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-05 Thread Paolo Bonzini
> > No, rmb and wmb need to generate code. > > If they do we'll have to surround each their use with > ifndef x86 as you suggest later. Which is just messy. [1 hour later] I see what you mean now. You assume there are no accesses to write-combining memory (of course) or non-temporal load/stores

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-05 Thread Michael S. Tsirkin
On Mon, Sep 05, 2011 at 02:43:16PM +1000, David Gibson wrote: > On Sun, Sep 04, 2011 at 12:16:43PM +0300, Michael S. Tsirkin wrote: > > On Sun, Sep 04, 2011 at 12:46:35AM +1000, David Gibson wrote: > > > On Fri, Sep 02, 2011 at 06:45:50PM +0300, Michael S. Tsirkin wrote: > > > > On Thu, Sep 01, 201

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-05 Thread Michael S. Tsirkin
On Mon, Sep 05, 2011 at 09:41:19AM +0200, Paolo Bonzini wrote: > On 09/04/2011 11:16 AM, Michael S. Tsirkin wrote: > >>> I mean argue for a richer set of barriers, with per-arch minimal > >>> implementations instead of the large but portable hammer of > >>> sync_synchronize, if you will. > > > >

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-05 Thread Paolo Bonzini
On 09/04/2011 11:16 AM, Michael S. Tsirkin wrote: > I mean argue for a richer set of barriers, with per-arch minimal > implementations instead of the large but portable hammer of > sync_synchronize, if you will. That's what I'm saying really. On x86 the richer set of barriers need not insert

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-04 Thread David Gibson
On Sun, Sep 04, 2011 at 12:16:43PM +0300, Michael S. Tsirkin wrote: > On Sun, Sep 04, 2011 at 12:46:35AM +1000, David Gibson wrote: > > On Fri, Sep 02, 2011 at 06:45:50PM +0300, Michael S. Tsirkin wrote: > > > On Thu, Sep 01, 2011 at 04:31:09PM -0400, Paolo Bonzini wrote: > > > > > > > Why not limi

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-04 Thread Michael S. Tsirkin
On Sun, Sep 04, 2011 at 12:46:35AM +1000, David Gibson wrote: > On Fri, Sep 02, 2011 at 06:45:50PM +0300, Michael S. Tsirkin wrote: > > On Thu, Sep 01, 2011 at 04:31:09PM -0400, Paolo Bonzini wrote: > > > > > > Why not limit the change to ppc then? > > > > > > > > > > Because the bug is masked by t

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-04 Thread Michael S. Tsirkin
On Sat, Sep 03, 2011 at 06:19:23PM +0200, Paolo Bonzini wrote: > On 09/02/2011 05:45 PM, Michael S. Tsirkin wrote: > >Well, can you describe an issue in virtio that lfence/sfence help solve > >in terms of a memory model please? > >Pls note that guest uses smp_ variants for barriers. > > /* Mak

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-03 Thread David Gibson
On Fri, Sep 02, 2011 at 06:45:50PM +0300, Michael S. Tsirkin wrote: > On Thu, Sep 01, 2011 at 04:31:09PM -0400, Paolo Bonzini wrote: > > > > > Why not limit the change to ppc then? > > > > > > > > Because the bug is masked by the x86 memory model, but it is still > > > > there even there conceptual

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-03 Thread Paolo Bonzini
On 09/02/2011 05:45 PM, Michael S. Tsirkin wrote: Well, can you describe an issue in virtio that lfence/sfence help solve in terms of a memory model please? Pls note that guest uses smp_ variants for barriers. /* Make sure buffer is written before we update index. */ wmb(); Without it,

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-03 Thread Blue Swirl
On Fri, Sep 2, 2011 at 6:49 AM, Paolo Bonzini wrote: > On 09/02/2011 02:08 AM, David Gibson wrote: >>> >>> > >  >Signed-off-by: Alexey Kardashevskiy >  >Signed-off-by: David Gibson >>> >>> > >>> >  It will most definitely break OpenBSD, but anyway: >> >> Uh, why? > > They use an anc

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-02 Thread Michael S. Tsirkin
On Fri, Sep 02, 2011 at 08:11:29AM +0200, Paolo Bonzini wrote: > On 09/02/2011 02:11 AM, David Gibson wrote: > >Why not limit the change to ppc then? > >>> > >>> Because the bug is masked by the x86 memory model, but it is still > >>> there even there conceptually. It is not really true th

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-02 Thread Michael S. Tsirkin
On Thu, Sep 01, 2011 at 04:31:09PM -0400, Paolo Bonzini wrote: > > > > Why not limit the change to ppc then? > > > > > > Because the bug is masked by the x86 memory model, but it is still > > > there even there conceptually. It is not really true that x86 does > > > not need memory barriers, though

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-01 Thread Paolo Bonzini
On 09/02/2011 02:08 AM, David Gibson wrote: > > >Signed-off-by: Alexey Kardashevskiy > >Signed-off-by: David Gibson > > It will most definitely break OpenBSD, but anyway: Uh, why? They use an ancient compiler because they do not want to use GPLv3. I thought it was 4.1.something but actu

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-01 Thread Paolo Bonzini
On 09/02/2011 02:11 AM, David Gibson wrote: > >Why not limit the change to ppc then? > > Because the bug is masked by the x86 memory model, but it is still > there even there conceptually. It is not really true that x86 does > not need memory barriers, though it doesn't in this case: > >

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-01 Thread David Gibson
On Thu, Sep 01, 2011 at 06:14:34PM +0200, Paolo Bonzini wrote: > On 09/01/2011 05:30 PM, Michael S. Tsirkin wrote: > >>> The virtio code already has memory barrier wmb() macros in the code. > >>> However they are was defined as no-ops. The comment claims that real > >>> barriers are not necessa

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-01 Thread David Gibson
On Thu, Sep 01, 2011 at 09:56:25AM +0200, Paolo Bonzini wrote: > On 09/01/2011 09:37 AM, Sasha Levin wrote: > >>> -#define wmb() __asm__ __volatile__("": : :"memory") > >>> + /* TODO: we may also need rmb()s. It hasn't bitten us yet, but.. */ > >>> + #define wmb() __sync_synchronize() > > > >Th

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-01 Thread David Gibson
On Thu, Sep 01, 2011 at 08:47:49AM +0200, Paolo Bonzini wrote: > On 09/01/2011 08:09 AM, David Gibson wrote: > >The patch defines wmb() as __sync_synchronize(), a cross platform memory > >barrier primitive available in sufficiently recent gcc versions (gcc 4.2 > >and after?). If we care about olde

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-01 Thread Paolo Bonzini
> > > Why not limit the change to ppc then? > > > > Because the bug is masked by the x86 memory model, but it is still > > there even there conceptually. It is not really true that x86 does > > not need memory barriers, though it doesn't in this case: > > > > http://bartoszmilewski.wordpress.com/20

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-01 Thread Michael S. Tsirkin
On Thu, Sep 01, 2011 at 06:14:34PM +0200, Paolo Bonzini wrote: > On 09/01/2011 05:30 PM, Michael S. Tsirkin wrote: > >>> The virtio code already has memory barrier wmb() macros in the code. > >>> However they are was defined as no-ops. The comment claims that real > >>> barriers are not necessa

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-01 Thread Paolo Bonzini
On 09/01/2011 05:30 PM, Michael S. Tsirkin wrote: > The virtio code already has memory barrier wmb() macros in the code. > However they are was defined as no-ops. The comment claims that real > barriers are not necessary because the code does not run concurrent. > However, with kvm and io-th

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-01 Thread Michael S. Tsirkin
On Thu, Sep 01, 2011 at 04:09:49PM +1000, David Gibson wrote: > The virtio code already has memory barrier wmb() macros in the code. > However they are was defined as no-ops. The comment claims that real > barriers are not necessary because the code does not run concurrent. > However, with kvm and

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-01 Thread Paolo Bonzini
On 09/01/2011 09:37 AM, Sasha Levin wrote: > -#define wmb() __asm__ __volatile__("": : :"memory") > + /* TODO: we may also need rmb()s. It hasn't bitten us yet, but.. */ > + #define wmb() __sync_synchronize() That asm directive also implicitly provided a compiler barrier, I could

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-01 Thread Sasha Levin
On Thu, 2011-09-01 at 10:37 +0300, Sasha Levin wrote: > On Thu, 2011-09-01 at 16:09 +1000, David Gibson wrote: > > The virtio code already has memory barrier wmb() macros in the code. > > However they are was defined as no-ops. The comment claims that real > > barriers are not necessary because th

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-01 Thread Sasha Levin
On Thu, 2011-09-01 at 16:09 +1000, David Gibson wrote: > The virtio code already has memory barrier wmb() macros in the code. > However they are was defined as no-ops. The comment claims that real > barriers are not necessary because the code does not run concurrent. > However, with kvm and io-thr

Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-08-31 Thread Paolo Bonzini
On 09/01/2011 08:09 AM, David Gibson wrote: The patch defines wmb() as __sync_synchronize(), a cross platform memory barrier primitive available in sufficiently recent gcc versions (gcc 4.2 and after?). If we care about older gccs then this patch will need to be updated with some sort of fallbac

[Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-08-31 Thread David Gibson
The virtio code already has memory barrier wmb() macros in the code. However they are was defined as no-ops. The comment claims that real barriers are not necessary because the code does not run concurrent. However, with kvm and io-thread enabled, this is not true and this qemu code can indeed run