From patchwork Sun Jan 29 02:44:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13119983 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 4541EC38142 for ; Sun, 29 Jan 2023 02:22:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF29C6B0072; Sat, 28 Jan 2023 21:22:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CA1B76B0073; Sat, 28 Jan 2023 21:22:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B91116B0074; Sat, 28 Jan 2023 21:22:30 -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 A74E36B0072 for ; Sat, 28 Jan 2023 21:22:30 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7340C14080E for ; Sun, 29 Jan 2023 02:22:30 +0000 (UTC) X-FDA: 80406237660.06.C41D3ED Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf18.hostedemail.com (Postfix) with ESMTP id 40A781C000F for ; Sun, 29 Jan 2023 02:22:26 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf18.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 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=1674958948; 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: references; bh=MhYxgd9UVPLlGEUu3KDODF507KFrOAhtfFwG2YfLqsQ=; b=WLqPW3dOVIymWFLw1So+wII7mgROUBgRygR8LyMxc1Zwtadu4mgqR5CdOXwPhqYKfu8VHH HFPkYNcS4F51XKimgxWgyLc64pP8ry+bsp/Bxyhr21UoANfeg/rifTYbG5tF+LudS+KpNI ZAActMU1UTe1nmLWhvmXsH1lUy+GxW4= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf18.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674958948; a=rsa-sha256; cv=none; b=Zpc+U+ChSwvFOLMXMtEZsjIOk+nsfRaD4K0mKbDJNFBstAf8RLZ922jk2+sCo7QOH8ArSa 6WDwsqCCfjVpIa18ohr53ibupY/TlUj2PSvSc76H8NVvyReiwXllD5jfk/HemGcxFsE20f LskIuTeL61/yYZb4thnet0n6MgYJUAc= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4P4FR31FQ4zJrKm; Sun, 29 Jan 2023 10:20:47 +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 10:22:19 +0800 From: Kefeng Wang To: Andrew Morton CC: Tejun Heo , Jens Axboe , Jan Kara , Shakeel Butt , Naoya Horiguchi , , , Kefeng Wang , Ma Wupeng Subject: [PATCH] mm: memcg: fix NULL pointer in mem_cgroup_track_foreign_dirty() Date: Sun, 29 Jan 2023 10:44:51 +0800 Message-ID: <20230129024451.121590-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 40A781C000F X-Stat-Signature: qujr33n3h1fz4px9r1835h64idqjkkm4 X-HE-Tag: 1674958946-308268 X-HE-Meta: U2FsdGVkX18qIw0d+RkCXPGne9CH0S9w4C8Hj8MqQjUoiAt6yFhuNoKZcsVuQ+CKgNiyHbbenSv9Krcg3ZGFIHcipRBzF3wDPmzBx0JvfqBlXBr/J17GdoLcqV6R0GYtAr51KDYTJS+gGvpuOtlVCPeAPDPYgVG2yunU7zorjf9pT6tjUjuZHCfDZIRw+28w/FB2k5GToV/LFcR4TUZoz/qiTkVx0DRIPZtV7IEqkfmOFjXf37FK9OpeoxvfWvw/zI1DpYxaWORjALfmyD2yR3vZ0zgFH+eF2WLj9BnIEsWaa3Wgc7kdWJw8eALtb57KRT5UrOSCCs7m/GtTQfwv0WvrDTEGimDe0k1lYSomjaVMIocM6gu3lvrNhyUHBtQjOG7pyoXNsydpOg738j7HtyFsaL07/2yHgC56MNwf60/ijlF9Wt7z6KgM72u6EBXMMrAO9szvBj32d6CEFTgyfQRFJqIfTnj0U83lb7MhqidNhs5zxrUNY/XoYqj31Czm5qD689WcQuae/UI7dsDVu4ubxJf95q79v4xmFLuSCPQS1cmKTkNntvYqNrfkeBsimPVq2DcXmS7MqNNThu2fX9dnvBwwIolvx4Q+eOek88M8aG9z6073THoIc60pwxfr1QnHHe9Py9SNhreKj+dnqKJ2LJR4/Xbp7ZIRf8J7+p3qzswhIRZ5UWrffl5KRwOhfV8nKmQ1IQr8pCsOVtyqFqivcpmSq+KdGZbKatjtzmVHVEptkn+ywKxm30CzL/+VewHlb5fs8eOuEN3w33o6UwgJEEmV/TEh3GTldL3amqnumOyUDBttgxQvt/n5wnAjxPJHXslYT88in9/mI+vYlj/e/dkh8L9ds53dea51FqOJKxp/JfWxm6C1Rc29Ux+hhdoQpp49ID833qQ7gX7QIsR9nbUWMTSKyHqlKKTmK71wQQUdJukDTPeAeAhV+pBPAaNmB1qVJVCml/EXrY3 sIpQSrQI 4CRpLNQF+xMPhuCDLeaZCtPQ5okoB/nHp/GrEdDWLEUD/6eOGZelJYh5YTKHYqpzf3lGjxsxBlHEIqjCnatEg/ABy40Zzh6EpbBVENuhVrWsi0x06cKoe+DftueFDwSu8Skg3A0xlm4vtd6dkMMXL00HN4vasRfaXEpSv99pU8WCcjsKBL8gel/qgJnAnKNHZMs4wqCrotnHfIHHMxvcmpB5+jw== 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() to fix it. Reported-by: Ma Wupeng Fixes: 97b27821b485 ("writeback, memcg: Implement foreign dirty flushing") Signed-off-by: Kefeng Wang Acked-by: Michal Hocko --- 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); }