From patchwork Thu Jul 6 08:50:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 13303389 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2E6FEB64D9 for ; Thu, 6 Jul 2023 09:04:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 492F98D0005; Thu, 6 Jul 2023 05:04:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 442FA8D0001; Thu, 6 Jul 2023 05:04:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E64E8D0005; Thu, 6 Jul 2023 05:04:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1E1DA8D0001 for ; Thu, 6 Jul 2023 05:04:54 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E47AF1C8F45 for ; Thu, 6 Jul 2023 09:04:53 +0000 (UTC) X-FDA: 80980602066.16.699058B Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf25.hostedemail.com (Postfix) with ESMTP id 93014A0004 for ; Thu, 6 Jul 2023 09:04:51 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=EZWxo9+z; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf25.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688634291; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=O/+NIHsmH+q4b9QJCEQ09zAxuImTZVSIxeXyQXIppyA=; b=snZgACwXdFwJrsvTmVmmrEX65DM20fEoDc+1gLS3mF5mB6DilC+UcZVfXZ4iSSKkZAEWLY AIG+rER89Ppqy/Oul/mCEqmGa6nJpXPKMfxTEIJf0fV/yFIHlJLSf9pPxix1QI+6d+cIix /IPHJsDEuToaesl0mf8EszJH90wJUv0= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=EZWxo9+z; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf25.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688634291; a=rsa-sha256; cv=none; b=MRscZ4zs8Tj9W8oV0BecrGzqZZpusdLdv0zy1c3mklp6rdRm5z9xesp0xqJby4TM+uB3up 4OB/7IwquEBJRE6SWalMIbswefjC3CCwUbNZRdtE5ZVBbWv3wbCZ1kZngOTGc712iWIj3m ia6BuNaijFxY9vt+HrriHTwTL1NtZEI= Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3668wcjs021260; Thu, 6 Jul 2023 09:04:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=O/+NIHsmH+q4b9QJCEQ09zAxuImTZVSIxeXyQXIppyA=; b=EZWxo9+z2N6d7/pH4wpxx5j2HWz8ruubVzE/DFEPwemsFisKk013dtp0YpVuvCWr9Ecw 5lRilpmfCXnHm8PKPm3+XdYLNCHZMtV8DaEfPqLhy93p8s6tjD7OsiBeX7GSAxK4Q8Fy /gIqfvJA97NZjyR7bPhXz/4KCrrhtiqUSXnb3ylF+LGvVDPMZix/uFbYldig563gWCYM QTlJe7KA/Vbf+klfru5J55afNIvrYTs58+pG8IMS6TRMK6FCob6Ki4Aj++5Gb5Fx1ACV tz+tgLqsOp4x+WGK5AKEtXKMG3rkY3pOW72Dqi8Ha5V97jnnLQFRzcPjnrZx85yezS6+ Qg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rntjv843u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Jul 2023 09:04:42 +0000 Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3668xZ5I025076; Thu, 6 Jul 2023 09:04:41 GMT Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rntjv8432-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Jul 2023 09:04:41 +0000 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 366866ZB017422; Thu, 6 Jul 2023 08:51:05 GMT Received: from smtprelay07.wdc07v.mail.ibm.com ([9.208.129.116]) by ppma03wdc.us.ibm.com (PPS) with ESMTPS id 3rjbs5ywrm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Jul 2023 08:51:05 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay07.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3668p4nY64356792 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 6 Jul 2023 08:51:04 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 32FEE5805D; Thu, 6 Jul 2023 08:51:04 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4FDE258057; Thu, 6 Jul 2023 08:51:00 +0000 (GMT) Received: from skywalker.in.ibm.com (unknown [9.109.212.144]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Thu, 6 Jul 2023 08:50:59 +0000 (GMT) From: "Aneesh Kumar K.V" To: linux-mm@kvack.org, akpm@linux-foundation.org, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, npiggin@gmail.com, christophe.leroy@csgroup.eu Cc: Oscar Salvador , David Hildenbrand , Michal Hocko , Vishal Verma , "Aneesh Kumar K.V" Subject: [PATCH v2 1/5] mm/hotplug: Embed vmem_altmap details in memory block Date: Thu, 6 Jul 2023 14:20:37 +0530 Message-ID: <20230706085041.826340-2-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230706085041.826340-1-aneesh.kumar@linux.ibm.com> References: <20230706085041.826340-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 3PrySruIznShIalK4Nj5VTvcvWY-MIw4 X-Proofpoint-GUID: 97ziFc4pemDXgK3nV0F6sNLEuBhkrYfW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-06_05,2023-07-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 clxscore=1015 priorityscore=1501 phishscore=0 suspectscore=0 bulkscore=0 mlxlogscore=535 spamscore=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307060080 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 93014A0004 X-Stat-Signature: 5arkxq3nb6h4s7ero1wcdgzjgqyxzctm X-HE-Tag: 1688634291-383447 X-HE-Meta: U2FsdGVkX18iRKj0hkvKbHNSNUIorl9JCg7ZaK4Glv3amAAyAHDY4FecdBpA6qWo7WFbIFVYiLhyujJ83+hTnBR260nR+8JIjYSpnpFfWk6vJV4pEv6Fn6JpLhG5jaHt1SafAFzRZ+RQGvn2s5roUKou/2m8czAIK8ahgZxFOxXC5Gpb/Zl1ddmA2kV1Hm6N8dNm/n55HfSgHny9ltnGfJfJ0G5Evd6p7PxfMi169M+9CKcHfrVXfGGDwQiih5LbOE/nsPw74AkTKXJ+vUY43+1069ISMAZwbiE1tTI+KBTC4rh4Y0AL/+/ccOSl1IeFV3vkbiUVo3mJtDvIl8BluMHnisZOp6Ttyoc3knXwRozdoTRNKT0PlNuknfV9NQn0XUTMD+OqcN+CSi9z6hc/6wiG3T5tm3CaoIzkTEf/P/WhFSTiqKiGq0Ox5wSbbuyPGgW3euKfmO6RXqeacrt6B69wpCXHBM0ZoSBij+E962D2to3xcoMgD9/HE/kDHQAvISs4wuTRnqGbasyGPcusgiuzP/THU6woBsXtu8hstkgDdblJUfFk30CNdIDFy6Jj4sNaztNPsjg4aFLpTHuPZyZ6I6WN2XFmcEsTMJlQdQGZ5ZCjTfshpB+z6ptlQLLpwfhDzKzGVlkBRvPbuYu7inTSXc1wVKPgytWuE2rgTVtLlICRmd9c3vxHEAjtSFqqjFYq5sWAb6MwgOHIPs+mTzWK1ZwJ1D7B36gV4hFjj8vCYe1pOeTwpy+UcP3HLg2/ESOCtKq45w3Ic6Hzry6gH7oXz4qJzIGQwRIsTYTCt2lC+O2Z5YYHAYsNxLQdYqTabTCLLljGLamOVPkmOIoSs3zEI+kteb0AnIhwaXnR70OsHwyPt+m9qlGFgkjWwISQcO9gHvJ/jQe9uHoiidoeIVV7xHwKmc2lSHGMAcLJ/YnbHtsdmbS67WeZF/gKWE8BpQZjVOKIsEqN2DEvoRv dHZVpOay 3wA0FHz3fPJeIj94W/WR2gWUPIrcs1YLBQEVFwA6MXXG3fa0Qr2DCS8cEMDxrCA0aDFUR6Cp+zrYJ7OYI935NxLPqNuS0+T3axPSPqodi+z6GtLaKb878J+V+IWPABDGOF0M1uP57Z5KNdEoAwkN72ln6pqRg88kxi56mgCo0fEK1bsN0FENtYE2gtO8qxUf0bLxKkmAmrynXt7lAqxLkzbTVIduSRFZR2HX+P+fjbHY4n0MjrDvv46oVMoYhCPICmXuSTO6K827rl2zChPGrIh/WDA== 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: With memmap on memory, some architecture needs more details w.r.t altmap such as base_pfn, end_pfn, etc to unmap vmemmap memory. Embed vmem_altmap data structure to memory_bock and use that instead of nr_vmemmap_pages. On memory unplug, if the kernel finds any memory block in the range to be using vmem_altmap, the kernel fails to unplug the memory if the request is not a single memory block unplug. Signed-off-by: Aneesh Kumar K.V --- drivers/base/memory.c | 28 +++++++++++++++++++--------- include/linux/memory.h | 25 +++++++++++++++++++------ include/linux/memremap.h | 18 +----------------- mm/memory_hotplug.c | 31 ++++++++++++++----------------- 4 files changed, 53 insertions(+), 49 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index b456ac213610..523cc1d37c81 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -106,6 +106,7 @@ static void memory_block_release(struct device *dev) { struct memory_block *mem = to_memory_block(dev); + WARN(mem->altmap.alloc, "Altmap not fully unmapped"); kfree(mem); } @@ -183,7 +184,7 @@ static int memory_block_online(struct memory_block *mem) { unsigned long start_pfn = section_nr_to_pfn(mem->start_section_nr); unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block; - unsigned long nr_vmemmap_pages = mem->nr_vmemmap_pages; + unsigned long nr_vmemmap_pages = 0; struct zone *zone; int ret; @@ -200,6 +201,9 @@ static int memory_block_online(struct memory_block *mem) * stage helps to keep accounting easier to follow - e.g vmemmaps * belong to the same zone as the memory they backed. */ + if (mem->altmap.alloc) + nr_vmemmap_pages = mem->altmap.alloc + mem->altmap.reserve; + if (nr_vmemmap_pages) { ret = mhp_init_memmap_on_memory(start_pfn, nr_vmemmap_pages, zone); if (ret) @@ -230,7 +234,7 @@ static int memory_block_offline(struct memory_block *mem) { unsigned long start_pfn = section_nr_to_pfn(mem->start_section_nr); unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block; - unsigned long nr_vmemmap_pages = mem->nr_vmemmap_pages; + unsigned long nr_vmemmap_pages = 0; int ret; if (!mem->zone) @@ -240,6 +244,9 @@ static int memory_block_offline(struct memory_block *mem) * Unaccount before offlining, such that unpopulated zone and kthreads * can properly be torn down in offline_pages(). */ + if (mem->altmap.alloc) + nr_vmemmap_pages = mem->altmap.alloc + mem->altmap.reserve; + if (nr_vmemmap_pages) adjust_present_page_count(pfn_to_page(start_pfn), mem->group, -nr_vmemmap_pages); @@ -726,7 +733,7 @@ void memory_block_add_nid(struct memory_block *mem, int nid, #endif static int add_memory_block(unsigned long block_id, unsigned long state, - unsigned long nr_vmemmap_pages, + struct vmem_altmap *altmap, struct memory_group *group) { struct memory_block *mem; @@ -744,7 +751,10 @@ static int add_memory_block(unsigned long block_id, unsigned long state, mem->start_section_nr = block_id * sections_per_block; mem->state = state; mem->nid = NUMA_NO_NODE; - mem->nr_vmemmap_pages = nr_vmemmap_pages; + if (altmap) + memcpy(&mem->altmap, altmap, sizeof(*altmap)); + else + mem->altmap.alloc = 0; INIT_LIST_HEAD(&mem->group_next); #ifndef CONFIG_NUMA @@ -783,14 +793,14 @@ static int __init add_boot_memory_block(unsigned long base_section_nr) if (section_count == 0) return 0; return add_memory_block(memory_block_id(base_section_nr), - MEM_ONLINE, 0, NULL); + MEM_ONLINE, NULL, NULL); } static int add_hotplug_memory_block(unsigned long block_id, - unsigned long nr_vmemmap_pages, + struct vmem_altmap *altmap, struct memory_group *group) { - return add_memory_block(block_id, MEM_OFFLINE, nr_vmemmap_pages, group); + return add_memory_block(block_id, MEM_OFFLINE, altmap, group); } static void remove_memory_block(struct memory_block *memory) @@ -818,7 +828,7 @@ static void remove_memory_block(struct memory_block *memory) * Called under device_hotplug_lock. */ int create_memory_block_devices(unsigned long start, unsigned long size, - unsigned long vmemmap_pages, + struct vmem_altmap *altmap, struct memory_group *group) { const unsigned long start_block_id = pfn_to_block_id(PFN_DOWN(start)); @@ -832,7 +842,7 @@ int create_memory_block_devices(unsigned long start, unsigned long size, return -EINVAL; for (block_id = start_block_id; block_id != end_block_id; block_id++) { - ret = add_hotplug_memory_block(block_id, vmemmap_pages, group); + ret = add_hotplug_memory_block(block_id, altmap, group); if (ret) break; } diff --git a/include/linux/memory.h b/include/linux/memory.h index 31343566c221..87f12924250f 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -64,6 +64,23 @@ struct memory_group { }; }; +/** + * struct vmem_altmap - pre-allocated storage for vmemmap_populate + * @base_pfn: base of the entire dev_pagemap mapping + * @reserve: pages mapped, but reserved for driver use (relative to @base) + * @free: free pages set aside in the mapping for memmap storage + * @align: pages reserved to meet allocation alignments + * @alloc: track pages consumed, private to vmemmap_populate() + */ +struct vmem_altmap { + unsigned long base_pfn; + const unsigned long end_pfn; + const unsigned long reserve; + unsigned long free; + unsigned long align; + unsigned long alloc; +}; + struct memory_block { unsigned long start_section_nr; unsigned long state; /* serialized by the dev->lock */ @@ -77,11 +94,7 @@ struct memory_block { */ struct zone *zone; struct device dev; - /* - * Number of vmemmap pages. These pages - * lay at the beginning of the memory block. - */ - unsigned long nr_vmemmap_pages; + struct vmem_altmap altmap; struct memory_group *group; /* group (if any) for this block */ struct list_head group_next; /* next block inside memory group */ #if defined(CONFIG_MEMORY_FAILURE) && defined(CONFIG_MEMORY_HOTPLUG) @@ -147,7 +160,7 @@ static inline int hotplug_memory_notifier(notifier_fn_t fn, int pri) extern int register_memory_notifier(struct notifier_block *nb); extern void unregister_memory_notifier(struct notifier_block *nb); int create_memory_block_devices(unsigned long start, unsigned long size, - unsigned long vmemmap_pages, + struct vmem_altmap *altmap, struct memory_group *group); void remove_memory_block_devices(unsigned long start, unsigned long size); extern void memory_dev_init(void); diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 1314d9c5f05b..4cb326f85302 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -2,6 +2,7 @@ #ifndef _LINUX_MEMREMAP_H_ #define _LINUX_MEMREMAP_H_ +#include #include #include #include @@ -10,23 +11,6 @@ struct resource; struct device; -/** - * struct vmem_altmap - pre-allocated storage for vmemmap_populate - * @base_pfn: base of the entire dev_pagemap mapping - * @reserve: pages mapped, but reserved for driver use (relative to @base) - * @free: free pages set aside in the mapping for memmap storage - * @align: pages reserved to meet allocation alignments - * @alloc: track pages consumed, private to vmemmap_populate() - */ -struct vmem_altmap { - unsigned long base_pfn; - const unsigned long end_pfn; - const unsigned long reserve; - unsigned long free; - unsigned long align; - unsigned long alloc; -}; - /* * Specialize ZONE_DEVICE memory into multiple types each has a different * usage. diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 3f231cf1b410..c4bac38cc147 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1354,7 +1354,7 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) goto error; /* create memory block devices after memory was added */ - ret = create_memory_block_devices(start, size, mhp_altmap.alloc, + ret = create_memory_block_devices(start, size, &mhp_altmap, group); if (ret) { arch_remove_memory(start, size, NULL); @@ -1956,12 +1956,18 @@ static int check_memblock_offlined_cb(struct memory_block *mem, void *arg) return 0; } -static int get_nr_vmemmap_pages_cb(struct memory_block *mem, void *arg) +static int get_vmemmap_altmap_cb(struct memory_block *mem, void *arg) { + struct vmem_altmap **altmap = (struct vmem_altmap **)arg; /* - * If not set, continue with the next block. + * If we have any pages allocated from altmap + * return the altmap details and break callback. */ - return mem->nr_vmemmap_pages; + if (mem->altmap.alloc) { + *altmap = &mem->altmap; + return 1; + } + return 0; } static int check_cpu_on_node(int nid) @@ -2036,9 +2042,8 @@ EXPORT_SYMBOL(try_offline_node); static int __ref try_remove_memory(u64 start, u64 size) { - struct vmem_altmap mhp_altmap = {}; + int ret; struct vmem_altmap *altmap = NULL; - unsigned long nr_vmemmap_pages; int rc = 0, nid = NUMA_NO_NODE; BUG_ON(check_hotplug_memory_range(start, size)); @@ -2060,24 +2065,16 @@ static int __ref try_remove_memory(u64 start, u64 size) * We only support removing memory added with MHP_MEMMAP_ON_MEMORY in * the same granularity it was added - a single memory block. */ + if (mhp_memmap_on_memory()) { - nr_vmemmap_pages = walk_memory_blocks(start, size, NULL, - get_nr_vmemmap_pages_cb); - if (nr_vmemmap_pages) { + ret = walk_memory_blocks(start, size, &altmap, get_vmemmap_altmap_cb); + if (ret) { if (size != memory_block_size_bytes()) { pr_warn("Refuse to remove %#llx - %#llx," "wrong granularity\n", start, start + size); return -EINVAL; } - - /* - * Let remove_pmd_table->free_hugepage_table do the - * right thing if we used vmem_altmap when hot-adding - * the range. - */ - mhp_altmap.alloc = nr_vmemmap_pages; - altmap = &mhp_altmap; } } From patchwork Thu Jul 6 08:50:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 13303368 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B49CEB64D9 for ; Thu, 6 Jul 2023 08:51:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E34988D0003; Thu, 6 Jul 2023 04:51:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBDB68D0001; Thu, 6 Jul 2023 04:51:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C10668D0003; Thu, 6 Jul 2023 04:51:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id ABC078D0001 for ; Thu, 6 Jul 2023 04:51:20 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7D6911A0550 for ; Thu, 6 Jul 2023 08:51:20 +0000 (UTC) X-FDA: 80980567920.22.682F26F Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf17.hostedemail.com (Postfix) with ESMTP id E30EC4001A for ; Thu, 6 Jul 2023 08:51:17 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=hYv908OY; spf=pass (imf17.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688633478; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=yWDKE2KFAvzWi+hJBYCHJUQfyTQYR3nDK4Q3JajXxqE=; b=n3OMODfdGSvd7nr4Q5B7g1FQzu+Km1Fd69di8KAQLM+635bOAQre7EGezUSGptjm0WwVb4 CZCEzMxZ7vvRn5Q0Q3ofDlm858ULCAQh+m38Dwy/irF+Zwj4tbbUxiVXXjCVawCRMfvAVL Pw/ur/pvB7yE7KZ5qF7Dvwnru0EOEBY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688633478; a=rsa-sha256; cv=none; b=AgH5nCq8t/ZoYPIcw2OcGAtl8vOr+F9KIMxc3XKI7UMRQ+W6Oh2MpPrPHbZJyPpMQe9ya5 ab47pGrj6PF/yS1MQU/oP9eXoW8Yp88r3fZ6S5xUQZvWOiIj0pgG93m4X3orv4SE5uqHl9 bjW0iGOTrQGpJCANBK2zja58NK5qS6w= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=hYv908OY; spf=pass (imf17.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3668lbmk029799; Thu, 6 Jul 2023 08:51:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=yWDKE2KFAvzWi+hJBYCHJUQfyTQYR3nDK4Q3JajXxqE=; b=hYv908OYurQWZrLWNCIPYbiqhyFONEKpfN0poxftJXMdsLDDHoHqPhcjhwRe2TBLAG1u M0BL/iN4Smf/i2g0IkZwgv1s9JEXah6qcd8b+BMkwJrev+hqsgTQIyhle2I6kA5iWwhg E9pLiS5XWX5P+ujYof5PdA4EqZFR3JFZgR0P3S+AvNUlFE8sqGsQlZ5EEQsXbicyhwt/ zhWZrIG8TUIXl0yaJn/EoiLaCOphDp+jiZGNJQ4IYx0hH4a7fMY4JZUgAdpHPyI0/Eq6 XOh/YwgG/TSO1v8YooNAajq2HW8y1OdanOW2jaKBKQenQDwjRDrFPT51Bq/+T9b5zEmR eg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rntdq023f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Jul 2023 08:51:11 +0000 Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3668m2EQ031779; Thu, 6 Jul 2023 08:51:10 GMT Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rntdq0232-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Jul 2023 08:51:10 +0000 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3667Kkk5001938; Thu, 6 Jul 2023 08:51:09 GMT Received: from smtprelay07.dal12v.mail.ibm.com ([9.208.130.99]) by ppma05wdc.us.ibm.com (PPS) with ESMTPS id 3rjbs5yx2x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Jul 2023 08:51:09 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay07.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3668p8kn36831860 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 6 Jul 2023 08:51:08 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7CCBB58057; Thu, 6 Jul 2023 08:51:08 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C520858059; Thu, 6 Jul 2023 08:51:04 +0000 (GMT) Received: from skywalker.in.ibm.com (unknown [9.109.212.144]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Thu, 6 Jul 2023 08:51:04 +0000 (GMT) From: "Aneesh Kumar K.V" To: linux-mm@kvack.org, akpm@linux-foundation.org, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, npiggin@gmail.com, christophe.leroy@csgroup.eu Cc: Oscar Salvador , David Hildenbrand , Michal Hocko , Vishal Verma , "Aneesh Kumar K.V" Subject: [PATCH v2 2/5] mm/hotplug: Allow architecture override for memmap on memory feature Date: Thu, 6 Jul 2023 14:20:38 +0530 Message-ID: <20230706085041.826340-3-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230706085041.826340-1-aneesh.kumar@linux.ibm.com> References: <20230706085041.826340-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: msxFzy6ToDq7gnEnmM3EuYtvcQ7vtZvM X-Proofpoint-ORIG-GUID: Te27x1c0_0o9MN28xfEeUwof_0E19SQr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-06_05,2023-07-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 mlxlogscore=999 impostorscore=0 adultscore=0 lowpriorityscore=0 bulkscore=0 phishscore=0 spamscore=0 clxscore=1015 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307060075 X-Rspamd-Queue-Id: E30EC4001A X-Rspam-User: X-Stat-Signature: cuygk5kh4aau83icznuwe4yt3kbmm1kg X-Rspamd-Server: rspam03 X-HE-Tag: 1688633477-133013 X-HE-Meta: U2FsdGVkX19zQ3/c4ZqHZ2lDQKc02+6N67WlRNqOw3KdKEzsr0NNSgJV1PfFvK+379/Py02JBjgugjZR9zi28anmq4X3ONPf6LYvXTdiAFfHfWqS3jaU/GP7DvIWjqYltMH65Nw3yY7hq0rCjs+FPTlPGWqgAOL9B/mdyK5RQ/mi/0NVzRKwIpXaRJfJwhxSBE/1+2sRIh9inH6d8G6k5eU0WUqww3EoZt4Dr9FzScuUdEWxh/eXM27c+zsZS9AdsP81SiuXI8rEzIpt+kOtqNwneCWBBvhwARWHXGmhGQllocITF87qMtTU+0dugQrrbsefdm3F8Y9wRcLYaIZnuDER35XTGELq29tTu5UCG00ssynElOyTIQo6ISormHjNgCZ2f2MlvUCJDj+C3f0/rJEloQDHZCyXRoNvGxMo7Nclgn9tehKV9Fdfge2YpAcC4jRWAo2s9V0YIsF7Ww5mETH/TOBJsIRSBeJKsa8r18hT4ynKEWsRp2k6zWm3cZHG+Ewp5r9A6fNMV1QmC28dt7/6H72YWk+CNOhqp3djnqZnFrnFwa6Kmb0EMeuU/coUv8GxDhJjHaU1f1Wy1jKAaqffjTFydlnYuWmYczPzLNjWqd8gsnf9z4hdgt1r0GCRbirx98vXFZPNgADME5tmjsHgF6eoOZNQ8/9l3Mn3LMD2vSoTty8dNr780WTyzqkuSv5QgIHMIIcZ3L6lAxTrtKmKMKIeJdn3jUJPGUr+TbaX9DeZYHbdvEHi/xynUrhDtfqQmcuywWJcX4BdIASF6+MJXME6Rp93f8tZqjM4scgBMIntBmcmVGKeRBhXlkq+hoOiLRNrJeYPrLMAi5PRSGw4i/gabAe0ceEmMwx/Hh/nsBmuAYXNBR3ZcINj5da3QtkeNOjCncMcUoG6FAiBZUnJf5q2VvbJDPX92hAvna4HN2EOzD8EozXddrhBH3OOox5VFcrqG0mA5ff6LQe bTXnx19u P2YQ75CDPVsgRQ223o0vmuTXIZPQ25qq9ZZVEYOQ+vh5feIe0DhraHQ8T3Qg7A9VCN3ybUDdyWLSgfRBAMWoW8ea9Ts/xkqd/KajjHSJaokQiNGeARnITazCl+3duh6ldBIpXZRXrAIHk4eOK6ClvyXAOjp9llL6D8BnZzcRv5AAuI95A9yYH1VutXYTmdFOQWlkXVsGU9BbCw4u/Ia3VPAIkkoq4vQIx71odD/BXz74LQGw= 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: Some architectures like ppc64 wants to enable this feature only with radix translation and their vemmap mappings have different alignment requirements. Add overrider for mhp_supports_memmap_on_memory() and also use altmap.reserve feature to adjust the pageblock alignment requirement. The patch also fallback to allocation of memmap outside memblock if the alignment rules are not met for memmap on memory allocation. This allows to use the feature more widely allocating memmap as much as possible within the memory block getting added. A follow patch to enable memmap on memory for ppc64 will use this. Signed-off-by: Aneesh Kumar K.V --- arch/arm64/mm/mmu.c | 5 +++++ arch/x86/mm/init_64.c | 6 ++++++ include/linux/memory_hotplug.h | 3 ++- mm/memory_hotplug.c | 36 ++++++++++++++++++++++++---------- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 95d360805f8a..0ff2ec634a58 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1340,6 +1340,11 @@ void arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap) __remove_pgd_mapping(swapper_pg_dir, __phys_to_virt(start), size); } +bool mhp_supports_memmap_on_memory(unsigned long size) +{ + return __mhp_supports_memmap_on_memory(size); +} + /* * This memory hotplug notifier helps prevent boot memory from being * inadvertently removed as it blocks pfn range offlining process in diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index a190aae8ceaf..b318d26a70d4 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1264,6 +1264,12 @@ void __ref arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap) __remove_pages(start_pfn, nr_pages, altmap); kernel_physical_mapping_remove(start, start + size); } + +bool mhp_supports_memmap_on_memory(unsigned long size) +{ + return __mhp_supports_memmap_on_memory(size); +} + #endif /* CONFIG_MEMORY_HOTPLUG */ static struct kcore_list kcore_vsyscall; diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 013c69753c91..a769f44b8368 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -354,7 +354,8 @@ extern struct zone *zone_for_pfn_range(int online_type, int nid, extern int arch_create_linear_mapping(int nid, u64 start, u64 size, struct mhp_params *params); void arch_remove_linear_mapping(u64 start, u64 size); -extern bool mhp_supports_memmap_on_memory(unsigned long size); +bool mhp_supports_memmap_on_memory(unsigned long size); +bool __mhp_supports_memmap_on_memory(unsigned long size); #endif /* CONFIG_MEMORY_HOTPLUG */ #endif /* __LINUX_MEMORY_HOTPLUG_H */ diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index c4bac38cc147..423f96dd5481 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1247,7 +1247,8 @@ static int online_memory_block(struct memory_block *mem, void *arg) return device_online(&mem->dev); } -bool mhp_supports_memmap_on_memory(unsigned long size) +/* Helper function for architecture to use. */ +bool __mhp_supports_memmap_on_memory(unsigned long size) { unsigned long nr_vmemmap_pages = size / PAGE_SIZE; unsigned long vmemmap_size = nr_vmemmap_pages * sizeof(struct page); @@ -1285,6 +1286,20 @@ bool mhp_supports_memmap_on_memory(unsigned long size) IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); } +bool __weak mhp_supports_memmap_on_memory(unsigned long size) +{ + return false; +} + +/* + * Architectures may want to override the altmap reserve details based + * on the alignment requirement for vmemmap mapping. + */ +unsigned __weak long memory_block_align_base(struct resource *res) +{ + return 0; +} + /* * NOTE: The caller must call lock_device_hotplug() to serialize hotplug * and online/offline operations (triggered e.g. by sysfs). @@ -1295,7 +1310,11 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) { struct mhp_params params = { .pgprot = pgprot_mhp(PAGE_KERNEL) }; enum memblock_flags memblock_flags = MEMBLOCK_NONE; - struct vmem_altmap mhp_altmap = {}; + struct vmem_altmap mhp_altmap = { + .base_pfn = PHYS_PFN(res->start), + .end_pfn = PHYS_PFN(res->end), + .reserve = memory_block_align_base(res), + }; struct memory_group *group = NULL; u64 start, size; bool new_node = false; @@ -1339,13 +1358,11 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) * Self hosted memmap array */ if (mhp_flags & MHP_MEMMAP_ON_MEMORY) { - if (!mhp_supports_memmap_on_memory(size)) { - ret = -EINVAL; - goto error; + if (mhp_supports_memmap_on_memory(size)) { + mhp_altmap.free = PHYS_PFN(size) - mhp_altmap.reserve; + params.altmap = &mhp_altmap; } - mhp_altmap.free = PHYS_PFN(size); - mhp_altmap.base_pfn = PHYS_PFN(start); - params.altmap = &mhp_altmap; + /* if not supported don't use altmap */ } /* call arch's memory hotadd */ @@ -1354,8 +1371,7 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) goto error; /* create memory block devices after memory was added */ - ret = create_memory_block_devices(start, size, &mhp_altmap, - group); + ret = create_memory_block_devices(start, size, &mhp_altmap, group); if (ret) { arch_remove_memory(start, size, NULL); goto error; From patchwork Thu Jul 6 08:50:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 13303369 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DBE1EB64D9 for ; Thu, 6 Jul 2023 08:51:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF98D8D0005; Thu, 6 Jul 2023 04:51:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E81168D0001; Thu, 6 Jul 2023 04:51:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CFBD78D0005; Thu, 6 Jul 2023 04:51:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BDF0E8D0001 for ; Thu, 6 Jul 2023 04:51:26 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7AF881204D2 for ; Thu, 6 Jul 2023 08:51:26 +0000 (UTC) X-FDA: 80980568172.28.1F5347B Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf30.hostedemail.com (Postfix) with ESMTP id 354408000B for ; Thu, 6 Jul 2023 08:51:24 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=XKTorbcR; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf30.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688633484; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zRrEFgiSl06WoUYA5FcS/votWh66pvHCGT+x7OFE9+4=; b=R+bo5IRlKyDHrwi16Bhyoim5U1YjdNzHJwPxG879vBAgbY4ReMsbETZIIZRraeSkBybMfw uqgAxaEVJ9rTsYTbspPwYgbBO8NaKgl2H6S6oJWpt/ioCiBwaVtPsRPUptmZWFYVohBPKx koUyC7yOjycFJ1cCZ28kY614TkXzjmM= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=XKTorbcR; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf30.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688633484; a=rsa-sha256; cv=none; b=PAlDlWi9ppFeKFOMEDFPFKtFBlXYeKqjN7gJruO1pWQLLzX3OJ/g4o1YOqaPtHI3enzo78 Nn9F2OP+KSi8n7ByY+VizVmlv1knGlWoBc3eMxkPuEhghbn8hOITehJSWEuyG+vlxStZ9l G7Eic7TXDFM6GaaCQbiQABG+RKbZ+hE= Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3668nPGP028370; Thu, 6 Jul 2023 08:51:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=zRrEFgiSl06WoUYA5FcS/votWh66pvHCGT+x7OFE9+4=; b=XKTorbcRyTFa6V3KgIyEIHDN/thGM7XGgRd6YsselrDXBlkJ3qHpoar5Abx6YDvHLR10 ONdvK0nkbwneFKAisiZMr/6U6vnecn1iIXBo97I75yeyyFO5zlgd4qomLelP70rvnbG1 ZwovbYI9Kng8abqtSI5JRLGlsu6X4uP748kSEKMUYUyYja1V7Z/DRiURtiDFquZau0BT IpXSa57wgUDpELkoxKRgZ5Lb3LrC0AOJDMUBPB0pRgnjksChCjM5XJXp68hiXJDfWMD1 32aWbBd5ECGGs4FC7GrnS3KxHF6N9gujFz7lfDjWblzqKg7gw+fWIexW+nlx7ZWZMhZq IQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rnted01m1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Jul 2023 08:51:15 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3668nTLb029060; Thu, 6 Jul 2023 08:51:15 GMT Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rnted01kr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Jul 2023 08:51:15 +0000 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3667UGWs017150; Thu, 6 Jul 2023 08:51:14 GMT Received: from smtprelay03.wdc07v.mail.ibm.com ([9.208.129.113]) by ppma03wdc.us.ibm.com (PPS) with ESMTPS id 3rjbs5yws0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Jul 2023 08:51:14 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay03.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3668pDdx36700650 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 6 Jul 2023 08:51:13 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E7ADC58057; Thu, 6 Jul 2023 08:51:12 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2107658059; Thu, 6 Jul 2023 08:51:09 +0000 (GMT) Received: from skywalker.in.ibm.com (unknown [9.109.212.144]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Thu, 6 Jul 2023 08:51:08 +0000 (GMT) From: "Aneesh Kumar K.V" To: linux-mm@kvack.org, akpm@linux-foundation.org, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, npiggin@gmail.com, christophe.leroy@csgroup.eu Cc: Oscar Salvador , David Hildenbrand , Michal Hocko , Vishal Verma , "Aneesh Kumar K.V" Subject: [PATCH v2 3/5] mm/hotplug: Simplify the handling of MHP_MEMMAP_ON_MEMORY flag Date: Thu, 6 Jul 2023 14:20:39 +0530 Message-ID: <20230706085041.826340-4-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230706085041.826340-1-aneesh.kumar@linux.ibm.com> References: <20230706085041.826340-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: OBfvSS76-ZExmrH3IUCz5uTxGrTB_QG1 X-Proofpoint-ORIG-GUID: SIf33BvggDc3tU4p00BbAqDomYrgthXJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-06_05,2023-07-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 impostorscore=0 bulkscore=0 spamscore=0 clxscore=1015 adultscore=0 priorityscore=1501 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307060075 X-Rspamd-Queue-Id: 354408000B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 1rp3f8dobmnsgh1dm6bwh3wdea1uegxi X-HE-Tag: 1688633484-370383 X-HE-Meta: U2FsdGVkX1/oiiSqOnghLTsBhJR5DJpG/W+6HsUhLCcQfKvr5sPw1cj85A9Jeh8Pr9NYAxQb5x8qvH80k8mNe3ZYcPQouuSsdcxsiq8+faNsF0vBSP26ufw742EEgRUrhGxIEcUb0QmvXWfzPA5ghZMvjLZWBbSBtZA7Mu1v55/TF8QQ1ZJM/gQfYwOFPElnLWhor/thRKOsp6EesTleSw+YoojZ/T2cSDqYdZkImnCSKkBC4lnlZSFCG8PcMOx6XlLCphuy4MhrcWYUA+S5TRkML/UFM5mA9YqL6KG57kt0aCKPPqwlPPIb5qWwS1KtpeIfAX4V7ZyYZByVwx73H0VQ8LU2PvjseOZjKoQqXpXvUYzcrqR0tdZbi7NmARzBIEbx3H2oedRqKNWy4XMhtesCMm8qf329Q7VBH0ct/c5SJimheFh+ASmFBaHyH6eiIzg3oROzaIao1hhOTXp9n5XRhCq10DQ+RpGlIrgiioEqK0ZGEDtZLJ3z/948KPMtUH0EdIhQSkHzq9hQMBqtjNf9wnAhKO2P1rz9av9k2wtxjUKfFk95QIIoXgrzkd5qRXW2ZAaw6LGRhqFJtkSqwhZE5IgO0NhqpvhTzgTikPM3QdiTM/8Ilf18e3vdEDzL7nYt++fnWy2pydGqBCcw8UHSa+w2rr0mH9YZ7+HTBwNb7HdrH9gk8xxF05shWgdlB1Y39gigkqP23KpPlcb1RCpEYey6wCsCuqNUFnaJD8xtWC7olwQEjEEsb1mPQ7mgvIvtMq4evx7qd5egWV/vXpLTdcjGVb5ybqzcFkvJIwIDctKw1Cuh7pU8tYwtSB+PChim2gUvCANkHTInGXjR/WfQGbCDWo4obHeN9F4wDi+43286Fqjr1ul630YRy4ixb5O5qdXHMRAdUVoscWMBCwLFXlyvCWr4DbGFhIkTHWLUZp8cIhOqWqEm4b9wTvTlF+P5/MqD3ZxyeU+axMH Ah3DC907 VqaQjoBb3Qge6sW4+3d8RbHOtNVzfj6SRrbCcY89roA+Nt3saS94Hi5B+UGPghwhtb/2mZjj6lJN7MZcb2xDrACxeZce/uVTXYFng33W9TEUDKw4YECeoaybmS/WT7Y/zXkDdweA7z1KWQH8QnBFH9c/8DIO5Ck290Uk4Byi0M9sk2O9WbaC9swtPsp96jggx2ZMYoPjYBdxzfvGiPWw837wQeYwbFGJuD5XdHk8kyL9XTE0ocWITIhOcSuFz6RbqQCk4WxtrWRhqAySyIfai8j9dAg== 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: Instead of checking for memmap on memory feature enablement within the functions checking for alignment, use the kernel parameter to control the memory hotplug flags. The generic kernel now enables memmap on memory feature if the hotplug flag request for the same. The ACPI code now can pass the flag unconditionally because the kernel will fallback to not using the feature if the alignment rules are not met. Signed-off-by: Aneesh Kumar K.V --- drivers/acpi/acpi_memhotplug.c | 3 +-- include/linux/memory_hotplug.h | 14 ++++++++++++++ mm/memory_hotplug.c | 35 +++++++++++----------------------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c index 24f662d8bd39..4d0096fc4cc2 100644 --- a/drivers/acpi/acpi_memhotplug.c +++ b/drivers/acpi/acpi_memhotplug.c @@ -211,8 +211,7 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) if (!info->length) continue; - if (mhp_supports_memmap_on_memory(info->length)) - mhp_flags |= MHP_MEMMAP_ON_MEMORY; + mhp_flags |= get_memmap_on_memory_flags(); result = __add_memory(mgid, info->start_addr, info->length, mhp_flags); diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index a769f44b8368..af7017122506 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -358,4 +358,18 @@ bool mhp_supports_memmap_on_memory(unsigned long size); bool __mhp_supports_memmap_on_memory(unsigned long size); #endif /* CONFIG_MEMORY_HOTPLUG */ +#ifdef CONFIG_MHP_MEMMAP_ON_MEMORY +extern bool memmap_on_memory; +static inline unsigned long get_memmap_on_memory_flags(void) +{ + if (memmap_on_memory) + return MHP_MEMMAP_ON_MEMORY; + return 0; +} +#else +static inline unsigned long get_memmap_on_memory_flags(void) +{ + return 0; +} +#endif #endif /* __LINUX_MEMORY_HOTPLUG_H */ diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 423f96dd5481..a1542b8f64e6 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -45,19 +45,9 @@ /* * memory_hotplug.memmap_on_memory parameter */ -static bool memmap_on_memory __ro_after_init; +bool memmap_on_memory __ro_after_init; module_param(memmap_on_memory, bool, 0444); MODULE_PARM_DESC(memmap_on_memory, "Enable memmap on memory for memory hotplug"); - -static inline bool mhp_memmap_on_memory(void) -{ - return memmap_on_memory; -} -#else -static inline bool mhp_memmap_on_memory(void) -{ - return false; -} #endif enum { @@ -1280,10 +1270,9 @@ bool __mhp_supports_memmap_on_memory(unsigned long size) * altmap as an alternative source of memory, and we do not exactly * populate a single PMD. */ - return mhp_memmap_on_memory() && - size == memory_block_size_bytes() && - IS_ALIGNED(vmemmap_size, PMD_SIZE) && - IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); + return size == memory_block_size_bytes() && + IS_ALIGNED(vmemmap_size, PMD_SIZE) && + IS_ALIGNED(remaining_size, (pageblock_nr_pages << PAGE_SHIFT)); } bool __weak mhp_supports_memmap_on_memory(unsigned long size) @@ -2082,15 +2071,13 @@ static int __ref try_remove_memory(u64 start, u64 size) * the same granularity it was added - a single memory block. */ - if (mhp_memmap_on_memory()) { - ret = walk_memory_blocks(start, size, &altmap, get_vmemmap_altmap_cb); - if (ret) { - if (size != memory_block_size_bytes()) { - pr_warn("Refuse to remove %#llx - %#llx," - "wrong granularity\n", - start, start + size); - return -EINVAL; - } + ret = walk_memory_blocks(start, size, &altmap, get_vmemmap_altmap_cb); + if (ret) { + if (size != memory_block_size_bytes()) { + pr_warn("Refuse to remove %#llx - %#llx," + "wrong granularity\n", + start, start + size); + return -EINVAL; } } From patchwork Thu Jul 6 08:50:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 13303370 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E25B8EB64D9 for ; Thu, 6 Jul 2023 08:51:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 61E868D0006; Thu, 6 Jul 2023 04:51:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 580488D0001; Thu, 6 Jul 2023 04:51:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D2F98D0006; Thu, 6 Jul 2023 04:51:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2D28C8D0001 for ; Thu, 6 Jul 2023 04:51:30 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id EAA0A140712 for ; Thu, 6 Jul 2023 08:51:29 +0000 (UTC) X-FDA: 80980568298.30.EDA200C Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf19.hostedemail.com (Postfix) with ESMTP id 81E141A001E for ; Thu, 6 Jul 2023 08:51:27 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=HMsdpxFs; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf19.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688633487; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YHKxaKoDkkum4zG8B/XuThKxljGD7Yu7g45RBZ6/RDU=; b=BYttUFsi4jQihpjbyzuV228gJfDYhhvrcXL+QCx8QBuAaWHQ6MvOlNNCHnUemh8cqt3o/3 yAblW8EhdR7bNE7TQ2u/FnGpFTe6DAiAbC5HSifvmnZru5/8RWxurSujPMnYbG+lv/Z5Uj QqEwnLwMZzgOyTszigeJ2BpZ3/GAMP8= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=HMsdpxFs; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf19.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688633487; a=rsa-sha256; cv=none; b=wfMT3PazFPJN1RfWpxegNqfwmdaYAJHDijGY4L3D9/lmvuG4lSMLyW+/uks9DRxxPbNfCS LQkRMCAVmzWW/eAEUlU3flsXPyNzvRkPmsE2z6XkJx8yTByYsZvXWuNxu5MP9YxkfjAyFC po/xYaLE+TwjVIF31mo5XpIOVYXD4os= Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3668nLT6027172; Thu, 6 Jul 2023 08:51:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=YHKxaKoDkkum4zG8B/XuThKxljGD7Yu7g45RBZ6/RDU=; b=HMsdpxFsFRiklaZgH0+9SOTTckV8E0N4oJ81isDgd935Dh2nYVsFppZJVQ7n/cJVB9mZ /4l02GST9PeGku+IdKD/VwirWWjgMj2ct5TmYFAAthCtznMQDj1akuamjDSMZ7nBYSyG 3eeKDWRm7s1A2tCBvsCYmKFQIWwQw65wudFEg+nznfWnqWlA4DFaJRJZtXdYAIYPTofr uW9vjaJi5iXxUgIvT12Vofj5L/E16Z5SuDhreqYNOiVIhwy4m39JqUgPm9UozRq01+mN sqM9E42FDeO9ZmZ/kHomwMfBIv6gr1x042xJA5HoAtLGegXBTgXHslWA3ZqeJRIIiJMy PA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rnted01q6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Jul 2023 08:51:20 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3668nbKP029624; Thu, 6 Jul 2023 08:51:20 GMT Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rnted01pj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Jul 2023 08:51:20 +0000 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 365KWKaC001784; Thu, 6 Jul 2023 08:51:19 GMT Received: from smtprelay07.wdc07v.mail.ibm.com ([9.208.129.116]) by ppma03dal.us.ibm.com (PPS) with ESMTPS id 3rjbs583ju-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Jul 2023 08:51:19 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay07.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3668pHca43319640 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 6 Jul 2023 08:51:18 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5C99C58068; Thu, 6 Jul 2023 08:51:17 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 818B658057; Thu, 6 Jul 2023 08:51:13 +0000 (GMT) Received: from skywalker.in.ibm.com (unknown [9.109.212.144]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Thu, 6 Jul 2023 08:51:13 +0000 (GMT) From: "Aneesh Kumar K.V" To: linux-mm@kvack.org, akpm@linux-foundation.org, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, npiggin@gmail.com, christophe.leroy@csgroup.eu Cc: Oscar Salvador , David Hildenbrand , Michal Hocko , Vishal Verma , "Aneesh Kumar K.V" Subject: [PATCH v2 4/5] mm/hotplug: Simplify ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE kconfig Date: Thu, 6 Jul 2023 14:20:40 +0530 Message-ID: <20230706085041.826340-5-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230706085041.826340-1-aneesh.kumar@linux.ibm.com> References: <20230706085041.826340-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: xPBw6_8DAFCu1W6iPCNVJXq3mO4EC6P4 X-Proofpoint-ORIG-GUID: JL5E_zexn2S2Qh-zaein-2edzmrVgcRI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-06_05,2023-07-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 malwarescore=0 mlxlogscore=587 impostorscore=0 bulkscore=0 spamscore=0 clxscore=1015 adultscore=0 priorityscore=1501 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307060075 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 81E141A001E X-Stat-Signature: mxu7rhgebz84ko4ec77f9w3nns8o3ksm X-Rspam-User: X-HE-Tag: 1688633487-210401 X-HE-Meta: U2FsdGVkX1/7o+v05Qn5cbmVKvJUSVH7tgHAY0rtRMYg0l2LxqaaJEKbU0p+8OFPAIXA9HiIqZ6ZX15mdKKqtJoh6MhPlnN6GU9B5/Hrwzr4kg8iTNXyWsrRING79UywzjtQ5+eXiBBCfFUKXlVKLvUfVxJU7UqaAl8EZCc27JZbs8kxStnMWmGdtgV0C3BSXtS19sMnM3+UVlQmSEe7pqlvg10qZIYlTFgiHeFxWYpll52ibI3C41ajGvu0ljUcjnPsYYg3WyzULHjuzCM8vX/gtE+t0EEx2XhNSc2f/uHrw6lFFztbWXVb9T8d+1u6bY9ayT3rlKG3z4adX0Z5l6CUHowKsYDyjvEoocYWHBbQS37v5XLX3zRheHJQjeZ9SssMm/unn0GpqA/QwNzABxQDt7/GhBFrkV2gkxcxMfFY2iyl/Zru2rfFGKw48wA2oCpm/HbkUQ59nam5BfW+wrFDyKLWQoKUqcGfkXoOtnhRkOep6hbPg18diBctkAoJF11FLbe7BXtWRBw5j/gFuvU898lgNIkZOhce6Qf4znMpYE2ooxNy4PIpCEQtXGhA1vtBy3np5pGYKCpOXfBUB3ZvOZMk1uBTM9ErIQjklUmRtmAYrVlu80fn4RcCe3M7hGLpSGJ79PjuYf51dYrtlbYYjsulhME8NZywrcmaEsg/R01LDvcOh5ylJuiLfN9fK7LAFPRduSfvC7AyLblM3BJUJ3Gw2CoQds/F0OauYCf0YSvfGO17flP6cDv/EHS8/hEwJECsXUssiub+t/5tCfuKXecBxoOrLnETZL9lFDXIWXGZ7tpl4Y8Bp6zMv2WOE12zp22MY1teV/XeUdxlETGprmQrujCAfKI6PdDtKmS8EU9fsI7cAWqk2kCU2/3QPbMSit3nLSJOcX+cyWimpwSzjhIE8Sm33kKBks47r8vLEvuEyjirYdGXMtIldcq6WByWtBP957Vitka+mFZ JIIC2wOk RxwE7p2uUwm/9KUPxm18ULK52JxrGO/QYupCwC+iK7262UNHomWpZRtOk2nJ63Zg7fh4VzfTgXjrF8jIrGGgjLifSodpZhilstPXr3oiIfAOkBRE5evFLPGqjOtAtl8OY50PXlETwvAThUN949cMiH1sD/oxXyIkXPvv62xPqIvFkx+X53e9Vwxq0gWIs37dLASGu91NywpuAt5Igtcziywjv8T2LFgAmMRi7w0xwKqx99MC5g9WdmxN6B5jnMr49dcMcOg3rRDof8kl5L/uDkeklIQ== 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: Instead of adding menu entry with all supported architectures, add mm/Kconfig variable and select the same from supported architectures. No functional change in this patch. Signed-off-by: Aneesh Kumar K.V Acked-by: David Hildenbrand --- arch/arm64/Kconfig | 4 +--- arch/x86/Kconfig | 4 +--- mm/Kconfig | 3 +++ 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 7856c3a3e35a..7e5985c018f8 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -78,6 +78,7 @@ config ARM64 select ARCH_INLINE_SPIN_UNLOCK_IRQ if !PREEMPTION select ARCH_INLINE_SPIN_UNLOCK_IRQRESTORE if !PREEMPTION select ARCH_KEEP_MEMBLOCK + select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE select ARCH_USE_CMPXCHG_LOCKREF select ARCH_USE_GNU_PROPERTY select ARCH_USE_MEMTEST @@ -346,9 +347,6 @@ config GENERIC_CSUM config GENERIC_CALIBRATE_DELAY def_bool y -config ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE - def_bool y - config SMP def_bool y diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 78224aa76409..d0258e92a8af 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -102,6 +102,7 @@ config X86 select ARCH_HAS_DEBUG_WX select ARCH_HAS_ZONE_DMA_SET if EXPERT select ARCH_HAVE_NMI_SAFE_CMPXCHG + select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE select ARCH_MIGHT_HAVE_ACPI_PDC if ACPI select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO @@ -2610,9 +2611,6 @@ config ARCH_HAS_ADD_PAGES def_bool y depends on ARCH_ENABLE_MEMORY_HOTPLUG -config ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE - def_bool y - menu "Power management and ACPI options" config ARCH_HIBERNATION_HEADER diff --git a/mm/Kconfig b/mm/Kconfig index 923bd35f81f2..2f9d28fee75d 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -570,6 +570,9 @@ config MHP_MEMMAP_ON_MEMORY depends on MEMORY_HOTPLUG && SPARSEMEM_VMEMMAP depends on ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE +config ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE + bool + endif # MEMORY_HOTPLUG # Heavily threaded applications may benefit from splitting the mm-wide From patchwork Thu Jul 6 08:50:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 13303371 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C1B4EB64D9 for ; Thu, 6 Jul 2023 08:51:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D23DA8D0007; Thu, 6 Jul 2023 04:51:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CAC078D0001; Thu, 6 Jul 2023 04:51:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B26008D0007; Thu, 6 Jul 2023 04:51:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9EBA08D0001 for ; Thu, 6 Jul 2023 04:51:33 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7418C1C8F50 for ; Thu, 6 Jul 2023 08:51:33 +0000 (UTC) X-FDA: 80980568466.02.882CB47 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf20.hostedemail.com (Postfix) with ESMTP id EAE221C0023 for ; Thu, 6 Jul 2023 08:51:30 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=kpGTkZ1d; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf20.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688633491; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7wIGBHIVWBJavonurc2vprDnaOE3vANQv3BfkW0LyfQ=; b=MDGjpAvrAKjyETItMRa1l/oyY7/wgvetlOCpVyC2TY/c3dO0AhPUDDHIKG3MsfWUXUjAVG ydh7GG0ewz/NhViCG+9NVCTMCzEhRnuNc0h9beSDsmf8F/eK2n5TvOab7QQEeOs4U8ztNu KttSYEXvn5fdFhlBVDgQiKC/wak8O9Y= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=kpGTkZ1d; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf20.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688633491; a=rsa-sha256; cv=none; b=JkoI6oZxPLY2wA6Op3JcdNsMjVHl9KQnGfFurWqfkY+q78FJsiztrSShwBs4U+0B3qSJm/ eCykw++4x8Ua+IFj1I47iNgJwlxH2G4godxmtmhA1nDTEYG4PNM/41+HSQVOmJEcoGgpYZ SEckmBSSm9w4tRNx9Q3hIOG2Ik/CKNc= Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3668dgki025532; Thu, 6 Jul 2023 08:51:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=7wIGBHIVWBJavonurc2vprDnaOE3vANQv3BfkW0LyfQ=; b=kpGTkZ1dJ6+dVrzXFlEwofmgplMEYut5urDnNg4KSoQ2kyKfI7yBLI/9C0ftYx7F6CxT fPHn+zmr/BWx/MkkUPjwneeaf2CoEQZXP3NADy5RbyN3RWeUfvD0qn2v5uBDHZo5W8DS W3GulED27qKk4RycqqZcsPwZpxp6a/Ev6VlXrwEhOVN6ol1YevYa/DYzEbau5ns+XeJX kTVDST/d2t9zzySHtcD7X0tyjDWFOp66AYFUfhBuGLibBszD7Q5icOI1Wj859dI92CbJ fThpaCxJ7pDAvvrhN703BBSDQeKi2FVWsTEhGKBVMvdpiC7LCttuoMYCMxLouGWnLN4V WA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rnsw08xq5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Jul 2023 08:51:24 +0000 Received: from m0353727.ppops.net (m0353727.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3668g051001612; Thu, 6 Jul 2023 08:51:23 GMT Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rnsw08xph-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Jul 2023 08:51:23 +0000 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 36683ZPi008598; Thu, 6 Jul 2023 08:51:22 GMT Received: from smtprelay07.dal12v.mail.ibm.com ([9.208.130.99]) by ppma01dal.us.ibm.com (PPS) with ESMTPS id 3rjbs6d33h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Jul 2023 08:51:22 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay07.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3668pLlv15729150 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 6 Jul 2023 08:51:21 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7DC5958059; Thu, 6 Jul 2023 08:51:21 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 08C3A58062; Thu, 6 Jul 2023 08:51:18 +0000 (GMT) Received: from skywalker.in.ibm.com (unknown [9.109.212.144]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Thu, 6 Jul 2023 08:51:17 +0000 (GMT) From: "Aneesh Kumar K.V" To: linux-mm@kvack.org, akpm@linux-foundation.org, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, npiggin@gmail.com, christophe.leroy@csgroup.eu Cc: Oscar Salvador , David Hildenbrand , Michal Hocko , Vishal Verma , "Aneesh Kumar K.V" Subject: [PATCH v2 5/5] powerpc/book3s64/memhotplug: Enable memmap on memory for radix Date: Thu, 6 Jul 2023 14:20:41 +0530 Message-ID: <20230706085041.826340-6-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230706085041.826340-1-aneesh.kumar@linux.ibm.com> References: <20230706085041.826340-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ElV9GzfJ6QS4-LqUXCZc9nJBUhhw7uks X-Proofpoint-ORIG-GUID: iOMEvrcWC8A-rClTS3chMQbpQBaBS5GX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-06_05,2023-07-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 impostorscore=0 adultscore=0 clxscore=1015 priorityscore=1501 phishscore=0 lowpriorityscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307060075 X-Rspamd-Queue-Id: EAE221C0023 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: pkeeotbnbghmzycsmkg7gu8s1sj1x98o X-HE-Tag: 1688633490-521249 X-HE-Meta: U2FsdGVkX18pS8tr1J+2hUOYivrxoztZNsk+vEtxApjBpNZ/OzBfDWFIyO8kuSXttk78Wh4W36jAwUBzpduEIwplBVWNeP8wAl3ybWxfEOUiG+9R0Fkhk6bxcDGkN1QMLPB+HTWghAG4/wvq5FwqKTAQu2wxEisQ06uyt1b7YLMQIWhU8BGgi/XcOKsKVoLdi/zfeZ4DbIWNNCDw/TFMGZnxks3KmEU2WEYI/Fx9XP1IfetxR9bLgf56A4y626APMi7N6p+z2QVpHCm8/gETQ6CfbM4aX8sShGHv5wbtIUG8/9li94tWQOEa0XGWREIyCW93zHBCGxFOByhE6jiOvHHhSuB/ac8xt9PO+bakjU2qEz8ZGGs3QFbDOqj64dJ4iiMbCcaaAA/qkfk6bXRDqYgS0hiBxCJtKWhAdAs0RXRx8cwhRvObSxnDwSTqhM7OHy26f2MTzoGKu28O9tAOdOS62Mkh2N3zijLO+MunUjjm9GQ1dtbBS2ArTkxKGsIQh1A0xGqUR0JM5pkq+dvUo8L6bgT5Yo1REEQlKweC2Bwq9icE2j5pqi6tjArY5fI7drSlCMEFxoJhmvcdRRDO/oL7mYRc1MNnvtE0Oh00yjh3i7QE1rHB6+DRwcPv31sG3OFW8f341cnTbW/xljGZuHSO7cLXU1ZZs7v27xL/wSk1s6jgCbQyZz6Mo0q+CRuRmx1cZoW+aIFrAtJE+cBvJFJRDfnRggzxJoSy4LKpmQLQGFTCLCAaa5eBs9b3ZksFv+PiX9uU9WvR4enpZNbuoTO0t8BQ1AbVg6LY/o7R7CTM5aWcsnZbelR6sbm7b1hcKP8qXmi235c1+pfrfNM9/y9xMp0ZEHlOKQyEw86FNW67tSi2rpdcWVEjIZ8PxQptMtfzjLEGavfoOryVjDME6cbahjYvqiqnZideCDWF2aAlVyz1b5xuj0uqKj++W7aWnDVb91BIQLCzttSrH1l vJ9yZska zdG4sM1TB0574AeV0A/f7W7GIU7uyObI8Mjuo8nGNT/ayU+JyWi9X4+FLr+MkJAiFnAbF0cgfSHL4O8YC3lmPyvYD2QDBeGrv6XhkjRKmQpJoxYLhVYGjlwGIA8mUHKbAGr0M5akTs+c3j8ZiyzsL7YHb6aK9+YuqezXtY6aKGGiTwan9tXG2L5qHkMZMfASbZXMWtyG0vslnL41HROehDGuoavT5pI9ODRoGVZjN8o8LIAo= 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: Radix vmemmap mapping can map things correctly at the PMD level or PTE level based on different device boundary checks. We also use altmap.reserve feature to align things correctly at pageblock granularity. We can end up loosing some pages in memory with this. For ex: with 256MB memory block size, we require 4 pages to map vmemmap pages, In order to align things correctly we end up adding a reserve of 28 pages. ie, for every 4096 pages 28 pages get reserved. Signed-off-by: Aneesh Kumar K.V --- arch/powerpc/Kconfig | 1 + arch/powerpc/mm/book3s64/radix_pgtable.c | 28 +++++++++++++++++++ .../platforms/pseries/hotplug-memory.c | 4 ++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 116d6add0bb0..f890907e5bbf 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -157,6 +157,7 @@ config PPC select ARCH_HAS_UBSAN_SANITIZE_ALL select ARCH_HAVE_NMI_SAFE_CMPXCHG select ARCH_KEEP_MEMBLOCK + select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE if PPC_RADIX_MMU select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c index a62729f70f2a..c0bd60b5fb64 100644 --- a/arch/powerpc/mm/book3s64/radix_pgtable.c +++ b/arch/powerpc/mm/book3s64/radix_pgtable.c @@ -1678,3 +1678,31 @@ int pmd_free_pte_page(pmd_t *pmd, unsigned long addr) return 1; } + +/* + * mm/memory_hotplug.c:mhp_supports_memmap_on_memory goes into details + * some of the restrictions. We don't check for PMD_SIZE because our + * vmemmap allocation code can fallback correctly. The pageblock + * alignment requirement is met using altmap->reserve blocks. + */ +bool mhp_supports_memmap_on_memory(unsigned long size) +{ + if (!radix_enabled()) + return false; + /* + * The pageblock alignment requirement is met by using + * reserve blocks in altmap. + */ + return size == memory_block_size_bytes(); +} + +unsigned long memory_block_align_base(struct resource *res) +{ + unsigned long base_pfn = PHYS_PFN(res->start); + unsigned long align, size = resource_size(res); + unsigned long nr_vmemmap_pages = size >> PAGE_SHIFT; + unsigned long vmemmap_size = (nr_vmemmap_pages * sizeof(struct page)) >> PAGE_SHIFT; + + align = pageblock_align(base_pfn + vmemmap_size) - (base_pfn + vmemmap_size); + return align; +} diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c index 9c62c2c3b3d0..326db26d773e 100644 --- a/arch/powerpc/platforms/pseries/hotplug-memory.c +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c @@ -617,6 +617,7 @@ static int dlpar_memory_remove_by_ic(u32 lmbs_to_remove, u32 drc_index) static int dlpar_add_lmb(struct drmem_lmb *lmb) { + mhp_t mhp_flags = MHP_NONE; unsigned long block_sz; int nid, rc; @@ -637,7 +638,8 @@ static int dlpar_add_lmb(struct drmem_lmb *lmb) nid = first_online_node; /* Add the memory */ - rc = __add_memory(nid, lmb->base_addr, block_sz, MHP_NONE); + mhp_flags |= get_memmap_on_memory_flags(); + rc = __add_memory(nid, lmb->base_addr, block_sz, mhp_flags); if (rc) { invalidate_lmb_associativity_index(lmb); return rc;