From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) by mx.groups.io with SMTP id smtpd.web11.88494.1675788229176791555 for ; Tue, 07 Feb 2023 08:43:49 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@posteo.de header.s=2017 header.b=OSRzn1QT; spf=pass (domain: posteo.de, ip: 185.67.36.66, mailfrom: mhaeuser@posteo.de) Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 74ECE2406F5 for ; Tue, 7 Feb 2023 17:43:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1675788227; bh=7eh30w8a/3UMVWzeSvpankMZd+Lamcv86DcTIH4gTlU=; h=From:Subject:Date:Cc:To:From; b=OSRzn1QThwWqe1OnFMiliaAcyz96Bi86qOs5Rf9DX855fJPCJxF/OoU9zZXIspOsH NMeS7r/4N1jJlL6dbc6SmeMtxeUUcZSV2Xi219olINKmiagwP16hMk+PWog/p7eSEA nk7b8x0W39FueDaDT59N6DOb+30jlPq04YtxnDO4r/gYdo0rCSuziE1pAHm1aQ+4Z8 oEt2EsFxKcoZZ38Rj/axuhh3lObwtgaslUDwLnKQcPUWDgCUEIg2375x9SDJtj8VfT 6KkeEJaTLOt5p2FssjHwQPFflMVbSKGkztCb8vg6OmaNVAguDjqImXa6y5lZY3Ajfs 74iwuVf0jXNug== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4PB88d6Yclz9rxN; Tue, 7 Feb 2023 17:43:45 +0100 (CET) From: =?UTF-8?B?TWFydmluIEjDpHVzZXI=?= Message-Id: <4F25EBC9-EB49-4B43-9671-8C0977EC936C@posteo.de> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.400.51.1.1\)) Subject: Re: [edk2-devel] [PATCH 2/5] UefiCpuPkg: Contiguous memory allocation and code clean-up. Date: Tue, 7 Feb 2023 16:43:35 +0000 In-Reply-To: <32073.1675788041796635561@groups.io> Cc: guo.dong@intel.com, ray.ni@intel.com, sean@starlabs.systems, james.lu@intel.com, gua.guo@intel.com, Gerd Hoffmann To: Yuanhao Xie , edk2-devel-groups-io References: <20230207134939.273-3-yuanhao.xie@intel.com> <32073.1675788041796635561@groups.io> Content-Type: multipart/alternative; boundary="Apple-Mail=_C46FAD74-57E8-4D6A-BF5F-24F776F506C0" --Apple-Mail=_C46FAD74-57E8-4D6A-BF5F-24F776F506C0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 CC Gerd (sorry the original quote is missing, groups.io = is terrible) I thought he was to be CC'd on all UefiCpuPkg patches? Best regards, Marvin > On 7. Feb 2023, at 17:40, Marvin H=C3=A4user = wrote: >=20 > Hi Yuanhao, >=20 > 1) The code comments and copy code suggest that the stacks are located = low and the function is located high (good). However, the = SetMemorySpaceAttributes() call un-XP's Address, which is the low = address. So, do I misunderstand the changes, or are you un-XP'ing the = first stack (and keep the function XP'd)? >=20 > 2) The same SetMemorySpaceAttributes() call, you now pass = ApLoopFuncSize over ApSafeBufferSize. The latter was explicitly = page-aligned, while the former is not. How is it guaranteed it is indeed = aligned? If it is not, I don't think this is supported, at least = universally. >=20 > 3) Similar to 2), the stack size is much smaller than the page size, = no? How do you guarantee the function is on a page boundary for memory = protection? >=20 > 4) A proper W^X flow should be to wait with un-XP till the CopyMem() = for the function code has returned. Right before that, the copied code = should be marked read-only. >=20 > Best regards, > Marvin --Apple-Mail=_C46FAD74-57E8-4D6A-BF5F-24F776F506C0 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 CC Gerd (sorry = the original quote is missing, groups.io is = terrible)

I thought he was to be CC'd on all = UefiCpuPkg patches?

Best = regards,
Marvin

On = 7. Feb 2023, at 17:40, Marvin H=C3=A4user <mhaeuser@posteo.de> = wrote:

Hi Yuanhao,

1) The = code comments and copy code suggest that the stacks are located low and = the function is located high (good). However, the SetMemorySpaceAttributes() call un-XP's = Address, which is the low address. So, do I misunderstand the changes, = or are you un-XP'ing the first stack (and keep the function = XP'd)?

2) The same
SetMemorySpaceAttributes() call, you now pass ApLoopFuncSize over ApSafeBufferSize. The latter was explicitly page-aligned, = while the former is not. How is it guaranteed it is indeed aligned? If = it is not, I don't think this is supported, at least = universally.

3) Similar to 2), the stack size is much smaller = than the page size, no? How do you guarantee the function is on a page = boundary for memory protection?

4) A proper W^X flow should be to = wait with un-XP till the CopyMem() for the
function code has returned. Right = before that, the copied code should be marked read-only.

Best = regards,
Marvin

= --Apple-Mail=_C46FAD74-57E8-4D6A-BF5F-24F776F506C0--