From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2001C4332F for ; Wed, 9 Feb 2022 18:12:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 569C98D0012; Wed, 9 Feb 2022 13:12:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F4BB8D0011; Wed, 9 Feb 2022 13:12:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F67E8D0012; Wed, 9 Feb 2022 13:12:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0056.hostedemail.com [216.40.44.56]) by kanga.kvack.org (Postfix) with ESMTP id 1163F8D0011 for ; Wed, 9 Feb 2022 13:12:06 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C8033951B2 for ; Wed, 9 Feb 2022 18:12:05 +0000 (UTC) X-FDA: 79124035410.19.22C16CC Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2088.outbound.protection.outlook.com [40.107.220.88]) by imf11.hostedemail.com (Postfix) with ESMTP id 19C9540008 for ; Wed, 9 Feb 2022 18:12:04 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M9L4f93W1Lr6t41eAHB6eeltgkIyN6jARUluK0rZvW2ymXX3ZdM/+5g/REkIrRVxma4U4UXkxwyEOPNAWadVvAw6ku0x1Wb5e/P81gJJwdW6kyIE5tXLtuUQD4bnLDMwbAQET8Y3WWzKgPeOMcTMf8tpfqXuXOaXhfe6X05yGbxilQT5p66mUIZnwxZasFx9pjtJo5/h3G2rNHZr5c7AO1tRZdxIS2XIudVkS49slLLjaIJ2DKJ5v7TaxR4RUghJumCnST67WvcGRy0deS1frZGLlPphoyyE6uHjCJCDtJ5GQKDIbh7U5ISx9FSVsyIZc8zccHNGgXX5x1v29iC4bw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VIl7FGcVVCCTXlpIwuSotWlAhVTgllnaxmtLpaZNBXA=; b=Y8CsYF+Eax0u2wek3OhgenyePE61X073kl7OegsJfqu8EDsp7M5e/65nrAQ5bHVy6s2HpyxbQF8/zv3id51DYPKZx7JB3KIqCEv/8LXINodrnwAgvH4EDmXMDOFj+sNWX515J18ND65Oi60s7dqgtsOvqS/EsSungbylSxmx7bfuj7TcCB2OQKtotdDchzyldjfP0DCmrhBnBlD+JSuajhEfzs7nhOJz65rBUmFyi2KKR2Sj2bMR6phP7xc9ouyvqGcUzxYL/SBD57kxALV8dU8hTH67LTOhKkvd75xsazIU5fjoC9+wsgmNmb8lLX+no8xxMRVayN1mChMvwDo+1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=VIl7FGcVVCCTXlpIwuSotWlAhVTgllnaxmtLpaZNBXA=; b=R+jVo3ALIn/L7dd5ZYvb+Uy3wRB1lkkJyvnwFzI9ZotMklSQ5zAj87cnG8gJhStJ8gCBUF0uu+3RJEltw+p/L87/mLAJR49G1cpq8cn3jheyupaF7OL0V3LNNaMrYnRAaat9M1B5pzti66vZAFlTyG791gIzASfp2I1spGzi5NI= Received: from BN9PR03CA0879.namprd03.prod.outlook.com (2603:10b6:408:13c::14) by BN6PR12MB1714.namprd12.prod.outlook.com (2603:10b6:404:107::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Wed, 9 Feb 2022 18:12:01 +0000 Received: from BN8NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13c:cafe::f3) by BN9PR03CA0879.outlook.office365.com (2603:10b6:408:13c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Wed, 9 Feb 2022 18:12:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT063.mail.protection.outlook.com (10.13.177.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4975.11 via Frontend Transport; Wed, 9 Feb 2022 18:12:01 +0000 Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Wed, 9 Feb 2022 12:11:59 -0600 From: Brijesh Singh To: , , , , , , CC: Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , "Vitaly Kuznetsov" , 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 , "Dr . David Alan Gilbert" , , , , , Brijesh Singh Subject: [PATCH v10 20/45] x86/kernel: Validate ROM memory before accessing when SEV-SNP is active Date: Wed, 9 Feb 2022 12:10:14 -0600 Message-ID: <20220209181039.1262882-21-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220209181039.1262882-1-brijesh.singh@amd.com> References: <20220209181039.1262882-1-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: aa8666a5-2d40-4025-f6ef-08d9ebf7ab9b X-MS-TrafficTypeDiagnostic: BN6PR12MB1714:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qFmNfXI+RYNFSi6ieWqt+YW+CVt5BPGoH45CoW09l8Ppm8WZN7SDvBZJHN4PJUL0+YZoSwtN3imMaxlaG7xsYCgGYRo0KlHPYDAfuz00TLVAmbiVljtyWfMAU5CrpZYOGIfudScN8jxw08fTOVDW+YdLpuq4nYPzJ+VJuzdqf9RatJ8Xapu+KhMgEjjszHTzcEBISCbTGzMoDWUZS7wjVHwmpfNUY6whlsN70023c8o/o72VE0XqlS4JeJRpqjoHZ1QZLNww/Jt1nhBIu4XTGBOA7LqFWSMS1fCDAJnOLBoivifqiUeZNIuCtzY7kOb2l3+jN7Us8pxseYqDA1fBzZwlwoFVhBJ7lcrPRRtl22zfFT1sKvUSVanztSfaI4zf+jQE+z1yU9FwkfwI7qjjjTBc4E7/nU/1DhGC1DKTjqiIAmYovJ5MytocOPpqwXswv48yn5T742iFuIdo73PJcUBMZcjh7qaO9hyYnLP9I7hugYqyew/PNdpa0K394ktR5YwJ0OwQtjU9oX1p15vevawl7mxdk7d4pMORs1QrN07qFR9SAaLhNvU2/wxtqL2o3UqG1QMKzWVosF+iIFsZarSuwEteJSxw9hYuG70jZryp213DNja8cAdcTXWIyiYqBLPP6pX7eZXCGlhLrzGU18gzhH4tLAKC4DQ7KluL9IV5Jt0OIPaPQ4Bagv2g3OLxobllzdLyBfo7wvZSecwgr3fUiQxlcm/9Tqt3e//K5Ok= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(81166007)(36860700001)(426003)(1076003)(356005)(2616005)(16526019)(186003)(26005)(83380400001)(47076005)(40460700003)(336012)(82310400004)(110136005)(508600001)(70586007)(54906003)(8936002)(7696005)(6666004)(15650500001)(2906002)(7406005)(5660300002)(44832011)(36756003)(7416002)(8676002)(86362001)(70206006)(4326008)(316002)(2101003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2022 18:12:01.7116 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aa8666a5-2d40-4025-f6ef-08d9ebf7ab9b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT063.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1714 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=R+jVo3AL; spf=pass (imf11.hostedemail.com: domain of brijesh.singh@amd.com designates 40.107.220.88 as permitted sender) smtp.mailfrom=brijesh.singh@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Stat-Signature: 3yzpgec7q3mm76so5p6acqzy9tqna5wp X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 19C9540008 X-Rspam-User: X-HE-Tag: 1644430324-840183 Content-Transfer-Encoding: quoted-printable 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: probe_roms() accesses 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 36e84d904260..319fef37d9dc 100644 --- a/arch/x86/kernel/probe_roms.c +++ b/arch/x86/kernel/probe_roms.c @@ -21,6 +21,7 @@ #include #include #include +#include =20 static struct resource system_rom_resource =3D { .name =3D "System ROM", @@ -197,11 +198,21 @@ static int __init romchecksum(const unsigned char *= rom, unsigned long length) =20 void __init probe_roms(void) { - const unsigned char *rom; unsigned long start, length, upper; + const unsigned char *rom; unsigned char c; int i; =20 + /* + * The ROM memory range is not part of the e820 table and is therefore = not + * pre-validated by BIOS. The kernel page table maps the ROM region as = encrypted + * memory, and SNP requires encrypted memory to be validated before acc= ess. + * Do that here. + */ + snp_prep_memory(video_rom_resource.start, + ((system_rom_resource.end + 1) - video_rom_resource.start), + SNP_PAGE_STATE_PRIVATE); + /* video rom */ upper =3D adapter_rom_resources[0].start; for (start =3D video_rom_resource.start; start < upper; start +=3D 2048= ) { --=20 2.25.1