Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1705082rwn; Fri, 9 Sep 2022 02:47:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR44C8edEVTtgTMdS7uy+ZBy5YgyPX8PowgXxIZVQN8I/LNwfkSde4HiMU7qI4s+SuScE5t+ X-Received: by 2002:a2e:5357:0:b0:26a:9a92:86c2 with SMTP id t23-20020a2e5357000000b0026a9a9286c2mr3517721ljd.178.1662716846864; Fri, 09 Sep 2022 02:47:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662716846; cv=none; d=google.com; s=arc-20160816; b=HLrJJqDWyl94gLa6dJNEY1ROtdbMVsP8LWHfW1sWg2U/eWkz5DXh7rJJ+Vtf1wrgoy 2mBwwQ75Hl/hxLF0J2JTTTdGDgAu8564xpc1UhsluLuf+PhFYSWinE6HAKVIdF2aCB5D Gy0VfWVpSn2PxJLvIomwCw/ts1IlpBkbmYKl9ZEBivR7Kpgxgx1ln+oXCRrf0f2p5SlR hLa+yPrTHDQf2b/AAtUmr0h2L0sGRRSQ8BU0WQH4IsaavOQIe1hRBu9QYWYq6XKlVDV9 mDFHTcmQnChcRB3Fir6D9Ynhqm/p2XaaH4CZzYKG/aEwskMVMwAwT3sn7Zeo+8/unvfw lYnA== 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=9HYcUGaGK/rNI8r2JbsD0klLxs3ZEExzxOON574yzO4=; b=uCSMe/886VhOEfygRtQuyTsA5EOH/LLyJlTaSsH1agwg/N8kwUXOL4yh0bCxwbsu4u y6U09U9oXSvG0fRBsQx81CTQxZWqZudB+QejFjfjuEJ2UGHLOMqaXkF52Yqp+IjiirIv NMD7Nr2PKLI1GcmZTYnNrzt46q7YNu9rKKozRVa4js8PL9kU7Ntg6mBPPmOpYSkeKYEE KJnD9nLqpS2kA5BfyQpNS0mNEo+gsO84S42f9x33XciS8DWknmnyjT0DNBJPbRK4Truy vToTEwYYjgBrC7PFereNvDdyEtZjcYIjwCAuPBFhAgN7dy+ED4xtXlF/ZNgHQO3HRw6v sR8A== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m15-20020a056512114f00b00489db719b30si51630lfg.11.2022.09.09.02.46.58; Fri, 09 Sep 2022 02:47:26 -0700 (PDT) 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 S231555AbiIIJ1d (ORCPT + 99 others); Fri, 9 Sep 2022 05:27:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231200AbiIIJ04 (ORCPT ); Fri, 9 Sep 2022 05:26:56 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECEE3979FD for ; Fri, 9 Sep 2022 02:25:30 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MP9TN6FrnzZcnt; Fri, 9 Sep 2022 17:20:56 +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.24; Fri, 9 Sep 2022 17:25:27 +0800 From: Miaohe Lin To: CC: , , , , Subject: [PATCH 06/16] mm/page_alloc: fix freeing static percpu memory Date: Fri, 9 Sep 2022 17:24:41 +0800 Message-ID: <20220909092451.24883-7-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220909092451.24883-1-linmiaohe@huawei.com> References: <20220909092451.24883-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500002.china.huawei.com (7.192.104.244) 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,T_SCC_BODY_TEXT_LINE 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 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 --- 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 3497919f4ef5..a35ef385d906 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -9510,9 +9510,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; + } } } -- 2.23.0