From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7C2B331209 for ; Tue, 28 Jul 2026 05:54:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785218061; cv=none; b=PrGRzkQ+FozwwucBkLaWu84Fek4eDkYVyvms5PxlxR/DNlqTVWbd7sA2TLqk+CXUpZ55S5Z4Q25df0Gbola+u/Jf41SIp3VLM64EdsjCCrQ66qc28+L+W0dWfawokPO23NK128aucZh5MUsF662y44dJRXFqo51XCGQZZtkHdCE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785218061; c=relaxed/simple; bh=mdYYWtp7CScd0MA7sIOfYBr7H2YCqFGHdncNB8bbx0s=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=btBbEsZyWrgauBnCPFy4oH9DjsLs1MJQnBat9wdMG6feCBDtUEuV8dlA2AClhLRc2V0CIUS+aO0S9jGELGifRSki83MUzhQ22XA1a71K1Hf9aqdO51S1U7F3tSx4vnzHd7L9y5Ac+zf3u4pU9Z15cearNVPqj1kBl9US1IVWGDs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--richardycc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=AE0jl1El; arc=none smtp.client-ip=209.85.210.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--richardycc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AE0jl1El" Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-8484b9fb055so7724561b3a.0 for ; Mon, 27 Jul 2026 22:54:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785218060; x=1785822860; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=TbaUQQC+pn/OWUqlcfjUbKPPwPnDIi5tfzFCEzmCL34=; b=AE0jl1ElxlDuADTOolDOdN8Rr+EdTwvd/sXsHRthvVbeMagnO03dHqkDTenyJ/nDp4 1kW9Fo83W7cnU1mzBmDlI7hUuKAaK1UFJVbdkO26/oVpPzPxe2myb+C3v+M+DqpmBHRX NnQws1vvQfjhT3/yFUiJ+nk4VWvOtxPrfwwqx+0WtJEYABGRoWldYzP7qw2I+EH4MFs7 +JK1d9reJqzsL/aqhvY7LvvTX23kfnEgPuefQDkM5p1pV7A8nrHgwgLABnElqTIKNPC0 JTSqqk3/YyLnrcLxUY0Egau8noFb3CDkrY1GrqdNdCl9wPOOiNbBBeeojWgsV0vCkyCb SMIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785218060; x=1785822860; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=TbaUQQC+pn/OWUqlcfjUbKPPwPnDIi5tfzFCEzmCL34=; b=sYD3xYO633SR3EzaHc8l9p80j/S+0OwI8p5rRCQzTf16yKPKjIOc2TkvbsmxvjgW8T spiXqobVtRf6b+55Cw0k6ZP2F2QijEWQFPc7SkqlJsk984UtCT8MHZeoCMmzHx7QNyxc +NpiCGBROG055qo2vclJI/8C5r9IfRrwmzBlaH68n4mJcaBRRlexnRQvtKQnw1f+l0eo 2JpwnwAhEpc+V3+5tBdtIj07a/TajIDHAVewD1vAXcWJPN0DbWD0kpgaUNB0ZuB3TUQS TVA6sXO/1HUABAMAIV9auG3ErPnzUibgRP3TPaKpuH7FyxvxP30msZUKRSuQX/Iq1nEE /slA== X-Forwarded-Encrypted: i=1; AHgh+RqYz5XF5IfbTdqI66yuX0/vH5dyMzVA/RdNwnS1Piagz8mLo3osUUhtyaO/L4O1NkJr8FXpAUL0dNx8cOw=@vger.kernel.org X-Gm-Message-State: AOJu0YyzeQ0gc6RirwugiRinwdd1T53n7a5n4DGJNFaZdvSMnL3OydHv /X4X+7GutDHv2l5Jruy9Xf0to5jMNjb11MnlMTlarhu1SKKCJipkWV/vYlKC09+xv1vOaQjdsnU PkrpfwP33mxEyjCpUsuue X-Received: from pfbmb2.prod.google.com ([2002:a05:6a00:7602:b0:847:80c0:ec04]) (user=richardycc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:94d3:b0:848:77b2:20a with SMTP id d2e1a72fcca58-84e933203d0mr966896b3a.39.1785218059622; Mon, 27 Jul 2026 22:54:19 -0700 (PDT) Date: Tue, 28 Jul 2026 05:53:33 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.55.0.487.gaf234c4eb3-goog Message-ID: <20260728055333.421080-1-richardycc@google.com> Subject: [PATCH] mm/zsmalloc: fix release order of locks in zs_page_migrate() From: Richard Chang To: Minchan Kim , Sergey Senozhatsky , Andrew Morton Cc: Martin Liu , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Richard Chang Content-Type: text/plain; charset="UTF-8" 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 --- 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