From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.72]) by mx.groups.io with SMTP id smtpd.web11.853.1631557208943823305 for ; Mon, 13 Sep 2021 11:20:09 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=RC5Ha7ba; 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.94.72, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QqxkDJ2KTaMcmLhz+5NT9aLGqr1JTkHREQ4/OTX9xqKOOXk1mjpUHJQrm35P4g2mkWCZNvNaKVOcoXD0b4oNBNWmaWa2tI1QK33baoC0rJFXdeZfH68on0sOcprWXoxNoHwl5S0xWYawot95Wh2vCVNILHkxTbtbDIZYiG2ZRuTCJdNnXJ1AEvUWZMTssJ13ky+M6ONgVQAYLq3gV7rSf+qhj5xFi2bpqmm6Fk9q654t36txzBAwjOm75aVd1bxpix5ZX53PdZwwAt8Hw6PrCyNtFsXwHTghh0AX8sih05rhllbXiUC5PTvTOdI0n+v6pcj1vsQtEVcxuF+LRsqlcg== 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; bh=OHUYwx2IGUCMbeJ0lSKnbxGJF9o8MgnUZh5wqz+qDBo=; b=PBqaP67fMSPnP435Hv3fd91JwGtFf3HQdj0PGkIAqvcu34tGTRxdAhUvpyEnkzRw+wMWOUEdV5NWR3Y6uGixl2C+3VtRqsHJmz2QK28MhjeUuIyJdGad0KCDVpZe8QzhhNYHJcvseKELwyu9u6X5CKRURCurY72fHrlu21XxEnhz6aOtRmYXh1sjFf/aA0rmC5ygPyme7VFGxOY++PZvIwWCd8RyaWl10GRz//dbVOODt7nF+Mk1itSyFcuGoxXr2UQz4OmR1QtSGt/XoH7TkDJl4Nz9E3bMizXJaaAWdem79s0buHsRoPwItfryoRaquTVvD8iaYpKPhkivMTlyOg== 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=OHUYwx2IGUCMbeJ0lSKnbxGJF9o8MgnUZh5wqz+qDBo=; b=RC5Ha7baW/ce9xDLVYHWUeY/TOLdyAqrAjhxGSKt83EV5a8gbaFVFdA14ko4TGLL+GVu+8iFAc8EZVmSxvdzsDuQEVs+xUnKYHDbbjoIhqjIFd/Pe/bg2U1kL99KrDVcvYjOm3LZxB8ABKLLGkiPX1/pokRZELYbYqhxH722g6Y= 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 SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SN1PR12MB2512.namprd12.prod.outlook.com (2603:10b6:802:31::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Mon, 13 Sep 2021 18:20: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.4500.019; Mon, 13 Sep 2021 18:20:08 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io CC: James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Erdem Aktas , Michael Roth , Gerd Hoffmann , Brijesh Singh , Michael Roth Subject: [PATCH v7 12/31] OvmfPkg/AmdSevDxe: do not use extended PCI config space Date: Mon, 13 Sep 2021 13:19:22 -0500 Message-ID: <20210913181941.23405-13-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210913181941.23405-1-brijesh.singh@amd.com> References: <20210913181941.23405-1-brijesh.singh@amd.com> X-ClientProxiedBy: SA9P221CA0012.NAMP221.PROD.OUTLOOK.COM (2603:10b6:806:25::17) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) Return-Path: brijesh.singh@amd.com MIME-Version: 1.0 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SA9P221CA0012.NAMP221.PROD.OUTLOOK.COM (2603:10b6:806:25::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 18:20:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a23250d9-d237-48f0-4502-08d976e31dd2 X-MS-TrafficTypeDiagnostic: SN1PR12MB2512: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:773; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fgRN4Koww0pTwdPsh8OyW34xP8SUExyTj6/rUsBRRClgfERo3sBIQFxyOKIzmYJlc4bkHhx8kix2D5RAfsGYb6pJjVnWhor1aEAr0Pmbez+tV+pOMcH+bhuBXMiJfER8ZE+j4cmuE5cWGZVQOb1C9eO9gWwjQ6i2kFE3ri5IrkM0y1GPSdhCpFs5gJcsWWvOqwlOYZLdzUAge15rqtxDXnjw0ZAkbAaT+e5POqQwaZYs/CULRVrFt1vuonp/UKWoXdag5UbyyHYm2qKEvmvCZKl5CaD/EB1MN4ggrt857vY1psFfEiHaWWYB24wxAPpe9y1hTCS6D08XrXvPgvQqocP6ac51glPjx0LOHeOOsalsvJdf+FKg2hIygtms34mWTOH/LvphvIXJ1GJK5dICv3XjFS/B1mjiCm9KqWt1iJk5xpE6aqAMYYJNpTJdqJoWuOLWhK4W34/2B2qJOd8Tl0YdDjaSiuU2pXkdJJ/bkc+ygyVUJx/LPhgx8uhSY6rS9g6dV8JUP5Rqi6y9jPsWL1InCM27fD9gZvF4m0cP5eedRG45Kz596SnTc0B1zdZSWt/QnPaHqI4aB8STqqb3Cc4LqfCC0PnsD+bctgyMYbVGeEyJq7sl7j4q6w7vBZwMM/cg5ojjWQPA7pApKpRHgv3ImmWD+MO+PSN3HJ7xh+WfFkbXMeh+k46+QfNv2EtTyEKbAgxoJ+Pmc8suiLGo2+VIhzMVQHoGqkR6JinHenK3LYJhG7hO39Qn25WGzn40h7mZUaFe5lCdoO46wXSi2Ce3asOJiVUJUaOMXOkzeVU= 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)(396003)(346002)(39860400002)(366004)(376002)(136003)(83380400001)(478600001)(86362001)(8936002)(966005)(6486002)(8676002)(186003)(6916009)(2906002)(38350700002)(38100700002)(26005)(36756003)(19627235002)(956004)(2616005)(66946007)(6666004)(66556008)(54906003)(5660300002)(52116002)(44832011)(66476007)(316002)(4326008)(1076003)(7696005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?FLg1qb7bacM6uIWziHskwcxLjtb8gGEPfWwBAc9ptweLeFr7nsR6avYd48C1?= =?us-ascii?Q?eJNQIKDgs7NsHG/QVAMGY8U00v6VyEPw+Lwfy6WGZQVRLkuArlP+/Sr1qOnz?= =?us-ascii?Q?UAvHDv0tTevkmILGFuc1WkOPGMP6is2eN/8edKflbFXQCwKpUWw8kA3LevjG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4EKlwuElojAvp9I7Gat/jm7eFKdbS?= =?us-ascii?Q?2Bv4gtGB8Aexjsm83u1gkuUgbcnVSVFQL5CTjT+U9qCUW1oJ0k9cumIl/XwZ?= =?us-ascii?Q?dLV01U+9YJpRrGGrdjk9mPB3HMbH2qA8fdGVHk2zBThfn8gpqXAKy7rDmYu1?= =?us-ascii?Q?liG1aeRRDSPFrbz0Pm97KcRO6kviUoSVmySIrf24iod/xHjbXd8VO5CBmKFG?= =?us-ascii?Q?g7kQOa3I6nqQb/fVZWtXZ/UMGFkMAf0WoxLie23hglCv3j4URVpydYOvpNrU?= =?us-ascii?Q?zHi3qjm4kgX2mXMXowI1l16I?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a23250d9-d237-48f0-4502-08d976e31dd2 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 18:20:08.1338 (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: ii8GBzeNucX+ujXpXN8Sm1ZJW0KzhmpXFgeY+hZnwmKwC7hPjnmeB6cwUwYf6h7o+AoApjr5kacXt+LZ3oHLEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2512 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: Michael Roth Cc: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Erdem Aktas Cc: Gerd Hoffmann Acked-by: Jiewen Yao 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 e6cd10b75922..a8ea08a10a99 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -812,7 +812,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 d8fe607d1cf7..f45634996247 100644 --- a/OvmfPkg/Bhyve/BhyveX64.dsc +++ b/OvmfPkg/Bhyve/BhyveX64.dsc @@ -790,7 +790,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 a467ab7090fb..f42abc041c0c 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -965,7 +965,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 e56b83d95e09..19cc5d4122e2 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -963,7 +963,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 a31519e356b7..383cb03d2a14 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -729,7 +729,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