From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com [40.107.76.71]) by mx.groups.io with SMTP id smtpd.web10.13522.1574280461461699248 for ; Wed, 20 Nov 2019 12:07:41 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=LZUTYjO+; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.76.71, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=buZuLHfILZ3ZBsTb47z/Oe983Cbxp0Lrc/VyHWgPIKDvYZnve/uSh6SoT3o6bh2NnofEp4sOBYUqrELb3S/d1Bd1o91iT93DYnKW5fk2PQ5mxqC71nEHLuHVVkW/XREv4ioKcq0XcdsaX9wxsv9RCnuAr9jOk6GiHDitc06yKk35hwV2wZBKNtlrHyycvzYw/hmgmuSIC8AOemUuFQKfC7D0hdPnKByc+SkjEES9VuBoGxI+mlyl8u+6QS05tpEdkDsNl8dTA/Dv/odD3rpz9jsR38XciCDHa5x85m+LxjNqCBg3RRposNSuz6tAummH0u+RabADbewfxa533JISAg== 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=WIsomzh7/gF8MT3ukg/aq6Y3tH6PpjMxCoTTI9GrNaM=; b=nG9StYFPpWwvoyu5/QWdDsBGPYAJsIV5zfyHJRnMqWVaUiuIeXYJi3e/OQUpc0uVYQoG6mlXrqcqmmA7WqNbC1roy4cCHsZqiVJF4F8gudLk85sT98+U6uEuY6Tto67dViAKxOEr/nXHMRueCTblDCY5KzHBxBnzRolAX0xu5Kbfl1MEZwXXKrWBF9ohlwvz1SiANSy32XRGcU9lfheeyalbg3qzbsVQfFYf95g2V8b35tYjyORgMxASZRlkbgXktsKJAxys3UP2zpT8BzrpWGAmwTlqmzAuySU9u50BxLi314efj+c+0/KSsZFhg7/xNR83JnVQVPqEoPdgSVBM8w== 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=WIsomzh7/gF8MT3ukg/aq6Y3tH6PpjMxCoTTI9GrNaM=; b=LZUTYjO+kev/9yAAxULcTxENXJzsEa3mTMXZ2oRbXbfcTu7tDy/uUtPlp3RBiLfRlMK7f3cvCDMiXoUciHegp5KMxaOJZgkpCWLvWL8pkTDk1ym93qR20O9ZCETMSSkeSuPra6k+YksBQCjvqbwMysiRMDsk7ORYyHdLMyHESr8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Received: from DM6PR12MB3163.namprd12.prod.outlook.com (20.179.71.154) by DM6PR12MB3675.namprd12.prod.outlook.com (10.255.76.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2451.28; Wed, 20 Nov 2019 20:07:40 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::dd0c:8e53:4913:8ef4]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::dd0c:8e53:4913:8ef4%5]) with mapi id 15.20.2451.031; Wed, 20 Nov 2019 20:07:40 +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: [RFC PATCH v3 23/43] OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function Date: Wed, 20 Nov 2019 14:06:45 -0600 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM3PR12CA0087.namprd12.prod.outlook.com (2603:10b6:0:57::31) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 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: 4bf1546e-ca2a-45be-47e9-08d76df54bb1 X-MS-TrafficTypeDiagnostic: DM6PR12MB3675: X-MS-Exchange-PUrlCount: 1 X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-Forefront-PRVS: 02272225C5 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(1496009)(4636009)(376002)(346002)(396003)(39860400002)(366004)(136003)(189003)(199004)(2361001)(50226002)(81156014)(81166006)(8676002)(2906002)(6486002)(99286004)(66476007)(486006)(47776003)(66556008)(25786009)(2616005)(476003)(54906003)(11346002)(118296001)(8936002)(316002)(2351001)(7736002)(305945005)(66066001)(6916009)(86362001)(16586007)(3846002)(6116002)(48376002)(14454004)(478600001)(966005)(5660300002)(66946007)(446003)(76176011)(36756003)(51416003)(6506007)(386003)(50466002)(52116002)(4326008)(6436002)(6306002)(6512007)(26005)(186003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB3675;H:DM6PR12MB3163.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A: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: CeDzRszxgA9WQVfLpKbtF8/Hmsdfn4EgyKQBYQ1yMTnWYf8Y4+pv7vK5bW4zf0wI/a8ShVVKf668a9PH8x1HbCD+wjhV8C7Zn0wbuWS8oDnfXAC8sBJe2XU58dZ0fwF7eR0D6AwR8IgBbZFCYGTnGN/llNjv0rawlWokFRxGd+uSKka7B8pqXwNoJhocJuUmsjikZpYebkl/RT2U7mtQEyJsBQhDNrDf8584xOo8S27gHSazdubUTxPPd9ozVFtayJmBcHv1pCtLfny/M6rJJJmffT/q01X2UsDDPp2Tl3M/7T4UeeZ70HK90l8kSSuQSupRdjxA3jqE68wYYeVVCzhF3W3MPDdEhxmsFJqO76rPQLJHCgulKKwnrKfZCuaD89g2EWYudsrjJqEqcGNHhWK1nT+H0iL5qepOmIfsq8J0dsIT5KMQM8LUJ6/HyYDZCXwDYTLSYArDLivfQ/KeLrM7jNjBczhoaPrIKeUz+jQ= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4bf1546e-ca2a-45be-47e9-08d76df54bb1 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2019 20:07:40.2727 (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: wD/vSF25CybT89UrvPqYN5m4ynqU1BGWjHC1SgwAlI4zBAI3+HDLq+yJKkviJQ1ONnGsHZO4lNus6rvYehwTIA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3675 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 | 77 ++++++++++++------- 2 files changed, 62 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..9c1d68e017fe 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,57 @@ InternalMemEncryptSevIsEnabled ( // Msr.Uint32 = AsmReadMsr32 (MSR_SEV_STATUS); if (Msr.Bits.SevBit) { - return TRUE; + mSevStatus = TRUE; + } + + if (Eax.Bits.SevEsBit) { + // + // 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