Re: [PATCH] virtio_pci: fix use after free on release

2016-01-14 Thread Jerome Marchand
On 01/14/2016 03:04 PM, Michael S. Tsirkin wrote: > KASan detected a use-after-free error in virtio-pci remove code. In > virtio_pci_remove(), vp_dev is still used after being freed in > unregister_virtio_device() (in virtio_pci_release_dev() more > precisely). > > To fix, keep a reference until

Possible memory corruption in virtio-pci driver.

2016-01-14 Thread Jerome Marchand
Hi Michael, KASan detected a use-after-free error in virtio-pci remove code. In virtio_pci_remove(), vp_dev is still used after being freed in unregister_virtio_device() (in virtio_pci_release_dev() more precisely). I don't know the proper way to fix this. Here is the KASan output: [

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Paul E. McKenney
On Thu, Jan 14, 2016 at 12:04:45PM +, Will Deacon wrote: > On Wed, Jan 13, 2016 at 12:58:22PM -0800, Leonid Yegoshin wrote: > > On 01/13/2016 12:48 PM, Peter Zijlstra wrote: > > >On Wed, Jan 13, 2016 at 11:02:35AM -0800, Leonid Yegoshin wrote: > > > > > >>I ask HW team about it but I have a

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Michael S. Tsirkin
On Wed, Jan 13, 2016 at 02:26:16PM -0800, Leonid Yegoshin wrote: > And all that is out-of-topic here in my mind. I just want to be sure that > this patchset still provides a use of a specific lightweight SYNCs on MIPS > vs bold and heavy generalized "SYNC 0" in any case. > > - Leonid. Of course

Re: [PATCH v3 0/4] x86: faster mb()+documentation tweaks

2016-01-14 Thread Borislav Petkov
On Wed, Jan 13, 2016 at 10:12:22PM +0200, Michael S. Tsirkin wrote: > mb() typically uses mfence on modern x86, but a micro-benchmark shows that > it's > 2 to 3 times slower than lock; addl that we use on older CPUs. > > So let's use the locked variant everywhere. > > While I was at it, I found

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Will Deacon
On Wed, Jan 13, 2016 at 12:58:22PM -0800, Leonid Yegoshin wrote: > On 01/13/2016 12:48 PM, Peter Zijlstra wrote: > >On Wed, Jan 13, 2016 at 11:02:35AM -0800, Leonid Yegoshin wrote: > > > >>I ask HW team about it but I have a question - has it any relationship with > >>replacing MIPS SYNC with

[PATCH] virtio_pci: fix use after free on release

2016-01-14 Thread Michael S. Tsirkin
KASan detected a use-after-free error in virtio-pci remove code. In virtio_pci_remove(), vp_dev is still used after being freed in unregister_virtio_device() (in virtio_pci_release_dev() more precisely). To fix, keep a reference until cleanup is done. Fixes: 63bd62a08ca4 ("virtio_pci: defer

Re: Possible memory corruption in virtio-pci driver.

2016-01-14 Thread Michael S. Tsirkin
On Thu, Jan 14, 2016 at 02:25:50PM +0100, Jerome Marchand wrote: > Hi Michael, > > KASan detected a use-after-free error in virtio-pci remove code. In > virtio_pci_remove(), vp_dev is still used after being freed in > unregister_virtio_device() (in virtio_pci_release_dev() more > precisely). I

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Paul E. McKenney
On Thu, Jan 14, 2016 at 01:36:50PM -0800, Leonid Yegoshin wrote: > On 01/14/2016 01:29 PM, Paul E. McKenney wrote: > > > >>On 01/14/2016 12:34 PM, Paul E. McKenney wrote: > >>> > >>>The WRC+addr+addr is OK because data dependencies are not required to be > >>>transitive, in other words, they are

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Leonid Yegoshin
On 01/14/2016 02:24 PM, Paul E. McKenney wrote: Actually, the Linux kernel doesn't have an acquire barrier, just an smp_load_acquire(). Or did someone sneak one in while I wasn't looking? That was an exactly starting point for this discussion. This patch just pulls out from MIPS files

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Leonid Yegoshin
On 01/14/2016 02:55 PM, Paul E. McKenney wrote: OK, so it looks like Will was asking not about WRC+addr+addr, but instead about WRC+sync+addr. (He actually asked twice about this and that too but skip this) I am guessing that the manual's "Older instructions which must be globally performed

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Paul E. McKenney
On Thu, Jan 14, 2016 at 01:45:44PM -0800, Leonid Yegoshin wrote: > On 01/14/2016 01:34 PM, Paul E. McKenney wrote: > >On Thu, Jan 14, 2016 at 12:46:43PM -0800, Leonid Yegoshin wrote: > >>On 01/14/2016 12:15 PM, Peter Zijlstra wrote: > >>>On Thu, Jan 14, 2016 at 11:42:02AM -0800, Leonid Yegoshin

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Paul E. McKenney
On Thu, Jan 14, 2016 at 03:33:40PM -0800, Leonid Yegoshin wrote: > On 01/14/2016 02:55 PM, Paul E. McKenney wrote: > >OK, so it looks like Will was asking not about WRC+addr+addr, but instead > >about WRC+sync+addr. > (He actually asked twice about this and that too but skip this) Fair enough!

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Leonid Yegoshin
On 01/14/2016 04:14 AM, Will Deacon wrote: On Wed, Jan 13, 2016 at 02:26:16PM -0800, Leonid Yegoshin wrote: Moreover, there are voices against guarantee that it will be in future and that voices point me to Documentation/memory-barriers.txt section "DATA DEPENDENCY BARRIERS" examples

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Leonid Yegoshin
On 01/14/2016 08:16 AM, Paul E. McKenney wrote: On Thu, Jan 14, 2016 at 12:04:45PM +, Will Deacon wrote: On Wed, Jan 13, 2016 at 12:58:22PM -0800, Leonid Yegoshin wrote: On 01/13/2016 12:48 PM, Peter Zijlstra wrote: On Wed, Jan 13, 2016 at 11:02:35AM -0800, Leonid Yegoshin wrote: I ask

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Paul E. McKenney
On Thu, Jan 14, 2016 at 01:24:34PM -0800, Leonid Yegoshin wrote: > On 01/14/2016 12:48 PM, Paul E. McKenney wrote: > > > >So SYNC_RMB is intended to implement smp_rmb(), correct? > Yes. > > > >You could use SYNC_ACQUIRE() to implement read_barrier_depends() and > >smp_read_barrier_depends(), but

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Leonid Yegoshin
On 01/14/2016 04:47 PM, Paul E. McKenney wrote: On Thu, Jan 14, 2016 at 03:33:40PM -0800, Leonid Yegoshin wrote: Don't be fooled here by words "ordered" and "completed" - it is HW design items and actually written poorly. Just assume that SYNC_MB is absolutely the same as SYNC for any CPU and

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Leonid Yegoshin
On 01/14/2016 04:04 AM, Will Deacon wrote: Consequently, it's important that the architecture back-ends implement these portable primitives (e.g. smp_mb()) in a way that satisfies the kernel memory model so that core code doesn't need to worry about the underlying architecture for

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Paul E. McKenney
On Thu, Jan 14, 2016 at 12:46:43PM -0800, Leonid Yegoshin wrote: > On 01/14/2016 12:15 PM, Peter Zijlstra wrote: > >On Thu, Jan 14, 2016 at 11:42:02AM -0800, Leonid Yegoshin wrote: > >>An the only point - please use an appropriate SYNC_* barriers instead of > >>heavy bold hammer. That stuff was

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Paul E. McKenney
On Thu, Jan 14, 2016 at 01:01:05PM -0800, Leonid Yegoshin wrote: > I need some time to understand your test examples. However, Understood. > On 01/14/2016 12:34 PM, Paul E. McKenney wrote: > > > > > >The WRC+addr+addr is OK because data dependencies are not required to be > >transitive, in other

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Leonid Yegoshin
On 01/14/2016 12:15 PM, Peter Zijlstra wrote: On Thu, Jan 14, 2016 at 11:42:02AM -0800, Leonid Yegoshin wrote: An the only point - please use an appropriate SYNC_* barriers instead of heavy bold hammer. That stuff was design explicitly to support the requirements of

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Peter Zijlstra
On Thu, Jan 14, 2016 at 09:15:13PM +0100, Peter Zijlstra wrote: > On Thu, Jan 14, 2016 at 11:42:02AM -0800, Leonid Yegoshin wrote: > > An the only point - please use an appropriate SYNC_* barriers instead of > > heavy bold hammer. That stuff was design explicitly to support the > > requirements of

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Paul E. McKenney
On Thu, Jan 14, 2016 at 12:12:53PM -0800, Leonid Yegoshin wrote: > On 01/14/2016 04:04 AM, Will Deacon wrote: > >Consequently, it's important that the architecture back-ends > >implement these portable primitives (e.g. smp_mb()) in a way that > >satisfies the kernel memory model so that core code

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Leonid Yegoshin
I need some time to understand your test examples. However, On 01/14/2016 12:34 PM, Paul E. McKenney wrote: The WRC+addr+addr is OK because data dependencies are not required to be transitive, in other words, they are not required to flow from one CPU to another without the help of an

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Peter Zijlstra
On Thu, Jan 14, 2016 at 11:42:02AM -0800, Leonid Yegoshin wrote: > An the only point - please use an appropriate SYNC_* barriers instead of > heavy bold hammer. That stuff was design explicitly to support the > requirements of Documentation/memory-barriers.txt That's madness. That document

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Paul E. McKenney
On Thu, Jan 14, 2016 at 11:28:18AM -0800, Leonid Yegoshin wrote: > On 01/14/2016 04:14 AM, Will Deacon wrote: > >On Wed, Jan 13, 2016 at 02:26:16PM -0800, Leonid Yegoshin wrote: > > > >> Moreover, there are voices against guarantee that it will be in future > >>and that voices point me to

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Paul E. McKenney
On Thu, Jan 14, 2016 at 09:15:13PM +0100, Peter Zijlstra wrote: > On Thu, Jan 14, 2016 at 11:42:02AM -0800, Leonid Yegoshin wrote: > > An the only point - please use an appropriate SYNC_* barriers instead of > > heavy bold hammer. That stuff was design explicitly to support the > > requirements of

Re: [v3,11/41] mips: reuse asm-generic/barrier.h

2016-01-14 Thread Leonid Yegoshin
On 01/14/2016 01:34 PM, Paul E. McKenney wrote: On Thu, Jan 14, 2016 at 12:46:43PM -0800, Leonid Yegoshin wrote: On 01/14/2016 12:15 PM, Peter Zijlstra wrote: On Thu, Jan 14, 2016 at 11:42:02AM -0800, Leonid Yegoshin wrote: An the only point - please use an appropriate SYNC_* barriers instead