From patchwork Tue Dec 11 18:48:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 10724453 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D9C814E2 for ; Tue, 11 Dec 2018 18:48:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 017432A6AB for ; Tue, 11 Dec 2018 18:48:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8FEF2A752; Tue, 11 Dec 2018 18:48:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8E502A6AB for ; Tue, 11 Dec 2018 18:48:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 06DB08E00CA; Tue, 11 Dec 2018 13:48:56 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 01DD78E00C9; Tue, 11 Dec 2018 13:48:55 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E769A8E00CA; Tue, 11 Dec 2018 13:48:55 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by kanga.kvack.org (Postfix) with ESMTP id BDCE68E00C9 for ; Tue, 11 Dec 2018 13:48:55 -0500 (EST) Received: by mail-oi1-f200.google.com with SMTP id u63so8142464oie.17 for ; Tue, 11 Dec 2018 10:48:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:mime-version:content-transfer-encoding; bh=KvVDX8E0f069tJcVnJ8W2TJiyXT541lmLCd8yDBBRr8=; b=CjXlir5p6MxStduZalJ/dXbN6xcwK3sPKocKUhfdx5y4Njqxj+cYd2imsO/4r44Zrp XfuqanuyE9Fe1dY6JrqHRT1NbSLe7OR7gGbFCKhzHoi2Fmt0+RWFGH/qrOsggOXms+6T g1wC/dtLHtPZeF9QcbX1vTOHdA4YifW7Elt+riBb300GUyrrGNKJTd/QG+ALYGLDPQAe Snm76v997NG8oFnDNNT+3s2Y6IqTwIu8aJ3plE/tNQ2R9aE8cIaxjvrsJjM2SJaTiypP E7XLq2dZNTp84dBNM9OtWIcIumgy1KVC5yrSx6dpoqBAjfu2jOuNjkG6mXWQMySveMyR sB3w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of robin.murphy@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=robin.murphy@arm.com X-Gm-Message-State: AA+aEWbmdFOFy4ZwT94mBCvRDNsSTRdEHQuTj24+OnoYLu4y6SqIkVbn Q5+4aTombJf39L3n8iXcAAhkuzeftqHsXw/1Ch/6DdB8dTy9WkLAQ3B1bO9gAE3HeeBPbSKmRV0 ElGen0sycAU4XnBMt1GMdIrcHCEmZ9ft7MitCSVs8niqC+u/KlvG/kGMXVupGb0E9GQ== X-Received: by 2002:a9d:128b:: with SMTP id g11mr11851792otg.130.1544554135485; Tue, 11 Dec 2018 10:48:55 -0800 (PST) X-Google-Smtp-Source: AFSGD/WIhJD7EhzRZC9pv2FcWlPUhKpsFfMR44ubSCfIcAujGE2FehWTEnQxCs2rdN/E5kldKnXz X-Received: by 2002:a9d:128b:: with SMTP id g11mr11851766otg.130.1544554134744; Tue, 11 Dec 2018 10:48:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544554134; cv=none; d=google.com; s=arc-20160816; b=VBqYq4JyoJ7jAkjL7Ubw2SnwEemBtgHQRs8pQAQJ7TJyNCYkykNdGkivet6BB+bs2v 6s5LcKaSLOuYwt9PP5izCrRkddy++K07QsHR4uomO94AGWnn5NtY5g9ZYSsFS85Lecii TQZVK5FTrUqe6ALa2ERQSdsTwV+NCqas7C4ZRUdklDrlPJjf7baYO12TIZ1LCB2N7XxU CUAlTu2tcK9A4TKu2GfyHjryymqoaXWbMdMUmITdyMFgS5mcAh3TurF+MnDj112B1nfL UV/cSlDiGS3jEoJTG9QosS6vmCrN8iBSe1tR2SIHsDzZ/iJn7KJ8GhgcQtSIPQjY66VD 7sfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from; bh=KvVDX8E0f069tJcVnJ8W2TJiyXT541lmLCd8yDBBRr8=; b=Spvn7Bw3VhY7EMbiNwC5qiK0U0qSYk91w+9JuCc6F8S+vty/CcBL/mmqn7j04Yav1Q JuSGojNXj8FeWuyh9HzPrvubvgUa8hE/WXKUInLdFUMSozYIdIbwYUL3Cje5Ip8nHbjf uHuFNQPwuxn59cUi7te2eyxPVv8UDJ0KVZ+/dnDja2ScQ6TahZovCgKvdnQqcDZJDRfM YfjkKKgGbVGVUKE6lIGuVkFSdUiIoOiUk+KJZKEmUBd4a0l68W1yJGHAwspYEFTt7UqF suogDtX+vhqmNT1UoSmRoz/hMgHQThHg+p9NOdspFyT/Wo7G1EtMxNw5fA7NSWHcQP6A yRzA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of robin.murphy@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=robin.murphy@arm.com Received: from foss.arm.com (usa-sjc-mx-foss1.foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id s205si5921129oie.38.2018.12.11.10.48.54 for ; Tue, 11 Dec 2018 10:48:54 -0800 (PST) Received-SPF: pass (google.com: domain of robin.murphy@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of robin.murphy@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=robin.murphy@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D75CFEBD; Tue, 11 Dec 2018 10:48:53 -0800 (PST) Received: from e110467-lin.cambridge.arm.com (e110467-lin.cambridge.arm.com [10.1.196.75]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 381563F6A8; Tue, 11 Dec 2018 10:48:52 -0800 (PST) From: Robin Murphy To: will.deacon@arm.com, catalin.marinas@arm.com Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, jonathan.cameron@huawei.com, cyrilc@xilinx.com, james.morse@arm.com, anshuman.khandual@arm.com, linux-mm@kvack.org Subject: [PATCH v2] arm64: Add memory hotplug support Date: Tue, 11 Dec 2018 18:48:48 +0000 Message-Id: <331db1485b4c8c3466217e16a1e1f05618e9bae8.1544553902.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.19.1.dirty MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP Wire up the basic support for hot-adding memory. Since memory hotplug is fairly tightly coupled to sparsemem, we tweak pfn_valid() to also cross-check the presence of a section in the manner of the generic implementation, before falling back to memblock to check for no-map regions within a present section as before. By having arch_add_memory(() create the linear mapping first, this then makes everything work in the way that __add_section() expects. We expect hotplug to be ACPI-driven, so the swapper_pg_dir updates should be safe from races by virtue of the global device hotplug lock. Signed-off-by: Robin Murphy Tested-by: Jonathan Cameron --- v2: Handle page-mappings-only cases appropriately arch/arm64/Kconfig | 3 +++ arch/arm64/mm/init.c | 8 ++++++++ arch/arm64/mm/mmu.c | 17 +++++++++++++++++ arch/arm64/mm/numa.c | 10 ++++++++++ 4 files changed, 38 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 4dbef530cf58..be423fda5cec 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -261,6 +261,9 @@ config ZONE_DMA32 config HAVE_GENERIC_GUP def_bool y +config ARCH_ENABLE_MEMORY_HOTPLUG + def_bool y + config SMP def_bool y diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 6cde00554e9b..4bfe0fc9edac 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -291,6 +291,14 @@ int pfn_valid(unsigned long pfn) if ((addr >> PAGE_SHIFT) != pfn) return 0; + +#ifdef CONFIG_SPARSEMEM + if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS) + return 0; + + if (!valid_section(__nr_to_section(pfn_to_section_nr(pfn)))) + return 0; +#endif return memblock_is_map_memory(addr); } EXPORT_SYMBOL(pfn_valid); diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 674c409a8ce4..da513a1facf4 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1046,3 +1046,20 @@ int pud_free_pmd_page(pud_t *pudp, unsigned long addr) pmd_free(NULL, table); return 1; } + +#ifdef CONFIG_MEMORY_HOTPLUG +int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, + bool want_memblock) +{ + int flags = 0; + + if (rodata_full || debug_pagealloc_enabled()) + flags = NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; + + __create_pgd_mapping(swapper_pg_dir, start, __phys_to_virt(start), + size, PAGE_KERNEL, pgd_pgtable_alloc, flags); + + return __add_pages(nid, start >> PAGE_SHIFT, size >> PAGE_SHIFT, + altmap, want_memblock); +} +#endif diff --git a/arch/arm64/mm/numa.c b/arch/arm64/mm/numa.c index 27a31efd9e8e..ae34e3a1cef1 100644 --- a/arch/arm64/mm/numa.c +++ b/arch/arm64/mm/numa.c @@ -466,3 +466,13 @@ void __init arm64_numa_init(void) numa_init(dummy_numa_init); } + +/* + * We hope that we will be hotplugging memory on nodes we already know about, + * such that acpi_get_node() succeeds and we never fall back to this... + */ +int memory_add_physaddr_to_nid(u64 addr) +{ + pr_warn("Unknown node for memory at 0x%llx, assuming node 0\n", addr); + return 0; +}