From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.72]) by mx.groups.io with SMTP id smtpd.web10.5571.1625057658135026392 for ; Wed, 30 Jun 2021 05:54:18 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=XkuLschQ; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.223.72, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DJaWCafMJjAM5A70+b6PYkWT56WjFkbpA0i8LNF9GQCqJqljtz9o4tJeh1mMmFcC+gWIWfhobbO8bCsBPFsPwdi1G8G4Pi/uiy1Z8f62+zbaAe/14fGYtp2QHV6GhiNkIn2YEvgX5pVX/A0DJTWjnnM1a5MM6j+jmaVqESMLtTi3QvrxV+fcJ8hgtmW93sMWJOWmlsaQQ6MsZZs79r1EkTOob/TSpSn7njx81l3yxdTaKkDo/SnEURHQRNzsK0tCp7aPgUgnAPEC8QlD3ODycJY4/pHy72vvLtUsAYW13NNxJg/YtH4ze+3idSsX4YxVDb/Ki77NfxgakHLyFmBH+Q== 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=NPv8YfpGhCBRXdslNfACTg5q1VaJCohOC88+QdWyUx8=; b=FujufaPkWaq7R1IgACxdG0eBaBr3aaVOKBQcuM1medDU9aYD0FAm+9/eRdK6gQqSUaKMOPRpqrBeGMfkLWTC6byuUNYXcrgZOJza5bBkptdFq9nTKs+Ma0yg2Xaf6C4M3GRqsUBFbdxZnBJiU6o7K3+3E3FpOg5i1KmtuyxXCMSOrjWkfriVusbCN9Yu5yFH4IxuwCMRTTBgOucD92aRDCr7sLzXGJmhLfhFRvANbvzkwaH5vqryQ2DKhhWRL+2LZIMyoBo1gmgAYbF4EIZnOhSOOSWVyd2iiHX+THs+0er9sjMDRbr5GAnhvi0fUVvd/GdMCS2fqcs6atyTBRX81A== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NPv8YfpGhCBRXdslNfACTg5q1VaJCohOC88+QdWyUx8=; b=XkuLschQqmostIPkFEeoqlXRVGmvtD2ZRX9NR4r3FKsKK13C2vyflHnwTBepoH+UeSOT3fhpKPSgGzq5t0G4b1LLRffJqKt43G+Bw5LSeN3D/nPnh4lpBOBqw2Y4wlEbM0kobUjtTxPKYyi42QKDlOWuPy4L+qkjKzHnqFczZDI= 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 DM6PR12MB2714.namprd12.prod.outlook.com (2603:10b6:5:42::18) by DM5PR1201MB0076.namprd12.prod.outlook.com (2603:10b6:4:55::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.20; Wed, 30 Jun 2021 12:54:16 +0000 Received: from DM6PR12MB2714.namprd12.prod.outlook.com ([fe80::7df8:b0cd:fe1b:ae7b]) by DM6PR12MB2714.namprd12.prod.outlook.com ([fe80::7df8:b0cd:fe1b:ae7b%5]) with mapi id 15.20.4264.026; Wed, 30 Jun 2021 12:54:16 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io CC: James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Laszlo Ersek , Erdem Aktas , Eric Dong , Ray Ni , Rahul Kumar , Michael D Kinney , Liming Gao , Zhiguang Liu , Michael Roth , Brijesh Singh Subject: [RFC PATCH v5 11/28] OvmfPkg/MemEncryptSevLib: add MemEncryptSevSnpEnabled() Date: Wed, 30 Jun 2021 07:53:04 -0500 Message-ID: <20210630125321.30278-12-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210630125321.30278-1-brijesh.singh@amd.com> References: <20210630125321.30278-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA9PR13CA0018.namprd13.prod.outlook.com (2603:10b6:806:21::23) To DM6PR12MB2714.namprd12.prod.outlook.com (2603:10b6:5:42::18) Return-Path: brijesh.singh@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SA9PR13CA0018.namprd13.prod.outlook.com (2603:10b6:806:21::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.14 via Frontend Transport; Wed, 30 Jun 2021 12:54:15 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bb5b9b3f-10c2-422f-29ce-08d93bc62af0 X-MS-TrafficTypeDiagnostic: DM5PR1201MB0076: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:196; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ux8t6De01nzeVLN9BOB/b3D0WvcCvxOpW4Su0KdbhRvb6OS3s6W5safM2kLuw1YbUMS+AMMMsYOhegSFpBsGxOVlxnqBTAxfmcf6jpUs0v2eLrE6StH3K0z13PM/vKtF4ijf8p5ZZzTNBurUYHho0WVU9Fd+ps045UNfxfV9SY2Llbr5RTEr4J/UBDG1N96xDIDbigcMVFE1iHby98IgX+8GfgwbYE63WN4M5KRF/SEglwvwbBHINgsk6Aole1ocW8m9a+rKHAxLfHsKcGngnMdV9K48vvZ8371XMBMrzifv64hBGFF9qX5MWDX91mVA0of2EdtZ6Za8IqWtzKSC5l3zUsA9w6ICBkU8fqQtoUifNl3ORa7hXCr/V9CyGuPUU+FYCfBviKsohhS5/z3dwlC7N5sT0SKbhizFcOiJvu21k7vWN9pmEouHMkDlwBqkPiPZN5RKrcJYaXM+isc5ldiwVPDKvLvXiIWXH06IfJHlumROOGd3pW1MhvJ6EpSr1wAdTcY3Cr6Ke7G7BN/LPCuxRZOeV2SLVS89oPYduMiRcY797ZMXnwzeQrLS6OnGuyq8TIA1CeSM85KITPN6mwx+BqDYJAhw6PMl36yzEWLhxAgA0vCUJfA0S10vWlJR9ljjHItuRAgSWFnQpO44ZRkr+HsZLlCqewL/ouMEjcNoDjKcfLXubYVGH9/bXmKgL21DkBlCyDRjH8CHA7Qg+vWGSse8cRxV2AbymeCYuiPyvq7tzmIXX0m8b832RIoVxJ1L2OKMeyNnqcpHH3E8ovTf0JPBv2gOt9jw+8cRATSWsW43kRcY7xeSvBUjPk2TDLD5xJJtkuovC9vsUn21la1tRS2q/CRHwK36Mp4h4I0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB2714.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(136003)(366004)(346002)(39860400002)(396003)(7696005)(1076003)(8676002)(16526019)(8936002)(6666004)(2616005)(4326008)(956004)(38350700002)(38100700002)(478600001)(186003)(6486002)(66556008)(66476007)(26005)(7416002)(316002)(966005)(86362001)(66946007)(52116002)(36756003)(54906003)(5660300002)(2906002)(6916009)(44832011)(213903007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?jL+FkcO5lhOdpw582ZBSMgQQXDbbM+cE1zoMt1ojbAMXN/Al890muyH5/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VoqzoryUZdD55VU5UWre5sqKs+?= =?us-ascii?Q?URFT69o9JSrQE8ricjzQ56oGPlgbvFcqNPANBW3KYg0Advj+hgxhAsj8adw0?= =?us-ascii?Q?XwL+M1a9M2lfdDAGy3FLMX9+HLpanitzSLMbnymaqP5q1IuXkGRMWgrCb6sq?= =?us-ascii?Q?FW01c4MbjJUngzdI4B4838zPX8EQUbPK3l6qZ6xKY/sXz92garxL7jzCRPGg?= =?us-ascii?Q?gxdO7jqNWt6iOai1Xohu2W2nZ+G/QQW5MWMI2bblo2T2/Rm6OoGo6jleqso7?= =?us-ascii?Q?xCoPoijRn29plm7m/SjUhKQxkx6ed7uZBW++UdlENLUlk+CaLrNzouEns7Av?= =?us-ascii?Q?nGWxVJrVZiFY8KtJhMVci6aEO/xsegSC1HSM+pmUYUJ4H2euqUkqpn9kNVL0?= =?us-ascii?Q?mOrb6ru3pzX3Fk7+NemKCfKV?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: bb5b9b3f-10c2-422f-29ce-08d93bc62af0 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB2714.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2021 12:54:16.2180 (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: kYfCMkzXTxxl/x1lmlm6Z4vHd1dfOLLxVBXx8HZtQODU+m5aPm9aNOtwuqZ7Ov6CZuPpUQnXoG5D1ClPKLk+lA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0076 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 Create a function that can be used to determine if VM is running as an SEV-SNP guest. Cc: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Erdem Aktas Signed-off-by: Brijesh Singh --- OvmfPkg/Include/Library/MemEncryptSevLib.h | 12 +++++++++ .../DxeMemEncryptSevLibInternal.c | 27 +++++++++++++++++++ .../PeiMemEncryptSevLibInternal.c | 27 +++++++++++++++++++ .../SecMemEncryptSevLibInternal.c | 19 +++++++++++++ 4 files changed, 85 insertions(+) diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/L= ibrary/MemEncryptSevLib.h index 76d06c206c8b..2425d8ba0a36 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -66,6 +66,18 @@ typedef enum { MemEncryptSevAddressRangeError, } MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE; =20 +/** + Returns a boolean to indicate whether SEV-SNP is enabled + + @retval TRUE SEV-SNP is enabled + @retval FALSE SEV-SNP is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevSnpIsEnabled ( + VOID + ); + /** Returns a boolean to indicate whether SEV-ES is enabled. =20 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLibIntern= al.c b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLibInternal.c index 2816f859a0c4..057129723824 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLibInternal.c @@ -19,6 +19,7 @@ =20 STATIC BOOLEAN mSevStatus =3D FALSE; STATIC BOOLEAN mSevEsStatus =3D FALSE; +STATIC BOOLEAN mSevSnpStatus =3D FALSE; STATIC BOOLEAN mSevStatusChecked =3D FALSE; =20 STATIC UINT64 mSevEncryptionMask =3D 0; @@ -82,11 +83,37 @@ InternalMemEncryptSevStatus ( if (Msr.Bits.SevEsBit) { mSevEsStatus =3D TRUE; } + + // + // Check MSR_0xC0010131 Bit 2 (Sev-Snp Enabled) + // + if (Msr.Bits.SevSnpBit) { + mSevSnpStatus =3D TRUE; + } } =20 mSevStatusChecked =3D TRUE; } =20 +/** + Returns a boolean to indicate whether SEV-SNP is enabled. + + @retval TRUE SEV-SNP is enabled + @retval FALSE SEV-SNP is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevSnpIsEnabled ( + VOID + ) +{ + if (!mSevStatusChecked) { + InternalMemEncryptSevStatus (); + } + + return mSevSnpStatus; +} + /** Returns a boolean to indicate whether SEV-ES is enabled. =20 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibIntern= al.c b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c index e2fd109d120f..b561f211f577 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c @@ -19,6 +19,7 @@ =20 STATIC BOOLEAN mSevStatus =3D FALSE; STATIC BOOLEAN mSevEsStatus =3D FALSE; +STATIC BOOLEAN mSevSnpStatus =3D FALSE; STATIC BOOLEAN mSevStatusChecked =3D FALSE; =20 STATIC UINT64 mSevEncryptionMask =3D 0; @@ -82,11 +83,37 @@ InternalMemEncryptSevStatus ( if (Msr.Bits.SevEsBit) { mSevEsStatus =3D TRUE; } + + // + // Check MSR_0xC0010131 Bit 2 (Sev-Snp Enabled) + // + if (Msr.Bits.SevSnpBit) { + mSevSnpStatus =3D TRUE; + } } =20 mSevStatusChecked =3D TRUE; } =20 +/** + Returns a boolean to indicate whether SEV-SNP is enabled. + + @retval TRUE SEV-SNP is enabled + @retval FALSE SEV-SNP is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevSnpIsEnabled ( + VOID + ) +{ + if (!mSevStatusChecked) { + InternalMemEncryptSevStatus (); + } + + return mSevSnpStatus; +} + /** Returns a boolean to indicate whether SEV-ES is enabled. =20 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibIntern= al.c b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c index 56d8f3f3183f..69852779e2ff 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c @@ -62,6 +62,25 @@ InternalMemEncryptSevStatus ( return ReadSevMsr ? AsmReadMsr32 (MSR_SEV_STATUS) : 0; } =20 +/** + Returns a boolean to indicate whether SEV-SNP is enabled. + + @retval TRUE SEV-SNP is enabled + @retval FALSE SEV-SNP is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevSnpIsEnabled ( + VOID + ) +{ + MSR_SEV_STATUS_REGISTER Msr; + + Msr.Uint32 =3D InternalMemEncryptSevStatus (); + + return Msr.Bits.SevSnpBit ? TRUE : FALSE; +} + /** Returns a boolean to indicate whether SEV-ES is enabled. =20 --=20 2.17.1