* [PATCH] mm/zsmalloc: fix release order of locks in zs_page_migrate()
@ 2026-07-28 5:53 Richard Chang
2026-07-28 6:39 ` Sergey Senozhatsky
0 siblings, 1 reply; 2+ messages in thread
From: Richard Chang @ 2026-07-28 5:53 UTC (permalink / raw)
To: Minchan Kim, Sergey Senozhatsky, Andrew Morton
Cc: Martin Liu, linux-mm, linux-kernel, Richard Chang
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@google.com>
---
mm/zsmalloc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 83f5820c45f9..b09299115886 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -1772,9 +1772,9 @@ static int zs_page_migrate(struct page *newpage, struct page *page,
* Since we complete the data copy and set up new zspage structure,
* it's okay to release migration_lock.
*/
- write_unlock(&pool->lock);
- spin_unlock(&class->lock);
zspage_write_unlock(zspage);
+ spin_unlock(&class->lock);
+ write_unlock(&pool->lock);
zpdesc_get(newzpdesc);
if (zpdesc_zone(newzpdesc) != zpdesc_zone(zpdesc)) {
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] mm/zsmalloc: fix release order of locks in zs_page_migrate()
2026-07-28 5:53 [PATCH] mm/zsmalloc: fix release order of locks in zs_page_migrate() Richard Chang
@ 2026-07-28 6:39 ` Sergey Senozhatsky
0 siblings, 0 replies; 2+ messages in thread
From: Sergey Senozhatsky @ 2026-07-28 6:39 UTC (permalink / raw)
To: Andrew Morton, Richard Chang
Cc: Minchan Kim, Sergey Senozhatsky, Martin Liu, linux-mm,
linux-kernel
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@google.com>
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Tested-by: Sergey Senozhatsky <senozhatsky@chromium.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-28 6:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-28 5:53 [PATCH] mm/zsmalloc: fix release order of locks in zs_page_migrate() Richard Chang
2026-07-28 6:39 ` Sergey Senozhatsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox