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.10919.1674032036651796508 for ; Wed, 18 Jan 2023 00:53:56 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gImjI197; 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=1674032035; 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=FRq8hl7ugC91jktG8U7tOuk3RgwJ1lJMw9Sk+FxsvzU=; b=gImjI197paTvv80YOnVgqVwauax59O+h8hYDoBxYnOzeeA1SzfKXNONeH/TiMhzWHv5Hcs l+EOP4qmkyX+gsMAAulu+WT7nn8J2rLc3jnwQXlBJ83vFwMYDOmUvyULPqrENUPXw869D/ lN4ZQe9L2cjisPZJ9uddFdPGk03q8iM= 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-470-4OBF304JN4WDqdUjLFK6Vg-1; Wed, 18 Jan 2023 03:53:52 -0500 X-MC-Unique: 4OBF304JN4WDqdUjLFK6Vg-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 EB050182360F; Wed, 18 Jan 2023 08:53:51 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.186]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9B802140EBF5; Wed, 18 Jan 2023 08:53:51 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 206961800091; Wed, 18 Jan 2023 09:53:50 +0100 (CET) Date: Wed, 18 Jan 2023 09:53:50 +0100 From: "Gerd Hoffmann" To: devel@edk2.groups.io, zhiguang.liu@intel.com Cc: "Ni, Ray" , "Kumar, Rahul R" , "Dong, Eric" , "Zeng, Star" , "Wu, Jiaxin" Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg: Fix SMM code hangs when InitPaging Message-ID: <20230118085350.bv7s7spmmhkr4ozj@sirius.home.kraxel.org> References: <20230104054118.280-1-zhiguang.liu@intel.com> <20230117121359.52rxmec7dv6gfksa@sirius.home.kraxel.org> 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 Wed, Jan 18, 2023 at 01:13:43AM +0000, Zhiguang Liu wrote: > Thanks all for reviewing, and I will send a new version to address the comment. > > As for Gerd's question, let me explain. > Let's see one example, that the CPU has SizeOfMemorySpace >48, but the CPU doesn't enable 5 level paging. > The purpose of the current function InitPaging is to modify existing > page table. To use the same logic to handle both 5 level and 4 level > paging, for 4 level paging, the logic will create a false 5 level > paging entry to treat it like a 5 level page table. Yes. Same for 3-level paging btw. There are always page tables for 5 levels, but the higher levels might be unused. > This way, the > number of 5 level paging should always be one. If we use > SizeOfMemorySpace to calculate the 5 level paging entry count, we will > get number more than one. However, as I just mentioned, we only > create one false 5 level paging entry, system may hang when we try to > access the second 5 level paging entry. If 5-level paging is turned off the CPU should not see what you are doing with the page tables for the second (and higher) 5-level entry. So, limiting the number of 5-level entries does make sense. Higher entries are not used, so it's pointless work. But that doesn't answer the question: Why does that fix the system hanging? I just can't see a reason for that when looking through the InitPaging code. I suspect this might hide a bug somewhere else. Related: We got UefiCpuPkg/Library/CpuPageTableLib last year, can this be used instead? take care, Gerd