From nobody Sun Feb 8 05:23:25 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6D456326D63 for ; Wed, 24 Dec 2025 11:21:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766575277; cv=none; b=RYKx3NjJpdiuYYiURSTtM/0xrro5tnG8uhv3U+eiJiNMx3rEA53Hvycho6hobSvbnyWvWaKBoY/SPezT1rMJhbM/ZFBnrgytm9pZahQ93cWGL8fY3lkmGSRcgoTR85TylWyTU6H/1XbrMB1N7nNpmJxrmODPY5CF0CLw8h9IsD0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766575277; c=relaxed/simple; bh=M5yFgKD2Ib3qD1QX8R9fTV8O/Sif57m4EVWR5kO0sVw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aXQRO9huLhuwq16xfewo315sw8AcrCx+vqJpO3DVprLj2vDMyDZb2+f/1Bh5p1jwCGg2CUSvZtFXRISp8mbiLl9vQ0ZwyIKyL1hKzocd5BenIK9buHkBlwq1rDtvJw90JTMnzoZ0yfOzn8qJmg4wEopKw2of4bvZYYDgFqxtAU4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dHe3ucKM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dHe3ucKM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18A43C16AAE; Wed, 24 Dec 2025 11:21:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1766575277; bh=M5yFgKD2Ib3qD1QX8R9fTV8O/Sif57m4EVWR5kO0sVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dHe3ucKMyAOFToZEzJLoIz/kxV9RI7kW/Ck/hov7wo82ufvmdCB5tj0svBM7oBJ/0 ie6gnxNqFzrUmmPubYdVt5B913lnF/DzBu3KyuDFSI37SNX3LCWzQM1ni7vRS5uxZd DI63KBwjgcDvIPI8JShARo72pTsPxFe8G9qdvrf1CLzJTaTRqGqAyR/LU63LknpkwD ov9sjksZ5FIV9dfYMo4j+0kovK4qoLhuwvS1ql1Wd/HvURowT1TRkvgtGdg3A/lti/ uAHFG19hYtRbIWCCmGNm60xIYEdqJ9qvfRNkiFApogQ1Ozw1MwJygJZSKsjxpJ4MPm Nhmce6e0I9CJQ== From: "Christophe Leroy (CS GROUP)" To: Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v5 1/7] powerpc/uaccess: Move barrier_nospec() out of allow_read_{from/write}_user() Date: Wed, 24 Dec 2025 12:20:49 +0100 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3128; i=chleroy@kernel.org; h=from:subject:message-id; bh=FRyCNlus/chAL58mdj2A43JkP4XfcjBtB27GVJaNvtw=; b=owGbwMvMwCV2d0KB2p7V54MZT6slMWR6n5ltnzvBPqx+m9qJ7J2m0j8u12bXzBKReHBvoYZ1i 8hdq/csHaUsDGJcDLJiiizH/3PvmtH1JTV/6i59mDmsTCBDGLg4BWAiF6sY/hmLHZ/Iypa1/cSc dddbi+TXvrJ/E3LuYD3f5p7TZSKbp8xi+B/aoZKm9vv+zKCzZyryZt79kGbvbrJTyviVmewya09 +Y0YA X-Developer-Key: i=chleroy@kernel.org; a=openpgp; fpr=10FFE6F8B390DE17ACC2632368A92FEB01B8DD78 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Christophe Leroy Commit 74e19ef0ff80 ("uaccess: Add speculation barrier to copy_from_user()") added a redundant barrier_nospec() in copy_from_user(), because powerpc is already calling barrier_nospec() in allow_read_from_user() and allow_read_write_user(). But on other architectures that call to barrier_nospec() was missing. So change powerpc instead of reverting the above commit and having to fix other architectures one by one. This is now possible because barrier_nospec() has also been added in copy_from_user_iter(). Move barrier_nospec() out of allow_read_from_user() and allow_read_write_user(). This will also allow reuse of those functions when implementing masked user access which doesn't require barrier_nospec(). Don't add it back in raw_copy_from_user() as it is already called by copy_from_user() and copy_from_user_iter(). Fixes: 74e19ef0ff80 ("uaccess: Add speculation barrier to copy_from_user()") Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/kup.h | 2 -- arch/powerpc/include/asm/uaccess.h | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/include/asm/kup.h b/arch/powerpc/include/asm/kup.h index dab63b82a8d4..f2009d7c8cfa 100644 --- a/arch/powerpc/include/asm/kup.h +++ b/arch/powerpc/include/asm/kup.h @@ -134,7 +134,6 @@ static __always_inline void kuap_assert_locked(void) =20 static __always_inline void allow_read_from_user(const void __user *from, = unsigned long size) { - barrier_nospec(); allow_user_access(NULL, from, size, KUAP_READ); } =20 @@ -146,7 +145,6 @@ static __always_inline void allow_write_to_user(void __= user *to, unsigned long s static __always_inline void allow_read_write_user(void __user *to, const v= oid __user *from, unsigned long size) { - barrier_nospec(); allow_user_access(to, from, size, KUAP_READ_WRITE); } =20 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/= uaccess.h index 784a00e681fa..3e622e647d62 100644 --- a/arch/powerpc/include/asm/uaccess.h +++ b/arch/powerpc/include/asm/uaccess.h @@ -301,6 +301,7 @@ do { \ __typeof__(sizeof(*(ptr))) __gu_size =3D sizeof(*(ptr)); \ \ might_fault(); \ + barrier_nospec(); \ allow_read_from_user(__gu_addr, __gu_size); \ __get_user_size_allowed(__gu_val, __gu_addr, __gu_size, __gu_err); \ prevent_read_from_user(__gu_addr, __gu_size); \ @@ -329,6 +330,7 @@ raw_copy_in_user(void __user *to, const void __user *fr= om, unsigned long n) { unsigned long ret; =20 + barrier_nospec(); allow_read_write_user(to, from, n); ret =3D __copy_tofrom_user(to, from, n); prevent_read_write_user(to, from, n); @@ -415,6 +417,7 @@ static __must_check __always_inline bool user_access_be= gin(const void __user *pt =20 might_fault(); =20 + barrier_nospec(); allow_read_write_user((void __user *)ptr, ptr, len); return true; } @@ -431,6 +434,7 @@ user_read_access_begin(const void __user *ptr, size_t l= en) =20 might_fault(); =20 + barrier_nospec(); allow_read_from_user(ptr, len); return true; } --=20 2.49.0