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.84]) by mx.groups.io with SMTP id smtpd.web10.5683.1595366608553496250 for ; Tue, 21 Jul 2020 14:23:28 -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=EbNSUZYv; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.94.84, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GMvlXrDJPydwnfPOLDnLxGFyJygFTXUSsolbj29Icww6RWZjHONVX5i0UI+BtsXPBRaVMQiYQbwNrOqUt7ALabk8S1iFsHoqQbQa6xZaCQmbtP5YkIIRhdztHWLiYBAtyLPgZepoKKR9aroM/O6TC9a580kGbOL4MhijeGhiTOmjJuA2IlozstVgqwP13cx/9eLGcTq0xy9kaKywpWp1GnKAG7SG0M0xsmbM+rtN7J9naJTWhL5+RodQ2JEjYfgI4txaa202oJ/fLTm1qhvYYp8d+p6xb+37cHvxxGkTl1Ahm3LxPlXa7jGTtShdboehwmpS6x5SkW8FMEFv+ptWtQ== 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=OiOliDalNWCYhx7RaADIUj5Z8UgrTrAZ32oE+wLNZ1RyUBf0O0qFggOoYcq2/rpM/mMHXaYNiWOQofiKFZbfF8etZ00Zdhe8E6FjvGaQTcCePea/U7AptQjb4t3dgzbLYyzNcRPcZHPZtIYo5H4U+cFTQAzVLTU+chz7+ju0EPQ/Rh2nNveG+oOpTcs1KWPVqnkWbZ8cnPv9TFcEKvPsUHrdURnLCSdIQ7xqMtNVk+WNV5TRZsPRJro4C9mGkFYOfoCIPHtF0bfEDY4+IJKCrw6QJQgLoQ7GI8fAu9epAhicrKcvXTavaaycBjw12oLEfulykhwLCTBqMhPk7d1SHg== 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=EbNSUZYvBf98ve/8sdqbBu8Wh7FO843mIU6AJuau58V/jkWgY5mxiW9O0yI0Qnpflloa5M4RzwXFjeHLJFpQIfj8qPNQt4R+lukPjXYR5LGLRW2IM8KUnDdwVasfh68S8q08ae4mDcYkIyS5XV3dwaeeiWvDSuUa94Rl6BpKMhY= 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 CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:23:25 +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.3216.020; Tue, 21 Jul 2020 21:23:25 +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 v11 27/46] OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function Date: Tue, 21 Jul 2020 16:19:04 -0500 Message-ID: <9617a7ed9a01abdeb95a08ee56dda9c0f5fcbfd9.1595366363.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: SN4PR0801CA0024.namprd08.prod.outlook.com (2603:10b6:803:29::34) 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 SN4PR0801CA0024.namprd08.prod.outlook.com (2603:10b6:803:29::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Tue, 21 Jul 2020 21:23:24 +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: af69607f-6e6b-46e7-32ca-08d82dbc4dae X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: 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: 0IvjlwqtNEqjL0Hkdag2+UUCkWJeOZ6r99fXtXXZ+cFrcgWL9Ym45RBsG4+fX8JBSOLuxujdByt9lzigV5zVOJ/kihnWOAlEHEPPh1yq87/XiR/V6W5NLUgZ9ldOBUKMlVTvppMK0FnNFqzYDp0oxenf9cYgpa/hNEjW+aXbRPDI754sONaMd7XE+qjeNklMPByKaA7CEyUe/8RLZ49wS57T7LMKfgn0a7DAmOMeof/DJfB1I0bDHlRCeyPUtSb9gseGjqnLP6Q2uQ4rr6k6RVsJItUxv7a9+EJj12xt0iRf30Z6v6wC/c63I25ikajdWd3fQw+IYEOOZoA5EUimSI/VBTi99atB+oyuColGmnJiMa3HK+AHw8uZpfF4DIbhL7Sza6QglmDdwSYm8/y4qhdm2Lk8dDjwEKeY1ozJI09SskZj4F7rf9S7yl5z0NAt10lWeCHp9vpvty8Z/VeVfQ== 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)(396003)(346002)(136003)(39860400002)(376002)(366004)(966005)(6916009)(26005)(6486002)(86362001)(8936002)(2906002)(66946007)(36756003)(8676002)(16526019)(186003)(2616005)(956004)(54906003)(478600001)(4326008)(66556008)(66476007)(7696005)(6666004)(52116002)(5660300002)(83380400001)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: JgxnTVLEWOkcrR/c0by6If42Y0o+xC/uj5FF3bc9e6MYSwNyf6bNdf+73ggWJJhnm4IQVuuassYqFsfD0QAW5kUS/igA+9w/NbNo7WNLQTXcLP0Tw0CA9K6UrDWWIq3j8fwM2QoRsINwoMp3fEflu6/Z6Xv3J3tPRIUHwWI/DszmxFy/hRuD84yDE8ub/Ombnqw3l/LYxFR2IH7rkczHZct3IkZvzkTctsLZll6HFy77C/xTa55vP6KHYXAZGGq3zAJUaQ1E1ZcBnlMlPYVoMQeR6Dy29KDvBbn10B5NvsNe4PNDAeD1kvBd1UZM4SWMfwUmBfs870cSS/K2Q1cbekk3aPp02nhAKewptxkgpHogMGwqpx8buWJHGZACfNox02AFBTLfxCGRTDCLp3ix+uAO77a0NiRIK+Uf9oIVrNOiz+qONuCZCQCnzvKtel4aRS3mBsbqOeNPTb0HZpcfS3eFTevMFslQ1PxLHeVbtgY= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: af69607f-6e6b-46e7-32ca-08d82dbc4dae X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jul 2020 21:23:25.4827 (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: xD4hvXqd9rVqbEXoCrFtyeNcaoenMQqBkFfIvyLmp15/vxN4t/ZqXn78uT1u+D1NBfRHiMjc3qZIebk9h8D0hA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 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