* Re: [Xen-devel] new barrier type for paravirt (was Re: [PATCH] virtio_ring: use smp_store_mb)
[not found] ` <20151220195944.GT6344@twins.programming.kicks-ass.net>
@ 2015-12-21 7:10 ` Michael S. Tsirkin
2015-12-21 7:22 ` [PATCH RFC] smp_store_mb should use smp_mb Michael S. Tsirkin
0 siblings, 1 reply; 2+ messages in thread
From: Michael S. Tsirkin @ 2015-12-21 7:10 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Andrew Cooper, Jason Wang, Rusty Russell, qemu-devel,
Alexander Duyck, linux-kernel, David Vrabel, xen-devel,
Boris Ostrovsky, virtualization, Arnd Bergmann, linux-arch
On Sun, Dec 20, 2015 at 08:59:44PM +0100, Peter Zijlstra wrote:
> On Sun, Dec 20, 2015 at 05:07:19PM +0000, Andrew Cooper wrote:
> >
> > Very much +1 for fixing this.
> >
> > Those names would be fine, but they do add yet another set of options in
> > an already-complicated area.
> >
> > An alternative might be to have the regular smp_{w,r,}mb() not revert
> > back to nops if CONFIG_PARAVIRT, or perhaps if pvops have detected a
> > non-native environment. (I don't know how feasible this suggestion is,
> > however.)
>
> So a regular SMP kernel emits the LOCK prefix and will patch it out with
> a DS prefix (iirc) when it finds but a single CPU. So for those you
> could easily do this.
>
> However an UP kernel will not emit the LOCK and do no patching.
>
> So if you're willing to make CONFIG_PARAVIRT depend on CONFIG_SMP or
> similar, this is doable.
One of the uses for virtio is to allow testing an existing kernel on
kvm just by loading a module, and this will break this usecase.
> I don't see people going to allow emitting the LOCK prefix (and growing
> the kernel text size) for UP kernels.
Thinking about this more, maybe __smp_*mb is a better set of names.
The nice thing about it is that we can then have generic code
that does basically
#ifdef CONFIG_SMP
#define smp_mb() __smp_mb()
#else
#define smp_mb() barrier()
#endif
and reuse this on all architectures.
So instead of a maintainance burden, we are actually
removing code duplication.
--
MST
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH RFC] smp_store_mb should use smp_mb
2015-12-21 7:10 ` [Xen-devel] new barrier type for paravirt (was Re: [PATCH] virtio_ring: use smp_store_mb) Michael S. Tsirkin
@ 2015-12-21 7:22 ` Michael S. Tsirkin
0 siblings, 0 replies; 2+ messages in thread
From: Michael S. Tsirkin @ 2015-12-21 7:22 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Andrew Cooper, Jason Wang, Rusty Russell, qemu-devel,
Alexander Duyck, linux-kernel, David Vrabel, xen-devel,
Boris Ostrovsky, virtualization, Arnd Bergmann, linux-arch
On some architectures smp_store_mb() calls mb() which is stronger
than implied by both the name and the documentation.
smp_store_mb is only used by core kernel code at the moment, so
we know no one mis-uses it for an MMIO barrier.
Make it call smp_mb consistently before some arch-specific
code uses it as such by mistake.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
Note: I'm guessing an ack from arch maintainers will be needed, but
I'm working on a bigger cleanup moving a bunch of duplicated code
into asm-generic/barrier.h which depends on this, so not Cc'ing
widely yet.
Please Ack if appropriate but do not merge yet.
diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
index df896a1..425552b 100644
--- a/arch/ia64/include/asm/barrier.h
+++ b/arch/ia64/include/asm/barrier.h
@@ -77,7 +77,7 @@ do { \
___p1; \
})
-#define smp_store_mb(var, value) do { WRITE_ONCE(var, value); mb(); } while (0)
+#define smp_store_mb(var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)
/*
* The group barrier in front of the rsm & ssm are necessary to ensure
diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
index 0eca6ef..4f0169e 100644
--- a/arch/powerpc/include/asm/barrier.h
+++ b/arch/powerpc/include/asm/barrier.h
@@ -34,7 +34,7 @@
#define rmb() __asm__ __volatile__ ("sync" : : : "memory")
#define wmb() __asm__ __volatile__ ("sync" : : : "memory")
-#define smp_store_mb(var, value) do { WRITE_ONCE(var, value); mb(); } while (0)
+#define smp_store_mb(var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)
#ifdef __SUBARCH_HAS_LWSYNC
# define SMPWMB LWSYNC
diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
index d68e11e..6c1d8b5 100644
--- a/arch/s390/include/asm/barrier.h
+++ b/arch/s390/include/asm/barrier.h
@@ -36,7 +36,7 @@
#define smp_mb__before_atomic() smp_mb()
#define smp_mb__after_atomic() smp_mb()
-#define smp_store_mb(var, value) do { WRITE_ONCE(var, value); mb(); } while (0)
+#define smp_store_mb(var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)
#define smp_store_release(p, v) \
do { \
diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
index b42afad..0f45f93 100644
--- a/include/asm-generic/barrier.h
+++ b/include/asm-generic/barrier.h
@@ -93,7 +93,7 @@
#endif /* CONFIG_SMP */
#ifndef smp_store_mb
-#define smp_store_mb(var, value) do { WRITE_ONCE(var, value); mb(); } while (0)
+#define smp_store_mb(var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)
#endif
#ifndef smp_mb__before_atomic
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-12-21 7:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1450347932-16325-1-git-send-email-mst@redhat.com>
[not found] ` <20151217105238.GA6375@twins.programming.kicks-ass.net>
[not found] ` <20151217131554-mutt-send-email-mst@redhat.com>
[not found] ` <20151217135726.GA6344@twins.programming.kicks-ass.net>
[not found] ` <20151217161124-mutt-send-email-mst@redhat.com>
[not found] ` <20151217143910.GD6344@twins.programming.kicks-ass.net>
[not found] ` <20151220105146-mutt-send-email-mst@redhat.com>
[not found] ` <5676E047.3010808@citrix.com>
[not found] ` <20151220195944.GT6344@twins.programming.kicks-ass.net>
2015-12-21 7:10 ` [Xen-devel] new barrier type for paravirt (was Re: [PATCH] virtio_ring: use smp_store_mb) Michael S. Tsirkin
2015-12-21 7:22 ` [PATCH RFC] smp_store_mb should use smp_mb Michael S. Tsirkin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).