From patchwork Mon Aug 19 08:04:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 13768043 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 C6ACDC54722 for ; Mon, 19 Aug 2024 08:04:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F4476B007B; Mon, 19 Aug 2024 04:04:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A4816B0083; Mon, 19 Aug 2024 04:04:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3BBA26B0085; Mon, 19 Aug 2024 04:04:29 -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 1D79A6B007B for ; Mon, 19 Aug 2024 04:04:29 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BDDFEA10DE for ; Mon, 19 Aug 2024 08:04:28 +0000 (UTC) X-FDA: 82468257816.08.967D160 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf17.hostedemail.com (Postfix) with ESMTP id 5770940019 for ; Mon, 19 Aug 2024 08:04:26 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=LP309HdD; spf=pass (imf17.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724054652; 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=a5pMgQRu6k6leW3rh4d4vvY0vdZxZHpL/sFft5GJjjc=; b=yyZlTefvZeICk6qnFSWf1DXYVy1oCSf+bMagA8KRwfHbKE0moiR/6UBzVzRMVYQABaUPwK eoLP0VViFIelo2OTHS9GwVbniyP0YfczRhg7/AoucpbMBHzI6LtuVrfaeniuqQ2XdLsrOS 7qCfqGChylT/6d30BIiPmshiv1cJo+0= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=LP309HdD; spf=pass (imf17.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724054652; a=rsa-sha256; cv=none; b=nwY0OiWuwN/13XOgSa3qtim+f2taJAjVJyLka3dOGvmmXQujp6NsHTGnoBlXE8Qa0sNyzg qAiCHG7QZggN3xD3mV0qLL2ERjzhFDYNREnhE2bKiPQz47d6BqqJDQ/3tW4glCQXgaywu6 lHDczwS0OH/B+RZzJ3e+eI9snBb+jOQ= Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-70d1d6369acso3197483b3a.0 for ; Mon, 19 Aug 2024 01:04:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1724054665; x=1724659465; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=a5pMgQRu6k6leW3rh4d4vvY0vdZxZHpL/sFft5GJjjc=; b=LP309HdDEt+he+jIhcr7SuqXCMiwql+bX5tABLwlRMtc/dqya+88lMwTqBpbWSSkbS uEFFUxCspllJ52YCjI8+NFIUuvTutCnUJg5Y4wE74wyzx4HskLb9YB+2kOwMsn59tiJW XzSv1PKyb8el69OTKREPALI0ooFQi98yW4Xg8vgehkXcecjfFianUh918NoC9HwvJyyf 5yse10cszp3rUi/WoxXWo/XkGX41X6WafWPCtG99kkEiOSKSb4KqKLrb4g8ayTkKStNL OaKvvxkWIqppnDOQkLL/A3soJWZdQ6QjPvwhAmvGYr1l9KsqV0ZJYgLjtq+S7PhVndih UOmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724054665; x=1724659465; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=a5pMgQRu6k6leW3rh4d4vvY0vdZxZHpL/sFft5GJjjc=; b=eByqMGrq7zGLOnm4rMl3tN/Eg/nrLeAenYF+2qMy4omJQwZIWei0N2+ScFkKmgAqxm vV3Iist8maNziH6PUx0SL3ICi5rhDecw2CDJZ0v41PB1dQzQ/NKc9rrD/JjI7IwlV87i EER0fO8BfYbmJ40xd36l6ISv7i0Rb+uD3JWqYiyD7qQn7EOciWxfaZgPtkpdydXxRj8u P5lJ45xZ8vjI9tM9Te8laKaRertDX44dvchOT8djQyxJfpxSjurLZ2iX3eHEirCsOa+H n6imFsd/wCzQK2t+Jw7IvSTyANwaZKpx63UFVwQHwNGrtLz4JZpSsq4TE+exP67rfbrt qN5Q== X-Forwarded-Encrypted: i=1; AJvYcCXmVd4uEr28XXXl5jFUCEhySE6gPW0mCt0AbbFquEoBwGVeUgZAF7y5BnTXgDtlVdS26UYohD34y+XAmkku/3w4xeA= X-Gm-Message-State: AOJu0YwlHw97Hq8poOVRW76Xc70DEWFXvjsLvJ200MkNrg3OfP5g/BDZ /MC+s0Uxa+8ezOqckYU6mvDhRQAj9sXzK2RKaCrY9hokE0p8zFe9K+1/tHVscxI= X-Google-Smtp-Source: AGHT+IHLfanBTcn2DvSOg+cw6SKdo5DRsRm2SonlABa3P0MXIOz858+YTpfkVL9sUDXKpvUfjPtHTg== X-Received: by 2002:a05:6a20:158b:b0:1c3:3d23:c325 with SMTP id adf61e73a8af0-1c8f870c61dmr19956646637.24.1724054664643; Mon, 19 Aug 2024 01:04:24 -0700 (PDT) Received: from PXLDJ45XCM.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7c6b61a7672sm7183121a12.4.2024.08.19.01.04.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 19 Aug 2024 01:04:24 -0700 (PDT) From: Muchun Song To: muchun.song@linux.dev, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, akpm@linux-foundation.org Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song , syzbot+ef4ecf7b6bdc4157bfa4@syzkaller.appspotmail.com Subject: [PATCH] mm: kmem: fix split_page_memcg() Date: Mon, 19 Aug 2024 16:04:15 +0800 Message-Id: <20240819080415.44964-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 3ngwt1eqeqp6r4s719qe8f9j453dy1kt X-Rspamd-Queue-Id: 5770940019 X-Rspamd-Server: rspam11 X-HE-Tag: 1724054666-779575 X-HE-Meta: U2FsdGVkX1/RmbEOiKzMTJwnVZriSSAHc5yxmgHCeRpPFxlEsDKeiNIgFaWNikS7knmsawonLrHy4REomcTAIR8OwH+qozqDbqKgQNNyts7w4BJVKkg6Zunsn0qH1cJPdv5R9O2gpevt6mTCu+yFhkISqh/AIp/SLFltVZKdSa+0vZXL2u+r+sTQD3ysfR0LhRjmCYLkmSulZU/EP4RsSTl+Vsg74ircqGIv/fi1PU42IJRJQW5cb7y629obPrHHsYD8nbQzFORbJ1BnTGhSxfSGMmq1ZOsGAjjX9eNboTRDnJXfkzOXej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p9C93xU0oSIbReHX95M3vJbCKMQpnHGY9BBdQ1aUeWUHTQlHSXENjFl73r8diJA+f5wgioAPP59ReKkUEjb62qJNXAqVaMqjJcNoB/25IZu3Q+bE1RHMo8qgsmSqObXo++sDYfyjrZYYuVA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: split_page_memcg() does not care about the returned memcg for kmem pages, so folio_memcg_charged() should be used, otherwise obj_cgroup_memcg will complain about this. Reported-by: syzbot+ef4ecf7b6bdc4157bfa4@syzkaller.appspotmail.com Signed-off-by: Muchun Song Acked-by: Shakeel Butt --- mm/memcontrol.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index e0b3b7ee6de6e..6c84af0a9ede6 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3018,12 +3018,11 @@ void __memcg_slab_free_hook(struct kmem_cache *s, struct slab *slab, void split_page_memcg(struct page *head, int old_order, int new_order) { struct folio *folio = page_folio(head); - struct mem_cgroup *memcg = folio_memcg(folio); int i; unsigned int old_nr = 1 << old_order; unsigned int new_nr = 1 << new_order; - if (mem_cgroup_disabled() || !memcg) + if (mem_cgroup_disabled() || !folio_memcg_charged(folio)) return; for (i = new_nr; i < old_nr; i += new_nr) @@ -3032,7 +3031,7 @@ void split_page_memcg(struct page *head, int old_order, int new_order) if (folio_memcg_kmem(folio)) obj_cgroup_get_many(__folio_objcg(folio), old_nr / new_nr - 1); else - css_get_many(&memcg->css, old_nr / new_nr - 1); + css_get_many(&folio_memcg(folio)->css, old_nr / new_nr - 1); } unsigned long mem_cgroup_usage(struct mem_cgroup *memcg, bool swap)