From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.85]) by mx.groups.io with SMTP id smtpd.web11.1342.1632163596175568212 for ; Mon, 20 Sep 2021 11:46:36 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=kjPIxWdl; 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.92.85, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qb63N2r8cWUzE1Fs4HnPXdBo/RBk4y3rQhSP29r8aV0CYTDvTVcEKPZ/ExveG5YNl/BojkVvuD6PpKs0D8l4Ppv8FOhR1zsMNSdFCUAjwDT/kn/ga12Gj8BaHq4uB8Fi65EOJvXp7Uuj6DKmM9vsRhW96+FYEr7N+jT8VydDeync2PuTUQvd3S8IUrkVePFUbgqWefVftnYcmJIhh0MxO2t8jtSLBECIvlW3MkdTk2VW/RUVC05+j0jWVM/6phl7LGxbVwhimQlFU86Yq3oRWepUkEDzPi2xngsadHIryicXYU6wffBLIB18ihakHEFd3sUwsqE2I0wJ2vQq0l02pg== 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; bh=v2Fx/75x/6c3x7A0PMVXdx4dTicA/iU+wOD3TCG65II=; b=YpQ2DuRcUnbUCJLS5bLCTeJyj2eGqhKXOSH9BVjC9k7+XUzgTvbwhrbMfQRQA1T3JL5Tz8ujl0zW0Bw0pPUOrHChXZJg4Cw+rhpQ3wVpe8LS8Wtvou29ZB5K3OZLpz7FrHR76olzOKjQ/dXLs3Z+AhwDpX6+d/zGoe5yt39DgPYGqOJJTUdu9AxSpdHXJc9YT3dL56YvBKhWw7aWfTRd/6JY+ZelZ7DsyyMvj9ax5+y1Qf67KNrErokc5lVz+pAScIqzqGk1r5ZfNUNRRjKJmZGKHXmFvY7OAt9yclWFBhe2iz6oU5F0/KsG/A/7ORSEx8E4y8bNqjScSaXSH1G87w== 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=v2Fx/75x/6c3x7A0PMVXdx4dTicA/iU+wOD3TCG65II=; b=kjPIxWdlf8eiC0Zb0Lnv5B2kNALBRiTZhqSPiCjDvHqxpAxraLSyA/duQN9iqeOW2WTfNVo9MRiFH5oTWebVTmZrGvS/cKPph1ca4tleGpEe5F0notwmMKHKQ6k45xlqF2Iir2o9OYlcPBswTHFHuEKqvkJT6ruvMftGrM0jiAY= 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 SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SA0PR12MB4575.namprd12.prod.outlook.com (2603:10b6:806:73::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Mon, 20 Sep 2021 18:46:34 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3%6]) with mapi id 15.20.4523.018; Mon, 20 Sep 2021 18:46:34 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io CC: James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Erdem Aktas , Michael Roth , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [PATCH v8 19/32] OvmfPkg/PlatformPei: validate the system RAM when SNP is active Date: Mon, 20 Sep 2021 13:45:51 -0500 Message-ID: <20210920184604.31590-20-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210920184604.31590-1-brijesh.singh@amd.com> References: <20210920184604.31590-1-brijesh.singh@amd.com> X-ClientProxiedBy: SN4PR0201CA0034.namprd02.prod.outlook.com (2603:10b6:803:2e::20) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) Return-Path: brijesh.singh@amd.com MIME-Version: 1.0 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SN4PR0201CA0034.namprd02.prod.outlook.com (2603:10b6:803:2e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Mon, 20 Sep 2021 18:46:33 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1c53bad8-965c-454d-c084-08d97c66f831 X-MS-TrafficTypeDiagnostic: SA0PR12MB4575: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vE1tNkvgj4WCFyBhuzk1ge69aUSnjE9apl8hpqUHfFI7xUB/Ow5l2Lve1VvKlAVwYfsb98EfHbd4S5Fk1XGJWK/MBsKQtjwIh8KK0LrdzddNTvIO7FT/h4MabiE6vDfQqWdTZIJqYIQRz6cYHbnKPK133h3BGwoo0UoiIlrZi9k9k0qceQPeTFb+p2uHywtz6UWQQhk7V1SHatnFZFl39jnBP30c5XL3SymT/bs7Ccuh/cCoRes2B4d8p2DJSOac+dwXOQsq1qqQ+kpqQ/So0E86iUdFwJZh/rl7QLE7M+xPzNuPv7hnYA/T2MiiTvUZsbd8RzVlUo9Nex1vHaSYovzj5cdKyNSqd3VmVqwmjNFmTioEEN6tPMg5VYdOUf/OlSugwfdgBkXAdeQYD2fnP4puQMF3+K1paZdSpbxs3EfSKjZA0PgD5bdPWHLxn4JqxGGL4iKqQAWt+j2f2fWfQ69SIL/eKVVwWJSLWj0BrtSZiKx6HKayiAtJ+2tTTrcgR4yyxfZC8FuPDpBDgVJSGbUl7or34BtaqqbgCXHARxgBYY+hfmvakgM95NThfsHOGGjV+b70vWoj3ga2e/RTW0ISP7Z9q4hlJ4C6TFeLAUXQprXJfdWjBy4cUkJPYzN58Qrr147dHQKiKEPDGHQoMIIqAixtDUIuPXhqqq6YpEHzo0sJ7ytU1C2DHVNBqkYwtUEEdJl2khRClVmxa0TRNfMF8XGXoAd7Sn28IrX5B8Hp8Ulw+B4JsexAkR978G5kY4f+mkC6Mkfu8VIp0kDqUA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(38350700002)(44832011)(5660300002)(15650500001)(36756003)(83380400001)(38100700002)(8936002)(66946007)(508600001)(6916009)(7696005)(52116002)(1076003)(6666004)(956004)(8676002)(186003)(54906003)(2616005)(2906002)(6486002)(26005)(45080400002)(316002)(66556008)(66476007)(966005)(86362001)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?T5VheRcTLy9E9AkLb2QPochgSUSTGzR4KoVVce01A0mOSjUew6YP6kCXlw85?= =?us-ascii?Q?F8xswU41/4Ewh7mktLTXx16eahRbcaC+eF59vD4vWIPPUhVnH+40Ln5XEeNK?= =?us-ascii?Q?E3OG+0R7PRqLzn7BFQP02HjbKI8/1rVJPC9r3LZVpjp6KnSffxYJX/VwGDoA?= =?us-ascii?Q?YmtYTHzWol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pqtTjkPOXzJ3MIdv?= =?us-ascii?Q?2ElQqLG5qvypGDHDchfaETJ/R/2Re2h1AihxuAjsGnXrk2eVC/022fE4Arjt?= =?us-ascii?Q?yGXgdOnO7xZNXG116/pxn2d0YBiuiv9L1Hxn8jwILCTHgtIVuJrIgk7T+J95?= =?us-ascii?Q?I40WULH0ChPI0j+NpdWvhfNOZbciUzLDlgUS3NyOA6MWIUW2VcuM/piAZ4dZ?= =?us-ascii?Q?OpJfY0X6LPYSv842cHCHwb0otLQqdrNr8SXiClNKwd4nBT/XW5K1MvoTlu0+?= =?us-ascii?Q?PJLzbjnQBxEyaVKWsXqqEXxJ?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1c53bad8-965c-454d-c084-08d97c66f831 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2021 18:46:34.5162 (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: 5iPXZ0SCYlx6GgdDlEBAWY0xxtQm+6S9ndRmJpk9Ve9TLjxPG5OFV4XXdRoZAe0YQvEt2uCqt5Z2X7flj+ZZnQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4575 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 When SEV-SNP is active, a memory region mapped encrypted in the page table must be validated before access. There are two approaches that can be taken to validate the system RAM detected during the PEI phase: 1) Validate on-demand OR 2) Validate before access On-demand =3D=3D=3D=3D=3D=3D=3D=3D=3D If memory is not validated before access, it will cause a #VC exception with the page-not-validated error code. The VC exception handler can perform the validation steps. The pages that have been validated will need to be tracked to avoid the double validation scenarios. The range of memory that has not been validated will need to be communicated to the OS through the recently introduced unaccepted memory type https://github.com/microsoft/mu_basecore/pull/66, so that OS can validate those ranges before using them. Validate before access =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Since the PEI phase detects all the available system RAM, use the MemEncryptSevSnpValidateSystemRam() function to pre-validate the system RAM in the PEI phase. For now, choose option 2 due to the dependency and the complexity of the on-demand validation. Cc: Michael Roth Cc: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Erdem Aktas Cc: Gerd Hoffmann Acked-by: Jiewen Yao Signed-off-by: Brijesh Singh --- OvmfPkg/PlatformPei/AmdSev.c | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index de876fdb478e..391e7bbb7dbd 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -23,6 +23,40 @@ =20 #include "Platform.h" =20 +/** + Initialize SEV-SNP support if running as an SEV-SNP guest. + +**/ +STATIC +VOID +AmdSevSnpInitialize ( + VOID + ) +{ + EFI_PEI_HOB_POINTERS Hob; + EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; + + if (!MemEncryptSevSnpIsEnabled ()) { + return; + } + + // + // Iterate through the system RAM and validate it. + // + for (Hob.Raw =3D GetHobList (); !END_OF_HOB_LIST (Hob); Hob.Raw =3D GET_= NEXT_HOB (Hob)) { + if (Hob.Raw !=3D NULL && GET_HOB_TYPE (Hob) =3D=3D EFI_HOB_TYPE_RESOUR= CE_DESCRIPTOR) { + ResourceHob =3D Hob.ResourceDescriptor; + + if (ResourceHob->ResourceType =3D=3D EFI_RESOURCE_SYSTEM_MEMORY) { + MemEncryptSevSnpPreValidateSystemRam ( + ResourceHob->PhysicalStart, + EFI_SIZE_TO_PAGES ((UINTN) ResourceHob->ResourceLength) + ); + } + } + } +} + /** Handle an SEV-SNP/GHCB protocol check failure. =20 @@ -240,6 +274,14 @@ AmdSevInitialize ( return; } =20 + // + // Check and perform SEV-SNP initialization if required. This need to be + // done before the GHCB page is made shared in the AmdSevEsInitialize().= This + // is because the system RAM must be validated before it is made shared. + // The AmdSevSnpInitialize() validates the system RAM. + // + AmdSevSnpInitialize (); + // // Set Memory Encryption Mask PCD // --=20 2.25.1