From patchwork Sun Jan 29 04:09:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13120021 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 B54DFC05027 for ; Sun, 29 Jan 2023 03:47:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0B2AD6B0072; Sat, 28 Jan 2023 22:47:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 063286B0073; Sat, 28 Jan 2023 22:47:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E457A6B0074; Sat, 28 Jan 2023 22:47:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D1F3B6B0072 for ; Sat, 28 Jan 2023 22:47:18 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9D720405C9 for ; Sun, 29 Jan 2023 03:47:18 +0000 (UTC) X-FDA: 80406451356.24.FCF015C Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf12.hostedemail.com (Postfix) with ESMTP id 700B04001B for ; Sun, 29 Jan 2023 03:47:14 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674964034; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UJLzIrdTgXgllxCj0G+2nTelsB+hpiS2BWr4yLMfTio=; b=vNjk16C4BOYE+7ZA7Yeai/icJuPhCszaQsPtQVXWK2qfPPMLccCbBzLbnvPO4fXc7Uj2ua l8UguY+geWxydNbYSc87Er2+zc+20DFkGbF7k8igANt2e3ct1nGzAswABCurDWkZC96aRr 818fhpDFMGP6/ILm/+UspzbNfSUA1G0= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674964035; a=rsa-sha256; cv=none; b=gkRmEEYKrR+Glutt5lhzei77gt7rjBeowWo5+jfOBKeBgTZU2SiV0QEfjMsvY9WOngFr9y kmJwjc5nc3QYfzNMQSz/z73D81ew5K4yaR+dZFirFAltXLdhJA//lEKzaXqTAoQedRKDpR 9FLYlM2KuFKEiatcI5CSc63WYNMHxWg= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4P4HJS4DG6z16MZW; Sun, 29 Jan 2023 11:45:12 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Sun, 29 Jan 2023 11:47:09 +0800 From: Kefeng Wang To: Andrew Morton CC: Tejun Heo , Jens Axboe , Jan Kara , Shakeel Butt , Naoya Horiguchi , , , Kefeng Wang , Ma Wupeng Subject: [PATCH resend] mm: memcg: fix NULL pointer in mem_cgroup_track_foreign_dirty_slowpath() Date: Sun, 29 Jan 2023 12:09:45 +0800 Message-ID: <20230129040945.180629-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230129024451.121590-1-wangkefeng.wang@huawei.com> References: <20230129024451.121590-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 700B04001B X-Rspam-User: X-Stat-Signature: dzrbfc1ccsq4ammsc91hpggrc3qqzm9y X-HE-Tag: 1674964034-603455 X-HE-Meta: U2FsdGVkX1/pVgR4XX6sHPMWVzTmdJrooSDMhZv3UixnDkcEqyC9Xd9RCKYhYj4PVj6s6C200OPMQ5Cf995l0jHIuyN8v3taDU3wZKM8Zat3wlXqcGLt21Qh3UpWaQ5xYRHyNo8fjXokVXQQEaSjoGnPJG5ZN+0ivyRaM/zPFxr+SH8/C89W4jNyzdKQtwDPAp0Pvze7h+7OUUQ4ipzqX9tSLDz5qlaDDBrseIo7e8p8PRs4f8KFXsI5lrH2hquWN9WNJb0BVUMQoLnlRB44EJLdZzceXmojjsrfdPLs+SajyTGs3ZOXvCtWcpUsOXuLDJnF67Rqb6PyxDEHJHd8/F8sPBLRgOZ0MhKEd7lI+Qom3OALFpXRBRa6RfdJmjuXQIu33a0Zwd+M9aoOQCRpCx/E/aIX62zImokr+BgwqchpDHK8CUpoy17H4nyYfDNXPz7UkybxDgYgTBHS0Sg5oWS/NiLz8sJuWcVjehGpe5VPm7wKyhwDaZC8H6PpYq7+QRufGKJxw/GYug/zMNYePi57Oj8YuyY6MSxAFDl3tE27DNKlRPrS15/PRjyWCh8BmVoQD253QHfdJW1gBa1ND0Y+EBlg2cgdgKq1G0Wo3OjO4NRF0otkwGUvEg+fsde1ypko8TSrRE+GRwoloJCxcWbp6SzxnNNO7EypJQp/klVkDKCFwBqOm9Ef/8rYWmPtRAuuG6ajr+CAiSBYZUgUK2sBzqKLPHcJbg+jdnNU8gzWN164o5JmOiLWuWpiyM7bL50hq9wObQuyyAkjLSuu9GXKi3y01pxttaZbZmLJfft71f2jMMNUupyEwv0hg9wnel49Q+Q12/VwEnQ0YY7tl6MC7NP0r+XM25ZuqX7lokQiu19ym1C2tJnXFo4WXSxG7CshpU5eQn0E912+fLt57iCsj8dNb5UWuWf8ZZwC8We+Ot36rUimAldayUFtH2/lsw7ZR47Bu2VeYZT27Dt 1faXDMOW 4r/LPFC07c3VU2Ni/4jmq7f/c/QFjXIYLl5zHCX61u2oB3wyI4O3BaMBoX/pIBekzvt/t+LSpPqPKUnYP1qFc9Jp3qEk/eCJUGwRW4H3x6clUJ1swxxP71VPdlswDJ01gQnrFDFQC/45DDDz/0gbH401t3z7KWOdJ4qT32DUM07Yte08+aX+A1sxwNnHH3lMe9zYcRkN01x+eo8Q= 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: As commit 18365225f044 ("hwpoison, memcg: forcibly uncharge LRU pages"), hwpoison will forcibly uncharg a LRU hwpoisoned page, the folio_memcg could be NULl, then, mem_cgroup_track_foreign_dirty_slowpath() could occurs a NULL pointer dereference, let's do not record the foreign writebacks for folio memcg is null in mem_cgroup_track_foreign_dirty() to fix it. Reported-by: Ma Wupeng Fixes: 97b27821b485 ("writeback, memcg: Implement foreign dirty flushing") Signed-off-by: Kefeng Wang Tested-by: Miko Larsson --- resend: correct function name include/linux/memcontrol.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index eb6e5b18e1ad..35478695cabf 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1688,10 +1688,13 @@ void mem_cgroup_track_foreign_dirty_slowpath(struct folio *folio, static inline void mem_cgroup_track_foreign_dirty(struct folio *folio, struct bdi_writeback *wb) { + struct mem_cgroup *memcg; + if (mem_cgroup_disabled()) return; - if (unlikely(&folio_memcg(folio)->css != wb->memcg_css)) + memcg = folio_memcg(folio); + if (unlikely(memcg && &memcg->css != wb->memcg_css)) mem_cgroup_track_foreign_dirty_slowpath(folio, wb); }