From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (NAM04-DM6-obe.outbound.protection.outlook.com [40.107.102.54]) by mx.groups.io with SMTP id smtpd.web08.27.1616599961841997394 for ; Wed, 24 Mar 2021 08:32:42 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=F4ilhuOD; 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.102.54, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tcr+7EVsY3JgJ7Ovaf7pkyPEHd7ER8ywXJaICXyP4jTTfREBRP4hzUMZ+K5nzrs0I6GlPMDBjHjW2lctrIB6ea+QADYfV7ok7amK4PzybAQ52Gs1IZf004VScdfyPTs5Ht904PET+k4wkFp7ETwEsJkypB2SN1WXdZnEPmViWHuLLAbdcN1qKuqzmU98TTUbfXdOUXgutQuPdbk2taGcIkaPXOO+AyV7nhsnWNr91Dp+w3SjAi0jVeh9nIQy2yXuaGRZC/ocfqyM569RCNJRcjG7UVu5M5NF1WOtOdPYEWRvbS4XJdSydfW8Za3m/rGGqzvLB15zvpGpEl2a1BsXBA== 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=6hOTdSZ1k1P37ocmxWGsaa/nh8MmFoauyPep6DozYkI=; b=bUQSVQkmICLgKkB95+quogryGpb8HPpTATLzFMmX431jHON3xsE03kWuaFlk8O4nA00xwVCdCMPSeINWNYWoJMebMwOeCBhmVTlh0lkVpU3heeZz5WsPTRtz7+pTjCtqJ8F82fAKe/0wV8MHrehQ/hYi95ettsN+Yk9nMhMmLkQWBP+XYzLAZfQ8C1jahjbNLt244FE6N9Eufjf6SYAEeSCnDOHreVFqQH5xnhIXjdO9dwY1/ld6/PVyDwXrv8B0z06/S4bX9GndXO2R/6sPZnPzUWdnzoWrf++m8oWzUh8lv51ZzVaAfs1q6dCTpp6i1tAbajSeFFB/gwQq2kRCGg== 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=6hOTdSZ1k1P37ocmxWGsaa/nh8MmFoauyPep6DozYkI=; b=F4ilhuODyETHh36SqpHWRCHs36ixsWcwn6jUlEnpsoqL1qQmeakUMAJpJSsrOskltYmWU3u7w0XYx9u1vPfI7muhjYxG3Bp1Mp0xH/jKn6hB1DzpnTEJaCbow6oe8rs/3rUI8+kvT/GEeGIa20g2IUjDZ99GPD9w19C9gcxY3gM= 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 SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Wed, 24 Mar 2021 15:32:40 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::30fb:2d6c:a0bf:2f1d]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::30fb:2d6c:a0bf:2f1d%3]) with mapi id 15.20.3955.027; Wed, 24 Mar 2021 15:32:40 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io Cc: Brijesh Singh , James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Laszlo Ersek Subject: [RFC PATCH 17/19] OvmfPkg/VmgExitLib: Allow PMBASE register access in Dxe phase Date: Wed, 24 Mar 2021 10:32:13 -0500 Message-Id: <20210324153215.17971-18-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210324153215.17971-1-brijesh.singh@amd.com> References: <20210324153215.17971-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA9PR11CA0006.namprd11.prod.outlook.com (2603:10b6:806:6e::11) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) 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 SA9PR11CA0006.namprd11.prod.outlook.com (2603:10b6:806:6e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18 via Frontend Transport; Wed, 24 Mar 2021 15:32:39 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 100c0940-06c4-4b3b-c6c9-08d8eeda0f40 X-MS-TrafficTypeDiagnostic: SA0PR12MB4430: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: T+uMCUYnddDrVGtSaAsrwyKi7kecKwUZirhelANJIhlkI9lqr7N9F2gCGbnsTHhX8GkDLnfpFpJb3AFHUuLz3ZX5j50l8DIJWYWqQNocECmyRP2nJpG5NAfzIS0Ex549sp2iY9iSepoDqnvZVE08LjcGDQ95jxjneeU4Vj0XWC3TMLdRdxFxUY6kSgbeS9ZhE1DqXzlT1s23l5lmV7tcXRI+pFrWPzDHAb4vmrkGtqgBttfs7CWuYub5cPpPA1KE9PAWAhHWQJMjdoFtmqXx7+bOkPRIWtaSHUXJKDMVgrCWLdpKlu192qEYO8gqaEkqvzV0hqCsQPGeULQsYdLHMRCSVz47u2oqAEZZL9+lCB2z/wkezX5GLuIKIHeGl9jg5qJC2Oc3oHK7CzIqcrfiTJC6zYQ/opkgf6EjslK7vsXwHaVTgfZdZ14/+bcZ07x8efSdVXE2n/Wzc7cH0f9thqfuVJbjjavwuPhvz60BH6v7OxXmkDnMsw42+9k8ymAUE6Fmyc08TVpdo6GT7We5LxvlQCcjHNlmUOIrRdNW/baP5coq7/0F1IF4WYzFXcb+QFSlIpa5+3KjUbESm7WDtjyBGB+8CzT729O5QVz+rT0cpR60OrcyxWoW04bIr4zcTc5tYFT03OFgRmfZmwSY5X4vv6Bb4eIYt25T31+a1Z6/jU4kkasc/3r7mkUPdqkZcZ4rnijnK+7CYD0kvXbF/ulwOuDndbG8k26EBmjoICU= 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)(366004)(39860400002)(136003)(376002)(346002)(396003)(2616005)(83380400001)(66476007)(4326008)(44832011)(1076003)(6486002)(2906002)(86362001)(66946007)(478600001)(316002)(66556008)(966005)(16526019)(6666004)(26005)(54906003)(6916009)(186003)(5660300002)(8676002)(7696005)(956004)(8936002)(38100700001)(36756003)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?g1DNswFTZTs46qGriGwhdAYrH3TfqAf2J3kHZaf/3qBxThRbvrwKPA1Ji3Cf?= =?us-ascii?Q?U0/Rx1slB55e6E3KxF43HchV/6rqsnBd2kVmV7SJoMm1gjlYbY68dmoIuJ4i?= =?us-ascii?Q?+J0LLyeTZawr8NmZY4e15pvUkzt5jhKDQ0DN6fZQR7Iai4qyVk25Em//f6Ib?= =?us-ascii?Q?b22c9panzt3KhDe1bPROEuj8Q4LuaE5B9zujEFqdkuPwAnOvfHQtciDOrcpC?= =?us-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2hhjFu6ZRZLFsS6abmnZKl?= =?us-ascii?Q?gzK+qd1WvBimOp/S5TSmxtcxM7l6raYuWAau96uY5+Kw/ZQWuuwd4PXH6H+/?= =?us-ascii?Q?4HTNRNO+dTpwqs05eswMnkX5PD+Q5Ce33WXi1zrZtmtqcmcqKup8fdNvc9MM?= =?us-ascii?Q?+lwLUIWEXI7qOYV2q3jBYdB3sPv00AFqf5WRYEDF/ONW2FJlCyFTHcJLlhBk?= =?us-ascii?Q?ZEnGmA1hJ5kQMBmfcodR3OPq?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 100c0940-06c4-4b3b-c6c9-08d8eeda0f40 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2021 15:32:40.0199 (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: 4nVbtd56GjyBnD8HuB7SWueNdUIsmbft9ru8NP2Q0enXg9R+AaXj5HgUJ08Qq88QHNz4J62ehw2SACUaK57cEw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4430 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3275 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 VmgExitLib library depends on ApicTimerLib to get the APIC base address so that it can exclude the APIC range from the un-encrypted check. The OvmfPkg provides ApicTimerLib for the DXE phase. The constructor AcpiTimerLibConstructor() used in the ApicTimerLib uses the PciRead to get the PMBASE register. The PciRead() will cause an MMIO access. The AmdSevDxe driver clears the memory encryption attribute from the MMIO ranges. However, if VmgExitLib is linked to AmdSevDxe driver then the AcpiTimerLibConstructor() will be called before AmdSevDxe driver can clear the encryption attributes for the MMIO regions. Exclude the PMBASE register from the encrypted check so that we can link VmgExitLib to the MemEncryptSevLib; which gets linked to AmdSevDxe driver. Cc: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Laszlo Ersek Signed-off-by: Brijesh Singh --- OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf | 4 ++ OvmfPkg/Library/VmgExitLib/VmgExitLib.inf | 7 +++ OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 45 ++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf b/OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf index e6f6ea7972..22435a0590 100644 --- a/OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf +++ b/OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf @@ -27,6 +27,7 @@ SecVmgExitVcHandler.c [Packages] + MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec UefiCpuPkg/UefiCpuPkg.dec @@ -42,4 +43,7 @@ [FixedPcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupSize + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf b/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf index c66c68726c..d3175c260e 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf +++ b/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf @@ -27,6 +27,7 @@ PeiDxeVmgExitVcHandler.c [Packages] + MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec UefiCpuPkg/UefiCpuPkg.dec @@ -37,4 +38,10 @@ DebugLib LocalApicLib MemEncryptSevLib + PcdLib +[FixedPcd] + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress + +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c index 24259060fd..01ac5d8c19 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -14,7 +14,10 @@ #include #include #include +#include +#include #include +#include #include "VmgExitVcHandler.h" @@ -596,6 +599,40 @@ UnsupportedExit ( return Status; } +STATIC +BOOLEAN +IsPmbaBaseAddress ( + IN UINTN Address + ) +{ + UINT16 HostBridgeDevId; + UINTN Pmba; + + // + // Query Host Bridge DID to determine platform type + // + HostBridgeDevId = PcdGet16 (PcdOvmfHostBridgePciDevId); + switch (HostBridgeDevId) { + case INTEL_82441_DEVICE_ID: + Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA); + break; + case INTEL_Q35_MCH_DEVICE_ID: + Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE); + // + // Add the MMCONFIG base address to get the Pmba base access address + // + Pmba += FixedPcdGet64 (PcdPciExpressBaseAddress); + break; + default: + return FALSE; + } + + // Round up the offset to page size + Pmba = Pmba & ~(SIZE_4KB - 1); + + return (Address == Pmba); +} + /** Validate that the MMIO memory access is not to encrypted memory. @@ -640,6 +677,14 @@ ValidateMmioMemory ( return 0; } + // + // Allow PMBASE accesses (which will have the encryption bit set before + // AmdSevDxe runs in the DXE phase) + // + if (IsPmbaBaseAddress (Address)) { + return 0; + } + // // Any state other than unencrypted is an error, issue a #GP. // -- 2.17.1