From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BFFF3C9885 for ; Thu, 16 Jul 2026 12:49:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784206190; cv=none; b=YSyFhCBWbpkmNjkJmpByrn2zogP7QULORqIy5AwE4392uOXJBHHLTFzfa9/SbvVkQTjRq3s0wwV/mtur/jRa8/Ci+LbxPuZkFU79KpmQdpslgNNnmxaGO29xfDTe/JMZ03fsaFA5QuwutFhrJLXmniZ5MgpewVtqt7t6PU2Qc5Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784206190; c=relaxed/simple; bh=m9NV4s/qRp2jikXxLoLRovSkvwyC0qD+k0PBIpOyaAs=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Se1DFVl85P5sIfZM/Sj+/QKgILQEL+MQISCSYe2xCUEB90SMzGfSPjzN2qc9q3zcBNjIe5BxB75vWND1tfiVXkaVqEHu1kO0FjLrVlVwVPKr+ssiGSLhtIUWykM6b0QqDjB9OUt0xEWtg8/WqZpLEjghDfvaHxZi8CIZHFKgBc4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dP+GoEud; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dP+GoEud" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-47df6a5202bso4317813f8f.0 for ; Thu, 16 Jul 2026 05:49:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784206186; x=1784810986; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=+CRZSR+u+OkE3YO11G5iWUXlOSqe5AUuOhb9l5/XeiY=; b=dP+GoEudZ+sINv6xEycC340gJ12QEAo75rD6E7sgdKLBtKBaWv2U854WcXRQLzlFcg NGN5NXjH9rmE4AIJkEkwdAPb8tOF/NW/gz6jwrBirwpOdqfAWZ6U1IIPN2RyeKN8pC46 zCWQ8ZkvdHmEWf580UWKKm9S8fEizLEzzBriH+YDHo8UC+tUptFISIUkAux0/NAwPEII YWjF1ajrXU/vwfirzc5qCQ/fMNE6Hm/YZv3f6mpzObHBo5nqlFPTfQ7GgWGyIN304ztx rTHu4xwLqpytwxGyMObVSCS1+1b0Z8fnkpH0kM6QI4DhI51aYkcSmLotf9hmXp699gwu Af6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784206186; x=1784810986; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=+CRZSR+u+OkE3YO11G5iWUXlOSqe5AUuOhb9l5/XeiY=; b=cvCZYGaLTbh76NHdTG2xTxEXLrM37fqYb3T98X50EewPDJU43aPETpHzU1SFIMfSAF Lk9vlNjacjvzoIjGFrFIaoRnLfv0iZJhGVLNh7dGk8EpUMXY0nBVRVhZxS0cFdfGb0z4 K0t2k3QhEr9wTibSlEhS7UvQQKZ8F2aCbZ0o8YLbr3vwgSbDUQZ2J49BNg2Pw8RXAly9 lQE0s5ymGCVli1PTsCAXiaezXicDlB+eqPwKBszKMSTkWQgD8LUBk/MpawlhmVVJOGh6 ZyFvJsVKjOtg915ay8bztprC/hrNFXvYqTF5wWaTihQ8AiyBqwLe3YSrTWKce8c5yq9X Z/0Q== X-Forwarded-Encrypted: i=1; AHgh+RpEMMjDuA0J9GbcuNCutsUgYAwEA3su3rzc6MghiMXNJQf3rqTUBB2xXEwA8AySgZEHWGsnM/z4M0f793Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+UJL2/O0UuZ6d9ICZ1bFy2R2YeFIli7eqRU9tTvsNWxLut/FF FUmUsYiCiG+VSMaWRyCn6ZX2hH0TUYzUcGKN7VWRn6CCEbeDZm5y6t9n X-Gm-Gg: AfdE7cmsyMXLzjWcSG5nevra9SgGZkuBuzP1VTFH5ssinnYF7gANOCW1T+GuEi98npQ iIWEDiFgS2Q7FKXiVHYIomiUYmYEKJDeYk6Q43Z4igf3tqTJuDEAcnRMtkspEi8vl71yP3W/a/D 1/glCuCTrAIaCzTVOhK6WTBjoAp7iZ3Xm+fLrkCXB/ZtrYbOOcrtGtNt8ArEP2BUuiHjIfhYBG8 uv0/rPVVlkCx1HL0Cm8Uz039UshJWDglb+/H2W8SX17Bzbz+VvHQiG+oKytZcpOP5PKWDuV4VU/ 1KBHOAF4XoVZHlFSQfQ35+1NW95KjTGlaRV4xAEJCne8iYLc1zglTvufyvsQffHuBgKr6bC/pUV E//4GWm4Ic9MV1dRlIBVsErBwZuSPbSiVZd79yXJoZXkOQC8FzyN9II+rSdT9WEyrhxoc+p+D7I jfRBNIM5kYKlCsPL/UK/HuZY7V4vxg5QPDoVuFF+4JPQQNfMrxpw== X-Received: by 2002:a05:6000:4a0a:b0:47d:f43b:fd63 with SMTP id ffacd0b85a97d-47f4fcc1527mr8566175f8f.26.1784206185454; Thu, 16 Jul 2026 05:49:45 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f4635c86csm24541526f8f.16.2026.07.16.05.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jul 2026 05:49:45 -0700 (PDT) Date: Thu, 16 Jul 2026 13:49:43 +0100 From: David Laight To: Juergen Gross Cc: Mike Rapoport , 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: <20260716134943.73103a22@pumpkin> In-Reply-To: References: <20260716-verify-rwx-fix-v1-1-d8a04854df06@kernel.org> <20260716133539.6ba7deb4@pumpkin> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) 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=UTF-8 Content-Transfer-Encoding: quoted-printable On Thu, 16 Jul 2026 14:46:48 +0200 Juergen Gross wrote: > On 16.07.26 14:35, David Laight wrote: > > On Thu, 16 Jul 2026 12:18:48 +0300 > > Mike Rapoport wrote: > > =20 > >> On Thu, Jul 16, 2026 at 10:37:00AM +0200, J=C3=BCrgen Gro=C3=9F wrote:= =20 > >>> On 16.07.26 10:10, Mike Rapoport (Microsoft) wrote: =20 > >>>> lookup_address_in_pgd_attr() accumulates the effective NX and RW bit= s of > >>>> the walked page table levels so that verify_rwx() can detect mapping= s that > >>>> are both writable and executable. > >>>> > >>>> The RW bits are folded into a bool with > >>>> > >>>> *rw &=3D 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 o= f the > >>>> actual permissions, and verify_rwx() treats every mapping as non-wri= table > >>>> and never reports a W^X violation. > >>>> > >>>> Accumulate NX and RW in unsigned long locals in their native bit pos= itions > >>>> 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) =20 > >>> > >>> Thanks for catching this. > >>> > >>> Reviewed-by: Juergen Gross > >>> > >>> Just one remark: instead of using additional local variables the fix = could > >>> just look like: > >>> > >>> *rw |=3D !!(pXd_flags(*pXd) & _PAGE_RW); > >>> > >>> I don't really care how the issue is fixed, but this would result in = less > >>> code. =20 > >> > >> But it will be slower :) > >> > >> I instrumented cpa-test and I see ~2% improvement with additional local > >> variables. =20 > >=20 > > Does it improve further if you defer the '& _PAGE_NX' to the final assi= gment? =20 >=20 > 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). Which is what the patch does... David >=20 >=20 > Juergen