From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.694.1583190475799820802 for ; Mon, 02 Mar 2020 15:07:57 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=2MScR0jQ; spf=none, err=SPF record not found (domain: amd.com, ip: , mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kilkFx+9gnTaeXEdTUuHuzaqt+NrvBUyEmnSGHnjvwRpg063WByyF1W+uZHXjps9IYuE9lyIFmo98WNipPU1AbuKLb+rsWs/zvJzFVYQojV+RNEgXoWPNFg05k+zTE4TTapgvxDWe2x4bfoXWdJ+RIksMFxLq+M4VExperS/SKK6ZMGRZCf9ZpSLRXOJw/+QNJ+jANG2b3AEPIP9sYSeEKI28A3QHo/0i/DC4JykSUgmQksdjPPf+UI69q8b27mdlF90lfctB3EdV8ILLDnF4ybf0aZqIvPJkzM+ap1givi+WQwV0cst6BD99WDMPF7w0iyHKV87QhbW05ad04Pirw== 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=leVy/1jMt4vkgIwUhcvhFGhuHT6gyzYQe7pro2sMB0A=; b=EcmIOQNgq2zyddpjsx/2ueFdee6KikIS2L7cPOVcJIf7gWvmUKYpBAeOaZ/+2gbom+sLwCYhCe0Sm1jJg6CfsshcZytUoI8otkD2p5h24sh4W1+MmyyQ4bdyuW+eKVhAy6s0apwmQNAxcO6jRZNTkKmC9/1xUgWqDZ3FnzkZI3eI7vf1iqWzpUYMKqqUAsVj5ySCYT4RMrnOOm7RoWv3GwoWMbz3agDWYM93LpwEiWGvfsRrOHftXiFqUaAeqEGd5EB9UHWpnJUKCetzoYxNhMUuPBGpuj+V7jKnIIG+zuKnKHi97MO0hx56wJi+UEG1GkUwx2QulceLA/RmZfzntQ== 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=leVy/1jMt4vkgIwUhcvhFGhuHT6gyzYQe7pro2sMB0A=; b=2MScR0jQGKybVMK2S9DiVW3r0o5y8o4d08vorEDNuvbWWb8g9xFkIuPwU9YAX0mrnOCc+TchGK3hDNe0AnFC3x5uQVxOjWZXktTLFyz/H4SRpKa39TAPxTEqIAIqGsr53Ccq9WXW2eQ2B7VJ8CIXlho48rbZogC3wRWXC96xM+Y= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Received: from DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) by DM6PR12MB4201.namprd12.prod.outlook.com (2603:10b6:5:216::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.18; Mon, 2 Mar 2020 23:07:53 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::f0f9:a88f:f840:2733]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::f0f9:a88f:f840:2733%7]) with mapi id 15.20.2772.019; Mon, 2 Mar 2020 23:07:52 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [PATCH v5 25/42] OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function Date: Mon, 2 Mar 2020 17:06:56 -0600 Message-Id: <90437a20a8661bdb3d7b5009a088e3323a048014.1583190432.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR2001CA0013.namprd20.prod.outlook.com (2603:10b6:4:16::23) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) 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 DM5PR2001CA0013.namprd20.prod.outlook.com (2603:10b6:4:16::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.16 via Frontend Transport; Mon, 2 Mar 2020 23:07:51 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 79cb4546-dd1d-416c-449d-08d7befe88de X-MS-TrafficTypeDiagnostic: DM6PR12MB4201:|DM6PR12MB4201: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-Forefront-PRVS: 033054F29A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(376002)(366004)(136003)(346002)(396003)(39860400002)(199004)(189003)(66946007)(8936002)(54906003)(316002)(81156014)(81166006)(6486002)(6916009)(66556008)(8676002)(4326008)(66476007)(52116002)(7696005)(2616005)(5660300002)(2906002)(36756003)(186003)(966005)(86362001)(478600001)(16526019)(26005)(956004);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB4201;H:DM6PR12MB3163.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BKRnaAHxC2+XuPiqPYMKj9z/pZjrA9gFyP+6NIoYkKlh7BX/k/ns55+VqdXV4KCaKS9c24XGbIpkGKDqHtF8SVmYW3EBdHzCB1/NCksdIO19iRRCFpPo/2Wo5QRoCPtDuXXiYWjzfaU+HryUswLEdaxW1BDyvgkkoges7Jolq7ZW5b3Vh2LFryeFvsjCCL6qgqLKfNA6mJw2MIzJNuYzm5+8bMcVrqqiAZUABIPunFLA7G6Oz8f+7ACLuEnoEpUYYDZKeM9vaGqUunkbY/SvqkoYEWCsUANm43VKx2wLh+VJ97VcJ8agxasrW4WNBmW7O5FfLSvNZ/KWc9qQdKDkuM71djczUl4Ea+YN7xsqP1V2mmBILIl+l4Q359j5r0C7DD6/LKkn1wQh9JZAMG9xaicZr6o0Ma8WcdeLNz/IVNL9L+cnbmF5E9Y+0+E+hhI9cVtZObyfjr+DBbgOSFWYnAQ7yoAXaFVeP6tNySPYXLDnUDUfVvaSbqlGrAt0YKk6lgWZ1/HBW2XYSBWhCv7aRg== X-MS-Exchange-AntiSpam-MessageData: ztXSxnzAqVnHg87ZALwtmdjBzj5iwRzqWSZsfxUpJ3BtaIdDdxnfgKyDp6BRUIqmKJkMDaJHYG5luvOOFxVaflQMyrug3jh9CoCFXFkeFeOi8blkmdd0PjJ78uXLOurmTCkMi7hyWj8kdlAlhHaE5Q== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 79cb4546-dd1d-416c-449d-08d7befe88de X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2020 23:07:52.5581 (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: 0gO/fz/f3/5IxQJbY07b0YFiSZF+baWvDPNvtCi2eOzG2PFzVNjmoDTnGvNqBVqJW1M4dqUXIVl5HQGfv3KrGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4201 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 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/Library/MemEncryptSevLib.h index 64dd6977b0f8..a50a0de9c870 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -13,6 +13,18 @@ #include +/** + 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 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c index 96a66e373f11..c859bb141963 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c @@ -20,19 +20,17 @@ #include STATIC BOOLEAN mSevStatus = FALSE; +STATIC BOOLEAN mSevEsStatus = FALSE; STATIC BOOLEAN mSevStatusChecked = FALSE; /** - Returns a boolean to indicate whether SEV is enabled - - @retval TRUE SEV is enabled - @retval FALSE SEV is not enabled + Reads and sets the status of SEV features **/ STATIC -BOOLEAN +VOID EFIAPI -InternalMemEncryptSevIsEnabled ( +InternalMemEncryptSevStatus ( VOID ) { @@ -56,32 +54,55 @@ InternalMemEncryptSevIsEnabled ( // Msr.Uint32 = AsmReadMsr32 (MSR_SEV_STATUS); if (Msr.Bits.SevBit) { - return TRUE; + mSevStatus = TRUE; + } + + // + // Check MSR_0xC0010131 Bit 1 (Sev-Es Enabled) + // + if (Msr.Bits.SevEsBit) { + mSevEsStatus = TRUE; } } } - 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 = InternalMemEncryptSevIsEnabled(); mSevStatusChecked = 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(); + } return mSevStatus; } -- 2.17.1