From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.62]) by mx.groups.io with SMTP id smtpd.web11.1235.1585071696689108433 for ; Tue, 24 Mar 2020 10:41:36 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=F4DYnQRm; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.244.62, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IfsfIgTJTHWGode9ov5amAUSxVIhQfhmwPlJJ2vaKw9/gZzC+3LhRPEApIIRmoLXErUeJg0+KRfJfZCu+TUEYIzU2f99t5om2rV4v5C+Sq0wO5S4n7MQ8oMCgEc0lfnZ/pCgoejI4a14h+ZL0nW0KVJfRn4ZtUMe5FKhFohXCV4Cyc/9UHIP7TMDx43MBZmGlOs4SFCRXXkWPNbkOkIT9J3dUXqrZiko/xEH++qWQAB7o/uw4UoblbTXMnaqKRzL8JTIhGagwaEPtt/h5hheiIO1HhrRr172/V4VVfGFC37vqW+4XkZ3kbZFACz5tXKq6TxUI1DFllR0baNXbtokqQ== 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=H4HzxrrBckTn/hybL545/j/0sbUAw33MTAmM3pIUWJM=; b=Codei7yDQ7ljFO8drH1ZpPq09SpRWQNXBn36TUvGhEBSwqOcq1GYovu0QvqUWfhCrTFHExBQngkimnhcgOSwZ1l8bYY4b/Nl6oQoO3KKX3sw1Ml6I+kZjhbsdSZkoAdzJ3zfw2ego0AWpWs8SvReM7wH8PdUeI4rGBZiifRJ+2cgV4PQOBRgz1mMPastIaQ6rMVLuPBEgySPa5i3aNevN/FIcj6DmKhfT0yRkV8KfnECGX3CR6YtUW+OBbsE7G0GiHF87Mwven802g4hi1j6LTMGvAibtdafGEovGyNpVcdRty4npnf8SFqoRp2TQyXU4KsL9O5bpwyc5q0fURiWxQ== 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=H4HzxrrBckTn/hybL545/j/0sbUAw33MTAmM3pIUWJM=; b=F4DYnQRmuM0N0VLFE20QMimDYyB1FWCjz+XE+jsjRT2EEXik6oejPjlLM5lnqBACXu9CMvCrCICjOA2FNw0vv78KYMSBaG5aIj8G5Z9AuqArKXUavSmyXonSo0L8AcAplSE1YDmLSpHXrtVbsJ/wVWUR5M7V+jqgKk8q3GsW3JY= 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 DM6PR12MB4027.namprd12.prod.outlook.com (2603:10b6:5:148::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2835.20; Tue, 24 Mar 2020 17:41:34 +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.2835.023; Tue, 24 Mar 2020 17:41:34 +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 v6 25/42] OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function Date: Tue, 24 Mar 2020 12:40:39 -0500 Message-Id: <89144824ba518024d1568e45ba66cba79a2d575f.1585071656.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR06CA0025.namprd06.prod.outlook.com (2603:10b6:3:5d::11) 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 DM5PR06CA0025.namprd06.prod.outlook.com (2603:10b6:3:5d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2835.19 via Frontend Transport; Tue, 24 Mar 2020 17:41:33 +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: f85bc906-c343-40a0-b716-08d7d01a984a X-MS-TrafficTypeDiagnostic: DM6PR12MB4027:|DM6PR12MB4027: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-Forefront-PRVS: 03524FBD26 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(366004)(376002)(396003)(346002)(136003)(39860400002)(2906002)(956004)(2616005)(5660300002)(8676002)(6916009)(8936002)(966005)(81156014)(478600001)(81166006)(316002)(36756003)(86362001)(54906003)(52116002)(186003)(6486002)(16526019)(66556008)(66946007)(4326008)(26005)(66476007)(7696005)(136400200001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB4027;H:DM6PR12MB3163.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords; 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: JQvcGCMNFFbHRcZ93AqAG4vVKWCBajxO/LkkLiKkUgolXyB7pyyZagGp4CfXRSpQPmUk6hhS79HyZ8S8wxnK9ShSkggeS1KH+ma9TIXdYjy60iAJQNCeiH5OKwzFjBYqNfxxlcr0syqXMvRUyhy/pB2E1O6zTJfQSL+LvrxqQJ9v3dF4WjHfI+exfrfhhMIV2do1KHvR05D/BRHJv4OKug8FS2pVCdshJ5MiCdFXI4L1tx9ACoNIHrgcZ9sLT5st3SaXoD8ETNBnDkNpH7GghNZSj8TUyo0/YRpt+xOueWcFsfcpxeAkxbgMprCp3wdK7c/PO+s3J7NnfmWAzhOvTTpOeTuWtZUNohg+mmb0Fgf/pZVdZjFUZxronDkzcZ4eU95Ob9WH+mJq/gIi+bmTzifZvqLktTvFidjGcsxVyzTEiRu3BRHFq3+/vR1ubJ2PRjqL4g2ChRyESaz38B7UJxF04/gE78usPFziFAFQmZZqtuTE12SV4TZDohiGW3q5Pk6DUIWoGYONJR5EVPnEqw+p6wy0RWxiBzzreiemsf7COYLb2CrU55/JkOjGsmfRBB+BVIV3AFk5JWBqnth/UA== X-MS-Exchange-AntiSpam-MessageData: +wuJqQ6vFItqFknhAvu0wAH6NItCWV7WJCGxq4ov5fD8fg6cOQ1uEo7RsqIkh65F0x/G7nlVZ/f3PJaKGOD78pSRAZxzqv/TNUKBFr8LmwEJVLEc8eka4bhWCVDxDGqKrRK3/xj0RojAqwETk/ctVA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f85bc906-c343-40a0-b716-08d7d01a984a X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2020 17:41:34.1163 (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: J/MwTzdIBaz4e2sNCcuxIxx/VAz98sIC0V6355cEc+SNiWEPlNDXrJT/rZmqBSWnAMarbXKGKyQvYYmn54qBoQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4027 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..933734fa4427 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