Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932607AbdLTT72 (ORCPT ); Wed, 20 Dec 2017 14:59:28 -0500 Received: from mail-bl2nam02on0051.outbound.protection.outlook.com ([104.47.38.51]:41612 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932527AbdLTT7X (ORCPT ); Wed, 20 Dec 2017 14:59:23 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Subject: Re: [PATCH v1 1/3] x86/mm: Centralize PMD flags in sme_encrypt_kernel() To: Borislav Petkov Cc: x86@kernel.org, Brijesh Singh , linux-kernel@vger.kernel.org, Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner References: <20171207233342.29646.12858.stgit@tlendack-t1.amdoffice.net> <20171207233352.29646.52076.stgit@tlendack-t1.amdoffice.net> <20171220191301.6ak5kzs5mi6h3vvg@pd.tnic> From: Tom Lendacky Message-ID: <00139399-780e-4d63-f43d-ff0e71db9440@amd.com> Date: Wed, 20 Dec 2017 13:59:15 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <20171220191301.6ak5kzs5mi6h3vvg@pd.tnic> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: MWHPR04CA0031.namprd04.prod.outlook.com (10.172.163.17) To DM5PR12MB1147.namprd12.prod.outlook.com (10.168.236.142) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 86a45615-2b25-42b0-9b1e-08d547e428e5 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(48565401081)(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603307)(7153060);SRVR:DM5PR12MB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XHDbWK9LEPK9j5FbRq28nsuUdQrP74fYrZMNxSXP9oXmbP8V34F/5zYdfB5Yrt45qUvIXgaCVowUndOlFh3P5GMjTOtgHsxdNYcyuDz+0mu7VTCLy7kf0vMJUKb3smPR/rIaK6MxTCJQIpHibKieAb8Gw7hodseucFM0nghZdo7bQTKQFUIzW4XJXpOex3V/MfU7Lzm7SGvZlT7X4pkPBpI/iQQU3BV56o1LRkUTVEw7JiA+yvtRwWGv+B7P9P4fjM/vJyO6zBy+yqwnT+FGiDWbL7J7iYj+DnDQYF5Smmz3nr8piakCB2PewszLUOTPva4Exc7tAKXUnJqpfI+YhTnBx5i+HVo02UnPB2V1kpBLSp6Zwd8eMuDSiCkyx1UFYxVVyfHD3ArvSQi;4:3LAZzjfz1BUpDC+cgbB7Sgxx3fnBiG0edoDpxALYz72cHZVNUxXYeqtmQYHZYA+T9Leo6OFzq4fzkCnriIn6hYKPfGROyCIQgCpSR65T220d2TfKpDgoZYsfGX+n/gHroJek6hbphVuNrcM64feLy2oNoKURaH+2GTdVx4ItHHv5ojUBdl1PB2VM+h8NtTs9Q1NMZC0W4Y+7kR3GPy2dRHGqGT5DNy1wGVpHMc6xG7jjNKCQxvFlMvL8pvJA+MpEsBB9rRc21gEpDkuKNuF1OTrue6XhbH8l4ZJfpGIWoIo7azY7KHg7EoQXdeRYk9UT X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(5005006)(8121501046)(3002001)(10201501046)(93006095)(93001095)(3231023)(6055026)(6041268)(20161123558120)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR12MB1147;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:DM5PR12MB1147; X-Forefront-PRVS: 0527DFA348 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(346002)(39380400002)(376002)(396003)(366004)(39860400002)(189003)(199004)(24454002)(53936002)(305945005)(81166006)(6116002)(86362001)(25786009)(105586002)(3260700006)(3846002)(229853002)(31686004)(81156014)(6486002)(77096006)(31696002)(36756003)(90366009)(64126003)(68736007)(65956001)(66066001)(106356001)(65826007)(8676002)(50466002)(6246003)(65806001)(8936002)(4326008)(76176011)(83506002)(478600001)(230700001)(47776003)(16526018)(2906002)(7736002)(72206003)(5660300001)(316002)(386003)(6916009)(2950100002)(58126008)(97736004)(2486003)(6666003)(53546011)(52146003)(23676004)(52116002)(16576012)(54906003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB1147;H:[10.236.65.116];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTVQUjEyTUIxMTQ3OzIzOmpZTnJaVnBhY1p3SE1FOTVobGh5Vm1SYkl1?= =?utf-8?B?SmhveDN2TFprSjk3ZnlSRnNQTTR0dWZVdVVzbEh3TVVrb2ZKSTQ2MkFNeVE3?= =?utf-8?B?L2R3WDhGTkEvZlJvL045UEFnSmZXbnZLRG5CR29pTFZaVkNobUMzUjN0eWt5?= =?utf-8?B?YTVYd1F0M3ZtSEVrTlpEUThUZ01WaXFlTzkyWC9lbkJ6cWZuSjBDWmc5VDBq?= =?utf-8?B?VlNSMWRtcEJ5NUdlMDI0MGxkZUU1aURWWVE2Rk92aUk1Z2dyZi8rK2dUS3BT?= =?utf-8?B?aDRZR2cwaExKai84dFZRNWJpNUh6MTFhbjVxa2UzN0U1d3dVczAvUnFDaTdU?= =?utf-8?B?WkFmYjBkU2l2RDdMMHFwL01MZW13R1U5SmRwTDVPUHFGN3Y0cEdBbHZFTTk4?= =?utf-8?B?WUtGNkUxak9aQ2k4bDVIVWczalVuVVQ3L2hGbFNGMDI5bXVrUXlvai9JNDh1?= =?utf-8?B?Z21zK2VjclkwQktrbG0vaDROVHgwTXJSeEJtN21L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hts=;5:xV9Hx39rcjTkSG/RpR8X6wj2r1x32aToXJBO5mEMya+8HVnTODogm0qY87KAK4OQNiojgoNd7m9QGHkcDymS7JIXE3YXUeRD8jijOj9dI0TGR0AQL0U7oy5W0xiUHlENXbD0BToDZuQqbu7uHHZegDtf3dbztK9I/hr9nyH7lag=;24:1mTLitEvmXT2wO+fBhfowGPpEWfyzh7S22m2NPbmAWozgOaETFJktz2rpIQpp84GGm0X+WbtMQjGSijb9CyapveBrHi41A8nwRGjyzBFLHg=;7:ugu9fbWR7ba4iq9dfFWlKoM+paCfMHettn3I27Iso+q/VtraevaT4BFa+bboLpmEbbMUUmAxYdff59jMvU4n4UB5ST2AiL9yqcea1VtFBjtlTFAaetFnzaKN9IzTNPnAi++vggC4HMcKuF7/QjkUSc3E3hvh+lNpG2woYjpMSzOTqo9LkxgpTV1fbEQQCrwmwwnxY+V1mfXUP8EmSgi7CNSdngYAVIEZCBGEHX2cP34KP84je7cAq2Wj1S7rSL10 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1147;20:P9Aitulhc9n5A0Ql0f0hy7YORM7oriV6oI//EVd0ZcYghFzhLrGJjMKR+5pu6CSer+vscAbSJnhdT1YlVLP0gsIUzYC92LjbAcnpBafJt7Fpjw/ms2BYzKx/hCuTKKRT9SSFP+VVoQ8TawAjOoZJBEIOmOYBVVth1lcOifedJxv9TtKcg5ZcJdYmo0uCCHFYZrSlDipDeV24U11llcC9M5MkJeVJqfu1TW/ubN2txy2nD9WvoJTy1du/SRiMr5ls X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Dec 2017 19:59:19.6888 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 86a45615-2b25-42b0-9b1e-08d547e428e5 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1147 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2357 Lines: 64 On 12/20/2017 1:13 PM, Borislav Petkov wrote: > On Thu, Dec 07, 2017 at 05:33:52PM -0600, Tom Lendacky wrote: >> In preparation for encrypting more than just the kernel during early >> boot processing, centralize the use of the PMD flag settings based >> on the type of mapping desired. When 4KB aligned encryption is added, >> this will allow either PTE flags or large page PMD flags to be used >> without requiring the caller to adjust. >> >> Signed-off-by: Tom Lendacky >> --- >> arch/x86/mm/mem_encrypt.c | 109 +++++++++++++++++++++++++-------------------- >> 1 file changed, 60 insertions(+), 49 deletions(-) >> >> diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c >> index d9a9e9f..2d8404b 100644 >> --- a/arch/x86/mm/mem_encrypt.c >> +++ b/arch/x86/mm/mem_encrypt.c >> @@ -464,6 +464,8 @@ void swiotlb_set_mem_attributes(void *vaddr, unsigned long size) >> set_memory_decrypted((unsigned long)vaddr, size >> PAGE_SHIFT); >> } >> >> +static void *pgtable_area; > > Ewww, a global variable which gets manipulated by functions. Can we not > do that pls? > > sme_populate_pgd() used to return it. Why change that? It was starting to get pretty hairy with all the parameters and what was needed to be returned when the second patch was introduced. I'll look at what I can do to avoid the global, maybe pass in the address of the variable for updating within the function or combining the parameters into a struct. > >> + >> static void __init sme_clear_pgd(pgd_t *pgd_base, unsigned long start, >> unsigned long end) >> { >> @@ -484,10 +486,16 @@ static void __init sme_clear_pgd(pgd_t *pgd_base, unsigned long start, >> #define PGD_FLAGS _KERNPG_TABLE_NOENC >> #define P4D_FLAGS _KERNPG_TABLE_NOENC >> #define PUD_FLAGS _KERNPG_TABLE_NOENC >> -#define PMD_FLAGS (__PAGE_KERNEL_LARGE_EXEC & ~_PAGE_GLOBAL) >> >> -static void __init *sme_populate_pgd(pgd_t *pgd_base, void *pgtable_area, >> - unsigned long vaddr, pmdval_t pmd_val) >> +#define PMD_FLAGS_LARGE (__PAGE_KERNEL_LARGE_EXEC & ~_PAGE_GLOBAL) >> + >> +#define PMD_FLAGS_DEC PMD_FLAGS_LARGE >> +#define PMD_FLAGS_DEC_WP ((PMD_FLAGS_DEC & ~_PAGE_CACHE_MASK) | \ >> + (_PAGE_PAT | _PAGE_PWT)) >> +#define PMD_FLAGS_ENC (PMD_FLAGS_LARGE | _PAGE_ENC) > > Align vertically. Ok Thanks, Tom > > Rest looks ok. >