Skip to content

x86/callthunks: Fix and unify call thunk assembly snippets

Uros Bizjak lkml llvm 2 versions – Applied

Status from this message: The following commit has been merged into the x86/percpu branch of tip:

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 3 repliesApplied
  2. v13 patches 4 repliesSuperseded

Changes in v2 from the cover letter

- Make PER_CPU_VAR macro available in 'asm' statements instead of moving 'asm' statements to *.S assembly files.
- Re-use existing relocation infrastructure from alternative.c

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/3x86/percpu: Define PER_CPU_VAR macro also for !__ASSEMBLY__arch/x86/include/asm/percpu.h+5 -00 replies
2/3x86/callthunks: Handle %rip-relative relocations in call thunk templatearch/x86/include/asm/text-patching.h arch/x86/kernel/alternative.c arch/x86/kernel/callthunks.c+28 -93 replies
3/3x86/callthunks: Fix and unify call thunks assembly snippetsarch/x86/include/asm/nospec-branch.h+7 -160 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH -tip v2 0/3] x86/callthunks: Fix and unify call thunk assembly snippets

Currently INCREMENT_CALL_DEPTH and thunk debug macros explicitly define %gs: segment register prefix for their percpu variables. This is not compatible with !CONFIG_SMP, which requires non-prefixed percpu variables.

Contrary to alternatives, relocations are currently not supported in call thunk templates. Due to unsupported relocations, two variants of INCREMENT_CALL_DEPTH macro are needed, ASM_ prefixed that allows relocations and non-prefixed version that allows only absolute addresses.

The following patch series fixes above issues by

a) Making PER_CPU_VAR macro from percpu.h also available without __ASSEMBLY__, so it can be used in 'asm' statements to conditionally use %gs: segment register prefix, depending on CONFIG_SMP.

b) Re-using existing infrastructure from alternative.c to allow %rip-relative relocations when copying call thunk template from its storage location.

c) Fixing call thunks debug macros to use PER_CPU_VAR macro from percpu.h to conditionally use %gs: segment register prefix, depending on CONFIG_SMP.

d) Unifying ASM_ prefixed assembly macros with their non-prefixed variants. With support of %rip-relative relocations in place, call thunk templates allow %rip-relative addressing, so unified assembly snippet can be used everywhere.

v2:
- Make PER_CPU_VAR macro available in 'asm' statements instead of moving 'asm' statements to *.S assembly files.
- Re-use existing relocation infrastructure from alternative.c

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Peter Zijlstra <[email protected]>

Uros Bizjak (3):
x86/percpu: Define PER_CPU_VAR macro also for !__ASSEMBLY__ x86/callthunks: Handle %rip-relative relocations in call thunk
template
x86/callthunks: Fix and unify call thunks assembly snippets

 arch/x86/include/asm/nospec-branch.h | 23 ++++++--------------
 arch/x86/include/asm/percpu.h        |  5 +++++
 arch/x86/include/asm/text-patching.h |  2 ++
 arch/x86/kernel/alternative.c        |  3 +--
 arch/x86/kernel/callthunks.c         | 32 ++++++++++++++++++++++------
 5 files changed, 40 insertions(+), 25 deletions(-)
Signature · 1 line
2.41.0