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 AC12B941910 for ; Fri, 8 Mar 2024 15:31:12 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=WIZqjo/bOp5sB0biIyNwW4qcEvjQ0eTL9E/n01gH6ww=; c=relaxed/simple; d=groups.io; h=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=20240206; t=1709911871; v=1; b=yeslSDM0K4P7tVA4XwnEeY3jW0cUBu154ZKvDDTUKDBJFvK2HY0sLYagbQqc2gOhuc34XpQm OSzB8KNBxuqfQYPAEaMNidbnbR/Tb2bWrh4Gfb5o3p/PzFWYgl3NaWMgDFhIC67c+8+B3PETDiE ai9mxmoqWSzpZSJXS33n4ZDYH/FE5NY2Xdwl7if9ET57cHI0ThCj1YUlT0EE3TZI5NLcO28pWhK G7rdXpyM9bEKDo0oszQ/0bU352DFnovBkPrMaJzRn74hwtixwHPjNU4IK6tdPD77hDFnmKCX5nx tFxuO/UrcSs82xrrYaFeuPkYL/N8XjImhLK+t3zv4gCUA== X-Received: by 127.0.0.2 with SMTP id z6TcYY7687511xatjQXOfsvr; Fri, 08 Mar 2024 07:31:11 -0800 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.40]) by mx.groups.io with SMTP id smtpd.web11.24843.1709911870736796596 for ; Fri, 08 Mar 2024 07:31:11 -0800 X-Received: from DM6PR11CA0053.namprd11.prod.outlook.com (2603:10b6:5:14c::30) by SJ2PR12MB8135.namprd12.prod.outlook.com (2603:10b6:a03:4f3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.24; Fri, 8 Mar 2024 15:31:08 +0000 X-Received: from CY4PEPF0000E9D7.namprd05.prod.outlook.com (2603:10b6:5:14c:cafe::fe) by DM6PR11CA0053.outlook.office365.com (2603:10b6:5:14c::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.27 via Frontend Transport; Fri, 8 Mar 2024 15:31:08 +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 CY4PEPF0000E9D7.mail.protection.outlook.com (10.167.241.78) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7386.12 via Frontend Transport; Fri, 8 Mar 2024 15:31:07 +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; Fri, 8 Mar 2024 09:31:06 -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 v3 09/24] OvmfPkg/BaseMemEncryptSevLib: Maximize Page State Change efficiency Date: Fri, 08 Mar 2024 07:31:11 -0800 Message-ID: <2014a0790e5fe6b8f2cb22f25f2ebb2af406f215.1709911792.git.thomas.lendacky@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D7:EE_|SJ2PR12MB8135:EE_ X-MS-Office365-Filtering-Correlation-Id: 5fca2f4e-c1e3-4503-e212-08dc3f84c6a6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: RtltsE5x1VP8uxrJV8VvvMo++Khz8tvJLg9punEu0acgU/g5hpTOFSBlBjV/EmwfejEVRiDTj517SBULThw4KTNJX/1hn2PNsH8JRURb2tNSF2B85gKiQK/fXSegHWeNY82S21dCAKUR//CXvxW5zhKscFPMsii5bCWZaUG2Pm5BH255QOxrLVixBxKT86NGQGUDYPuw47bdt6cl3aoZhe64Pl8rRbql/AihEzhgq493eZoM/kAoaQovxD+CshrhQDPweeqDJnJBF9XLbhfBz8OgUShviW0WRewBAjpQk8IC7ue1r7zXYuhAD70MLHwXMQS+Yeqhn9MGypq7ywV22zdPAD4iKmfAn6ShC0HjArrK953fm/NWLE1KE0AVAvQC/V+djdin7kKXIO1KHmi/RDU+Vv5ps1iEjaOZ8ucfQq6MkozOUkKtJAUpAwXg6xFhz05ka9CVdujB7JErHJ57CLy7efwcuCITitkajQO5DJ5M10gWHeHVmZ2GbwN5Uwt/1ULcndQR76gcBdKQ8ab76KSIRYh3jfeRlfu32XQR2/77P892ZA9UH3QVAVePO3/XjMkq7VlsO//74Q2eLlEHYWmqbrPaIDZ7oP5ZvwLEplJwFagpReeD7pMZsezRM5p368k0Nd+w6ZAfoiEJOh7Kv6ZmHucdb5pIUBO2uk946G6hCmCj0eQeBIrcDjxp5+rF1F8bzob8QR29cMx6dtXLxg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2024 15:31:07.9732 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5fca2f4e-c1e3-4503-e212-08dc3f84c6a6 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: CY4PEPF0000E9D7.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8135 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: 1XU31LeCsWcKjews1nY55eXZx7686176AA= 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=20240206 header.b=yeslSDM0; 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. Cc: Ard Biesheuvel Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: Jiewen Yao Cc: Laszlo Ersek Cc: Michael Roth Cc: Min Xu Reviewed-by: Gerd Hoffmann 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.43.2 -=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 (#116534): https://edk2.groups.io/g/devel/message/116534 Mute This Topic: https://groups.io/mt/104810705/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-