From patchwork Fri Aug 20 15:19:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 12449399 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B9FFC432BE for ; Fri, 20 Aug 2021 15:21:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EE25A61183 for ; Fri, 20 Aug 2021 15:21:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EE25A61183 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id A68796B0088; Fri, 20 Aug 2021 11:21:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A19276B0089; Fri, 20 Aug 2021 11:21:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81D526B008A; Fri, 20 Aug 2021 11:21:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0106.hostedemail.com [216.40.44.106]) by kanga.kvack.org (Postfix) with ESMTP id 66CEB6B0088 for ; Fri, 20 Aug 2021 11:21:17 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1BF1E2CFF3 for ; Fri, 20 Aug 2021 15:21:17 +0000 (UTC) X-FDA: 78495822594.08.A048880 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2076.outbound.protection.outlook.com [40.107.220.76]) by imf14.hostedemail.com (Postfix) with ESMTP id 965B96001982 for ; Fri, 20 Aug 2021 15:21:16 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AD66gOf1vXgMH5h2zGmoeOGQqFKGj037xPKCtLHC+TTp5IvHGBPnT+ueC/9YI1HvGuaorAKER7Qrzw6PZu6noPP1C1XSHUbQ/XJ0NtFjMxlfB/dlsHbdvofphd7Q8s+3oJscJThM3B7i2IGwrUI2HFzs+H5l8XnX6uOjoKpPLuoXKeOh7I0HZRu5b3Jx8aofId2v2b2FaF+ftwqY1lKNpJTkzCTyBQdx3YCpsCTTS+M7BqW0FA6iTgs7aPm9cbTdQbU8EROd6LnZj72fX8KiRBOrDF15MpUc7621cRtRfWfr362+70O0L7Zh1UbuPWiCLxt0LTvNxZWCFSztHLqE+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+GAj0n/mh4HxIHmd8pu1nVhyIj/Ean9oCwoFOmBwMJ4=; b=NIZC4QxH2dftZb8G6+PBVZI7gh92m8RkiOy15B29DVKfVSRXuvZbaUu17ggWRKHG1aXjLl9ZrYue77p93f9WU17ePlnHvj56Q2vVEzP0M13rPRDLDPd6dMw8qEGFL9CBx/6ktuO/R8XL/1b55bszOTJyV778LRnysXtWQxAXs9py3vsre0mb8LIjaArzFC8dwr5WtBfRVk3fVYFdt/zDJoQLlool0A3pDa2YoptlQyDzV2nlFEnI9y5JCu/Vx8qKpcel/mv2UVIBsWdSEDlmRM9Q+7T/vGo5dtkCLwJfJ8fR3Jip59QsxPTO+JmVjT69IzcglNh/O0Gh7beSBQVUww== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+GAj0n/mh4HxIHmd8pu1nVhyIj/Ean9oCwoFOmBwMJ4=; b=xbszn9ayIDU8VXJUH/Jot6tCMZiqM2BENpd6vaRUKMcnybvD7qdCGBlkYK8C8YSPybGeH2ElOEAVbVWUcLcdTay6KBl+PFSWfgndJboopk48WE6GM1+4IsMM+rj5EzBp77EynUjVXTWDg6lAdWtYPN74CbOAI0yj5qpFHbcVAeE= Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SN1PR12MB2446.namprd12.prod.outlook.com (2603:10b6:802:26::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.22; Fri, 20 Aug 2021 15:21:08 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3%6]) with mapi id 15.20.4436.019; Fri, 20 Aug 2021 15:21:08 +0000 From: Brijesh Singh To: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org Cc: Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com, Brijesh Singh Subject: [PATCH Part1 v5 16/38] x86/kernel: Validate rom memory before accessing when SEV-SNP is active Date: Fri, 20 Aug 2021 10:19:11 -0500 Message-Id: <20210820151933.22401-17-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210820151933.22401-1-brijesh.singh@amd.com> References: <20210820151933.22401-1-brijesh.singh@amd.com> X-ClientProxiedBy: SA9P223CA0002.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::7) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SA9P223CA0002.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Fri, 20 Aug 2021 15:21:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 24e8c95a-7068-4cfa-d868-08d963ee223c X-MS-TrafficTypeDiagnostic: SN1PR12MB2446: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z+qy+TXfWVdcPFNCtljsM8jNEqZpJaE+I0VjM/dQ4gKdrF8fdHmJvc/VvIqMF1Onhn1pt/eFgDXQArBufs7T3GomegnRjXvwxoFzBvRqbnez6MDu1dt0BeqvFFnJQzYveDpEmkqM0sErmjf8//oskhrZbdc9K7UVtS2yPrQ6kxLlhVHBsUS/3fl7bTSgFCYMBp6GNWzEqNvIoeOkuoSvYS5hY41uUg4gdID/FIUQsix50iXD+o9+gVBsk1/8rwMVu5WNR/aawWhzz/g8La2aPG69Ebl7DE4PH7H2GmmZZeAyKZDGrwjzZSXqMrguxprb490cOT4smVihyi8vNGcMVWXpDdcO0y63q1nDeEsppsY3cXIKacZgKquh4glBbfV8e/H98+ym6XkUMWkrRv4j17wNCc3CW075nEgPY6LoYwUGzMJDxei3dM2BiLkaNz8qoNN/9yhnszmadPbbl2D/B5xiUioifGcWaO9X2hcge1Dn8HzZLQg52wCIwx4NXIJ7qGCmmLirPrKDmIulvRW/Yzzsz4etWHhjl6Qtnmhr57COxPxXnsmcUIcQarrOJEt1z0PuE6ee22EosQu/IcF5YQdNqTwhhh4I3B9TcFjzTONDjIgWO81b2vIbs6SSTs0B9oUVAjt2Alkrh+7t5a7K6WCYNOPRNg9LUPcCJYM9bHImUyk9vmT05lYwTLIEqYvqW0hVGPX5Vu36HV+BOivrIg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(136003)(396003)(376002)(39860400002)(346002)(66556008)(478600001)(54906003)(4326008)(1076003)(6486002)(7416002)(38350700002)(52116002)(83380400001)(2616005)(7696005)(38100700002)(8676002)(26005)(8936002)(15650500001)(2906002)(316002)(66946007)(86362001)(66476007)(44832011)(36756003)(956004)(6666004)(5660300002)(7406005)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DrV06unxxeCp2w2dMfodb5qIkg3iua4Xa4VFbeWZyFU4H+6yF3S2iJc6ghipYLW0wRmtv3VV5Q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6ar8MEtRYYwg+/jSw96g0aS9fb1TZu4pIFoKkU2VRbb3CoBH8ECkN19mqfXVJZuAcaMMfQUcnRv/yzEnZjgxs1i3swEwpaPucbIJE1da+Uejf28fjB4zL5BoqYR0eQN32z5xNIO7V9VY09BLG+3N8VcjCc4a2kQW84037RoA3KugPsOJSx+VvrE6ayndHKi X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 24e8c95a-7068-4cfa-d868-08d963ee223c X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Aug 2021 15:21:08.0223 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eE46G4bXuZceEBXoa3S1YrVxiuVmMkaKofODuZ0M939hAoLmJKWBwGkp24g+JMNBVLKaJA9jewvOKQI0QwaBnA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2446 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=xbszn9ay; spf=pass (imf14.hostedemail.com: domain of brijesh.singh@amd.com designates 40.107.220.76 as permitted sender) smtp.mailfrom=brijesh.singh@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 965B96001982 X-Stat-Signature: i3qi76t7e5nthumqs8zbnaggdfhtt9wf X-HE-Tag: 1629472876-313839 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The probe_roms() access the memory range (0xc0000 - 0x10000) to probe various ROMs. The memory range is not part of the E820 system RAM range. The memory range is mapped as private (i.e encrypted) in page table. When SEV-SNP is active, all the private memory must be validated before the access. The ROM range was not part of E820 map, so the guest BIOS did not validate it. An access to invalidated memory will cause a VC exception. The guest does not support handling not-validated VC exception yet, so validate the ROM memory regions before it is accessed. Signed-off-by: Brijesh Singh --- arch/x86/kernel/probe_roms.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/probe_roms.c b/arch/x86/kernel/probe_roms.c index 9e1def3744f2..9c09df86d167 100644 --- a/arch/x86/kernel/probe_roms.c +++ b/arch/x86/kernel/probe_roms.c @@ -21,6 +21,7 @@ #include #include #include +#include static struct resource system_rom_resource = { .name = "System ROM", @@ -197,11 +198,21 @@ static int __init romchecksum(const unsigned char *rom, unsigned long length) void __init probe_roms(void) { - const unsigned char *rom; unsigned long start, length, upper; + const unsigned char *rom; unsigned char c; int i; + /* + * The ROM memory is not part of the E820 system RAM and is not pre-validated + * by the BIOS. The kernel page table maps the ROM region as encrypted memory, + * the SEV-SNP requires the encrypted memory must be validated before the + * access. Validate the ROM before accessing it. + */ + snp_prep_memory(video_rom_resource.start, + ((system_rom_resource.end + 1) - video_rom_resource.start), + SNP_PAGE_STATE_PRIVATE); + /* video rom */ upper = adapter_rom_resources[0].start; for (start = video_rom_resource.start; start < upper; start += 2048) {