From: Viacheslav Dubeyko <slava@dubeyko.com>
To: Shawn Shao <shawnq1@163.com>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
Yangtao Li <frank.li@vivo.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] hfsplus: reorder complete combining runs for dentry keys
Date: Mon, 30 Nov 2026 13:12:10 -0800 [thread overview]
Message-ID: <16d041e4b01dc83a82168696742c731710f4db69.camel@dubeyko.com> (raw)
In-Reply-To: <20261130074816.2537284-1-shawnq1@163.com>
On Mon, 2026-11-30 at 07:48 +0000, Shawn Shao wrote:
> Hello,
>
> Thanks for reviewing the patch and reporting the frame-size warnings.
>
> The iterator still reorders a complete combining run. The refill
> routine is
> now kept out of the caller's stack frame, and the KUnit test
> allocates its
> two stored Unicode strings with KUnit-managed memory.
>
> Two equivalent UTF-8 spellings with a 33-mark run could produce
> different
> dentry hashes and comparisons, although HFS+ stores them in the same
> canonical order. The regression test checks hashes, comparison, and
> stored
> Unicode forms.
>
> Tested on:
> Tested source: v7.3-23903-g7cd8495c0f162
> compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0
> QEMU: QEMU emulator version 6.2.0
>
> The x86-64 bzImage build completed with CONFIG_FRAME_WARN=1280 and
> KCFLAGS=-Wframe-larger-than=1280. GCC reports stack usage of 1136
> bytes in
> hfsplus_compare_dentry(), 64 bytes in the refill routine, and 256
> bytes in
> the KUnit test. The hfsplus_unicode suite passed all 35 tests. The
> QEMU
> reproducer found the alternate 33-mark spelling immediately after
> creation
> (POS_BAD_AFTER_CREATE=1); the 31-mark control also passed. The
> unchanged
> positive-only reproducer exits 1 on the fixed kernel after printing
> ORACLE: NOT CONFIRMED. POS_BAD_AFTER_CREATE=1 confirms the alternate
> spelling is found before remount, as expected for the fix. The
> reproducer
> and image inputs are unchanged from v1.
>
> Fixes: bbe5ebcbc006 ("hfsplus: canonicalize decomposed catalog names
> like fsck_hfs expects")
> Signed-off-by: Shawn Shao <shawnq1@163.com>
> ---
> Changes in v2:
> - Keep the refill routine in a separate stack frame to reduce stack
> usage.
> - Allocate the full-size KUnit Unicode buffers dynamically.
>
> fs/hfsplus/unicode.c | 19 +++++-------
> fs/hfsplus/unicode_test.c | 73
> +++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 80 insertions(+), 12 deletions(-)
>
> diff --git a/fs/hfsplus/unicode.c b/fs/hfsplus/unicode.c
> index 59b8788a69a9e..840a115609aa0 100644
> --- a/fs/hfsplus/unicode.c
> +++ b/fs/hfsplus/unicode.c
> @@ -577,21 +577,15 @@ int hfsplus_asc2uni(struct super_block *sb,
> EXPORT_SYMBOL_IF_KUNIT(hfsplus_asc2uni);
>
> /*
> - * Maximum length of a single maximal run of nonzero-combining-class
> code
> - * units that hfsplus_decompose_iter_next() below will canonically
> - * reorder. Every code unit with combining class 0 starts a new run,
> so
> - * this only bounds how many *consecutive* combining marks between
> two
> - * base characters get sorted - real text, and even deliberately
> - * adversarial "Zalgo" text, essentially never approaches this.
> Keeping
> - * it small means hfsplus_hash_dentry() and hfsplus_compare_dentry()
> only
> - * ever need a tiny amount of lookahead state, rather than buffering
> an
> - * entire (up to 255-unit) name.
> + * A maximal combining run can contain every code unit in an HFS+
> catalog
> + * name. Keep the iterator limit aligned with the name limit so it
> can
> + * reorder the complete run like hfsplus_decompose_str().
> */
> -#define HFSPLUS_CCC_RUN_MAX 32
> +#define HFSPLUS_CCC_RUN_MAX HFSPLUS_MAX_STRLEN
>
I don't quite follow to the explanation. Why should we change the
constant on HFSPLUS_MAX_STRLEN? Could you please explain it more
clearly and precise?
>
> /*
> * Iterator that produces the canonically-ordered, decomposed code
> units
> - * of a Linux name one at a time, without materializing the whole
> name.
> + * of a Linux name one combining run at a time.
> * hfsplus_hash_dentry() and hfsplus_compare_dentry() use this so
> that
> * hashing and comparison always agree with what hfsplus_asc2uni()
> would
> * actually store, while still comparing lazily (stopping at the
> first
> @@ -630,7 +624,8 @@ static void hfsplus_decompose_iter_init(struct
> hfsplus_decompose_iter *it,
> * we know the class of the first unit it produces, so decoding it
> is
> * speculative until that's decided.
> */
> -static bool hfsplus_decompose_iter_refill(struct
> hfsplus_decompose_iter *it)
> +static noinline_for_stack bool
> +hfsplus_decompose_iter_refill(struct hfsplus_decompose_iter *it)
> {
> it->run_pos = 0;
> it->run_len = 0;
> diff --git a/fs/hfsplus/unicode_test.c b/fs/hfsplus/unicode_test.c
Now the unicode_test.c file is named as hfsplus_unicode_test.c. Please,
based the patch on for-next branch of HFS/HFS+ git tree.
> index a683c6d5fc221..9a50e3fcb7764 100644
> --- a/fs/hfsplus/unicode_test.c
> +++ b/fs/hfsplus/unicode_test.c
> @@ -1479,6 +1479,78 @@ static void
> hfsplus_hash_dentry_combining_reorder_test(struct kunit *test)
> free_mock_sb(mock_sb);
> }
>
> +static void hfsplus_dentry_combining_reorder_long_test(struct kunit
> *test)
Current explanation of the patch gives to me no clue why do we need
this unit-test? Could you please explain it?
Thanks,
Slava.
> +{
> + static const char acute[] = "\xcc\x81";
> + static const char dot_below[] = "\xcc\x96";
> + enum { NR_ACUTE = 32, NAME_LEN = 1 + (NR_ACUTE + 1) * 2 + 1
> };
> + char acute_first[NAME_LEN], dot_first[NAME_LEN];
> + struct hfsplus_unistr *stored1, *stored2;
> + struct test_mock_sb *mock_sb;
> + struct qstr str1, str2;
> + char *p;
> + int i, result;
> +
> + mock_sb = setup_mock_sb();
> + KUNIT_ASSERT_NOT_NULL(test, mock_sb);
> +
> + stored1 = kunit_kzalloc(test, sizeof(*stored1), GFP_KERNEL);
> + KUNIT_ASSERT_NOT_NULL(test, stored1);
> + stored2 = kunit_kzalloc(test, sizeof(*stored2), GFP_KERNEL);
> + KUNIT_ASSERT_NOT_NULL(test, stored2);
> +
> + setup_mock_dentry(&mock_sb->sb);
> + mock_sb->nls.char2uni = test_char2uni_utf8;
> +
> + p = acute_first;
> + *p++ = 'e';
> + for (i = 0; i < NR_ACUTE; i++) {
> + memcpy(p, acute, sizeof(acute) - 1);
> + p += sizeof(acute) - 1;
> + }
> + memcpy(p, dot_below, sizeof(dot_below) - 1);
> + p += sizeof(dot_below) - 1;
> + *p = '\0';
> +
> + p = dot_first;
> + *p++ = 'e';
> + memcpy(p, dot_below, sizeof(dot_below) - 1);
> + p += sizeof(dot_below) - 1;
> + for (i = 0; i < NR_ACUTE; i++) {
> + memcpy(p, acute, sizeof(acute) - 1);
> + p += sizeof(acute) - 1;
> + }
> + *p = '\0';
> +
> + create_qstr(&str1, acute_first);
> + create_qstr(&str2, dot_first);
> + result = hfsplus_hash_dentry(&test_dentry, &str1);
> + KUNIT_ASSERT_EQ(test, 0, result);
> + result = hfsplus_hash_dentry(&test_dentry, &str2);
> + KUNIT_ASSERT_EQ(test, 0, result);
> + KUNIT_EXPECT_EQ(test, str1.hash, str2.hash);
> +
> + KUNIT_EXPECT_EQ(test, 0,
> + hfsplus_compare_dentry(&test_dentry,
> str1.len,
> + str1.name, &str2));
> +
> + result = hfsplus_asc2uni(&mock_sb->sb, stored1,
> HFSPLUS_MAX_STRLEN,
> + str1.name, str1.len,
> HFS_REGULAR_NAME);
> + KUNIT_ASSERT_EQ(test, 0, result);
> + result = hfsplus_asc2uni(&mock_sb->sb, stored2,
> HFSPLUS_MAX_STRLEN,
> + str2.name, str2.len,
> HFS_REGULAR_NAME);
> + KUNIT_ASSERT_EQ(test, 0, result);
> + KUNIT_EXPECT_EQ(test, be16_to_cpu(stored1->length),
> + be16_to_cpu(stored2->length));
> + KUNIT_EXPECT_EQ(test, 34, be16_to_cpu(stored1->length));
> + KUNIT_EXPECT_EQ(test,
> + memcmp(stored1->unicode, stored2->unicode,
> + be16_to_cpu(stored1->length) *
> sizeof(stored1->unicode[0])),
> + 0);
> +
> + free_mock_sb(mock_sb);
> +}
> +
> /* Test hfsplus_compare_dentry basic functionality */
> static void hfsplus_compare_dentry_basic_test(struct kunit *test)
> {
> @@ -1880,6 +1952,7 @@ static struct kunit_case
> hfsplus_unicode_test_cases[] = {
> KUNIT_CASE(hfsplus_hash_dentry_consistency_test),
> KUNIT_CASE(hfsplus_hash_dentry_edge_cases_test),
> KUNIT_CASE(hfsplus_hash_dentry_combining_reorder_test),
> + KUNIT_CASE(hfsplus_dentry_combining_reorder_long_test),
> KUNIT_CASE(hfsplus_compare_dentry_basic_test),
> KUNIT_CASE(hfsplus_compare_dentry_casefold_test),
> KUNIT_CASE(hfsplus_compare_dentry_special_chars_test),
prev parent reply other threads:[~2026-11-30 21:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 16:07 [PATCH] " shaos
2026-11-27 3:52 ` kernel test robot
2026-11-27 17:53 ` Viacheslav Dubeyko
2026-11-30 7:48 ` [PATCH v2] " Shawn Shao
2026-11-30 21:12 ` Viacheslav Dubeyko [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=16d041e4b01dc83a82168696742c731710f4db69.camel@dubeyko.com \
--to=slava@dubeyko.com \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shawnq1@163.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®