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.6007.1675854580486067526 for ; Wed, 08 Feb 2023 03:09:40 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Zgz+bb6r; 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=1675854579; 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=tnbHLT+7nwXG7CJ44b/LbGWT20NHXVQHKZbZTzTmXBg=; b=Zgz+bb6rB4pNRht7Jkvst+VRdJ6jlHEUmU9CO65lP69LdoWztNHKrGjsT5KFmFCyhkJLP7 dMIzQsZD4TyoFE/FU4aLOZRYVCePmWBP4ohECCzhxQstEyM45DdABZben3U+HCSEiyPJE/ v9EjO8jCvZcwzTU6RWrX7toNiLWw48Y= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-148-IuEDm5f_OsK-VlHSwdr6zg-1; Wed, 08 Feb 2023 06:09:35 -0500 X-MC-Unique: IuEDm5f_OsK-VlHSwdr6zg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 65DA488646D; Wed, 8 Feb 2023 11:09:35 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.85]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A4FF818EC2; Wed, 8 Feb 2023 11:09:34 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 06A8318003BF; Wed, 8 Feb 2023 12:09:33 +0100 (CET) Date: Wed, 8 Feb 2023 12:09:33 +0100 From: "Gerd Hoffmann" To: devel@edk2.groups.io, yuanhao.xie@intel.com Cc: Guo Dong , Ray Ni , Sean Rhodes , James Lu , Gua Guo Subject: Re: [edk2-devel] [PATCH 2/5] UefiCpuPkg: Contiguous memory allocation and code clean-up. Message-ID: <20230208110933.bho5lybb6evnqcoh@sirius.home.kraxel.org> References: <20230207134939.273-1-yuanhao.xie@intel.com> <20230207134939.273-3-yuanhao.xie@intel.com> MIME-Version: 1.0 In-Reply-To: <20230207134939.273-3-yuanhao.xie@intel.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline > + AllocSize = EFI_PAGES_TO_SIZE ( > + EFI_SIZE_TO_PAGES ( > + CpuMpData->CpuCount * AP_SAFE_STACK_SIZE + ApLoopFuncSize > + ) > + ); > + Status = gBS->AllocatePages ( > + AllocateMaxAddress, > + EfiReservedMemoryType, > + EFI_SIZE_TO_PAGES (AllocSize), > + &Address > + ); Hmm? You convert size to pages, pages to size, size to pages again. Also you don't want stack and code being on the same page, so I guess the logic you actually need is this: StackPages = EFI_SIZE_TO_PAGES(CpuMpData->CpuCount * AP_SAFE_STACK_SIZE); FuncPages = EFI_SIZE_TO_PAGES(ApLoopFuncSize) gBS->AllocatePages(..., StackPages + FuncPages, ...); > +// > +// Union holds the relocate APs loop entries for different cases > +// > +typedef union { > + VOID *Data; > + ASM_RELOCATE_AP_LOOP_AMD64 Amd64Entry; // 64-bit AMD Processor > + ASM_RELOCATE_AP_LOOP GenericEntry; // Intel Processor (32-bit or 64-bit), or 32-bit AMD Processor > +} RELOCATE_AP_LOOP_ENTRY; I'm sure I've mentioned this before. The special case you have to handle is not running on a AMD Processor, but AmdSev being active (i.e. UseSevEsAPMethod == True). Otherwise it should be just standard Ia32 and X64, there should be no need to check whenever you are running on a AMD processor. take care, Gerd