Skip to content

RFC x86: Patchable constants

Kirill A. Shutemov linux-mm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest3 patches 6 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3x86: Introduce patchable constantsarch/x86/Kconfig arch/x86/include/asm/patchable_const.h arch/x86/kernel/Makefile +2 more+163 -00 replies
2/3x86/mm/encrypt: Convert __PHYSICAL_MASK to patchable constantarch/x86/Kconfig arch/x86/include/asm/page_types.h arch/x86/kernel/patchable_const.c +1 more+19 -10 replies
3/3x86/mm/encrypt: Convert sme_me_mask to patchable constantarch/x86/include/asm/mem_encrypt.h arch/x86/kernel/patchable_const.c arch/x86/mm/mem_encrypt.c+10 -120 replies

Reviews trailers per patch

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

Read the v1 thread

Cover letter [RFC 0/3] x86: Patchable constants

This patchset introduces concept of patchable constants: constant values that can be adjusted at boot-time in response to system configuration or user input (kernel command-line).

Patchable constants can replace variables that never changes at runtime (only at boot-time), but used in very hot path.

Patchable constants implemented by replacing a constant with call to inline function that returns the constant value using inline assembler. In inline assembler we also write down into separate section location of the instruction that loads the constant. This way we can find the location later and adjust the value.

My idea was to make __PHYSICAL_MASK a patchable constant in hope to offset overhead of having it dynamic. We need it dynamic for memory encryption implementation (both AMD SME and Intel MKTME).

But this didn't pay off. :(

This conversion makes GCC generate worse code. Conversion __PHYSICAL_MASK to a patchable constant adds about 5k in .text on defconfig and makes it slightly slower at runtime (~0.2% on my box).

That's not result I hoped for.

I this wanted to share it just in case if anybody find a better use of it or a way to improve it.

Other candidates may be PAGE_OFFSET/VMALLOC_START/VMEMMAP_START.

Kudos to PeterZ for hints on how it can be implemented.

Any feedback?

Kirill A. Shutemov (3):
x86: Introduce patchable constants
x86/mm/encrypt: Convert __PHYSICAL_MASK to patchable constant x86/mm/encrypt: Convert sme_me_mask to patchable constant

 arch/x86/Kconfig                       |   5 ++
 arch/x86/include/asm/mem_encrypt.h     |   5 +-
 arch/x86/include/asm/page_types.h      |  11 ++-
 arch/x86/include/asm/patchable_const.h |  28 ++++++++
 arch/x86/kernel/Makefile               |   3 +
 arch/x86/kernel/module.c               |  14 ++++
 arch/x86/kernel/patchable_const.c      | 119 +++++++++++++++++++++++++++++++++
 arch/x86/mm/mem_encrypt.c              |  20 +++---
 8 files changed, 192 insertions(+), 13 deletions(-)
 create mode 100644 arch/x86/include/asm/patchable_const.h
 create mode 100644 arch/x86/kernel/patchable_const.c
Signature · 7 lines
2.15.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>