From: Jinseob Kim <kimjinseob88@gmail.com>
To: yury.norov@gmail.com
Cc: linux@rasmusvillemoes.dk, akpm@linux-foundation.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] lib/test_bitmap: cover unused tail bits in bitmap_cut()
Date: Mon, 23 Nov 2026 13:31:54 +0900 [thread overview]
Message-ID: <9350566bc24af03c9dbd9c7dff0691769edcaf32.1795407826.git.kimjinseob88@gmail.com> (raw)
In-Reply-To: <cover.1795407826.git.kimjinseob88@gmail.com>
Exercise 33-, 65-, and 127-bit bitmaps with pairs of inputs that
differ only in the first unused storage bit. Check the valid output
against a per-bit reference and compare it with the output from the
second input.
Cover in-place and disjoint buffers and both directions of partial
overlap when the bitmap spans multiple words. Check that disjoint
source storage is preserved.
Signed-off-by: Jinseob Kim <kimjinseob88@gmail.com>
---
lib/test_bitmap.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 90 insertions(+), 1 deletion(-)
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index eb925d576..104fc23a4 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -1145,6 +1145,7 @@ static struct test_bitmap_cut test_cut[] = {
static void __init test_bitmap_cut(void)
{
unsigned long b[5], *in = &b[1], *out = &b[0]; /* Partial overlap */
+ unsigned int initial_failures = failed_tests;
int i;
for (i = 0; i < ARRAY_SIZE(test_cut); i++) {
@@ -1154,10 +1155,97 @@ static void __init test_bitmap_cut(void)
bitmap_cut(out, in, t->first, t->cut, t->nbits);
- expect_eq_bitmap(t->expected, out, t->nbits);
+ if (expect_eq_bitmap(t->expected, out, t->nbits))
+ pr_warn("bitmap_cut existing row=%d first=%u cut=%u nbits=%u\n",
+ i + 1, t->first, t->cut, t->nbits);
}
+
+ pr_info("bitmap_cut existing rows=%zu failures=%u\n", ARRAY_SIZE(test_cut),
+ failed_tests - initial_failures);
}
+#define BITMAP_CUT_TEST_MAX_BITS 127
+
+static void __init test_bitmap_cut_padding_case(unsigned int nbits, unsigned int first,
+ unsigned long *dst, unsigned long *src,
+ const char *layout, bool separate)
+{
+ DECLARE_BITMAP(input, BITMAP_CUT_TEST_MAX_BITS);
+ DECLARE_BITMAP(expected, BITMAP_CUT_TEST_MAX_BITS);
+ DECLARE_BITMAP(clean, BITMAP_CUT_TEST_MAX_BITS);
+ unsigned int bit;
+ size_t bytes = bitmap_size(nbits);
+
+ bitmap_zero(input, nbits);
+ bitmap_zero(expected, nbits);
+
+ if (first) {
+ /* Preserve bit 1, remove bit 2, and move the bits above it. */
+ __set_bit(1, input);
+ __set_bit(2, input);
+ __set_bit(4, input);
+ __set_bit(nbits - 1, input);
+ }
+
+ for (bit = 0; bit < nbits; bit++) {
+ unsigned int source = bit + (bit >= first);
+
+ if (source < nbits && test_bit(source, input))
+ __set_bit(bit, expected);
+ }
+
+ bitmap_copy(src, input, nbits);
+ bitmap_cut(dst, src, first, 1, nbits);
+ if (expect_eq_bitmap(expected, dst, nbits))
+ pr_warn("bitmap_cut clean nbits=%u first=%u layout=%s\n", nbits, first, layout);
+ if (separate && expect_eq_uint(0, memcmp(src, input, bytes) != 0))
+ pr_warn("bitmap_cut clean input changed nbits=%u first=%u\n", nbits, first);
+ bitmap_copy(clean, dst, nbits);
+
+ /* The first padding bit is in storage, but outside the bitmap. */
+ __set_bit(nbits, input);
+ bitmap_copy(src, input, nbits);
+ bitmap_cut(dst, src, first, 1, nbits);
+ if (expect_eq_bitmap(clean, dst, nbits))
+ pr_warn("bitmap_cut padding nbits=%u first=%u layout=%s\n", nbits, first, layout);
+ if (separate && expect_eq_uint(0, memcmp(src, input, bytes) != 0))
+ pr_warn("bitmap_cut padded input changed nbits=%u first=%u\n", nbits, first);
+}
+
+static void __init test_bitmap_cut_padding(void)
+{
+ static const unsigned int sizes[] = { 33, 65, BITMAP_CUT_TEST_MAX_BITS };
+ static const unsigned int starts[] = { 0, 2 };
+ unsigned long buf[2 * BITS_TO_LONGS(BITMAP_CUT_TEST_MAX_BITS)];
+ unsigned int initial_failures = failed_tests;
+ unsigned int i, j, pairs = 0;
+
+ for (i = 0; i < ARRAY_SIZE(sizes); i++) {
+ unsigned int nbits = sizes[i];
+ unsigned int len = BITS_TO_LONGS(nbits);
+
+ for (j = 0; j < ARRAY_SIZE(starts); j++) {
+ test_bitmap_cut_padding_case(nbits, starts[j], buf, buf, "in-place", false);
+ test_bitmap_cut_padding_case(nbits, starts[j], buf, buf + len,
+ "separate", true);
+ pairs += 2;
+
+ if (len > 1) {
+ test_bitmap_cut_padding_case(nbits, starts[j], buf, buf + 1,
+ "dst-before-src", false);
+ test_bitmap_cut_padding_case(nbits, starts[j], buf + 1, buf,
+ "dst-after-src", false);
+ pairs += 2;
+ }
+ }
+ }
+
+ pr_info("bitmap_cut padding pairs=%u failures=%u\n", pairs,
+ failed_tests - initial_failures);
+}
+
+#undef BITMAP_CUT_TEST_MAX_BITS
+
struct test_bitmap_print {
const unsigned long *bitmap;
unsigned long nbits;
@@ -1587,6 +1675,7 @@ static void __init selftest(void)
test_bitmap_printlist();
test_mem_optimisations();
test_bitmap_cut();
+ test_bitmap_cut_padding();
test_bitmap_print_buf();
test_bitmap_const_eval();
test_bitmap_read_write();
prev parent reply other threads:[~2026-11-23 4:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 4:31 [PATCH 0/2] bitmap: keep unused tail bits out of bitmap_cut() results Jinseob Kim
2026-11-23 4:31 ` [PATCH 1/2] bitmap: ignore unused tail bits in bitmap_cut() Jinseob Kim
2026-11-23 4:31 ` Jinseob Kim [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9350566bc24af03c9dbd9c7dff0691769edcaf32.1795407826.git.kimjinseob88@gmail.com \
--to=kimjinseob88@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®