From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.43]) by mx.groups.io with SMTP id smtpd.web10.58373.1595863814959816186 for ; Mon, 27 Jul 2020 08:30:15 -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=oyuOKJdx; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.70.43, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SsukQ0NkJIToNPzOW3ly9LaI4OogTyohP+S51LRNh9MNx6RwqpIPQXCBt28X3rGYQDaPZATMsQYltGNK9SJs22aisvt00h+QLQVJsx4uuhEdY41yhMDIlx5lbE6aTqdLnCSzBlqnHBcYBoq/sm0G95O4GadrEn6oFhxIBSWPax3MX5QH6DDGTWixvoehn5DhLyp4Ss9Usy9VR0RpHDbZ2I1eXzQGN0wnFSVQkNYoeuVJqEhy2k7mactg42LyBGfevFAqBAdyyjvDdMjOSdaeFaFsuJll9866wA0RnOTuT7jrFjyeDkJKkOGC4p9yR7gk8mKntuHOcBJj453YRgOsNA== 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=EO9EKDfQd365ECE3kVoa5rDaXrHqPq1CE0RPmG0lVrTk3v2aRNdAwcDSgOQq8BrqixeaBuPV1687lQkgm8Su0TPCpYf+/6CjgJLw/5IOZvv59TQ1P+0f+ETS7NX17pqmEouunAJrkphNZQcutE4h4kqZvVI7efsFCQ1THaIGmHv7hUgtQUDFYeZOM4rnK7roreqBjIpFU++zPF/5/f5V0iT9LXY2OkpJ/gIxEbsQk7ih6l2MWq7HcL5E8aHA+kOrhxMDi/gDQRtXzaY1a4P4yjahuiS9DBR1pvUgGFbgC6KeZfyJfoYXjOuHfBRhqX+6ahujSgUYjcU4grkdiQutNw== 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=oyuOKJdxs2V6/tq0BigdqUFnDsuJ3O9HNkzv5+9q2keWKCffwNwgmI0va8UevKdNzoK07TPwhA/IwKYNlP0f1npU9QNFxX82czN4vqKVZdlaUKQf7rPNSyrXAbm6VCh8U0rqabyHE7Czv4zV+is063rPj+DN2rdq0ID49s2PpNM= 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 DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:30:13 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:30:13 +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 v12 27/46] OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function Date: Mon, 27 Jul 2020 10:26:08 -0500 Message-ID: <5640f7c2800169018ff262d5715078904e1dab72.1595863587.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: SN4PR0401CA0017.namprd04.prod.outlook.com (2603:10b6:803:21::27) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) 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 SN4PR0401CA0017.namprd04.prod.outlook.com (2603:10b6:803:21::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23 via Frontend Transport; Mon, 27 Jul 2020 15:30:12 +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: 60cfd652-8ca4-43ea-87fc-08d83241f4d5 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: l27UN4/BX1S2O8XZ8QclTERb5OPsRuwOO9zNtWtxjWc2BU9IipVOBKRYP0Utnm07wKnAVkum76T8i6r/qMyGlRz/ORJb4fN8IPWuI3B9bSZWYQDW9UAxkgNXIW1hw24gVjjVkARvAQ0vEtewEgrV/ICOqggEwpVSvie+4R2rVVCcy2FHGanR09jd2Yasd84xl05BQRIROZCxZ3cb8+JHa1WGvF6a/StNpOdJ0+/YMYMDPPegZvvLH5N32eikShki48+1eX/21uLFMo0m340ZvHOhZM2bd2ghjKSpQtLpNc3LHjm/Z05Fz0jBNaEStC7SJI/uJ8NxsNUSYiCYQTW9iyYg9M44oNBRKK20fqDCsmsUG2F5McVnliISWZLbnrEw+TGuQeFXqXT24UlSK+yVBpn3TbYFrf812KxkZukOgGH4jwVuPR5kLBpNoxNNigRP6bJJtun+eq9884uy2RgdoQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1355.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(376002)(39860400002)(346002)(396003)(136003)(366004)(26005)(7696005)(16526019)(52116002)(186003)(66946007)(2616005)(66556008)(316002)(36756003)(956004)(966005)(5660300002)(66476007)(54906003)(6666004)(478600001)(2906002)(4326008)(6486002)(8676002)(8936002)(6916009)(83380400001)(86362001)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: suL2PbosIdk3ur+N/Gh5GvhIWKusgmWVWXi9i/WlHBCPAZu55zRK3NUdexT7CDpeW8/+oKCSyG/Ov6wWeltAND85YxZ91CfsLptGd+LBmMtv0rJZ4SXrWHy0yJDQKjT/x0I1vcTus+kUZXL4NX57K5RrWZNtnhu/ppgHu84IMXajxTZJSx5HF2A/fV4OZz/U/C4CVzh5X16XHpaR+bOwfQ+5aY+MTm2dtHHjdtCgl39HxBr+PGW82uWoxyVgJ+ua090oSFHF2y8tv3FLKBKbEcnOUYAS/P/4LbIsP3Ks+VCMl3eZ0rKqdcrm2uL6aAf0mKKpE8IDs2BzEftuQpCmoDEA14PUP/6JZU70VcsaGFWudn7iIbms5BqfuUYY7zwhOuPTsYkfpo8r2jgK0mO2TbVYuHLq1bp6kl34IbHQpwVu8ZEsjQ//Tisi1wNwtE6oNYH2ENSn0rDmEKrdGutSfhNrdNBD9/Utuc1gwYHh+Ag= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 60cfd652-8ca4-43ea-87fc-08d83241f4d5 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:30:13.5882 (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: qXOlsKg9+4KXDlqWPe7UaPJlmW2QsTmCHpmlQbhnqTGqYXLmHa37ry7nLacl/fXWcFTaan+t93ax31BlhLGHdA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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