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 4B802740032 for ; Wed, 7 Feb 2024 01:05:42 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=9BarsiWI/dvyhNiLxnwUaYhR7DqiFPwMWoO+EFx2QX4=; c=relaxed/simple; d=groups.io; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Transfer-Encoding; s=20140610; t=1707267941; v=1; b=SiB3ogroCU/CMcERIoUFmUpwIDtwObIzFFSmML7gZlGebbm8VOdmKMbdBG2sqDLrKkON0HuV /+yHV8cM39GXh3yqCEPBUrSDyln0BQI+1qE8d1QpE9TyXns/lGUMrv7sTmLe1MuzLudyQ7s1Y3B 3IBYjXBOgcgCinQBHcK/40yE= X-Received: by 127.0.0.2 with SMTP id mkvlYY7687511xuDWp5KAeTA; Tue, 06 Feb 2024 17:05:41 -0800 X-Received: from mail-ua1-f41.google.com (mail-ua1-f41.google.com [209.85.222.41]) by mx.groups.io with SMTP id smtpd.web10.10322.1707267940344019209 for ; Tue, 06 Feb 2024 17:05:40 -0800 X-Received: by mail-ua1-f41.google.com with SMTP id a1e0cc1a2514c-7d6275d7d4dso25292241.2 for ; Tue, 06 Feb 2024 17:05:40 -0800 (PST) X-Gm-Message-State: qd228wCK1yJXud5KUnb3rBO4x7686176AA= X-Google-Smtp-Source: AGHT+IGO5KqnDw7SjaWYT0IXkehR2zDmdIUSe2mNsnCHeWsaggl+LgPhbeM2lYUGvXVJodesuG1JCKG8qjf8OyOw4Sk= X-Received: by 2002:a05:6122:1699:b0:4c0:2553:3b19 with SMTP id 25-20020a056122169900b004c025533b19mr1306425vkl.13.1707267939306; Tue, 06 Feb 2024 17:05:39 -0800 (PST) MIME-Version: 1.0 References: <20240205140345.1437-1-dun.tan@intel.com> <20240205140345.1437-2-dun.tan@intel.com> In-Reply-To: From: "Pedro Falcato" Date: Wed, 7 Feb 2024 01:05:28 +0000 Message-ID: Subject: Re: [edk2-devel] [PATCH 1/3] UefiCpuPkg: Reduce and optimize access to attribute To: "Zhou, Jianfeng" Cc: "devel@edk2.groups.io" , "lersek@redhat.com" , "Tan, Dun" , "Ni, Ray" , "Kumar, Rahul R" , Gerd Hoffmann 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,pedro.falcato@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: 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=SiB3ogro; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.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 Wed, Feb 7, 2024 at 12:47=E2=80=AFAM Zhou, Jianfeng wrote: > > Hi Laszlo, Pedro, > > Clarify one thing, this change is not for racing introduced by MP reading= /writing to the same page table at the same time, but for unexpected behavi= or introduced by compiler. > As my understanding, MP reading/writing to the same page table at the sa= me time is not recommended, perhaps, it is not allowed. AFAIK, it's not allowed as IIRC APs cannot run arbitrary EFI boot services = code. > > For bit operation code, such as Pnle->Bits.Present =3D Attribute->Bits.Pr= esent, we might think it is atomic assignment, while not. The assembly code= looks like: > and dword [rcx], 0xfffffffe > and eax, 0x1 > or [rcx], eax > In case Pnle->Bits.Present =3D 1, Attribute->Bits.Present =3D 1, we mig= ht think it is harmless, as the value not changed. While actually, > and dword [rcx], 0xfffffffe // the present bit set to 0 ---- this is= unexpected !!!!! we don=E2=80=99t want the present bit set to 0! > and eax, 0x1 > or [rcx], eax // the present bit set to right value 1 > > Let's consider such a MP scenario: > 1) one processor executing instruction "and dword [rcx], 0xfffffffe" > 2) other processors happened to access the memory mapped by Pnle, it may = lead to exception. I understand your original problem, but: 1) Your fix is not correct. The compiler can tear your store, you need to use a volatile store for this. 2) What kind of page table manipulation is happening while APs are running code, and does this mean you need a TLB shootdown mechanism? --=20 Pedro -=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 (#115207): https://edk2.groups.io/g/devel/message/115207 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-