From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.60]) by mx.groups.io with SMTP id smtpd.web10.5579.1625057681627900252 for ; Wed, 30 Jun 2021 05:54:41 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=Ny+zesI1; 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.236.60, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h66I5jK6D68qWBxqSuCLysLChwBP/v5nvUI59lxheVOfhDCqW3mU4toHdqKQtDRPPvmrZ5aoyfb8FRV1GCVigBrKISI6LqQvxdqUH9gO5A5XeZ76TmyOPQznPe4bNRIesCMd8Ndt+s7LDmDLtqQc2inxCiI6MonrQ9vWjPTeq/HfRo4Pcj/ZdsWsyNpJko4+Y7Du2q624dBjzc5nsXx+G5Hva3Rr0+IN5B5lS9kqXgeOJBuaC3qmNg5dXzYSNRACLqAKrND8QEyho+daZc6H/3cRt63x7Psm2vMl5lgM8HeZfyTUbXXeogm0Vw6iVawtwjVNThPGa8+esttZ6BBPKQ== 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=feKMnXykpClFn+Z1vy3jA1qLSrIH3miIPsLQ6vxuftw=; b=GzR3aiCVOrpJb/WSv+iKD1W4jOuojB317OaDzFFRobtOANuToWMuYP/IuWBFXqNCeRr9WJ42krPM1QseHZ8y0t9NmQ1OlydEJKIo2dcNubcrvVDugiSF+RHYg1UNEk6CbE2rPM8j6/tpUMhsdtNw/JZc0uB2Jr2kTdHWKf6di8FsxYVvcsIFKbG/Z1KM8/p+n8MnKx0dFUC3f3fkp7804IckrlJEBNLjYjZ3PVdwyLa2cXChY27Gsa3Z1ZVfmxZvka6uMArR0ZwPPjyvP59trdw1j9Hjd/sQNC7CGI4VD2fzlCEEjh9zhO2gyZwKzrATW27f3v4D73ngYV0ROzL61A== 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=feKMnXykpClFn+Z1vy3jA1qLSrIH3miIPsLQ6vxuftw=; b=Ny+zesI1MXpW/i+HgqqFxq5zrp7aieM4BMtnY9o1rQP8//ovUcVl8JtUooeuIzowKj9PDFDGro8RWXUT50Q02Ofsv8lrJbMPAIRcAKeCoORR8jytfys+efe4TQrMJ1RzXD6ufCGgbxU1F2aZSWSMlRyZzGpHy6o9fiwOej0Z8Jw= 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 DM5PR1201MB0172.namprd12.prod.outlook.com (2603:10b6:4:51::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.21; Wed, 30 Jun 2021 12:54:39 +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:39 +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 25/28] OvmfPkg/MemEncryptSevLib: skip page state change for Mmio address Date: Wed, 30 Jun 2021 07:53:18 -0500 Message-ID: <20210630125321.30278-26-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:38 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 76ea1acc-1d21-482c-0115-08d93bc638ca X-MS-TrafficTypeDiagnostic: DM5PR1201MB0172: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UZAOHYSW1PF/GTYL0Vv5hWVSf1RvZh+ESgV4BAmRF9na2fbqfp77IRh5mq5gJIEgdi/Rb2AqwHJnuxXyc98hCJ5yR8wdLz9KAM1lTWjxC0GUd5/JyzT6M7KpBUVQ9W9qOfOVajoA9+1E1iCtB2Ls5e9nhwK0D6TuKQCax8Ztr1U2Zb6FN7KXjloEKFjBFAeK32WO6CoUfPrXKOS3kFPMTkh++7OkbMm+QDnDVA4ft3+oyIv/E5nV+j52onLnoNE1AKju0QtFChcSe2v+LTAB5Xi20tQLWul+cW0pCoTYqLZ4hJ4onGSSJkEIIhtGXhNJxBcPl3Qse+XaCZn3xKmlBuaVRqv+G+GBT4FJuMOc16zom4pHnldRUmTHPBjrizhtz6tY0UvjpQpclQrwuRi71qB4jQ+yb6M0GkVso+p1KrwuI5kgbLjPBjZZFwMblEDI1uHHKgscrQncaJQpvFYnngR1NGLHGMB8dHoGjCpyGxCnF21Abs06OABoo+GfqZv/R2oBgVyt2e6zWpkpwqlSI6gQVbUF4dB9I/HLxgx6+WmekjTqrBlvN8A7LlLaZtTfjuIc2vsp213wjnMZ8AySq8xLSmo7UlKx/R6q+eJNeRaLkGX/xo93h8giWnpq4n6dH20Xv6czpOXVZQpT6N9i/blCXN9nbxBfMgFZOiuwTFMpy6MyK/R70bfPURqOKLUfUVYDdzr8ArIdOH41++Q8Vg== 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)(366004)(39860400002)(136003)(346002)(396003)(19627235002)(7416002)(36756003)(5660300002)(8676002)(8936002)(54906003)(38100700002)(44832011)(2906002)(38350700002)(4326008)(83380400001)(7696005)(6486002)(1076003)(2616005)(956004)(66946007)(186003)(26005)(478600001)(52116002)(6666004)(316002)(66476007)(66556008)(16526019)(86362001)(6916009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?ggjVuyxLBw31upPY633TZiAbR5hZBv9IGbaFrxZkV4nTzdPQvCIpvodDgGqL?= =?us-ascii?Q?pCHfN4u7C1/mnAAL6ro01IOjyj5heUCXctkw9ZXBlA5mlDTriA8nSRQWzFXu?= =?us-ascii?Q?h4tl+r48VMr5+FO6b+SAp+MRrbfyIoTj1rhf3tYM8zkAgsr/NMVaJkjuTAnO?= =?us-ascii?Q?EOebBCoakWgcJSxdunueF3STb5UDqkqAFymmMdytMZd7TmmLOBqyDBVRJQt7?= =?us-ascii?Q?59KArt94/V0pghCs28Ep/2JwXirzqAxYA7Qdg27QU+R+WzUKuQN1ytgZNS9G?= =?us-ascii?Q?IKrWDiYQtciVZMqc6HDVyeVJtbxM5tGeEe04SmmTdzYtF54OwjiHjtQIGJr6?= =?us-ascii?Q?pTIp1zIFqrX8MvDw6SeO5oMS527GHK5EF5rH7VfR87jOCmpmpYe52s63RZn0?= =?us-ascii?Q?bsU83k+L9gRudQyMw5jsI66BeFsW+ZHUu5au0T0p9IKIHrE0iUnEE5AMsCeB?= =?us-ascii?Q?UOOXQzFX18o4ARUembKmd9am7p0M/amU5kOG9+Qxoq/xJw0+6pnMY8k4nuCL?= =?us-ascii?Q?Di369qP8VT3YxJBLzBmLeYeUnrvYET9/OWKxvF8rx9qLf7YbqtAOfOOC3rS7?= =?us-ascii?Q?13/4rwHreMMV9LE3JB49M93vTjFPireH05ybHWD/eNoCNdj7V8w7UUOtnV06?= =?us-ascii?Q?ouhYQZ9FoI/knrZ+Lcc5dU+tGXCqnIk2kggvl8JXqqRVAcyr2bxRcu68uHat?= =?us-ascii?Q?+fiJa8b8OP2p16vRToZjJQuP3Fu8U9T4weXF69lNJNOG34XNZd906Mmlt+Ps?= =?us-ascii?Q?zTstjH+dfcdXAUB1EMu6wdQoOxGf33drOOfcd9CO4KhSa30FuGX33YcWPCcN?= =?us-ascii?Q?rLpDrR6DSMLkn0SCXmwA1q8d9ZdEBWE+9DKQEJ87Vjev+QWaNXBhyQn5ARQU?= =?us-ascii?Q?7fStdmvuKF26MTnkgl32tpCnLvbCFjaHS6bzeuxSQPraIRlYXSMWIuH+scmX?= =?us-ascii?Q?BCRazV3p7puT81iGknRiB3X/tKrGcoB0dC7w8r/H4xKB2MFB6xoxhGEVU67A?= =?us-ascii?Q?hpsflY2b7DlfhRU5zsZJIoNm56Ymj2iOFowfOQJd7wkX90JZyj1b7A0LO4UR?= =?us-ascii?Q?s/G71rZP/lV7Uj60vDswzRU0WypLOxoCGFLyNYh/ijlILPWKZJlBSWZW4qcm?= =?us-ascii?Q?xXyzk+qqh5ORpoRIGzVMA6NCKziUbJVo95yxFNnvTCKpjgzOwyaChCQbOfX+?= =?us-ascii?Q?2KmyjnmVV6eF04ZsClp0svz2xWHW7n/Vx01P2wxo5BfXH7EWv59ARbhqHXNi?= =?us-ascii?Q?7ucPa0HEXxk6YZR7B7XheU1KVeXsUOi4TqJBuT+zjpXDIH/ogcA6T7E/PGhv?= =?us-ascii?Q?b0DWHobo21ZYVC6PE8V6K60O?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 76ea1acc-1d21-482c-0115-08d93bc638ca 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:39.4200 (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: mR3YNZWAcQsfreYYRisW/o6ikKUKN3NY2LErVfIA8vSK/j5arz+XiOlfRKh3IIbfIjDU9a8c/bqZl1RZsHbKOg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0172 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: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Erdem Aktas 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