* [PATCH v11 0/8] lib and lib/cmdline enhancements
@ 2026-05-19 17:22 Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 1/8] lib: fix _parse_integer_limit() to handle overflow Dmitry Antipov
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: Dmitry Antipov @ 2026-05-19 17:22 UTC (permalink / raw)
To: Andrew Morton
Cc: Andy Shevchenko, Charlie Jenkins, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Ard Biesheuvel, linux-riscv,
linux-efi, linux-kernel, Dmitry Antipov
This series is a merge of the recently posted [1] and [2]. The first
one is intended to adjust '_parse_integer_limit()' and 'memparse()' to
not ignore overflows, extend string to 64-bit integer conversion tests,
add KUnit-based test for 'memparse()' and fix kernel-doc glitches found
in lib/cmdline.c. The second one was originated from RISCV-specific
build fixes needed to integrate the former and now aims to provide
platform-specific double-word shifts and corresponding KUnit test.
This series was briefly tested on X86, RISCV32, ARM, and MIPS using QEMU,
and compile-tested for LoongArch32 as well.
Getting feedback from RISCV core maintainers would be very helpful.
Special thanks to Andy Shevchenko, Charlie Jenkins, and Andrew Morton.
[1] https://lore.kernel.org/linux-riscv/20260403103338.1122415-1-dmantipov@yandex.ru
[2] https://lore.kernel.org/linux-riscv/20260427090105.705529-1-dmantipov@yandex.ru
Dmitry Antipov (8):
lib: fix _parse_integer_limit() to handle overflow
lib: fix memparse() to handle overflow
lib: add more string to 64-bit integer conversion overflow tests
lib/cmdline_kunit: add test case for memparse()
lib/cmdline: adjust a few comments to fix kernel-doc -Wreturn warnings
riscv: add platform-specific double word shifts for riscv32
lib: kunit: add tests for __ashldi3(), __ashrdi3(), and __lshrdi3()
riscv: fix building compressed EFI image
arch/riscv/Kconfig | 3 -
arch/riscv/include/asm/asm-prototypes.h | 4 +
arch/riscv/kernel/image-vars.h | 9 ++
arch/riscv/lib/Makefile | 1 +
arch/riscv/lib/ashldi3.S | 36 +++++
arch/riscv/lib/ashrdi3.S | 36 +++++
arch/riscv/lib/lshrdi3.S | 36 +++++
drivers/firmware/efi/libstub/Makefile | 3 +-
lib/Kconfig.debug | 10 ++
lib/cmdline.c | 30 ++--
lib/kstrtox.c | 37 +++--
lib/test-kstrtox.c | 6 +
lib/tests/Makefile | 1 +
lib/tests/cmdline_kunit.c | 56 ++++++++
lib/tests/shdi3_kunit.c | 175 ++++++++++++++++++++++++
15 files changed, 414 insertions(+), 29 deletions(-)
create mode 100644 arch/riscv/lib/ashldi3.S
create mode 100644 arch/riscv/lib/ashrdi3.S
create mode 100644 arch/riscv/lib/lshrdi3.S
create mode 100644 lib/tests/shdi3_kunit.c
--
2.54.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v11 1/8] lib: fix _parse_integer_limit() to handle overflow
2026-05-19 17:22 [PATCH v11 0/8] lib and lib/cmdline enhancements Dmitry Antipov
@ 2026-05-19 17:22 ` Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 2/8] lib: fix memparse() " Dmitry Antipov
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Dmitry Antipov @ 2026-05-19 17:22 UTC (permalink / raw)
To: Andrew Morton
Cc: Andy Shevchenko, Charlie Jenkins, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Ard Biesheuvel, linux-riscv,
linux-efi, linux-kernel, Dmitry Antipov
In '_parse_integer_limit()', adjust native integer arithmetic
with near-to-overflow branch where 'check_mul_overflow()' and
'check_add_overflow()' are used to check whether an intermediate
result goes out of range, and denote such a case with ULLONG_MAX,
thus making the function more similar to standard C library's
'strtoull()'. Adjust comment to kernel-doc style as well.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
v9 and upwards: bump version to match the series
v8: do not use explicit temporary in check_xxx_overflow()
calls and handle overflow flag using separate variable
v7: drop redundant check against ULLONG_MAX and restore
original comment
v6: more compact for-loop and minor style adjustments again
v5: minor brace style adjustment
v4: restore plain integer arithmetic and use check_xxx_overflow()
on near-to-overflow branch only
v3: adjust commit message and comments as suggested by Andy
v2: initial version to join the series
---
lib/kstrtox.c | 37 ++++++++++++++++++++++---------------
1 file changed, 22 insertions(+), 15 deletions(-)
diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index 97be2a39f537..edc4eb7c1bca 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -39,25 +39,30 @@ const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
return s;
}
-/*
- * Convert non-negative integer string representation in explicitly given radix
- * to an integer. A maximum of max_chars characters will be converted.
+/**
+ * _parse_integer_limit - Convert integer string representation to an integer
+ * @s: Integer string representation
+ * @base: Radix
+ * @p: Where to store result
+ * @max_chars: Maximum amount of characters to convert
+ *
+ * Convert non-negative integer string representation in explicitly given
+ * radix to an integer. If overflow occurs, value at @p is set to ULLONG_MAX.
*
- * Return number of characters consumed maybe or-ed with overflow bit.
- * If overflow occurs, result integer (incorrect) is still returned.
+ * This function is the workhorse of other string conversion functions and it
+ * is discouraged to use it explicitly. Consider kstrto*() family instead.
*
- * Don't you dare use this function.
+ * Return: Number of characters consumed, maybe ORed with overflow bit
*/
noinline
unsigned int _parse_integer_limit(const char *s, unsigned int base, unsigned long long *p,
size_t max_chars)
{
+ unsigned int rv, overflow = 0;
unsigned long long res;
- unsigned int rv;
res = 0;
- rv = 0;
- while (max_chars--) {
+ for (rv = 0; rv < max_chars; rv++, s++) {
unsigned int c = *s;
unsigned int lc = _tolower(c);
unsigned int val;
@@ -76,15 +81,17 @@ unsigned int _parse_integer_limit(const char *s, unsigned int base, unsigned lon
* it in the max base we support (16)
*/
if (unlikely(res & (~0ull << 60))) {
- if (res > div_u64(ULLONG_MAX - val, base))
- rv |= KSTRTOX_OVERFLOW;
+ if (check_mul_overflow(res, base, &res) ||
+ check_add_overflow(res, val, &res)) {
+ res = ULLONG_MAX;
+ overflow = KSTRTOX_OVERFLOW;
+ }
+ } else {
+ res = res * base + val;
}
- res = res * base + val;
- rv++;
- s++;
}
*p = res;
- return rv;
+ return rv | overflow;
}
noinline
--
2.54.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v11 2/8] lib: fix memparse() to handle overflow
2026-05-19 17:22 [PATCH v11 0/8] lib and lib/cmdline enhancements Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 1/8] lib: fix _parse_integer_limit() to handle overflow Dmitry Antipov
@ 2026-05-19 17:22 ` Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 3/8] lib: add more string to 64-bit integer conversion overflow tests Dmitry Antipov
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Dmitry Antipov @ 2026-05-19 17:22 UTC (permalink / raw)
To: Andrew Morton
Cc: Andy Shevchenko, Charlie Jenkins, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Ard Biesheuvel, linux-riscv,
linux-efi, linux-kernel, Dmitry Antipov
Since '_parse_integer_limit()' (and so 'simple_strtoull()') is now
capable to handle overflow, adjust 'memparse()' to handle overflow
(denoted by ULLONG_MAX) returned from 'simple_strtoull()'. Also
use 'check_shl_overflow()' to catch an overflow possibly caused
by processing size suffix and denote it with ULLONG_MAX as well.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
v9 and upwards: bump version to match the series
v8: do not use temporary in check_shl_overflow()
v7: do not double-adjust endptr and drop
redundant check against ULLONG_MAX
v6: handle valid-suffix-only string like "k"
as unrecognized, minor style adjustments
v5: initial version to join the series
---
lib/cmdline.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/lib/cmdline.c b/lib/cmdline.c
index 90ed997d9570..f6e4b113ca9f 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -150,39 +150,46 @@ EXPORT_SYMBOL(get_options);
unsigned long long memparse(const char *ptr, char **retptr)
{
char *endptr; /* local pointer to end of parsed string */
-
unsigned long long ret = simple_strtoull(ptr, &endptr, 0);
+ unsigned int shl = 0;
+ /* Consume valid suffix even in case of overflow. */
switch (*endptr) {
case 'E':
case 'e':
- ret <<= 10;
+ shl += 10;
fallthrough;
case 'P':
case 'p':
- ret <<= 10;
+ shl += 10;
fallthrough;
case 'T':
case 't':
- ret <<= 10;
+ shl += 10;
fallthrough;
case 'G':
case 'g':
- ret <<= 10;
+ shl += 10;
fallthrough;
case 'M':
case 'm':
- ret <<= 10;
+ shl += 10;
fallthrough;
case 'K':
case 'k':
- ret <<= 10;
- endptr++;
+ shl += 10;
fallthrough;
default:
break;
}
+ if (shl && likely(ptr != endptr)) {
+ /* Have valid suffix with preceding number. */
+ if (unlikely(check_shl_overflow(ret, shl, &ret)))
+ ret = ULLONG_MAX;
+ endptr++;
+ }
+
if (retptr)
*retptr = endptr;
--
2.54.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v11 3/8] lib: add more string to 64-bit integer conversion overflow tests
2026-05-19 17:22 [PATCH v11 0/8] lib and lib/cmdline enhancements Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 1/8] lib: fix _parse_integer_limit() to handle overflow Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 2/8] lib: fix memparse() " Dmitry Antipov
@ 2026-05-19 17:22 ` Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 4/8] lib/cmdline_kunit: add test case for memparse() Dmitry Antipov
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Dmitry Antipov @ 2026-05-19 17:22 UTC (permalink / raw)
To: Andrew Morton
Cc: Andy Shevchenko, Charlie Jenkins, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Ard Biesheuvel, linux-riscv,
linux-efi, linux-kernel, Dmitry Antipov
Add a few more string to 64-bit integer conversion tests to
check whether 'kstrtoull()', 'kstrtoll()', 'kstrtou64()' and
'kstrtos64()' can handle overflows reported by
'_parse_integer_limit()'.
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
v5 and upwards: bump version to match the series
v4: initial version to join the series
---
lib/test-kstrtox.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/test-kstrtox.c b/lib/test-kstrtox.c
index ee87fef66cb5..811128d0df16 100644
--- a/lib/test-kstrtox.c
+++ b/lib/test-kstrtox.c
@@ -198,6 +198,7 @@ static void __init test_kstrtoull_fail(void)
{"10000000000000000000000000000000000000000000000000000000000000000", 2},
{"2000000000000000000000", 8},
{"18446744073709551616", 10},
+ {"569202370375329612767", 10},
{"10000000000000000", 16},
/* negative */
{"-0", 0},
@@ -275,9 +276,11 @@ static void __init test_kstrtoll_fail(void)
{"9223372036854775809", 10},
{"18446744073709551614", 10},
{"18446744073709551615", 10},
+ {"569202370375329612767", 10},
{"-9223372036854775809", 10},
{"-18446744073709551614", 10},
{"-18446744073709551615", 10},
+ {"-569202370375329612767", 10},
/* sign is first character if any */
{"-+1", 0},
{"-+1", 8},
@@ -334,6 +337,7 @@ static void __init test_kstrtou64_fail(void)
{"-1", 10},
{"18446744073709551616", 10},
{"18446744073709551617", 10},
+ {"569202370375329612767", 10},
};
TEST_FAIL(kstrtou64, u64, "%llu", test_u64_fail);
}
@@ -386,6 +390,8 @@ static void __init test_kstrtos64_fail(void)
{"18446744073709551615", 10},
{"18446744073709551616", 10},
{"18446744073709551617", 10},
+ {"569202370375329612767", 10},
+ {"-569202370375329612767", 10},
};
TEST_FAIL(kstrtos64, s64, "%lld", test_s64_fail);
}
--
2.54.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v11 4/8] lib/cmdline_kunit: add test case for memparse()
2026-05-19 17:22 [PATCH v11 0/8] lib and lib/cmdline enhancements Dmitry Antipov
` (2 preceding siblings ...)
2026-05-19 17:22 ` [PATCH v11 3/8] lib: add more string to 64-bit integer conversion overflow tests Dmitry Antipov
@ 2026-05-19 17:22 ` Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 5/8] lib/cmdline: adjust a few comments to fix kernel-doc -Wreturn warnings Dmitry Antipov
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Dmitry Antipov @ 2026-05-19 17:22 UTC (permalink / raw)
To: Andrew Morton
Cc: Andy Shevchenko, Charlie Jenkins, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Ard Biesheuvel, linux-riscv,
linux-efi, linux-kernel, Dmitry Antipov
Better late than never, now there is a long-awaited basic
test for 'memparse()' which is provided by cmdline.c.
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
v7 and upwards: bump version to match the series
v6: tests to check whether valid-suffix-only string is handled as unrecognized
v5: even more tests to trigger overflow with size suffix
v4: move actual overflow tests to test-kstrtox.c
v3: adjust style as suggested by Andy
v2: few more test cases to trigger overflows
---
lib/tests/cmdline_kunit.c | 56 +++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/lib/tests/cmdline_kunit.c b/lib/tests/cmdline_kunit.c
index c1602f797637..18b19c85baef 100644
--- a/lib/tests/cmdline_kunit.c
+++ b/lib/tests/cmdline_kunit.c
@@ -6,6 +6,7 @@
#include <kunit/test.h>
#include <linux/kernel.h>
#include <linux/random.h>
+#include <linux/sizes.h>
#include <linux/string.h>
static const char *cmdline_test_strings[] = {
@@ -139,11 +140,66 @@ static void cmdline_test_range(struct kunit *test)
} while (++i < ARRAY_SIZE(cmdline_test_range_strings));
}
+struct cmdline_test_memparse_entry {
+ const char *input;
+ const char *unrecognized;
+ unsigned long long result;
+};
+
+static const struct cmdline_test_memparse_entry testdata[] = {
+ { "0", "", 0ULL },
+ { "1", "", 1ULL },
+ { "a", "a", 0ULL },
+ { "k", "k", 0ULL },
+ { "E", "E", 0ULL },
+ { "0xb", "", 11ULL },
+ { "0xz", "x", 0ULL },
+ { "1234", "", 1234ULL },
+ { "04567", "", 2423ULL },
+ { "0x9876", "", 39030LL },
+ { "05678", "8", 375ULL },
+ { "0xabcdefz", "z", 11259375ULL },
+ { "0cdba", "c", 0ULL },
+ { "4K", "", SZ_4K },
+ { "0x10k@0xaaaabbbb", "@", SZ_16K },
+ { "32M", "", SZ_32M },
+ { "067m:foo", ":", 55 * SZ_1M },
+ { "2G;bar=baz", ";", SZ_2G },
+ { "07gz", "z", 7ULL * SZ_1G },
+ { "3T+data", "+", 3 * SZ_1T },
+ { "04t,ro", ",", SZ_4T },
+ { "012p", "", 11258999068426240ULL },
+ { "7P,sync", ",", 7881299347898368ULL },
+ { "0x2e", "", 46ULL },
+ { "2E and more", " ", 2305843009213693952ULL },
+ { "18446744073709551615", "", ULLONG_MAX },
+ { "0xffffffffffffffff0", "", ULLONG_MAX },
+ { "1111111111111111111T", "", ULLONG_MAX },
+ { "222222222222222222222G", "", ULLONG_MAX },
+ { "3333333333333333333333M", "", ULLONG_MAX },
+};
+
+static void cmdline_test_memparse(struct kunit *test)
+{
+ const struct cmdline_test_memparse_entry *e;
+ unsigned long long ret;
+ char *retptr;
+
+ for (e = testdata; e < testdata + ARRAY_SIZE(testdata); e++) {
+ ret = memparse(e->input, &retptr);
+ KUNIT_EXPECT_EQ_MSG(test, ret, e->result,
+ " when parsing '%s'", e->input);
+ KUNIT_EXPECT_EQ_MSG(test, *retptr, *e->unrecognized,
+ " when parsing '%s'", e->input);
+ }
+}
+
static struct kunit_case cmdline_test_cases[] = {
KUNIT_CASE(cmdline_test_noint),
KUNIT_CASE(cmdline_test_lead_int),
KUNIT_CASE(cmdline_test_tail_int),
KUNIT_CASE(cmdline_test_range),
+ KUNIT_CASE(cmdline_test_memparse),
{}
};
--
2.54.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v11 5/8] lib/cmdline: adjust a few comments to fix kernel-doc -Wreturn warnings
2026-05-19 17:22 [PATCH v11 0/8] lib and lib/cmdline enhancements Dmitry Antipov
` (3 preceding siblings ...)
2026-05-19 17:22 ` [PATCH v11 4/8] lib/cmdline_kunit: add test case for memparse() Dmitry Antipov
@ 2026-05-19 17:22 ` Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 6/8] riscv: add platform-specific double word shifts for riscv32 Dmitry Antipov
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Dmitry Antipov @ 2026-05-19 17:22 UTC (permalink / raw)
To: Andrew Morton
Cc: Andy Shevchenko, Charlie Jenkins, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Ard Biesheuvel, linux-riscv,
linux-efi, linux-kernel, Dmitry Antipov
Fix 'get_option()', 'memparse()' and 'parse_option_str()' comments
to match the commonly used style as suggested by kernel-doc -Wreturn.
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
v2 and upwards: bump version to match the series
---
lib/cmdline.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/lib/cmdline.c b/lib/cmdline.c
index f6e4b113ca9f..16cce6621cec 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -43,7 +43,7 @@ static int get_range(char **str, int *pint, int n)
* When @pint is NULL the function can be used as a validator of
* the current option in the string.
*
- * Return values:
+ * Return:
* 0 - no int in string
* 1 - int found, no subsequent comma
* 2 - int found including a subsequent comma
@@ -145,6 +145,9 @@ EXPORT_SYMBOL(get_options);
*
* Parses a string into a number. The number stored at @ptr is
* potentially suffixed with K, M, G, T, P, E.
+ *
+ * Return: The value as recognized by simple_strtoull() multiplied
+ * by the value as specified by suffix, if any.
*/
unsigned long long memparse(const char *ptr, char **retptr)
@@ -205,7 +208,7 @@ EXPORT_SYMBOL(memparse);
* This function parses a string containing a comma-separated list of
* strings like a=b,c.
*
- * Return true if there's such option in the string, or return false.
+ * Return: True if there's such option in the string or false otherwise.
*/
bool parse_option_str(const char *str, const char *option)
{
--
2.54.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v11 6/8] riscv: add platform-specific double word shifts for riscv32
2026-05-19 17:22 [PATCH v11 0/8] lib and lib/cmdline enhancements Dmitry Antipov
` (4 preceding siblings ...)
2026-05-19 17:22 ` [PATCH v11 5/8] lib/cmdline: adjust a few comments to fix kernel-doc -Wreturn warnings Dmitry Antipov
@ 2026-05-19 17:22 ` Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 7/8] lib: kunit: add tests for __ashldi3(), __ashrdi3(), and __lshrdi3() Dmitry Antipov
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Dmitry Antipov @ 2026-05-19 17:22 UTC (permalink / raw)
To: Andrew Morton
Cc: Andy Shevchenko, Charlie Jenkins, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Ard Biesheuvel, linux-riscv,
linux-efi, linux-kernel, Dmitry Antipov, kernel test robot
Add riscv32-specific '__ashldi3()', '__ashrdi3()', and '__lshrdi3()'.
Initially it was intended to fix the following link error observed
when building EFI-enabled kernel with CONFIG_EFI_STUB=y and
CONFIG_EFI_GENERIC_STUB=y:
riscv32-linux-gnu-ld: ./drivers/firmware/efi/libstub/lib-cmdline.stub.o: in function `__efistub_.L49':
__efistub_cmdline.c:(.init.text+0x1f2): undefined reference to `__efistub___ashldi3'
riscv32-linux-gnu-ld: __efistub_cmdline.c:(.init.text+0x202): undefined reference to `__efistub___lshrdi3'
Reported at [1] trying to build https://patchew.org/linux/20260212164413.889625-1-dmantipov@yandex.ru,
tested with 'qemu-system-riscv32 -M virt' only.
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202603041925.KLKqpK6N-lkp@intel.com [1]
Suggested-by: Ard Biesheuvel <ardb@kernel.org>
Tested-by: Charlie Jenkins <thecharlesjenkins@gmail.com>
Assisted-by: Gemini:gemini-3.1-pro-preview sashiko
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
v11: add prototypes to arch/riscv/include/asm/asm-prototypes.h (Sashiko)
v10: bump version to match merged series
v7: export for stub and optimize '__ashrdi3()' (Sashiko)
v4, v5, v6: and upwards: bump version to match the series
v3: more tests by Charlie Jenkins
v2: adjust commit message
---
arch/riscv/Kconfig | 3 ---
arch/riscv/include/asm/asm-prototypes.h | 4 +++
arch/riscv/kernel/image-vars.h | 9 +++++++
arch/riscv/lib/Makefile | 1 +
arch/riscv/lib/ashldi3.S | 36 +++++++++++++++++++++++++
arch/riscv/lib/ashrdi3.S | 36 +++++++++++++++++++++++++
arch/riscv/lib/lshrdi3.S | 36 +++++++++++++++++++++++++
7 files changed, 122 insertions(+), 3 deletions(-)
create mode 100644 arch/riscv/lib/ashldi3.S
create mode 100644 arch/riscv/lib/ashrdi3.S
create mode 100644 arch/riscv/lib/lshrdi3.S
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index c5754942cf85..0d10b299bad8 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -404,9 +404,6 @@ config ARCH_RV32I
bool "RV32I"
depends on NONPORTABLE
select 32BIT
- select GENERIC_LIB_ASHLDI3
- select GENERIC_LIB_ASHRDI3
- select GENERIC_LIB_LSHRDI3
select GENERIC_LIB_UCMPDI2
config ARCH_RV64I
diff --git a/arch/riscv/include/asm/asm-prototypes.h b/arch/riscv/include/asm/asm-prototypes.h
index 5b90ba5314ee..a0ca9efff267 100644
--- a/arch/riscv/include/asm/asm-prototypes.h
+++ b/arch/riscv/include/asm/asm-prototypes.h
@@ -5,6 +5,10 @@
#include <linux/ftrace.h>
#include <asm-generic/asm-prototypes.h>
+long long __lshrdi3(long long a, int b);
+long long __ashrdi3(long long a, int b);
+long long __ashldi3(long long a, int b);
+
long long __lshrti3(long long a, int b);
long long __ashrti3(long long a, int b);
long long __ashlti3(long long a, int b);
diff --git a/arch/riscv/kernel/image-vars.h b/arch/riscv/kernel/image-vars.h
index 3bd9d06a8b8f..7b44b94f1283 100644
--- a/arch/riscv/kernel/image-vars.h
+++ b/arch/riscv/kernel/image-vars.h
@@ -32,6 +32,15 @@ __efistub___init_text_end = __init_text_end;
__efistub_sysfb_primary_display = sysfb_primary_display;
#endif
+/*
+ * These double-word integer shifts are used by the library code, and
+ * the first two of them are required to link EFI stub. Note __ashrdi3()
+ * is not actually used by the stub but this may change in the future.
+ */
+PROVIDE(__efistub___lshrdi3 = __lshrdi3);
+PROVIDE(__efistub___ashldi3 = __ashldi3);
+PROVIDE(__efistub___ashrdi3 = __ashrdi3);
+
#endif
#endif /* __RISCV_KERNEL_IMAGE_VARS_H */
diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile
index 6f767b2a349d..f668b98970bd 100644
--- a/arch/riscv/lib/Makefile
+++ b/arch/riscv/lib/Makefile
@@ -16,6 +16,7 @@ ifeq ($(CONFIG_MMU), y)
lib-$(CONFIG_RISCV_ISA_V) += uaccess_vector.o
endif
lib-$(CONFIG_MMU) += uaccess.o
+lib-$(CONFIG_32BIT) += ashldi3.o ashrdi3.o lshrdi3.o
lib-$(CONFIG_64BIT) += tishift.o
lib-$(CONFIG_RISCV_ISA_ZICBOZ) += clear_page.o
obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
diff --git a/arch/riscv/lib/ashldi3.S b/arch/riscv/lib/ashldi3.S
new file mode 100644
index 000000000000..c3408862e2f6
--- /dev/null
+++ b/arch/riscv/lib/ashldi3.S
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/**
+ * Adopted for the Linux kernel from IPXE project, see
+ * https://github.com/ipxe/ipxe/blob/master/src/arch/riscv32/libgcc/llshift.S
+ */
+
+#include <linux/linkage.h>
+#include <asm/asm.h>
+
+/**
+ * Shift left
+ *
+ * @v a1:a0 Value to shift
+ * @v a2 Shift amount
+ * @ret a1:a0 Shifted value
+ */
+
+SYM_FUNC_START(__ashldi3)
+
+ /* Perform shift by 32 bits, if applicable */
+ li t0, 32
+ sub t1, t0, a2
+ bgtz t1, 1f
+ mv a1, a0
+ mv a0, zero
+1: /* Perform shift by modulo-32 bits, if applicable */
+ andi a2, a2, 0x1f
+ beqz a2, 2f
+ srl t2, a0, t1
+ sll a0, a0, a2
+ sll a1, a1, a2
+ or a1, a1, t2
+2: ret
+
+SYM_FUNC_END(__ashldi3)
+EXPORT_SYMBOL(__ashldi3)
diff --git a/arch/riscv/lib/ashrdi3.S b/arch/riscv/lib/ashrdi3.S
new file mode 100644
index 000000000000..426de0946606
--- /dev/null
+++ b/arch/riscv/lib/ashrdi3.S
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/**
+ * Adopted for the Linux kernel from IPXE project, see
+ * https://github.com/ipxe/ipxe/blob/master/src/arch/riscv32/libgcc/llshift.S
+ */
+
+#include <linux/linkage.h>
+#include <asm/asm.h>
+
+/**
+ * Arithmetic shift right
+ *
+ * @v a1:a0 Value to shift
+ * @v a2 Shift amount
+ * @ret a1:a0 Shifted value
+ */
+
+SYM_FUNC_START(__ashrdi3)
+
+ /* Perform shift by 32 bits, if applicable */
+ li t0, 32
+ sub t1, t0, a2
+ bgtz t1, 1f
+ mv a0, a1
+ srai a1, a1, 31
+1: /* Perform shift by modulo-32 bits, if applicable */
+ andi a2, a2, 0x1f
+ beqz a2, 2f
+ sll t2, a1, t1
+ sra a1, a1, a2
+ srl a0, a0, a2
+ or a0, a0, t2
+2: ret
+
+SYM_FUNC_END(__ashrdi3)
+EXPORT_SYMBOL(__ashrdi3)
diff --git a/arch/riscv/lib/lshrdi3.S b/arch/riscv/lib/lshrdi3.S
new file mode 100644
index 000000000000..1af03985ccb7
--- /dev/null
+++ b/arch/riscv/lib/lshrdi3.S
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/**
+ * Adopted for the Linux kernel from IPXE project, see
+ * https://github.com/ipxe/ipxe/blob/master/src/arch/riscv32/libgcc/llshift.S
+ */
+
+#include <linux/linkage.h>
+#include <asm/asm.h>
+
+/**
+ * Logical shift right
+ *
+ * @v a1:a0 Value to shift
+ * @v a2 Shift amount
+ * @ret a1:a0 Shifted value
+ */
+
+SYM_FUNC_START(__lshrdi3)
+
+ /* Perform shift by 32 bits, if applicable */
+ li t0, 32
+ sub t1, t0, a2
+ bgtz t1, 1f
+ mv a0, a1
+ mv a1, zero
+1: /* Perform shift by modulo-32 bits, if applicable */
+ andi a2, a2, 0x1f
+ beqz a2, 2f
+ sll t2, a1, t1
+ srl a1, a1, a2
+ srl a0, a0, a2
+ or a0, a0, t2
+2: ret
+
+SYM_FUNC_END(__lshrdi3)
+EXPORT_SYMBOL(__lshrdi3)
--
2.54.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v11 7/8] lib: kunit: add tests for __ashldi3(), __ashrdi3(), and __lshrdi3()
2026-05-19 17:22 [PATCH v11 0/8] lib and lib/cmdline enhancements Dmitry Antipov
` (5 preceding siblings ...)
2026-05-19 17:22 ` [PATCH v11 6/8] riscv: add platform-specific double word shifts for riscv32 Dmitry Antipov
@ 2026-05-19 17:22 ` Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 8/8] riscv: fix building compressed EFI image Dmitry Antipov
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Dmitry Antipov @ 2026-05-19 17:22 UTC (permalink / raw)
To: Andrew Morton
Cc: Andy Shevchenko, Charlie Jenkins, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Ard Biesheuvel, linux-riscv,
linux-efi, linux-kernel, Dmitry Antipov
Add KUnit tests for '__ashldi3()', '__ashrdi3()', and '__lshrdi3()'
helper functions used to implement 64-bit arithmetic shift left,
arithmetic shift right and logical shift right, respectively,
on a 32-bit CPUs.
Tested with 'qemu-system-riscv32 -M virt' and 'qemu-system-arm -M virt'.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Tested-by: Charlie Jenkins <thecharlesjenkins@gmail.com>
Assisted-by: Gemini:gemini-3.1-pro-preview sashiko
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
v11: explicitly depends on arm/xtensa/microblaze or 32-bit riscv/sparc (Sashiko)
v4-v10: bump version to match the series
v3: more tests by Charlie Jenkins
v2: include test-specific headers rather than generic linux/kernel.h
---
lib/Kconfig.debug | 10 +++
lib/tests/Makefile | 1 +
lib/tests/shdi3_kunit.c | 175 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 186 insertions(+)
create mode 100644 lib/tests/shdi3_kunit.c
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 8ff5adcfe1e0..7ca468c7d81d 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2971,6 +2971,16 @@ config BITS_TEST
If unsure, say N.
+config SHDI3_KUNIT_TEST
+ tristate "KUnit test for __ashldi3(), __ashrdi3(), and __lshrdi3()"
+ depends on KUNIT
+ depends on ARM || XTENSA || MICROBLAZE || ((RISCV || SPARC) && !64BIT)
+ help
+ This builds the unit test for __ashldi3(), __ashrdi3(), and
+ __lshrdi3() helper functions used to implement 64-bit arithmetic
+ shift left, arithmetic shift right and logical shift right,
+ respectively, on a 32-bit CPUs.
+
config SLUB_KUNIT_TEST
tristate "KUnit test for SLUB cache error detection" if !KUNIT_ALL_TESTS
depends on SLUB_DEBUG && KUNIT
diff --git a/lib/tests/Makefile b/lib/tests/Makefile
index 7e9c2fa52e35..4ead57602eac 100644
--- a/lib/tests/Makefile
+++ b/lib/tests/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_BASE64_KUNIT) += base64_kunit.o
obj-$(CONFIG_BITOPS_KUNIT) += bitops_kunit.o
obj-$(CONFIG_BITFIELD_KUNIT) += bitfield_kunit.o
obj-$(CONFIG_BITS_TEST) += test_bits.o
+obj-$(CONFIG_SHDI3_KUNIT_TEST) += shdi3_kunit.o
obj-$(CONFIG_BLACKHOLE_DEV_KUNIT_TEST) += blackhole_dev_kunit.o
obj-$(CONFIG_CHECKSUM_KUNIT) += checksum_kunit.o
obj-$(CONFIG_CMDLINE_KUNIT_TEST) += cmdline_kunit.o
diff --git a/lib/tests/shdi3_kunit.c b/lib/tests/shdi3_kunit.c
new file mode 100644
index 000000000000..44f65e66512b
--- /dev/null
+++ b/lib/tests/shdi3_kunit.c
@@ -0,0 +1,175 @@
+// SPDX-License-Identifier: GPL-2.0-or-later OR Apache-2.0
+/*
+ * Test cases for __ashldi3(), __ashrdi3(), and __lshrdi3().
+ */
+
+#include <linux/array_size.h>
+#include <linux/module.h>
+#include <linux/libgcc.h>
+#include <kunit/test.h>
+
+struct shdi3_test_entry {
+ long long input;
+ int shift;
+ long long result;
+};
+
+static const struct shdi3_test_entry ashldi3_testdata[] = {
+ /* https://github.com/llvm/llvm-project/compiler-rt/test/builtins/Unit/ashldi3_test.c */
+ { 0x0123456789ABCDEFLL, 0, 0x123456789ABCDEFLL },
+ { 0x0123456789ABCDEFLL, 1, 0x2468ACF13579BDELL },
+ { 0x0123456789ABCDEFLL, 2, 0x48D159E26AF37BCLL },
+ { 0x0123456789ABCDEFLL, 3, 0x91A2B3C4D5E6F78LL },
+ { 0x0123456789ABCDEFLL, 4, 0x123456789ABCDEF0LL },
+ { 0x0123456789ABCDEFLL, 28, 0x789ABCDEF0000000LL },
+ { 0x0123456789ABCDEFLL, 29, 0xF13579BDE0000000LL },
+ { 0x0123456789ABCDEFLL, 30, 0xE26AF37BC0000000LL },
+ { 0x0123456789ABCDEFLL, 31, 0xC4D5E6F780000000LL },
+ { 0x0123456789ABCDEFLL, 32, 0x89ABCDEF00000000LL },
+ { 0x0123456789ABCDEFLL, 33, 0x13579BDE00000000LL },
+ { 0x0123456789ABCDEFLL, 34, 0x26AF37BC00000000LL },
+ { 0x0123456789ABCDEFLL, 35, 0x4D5E6F7800000000LL },
+ { 0x0123456789ABCDEFLL, 36, 0x9ABCDEF000000000LL },
+ { 0x0123456789ABCDEFLL, 60, 0xF000000000000000LL },
+ { 0x0123456789ABCDEFLL, 61, 0xE000000000000000LL },
+ { 0x0123456789ABCDEFLL, 62, 0xC000000000000000LL },
+ { 0x0123456789ABCDEFLL, 63, 0x8000000000000000LL },
+};
+
+static void shdi3_test_ashldi3(struct kunit *test)
+{
+ const struct shdi3_test_entry *e;
+ long long ret;
+
+ for (e = ashldi3_testdata;
+ e < ashldi3_testdata + ARRAY_SIZE(ashldi3_testdata); e++) {
+ ret = __ashldi3(e->input, e->shift);
+ KUNIT_EXPECT_EQ_MSG(test, ret, e->result,
+ " when evaluating __ashldi3(%lld, %d)",
+ e->input, e->shift);
+ }
+}
+
+static const struct shdi3_test_entry ashrdi3_testdata[] = {
+ /* https://github.com/llvm/llvm-project/compiler-rt/test/builtins/Unit/ashrdi3_test.c */
+ { 0x0123456789ABCDEFLL, 0, 0x123456789ABCDEFLL },
+ { 0x0123456789ABCDEFLL, 1, 0x91A2B3C4D5E6F7LL },
+ { 0x0123456789ABCDEFLL, 2, 0x48D159E26AF37BLL },
+ { 0x0123456789ABCDEFLL, 3, 0x2468ACF13579BDLL },
+ { 0x0123456789ABCDEFLL, 4, 0x123456789ABCDELL },
+ { 0x0123456789ABCDEFLL, 28, 0x12345678LL },
+ { 0x0123456789ABCDEFLL, 29, 0x91A2B3CLL },
+ { 0x0123456789ABCDEFLL, 30, 0x48D159ELL },
+ { 0x0123456789ABCDEFLL, 31, 0x2468ACFLL },
+ { 0x0123456789ABCDEFLL, 32, 0x1234567LL },
+ { 0x0123456789ABCDEFLL, 33, 0x91A2B3LL },
+ { 0x0123456789ABCDEFLL, 34, 0x48D159LL },
+ { 0x0123456789ABCDEFLL, 35, 0x2468ACLL },
+ { 0x0123456789ABCDEFLL, 36, 0x123456LL },
+ { 0x0123456789ABCDEFLL, 60, 0 },
+ { 0x0123456789ABCDEFLL, 61, 0 },
+ { 0x0123456789ABCDEFLL, 62, 0 },
+ { 0x0123456789ABCDEFLL, 63, 0 },
+ { 0xFEDCBA9876543210LL, 0, 0xFEDCBA9876543210LL },
+ { 0xFEDCBA9876543210LL, 1, 0xFF6E5D4C3B2A1908LL },
+ { 0xFEDCBA9876543210LL, 2, 0xFFB72EA61D950C84LL },
+ { 0xFEDCBA9876543210LL, 3, 0xFFDB97530ECA8642LL },
+ { 0xFEDCBA9876543210LL, 4, 0xFFEDCBA987654321LL },
+ { 0xFEDCBA9876543210LL, 28, 0xFFFFFFFFEDCBA987LL },
+ { 0xFEDCBA9876543210LL, 29, 0xFFFFFFFFF6E5D4C3LL },
+ { 0xFEDCBA9876543210LL, 30, 0xFFFFFFFFFB72EA61LL },
+ { 0xFEDCBA9876543210LL, 31, 0xFFFFFFFFFDB97530LL },
+ { 0xFEDCBA9876543210LL, 32, 0xFFFFFFFFFEDCBA98LL },
+ { 0xFEDCBA9876543210LL, 33, 0xFFFFFFFFFF6E5D4CLL },
+ { 0xFEDCBA9876543210LL, 34, 0xFFFFFFFFFFB72EA6LL },
+ { 0xFEDCBA9876543210LL, 35, 0xFFFFFFFFFFDB9753LL },
+ { 0xFEDCBA9876543210LL, 36, 0xFFFFFFFFFFEDCBA9LL },
+ { 0xAEDCBA9876543210LL, 60, 0xFFFFFFFFFFFFFFFALL },
+ { 0xAEDCBA9876543210LL, 61, 0xFFFFFFFFFFFFFFFDLL },
+ { 0xAEDCBA9876543210LL, 62, 0xFFFFFFFFFFFFFFFELL },
+ { 0xAEDCBA9876543210LL, 63, 0xFFFFFFFFFFFFFFFFLL },
+};
+
+static void shdi3_test_ashrdi3(struct kunit *test)
+{
+ const struct shdi3_test_entry *e;
+ long long ret;
+
+ for (e = ashrdi3_testdata;
+ e < ashrdi3_testdata + ARRAY_SIZE(ashrdi3_testdata); e++) {
+ ret = __ashrdi3(e->input, e->shift);
+ KUNIT_EXPECT_EQ_MSG(test, ret, e->result,
+ " when evaluating __ashrdi3(%lld, %d)",
+ e->input, e->shift);
+ }
+}
+
+static const struct shdi3_test_entry lshrdi3_testdata[] = {
+ /* https://github.com/llvm/llvm-project/compiler-rt/test/builtins/Unit/lshrdi3_test.c */
+ { 0x0123456789ABCDEFLL, 0, 0x123456789ABCDEFLL },
+ { 0x0123456789ABCDEFLL, 1, 0x91A2B3C4D5E6F7LL },
+ { 0x0123456789ABCDEFLL, 2, 0x48D159E26AF37BLL },
+ { 0x0123456789ABCDEFLL, 3, 0x2468ACF13579BDLL },
+ { 0x0123456789ABCDEFLL, 4, 0x123456789ABCDELL },
+ { 0x0123456789ABCDEFLL, 28, 0x12345678LL },
+ { 0x0123456789ABCDEFLL, 29, 0x91A2B3CLL },
+ { 0x0123456789ABCDEFLL, 30, 0x48D159ELL },
+ { 0x0123456789ABCDEFLL, 31, 0x2468ACFLL },
+ { 0x0123456789ABCDEFLL, 32, 0x1234567LL },
+ { 0x0123456789ABCDEFLL, 33, 0x91A2B3LL },
+ { 0x0123456789ABCDEFLL, 34, 0x48D159LL },
+ { 0x0123456789ABCDEFLL, 35, 0x2468ACLL },
+ { 0x0123456789ABCDEFLL, 36, 0x123456LL },
+ { 0x0123456789ABCDEFLL, 60, 0 },
+ { 0x0123456789ABCDEFLL, 61, 0 },
+ { 0x0123456789ABCDEFLL, 62, 0 },
+ { 0x0123456789ABCDEFLL, 63, 0 },
+ { 0xFEDCBA9876543210LL, 0, 0xFEDCBA9876543210LL },
+ { 0xFEDCBA9876543210LL, 1, 0x7F6E5D4C3B2A1908LL },
+ { 0xFEDCBA9876543210LL, 2, 0x3FB72EA61D950C84LL },
+ { 0xFEDCBA9876543210LL, 3, 0x1FDB97530ECA8642LL },
+ { 0xFEDCBA9876543210LL, 4, 0xFEDCBA987654321LL },
+ { 0xFEDCBA9876543210LL, 28, 0xFEDCBA987LL },
+ { 0xFEDCBA9876543210LL, 29, 0x7F6E5D4C3LL },
+ { 0xFEDCBA9876543210LL, 30, 0x3FB72EA61LL },
+ { 0xFEDCBA9876543210LL, 31, 0x1FDB97530LL },
+ { 0xFEDCBA9876543210LL, 32, 0xFEDCBA98LL },
+ { 0xFEDCBA9876543210LL, 33, 0x7F6E5D4CLL },
+ { 0xFEDCBA9876543210LL, 34, 0x3FB72EA6LL },
+ { 0xFEDCBA9876543210LL, 35, 0x1FDB9753LL },
+ { 0xFEDCBA9876543210LL, 36, 0xFEDCBA9LL },
+ { 0xAEDCBA9876543210LL, 60, 0xALL },
+ { 0xAEDCBA9876543210LL, 61, 0x5LL },
+ { 0xAEDCBA9876543210LL, 62, 0x2LL },
+ { 0xAEDCBA9876543210LL, 63, 0x1LL },
+};
+
+static void shdi3_test_lshrdi3(struct kunit *test)
+{
+ const struct shdi3_test_entry *e;
+ long long ret;
+
+ for (e = lshrdi3_testdata;
+ e < lshrdi3_testdata + ARRAY_SIZE(lshrdi3_testdata); e++) {
+ ret = __lshrdi3(e->input, e->shift);
+ KUNIT_EXPECT_EQ_MSG(test, ret, e->result,
+ " when evaluating __lshrdi3(%lld, %d)",
+ e->input, e->shift);
+ }
+}
+
+static struct kunit_case shdi3_test_cases[] = {
+ KUNIT_CASE(shdi3_test_ashldi3),
+ KUNIT_CASE(shdi3_test_ashrdi3),
+ KUNIT_CASE(shdi3_test_lshrdi3),
+ {}
+};
+
+static struct kunit_suite shdi3_test_suite = {
+ .name = "shdi3",
+ .test_cases = shdi3_test_cases,
+};
+kunit_test_suite(shdi3_test_suite);
+
+MODULE_DESCRIPTION("Test cases for __ashldi3(), __ashrdi3(), and __lshrdi3()");
+MODULE_LICENSE("GPL");
--
2.54.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v11 8/8] riscv: fix building compressed EFI image
2026-05-19 17:22 [PATCH v11 0/8] lib and lib/cmdline enhancements Dmitry Antipov
` (6 preceding siblings ...)
2026-05-19 17:22 ` [PATCH v11 7/8] lib: kunit: add tests for __ashldi3(), __ashrdi3(), and __lshrdi3() Dmitry Antipov
@ 2026-05-19 17:22 ` Dmitry Antipov
2026-05-19 19:10 ` [PATCH v11 0/8] lib and lib/cmdline enhancements Andrew Morton
2026-06-26 8:21 ` patchwork-bot+linux-riscv
9 siblings, 0 replies; 11+ messages in thread
From: Dmitry Antipov @ 2026-05-19 17:22 UTC (permalink / raw)
To: Andrew Morton
Cc: Andy Shevchenko, Charlie Jenkins, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Ard Biesheuvel, linux-riscv,
linux-efi, linux-kernel, Dmitry Antipov
When building vmlinuz.efi with CONFIG_EFI_ZBOOT enabled,
'__lshrdi3()' is also needed to fix yet another link error:
riscv32-linux-gnu-ld: drivers/firmware/efi/libstub/lib-cmdline.stub.o: in function `__efistub_.L49':
__efistub_cmdline.c:(.init.text+0x202): undefined reference to `__efistub___lshrdi3'
And since riscv64 can have CONFIG_EFI_ZBOOT but doesn't need
these library routines, rely on CONFIG_32BIT to manage linking
of lib-ashldi3.o and lib-lshrdi3.o on riscv32 only.
Reported-by: Charlie Jenkins <thecharlesjenkins@gmail.com>
Closes: https://lore.kernel.org/linux-riscv/20260409050018.GA371560@inky.localdomain
Tested-by: Charlie Jenkins <thecharlesjenkins@gmail.com>
Suggested-by: Ard Biesheuvel <ardb@kernel.org>
Assisted-by: Gemini:gemini-3.1-pro-preview sashiko
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
v10 and upwards: bump version to match merged series
v7: use lib-clz_ctz.o exactly once (Sashiko)
v6: adjust to match recent upstream changes
v5: rely on CONFIG_32BIT rather than dedicated Kconfig symbol (Ard)
v4: use more meaningful CONFIG_EFI_ZBOOT_USE_LIBGCC and adjust tags (Andy)
v3: initial version to join the series
---
drivers/firmware/efi/libstub/Makefile | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
index cfedb3025c26..251571d293c3 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -95,7 +95,8 @@ CFLAGS_zboot-decompress-gzip.o += -I$(srctree)/lib/zlib_inflate
zboot-obj-$(CONFIG_KERNEL_ZSTD) := zboot-decompress-zstd.o lib-xxhash.o
CFLAGS_zboot-decompress-zstd.o += -I$(srctree)/lib/zstd
-zboot-obj-$(CONFIG_RISCV) += lib-clz_ctz.o lib-ashldi3.o
+zboot-riscv-obj-$(CONFIG_32BIT) += lib-ashldi3.o lib-lshrdi3.o
+zboot-obj-$(CONFIG_RISCV) += lib-clz_ctz.o $(zboot-riscv-obj-y)
zboot-obj-$(CONFIG_LOONGARCH) += lib-clz_ctz.o lib-ashldi3.o
lib-$(CONFIG_EFI_ZBOOT) += zboot.o $(zboot-obj-y)
--
2.54.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v11 0/8] lib and lib/cmdline enhancements
2026-05-19 17:22 [PATCH v11 0/8] lib and lib/cmdline enhancements Dmitry Antipov
` (7 preceding siblings ...)
2026-05-19 17:22 ` [PATCH v11 8/8] riscv: fix building compressed EFI image Dmitry Antipov
@ 2026-05-19 19:10 ` Andrew Morton
2026-06-26 8:21 ` patchwork-bot+linux-riscv
9 siblings, 0 replies; 11+ messages in thread
From: Andrew Morton @ 2026-05-19 19:10 UTC (permalink / raw)
To: Dmitry Antipov
Cc: Andy Shevchenko, Charlie Jenkins, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Ard Biesheuvel, linux-riscv,
linux-efi, linux-kernel
On Tue, 19 May 2026 20:22:51 +0300 Dmitry Antipov <dmantipov@yandex.ru> wrote:
> This series is a merge of the recently posted [1] and [2]. The first
> one is intended to adjust '_parse_integer_limit()' and 'memparse()' to
> not ignore overflows, extend string to 64-bit integer conversion tests,
> add KUnit-based test for 'memparse()' and fix kernel-doc glitches found
> in lib/cmdline.c. The second one was originated from RISCV-specific
> build fixes needed to integrate the former and now aims to provide
> platform-specific double-word shifts and corresponding KUnit test.
>
> This series was briefly tested on X86, RISCV32, ARM, and MIPS using QEMU,
> and compile-tested for LoongArch32 as well.
>
> Getting feedback from RISCV core maintainers would be very helpful.
>
> Special thanks to Andy Shevchenko, Charlie Jenkins, and Andrew Morton.
>
> [1] https://lore.kernel.org/linux-riscv/20260403103338.1122415-1-dmantipov@yandex.ru
> [2] https://lore.kernel.org/linux-riscv/20260427090105.705529-1-dmantipov@yandex.ru
Thanks. I updated mm.git's mm-nonmm-unstable branch to this version.
Below is how v11 altered mm.git. Please note that it's conventional to
changelog the updates in the [0/N]. I see it there in the [6/8] and
[7/8] changelogs:
v11: add prototypes to arch/riscv/include/asm/asm-prototypes.h (Sashiko)
v11: explicitly depends on arm/xtensa/microblaze or 32-bit riscv/sparc (Sashiko)
arch/riscv/include/asm/asm-prototypes.h | 4 ++++
lib/Kconfig.debug | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
--- a/arch/riscv/include/asm/asm-prototypes.h~b
+++ a/arch/riscv/include/asm/asm-prototypes.h
@@ -5,6 +5,10 @@
#include <linux/ftrace.h>
#include <asm-generic/asm-prototypes.h>
+long long __lshrdi3(long long a, int b);
+long long __ashrdi3(long long a, int b);
+long long __ashldi3(long long a, int b);
+
long long __lshrti3(long long a, int b);
long long __ashrti3(long long a, int b);
long long __ashlti3(long long a, int b);
--- a/lib/Kconfig.debug~b
+++ a/lib/Kconfig.debug
@@ -2974,7 +2974,7 @@ config BITS_TEST
config SHDI3_KUNIT_TEST
tristate "KUnit test for __ashldi3(), __ashrdi3(), and __lshrdi3()"
depends on KUNIT
- depends on (32BIT || ARM)
+ depends on ARM || XTENSA || MICROBLAZE || ((RISCV || SPARC) && !64BIT)
help
This builds the unit test for __ashldi3(), __ashrdi3(), and
__lshrdi3() helper functions used to implement 64-bit arithmetic
_
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v11 0/8] lib and lib/cmdline enhancements
2026-05-19 17:22 [PATCH v11 0/8] lib and lib/cmdline enhancements Dmitry Antipov
` (8 preceding siblings ...)
2026-05-19 19:10 ` [PATCH v11 0/8] lib and lib/cmdline enhancements Andrew Morton
@ 2026-06-26 8:21 ` patchwork-bot+linux-riscv
9 siblings, 0 replies; 11+ messages in thread
From: patchwork-bot+linux-riscv @ 2026-06-26 8:21 UTC (permalink / raw)
To: Dmitry Antipov
Cc: linux-riscv, akpm, andriy.shevchenko, thecharlesjenkins, pjw,
palmer, aou, alex, ardb, linux-efi, linux-kernel
Hello:
This series was applied to riscv/linux.git (fixes)
by Andrew Morton <akpm@linux-foundation.org>:
On Tue, 19 May 2026 20:22:51 +0300 you wrote:
> This series is a merge of the recently posted [1] and [2]. The first
> one is intended to adjust '_parse_integer_limit()' and 'memparse()' to
> not ignore overflows, extend string to 64-bit integer conversion tests,
> add KUnit-based test for 'memparse()' and fix kernel-doc glitches found
> in lib/cmdline.c. The second one was originated from RISCV-specific
> build fixes needed to integrate the former and now aims to provide
> platform-specific double-word shifts and corresponding KUnit test.
>
> [...]
Here is the summary with links:
- [v11,1/8] lib: fix _parse_integer_limit() to handle overflow
https://git.kernel.org/riscv/c/6e30111dbb40
- [v11,2/8] lib: fix memparse() to handle overflow
https://git.kernel.org/riscv/c/9a4580db6e9f
- [v11,3/8] lib: add more string to 64-bit integer conversion overflow tests
https://git.kernel.org/riscv/c/ab90fc100724
- [v11,4/8] lib/cmdline_kunit: add test case for memparse()
(no matching commit)
- [v11,5/8] lib/cmdline: adjust a few comments to fix kernel-doc -Wreturn warnings
https://git.kernel.org/riscv/c/117d2bfa0ab1
- [v11,6/8] riscv: add platform-specific double word shifts for riscv32
https://git.kernel.org/riscv/c/a354b8de9ad6
- [v11,7/8] lib: kunit: add tests for __ashldi3(), __ashrdi3(), and __lshrdi3()
https://git.kernel.org/riscv/c/6bba2ae43e8f
- [v11,8/8] riscv: fix building compressed EFI image
(no matching commit)
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-06-26 8:21 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-19 17:22 [PATCH v11 0/8] lib and lib/cmdline enhancements Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 1/8] lib: fix _parse_integer_limit() to handle overflow Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 2/8] lib: fix memparse() " Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 3/8] lib: add more string to 64-bit integer conversion overflow tests Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 4/8] lib/cmdline_kunit: add test case for memparse() Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 5/8] lib/cmdline: adjust a few comments to fix kernel-doc -Wreturn warnings Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 6/8] riscv: add platform-specific double word shifts for riscv32 Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 7/8] lib: kunit: add tests for __ashldi3(), __ashrdi3(), and __lshrdi3() Dmitry Antipov
2026-05-19 17:22 ` [PATCH v11 8/8] riscv: fix building compressed EFI image Dmitry Antipov
2026-05-19 19:10 ` [PATCH v11 0/8] lib and lib/cmdline enhancements Andrew Morton
2026-06-26 8:21 ` patchwork-bot+linux-riscv
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox