From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web10.38022.1639558390975340310 for ; Wed, 15 Dec 2021 00:53:11 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U015M1pl; spf=pass (domain: redhat.com, ip: 170.10.133.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639558390; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wG27O5Q1sT+/QMxi+ZzSVizYApeLLiEdPs1nTqfsYdI=; b=U015M1pllsMCrS6Of80zgIakYJDKsf4YJeT/fcZPcpWgPuFr0vJ/c5xHeD0RQBIdvTpJF3 a1YSH+GZp6ELVYC7pvXkKYDE+bxt81D+eNGC/pyNVrCIhy3aDnVnCSA/B2EhnE9qsOLl1J Z/g3QOj6PoQMq34PvYqTq7avRBdF0ak= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-56-tRXkFcqEN4ukTJqHH-ngeA-1; Wed, 15 Dec 2021 03:53:08 -0500 X-MC-Unique: tRXkFcqEN4ukTJqHH-ngeA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4249881CCFE; Wed, 15 Dec 2021 08:53:07 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.14]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DC74C10927A7; Wed, 15 Dec 2021 08:53:06 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 2AD43180039F; Wed, 15 Dec 2021 09:53:05 +0100 (CET) Date: Wed, 15 Dec 2021 09:53:05 +0100 From: "Gerd Hoffmann" To: Min Xu Cc: devel@edk2.groups.io, Ard Biesheuvel , Jordan Justen , Brijesh Singh , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky Subject: Re: [PATCH V4 22/31] OvmfPkg: Update PlatformPei to support TDX Message-ID: <20211215085305.qb6akg5nlxio4m2h@sirius.home.kraxel.org> References: <94bb5cbbb19bb7b14513082b386554fc59168eb4.1639399598.git.min.m.xu@intel.com> MIME-Version: 1.0 In-Reply-To: <94bb5cbbb19bb7b14513082b386554fc59168eb4.1639399598.git.min.m.xu@intel.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline > +/** > + Check if it is Tdx guest > + > + @retval TRUE It is Tdx guest > + @retval FALSE It is not Tdx guest > +**/ > +BOOLEAN > +PlatformPeiIsTdxGuest ( > + VOID > + ) > +{ > + CONFIDENTIAL_COMPUTING_WORK_AREA_HEADER *CcWorkAreaHeader; > + > + CcWorkAreaHeader = (CONFIDENTIAL_COMPUTING_WORK_AREA_HEADER *)FixedPcdGet32 (PcdOvmfWorkAreaBase); > + return (CcWorkAreaHeader != NULL && CcWorkAreaHeader->GuestType == GUEST_TYPE_INTEL_TDX); > +} fwcfg patch adds a similar function. Can't we have a single function somewhere, or have a #define for this check, instead of doing this cut+paste programming? > +VOID > +EFIAPI > +DEBUG_HOBLIST ( > + IN CONST VOID *HobStart > + ) > +{ > + EFI_PEI_HOB_POINTERS Hob; > + > + Hob.Raw = (UINT8 *)HobStart; > + // > + // Parse the HOB list until end of list or matching type is found. > + // > + while (!END_OF_HOB_LIST (Hob)) { > + DEBUG ((DEBUG_INFO, "HOB(%p) : %x %x\n", Hob, Hob.Header->HobType, Hob.Header->HobLength)); > + switch (Hob.Header->HobType) { > + case EFI_HOB_TYPE_RESOURCE_DESCRIPTOR: > + DEBUG (( > + DEBUG_INFO, > + "\t: %x %x %llx %llx\n", > + Hob.ResourceDescriptor->ResourceType, > + Hob.ResourceDescriptor->ResourceAttribute, > + Hob.ResourceDescriptor->PhysicalStart, > + Hob.ResourceDescriptor->ResourceLength > + )); > + > + break; > + case EFI_HOB_TYPE_MEMORY_ALLOCATION: > + DEBUG (( > + DEBUG_INFO, > + "\t: %llx %llx %x\n", > + Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress, > + Hob.MemoryAllocation->AllocDescriptor.MemoryLength, > + Hob.MemoryAllocation->AllocDescriptor.MemoryType > + )); > + break; > + default: > + break; > + } > + > + Hob.Raw = GET_NEXT_HOB (Hob); > + } > +} Likewise, I've seen this before in another patch of this series. > diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c > index 934d5c196570..9227fa260ccd 100644 > --- a/OvmfPkg/PlatformPei/MemDetect.c > +++ b/OvmfPkg/PlatformPei/MemDetect.c > @@ -36,6 +36,7 @@ Module Name: > #include > #include > #include > +#include > > #include "Platform.h" > #include "Cmos.h" > @@ -556,7 +557,19 @@ AddressWidthInitialization ( > mPhysMemAddressWidth = 36; > } > > + #if defined (MDE_CPU_X64) > + if (PlatformPeiIsTdxGuest ()) { > + if (TdSharedPageMask () == (1ULL << 47)) { > + mPhysMemAddressWidth = 48; > + } else { > + mPhysMemAddressWidth = 52; > + } > + } > + > + ASSERT (mPhysMemAddressWidth <= 52); > + #else Making this TDX-specific looks wrong to me. 5-level paging exists outside TDX too. Given we don't support 5-level paging (yet) I think we can just drop this and revisit in case 5-level paging support is added in the future. > + UINT32 Pml5Entries; Same here. take care, Gerd