From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (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 E38C93F485E for ; Fri, 11 Sep 2026 07:04:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789110263; cv=none; b=c8vxtOpVAUuMrBMEL8rFnvnFIZ/2ApFChvPoTPoOhGrJ2JYf1s9qMcpfG5iyJkI/SO2K1272sb4EqQ4JfchcRUcqQ+4E9GwaSIY6A+FhBjo6VMffAGZXlSlFv0Hp0UG1XOIPhgZg9TJbdpzdoX3o7jUP44cp1bnopgJQWU1CGPc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789110263; c=relaxed/simple; bh=R3mamHcjqtuk8KE+ymGSXTr7kdrGSGWqP7eBuJzhREA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Fjw6UI0L3Rst+gAaIN5EJN4sKca5UCXvjbmSiwLUp/a2vmky70kqd3FRliII+IFwGohk/faU6SgS0LkiQMIRH45hZGHSGiE3nHTPd75ADc7ZahZmUE2IXNAVyAp/PK/ky09QEdYyuwb7BLS+buLDDTqrVBu0leh8BYkGBSawT1M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--morbo.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=hSAKQ/S2; arc=none smtp.client-ip=209.85.214.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--morbo.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hSAKQ/S2" Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-2cec4226c70so7973065ad.1 for ; Fri, 11 Sep 2026 00:04:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789110253; x=1789715053; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=v4log2b7lXSyNC0NL5JxC6rtxmWq5NdYaV3uhGWFgpQ=; b=hSAKQ/S2mhCvMF2YYH3xWnDEBCvTgwRmu+c2IkdWvo2Cn1xKPrMPO8Fch9nBooG+jN Yo5nINC9akFagDai8BWJTafV2gQVFKk6A1TSVCbANNaV8XwLvB0QZ2k0D7eI80Oo2F8y U/EBYpJmBTwIVT6ABFKNwnCAmoeAMp62vtA2Rs401YCydnmJBvaD6wXqRFwUjyvMsMQu YNyfDri9jdmoWJ7kt1b6uaUE5En/vyVZu1tr6lCrL9Sc0y8GpSE90kpa18sHd20S+Isc P62GONAd/6oeUUtNwxqUvYNGmmnKGpB89oPpGsDBveTHTev4tAPijB7xGLbnPx+nOAxO FoUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789110253; x=1789715053; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=v4log2b7lXSyNC0NL5JxC6rtxmWq5NdYaV3uhGWFgpQ=; b=OccT3VKvM8hVF/JLdkYiOCKWRlCBtDA5C9bGRftmaUUBVMwcZMcFgdygy7esnP7zlV cFLqx6X/6nAoyG1eIrPvAa11jHDkulURHt+tEP5Ye6eZis86I8/OVHIKF2rXiz2vgMLw aFOqaktphARsO1GHNymMeGQEq6qshGR9MgMf2h2EM1mYbl37fu+aW1uvRTLAs36T9Dk/ bPe0qbWL/+RBUKh1ZBOHj08lkHn5TRW9lVH7+7sDTBza4QvIYUBdTUaPDchrdjqlhTuu EMddzfETzmeFgh9501PPKuNXi+TJDJJDfrsivpK0tvp5zk0yiauN+oxyPtTc3S2sKylz cTNA== X-Gm-Message-State: AFuF++lZ2ODsUSAYSD7ALRi7I8kzXidAsOA23F1Soyw5pAEXmzKAvpEX dGLWo4aM9//MJIHFPHOK+nVWWJ31GbCw2vP1K8wMh6AAijEYKdPSfzNk4j7cccUZSJqYniUw5Kh S+s7YAFkGhsS4hDQnqHNEBnfUei42GgCENZAmSYG1yZMB3OU0fUuqrnAdgOj69VYRhodjmNZg1y GZZPReJWthWVCO03iKmS6aO94fHtDTD7Ia2yMZgA== X-Received: from plbmm11.prod.google.com ([2002:a17:903:a0b:b0:2db:34ec:27e6]) (user=morbo job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2983:b0:2db:257c:9fd5 with SMTP id d9443c01a7336-2dd2a35dd2bmr69446655ad.16.1789110252766; Fri, 11 Sep 2026 00:04:12 -0700 (PDT) Date: Fri, 11 Sep 2026 07:03:40 +0000 In-Reply-To: <20260911070346.801948-1-morbo@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260911070346.801948-1-morbo@google.com> X-Mailer: git-send-email 2.55.0.1032.g73a4cd73de-goog Message-ID: <20260911070346.801948-3-morbo@google.com> Subject: [PATCH 2/7] x86/word-at-a-time: Instrument load_unaligned_zeropad() From: Bill Wendling To: linux-kernel@vger.kernel.org Cc: Bill Wendling , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Arnd Bergmann , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Kees Cook , Catalin Marinas , Peter Collingbourne , linux-arch@vger.kernel.org, linux-riscv@lists.infradead.org, x86@kernel.org Content-Type: text/plain; charset="UTF-8" load_unaligned_zeropad() is implemented as inline asm plus an exception table entry on every architecture, so the compiler never sees the actual memory access and cannot emit KASAN/KCSAN instrumentation for it. Resurrect the instrumentation that was lost when migrating from read_word_at_a_time() by renaming load_unaligned_zeropad() to arch_load_unaligned_zeropad() and adding a common instrumented load_unaligned_zeropad() in the new asm-generic/word-at-a-time-instrumented.h, pulled in from the bottom of asm/word-at-a-time.h. This mirrors the existing arch_atomic_*()/atomic_*() split in linux/atomic/atomic-instrumented.h, where the arch_* version is the raw, uninstrumented primitive and the plain name is the instrumented one everyone should call. The wrapper is __always_inline, so it compiles down to exactly the same inline asm as before plus instrument_read() -- confirmed via objdump that no calls or relocations to load_unaligned_zeropad(), instrument_read(), or the KASAN/KCSAN check functions remain when KASAN and KCSAN are both disabled. Convert x86 to the new split here. Follow-up patches convert the remaining architectures (arm64, arm, riscv, s390, powerpc) that implement load_unaligned_zeropad(). Fixes: d94c12bd97d5 ("string: Add load_unaligned_zeropad() code path to sized_strscpy()") Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Bill Wendling --- Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Arnd Bergmann Cc: Paul Walmsley Cc: Palmer Dabbelt Cc: Albert Ou Cc: Alexandre Ghiti Cc: Kees Cook Cc: Catalin Marinas Cc: Peter Collingbourne Cc: linux-kernel@vger.kernel.org Cc: linux-arch@vger.kernel.org Cc: linux-riscv@lists.infradead.org Cc: x86@kernel.org --- arch/x86/include/asm/word-at-a-time.h | 4 ++- .../asm-generic/word-at-a-time-instrumented.h | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 include/asm-generic/word-at-a-time-instrumented.h diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h index 422a47746657..483d27dc96b2 100644 --- a/arch/x86/include/asm/word-at-a-time.h +++ b/arch/x86/include/asm/word-at-a-time.h @@ -67,7 +67,7 @@ static inline unsigned long find_zero(unsigned long mask) * and the next page not being mapped, take the exception and * return zeroes in the non-existing part. */ -static inline unsigned long load_unaligned_zeropad(const void *addr) +static inline unsigned long arch_load_unaligned_zeropad(const void *addr) { unsigned long ret; @@ -81,4 +81,6 @@ static inline unsigned long load_unaligned_zeropad(const void *addr) return ret; } +#include + #endif /* _ASM_WORD_AT_A_TIME_H */ diff --git a/include/asm-generic/word-at-a-time-instrumented.h b/include/asm-generic/word-at-a-time-instrumented.h new file mode 100644 index 000000000000..8a66d53bf538 --- /dev/null +++ b/include/asm-generic/word-at-a-time-instrumented.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_WORD_AT_A_TIME_INSTRUMENTED_H +#define _ASM_GENERIC_WORD_AT_A_TIME_INSTRUMENTED_H + +#include + +/* + * Each arch's asm/word-at-a-time.h defines arch_load_unaligned_zeropad() + * as inline asm plus an exception table entry, so the compiler never sees + * the actual memory access and cannot emit KASAN/KCSAN instrumentation + * for it. Provide the common, instrumented load_unaligned_zeropad() that + * every caller uses by wrapping the arch version with instrument_read(). + * + * This is marked __always_inline, and arch_load_unaligned_zeropad() is + * itself a tiny inline-asm-only function, so this compiles down to the + * same inline asm as before plus instrument_read() (which itself compiles + * to nothing when KASAN and KCSAN are both disabled) -- no actual call. + */ +static __always_inline unsigned long load_unaligned_zeropad(const void *addr) +{ + instrument_read(addr, 1); + return arch_load_unaligned_zeropad(addr); +} + +#endif /* _ASM_GENERIC_WORD_AT_A_TIME_INSTRUMENTED_H */ -- 2.47.3