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.89]) by mx.groups.io with SMTP id smtpd.web11.9962.1667924675275309978 for ; Tue, 08 Nov 2022 08:24:35 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=wT5y5+Jv; 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.89, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BRalu+ZeAew/KPOYZdMLlv5mH746Yn91JWnmNaPH6xjPmNgnZu5yGxu5VtWeSkO4lFDlcAYnMqEwTXBKSVhwV46zWCvtOIb/1hGM8gX2ssjlbHdt9OxxfH71GUbHImhqFWK0K2G1ANt6EKzkBvnOjg9t7iriFTn+8AWhw56XgDiqiTYxvHQFVZ/qUnaB7LMEk/68kafn4ecex6/Oxu+kRtGIkMjdRQbiE1ITucQV+OtOUo67XZb27rNrVINDtbpfk4m1Yg2GsnPowv3uMjzsKLXBX/tF07Imeg67R7gtG9dHlvC2cC39TmOOvU/QDRHIzuSh+JkdOOtgRtVXQRcyPQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=z44oPY6dWBgnP/eo5jKzkT7O52RxINWijwbDYQ5dUMw=; b=JxyhzE6q4Fnx2JtJqMCmGsDltlML5shY8y8GM/mSrqUGordcnx0kI8tmHnOz1oIF3wZICB7Z38sK8qLbGI8UJHe/7MZON4L9nk4ZL+pXoFhNrf8a9HWTubeXnXYJeIW7euvLq9M5gugDko3Nrwfr55KUCQUqZketpbUy79VqU7NcWkSUIN2VKTMEOd6AyOtRGcxY/ZQVTClaHXNMbK3x7+yPE501cg0p/PIkHdLcLCgNJBioADaFbHTbRGu6RcqivLuOpdAYFEowsAhxnyVcRxAy+cvrC19AOjHQ7Wy4PaIZK2HX4CatyF/vI0a+fhHWo+mQ5JMQnZVMAthvm/U1Zw== 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=z44oPY6dWBgnP/eo5jKzkT7O52RxINWijwbDYQ5dUMw=; b=wT5y5+JvbZv1SwwkYNWipvCbtdvRXm/+SEg8J9onqhSikxsCmrGGzuXTIVGEfStFxLXBZlB6UnzzM2vw5G6DVQjjRxf283dqC/FBjL24EgPvbqDVf0pcU4nyMogoG9YoVeLebIuba7Kb4oPCzGflWSQAIENOyIT7SmAHx68gIc8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) by BL1PR12MB5755.namprd12.prod.outlook.com (2603:10b6:208:392::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.26; Tue, 8 Nov 2022 16:24:32 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::4da8:e3eb:20eb:f00]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::4da8:e3eb:20eb:f00%2]) with mapi id 15.20.5791.027; Tue, 8 Nov 2022 16:24:31 +0000 Message-ID: Date: Tue, 8 Nov 2022 10:24:29 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH v8 1/7] OvmfPkg: Realize EfiMemoryAcceptProtocol in AmdSevDxe To: Dionna Glaze , devel@edk2.groups.io Cc: Gerd Hoffmann , James Bottomley , Jiewen Yao References: <20221024204114.2772064-1-dionnaglaze@google.com> <20221024204114.2772064-2-dionnaglaze@google.com> From: "Lendacky, Thomas" In-Reply-To: <20221024204114.2772064-2-dionnaglaze@google.com> X-ClientProxiedBy: CH0PR03CA0255.namprd03.prod.outlook.com (2603:10b6:610:e5::20) To DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) Return-Path: Thomas.Lendacky@amd.com MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR12MB5229:EE_|BL1PR12MB5755:EE_ X-MS-Office365-Filtering-Correlation-Id: abe04f3c-0265-4285-b710-08dac1a5b763 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: voeN3P4elFZYO0D/NrEwez2MWAHI7sSvujctD6PXwZ8IqcLlioXkhqtUM7heAfzkY/UWeecPdmMWlZ6Jda0MRKuOV+jF+B5YyvLH8hYly3P7B5uFp1BMbxKi4RoGYXEuXccOS+j8kIVITNznPgJVOm01rctx+DgBtokDv/IhPn2Kk9nXK4qkkhNwRVRsJL1iY95yURdK4a1p+jem/9zfvhL+oXyOUoTJTLi6G1haKnikji80qFBNhTcfnP3HZ43sQCzJu9zkZXb2a/zKJsJ+Rug4mv4zZkg+X6pukQ4w8surdtS3AIO0YPBLxRlD6MVZRSOlyugkaWWbakJsZkzSWl0wjh8e1oHUZdtdttZjKDVqBbIR6clTrIIkJxr1vPSrCrswp8U1WnGNsM8WMzydHgIZL5OIxouZeZhMxQm3zAey1XZT6RbNCxxB3VTC2aSSPKsEEdI7vkqUctvA8Y602nVOXvRqe5fcC5vLZpVcUlok4L79z8mDDqy9mT5IF91nzYpu8t1p4Fa2kHb/OpnB+d3R8EWrI4Lglg3GMmr/7i1YanhOEqeA/vp2rorJ1xb0Ea+mpimp++vujpb7RGhhHDw54Nwkh2uSpCcmz3G883A3rOjz/YIGJGlOeVg/aXI6ZoW1VRXTLua7mH7LqjDFxF0ZFw2Msh1HkPrlbCInhDQ/3ZjcBpWTGH7c05GsLoviTFAtCJ2BEjd5E/Ou34aJFzegr/XQU48exfskHit1WqLbFjEYcMNxScBmPJV77yU46duENE60ov2dX6aNX5iK56pn8XQWP537ZZFlkVg+7P4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR12MB5229.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(346002)(366004)(136003)(396003)(376002)(451199015)(36756003)(31686004)(86362001)(31696002)(2906002)(8936002)(2616005)(26005)(6512007)(83380400001)(53546011)(38100700002)(186003)(6506007)(5660300002)(41300700001)(6486002)(66556008)(66946007)(66476007)(316002)(4326008)(8676002)(19627235002)(478600001)(54906003)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Y3N1UGxqMitYUEt3SnZrSmpwRDM1d1RWdkdXY3dzSjNBSjdtQU9KVWxNaEdy?= =?utf-8?B?cHc2T2tGMzdNamJNYjZKOHRWd2pxM3J6MUJuUDRZQzlPQkxEV0xOaWEyT0dQ?= =?utf-8?B?RHZITUFwdElpdFp6dU1ESnpjZEVVTUFNVVlyTHpiSUZtaStneW90dU5zTmJX?= =?utf-8?B?Vnl1dUdLVGplZW9wdWhDcm0yS3Z1ZUovb0F2N3pGVlhpbnVqN1c2MmtOZmFz?= =?utf-8?B?aHJ1SUpiQ3NEYWEwNTFkTUtzK2lPZmVFdkhSYzZPMmVxbGxBblA4TmVFZUVl?= =?utf-8?B?TzEvQmFiVENON0pVVzI2T2Z3b0tzSDQ4USt5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= =?utf-8?Q?Ee+iWttoBmOFg9BBWmAVbiD+T?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: abe04f3c-0265-4285-b710-08dac1a5b763 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2022 16:24:31.8126 (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: NPw7JjIvAcgG4FLbVsusNhnCEkjUbFJEGccqxr8yEUdSncKke4G+6EXy9iy8hw+WIOa9LLpF1ZprTx9v2CnhEg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5755 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 10/24/22 15:41, Dionna Glaze wrote: > From: Sophia Wolf > > When a guest OS does not support unaccepted memory, the unaccepted > memory must be accepted before returning a memory map to the caller. > > EfiMemoryAcceptProtocol is defined in MdePkg and is implemented / > Installed in AmdSevDxe for AMD SEV-SNP memory acceptance. > > Cc: Gerd Hoffmann > Cc: James Bottomley > Cc: Jiewen Yao > Cc: Tom Lendacky > Signed-off-by: Dionna Glaze Reviewed-by: Tom Lendacky > --- > OvmfPkg/AmdSevDxe/AmdSevDxe.c | 55 ++++++++++++++++++-- > OvmfPkg/AmdSevDxe/AmdSevDxe.inf | 3 ++ > OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c | 24 +++++++-- > 3 files changed, 74 insertions(+), 8 deletions(-) > > diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.c b/OvmfPkg/AmdSevDxe/AmdSevDxe.c > index 662d3c4ccb..f7600c3c81 100644 > --- a/OvmfPkg/AmdSevDxe/AmdSevDxe.c > +++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.c > @@ -20,6 +20,7 @@ > #include > #include > #include > +#include > > STATIC CONFIDENTIAL_COMPUTING_SNP_BLOB_LOCATION mSnpBootDxeTable = { > SIGNATURE_32 ('A', 'M', 'D', 'E'), > @@ -31,6 +32,40 @@ STATIC CONFIDENTIAL_COMPUTING_SNP_BLOB_LOCATION mSnpBootDxeTable = { > FixedPcdGet32 (PcdOvmfCpuidSize), > }; > > +STATIC EFI_HANDLE mAmdSevDxeHandle = NULL; > + > +#define IS_ALIGNED(x, y) ((((x) & ((y) - 1)) == 0)) > + > +STATIC > +EFI_STATUS > +EFIAPI > +AmdSevMemoryAccept ( > + IN EDKII_MEMORY_ACCEPT_PROTOCOL *This, > + IN EFI_PHYSICAL_ADDRESS StartAddress, > + IN UINTN Size > + ) > +{ > + // > + // The StartAddress must be page-aligned, and the Size must be a positive > + // multiple of SIZE_4KB. Use an assert instead of returning an erros since > + // this is an EDK2-internal protocol. > + // > + ASSERT (IS_ALIGNED (StartAddress, SIZE_4KB)); > + ASSERT (IS_ALIGNED (Size, SIZE_4KB)); > + ASSERT (Size != 0); > + > + MemEncryptSevSnpPreValidateSystemRam ( > + StartAddress, > + EFI_SIZE_TO_PAGES (Size) > + ); > + > + return EFI_SUCCESS; > +} > + > +STATIC EDKII_MEMORY_ACCEPT_PROTOCOL mMemoryAcceptProtocol = { > + AmdSevMemoryAccept > +}; > + > EFI_STATUS > EFIAPI > AmdSevDxeEntryPoint ( > @@ -147,11 +182,23 @@ AmdSevDxeEntryPoint ( > } > } > > - // > - // If its SEV-SNP active guest then install the CONFIDENTIAL_COMPUTING_SEV_SNP_BLOB. > - // It contains the location for both the Secrets and CPUID page. > - // > if (MemEncryptSevSnpIsEnabled ()) { > + // > + // Memory acceptance began being required in SEV-SNP, so install the > + // memory accept protocol implementation for a SEV-SNP active guest. > + // > + Status = gBS->InstallProtocolInterface ( > + &mAmdSevDxeHandle, > + &gEdkiiMemoryAcceptProtocolGuid, > + EFI_NATIVE_INTERFACE, > + &mMemoryAcceptProtocol > + ); > + ASSERT_EFI_ERROR (Status); > + > + // > + // If its SEV-SNP active guest then install the CONFIDENTIAL_COMPUTING_SEV_SNP_BLOB. > + // It contains the location for both the Secrets and CPUID page. > + // > return gBS->InstallConfigurationTable ( > &gConfidentialComputingSevSnpBlobGuid, > &mSnpBootDxeTable > diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.inf b/OvmfPkg/AmdSevDxe/AmdSevDxe.inf > index 9acf860cf2..cd1b686c53 100644 > --- a/OvmfPkg/AmdSevDxe/AmdSevDxe.inf > +++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.inf > @@ -47,6 +47,9 @@ > gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase > gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsSize > > +[Protocols] > + gEdkiiMemoryAcceptProtocolGuid > + > [Guids] > gConfidentialComputingSevSnpBlobGuid > > diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c > index d3a95e4913..cbcdd46f52 100644 > --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c > +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c > @@ -14,6 +14,7 @@ > #include > > #include "SnpPageStateChange.h" > +#include "VirtualMemory.h" > > /** > Pre-validate the system RAM when SEV-SNP is enabled in the guest VM. > @@ -29,12 +30,27 @@ MemEncryptSevSnpPreValidateSystemRam ( > IN UINTN NumPages > ) > { > + EFI_STATUS Status; > + > if (!MemEncryptSevSnpIsEnabled ()) { > return; > } > > - // > - // All the pre-validation must be completed in the PEI phase. > - // > - ASSERT (FALSE); > + // DXE pre-validation may happen with the memory accept protocol. > + // The protocol should only be called outside the prevalidated ranges > + // that the PEI stage code explicitly skips. Specifically, only memory > + // ranges that are classified as unaccepted. > + if (BaseAddress >= SIZE_4GB) { > + Status = InternalMemEncryptSevCreateIdentityMap1G ( > + 0, > + BaseAddress, > + EFI_PAGES_TO_SIZE (NumPages) > + ); > + if (EFI_ERROR (Status)) { > + ASSERT (FALSE); > + CpuDeadLoop (); > + } > + } > + > + InternalSetPageState (BaseAddress, NumPages, SevSnpPagePrivate, TRUE); > }