From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.65]) by mx.groups.io with SMTP id smtpd.web09.158.1630513074592019784 for ; Wed, 01 Sep 2021 09:17:56 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=Kh2ySWbj; 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.92.65, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YOjs08ygheZD/z5YVvlmIhm4VPBsGHnB2O5CghF+9ZCHTQQHUxboAPTXn7/0nJBq948zKyMGgpEoEOfPTtWhaxpKGiAnucxlScYgaeObA823GnXKWPu6N1sJgzIxMai7uc97iFS7GG/WsJhldn8pOrmsGFB7UvIPa/nZgZSG/GzWnYVqR6MhXTAuIXNqV6vuifwayu0zpasUTgTlWWqzS48Hvs4PNMvZuzttW15JIHd7hXpCPP5zoN9QgpicqDt8RIzVT0LzaNNbEw/2CbxuGjI4dH/dqzAaqy1gKRoOG4WRITxbs8g2jO8+guyrx9vLWSNf6iKxkNyjeS6fXdFcOA== 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=OShJX/RhL41kbpYzPsc/6Da3+ow9z7IRLd9MET3wcDc=; b=LVcHQB/MMYVespPdkv4sXQkAPqvlsH95i22V/pXw0oW7cKrofibVdKfQeYnRQB19v+EZ3dbJPRMvnaIgJGQ/TfJDIanfoPllqHTAibASp+3k3K1pUbF0qcOKB4l7NlDf4X/cy4iGxjrz0+QPbn4dt9i8hX/W3E1tLy2b4QHu98kKlB2DxCGF01pf+935sVbft+s2BDY9H6kFFqSV6IZSNRDIn759a7Q/QIj+T4MWq2wLrOtNG4fJJ/97KtcCfBdhwCLEB4nLcm4x2KRd8XnEq/C1VzpvbTqqdWZ1tyw2HkP1Ied1egx3xnIPL/yamDRLDGweYuT/NZg4mKRn+Dh+Hg== 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=OShJX/RhL41kbpYzPsc/6Da3+ow9z7IRLd9MET3wcDc=; b=Kh2ySWbjyJbKvpu7+NNzZgUnDFtRNlnK+R5yTzDabbe36FvTcGMo8s8pTIzSA1803pmIBYBZgvcji75+kWHui+D+BkEKhnXAfTvnAcAfie0XPjYu3By1SyyjZH5DCzLuArO9nU+IYLtosIn788Zp4KQYebuiWbMbjk+QUXZHfpI= 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 SA0PR12MB4512.namprd12.prod.outlook.com (2603:10b6:806:71::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.17; Wed, 1 Sep 2021 16:17:54 +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.4457.025; Wed, 1 Sep 2021 16:17:54 +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 v6 26/29] OvmfPkg/MemEncryptSevLib: skip page state change for Mmio address Date: Wed, 1 Sep 2021 11:16:43 -0500 Message-ID: <20210901161646.24763-27-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210901161646.24763-1-brijesh.singh@amd.com> References: <20210901161646.24763-1-brijesh.singh@amd.com> X-ClientProxiedBy: SN4PR0501CA0062.namprd05.prod.outlook.com (2603:10b6:803:41::39) 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 SN4PR0501CA0062.namprd05.prod.outlook.com (2603:10b6:803:41::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.12 via Frontend Transport; Wed, 1 Sep 2021 16:17:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9aff71ac-50b6-4275-d234-08d96d640dd9 X-MS-TrafficTypeDiagnostic: SA0PR12MB4512: 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: wJSIyvu/33VOrejflHQ3oPFKRcsPbkI3K9jVDprk9ZH+6qCEt9Vr3FlN/Ojyn2kExHwkf2G3GQiVPhR7rf7td1kRGrvu3XnQH5sVmtYgnAnQDLCff1NDEuHQnrIXIeNL7DcOr+3KSrvfgEURg80QZSQEoqEMUcRnEhDItkQPv5utmmq1cpjfVhCZ1ebaZ/9skEmm3B7Mfo0Lm5xshy5HdZFCCjqlx+pu9QikEIlQEp+6QHzdhp/zH45M3fN4njWq1JyEptwRSsxxc/ZHI155E2WyMjW4IbiFEEBR92XCqYUEvhRo7LC39ZGB/r/dsj+Tp2T0cJuyXelBfX0Ck3VyqUHpD4mdS/g8FKL+l/eCD8asMFrZFGQJw4+2uVWsj4oi7XIiN5RroJlVOMfnBkB0Y7fBCIYw9HRt+yb0OySgx0GhrwxJqF0TRAlf/Sdqij2DYhGdLVDiT/pk9OChZtUY1X+KX9O6xh1uPrVhhTh4oZ7ySWZ44eln19J/QYyiGN9FdnoFHO3VqS6IcwBmzXbk9d5dKlHd4hj8dUwoJGu9bNHKofHN3tb/XtJycvxKAuHJlArCg4S2tvbvad9jnX949ZeR0xDcWIshPE565fWSh/Vbk+MOrzvS/bL/NSVBbVPUZo4ssQxLUgYmQqjAxr311FkbUKsFIlLlp0YM1otvWmd0VeW1zVfpipDIWOSafxN894Ob6TP/r+cqcf4pKYLicQ== 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)(396003)(376002)(346002)(366004)(39860400002)(136003)(66476007)(66946007)(66556008)(4326008)(478600001)(316002)(26005)(2616005)(956004)(186003)(83380400001)(19627235002)(44832011)(5660300002)(86362001)(54906003)(7696005)(8936002)(36756003)(2906002)(8676002)(38100700002)(38350700002)(6486002)(6666004)(52116002)(1076003)(6916009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?7Gef0LdAkUTvhXvl5TKXOJBOXCgKsl5TtsohFMl/vKePMjO77jlryntBSf8/?= =?us-ascii?Q?ulrptnYcm4T8vzS0evBFEU2PHmd3ih89RZmP7qmRm5llTU/Pso/YZphcmMx5?= =?us-ascii?Q?DZfwLmAJdzZVJsFRasI13eEVz0ui1xA+yjg3txrowKpPS8QHbB6hvFoLJII1?= =?us-ascii?Q?fLBOzPHUCPqOHlV98oRtVKZ/bPWiNJOZpYMGNWo2VvgvRjeXj7qEkw18UtdZ?= =?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N6q5p0L7Hg4gR3KZMnry?= =?us-ascii?Q?cxZCqeUoUarFAy0c5WjPvlEBurALR1WoGDMaZlWEYb9me9Q9lxOsPhDv7k2L?= =?us-ascii?Q?MSN7EKxn4FrRCmCpX0cgsHXxsifLAbQt6Fhsp7zKCJsO17LeLdBZR+X0eYu+?= =?us-ascii?Q?/OQ2kPGgZ3y7kgv0c4WLC3RI3v3S3xhuWroCKRBwk7G8x6ccnAmc2OrLwxm+?= =?us-ascii?Q?xmI06iYPK9akleOwJY2l1Zu+?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9aff71ac-50b6-4275-d234-08d96d640dd9 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2021 16:17:54.7841 (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: F1107hBkEau92XehOKFyzRx0qXVlG7prRKofeT7at+xO+w5oWqVXQdRLrQDBM8M0m2rTmO+TPeIkTFPwDMTxKw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4512 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 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