RFC xen/arm: port Linux LL/SC and LSE atomics helpers to Xen.
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v2 RFC Latest15 patches 8 repliesIn review
- v1 RFC6 patches 5 repliesSuperseded
Changes in v2 from the cover letter
====================
- Broken up patches into smaller chunks to aid in readability.
- As per Julien's feedback I've also introduced intermediary patches that first remove Xen's existing headers, then pull in the current Linux versions as-is. This means we only need to review the changes made while porting to Xen, rather than reviewing the existing Linux code.
- Pull in Linux's <asm-generic/rwonce.h> as <xen/rwonce.h> for __READ_ONCE()/__WRITE_ONCE() instead of putting these in Xen's <xen/compiler.h>. While doing this, provide justification for dropping Linux's <linux/compiler_types.h> and relaxing the __READ_ONCE() usage of __unqual_scalar_typeof() to just typeof() (see patches #5 and #6).
Patches in v2 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/15 | xen/arm: Support detection of CPU features in other ID registersxen/ xen/ | +24 | 0 replies | |
| 2/15 | xen/arm: Add detection of Armv8.1-LSE atomic instructionsxen/ xen/ | +12 | 0 replies | |
| 3/15 | xen/arm: Add ARM64_HAS_LSE_ATOMICS hwcapxen/ xen/ xen/ +1 more | +27 | 0 replies | |
| 4/15 | xen/arm: Delete Xen atomics helpersxen/ xen/ xen/ +1 more | +0 | 0 replies | |
| 5/15 | xen/arm: pull in Linux atomics helpers and dependenciesxen/ xen/ xen/ +5 more | +2209 | 2 replies | |
| 6/15 | xen: port Linux <asm-generic/rwonce.h> to Xenxen/ | +5 | 0 replies | |
| 7/15 | xen/arm: prepare existing Xen headers for Linux atomicsxen/ xen/ xen/ | +13 | 0 replies | |
| 8/15 | xen/arm64: port Linux's arm64 atomic_ll_sc.h to Xenxen/ | +6 | 1 reply | |
| 9/15 | xen/arm64: port Linux's arm64 atomic_lse.h to Xenxen/ | +8 | 0 replies | |
| 10/15 | xen/arm64: port Linux's arm64 cmpxchg.h to Xenxen/ | +131 | 1 reply | |
| 11/15 | xen/arm64: port Linux's arm64 atomic.h to Xenxen/ | +73 | 0 replies | |
| 12/15 | xen/arm64: port Linux's arm64 lse.h to Xenxen/ | +15 | 0 replies | |
| 13/15 | xen/arm32: port Linux's arm32 atomic.h to Xenxen/ | +28 | 0 replies | |
| 14/15 | xen/arm32: port Linux's arm32 cmpxchg.h to Xenxen/ | +188 | 0 replies | |
| 15/15 | xen/arm: remove dependency on gcc built-in __sync_fetch_and_add()xen/ | +8 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.
Cover letter [RFC PATCH v2 00/15] xen/arm: port Linux LL/SC and LSE atomics helpers to Xen.
From: Ash Wilding <[email protected]>
Hey,
I've found some time to improve this series a bit:
Changes since RFC v1
====================
- Broken up patches into smaller chunks to aid in readability.
- As per Julien's feedback I've also introduced intermediary patches that first remove Xen's existing headers, then pull in the current Linux versions as-is. This means we only need to review the changes made while porting to Xen, rather than reviewing the existing Linux code.
- Pull in Linux's <asm-generic/rwonce.h> as <xen/rwonce.h> for __READ_ONCE()/__WRITE_ONCE() instead of putting these in Xen's <xen/compiler.h>. While doing this, provide justification for dropping Linux's <linux/compiler_types.h> and relaxing the __READ_ONCE() usage of __unqual_scalar_typeof() to just typeof() (see patches #5 and #6).
Keeping the rest of the cover-letter unchanged as it would still be good to discuss these things:
Arguments in favour of doing this
=================================
- Lets SMMUv3 driver switch to using <asm/atomic.h> rather than maintaining its own implementation of the helpers.
- Provides mitigation against XSA-295 [2], which affects both arm32 and arm64, across all versions of Xen, and may allow a domU to maliciously or erroneously DoS the hypervisor.
- All Armv8-A core implementations since ~2017 implement LSE so there is an argument to be made we are long overdue support in Xen. This is compounded by LSE atomics being more performant than LL/SC atomics in most real-world applications, especially at high core counts.
- We may be able to get improved performance when using LL/SC too as Linux provides helpers with relaxed ordering requirements which are currently not available in Xen, though for this we would need to go back through existing code to see where the more relaxed versions can be safely used.
- Anything else?
Arguments against doing this
============================
- Limited testing infrastructure in place to ensure use of new atomics helpers does not introduce new bugs and regressions. This is a particularly strong argument given how difficult it can be to identify and debug malfunctioning atomics. The old adage applies, "If it ain't broke, don't fix it."
- Anything else?
Disclaimers
===========
- This is a very rough first-pass effort intended to spur the discussions along.
- Only build-tested on arm64 and arm32, *not* run-tested. I did also build for x86_64 just to make I didn't inadvertently break that.
- This version only tackles atomics and cmpxchg; I've not yet had a chance to look at locks so those are still using LL/SC.
- The timeout variants of cmpxchg() (used by guest atomics) are still using LL/SC regardless of LSE being available, as these helpers are not provided by Linux so I just copied over the existing Xen ones.
Any further comments, guidance, and discussion on how to improve this approach and get LSE atomics support merged into Xen would be greatly appreciated.
Thanks!
Ash.
[1] https://lore.kernel.org/xen-devel/[email protected]/
[2] https://xenbits.xen.org/xsa/advisory-295.txt
Ash Wilding (15):
xen/arm: Support detection of CPU features in other ID registers xen/arm: Add detection of Armv8.1-LSE atomic instructions xen/arm: Add ARM64_HAS_LSE_ATOMICS hwcap
xen/arm: Delete Xen atomics helpers
xen/arm: pull in Linux atomics helpers and dependencies
xen: port Linux <asm-generic/rwonce.h> to Xen
xen/arm: prepare existing Xen headers for Linux atomics xen/arm64: port Linux LL/SC atomics helpers to Xen xen/arm64: port Linux LSE atomics helpers to Xen xen/arm64: port Linux's arm64 cmpxchg.h to Xen xen/arm64: port Linux's arm64 atomic.h to Xen xen/arm64: port Linux's arm64 lse.h to Xen
xen/arm32: port Linux's arm32 atomic.h to Xen xen/arm32: port Linux's arm32 cmpxchg.h to Xen xen/arm: remove dependency on gcc built-in __sync_fetch_and_add()
xen/arch/arm/Kconfig | 11 + xen/arch/arm/Makefile | 1 + xen/arch/arm/lse.c | 13 + xen/arch/arm/setup.c | 13 +- xen/include/asm-arm/arm32/atomic.h | 253 +++++++----- xen/include/asm-arm/arm32/cmpxchg.h | 388 +++++++++++------- xen/include/asm-arm/arm32/system.h | 2 +- xen/include/asm-arm/arm64/atomic.h | 236 +++++------ xen/include/asm-arm/arm64/atomic_ll_sc.h | 231 +++++++++++ xen/include/asm-arm/arm64/atomic_lse.h | 246 +++++++++++ xen/include/asm-arm/arm64/cmpxchg.h | 497 ++++++++++++++++------- xen/include/asm-arm/arm64/lse.h | 48 +++ xen/include/asm-arm/arm64/system.h | 2 +- xen/include/asm-arm/atomic.h | 15 +- xen/include/asm-arm/cpufeature.h | 57 +-- xen/include/asm-arm/system.h | 9 +- xen/include/xen/rwonce.h | 21 + 17 files changed, 1469 insertions(+), 574 deletions(-) create mode 100644 xen/arch/arm/lse.c create mode 100644 xen/include/asm-arm/arm64/atomic_ll_sc.h create mode 100644 xen/include/asm-arm/arm64/atomic_lse.h create mode 100644 xen/include/asm-arm/arm64/lse.h create mode 100644 xen/include/xen/rwonce.h
Signature · 1 line
2.24.3 (Apple Git-128)