From patchwork Thu Mar 2 15:12:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9600503 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 266A660453 for ; Thu, 2 Mar 2017 15:38:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16DE727F90 for ; Thu, 2 Mar 2017 15:38:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B8772859F; Thu, 2 Mar 2017 15:38:02 +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 A2BC527F90 for ; Thu, 2 Mar 2017 15:38:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752978AbdCBPgL (ORCPT ); Thu, 2 Mar 2017 10:36:11 -0500 Received: from mail-sn1nam01on0055.outbound.protection.outlook.com ([104.47.32.55]:54286 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753236AbdCBPfA (ORCPT ); Thu, 2 Mar 2017 10:35:00 -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=tK28jyjZB9Tou6rn0CBIPS08dT+uclw57TTOgy56ohc=; b=Xjf2xC6DLPb1svydWIClqTKS6PRiu/Hztuf4ppFOua89GvyW/Ig1d3CUc0HITIM6ZbsNfxCIml2sbXAdv0Xf8cWCWhiRof1F2dZpG52QAr73n4ImpWweiUygjMrsxWK6k1Xqw15JTmhc2NuI9Q3dLSynKYKXUjaoUTW97qojUUc= 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 MWHPR12MB1613.namprd12.prod.outlook.com (10.172.56.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.933.12; Thu, 2 Mar 2017 15:13:01 +0000 Subject: [RFC PATCH v2 05/32] x86: Use encrypted access of BOOT related data with SEV From: Brijesh Singh To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Date: Thu, 2 Mar 2017 10:12:59 -0500 Message-ID: <148846757895.2349.561582698953591240.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: DM5PR16CA0043.namprd16.prod.outlook.com (10.172.42.157) To MWHPR12MB1613.namprd12.prod.outlook.com (10.172.56.14) X-MS-Office365-Filtering-Correlation-Id: d8bac782-7ff2-49d4-06c7-08d4617ea013 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:MWHPR12MB1613; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1613; 3:Fe8Q1uwOcsllnvu4WeTGkueKk2EGko26LSKql2RvUkASseqQDnmz7vOArSHPUcsKUZRcKnf+q4l/6bu/7MsC+u7F5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oIihfb1XrOVycjId9z5e3zyp6wipiTzbxOYG9JjZRtG1p5oEQb1l+MixHMfjU38PiCVzcTlRjeFzveOuTFsbSQoVddTbDbP6JqDBk/+dwKhqIqEjhUFC+wVi/r4i8LPDcqrY/rdSdqXjm3z8EnBy1hguAk7nvuyAO9I1AKczpg2OW19sPGxYA3vtr17pVFbZU3XRbjbwQoOnYt1NSn3Hci4pJgK2FP2ddKs4j4+4WeFebZw438eSY7KKUbak1VCW/v1EePd9bXKeQQ9OFhc39xOaQsldphba4EnyC12KguRG8pI6Gr6LsfY+G3jWR4tLdCgceVGde2+k8ep/vLRYZKJqbYLIo+Ar6Lo0c7Aa5iqYG/3ZgxxhHBt78/0y0qeigN4/V+a9AASVBFBbCEI 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)(10201501046)(3002001)(6055026)(6041248)(20161123555025)(20161123564025)(20161123562025)(20161123558025)(20161123560025)(6072148); SRVR:MWHPR12MB1613; BCL:0; PCL:0; RULEID:; SRVR:MWHPR12MB1613; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1613; 4:lCnzsSYUytTYK09f8wzYo/aL1MaWXB5JUNfk0Ml6gD/0weBhSFiYkaOzR/YEDp5Cs0oBC8vlag8k7JWFovQA8HKYDcEKp+3Xjcj0Gkrlzju2Nb1irYkGRLKhje72hRyNjwKQlLdyTlg6VZl6558Lyb1P9pPqBmeQFWpfRSPv+2yerCFQmc3fz/KlRs47HkS5IB6kXhFxsAanONBnA0Op8rgRFu0aUwtF7hwxm5dEFgVwXFaxdUgrAZFDmKE0WuzsrU3oLjRQ5YZt8CjFLNWPnpo34l3yTXnwkRV30ojY2EGDdGQq+lBswXjHmTXD2abqX8O8yXKIfK/9EqkdRUFE2YddwnEFT+ix1+NbT4HL5VlApkpg8lEOKbhL0DQYEmhnvlIebuUCqSPxrBvQJty38vaCMOc84w9LziS/lwirbu+ijF/gKBaQW90soDGH9oegFFLvKcUZiqWGTmiG7PV+OB1lfTMA/Fv9kIMqO4knDTrpen0C5FGgtUkpV86e0Z28VZHl6icAn2KdnngoBxtliZbEiybJjK1+mXjfEwWGP6rLF0SliiZnjykAfxnKwm+UOCofkWUcmYKjqKAGSi2wSFAlORRDtigz2LgyvV/zmyO5Gtn25CK8rrKuiXVrZ83yOvMWUhOiXcs+Mffcs/jErmd5WJ80Wf4RwEk5WxgPk88= X-Forefront-PRVS: 023495660C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6049001)(7916002)(39450400003)(39840400002)(39860400002)(39410400002)(39850400002)(54356999)(230700001)(42186005)(76176999)(3846002)(2950100002)(5660300001)(2906002)(33646002)(33716001)(50986999)(83506001)(6116002)(66066001)(8676002)(9686003)(38730400002)(25786008)(53936002)(92566002)(77096006)(6486002)(189998001)(90366009)(2201001)(50466002)(23676002)(7406005)(1191002)(7366002)(103116003)(86362001)(7416002)(7736002)(305945005)(81166006)(47776003)(921003)(2101003)(1121003)(83996005)(217873001)(84006005); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1613; H:[127.0.1.1]; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtNV0hQUjEyTUIxNjEzOzIzOmNtM0FXWEVTUDZYV2gveHVpWUhBVnMrVy91?= =?utf-8?B?VzlFclpUWTFvbml2Y2JnT29jeng0MjVQL1dUYmlCQUtBTmpZNXhaV1FCRFVJ?= =?utf-8?B?NVdoeGs3U0V5S2dYS3ltZEwvZ3hDcnUySG1YbkNaTWtoRHNQV2NWQksya0Yy?= =?utf-8?B?bWRoaVpQQlQzM2FkRlN4TEFrMkM5M2JXZndDUktJdGRRaWIzQy8rTnAvNUh1?= =?utf-8?B?d0c3SUxkaHNzYm9vZm9xWnFCeTErZytMa0xHT2ZURlhlUFk3cm5VbllseER3?= =?utf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ujAa2RK9kLL44EEVe/YcPJBJI6JGb6rpsjhTKrLQsO6Pvc=; 5:qwuAiHpq9oDTIGJbkiz14ououHsQO5Fy5CHUhwJR6mM+eJHfsnDoW+y/0E7D1ifre6APSa56Bab3Js9UQYWQp3CEz8NqwPCNY/9aj8BDQx7+r3uvc+nzRNGWeYxhkWX7nGJxc7CqSpchr4rEwDMVnA==; 24:xGgxsIYesUGAB4rAS/moI30OV6OUGvwGBEcdkXW/AuwOeFOaKvqrnRgNHGnwzpvZkVz9hsFThcWve3JkIqnOuiuRR/vqX8EBLwrG0LtA5QU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1613; 7:hpcMvbh4OEYBJX8Bjksl47xi/rGow8eDJJYcVKZgQlc/58cB/4V7AAmQQ0ZWSfeKMb2WlTDPbO/k/NaIo/jLmN9zh0rvb5hSi3ovYm/FCdRp1NerWbisuW3uHDgI/uKrrdWcX3kjmu5jCoeM9+IUEvAO1yzF+la0e+V82B7ZjQ2DqkF5U+u1P0gIufFKLQYoUwV9nhxAAUk6USWm52O7ho79ZUM/TBAYBs7S8R+q1DD+3B4LZgzxdOEXLS7lvUrDAN+oKMl2MOjjMMmiV16eTTR1bXqgestXFfNS8raU/s8iYw/P9dXRQDI2CVCbibl6sXREfr0MRNHdr9FWtc0HHQ==; 20:LkYgkrcxMfyOdu6yPN5/D7/zd8eUs/gboC6zLrPSo2WxLl47QKix81ga163hblZwPdwBd7Qlotu76R47HuMGB3Qf65k6c7kpCaVnpqS98x+J8eUQRRUOqMGMgmdQv72nbUou1YTSXGBcbRB6vI9v/bLPIqyBWyTg02topNt3U86k6V+XX+2BxKVFXkHb5G6DU+Vft7gdHWwWuIXMdl2T2sgwN9j2lYRaJnjC4U92Bpw1EjE7Bz+DO1gzPWpwqVpq X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2017 15:13:01.3583 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1613 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 When Secure Encrypted Virtualization (SEV) is active, BOOT data (such as EFI related data, setup data) is encrypted and needs to be accessed as such when mapped. Update the architecture override in early_memremap to keep the encryption attribute when mapping this data. Signed-off-by: Tom Lendacky --- arch/x86/mm/ioremap.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c index c6cb921..c400ab5 100644 --- a/arch/x86/mm/ioremap.c +++ b/arch/x86/mm/ioremap.c @@ -462,12 +462,31 @@ static bool memremap_is_setup_data(resource_size_t phys_addr, } /* - * This function determines if an address should be mapped encrypted. - * Boot setup data, EFI data and E820 areas are checked in making this - * determination. + * This function determines if an address should be mapped encrypted when + * SEV is active. E820 areas are checked in making this determination. */ -static bool memremap_should_map_encrypted(resource_size_t phys_addr, - unsigned long size) +static bool memremap_sev_should_map_encrypted(resource_size_t phys_addr, + unsigned long size) +{ + /* Check if the address is in persistent memory */ + switch (e820__get_entry_type(phys_addr, phys_addr + size - 1)) { + case E820_TYPE_PMEM: + case E820_TYPE_PRAM: + return false; + default: + break; + } + + return true; +} + +/* + * This function determines if an address should be mapped encrypted when + * SME is active. Boot setup data, EFI data and E820 areas are checked in + * making this determination. + */ +static bool memremap_sme_should_map_encrypted(resource_size_t phys_addr, + unsigned long size) { /* * SME is not active, return true: @@ -508,6 +527,13 @@ static bool memremap_should_map_encrypted(resource_size_t phys_addr, return true; } +static bool memremap_should_map_encrypted(resource_size_t phys_addr, + unsigned long size) +{ + return sev_active() ? memremap_sev_should_map_encrypted(phys_addr, size) + : memremap_sme_should_map_encrypted(phys_addr, size); +} + /* * Architecure function to determine if RAM remap is allowed. */