From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D6A3C433DF for ; Sat, 17 Oct 2020 08:28:16 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BE2C720759 for ; Sat, 17 Oct 2020 08:28:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GS2lCNcT"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="rKwDw5MG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BE2C720759 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zaY23n4pqgcLlHxN3ZzCdOKPhj3XMh2sLhl4WwIyuvY=; b=GS2lCNcTSHfCd3KcdeoWJ2UML YFSOf8QVBIILMF6aChLOHKAH+tbuMYb3lxHRX+FItbbIUAjTZ+PDHfEUIICMpWex3e24zZ6F4Tt7V S3Dr2bC+jR4zf1zR3tyTurdIDwLWoplV4Sno1rINjsYYA4pzYt4s8HPYcjh3GUOELFmVLINbRogmu 74kvkUM1i2YyvkXRCc2qYB/CWk9MPk5DN9gnT471mQK94Wu1Z6BtIFMcpvvEUKdjby9ukDuW4SfQC yyh1L6V6EwZaVP0BSK07H2RmYK6DQTsGwB2impVz39tgJyWDXwjRZHoH/AeE8VFVvf2N/EhB6IQGU A4NIsG36g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kThXb-0004X8-On; Sat, 17 Oct 2020 08:26:15 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kThXX-0004Wn-35 for linux-arm-kernel@lists.infradead.org; Sat, 17 Oct 2020 08:26:13 +0000 Received: from kernel.org (unknown [87.71.73.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9380F20759; Sat, 17 Oct 2020 08:26:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602923168; bh=3nvs9MYdhboxp7AMcZpBlXWe6EssAqp62hsnyKaplHE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rKwDw5MGwYGJmzCeEEqmpzTnx4nc0RM4iwUcAR2no95MR5mzBezHIWQMP/jQUXzA/ wbe4i6QQOz1gltPcBLA9mCGO4h+TvOEdzuav3F+QI7S4HKlO3UhLV3YEIxan1zx5JE WwxA0ghilCtJYpoyieMaG9nUj5jB5GfTqtbaCaDk= Date: Sat, 17 Oct 2020 11:26:00 +0300 From: Mike Rapoport To: Sudarshan Rajagopalan Subject: Re: [PATCH 1/2] mm/memory_hotplug: allow marking of memory sections as hotpluggable Message-ID: <20201017082600.GB16395@kernel.org> References: <2cba881c51e42cfe5ba213e09273642136e8ef93.1602899443.git.sudaraja@codeaurora.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <2cba881c51e42cfe5ba213e09273642136e8ef93.1602899443.git.sudaraja@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201017_042611_250468_1E1DD85E X-CRM114-Status: GOOD ( 32.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , David Hildenbrand , Catalin Marinas , Anshuman Khandual , linux-kernel@vger.kernel.org, Steven Price , Suren Baghdasaryan , Logan Gunthorpe , Will Deacon , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Oct 16, 2020 at 07:02:23PM -0700, Sudarshan Rajagopalan wrote: > Certain architectures such as arm64 doesn't allow boot memory to be > offlined and removed. Distinguish certain memory sections as > "hotpluggable" which can be marked by module drivers stating to memory > hotplug layer that these sections can be offlined and then removed. I don't quite follow why marking sections as hotpluggable or not should be done by a device driver. Can you describe in more details your use-case and why there is a need to add a flag to the memory map? > This is done by using a separate section memory mab bit and setting it, > rather than clearing the existing SECTION_IS_EARLY bit. > This patch introduces SECTION_MARK_HOTPLUGGABLE bit into section mem map. > Only the allowed sections which are in movable zone and have unmovable > pages are allowed to be set with this new bit. > > Signed-off-by: Sudarshan Rajagopalan > Cc: Catalin Marinas > Cc: Will Deacon > Cc: Mike Rapoport > Cc: Anshuman Khandual > Cc: David Hildenbrand > Cc: Mark Rutland > Cc: Steven Price > Cc: Logan Gunthorpe > Cc: Suren Baghdasaryan > --- > include/linux/memory_hotplug.h | 1 + > include/linux/mmzone.h | 9 ++++++++- > mm/memory_hotplug.c | 20 ++++++++++++++++++++ > mm/sparse.c | 31 +++++++++++++++++++++++++++++++ > 4 files changed, 60 insertions(+), 1 deletion(-) > > diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h > index 375515803cd8..81df45b582c8 100644 > --- a/include/linux/memory_hotplug.h > +++ b/include/linux/memory_hotplug.h > @@ -319,6 +319,7 @@ extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); > extern int remove_memory(int nid, u64 start, u64 size); > extern void __remove_memory(int nid, u64 start, u64 size); > extern int offline_and_remove_memory(int nid, u64 start, u64 size); > +extern int mark_memory_hotpluggable(unsigned long start, unsigned long end); > > #else > static inline void try_offline_node(int nid) {} > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > index 8379432f4f2f..3df3a4975236 100644 > --- a/include/linux/mmzone.h > +++ b/include/linux/mmzone.h > @@ -1247,7 +1247,8 @@ extern size_t mem_section_usage_size(void); > #define SECTION_HAS_MEM_MAP (1UL<<1) > #define SECTION_IS_ONLINE (1UL<<2) > #define SECTION_IS_EARLY (1UL<<3) > -#define SECTION_MAP_LAST_BIT (1UL<<4) > +#define SECTION_MARK_HOTPLUGGABLE (1UL<<4) > +#define SECTION_MAP_LAST_BIT (1UL<<5) > #define SECTION_MAP_MASK (~(SECTION_MAP_LAST_BIT-1)) > #define SECTION_NID_SHIFT 3 > > @@ -1278,6 +1279,11 @@ static inline int early_section(struct mem_section *section) > return (section && (section->section_mem_map & SECTION_IS_EARLY)); > } > > +static inline int removable_section(struct mem_section *section) > +{ > + return (section && (section->section_mem_map & SECTION_MARK_HOTPLUGGABLE)); > +} > + > static inline int valid_section_nr(unsigned long nr) > { > return valid_section(__nr_to_section(nr)); > @@ -1297,6 +1303,7 @@ static inline int online_section_nr(unsigned long nr) > void online_mem_sections(unsigned long start_pfn, unsigned long end_pfn); > #ifdef CONFIG_MEMORY_HOTREMOVE > void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn); > +int section_mark_hotpluggable(struct mem_section *ms); > #endif > #endif > > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index e9d5ab5d3ca0..503b0de489a0 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -1860,4 +1860,24 @@ int offline_and_remove_memory(int nid, u64 start, u64 size) > return rc; > } > EXPORT_SYMBOL_GPL(offline_and_remove_memory); > + > +int mark_memory_hotpluggable(unsigned long start_pfn, unsigned long end_pfn) > +{ > + struct mem_section *ms; > + unsigned long nr; > + int rc = -EINVAL; > + > + if (end_pfn < start_pfn) > + return rc; > + > + for (nr = start_pfn; nr <= end_pfn; nr++) { > + ms = __pfn_to_section(nr); > + rc = section_mark_hotpluggable(ms); > + if (!rc) > + break; > + } > + > + return rc; > +} > +EXPORT_SYMBOL_GPL(mark_memory_hotpluggable); > #endif /* CONFIG_MEMORY_HOTREMOVE */ > diff --git a/mm/sparse.c b/mm/sparse.c > index fcc3d176f1ea..cc21c23e2f1d 100644 > --- a/mm/sparse.c > +++ b/mm/sparse.c > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > > #include "internal.h" > #include > @@ -644,6 +645,36 @@ void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn) > ms->section_mem_map &= ~SECTION_IS_ONLINE; > } > } > + > +int section_mark_hotpluggable(struct mem_section *ms) > +{ > + unsigned long section_nr, pfn; > + bool unmovable; > + struct page *page; > + > + /* section needs to be both valid and present to be marked */ > + if (WARN_ON(!valid_section(ms)) || !present_section(ms)) > + return -EINVAL; > + > + /* > + * now check if this section is removable. This can be done by checking > + * if section has unmovable pages or not. > + */ > + section_nr = __section_nr(ms); > + pfn = section_nr_to_pfn(section_nr); > + page = pfn_to_page(pfn); > + unmovable = has_unmovable_pages(page_zone(page), page, > + MIGRATE_MOVABLE, MEMORY_OFFLINE | REPORT_FAILURE); > + if (unmovable) { > + pr_info("section %lu has unmovable pages. Cannot be marked as hotpluggable\n"); > + return -EINVAL; > + } > + > + /* all good! mark section as hotpluggable */ > + ms->section_mem_map |= SECTION_MARK_HOTPLUGGABLE; > + > + return 0; > +} > #endif > > #ifdef CONFIG_SPARSEMEM_VMEMMAP > -- > Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, > a Linux Foundation Collaborative Project > -- Sincerely yours, Mike. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel