From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F14273DA5A1 for ; Thu, 16 Jul 2026 09:18:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784193536; cv=none; b=dACcx3m/h6mmGKLU7XKDIl+KjVLa/ynQ2F4x33q54ZwXCc5pA6EhAZlxQ9rLB+1Rtd/6ChExvQPYeZybzI3dkjchyCz1gw8ayok75qnIb/jgiZE2RvufcmEVNVR1HeCBQKFHa42+Prcq8ubdTUEI76QlqocHYmjMFgg2hq+ahaE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784193536; c=relaxed/simple; bh=TeSb7whIN3JI9eROvd0Y+m1jVu9UNA8okUvIJaUa5EE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IxkEUrA5w9jB2adavabnYdQRN1NYeaM49LeqqofIL2icYDUdNjcDkd8387JshshZRWD5HWKkndWu789x70hGpCI9iGRwFcVc4D3SidI1hL/jU3/QAER3RKs+CZm7j7i5EI1cfxpn2Ryd0tu7aFUsbFou3ycULFIDfWt88XNOw6o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HIYnBbMA; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HIYnBbMA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCA0C1F000E9; Thu, 16 Jul 2026 09:18:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784193534; bh=X13/0XGyJ5s3/aemN9xVMKWmHz2DpDGc2Ptcu1tjn+w=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=HIYnBbMAMO09FLQTmOH4GgzUpoFB/d5Ogzemq1myNkRfHyhZCA4ZHPKIR6tMRbMw+ cD00qI8Xp4jO/O8chHfEmv4maF0MuYVMh96aXCfByL+AR7iRqLB3jaxchzmZlR9ZlC KEE1fqkbA/utoB/NZ2O1/aJJU+y1GTcZK9KCLWNo6Lhh5TmKl/zYbL1ynl4AyaRHGG fAC6ZGM5N6NgLAnEcpD97qb0wiCPpys1kC/sXftjot1BNbfvpl5tCA7mlgZ8NVjX2A ybRidESB9u9n28Zf+MQD8KkCgnOgNc7av56vJXRv66dPsgmFAAKfL6uAQTT/nTyVri cz/N4N+lqzLag== Date: Thu, 16 Jul 2026 12:18:48 +0300 From: Mike Rapoport To: =?iso-8859-1?Q?J=FCrgen_Gro=DF?= Cc: Dave Hansen , Andy Lutomirski , Borislav Petkov , Ingo Molnar , Ingo Molnar , "H. Peter Anvin" , Peter Zijlstra , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86/mm/pat: fix effective RW computation in lookup_address_in_pgd_attr() Message-ID: References: <20260716-verify-rwx-fix-v1-1-d8a04854df06@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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) > > Thanks for catching this. > > Reviewed-by: Juergen Gross > > 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. > Juergen -- Sincerely yours, Mike.