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 C2E4622B8AB for ; Sun, 19 Jul 2026 08:38:40 +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=1784450321; cv=none; b=dMUE2d+4LzmXHAoLdMl8zM67Tt0Ka2PCAWJUk7QdIs4PsvKb4xF1KWE+T4Z+xEh7iaJ5ipbpfe7tWBsystUTtyj7NrnS12pXTh+i9mB7QBYDwTr4Adwfm0UkqZ2dGq9K/rsF0R2qhRBAhuKmEIUm+hF3YLRVZ70zL2TsM8A3b+U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784450321; c=relaxed/simple; bh=oSDP9LVj/wTmgw4b9hJ+65YXPB4eYin3/22NmcN/KBM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RBYBV5SbqfloFIrI2+qMVL3y9/0ZBSoVaFlyy1Sx/OqRiKga26QmhPU+Mqw70QQ49HCRMItJ1IeThO/FnkYQUHWWle7Vzuh4c1it4bO6tw9emuFAlPMo847RWMIATe+gvMO8WJi337kQhXr7ng0NHW0BrlY474nd5R+df/fM5NM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UM4nEjFW; 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="UM4nEjFW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79BFA1F000E9; Sun, 19 Jul 2026 08:38:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784450320; bh=ezIYJMlF6PhGPeUzfNMuJHSTK7rUp/MhQjKYM0Z8Ftk=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=UM4nEjFWaBPQI3s8viSLG0Ylrc/syEnp5SGRXh2l21W3FkLBAxOfDdTBPWlbBuhDH oc7+L6si2pZmXZEfEWAeuDpsX0NOyhPqcSQPhuCazhyemSbzGzVtZZzT2jFMlXEQ0f df0T6ef+vT5YCXa+oz7s3UrOq8487Wh7ugz8vNNKgm6qBD/duLOkxYxSbdYAJnm88J p1vJMds6n0Z4Il8QO1uU2XPcn/kOin1nNwEi8UPV3g+nbfga5NebqhmL4Z6jzdLxKL SQ6iZXqukFUlh0EpZDrDisJJGuHnmr7zIP+0q6IOQ9bMI5mD+lFAs9yKhR18gGui3t pjHJ1G+RzRxhA== Date: Sun, 19 Jul 2026 11:38:32 +0300 From: Mike Rapoport To: David Laight Cc: Dave Hansen , Andy Lutomirski , Borislav Petkov , Ingo Molnar , Ingo Molnar , Juergen Gross , "H. Peter Anvin" , Peter Zijlstra , Thomas Gleixner , 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() Message-ID: References: <20260717-verify-rwx-fix-v2-1-fc23141311d6@kernel.org> <20260717113209.178573db@pumpkin> 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=us-ascii Content-Disposition: inline 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)" 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) > > Reviewed-by: Juergen Gross > > --- > > 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.