From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796245431; b=PrONwqruPRftV0MNXhcKmrIa1x0LhsMAielDzkVLj7UInP9sRZ9mrdn0jvhCMgZwYnqz X4O7hQokZ8H+NOvGzsamCUMFUMZ1KRqqRhEibkwHR5IyJ7yeEc85jnMDlfBfRZqxIjKWk YdeD1OSfmluFPTADE8DEDisyAuZUS5Jj+ZKfB53MEOKyRPtQaBFbc3rQeM1p8ahOHci0b GbbmZLNmfnvULheEgmlB8otBasAuQCCiwPuWVG80u8ToNq90znDO7suYrlv7bUHjfnqW+ /Vi9br4OFrY9/DSZSQ9k4pkHZcA+qglkVAbhtD+8phDnMxh9Dq0n/KEuZibV2JZclAA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796245431; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References:Autocrypt: Content-Type:Content-Transfer-Encoding:User-Agent:MIME-Version; bh=fWK6uNqa507Ct5rTwP8J5U7Gz4WbOriYF1bCSn+42TY=; b=CxS1OVWOZwEVsn6YyxQjgVzPONcoBkvFR3DWFYC8m7vgJSv8Dxe5KkePBMMKwR1Sefmq 5PVcZ1UA+M1N9nZ/K5bOHbbp2BhdfcWujaDLFMumSKJGIgUcuirfgEqAWCmRYCGfId3Ho oWXaN4hNJ/mVJ/ehSWD4hfK5ScCNTmA4YrMycMU4DTkJDierMike+DPWtKa4Hi2XkGjPu vA2pOvMQRWSN198ufS1BMt6lfp0v8Tlp8T5mxflNsE6lev6eCj7NIKD+7nvDfqMqDhS/+ M+UoU/qDPOS/BvFrYxPIe6XvinVBatye+EWLugOth+jpE6IjnMHQXG/W+NsEq+JJ3Og== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=dubeyko.com; spf=pass smtp.mailfrom=dubeyko.com; dkim=pass header.d=dubeyko-com.20260707.gappssmtp.com header.i=@dubeyko-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=moqm8tKe; arc=none smtp.remote-ip=209.85.128.169 Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9143606A32C for ; Wed, 2 Dec 2026 21:03:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C9143606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dubeyko.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dubeyko.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dubeyko-com.20260707.gappssmtp.com header.i=@dubeyko-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=moqm8tKe Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-8b502b9b702so164189207b3.3 for ; Wed, 02 Dec 2026 13:03:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dubeyko-com.20260707.gappssmtp.com; s=20260707; t=1796245430; x=1796850230; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:content-type :autocrypt:references:in-reply-to:date:cc:to:from:subject:message-id :from:to:cc:subject:date:message-id:reply-to:content-type; bh=fWK6uNqa507Ct5rTwP8J5U7Gz4WbOriYF1bCSn+42TY=; b=moqm8tKe4AFU5Os9Z/ixJRbyh7dIAkdU0LHEpuXqZOyLIUu/LGp914BPbrCYQA5MWA i/v6KJa4FXjJicuAJWAPrnbo8e2lzHXPWxRBje2Hp61xOj5SkXkPZuJigQ/IdRaYAIFM 327HBNJQ2Uk9NTPzFilIHrSJPrJ2ngTrKsiYxzzWkWnxUZu4INTbY2z0F+7HNh2x+oOX LzJnhFSTPuUFQE8nWNy+i6hNMqy1MkW69yPg4AtsXBRAuhJAE8btS6Y5fEH/etNbT58k Nz4t7NS+sDBVxsQCGjYCaWgNrFu+E1eBcD/IBekD0Qn5h9DG1DzolsnJKbYHpV2qSe9k ix0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796245430; x=1796850230; h=mime-version:user-agent:content-transfer-encoding:content-type :autocrypt:references:in-reply-to:date:cc:to:from:subject:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=fWK6uNqa507Ct5rTwP8J5U7Gz4WbOriYF1bCSn+42TY=; b=IDK7Q+UW0rQlDEJZAeXj/zrclIvbZiluhedXDWCbuDeRrtclvMquZSW6COPsq1V0j3 BgVkxoK8AExpv1GK54TzvCMERezokSXaT6PjFkdh4nBjNsGBvEX1gJr/bq5Kx/eK/GU1 dcqbpXD1bIeCknE0ZoBvdMpaIzkZ1AyZkheTatsaoPXlt2TxIoB5tJ3d+RyXtQrvXEKZ Giq2OcTf/4pOBpiexjxWck5+3kp9+Xz2BYXkIEof4/5DE2GuP2sNkrJ/b7e2tNNgmySc tI8vKBRKPcYkElpBTugtDDCnjlTN37WdmII2z03C0TxQlOYjdACLb0w6qyS+BVwEDYdN z4EQ== X-Forwarded-Encrypted: i=1; AL+hErFtZ1TrFt/hmOHo6a0jSud7anvKkSDCqF8TCJkId03sRcafYyScv57bhOV2M+5XeBsqFioPIm2BW87LeXI=@vger.kernel.org X-Gm-Message-State: APuU4Z/ovExs8zwAZ6s8Kzx11C3ki52IES63YM8eYCU8EgcVLE4d0/hu W5Rss/bymeYlUVqrT2ehpd3KVVfefm/3aMycePNeZ3NpPvpWnqcJu6ahj0h6H8MRvf0= X-Gm-Gg: AZFdTZd9tf1P2VVO2a53YsFc+mYENSeSzv+gQuv4Si2ToQvscaTh7vii2KgrsNYtpSS 2ySfzlkOBLCcQjCxey2e3nlLS63UUc91wsDIKPFttrcd1j/xKMcVJt8Z0+Qv8aH51V2VK+lb984 ynI7KrbKEDA4Y73f9GICgvGYYDUuObwIsPM38pIAkike3CVv9l2EBJS2iTjRsII55tTZKSg7aPN Yfy69qGgGj6bstwAIvA/f6vqq3eYfGZCemxH9PepACdvuhuP86B2acnFHhYURyCAyWNBZbNlKTF vni09l6+iFtvO9U4FVLJm8iMLOS6vvb3mFImJbxGgGD9Akun5uUYoxgXsGahbPrIq3R59oCV5ej 7/ZqCV6ZS6oSO1WJua2jRLgptEq794FtJCHkBkLUsAGdWy0IZXN5YTSWAIaIUuFV/k9V8KL9kMF aU3pp/xM+1IqRE/JuoZsgGGma2L59eK7Rzak9eMKO5g+wPjLrjvWViBncdShihr8nqZpkJq2xu9 iLt7YL6gjSTeT+y+t5XjUX8D7+jo1GflbOtPeiOg6QLlYcYJGswJdWJZSHzmA3sNGf4GQrdavKU 4jt7DfNYzrHx0g5r0a7aPTnr+WJZfcAmKjo2IWkazC8No4jj2KbO+IgyY2Kfb0bfsvdTI8Z9jvv X76CUx0gJEi7WDbv202H4C7GT/TD7PxQwy7MnSYUXIZlXDJ+pZaCHdF+Sn/CZMfByoIG4jP/EU4 zHG4Rf11ZeYZshZ0b2 X-Received: by 2002:a05:690c:45c2:b0:8b3:3854:c28d with SMTP id 00721157ae682-8b52042b835mr128782567b3.17.1796245429481; Wed, 02 Dec 2026 13:03:49 -0800 (PST) Received: from ?IPv6:2600:1700:6476:1430:f726:86c4:c7ef:c27? ([2600:1700:6476:1430:f726:86c4:c7ef:c27]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8b5202dd36dsm161078087b3.26.2026.12.02.13.03.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 13:03:48 -0800 (PST) Message-ID: <86f82b7f539efa87531acff002a83efe7936f1c1.camel@dubeyko.com> Subject: Re: [PATCH v4] hfsplus: reorder complete combining runs for dentry keys From: Viacheslav Dubeyko To: Shawn Shao Cc: John Paul Adrian Glaubitz , Yangtao Li , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 02 Dec 2026 13:03:47 -0800 In-Reply-To: <20261202075614.272772-1-shawnq1@163.com> References: <20261126160720.3007837-1-shawnq1@163.com> <20261130074816.2537284-1-shawnq1@163.com> <16d041e4b01dc83a82168696742c731710f4db69.camel@dubeyko.com> <4d40982a598dff9bc50fccbaee34a313fb896fb0.camel@dubeyko.com> <20261202075614.272772-1-shawnq1@163.com> Autocrypt: addr=slava@dubeyko.com; prefer-encrypt=mutual; keydata=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 NFdvziOa4FgUBC4X71upsZIoZJeii2V/Jtc3B4g== Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2-9 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 On Wed, 2026-12-02 at 07:56 +0000, Shawn Shao wrote: > Dentry hashing and comparison reorder decomposed names in fixed-size > chunks. When a combining run exceeds the chunk size, marks with lower > combining classes in a later chunk cannot move ahead of earlier > marks. > The resulting dentry key can differ from the full canonical key > produced > by hfsplus_asc2uni(). >=20 > Keep the 32-unit buffer for the common case. For longer runs, > remember the > combining classes present and rescan the run in ascending class > order. This > preserves source order for marks of equal class without allocating > memory > or growing the iterator state with the run length. Apply the HFS+ > legacy > sequence fixups to the streamed key so hashing and comparison agree > with > catalog conversion. >=20 > Add a regression test with a combining run longer than the fast path. >=20 > Fixes: bbe5ebcbc006 ("hfsplus: canonicalize decomposed catalog names > like fsck_hfs expects") > Signed-off-by: Shawn Shao >=20 > --- > Changes in v4: > - Keep a 32-unit fast path and rescan longer runs by combining class > using > =C2=A0 fixed-size state. > - Apply HFS+ legacy sequence corrections while streaming dentry keys. > - Test equal hash, comparison, and stored catalog key for a 33-mark > run. >=20 > Testing: > - x86-64 disassembly shows hfsplus_compare_dentry reserves 456 bytes > for > =C2=A0 its stack frame. The bzImage build passed with CONFIG_HFSPLUS_FS= =3Dy, > =C2=A0 CONFIG_FRAME_WARN=3D1280, and KCFLAGS=3D-Wframe-larger-than=3D1280= ; no > frame > =C2=A0 size warning was emitted. > - hfsplus_unicode KUnit suite: 36 tests passed. > - Fixed-kernel QEMU test: the alternate 33-mark spelling resolved > before > =C2=A0 remount; the controls passed (POC_EXIT=3D0). > - git apply --check, git diff --check, and checkpatch --strict > passed. >=20 > Reproducer, configuration, KUnit output, and console log: > https://gist.github.com/shaos26/73b61181ce48283492d2a10f69bb11eb >=20 > =C2=A0fs/hfsplus/hfsplus_unicode_test.c |=C2=A0 83 ++++++++++++ > =C2=A0fs/hfsplus/tables.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 70 +++++------ > =C2=A0fs/hfsplus/unicode.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 258 > ++++++++++++++++++++++++++++---------- > =C2=A0fs/hfsplus/unicode.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 1 + > =C2=A04 files changed, 311 insertions(+), 101 deletions(-) >=20 > diff --git a/fs/hfsplus/hfsplus_unicode_test.c > b/fs/hfsplus/hfsplus_unicode_test.c > index cb237a40c0c3e..e8f066447e89f 100644 > --- a/fs/hfsplus/hfsplus_unicode_test.c > +++ b/fs/hfsplus/hfsplus_unicode_test.c > @@ -1533,6 +1533,88 @@ static void > hfsplus_hash_dentry_combining_reorder_test(struct kunit *test) > =C2=A0 free_mock_sb(mock_sb); > =C2=A0} > =C2=A0 > +static void hfsplus_dentry_combining_reorder_long_test(struct kunit > *test) > +{ > + static const char acute[] =3D "\xcc\x81"; > + static const char dot_below[] =3D "\xcc\x96"; > + enum { NR_ACUTE =3D 32, NAME_LEN =3D 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 =3D setup_mock_sb(); > + KUNIT_ASSERT_NOT_NULL(test, mock_sb); > + > + stored1 =3D kunit_kzalloc(test, sizeof(*stored1), GFP_KERNEL); > + KUNIT_ASSERT_NOT_NULL(test, stored1); > + stored2 =3D kunit_kzalloc(test, sizeof(*stored2), GFP_KERNEL); > + KUNIT_ASSERT_NOT_NULL(test, stored2); > + > + setup_mock_dentry(&mock_sb->sb); > + mock_sb->nls.char2uni =3D test_char2uni_utf8; > + > + p =3D acute_first; > + *p++ =3D 'e'; > + for (i =3D 0; i < NR_ACUTE; i++) { > + memcpy(p, acute, sizeof(acute) - 1); > + p +=3D sizeof(acute) - 1; > + } > + memcpy(p, dot_below, sizeof(dot_below) - 1); > + p +=3D sizeof(dot_below) - 1; > + *p =3D '\0'; > + > + p =3D dot_first; > + *p++ =3D 'e'; > + memcpy(p, dot_below, sizeof(dot_below) - 1); > + p +=3D sizeof(dot_below) - 1; > + for (i =3D 0; i < NR_ACUTE; i++) { > + memcpy(p, acute, sizeof(acute) - 1); > + p +=3D sizeof(acute) - 1; > + } > + *p =3D '\0'; > + > + create_qstr(&str1, acute_first); > + create_qstr(&str2, dot_first); > + result =3D hfsplus_hash_dentry(&test_dentry, &str1); > + KUNIT_ASSERT_EQ(test, 0, result); > + result =3D hfsplus_hash_dentry(&test_dentry, &str2); > + KUNIT_ASSERT_EQ(test, 0, result); > + KUNIT_EXPECT_EQ(test, str1.hash, str2.hash); > + KUNIT_EXPECT_EQ(test, > + hfsplus_compare_dentry(&test_dentry, > str1.len, > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 str1.name, &str2), > 0); > + > + result =3D hfsplus_asc2uni(&mock_sb->sb, stored1, > HFSPLUS_MAX_STRLEN, > + str1.name, str1.len, > HFS_REGULAR_NAME); > + KUNIT_ASSERT_EQ(test, 0, result); > + result =3D 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, > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 be16_to_cpu(stored1->length) * > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 sizeof(stored1->unicode[0])), 0)= ; > + > + create_qstr(&str1, "e\xcc\x86\xcc\x87"); > + create_qstr(&str2, "e\xcc\x90"); > + result =3D hfsplus_hash_dentry(&test_dentry, &str1); > + KUNIT_ASSERT_EQ(test, 0, result); > + result =3D hfsplus_hash_dentry(&test_dentry, &str2); > + KUNIT_ASSERT_EQ(test, 0, result); > + KUNIT_EXPECT_EQ(test, str1.hash, str2.hash); > + KUNIT_EXPECT_EQ(test, > + hfsplus_compare_dentry(&test_dentry, > str1.len, > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 str1.name, &str2), > 0); > + > + free_mock_sb(mock_sb); > +} > + > =C2=A0/* Test hfsplus_compare_dentry basic functionality */ > =C2=A0static void hfsplus_compare_dentry_basic_test(struct kunit *test) > =C2=A0{ > @@ -1935,6 +2017,7 @@ static struct kunit_case > hfsplus_unicode_test_cases[] =3D { > =C2=A0 KUNIT_CASE(hfsplus_hash_dentry_consistency_test), > =C2=A0 KUNIT_CASE(hfsplus_hash_dentry_edge_cases_test), > =C2=A0 KUNIT_CASE(hfsplus_hash_dentry_combining_reorder_test), > + KUNIT_CASE(hfsplus_dentry_combining_reorder_long_test), > =C2=A0 KUNIT_CASE(hfsplus_compare_dentry_basic_test), > =C2=A0 KUNIT_CASE(hfsplus_compare_dentry_casefold_test), > =C2=A0 KUNIT_CASE(hfsplus_compare_dentry_special_chars_test), > diff --git a/fs/hfsplus/tables.c b/fs/hfsplus/tables.c > index 2101201ab973f..022b655f9ccf1 100644 > --- a/fs/hfsplus/tables.c > +++ b/fs/hfsplus/tables.c > @@ -3693,50 +3693,50 @@ const u16 *hfsplus_legacy_decompose(u16 uc, > int *size) > =C2=A0 return NULL; > =C2=A0} > =C2=A0 > +/* Apply one legacy correction at the start of a decomposed > sequence. */ > +bool hfsplus_fixup_legacy_sequence(u16 *buf, int *len) > +{ > + unsigned int j; > + > + for (j =3D 0; j < ARRAY_SIZE(hfsplus_legacy_seq_fixups); j++) > { > + struct hfsplus_legacy_seq_fixup *f =3D > + &hfsplus_legacy_seq_fixups[j > ]; > + size_t copy_len; > + int k; > + > + if (f->match_len > *len) > + continue; > + for (k =3D 0; k < f->match_len; k++) > + if (buf[k] !=3D f->match[k]) > + break; > + if (k !=3D f->match_len) > + continue; > + > + copy_len =3D (*len - f->match_len) * sizeof(*buf); > + memmove(buf + f->repl_len, buf + f->match_len, > copy_len); > + memcpy(buf, f->repl, f->repl_len * sizeof(*buf)); > + *len +=3D f->repl_len - f->match_len; > + return true; > + } > + > + return false; > +} > + > =C2=A0/* > =C2=A0 * Scan an already decomposed and canonically-reordered code unit > buffer > - * for any of the short legacy sequences above and replace them in > place > - * with their corrected form. @len is updated to the buffer's new > length. > + * for corrected legacy sequences. @len is updated to the buffer's > new > + * length. > =C2=A0 */ > =C2=A0void hfsplus_fixup_legacy_sequences(u16 *buf, int *len) > =C2=A0{ > =C2=A0 int i =3D 0; > =C2=A0 > =C2=A0 while (i < *len) { > - unsigned int j; > - bool matched =3D false; > + int remaining =3D *len - i; > =C2=A0 > - for (j =3D 0; j < > ARRAY_SIZE(hfsplus_legacy_seq_fixups); j++) { > - struct hfsplus_legacy_seq_fixup *f =3D > - > &hfsplus_legacy_seq_fixups[j]; > - u16 *src, *dst; > - size_t copy_len; > - int k; > - > - if (i + f->match_len > *len) > - continue; > - for (k =3D 0; k < f->match_len; k++) > - if (buf[i + k] !=3D f->match[k]) > - break; > - if (k !=3D f->match_len) > - continue; > - > - dst =3D &buf[i + f->repl_len]; > - src =3D &buf[i + f->match_len]; > - copy_len =3D (*len - i - f->match_len) * > sizeof(*buf); > - memmove(dst, src, copy_len); > - > - dst =3D &buf[i]; > - src =3D f->repl; > - copy_len =3D f->repl_len * sizeof(*buf); > - memcpy(dst, src, copy_len); > - > - *len +=3D f->repl_len - f->match_len; > - matched =3D true; > - break; > - } > - > - if (!matched) > + if (hfsplus_fixup_legacy_sequence(buf + i, > &remaining)) > + *len =3D i + remaining; > + else > =C2=A0 i++; > =C2=A0 } > =C2=A0} > diff --git a/fs/hfsplus/unicode.c b/fs/hfsplus/unicode.c > index 59b8788a69a9e..740107f799bad 100644 > --- a/fs/hfsplus/unicode.c > +++ b/fs/hfsplus/unicode.c > @@ -576,37 +576,47 @@ int hfsplus_asc2uni(struct super_block *sb, > =C2=A0} > =C2=A0EXPORT_SYMBOL_IF_KUNIT(hfsplus_asc2uni); > =C2=A0 > -/* > - * 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. > - */ > -#define HFSPLUS_CCC_RUN_MAX 32 > +#define HFSPLUS_HANGUL_MAX_JAMO (3) /* L + V + > optional T */ > +#define HFSPLUS_CCC_RUN_MAX (32) /* fast-path run > size */ > + > +static_assert(HFSPLUS_HANGUL_MAX_JAMO >=3D > HFSPLUS_LEGACY_DECOMP_MAX_LEN, > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "decomposition buffer must fit the longe= st legacy > sequence"); > + > +/* State for reading decomposed UTF-16 code units from an input > name. */ > +struct hfsplus_decompose_state { > + const char *astr; > + int len; > + u16 units[HFSPLUS_HANGUL_MAX_JAMO]; > + u8 unit_pos; > + u8 unit_len; > +}; > =C2=A0 > =C2=A0/* > - * Iterator that produces the canonically-ordered, decomposed code > units > - * of a Linux name one at a time, without materializing the whole > name. > - * 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 > - * difference) the way this code did before canonical reordering > existed. > + * The dentry iterator keeps short runs in a fixed-size fast path > and > + * rescans longer runs by combining class. Its storage does not grow > with > + * the input run. > =C2=A0 */ > =C2=A0struct hfsplus_decompose_iter { > =C2=A0 struct super_block *sb; > - const char *astr; > - int len; > =C2=A0 int name_type; > =C2=A0 int decompose; > =C2=A0 > - u16 run[HFSPLUS_CCC_RUN_MAX]; > - int run_len; > - int run_pos; > + struct hfsplus_decompose_state raw; > + struct hfsplus_decompose_state run_start; > + struct hfsplus_decompose_state scan; > + u16 fast_run[HFSPLUS_CCC_RUN_MAX]; > + u8 classes[U8_MAX / 8 + 1]; > + unsigned int fast_len; > + unsigned int fast_pos; > + unsigned int run_len; > + unsigned int run_left; > + unsigned int run_class; > + bool fast_active; > + bool run_active; > + > + u16 fixup[HFSPLUS_LEGACY_SEQ_MAX_MATCH]; > + int fixup_len; > + bool raw_done; > =C2=A0}; > =C2=A0 > =C2=A0static void hfsplus_decompose_iter_init(struct > hfsplus_decompose_iter *it, > @@ -615,68 +625,184 @@ static void hfsplus_decompose_iter_init(struct > hfsplus_decompose_iter *it, > =C2=A0 int name_type) > =C2=A0{ > =C2=A0 it->sb =3D sb; > - it->astr =3D astr; > - it->len =3D len; > =C2=A0 it->name_type =3D name_type; > =C2=A0 it->decompose =3D !test_bit(HFSPLUS_SB_NODECOMPOSE, > &HFSPLUS_SB(sb)->flags); > + it->raw.astr =3D astr; > + it->raw.len =3D len; > + memset(it->raw.units, 0, sizeof(it->raw.units)); > + it->raw.unit_pos =3D 0; > + it->raw.unit_len =3D 0; > + it->fast_len =3D 0; > + it->fast_pos =3D 0; > =C2=A0 it->run_len =3D 0; > - it->run_pos =3D 0; > + it->run_left =3D 0; > + it->run_class =3D 0; > + it->fast_active =3D false; > + it->run_active =3D false; > + it->fixup_len =3D 0; > + it->raw_done =3D false; > =C2=A0} > =C2=A0 > -/* > - * Gather the next maximal run of nonzero-combining-class code units > - * (starting with whatever character comes next, base or not) and > - * canonically reorder just that run. A character is only included > once > - * 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 int hfsplus_decompose_iter_raw_next(struct > hfsplus_decompose_iter *it, > + =C2=A0=C2=A0 struct > hfsplus_decompose_state *state) > =C2=A0{ > - it->run_pos =3D 0; > - it->run_len =3D 0; > + u16 dhangul[HFSPLUS_HANGUL_MAX_JAMO]; > + const u16 *dstr; > + int dsize, size; > + wchar_t c; > + > + if (state->unit_pos < state->unit_len) > + return state->units[state->unit_pos++]; > + if (!state->len) > + return -1; > =C2=A0 > - while (it->len > 0) { > - u16 *dstr; > - u16 dhangul[HFSPLUS_HANGUL_MAX_JAMO]; > - int dsize, size; > - wchar_t c; > + size =3D asc2unichar(it->sb, state->astr, state->len, &c, > + =C2=A0=C2=A0 it->name_type); > + dstr =3D it->decompose ? decompose_unichar(c, &dsize, dhangul) > : NULL; > + if (!dstr) { > + dhangul[0] =3D c; > + dstr =3D dhangul; > + dsize =3D 1; > + } > =C2=A0 > - size =3D asc2unichar(it->sb, it->astr, it->len, &c, > - =C2=A0=C2=A0 it->name_type); > + memcpy(state->units, dstr, dsize * sizeof(*dstr)); > + state->unit_len =3D dsize; > + state->unit_pos =3D 1; > + state->astr +=3D size; > + state->len -=3D size; > + return state->units[0]; > +} > + > +static void hfsplus_decompose_iter_set_class(struct > hfsplus_decompose_iter *it, > + =C2=A0=C2=A0=C2=A0=C2=A0 u8 cls) > +{ > + it->classes[cls / 8] |=3D 1U << (cls % 8); > +} > + > +static bool hfsplus_decompose_iter_has_class(struct > hfsplus_decompose_iter *it, > + =C2=A0=C2=A0=C2=A0=C2=A0 unsigned int cls) > +{ > + return it->classes[cls / 8] & (1U << (cls % 8)); > +} > =C2=A0 > - dstr =3D it->decompose ? > - decompose_unichar(c, &dsize, dhangul) : > NULL; > - if (!dstr) { > - dhangul[0] =3D c; > - dstr =3D dhangul; > - dsize =3D 1; > +/* Return the next canonically ordered code unit without buffering a > run. */ > +static int hfsplus_decompose_iter_next_reordered(struct > hfsplus_decompose_iter *it) > +{ > + while (1) { > + if (it->fast_active) { > + if (it->fast_pos < it->fast_len) > + return it->fast_run[it->fast_pos++]; > + it->fast_active =3D false; > =C2=A0 } > =C2=A0 > - if (it->run_len > 0 && > !hfsplus_combining_class(dstr[0])) > - break; > + if (it->run_active) { > + while (it->run_left) { > + int c =3D > hfsplus_decompose_iter_raw_next(it, &it->scan); > =C2=A0 > - if (it->run_len + dsize > HFSPLUS_CCC_RUN_MAX) > - break; > + if (c < 0) { > + it->run_active =3D false; > + return -1; > + } > + it->run_left--; > + if (hfsplus_combining_class(c) =3D=3D > it->run_class) > + return c; > + } > =C2=A0 > - it->astr +=3D size; > - it->len -=3D size; > + while (++it->run_class <=3D U8_MAX) { > + if > (hfsplus_decompose_iter_has_class(it, > + =C2=A0=C2=A0=C2=A0=C2=A0 > it->run_class)) { > + it->scan =3D it->run_start; > + it->run_left =3D it->run_len; > + break; > + } > + } > + if (it->run_class <=3D U8_MAX) > + continue; > + it->run_active =3D false; > + } > =C2=A0 > - do { > - it->run[it->run_len++] =3D *dstr++; > - } while (--dsize > 0); > - } > + { > + struct hfsplus_decompose_state scan; > + int c; > + u8 cls; > + bool overflow =3D false; > + > + it->run_start =3D it->raw; > + c =3D hfsplus_decompose_iter_raw_next(it, &it- > >raw); > + if (c < 0) > + return -1; > + cls =3D hfsplus_combining_class(c); > + if (!cls) > + return c; > + > + memset(it->classes, 0, sizeof(it->classes)); > + it->fast_len =3D 1; > + it->fast_run[0] =3D c; > + it->run_len =3D 1; > + hfsplus_decompose_iter_set_class(it, cls); > + scan =3D it->raw; > + while (1) { > + struct hfsplus_decompose_state next > =3D scan; > + > + c =3D > hfsplus_decompose_iter_raw_next(it, &next); > + if (c < 0 || > !hfsplus_combining_class(c)) > + break; > + scan =3D next; > + it->raw =3D next; > + if (it->fast_len < > HFSPLUS_CCC_RUN_MAX) > + it->fast_run[it->fast_len++] > =3D c; > + else > + overflow =3D true; > + it->run_len++; > + hfsplus_decompose_iter_set_class(it, > + =09 > hfsplus_combining_class(c)); > + } > + > + if (!overflow) { > + hfsplus_canonical_reorder(it- > >fast_run, > + =C2=A0 it- > >fast_len); > + it->fast_pos =3D 0; > + it->fast_active =3D true; > + continue; > + } > =C2=A0 > - hfsplus_canonical_reorder(it->run, it->run_len); > - hfsplus_fixup_legacy_sequences(it->run, &it->run_len); > - return it->run_len > 0; > + it->run_class =3D 0; > + it->scan =3D it->run_start; > + it->run_left =3D it->run_len; > + it->run_active =3D true; > + } > + } > =C2=A0} > =C2=A0 > -/* Returns the next code unit, or a negative value once @it is > exhausted. */ > +/* Apply legacy replacements with a three-code-unit lookahead. */ > =C2=A0static int hfsplus_decompose_iter_next(struct hfsplus_decompose_ite= r > *it) > =C2=A0{ > - if (it->run_pos >=3D it->run_len && > !hfsplus_decompose_iter_refill(it)) > - return -1; > - return it->run[it->run_pos++]; > + while (1) { > + while (it->fixup_len < HFSPLUS_LEGACY_SEQ_MAX_MATCH > && > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 !it->raw_done) { > + int c =3D > hfsplus_decompose_iter_next_reordered(it); > + > + if (c < 0) > + it->raw_done =3D true; > + else > + it->fixup[it->fixup_len++] =3D c; > + } > + > + if (!it->fixup_len) > + return -1; > + > + if (hfsplus_fixup_legacy_sequence(it->fixup, &it- > >fixup_len)) > + continue; > + > + { > + int c =3D it->fixup[0]; > + > + it->fixup_len--; > + memmove(it->fixup, it->fixup + 1, > + it->fixup_len * sizeof(*it->fixup)); > + return c; > + } > + } > =C2=A0} > =C2=A0 > =C2=A0/* > diff --git a/fs/hfsplus/unicode.h b/fs/hfsplus/unicode.h > index 31cc7691c9162..db16e1d5dd1bb 100644 > --- a/fs/hfsplus/unicode.h > +++ b/fs/hfsplus/unicode.h > @@ -58,6 +58,7 @@ extern struct hfsplus_legacy_seq_fixup > hfsplus_legacy_seq_fixups[]; > =C2=A0 > =C2=A0u8 hfsplus_combining_class(u16 c); > =C2=A0const u16 *hfsplus_legacy_decompose(u16 uc, int *size); > +bool hfsplus_fixup_legacy_sequence(u16 *buf, int *len); > =C2=A0void hfsplus_fixup_legacy_sequences(u16 *buf, int *len); > =C2=A0 > =C2=A0#endif /* _LINUX_HFSPLUS_UNICODE_H */ Sorry, I am going to reject your patch. Because, you cannot write and test all this code alone for several hours. I can ask my Claude AI agent to fix all of these issues. Why do I need your patches then? Don't get me wrong. I am not against of using AI to help us to fix bugs, to learn and to be more productive. But kernel work is not about asking AI to generate something without any understanding of this. Thanks, Slava.