Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp160812ybl; Thu, 9 Jan 2020 19:10:04 -0800 (PST) X-Google-Smtp-Source: APXvYqw66wWIMVTHUtmgsdtgutxW6YMUvJNsXeO91EVMvOflUJteAz2/KsxJ9JBZkV+kPD/XIst1 X-Received: by 2002:aca:7244:: with SMTP id p65mr562998oic.50.1578625804812; Thu, 09 Jan 2020 19:10:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578625804; cv=none; d=google.com; s=arc-20160816; b=Yl+sy9nK85OUxbY+Db28imxKANLQsOddm2Ai4Yy3IVUJAUQEDdTMcnb//jnIqVqX2V yItbwgyRtd9SN/47I3wlUjLl9l8Kdr5NOf2X5g7ki7kGaDf6gPWjuidX7qcaXWHH3FL0 et8RmTv+h+IuwEWlcKWi0xLyDy3/I019HQvV2wjqXLMQIWMIYYhIwJWEnb2PGTQk/K2d nOHvuoV5XAvBJJv3egrG+o/UkkiMOJVJyvhjuFAWo+9sV0d34jeUhc7Ni2fsW+7fynht ai2GIPKfdiu7Yt6fDTbXcCO2NqyrAW/NSNrnbeEev+5v/q6Dwyd8vRDH9sBksiWKhMBH 2INw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=oywqMvtEUyk/9NkCQ2crxjJLXNU65FpAT06cpgi/c1M=; b=z13w5r5vIexEzdAmKK51XtM7pGuotcNXtDRo+ZeDhDhyuGzy89pQ5Xy6g5LeHdUYco uqQxUPaJOoSeg/iJUxjvJfjK/7RQXUBTOwBxfRmvl/JJceLjyB85Pqr2VfJKJlqESlkh GhDG5K3JHc4H8fNDYrkvI28SGZNXCHmIfR4UEHyDThTDtX9+emhtCv5WPtxjK6cmA+iN XzFlPWkpDnFTGh3T5reNIvUL9WP4owenzFTNnkLP1Sd0NpDWOeYPc0hjLdsx8UHGEGAX Jn+TRXE393i/+YamrlmWUbV6NAbtnqRh8NuNgI5w+SGDtyHZFrP4XT/XuDT/a8QLqcwh PXYA== 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 o14si296289oie.257.2020.01.09.19.09.53; Thu, 09 Jan 2020 19:10:04 -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 S1731060AbgAJDIt (ORCPT + 99 others); Thu, 9 Jan 2020 22:08:49 -0500 Received: from foss.arm.com ([217.140.110.172]:38976 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730952AbgAJDIt (ORCPT ); Thu, 9 Jan 2020 22:08:49 -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 C8D211007; Thu, 9 Jan 2020 19:08:48 -0800 (PST) Received: from p8cg001049571a15.blr.arm.com (p8cg001049571a15.blr.arm.com [10.162.42.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 064CB3F703; Thu, 9 Jan 2020 19:08:40 -0800 (PST) From: Anshuman Khandual To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, akpm@linux-foundation.org, catalin.marinas@arm.com, will@kernel.org Cc: mark.rutland@arm.com, david@redhat.com, cai@lca.pw, logang@deltatee.com, cpandya@codeaurora.org, arunks@codeaurora.org, dan.j.williams@intel.com, mgorman@techsingularity.net, osalvador@suse.de, ard.biesheuvel@arm.com, steve.capper@arm.com, broonie@kernel.org, valentin.schneider@arm.com, Robin.Murphy@arm.com, steven.price@arm.com, suzuki.poulose@arm.com, ira.weiny@intel.com, Anshuman Khandual Subject: [PATCH V11 1/5] mm/hotplug: Introduce arch callback validating the hot remove range Date: Fri, 10 Jan 2020 08:39:11 +0530 Message-Id: <1578625755-11792-2-git-send-email-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1578625755-11792-1-git-send-email-anshuman.khandual@arm.com> References: <1578625755-11792-1-git-send-email-anshuman.khandual@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently there are two interfaces to initiate memory range hot removal i.e remove_memory() and __remove_memory() which then calls try_remove_memory(). Platform gets called with arch_remove_memory() to tear down required kernel page tables and other arch specific procedures. But there are platforms like arm64 which might want to prevent removal of certain specific memory ranges irrespective of their present usage or movability properties. Current arch call back arch_remove_memory() is too late in the process to abort memory hot removal as memory block devices and firmware memory map entries would have already been removed. Platforms should be able to abort the process before taking the mem_hotplug_lock with mem_hotplug_begin(). This essentially requires a new arch callback for memory range validation. This differentiates memory range validation between memory hot add and hot remove paths before carving out a new helper check_hotremove_memory_range() which incorporates a new arch callback. This call back provides platforms an opportunity to refuse memory removal at the very onset. In future the same principle can be extended for memory hot add path if required. Platforms can choose to override this callback in order to reject specific memory ranges from removal or can just fallback to a default implementation which allows removal of all memory ranges. Cc: Andrew Morton Signed-off-by: Anshuman Khandual --- include/linux/memory_hotplug.h | 7 +++++++ mm/memory_hotplug.c | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index ba0dca6..f661bd5 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -305,6 +305,13 @@ static inline void pgdat_resize_init(struct pglist_data *pgdat) {} #ifdef CONFIG_MEMORY_HOTREMOVE +#ifndef arch_memory_removable +static inline bool arch_memory_removable(u64 base, u64 size) +{ + return true; +} +#endif + extern bool is_mem_section_removable(unsigned long pfn, unsigned long nr_pages); extern void try_offline_node(int nid); extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index a91a072..7cdf800 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1014,6 +1014,23 @@ static int check_hotplug_memory_range(u64 start, u64 size) return 0; } +static int check_hotremove_memory_range(u64 start, u64 size) +{ + int rc; + + BUG_ON(check_hotplug_memory_range(start, size)); + + /* + * First check if the platform is willing to have this + * memory range removed else just abort. + */ + rc = arch_memory_removable(start, size); + if (!rc) + return -EINVAL; + + return 0; +} + static int online_memory_block(struct memory_block *mem, void *arg) { return device_online(&mem->dev); @@ -1762,7 +1779,9 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size) { int rc = 0; - BUG_ON(check_hotplug_memory_range(start, size)); + rc = check_hotremove_memory_range(start, size); + if (rc) + return rc; mem_hotplug_begin(); -- 2.7.4