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.82]) by mx.groups.io with SMTP id smtpd.web11.1820.1596134910779388931 for ; Thu, 30 Jul 2020 11:48:30 -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=ccF4UWiZ; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.94.82, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gJYp8Qs5XKv+irujV4WhSnY+JUYIfHz2LgnMkNcn44py1xOC9aDk03tveLcPgK4nDyoa1DMo3O0/IRhh6cZB6Ss8sq3XEbvFqO9H7yCsP+vJEjx3nDBM5w/d4W0yIMx9zsJa+hj6G0GLc2epeYYVsHyGwPDNjJDV8kVFamzIRMXAAsEJ67ruEdfboluHZF8e+OngVHhUGl6q6eRcKrS5CPNUzZXTdX4enNlaFAvMfxTnZ0NqlzvDV0wKfllBim3q434zYWdiOizm52VPcyTZds3f+LwI+Xi/XHsvt/Yv+bw+lHpWnt7yF4XRVAxwJI5XCGu1JCQPU1dBuiandkkQgg== 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=djevNalRRaunaPaN2OAdIuC1yIZcVLbLgEPeAz0ruVZYq9W1hhIcQ0sNsDEkTYJxM46m/t8TawSwcICqBphIl5B8jlm8wq/uaY+wQFE4qvJYy3FT/zagLqgRrJqMqhV5qjT+FMuLyxukjL6T8G1ddLa4jjxzd62qTfYtsPb1KgO4n+cNbwKMAWax7WrnzQOGAaHF8hhMBq7DFcfXnWtLDvQSGUQaStCUGLiMI/jikwp3Cbmt5+Pn6ya+ALwFTpkr9M20COinhP96bHB3SGiPfuCGIRi11CPjpWkJ1x6f0KNUBrU5Me9ZcAK/dECajMBYmOUVWhxJU1e6eppen1z1Nw== 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=ccF4UWiZVXAQS3FIzejYBsCUEyPG7Bw9xCljh8bzOkyC/WYd1FoW8a81/z9Aa2pX+yTmPFCx/6/4BGNsT0mP/DtCCde6mU1/ErANx1ZR5yT10rwFHKgI2Q0HAuCLhTQC3TyzKl5gSh4CF3eRauMmTtZ7crLhgZJqAqzZe74Oo7Q= 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:48:29 +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.3239.020; Thu, 30 Jul 2020 18:48:29 +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 v13 27/46] OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function Date: Thu, 30 Jul 2020 13:43:39 -0500 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM6PR06CA0019.namprd06.prod.outlook.com (2603:10b6:5:120::32) 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 DM6PR06CA0019.namprd06.prod.outlook.com (2603:10b6:5:120::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.20 via Frontend Transport; Thu, 30 Jul 2020 18:48:28 +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: 5f3c2afc-f3c6-4f65-d252-08d834b92674 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: PNirAce/SojRV2ES85L5ZDg/treZZ4voqYbJnwk+ydpROEAQB2sQkqwQNrSsa/sadVYccLN5pEVwnjNxe5gzOjk/An4Sriv6c3buSZwzrDVXjOl0xfHW5KFgacLHo0glQPj1dSLCyB83CFnNx15ketuPPqMJDaJpqV6+IQJCzh3RhxVuU3E9eqc7SjQ19II14xMgN1SmIAm902XoT9RsWnpkEX76+LytY5oWpBzt5kiDjuhtsHt82Buh/Gc9C2tVzjl5IJ3ohrtX43rqeZCj1r1xwROG+naM2Utg3n6k9NnzNnkPJVQ5wb0CVuzCSd42Wazd0VSz+QfbUA3aNHu6eNwz9SCA2FNsTBPxEQOJwltMLhbHn3T805dAiWvO144C5wB1/eLbQ2r5zdND714hCE/ixeHxIIuHbrf/R+WmE4J6Rg94g3KSpbGynD1Diu+4bDwQJJud8FTUPpkB+9+yJg== 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)(366004)(346002)(39860400002)(376002)(396003)(136003)(6486002)(52116002)(7696005)(26005)(5660300002)(186003)(16526019)(54906003)(66556008)(4326008)(66476007)(66946007)(316002)(6666004)(86362001)(2906002)(2616005)(6916009)(36756003)(966005)(8676002)(83380400001)(478600001)(956004)(8936002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ch0fbMtvkxCzMQ3atBb5JSRB37ttm9C6w2y9m3/rIPxxdmfP6z/Sn/qpn8it0YQHdcWHRvuQCKuiN07mFeMZVeGY3EPI1FaG39kXwNMxtrSYvwU7nG29r4uowqha9QiVGpeoyWGtV3Uvp+Zp1pjhYW3x6vF7vaxJxbXb0xCOrWBRCuXtneInfhh6SUeN1qIPDxkC/bJ58+FRXhWU0mM7lJJbfIHXdmmoBVghGgkiq/vsaNGYGTLiqCxtz5j/btBv7/8bmyZ7vfT7kkp/BFxgh+rT56qHGBstjyypvvOr+4qZAhpVwbamqJ5DgWSO5O46kwVYeYHC5qNfO4Q1IXlLaNWS4l95aJXtEUc0kqjCC31jAbkUn4xyM7C94PwqxpIUcVkJ9IUbR6q/ZIu/RWjKuxldwDQHOqArQGqiqFjdmCRV0qLCtKRMj8m9TP2RD5ZPDYlLtXX06+hIrwh7JiS5hH5XjrgFuzBR0SMd2t/XtuwLI/MlIuJ4yD/owLd1Y83PLh3Du/sgurQqSPejhLT3WeNnUt4vft7zgWUd71LiaGTDYSoKhwYPZxWGFggSaN3WtPxxftOTAmFnj9QFYN7cpX/PYjlbtxZBTGKJmHCySyIt75Zomj8JekSFZoAtYG3G6jowjCbVh19YUA4um6eRzw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5f3c2afc-f3c6-4f65-d252-08d834b92674 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:48:29.5667 (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: J1eAn8M3+in+7wZUa2t1C3NCN57ShF+CUbrSizcnOIlieCZ4/u4b1s/MkMFTaO49nZRzmHoJohzS9z4oqdWllA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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