From patchwork Fri Sep 16 07:22:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12978213 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 509E8ECAAD8 for ; Fri, 16 Sep 2022 07:23:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 743EE80009; Fri, 16 Sep 2022 03:23:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5874F8000E; Fri, 16 Sep 2022 03:23:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3273D8000D; Fri, 16 Sep 2022 03:23:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 13D6F8000B for ; Fri, 16 Sep 2022 03:23:47 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CE9E314083D for ; Fri, 16 Sep 2022 07:23:46 +0000 (UTC) X-FDA: 79917108852.02.8AAF678 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf26.hostedemail.com (Postfix) with ESMTP id 540281400D0 for ; Fri, 16 Sep 2022 07:23:46 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MTQRT18CRzMmx1; Fri, 16 Sep 2022 15:19:01 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 16 Sep 2022 15:23:38 +0800 From: Miaohe Lin To: , , , CC: , , , Subject: [PATCH v2 06/16] mm/page_alloc: fix freeing static percpu memory Date: Fri, 16 Sep 2022 15:22:47 +0800 Message-ID: <20220916072257.9639-7-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220916072257.9639-1-linmiaohe@huawei.com> References: <20220916072257.9639-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663313026; a=rsa-sha256; cv=none; b=eYm2Xdnmx5HdV0hF8JDVmG7DRz009aCoRWmfH9oYmCP+/CnzudU//yqYvqTvkAEgOQinyu wlLC8x/btX9Rn4jpOw9eRY0MNGEaRl8YsLbunasTFAuyjt/f/kA1uPd9UmGo7k3z4SMyOC c6mf4lPrbEcBlHwVo8pU43JGojsgu9E= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf26.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663313026; 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=9PT+NFWr6n4hbOQN1nIg0F2Tcs95ZMNXMHfuFj4JHrM=; b=aOBgyEjjh6Rtur/UNR64K4azat8yoyYTK2ngrBniZ77PVDNPeW0/NIkr7WNWXXRs6nVXry m4rMmNGzp5NMEmARB/lbn3L07Qz/ISmW/SY3u0V46I83gqyzwyJKwKJzaEdv3x6C0chk87 adBBSe2wIlBziSGQjsjIe0PrKVaqc5c= X-Stat-Signature: g1kjbjye359qn7jb47htif5p3x5zrhy7 X-Rspamd-Queue-Id: 540281400D0 Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf26.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspamd-Server: rspam01 X-Rspam-User: X-HE-Tag: 1663313026-203864 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: The size of struct per_cpu_zonestat can be 0 on !SMP && !NUMA. In that case, zone->per_cpu_zonestats will always equal to boot_zonestats. But in zone_pcp_reset(), zone->per_cpu_zonestats is freed via free_percpu() directly without checking against boot_zonestats first. boot_zonestats will be released by free_percpu() unexpectedly. Fixes: 28f836b6777b ("mm/page_alloc: split per cpu page lists and zone stats") Signed-off-by: Miaohe Lin Reviewed-by: David Hildenbrand Reviewed-by: Oscar Salvador --- mm/page_alloc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 27ef763bb59f..cad235770948 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -9505,9 +9505,11 @@ void zone_pcp_reset(struct zone *zone) drain_zonestat(zone, pzstats); } free_percpu(zone->per_cpu_pageset); - free_percpu(zone->per_cpu_zonestats); zone->per_cpu_pageset = &boot_pageset; - zone->per_cpu_zonestats = &boot_zonestats; + if (zone->per_cpu_zonestats != &boot_zonestats) { + free_percpu(zone->per_cpu_zonestats); + zone->per_cpu_zonestats = &boot_zonestats; + } } }