From nobody Mon Feb 9 16:53:01 2026 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F13B38E5D8 for ; Thu, 5 Feb 2026 09:03:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770282224; cv=none; b=bgmpMtjwN/aEr71uNIiidCdCYWkJhw+diPj/H6qaIrpaiZJm6+WmpDlEhjBCzB5ytbyp4mskpwX8cnPgYK12qdXCQMNWCftj/VsL4vfGNcLDhxgYBf08oS6ruP5gcle4as3NVirXZ7WbB3U4dH7q4HxNMiOOrV045v/s483p3Wo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770282224; c=relaxed/simple; bh=Y/zzESTsEBN7BWkVnUXZWeXofW0H6Zyl13gBJqcxsXQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QRpBxdynr4VsMY/9eAHOtMjviMo8Q6fi07cULbzv9DbIKeJYdIZdECQiiJaeMFJq4Ka66STfq8VxdKNxp0XSb2QYAj2087rOSlNltakkpxWz1E/qXLdAFh1jxVhyr4cpGPwh2q+t1lpgJqK76tOe1HZAh06ql1CL69okilmdYpA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=oLJ5ufLc; arc=none smtp.client-ip=95.215.58.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="oLJ5ufLc" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1770282222; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OqV/eFIkaVw38X0p3K1tJbQ+i+hlw2eit08Kykms+G0=; b=oLJ5ufLcBmOC0W58tNfEk/SWtVxBvwf6YpmAA7MPKXSHoBsl/kJzc8x8aS/Xl7vbcpvF27 V9uxjFkFhqyVBhAoKOkPfotQ8ZKgneDa+F8pOwkpXmFP7uBeBYTIIJZwEqDY4GtTCCMBJ5 iLof/J7EcVNubqPGy15OzHdDN1ELBns= From: Qi Zheng To: hannes@cmpxchg.org, hughd@google.com, mhocko@suse.com, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, david@kernel.org, lorenzo.stoakes@oracle.com, ziy@nvidia.com, harry.yoo@oracle.com, yosry.ahmed@linux.dev, imran.f.khan@oracle.com, kamalesh.babulal@oracle.com, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, chenridong@huaweicloud.com, mkoutny@suse.com, akpm@linux-foundation.org, hamzamahfooz@linux.microsoft.com, apais@linux.microsoft.com, lance.yang@linux.dev, bhe@redhat.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Qi Zheng Subject: [PATCH v4 18/31] mm: zswap: prevent memory cgroup release in zswap_compress() Date: Thu, 5 Feb 2026 17:01:37 +0800 Message-ID: <2dbc70b6cb57d32ae5c888b5623329aecec8414c.1770279888.git.zhengqi.arch@bytedance.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Qi Zheng In the near future, a folio will no longer pin its corresponding memory cgroup. To ensure safety, it will only be appropriate to hold the rcu read lock or acquire a reference to the memory cgroup returned by folio_memcg(), thereby preventing it from being released. In the current patch, the rcu read lock is employed to safeguard against the release of the memory cgroup in zswap_compress(). Signed-off-by: Qi Zheng Acked-by: Johannes Weiner Acked-by: Shakeel Butt Acked-by: Muchun Song Reviewed-by: Harry Yoo --- mm/zswap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/zswap.c b/mm/zswap.c index 3d2d59ac3f9c2..a9319ecd92b4b 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -893,11 +893,14 @@ static bool zswap_compress(struct page *page, struct = zswap_entry *entry, * to the active LRU list in the case. */ if (comp_ret || !dlen || dlen >=3D PAGE_SIZE) { + rcu_read_lock(); if (!mem_cgroup_zswap_writeback_enabled( folio_memcg(page_folio(page)))) { + rcu_read_unlock(); comp_ret =3D comp_ret ? comp_ret : -EINVAL; goto unlock; } + rcu_read_unlock(); comp_ret =3D 0; dlen =3D PAGE_SIZE; dst =3D kmap_local_page(page); --=20 2.20.1