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 8CC3C1FC8 for ; Thu, 23 Apr 2026 15:58:54 +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=1776959937; cv=none; b=evtyuFGTleKfQ2Z5g3tmKr3rV0HBK84Na2goqE13MCmh605bBuwAolRR8QBO8pDsPu2RT7s+yG0Yy2iGbq5FXQmuadUewh5T0rqE/+duhVnQ01MkA35GR70sJqEY3sYvxzFAo9gRTB8CNhcH1K+UXYEgTZD+MyrxWapfHXxtt18= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776959937; c=relaxed/simple; bh=1Xzhjt590SSTISldN0ZqT27mVn5muEQ0oltI6ugfGj0=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type; b=AYEwmdhjHMbGTL/ldJGGyOke6jlF/YhTk32D0tMx6EGLDmF47k2/rOEJKVggAcBoUY434vm0Ofm2Ydr8QFKul51Lx+oZ0H3yt2whi88tAIEesv51jBfpJO11Gm44Rok4VAriQqWH6Av3Jm+jnGKzZGt7LSE3xJFRXJolNF3KS2o= 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=iTiYf3Nz; 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="iTiYf3Nz" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:Message-ID:References: In-Reply-To:Subject:Cc:To:From:Date:MIME-Version: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=xdei9ZM7WTccU6AfBRlzsKRTYKtjrdEquFKjWHLZr4Y=; b=iTiYf3Nzj5Np2xldc79/j65JLs VjsDJrQ0MdOSXjVwmYndAMc5CnAJyL/qhkfzeFgVSH9oP/iuNoZrJlGwDBRnoNdn3tdnvoys5Ergx QAYzIVZiJU5wlHxM9zjXdUkms7dq3RA9wS1oGADO5CXHpkPzA7wmZrUNtIjQS/xz/3bTCsTFqLiGj bl7gSF67h3l35cYri9xNAn8Sb6Vod1++ofxhxBe3pltxcKtmqMDZ5odZ8Umc1pGyQ23Zw3xEWfuAF yjtpFRvwqnJ0LAc/o5PN2wHBjE3lHZtIU2q72C4U67i5xCkmksAu0QlUoCXis2FXMEERxuMVFGHWa ZvBmMFsQ==; Received: from maestria.local.igalia.com ([192.168.10.14] helo=mail.igalia.com) by fanzine2.igalia.com with esmtps (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wFwRl-001AbI-Gv; Thu, 23 Apr 2026 17:58:32 +0200 Received: from webmail.service.igalia.com ([192.168.21.45]) by mail.igalia.com with esmtp (Exim) id 1wFwRi-002EgO-KM; Thu, 23 Apr 2026 17:58:32 +0200 Received: from localhost ([127.0.0.1] helo=webmail.igalia.com) by webmail.service.igalia.com with esmtp (Exim 4.98.2) (envelope-from ) id 1wFwRh-00000000VIN-47KH; Thu, 23 Apr 2026 17:58:30 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Thu, 23 Apr 2026 12:58:30 -0300 From: Mauricio Faria de Oliveira To: David Laight Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Juergen Gross , Alexey Dobriyan , Boris Ostrovsky , kernel-dev@igalia.com, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Subject: Re: [PATCH 1/3] x86/asm, x86/boot: Expose inline memcmp In-Reply-To: <20260422215441.4204c142@pumpkin> References: <20260422-pvh-kasan-inline-v1-0-7e6194344c92@igalia.com> <20260422-pvh-kasan-inline-v1-1-7e6194344c92@igalia.com> <20260422215441.4204c142@pumpkin> Message-ID: <324ef97b16f52e0ccc72f6381d1b5dd2@igalia.com> X-Sender: mfo@igalia.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Report: NO, Score=-2.2, Tests=ALL_TRUSTED=-3,BAYES_50=0.8 X-Spam-Score: -21 X-Spam-Bar: -- On 2026-04-22 17:54, David Laight wrote: > On Wed, 22 Apr 2026 17:07:45 -0300 > Mauricio Faria de Oliveira wrote: > >> Move the inline memcmp function, currently only available to boot code >> (boot/string.c), into the header with similar inline string functions >> (include/asm/string.h) so it may be reused. > > This needs a comment/warning that it is incompatible with normal memcmp() > because it only returns 0/1 not -1/0/1. > Most callers don't care. Thanks for catching and suggesting this. I can also change it to -1/0/1 in a later patch, to keep v2 only a fix and split a behavior change, with something like this (lightly tested): static __always_inline int __inline_memcmp(const void *s1, const void *s2, size_t len) { bool above, below; asm("repe cmpsb" : "+S" (s1), "+D" (s2), "+c" (len), "=@cca" (above), "=@ccb" (below)); return above - below; } cheers, > > David > > >> >> Add a _SETUP guard in string.h so not to include the 32/64-bit specific >> string headers in boot/ code (16-bit, real mode) and avoid build errors. >> >> Signed-off-by: Mauricio Faria de Oliveira >> --- >> arch/x86/boot/string.c | 6 ++---- >> arch/x86/include/asm/string.h | 11 +++++++++++ >> 2 files changed, 13 insertions(+), 4 deletions(-) >> >> diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c >> index b25c6a9303b7314d5caf5c9306239811705294fe..bbee78637b349e42e9281d8df50d89d48f4490b9 100644 >> --- a/arch/x86/boot/string.c >> +++ b/arch/x86/boot/string.c >> @@ -15,6 +15,7 @@ >> #include >> #include >> #include >> +#include >> #include "ctype.h" >> #include "string.h" >> >> @@ -31,10 +32,7 @@ >> >> int memcmp(const void *s1, const void *s2, size_t len) >> { >> - bool diff; >> - asm("repe cmpsb" >> - : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)); >> - return diff; >> + return __inline_memcmp(s1, s2, len); >> } >> >> /* >> diff --git a/arch/x86/include/asm/string.h b/arch/x86/include/asm/string.h >> index 9cb5aae7fba9ffcf0f5af8f939d30467750ccaa9..736a6f6a31f0a68281b4f17415aba0fcd95dc228 100644 >> --- a/arch/x86/include/asm/string.h >> +++ b/arch/x86/include/asm/string.h >> @@ -2,11 +2,13 @@ >> #ifndef _ASM_X86_STRING_H >> #define _ASM_X86_STRING_H >> >> +#ifndef _SETUP >> #ifdef CONFIG_X86_32 >> # include >> #else >> # include >> #endif >> +#endif >> >> static __always_inline void *__inline_memcpy(void *to, const void *from, size_t len) >> { >> @@ -29,4 +31,13 @@ static __always_inline void *__inline_memset(void *s, int v, size_t n) >> return ret; >> } >> >> +static __always_inline int __inline_memcmp(const void *s1, const void *s2, size_t len) >> +{ >> + bool diff; >> + >> + asm("repe cmpsb" >> + : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)); >> + return diff; >> +} >> + >> #endif /* _ASM_X86_STRING_H */ >> -- Mauricio