From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=h9D06GQ3; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.94.67, mailfrom: thomas.lendacky@amd.com) 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vjUCEgWiruW32rdghdGFw/QPeneWsq53gmsGSiMfqdM=; b=h9D06GQ3rUMmAMVvzt0ABY4HB2Faq3VAZLOt1p7yH+FwoEZuawKCuinuXNgPOoWZqn/LKwTh4K/WF4enSmeTZDddXEHbgf0GzhzDjmGz6vSuGn3TW3big4sKT8SLogfeZrCL+vlMEPQ3xNcmSAJf/25vP19VEDXZb52UEcord0k= 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 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 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: [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> X-Mailer: git-send-email 2.27.0 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) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 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-Mailer: git-send-email 2.27.0 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: BCL:0; X-Microsoft-Antispam-Message-Info: Fx+i9Hq79NwjrWY92pS/I52i+klkmzkPL5NNHdED6WRAM8jvGbd2svApbXEAmEY12J89cjcNkmgBSOShq6cP3K1H2j4IJte4eP7BpnIxAAbiFLG+ldssAeu3hkKV7Rp/VqFSlqtHTQmdDP2MGCd0UAC/z3UcU06Hsq13cg+Rit7ZVRexrllDMcjrpFOk2O5qlNanmUDnBS2gaJiYPJbK2WiSyHucECH/rsowD9rFA+g2aY4SuwUfCPo/blUxefZZAAnFhpZ3IdFVea375KAnBZ4/hQWkJCYnguY3e41lNeFTHMhFVdDH9894cnrHopgc6rJiCDdEU54YAXh0vQNhPaxuQF1noG+IutO852jmiY69pYQadtQwK5K1D/A9SMnv+/alLpbGMG3TfmfbaXlfMLmi3EWL+QGjkXneLKvgYz4g4NkJBcPpqLiIoHaZERMucBg3cPUyc2lVA4/G/lAK3A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR12MB1352.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(376002)(136003)(366004)(39860400002)(346002)(396003)(4326008)(66946007)(6486002)(2906002)(66556008)(66476007)(5660300002)(966005)(478600001)(8676002)(7696005)(26005)(8936002)(16526019)(186003)(86362001)(956004)(6916009)(36756003)(2616005)(6666004)(52116002)(316002)(54906003)(83380400001)(136400200001);DIR:OUT;SFP:1101; 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 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