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;