Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp21098362ybl; Sun, 5 Jan 2020 20:12:14 -0800 (PST) X-Google-Smtp-Source: APXvYqwH574MnJZZgQml6axV/w0x138dIP+Pqjv0qdECvacTNjAyfv5bEE01YhVm1DlQEHRgUNYH X-Received: by 2002:a9d:7501:: with SMTP id r1mr112251205otk.196.1578283934053; Sun, 05 Jan 2020 20:12:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578283934; cv=none; d=google.com; s=arc-20160816; b=CKwB8pQTALq/tVUB+H5IFHn2F4iw74okeZkZpDLJKoF4nWNIs6pM/tA9+loZKsHzYi uTQNUzrEmdW8IrWAtKtJwwKaBLF5sOuAJPL5roLjNmPT2ocC8cw5YANlJjzLaoS+1O7D cywD0NcPCf/99cKAtd/wSvxpPWyM5QpNvRR2Zo6viT0fkiX6koAzONCpqQRbWQF1BvLv zQ7UtrcV/oI0ifi1XHvLnzYVDrm/5x7FEup5EMKgCJm95gYglvV/RMQO7Fqg+luiugJ3 dnGu5lTaNsEU0C1aWmh88zVj5Tg4hUcsJE0t4rXSNuz+w3+OzKWwVCBYUgpD6racCAN4 4tDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=YTh2xx/02kvqDlpNWzb2bg7dm5lw5zcx3zgnOIw7HtM=; b=cZCrsLTfEzUmwqSIBwuaVkTlb8ChNKtaCmMjJdPn+jfnWap+aNbA7y7GVFeFiNfav6 BUBgTNQ+fbQ6Ziig8DfTcfGvy8eYwdHTidJaNT7UtoLHvWMcv1hALIAHiTDOdopAsHmv pN2GbOiUlLtDsU7npLV5Be9tgfSrwJdMqliNwWixIX12FHVFrAT/iMLAjdzur6KPZQvH pxTWp7eNX+SgIIvDWJC/dPcGfD7C2BRFwVnz8meonICfaoHemkd1QG7VXOcC3wskfp8h 3c8ji8kC0x6l8GemislbXhTPcYp0YQMsGTRbb3kZnsKcy/HkJRFqe2jmEgupPkcXrBIV 50xg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q127si30538454oic.99.2020.01.05.20.11.36; Sun, 05 Jan 2020 20:12:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727476AbgAFEJb (ORCPT + 99 others); Sun, 5 Jan 2020 23:09:31 -0500 Received: from foss.arm.com ([217.140.110.172]:40278 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727450AbgAFEJb (ORCPT ); Sun, 5 Jan 2020 23:09:31 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4ABC831B; Sun, 5 Jan 2020 20:09:30 -0800 (PST) Received: from p8cg001049571a15.blr.arm.com (p8cg001049571a15.blr.arm.com [10.162.41.131]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B32C83F534; Sun, 5 Jan 2020 20:09:26 -0800 (PST) From: Anshuman Khandual To: linux-mm@kvack.org Cc: Anshuman Khandual , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Martin Schwidefsky , Collin Walling , Gerald Schaefer , Philipp Rudo , Mike Rapoport , Andrew Morton , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/memblock: Define memblock_physmem_add() Date: Mon, 6 Jan 2020 09:40:35 +0530 Message-Id: <1578283835-21969-1-git-send-email-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On s390 platform memblock.physmem array is being built by directly calling into memblock_add_range() which is a low level function not intended to be used outside of memblock. Hence lets conditionally add helper functions for physmem array when HAVE_MEMBLOCK_PHYS_MAP is enabled. Also use MAX_NUMNODES instead of 0 as node ID similar to memblock_add() and memblock_reserve(). Make memblock_add_range() a static function as it is no longer getting used outside of memblock. Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Christian Borntraeger Cc: Martin Schwidefsky Cc: Collin Walling Cc: Gerald Schaefer Cc: Philipp Rudo Cc: Mike Rapoport Cc: Andrew Morton Cc: linux-s390@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual --- Only build tested for s390, will appreciate if some one can give it a try on a real system. Changes from RFC: - Dropped all memblock_dbg() changes per Mike - Renamed memblock_physmem() as memblock_physmem_add() per Mike - Made memblock_add_range() a static function per Mike - Updated the commit message RFC: (https://patchwork.kernel.org/patch/11316627/) arch/s390/kernel/setup.c | 12 +++--------- include/linux/memblock.h | 7 +++---- mm/memblock.c | 14 +++++++++++++- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c index b9104ae162f4..424cb8fd2c35 100644 --- a/arch/s390/kernel/setup.c +++ b/arch/s390/kernel/setup.c @@ -762,14 +762,6 @@ static void __init free_mem_detect_info(void) memblock_free(start, size); } -static void __init memblock_physmem_add(phys_addr_t start, phys_addr_t size) -{ - memblock_dbg("memblock_physmem_add: [%#016llx-%#016llx]\n", - start, start + size - 1); - memblock_add_range(&memblock.memory, start, size, 0, 0); - memblock_add_range(&memblock.physmem, start, size, 0, 0); -} - static const char * __init get_mem_info_source(void) { switch (mem_detect.info_source) { @@ -794,8 +786,10 @@ static void __init memblock_add_mem_detect_info(void) get_mem_info_source(), mem_detect.info_source); /* keep memblock lists close to the kernel */ memblock_set_bottom_up(true); - for_each_mem_detect_block(i, &start, &end) + for_each_mem_detect_block(i, &start, &end) { + memblock_add(start, end - start); memblock_physmem_add(start, end - start); + } memblock_set_bottom_up(false); memblock_dump_all(); } diff --git a/include/linux/memblock.h b/include/linux/memblock.h index b38bbefabfab..079d17d96410 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -113,6 +113,9 @@ int memblock_add(phys_addr_t base, phys_addr_t size); int memblock_remove(phys_addr_t base, phys_addr_t size); int memblock_free(phys_addr_t base, phys_addr_t size); int memblock_reserve(phys_addr_t base, phys_addr_t size); +#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP +int memblock_physmem_add(phys_addr_t base, phys_addr_t size); +#endif void memblock_trim_memory(phys_addr_t align); bool memblock_overlaps_region(struct memblock_type *type, phys_addr_t base, phys_addr_t size); @@ -127,10 +130,6 @@ void reset_node_managed_pages(pg_data_t *pgdat); void reset_all_zones_managed_pages(void); /* Low level functions */ -int memblock_add_range(struct memblock_type *type, - phys_addr_t base, phys_addr_t size, - int nid, enum memblock_flags flags); - void __next_mem_range(u64 *idx, int nid, enum memblock_flags flags, struct memblock_type *type_a, struct memblock_type *type_b, phys_addr_t *out_start, diff --git a/mm/memblock.c b/mm/memblock.c index 4bc2c7d8bf42..fc0d4db1d646 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -575,7 +575,7 @@ static void __init_memblock memblock_insert_region(struct memblock_type *type, * Return: * 0 on success, -errno on failure. */ -int __init_memblock memblock_add_range(struct memblock_type *type, +static int __init_memblock memblock_add_range(struct memblock_type *type, phys_addr_t base, phys_addr_t size, int nid, enum memblock_flags flags) { @@ -830,6 +830,18 @@ int __init_memblock memblock_reserve(phys_addr_t base, phys_addr_t size) return memblock_add_range(&memblock.reserved, base, size, MAX_NUMNODES, 0); } +#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP +int __init_memblock memblock_physmem_add(phys_addr_t base, phys_addr_t size) +{ + phys_addr_t end = base + size - 1; + + memblock_dbg("%s: [%pa-%pa] %pS\n", __func__, + &base, &end, (void *)_RET_IP_); + + return memblock_add_range(&memblock.physmem, base, size, MAX_NUMNODES, 0); +} +#endif + /** * memblock_setclr_flag - set or clear flag for a memory region * @base: base address of the region -- 2.20.1