From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id C3E71AC1888 for ; Thu, 22 Feb 2024 17:31:23 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=K/KE6BpAzszQxm3DHfBm16UqV9EeqFEPga1rkThr+U8=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:Received-SPF:From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1708623082; v=1; b=bpTwbdklfRlxn4lk3Xh8jbCGSld8vEe/xrKuVmMhIkMzcGUsqZfLR3asw7r7xBuqSna6fuMB 9YOHF6QzBvlJNL8To2b1oD0yyhQX5K8+3nkgfadj+RYvCrBJBSQaqLmgoxlFaJoYJc69j3N4ELt GI4E3utRdY81QP80/eRNbOn8= X-Received: by 127.0.0.2 with SMTP id ZoC0YY7687511x6BqcFueCmQ; Thu, 22 Feb 2024 09:31:22 -0800 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.45]) by mx.groups.io with SMTP id smtpd.web11.18815.1708623081789535385 for ; Thu, 22 Feb 2024 09:31:22 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DriY6mqmr6IkBdFNq314pMOHF8oWoJSw3+amnZ6dWGTuMObzYSfZK4kUk1D7wTxxyuQSW1l2V1duxG/fg+jZ1gZgCyOfo7jdKxB0cYLDTA8ly6ovBlQgEWBUV5wA97b8nUpb1Hnvvqr+75CoYxIKiAa/UVlkAfPY+Z3oncn0WkJU+EpzI5XpnAyHHGBjFQl0IoXdL96e207U7OJ+x6991VcWBUx2d/JH0OI072l4VwftEDOyGHXm/6oJtpprLiVFixS7EGFXam/7LCvTx+Gev9GrA+6IkDBFRd7DAltCj6AuaGKNiUUKZu4uUeAXTbv4Gpd4hOTO0qOp6voQfSFmTw== 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=OV9RuyYD/MjI3pDbHCS7u9qxcVsnehG1suRdr3DHLF8=; b=a4HN1moYCB94CQ20Bi+HbZLpX48BrasbzJQdp7hsuVVR/j5LiiS+rcZ1SpNidYsfnQ/OvF7La2i5/5owdtQ9f0RvZRVXAGKuPAjox4iDnjUkGEG7E58kjdcVDoH5YHCRvJZuwwKtNf7/Up0Uq0vPIkjU8Qh8iF+xfyQhS0WQVKtyoFnvZn0zO5tPQzPO+OkIiLwKUrkuzrmb27W8S+ZJIzeYYmYJiVsQUrPgCjnIJJCsGEwbin2OZfhfFvpilNUW//Z9oOZzZevVQ/oQKvSKooCC/qyVMwsF9wP7a7HtJ7njF2+TP9CNVcdbzJHuP7FYDIaDdsJ1GSLJGCF17LWmAw== 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 (0) X-Received: from BN9PR03CA0687.namprd03.prod.outlook.com (2603:10b6:408:10e::32) by CY5PR12MB6624.namprd12.prod.outlook.com (2603:10b6:930:40::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.19; Thu, 22 Feb 2024 17:31:17 +0000 X-Received: from BN2PEPF000044AB.namprd04.prod.outlook.com (2603:10b6:408:10e:cafe::75) by BN9PR03CA0687.outlook.office365.com (2603:10b6:408:10e::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.43 via Frontend Transport; Thu, 22 Feb 2024 17:31:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;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; pr=C X-Received: from SATLEXMB04.amd.com (165.204.84.17) by BN2PEPF000044AB.mail.protection.outlook.com (10.167.243.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7292.25 via Frontend Transport; Thu, 22 Feb 2024 17:31:17 +0000 X-Received: from tlendack-t1.amdoffice.net (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.2507.35; Thu, 22 Feb 2024 11:31:15 -0600 From: "Lendacky, Thomas via groups.io" To: CC: Ard Biesheuvel , Erdem Aktas , Gerd Hoffmann , Jiewen Yao , Laszlo Ersek , Liming Gao , Michael D Kinney , Min Xu , Zhiguang Liu , "Rahul Kumar" , Ray Ni , Michael Roth Subject: [edk2-devel] [PATCH v2 09/23] OvmfPkg/BaseMemEncryptSevLib: Maximize Page State Change efficiency Date: Thu, 22 Feb 2024 11:29:48 -0600 Message-ID: <4f8a004b8f5f6de32d44c478543f9542fd9c82f2.1708623001.git.thomas.lendacky@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044AB:EE_|CY5PR12MB6624:EE_ X-MS-Office365-Filtering-Correlation-Id: 9f33a319-89d1-41a4-42cb-08dc33cc1362 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: rfsXkFTBgBcUZSaQJTy+dze0xJNwB8WbS3EmXAY0WbGTH5I8MehZO0V6pma5/KvjivQiHeJ62KLwsTq6uX1w/ow1E32Cx7thehE1ISkUyUu473rDjlkpUfA7D7UJ5xDa88FYvR/OYACeeTKk9WaB41K58vE6NfgGs0t7ByT+4rrz9tfFUzM3I0AyL9Ozpd5qLQb3YTBa17gwEIfItQNueH3XZfzn7Me4/tq6zkKQ2vJIM4O2ofGjVpsIOc7S3P+kjMROyrkBwh5yyWbt0g7S3dACsj1KdpwuJUST/pESOdWi8DzNbbm07RHg0DGtsNh89k4Cfjay5t5RowENQmaOeZvmQWc9o/oodEhlZxlaazi46nfbnvriPBP/r+5gUJfBDJxOJSaAyAaxw3H3x16+Zggd0Ik0eZrXwzwcSG0+BBvKms/DznsPQSDrMCtFu2+l8z85cqdpv8EfZiM00+f8HXNwdQoAOLc+QhOtUTbq+yufuaXyp4eDQGRjIpZ0lQ+5q+zFGXboWOSj7Qy1LzBBF6bVVHgTDVTnOLG/OrLKPzoY7zxxUikUexHOsl1btsHxdUSXslucLkaCJ/BMJ3TgJA8A5k3u80Ci3eqVsnTtAm4EmsOPAGpnlxo+u6cPrinUHstK1Ze+kidGBN5IwksJdA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Feb 2024 17:31:17.0225 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9f33a319-89d1-41a4-42cb-08dc33cc1362 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: BN2PEPF000044AB.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6624 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: bF6MCxQE3jj1cdOozLH35R5lx7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=bpTwbdkl; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4654 When building the Page State Change entries for a range of memory, it can happen that multiple calls to BuildPageStateBuffer() need to be made. If the size of the input work area passed to BuildPageStateBuffer() exceeds the number of entries that can be passed to the hypervisor using the GHCB shared buffer, the Page State Change VMGEXIT support will issue multiple VMGEXITs to process all entries in the buffer. However, it could be that the final VMGEXIT for each round of Page State Changes is only for a small number of entries and subsequent VMGEXITs may still be issued to handle the full range of memory requested. To maximize the number of entries processed during the Page State Change VMGEXIT, limit BuildPageStateBuffer() to not build entries that exceed the maximum number of entries that can be handled in a single Page State Change VMGEXIT. Signed-off-by: Tom Lendacky --- OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c | 11= +++++++++++ 1 file changed, 11 insertions(+) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInt= ernal.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeIntern= al.c index bcc0798d6b02..f1883239a661 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c @@ -145,6 +145,7 @@ BuildPageStateBuffer ( UINTN RmpPageSize; UINTN Index; UINTN IndexMax; + UINTN PscIndexMax; =20 // Clear the page state structure SetMem (Info, InfoSize, 0); @@ -153,6 +154,16 @@ BuildPageStateBuffer ( IndexMax =3D (InfoSize - sizeof (Info->Header)) / sizeof (Info->Entry= [0]); NextAddress =3D EndAddress; =20 + // + // Make the use of the work area as efficient as possible relative to + // exiting from the guest to the hypervisor. Maximize the number of entr= ies + // that can be processed per exit. + // + PscIndexMax =3D (IndexMax / SNP_PAGE_STATE_MAX_ENTRY) * SNP_PAGE_STATE_M= AX_ENTRY; + if (PscIndexMax > 0) { + IndexMax =3D MIN (IndexMax, PscIndexMax); + } + // // Populate the page state entry structure // --=20 2.42.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115844): https://edk2.groups.io/g/devel/message/115844 Mute This Topic: https://groups.io/mt/104512950/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-