From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 191BA9416A0 for ; Mon, 22 Apr 2024 12:18:18 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=Fz0Xmkr+G0wMfoPfegBJgwud/Nkt7EDOZHwZVNO+41E=; 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:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20240206; t=1713788297; v=1; b=Jkil7d6mLcrQ0BPn5JHo5NzPcovOyaKvc/thTzn1/TjveQOOuNx4fWkKnIGffxGAlZ6lgw7G 159V4pE0Vh+uxo/fIDRvVVhYdc9AxngRD4sZuCUTF26HCwXR+tq8CSaw6ogYUg4F5eAr1eeYf2i eUl6KeMmdD44yZtu6dbVi385PeE5e7qtOBLZDN1U3qwpd/lNLz1SM54kpWyG+3fkXvxPl76zjaS eKlfoSNbnT1xfMIxlFxTeiGvgAPB8Ksj10BmGOsE4XCi0/9hCowdARP4FAiUWBG3n43V+zqgpgR bs0fCLdn4DZ8RKx9F/mLl5ODuoLUNmBAJMViJRB31GOPQ== X-Received: by 127.0.0.2 with SMTP id cOoiYY7687511xsp5EUj790g; Mon, 22 Apr 2024 05:18:17 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.76]) by mx.groups.io with SMTP id smtpd.web11.16932.1713788296714510685 for ; Mon, 22 Apr 2024 05:18:16 -0700 X-Received: from SN6PR08CA0021.namprd08.prod.outlook.com (2603:10b6:805:66::34) by PH7PR12MB7890.namprd12.prod.outlook.com (2603:10b6:510:268::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Mon, 22 Apr 2024 12:18:12 +0000 X-Received: from SN1PEPF0002BA4B.namprd03.prod.outlook.com (2603:10b6:805:66:cafe::e8) by SN6PR08CA0021.outlook.office365.com (2603:10b6:805:66::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.34 via Frontend Transport; Mon, 22 Apr 2024 12:18:12 +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 SN1PEPF0002BA4B.mail.protection.outlook.com (10.167.242.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Mon, 22 Apr 2024 12:18:12 +0000 X-Received: from aiemdee.2.ozlabs.ru (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; Mon, 22 Apr 2024 07:18:10 -0500 From: "Alexey Kardashevskiy via groups.io" To: CC: Gerd Hoffmann , Tom Lendacky , Alexey Kardashevskiy Subject: [edk2-devel] [PATCH ovmf v2 3/5] OvmfPkg: Add AMD SEV-ES DebugSwap feature support Date: Mon, 22 Apr 2024 22:17:02 +1000 Message-ID: <20240422121704.200856-4-aik@amd.com> In-Reply-To: <20240422121704.200856-1-aik@amd.com> References: <20240422121704.200856-1-aik@amd.com> 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: SN1PEPF0002BA4B:EE_|PH7PR12MB7890:EE_ X-MS-Office365-Filtering-Correlation-Id: 3aa38878-f76e-4a6f-a01b-08dc62c64772 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?13OkpiMKJK7aOeSXXEPCMAqCM7svNkIQQX3K+0U3xRuyd588tXcz/qGCjGm3?= =?us-ascii?Q?0WRTeo5zVvSwkb5duScaCh7FbjzCjIsyVzE7IT/nNge6NAt/R3TsHrak4Rk6?= =?us-ascii?Q?S8BhdxtHGVaenXdqyCR0VNJcACrDpVwhEltihe+nHRyZuPHo5TZK0844fqnd?= =?us-ascii?Q?WD3Gs7dCGSsmGDwGAtDk9ds4Go3W66+q3tc0KKponAqoAxqcTdN8CR3L+hju?= =?us-ascii?Q?y6qVOy6HRR7HQCibmD/fQBYX14CYIWE9iCn3s9kFmsalqZdp0Te5Z2bRGr0O?= =?us-ascii?Q?vaLHsUaNLpSi+p+JDJWwaYGVxHI2WCValDYCXk1xfJWtpw3FTG8EvpghKZuW?= =?us-ascii?Q?eRNpO6nN9QEVbIw/yGnPuFUtC4Jqegf/RPuzO7ccN2+rt61DfS5KUyVAsmA5?= =?us-ascii?Q?kscnTIo99cI1Q0A1s3dq055FcCQinlekQzvkWYHmhRoA0LwtMSq2wFOkwn1F?= =?us-ascii?Q?qVCnFjeSVyV8N+J7+cUB2ljC/0CpfqrHr8SBU7gcP0n1t8LzWX+QIsxsAQ/J?= =?us-ascii?Q?mDl2pwQ4qkvItub3Iq5Ci4f3hcypGOWgQvqMWehxnOJ9mTwrA9t9axBJtzTP?= =?us-ascii?Q?l/XlLx4bY67/FuYZlXq7258R4XS9SFXb/clEZ7bg+B8tECTgfB8dmzr7p0yg?= =?us-ascii?Q?E7okYEi16a4JNDWxSd9fO4AQ5LEDVLFrkvaGX8bQukJiNW4hLlnvQGuAR5Dk?= =?us-ascii?Q?ngl+Zgdc3x3jl0Gb5J1rKXhHw5peiRNS7Se5McTR9wfVM6bY9K0qCJp7AD5z?= =?us-ascii?Q?58IgKmVLAsxum2eZ+hiw7pETfJVx/71sHXtE4BZq8TxMNfF9cs+IioiOKCey?= =?us-ascii?Q?XTqjBRNfdW4sciWq3fwPOTJYfhBoJfBcjYwtxBYSiX4WAOqo7oI8YlxFOio8?= =?us-ascii?Q?H442+rZeQ8mfji3jDhOQFbYhH0OJaAEZ9ZgOAhl2nb2Z3Enh8qYTPTjJjLZU?= =?us-ascii?Q?pGiV7WRM7Bg19dbN43Ou9l1iEXuWFitZmQJ6yyXWRVXrL0HWFM6OGPqa95vS?= =?us-ascii?Q?D9J/tkAzPMPS8tHWYVBy/Ea0db/YJmtCHcrysP+vgEZahXxOarmv+ZrRvJUg?= =?us-ascii?Q?aI+nn6fApbg69prIZ1XjHcuGSP8zsQsJsBTB+peAnkeYMVbAA2/Dw4A8q1Gi?= =?us-ascii?Q?6aWkEEUFbI9aMKQ6AQ92NAxR9t6UqSFvpoVohKCLU/SUx+9aPA8mn65hDBOq?= =?us-ascii?Q?Rb9xV7rFVANVxQvPzrh7Z0+xrChwjRkNUvoswnla0fneJBengW7SF8rSaUkl?= =?us-ascii?Q?bKwqE6LSR1Gm4pR6eyoRlxSojqRrVUWWEO3O3CD/k9X1LRgc0qk6ONC8y9J5?= =?us-ascii?Q?yfpNNhGiJJmspLN0wLs7W7A/ewI+RZ0dWqJ0XVHMi/EeZmt7zi1/i/fDhX6n?= =?us-ascii?Q?JgLY7lcGB1fgxuPBTmVzy3j1kv/A?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2024 12:18:12.0883 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3aa38878-f76e-4a6f-a01b-08dc62c64772 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: SN1PEPF0002BA4B.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7890 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 Resent-Date: Mon, 22 Apr 2024 05:18:17 -0700 Resent-From: aik@amd.com Reply-To: devel@edk2.groups.io,aik@amd.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: AJJnn9XwvvXm6SDiUR0SOcDfx7686176AA= 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=Jkil7d6m; dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io The SEV-ES DebugSwap feature enables type B swaping of debug registers on #VMEXIT and makes #DB and DR7 intercepts unnecessary and unwanted. When DebugSwap is enabled, this stops booting if #VC for #DB or DB7 read/write occurs as this signals unwanted interaction from the HV. This adds new API which uses SEV-ES working area in PEI and SEC. This does not change the existing behavour for DXE just yet but soon. Signed-off-by: Alexey Kardashevskiy --- OvmfPkg/Include/Library/MemEncryptSevLib.h | 12 ++= ++++++++ OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLibInternal.c | 25 ++= +++++++++++++++--- OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c | 19 ++= +++++++++++++ OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c | 20 ++= ++++++++++++++ OvmfPkg/Library/CcExitLib/CcExitVcHandler.c | 8 ++= +++++ 5 files changed, 81 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/L= ibrary/MemEncryptSevLib.h index 4fa9c0d70083..0fa86aecc38c 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -166,6 +166,18 @@ MemEncryptSevGetEncryptionMask ( VOID ); =20 +/** + Returns a boolean to indicate whether DebugSwap is enabled. + + @retval TRUE DebugSwap is enabled + @retval FALSE DebugSwap is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevEsDebugSwapIsEnabled ( + VOID + ); + /** Returns the encryption state of the specified virtual address range. =20 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLibIntern= al.c b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLibInternal.c index 4aba0075b9e2..79449096a388 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLibInternal.c @@ -40,19 +40,23 @@ AmdMemEncryptionAttrCheck ( IN CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr ) { + UINT64 CurrentLevel =3D CurrentAttr & CCAttrTypeMask; + switch (Attr) { case CCAttrAmdSev: // // SEV is automatically enabled if SEV-ES or SEV-SNP is active. // - return CurrentAttr >=3D CCAttrAmdSev; + return CurrentLevel >=3D CCAttrAmdSev; case CCAttrAmdSevEs: // // SEV-ES is automatically enabled if SEV-SNP is active. // - return CurrentAttr >=3D CCAttrAmdSevEs; + return CurrentLevel >=3D CCAttrAmdSevEs; case CCAttrAmdSevSnp: - return CurrentAttr =3D=3D CCAttrAmdSevSnp; + return CurrentLevel =3D=3D CCAttrAmdSevSnp; + case CCAttrFeatureAmdSevDebugSwap: + return !!(CurrentAttr & CCAttrFeatureAmdSevDebugSwap); default: return FALSE; } @@ -159,3 +163,18 @@ MemEncryptSevGetEncryptionMask ( =20 return mSevEncryptionMask; } + +/** + Returns a boolean to indicate whether DebugSwap is enabled. + + @retval TRUE DebugSwap is enabled + @retval FALSE DebugSwap is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevEsDebugSwapIsEnabled ( + VOID + ) +{ + return ConfidentialComputingGuestHas (CCAttrFeatureAmdSevDebugSwap); +} diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibIntern= al.c b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c index 41d1246a5b31..e2ebc8afcaee 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c @@ -141,3 +141,22 @@ MemEncryptSevGetEncryptionMask ( =20 return SevEsWorkArea->EncryptionMask; } + +/** + Returns a boolean to indicate whether DebugSwap is enabled. + + @retval TRUE DebugSwap is enabled + @retval FALSE DebugSwap is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevEsDebugSwapIsEnabled ( + VOID + ) +{ + MSR_SEV_STATUS_REGISTER Msr; + + Msr.Uint32 =3D InternalMemEncryptSevStatus (); + + return Msr.Bits.DebugSwap ? TRUE : FALSE; +} diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibIntern= al.c b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c index 27148c7e337a..974be9555296 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c @@ -142,6 +142,26 @@ MemEncryptSevGetEncryptionMask ( return SevEsWorkArea->EncryptionMask; } =20 + +/** + Returns a boolean to indicate whether DebugSwap is enabled. + + @retval TRUE DebugSwap is enabled + @retval FALSE DebugSwap is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevEsDebugSwapIsEnabled ( + VOID + ) +{ + MSR_SEV_STATUS_REGISTER Msr; + + Msr.Uint32 =3D InternalMemEncryptSevStatus (); + + return Msr.Bits.DebugSwap ? TRUE : FALSE; +} + /** Locate the page range that covers the initial (pre-SMBASE-relocation) SM= RAM Save State Map. diff --git a/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c b/OvmfPkg/Library/= CcExitLib/CcExitVcHandler.c index 0b61d28f8b94..9567c257217f 100644 --- a/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c +++ b/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c @@ -1625,6 +1625,10 @@ Dr7WriteExit ( UINT64 *Register; UINT64 Status; =20 + if (MemEncryptSevEsDebugSwapIsEnabled ()) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Ext =3D &InstructionData->Ext; SevEsData =3D (SEV_ES_PER_CPU_DATA *)(Ghcb + 1); =20 @@ -1677,6 +1681,10 @@ Dr7ReadExit ( SEV_ES_PER_CPU_DATA *SevEsData; UINT64 *Register; =20 + if (MemEncryptSevEsDebugSwapIsEnabled ()) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Ext =3D &InstructionData->Ext; SevEsData =3D (SEV_ES_PER_CPU_DATA *)(Ghcb + 1); =20 --=20 2.41.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 (#118091): https://edk2.groups.io/g/devel/message/118091 Mute This Topic: https://groups.io/mt/105668062/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-