From patchwork Fri Jun 14 01:07:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13697697 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01701C27C4F for ; Fri, 14 Jun 2024 01:07:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 849046B00AC; Thu, 13 Jun 2024 21:07:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D2DA6B00AF; Thu, 13 Jun 2024 21:07:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 674096B00B0; Thu, 13 Jun 2024 21:07:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 457D36B00AC for ; Thu, 13 Jun 2024 21:07:59 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E2B361603E2 for ; Fri, 14 Jun 2024 01:07:58 +0000 (UTC) X-FDA: 82227707436.24.340BBA5 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by imf05.hostedemail.com (Postfix) with ESMTP id 0109C100002 for ; Fri, 14 Jun 2024 01:07:55 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=QUDh5MMl; spf=pass (imf05.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.98 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718327276; a=rsa-sha256; cv=none; b=ye4kFy3nq/pBa6lpt5KLsyj66fJQhPxFjjctwjhr66/15OciHXNX9iD1wHtL+JLarnXGrQ YZYEbVRbO/A6A5ydHwBnrw+6MHG11XurLVkwacOXnLuvdn1NfkDw5e9Rq3YSwCJV43oFNR oqNoMh0hGUFanpjN+zmj7KKIfkWiTBo= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=QUDh5MMl; spf=pass (imf05.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.98 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718327276; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=BQDb2F0aaOJSuzhQ9lADc/Q15DnIgg4AnXxoddC9IM4=; b=rmjDSzBViu2EVwhl0Fm6NRnAvyA7a1pDTq3wq/Kj9YvDf8ke0GDgAjXKYRF0izgDjAcnkr qmU31poTWNIDfOl6HCf0htPI8J494Ykg1f1Ysl68H3CVwlP0ls2ncaqr5HmPwgsKt8gA8o 8cPv8yICa+6zxfWFSdXZcYgxM+lpM4w= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1718327273; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=BQDb2F0aaOJSuzhQ9lADc/Q15DnIgg4AnXxoddC9IM4=; b=QUDh5MMlcGdehLNnsiVsa+Hx/iOEAcL1ErPIuM+tcymDGZT9iJF/2nSgzGVfowvGz2VP9gIhm5NRjXNEfldD7xDp0Qa7QBt10G/KinAAophL5GWm2YkhAbodpuL8LUslW0gnHY2mDenOjTP6NM3fHyIBphFTN8EMpQLERM8u4Yw= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R291e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067110;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0W8PMaPD_1718327271; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W8PMaPD_1718327271) by smtp.aliyun-inc.com; Fri, 14 Jun 2024 09:07:52 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, hannes@cmpxchg.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: memcontrol: add VM_BUG_ON_FOLIO() to catch lru folio in mem_cgroup_migrate() Date: Fri, 14 Jun 2024 09:07:42 +0800 Message-Id: <66d181c41b7ced35dbd39ffd3f5774a11aef266a.1718327124.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Stat-Signature: x5s65hni83it3gxxkti6ekmw31rwkiue X-Rspamd-Queue-Id: 0109C100002 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1718327275-136780 X-HE-Meta: U2FsdGVkX19w+xtp1OOowqEFlK5s+V4anlP/7nOkJ2+w48OA+ToWLEs0zqOeICR7K81qZmq0PJ+hS17KuASeeipnxh9Ds+z+AFBiqcMwKJzYxpFUBcZedE/Sr54/iRuTSGAZkrNUEFROk4kabW4K8Fs0zbZl+vtfvcYYcIkrTHDkIAjYUAckJ6MOJTBnbAS2JkMt4LJZINiudEWQDTbyHq5gWOuU7VrxnMxsr/yMeL8z1hZI0IJ22d9PCVhwiOLgWGfAyOvhgvqTwKDwZefd5trZPvtQJGIZzYXMOAE/fwOlzgurxUmxH7TuzRotGZky1LNcFR/8ycge/rewwxK1Ts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owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The mem_cgroup_migrate() will clear the memcg data of the old folio, therefore, the callers must make sure the old folio is no longer on the LRU list, otherwise the old folio can not get the correct lruvec object without the memcg data, which could lead to potential problems [1]. Thus adding a VM_BUG_ON_FOLIO() to catch this issue. [1] https://lore.kernel.org/all/5ab860d8ee987955e917748f9d6da525d3b52690.1718326003.git.baolin.wang@linux.alibaba.com/ Suggested-by: Shakeel Butt Signed-off-by: Baolin Wang Acked-by: Shakeel Butt --- mm/memcontrol.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 4d9fda1d84a0..62fa3869065c 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -7844,6 +7844,7 @@ void mem_cgroup_migrate(struct folio *old, struct folio *new) VM_BUG_ON_FOLIO(!folio_test_locked(new), new); VM_BUG_ON_FOLIO(folio_test_anon(old) != folio_test_anon(new), new); VM_BUG_ON_FOLIO(folio_nr_pages(old) != folio_nr_pages(new), new); + VM_BUG_ON_FOLIO(folio_test_lru(old), old); if (mem_cgroup_disabled()) return;