From patchwork Mon Mar 6 18:11:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9607271 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1B8DB602B4 for ; Mon, 6 Mar 2017 18:30:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BE27279B3 for ; Mon, 6 Mar 2017 18:30:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F0B427D4A; Mon, 6 Mar 2017 18:30:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3937A279B3 for ; Mon, 6 Mar 2017 18:30:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753817AbdCFSa0 (ORCPT ); Mon, 6 Mar 2017 13:30:26 -0500 Received: from mail-bn3nam01on0080.outbound.protection.outlook.com ([104.47.33.80]:55601 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753555AbdCFS3r (ORCPT ); Mon, 6 Mar 2017 13:29:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=t+ug9hSuTQ5HiPTEvUCnr0Ks9cdC+FWRToG7cYenU3A=; b=GZMsXMsq0WEKPh7wAoPt+7Rdz/aHsBqS2Bm6JqfG01TZKWnszql/YH0hssXCJE2HUrEiY9IQSfdLikoEUJrsnRUUirxhSkCWzN4HaJYExQphP1kwshSpy5SzvVe39cOAIE9RmFkNz0pViL9T4dGP4o1OwguPAtWFy/CIRjU2W9M= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from [127.0.1.1] (165.204.77.1) by MWHPR12MB1616.namprd12.prod.outlook.com (10.172.56.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.947.12; Mon, 6 Mar 2017 18:11:07 +0000 Subject: Re: [RFC PATCH v2 01/32] x86: Add the Secure Encrypted Virtualization CPU feature From: Brijesh Singh To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Date: Mon, 6 Mar 2017 13:11:03 -0500 Message-ID: <148882363019.12034.4647462304803229954.stgit@brijesh-build-machine> In-Reply-To: <20170304101113.k6ontjjbljanm6tv@pd.tnic> References: <20170304101113.k6ontjjbljanm6tv@pd.tnic> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR1001CA0014.namprd10.prod.outlook.com (10.174.84.27) To MWHPR12MB1616.namprd12.prod.outlook.com (10.172.56.17) X-MS-Office365-Filtering-Correlation-Id: 3a67ba51-31db-4113-1c3a-08d464bc2d14 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:MWHPR12MB1616; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1616; 3:LLObllSqx4Hif4EjHu3dK/7xbVkJ4PP8YWi0Anuq0zZIlDRH/AS/8rI51x0ULL5F15zrS34AeuD0uqNF2dfGz4lvRSu68fIJ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+2Hl6S1QPmiJSHovUCZae3EjosWmj4Jrq22fs8TRLvSVMNJd5UrH6zv/AScnXjU59/VomnlKg2MT3eMQmeCN/zrA1HaaDWFIvI0TDdY6eUKJINWUyITWHTvBGuKIyMIMQD5Mjbs++PiSkNoXxMXTm0uSlkj4bnlZ4YnasJea/BW97U1f19//ODSBdarB+pKY2VqLOkXYuDKHQEjw0lx37gIZn73EwjhUg6uua1lQ1uJXdryDgiPhcoFX43EZiDj9UyYxdhBMyPA9I1HTUltqhxVdiadfApelunIBlApD2viPEwTKScnmfObNjjVyBm7cv7TdQWNeTi45SGdrgCP34MDc9DVx5Y+ZGvjF1r0DzGyFcO X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(20558992708506); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6041248)(20161123560025)(20161123564025)(20161123558025)(20161123562025)(20161123555025)(6072148); SRVR:MWHPR12MB1616; BCL:0; PCL:0; RULEID:; SRVR:MWHPR12MB1616; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1616; 4:Y8RCtVusstvwIoVt2BeG6uWZy4F0LQFkD5wpgViWqQICFdqQDDUsrfwtQE9YNX/IVgARDpwkuaCyZdTzeT0Hca95vdIkZUpC1YKMD+rc9rLb4cA1dy6yKlpk+KAbeKAPwffqlG/18M7k45VR8h4sneVyVQOpNG1T3NFdZGJAxseeABxYsyNpHt3U7g/3OWFLyfBreDb9afbL150nxccgS5dZVGR9SGH1pfw1Qrg5v/P5/Eh//XV4g4V+LHNBoav5VefYcS3BnmuBX6nlMxExgXqSX4/guwOFUQYtX29zZEhQ02Llodn/Tu4pZ7ePaYHiuEF4mY5kpw3Jd02YMeC2m2hejzQuunkpK3mWe+UNpePkxR6M6DFl8JLHhilD2ebxCrUcRVVGVCNnNAn9IHbZoPz5ZbwsyIjZuGMpT+gHUvitgU9rjOoQKhReM0OqMvdeE55JHjxZRAJbKyMosDb6hv590+BWD+vT58QDFY5ay3WY8EYcx0HiROJLHdwclLeEHf2QG5lDFMRw6fmOmYiHzEyECEKGQxkGxNTp03lW8YTbMNnB1X3zdtdhNyrXoyamBySVEOvkmTH5Z0eFR/fXcF+cyeq4e/No39mGGwFJEol2Y2+hauPyzJDwOIvYyLsSql8xgTLOxnKQGfA+AFSiEKf0x+F7zfMiBjfEUefe4ZA= X-Forefront-PRVS: 0238AEEDB0 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6049001)(7916002)(39450400003)(39850400002)(39410400002)(39840400002)(39860400002)(377454003)(24454002)(76176999)(8676002)(81166006)(47776003)(77096006)(3846002)(90366009)(7736002)(230700001)(305945005)(4326008)(53546006)(4001350100001)(9686003)(33646002)(6486002)(66066001)(54906002)(53936002)(92566002)(25786008)(189998001)(7406005)(7416002)(38730400002)(6246003)(33716001)(110136004)(23676002)(2351001)(50466002)(42186005)(54356999)(7366002)(6116002)(86362001)(50986999)(2906002)(6916009)(83506001)(2950100002)(6666003)(5660300001)(103116003)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1616; H:[127.0.1.1]; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtNV0hQUjEyTUIxNjE2OzIzOmFKYU96aW10TFdHenh3UHIyM1VTc2NaUWVY?= =?utf-8?B?OUY1ekZqZldnZXkwTmwzTHRUNkQxSWVwS2xRRGZhUnZBaVZZZXhFZi82cE1M?= =?utf-8?B?cnNjcC9MMnFzTnlNd0N0NFRXOUNiUmthMmJSZGxXa0VXVUhXekxwbVExTUh6?= =?utf-8?B?UTZScnVxM2cxdUxTd1IvN0VMUloyc0FaMEticDZmd2tzaDM3UFovaHp4cmtv?= =?utf-8?B?eitlT29PSGNxYVV6MjRKZEhJc29qVnQ3M2V2N0ZVKzF5TnRyb3dxbHVFS1dM?= =?utf-8?B?TEtINHArSkJMb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3Jfq2Shql3FM/jmajhzFM4zTtmACRVJAxLuSjqNCDU7yLnbXQQTr1a7lJriUgTi6m1fndNrtvwjFjXU3Krn76e+X X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2017 18:11:07.4450 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1616 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 03/04/2017 04:11 AM, Borislav Petkov wrote: > On Fri, Mar 03, 2017 at 03:01:23PM -0600, Brijesh Singh wrote: > > This looks like a wraparound... > > $ test-apply.sh /tmp/brijesh.singh.delta > checking file Documentation/admin-guide/kernel-parameters.txt > Hunk #1 succeeded at 2144 (offset -9 lines). > checking file Documentation/x86/amd-memory-encryption.txt > patch: **** malformed patch at line 23: DRAM from physical > > Yap. > > Looks like exchange or your mail client decided to do some patch editing > on its own. > > Please send it to yourself first and try applying. > Sending it through stg mail to avoid line wrapping. Please let me know if something is still messed up. I have tried applying it and it seems to apply okay. --- Documentation/admin-guide/kernel-parameters.txt | 4 +-- Documentation/x86/amd-memory-encryption.txt | 33 +++++++++++++---------- arch/x86/include/asm/cpufeature.h | 7 +---- arch/x86/include/asm/cpufeatures.h | 6 +--- arch/x86/include/asm/disabled-features.h | 3 +- arch/x86/include/asm/required-features.h | 3 +- arch/x86/kernel/cpu/amd.c | 23 ++++++++++++++++ arch/x86/kernel/cpu/common.c | 23 ---------------- arch/x86/kernel/cpu/scattered.c | 1 + 9 files changed, 50 insertions(+), 53 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 91c40fa..b91e2495 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2153,8 +2153,8 @@ mem_encrypt=on: Activate SME mem_encrypt=off: Do not activate SME - Refer to the SME documentation for details on when - memory encryption can be activated. + Refer to Documentation/x86/amd-memory-encryption.txt + for details on when memory encryption can be activated. mem_sleep_default= [SUSPEND] Default system suspend mode: s2idle - Suspend-To-Idle diff --git a/Documentation/x86/amd-memory-encryption.txt b/Documentation/x86/amd-memory-encryption.txt index 0938e89..0b72ff2 100644 --- a/Documentation/x86/amd-memory-encryption.txt +++ b/Documentation/x86/amd-memory-encryption.txt @@ -7,9 +7,9 @@ DRAM. SME can therefore be used to protect the contents of DRAM from physical attacks on the system. A page is encrypted when a page table entry has the encryption bit set (see -below how to determine the position of the bit). The encryption bit can be -specified in the cr3 register, allowing the PGD table to be encrypted. Each -successive level of page tables can also be encrypted. +below on how to determine its position). The encryption bit can be specified +in the cr3 register, allowing the PGD table to be encrypted. Each successive +level of page tables can also be encrypted. Support for SME can be determined through the CPUID instruction. The CPUID function 0x8000001f reports information related to SME: @@ -17,13 +17,14 @@ function 0x8000001f reports information related to SME: 0x8000001f[eax]: Bit[0] indicates support for SME 0x8000001f[ebx]: - Bit[5:0] pagetable bit number used to activate memory - encryption - Bit[11:6] reduction in physical address space, in bits, when - memory encryption is enabled (this only affects system - physical addresses, not guest physical addresses) - -If support for SME is present, MSR 0xc00100010 (SYS_CFG) can be used to + Bits[5:0] pagetable bit number used to activate memory + encryption + Bits[11:6] reduction in physical address space, in bits, when + memory encryption is enabled (this only affects + system physical addresses, not guest physical + addresses) + +If support for SME is present, MSR 0xc00100010 (MSR_K8_SYSCFG) can be used to determine if SME is enabled and/or to enable memory encryption: 0xc0010010: @@ -41,7 +42,7 @@ The state of SME in the Linux kernel can be documented as follows: The CPU supports SME (determined through CPUID instruction). - Enabled: - Supported and bit 23 of the SYS_CFG MSR is set. + Supported and bit 23 of MSR_K8_SYSCFG is set. - Active: Supported, Enabled and the Linux kernel is actively applying @@ -51,7 +52,9 @@ The state of SME in the Linux kernel can be documented as follows: SME can also be enabled and activated in the BIOS. If SME is enabled and activated in the BIOS, then all memory accesses will be encrypted and it will not be necessary to activate the Linux memory encryption support. If the BIOS -merely enables SME (sets bit 23 of the SYS_CFG MSR), then Linux can activate -memory encryption. However, if BIOS does not enable SME, then Linux will not -attempt to activate memory encryption, even if configured to do so by default -or the mem_encrypt=on command line parameter is specified. +merely enables SME (sets bit 23 of the MSR_K8_SYSCFG), then Linux can activate +memory encryption by default (CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT=y) or +by supplying mem_encrypt=on on the kernel command line. However, if BIOS does +not enable SME, then Linux will not be able to activate memory encryption, even +if configured to do so by default or the mem_encrypt=on command line parameter +is specified. diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h index ea2de6a..d59c15c 100644 --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -28,7 +28,6 @@ enum cpuid_leafs CPUID_8000_000A_EDX, CPUID_7_ECX, CPUID_8000_0007_EBX, - CPUID_8000_001F_EAX, }; #ifdef CONFIG_X86_FEATURE_NAMES @@ -79,9 +78,8 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 15, feature_bit) || \ CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 16, feature_bit) || \ CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 17, feature_bit) || \ - CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 18, feature_bit) || \ REQUIRED_MASK_CHECK || \ - BUILD_BUG_ON_ZERO(NCAPINTS != 19)) + BUILD_BUG_ON_ZERO(NCAPINTS != 18)) #define DISABLED_MASK_BIT_SET(feature_bit) \ ( CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 0, feature_bit) || \ @@ -102,9 +100,8 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 15, feature_bit) || \ CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 16, feature_bit) || \ CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 17, feature_bit) || \ - CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 18, feature_bit) || \ DISABLED_MASK_CHECK || \ - BUILD_BUG_ON_ZERO(NCAPINTS != 19)) + BUILD_BUG_ON_ZERO(NCAPINTS != 18)) #define cpu_has(c, bit) \ (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \ diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 331fb81..b1a4468 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -12,7 +12,7 @@ /* * Defines x86 CPU feature bits */ -#define NCAPINTS 19 /* N 32-bit words worth of info */ +#define NCAPINTS 18 /* N 32-bit words worth of info */ #define NBUGINTS 1 /* N 32-bit bug flags */ /* @@ -187,6 +187,7 @@ * Reuse free bits when adding new feature flags! */ +#define X86_FEATURE_SME ( 7*32+ 0) /* AMD Secure Memory Encryption */ #define X86_FEATURE_CPB ( 7*32+ 2) /* AMD Core Performance Boost */ #define X86_FEATURE_EPB ( 7*32+ 3) /* IA32_ENERGY_PERF_BIAS support */ #define X86_FEATURE_CAT_L3 ( 7*32+ 4) /* Cache Allocation Technology L3 */ @@ -296,9 +297,6 @@ #define X86_FEATURE_SUCCOR (17*32+1) /* Uncorrectable error containment and recovery */ #define X86_FEATURE_SMCA (17*32+3) /* Scalable MCA */ -/* AMD-defined CPU features, CPUID level 0x8000001f (eax), word 18 */ -#define X86_FEATURE_SME (18*32+0) /* Secure Memory Encryption */ - /* * BUG word(s) */ diff --git a/arch/x86/include/asm/disabled-features.h b/arch/x86/include/asm/disabled-features.h index 8b45e08..85599ad 100644 --- a/arch/x86/include/asm/disabled-features.h +++ b/arch/x86/include/asm/disabled-features.h @@ -57,7 +57,6 @@ #define DISABLED_MASK15 0 #define DISABLED_MASK16 (DISABLE_PKU|DISABLE_OSPKE) #define DISABLED_MASK17 0 -#define DISABLED_MASK18 0 -#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 19) +#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 18) #endif /* _ASM_X86_DISABLED_FEATURES_H */ diff --git a/arch/x86/include/asm/required-features.h b/arch/x86/include/asm/required-features.h index 6847d85..fac9a5c 100644 --- a/arch/x86/include/asm/required-features.h +++ b/arch/x86/include/asm/required-features.h @@ -100,7 +100,6 @@ #define REQUIRED_MASK15 0 #define REQUIRED_MASK16 0 #define REQUIRED_MASK17 0 -#define REQUIRED_MASK18 0 -#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 19) +#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 18) #endif /* _ASM_X86_REQUIRED_FEATURES_H */ diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 35a5d5d..6bddda3 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -615,6 +615,29 @@ static void early_init_amd(struct cpuinfo_x86 *c) */ if (cpu_has_amd_erratum(c, amd_erratum_400)) set_cpu_bug(c, X86_BUG_AMD_E400); + + /* + * BIOS support is required for SME. If BIOS has enabld SME then + * adjust x86_phys_bits by the SME physical address space reduction + * value. If BIOS has not enabled SME then don't advertise the + * feature (set in scattered.c). + */ + if (c->extended_cpuid_level >= 0x8000001f) { + if (cpu_has(c, X86_FEATURE_SME)) { + u64 msr; + + /* Check if SME is enabled */ + rdmsrl(MSR_K8_SYSCFG, msr); + if (msr & MSR_K8_SYSCFG_MEM_ENCRYPT) { + unsigned int ebx; + + ebx = cpuid_ebx(0x8000001f); + c->x86_phys_bits -= (ebx >> 6) & 0x3f; + } else { + clear_cpu_cap(c, X86_FEATURE_SME); + } + } + } } static void init_amd_k8(struct cpuinfo_x86 *c) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 358208d7..c188ae5 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -763,29 +763,6 @@ void get_cpu_cap(struct cpuinfo_x86 *c) if (c->extended_cpuid_level >= 0x8000000a) c->x86_capability[CPUID_8000_000A_EDX] = cpuid_edx(0x8000000a); - if (c->extended_cpuid_level >= 0x8000001f) { - cpuid(0x8000001f, &eax, &ebx, &ecx, &edx); - - /* SME feature support */ - if ((c->x86_vendor == X86_VENDOR_AMD) && (eax & 0x01)) { - u64 msr; - - /* - * For SME, BIOS support is required. If BIOS has - * enabled SME adjust x86_phys_bits by the SME - * physical address space reduction value. If BIOS - * has not enabled SME don't advertise the feature. - */ - rdmsrl(MSR_K8_SYSCFG, msr); - if (msr & MSR_K8_SYSCFG_MEM_ENCRYPT) - c->x86_phys_bits -= (ebx >> 6) & 0x3f; - else - eax &= ~0x01; - } - - c->x86_capability[CPUID_8000_001F_EAX] = eax; - } - init_scattered_cpuid_features(c); /* diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c index d979406..cabda87 100644 --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c @@ -30,6 +30,7 @@ static const struct cpuid_bit cpuid_bits[] = { { X86_FEATURE_HW_PSTATE, CPUID_EDX, 7, 0x80000007, 0 }, { X86_FEATURE_CPB, CPUID_EDX, 9, 0x80000007, 0 }, { X86_FEATURE_PROC_FEEDBACK, CPUID_EDX, 11, 0x80000007, 0 }, + { X86_FEATURE_SME, CPUID_EAX, 0, 0x8000001f, 0 }, { 0, 0, 0, 0, 0 } };