Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp511264lqs; Thu, 13 Jun 2024 18:08:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVkZuqssLSUXo3som+SIPXVz7600yrFR776LEyW5mIz9FWIEqrs43fosoID8IuolGje8hpbbHqtqpYSPQiEsI7iIDQkrnE5d4S6j5u+MQ== X-Google-Smtp-Source: AGHT+IGvwvFuHrNXofMMJYpTpFQ62DP1czN10i80VsEcPJwv/C3dobDNT9ww7QvWcJgALT6D7dsg X-Received: by 2002:a17:906:5913:b0:a6f:4f2c:1939 with SMTP id a640c23a62f3a-a6f60cee403mr79230566b.1.1718327293258; Thu, 13 Jun 2024 18:08:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718327293; cv=pass; d=google.com; s=arc-20160816; b=QrfXSCB0PiDu1pKE/+3VP2FSokNLgzGELTrjD1MUw+o4c6O7bQW2AgSSHDHGh+0P6O wAg37z4D3qIeXwnIiLKZ3azlob70+aFQiV5AsN6MdbzWZAlkRmI5JG78MxCh41QDLKxu /f1uyFly79EutXSYVx2DS09XAxhYYcjUvLMjZ3oN3eNrXO4Wu8EXn4vMLdpv0osNpcbB Gp80tQUhB5g02E3gBtwkNtBrQqyhD/emcyaEgS1lpXnZqO3HZU9eADLjUvLtHhnYOgnW ixGK2q912/AUErYhM1XuqmipQvrNaGSXqA6HKcmMnyZiFPWgOBf3suoGRxYl3HDbes/O SsYA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=BQDb2F0aaOJSuzhQ9lADc/Q15DnIgg4AnXxoddC9IM4=; fh=3BO7FkmogWIPFKIKDxoZySqjz0cSaEVx8fTSOVFyPDs=; b=C8zVx1ExFbLUNFji/q3+YqxtDmlg+r2irJADSuATooOf/36ov9FcM4GV6EdZdGLFJ4 B49sGypumPNVBCWiFRTqE3hD061ZFECFcIQGUxdWamlk3pPV5AwYSIRwd0pgrW6FJ9+4 gOUrk/owobd6i+taGN00cWz6KwypObGOzH8KesPDVH/2+/mRddSGLdP61c7BnJDuQZYi Q10RHg4ve5Yu5JspkwdcFC47gx0WYAGLXAVyZo3A9mZAivd7FnRJfAfvBIuvqHvj651+ xOH7muKwU9sZ/Lmwv8g8erZA0ONdAm4Qr/sZlv3VlqYGrSf8Z0wNTk4o8dVxlM+vHDGl NS7w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=LNDgX3iZ; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-214174-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-214174-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f60ba12dcsi44055766b.936.2024.06.13.18.08.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 18:08:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-214174-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=LNDgX3iZ; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-214174-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-214174-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id F0DDE1F227B1 for ; Fri, 14 Jun 2024 01:08:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41F32158D81; Fri, 14 Jun 2024 01:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="LNDgX3iZ" Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) (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 16CA72F25 for ; Fri, 14 Jun 2024 01:08:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.112 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718327283; cv=none; b=C97It4DHaXKu35HiSJ254GuttZ2/bOAi3ha49hAehMnkXdmyyIPFmdSmwolLyynNqM97hYSnOcAJI5fvDAZqiJs7k3ELKin64dFl8jibVigraSK8doOm47JFMybf5t4GoLPBltP56ddpRQbymdfvBCuDmfVLxw9ecTpDDhx6vKQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718327283; c=relaxed/simple; bh=tIbaCIP9xAaKgjIU3FiXTfrp4VG6oaih8IQWZccKNQM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=BxobczFqE3aa1OUtdOe4jU8HItzE88xILlGvIy38Fv+ukSNLkapK6mk1DDHYvtloYK0KI5Cbm5EVOtBDAY1/eb5FCzDKAFnkuSxolEq2/XbAOCx8EernsddedPlpP7w0DgK0nyFdSpWLCPkDUAqMVCKV47zbLJtsxIFh0O9fGNY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=LNDgX3iZ; arc=none smtp.client-ip=115.124.30.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1718327272; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=BQDb2F0aaOJSuzhQ9lADc/Q15DnIgg4AnXxoddC9IM4=; b=LNDgX3iZD0wpYv8+b6agYJBdfOA27xdC97aGDMvcqHQm86jUi3GhIlX+3YfNpR/L2WE8lYEAHCxN9KhwSJSt8bsSXYIavBUbwW1m+bbOTr5ApsLAZmwzFRsT1oVRllFJCg7lHeJjbGQ166XJp3ITO61ZA9iFDQBkPWYU1+ekAeI= 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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; -- 2.39.3