[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH 0/6] Port Linux LL/SC and LSE atomics to Xen



[this is my personal account, opinions expressed are entirely my own]

Hi,

I'm starting this new series thread to discuss how Linux's LL/SC and LSE
atomics helpers may best be ported to Xen, as per the discussion at [1].


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.


Series contents
===============

    - Patch #1 allows for detecting architectural features advertised
      in ID registers other than ID_AA64PFR{0,1}_EL1 and ID_PFR{0,1}.

    - Patch #2 uses the new infrastructure above to detect the presence
      of Armv8.1-LSE atomic instructions, as advertised by ID register
      ID_AA64ISAR0_EL1.

    - Patch #3 introduces the ARM64_HAS_LSE_ATOMICS hwcap, as well as
      the new Kconfig CONFIG_ARM64_LSE_ATOMICS, which enables runtime
      detection and setting of this hwcap.

    - Patch #4 pulls in the Linux LL/SC and LSE atomics helpers for
      arm64, using the new ARM64_HAS_LSE_ATOMICS hwcap to patch itself
      at runtime to use LSE where available and otherwise falling back
      on LL/SC.

        !! NB: Patch #4 breaks arm32 builds until Patch #5 ports
           Linux's 32-bit LL/SC helpers. I split the patches up
           to make them easier to review and discuss.

    - Patch #5 pulls in the Linux LL/SC atomics helpers for arm32.

    - Finally, Patch #6 removes Xen's dependency on gcc's built-in
      __sync_fetch_and_add() helper, instead using the ported Linux
      atomic_fetch_add() helper.


Any comments, guidance, and discussion on how to improve this first-pass
approach to get LSE atomics support merged into Xen would be greatly
appreciated.

Thanks!
Ash.

[1] 
https://lore.kernel.org/xen-devel/13baac40-8b10-0def-4e44-0d8f655fcaf1@xxxxxxx/
[2] https://xenbits.xen.org/xsa/advisory-295.txt

Ash Wilding (6):
  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/arm64: Port Linux LL/SC and LSE atomics helpers to Xen
  xen/arm32: Port Linux LL/SC atomics helpers to Xen
  xen/arm: Remove dependency on gcc builtin __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       | 261 +++++++-----
 xen/include/asm-arm/arm32/cmpxchg.h      | 403 +++++++++++-------
 xen/include/asm-arm/arm32/system.h       |   2 +-
 xen/include/asm-arm/arm64/atomic.h       | 242 +++++------
 xen/include/asm-arm/arm64/atomic_ll_sc.h | 236 +++++++++++
 xen/include/asm-arm/arm64/atomic_lse.h   | 251 +++++++++++
 xen/include/asm-arm/arm64/cmpxchg.h      | 505 ++++++++++++++++-------
 xen/include/asm-arm/arm64/lse.h          |  53 +++
 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             |  10 +-
 xen/include/xen/compiler.h               |   3 +
 17 files changed, 1506 insertions(+), 572 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

-- 
2.24.3 (Apple Git-128)




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.