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.49]) by mx.groups.io with SMTP id smtpd.web11.861.1631557222462732596 for ; Mon, 13 Sep 2021 11:20:24 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=yvxW6twH; 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.49, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K3OMoloY2jPDXhdYAHaNIhr/OwTryouSoiG9owuV0kus2Hk/Q1Rt7dEjH0JVfed6/A741Uk1QANOtGfMOIiGZttggwQqOSZ2mxiFjgpYnMlEvLFJveZe7eoALHYqlbtm6/Z695JjHrQ72PR6P+ZFcll47OWFBJiXrI/YcLba83Yem0ejK6MLClPYk8ky1/VUOG+YrzD4FdYi6PVyJR2Zo6Mv7imWSAWukQoAg1IyP/ZTZMCh3orADcfUvcAysjm+xK/YlwdpLGxMU3D5asPk4XznXbLMJ5sZTM5sfNcpaJenKaQOZuNhFAMLif7DQt0zv1LOF81qW1qgm7XaP0Y9PQ== 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=PYylhL3Jbb5VwbocO9nzuFw0rZXHakw5Q0ioFRbUa+Y=; b=E2jD58QGaaT7zy2YqcGUKz3T2mxcHITpthmnD42iBO+pnBLMzvcbAVnKXHMbYq6nhQtgyt7/fuH8lcJYpSDh+aFL1ROAHBkK6rntumzZ+0SAodETzmgiRA5D7cn2/3YGgrPP7Ev3YRx3C4PNXSdqIxfVwIFw+kq6YGb5hX6HODftdXIyKVr/l0OCbJLy4w+kAbIEr0+F2kBNcetijPKSFJ1HM94cXUbRKEzA+vXBYpnoxei4i2XjOJTOENIZ2mm01d7EOUf0qnOsSe2k5hAo6ey52ma0Y/dFn5R5otEeR3fUPmcmPFTX4VlZIsUcHMJ54gYaBuqvo1n4rMhZ5vnIZw== 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=PYylhL3Jbb5VwbocO9nzuFw0rZXHakw5Q0ioFRbUa+Y=; b=yvxW6twHJIyAjPX6G1ZXQufZ5O62PxY+2TljSsMf/juHQ+B70pzVXG9i88OLtW+FWdZAEYHX5g4KzKf49LIIu6NSOQ3bHofQ2R9YgWBW1mkIzVepDKQHhUrk+clYSNfzTukVR47U+DcqHJ+OHgnGF5Q2N5aJ6YLLT54OnvZTMF0= 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 SN6PR12MB2830.namprd12.prod.outlook.com (2603:10b6:805:e0::27) 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:21 +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:21 +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 28/31] OvmfPkg/MemEncryptSevLib: skip page state change for Mmio address Date: Mon, 13 Sep 2021 13:19:38 -0500 Message-ID: <20210913181941.23405-29-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:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0ebae0c8-81ed-4de8-02c3-08d976e32590 X-MS-TrafficTypeDiagnostic: SN6PR12MB2830: X-MS-Exchange-Transport-Forked: True 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: 8G9c0O8Gu47VQpLsvr1EFJ2wUtF6RvU1vKxRS+QFdj6yEJWK/KtpO3QMnH0VAmx0kZOWax/zxRAGUDMUuVTo79N0kbbGcyVnxioGx92FlV7JaLF9aWtq7tTECGOG/tuiX4w0Ipvi0UJXl2qfxrCPnXYhHnP70NLVsjQbqj6pB9B+NVZ9cSmbNjY1dcPK4HGF5DcJFb55UdDgf56GuDJMMXhdUb5rBE/6cV4Gbl+3jeoLhBb6gmq+Q4UkgKv4DgBZZ8je/u+seTz8zsTO8zZYOUqsAi039gH5/cCQTD0uBxl4XH9zUf9NyiBKx+wVcx05aAwS4mck6ZEgLMo4BF3yegVDZHkxqgWDHW7kj0jNHISR2hxUiCgKL4zMS+dhbAyH09ZJgYDim10/N05GFgNYb6g3A79oS1+U4UEiyzhJ4EnAk5uFZx5eAqwKPBu9xGiVUkM3+7U/CRAlOPJ3SyXWjZ95k7u8Yqqz68jSkqJISWwvDVyMdQtEWdfl77CIX8kVASak+7zNXF7vgKqczICcN0EEAzyXBL48FuYtBEs/TRsBpxrdfXCVCkq/P1skq95uBs8Cv65HBsooAKwm+tdnOB9IpCVwDtV22XYSUByphlr/pz1oMHv0UarMFnxUt5bRoqNmpKS+up1KbIXYsPR0E0uUzBLBY/GMF+P9QDtp7xDTrkFSpAbpbb9uoI/6dALpATS0ozNiu4l47qcRBmzitA== 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)(346002)(39860400002)(366004)(136003)(396003)(376002)(38100700002)(38350700002)(54906003)(4326008)(1076003)(186003)(6916009)(66476007)(956004)(19627235002)(2906002)(6666004)(66946007)(66556008)(2616005)(8936002)(83380400001)(478600001)(44832011)(8676002)(5660300002)(26005)(86362001)(316002)(6486002)(36756003)(52116002)(7696005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?YdvUgOtyQ5Q1RpsvfZUymG2fLz0m0z8o5ycvGAGijuZlKn72OTIWYvVFY2KI?= =?us-ascii?Q?mUoFVQDwuYX7pp2ji0FiZGWvmI9+Rl1kDDzYI0AjauKOM4qHzxpZy2DomMAZ?= =?us-ascii?Q?qVQM+OP7ihS7ZnXWBqTliaxe+yVms6fASVf2mmOgfNPRfM8SkfTQLebraCqq?= =?us-ascii?Q?oxnjgm8VFaMqpgTNuyIF5iut6QC6mb0mNKaDQGPUIUk9iat39r5uGtN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PpSz01DlL8b4QpBAXCLvon0sb48bgB3KSVeak?= =?us-ascii?Q?Fm4LbZG4+JJTznQFeuIAv1VFJnbAtX4bT7YCFPFt6lX7/67TcPn+jCSY0twk?= =?us-ascii?Q?dUtWPpXsYavWDbvPdtAJzCboczOfrJ9fIcKCC+vniX17D3s5VBKl+hfiEc/E?= =?us-ascii?Q?JZG80PcD02s/0GsIcYzLwQ/DrF8/oKgVfYTC382Ul/1UPLV0JHnXW6dhc4O1?= =?us-ascii?Q?xywVaOOoAH++jSf2+FHFPJxa?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0ebae0c8-81ed-4de8-02c3-08d976e32590 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:21.2122 (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: SXZKOzTOJVjc72Jswy+eqdPsQznZ4PuYLPVCq6vn5yc+QfAidwk+EvkHU9hsQGyeIBWG/bA1QJJEhYrpKMZWeg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2830 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: 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.17.1