From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 6FB1641B8E4 for ; Thu, 16 Jul 2026 12:35:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784205348; cv=none; b=oVj4KbwpSvK0mlx6bOM/oGBK66xY0JowqgRgQyql/giyoG+a6MGgzrJtvJrG5IeIfVSQzJ1B3CXZ0k3MPIAWR2JeZtbRH83Sn9F2twzMkRoCqC14fMkve2d04PBikCgabWywvy+Q8NwmGRTKhWmKnGzwuWy/14ltffgc7dGsLLU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784205348; c=relaxed/simple; bh=m04ZqABGMQw34Qe2Oxo7Beh+Hax2msfv40DiWk/U1sE=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OuzuWFDt1RB7gyXGzq+3e/9IPo2B/eH+e4dcPW5AinJWxvM9BOiXMV+awxE4AJ+rpSQEcBpX9GKHdWO6MPLcMjPpkj4Bo5w0VsTZh8mMCHzkTJbFbldYZCeCr1JWC2FQsUtPeEB4OsPvoAZhzAkmDL2ftphE35uc6sReaQipSA0= 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=UKtckDpv; arc=none smtp.client-ip=209.85.221.43 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="UKtckDpv" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-472326ca506so5353277f8f.2 for ; Thu, 16 Jul 2026 05:35:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784205345; x=1784810145; 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=l+PAtbYlKiOtsbAnDhq+viwTMehxjNe8w4HCh/1mOAU=; b=UKtckDpvbDAXaVe3LsI/eeLp9cuSTvKnjx1HJqXH5v9KSeq9Aj8q8eP45jHeMJuy8A KJQImigugJiJ88Lv4NZXqYryeFil1JCF6l4EdrGHQtDeArAoF7+9HVKdtnHHZu2BhWMQ DlgjpI4ya617VrMkupmiQRZKZr2PDkE4Dp4O+Dq84r60ehhrH6DvHXhQzpnfcXz0VHYU nYHZGh8X2MOc5UTRL6e6MNdgpiGuvY6Y9A+WKXbR8NuQXuAK30dujVProLQMnTX5CiDJ cCzshai9/x3tEWzyiBH/QlFNyky4/avgdwi1mpfHDWwxPnMOWColpUzrP+QV+vK8ZojK vO9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784205345; x=1784810145; 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=l+PAtbYlKiOtsbAnDhq+viwTMehxjNe8w4HCh/1mOAU=; b=syvW6+YQgQHMCe677skZfhS3N+moJlM9Job33yCvKrjAa4nMWPB6ZD1Qjf3mGTdvPO MVq3eBGaqjQkVRNvO1b2FzAsm/smMvaR782V28Boivt2P3+hZbnuS8l+D3Gv2LnUY+50 SYBHr8v22ztJCw8OvsZraNDgY6TggymwNNXil18N0RAjuftcUWdpwaTzgVZfxymixhBm gT+dK4tfm97qi5xYoalwWaZhriCjOpUg27oaGOLazrT8UktnrLDk5JBhR7OGzLgU9V1+ lANwi1P0/M8eIbH4S+ODByzSOxCoPVH/QbN/RLg6GHXyRHVsU7uHjN7ZeDDqKtDHk5wi XunQ== X-Forwarded-Encrypted: i=1; AHgh+RqGnXL4fY612Xv1JaI0YuXU/mDQyDNlMJnrFgg+Quusj4YQnXpmbY765Iub6S/yCzMmMAd0vSfFTjHWK+Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7GAvYLFF+S0NSAT61p20Fny2ovkRgEWky9J9PpYuBu4/Iz12Z uYDwYrc58PU9rmfHqiCMymhSllM+ua+WzvpqL1+9utbklPq9mqGrbJD5 X-Gm-Gg: AfdE7cm/VLsbXa6yVGvFDLoK83vFD2Gw2ETLX2FGcRWPFxtyzumqsgEW+b+c0e7tpn7 O0WhYpHItTUvVYPlc/n35YJsQU0cd4/BGdY6Y8HrME1fmdziRn9zZZXPdL5pPAJg0CYAYAPjm7T WrUMnlYEyW7H6z2d+1c+d/GJ/NulRYA/lu/KCEZP2L5qyynyYFVrc8io2pKEqPkoYF4Xe8+0wxv BlZxc/mRPUwRTeyOltMgSOiRuTB7/H4gGCeer1i5GHD4k75gG94Es8KdVd9F/oUd9MimLf1Y4nD A6lnMr1tX2sQ0J97BJsdsdKoCWzm6M8LiKWD7m8LaL9y1JZRwSZtj7zSi/F+XxxfZHTq3lzxp0m arGe33Jv2twr37hLOEY6OdcVy1S4j8mOhh3cB4NXL/kAAinNaphoxam8qXUqrpHMydf05drzW0e BMRjaS/I/xheBymxooYmWKmo5PUk9pzjiO8YZ9cwfQBOu3LTaZBg== X-Received: by 2002:adf:e002:0:10b0:47d:e01c:c28 with SMTP id ffacd0b85a97d-47f46373d2dmr11468014f8f.36.1784205344429; Thu, 16 Jul 2026 05:35:44 -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-47f464c30a9sm23317989f8f.31.2026.07.16.05.35.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jul 2026 05:35:43 -0700 (PDT) Date: Thu, 16 Jul 2026 13:35:39 +0100 From: David Laight To: Mike Rapoport Cc: =?UTF-8?B?SsO8cmdlbiBHcm/Dnw==?= , 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: <20260716133539.6ba7deb4@pumpkin> In-Reply-To: References: <20260716-verify-rwx-fix-v1-1-d8a04854df06@kernel.org> 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 12:18:48 +0300 Mike Rapoport wrote: > On Thu, Jul 16, 2026 at 10:37:00AM +0200, J=C3=BCrgen Gro=C3=9F wrote: > > On 16.07.26 10:10, Mike Rapoport (Microsoft) wrote: =20 > > > 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. > > >=20 > > > The RW bits are folded into a bool with > > >=20 > > > *rw &=3D pXd_flags(*pXd) & _PAGE_RW; > > >=20 > > > 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-writ= able > > > and never reports a W^X violation. > > >=20 > > > Accumulate NX and RW in unsigned long locals in their native bit posi= tions > > > and store the result into the bool outputs once. > > >=20 > > > Fixes: ceb647b4b529 ("x86/pat: Introduce lookup_address_in_pgd_attr()= ") > > > Assisted-by: Copilot:claude-opus-4.8 > > > Signed-off-by: Mike Rapoport (Microsoft) =20 > >=20 > > Thanks for catching this. > >=20 > > Reviewed-by: Juergen Gross > >=20 > > Just one remark: instead of using additional local variables the fix co= uld > > just look like: > >=20 > > *rw |=3D !!(pXd_flags(*pXd) & _PAGE_RW); > >=20 > > I don't really care how the issue is fixed, but this would result in le= ss > > code. =20 >=20 > But it will be slower :)=20 >=20 > 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 assigmen= t? David > =20 > > Juergen =20 >=20 >=20 >=20 >=20 >=20 >=20