From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web11.26914.1658150326443022020 for ; Mon, 18 Jul 2022 06:18:46 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=Cz6jYPSa; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: ray.ni@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658150326; x=1689686326; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Q/KXKPclkGxt98/g3v+DMWW7iKJtghVkiscGcrg66FI=; b=Cz6jYPSaXlzWBW3nb20y+hyzPeExDUt7hmTl1RtZIXEjONjuroovjMqp 1ineBuO/pDG9uyb73aa7KpAUqbgTYeAUkJJl22M3w8vqOxBV+QdP7hhYe lbatpjhalFMu+H8ZIBomhI+wiQwVf9M88GnulHMIOa85x0Zz58mZAyd14 sFEIgmIj2oYEuYuCF8ZaNGQaf8xKExe7ean7y/k7nrMlJ0cQlH3orKkqh RbsqBuam9f66ZxxwcXD18LF+2KwzcIoW1lLPB/FUlNliXh3MTA0Q9YWyW nObDLFgpJRHkNWo0cyIR14JmkQnVs8ABwNTt7vvRP8QxBA4Ts/kkWm+KH A==; X-IronPort-AV: E=McAfee;i="6400,9594,10411"; a="287363892" X-IronPort-AV: E=Sophos;i="5.92,281,1650956400"; d="scan'208";a="287363892" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jul 2022 06:18:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,281,1650956400"; d="scan'208";a="624724967" Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.183.102]) by orsmga008.jf.intel.com with ESMTP; 18 Jul 2022 06:18:42 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Zhiguang Liu , Eric Dong Subject: [PATCH 03/10] CpuPageTableLib: Fix a bug when a bit is 1 in Attribute, 0 in Mask Date: Mon, 18 Jul 2022 21:18:24 +0800 Message-Id: <20220718131831.660-4-ray.ni@intel.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220718131831.660-1-ray.ni@intel.com> References: <20220718131831.660-1-ray.ni@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To reproduce the issue: UINTN PageTable; VOID *Buffer; UINTN PageTableBufferSize; IA32_MAP_ATTRIBUTE Attribute; IA32_MAP_ATTRIBUTE Mask; RETURN_STATUS Status; Attribute.Uint64 =3D 0; Mask.Uint64 =3D 0; PageTableBufferSize =3D 0; PageTable =3D 0; Buffer =3D NULL; Attribute.Bits.Present =3D 1; Attribute.Bits.Nx =3D 1; Mask.Bits.Present =3D 1; Mask.Uint64 =3D MAX_UINT64; // // Create page table to cover [0, 10M) // Status =3D PageTableMap ( &PageTable, PagingMode, Buffer, &PageTableBufferSize, 0, (UINT64)SIZE_2MB * 5, &Attribute, &Mask ); ASSERT (Status =3D=3D RETURN_BUFFER_TOO_SMALL); Buffer =3D AllocatePages (EFI_SIZE_TO_PAGES (PageTableBufferSize)); Status =3D PageTableMap ( &PageTable, PagingMode, Buffer, &PageTableBufferSize, 0, (UINT64)SIZE_2MB * 5, &Attribute, &Mask ); ASSERT (Status =3D=3D RETURN_SUCCESS); // // Change the mapping for [0, 4KB) // No change actually. Just clear Nx bit in Mask. // Mask.Bits.Nx =3D 0; PageTableBufferSize =3D 0; Status =3D PageTableMap ( &PageTable, PagingMode, NULL, &PageTableBufferSize, 0, (UINT64)SIZE_4KB, &Attribute, &Mask ); ASSERT (Status =3D=3D RETURN_SUCCESS); // FAIL!! The root cause is when comparing the existing mapping attributes against the requested one, Mask is not used but it should be used. Signed-off-by: Zhiguang Liu Reviewed-by: Ray Ni Cc: Eric Dong --- UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c b/UefiCpu= Pkg/Library/CpuPageTableLib/CpuPageTableMap.c index 17bca5e351..429b014b7b 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c @@ -308,7 +308,7 @@ PageTableLibMapInLevel ( //=0D PleBAttribute.Uint64 =3D PageTableLibGetPleBMapAttribute (&ParentPagin= gEntry->PleB, &NopAttribute);=0D if ((IA32_MAP_ATTRIBUTE_ATTRIBUTES (&PleBAttribute) & IA32_MAP_ATTRIBU= TE_ATTRIBUTES (Mask))=0D - =3D=3D IA32_MAP_ATTRIBUTE_ATTRIBUTES (Attribute))=0D + =3D=3D (IA32_MAP_ATTRIBUTE_ATTRIBUTES (Attribute) & IA32_MAP_ATTRI= BUTE_ATTRIBUTES (Mask)))=0D {=0D //=0D // This function is called when the memory length is less than the r= egion length of the parent level.=0D --=20 2.35.1.windows.2