• Mark Rutland's avatar
    arm64: entry: call exit_to_user_mode() from C · e130338e
    Mark Rutland authored
    When handling an exception from EL0, we perform the entry work in that
    exception's C handler, and once the C handler has finished, we return
    back to the entry assembly. Subsequently in the common `ret_to_user`
    assembly we perform the exit work that balances with the entry work.
    This can be somewhat difficult to follow, and makes it hard to rework
    the return paths (e.g. to pass additional context to the exit code, or
    to have exception return logic for specific exceptions).
    
    This patch reworks the entry code such that each EL0 C exception handler
    is responsible for both the entry and exit work. This clearly balances
    the two (and will permit additional variation in future), and avoids an
    unnecessary bounce between assembly and C in the common case, leaving
    `ret_from_fork` as the only place assembly has to call the exit code.
    This means that the exit work is now inlined into the C handler, which
    is already the case for the entry work, and allows the compiler to
    generate better code (e.g. by immediately returning when there is no
    exit work to perform).
    
    To align with other exception entry/exit helpers, enter_from_user_mode()
    is updated to take the EL0 pt_regs as a parameter, though this is
    currently unused.
    
    There should be no functional change as a result of this patch. However,
    this should lead to slightly better backtraces when an error is
    encountered within do_notify_resume(), as the C handler should appear in
    the backtrace, indicating the specific exception that the kernel was
    entered with.
    Signed-off-by: default avatarMark Rutland <mark.rutland@arm.com>
    Cc: James Morse <james.morse@arm.com>
    Cc: Joey Gouly <joey.gouly@arm.com>
    Cc: Marc Zyngier <maz@kernel.org>
    Cc: Will Deacon <will@kernel.org>
    Reviewed-by: default avatarJoey Gouly <joey.gouly@arm.com>
    Link: https://lore.kernel.org/r/20210802140733.52716-5-mark.rutland@arm.comSigned-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
    e130338e
entry-common.c 20.4 KB