From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> To: Linus Torvalds <torvalds@linux-foundation.org>, x86@kernel.org, Tom Lendacky <thomas.lendacky@amd.com>, Peter Zijlstra <peterz@infradead.org> Cc: Dave Hansen <dave.hansen@intel.com>, Andy Lutomirski <luto@kernel.org>, Borislav Petkov <bp@suse.de>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Subject: [RFC 0/3] x86: Patchable constants Date: Wed, 7 Feb 2018 17:59:10 +0300 [thread overview] Message-ID: <20180207145913.2703-1-kirill.shutemov@linux.intel.com> (raw) 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 -- 2.15.1
WARNING: multiple messages have this Message-ID (diff)
From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> To: Linus Torvalds <torvalds@linux-foundation.org>, x86@kernel.org, Tom Lendacky <thomas.lendacky@amd.com>, Peter Zijlstra <peterz@infradead.org> Cc: Dave Hansen <dave.hansen@intel.com>, Andy Lutomirski <luto@kernel.org>, Borislav Petkov <bp@suse.de>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Subject: [RFC 0/3] x86: Patchable constants Date: Wed, 7 Feb 2018 17:59:10 +0300 [thread overview] Message-ID: <20180207145913.2703-1-kirill.shutemov@linux.intel.com> (raw) 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 -- 2.15.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next reply other threads:[~2018-02-07 14:59 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-02-07 14:59 Kirill A. Shutemov [this message] 2018-02-07 14:59 ` [RFC 0/3] x86: Patchable constants Kirill A. Shutemov 2018-02-07 14:59 ` [RFC 1/3] x86: Introduce patchable constants Kirill A. Shutemov 2018-02-07 14:59 ` Kirill A. Shutemov 2018-02-07 14:59 ` [RFC 2/3] x86/mm/encrypt: Convert __PHYSICAL_MASK to patchable constant Kirill A. Shutemov 2018-02-07 14:59 ` Kirill A. Shutemov 2018-02-07 14:59 ` [RFC 3/3] x86/mm/encrypt: Convert sme_me_mask " Kirill A. Shutemov 2018-02-07 14:59 ` Kirill A. Shutemov 2018-02-07 16:25 ` [RFC 0/3] x86: Patchable constants Peter Zijlstra 2018-02-07 16:25 ` Peter Zijlstra 2018-02-07 17:12 ` Kirill A. Shutemov 2018-02-07 17:12 ` Kirill A. Shutemov 2018-02-07 17:01 ` Linus Torvalds 2018-02-07 17:01 ` Linus Torvalds 2018-02-07 17:13 ` hpa 2018-02-07 17:13 ` hpa 2018-02-07 20:20 ` H. Peter Anvin 2018-02-07 20:20 ` H. Peter Anvin 2018-02-07 20:43 ` H. Peter Anvin 2018-02-07 20:43 ` H. Peter Anvin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180207145913.2703-1-kirill.shutemov@linux.intel.com \ --to=kirill.shutemov@linux.intel.com \ --cc=bp@suse.de \ --cc=dave.hansen@intel.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=luto@kernel.org \ --cc=peterz@infradead.org \ --cc=thomas.lendacky@amd.com \ --cc=torvalds@linux-foundation.org \ --cc=x86@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.