M Michael S. Tsirkin #
Message details and related content
Changes since v2: - extended checkpatch tests for barriers, and added patches teaching it to warn about incorrect usage of barriers (__smp_xxx barriers are for use by asm-generic code only), should help prevent misuse by arch code to address comments by Russell King - patched more instances of xen to use virt_ barriers as suggested by Stefano Stabellini - implemented a 2 byte xchg on sh instead of hacking around it as suggested by Peter Zijlstra and Rich Felker - added a patch to drop some s390 arch-specific smp_xxx barriers - generic versions are more efficient as suggested by Peter Zijlstra and Martin Schwidefsky - added a patch to replace before/after atomic barriers with barrier() on s390 as suggested by Peter Zijlstra and Martin Schwidefsky - included acks from multiple arch maintainers thanks a lot for the review! Changes since v1: - replaced an asm-generic patch with an equivalent patch already in tip - add wrappers with virt_ prefix for better code annotation, as suggested by David Miller - dropped XXX in patch names as this makes vger choke, Cc all relevant mailing lists on all patches (not personal email, as the list becomes too long then) I parked this in vhost tree for now, though the inclusion of patch 1 from tip creates a merge conflict - but one that is trivial to resolve. So I intend to just merge it all through my tree, including the duplicate patch, and assume conflict will be resolved. I would really appreciate some feedback on arch bits (especially the x86 bits), and acks for merging this through the vhost tree. Thanks! What really started me off is trying to cleanup some virt code, as suggested by Peter, who said
You could of course go fix that instead of mutilating things into sort-of functional state.
This work is needed for virtio, so it's probably easiest to merge it through my tree - is this fine by everyone? Note to arch maintainers: please don't cherry-pick patches out of this patchset as it's been structured in this order to avoid breaking bisect. Please send acks instead! ===== Sometimes, virtualization is weird. For example, virtio does this (conceptually): #ifdef CONFIG_SMP smp_mb(); #else mb(); #endif Similarly, Xen calls mb() when it's not doing any MMIO at all. Of course it's wrong in the sense that it's suboptimal. What we would really like is to have, on UP, exactly the same barrier as on SMP. This is because a UP guest can run on an SMP host. But Linux doesn't provide this ability: if CONFIG_SMP is not defined is optimizes most barriers out to a compiler barrier. Consider for example x86: what we want is xchg (NOT mfence - there's no real IO going on here - just switching out of the VM - more like a function call really) but if built without CONFIG_SMP smp_store_mb does not include this. Virt in general is probably the only use-case, because this really is an artifact of interfacing with an SMP host while running an UP kernel, but since we have (at least) two users, it seems to make sense to put these APIs in a central place. In fact, smp_ barriers are stubs on !SMP, so they can be defined as follows: arch/XXX/include/asm/barrier.h: