From nobody Mon May 25 02:04:48 2026 Received: from forward201a.mail.yandex.net (forward201a.mail.yandex.net [178.154.239.92]) (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 D54B226056C; Tue, 19 May 2026 17:28:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.92 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779211733; cv=none; b=F5M0XjpylFcKyVOXuGeVcNM/tE2zFVOlKfG16+Bi0GaqP+v7+9tJifnzXSCmFmxrAaU2waUr9FhKVVnNWBvMeIHw7R7HlVTjwhDu7RFGpo3B2qmTxfn5m547DBZDmSgZZ12J+R4sIMCCJhDB3yeoX1Fl5oQ+RYCOreYMdzk6pRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779211733; c=relaxed/simple; bh=5unapVmx2VbqB5nn/Gbx4ZyoZw7Grw7YupbOT+ZcRTE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gq0Rj+0wD+qaE6TcV4VTIfM8/vRrs0YkP+NGd6HFXQhf/y/OGXwUEVptlcuDQ5lZlNGLY5w8KoCnbbZYcbnDdVJRUF1fA558OQNJHXf94IyisGYRt8rtxlWwssnBgENIKlRseoswe1bXk9gRNYnJm7pw13m7/tUVXOCVVZxr2FE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=dUTNcOH1; arc=none smtp.client-ip=178.154.239.92 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="dUTNcOH1" Received: from forward101a.mail.yandex.net (forward101a.mail.yandex.net [IPv6:2a02:6b8:c0e:500:1:45:d181:d101]) by forward201a.mail.yandex.net (Yandex) with ESMTPS id CEC58838C7; Tue, 19 May 2026 20:23:14 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:190d:0:640:bab5:0]) by forward101a.mail.yandex.net (Yandex) with ESMTPS id B238E80C08; Tue, 19 May 2026 20:23:06 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net (smtp) with ESMTPSA id 0NVul40SU0U0-O5TK05PT; Tue, 19 May 2026 20:23:05 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1779211385; bh=TBxNdS4HSxmdP1AXz5UGyX20Ie/mR2EERiHh7P+Kz6A=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=dUTNcOH1uMISJWvdP8WrZXM0GUPpIDaj0dDk6sINUnI6xIUmkCKSzMRtiSCChtyE+ 1YUplqdvxbK/69WsRNiwTMeq0muVSL7YWuI8rUc2ty94GCU78F1T99eA8PPpffxGJd K0QgDYJtKkZOWZ/Ygy+xtnGD8YkrON6LSeAAFZ4g= Authentication-Results: mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andrew Morton Cc: Andy Shevchenko , Charlie Jenkins , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Ard Biesheuvel , linux-riscv@lists.infradead.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v11 1/8] lib: fix _parse_integer_limit() to handle overflow Date: Tue, 19 May 2026 20:22:52 +0300 Message-ID: <20260519172259.908980-2-dmantipov@yandex.ru> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260519172259.908980-1-dmantipov@yandex.ru> References: <20260519172259.908980-1-dmantipov@yandex.ru> 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" 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 Signed-off-by: Dmitry Antipov --- 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, u= nsigned int *base) return s; } =20 -/* - * 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 inte= ger + * @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_M= AX. * - * 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, unsign= ed long long *p, size_t max_chars) { + unsigned int rv, overflow =3D 0; unsigned long long res; - unsigned int rv; =20 res =3D 0; - rv =3D 0; - while (max_chars--) { + for (rv =3D 0; rv < max_chars; rv++, s++) { unsigned int c =3D *s; unsigned int lc =3D _tolower(c); unsigned int val; @@ -76,15 +81,17 @@ unsigned int _parse_integer_limit(const char *s, unsign= ed 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 |=3D KSTRTOX_OVERFLOW; + if (check_mul_overflow(res, base, &res) || + check_add_overflow(res, val, &res)) { + res =3D ULLONG_MAX; + overflow =3D KSTRTOX_OVERFLOW; + } + } else { + res =3D res * base + val; } - res =3D res * base + val; - rv++; - s++; } *p =3D res; - return rv; + return rv | overflow; } =20 noinline --=20 2.54.0 From nobody Mon May 25 02:04:48 2026 Received: from forward100d.mail.yandex.net (forward100d.mail.yandex.net [178.154.239.211]) (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 AD825226CF6; Tue, 19 May 2026 17:23:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.211 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779211401; cv=none; b=e/JJ9zh1SnqZWxzHcHkwmE++Mg9lOI37pUkGa54UrmpAgHTuJGq/IcKXPbqtHswtibY3Jj6SaFq+REF0kDg7jmLkPxUNegC7TrqnQ5pcs+NZYNgpka+JaoVNk93yc74cgBoN6qOhTA/xzK7hugt8XoBeJCYsvQyxHiArvhx8Pu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779211401; c=relaxed/simple; bh=fEBy8PwiXNY8RhSQMbxjv/pfcxS3iIEOPQejxH/LpgQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YNivNlYuL6XoDs6iau0yyjAritGeBbGr4V4ReYZGFp5Tt1hJl7G6VyMBJUmPzoefMytG7m8B+e1yEL6uk89ie/+qjKGM/wmX/4K0yDCV273yzBnJ5CoNEDY1qTKtLGL+x5YRa+j9ZT7F3gzsZ21/rbefMPJdwqucnu1eMQU0NRQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=wM4ir5Wg; arc=none smtp.client-ip=178.154.239.211 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="wM4ir5Wg" Received: from mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:190d:0:640:bab5:0]) by forward100d.mail.yandex.net (Yandex) with ESMTPS id 01273C0051; Tue, 19 May 2026 20:23:09 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net (smtp) with ESMTPSA id 0NVul40SU0U0-h1uA6rsG; Tue, 19 May 2026 20:23:08 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1779211388; bh=6V25NbAI3/rMJ9o0WKC5Hikn/U0EkOQjDi4xZKCFUJ8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=wM4ir5WgqIXnjYDbIyTg9dAD0zEBOQtMGJz5TaHG1TXnN65QbqlWTWHyaZObz0Mpt QjgQiiV2gjDDLTPKG/8k/+zr2/AxW91nyxIuFGkZLRS777skPEjId5yHX1BBU94Si3 BEudjJf64ax3eLeRhYSKfswPGMyXn0On+U2hscZM= Authentication-Results: mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andrew Morton Cc: Andy Shevchenko , Charlie Jenkins , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Ard Biesheuvel , linux-riscv@lists.infradead.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v11 2/8] lib: fix memparse() to handle overflow Date: Tue, 19 May 2026 20:22:53 +0300 Message-ID: <20260519172259.908980-3-dmantipov@yandex.ru> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260519172259.908980-1-dmantipov@yandex.ru> References: <20260519172259.908980-1-dmantipov@yandex.ru> 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" 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 Signed-off-by: Dmitry Antipov --- 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 =3D simple_strtoull(ptr, &endptr, 0); + unsigned int shl =3D 0; =20 + /* Consume valid suffix even in case of overflow. */ switch (*endptr) { case 'E': case 'e': - ret <<=3D 10; + shl +=3D 10; fallthrough; case 'P': case 'p': - ret <<=3D 10; + shl +=3D 10; fallthrough; case 'T': case 't': - ret <<=3D 10; + shl +=3D 10; fallthrough; case 'G': case 'g': - ret <<=3D 10; + shl +=3D 10; fallthrough; case 'M': case 'm': - ret <<=3D 10; + shl +=3D 10; fallthrough; case 'K': case 'k': - ret <<=3D 10; - endptr++; + shl +=3D 10; fallthrough; default: break; } =20 + if (shl && likely(ptr !=3D endptr)) { + /* Have valid suffix with preceding number. */ + if (unlikely(check_shl_overflow(ret, shl, &ret))) + ret =3D ULLONG_MAX; + endptr++; + } + if (retptr) *retptr =3D endptr; =20 --=20 2.54.0 From nobody Mon May 25 02:04:48 2026 Received: from forward102d.mail.yandex.net (forward102d.mail.yandex.net [178.154.239.213]) (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 4DB123DB33F; Tue, 19 May 2026 17:23:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.213 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779211402; cv=none; b=al2v8El/RvTKmBto4N+xkKcwloOuQUktWJL2FDZWt+vGzYElESR/Sdm3tIuCnX1jZd8zkR2tWFTEB0TfRBMMtMdQKkM3vEXtRW+gfOrjK/2k5zzC9XLAGoxQfLdkOwYCAfXEy7DZfmJLhuZIUuSs4sTsOuus9CbAXBx/X1pXm1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779211402; c=relaxed/simple; bh=q0ak2hPMrGptHgj29Xb2vDdGw9aze3WfCZB8YABZlio=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WWleVXYAw3H/UMaBT6jsxKI5gZdjJzzg/Pwks2J3UQ7YNeimdJXZXuKRkFRy5ntciWeTgBM9xr11xWnDo+hTULYYP2e3k5gLeyAjLEIqVjVUu3BLLuVxsDnkAREbo2MpNPQS0BrsmjwgHmrPkCyyHgWn5VxDzn7HHnIpWKp1mEU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=NSSYux7h; arc=none smtp.client-ip=178.154.239.213 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="NSSYux7h" Received: from mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:190d:0:640:bab5:0]) by forward102d.mail.yandex.net (Yandex) with ESMTPS id 604B1C007D; Tue, 19 May 2026 20:23:10 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net (smtp) with ESMTPSA id 0NVul40SU0U0-XRPZAYTb; Tue, 19 May 2026 20:23:09 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1779211389; bh=9g1rCpxz2tcUvBZ4ViA0PV+aISe/bmNJIWEfyzUAKpg=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=NSSYux7hqTyjHSUqQoKwJqBitdSvRASZAoYE1h8p1hsyAPUve9aMjOllPG6R/0vb5 +sbubibTEqLujVVWNlUX/7xd+gdKEm65ew1Z2lToar4qM9+KBseA1xHHr8RtoAw03u DeLrFvh5u+X7ny9VVom9Gr0b91buE/k9UJceiKZA= Authentication-Results: mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andrew Morton Cc: Andy Shevchenko , Charlie Jenkins , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Ard Biesheuvel , linux-riscv@lists.infradead.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v11 3/8] lib: add more string to 64-bit integer conversion overflow tests Date: Tue, 19 May 2026 20:22:54 +0300 Message-ID: <20260519172259.908980-4-dmantipov@yandex.ru> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260519172259.908980-1-dmantipov@yandex.ru> References: <20260519172259.908980-1-dmantipov@yandex.ru> 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" 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 Reviewed-by: Andy Shevchenko Signed-off-by: Dmitry Antipov --- 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); } --=20 2.54.0 From nobody Mon May 25 02:04:48 2026 Received: from forward205a.mail.yandex.net (forward205a.mail.yandex.net [178.154.239.88]) (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 785E040961E; Tue, 19 May 2026 17:31:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.88 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779211887; cv=none; b=lUNnlKfpksstYJMtjENrfhe47O77wasaKod4IZzu5Vz/9lZvF2D+HK9re/J202Gwu8jfY4LQR0Nz4yDnG3EtKmvC+Fz14zoz9JQoUS7H9FQnU1iRdo2Bw2zTHpKWuZEASMUjuoCHKndoe2ZV9zrLGuztR6Emva2pumL/73/tWbE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779211887; c=relaxed/simple; bh=48e/NtcfrEecoxDCuEjuVsQCDDgGwjBQKc6n0WNja+w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MsqEcef06Y96WCL7DksXh6oOJ2VbI/iVH/HDIxmYDgGujQDt4YpGZRq1yJhXEFXLtGNF+Kdpe6tf/vO/L4ufOROGFbLO/l71hl+p5RkZhAZE3mc25elA+gHb6zxbxa6i9Heujwoe9kcTp9pz89cb/mZ9/r9NfW2clnXLGsnn0EI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=w2+JShxA; arc=none smtp.client-ip=178.154.239.88 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="w2+JShxA" Received: from forward100a.mail.yandex.net (forward100a.mail.yandex.net [IPv6:2a02:6b8:c0e:500:1:45:d181:d100]) by forward205a.mail.yandex.net (Yandex) with ESMTPS id EA7E5C5277; Tue, 19 May 2026 20:23:18 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:190d:0:640:bab5:0]) by forward100a.mail.yandex.net (Yandex) with ESMTPS id 6DE4BC0188; Tue, 19 May 2026 20:23:11 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net (smtp) with ESMTPSA id 0NVul40SU0U0-yH0wfFvb; Tue, 19 May 2026 20:23:10 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1779211390; bh=5sQTk16iTwRjsA7opO3KVlv5gR/NRWgPvIqwzzepJnA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=w2+JShxAAgcXPB9AFl3ER7QVJRUTXPQasbyRsbFu/ThwFYRbj8f7TbU4PeY0xZZWN 3pflaEWzDWYlXtaM84auXB89Y2Ha7SjV942e278SARaIVubMV6O3dfguWjRy4TAcrL hSpS9PocpF2LOaNdG62cVQ4Ck2z/9taUbJ3iUVtc= Authentication-Results: mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andrew Morton Cc: Andy Shevchenko , Charlie Jenkins , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Ard Biesheuvel , linux-riscv@lists.infradead.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v11 4/8] lib/cmdline_kunit: add test case for memparse() Date: Tue, 19 May 2026 20:22:55 +0300 Message-ID: <20260519172259.908980-5-dmantipov@yandex.ru> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260519172259.908980-1-dmantipov@yandex.ru> References: <20260519172259.908980-1-dmantipov@yandex.ru> 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" Better late than never, now there is a long-awaited basic test for 'memparse()' which is provided by cmdline.c. Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Signed-off-by: Dmitry Antipov --- v7 and upwards: bump version to match the series v6: tests to check whether valid-suffix-only string is handled as unrecogni= zed 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 #include #include +#include #include =20 static const char *cmdline_test_strings[] =3D { @@ -139,11 +140,66 @@ static void cmdline_test_range(struct kunit *test) } while (++i < ARRAY_SIZE(cmdline_test_range_strings)); } =20 +struct cmdline_test_memparse_entry { + const char *input; + const char *unrecognized; + unsigned long long result; +}; + +static const struct cmdline_test_memparse_entry testdata[] =3D { + { "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=3Dbaz", ";", 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 =3D testdata; e < testdata + ARRAY_SIZE(testdata); e++) { + ret =3D 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[] =3D { 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), {} }; =20 --=20 2.54.0 From nobody Mon May 25 02:04:48 2026 Received: from forward204d.mail.yandex.net (forward204d.mail.yandex.net [178.154.239.217]) (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 987E33FC5C0; Tue, 19 May 2026 17:23:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.217 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779211409; cv=none; b=n1K/4yYUvnyAVacDT1IaKDqr7ffB3o8QCIhZogAF+3BYHZslmol4Bst3WdZvWdmVNdzSna6CESziG59X1A8KEqt9WaGFL2VkP2Rt9ARLTPXw9Z1Ho05ZbfXIFctaIG7ovIFw+cawwGRzxNwlq/EbDbTL6UFouOehmdOOT0SqIHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779211409; c=relaxed/simple; bh=qUVbE+TeHACIDYQtXvQZb/Jb/ZvYZJiXsNQli4gdvAA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VxMUelLZGkF1TgMroWMzJFpmkiM1HEuPE69hvI1TkBZ9yaPm95TlfQHOQKcwcnOG5BpMKXXYlggESmXmlk/dI4M5JC47QAciwL1fgd456YwkXcGBJq9ZtgELlCkeYdSm+X8MLdz8OcwuEHYbA8uKD30pMaCc3NjvWDMCuVk4Ux4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=BUblyzK4; arc=none smtp.client-ip=178.154.239.217 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="BUblyzK4" Received: from forward103d.mail.yandex.net (forward103d.mail.yandex.net [IPv6:2a02:6b8:c41:1300:1:45:d181:d103]) by forward204d.mail.yandex.net (Yandex) with ESMTPS id BAD9585438; Tue, 19 May 2026 20:23:19 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:190d:0:640:bab5:0]) by forward103d.mail.yandex.net (Yandex) with ESMTPS id 90418C0048; Tue, 19 May 2026 20:23:12 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net (smtp) with ESMTPSA id 0NVul40SU0U0-DLgLxBU6; Tue, 19 May 2026 20:23:11 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1779211391; bh=TvbFunkv2EyimV0ymMZbjXhYDuTThqNebOOa38V8+rw=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=BUblyzK4TFxjKFwZKM9GA5Jvby+tQwkakijbfwBOO3T7xM6xa5tWGMqzMqp8sMocv NLZ0vFQm9mpwLscS5hSR09lNbGGVj9/qMXR/xxKHVbA3uqZc4ehioRc/ymxS3Vumro iXy+SUvFsKrU91BpDs2FjOqRUYocOL6kI/E0Zb0c= Authentication-Results: mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andrew Morton Cc: Andy Shevchenko , Charlie Jenkins , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Ard Biesheuvel , linux-riscv@lists.infradead.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v11 5/8] lib/cmdline: adjust a few comments to fix kernel-doc -Wreturn warnings Date: Tue, 19 May 2026 20:22:56 +0300 Message-ID: <20260519172259.908980-6-dmantipov@yandex.ru> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260519172259.908980-1-dmantipov@yandex.ru> References: <20260519172259.908980-1-dmantipov@yandex.ru> 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" 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 Reviewed-by: Andy Shevchenko Signed-off-by: Dmitry Antipov --- 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. */ =20 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=3Db,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) { --=20 2.54.0 From nobody Mon May 25 02:04:48 2026 Received: from forward102a.mail.yandex.net (forward102a.mail.yandex.net [178.154.239.85]) (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 BC3D226ED33; Tue, 19 May 2026 17:23:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.85 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779211404; cv=none; b=L0OHGAmMbuF9cRt+UbBvaI194+WJla/DgapwxQGe0LpK0VzoIXaHSWK53TQ2KWl/AxA9jthXVxbuOmODRCuUPf0wuIdk9POQhs1giIytHY96/am5mCbOEjOv+9QJB7yH3U7RePgWCHYwL+ytPqzpHnrjHY2wOQ6er5z/R9aRJZg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779211404; c=relaxed/simple; bh=BXm3k9DwZOydVTnW3wTU5zUjHH8/aFRyR7x74yT3GjY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WI1N3QZPkpjlhHJQ25zdgv7wmp6igM76dn+Q7UTcfNBUfhzwzoZbvgydidgr628lZ28mKhHFkqvGN2LUNsCuLQtFMOfGgdRnI22yb/gTFLX2q5J3jib97mYn5eV3Of1c+z+P207xrDRObjEGxfhchFNsV4yE69u/x5q7fs7Xnxo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=dApCFRiU; arc=none smtp.client-ip=178.154.239.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="dApCFRiU" Received: from mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:190d:0:640:bab5:0]) by forward102a.mail.yandex.net (Yandex) with ESMTPS id 92750C005E; Tue, 19 May 2026 20:23:13 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net (smtp) with ESMTPSA id 0NVul40SU0U0-Gci2XP8h; Tue, 19 May 2026 20:23:12 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1779211393; bh=RlBllG7xaFB9wd9pV2iJ33aeysyHThnJfl/5cV3wCu4=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=dApCFRiUhX27g6H/mF6Ny4fWKiH1sHsKJoznxAYCWzp9cXa9GBzXe0JZaOOtCEYpp YYY4H10H4hnNNUiXZQv3rb3lHKrCW8ur1cAuF+8fsF4fS6nFMXE9Y3dyggz6k2T0MP qDkS4UoQoxmpBx6gKNDtQ0ProDuW2eda/opDukLI= Authentication-Results: mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andrew Morton Cc: Andy Shevchenko , Charlie Jenkins , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Ard Biesheuvel , linux-riscv@lists.infradead.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov , kernel test robot Subject: [PATCH v11 6/8] riscv: add platform-specific double word shifts for riscv32 Date: Tue, 19 May 2026 20:22:57 +0300 Message-ID: <20260519172259.908980-7-dmantipov@yandex.ru> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260519172259.908980-1-dmantipov@yandex.ru> References: <20260519172259.908980-1-dmantipov@yandex.ru> 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" 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=3Dy and CONFIG_EFI_GENERIC_STUB=3Dy: 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 ref= erence to `__efistub___lshrdi3' Reported at [1] trying to build https://patchew.org/linux/20260212164413.88= 9625-1-dmantipov@yandex.ru, tested with 'qemu-system-riscv32 -M virt' only. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202603041925.KLKqpK6N-lkp@int= el.com [1] Suggested-by: Ard Biesheuvel Tested-by: Charlie Jenkins Assisted-by: Gemini:gemini-3.1-pro-preview sashiko Signed-off-by: Dmitry Antipov --- 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 =20 config ARCH_RV64I diff --git a/arch/riscv/include/asm/asm-prototypes.h b/arch/riscv/include/a= sm/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 #include =20 +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 =3D __init_text_end; __efistub_sysfb_primary_display =3D sysfb_primary_display; #endif =20 +/* + * 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 =3D __lshrdi3); +PROVIDE(__efistub___ashldi3 =3D __ashldi3); +PROVIDE(__efistub___ashrdi3 =3D __ashrdi3); + #endif =20 #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) +=3D uaccess_vector.o endif lib-$(CONFIG_MMU) +=3D uaccess.o +lib-$(CONFIG_32BIT) +=3D ashldi3.o ashrdi3.o lshrdi3.o lib-$(CONFIG_64BIT) +=3D tishift.o lib-$(CONFIG_RISCV_ISA_ZICBOZ) +=3D clear_page.o obj-$(CONFIG_FUNCTION_ERROR_INJECTION) +=3D 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/llshif= t.S + */ + +#include +#include + +/** + * 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/llshif= t.S + */ + +#include +#include + +/** + * 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/llshif= t.S + */ + +#include +#include + +/** + * 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) --=20 2.54.0 From nobody Mon May 25 02:04:48 2026 Received: from forward203d.mail.yandex.net (forward203d.mail.yandex.net [178.154.239.218]) (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 54181408008; Tue, 19 May 2026 17:23:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.218 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779211413; cv=none; b=LsVPE/CO1Oj8+WRUq+FI6NN97IYYzKyiU5AzelNd5Mg1n7V6XzC0aMWKv7vo6bGhLRhF3/8aKhaQB5WxnHTbqeKQKrk3pigFjA9BavaPTEsuXQS5mJFzDfqucGD0Li8k5YQb0EEJtPsXlNIAuJQ0nwzzAxlxIcStPLDWWZnQTD0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779211413; c=relaxed/simple; bh=oFBnyIxrDyT0KKeVfzBdBq8Ns789hhv/2FdHmuqflJU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=loTI4lcHGQl1Ok8kBFdVGoT5cCZazKiyJyB5Jbou9o2oL8hvER5DZc+NtPkmy/uDYliF0ddR0xslzpSTyQM8rWNveHYYlyGpuXJ+XwD8S2jwUY6Sy5GJilMXikiI1o0MOJmc77NaxnDnNPPGwaSN5H562+Ts/MFZ896exYwE944= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=OXQq27gJ; arc=none smtp.client-ip=178.154.239.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="OXQq27gJ" Received: from forward103d.mail.yandex.net (forward103d.mail.yandex.net [IPv6:2a02:6b8:c41:1300:1:45:d181:d103]) by forward203d.mail.yandex.net (Yandex) with ESMTPS id 5BAAC846CA; Tue, 19 May 2026 20:23:23 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:190d:0:640:bab5:0]) by forward103d.mail.yandex.net (Yandex) with ESMTPS id C4C96C006C; Tue, 19 May 2026 20:23:14 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net (smtp) with ESMTPSA id 0NVul40SU0U0-VgL9yf6V; Tue, 19 May 2026 20:23:13 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1779211394; bh=xzG4XWRWYOhW+VDKKOYbDyFIDHXX/FS9o4Tjn79fogA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=OXQq27gJ8UHBNAaXysC+DXwjIAc8+m6o3nLIUj7YpGKCSO1L/lZY++ZYhjtVHS5vf oRmrKhgLJbl4WwD6uuKjMuAP2uurxAaZE9SH5LwK9EGbLWPpMl+v5Xx2RBFo7yboZE /d+pDTXRsGfWRSZsb++7VsiouP4ItZGuF+UlLZ+Q= Authentication-Results: mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andrew Morton Cc: Andy Shevchenko , Charlie Jenkins , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Ard Biesheuvel , linux-riscv@lists.infradead.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v11 7/8] lib: kunit: add tests for __ashldi3(), __ashrdi3(), and __lshrdi3() Date: Tue, 19 May 2026 20:22:58 +0300 Message-ID: <20260519172259.908980-8-dmantipov@yandex.ru> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260519172259.908980-1-dmantipov@yandex.ru> References: <20260519172259.908980-1-dmantipov@yandex.ru> 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" 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 Tested-by: Charlie Jenkins Assisted-by: Gemini:gemini-3.1-pro-preview sashiko Signed-off-by: Dmitry Antipov --- v11: explicitly depends on arm/xtensa/microblaze or 32-bit riscv/sparc (Sas= hiko) 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 =20 If unsure, say N. =20 +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) +=3D base64_kunit.o obj-$(CONFIG_BITOPS_KUNIT) +=3D bitops_kunit.o obj-$(CONFIG_BITFIELD_KUNIT) +=3D bitfield_kunit.o obj-$(CONFIG_BITS_TEST) +=3D test_bits.o +obj-$(CONFIG_SHDI3_KUNIT_TEST) +=3D shdi3_kunit.o obj-$(CONFIG_BLACKHOLE_DEV_KUNIT_TEST) +=3D blackhole_dev_kunit.o obj-$(CONFIG_CHECKSUM_KUNIT) +=3D checksum_kunit.o obj-$(CONFIG_CMDLINE_KUNIT_TEST) +=3D 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 +#include +#include +#include + +struct shdi3_test_entry { + long long input; + int shift; + long long result; +}; + +static const struct shdi3_test_entry ashldi3_testdata[] =3D { + /* https://github.com/llvm/llvm-project/compiler-rt/test/builtins/Unit/as= hldi3_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 =3D ashldi3_testdata; + e < ashldi3_testdata + ARRAY_SIZE(ashldi3_testdata); e++) { + ret =3D __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[] =3D { + /* https://github.com/llvm/llvm-project/compiler-rt/test/builtins/Unit/as= hrdi3_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 =3D ashrdi3_testdata; + e < ashrdi3_testdata + ARRAY_SIZE(ashrdi3_testdata); e++) { + ret =3D __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[] =3D { + /* https://github.com/llvm/llvm-project/compiler-rt/test/builtins/Unit/ls= hrdi3_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 =3D lshrdi3_testdata; + e < lshrdi3_testdata + ARRAY_SIZE(lshrdi3_testdata); e++) { + ret =3D __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[] =3D { + KUNIT_CASE(shdi3_test_ashldi3), + KUNIT_CASE(shdi3_test_ashrdi3), + KUNIT_CASE(shdi3_test_lshrdi3), + {} +}; + +static struct kunit_suite shdi3_test_suite =3D { + .name =3D "shdi3", + .test_cases =3D shdi3_test_cases, +}; +kunit_test_suite(shdi3_test_suite); + +MODULE_DESCRIPTION("Test cases for __ashldi3(), __ashrdi3(), and __lshrdi3= ()"); +MODULE_LICENSE("GPL"); --=20 2.54.0 From nobody Mon May 25 02:04:48 2026 Received: from forward101b.mail.yandex.net (forward101b.mail.yandex.net [178.154.239.148]) (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 B0307366563; Tue, 19 May 2026 17:23:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779211406; cv=none; b=UYaczQnzr1Qr3lnVQBZRaqko3r/AyTGikVjA5Lupq39GqKl5FvJ/LCTyZvjuoWizUIAR1/rGKWzWGXKBIqielgVMaINlfPoqNXoKlJoXaEvXEy+Zt6Y9fQVVO2FMu8xvosbjKWpS6a1wEJJMIKQ7PtCOFMOQGZrR5IIo2iEHwWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779211406; c=relaxed/simple; bh=TxsMJH4Y1ddz1II7TlZpYOPpl2Rs7MjmP1GzGotDf8I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sRmQRQaLkZSX7bAaDxGSjcJNQVu9q2J5h13zyy3JKXhMogdhbmaYbRraozm+Mf1+4nhJTI/5j8LuLfh/cr1ghZnma6eidLUkBdusVbFc52DMrWc+kkW8eBpBX/kH2/880gphuALY6ESFsh0FlrfUGoIJdz1agdmGjseN3Bq8uf4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=YmepTDbL; arc=none smtp.client-ip=178.154.239.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="YmepTDbL" Received: from mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:190d:0:640:bab5:0]) by forward101b.mail.yandex.net (Yandex) with ESMTPS id AE87BC007F; Tue, 19 May 2026 20:23:15 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net (smtp) with ESMTPSA id 0NVul40SU0U0-d8TIqb0q; Tue, 19 May 2026 20:23:15 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1779211395; bh=/FIawmucMp3alAanBUAmlLHzqCj+wCHK3Vge4Om/wTA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=YmepTDbLQjOK8OGza2J5im7u1kgbJqijMeIY2G8i75YT6X1kQLYAQQtjug/1Lq/Lz SowH3z5JqQ8f/PiXNg3wmtzYth7qEG+LbzHl6xlOtE4Vkkju4OoMT+W826vJxx+3jy eBc/dGg8azALrMOCbHutpop4Q8FXWo3xFf281Dj4= Authentication-Results: mail-nwsmtp-smtp-production-main-92.iva.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Andrew Morton Cc: Andy Shevchenko , Charlie Jenkins , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Ard Biesheuvel , linux-riscv@lists.infradead.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Antipov Subject: [PATCH v11 8/8] riscv: fix building compressed EFI image Date: Tue, 19 May 2026 20:22:59 +0300 Message-ID: <20260519172259.908980-9-dmantipov@yandex.ru> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260519172259.908980-1-dmantipov@yandex.ru> References: <20260519172259.908980-1-dmantipov@yandex.ru> 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" 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 f= unction `__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 Closes: https://lore.kernel.org/linux-riscv/20260409050018.GA371560@inky.lo= caldomain Tested-by: Charlie Jenkins Suggested-by: Ard Biesheuvel Assisted-by: Gemini:gemini-3.1-pro-preview sashiko Signed-off-by: Dmitry Antipov --- 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/l= ibstub/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 +=3D -I$(srctree)/lib/zlib= _inflate zboot-obj-$(CONFIG_KERNEL_ZSTD) :=3D zboot-decompress-zstd.o lib-xxhash.o CFLAGS_zboot-decompress-zstd.o +=3D -I$(srctree)/lib/zstd =20 -zboot-obj-$(CONFIG_RISCV) +=3D lib-clz_ctz.o lib-ashldi3.o +zboot-riscv-obj-$(CONFIG_32BIT) +=3D lib-ashldi3.o lib-lshrdi3.o +zboot-obj-$(CONFIG_RISCV) +=3D lib-clz_ctz.o $(zboot-riscv-obj-y) zboot-obj-$(CONFIG_LOONGARCH) +=3D lib-clz_ctz.o lib-ashldi3.o lib-$(CONFIG_EFI_ZBOOT) +=3D zboot.o $(zboot-obj-y) =20 --=20 2.54.0