From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (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 6999F81C7F for ; Tue, 29 Nov 2016 13:54:25 -0800 (PST) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A9C588123E; Tue, 29 Nov 2016 21:54:24 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-57.phx2.redhat.com [10.3.116.57]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uATLsNxl010477; Tue, 29 Nov 2016 16:54:23 -0500 To: Jiewen Yao , edk2-devel@ml01.01.org References: <1480405175-61868-1-git-send-email-jiewen.yao@intel.com> Cc: Michael D Kinney , Jeff Fan From: Laszlo Ersek Message-ID: <6b50ad2b-b01f-0345-bf20-6fcd875dccec@redhat.com> Date: Tue, 29 Nov 2016 22:54:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.0 MIME-Version: 1.0 In-Reply-To: <1480405175-61868-1-git-send-email-jiewen.yao@intel.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 29 Nov 2016 21:54:24 +0000 (UTC) Subject: Re: [PATCH] UefiCpuPkg:PiSmmCpu: Set correct attribute on split. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Nov 2016 21:54:25 -0000 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 11/29/16 08:39, Jiewen Yao wrote: > PiSmmCpu driver may split page for page attribute request. > Current logic will propagate the super page attribute attribute. > However, it might be wrong because we cannot clear protection > without touch super page attribute. > > We should always clear protection on super page and set > protection on end page for easy clear later. > > Cc: Jeff Fan > Cc: Michael D Kinney > Cc: Laszlo Ersek > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Jiewen Yao > --- > UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c > index accc11e..d0f41a8 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c > @@ -303,7 +303,7 @@ SplitPage ( > for (Index = 0; Index < SIZE_4KB / sizeof(UINT64); Index++) { > NewPageEntry[Index] = BaseAddress + SIZE_4KB * Index + ((*PageEntry) & PAGE_PROGATE_BITS); > } > - (*PageEntry) = (UINT64)(UINTN)NewPageEntry + ((*PageEntry) & PAGE_PROGATE_BITS); > + (*PageEntry) = (UINT64)(UINTN)NewPageEntry + PAGE_ATTRIBUTE_BITS; > return RETURN_SUCCESS; > } else { > return RETURN_UNSUPPORTED; > @@ -324,7 +324,7 @@ SplitPage ( > for (Index = 0; Index < SIZE_4KB / sizeof(UINT64); Index++) { > NewPageEntry[Index] = BaseAddress + SIZE_2MB * Index + IA32_PG_PS + ((*PageEntry) & PAGE_PROGATE_BITS); > } > - (*PageEntry) = (UINT64)(UINTN)NewPageEntry + ((*PageEntry) & PAGE_PROGATE_BITS); > + (*PageEntry) = (UINT64)(UINTN)NewPageEntry + PAGE_ATTRIBUTE_BITS; > return RETURN_SUCCESS; > } else { > return RETURN_UNSUPPORTED; > I had to stare a while at this, to get a superficial understanding :) But, it does seem to make sense (I checked PAGE_ATTRIBUTE_BITS and PAGE_PROGATE_BITS too, just to be sure). So, this change preserves the protection inheritance for the leaf pages, but clears NX and sets Dirty / Accessed / Writeable / Present on the relevant parent entry. (I see hat User mode access is enabled as well; I don't know why that is useful here.) Some notes about the commit message: - we have "attribute attribute". I think we should either drop one of those words, or say "super page attribute to leaf page attribute". - "end page" might be more clearly stated as "leaf page" (just a guess) - I think it would be useful to mention, for the uninitiated like me :), that the effective protection is (apparently) the strictest combination across the levels. - What do you think of the following subject line? UefiCpuPkg/PiSmmCpuDxeSmm: relax superpage protection on page split Anyway, to the extent that I understand this, I agree: Acked-by: Laszlo Ersek I gave the patch a bit of testing in my usual environment; it seems to cause no problems. Tested-by: Laszlo Ersek Thanks Laszlo