Received: by 10.223.176.5 with SMTP id f5csp1867118wra; Thu, 8 Feb 2018 04:56:36 -0800 (PST) X-Google-Smtp-Source: AH8x22559PgmUpF6grz1Hm+r4PnWFARf3foMYawNZT8nY/KXKXPYWzCNxhiNLU5tDJTcv+dd/HPV X-Received: by 10.98.157.93 with SMTP id i90mr647480pfd.58.1518094596883; Thu, 08 Feb 2018 04:56:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518094596; cv=none; d=google.com; s=arc-20160816; b=o+o8FUl3DNxEy2FG4qvT9VrOrDk2fniM9GQxrhVH4sWHAV9iz10uuOGuPoO/GOyHpF HsDfjLP0joDv/XtaYapsGyOT5GxFeAuI+fcUpZyhQJA1ufFKe9xbEA9cx+U6QXnI6JTy G3tC2H/IHBtvMgbDy/JqOUijDu8SHn8ACRt9Xqjj9Agc0tk1vKP8oDipwg84z/lSEipJ noUAn8RdJ1JLu91uLZiAjmV/51lz/Q0kR0k7pfSJoRRaasZSztCw/nmA4E3+5vPy9jyO WleYNOb7vQNoSIEM2N46wJw21gbP2r9AK/5waelJSRb9jn8aDWfm4YICmO6sF4JAhAGE P+9w== 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=TtPPblFHpGv27bVL7ajX99LYCaY85leXZpEFXctSmuY=; b=Qx44VFzjwGaXiRUtD8dlzYcB5ERyOF1Aketj5SS6cOacx4fR0qkqDRTDZKybGromNO KoTc/Dtwd4TduEsYenf9ckryrkSfCE6qYmjZgcyNAlJVP6XS7bZsdavz7975S1nnnbl6 fD7Cmhvb0BKzb9BeNFFtdjslkUfI53JmLwXLG0SRqxlBZqQTo7rW/0jaChPH+4wg5Le3 KEi9Ir3cqK1YXgJLT5ln/eHhCxo4BUekpP+CnbuuyGo+2THAd2F1HHthWnsdaWfofoXz C5JurVs2QRVx4oU5P8nSgNLgAFUS1Kw9DP6PR3E/e/7IiqYLnYe0adqvH9QiEHllotYi Ldhg== 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 m6-v6si1545037pln.711.2018.02.08.04.56.20; Thu, 08 Feb 2018 04:56:36 -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 S1752092AbeBHMzg (ORCPT + 99 others); Thu, 8 Feb 2018 07:55:36 -0500 Received: from mga07.intel.com ([134.134.136.100]:2801 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752028AbeBHMzd (ORCPT ); Thu, 8 Feb 2018 07:55:33 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Feb 2018 04:55:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,478,1511856000"; d="scan'208";a="16279867" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 08 Feb 2018 04:55:30 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 98E48142; Thu, 8 Feb 2018 14:55:29 +0200 (EET) From: "Kirill A. Shutemov" To: Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" , Tom Lendacky Cc: Dave Hansen , Kai Huang , linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCH] x86/mm: Decouple dynamic __PHYSICAL_MASK from AMD SME Date: Thu, 8 Feb 2018 15:55:24 +0300 Message-Id: <20180208125524.88795-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 AMD SME claims one bit from physical address to indicate whether the page is encrypted or not. To achieve that we clear out the bit from __PHYSICAL_MASK. The capability to adjust __PHYSICAL_MASK is required beyond AMD SME. For instance for upcoming Intel Multi-Key Total Memory Encryption. Let's factor it out into separate feature with own Kconfig handle. It also helps with overhead of AMD SME. It saves more than 3k in .text on defconfig + AMD_MEM_ENCRYPT: add/remove: 3/2 grow/shrink: 5/110 up/down: 189/-3753 (-3564) We would need to return to this once we have infrastructure to patch constants in code. That's good candidate for it. Signed-off-by: Kirill A. Shutemov --- arch/x86/Kconfig | 4 ++++ arch/x86/boot/compressed/pagetable.c | 3 +++ arch/x86/include/asm/page_types.h | 8 +++++++- arch/x86/mm/mem_encrypt.c | 3 +++ arch/x86/mm/pgtable.c | 5 +++++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index b52cdf48ad26..ffd9ef3f6ca6 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -332,6 +332,9 @@ config ARCH_SUPPORTS_UPROBES config FIX_EARLYCON_MEM def_bool y +config DYNAMIC_PHYSICAL_MASK + bool + config PGTABLE_LEVELS int default 5 if X86_5LEVEL @@ -1469,6 +1472,7 @@ config ARCH_HAS_MEM_ENCRYPT config AMD_MEM_ENCRYPT bool "AMD Secure Memory Encryption (SME) support" depends on X86_64 && CPU_SUP_AMD + select DYNAMIC_PHYSICAL_MASK ---help--- Say yes to enable support for the encryption of system memory. This requires an AMD processor that supports Secure Memory diff --git a/arch/x86/boot/compressed/pagetable.c b/arch/x86/boot/compressed/pagetable.c index b5e5e02f8cde..4318ac0af815 100644 --- a/arch/x86/boot/compressed/pagetable.c +++ b/arch/x86/boot/compressed/pagetable.c @@ -16,6 +16,9 @@ #define __pa(x) ((unsigned long)(x)) #define __va(x) ((void *)((unsigned long)(x))) +/* No need in adjustable __PHYSICAL_MASK during decompresssion phase */ +#undef CONFIG_DYNAMIC_PHYSICAL_MASK + /* * The pgtable.h and mm/ident_map.c includes make use of the SME related * information which is not used in the compressed image support. Un-define diff --git a/arch/x86/include/asm/page_types.h b/arch/x86/include/asm/page_types.h index 1e53560a84bb..c85e15010f48 100644 --- a/arch/x86/include/asm/page_types.h +++ b/arch/x86/include/asm/page_types.h @@ -17,7 +17,6 @@ #define PUD_PAGE_SIZE (_AC(1, UL) << PUD_SHIFT) #define PUD_PAGE_MASK (~(PUD_PAGE_SIZE-1)) -#define __PHYSICAL_MASK ((phys_addr_t)(__sme_clr((1ULL << __PHYSICAL_MASK_SHIFT) - 1))) #define __VIRTUAL_MASK ((1UL << __VIRTUAL_MASK_SHIFT) - 1) /* Cast *PAGE_MASK to a signed type so that it is sign-extended if @@ -55,6 +54,13 @@ #ifndef __ASSEMBLY__ +#ifdef CONFIG_DYNAMIC_PHYSICAL_MASK +extern phys_addr_t physical_mask; +#define __PHYSICAL_MASK physical_mask +#else +#define __PHYSICAL_MASK ((phys_addr_t)((1ULL << __PHYSICAL_MASK_SHIFT) - 1)) +#endif + extern int devmem_is_allowed(unsigned long pagenr); extern unsigned long max_low_pfn_mapped; diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 1a53071e2e17..18954f97f3da 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -999,6 +999,7 @@ void __init __nostackprotector sme_enable(struct boot_params *bp) /* SEV state cannot be controlled by a command line option */ sme_me_mask = me_mask; sev_enabled = true; + physical_mask &= ~sme_me_mask; return; } @@ -1033,4 +1034,6 @@ void __init __nostackprotector sme_enable(struct boot_params *bp) sme_me_mask = 0; else sme_me_mask = active_by_default ? me_mask : 0; + + physical_mask &= ~sme_me_mask; } diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index 004abf9ebf12..a4dfe85f2fd8 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -7,6 +7,11 @@ #include #include +#ifdef CONFIG_DYNAMIC_PHYSICAL_MASK +phys_addr_t physical_mask __ro_after_init = (1ULL << __PHYSICAL_MASK_SHIFT) - 1; +EXPORT_SYMBOL(physical_mask); +#endif + #define PGALLOC_GFP (GFP_KERNEL_ACCOUNT | __GFP_ZERO) #ifdef CONFIG_HIGHPTE -- 2.15.1