From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 18AFD3FFACF for ; Tue, 26 May 2026 14:53:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779807193; cv=none; b=o5AsJxEo0X3Rvmw5JifJPJ2s5pMoQam+P0gITfJgBmqwYVqF2slqUUE7QfsQffuo/kO3F6LOJqVgNrj6ZPYmi5f9cLnuu6JX9jRLbI/0fYT90nVqMIYf1ks2chw6EXD02eZcARZ4rFDsp07P25+TXBql1RiV/0jhII2cCLHrS5Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779807193; c=relaxed/simple; bh=uVCom8cEIdfHcNG1ttniDkpym2miSRphcVusMyzmVjE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gQNKR905MCVHul4qE7aysT+ze3Rvb5r95ia8/SfQa7rS3ogqLlj17TFUzVovI6rmN0yoGcifs0qHBpIamJ/ACT6VU9cyn14+rzu6Rc0z9oBDClef6G5LvZPhlhFdDT2e419DO6n6YvILLL6av+0WyyNmNbyT343UFtN1FQIUwhQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=WuYAJhAN; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="WuYAJhAN" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=rZqhwZAX9gu8lRikViZCp0rEPli4a286DTrRRjyvllQ=; b=WuYAJhANIcWzzse+dgQGkYqb5a sTO9DiiY9WqvwBeNnKJgGHjCYn/gJh9auXrf16rHEn4GligS1r5rYO1ULIahN2W4UH5P5cTD3sDfv oju7p8gCs1SvahCyN18CxQTeQrr7ZlVdnmFa/IL+fmp5TELb+oIbxd4hpWxqQKsRTjSa73NSlaMbT 9fR8xMsZZbSiW7o/VDf/UsUmw14ax0q2W2+1nLvR5HD6JI2O893xWpRIXDFCxHLrIcoYuhhL/Vhzb +6d5I7f7kq9l6f5dw2S1xF1++r5c4AVPSbZVwee2+jMdpzr1QyfQursdOS9ftc9JrMvAFX9eZo7tg AXa8kRnQ==; Received: from 186-249-145-161.shared.desktop.com.br ([186.249.145.161] helo=[192.168.1.68]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wRt9G-008TwX-4x; Tue, 26 May 2026 16:52:50 +0200 From: Mauricio Faria de Oliveira Date: Tue, 26 May 2026 11:52:33 -0300 Subject: [PATCH v4 1/4] x86/asm: move inline string functions to 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: 7bit Message-Id: <20260526-pvh-kasan-inline-v4-1-a310e6a25ecd@igalia.com> References: <20260526-pvh-kasan-inline-v4-0-a310e6a25ecd@igalia.com> In-Reply-To: <20260526-pvh-kasan-inline-v4-0-a310e6a25ecd@igalia.com> To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Juergen Gross , Alexey Dobriyan , Boris Ostrovsky Cc: kernel-dev@igalia.com, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, Mauricio Faria de Oliveira , kernel test robot X-Mailer: b4 0.14.2 In a future patch, 'boot/string.c' will include inline string functions. Using the header is problematic for a couple of reasons (i.e., build errors), which can be addressed, but introduce unnecessary complexity and regression risk (beyond these _found_ couple of reasons). Using a new header is simpler and transparent to existing users of , with less changes to 'boot/string.c' and its users (eg 'boot/compressed/string.c' and 'purgatory/purgatory.ro'), which minimize regression risk. No functional change intended. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202605140922.q7IlUv7o-lkp@intel.com/ Signed-off-by: Mauricio Faria de Oliveira Reviewed-by: Juergen Gross --- (*) Reasons not to include in 'boot/string.c': 1) 'boot/string.c' is built for 16-bit/real mode thus some type and word size errors happen when include, e.g., . This can be addressed with '#ifndef _SETUP' (defined by 'boot/Makefile'). 2) 'boot/string.c' is included by 'boot/compressed/string.c' which is the source of 'purgatory/string.o', linked by 'purgatory/purgatory.ro' (CONFIG_KEXEC_FILE). In 64BIT, includes , which references __memset() and __memmove() with KCFI_REFERENCE(), ie, __ADDRESSABLE(); however, 'purgatory/purgatory.ro' is not linked with implementations. So, CONFIG_KEXEC_FILE and CONFIG_CFI without CONFIG_KASAN hit errors: >> ld.lld: error: undefined symbol: __memset >>> referenced by string.c >>> arch/x86/purgatory/purgatory.ro:\ (__UNIQUE_ID_addressable___memset_0) -- >> ld.lld: error: undefined symbol: __memmove >>> referenced by string.c >>> arch/x86/purgatory/purgatory.ro:\ (__UNIQUE_ID_addressable___memmove_1) (Note: this is not hit with CONFIG_KASAN because 'boot/compressed/string.c' adds aliases __memset()/__memmove() to memset()/memmove() in that case.) This can be addressed with 'CFLAGS_string.o := -D__DISABLE_EXPORTS' so to disable KCFI_REFERENCE() in 'purgatory/Makefile' (it removes CC_FLAGS_CFI anyway). ... However, since a change in this series would need more changes to address errors it causes, it is reasonable to change the series not to cause them, by using a separate header with _just_ inline string functions. --- arch/x86/include/asm/string.h | 21 +-------------------- arch/x86/include/asm/string_inline.h | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/arch/x86/include/asm/string.h b/arch/x86/include/asm/string.h index 9cb5aae7fba9ffcf0f5af8f939d30467750ccaa9..8a849bb5d0c7100a2a1820ec0af9fc9f850727fd 100644 --- a/arch/x86/include/asm/string.h +++ b/arch/x86/include/asm/string.h @@ -8,25 +8,6 @@ # include #endif -static __always_inline void *__inline_memcpy(void *to, const void *from, size_t len) -{ - void *ret = to; - - asm volatile("rep movsb" - : "+D" (to), "+S" (from), "+c" (len) - : : "memory"); - return ret; -} - -static __always_inline void *__inline_memset(void *s, int v, size_t n) -{ - void *ret = s; - - asm volatile("rep stosb" - : "+D" (s), "+c" (n) - : "a" ((uint8_t)v) - : "memory"); - return ret; -} +#include #endif /* _ASM_X86_STRING_H */ diff --git a/arch/x86/include/asm/string_inline.h b/arch/x86/include/asm/string_inline.h new file mode 100644 index 0000000000000000000000000000000000000000..ffcfa6583d2bc7b91d078888518d0e80248af940 --- /dev/null +++ b/arch/x86/include/asm/string_inline.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_STRING_INLINE_H +#define _ASM_X86_STRING_INLINE_H + +static __always_inline void *__inline_memcpy(void *to, const void *from, size_t len) +{ + void *ret = to; + + asm volatile("rep movsb" + : "+D" (to), "+S" (from), "+c" (len) + : : "memory"); + return ret; +} + +static __always_inline void *__inline_memset(void *s, int v, size_t n) +{ + void *ret = s; + + asm volatile("rep stosb" + : "+D" (s), "+c" (n) + : "a" ((uint8_t)v) + : "memory"); + return ret; +} + +#endif /* _ASM_X86_STRING_INLINE_H */ -- 2.51.0