From nobody Tue Nov 26 00:16:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63869+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63869+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1596829405654123.01147908617963; Fri, 7 Aug 2020 12:43:25 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id hfF2YY1788612xFo2qv0KOAM; Fri, 07 Aug 2020 12:43:25 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.67]) by mx.groups.io with SMTP id smtpd.web12.4256.1596829404306541511 for ; Fri, 07 Aug 2020 12:43:24 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lz1dOpzimStkRU4ijs26Ac6YGFZ9+yvrhE6oDTKrLqaPDcbHeOKTvTY3oXLtYpOVriJiqReS28qf3W8kwYGpe3hTpul+LdDmxEfMdRdU3MBI/5XLJcJ83IOY/Sx5ofGlmVf0VoVt3CsHRLhzg/s7IJIw6PpVS9SIJsrSGE2Lug0xS1fpoWfxl1ExnPTcjyEyjczBIPkkfjHR8YH9X91hQSzlcDN+6CekvWsoq17fayfDCYoCevy7UzvTG5Zr1rxP52iFWbFy7sxZTFL0jdUaW7V+OE+2lkrkIlwZ4XwZ8Y5F8PTn7Ow6iuIQJ8nI84a0y9BySOLQ+jM9eot7+RyXKA== 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=vjUCEgWiruW32rdghdGFw/QPeneWsq53gmsGSiMfqdM=; b=KnDUU0zcxo3fgSGNmNHXjAmpTtSD6Fwq5u5Ew8/xWvZr7kXT4tNVQHHHQqVYoqHEk+W9+KcZQdfWP54DtTCytANvQF5C5YZM1B8FbX561dx3dyL5pMHBc70UwEIXsw8cNJ+eaix1YD5nL+kOMpskqA12fpaawrVOJnNsxuzTzcuB7f6FXu/fxFNo/5VkljGAk8gXL7iY6LtErBCKfPlvNRNv7WihJDAzVCY/YTXEH7J1Oq+IvCzeAQpmcw3O03Z2evkWjOvUK5FvRn180YMotBspNg+GH5CaMcCq6Cx/2MN2APwylL+1KV8gcZwXxV4LIu54MGSKWPS1FowS3LKlfA== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:43:22 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:43:22 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v14 27/46] OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function Date: Fri, 7 Aug 2020 14:39:12 -0500 Message-ID: <1b94a7937c6fd60471ccd4b0b88dfe9b60330664.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0024.namprd10.prod.outlook.com (2603:10b6:806:a7::29) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA9PR10CA0024.namprd10.prod.outlook.com (2603:10b6:806:a7::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 19:43:22 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: eefd27e2-874c-450f-4bd6-08d83b0a24e1 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: Fx+i9Hq79NwjrWY92pS/I52i+klkmzkPL5NNHdED6WRAM8jvGbd2svApbXEAmEY12J89cjcNkmgBSOShq6cP3K1H2j4IJte4eP7BpnIxAAbiFLG+ldssAeu3hkKV7Rp/VqFSlqtHTQmdDP2MGCd0UAC/z3UcU06Hsq13cg+Rit7ZVRexrllDMcjrpFOk2O5qlNanmUDnBS2gaJiYPJbK2WiSyHucECH/rsowD9rFA+g2aY4SuwUfCPo/blUxefZZAAnFhpZ3IdFVea375KAnBZ4/hQWkJCYnguY3e41lNeFTHMhFVdDH9894cnrHopgc6rJiCDdEU54YAXh0vQNhPaxuQF1noG+IutO852jmiY69pYQadtQwK5K1D/A9SMnv+/alLpbGMG3TfmfbaXlfMLmi3EWL+QGjkXneLKvgYz4g4NkJBcPpqLiIoHaZERMucBg3cPUyc2lVA4/G/lAK3A== X-MS-Exchange-AntiSpam-MessageData: XADU0wUGJ+hZ1Tc0NLlKnTJsLE6l8/8xYPa0Xs48LpT0+Ob6euoPlKBl/1Zpuxhv6r/Vxb8AUf4ZjzTguKeoiYW9+GUvf8mKJaW9xcI3S2fuLDnFFQ/CQ8ER6Yv8c0MeUguuKbulfNWiIP+9wmQ7GJUoRtfEYs0yv/ik0+uxP7I07l6j8nNDcGxJZSlAr0/7NTylm1FwVB5YVn72wdZ0CAUcatC2IdVgdB70uaDwPApkwh2l0VPPfGOf0aM8hd4LeT3ZxRbXQUNLdEQOgyFe7n3CkwsrObUOv3d2sAnoE5MBNyZfAJ7O6gp7F4eGfnOy3FGkdfaUfdx5q40fElFE3c3NKX5YrCclinKndhMvi/rWCw0OWVUKmE8V6IUMq8NvvaueNDugvPcgWAoEruQCNuaDao+/Wd501f/TF1Y+fogG6XsRJYJPoow2GXH+tr2tIy2Eby7XBObfJdnp1DDYnJae22rm5G1lunfR7ILkzvGF1kZ9gE5DLZE1qcfT5Gg9jPItXiOM3VbC16DBi1GE3kW5qNGLALuthoxy2lhI8p/OaK+6bUL/JMeE+XZxqGLYSheFhVddvo2LCLPoXs0vZgikvvtgUUm2XihyQMHA8ZCkKeP7KuPLpNd/xa+PTjD+JYtXEsxJEWNEdRFUnu8lrg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: eefd27e2-874c-450f-4bd6-08d83b0a24e1 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:43:22.8980 (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: 5xgKsSR/M/oWS/jQVhHMh9xVPlXBJoOl3Zch2yD1vmgXEJBUCTnQeP6K1kTvZ1LoniQytL+pvfuXNRqoCI3zcw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: Kl3eujr7w2BphbqzQM27zPAHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829405; bh=iuX20JfpO7+0raLKw8ojoAYwRvUWida3/ZUlGXno+VQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=iohiBdNGa2ZxARbc6JBUcySakzbmeGpPr6k8KZjmZv2cfX4y1t973cbqIXP2mj3ErTI oeal6xbhJnIZQfg1uAOEfqU5aJc4rCcdxZrAXvrLlXZlGwWtfSv+z5/lT6AMdBHWSWYD3 47SCHXpkolc22GVQUJSPsJwWcd/8xsBU5fQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Create a function that can be used to determine if the VM is running as an SEV-ES guest. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Include/Library/MemEncryptSevLib.h | 12 +++ .../MemEncryptSevLibInternal.c | 75 ++++++++++++------- 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/L= ibrary/MemEncryptSevLib.h index 64dd6977b0f8..a50a0de9c870 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -13,6 +13,18 @@ =20 #include =20 +/** + Returns a boolean to indicate whether SEV-ES is enabled + + @retval TRUE SEV-ES is enabled + @retval FALSE SEV-ES is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevEsIsEnabled ( + VOID + ); + /** Returns a boolean to indicate whether SEV is enabled =20 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.= c b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c index 96a66e373f11..3301c5c2862f 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c @@ -20,19 +20,17 @@ #include =20 STATIC BOOLEAN mSevStatus =3D FALSE; +STATIC BOOLEAN mSevEsStatus =3D FALSE; STATIC BOOLEAN mSevStatusChecked =3D FALSE; =20 /** + Reads and sets the status of SEV features =20 - Returns a boolean to indicate whether SEV is enabled - - @retval TRUE SEV is enabled - @retval FALSE SEV is not enabled **/ STATIC -BOOLEAN +VOID EFIAPI -InternalMemEncryptSevIsEnabled ( +InternalMemEncryptSevStatus ( VOID ) { @@ -56,32 +54,55 @@ InternalMemEncryptSevIsEnabled ( // Msr.Uint32 =3D AsmReadMsr32 (MSR_SEV_STATUS); if (Msr.Bits.SevBit) { - return TRUE; + mSevStatus =3D TRUE; + } + + // + // Check MSR_0xC0010131 Bit 1 (Sev-Es Enabled) + // + if (Msr.Bits.SevEsBit) { + mSevEsStatus =3D TRUE; } } } =20 - return FALSE; -} - -/** - Returns a boolean to indicate whether SEV is enabled - - @retval TRUE SEV is enabled - @retval FALSE SEV is not enabled -**/ -BOOLEAN -EFIAPI -MemEncryptSevIsEnabled ( - VOID - ) -{ - if (mSevStatusChecked) { - return mSevStatus; - } - - mSevStatus =3D InternalMemEncryptSevIsEnabled(); mSevStatusChecked =3D TRUE; +} + +/** + Returns a boolean to indicate whether SEV-ES is enabled + + @retval TRUE SEV-ES is enabled + @retval FALSE SEV-ES is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevEsIsEnabled ( + VOID + ) +{ + if (!mSevStatusChecked) { + InternalMemEncryptSevStatus (); + } + + return mSevEsStatus; +} + +/** + Returns a boolean to indicate whether SEV is enabled + + @retval TRUE SEV is enabled + @retval FALSE SEV is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevIsEnabled ( + VOID + ) +{ + if (!mSevStatusChecked) { + InternalMemEncryptSevStatus (); + } =20 return mSevStatus; } --=20 2.27.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 (#63869): https://edk2.groups.io/g/devel/message/63869 Mute This Topic: https://groups.io/mt/76056555/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-