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.129.124]) by mx.groups.io with SMTP id smtpd.web11.194619.1673957643517709388 for ; Tue, 17 Jan 2023 04:14:03 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Na85/b0A; spf=pass (domain: redhat.com, ip: 170.10.129.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673957642; 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=U0yTGARcbAQoJjCTxvFobewA6tS5i4dBjAi6Gn20fe4=; b=Na85/b0A1o/B3/ckJLa8YpLjO+56yQ9aXbf0YY+fcEyPpLcqkFljQLWIt9WUJTfIn73Mbd 1cBbFhh7Y9U3F5vQDWxy3o2UemqwXM06D3up4dHal9IiSDlAbbYFjlj1qYqvDJKp/DRFDl f5MZU18wF1vdzKr5CZY9rrahCuY0d38= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-563-Ocz5siutOCWMFK2oXeUEYg-1; Tue, 17 Jan 2023 07:14:01 -0500 X-MC-Unique: Ocz5siutOCWMFK2oXeUEYg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F270B3806631; Tue, 17 Jan 2023 12:14:00 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.124]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C33CF14171B8; Tue, 17 Jan 2023 12:14:00 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 5B2321800097; Tue, 17 Jan 2023 13:13:59 +0100 (CET) Date: Tue, 17 Jan 2023 13:13:59 +0100 From: "Gerd Hoffmann" To: "Ni, Ray" Cc: "Liu, Zhiguang" , "devel@edk2.groups.io" , "Kumar, Rahul R" , "Dong, Eric" Subject: Re: [PATCH] UefiCpuPkg: Fix SMM code hangs when InitPaging Message-ID: <20230117121359.52rxmec7dv6gfksa@sirius.home.kraxel.org> References: <20230104054118.280-1-zhiguang.liu@intel.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Jan 17, 2023 at 09:02:01AM +0000, Ni, Ray wrote: > + Gerd. > > > -----Original Message----- > > From: Liu, Zhiguang > > Sent: Wednesday, January 4, 2023 1:41 PM > > To: devel@edk2.groups.io > > Cc: Liu, Zhiguang ; Ni, Ray ; Kumar, Rahul R ; Dong, > > Eric > > Subject: [PATCH] UefiCpuPkg: Fix SMM code hangs when InitPaging > > > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4246 > > > > In function InitPaging, NumberOfPml5Entries is calculated by below code > > NumberOfPml5Entries = (UINTN)LShiftU64 (1, SizeOfMemorySpace - 48); > > If the SizeOfMemorySpace is larger than 48, NumberOfPml5Entries will be > > larger than 1. However, this doesn't make sense if the hardware doesn't > > support 5 level page table. > > + ASSERT (SizeOfMemorySpace <= 52); > > + > > // > > - // Calculate the table entries of PML4E and PDPTE. > > + // Calculate the table entries of PML5E, PML4E and PDPTE. > > // > > NumberOfPml5Entries = 1; > > - if (SizeOfMemorySpace > 48) { > > + if (Enable5LevelPaging && (SizeOfMemorySpace > 48)) { > > NumberOfPml5Entries = (UINTN)LShiftU64 (1, SizeOfMemorySpace - 48); > > - SizeOfMemorySpace = 48; > > } > > > > + SizeOfMemorySpace = SizeOfMemorySpace > 48 ? 48 : SizeOfMemorySpace; if (SizeOfMemorySpace > 48) { if (Enable5LevelPaging) { NumberOfPml5Entries = ... } SizeOfMemorySpace = 48 } That is a much more readable version. The only effect I can see is that this avoids creating page tables which would not be used anyway. Can you explain where the hangs mentioned in the subject line are coming from and why the patch fixes them? take care, Gerd