From patchwork Tue Jul 11 04:48:31 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: 13308124 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 5B6F2EB64DC for ; Tue, 11 Jul 2023 04:49:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB6F38E0007; Tue, 11 Jul 2023 00:49:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E66348E0006; Tue, 11 Jul 2023 00:49:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2E568E0007; Tue, 11 Jul 2023 00:49:29 -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 C500C8E0006 for ; Tue, 11 Jul 2023 00:49:29 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 832ECAFD9E for ; Tue, 11 Jul 2023 04:49:29 +0000 (UTC) X-FDA: 80998102458.25.58BBBB4 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf02.hostedemail.com (Postfix) with ESMTP id 45FE080008 for ; Tue, 11 Jul 2023 04:49:27 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=ItPoa9bt; spf=pass (imf02.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=1689050967; 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=9hGLX82mpM7A1sG7cUX4F22RXgthqmPVRb138g4/vAU=; b=ueVoGZfJpiAAdWdbPz6Oex+SR4cjszJeafeX1rj/+D5dLY4BdJpRGgqEz3vp2UJmonBT6R Qlk7w3g9B1USWKdYxaxWGZMfJ2bWE3TstI1Robwd6vabgob3fKwofp7RwQVW4KMM/J0n+H rS509V/dwh5HyDBQyCcexQIDpc8PJmg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689050967; a=rsa-sha256; cv=none; b=d0E5KGHKFW5rWHN3Udu8tBw0d7PdAdMIoH+4gqeA1caMKaYNWFY0SskI347xVTWWYdYcwc BxY7axBgwbIo7aVBdGIAPNlouDrRG0Z++De/jErsaWn/EOQA/6rFp4SWj5DzZ5S9qOz/zS aFXP+SSW7BR70SWgvM0adjqn+LFOt34= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=ItPoa9bt; spf=pass (imf02.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 (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36B4kwXo016793; Tue, 11 Jul 2023 04:49:20 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=9hGLX82mpM7A1sG7cUX4F22RXgthqmPVRb138g4/vAU=; b=ItPoa9bt3C43BAS676bvRNT1jZcjwr1NAJmXMLZkqS63/ltVOYhgSaycan52ArAGCHqr TKTJXu+dnNDs+7cMap/dziHWV+/9GTFpAsI7ZQAWtWS5ERj8RjRb8ey0B9yHrjf0CMqd ZBGG4zito4yiygTY+rXZhJE5ZMNbBhA0wjTIC+8P7WlnsDuUn0w9ZVpzCa8EMFP3DJ64 7DDTDEVFjeGQZyv1y5GKd2cjKBm6AFWpw7KAW9Dxr+0zdBc2O/S4S5oIrPjqlY8Bqq6W U817niqRB0W3ZOhdBA84jO+my+xfKQ+m3GExlz6HYgtXTyzcJaLAg3v/Tjms9Ns55aAA rw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rs0btg4a2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Jul 2023 04:49:20 +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 36B4kuEq016759; Tue, 11 Jul 2023 04:49:19 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 3rs0btg497-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Jul 2023 04:49:19 +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 36B4ZL56017145; Tue, 11 Jul 2023 04:49:18 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([9.208.129.114]) by ppma01dal.us.ibm.com (PPS) with ESMTPS id 3rpye6vedj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Jul 2023 04:49:18 +0000 Received: from smtpav01.wdc07v.mail.ibm.com (smtpav01.wdc07v.mail.ibm.com [10.39.53.228]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 36B4nHCK34603388 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Jul 2023 04:49:17 GMT Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0A78558055; Tue, 11 Jul 2023 04:49:17 +0000 (GMT) Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2A5AB58063; Tue, 11 Jul 2023 04:49:12 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.43.86.43]) by smtpav01.wdc07v.mail.ibm.com (Postfix) with ESMTP; Tue, 11 Jul 2023 04:49:11 +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 v3 5/7] powerpc/book3s64/memhotplug: Enable memmap on memory for radix Date: Tue, 11 Jul 2023 10:18:31 +0530 Message-ID: <20230711044834.72809-6-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230711044834.72809-1-aneesh.kumar@linux.ibm.com> References: <20230711044834.72809-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: iew4llAaLdvPnwP5c6khYbjOxStUR01A X-Proofpoint-GUID: 06NDGcN6XjIVYL-dF1kmE_6ApCwGdXkg 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-11_02,2023-07-06_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 impostorscore=0 clxscore=1015 mlxlogscore=999 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307110040 X-Rspamd-Queue-Id: 45FE080008 X-Rspam-User: X-Stat-Signature: h4j7xb6jkgunrtodir5bxcrhrj18fu1c X-Rspamd-Server: rspam03 X-HE-Tag: 1689050967-796149 X-HE-Meta: U2FsdGVkX1+TS7sEUEBMEZFnF8Z2o8V7Kfvx7pD0+hdEHBeO9is6Hs2m786YbmytAMAOwe+12iJhDOj+/TK27o2DzmT5V3J/TgLTMgasaC8XBJNkBsSnmQUQ0FETkaPgA9XHvZPOLfULQhvBKGaTx41chtN2EZJNnp1FmLfmHhmMkeJz/BeRNBFYbs4WRQSTNY2H06bL0A5iI5nN1Kk2gEzK5vxtIfgjeuGnseqBwUa8GwDEufnbVh/g2lFatEaaKrDHcou9M/Jwyrgm2c6eOzwqh0AdrAvVLQAk8ZvGJiI8HAeEnRjXjebeYGyJ85KsJkFHJqqU3UXs1OT0in3/6ON5G4W1OpMpR6Pkgb7w2W6JEYG/Kl2RxMaon4cpjorRIfYfkw6EkDqg0f3CbebL89CyiH+Bsl1I4j4Fk/KcwIELS2yvZB9UIACLL+IG4IpZd3LdVfkksQmaFCDdjl9bhl0F4YuXCYyT58u1PAtXFjQs3JzTJ3t56VNYnDTd8BlXxuXaL/LLrxgbNEWXQVRZR+Y3oOeMX4Wh6KmVDsXPwoZdvk/4MjHuk8C92D3HotD7sBC5yZyCxB2osk/JKa9HKpOD+cQ064h79YzW4FW3mQk3kHHl4x7ZUziXIzm2btAdTUHxNgOeMTKL/r7zQWwrLSt9e0boILLjDwZU4DFzBftPNgCoFuaGnN8lrUiyGoiDR+USQUdaKwn8+1zcvObc9rfZm/IfvGh/lLHhkMp7OsbfP6GIjHCdv9WDQoQqcyiV0gELyjtJk5YCjGrjCgnD//PYI1wY5UoAkP4fVsX2X3rpM9+Q48Em/Wwrj7vPOHw2HZ/bEJg464oFcINmjkmb5VOkrWRWILlcO9kI+eT7X2G3AvlROmluRf2isWx8UPCbjy3J99zF2rJdwJFMSCYfwOJJ0PEnhfdEhqrZ+vy8zZM72gmxmwy6qQ7Gg3T9Sr8qM3XqFsqk/5XA4F2/3tY b2CBvHlO gGBexW+FMClLRFgtklOEH7pOjNfxJCVKZ4GuVXMuzMbmrT1k/3I7GezoWXui2e0ZLfOUmAETVeX1LBbDb1Bi3E44nz1qWkPkiJfMMwrySQ0sm0ZuYzwvJYYLfJdQBMFdM9BqoRR7wvdY8X3Q= 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. Hence we skip the restrictions w.r.t vmemmap size to be multiple of PMD_SIZE. This also makes the feature widely useful because to use PMD_SIZE vmemmap area we require a memory block size of 2GiB We can also use MHP_RESERVE_PAGES_MEMMAP_ON_MEMORY to that the feature can work with a memory block size of 256MB. Using altmap.reserve feature to align things correctly at pageblock granularity. We can end up losing some pages in memory with this. For ex: with a 256MiB 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/include/asm/pgtable.h | 28 +++++++++++++++++++ .../platforms/pseries/hotplug-memory.c | 3 +- mm/memory_hotplug.c | 2 ++ 4 files changed, 33 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/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h index 68817ea7f994..8e6c92dde6ad 100644 --- a/arch/powerpc/include/asm/pgtable.h +++ b/arch/powerpc/include/asm/pgtable.h @@ -169,6 +169,34 @@ static inline bool is_ioremap_addr(const void *x) int __meminit vmemmap_populated(unsigned long vmemmap_addr, int vmemmap_map_size); bool altmap_cross_boundary(struct vmem_altmap *altmap, unsigned long start, unsigned long page_size); +/* + * 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. + */ +#define arch_supports_memmap_on_memory arch_supports_memmap_on_memory +static inline bool arch_supports_memmap_on_memory(unsigned long size) +{ + unsigned long nr_pages = size >> PAGE_SHIFT; + unsigned long vmemmap_size = nr_pages * sizeof(struct page); + + if (!radix_enabled()) + return false; + +#ifdef CONFIG_PPC_4K_PAGES + return IS_ALIGNED(vmemmap_size, PMD_SIZE); +#else + /* + * Make sure the vmemmap allocation is fully contianed + * so that we always allocate vmemmap memory from altmap area. + * The pageblock alignment requirement is met by using + * reserve blocks in altmap. + */ + return IS_ALIGNED(vmemmap_size, PAGE_SIZE); +#endif +} + #endif /* CONFIG_PPC64 */ #endif /* __ASSEMBLY__ */ diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c index 9c62c2c3b3d0..1447509357a7 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 | MHP_MEMMAP_ON_MEMORY; unsigned long block_sz; int nid, rc; @@ -637,7 +638,7 @@ 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); + rc = __add_memory(nid, lmb->base_addr, block_sz, mhp_flags); if (rc) { invalidate_lmb_associativity_index(lmb); return rc; diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index f36aec1f7626..0c4d3fdd31a2 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -2108,6 +2108,8 @@ static int __ref try_remove_memory(u64 start, u64 size) * right thing if we used vmem_altmap when hot-adding * the range. */ + mhp_altmap.base_pfn = PHYS_PFN(start); + mhp_altmap.free = PHYS_PFN(size) - nr_vmemmap_pages; mhp_altmap.alloc = nr_vmemmap_pages; altmap = &mhp_altmap; }