Skip to contentSkip to conversation

mm/memory-failure: fix refcount leak on soft-offline LBS folio

PATCH 李佑鸿 1 participant 1 message Aug 4 Memory management

lore
Share & tools
lore

李佑鸿

author
#0 lore raw

Hi Andrew,
Thanks for your review.

Quoted 10 lines · Andrew Morton
Quoted 7 lines · On Mon, 3 Aug 2026 14:00:01 +0800 [email protected] wrote:

From: liyouhong <[email protected]>

soft_offline_in_use_page() runs with a folio reference taken by get_hwpoison_page() (or by the caller when MF_COUNT_INCREASED is set, e.g. madvise(MADV_SOFT_OFFLINE)).

made soft-offline skip splitting when min_order_for_split()

Quoted 9 lines

Something went wrong with this paragraph?

Quoted 2 lines

is non-zero, so large-block-size folios stay intact. That early return -EBUSY path never drops the reference.

So the effect is to leak a folio ref if min_order_for_split() returns
0. Has this been known to happen in the real world?

The leak is identified via code inspection. We haven't reproduced it under real workloads yet, but the code path clearly misses folio_put() on this early return path and creates a reference leak risk.

Quoted 4 lines

It would be good to update soft_offline_in_use_page()'s introductory comment to describe its folio refcount handling.

Will add detailed refcount handling comments in v2.

Quoted 9 lines

Thanks, lgtm.

AI review might have found a couple of pre-existing issues in the surrounding code. From a quick read, it doesn't seem appropriate to address either within the context of this change.

	https://sashiko.dev/#/patchset/[email protected]

I agree. Those separate pre-existing problems are not touched here.
I will send an independent patch later to fix the TOCTOU race of folio->mapping in min_order_for_split().

I will send out v2 soon.

Thanks,
liyouhong