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 21CFFD81163 for ; Tue, 6 Feb 2024 17:34:44 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=Xn07juJw1lJP2bApDtKy6YdtN5HyTJkqED+u3611i7c=; 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=1707240883; v=1; b=ihofcT0/E6J24qTDc5yr9wLhe3DcXhglQHfbWMvsv3DNLmunojQrH6kzNP5xkvQxzYnj26Hc FOjlu3NTH2B9SIPnvpO3L85LaDCnuLpRdmb5U9BRFJFzK5qc2hZAXuqygzUMsbOPFoJvhqDlTTX 1GAywhYLUYY5Mfo3VIanheiE= X-Received: by 127.0.0.2 with SMTP id R6LcYY7687511xG2uhi0EUOr; Tue, 06 Feb 2024 09:34:43 -0800 X-Received: from mail-vk1-f172.google.com (mail-vk1-f172.google.com [209.85.221.172]) by mx.groups.io with SMTP id smtpd.web11.27596.1707240883166078761 for ; Tue, 06 Feb 2024 09:34:43 -0800 X-Received: by mail-vk1-f172.google.com with SMTP id 71dfb90a1353d-4bfecb14f5dso1924092e0c.3 for ; Tue, 06 Feb 2024 09:34:43 -0800 (PST) X-Gm-Message-State: vuetqUKmU27FR9N50qhk9i8Tx7686176AA= X-Google-Smtp-Source: AGHT+IGAZ+5orAoiUBkIaIq6zaY1dWhIf0cnwduXDofHURy4pHyl8r1apz/o6eOqeM9b1+wquUjY7nNdg+vqPm8j+EU= X-Received: by 2002:a05:6122:4a0a:b0:4c0:2538:171c with SMTP id ez10-20020a0561224a0a00b004c02538171cmr214968vkb.16.1707240882003; Tue, 06 Feb 2024 09:34:42 -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: Tue, 6 Feb 2024 17:34:30 +0000 Message-ID: Subject: Re: [edk2-devel] [PATCH 1/3] UefiCpuPkg: Reduce and optimize access to attribute To: devel@edk2.groups.io, lersek@redhat.com Cc: dun.tan@intel.com, Zhou Jianfeng , Ray Ni , Rahul Kumar , 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="ihofcT0/"; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=none) On Tue, Feb 6, 2024 at 1:32=E2=80=AFPM Laszlo Ersek wro= te: > > On 2/5/24 15:03, duntan wrote: > > From: Zhou Jianfeng > > > > This commit is to reduce and optimize access to > > attribute in CpuPageTableLib. > > > > Unreasonable writing to attribute of page table may > > leads to expection. > > The assembly code for C code Pnle->Bits.Present =3D > > Attribute->Bits.Present looks like: > > and dword [rcx], 0xfffffffe > > and eax, 0x1 > > or [rcx], eax > > In case Pnle->Bits.Present and Attribute->Bits.Present > > is 1, Pnle->Bits.Present will be set to 0 for short > > time(2 instructions) which is unexpected. If some other > > core is accessing the page, it may leads to expection. > > This change reduce and optimize access to attribute of > > page table, attribute of page table is set only when it > > need to be changed. > > This patch does nothing to eliminate the actual race condition, it only > shrinks the window of potential corruption. FWIW, it's still not entirely correct: the compiler can tear the Uint64 sto= re. You'd need something like WRITE_ONCE (which in Linux essentially does *(volatile Type *) ptr =3D val;) > The PTEs continue to be overwritten without any kind of synchronization > with the other processors. I don't think we should be messing with page tables while APs are up. That will require a whole infrastructure to do TLB shootdowns. Zhou, Ray, what exactly is racing here? --=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 (#115187): https://edk2.groups.io/g/devel/message/115187 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-