[PATCH v6 0/2] ext4: add hash Kunit tests and optimize str2hashbuf

Guan-Chun Wu posted 2 patches 1 week ago
fs/ext4/Makefile    |   2 +-
fs/ext4/hash-test.c | 567 ++++++++++++++++++++++++++++++++++++++++++++
fs/ext4/hash.c      |  68 ++++--
3 files changed, 614 insertions(+), 23 deletions(-)
create mode 100644 fs/ext4/hash-test.c
[PATCH v6 0/2] ext4: add hash Kunit tests and optimize str2hashbuf
Posted by Guan-Chun Wu 1 week ago
This series adds Kunit tests for fs/ext4/hash.c and refactors
the str2hashbuf_{signed,unsigned}() helpers.

Patch 1 adds test coverage for ext4fs_dirhash(), including the main
hash variants and relevant edge cases.

Patch 2 simplifies the str2hashbuf helper implementation by processing
input in 4-byte chunks and removing function-pointer dispatch. This also
reduces overhead and shows roughly 2x improvement on longer inputs in
local testing.

Thanks,
Guan-Chun Wu

Link: https://lore.kernel.org/lkml/20260530155817.2311587-1-409411716@gms.tku.edu.tw/

---

v5 -> v6 :

  - Fix a modpost undefined symbol error for ext4_cryptops
    when building ext4-test.ko.

v4 -> v5 :

  - Fix NULL pointer dereference and out-of-bounds read in SipHash tests.
  - Use IS_ERR() instead of NULL check for utf8_load() error handling.
  - Fix unicode_map memory leaks on assertion failures via kunit_add_action_or_reset().
  - Avoid a UBSAN shift warning in str2hashbuf by casting signed char values
    to __u32 before left-shifting them.

v3 -> v4 :

  - Fix a modpost undefined symbol error for ext4fs_dirhash when building
    ext4-test.ko.

v2 -> v3 :

  - Added Kunit tests for fs/ext4/hash.c.

v1 -> v2:

  - Drop redundant (int) casts.
  - Replace indirect calls with simple conditionals.
  - Use get_unaligned_be32() instead of manual byte extraction.

---

Guan-Chun Wu (2):
  ext4: add Kunit coverage for directory hash computation
  ext4: improve str2hashbuf by processing 4-byte chunks and removing
    function pointers

 fs/ext4/Makefile    |   2 +-
 fs/ext4/hash-test.c | 567 ++++++++++++++++++++++++++++++++++++++++++++
 fs/ext4/hash.c      |  68 ++++--
 3 files changed, 614 insertions(+), 23 deletions(-)
 create mode 100644 fs/ext4/hash-test.c

-- 
2.34.1
Re: [PATCH v6 0/2] ext4: add hash Kunit tests and optimize str2hashbuf
Posted by Theodore Ts'o 3 days, 16 hours ago
On Sun, 31 May 2026 16:00:17 +0800, Guan-Chun Wu wrote:
> This series adds Kunit tests for fs/ext4/hash.c and refactors
> the str2hashbuf_{signed,unsigned}() helpers.
> 
> Patch 1 adds test coverage for ext4fs_dirhash(), including the main
> hash variants and relevant edge cases.
> 
> Patch 2 simplifies the str2hashbuf helper implementation by processing
> input in 4-byte chunks and removing function-pointer dispatch. This also
> reduces overhead and shows roughly 2x improvement on longer inputs in
> local testing.
> 
> [...]

Applied, thanks!

[1/2] ext4: add Kunit coverage for directory hash computation
      commit: 3147cac6c1929f26b4687993b8c7af5b7b34496d
[2/2] ext4: improve str2hashbuf by processing 4-byte chunks and removing function pointers
      commit: 3ca1d19c1971ac4f25478eafb741e726bf2d5954

Best regards,
-- 
Theodore Ts'o <tytso@mit.edu>