From nobody Sat Feb 7 10:08:02 2026 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (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 64586185939 for ; Sat, 23 Nov 2024 09:47:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732355266; cv=none; b=jc57UMhGH21O5pI1cL0Wldopv3SD5tVfRT4nLBlPVUhNgNk7aOu9AMWCizTJ5iqvYSbe4L4VwMor/gBMddqZIdhcf+CndO7RN404Qvc4DF0NN0FUbNn06ekW0egViZwrcDooujLsmYnGGc8wXwswK6H6/p02KmqyPQN7yM1AA4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732355266; c=relaxed/simple; bh=lk4JULyB77R1m3+zIEqqwIEYphVgQiXFvTfAM8r1YpA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tI480cEvjyRAAJ0AnWKo/50+b8nwVCcWxBYNsCWwg0btFTinFD6XTtbd9bwnF1bav++WP0yZSdDOP3YmB4P3wJNHohksmz/JeL/IN80z4JgzFHW1tBGTPeFUShMUc/bB0Lk5jfsmi96m/VyNnDQpNQFMHW4g3oU9aC/IDScfss4= 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=f2qxKVK9; arc=none smtp.client-ip=209.85.208.169 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="f2qxKVK9" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2fb388e64b0so34696141fa.0 for ; Sat, 23 Nov 2024 01:47:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732355262; x=1732960062; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=StUlAr6p77Gw1Xl5bleouTa+4voBxpVFLX0KT3Pnj6g=; b=f2qxKVK9iLTLFxiwxar2X/gN06vAb9MwlV/DEDxXux7kb1cWk3WO2IBQ/aCpA4VWQr wpUCEBL+O2HjoaEpke7vuD3NHxQwlFkl2zVKpfMSVJZLYPKn7udaCDPzGuYYCazBBvgK HusbPm3E7ds79KMHrSdGU4s6JG4cF2plUmibTE3es7PSI0oTIv7oO1/je97lSeCwK1Vf oW6jIdu8gMnUfwiO4WjW+1/1zymlAPeZhK3jo/0ayOFrUvxxgNzmo+t++hGyp6cO1R+A WHYxstoa0XDpLQu/fU7NfHB4qcJzqUfTF0r+wtWAgRN8Ut/FiB+UUda1KRZUudaW0KF4 ZC2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732355262; x=1732960062; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=StUlAr6p77Gw1Xl5bleouTa+4voBxpVFLX0KT3Pnj6g=; b=MaSJiNDrWLfrGVbWwJFiW01G7pxyE+G1Mgq612azCMeHvBNPKIEZlye8EKGDXeW58k VGlbMFa/6K1ntgEBEjwVwEebuJanNsM3d0tn5tLa7BFgUz+vTj+tAruODCc1b59Goyi9 tiJAf4cQmJe/K5q6TT1ekl1gCr/ypKwt3FflQSfs3wt8R4yTB7IlOY5cLGTSCs0NSwXg vb/NgT+7d4e1mQg45cUigH264+7ue7GExlNPtX7kyPAgc6FBedV4stzEqhJ6GkYLlMNI 5wTxk9Y+OPJq+2ItslczaBu65UjFQd0LAAwvOUDFkd61bZKo6KJLjHVbHyAhazYB7yY7 DjWA== X-Gm-Message-State: AOJu0YxlXMoxkVAmg06/5WkaZTQzWfjUFCcPTE3tUOXkolKOvi9izmTp 3JpgGbxC9Gm+CtXvf8W1RZrEuowHTaHEshNeBWRvumLjmBtJXVWg X-Gm-Gg: ASbGnctVDdWKHFs3Rw77E6KHtQwO0thlArdOLAUu1BFUoe/vu/hFM4QU3S008heYqO9 M+UwlCel6mn6IHFs9N7YNuU+X45bMtK/0el2yxl5P1YrPFQJYHWPqjlHrmkBEoo18YLmGlsAWJi XP44RBog99+n/R3GylwwffoCAJxywy+bCclO3CInAx6I77iMfRVzGcNObjXIHGPM+5rrRWMUG8b rFQvNA0Sxc5ObXFbBhFdnakD+nkbA7qVNk6BuTd6MF5AKZqiJFj5oFOA7D5NNRv+A== X-Google-Smtp-Source: AGHT+IFED4EXtryokWjqi11tEn3yvFfrmgLfyFdFW1l/DMA6NOv3mGtQgRYzxT/BKaCx2yS3PBy8pQ== X-Received: by 2002:a05:6512:b12:b0:53d:d242:6bb0 with SMTP id 2adb3069b0e04-53dd39b6ee5mr3476480e87.49.1732355262113; Sat, 23 Nov 2024 01:47:42 -0800 (PST) Received: from f.. (cst-prg-93-87.cust.vodafone.cz. [46.135.93.87]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d01d3c2294sm1817427a12.53.2024.11.23.01.47.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Nov 2024 01:47:41 -0800 (PST) From: Mateusz Guzik To: tglx@linutronix.de, bp@alien8.de, andy@kernel.org, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Mateusz Guzik Subject: [PATCH 1/2] x86/callthunks: s/bcmp/memcmp/ Date: Sat, 23 Nov 2024 10:47:28 +0100 Message-ID: <20241123094729.1099378-2-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241123094729.1099378-1-mjguzik@gmail.com> References: <20241123094729.1099378-1-mjguzik@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" bcmp() is implemented as a call to memcmp() and callthunks is the only consumer. Use memcmp() directly so that bcmp() can get retired. Signed-off-by: Mateusz Guzik --- arch/x86/kernel/callthunks.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/callthunks.c b/arch/x86/kernel/callthunks.c index 465647456753..dda60b91944f 100644 --- a/arch/x86/kernel/callthunks.c +++ b/arch/x86/kernel/callthunks.c @@ -188,11 +188,11 @@ static void *patch_dest(void *dest, bool direct) apply_relocation(insn_buff, pad, tsize, skl_call_thunk_template, tsize); =20 /* Already patched? */ - if (!bcmp(pad, insn_buff, tsize)) + if (!memcmp(pad, insn_buff, tsize)) return pad; =20 /* Ensure there are nops */ - if (bcmp(pad, nops, tsize)) { + if (memcmp(pad, nops, tsize)) { pr_warn_once("Invalid padding area for %pS\n", dest); return NULL; } @@ -309,7 +309,7 @@ static bool is_callthunk(void *addr) memcpy(insn_buff, skl_call_thunk_template, tmpl_size); apply_relocation(insn_buff, pad, tmpl_size, skl_call_thunk_template, tmpl= _size); =20 - return !bcmp(pad, insn_buff, tmpl_size); + return !memcmp(pad, insn_buff, tmpl_size); } =20 int x86_call_depth_emit_accounting(u8 **pprog, void *func, void *ip) --=20 2.43.0 From nobody Sat Feb 7 10:08:02 2026 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 3A92618A6B8 for ; Sat, 23 Nov 2024 09:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732355269; cv=none; b=fG0XKf64M/Ca2a1WtuewWYmsjJtZebRlwNFiJaMAzFrLOTT1zliyUBuzmJEkrtCARPW63ZeXfBCyX1O/IEtqIi+CoS23O4bFpz83WjkqnsiSLs9KdUnxrY2SqpHmlbCVtoWtDusm/BImUlSzc/xcs5cshVsSqGxaHe68YXOSH4Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732355269; c=relaxed/simple; bh=/weL+RHxYRT2sc4snfesaJ/PKodr3pweOq0UKMGWplk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l6iD19U3iUkiO6XuSO8ctCFgfc9brkGCIWBt/eQklfpqcByXu0c5rrDxuQQFFDCfna6gN4XeVTVnSE1Ycfdfx5ukUVy7or/yP+ar56n0/Z1AuL3RYlE0EWt9dQGqjjXHZUK8aI2PSA9ulxD3kdj9MKWgBHePDvxigIKxL9gVoCk= 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=OixYiWnu; arc=none smtp.client-ip=209.85.208.49 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="OixYiWnu" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5cfa90e04c2so3217372a12.1 for ; Sat, 23 Nov 2024 01:47:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732355265; x=1732960065; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QNBz0MU3962msQGvdaa4ePqZV5jTJbWC+jhpcScGK1I=; b=OixYiWnuEg+YH0AX/ROCCx3uAtgLmZyhsh3LMi5gCSXuKhknlzmQ2XDrQLJO35E3l/ ifP0LOdizw3IeUJhT+a/Ai5yhg+ttqlKUxkdyzrFYh/O5fZngzeR+rbxtF7enRvReu3Q V2HqzHoRmtLtxUXi45T4P1nMGullz5PiCnS3kNwO0hSuKzHiQKCr0pjIh6hXhLET62db kvyMNkPrsdg3APoMuLfZ5tX7IjHzT4PNhMF1cEjsawoWkHR61Bd5VG/5DGiEHwTonrEK uCVIdraEGcZKQd+e/C/ScW029dLE0AObeR8wlFpb3oEm5bE3G/8fLKVw97ht3NkwXqPQ 1lIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732355265; x=1732960065; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QNBz0MU3962msQGvdaa4ePqZV5jTJbWC+jhpcScGK1I=; b=t99dciaSeV9VhcXI4wsEaKdq1nF0gKy4chqM8fRSbsjlYjF6jQvCh4JV0IgaCOb9Iv X3UYUYMw1H/hhZKnhOKRP3I8qiUo+z4dRwHvuroqXYO8ssZ1z5pncPLWzgIqIp6BtyfS cuRtOXeih8jZcTzoEQVm3BG+GCKhklhAkqJhp4w2iiuZYMYrSUCS0LiUtTS+lUofRhFn bTXzZTHfMdmntVdVfJLdF7IRzvwTiZwXzP7Cz0RJw/8eqZr+Z7aZ3YLecYdVONsQ1inY OC0mgACQ6s9YiueQLF367MVK/wJ0pCdyrDbWBt/kwmRk0zupwR/StKUs3Vh/tAjfSXLi L4sw== X-Gm-Message-State: AOJu0YxZxrMaoW0wQ+vEoZiMjhW+/EUQSOFdwcXy9sTlC5LmDPIq30G0 tNuftUiA3hVHqoMld3rfm52DzIMzCgv2qA8VKJUFwN0k+49mdB9W X-Gm-Gg: ASbGncvRT+KtIFodYgmvr3Npk1u4LBrXL/nD2ivK3fbO9M3xxZ905Rsh2ncp2Tx+IB/ zyZyQc5Z59BKQ1mNB3VTW4lLoDTrAw3hfX9ZPWSerwmBSAGLuw3u0DaXKNexnIf3C7+HgsoN0M5 hBDRRHiEZ0+QfSgqSVtD9GxMxWITSQE8GN8AIyNBeH390wo9oEtmJAjCiEhkRMrg1bOgTAEtXGf IccDlS3jgN2W1ixeJfaFRjzxklBHKG/ovRBrRdOWmj/7mBlhcZQVvWRO+L0cpQw+Q== X-Google-Smtp-Source: AGHT+IG44IU6wFCJFK+Qg05WJ38hwIHfPCaheO1jvBiDGmynuqeMQ3Cp8+11X6SHlYc2OCdlF5/WaA== X-Received: by 2002:a05:6402:35c8:b0:5cf:d8aa:3f14 with SMTP id 4fb4d7f45d1cf-5d0207929camr4471223a12.22.1732355265301; Sat, 23 Nov 2024 01:47:45 -0800 (PST) Received: from f.. (cst-prg-93-87.cust.vodafone.cz. [46.135.93.87]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d01d3c2294sm1817427a12.53.2024.11.23.01.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Nov 2024 01:47:44 -0800 (PST) From: Mateusz Guzik To: tglx@linutronix.de, bp@alien8.de, andy@kernel.org, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Mateusz Guzik Subject: [PATCH 2/2] string: retire bcmp() Date: Sat, 23 Nov 2024 10:47:29 +0100 Message-ID: <20241123094729.1099378-3-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241123094729.1099378-1-mjguzik@gmail.com> References: <20241123094729.1099378-1-mjguzik@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" While architectures could override it thanks to __HAVE_ARCH_BCMP, none of them did. Instead it was implemented as a call to memcmp(). These routines differ in the API contract: memcmp()'s result indicates which way the difference goes (making it usable for sorting), whereas bcmp()'s result merely states whether the buffers differ in any way. This means that a dedicated optimized bcmp() is cheaper to execute than memcmp() for differing buffers as there is no need to compute the return value. However, per the above nobody bothered to write one and it is unclear if it makes sense to do it. Users which really want to compare stuff may want to handle it differently (like e.g., the path lookup). As there are no users and the code is merely a wrapper around memcmp(), just whack it. Signed-off-by: Mateusz Guzik --- arch/x86/boot/string.c | 8 -------- arch/x86/boot/string.h | 1 - include/linux/string.h | 3 --- lib/Makefile | 3 +-- lib/string.c | 19 ------------------- 5 files changed, 1 insertion(+), 33 deletions(-) diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c index c23f3b9c84fe..e8095abf03df 100644 --- a/arch/x86/boot/string.c +++ b/arch/x86/boot/string.c @@ -37,14 +37,6 @@ int memcmp(const void *s1, const void *s2, size_t len) return diff; } =20 -/* - * Clang may lower `memcmp =3D=3D 0` to `bcmp =3D=3D 0`. - */ -int bcmp(const void *s1, const void *s2, size_t len) -{ - return memcmp(s1, s2, len); -} - int strcmp(const char *str1, const char *str2) { const unsigned char *s1 =3D (const unsigned char *)str1; diff --git a/arch/x86/boot/string.h b/arch/x86/boot/string.h index e5d2c6b8c2f1..cf83faee78cc 100644 --- a/arch/x86/boot/string.h +++ b/arch/x86/boot/string.h @@ -11,7 +11,6 @@ void *memcpy(void *dst, const void *src, size_t len); void *memmove(void *dst, const void *src, size_t len); void *memset(void *dst, int c, size_t len); int memcmp(const void *s1, const void *s2, size_t len); -int bcmp(const void *s1, const void *s2, size_t len); =20 /* Access builtin version by default. */ #define memcpy(d,s,l) __builtin_memcpy(d,s,l) diff --git a/include/linux/string.h b/include/linux/string.h index 0dd27afcfaf7..d4904951b627 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -267,9 +267,6 @@ extern void * memscan(void *,int,__kernel_size_t); #ifndef __HAVE_ARCH_MEMCMP extern int memcmp(const void *,const void *,__kernel_size_t); #endif -#ifndef __HAVE_ARCH_BCMP -extern int bcmp(const void *,const void *,__kernel_size_t); -#endif #ifndef __HAVE_ARCH_MEMCHR extern void * memchr(const void *,int,__kernel_size_t); #endif diff --git a/lib/Makefile b/lib/Makefile index 773adf88af41..c382b43fe37e 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -265,8 +265,7 @@ obj-$(CONFIG_IRQ_POLL) +=3D irq_poll.o obj-$(CONFIG_POLYNOMIAL) +=3D polynomial.o =20 # stackdepot.c should not be instrumented or call instrumented functions. -# Prevent the compiler from calling builtins like memcmp() or bcmp() from = this -# file. +# Prevent the compiler from calling builtins like memcmp() from this file. CFLAGS_stackdepot.o +=3D -fno-builtin obj-$(CONFIG_STACKDEPOT) +=3D stackdepot.o KASAN_SANITIZE_stackdepot.o :=3D n diff --git a/lib/string.c b/lib/string.c index 76327b51e36f..3a319d1c5aae 100644 --- a/lib/string.c +++ b/lib/string.c @@ -680,25 +680,6 @@ __visible int memcmp(const void *cs, const void *ct, s= ize_t count) EXPORT_SYMBOL(memcmp); #endif =20 -#ifndef __HAVE_ARCH_BCMP -/** - * bcmp - returns 0 if and only if the buffers have identical contents. - * @a: pointer to first buffer. - * @b: pointer to second buffer. - * @len: size of buffers. - * - * The sign or magnitude of a non-zero return value has no particular - * meaning, and architectures may implement their own more efficient bcmp(= ). So - * while this particular implementation is a simple (tail) call to memcmp,= do - * not rely on anything but whether the return value is zero or non-zero. - */ -int bcmp(const void *a, const void *b, size_t len) -{ - return memcmp(a, b, len); -} -EXPORT_SYMBOL(bcmp); -#endif - #ifndef __HAVE_ARCH_MEMSCAN /** * memscan - Find a character in an area of memory. --=20 2.43.0