From nobody Wed Dec 25 05:38:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1512545515758438.87408973029585; Tue, 5 Dec 2017 23:31:55 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C3DFC2035627E; Tue, 5 Dec 2017 23:27:21 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5BE85220FB33F for ; Tue, 5 Dec 2017 23:27:20 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Dec 2017 23:31:51 -0800 Received: from jwang36-mobl2.ccr.corp.intel.com ([10.239.192.49]) by fmsmga002.fm.intel.com with ESMTP; 05 Dec 2017 23:31:48 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,367,1508828400"; d="scan'208";a="1252390292" From: Jian J Wang To: edk2-devel@lists.01.org Date: Wed, 6 Dec 2017 15:31:18 +0800 Message-Id: <20171206073120.2248-2-jian.j.wang@intel.com> X-Mailer: git-send-email 2.15.1.windows.2 In-Reply-To: <20171206073120.2248-1-jian.j.wang@intel.com> References: <20171206073120.2248-1-jian.j.wang@intel.com> Subject: [edk2] [PATCH 1/3] IntelFrameworkPkg/LegacyBios.h: Add a macro to guarantee page 0 access X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Due to the introduction of NULL pointer detection feature, page 0 will be disabled if the feature is enabled, which will cause legacy code failed to update legacy data in page 0. This macro is introduced to make sure the page 0 is enabled before those code and restore the original status of it afterwards. Another reason to introduce this macro is to eliminate the dependency on the PcdNullPointerDetectionPropertyMask. Because this is a new PCD, it could cause some backward compatibility issue for some old packages. This macro will simply check if the page 0 is disabled or not. If it's disabled, it will enable it before code updating page 0 and disable it afterwards. Otherwise, this macro will do nothing to page 0. The usage of the macro will be look like (similar to DEBUG_CODE macro): ACCESS_PAGE0_CODE( { } ); Cc: Liming Gao Cc: Michael D Kinney Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- IntelFrameworkPkg/Include/Protocol/LegacyBios.h | 34 +++++++++++++++++++++= ++++ 1 file changed, 34 insertions(+) diff --git a/IntelFrameworkPkg/Include/Protocol/LegacyBios.h b/IntelFramewo= rkPkg/Include/Protocol/LegacyBios.h index 641f101bce..f77c92ba21 100644 --- a/IntelFrameworkPkg/Include/Protocol/LegacyBios.h +++ b/IntelFrameworkPkg/Include/Protocol/LegacyBios.h @@ -1518,6 +1518,40 @@ struct _EFI_LEGACY_BIOS_PROTOCOL { EFI_LEGACY_BIOS_BOOT_UNCONVENTIONAL_DEVICE BootUnconventionalDevice; }; =20 +// +// Legacy BIOS needs to access memory in page 0 (0-4095), which is disable= d if +// NULL pointer detection feature is enabled. Following macro can be used = to +// enable/disable page 0 before/after accessing it. +// +#define ACCESS_PAGE0_CODE(statements) \ + do { \ + EFI_STATUS Status_; \ + EFI_GCD_MEMORY_SPACE_DESCRIPTOR Desc_; \ + \ + Status_ =3D gDS->GetMemorySpaceDescriptor (0, &Desc_); \ + if (!EFI_ERROR (Status_)) { \ + if ((Desc_.Attributes & EFI_MEMORY_RP) !=3D 0) { \ + Status_ =3D gDS->SetMemorySpaceAttributes ( \ + 0, \ + EFI_PAGES_TO_SIZE(1), \ + Desc_.Attributes &=3D ~EFI_MEMORY_RP \ + ); \ + ASSERT_EFI_ERROR (Status_); \ + } \ + \ + statements; \ + \ + if ((Desc_.Attributes & EFI_MEMORY_RP) !=3D 0) { \ + Status_ =3D gDS->SetMemorySpaceAttributes ( \ + 0, \ + EFI_PAGES_TO_SIZE(1), \ + Desc_.Attributes \ + ); \ + ASSERT_EFI_ERROR (Status_); \ + } \ + } \ + } while (FALSE) + extern EFI_GUID gEfiLegacyBiosProtocolGuid; =20 #endif --=20 2.15.1.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel