From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.68]) by mx.groups.io with SMTP id smtpd.web10.15345.1634672420644037838 for ; Tue, 19 Oct 2021 12:40:20 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=xvuc/o5Z; 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.93.68, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J04lxf2HIY5ungxINyXrV2aRvV2eCUCHbtYYZqcmxF/ttLtjVbWOc4tDmveAsFNCDvzWa7fQGfYLNk0rxe8ygXBOW+Msk9PCSCLjlRXQTWmggj+UFaYp1W2P1dmBr4GePL9Esr8yKy+i+SMgovQ7hZyfwYJY6FX5vpfK5cnkjJAavOe96QGMWIpfGjnwLLueUOioRnY1w1FjE+n9WIcx2eRXmOhBXtSMcI5FrnLTfGd4xhKBkjdS5aUMv49mjahoXN9hVPcamGT9LU/Mpwp62WjfCJP+vnLjRHggMP8E1pml5cgxsWf5CCkZubd+c7+DEJrSkXYmISwV+L+4e2Gqyw== 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=oMctcOtIeTQj92ywG7bJsh7OcgCIv1l6OfNWVL8ygi8=; b=O39i1HgHOjOFAe7Qz9vjGwjDu1N5e95XuXSCRJnndgMEtO8+RbF5Nuf7miNR+5Wsvcw6OZG9H5aOin+Dopv6UJ2wVnzJz4vDBH1RCmeKZbS8J6p1Y1YBi2lzFijFK890HH73nhLU3AbPnOP2DF5BMYWSR7/6lhExlewfYCpN1PUj9BDe/6PXBZbiRHL69mu5oQr7aeDv12bu4D4VEyqCqgFXEkOH3Sb4vMh0a3AQT1m7RDD/Ybb7cugl0jG8qf5z1b4spD/SffwDaw5fznhirZSRqugWtXuwPgm6l9IDVk4Q6bc5+d1SfVONjuwg+qrf7WMSOr/PBuanVaXc8g972w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io 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=oMctcOtIeTQj92ywG7bJsh7OcgCIv1l6OfNWVL8ygi8=; b=xvuc/o5Z4Zosy87Iq6CjOzQ9Exu9CyPtAR/2u5f9WlKEH0QKf+1OssQikDGxA+IY0sOdtCceuJSMsyYy7EstMb1UkgcWM3RQP+qxZRykcxXO9iEkHmXkj+1Pzpb3k48JI1qqSQVNDvkYenzn6wJUIVEuOivxHA15yll5/OVucfU= Received: from MWHPR02CA0006.namprd02.prod.outlook.com (2603:10b6:300:4b::16) by CY4PR1201MB0245.namprd12.prod.outlook.com (2603:10b6:910:1e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.18; Tue, 19 Oct 2021 19:40:18 +0000 Received: from CO1NAM11FT054.eop-nam11.prod.protection.outlook.com (2603:10b6:300:4b:cafe::f6) by MWHPR02CA0006.outlook.office365.com (2603:10b6:300:4b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 via Frontend Transport; Tue, 19 Oct 2021 19:40:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; 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 CO1NAM11FT054.mail.protection.outlook.com (10.13.174.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Tue, 19 Oct 2021 19:40:17 +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.2308.15; Tue, 19 Oct 2021 14:40:13 -0500 From: "Brijesh Singh" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [PATCH v10 29/32] OvmfPkg/MemEncryptSevLib: skip page state change for Mmio address Date: Tue, 19 Oct 2021 14:39:31 -0500 Message-ID: <20211019193934.1052465-30-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211019193934.1052465-1-brijesh.singh@amd.com> References: <20211019193934.1052465-1-brijesh.singh@amd.com> MIME-Version: 1.0 Return-Path: brijesh.singh@amd.com 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: fe9d4fbe-f342-47ba-f80d-08d9933847c8 X-MS-TrafficTypeDiagnostic: CY4PR1201MB0245: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X2bm9mrJOjiK1UXrrIVc9Ujd8T1+uGQdCo5h7nJjKL9e9LtgHq/ZIzRalLvJ24lku7FvMjEUwwkDOVqrr2m9c2O79+vkDzRswyOnMyoIG708wlfcABdIkw42bFy2+q+xWKtzXmxV+Emh9Wha7LTuUBYEZ53QXZLbers5S+XQBfcKoNzFiSUfdCF99GD7qwwAhfbkJ/gcYxl+XvUZYJAVMhTw93NubW+DXkNxM+7JbUXbJPPv4vUmMs5EsJ3OYDghHfaHrDUGPZjl3DXXP+lSoKIwzKtNYS2OHTEkU1Vgd6Kt6R/4EAOxbOrC4zLvVwnrqhQuAoQxcm71jY0d3SxdfVLpoK8Yo414JwgT9ydvBXqVX4tChASGQTlRIc9EIlT1h9tYBVegoedHPrlcacZfOyCG8SqOlqYQPAMV5f1Y8KHYCSjoJAu3GxWxCdwQWSX/bY7wIYtfqkQwa9UZuvsKnGmPpqM7qxaj4Xo70t7yefQCRmldnZKBttutI8aJTiYJDqV/1I5fRvn0o9kOabo8HobGeDfRcOgiOrfT2zhSfwaGH5iU0k48bq3ZBA7tQ4n3nkv9rzmQIX7PVu0jsfPMlKJBQjAXaqoSVPiQ84s6hg1fa+HXGEcEoNkdFHMybX5I4DRyo2RcLTuMitSlXTwAWgHjeJIa7Br1GYKQRJ/palGKGbwdIf8lLkY0VqkJTFpgAfXZ6bf2Bmg2qN1sexnGKs+C15Iq+98cv6kN6sQmqfM= 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:(4636009)(46966006)(36840700001)(2616005)(83380400001)(426003)(44832011)(7696005)(19627235002)(508600001)(36756003)(16526019)(4326008)(2906002)(316002)(5660300002)(36860700001)(186003)(6916009)(356005)(6666004)(54906003)(70206006)(82310400003)(26005)(70586007)(8676002)(47076005)(336012)(86362001)(8936002)(81166007)(1076003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 19:40:17.9761 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe9d4fbe-f342-47ba-f80d-08d9933847c8 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: CO1NAM11FT054.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB0245 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain The SetMemoryEncDec() is used by the higher level routines to set or clear the page encryption mask for system RAM and Mmio address. When SEV-SNP is active, in addition to set/clear page mask it also updates the RMP table. The RMP table updates are required for the system RAM address and not the Mmio address. Add a new parameter in SetMemoryEncDec() to tell whether the specified address is Mmio. If its Mmio then skip the page state change in the RMP table. 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: Gerd Hoffmann Acked-by: Jiewen Yao Signed-off-by: Brijesh Singh --- .../X64/PeiDxeVirtualMemory.c | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c= b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c index 56db1e4b6ecf..0bb86d768017 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c @@ -673,6 +673,7 @@ InternalMemEncryptSevCreateIdentityMap1G ( @param[in] Mode Set or Clear mode @param[in] CacheFlush Flush the caches before applying the encryption mask + @param[in] Mmio The physical address specified is Mm= io =20 @retval RETURN_SUCCESS The attributes were cleared for the memory region. @@ -688,7 +689,8 @@ SetMemoryEncDec ( IN PHYSICAL_ADDRESS PhysicalAddress, IN UINTN Length, IN MAP_RANGE_MODE Mode, - IN BOOLEAN CacheFlush + IN BOOLEAN CacheFlush, + IN BOOLEAN Mmio ) { PAGE_MAP_AND_DIRECTORY_POINTER *PageMapLevel4Entry; @@ -711,14 +713,15 @@ SetMemoryEncDec ( =20 DEBUG (( DEBUG_VERBOSE, - "%a:%a: Cr3Base=3D0x%Lx Physical=3D0x%Lx Length=3D0x%Lx Mode=3D%a Cach= eFlush=3D%u\n", + "%a:%a: Cr3Base=3D0x%Lx Physical=3D0x%Lx Length=3D0x%Lx Mode=3D%a Cach= eFlush=3D%u Mmio=3D%u\n", gEfiCallerBaseName, __FUNCTION__, Cr3BaseAddress, PhysicalAddress, (UINT64)Length, (Mode =3D=3D SetCBit) ? "Encrypt" : "Decrypt", - (UINT32)CacheFlush + (UINT32)CacheFlush, + (UINT32)Mmio )); =20 // @@ -760,7 +763,7 @@ SetMemoryEncDec ( // // The InternalSetPageState() is used for setting the page state in the = RMP table. // - if ((Mode =3D=3D ClearCBit) && MemEncryptSevSnpIsEnabled ()) { + if (!Mmio && (Mode =3D=3D ClearCBit) && MemEncryptSevSnpIsEnabled ()) { InternalSetPageState (PhysicalAddress, EFI_SIZE_TO_PAGES (Length), Sev= SnpPageShared, FALSE); } =20 @@ -998,7 +1001,8 @@ InternalMemEncryptSevSetMemoryDecrypted ( PhysicalAddress, Length, ClearCBit, - TRUE + TRUE, + FALSE ); } =20 @@ -1031,7 +1035,8 @@ InternalMemEncryptSevSetMemoryEncrypted ( PhysicalAddress, Length, SetCBit, - TRUE + TRUE, + FALSE ); } =20 @@ -1064,6 +1069,7 @@ InternalMemEncryptSevClearMmioPageEncMask ( PhysicalAddress, Length, ClearCBit, - FALSE + FALSE, + TRUE ); } --=20 2.25.1