From patchwork Tue Jul 18 02:44: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: 13316693 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 635A2EB64DC for ; Tue, 18 Jul 2023 02:44:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 06BF96B007E; Mon, 17 Jul 2023 22:44:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 01BC28D0001; Mon, 17 Jul 2023 22:44:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFF8A6B0081; Mon, 17 Jul 2023 22:44:55 -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 D400D6B007E for ; Mon, 17 Jul 2023 22:44:55 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B5FF4B0ED1 for ; Tue, 18 Jul 2023 02:44:55 +0000 (UTC) X-FDA: 81023190150.18.445D006 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf15.hostedemail.com (Postfix) with ESMTP id 5FCECA000A for ; Tue, 18 Jul 2023 02:44:53 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=hGnztzR0; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf15.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=1689648293; 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=LkFHfh9uSQDI/r/WIP7SzQwU2qKL/y6mKGMPa0SG5yE=; b=fj9c1j77zAbe58itzr83JOhOcBhbTJ/CRGA+kC+P5p3Xgh1H6qh/odNBbCRNPb4uG3dupQ z+vQbFB54ann9Boob375yESSNpN0ONXIlI6CIM3rTH415eDdqkIvLqSKXiWbHrM1N9cURU efvFUZZfi+99SPi1miYK3yL2IcpQ5fQ= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=hGnztzR0; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf15.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=1689648293; a=rsa-sha256; cv=none; b=I8Xt95KdVeZE2nywCmo+cRJtf9vvafv4FmVCEWxU/9Xe6B7ZDClXD/CaVyOYI8mF7sAJgm PqWp0LtAAzK262vBTl92O3lrgnEhOHKsuNrmWj3npVolD4TTr7d5yW8gNHBsxMbLMYZzJA UDkjmBy2lsFoGSLCKh35a5l/XjugkIo= Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36I2grfG011835; Tue, 18 Jul 2023 02:44:44 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=LkFHfh9uSQDI/r/WIP7SzQwU2qKL/y6mKGMPa0SG5yE=; b=hGnztzR0ca/y8BLep+xPvHsJeAQouR0wTTgpn9wPZynwbr6Ibi8eaIdd4710udxN/fHK NH3BsJF9dkN/Ok2rZYnBGfuC/zg2rjSa74ynp9aWvI+nwv4Tt09XjtealdpG4Sj9GMpO 0DhmOhUqfMP8oz+arkHHG1/7xwGc9rU5lQeFFCvbWdovIJswPA0bnRgIwt4qdhHbwLz4 uZoX6vVPdHZ3ZD1dGUU5qbg79CBoHc25kWcq3UZGfX9QT4LYC8XKt/qwBheh1ZqzxpWN Xy4k1gzNEfTfvxcmNZ+ubDyYy/S/QoWPu8fv5q3rmbV9Z8IAdzJMcWJ43mA+3FJIBlD3 2A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rwj6gr0vn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Jul 2023 02:44:43 +0000 Received: from m0353726.ppops.net (m0353726.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 36I2ig94016746; Tue, 18 Jul 2023 02:44:43 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rwj6gr0va-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Jul 2023 02:44:42 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 36I0VVhP004183; Tue, 18 Jul 2023 02:44:42 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([172.16.1.71]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3rv8g0vjkd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Jul 2023 02:44:42 +0000 Received: from smtpav02.dal12v.mail.ibm.com (smtpav02.dal12v.mail.ibm.com [10.241.53.101]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 36I2ieOT35521104 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Jul 2023 02:44:41 GMT Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BE5D35805F; Tue, 18 Jul 2023 02:44:40 +0000 (GMT) Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C4B8E5805A; Tue, 18 Jul 2023 02:44:36 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.43.62.199]) by smtpav02.dal12v.mail.ibm.com (Postfix) with ESMTP; Tue, 18 Jul 2023 02:44:36 +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 v4 5/6] powerpc/book3s64/memhotplug: Enable memmap on memory for radix Date: Tue, 18 Jul 2023 08:14:08 +0530 Message-ID: <20230718024409.95742-6-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230718024409.95742-1-aneesh.kumar@linux.ibm.com> References: <20230718024409.95742-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: lLZ4TmkfpjG09hPnXuQpGqkJXDJoD7u3 X-Proofpoint-GUID: WJbr-P-9oOJ8U2sZnmQEHRwhlzTvvOQo 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-17_15,2023-07-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 impostorscore=0 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 malwarescore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307180022 X-Rspamd-Queue-Id: 5FCECA000A X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 5mocchjgorz5w3r9dkua3kwiiw1j1mr9 X-HE-Tag: 1689648293-401951 X-HE-Meta: U2FsdGVkX1+Ko/pIi4O/rj7enyq2dBRcNE/g1lV0IYEza4SJd98nG9BjVWmnIxnvTCsT6ojtupmwqYbxoNqRlllOay4P8tUS3/RGVG62Q3YhTB1hNDWvOp2ZaYcdv8tmUXfVaeXmNsVZZMSUZss5e7l7+tH1eefP4dwqlQEy7lnpV9bnrC3jGWrYX/fZg8EVdUCkf5jBbU9key1tOabsS5cpml1kdNxSEMiZ/MuRpLynYaWJs9sQlmyu5Gtgah7bsLynFATxRpxsgIuuGIyEhUM1U2b/QYJIJjSWBcmEL4bez9f9TGvodSXwcOIk+71Js75mxSasgQWfPvBFZbeoZHo2OLNNw4o556q/+k/uNlDJkL1cOv3wjGhmPdsQRFLWGXmSSLkr3dx7l/HYz1L5KHC3t6wM2QNsCPsocEUDGDn+VLoc7L9o6rZ6VtwViowwCpKAXXqUHEF65Qa7zRXvbSO39nk+MS1bJnq4wUc078EP0HjXumwLtXYH9LxWE8/hHDT5DeGUKEnuxtifLQu/YJK2OzAAGtx4bBsSiDKiIrPWASMrG5MuSgn5Lc180rt7wt7ENjMOFuOOCGhsXrbPvLECFHpRuGwDo1/XQAfWWV1rxFVhc8cQrI2h1x0ckbqY2WwjI85+bQQBmZYMY4Ud/hkroEUlXgT04XPQdAVWgKB97Fc7oh4+DbU8WSmNbSZVtco7WBQcdOXyzysrmgsZbFistvcoW5S75wFrHoAantDOHk6PWdD9s2AoaPLyPF8QBEgAks9HikNBoRi9gCBaqmWYuU6fLthIfwP1wFC6Qe0qgavyJenfoRoOZWbiZSbh7fYw5/DoKotdsPf/YY/lEMzprUydnZFDyZB0GeYzdY0YPtwI2Okd1G0Py6eJpctgxRZEA1nreqtmtpmZLxFo9cvNjeSuNxsLW2D87bO73ZJmRPOcwT72BhvmDA9kzy2J8Xgu3Oq3TgpzBnuclfm AlgSm4T7 /EdRV7l1APbR2XVgJqhetK3jQXwvE6LEpm3Aqtx3inoHiOaPFVq8mQ8y1jVxqWAAnz/SCbRPoDIcQLmlKo11V5DSTv57xz233yIx67c+0kYMUxsdzZfxxJCwny7iRV0dfbKtyTvauHR/UYnlENk8jxXfljZ6SxH4NLkt8pk3YxPgu2IUSqxmyOYeLh/TB738DiwaR1z1s9d3fG+ePLQV+56fNZ4biJ0bn3xUw1I1/Ky0pUPo= 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 | 24 +++++++++++++++++++ .../platforms/pseries/hotplug-memory.c | 3 ++- mm/memory_hotplug.c | 2 ++ 4 files changed, 29 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..3d35371395a9 100644 --- a/arch/powerpc/include/asm/pgtable.h +++ b/arch/powerpc/include/asm/pgtable.h @@ -169,6 +169,30 @@ 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; + + if (IS_ENABLED(CONFIG_PPC_4K_PAGES)) + return IS_ALIGNED(vmemmap_size, PMD_SIZE); + /* + * The pageblock alignment requirement is met by using + * reserve blocks in altmap. + */ + return true; +} + #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 c409f5ff6a59..6da063c80733 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -2174,6 +2174,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; }