Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1728427pxj; Wed, 19 May 2021 12:28:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdaEkFwdTQWv3aH/aCUNCeNxA+cWclB0ROZnKoegnD7vQgqa7VxoBiHwqVjHvPvZghPVow X-Received: by 2002:a05:6638:2243:: with SMTP id m3mr724489jas.88.1621452493329; Wed, 19 May 2021 12:28:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621452493; cv=none; d=google.com; s=arc-20160816; b=VUMQ2FqCLhYqr1HS540HTJcr/8GxjwcloqBDcfKMlCjTFsYw0TqlLT5XEibGWequP4 mx6An5aDVV7YiAV7UbNXqfPowNMSyX3/qWrwKt6BtNHLMFtHRirCn6//aLtvDKEgLJIi Izp0zphCuCDXWP7SUY19w7ZMjX2kEK0eaV5faD/cweh5DFOme8iqCJA0gCM6QH/L0zUc 5Poa5EcI0ToHnw6qlk0CLLBR1gletysEb5KwZ9/3ztsJ3d7XPPQ770SbYZnTUnl11svu H+E67jkP6lhVjrg0u//JMwNMJQKvta4SWIUHEWTsj1cYnSwXmgMjHl/N4oJ7opZDYTAh UUzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=Gc5w6U5NRPemdtc5P+DWJt4Z6ssoYX0goIlJQQyor5Q=; b=z2PILW3qxtUHeCVEbA2AjH6x+FVzqT8GCQqxe2yUk+snacGT8naqy6pbjFuynPek4X grgQPfM/urqS7glaHEvL/T8WMpK2dB9s3d7qh0LVPKFuGzTNuK+0rxME/bb41y/0pKpJ 3odrHbliuBZ1h6Zl6HltLTdkZh//q7d/tTXnUGeoao594KLEn8jnRhe0GIBMqPkdw1NW l06e0JQ9rapXR5167QPFsjZ8Z0RXvi03nDnMVRTRCamF273IQjo8lSJHLkKtmr7SosAa VxU5JajGq6z1RI3bHDw1AmiA1CAdnjRIL+YGPnITIV7ON7sW9ll8ijbq8puoClf+r682 PIpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c11si179083jaq.7.2021.05.19.12.28.01; Wed, 19 May 2021 12:28:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240020AbhESK5d (ORCPT + 99 others); Wed, 19 May 2021 06:57:33 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:43084 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229720AbhESK5d (ORCPT ); Wed, 19 May 2021 06:57:33 -0400 X-UUID: 7fe39ef1c05a4eee9c028761d6bc8ecf-20210519 X-UUID: 7fe39ef1c05a4eee9c028761d6bc8ecf-20210519 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1392854785; Wed, 19 May 2021 18:56:11 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 19 May 2021 18:56:10 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 19 May 2021 18:56:10 +0800 From: Miles Chen To: Andrew Morton , Mike Rapoport CC: , , , , Miles Chen , Baoquan He , Kazu Subject: [PATCH v2] mm/sparse: fix check_usemap_section_nr warnings Date: Wed, 19 May 2021 18:56:08 +0800 Message-ID: <20210519105608.23806-1-miles.chen@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I see a "virt_to_phys used for non-linear address" warning from check_usemap_section_nr() on arm64 platforms. In current implementation of NODE_DATA, if CONFIG_NEED_MULTIPLE_NODES=y, pglist_data is dynamically allocated and assigned to node_data[]. For example, in arch/arm64/include/asm/mmzone.h: extern struct pglist_data *node_data[]; \#define NODE_DATA(nid) (node_data[(nid)]) If CONFIG_NEED_MULTIPLE_NODES=n, pglist_data is defined as a global variable named "contig_page_data". For example, in include/linux/mmzone.h: extern struct pglist_data contig_page_data; \#define NODE_DATA(nid) (&contig_page_data) If CONFIG_DEBUG_VIRTUAL is not enabled, __pa() can handle both dynamically allocated linear addresses and symbol addresses. However, if (CONFIG_DEBUG_VIRTUAL=y && CONFIG_NEED_MULTIPLE_NODES=n) ,we can see the "virt_to_phys used for non-linear address" warning because that &contig_page_data is not a linear address on arm64. To fix it, create a small function to handle both translation. Warning message: [ 0.000000] ------------[ cut here ]------------ [ 0.000000] virt_to_phys used for non-linear address: (____ptrval____) (contig_page_data+0x0/0x1c00) [ 0.000000] WARNING: CPU: 0 PID: 0 at arch/arm64/mm/physaddr.c:15 __virt_to_phys+0x58/0x68 [ 0.000000] Modules linked in: [ 0.000000] CPU: 0 PID: 0 Comm: swapper Tainted: G W 5.13.0-rc1-00074-g1140ab592e2e #3 [ 0.000000] Hardware name: linux,dummy-virt (DT) [ 0.000000] pstate: 600000c5 (nZCv daIF -PAN -UAO -TCO BTYPE=--) [ 0.000000] pc : __virt_to_phys+0x58/0x68 [ 0.000000] lr : __virt_to_phys+0x54/0x68 [ 0.000000] sp : ffff800011833e70 [ 0.000000] x29: ffff800011833e70 x28: 00000000418a0018 x27: 0000000000000000 [ 0.000000] x26: 000000000000000a x25: ffff800011b70000 x24: ffff800011b70000 [ 0.000000] x23: fffffc0001c00000 x22: ffff800011b70000 x21: 0000000047ffffb0 [ 0.000000] x20: 0000000000000008 x19: ffff800011b082c0 x18: ffffffffffffffff [ 0.000000] x17: 0000000000000000 x16: ffff800011833bf9 x15: 0000000000000004 [ 0.000000] x14: 0000000000000fff x13: ffff80001186a548 x12: 0000000000000000 [ 0.000000] x11: 0000000000000000 x10: 00000000ffffffff x9 : 0000000000000000 [ 0.000000] x8 : ffff8000115c9000 x7 : 737520737968705f x6 : ffff800011b62ef8 [ 0.000000] x5 : 0000000000000000 x4 : 0000000000000001 x3 : 0000000000000000 [ 0.000000] x2 : 0000000000000000 x1 : ffff80001159585e x0 : 0000000000000058 [ 0.000000] Call trace: [ 0.000000] __virt_to_phys+0x58/0x68 [ 0.000000] check_usemap_section_nr+0x50/0xfc [ 0.000000] sparse_init_nid+0x1ac/0x28c [ 0.000000] sparse_init+0x1c4/0x1e0 [ 0.000000] bootmem_init+0x60/0x90 [ 0.000000] setup_arch+0x184/0x1f0 [ 0.000000] start_kernel+0x78/0x488 [ 0.000000] ---[ end trace f68728a0d3053b60 ]--- Cc: Mike Rapoport Cc: Baoquan He Cc: Kazu Signed-off-by: Miles Chen --- Change since v1: 1) change "kzmalloc" to "dynamically allocated" 2) describe the issue in detail --- mm/sparse.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index b2ada9dc00cb..55c18aff3e42 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -344,6 +344,15 @@ size_t mem_section_usage_size(void) return sizeof(struct mem_section_usage) + usemap_size(); } +static inline phys_addr_t pgdat_to_phys(struct pglist_data *pgdat) +{ +#ifndef CONFIG_NEED_MULTIPLE_NODES + return __pa_symbol(pgdat); +#else + return __pa(pgdat); +#endif +} + #ifdef CONFIG_MEMORY_HOTREMOVE static struct mem_section_usage * __init sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat, @@ -362,7 +371,7 @@ sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat, * from the same section as the pgdat where possible to avoid * this problem. */ - goal = __pa(pgdat) & (PAGE_SECTION_MASK << PAGE_SHIFT); + goal = pgdat_to_phys(pgdat) & (PAGE_SECTION_MASK << PAGE_SHIFT); limit = goal + (1UL << PA_SECTION_SHIFT); nid = early_pfn_to_nid(goal >> PAGE_SHIFT); again: @@ -390,7 +399,7 @@ static void __init check_usemap_section_nr(int nid, } usemap_snr = pfn_to_section_nr(__pa(usage) >> PAGE_SHIFT); - pgdat_snr = pfn_to_section_nr(__pa(pgdat) >> PAGE_SHIFT); + pgdat_snr = pfn_to_section_nr(pgdat_to_phys(pgdat) >> PAGE_SHIFT); if (usemap_snr == pgdat_snr) return; -- 2.18.0