From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.65]) by mx.groups.io with SMTP id smtpd.web11.5556.1625057663289249484 for ; Wed, 30 Jun 2021 05:54:23 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=0mJS5pel; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.223.65, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jxEv/LBiCVqkTE8HEyHXNH5zjnWt5T0WOpCHRsH8DjSyJRFbQvzpCMZ6stULB+jc4az0PC8mkTQVl9i6i5vMBbxzlty6KQfJDZtlp6xhpXGT2f75HUARkhSIcbcK6ZBki1kMNYU5VMDVuoxtNOAnrv8NxaYYVYNo7fveTutQNjTLTBVn9nNVK9IlLLvkweUGjJpblIAOPwL5FApMur8eLJ7MAFNgGKFlfXS5orxQD9ysY4DdtYlHCPFu263VCTkhFPVMVMOXHbdZ9+j1VvEZCBvfJjS8J23eVTzcWWpyIf2moyuOSSfHQIS/UFghixXobF98nmjWX/5IiOOeYwdevA== 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=oi68z2wD8/2V4B85XwZKA2/OtChrfx6Q/wv17/CWhio=; b=oZQ0jnsscuIrO6HGMNstW/9Pvt5aUynVqdQ1DoItifxxKskSCbyQWQw6+3jQBZFMiVlgUjaIUoTdUbFmlgYmxZlnJvyU16Cie/eZu3j02sFJGM1xbQiZzApOFAxxtohRpUnxxLkJXoIFerIKFAYdGpgtsUa81DsFxqlFkMo7154+rozBLjM2y+r3W8DHCUeClgoEhZntOHeXGa1Xy+l8sknzF778t0kMMnSVRLQPu7hwbTv4DymNxUR2ovAYtu1K1BCqSS4IKkzcYZI/dnt50YITVv/3QcEvgolPRyyvf3BcoPnmBgiZJJXTJsL4nqlm1i7lZMUx8Ykc3A20vL8HaA== 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=oi68z2wD8/2V4B85XwZKA2/OtChrfx6Q/wv17/CWhio=; b=0mJS5pelhmOIAiIuPuuDRc9a4/ti1gBZw+D3Bb6Yjo7QQMxUq48YoL+zsSWFh5HtE178bQ+8Q71ST0atato7caPA+tY6plQjFx0fYRA2Q9Fb8vXYoD6h0eNN4ZG9hO08lSpxBCSXiNBO+HL4xbTCuZq78F7vdliM2U/Gd7ulFP4= 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 DM6PR12MB2714.namprd12.prod.outlook.com (2603:10b6:5:42::18) by DM5PR1201MB0076.namprd12.prod.outlook.com (2603:10b6:4:55::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.20; Wed, 30 Jun 2021 12:54:21 +0000 Received: from DM6PR12MB2714.namprd12.prod.outlook.com ([fe80::7df8:b0cd:fe1b:ae7b]) by DM6PR12MB2714.namprd12.prod.outlook.com ([fe80::7df8:b0cd:fe1b:ae7b%5]) with mapi id 15.20.4264.026; Wed, 30 Jun 2021 12:54:21 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io CC: James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Laszlo Ersek , Erdem Aktas , Eric Dong , Ray Ni , Rahul Kumar , Michael D Kinney , Liming Gao , Zhiguang Liu , Michael Roth , Brijesh Singh Subject: [RFC PATCH v5 14/28] OvmfPkg/AmdSevDxe: do not use extended PCI config space Date: Wed, 30 Jun 2021 07:53:07 -0500 Message-ID: <20210630125321.30278-15-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210630125321.30278-1-brijesh.singh@amd.com> References: <20210630125321.30278-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA9PR13CA0018.namprd13.prod.outlook.com (2603:10b6:806:21::23) To DM6PR12MB2714.namprd12.prod.outlook.com (2603:10b6:5:42::18) Return-Path: brijesh.singh@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SA9PR13CA0018.namprd13.prod.outlook.com (2603:10b6:806:21::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.14 via Frontend Transport; Wed, 30 Jun 2021 12:54:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8425b1b4-fd09-476b-708f-08d93bc62d68 X-MS-TrafficTypeDiagnostic: DM5PR1201MB0076: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:773; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GZS/S5Ztzo0Q8DX99T8ih1n9JAhCqg6qoub/psbxKpyu5o325NlQN7fnvvLJMSGbCTIxD9cnPZaFmhEH0OZUN6Qvf/S4idAkEN1HsF0bWMGeKfEfrL32Dn6/ZTqPwE2LrqHLBAipxecy/rLdzI+Ef1Si3IFnSGgdQzvaa57KL9wVlMobZsY8JcZ4LAMvDlerXXLZ6uflEgKnFLDHBbC8wem8yBTHek4Z1R5kuHrHvZY8jIrYxJhhHhRpDM3ivU/l6+njKDAE3AROgHLXmgnW7XhX7R8Y03kcYDSs44wBG6AdnYTNM8ghNxeCGyTIRQoXaueODurg/lGA54j3WhF6m0w5qBhY+Vi2ZvZCAdlMHSvwd/XA4yUmw0eGxT4wiWak3VqFskST+JfCxIT09doid6Tr392C/U/fHNC4VfmHDIXSSy6ZJ9ZgSCTznY5zuusZY3QDs7yUPHriuV78s1tI1dB2qwEC2yg0ojr2uwktG5wh6iWdmhWK5d5zxtduNoIg9kcy/MAShIebIVDVnRrhAiqPt0P7XjTeYuWvwBp/IwYad3AvaueDOAw1oBI2Wkwf/mUkhVmSyjmbatNlFEBvtd8vKO2MjR3xZFnbijNyp6dX+kqyjY9zRG45C7PLKva/bCE2XustenHjYqBeedQh/KraQPCnwZzHqVXuxhUDtPjRBqjKJSM5lxTEGx/4BuUZvjXKdoQo6Uct9Q0XBWuWfx5CBg+Zvw1RqaWYQB652CXYl/9Vp+jNjLgv2Zea/hYYGD4gapeelFSmB+f7d4J35aCvvCPjtaDwiIPkSeCzS5BwfVlDYGdXFvoegEp3Wojd X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB2714.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(136003)(366004)(346002)(39860400002)(396003)(7696005)(1076003)(8676002)(16526019)(8936002)(6666004)(2616005)(4326008)(956004)(38350700002)(38100700002)(478600001)(186003)(6486002)(19627235002)(66556008)(66476007)(26005)(7416002)(316002)(966005)(86362001)(66946007)(52116002)(36756003)(54906003)(5660300002)(2906002)(6916009)(44832011)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?uKkNsSNwzqVu9buyNXqRE7G3LHrc2C2lzYhDBmp18rCPrFRStc1ShtZ7enK8?= =?us-ascii?Q?Yj6GBl8XoCKr7XFjQYgIhU/amzN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Q?beADhZXlXsMeMJwqowiuzLDzUncjZ2MxLQKxnmLRZMAKqn49uWpogAiY+xFz?= =?us-ascii?Q?FWTthhp74DhuYo305nqID46iHOuhgyxar0OT/OtqV5tDCKbxP9BjBLK7L7Tm?= =?us-ascii?Q?9810irr7kRk10hMjHgBwc1B0ghHbkgs69VNUuWRSyZG7veAgTqiEJaRxAvBp?= =?us-ascii?Q?DNVwy4A7igyfJ2CIfFGsPJfr61zoetRAIx4NeTKGfC+OQXdwlMl5mrNaWhzr?= =?us-ascii?Q?4l7ODENICHTymbep0P4u1cuKjjWnxe8nxj1DecoW0hBduRRhs1yD4+UdoUOZ?= =?us-ascii?Q?zk9PcmCCU9gJbq/BsfdrAihA9/32PDEaVxTj5KV3EYy5isRP3EE4Hcd8KYzF?= =?us-ascii?Q?buBgvedBfa0PSpwA4j2/LlLW?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8425b1b4-fd09-476b-708f-08d93bc62d68 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB2714.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2021 12:54:21.4101 (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: IIph8slbT8rDRJSfF6fTFC66eIORfuTP9j8uA5JAnw8J3xKdYysPUD6bC30Wccf9XVSoqrFUMtrVfwn8kvCwHw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0076 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 Commit 85b8eac59b8c5bd9c7eb9afdb64357ce1aa2e803 added support to ensure that MMIO is only performed against the un-encrypted memory. If MMIO is performed against encrypted memory, a #GP is raised. The AmdSevDxe uses the functions provided by the MemEncryptSevLib to clear the memory encryption mask from the page table. If the MemEncryptSevLib is extended to include VmgExitLib then depedency chain will look like this: OvmfPkg/AmdSevDxe/AmdSevDxe.inf -----> MemEncryptSevLib class -----> "OvmfPkg/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf" instance -----> VmgExitLib class -----> "OvmfPkg/VmgExitLib" instance -----> LocalApicLib class -----> "UefiCpuPkg/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf" instance -----> TimerLib class -----> "OvmfPkg/AcpiTimerLib/DxeAcpiTimerLib.inf" instance -----> PciLib class -----> "OvmfPkg/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf" instance -----> PciExpressLib class -----> "MdePkg/BasePciExpressLib/BasePciExpressLib.inf" instance The LocalApicLib provides a constructor that gets called before the AmdSevDxe can clear the memory encryption mask from the MMIO regions. When running under the Q35 machine type, the call chain looks like this: AcpiTimerLibConstructor () [AcpiTimerLib] PciRead32 () [DxePciLibI440FxQ35] PciExpressRead32 () [PciExpressLib] The PciExpressRead32 () reads the MMIO region. The MMIO regions are not yet mapped un-encrypted, so the check introduced in the commit 85b8eac59b8c5bd9c7eb9afdb64357ce1aa2e803 raises a #GP. The AmdSevDxe driver does not require the access to the extended PCI config space. Accessing a normal PCI config space, via IO port should be sufficent. Use the module-scope override to make the AmdSevDxe use the BasePciLib instead of BasePciExpressLib so that PciRead32 () uses the IO ports instead of the extended config space. Cc: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Erdem Aktas Suggested-by: Laszlo Ersek Signed-off-by: Brijesh Singh --- OvmfPkg/AmdSev/AmdSevX64.dsc | 5 ++++- OvmfPkg/Bhyve/BhyveX64.dsc | 5 ++++- OvmfPkg/OvmfPkgIa32X64.dsc | 5 ++++- OvmfPkg/OvmfPkgX64.dsc | 5 ++++- OvmfPkg/OvmfXen.dsc | 5 ++++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index 1d487befae08..f1cf2e916a10 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -807,7 +807,10 @@ [Components] !endif =20 OvmfPkg/PlatformDxe/Platform.inf - OvmfPkg/AmdSevDxe/AmdSevDxe.inf + OvmfPkg/AmdSevDxe/AmdSevDxe.inf { + + PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf + } OvmfPkg/IoMmuDxe/IoMmuDxe.inf =20 # diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc index cbf896e89bd2..75d4b196057f 100644 --- a/OvmfPkg/Bhyve/BhyveX64.dsc +++ b/OvmfPkg/Bhyve/BhyveX64.dsc @@ -779,7 +779,10 @@ [Components] !endif =20 OvmfPkg/PlatformDxe/Platform.inf - OvmfPkg/AmdSevDxe/AmdSevDxe.inf + OvmfPkg/AmdSevDxe/AmdSevDxe.inf { + + PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf + } OvmfPkg/IoMmuDxe/IoMmuDxe.inf =20 =20 diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index b3662e17f256..783622c61ac5 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -960,7 +960,10 @@ [Components.X64] !endif =20 OvmfPkg/PlatformDxe/Platform.inf - OvmfPkg/AmdSevDxe/AmdSevDxe.inf + OvmfPkg/AmdSevDxe/AmdSevDxe.inf { + + PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf + } OvmfPkg/IoMmuDxe/IoMmuDxe.inf =20 !if $(SMM_REQUIRE) =3D=3D TRUE diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 0a237a905866..f2b13f7228a1 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -958,7 +958,10 @@ [Components] !endif =20 OvmfPkg/PlatformDxe/Platform.inf - OvmfPkg/AmdSevDxe/AmdSevDxe.inf + OvmfPkg/AmdSevDxe/AmdSevDxe.inf { + + PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf + } OvmfPkg/IoMmuDxe/IoMmuDxe.inf =20 !if $(SMM_REQUIRE) =3D=3D TRUE diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 3c1ca6bfd493..d9619ac5a050 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -725,7 +725,10 @@ [Components] } =20 OvmfPkg/PlatformDxe/Platform.inf - OvmfPkg/AmdSevDxe/AmdSevDxe.inf + OvmfPkg/AmdSevDxe/AmdSevDxe.inf { + + PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf + } OvmfPkg/IoMmuDxe/IoMmuDxe.inf =20 # --=20 2.17.1