From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 8FDD2740035 for ; Wed, 7 Feb 2024 20:42:38 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=gApM7m/9RETKxW6HTyc3i8T694PNez2S6SWFIjm8jNc=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1707338557; v=1; b=uSYxTLudJPxnjM7H3cd8norxdoPtNO1KDE65syPUWekFNjN1jQss4j9qQVAdJ8wYWHF17zGg 3x+ZsywshMjr2+cLgzBexME5qqUpRFdeXHmQLNiLQP08xPGA1N517YEEHucEaMEnmSk9z7SnUPv I6Er2SoaF7wVygASXqv8rIu4= X-Received: by 127.0.0.2 with SMTP id NMfHYY7687511xmS8L0lrgDT; Wed, 07 Feb 2024 12:42:37 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web10.806.1707338556552552844 for ; Wed, 07 Feb 2024 12:42:36 -0800 X-Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-270-z16BXcacO_-natjHY6I9iw-1; Wed, 07 Feb 2024 15:42:29 -0500 X-MC-Unique: z16BXcacO_-natjHY6I9iw-1 X-Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0804829AC00E; Wed, 7 Feb 2024 20:42:28 +0000 (UTC) X-Received: from [10.39.195.126] (unknown [10.39.195.126]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E7DCA111F9; Wed, 7 Feb 2024 20:42:26 +0000 (UTC) Message-ID: <7262d528-ee3d-d8f8-cad7-9bddec057a1b@redhat.com> Date: Wed, 7 Feb 2024 21:42:25 +0100 MIME-Version: 1.0 Subject: Re: [edk2-devel] [PATCH 1/3] UefiCpuPkg: Reduce and optimize access to attribute To: "Zhou, Jianfeng" , Pedro Falcato Cc: "devel@edk2.groups.io" , "Tan, Dun" , "Ni, Ray" , "Kumar, Rahul R" , Gerd Hoffmann References: <20240205140345.1437-1-dun.tan@intel.com> <20240205140345.1437-2-dun.tan@intel.com> From: "Laszlo Ersek" In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: E8Op4F38t1xWVylZSsUiDMM7x7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=uSYxTLud; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io On 2/7/24 02:57, Zhou, Jianfeng wrote: > Hi Pedro, >=20 >>> AFAIK, it's not allowed as IIRC APs cannot run arbitrary EFI boot serv= ices code. > [Zhou] The scenario I mentioned/The case we hit is during BIOS boot, not = software after EndOfBootService. >=20 >>> 1) Your fix is not correct. The compiler can tear your store, you need= to use a volatile store for this. > [Zhou] Assembly code of function PageTableLibSetPnle attached. The code i= s expected.=20 > Can't get "need to use a volatile store for this", would you pleas= e share more detail about it? With the patch in place, the compiler *happens* to generate code that uses a single instruction. That's nice, but how stable is that? IIUC, Pedro's point is that the "Pte4K" parameter of PageTableLibSetPte4K() should point to a volatile IA32_PTE_4K object, because that would *guarantee* that the compiler *always* generates a single instruction for the final assignment. (Now, I'm not sure about that, i.e. that even volatile is strong enough, but that's a different topic.) --*-- BTW, with this patch in place (as commit 30a25f277821, "UefiCpuPkg: Reduce and optimize access to attribute", 2024-02-06), we have: VOID PageTableLibSetPte4K ( IN IA32_PTE_4K *Pte4K, IN UINT64 Offset, IN IA32_MAP_ATTRIBUTE *Attribute, IN IA32_MAP_ATTRIBUTE *Mask ) { IA32_PTE_4K LocalPte4K; LocalPte4K.Uint64 =3D Pte4K->Uint64; ... if (Pte4K->Uint64 !=3D LocalPte4K.Uint64) { Pte4K->Uint64 =3D LocalPte4K.Uint64; } } This means that the "Pte4K" parameter should be marked "IN OUT", not just "IN". (Independently of whether we also qualify (*Pte4K) as volatile.) Of course, it's not a bug in the patch, it's a (documentation) bug in the pre-patch code. Can you perhaps submit a patch to fix that? Thanks, Laszlo -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115251): https://edk2.groups.io/g/devel/message/115251 Mute This Topic: https://groups.io/mt/104176232/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-