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.80]) by mx.groups.io with SMTP id smtpd.web12.14901.1624902231284358566 for ; Mon, 28 Jun 2021 10:43:51 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=ydHRL6Xj; 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.80, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=So09t68duKzNdYbv1SxOOg5DcaswyktrwbwJMaFMNN+ch6Kzi08OMFDNa6YnkamySzJKYjJAyH+TJy2gtc7h52LQ9yliKIfHhNzbwZAKIzewj0fVRZ1y0CHX5xTt9n5echkbJGcbUyu1dD9wJwxKFzJg9Nfl++Inkl8lGfj2rl1/qXMIH7Hg4+8Ioo14i2ex350BygHR6lGtKTOemTthCarow40IoldU+/b3cWylCuE4eBeOq1+Z/VKwxXod8WoJEkboJios2P8pL7y0uDz2oE1Fog0YeuNRJw5tGJAtA9HpBozOhCEYheNN2oAW04lkKniErv2IXXBupfCmDBB6IQ== 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=gS9omktqFgbmR1uhu4ZIqyN0iyvMJmbok96cxeIaJd9bwzghP6jK4XzguuzUENrlZNtq3Cb8kbtfdUEbYR6huXksfZ41je1wMiMCwebQvyRAB7zSg3H+8ngLsx1FrBS0COldUyIxGwdiK42EKMuo9IpoFNxKs6yjU1OMPRr0keQCm0nswImNgMWUxd437EKskpH/GE9ikTvKxnPxAkrA6X/EJMbjlXoIM7iRVE7BrE2+0wgpPwo+5fouJNF29Wsuefeo/G5iHCmztl9Iqzniv0r2jNVyhGDsLFaalX6Ln+zykxCAETAklRAWMWdICx9Cin0h202cuMVlSA4tpNo/0w== 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=ydHRL6XjOXB0ZI5QdWkHIRCSqLxWHRGMGjIDULBlYUZVIiudAZ0cpERBBaMPerNmUU6qzuBNMs3JfTX/qyOO+TzFdPnjbpKakij42XUd3BJBS60NIdfLfQme6c6GJ2HQaPMb6BYA3pSYXis91GDU4Yy4Shqn82uJD9fSvcX/bDE= 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 DM6PR12MB4761.namprd12.prod.outlook.com (2603:10b6:5:75::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.19; Mon, 28 Jun 2021 17:43:49 +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; Mon, 28 Jun 2021 17:43:49 +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 v4 24/27] OvmfPkg/MemEncryptSevLib: skip page state change for Mmio address Date: Mon, 28 Jun 2021 12:42:20 -0500 Message-ID: <20210628174223.1302-25-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210628174223.1302-1-brijesh.singh@amd.com> References: <20210628174223.1302-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0601CA0020.namprd06.prod.outlook.com (2603:10b6:803:2f::30) 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 SN4PR0601CA0020.namprd06.prod.outlook.com (2603:10b6:803:2f::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.19 via Frontend Transport; Mon, 28 Jun 2021 17:43:48 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: da9831c2-a768-48a7-a8cc-08d93a5c497c X-MS-TrafficTypeDiagnostic: DM6PR12MB4761: 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: 4X5RFDOj8Qo1VwFyoZMf7geauS73oCdM4Ep0X9CUTeqMFnAqDSx+T0lWQDs8lfBy9Zp2Nu7HKjTkUivi5aLGwzeSfrRQKSDrK5QQ5LIKalhjIUyoH9dZzBcw9kemOFskKGdnjl3xnxOQeLDobciRmC43gozh2+FtB8IPQa03F5Ona63wxj6MC1DrOETDPkVW1PZxrTXO2jcPDGKJeBcc/QbPpoL+xREQMA3ObosY44M+92wq6U9z3i/oUBJTDIoTtTVc9rWa3miL/YI7SuqDY/wVR8VdP60ruNDzflT4FgGxg07g4Ej724TslRdoKyRsdNQUOzrQgA12mLHj/1sz/EOWnPYQfFhZLYrYWFNGkyMhZSRrgC+rEEXfni/x1xOKQiiZhbs+fX6jPRbcA1qm2/ukaWzDrlN8zWRzBFxnMSNJjMKoNASMdBohAcn9iBJg2U9ADBWOSuTJatbMKcTkeDD5ucXiLZE9GzEUZYi0d3MLt8ive49PAMIH0VTzqkzkBzdF/03aG3bzmiYJhjOk4Kc54x0pgXzlrRMMbUZXlkulbxSQHQTw6FlDNRqpscQ74gYSR7j5GwQXdzrqolXIckZd+DY6xMSjXEQyYVCjFkrKofoZgK/cmZ5dJYIssfqBfCb22hX83/n+MRmCMGB+pcgZZlJoTA6ECtp4ijIb6+8eN5KR7UNSQAIJcbGsgckG1xLUoMWWSg74M8Nq4oa6cg== 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)(136003)(376002)(39860400002)(396003)(366004)(346002)(52116002)(36756003)(26005)(7696005)(1076003)(2616005)(8676002)(19627235002)(186003)(16526019)(8936002)(86362001)(66556008)(5660300002)(316002)(54906003)(66946007)(66476007)(6666004)(44832011)(38100700002)(83380400001)(4326008)(2906002)(6486002)(6916009)(956004)(7416002)(478600001)(38350700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Bg4m3Fm0sEsFwPvedb96/mGNWqXY0eIyVa8qYkgJj9+0MFd+vLxS4gaF3w9L?= =?us-ascii?Q?CndRVa6vZK4graelfnKY3K0qteBNeSxwhQWlHeD8kL3mZp8u9yobeyRa0qKh?= =?us-ascii?Q?TvKElU3wucRQVn8BfsiS1aieVhAMVvQDvadHum5powubDfEMPWyP7XOSOuWC?= =?us-ascii?Q?hZPlc/p4O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MhNnONOl?= =?us-ascii?Q?IufeHFe15BfVBUGZ9tjCDRRXgX7RDjVBtwx4gUIMaEeOf5X5z7Kc+YXm57AC?= =?us-ascii?Q?t5mjAradihpbR7KhAp/Pc262ixkgVzbH6eoy2vyRUpjbDDn0OFe20HPUmnup?= =?us-ascii?Q?N9T++/iXdb4ZK2OaMHSNEZuVTUE2GetXG4bNfZADUP/kq4HykseHXyjQ8VYl?= =?us-ascii?Q?36gbHjoKlCwhVTkzHA+v4wd6thQVxRYu9J+A4Lj+FLUgJkG1DPMxbU008bM1?= =?us-ascii?Q?kf9qK5WRXsq/TxTqwGNWr8uJ?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: da9831c2-a768-48a7-a8cc-08d93a5c497c X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB2714.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2021 17:43:49.5583 (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: 8hkflphrp/YqINhsEaRG0YF/IzkNVYEO77dogbgJSpR6F7hMGesForOcgUNh/D4UwYupms/GfUfr39QkPAlEtA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4761 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