From patchwork Thu Mar 2 15:12:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9600467 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 1EA3660414 for ; Thu, 2 Mar 2017 15:33:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F1B327D85 for ; Thu, 2 Mar 2017 15:33:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0337F285A0; Thu, 2 Mar 2017 15:33:29 +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=ham 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 727FA27D85 for ; Thu, 2 Mar 2017 15:33:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753518AbdCBPd0 (ORCPT ); Thu, 2 Mar 2017 10:33:26 -0500 Received: from mail-sn1nam02on0053.outbound.protection.outlook.com ([104.47.36.53]:43642 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751038AbdCBP3Y (ORCPT ); Thu, 2 Mar 2017 10:29:24 -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=ZkiR316T3VuvbtQGzPJ1l/mdMQIhQs4OYS1RrKkJNJU=; b=ELpa658vSAVsbr5bLFDhmR2BPpo0gh/3J9GF5i5EcrDdfnzPt8KMpuUDSiIFFkwDrMdQBglJ2G8o3lOtGPFVYyR8mPPkW4D/V0E8Q44mh6XbeoXMXOReaG/RyMziqtsgggaFuVU04m3IjkOzdFbwAxKhZha9j6SV/7RAiwQ4I4A= 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 BN6PR12MB1602.namprd12.prod.outlook.com (10.172.20.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.947.12; Thu, 2 Mar 2017 15:12:25 +0000 Subject: [RFC PATCH v2 02/32] x86: Secure Encrypted Virtualization (SEV) support From: Brijesh Singh To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Date: Thu, 2 Mar 2017 10:12:20 -0500 Message-ID: <148846754069.2349.4698319264278045964.stgit@brijesh-build-machine> In-Reply-To: <148846752022.2349.13667498174822419498.stgit@brijesh-build-machine> References: <148846752022.2349.13667498174822419498.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR07CA0014.namprd07.prod.outlook.com (10.172.94.24) To BN6PR12MB1602.namprd12.prod.outlook.com (10.172.20.151) X-MS-Office365-Filtering-Correlation-Id: 0ac2c98e-312f-4695-9215-08d4617e8ce8 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:BN6PR12MB1602; X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1602; 3:ZlH6u0bz3/KMG0UoeUayy1yD2SxSkiNMUvduETNDq5V0c78FEzJ8+fp49bqTqHpp32OEb1bq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qv0xV14y0lMP17awHiwoc20UlXiFKwlXuauBPDIoQgGFeFNo83YWp8EEeQY1CosRl5jZUxPrP82ux8M82oti7P38VP3EFzbhzSz6aVO92j0KMroJFl3VkOdbk72bYrJgmiZx13qDJ+gaQEOqiCwWo3KfSK4PxWuxB5qpDfLlBkt8jmGXQ7ZUo4OIk0CNLW5kG8D+OUFYDST+dRJGHUEfXR1pzhCfERydhZ/uN46OTzG63I1sj5lzFMGkS39UWl9/PFu3ffRWPFH3n9gwar1RU8edxPTlS4nm9zvHCoHUroEI3l1EHVK/lOhZkB+Z9RWSLAM2UcvwZr2IlY+S/nbhnQYckP+mXBmYGDYFuqbrlXkK8Rv4u2jyNoPwH7bJUNTdn2kzHljFZu7sUyXV+BHHQFKNnqPvTkooSC0CfDnQp+XCiwHchjyd2QMnSDa48 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6041248)(20161123562025)(20161123564025)(20161123560025)(20161123555025)(20161123558025)(6072148); SRVR:BN6PR12MB1602; BCL:0; PCL:0; RULEID:; SRVR:BN6PR12MB1602; X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1602; 4:4KBfvnAVzpR1tJmVT7y0lKcb060NU7yKGKvlgWcrEFbaFvtYHCKLl3nq1BuF3nFkHUa+Mw38jp8ZBDzkJPvjBn8m8Gy6ff5q92GsDC+uavYcl0wsH8ppZXggJax1gnukjWXLxs43yAXIjjBcJ0roUVVakrDFNneBDjHZ/X+77SPm+wn4NMV1uc5dIN92VnWWvunrEz7zfhF5CSAP0U/MnYNI+SvASmLVyK2YRlbRA85pTuTCVMER21E1k5TE25GtpWaec9ISREIVj/Dl2lGZv78/viSuxxJVh0m0nqhzeSdkY1GcID20e20Rde5CjHd/rGbwEqxpLZsptOpSD77wUXAfC+NVv0Goe/qo/ZaZ6fG2/JXffwRQlzUthnI2NRG5PZOZ0cl+bvXLgyNB8G46zaWPC7hewvGMOscUAPezxEt0Q2Pftwq4TpCm17ymsY7tacNcbyD7Vd3XUHLee0s1c6hGtxM8o/cXvSfzHTXZcpfJ5cwfp0Bwgl5G+GciXtNiCs6puIqp8x5TmOUZEOOnDsvDMQ1YIQT1TkqhxNdnxfJ8pAds87XnjmkFdpEY2Ld0rc0zkpW49T0vdsyQo0Glu9JCr363klxcT1xrTa7NQ4W3VN37hBD3r1EbMLDXKkPafCIS+KUO/9e6uuJEBEnsws76t0+7pL0jcHWDuhEV1wQ= X-Forefront-PRVS: 023495660C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6049001)(7916002)(39850400002)(39450400003)(39860400002)(39840400002)(39410400002)(25786008)(77096006)(23676002)(50466002)(47776003)(6486002)(230700001)(66066001)(5660300001)(9686003)(3846002)(50986999)(92566002)(83506001)(7416002)(7366002)(7736002)(7406005)(305945005)(103116003)(42186005)(1191002)(2906002)(90366009)(54356999)(33716001)(6116002)(53936002)(33646002)(2950100002)(8676002)(81166006)(6666003)(38730400002)(2201001)(86362001)(189998001)(76176999)(921003)(2101003)(84006005)(1121003)(83996005)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR12MB1602; H:[127.0.1.1]; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTjZQUjEyTUIxNjAyOzIzOndxbUdTT3ZxTXJla282NHBXUzFjN1lablhH?= =?utf-8?B?bzE0U3NqZktIT3BEZE1CVCt0U2pxYjd2OThSclZ5N21uWXZRVmZtenNHRmpV?= =?utf-8?B?WGJjV1Z2MFZERmNuQno0SmNIbzJVQW90Zzg5aVFQNlFIQjUwaG85RHNkMFhq?= =?utf-8?B?bDFGSnkydDROdnM2SUlBVmM1L0tRRlJxYWlXNzNjVEhtalB3MVpjMVNGODhD?= =?utf-8?B?RkFlWEtWd2J4L0ZjWU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HfGcRVAPztsQTo5bZ0gVNJIWiVdYSZmurZAfJcGpOOL2LXTy4KrvMKo76NiLmsRIcrhiGI=; 5:quirlXO4pS4cApTKyJo/6sBwMvqqoINfOpboLbVE8sXxAqRpaqDtOvD4cMxD5MzGTRqiu1mezOwj4UcNYNH1ywk4zuxIh7N+1mevCepTXGRXN9CLHYypkfu/c6CHFKxRCcgCRBfCe5SKtTXpv5XTIg==; 24:0XmMB+wuZeKq1+jrLPNlkaFd8EV4tA/00H10+5yTMDCtGGlNBjdB5nNSsKI9BT39R1D8noOY2V9hqASFq0PowTcJ+uVzPyc7il/VVD2PgCI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1602; 7:oy0mlll2P4HoAn5Plv0G7Rcf/Vu0qIQDvIHIfbVpFP1mPNcd9O55tCM1cLVRHd6VJpOww2xaMyraLq1Fu4ugdWKlJLgcdtk+nf8hm5uPlPPXaaFI8I0t+X7EMAgGBAJuq39MZG5BE27eqAMU1bwDoDzwMTWy0+Yw5pu+arXuJaXgG0Dd5znHAqkEB7Kjb6rQeDRty8e2IbatFbAiQyIV819/eYzgZqKJ4DtSoSiL5/H36YDGy7XoNucLHb1SFJjHkDQNYTs45J7Zs5d/ACh11xrHA5/cEnqxS4n/GRiboam9b3kwaQeeC1Ef6zWJcalGJTPBQC1m0z3BLSm93gGEAQ==; 20:pWaBmVcQmH+Z8wb4taNiGPTKZrf9b8fnXvKuMsklGMHtJQv4VVyH2FaFLJxhOIjZS9cbKSexgu3bDs51g+ZkYdCJohO+USeVXnXh84CXZdHqLUgABsxNePMoL10GOOPSCdvY+nE/hr3eldoRZziuKLTWt+Qdn554XM1mOxlyQCIpQv/FqLUjnlj9IYtIgTZKNwjGk4lyD9hgZQkKoYfyt6IrN7DxEUn51I1UtBH/pMfT2bjGeUREFL0Uw/t3I9Ow X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2017 15:12:25.0937 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1602 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tom Lendacky Provide support for Secure Encyrpted Virtualization (SEV). This initial support defines a flag that is used by the kernel to determine if it is running with SEV active. Signed-off-by: Tom Lendacky --- arch/x86/include/asm/mem_encrypt.h | 14 +++++++++++++- arch/x86/mm/mem_encrypt.c | 3 +++ include/linux/mem_encrypt.h | 6 ++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index 1fd5426..9799835 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -20,10 +20,16 @@ #ifdef CONFIG_AMD_MEM_ENCRYPT extern unsigned long sme_me_mask; +extern unsigned int sev_enabled; static inline bool sme_active(void) { - return (sme_me_mask) ? true : false; + return (sme_me_mask && !sev_enabled) ? true : false; +} + +static inline bool sev_active(void) +{ + return (sme_me_mask && sev_enabled) ? true : false; } static inline u64 sme_dma_mask(void) @@ -53,6 +59,7 @@ void swiotlb_set_mem_attributes(void *vaddr, unsigned long size); #ifndef sme_me_mask #define sme_me_mask 0UL +#define sev_enabled 0 static inline bool sme_active(void) { @@ -64,6 +71,11 @@ static inline u64 sme_dma_mask(void) return 0ULL; } +static inline bool sev_active(void) +{ + return false; +} + static inline int set_memory_encrypted(unsigned long vaddr, int numpages) { return 0; diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index c5062e1..090419b 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -34,6 +34,9 @@ void __init __early_pgtable_flush(void); unsigned long sme_me_mask __section(.data) = 0; EXPORT_SYMBOL_GPL(sme_me_mask); +unsigned int sev_enabled __section(.data) = 0; +EXPORT_SYMBOL_GPL(sev_enabled); + /* Buffer used for early in-place encryption by BSP, no locking needed */ static char sme_early_buffer[PAGE_SIZE] __aligned(PAGE_SIZE); diff --git a/include/linux/mem_encrypt.h b/include/linux/mem_encrypt.h index 913cf80..4b47c73 100644 --- a/include/linux/mem_encrypt.h +++ b/include/linux/mem_encrypt.h @@ -23,6 +23,7 @@ #ifndef sme_me_mask #define sme_me_mask 0UL +#define sev_enabled 0 static inline bool sme_active(void) { @@ -34,6 +35,11 @@ static inline u64 sme_dma_mask(void) return 0ULL; } +static inline bool sev_active(void) +{ + return false; +} + static inline int set_memory_encrypted(unsigned long vaddr, int numpages) { return 0;