• Mark Rutland's avatar
    arm64: factor out EL1 SSBS emulation hook · bff8f413
    Mark Rutland authored
    Currently call_undef_hook() is used to handle UNDEFINED exceptions from
    EL0 and EL1. As support for deprecated instructions may be enabled
    independently, the handlers for individual instructions are organised as
    a linked list of struct undef_hook which can be manipulated dynamically.
    As this can be manipulated dynamically, the list is protected with a
    raw_spinlock which must be acquired when handling UNDEFINED exceptions
    or when manipulating the list of handlers.
    
    This locking is unfortunate as it serialises handling of UNDEFINED
    exceptions, and requires RCU to be enabled for lockdep, requiring the
    use of RCU_NONIDLE() in resume path of cpu_suspend() since commit:
    
      a2c42bba ("arm64: spectre: Prevent lockdep splat on v4 mitigation enable path")
    
    The list of UNDEFINED handlers largely consist of handlers for
    exceptions taken from EL0, and the only handler for exceptions taken
    from EL1 handles `MSR SSBS, #imm` on CPUs which feature PSTATE.SSBS but
    lack the corresponding MSR (Immediate) instruction. Other than this we
    never expect to take an UNDEFINED exception from EL1 in normal
    operation.
    
    This patch reworks do_el0_undef() to invoke the EL1 SSBS handler
    directly, relegating call_undef_hook() to only handle EL0 UNDEFs. This
    removes redundant work to iterate the list for EL1 UNDEFs, and removes
    the need for locking, permitting EL1 UNDEFs to be handled in parallel
    without contention.
    
    The RCU_NONIDLE() call in cpu_suspend() will be removed in a subsequent
    patch, as there are other potential issues with the use of
    instrumentable code and RCU in the CPU suspend code.
    
    I've tested this by forcing the detection of SSBS on a CPU that doesn't
    have it, and verifying that the try_emulate_el1_ssbs() callback is
    invoked.
    Signed-off-by: default avatarMark Rutland <mark.rutland@arm.com>
    Cc: Catalin Marinas <catalin.marinas@arm.com>
    Cc: James Morse <james.morse@arm.com>
    Cc: Joey Gouly <joey.gouly@arm.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Will Deacon <will@kernel.org>
    Link: https://lore.kernel.org/r/20221019144123.612388-4-mark.rutland@arm.comSigned-off-by: default avatarWill Deacon <will@kernel.org>
    bff8f413
spectre.h 2.87 KB