Re: [PATCH] mm/zsmalloc: fix release order of locks in zs_page_migrate()

From: Sergey Senozhatsky

Date: Tue Jul 28 2026 - 02:47:42 EST


On (26/07/28 05:53), Richard Chang wrote:
> In zs_page_migrate(), locks are acquired in the following order:
> 1. write_lock(&pool->lock)
> 2. spin_lock(&class->lock)
> 3. zspage_write_trylock(zspage)
>
> However, upon successful page migration, they were being released in
> forward acquisition (FIFO) order:
> 1. write_unlock(&pool->lock)
> 2. spin_unlock(&class->lock)
> 3. zspage_write_unlock(zspage)
>
> Fix the unlocking order to release locks in strict reverse (LIFO)
> order of acquisition:
> 3. zspage_write_unlock(zspage)
> 2. spin_unlock(&class->lock)
> 1. write_unlock(&pool->lock)
>
> Releasing locks in reverse order of acquisition adheres to standard
> kernel locking hygiene, prevents potential lock ordering and lockdep
> inconsistencies.
>
> Signed-off-by: Richard Chang <richardycc@xxxxxxxxxx>

Reviewed-by: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>
Tested-by: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>