|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH RESEND v5 1/3] x86/asm, x86/boot: expose inline memcmp
On 2026-07-01 04:05, Peter Zijlstra wrote:
> On Tue, Jun 30, 2026 at 02:21:46PM -0300, Mauricio Faria de Oliveira wrote:
>> Move the inline memcmp function currently only available in 'boot/string.c'
>> into the shared string function header <asm/shared/string.h> to be reused.
>>
>> This is not done through <asm/string.h> to avoid pulling unnecessary code
>> in 'boot/string.c' that causes build errors in 'boot/compressed/string.c'
>> and 'purgatory/purgatory.ro'.
>>
>> Note that the inline memcmp() returns 0/1, not -1/0/1 as regular memcmp()
>> (reported by David Laight <david.laight.linux@xxxxxxxxx>).
>>
>> Signed-off-by: Mauricio Faria de Oliveira <mfo@xxxxxxxxxx>
>> ---
>> arch/x86/boot/string.c | 6 ++----
>> arch/x86/include/asm/shared/string.h | 16 ++++++++++++++++
>> arch/x86/include/asm/string.h | 1 +
>> 3 files changed, 19 insertions(+), 4 deletions(-)
>>
>> diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
>> index
>> ac0f900ebc47efa81c92e1bb2010ea41677899c4..be454a6864225f3a972c3e81826b77ed4e8a57fe
>> 100644
>> --- a/arch/x86/boot/string.c
>> +++ b/arch/x86/boot/string.c
>> @@ -15,6 +15,7 @@
>> #include <linux/errno.h>
>> #include <linux/limits.h>
>> #include <asm/asm.h>
>> +#include <asm/shared/string.h>
>> #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/shared/string.h
>> b/arch/x86/include/asm/shared/string.h
>> new file mode 100644
>> index
>> 0000000000000000000000000000000000000000..422952152f533ad75b98f3873297b39c4f5e2477
>> --- /dev/null
>> +++ b/arch/x86/include/asm/shared/string.h
>> @@ -0,0 +1,16 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +#ifndef _ASM_X86_SHARED_STRING_H
>> +#define _ASM_X86_SHARED_STRING_H
>> +
>> +/* Note: this memcmp() returns 0/1, not -1/0/1 as regular memcmp(). */
>> +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_SHARED_STRING_H */
>> diff --git a/arch/x86/include/asm/string.h b/arch/x86/include/asm/string.h
>> index
>> 9cb5aae7fba9ffcf0f5af8f939d30467750ccaa9..f0f4fd8227bf992e78c69209efb31f0a9a0cc3b1
>> 100644
>> --- a/arch/x86/include/asm/string.h
>> +++ b/arch/x86/include/asm/string.h
>> @@ -7,6 +7,7 @@
>> #else
>> # include <asm/string_64.h>
>> #endif
>> +#include <asm/shared/string.h>
>>
>> static __always_inline void *__inline_memcpy(void *to, const void *from,
>> size_t len)
>> {
>
> It seems weird to have __inline_mem{cpy,set}() in a different header than
> __inline_memcmp(). I'm assuming this is because boot cannot include the
> normal string thing?
>
> Perhaps make inline_string.h or somesuch to carry all three of them and
> include that from the relevant places?
Thanks for looking into this.
Yes, your question and suggestion above are essentially patch 1 in v4
[1].
Borislav Petkov requested a clean header in arch/x86/include/asm/shared/
for this (without other code), which is patch 1 in v5.
cheers,
[1]
https://lore.kernel.org/all/20260526-pvh-kasan-inline-v4-1-a310e6a25ecd@xxxxxxxxxx/
--
Mauricio
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |