Received: by 10.223.176.5 with SMTP id f5csp750997wra; Wed, 7 Feb 2018 07:01:04 -0800 (PST) X-Google-Smtp-Source: AH8x225100Ao1wMWxlVYK/4j2VFEWYKdPPGstnIHvjfXWXreUgE5G8ouKwX9VwunYn2Sq5gec9+m X-Received: by 2002:a17:902:7682:: with SMTP id m2-v6mr6177466pll.163.1518015664311; Wed, 07 Feb 2018 07:01:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518015664; cv=none; d=google.com; s=arc-20160816; b=Kc+A7gCzOLGMNmmoyHUZ0m30yH6PWoOhSU1rkSJiq6YmshSdiBVPVlWyHWWzxUd0/d 8nh7rUyAOyjWE8LOkDhXrV5ifu9IpCju9K5RQAiyUGebqw/qiX0rPaMsuXlwunj/d+8A 81kXqJwscXK0dGhVzWP2WCy/9pLWiRQIrL3aPcKW9/78SbjQfEGzOfiV/74bD/MGbmdw zREErQDH9rVua9uITrvVjRf3EbsGFTjYdGpx5AXNp4p04RF8E5QBUm6QS/kJXAtAE3UF mYAqay5z14e+Qs626soB4f5p++dM/3GVyw/rbCJEfPeRazzN1YkipUSEHbsiwA+gbDZD v2oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=3OqnuL6uC3UyrwOVvTsQnma44PBsCk71d0ugBN5XK4k=; b=q0AMwquEei0FohEwbgqu+FOrdLsMxoAjzaKvV5uh2rPDGiGEhMUdL0mZH8MUQ05dka wYQ2JyjJTFtFX1S74VhkyRcrgA+QeUzSzFZxb2g0adPzL2F5VLJdPTYaeFALhwbu3Jen QqZcAdd9iIm+ZvzzuOVOc7yG2vKw4Eud5VC0NM72jM/icYIg9gwh0EltGcQRsWFkRWgg rp8yNfWds/KJNBO8f98uHX9avWAk0GfDmgsY10YYICmczOU/ef9KiXA/78HpMMehR4ry p8kDHEiYolYg2fQhywAV1KbOBZ1yF800OEI3FK8B1je5kYOJI9rcXAUUHgbCCx4Ir/3/ aIHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p2-v6si1175431plo.798.2018.02.07.07.00.49; Wed, 07 Feb 2018 07:01:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754494AbeBGO7b (ORCPT + 99 others); Wed, 7 Feb 2018 09:59:31 -0500 Received: from mga05.intel.com ([192.55.52.43]:12850 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754190AbeBGO72 (ORCPT ); Wed, 7 Feb 2018 09:59:28 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Feb 2018 06:59:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,473,1511856000"; d="scan'208";a="172440858" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 07 Feb 2018 06:59:25 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 8518CC5; Wed, 7 Feb 2018 16:59:24 +0200 (EET) From: "Kirill A. Shutemov" To: Linus Torvalds , x86@kernel.org, Tom Lendacky , Peter Zijlstra Cc: Dave Hansen , Andy Lutomirski , Borislav Petkov , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [RFC 0/3] x86: Patchable constants Date: Wed, 7 Feb 2018 17:59:10 +0300 Message-Id: <20180207145913.2703-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.15.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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