Re: [RFC PATCH v4 2/4] zram: support compression at the granularity of multi-pages

From: Nanzhe Zhao

Date: Fri Nov 27 2026 - 03:29:05 EST


> [Severity: High]
> Can concurrent zram_slot_free_notify() calls on sibling sub-slots leak the
> multi-page object?
>
> __test_multi_pages_comp() counts ZRAM_COMP_MULTI_PAGES across the group
> while only holding slot_trylock(zram, index) on the current sub-slot:
> ...
> In addition, when comp_count == 1, clearing ZRAM_COMP_MULTI_PAGES and
> unlocking index before slot_trylock(zram, head) means that if
> slot_trylock(zram, head) fails, the last ZRAM_COMP_MULTI_PAGES flag has
> already been cleared, and another CPU can also reallocate and write to
> head in the unlocked window before slot_trylock(zram, head) runs.

These are valid issues. The locking and lifecycle model for compound slots in
v4 had inconsistent semantics between slot_free() and slot_free_notify(), and
lacked a unified locking boundary across sub-slots. I will redesign the
concurrency model for multi-page slots in the next RFC version.

> [Severity: High]
> Does setting ZRAM_COMP_MULTI_PAGES on index + 1 .. index + nr_pages - 1
> without locking or freeing those tail slots corrupt the slot bit-lock and
> leak existing objects?
>
> zram_write_page(), write_same_filled_page(), and
> write_incompressible_page() only lock and call slot_free() on the head
> slot index:
>
> 1. Because table[index + i].attr.flags aliases table[index + i].__lock,
> the unlocked non-atomic |= in set_slot_flag(zram, index + i, ...) races
> with concurrent slot_lock() / slot_unlock() on tail slots and can
> corrupt ZRAM_ENTRY_LOCK_BIT, hanging waiters in wait_on_bit_lock().
> 2. Any single-page zsmalloc handles already stored in the tail slots are
> never freed before ZRAM_COMP_MULTI_PAGES is set on them, leaking those
> objects.

Same here.

> [Severity: High]
> Can two concurrent partial writes to different sub-slots in the same
> multi-page group overwrite each other?
>
> zram_read_page_size() unlocks slot_lock(zram, index) after reading the
> multi-page into the temporary page, and zram_write_page() only re-acquires
> slot_lock(zram, index) after compressing the updated buffer. If two CPUs
> concurrently perform partial writes to different offsets of the same head
> index, both read the old multi-page before either writes back, so the
> second writer overwrites the first writer's sub-page with stale data.

Same here.