mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: David Laight <david.laight.linux@gmail.com>
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>,
	Juergen Gross <jgross@suse.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 v2] x86/mm/pat: fix effective RW computation in lookup_address_in_pgd_attr()
Date: Sun, 19 Jul 2026 11:38:32 +0300	[thread overview]
Message-ID: <alyNCN3LSGpY8BXc@kernel.org> (raw)
In-Reply-To: <20260717113209.178573db@pumpkin>

On Fri, Jul 17, 2026 at 11:32:09AM +0100, David Laight wrote:
> On Fri, 17 Jul 2026 12:41:43 +0300
> "Mike Rapoport (Microsoft)" <rppt@kernel.org> 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 0x2. So consider the accumulation line:
> > 
> >         rw &= pXd_flags(*pXd) & _PAGE_RW;
> > 
> > where rw=0x1 and the right side evaluates down to 0x2. It'll end up doing:
> > 
> >         rw = 0x1 & 0x2
> > 
> > and rw always ends up 0.
> > 
> > This way 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.
> > 
> > Add double negation to the right side to normalize the _PAGE_RW flag to
> > 0 or 1.
> > 
> > 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>
> > Reviewed-by: Juergen Gross <jgross@suse.com>
> > ---
> > v2 changes:
> > * use a simpler version that uses !! to ensure the comparison result is
> >   0 or 1
> 
> Isn't this slower (and probably larger) because of the repeated references
> to the parameter passed by reference?

Yes, it is, but Dave objected micro-optimization:

https://lore.kernel.org/all/adecc483-ca7e-4c03-ab35-88a0400a4867@intel.com/

and there is no measurable difference in BPF program load times.
 
> 	David

-- 
Sincerely yours,
Mike.

      reply	other threads:[~2026-07-19  8:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17  9:41 Mike Rapoport (Microsoft)
2026-07-17 10:32 ` David Laight
2026-07-19  8:38   ` Mike Rapoport [this message]

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=alyNCN3LSGpY8BXc@kernel.org \
    --to=rppt@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=david.laight.linux@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.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

Powered by JetHome