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.web10.11779.1674036647525992848 for ; Wed, 18 Jan 2023 02:10:47 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fo6lt3rG; 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=1674036646; 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=ybykXP/kkVsVeI9pfw1dR+ub6bc0WVgdgSamH9RQx84=; b=fo6lt3rGyp834rEQB0+rM/ff292EUaahpZumSBjX/IVLrY1rfCatCkJG4rpw5KerMYME6q LZ8I1prGeEgryPLWdHhprXOighhVXkDnN8wkatsg3aZjLGJfWEsUu3fNMnqhsgCnrAwRYp OLpU62sXOCtzS8IJCilR5gvICv08G48= 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-307--l1PcxodMwG3YlFV1IUR-A-1; Wed, 18 Jan 2023 05:10:41 -0500 X-MC-Unique: -l1PcxodMwG3YlFV1IUR-A-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0724E101A521; Wed, 18 Jan 2023 10:10:41 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.186]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB74A492B00; Wed, 18 Jan 2023 10:10:40 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id B8D371801AB5; Wed, 18 Jan 2023 11:10:38 +0100 (CET) Date: Wed, 18 Jan 2023 11:10:38 +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: <20230118101038.75fuv5lzt7rxxen7@sirius.home.kraxel.org> References: <20230104054118.280-1-zhiguang.liu@intel.com> <20230117121359.52rxmec7dv6gfksa@sirius.home.kraxel.org> <20230118085350.bv7s7spmmhkr4ozj@sirius.home.kraxel.org> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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 09:12:09AM +0000, Zhiguang Liu wrote: > Hi Gerd, > > Let's check the code in InitPaging. > If 5LevelPaging is disabled, Pml5 points to a local variable. Pml5[1] shouldn't be used. > > UINT64 Pml5Entry; > UINT64 *Pml5; > if (!Enable5LevelPaging) { > Pml5Entry = (UINTN)mSmmProfileCr3 | IA32_PG_P; > Pml5 = &Pml5Entry; Oh, it's just a dummy entry on the stack, not an dummy page table. Missed that detail. So writing entry #2 and higher smashes the stack. That certainly explains why the code hangs. > And for the CpuPageTableLib, I think the API don't provide the > interface to split 2MB-page page table into 4KB-page, which is the > function wants to do. I think that is handled by the library automatically. You can request address ranges being mapped with specific attributes (such as NX set), and the library will transparently split pages for you if needed. take care, Gerd