Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp606901pxj; Wed, 2 Jun 2021 07:09:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcnUh1XKTE7fG0PTzX+uOVbVpzDDi7jv3LEBq1jfG34m7abn9X3KFcW0X1JRL9KXklQ7ag X-Received: by 2002:a17:906:3c44:: with SMTP id i4mr17046061ejg.135.1622642986823; Wed, 02 Jun 2021 07:09:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1622642986; cv=pass; d=google.com; s=arc-20160816; b=UQYMTXnnHv3sUaeck7pK5ry+PLFQ6JjJk6R3/YjG+JRoHlyvNe3lJuOZP11KmyC2Ak ZgNw+9BadLEQzBkv4sJdyCEwqCQ/FK3h3dAFjimd78QcmBcxuf2CoSMjGWd8DrVSRk+C FqfHuENTE4g8poiD18m5ILK87BLCSXXXb0RFuzY5aSxRN2w+wzZfyYzsQwiUUjVgi43A XJaaYBBii//VJ6a7fcqbZz7le1feBZsdX13oHULDQNW+OQwMFufrL8Tu3lPIzvKDg8WO YX3yOlX69nyKr4VHZ72oNYcjEsp/k96rTO3f0m1nlxe4kEBXQ+a3g5ZVaAv9hHUtS9cG GoJA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=iBYwKWM1e2f6h3Bx093S/ZsTxx9S/8/Wr0mKLor3GzE=; b=Se+lWPH5ypXFI/HPgSAIGzVAJlLInRHttfLKiHaN3qlNPeXK5WbmTn4qJlI4jKcxsV +CxprREibnpuMZEl2DVow7MSj6NWfIzl4JO82jzjhAtlvxSGCdw0KRSY6GddjBhk8CjS hDPjM0lkrN3IbbNKOOnnETR9OpV5mOhALbOXb9ZzsEWhxoAcD9+B972tUGCUniLyV/os SvL76z0XStnNdb58dEG3o/ZaSANNd9Zm2xwmEkWac0fIg7cmwqAsUXjULSMlO6JUpIK0 EzslRYTSTH2W+gd6nn+EOX8LWQAKjWCXLvMJETu9UepRB3ued2HolyECZcSGFxh3zWzs /rNA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=cF8nLsfP; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=amd.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f8si12625edk.566.2021.06.02.07.09.23; Wed, 02 Jun 2021 07:09:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=cF8nLsfP; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230173AbhFBOJF (ORCPT + 99 others); Wed, 2 Jun 2021 10:09:05 -0400 Received: from mail-mw2nam12on2085.outbound.protection.outlook.com ([40.107.244.85]:36984 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230377AbhFBOHv (ORCPT ); Wed, 2 Jun 2021 10:07:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i/mBHPiurMftLFKfySTyalzs0PEBTKqClLubMhvtohk7hmKjG0c0vFzPqa+gPdBLZp3NJy8NTLwdcu4WMgkbAZjLf//LOpJt9aa5Dq4oZFVh4t54s1jsVRGG7lgTF4RQYC3zzTCXzT5Zf3PNLeeDNhXQAE5Kp+2F+WIgyPaOhYKnSFAoyeI2XHi0eJKTAnBXSamyVpzLE7Oiy+wshyfzpj7fy3qIFAvYQ4US9te7vXbflK4AKX5HpJMwYptnm/i1iDImo8cosxTXtsD/X6weWCqFOXdL7K4/i/jOQ80WhptToXUwg7goksb5DRXtYp6b0KQyudtWuGuLlqdjcLgLCg== 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=iBYwKWM1e2f6h3Bx093S/ZsTxx9S/8/Wr0mKLor3GzE=; b=Yb5f6xVHNfroGTC9sVwdhBb17Ai6u9gqVMF4DweX2sLM4mXEZmoNS8TavY4STJZRiccgyvlAlseUmXkfuJIhp35QMl6+ACEDHY3YLRj18BwM7xpBMUkqNf9EpJ6ZE1wd6jsX5CbwQYMi/+5MO5CLBX1r9Cifmml7iPIIB9av7rMbT0D128+1aBUuHL87is1+MUshcc2O+4+fLLe3yEWFsbZ/+GrSbZXF/OaDc+pHZEJHgiWBoJ/qvPTs9lXy9uuZBKnSiH3ADpnS4RobB7DJXgH/PHjPqQxbg9phYmjjVn5c2zEeYpREZ/Z8cHOTMWfi+d89szUfInX9Mw/6jaOhTg== 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=iBYwKWM1e2f6h3Bx093S/ZsTxx9S/8/Wr0mKLor3GzE=; b=cF8nLsfPWGx/jbtiqAGO2Pbkrs/4xMxo/frF7b/+JCxNz6HDb3k2qVUu1NKprOigiO4GdlyIPTaPz+nXWmFPKYiTiWQXT8QOEXDAsEykqIzxXsxW6Rv5mS6FmHhPMKNGrHrs7Fcn8QOCurxEvYnH1TzJZutuSjLMuUoxiKA8O7E= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SN6PR12MB2766.namprd12.prod.outlook.com (2603:10b6:805:78::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.22; Wed, 2 Jun 2021 14:05:00 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94%6]) with mapi id 15.20.4173.030; Wed, 2 Jun 2021 14:05:00 +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, linux-crypto@vger.kernel.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 , tony.luck@intel.com, npmccallum@redhat.com, Brijesh Singh Subject: [PATCH Part1 RFC v3 13/22] x86/kernel: Validate rom memory before accessing when SEV-SNP is active Date: Wed, 2 Jun 2021 09:04:07 -0500 Message-Id: <20210602140416.23573-14-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210602140416.23573-1-brijesh.singh@amd.com> References: <20210602140416.23573-1-brijesh.singh@amd.com> Content-Type: text/plain X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN6PR05CA0010.namprd05.prod.outlook.com (2603:10b6:805:de::23) 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 SN6PR05CA0010.namprd05.prod.outlook.com (2603:10b6:805:de::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.9 via Frontend Transport; Wed, 2 Jun 2021 14:04:59 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a7bd03a4-6a6b-4711-f548-08d925cf68dc X-MS-TrafficTypeDiagnostic: SN6PR12MB2766: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ts37rTnYNg1nyIuRjqFKaG6HCJPdV5cqH/WSR1o/q0DchoER6eNkcxsvh1CI8/YHukm9urdE0uz7VdINMGRDS+m1Odhs2y/1YshwegpJBXTRxQacX5YBdFPNanVq7MFMSW89oOf1cYUFzHfmDJeDVj0Id+bfd0PhPGyC3NeHhNJcBp2X8MXdTB/4ODlIpgnEYmvd6NPt+ZXkeLSPXn1QsFH1tjM5b2qzJVhFDplkA8jxNAjygVufIYDyVgoagMU6vXYpPwOApyPns+pgsa0QGjHVSYQH/x2yf+HggePx6ahWcTMgk0AKLdrNFeuh2THUr4YhYZDOEMS+o1ItRSMdToOxudyrZ8nfQZqXW5gpWi4iVE9PLuQXXigpnNVRfKxFLxQEvPjmrAIZgf11vM4dV/H2rxk7c/LbsKgAgyJxrjXkrdHMc/EZdxW3Im663/VALLsJWyY8Eer7FLNiYexrORLJVHoSvIPYyuN+STznpGCa80QuOofKYB2Q89TkRh9kpxkY/l2j4q8fKXQehYiRcEXPwvZNN29I17s8h/qJtPUDzHLexwfPyTOFmFuBLNq1jkFBuREJUHAqJhngkJtVsBZfsne+4Kwi9t5DURizHaEBNrNuP73Sq0basQf9SQbP++shjGjbGE/9SBgNMop3cg== 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)(376002)(136003)(346002)(396003)(39860400002)(366004)(6486002)(38350700002)(86362001)(66946007)(38100700002)(44832011)(52116002)(36756003)(8676002)(83380400001)(7416002)(26005)(4326008)(2616005)(1076003)(186003)(956004)(16526019)(2906002)(316002)(54906003)(6666004)(66476007)(15650500001)(478600001)(5660300002)(7696005)(66556008)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?XzlLhSQV+R6HHd1W8+cMp1U2Wm63s6SO//gMAWJYnDHtb8n3uhLGpENnTUaa?= =?us-ascii?Q?mVCrTI6cuZUtAgsAiLPtvHFP2qACmP+4+4EIxnKlNOMGyjv8mGytqJsf0qON?= =?us-ascii?Q?RvkbsIqznNYKAoZDoUs8fPMXwv9mCKPolppK+7WEHNRvuT4R/QaNgql2DBxf?= =?us-ascii?Q?f6/MWsqSqG6u40svy7njiugwXxq+dmc99ubRRka5j8oF2ZgiHK8hDun/Dyfi?= =?us-ascii?Q?86MhAtaI78iJtaVWkpTS428e6eTRcHf8hMxSrCS1fJvthrh2UBzbd1jgd2Oz?= =?us-ascii?Q?Mz7Si2U9/nFluXhml9M4liu68BHu5jZa5tK313GzjvatupxRvmwla5SaHcWi?= =?us-ascii?Q?AQjg+A+ju6UcnDh2om+jF65rnkaK2kULDBaXKZEGwU3VYk7Slnkof/ITyoPH?= =?us-ascii?Q?UwubB+U0sK/7DH2b+sOVfcWjtPKZUHajplr9rfNV90xHNIrebbSw7RnHPbVc?= =?us-ascii?Q?CVc1ron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rossTenant-Network-Message-Id: a7bd03a4-6a6b-4711-f548-08d925cf68dc X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 14:05:00.2212 (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: LoNWDRdWWMdR1Czh7wk0I5F8SAFcC4tHTUDP7mcAfeZmLsTbiMsocUZylB+giNA8Yw2nGQKZBQ5HAc7Ukw/4sA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2766 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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..04b59ee77e42 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), + MEMORY_PRIVATE); + /* video rom */ upper = adapter_rom_resources[0].start; for (start = video_rom_resource.start; start < upper; start += 2048) { -- 2.17.1