Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754796AbcKJAvG (ORCPT ); Wed, 9 Nov 2016 19:51:06 -0500 Received: from mail-by2nam01on0072.outbound.protection.outlook.com ([104.47.34.72]:2368 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754261AbcKJAvA (ORCPT ); Wed, 9 Nov 2016 19:51:00 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; From: Tom Lendacky Subject: [RFC PATCH v3 04/20] x86: Handle reduction in physical address size with SME To: , , , , , , , , CC: Rik van Riel , Radim =?utf-8?b?S3LEjW3DocWZ?= , Arnd Bergmann , Jonathan Corbet , Matt Fleming , Joerg Roedel , Konrad Rzeszutek Wilk , "Paolo Bonzini" , Larry Woodman , "Ingo Molnar" , Borislav Petkov , Andy Lutomirski , "H. Peter Anvin" , Andrey Ryabinin , Alexander Potapenko , "Thomas Gleixner" , Dmitry Vyukov Date: Wed, 9 Nov 2016 18:35:13 -0600 Message-ID: <20161110003513.3280.12104.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20161110003426.3280.2999.stgit@tlendack-t1.amdoffice.net> References: <20161110003426.3280.2999.stgit@tlendack-t1.amdoffice.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: CY4PR13CA0010.namprd13.prod.outlook.com (10.168.161.148) To MWHPR12MB1152.namprd12.prod.outlook.com (10.169.204.16) X-MS-Office365-Filtering-Correlation-Id: 0dda5d73-f300-426b-dd4e-08d409017307 X-Microsoft-Exchange-Diagnostics: 1;MWHPR12MB1152;2:odp4rs122WgGAD2Q0TKfDPEU5SvvN03d3UgFBdf6zxtWuxPdDshbetsUHa8qJgcJAOmfgumltnnV7clx13DJoSNCxpwwU3njyyOpZV2PAl8yAhk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NW;20:dQiBECCI7PojseFPWRsVqVGIijoVamLcl6f4ejbfpMb7EmWXExTR4SFnAYe+nkIsbKFLhXEyYONlzrVZAP5SiQ5q10y0lnGgobBvbLhnjF6jYRXhAIrbvTFN9pLsoFjxYvvEuzvTPbeZiyR0ale6AF2rogcil/jRp2A/DKkM0OCWLmfCHrfm5RQjVC7M9ECRNCTgJW0N38ENX+8dTpqKICfPqm6Mw2oH70AH/CU3fRFG84kb3DNUGzXhUhsKw1D7oe7PgeNnuYnQ/N8VSBT4yhAhSMhLyzKHUUUHhV5B0Q1DyTMqu1KSjFwkfgU6imG0BCtF+C/98BKf/PRpHDFpEqs7+Y/660Dr8UuGJE48YmMnBVPP4xo0kRZu+KxJhya2/1CqOtMXlxgx4BMDGhoOitHwJIHemYlbLgKrutiSfIreu4fUXvpC/dMHKfarg74tuT1T6Ml9qwHsKzt0ocDUqg+wdmclU7VL5CzJ4ev1jheyz6qp7rt5YmbxjJqaY5ZD X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026);SRVR:MWHPR12MB1152;BCL:0;PCL:0;RULEID:;SRVR:MWHPR12MB1152; X-Microsoft-Exchange-Diagnostics: 1;MWHPR12MB1152;4:4Z+P4ormPCl6M/Ygok0dS4EwEKvI8yxNM7qItL3YmXdicTtFMsYKO4zEwGmeIJ7BMiOCDhaXd7UpTuuJyH16BvvN8Rf64jkbeZ609wkiWB+5yQqv0Q98Ihf/v5Vt9qWNtkh38VZkDi47UHwqZhzih9Ooj44zz9P+GiTaUkIQdKilEdF0zXbg5LWHEUKZEb5OYA6BVlS4m5VPr3QXsOEiErlVu9hmvm9x7mCRGvAtw5M8Fy1FnvEcFx1FD10nbHLo4wb+kqJibPnWC2GxaytDNNgmiXz/k1wIK/ciwKnwHYc8aT+jyZNck/Q+6z5eP06eYp/h9BaQFgvBbocKzMmy3bzbvfVopOJgeEHlgZwHdzFxeGbvEb/9KNmRmbdfCu9Whu+ys+54Nf81apufl7oaBVCj5H5FLybJJo+aFHIZR+nBMm3xaGI6Ps4IqxzWlDXoMDsnnKKor8V42wll5GaJgg== X-Forefront-PRVS: 01221E3973 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(7916002)(189002)(199003)(97736004)(5001770100001)(66066001)(47776003)(189998001)(23676002)(4001350100001)(9686002)(7416002)(5660300001)(86362001)(68736007)(33646002)(2201001)(230700001)(2950100002)(6666003)(8676002)(81156014)(1076002)(7846002)(97746001)(81166006)(50466002)(103116003)(4326007)(2906002)(305945005)(6116002)(586003)(3846002)(101416001)(83506001)(7736002)(42186005)(77096005)(76176999)(54356999)(92566002)(69596002)(53416004)(50986999)(106356001)(105586002)(71626007)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR12MB1152;H:tlendack-t1.amdoffice.net;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtNV0hQUjEyTUIxMTUyOzIzOkJBa2cyb1ZrdEpTZm1RdWhDTGNLdXZxWG9x?= =?utf-8?B?b0lsekxBaEZ6Z1JsYlRpSXlTb1NrQkM5SURwdGtaOFp6OGovdUhDRGYyMXNP?= =?utf-8?B?eUJLOHpEN0ZVZG9TYnpmNmJuMzc4Qi9aRXNoYUtFZ055OFp0L21panhLQXp1?= =?utf-8?B?Z01OYlc3T2l1amI5bXlvdlBSYkp6TFhROENlRVgwampBd2RYdmxhejZzZDh3?= =?utf-8?B?Um56K0tFR2ZlcDFjT2NFNERjRlZkYjVUZDBnRC9NZVMrcWkvN3dsUjkxdHNS?= =?utf-8?B?bDM0U0FGcnk3TmVXSnB1bTdpVFlXRnpYcW16N2wxVkZXc21JL3JCcTdoM3Vz?= =?utf-8?B?TGRLM2hEczJBNzFQZjZUcWRXbE0zN1RoTGZJ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ZflocPvacg==;24:59Y9vygRY/3TRUF0Ak02TYCvmCRie2D885MzllVT9ySmwW8bUZaNyf0C2dyqTxHBCw3dMFbZtlYq3bdOBIDr+pjwI/cJp/mALXkIiaaM86Y= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;MWHPR12MB1152;7:fZ5vWUkPJcDzdYHe6dD4j9vo1JevuyGoNBsEzYaRjZ17qwRcY9XONxTZtQaJoOQgEaVKQIpMoyp2QBQJx25LrmgcDwtPY0kD0DWe8VXEkIq7+jQmazcQB9SgKp6gBHnXk0FMNivopmPtYXlRecgX3egrSL9a7xPdU6D1l6XpmOgvxRo2kfdSpA03ONVERbR+s5TLAbhaeJ1JvAGngMrFPcPeNgGq9ZRqM17L94g4pwNm9x+Pz4X/4+W1QlkS8y/Y43ubRndFWSZF6GboKK/xSTZmN7/7rHz+P8TFr0uCgH58j1Scj+qi9YcrUyRKd2b95dOgz+WPBjc3pGhWVGPJ4FhLDhgG6BzsqwKBV5G4WaU=;20:x/Z8LItgFZjP5ZHJjx+Y3+zjZJkGWRMv3Se2q5+YVnSAe7ug1f1m74tyfjo8wP3Ju8lFwzDguitGhwwdynPMALPe/6U8OBVoZxdu/0Nm3Yy8XrJC8nEHCrbsh/kdOhMbgFILzHtZgtyjgIExncxUeqKgSQrzDbijlKNY2OLCiF4DivEiACxG0eFJb4IObaHDx+JQ+i3ey+1MEBTcFFD5Gz9GqvP5FbYJT6DiQNaLeiNZBqyXPnFiMSF2tD7LwqPh X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2016 00:35:18.0652 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1152 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2141 Lines: 71 When System Memory Encryption (SME) is enabled, the physical address space is reduced. Adjust the x86_phys_bits value to reflect this reduction. Signed-off-by: Tom Lendacky --- arch/x86/include/asm/msr-index.h | 2 ++ arch/x86/kernel/cpu/common.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 56f4c66..4949259 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -336,6 +336,8 @@ #define MSR_K8_TOP_MEM1 0xc001001a #define MSR_K8_TOP_MEM2 0xc001001d #define MSR_K8_SYSCFG 0xc0010010 +#define MSR_K8_SYSCFG_MEM_ENCRYPT_BIT 23 +#define MSR_K8_SYSCFG_MEM_ENCRYPT BIT_ULL(MSR_K8_SYSCFG_MEM_ENCRYPT_BIT) #define MSR_K8_INT_PENDING_MSG 0xc0010055 /* C1E active bits in int pending message */ #define K8_INTP_C1E_ACTIVE_MASK 0x18000000 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 9bd910a..82c64a6 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -604,6 +604,35 @@ out: #endif } +/* + * AMD Secure Memory Encryption (SME) can reduce the size of the physical + * address space if it is enabled, even if memory encryption is not active. + * Adjust x86_phys_bits if SME is enabled. + */ +static void phys_bits_adjust(struct cpuinfo_x86 *c) +{ + u32 eax, ebx, ecx, edx; + u64 msr; + + if (c->x86_vendor != X86_VENDOR_AMD) + return; + + if (c->extended_cpuid_level < 0x8000001f) + return; + + /* Check for SME feature */ + cpuid(0x8000001f, &eax, &ebx, &ecx, &edx); + if (!(eax & 0x01)) + return; + + /* Check if SME is enabled */ + rdmsrl(MSR_K8_SYSCFG, msr); + if (!(msr & MSR_K8_SYSCFG_MEM_ENCRYPT)) + return; + + c->x86_phys_bits -= (ebx >> 6) & 0x3f; +} + static void get_cpu_vendor(struct cpuinfo_x86 *c) { char *v = c->x86_vendor_id; @@ -736,6 +765,7 @@ void get_cpu_cap(struct cpuinfo_x86 *c) c->x86_virt_bits = (eax >> 8) & 0xff; c->x86_phys_bits = eax & 0xff; + phys_bits_adjust(c); c->x86_capability[CPUID_8000_0008_EBX] = ebx; } #ifdef CONFIG_X86_32