From: Juergen Gross <jgross@suse.com>
To: David Laight <david.laight.linux@gmail.com>,
Mike Rapoport <rppt@kernel.org>
Cc: Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>, Borislav Petkov <bp@alien8.de>,
Ingo Molnar <mingo@kernel.org>, Ingo Molnar <mingo@redhat.com>,
"H. Peter Anvin" <hpa@zytor.com>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@kernel.org>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86/mm/pat: fix effective RW computation in lookup_address_in_pgd_attr()
Date: Thu, 16 Jul 2026 14:46:48 +0200 [thread overview]
Message-ID: <ca82df81-d606-4962-8893-1bd6c3d377c6@suse.com> (raw)
In-Reply-To: <20260716133539.6ba7deb4@pumpkin>
[-- Attachment #1.1.1: Type: text/plain, Size: 1937 bytes --]
On 16.07.26 14:35, David Laight wrote:
> On Thu, 16 Jul 2026 12:18:48 +0300
> Mike Rapoport <rppt@kernel.org> wrote:
>
>> On Thu, Jul 16, 2026 at 10:37:00AM +0200, Jürgen Groß wrote:
>>> On 16.07.26 10:10, Mike Rapoport (Microsoft) wrote:
>>>> lookup_address_in_pgd_attr() accumulates the effective NX and RW bits of
>>>> the walked page table levels so that verify_rwx() can detect mappings that
>>>> are both writable and executable.
>>>>
>>>> The RW bits are folded into a bool with
>>>>
>>>> *rw &= pXd_flags(*pXd) & _PAGE_RW;
>>>>
>>>> but _PAGE_RW is bit 1 while *rw only ever holds 0 or 1, so the AND is
>>>> always 0. *rw becomes false at the first level walked, regardless of the
>>>> actual permissions, and verify_rwx() treats every mapping as non-writable
>>>> and never reports a W^X violation.
>>>>
>>>> Accumulate NX and RW in unsigned long locals in their native bit positions
>>>> and store the result into the bool outputs once.
>>>>
>>>> Fixes: ceb647b4b529 ("x86/pat: Introduce lookup_address_in_pgd_attr()")
>>>> Assisted-by: Copilot:claude-opus-4.8
>>>> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
>>>
>>> Thanks for catching this.
>>>
>>> Reviewed-by: Juergen Gross <jgross@suse.com>
>>>
>>> Just one remark: instead of using additional local variables the fix could
>>> just look like:
>>>
>>> *rw |= !!(pXd_flags(*pXd) & _PAGE_RW);
>>>
>>> I don't really care how the issue is fixed, but this would result in less
>>> code.
>>
>> But it will be slower :)
>>
>> I instrumented cpa-test and I see ~2% improvement with additional local
>> variables.
>
> Does it improve further if you defer the '& _PAGE_NX' to the final assigment?
If so, it would probably be beneficial to have one local variable for the
logical OR of all page table entries involved (used for *nx), and one for
the logical AND of all entries (used for *rw).
Juergen
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
next prev parent reply other threads:[~2026-07-16 12:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 8:10 Mike Rapoport (Microsoft)
2026-07-16 8:37 ` Jürgen Groß
2026-07-16 8:46 ` Juergen Gross
2026-07-16 9:18 ` Mike Rapoport
2026-07-16 12:35 ` David Laight
2026-07-16 12:46 ` Juergen Gross [this message]
2026-07-16 12:49 ` David Laight
2026-07-16 12:55 ` Jürgen Groß
2026-07-16 13:27 ` Dave Hansen
2026-07-16 13:44 ` Mike Rapoport
2026-07-16 13:50 ` Dave Hansen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ca82df81-d606-4962-8893-1bd6c3d377c6@suse.com \
--to=jgross@suse.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=david.laight.linux@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rppt@kernel.org \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®