From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.60]) by mx.groups.io with SMTP id smtpd.web10.9752.1602346103450810039 for ; Sat, 10 Oct 2020 09:08:23 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=apADjchk; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.244.60, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CwnpRT84W80gBDFj71knxNHSwPbuvTBbu5z6tITnzw4L/Dnz/fYHEdzNwlQyq9baepvSQpXlLyaOKNqtekkPapE+ExjKHIM/+lN1Tw/Xpbtx+81GUAnVKzrY3sZyo1VG+sd12yMZoEDK1MsbBa6pVxvKwIWLeXRRJIAXkPC+vZS2rIKB/DDbGWIa2c45zoacrIAAhjSNEyDq9OwlR6NhLi6iGuTkWrCQ9T8xPGpTvDRAafCGLYjYnJ7m9Wv7vDhz5M6CN2/1L1ts+4V0ywrpqyFL34sHiHh160jSrghlL/8ckPsza+vbGi2M5R9Qpmg/jBC4ZvfhHdjJd6QvEF0qEA== 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=ZWKO99vuI9u6gOfSLlNP9EGF193B7P1aOtRy2IbJtHw=; b=lWvrU++bdeRSjcCL7q/Oy8tAuaw7A443Leq0G2/qTu9uVrrcJdw0cPGi0SA3sFDCXjk+7woYqv7jHccKnOVoBVI+YtjNKA9PzMcb1R3h9egPzRPBoXKM9wEsOb5CER9wVyKr/1xbRsosbnALSnR6cQrYw/Gsg/MJhfkLyZ/U+yVUAiosBcieFhDLxLBaJx0Zdjttf8VYdbtF99BAg4tc7VOpKmq1UpeVoHM+CcPeACOGqoOhLgRpBQlcNQuRNKYyMwg1zQWtTuQXO1i2fg6tiqhqIAMKEQNy+SU61ibqUFhZ1V49pX8yhNCmZp8xtbhQ3xCV4f09+staT1ykSpxdtA== 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=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZWKO99vuI9u6gOfSLlNP9EGF193B7P1aOtRy2IbJtHw=; b=apADjchkNO+mIt2yqNG11M6AMF5o0POzsIw3BzyYJ2OXXRybo3EN6Ti+yyt+7pD8BCt0yEBjyLplE/MqS1++d1IJiFIFzUoXTHes9J0NwDcdO/Je1POWlFRyjljuRiaoi2wIeUYtTjitmiKxLaMyyY1QqsbVNws4c1GJooRGVm8= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR1201MB0122.namprd12.prod.outlook.com (2603:10b6:4:57::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.28; Sat, 10 Oct 2020 16:08:22 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4d88:9239:2419:7348]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4d88:9239:2419:7348%2]) with mapi id 15.20.3455.026; Sat, 10 Oct 2020 16:08:22 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [PATCH 8/9] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Disable interrupts when using GHCB Date: Sat, 10 Oct 2020 11:07:06 -0500 Message-ID: <4f66dc48ae127d8b42313e7a0a8c7cf10667dcb3.1602346027.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR13CA0001.namprd13.prod.outlook.com (2603:10b6:3:23::11) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR13CA0001.namprd13.prod.outlook.com (2603:10b6:3:23::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.11 via Frontend Transport; Sat, 10 Oct 2020 16:08:21 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 30d4158f-7d32-4277-66ca-08d86d36b5c4 X-MS-TrafficTypeDiagnostic: DM5PR1201MB0122: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WwgZc6cJdVNkkzY09+kH564ZpZ6a1lpBtuwQXygVVs4yfHxY6z4+X5ijny+/6Xs2cNIUwRceRu2WpE9efRp2860xeXahhIRkZs3jVp4EdOpS+l2LE3+SoY5WvVVODdeRYMi239KGFaquiFmDZUlTRR9PUvu3AtpocQVooF9ohTmYpsE5A1Cs5w0YZ4WME5vjLFdcNV2rKhiX31SCjxW5ci+yeel9g7dJCnsEYeQT4NCc/pmYnV8wBCmCZjEuUQcmZ4YTZUpSOhHqH0tv1v5BfAfM2o70JTBiJa+1z1i8UhOAY13vFlGypog3LKur7f/QP2UTsKN0Uc1utInQRRbn3GR31etyFTHZWLkI0E7YPoeSaGz7OZh8OyeLVGSCAVPI X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1355.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(39860400002)(396003)(346002)(366004)(376002)(478600001)(4326008)(6916009)(2616005)(956004)(86362001)(26005)(54906003)(66476007)(316002)(8676002)(66946007)(6666004)(66556008)(52116002)(5660300002)(2906002)(83380400001)(36756003)(6486002)(7696005)(16526019)(186003)(8936002)(213903007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: w/tuOOy5hXDjJ9ZLhR9l8ZK8yDdbS8AuzMcOWrjljCZYTaUkFoxohxiIqtEg2wulKDXW4hCB5tS27ckJTPCAtfH+M4LUjVyGT/a3Cth4PsG0JYDzqYh318VLgbeFVvQdrXHsl8i5pygu9LsFfL0MsBv6S9c8q+ffi/cddUfFGgrrP8OebS1TOy9Qw08YuMeDVEtHpQyAKwCR30koknanoS9NQfCrjGj3OWmKnW5ME53QPZ/jyb6Ieszh58W3uON8Ff7b75p2TgfoPV8NOvVp10fGqbX9Hfpd1jsZr3dcinP4VRcs9KNEEMegfHFdX7GR9rDYNjgbhFkEtIqFBhE+RQmAOyfwd2IJHU2R1EFtTzu/sccryQc7+h+JGMoqMphuEw1h4xT9ddNHTTL211cbh6747iNNHGlSewQw7cM6eG+HHT02GRY26WQKzr5ZMI9SapoWfnxu2Gq6iNksLK9NLv65XRr79NP5RBYEWPF4LUlZ89QsEaPa184KKUSyQ6F3Zb2kbDHDPO+rGi1i/Jt/fG8j/C/tmDutJ7ZECkyFI82gpSmBSbs9xn5/bycjeRz8yyRxvxyzPh0sN3rp5hPvd/mJgV5QAElOe44SZ+JQQdby5I+MDawccErkWg3CRHJmrRKzbeiBJQlMsy/eJtkRVw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30d4158f-7d32-4277-66ca-08d86d36b5c4 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2020 16:08:22.0803 (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: Wr7LWy7+1OdlNAe192jUG+rfejUUk7au8p2UpT5mH//dEhdaW0Mk0k2OQ03pzfC93QUo88wmfu4082GZbnehCg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0122 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable From: Tom Lendacky The QemuFlashPtrWrite() flash services runtime uses the GHCB and VmgExit() directly to perform the flash write when running as an SEV-ES guest. If an interrupt arrives between VmgInit() and VmgDone(), the Dr7 read in the interrupt handler will generate a #VC, which can overwrite information in the GHCB that QemuFlashPtrWrite() has set. Prevent this from occurring by disabling interrupts around the usage of the GHCB. Fixes: 437eb3f7a8db ("OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Bypass flash = detection with SEV-ES") Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Tom Lendacky --- OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c b/OvmfPk= g/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c index 5d5a117c48e0..872e58db7cc0 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c @@ -9,6 +9,7 @@ =20 **/ =20 +#include #include #include #include @@ -54,6 +55,7 @@ QemuFlashPtrWrite ( GHCB *Ghcb; UINT32 ScratchIndex; UINT32 ScratchBit; + BOOLEAN InterruptsEnabled; =20 Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); Ghcb =3D Msr.Ghcb; @@ -61,6 +63,15 @@ QemuFlashPtrWrite ( ScratchIndex =3D GhcbSwScratch / 8; ScratchBit =3D GhcbSwScratch & 0x07; =20 + // + // Be sure that an interrupt can't cause a #VC while the GHCB is + // being used. + // + InterruptsEnabled =3D GetInterruptState (); + if (InterruptsEnabled) { + DisableInterrupts (); + } + // // Writing to flash is emulated by the hypervisor through the use of w= rite // protection. This won't work for an SEV-ES guest because the write w= on't @@ -74,6 +85,10 @@ QemuFlashPtrWrite ( Ghcb->SaveArea.ValidBitmap[ScratchIndex] |=3D (1 << ScratchBit); VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, (UINT64) (UINTN) Ptr, 1); VmgDone (Ghcb); + + if (InterruptsEnabled) { + EnableInterrupts (); + } } else { *Ptr =3D Value; } --=20 2.28.0