From patchwork Mon Jun 26 10:22:08 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: 13292602 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 509CFEB64D7 for ; Mon, 26 Jun 2023 10:22:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1DBC8D0003; Mon, 26 Jun 2023 06:22:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DCFB58D0001; Mon, 26 Jun 2023 06:22:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C97188D0003; Mon, 26 Jun 2023 06:22:38 -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 BA4A48D0001 for ; Mon, 26 Jun 2023 06:22:38 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 85B50806A9 for ; Mon, 26 Jun 2023 10:22:38 +0000 (UTC) X-FDA: 80944509996.08.50F24DF Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf14.hostedemail.com (Postfix) with ESMTP id D6A4910000D for ; Mon, 26 Jun 2023 10:22:35 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=qLkAiX94; spf=pass (imf14.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687774956; a=rsa-sha256; cv=none; b=zZJlZTSC0UH3UZS2GzHLC2rb14N74NmnVWMN/TeJc3ZyitEccukuJdzS7VrXWecVhckIxi mKvQTTenaGzRQbPva0V84H3Wy0Qs3jRJ84gohRZFa+7BZf+/QsSHsM+0bA3vYXpf8GdAjV /IrFDlLu4OkHB4VBFQ7RFGESJAAU64g= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=qLkAiX94; spf=pass (imf14.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=1687774956; 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=rKnaqMrhtfal6qJFhRUY26PfAk+2Nwoh3Jm2JBU0xCg=; b=06TdrlAa+AuM80xX710mBLTRoErBiUciSI1hgjcd58PKTT9RYoMcQmjAyboBZz+rGg3UuD 1Ipzt+8/szvHlY8lPg2N5IwItLeyXlal1aGYu3Uc4A/FACWSoUYBVJgnVawCM/DU76eEeG c0BIK2Wv+SlYzSB7fNZjoz90nYM7hN0= 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 35QAHRcC028316; Mon, 26 Jun 2023 10:22:29 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=rKnaqMrhtfal6qJFhRUY26PfAk+2Nwoh3Jm2JBU0xCg=; b=qLkAiX94k87sVz4jnASQM70n6fii8ifH6WK65AEbTy8tQM0NUZHhF4tKMqcFZrBOz0rf jCNtFUy2qme9kGWTE5Xp0nk8lrizqGZwe2diRCdJUgWk63PLZYOOdC0gcql43TS6Dr+j jIZagcMnkxGTpdt/NILEa6ki9Y+6eR5qspHJU6IZQ+A8NX67JLkCzi8rO09YXdKU7EGy F0Wi1UWJT293RLt4KxVuSkIQnSYo47Vj5iBiw4bZN+HhLYoOGP2QvhXxI30gZvW2JvM3 XWpFy9gyA159ghbWmkB3EUZjKN7MZHVmf+UCuD2hX0TJk2Ay8/vHRQ44WsWvPVjyd7Pp sw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rf8sq842p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Jun 2023 10:22:28 +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 35QALa4m008926; Mon, 26 Jun 2023 10:22:27 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 3rf8sq841p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Jun 2023 10:22:27 +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 35Q87uJt005949; Mon, 26 Jun 2023 10:22:26 GMT Received: from smtprelay06.wdc07v.mail.ibm.com ([9.208.129.118]) by ppma05wdc.us.ibm.com (PPS) with ESMTPS id 3rdr45je3r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Jun 2023 10:22:26 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay06.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35QAMOhx55443866 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Jun 2023 10:22:25 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9B86E58059; Mon, 26 Jun 2023 10:22:24 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8437F58057; Mon, 26 Jun 2023 10:22:20 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.43.116.175]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 26 Jun 2023 10:22:20 +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: [RFC PATCH 1/5] mm/hotplug: Embed vmem_altmap details in memory block Date: Mon, 26 Jun 2023 15:52:08 +0530 Message-ID: <20230626102212.119919-2-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230626102212.119919-1-aneesh.kumar@linux.ibm.com> References: <20230626102212.119919-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Djf6zrLowzWQdY0mVP0wnjDhf796vocu X-Proofpoint-GUID: pjL93lxYTRRIRa25q7paYaDFTW7zvZeK 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-06-26_06,2023-06-22_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 impostorscore=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxlogscore=443 mlxscore=0 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306260091 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: D6A4910000D X-Stat-Signature: 6ih4ipfmrzti1t7rehmjti736og619ns X-Rspam-User: X-HE-Tag: 1687774955-178650 X-HE-Meta: U2FsdGVkX18G4zssC96m2It+/DiYdF1TC7xq2dt1dYcvVH3qVQVu7wkBLRX1ldYkhvfMal1AyhjXidhtgrij5c17B47DRb1D4GY2U8yDiUjj3+W8yXfmuONDyK8HmgjftHsmytc77WdhhGWJj9ZPDDb1xlrm8rcVbNBa07d7OvpVqC4xAvLkTe6b7piGGv3BnzmE4A/A7jHwfzprAo9WvRwGpE5u60nTLh5n0+O0FXxt+umeOO4uJhnKLQ24YZLiYDD8QhrPNBZgndPnPc38y+8HDpFypNzbLHxrUKyhtQYPPRMO9J+Ro/WMqsSZuSm5Pt00Lhwacw0b8sb/yP8pOEA86GAfBq8HI0PwPZC9q/dHoIzYQbbqSC/n2A3pwWA84p0rjB4ETB9gfu1Su/kIvdHKHH6MEF0d0KuryI9MSuaquTMHWwQoy+Voi2P+PVyO9UwmXQVutMhp1bAhmktn17PTaTaxoJTm0sqKL3Xvh0/38Q0QGQWd7fY0R1rXOrFlsptu9upetd2fZD2CdgLpE1WZKcfJBu4Gjsn3ttSHA5pjcUwuXvP1vX9DHA06CjCPHNUJ4WDNaobaHqXJbMSHe+mNd6nA2hbv47oMsltBt/6KmuWXUc0PecsY50elhyUWBOBlzYNGzLee22bpW6GUbuzSejK3ZFV5kksDhIilkak5OmFTLVa8Os5kwY+r0Ku+28TnBmDHf2i+I4AkRoeQGCsyZUQIvV/q56+m9ecrCJIemWE8MzWDgBc6hGSTpHqBkMNVMIW0hLQPjsYfgd8asSnmyeX6rYNKAhn6D4sEIh2ue+PakKBbrkwF8WqCoTn+Uh+rA5X+0OlETMWBfSnNeBjHuKJN2VbVWVcI33n3gCfvVtTkyc526xIJl9IVVditoE1CELlyxEkIVUZczmz0xj8iagVd7e4WWn9quQQCv5Z2zmkX/lO+OMyFeIneUSJVpXa7VesHc9DDZlqVne1 cQwGvW1w TjU+nYvHwQApu1MIMx46VepjoZgvW03LCKblT/wgOz1Ub78rp04XUq1xujuXnZBJkbPvI7RjrEq3T9GqKRHvXrBlx5YWSCUYQGRVFEXZz9n6HbI285zsm6MRM8RKgEli1Jjm6zBq21XhS5L+GNyp3AUwFbjak8HdsinxHPpLgn2Ha4w01npqa27ANm7wp5oYQ0i6l 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 | 42 +++++++++++++++++----------------------- 4 files changed, 57 insertions(+), 56 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 eb18d1ac7e84..88a9c4443fc0 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1391,7 +1391,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); @@ -1993,12 +1993,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) @@ -2073,9 +2079,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)); @@ -2097,24 +2102,13 @@ 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) { - 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; + 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 Mon Jun 26 10:22:09 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: 13292603 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 67E80EB64D7 for ; Mon, 26 Jun 2023 10:22:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F09298D0005; Mon, 26 Jun 2023 06:22:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EB8378D0001; Mon, 26 Jun 2023 06:22:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D80EE8D0005; Mon, 26 Jun 2023 06:22:42 -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 C9A1A8D0001 for ; Mon, 26 Jun 2023 06:22:42 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A6DB4140690 for ; Mon, 26 Jun 2023 10:22:42 +0000 (UTC) X-FDA: 80944510164.30.6436D9D Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf18.hostedemail.com (Postfix) with ESMTP id 359CB1C0005 for ; Mon, 26 Jun 2023 10:22:39 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=EyIl6BQH; spf=pass (imf18.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 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=1687774960; 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=RKhqFCmvYDi80QG/8OWPoapj/fHMV2IUE0lhLM4968Y=; b=OwyAnkRH63WLa2HHOoZ+4xWOFyp8iUXYAJAKqZLQASAWwb3FaI1CBUecGlIkVCMIE9NDvm icHf3HUrhEBfm9CDoim2GnoGeSykJ/xSSyQBuNCETSq+Ou5IPQ8H0E3N7t4RZ2k0diVEbU qlz1EnDnzppDpm4zCCck5LrFagJ8m0Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687774960; a=rsa-sha256; cv=none; b=NNIHX0FOAr+3Hjh0bXTc9J5wX+f9t/ea1d0kQOwijaFjxhks54UChZqpLKpFlNZ+vXpnLR Dobv/aN/mN67d6+J1Y0L9UuosOXq6Y/LgqdCRqIRnoNa7qpPxjHqvOC2wdWyS6zUKyEQ9d iDfC1NE9+g8iVdwVu9XWEaI/VqbydMY= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=EyIl6BQH; spf=pass (imf18.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35QAHAlQ003467; Mon, 26 Jun 2023 10:22:32 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=RKhqFCmvYDi80QG/8OWPoapj/fHMV2IUE0lhLM4968Y=; b=EyIl6BQHlGdQM5dRMJ/k7+r4fTSupX7uSuNqUzxg9tPxAKpcIWM/OKp4SDuNMqFWlW2e HR7arcBr1I6fqXxQuU5liMa2CMFMvVDwKD9RGSdRvRB1xY+AYO2TcXcDSUBq2m9ppumx 8h7XrC3q5UlLcCEadqVQOqzLhDJaZ1jnMH6YHR6WtiiYt0j1dlu0LO0G2Vumx+GOwhTn QW/jxU68AlKFrkxWq2N847VV9eykVQPSJuR2eOWKzIHiZBEFypUGbx8CLe96H59V5/HM TYYgvG5TPl7xRGQNVmdot9J56mIzPvtwlE5DNhzDdZ5tJ6Bt02hNuyGRKcF89aTRQDTS Ig== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rf8ss03ws-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Jun 2023 10:22:32 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35QAIrf2007638; Mon, 26 Jun 2023 10:22:31 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 3rf8ss03wf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Jun 2023 10:22:31 +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 35Q88WVM027941; Mon, 26 Jun 2023 10:22:30 GMT Received: from smtprelay02.wdc07v.mail.ibm.com ([9.208.129.120]) by ppma03wdc.us.ibm.com (PPS) with ESMTPS id 3rdr45ae3t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Jun 2023 10:22:30 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay02.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35QAMTVf852548 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Jun 2023 10:22:29 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3C5A358058; Mon, 26 Jun 2023 10:22:29 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3D18858057; Mon, 26 Jun 2023 10:22:25 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.43.116.175]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 26 Jun 2023 10:22:24 +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: [RFC PATCH 2/5] mm/hotplug: Allow architecture override for memmap on memory feature Date: Mon, 26 Jun 2023 15:52:09 +0530 Message-ID: <20230626102212.119919-3-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230626102212.119919-1-aneesh.kumar@linux.ibm.com> References: <20230626102212.119919-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: klXlrt_l9oXRg38XaWWRznA0rci86H-e X-Proofpoint-ORIG-GUID: 6YjO-SOwCluy-1G8xCLozjQdVBrDHCzy 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-06-26_06,2023-06-22_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 clxscore=1015 spamscore=0 mlxscore=0 adultscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306260091 X-Rspamd-Queue-Id: 359CB1C0005 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 8z78enst86gw3r5rmnwaai8yyx8hzces X-HE-Tag: 1687774959-412135 X-HE-Meta: U2FsdGVkX1+SE7u00PEbA/LH+k/ttsoaaOV02XngO1C7WX3RxblgE1Pszy5iYC9Ju5QmisGBcrefC7byrDgSQrsLNgBAaBEx499lggdw2uj448hv19olztW4NXSNftWS512lrnVWD96iV+aafENQ6+mgdBn8cPh+1nNqKlnmC/BzOxVyk0eUTTVbfe9C3y324AVd1ug6IltyaKM49hjTNjAh7RhsomhQ93ceTM1sAuv2qv6uYYI4FxwbI9OSfzp2eZo1plD3lfXFUCAYYr9qyJQtiFFceGRboeBZNytiTfqv6rqSUiTQVN0CUWRL1RxnCycqsVGbgnNSCMaElang9TXdInhPbDp5la6tkb//mJLELsPN2Izwd4slluOX1U/UaiUh/vxK+EzxYM4UbBOC6fYBaJy1T5UEOQQSxfIsHi/lNPcnVXD/F0M/5RMG/IzjRaoZ43YPYDkLuMYmvQe3URrhNzj0fP36qWkYLW/uk2468xJyS18N0erHlaJ1fh1ltr3BiqR7hxICvrQEPc+juJzGwN05Pr/0dAi76mrdzmGC1cvkkklc7+A+LNbCxIZLH54Kk6xRA9b2Ggdip0pK7R6ptq+FmV0aBfoPsAGttu52g3q3/3jbucu3uq8nsCxncZ52o1CUTst3/hJYcAQWLYrB/yca15XubneIUh8Itv9xjhWbSrjrQ8y6Cmm77wqeAEuJlHDsZiv1vTHLUhxBXrkU8x7Eaifg0V8fMty/3wIrjndnDm4iPgEV26Y18Rr/tttjObPcA70E614lR+nDWie+48K5X3nOctkRR9Rm4sWPemDE1XdNvbTm0EHUtggx/V9Eu50l0FnHnc0SCXnfH+uoNhLu1+2EvhN0QNFb26pJ1JXLs/hNMqPtQDXT9CBIVo7uaDG5g0R9IQe6Y56LAiNYbEVqUG3+WJMzFQgu6QJXADGDUV3j2OURq89Z7QV3BuSww3ODkiWRbYqLPi6 b8gd3u+z 6UnJCHtRbE8R1SMn/5y9jQ+cS10HXjmJVuif4EOIrpkcyCYKwtPlIICMsA26pBpWaAXnn170N1XO6iAyjKSR5sCxCXwOxa9Gu/6pXeSZpZ86cstj719iY6gHoVcXnoCjtKhm96bJeP2Bus3k= 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 af6bc8403ee4..a5165897ea58 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1335,6 +1335,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 9fcbf5706595..2387391ee93a 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -358,7 +358,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 88a9c4443fc0..7cb112fb4996 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1284,7 +1284,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); @@ -1322,6 +1323,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). @@ -1332,7 +1347,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; @@ -1376,13 +1395,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 */ @@ -1391,8 +1408,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 Mon Jun 26 10:22:10 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: 13292604 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 A65EEEB64DC for ; Mon, 26 Jun 2023 10:22:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E51B8D0006; Mon, 26 Jun 2023 06:22:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3961B8D0001; Mon, 26 Jun 2023 06:22:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25E9A8D0006; Mon, 26 Jun 2023 06:22:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 188B18D0001 for ; Mon, 26 Jun 2023 06:22:45 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BF303A0674 for ; Mon, 26 Jun 2023 10:22:44 +0000 (UTC) X-FDA: 80944510248.14.A0EA161 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf12.hostedemail.com (Postfix) with ESMTP id 67FC04000B for ; Mon, 26 Jun 2023 10:22:42 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=NLR0qQNo; spf=pass (imf12.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687774962; a=rsa-sha256; cv=none; b=B/lzO3TvyXgT7oLd66Nh+y3eEvYL/2yNgx4CNx5bTltHTr3pvW+q/UVT1kjParpJaIyvtc ydLAYUDr9iIBP36KXI+4B2Pbmy286+aPRJlMAddE8+8Gcoa7wdkYewchVVV2LwDUP/jeHp utYk5OlxBMshwSO9hb2Iatt+4IZ+r7o= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=NLR0qQNo; spf=pass (imf12.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 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=1687774962; 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=OutdXd031v+aPB7lFIBkRLXayQgfZl+QfPvoEBGYOAY=; b=zJzc5oVvip56IZX+NwRAQzd/JyHIBR97TlC88iNpBzyWQTcJcC7qc9feJ4sacDzJlbsMNY DO7Z/qjVLrIOpDpMRq6QCzJGMvSH42WDPgaN9sAxOh47tV3pQ4kn0fyY9r1P9N3jayK+M/ cAL8dN6Uyn1VUjPfXmIx89RouNeQpcw= 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 35QAGwvk008510; Mon, 26 Jun 2023 10:22:36 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=OutdXd031v+aPB7lFIBkRLXayQgfZl+QfPvoEBGYOAY=; b=NLR0qQNowd+TjO4mL3RafjC5Q/u6k0IjwSP1LHwNP3w5lZ1oBNObDaN5MLQEmsg4bt84 jqDaQn9/ukchGxIcmatmHo/RtephMn/A1nMrGCOecnE6HRegcPw9hxVQr/2bW7Jl51y9 NioowWQfGAuWP4Huny3fiMnbm5Le/G1CTLFmUN71lEqeeOzqu0h70GQTemHXQ7zmFPxz wsmJXU5PYRDyq6sovul6gmhH36KH6jZ+vLk4p+J1LNyPEB10EZQXc2TvGYyx3ioC7V3P 6YTmtYB8z84E07bCSuJZvjoOd87Wnwx6Rmwab0I0q5cqfCC+Jq+Z94PLx1JYvT3JzkVp Iw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rf8sn03we-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Jun 2023 10:22:35 +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 35QAJDvS013672; Mon, 26 Jun 2023 10:22:35 GMT Received: from ppma02wdc.us.ibm.com (aa.5b.37a9.ip4.static.sl-reverse.com [169.55.91.170]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rf8sn03vy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Jun 2023 10:22:35 +0000 Received: from pps.filterd (ppma02wdc.us.ibm.com [127.0.0.1]) by ppma02wdc.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35Q89geG023990; Mon, 26 Jun 2023 10:22:34 GMT Received: from smtprelay06.dal12v.mail.ibm.com ([9.208.130.100]) by ppma02wdc.us.ibm.com (PPS) with ESMTPS id 3rdr45teq6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Jun 2023 10:22:34 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay06.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35QAMYlV6947344 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Jun 2023 10:22:34 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E99B658057; Mon, 26 Jun 2023 10:22:33 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D1E1658059; Mon, 26 Jun 2023 10:22:29 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.43.116.175]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 26 Jun 2023 10:22:29 +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: [RFC PATCH 3/5] mm/hotplug: Simplify the handling of MHP_MEMMAP_ON_MEMORY flag Date: Mon, 26 Jun 2023 15:52:10 +0530 Message-ID: <20230626102212.119919-4-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230626102212.119919-1-aneesh.kumar@linux.ibm.com> References: <20230626102212.119919-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: qKbBUn7tv0d9_83dVdL0DTE0aa5r2hqc X-Proofpoint-GUID: eM2vG3u38snH7SpxZ7SCpzpK2CQFnRUC 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-06-26_06,2023-06-22_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxlogscore=999 impostorscore=0 clxscore=1015 priorityscore=1501 mlxscore=0 spamscore=0 malwarescore=0 phishscore=0 suspectscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306260091 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 67FC04000B X-Stat-Signature: ixkyidaw9q386rkbxxw7t599reyghiws X-Rspam-User: X-HE-Tag: 1687774962-321755 X-HE-Meta: U2FsdGVkX18V9F/SqrDrLQkCWA1mkPhd2wbfM4D86Ajok0tsuc1zAkD1PAxURmEOCBLLKH44ujNJtmMGtmAYppb+slATBhDX7F0K+UuYPLdj22llu/WrPdWBJx7WaQgeN4T+OMm0Caln1eGqErvDHG327mlne3FCCb9ZVtqqfWUKq+c8V42rrTYKAYfYNc6hHSH0ImwtTyJBWQgJm7TBvt11BIVo6FE6vrj1heoarw+fIoAV6hK2OYca3IYJoFMg4OLaBi+BYxVere9+dx+reOjrgLeObP1IMsSyXB4vQILBFluzZjygxoW/2wfs0OctSUc4X8iXkKlR0imhu+H7N4nDjv/RWMYcwqCAAxcLrjP+FXfniDk+PefOp3R/lVvIjFpLX++B+4OddsShMHb3j1DadjjpJHhHbNlNzEDhaK4SVqLXOZZFB7jV8qyz27+9wBSQDSPnJ5OCLjM9krWRqzVUr3NoafHvAC8S7KETarRQ68hHNzewaHwHZ5ycyR07vmhSw010xFTPY0cIqvb1fpBJVx1J2iUClJJfVe1tuC5fUJplMBngXjrUf2wBqgOl4588MQO5gZqBmFIFdbu/W0PL3SQCnKqtCZbgJucDjqvRm117tItcC4kVHd7yOOyYyrGWEEMpEkNkW8MfVswbdg+xY5iliOtcEfdkVj9N1OnGn+QmTdt4m90/DIhTC/TSKci8FjLQNu8Qh7XAcpCuG650CUhLl4DzY1Ve8kypetGsrdRSe9O5eIlSJ2jKzzG2MuZSwez8h5FYxp2/K5L1mJmXOgd33SlZRbnJvQjxQ9GxAHBnwTa95U/N/h7CVpx+CIaz5pAh+CijdU9ndl64lQuTlNfeNrumhJtIXSjmJg5njroLeyvVMx//ARFAlM4j9vXyVg4D7+l9lBqZriJgvREcR3Y+qNx11KkAV81dYynZhqqFxWsHdvkFkz7CU4+XpfXC7OT/bvwQfwOHiqr BEmBm8oO Kl04B8VXTq3pn1wtkV8xZsZfCJTyfRkiYyDs0V+PzZiVeAW4JIUvMR76039CiZe1J9uA8obB8Pn3CmSjks7Rwce7sDAxuXNkJpO/AzzuSXegjndvBHr0ht4TOzAOZRV7efswENugdXdWCgkLGiogMgSdxkZMmCL3lLEV3+17Nfdv/QV0MNtYtIyyBwao6YqpyGVss 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 | 19 ++++--------------- 3 files changed, 19 insertions(+), 17 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 2387391ee93a..add3e7829c80 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -362,4 +362,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 7cb112fb4996..9cfa6fa31df5 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -46,19 +46,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 { @@ -1317,10 +1307,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) From patchwork Mon Jun 26 10:22:11 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: 13292605 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 BE6C1EB64DA for ; Mon, 26 Jun 2023 10:22:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2AC338D0007; Mon, 26 Jun 2023 06:22:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 25C7B8D0001; Mon, 26 Jun 2023 06:22:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0FE248D0007; Mon, 26 Jun 2023 06:22:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0203A8D0001 for ; Mon, 26 Jun 2023 06:22:50 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D13C71A064E for ; Mon, 26 Jun 2023 10:22:50 +0000 (UTC) X-FDA: 80944510500.16.D1C23C8 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf05.hostedemail.com (Postfix) with ESMTP id 7C70A100006 for ; Mon, 26 Jun 2023 10:22:48 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=F28rI3rV; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf05.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=1687774968; 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=FNKFW8wpqigijfCWM3rq6GFS2HxCr8bUTxnaXbps4Mg=; b=vEggBZDlM42pMwJAikW1BN1z6xtbjOf4dviC6rbeY7e80OoF66l7Xy4qePRXYXnR08JmDu v58rEwsUUeWimbru/ckYZUmUMjKyQan/s1ZDUwSAdYccPrWNpML7mFzEj+G24TotHvXg8R t3pu7uBkj+173Zao3rkW6DV/Akb2Ef8= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=F28rI3rV; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf05.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=1687774968; a=rsa-sha256; cv=none; b=4SCV/NOrN0ZMHk6aAch93B8Z8e/Z9MkU2F3g15LAa65cXKO3gtRizzIZ3ZXNf6AtGF1XOs v3Y5T6ge6kjPlc+CB13Z9yGr+7xb7Lqqwo/6ma4SbLV2eWeHJ/t/b48+/+IOSRA03t2UP7 zc+oQshXsi20qSN8LzW4hn9HaoJGK0M= Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35QAFtmO004017; Mon, 26 Jun 2023 10:22:41 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=FNKFW8wpqigijfCWM3rq6GFS2HxCr8bUTxnaXbps4Mg=; b=F28rI3rVSMQswrNHAjTiH+3esxHT5jBfbkgfVircyMShJG6J4z9G9JVc6JeDki/9GfQk NlnIIVRsLWYxP7zc3piIzrOngUtktPd9qWgaodBlNFMCezumb0BFAB8kwfmF9H/E5myf 5uSnwx0gkdeP1CZBcu9C/kHqmEfRJ0uLJZzZCs+0yed+0nd/eGoR9gQ5tdgjW/xdtJAH XyU2YjvQmq6b+ivCh9NiYm4/gUMMTN3rpuH2CH9Te5o1xnGteIhPk6uTYeyJOpKEzDwj w7N829ZzioOyXw8AxisoDZrlAX9uIosOAgklaW3OiiQYTMXprWlvv6DGzDOsgQ0KZ7qx QA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rf8s3891h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Jun 2023 10:22:41 +0000 Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35QAG5x6004786; Mon, 26 Jun 2023 10:22:40 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 3rf8s3891a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Jun 2023 10:22:40 +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 35Q860SQ005910; Mon, 26 Jun 2023 10:22:40 GMT Received: from smtprelay07.wdc07v.mail.ibm.com ([9.208.129.116]) by ppma05wdc.us.ibm.com (PPS) with ESMTPS id 3rdr45je4g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Jun 2023 10:22:39 +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 35QAMc7S64946600 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Jun 2023 10:22:38 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 89E885805D; Mon, 26 Jun 2023 10:22:38 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8B86A58057; Mon, 26 Jun 2023 10:22:34 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.43.116.175]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 26 Jun 2023 10:22:34 +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: [RFC PATCH 4/5] mm/hotplug: Simplify ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE kconfig Date: Mon, 26 Jun 2023 15:52:11 +0530 Message-ID: <20230626102212.119919-5-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230626102212.119919-1-aneesh.kumar@linux.ibm.com> References: <20230626102212.119919-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: SHxV05aMKYlcglcpEURiQCZBI62mDQhi X-Proofpoint-GUID: WUlkGdbUQF-vEJOX82TZaIZwuFJyTfKA 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-06-26_06,2023-06-22_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxlogscore=472 spamscore=0 bulkscore=0 mlxscore=0 lowpriorityscore=0 clxscore=1015 malwarescore=0 impostorscore=0 priorityscore=1501 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306260091 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 7C70A100006 X-Stat-Signature: i1rx46hynub67zb7o1w6hype711mfqi5 X-HE-Tag: 1687774968-876592 X-HE-Meta: U2FsdGVkX1+oYuyqocEBU+DPEuxmpCQdXOi9g2UYwfXg+v4sTKUs+gQjl1PRMjMXOQXydLEVmQO7E93vcprCHXPgq6x6uaGUPdQ1/rCh/B5I9xUsD4kBD4Tk2JF0lDfaS6/YoouhkZ1s3Twm6eE2Y5tKM/pxLv/tAls2MqL3cJ04a1FWQTRGfTdB5tffz3sN9LrsxkZpBarWGxP43OKokz0B/tm1bGx9yeKiQ6n46h0mEJhho/zlMPIOXpuvkpchjYxwy636K5OSyU4WZ16uLQeZ2UtcQ10Wkf4OdoiDZ4bp19wAx1sYjl80Hw8i/eLgdKByJfwJtSXsEe1Jtht7s6k2gAL57uJgcivQjxsxST+hE5TzOTvMYeXI31JCqeSZGhrvxqWFK2+vfcY82la/bxO5GH9bQgf6pFoxQO9JAFo/xspgTTXvwONDbN2AqbEXTm6K5DkFBXRJtOe1WVyk7OwzBRGujNp+aFj/bPAEwISgYp9UYbhe75ydjsLf3o+crls5wKh8GOJt58gVm9J2hCWhwahzUc6TmmLEZwcGndLIUT8TVq8VXk5leDJ4cjRKtICnXRVVgriswo6zj7YJqdlX1hCnIm6niht9Rn2OoiC8p90DkIv0imGTD36xjqU30QOQ3ihrkjip+eLDoAECr/Gr/zWGRTSqHXA/Z6y8GZiER6nnZAP4lVNCWdHXtjrQPypaLZ3kB5ZXJfh5UzOszR2RpkGcr6OZY9E5kfCd0oFcgTSAq2Rh4cpFwB5WRU4RGVymFriU+UOEsKd2+PUHdvSuGbFJRxoGmB/kZ9uf3y3BB6qVPNQyYcqKmXnKS4rBE4RF7gBZDS/4NlAFUgPGs8zSc2O1U/E5e0jeOMLd8Rhodno/QC88pO7T+HrcaHgZhbpdgqQmfUfueceLLLGobyIv481Ub5jvxZT0WZzKy253jyY4GF0ROssjM+a4WK++k0BcSrbo8ypFd5Vuzjf MEIWf9/Q RjvHitDUMP8ZZHI2SYEScezpaR+heC0io/c7aDaKH5BcUykJDaFybVMyHUiN9hcjCBW58mLezZC/iGfIw9ugfTeiJzvUS+290CsVyNRjFpN4KS0wMO3gGkNo8PuPsRksYc5w+KGGtGfwuNxr8Gmc9iLx7rF7y/7W9U/hF03rImO30OZikpocqiaOxs2XIYdyjAoez 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 --- 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 343e1e1cae10..20e909dac7ab 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 @@ -338,9 +339,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 eb383960b6ee..c77c881e35da 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -101,6 +101,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 @@ -2656,9 +2657,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 7b388c10baab..4e5862c001e4 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -544,6 +544,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 Mon Jun 26 10:22:12 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: 13292606 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 049FEEB64DA for ; Mon, 26 Jun 2023 10:22:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 915568D0008; Mon, 26 Jun 2023 06:22:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C5B88D0001; Mon, 26 Jun 2023 06:22:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7661A8D0008; Mon, 26 Jun 2023 06:22:55 -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 65F418D0001 for ; Mon, 26 Jun 2023 06:22:55 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 280FD405AD for ; Mon, 26 Jun 2023 10:22:55 +0000 (UTC) X-FDA: 80944510710.05.40FE0AA Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf28.hostedemail.com (Postfix) with ESMTP id A91A8C000D for ; Mon, 26 Jun 2023 10:22:52 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=poSa4lSy; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf28.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=1687774972; 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=oxvnKRSpGoW8JFJutnQHFPsa2w6ImNzo01OT7dEV1Yo=; b=5no/FzY14jxl6qCVgsJB89+d+xnb0AT7SOobE3q1VkE6TIMj2yJufVOzP45UCoSH0GjyLj cBWKoUKGEkjXyv5KM28e9kxQQFxBP3NPLUQPaGtVx8PMbTNqVzDcIwe3RyJdg3dJVlqukR 6kgGMBcWXUZeRvn7fkBMg2exRtBe0RY= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=poSa4lSy; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf28.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=1687774972; a=rsa-sha256; cv=none; b=epEOX2gY2gJHzbPd1o7cOjmaq9gCh0cgp7khRw5J5Ic3YHJd4/cIMiNQHd8jWRl5F9swKJ JQkpemzALbL3MROvg3lXfMREIXLdr5ffAW8Pi4jG0Cr1kT4DqI5MHXlthUQiUfCyCZudnY 3ovDM9lGbNDAa8DDc6owMpTA4bz4awY= 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 35QAHOCj028263; Mon, 26 Jun 2023 10:22:46 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=oxvnKRSpGoW8JFJutnQHFPsa2w6ImNzo01OT7dEV1Yo=; b=poSa4lSyeGRBevI379bTanXRVWiH5oEff+/dQwVevmCkNZQh6yFV9kMYJ6NB9qsS41vq 4Y3XBHgF+eOrGa2d4PtOIphJqWXkllLSHeKlqX569qEJVQIDma0A+KfJLAPyBnPc4aF/ sFqjtsQCDxmWJ839Cp/KAK7HnpK8nLzbAr6DVXgRE2DhdqKyBOB1eEGndEHX3WWl9Ym9 wMbXEqxb1XC3qmQwgVDkaOCzYJGJ6EW+2lTW0OZqOmH7xifS8yUAsVJEv5OgylJls6zi 0Oclbpd0AboD6EUUl55GnlYlAFytHJf1u1y4ZBd4Qgzcu4BX9gXLiNvhNSkwh0bYFGkL /A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rf8sq84ap-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Jun 2023 10:22:46 +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 35QAKnAW005905; Mon, 26 Jun 2023 10:22:45 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 3rf8sq84a6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Jun 2023 10:22:45 +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 35Q8Lqht028053; Mon, 26 Jun 2023 10:22:44 GMT Received: from smtprelay02.wdc07v.mail.ibm.com ([9.208.129.120]) by ppma03wdc.us.ibm.com (PPS) with ESMTPS id 3rdr45ae4s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Jun 2023 10:22:44 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay02.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35QAMgtl52887914 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Jun 2023 10:22:43 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D5B8A58059; Mon, 26 Jun 2023 10:22:42 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2BB6A58057; Mon, 26 Jun 2023 10:22:39 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.43.116.175]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 26 Jun 2023 10:22:38 +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: [RFC PATCH 5/5] powerpc/book3s64/memhotplug: Enable memmap on memory for radix Date: Mon, 26 Jun 2023 15:52:12 +0530 Message-ID: <20230626102212.119919-6-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230626102212.119919-1-aneesh.kumar@linux.ibm.com> References: <20230626102212.119919-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: l6nyOvHImYr2ncmzpAHpJpj-D7a6hwbk X-Proofpoint-GUID: p6ifLIVYMARIoyS0jhsdU5P2mBOTmdPC 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-06-26_06,2023-06-22_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 impostorscore=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306260091 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A91A8C000D X-Stat-Signature: mhzkyns1x7igx3n7aqmnbgyq1gxgnhh1 X-HE-Tag: 1687774972-467754 X-HE-Meta: U2FsdGVkX18FKqqNiCSvyV6CQV/z1Nqkl4V35YgKUUNrvOLvGrcUos2R6vA4y4IUV7dNYHXlwb32QxORs28Dvwad5AqG1otx4NgPAy546xUgCM6l0xfj6tZSiQy6htEemv/n6xPYCuVmJT7mxKcdxX+C/pJxUdkteAF8T5ARGoLjkrssrZfZfSsm/y3oskQqtzU3Byw9srtK0Z53t3K1uV+KCDqk244Tx2X1HGmEcvuQJeaVlwS3dSIT1eZeasi4N8zV3bBXqn/92ma6sElL2isYbUjR3Vhiygj5aU8EEb5ZU/bhX+1QGhUi+QD6VWlehroZa+Aow2tDfhFNR18TTYewHftpnLanKSNJ+9T2d0Xk0aYfPOi1rcytQN6FWaDxBPaGvAyTe4BxdjjJDBdPgSpxpZbNj7n01DDdLMr//pquGvIuxAkgB0LHlPmnoJ510sM3jHzxqo25up559l5qWdL4fqukQSp45Vyhnr4gbSv8X0D5lgmoB0Sb36h/WkT6Mx0+dw/8ekZl9ZUNQKiVtztch2vCSYp1hHRNFCn1A1LxapRLq0Cy67qyj3HPSZxRv+DldS878KA88ZTE23jlzUMlZuo0vjJfxhcFDCCb1kMS0JzyTMvfLYTar0AksaFrNrmFptm+O1dygHo47VeyVxwMquH6jNO3gyutv3QV9VNqUcFUzrMaexeDDvYJDysw8kfhPVAsOIzzFPUgcT62yNeWNUsaAFTasg4bK2z6ndyddMnjSbygl3REh5cXciVNQ+pDlJOCzYIKNk1sL33vUGYcPyPpbLODto/DNWDNEW7QmSPq+YZADCgVU3OxpE0BeNgTkQmhM+xReilaYEIlKatyLdMGu99vAahjl/K7MjNqkVawmnjFJOrvt8m905quc+5BuvwbzLuMZzbpaew5eX8j/tJhA+O4tdQ2t4kAkputRnhF1PiasV5geVBPoA1vN56/zH0sJzFhcNxmUkq NN8WkO6y hGDx3yBZMrCmHZfkHBg0w1Fkr5W6LV6CTjrgaaev8n1ayDI9P14j0/BtTG0epe9IGQkD6sVM2H8I5V2++V+96g+XQyN5nAQZz8cJ+5nVFv1AFY0WPObmS6Ulj/uqkofaU1TLGU8OdwWrRp4A= 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 6bd9ca6f2448..1b0954854a12 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -158,6 +158,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 afbae37612ad..e0e292b87b4b 100644 --- a/arch/powerpc/mm/book3s64/radix_pgtable.c +++ b/arch/powerpc/mm/book3s64/radix_pgtable.c @@ -1692,3 +1692,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_SIZE; + unsigned long vmemmap_size = (nr_vmemmap_pages * sizeof(struct page))/PAGE_SIZE; + + 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;