From nobody Sat May 4 14:30:50 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 1522807717474988.033817447494; Tue, 3 Apr 2018 19:08:37 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E4777225501E4; Tue, 3 Apr 2018 19:08:35 -0700 (PDT) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 78282226C7C33 for ; Tue, 3 Apr 2018 19:08:34 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Apr 2018 19:08:33 -0700 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.158.46]) by orsmga004.jf.intel.com with ESMTP; 03 Apr 2018 19:08:31 -0700 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.93; helo=mga11.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,404,1517904000"; d="scan'208";a="188458097" From: Star Zeng To: edk2-devel@lists.01.org Date: Wed, 4 Apr 2018 10:08:28 +0800 Message-Id: <1522807708-75668-1-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 Subject: [edk2] [PATCH V2] MdeModulePkg/Gcd: Filter gCpu->SetMemoryAttributes() calls X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Yi Li , Eric Dong , Renhao Liang , Liming Gao , Heyi Guo , "Kinney, Michael D" , Star Zeng 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" From: "Kinney, Michael D" This patch fixes an issue with VlvTbltDevicePkg introduced by commit 5b91bf82c67b586b9588cbe4bbffa1588f6b5926. The history is as below. To support heap guard feature, 14dde9e903bb9a719ebb8f3381da72b19509bc36 added support for SetMemorySpaceAttributes() to handle page attributes, but after that, a combination of CPU arch attributes and other attributes was not allowed anymore, for example, UC + RUNTIME. It is a regression. Then 5b91bf82c67b586b9588cbe4bbffa1588f6b5926 was to fix the regression, and we thought 0 CPU arch attributes may be used to clear CPU arch attributes, so 0 CPU arch attributes was allowed to be sent to gCpu->SetMemoryAttributes(). But some implementation of CPU driver may return error for 0 CPU arch attributes. That fails the case that caller just calls SetMemorySpaceAttributes() with none CPU arch attributes (for example, RUNTIME), and the purpose of the case is not to clear CPU arch attributes. This patch filters the call to gCpu->SetMemoryAttributes() if the requested attributes is 0. It also removes the #define INVALID_CPU_ARCH_ATTRIBUTES that is no longer used. Cc: Heyi Guo Cc: Yi Li Cc: Renhao Liang Cc: Star Zeng Cc: Eric Dong Cc: Liming Gao Cc: Jian J Wang Cc: Ruiyu Ni Signed-off-by: Michael D Kinney Signed-off-by: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.1 Reviewed-by: Jiewen.yao@intel.com Reviewed-by: Michael D Kinney --- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gc= d.c index 907245a3f512..31ddf9c3bb51 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -48,8 +48,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER= EXPRESS OR IMPLIED. #define NONEXCLUSIVE_MEMORY_ATTRIBUTES (EFI_MEMORY_XP | EFI_MEMORY_RP | \ EFI_MEMORY_RO) =20 -#define INVALID_CPU_ARCH_ATTRIBUTES 0xffffffff - // // Module Variables // @@ -873,7 +871,21 @@ CoreConvertSpace ( // Call CPU Arch Protocol to attempt to set attributes on the range // CpuArchAttributes =3D ConverToCpuArchAttributes (Attributes); - if (CpuArchAttributes !=3D INVALID_CPU_ARCH_ATTRIBUTES) { + // + // CPU arch attributes include page attributes and cache attributes.=20 + // Only page attributes supports to be cleared, but not cache attribut= es. + // Caller is expected to use GetMemorySpaceDescriptor() to get the cur= rent + // attributes, AND/OR attributes, and then calls SetMemorySpaceAttribu= tes() + // to set the new attributes. + // So 0 CPU arch attributes should not happen as memory should always = have + // a cache attribute (no matter UC or WB, etc).=20 + // + // Here, 0 CPU arch attributes will be filtered to be compatible with = the + // case that caller just calls SetMemorySpaceAttributes() with none CPU + // arch attributes (for example, RUNTIME) as the purpose of the case i= s not + // to clear CPU arch attributes. + // + if (CpuArchAttributes !=3D 0) { if (gCpu =3D=3D NULL) { Status =3D EFI_NOT_AVAILABLE_YET; } else { @@ -936,6 +948,13 @@ CoreConvertSpace ( // Set attributes operation // case GCD_SET_ATTRIBUTES_MEMORY_OPERATION: + if (CpuArchAttributes =3D=3D 0) { + // + // Keep original CPU arch attributes when caller just calls + // SetMemorySpaceAttributes() with none CPU arch attributes (for e= xample, RUNTIME). + // + Attributes |=3D (Entry->Attributes & (EXCLUSIVE_MEMORY_ATTRIBUTES = | NONEXCLUSIVE_MEMORY_ATTRIBUTES)); + } Entry->Attributes =3D Attributes; break; // --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel