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: 49938 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1599292wrn; Sat, 28 Jan 2023 19:53:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXuRmy2E60Y3ZMCADDXYUIAhOGi9BNQTCYYZMYnKf/3xTQoLZMgX3qSHiD06OhTYHR6pe/3i X-Received: by 2002:a17:903:31c9:b0:193:2d53:3fc9 with SMTP id v9-20020a17090331c900b001932d533fc9mr41708390ple.6.1674964381879; Sat, 28 Jan 2023 19:53:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674964381; cv=none; d=google.com; s=arc-20160816; b=i+Bx5PDWjb2KI3bsreYdEHTu/B3dJKRXupJO3/ovXN/vNC/1jTWeHX0x1CM76gYBrw 7iBw7dMFRrw5fotHWcmq9PJ3hjydYlpr7s0sSm8MCVgUcF1Giw5BNIVXQowEoOcnzhhs yns0dgbARi+5C39dJb5bJQm76ba8pF+SZgoGvzQpDG88OMVb7P8COSzMEyGEHHSLVcFv RFMxUcc/rcyk1sI53InllWMRE+iIIzdBopczLeeHADRfFKy42ZTBzvLvXxkXVdtsOfCc YGw3e5+PIDwLoFbYjhqXDQpLlD3y2vQRJ3E84zz22DSYWOmMFVmlKQOOB2I27CZmz8vu ZA1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=UJLzIrdTgXgllxCj0G+2nTelsB+hpiS2BWr4yLMfTio=; b=Dh86+e+aC+e0hLn4z0fnDPu+ZcLkE2n1We9VL4moInhNKfm68ZwSDvUNIZfvopoP8f AHZxe1AYqKBxNbBODovBOqpI1HoDD2IdzmaSRccwX7K3iNTb7JW+NASuFpmqsxOSNOLt 6yYUlC8a/a/fWo2DtdHdAazf3tGDCEZZKoXsC0QEZF+OSz2BrFCrmV7HvrkimUTXI5mt iRTDT48G9z2y3DKKsZPXZgMoRmmXh4lWYcYXsbfOkGph4wAOOiZcGkw3LfRi6/gv4Q9c znUt1FxoHq94ZO1UDFeewBAXdTH4gVxabDWfFpB5scyGXSSWTU+32ipMFkxnjkDjSHWE fAOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y14-20020a17090322ce00b001944983f4e2si10113586plg.491.2023.01.28.19.52.49; Sat, 28 Jan 2023 19:53:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229600AbjA2DrO (ORCPT + 99 others); Sat, 28 Jan 2023 22:47:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjA2DrN (ORCPT ); Sat, 28 Jan 2023 22:47:13 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21B44126 for ; Sat, 28 Jan 2023 19:47:12 -0800 (PST) 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756327451861871569?= X-GMAIL-MSGID: =?utf-8?q?1756327451861871569?= 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); }