From mboxrd@z Thu Jan 1 00:00:00 1970 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 DA57DEB64DC for ; Tue, 11 Jul 2023 15:41:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B0AF6B0072; Tue, 11 Jul 2023 11:41:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 339EB6B0074; Tue, 11 Jul 2023 11:41:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 18C8C6B0075; Tue, 11 Jul 2023 11:41:17 -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 0466B6B0072 for ; Tue, 11 Jul 2023 11:41:17 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9F5B11A0307 for ; Tue, 11 Jul 2023 15:41:16 +0000 (UTC) X-FDA: 80999744952.21.7304E1B Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf08.hostedemail.com (Postfix) with ESMTP id 1AE6B160018 for ; Tue, 11 Jul 2023 15:41:13 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=X9jrfrYE; spf=pass (imf08.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=1689090074; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5yydZFlElCVG4pegshd1EZfsfCQim0k9/oE/biT7m4g=; b=8YAhe+UqCtf34U2ZwTG215L8rr64JSt6N4+xHakK+ziF5u6YDTUsbE9ne4l0nL8Hg4R4RA o/4DlS5ZLefGe9vN6zov7ZHgdD4RyiFeMdvy0Dz+qix5nFlK115FMaHn/YtSRyJDeHwqaI gaCvQZkn+3aPRSxFx9ckxldgL5s6Hvw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689090074; a=rsa-sha256; cv=none; b=ioiQvNUfN9o76DgJSY1eFJJ+UMVjlCfzMoznOyqU0I7gzhAnOtnGkpbZ7qjS5NSgecxTbN Ce5bXMVp7sfJojbWL08DAdHRisIjVH+HdplOebWGMthK2alqWaJ4+js4mpCvinRh5Z1tVp mHa+jynk19bz0AkHth9XrHNEjCMcEKo= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=X9jrfrYE; spf=pass (imf08.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 36BFd4hj032041; Tue, 11 Jul 2023 15:41:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=5yydZFlElCVG4pegshd1EZfsfCQim0k9/oE/biT7m4g=; b=X9jrfrYEF+SB2Fpkz1JRYwVsRFG2CR45mIv7ZNYmLB8yL8dbdYaMu1rhTA2adYHnmoAm Ep0HdS4uqGVx6+a9CWq3c+wKg15cuw0vi2QP0+wDvlwQpu8tCX2eQIsC345y+8NC9WYJ m1sSubOZMLTtKF0LmQxhVl91WOvWjqObTJfKjgb3sFoPHxgjHzCue93Ha1vfrkCoYuE2 p4lv5/D80xHpp9261jBswFDApRRYLsenpztDd/zsEML5trc6I0cvF/fu5TuTCkaXDZHO LI+qPzeacwulLrJ1XxMp22k+zeijoYdRPBtD+9T1j13/DCTSPdRjT5sSJEsOnALfSAdz 1w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rs9nk8c9u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Jul 2023 15:41:04 +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 36BFd6M3032387; Tue, 11 Jul 2023 15:41:04 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 3rs9nk8c9m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Jul 2023 15:41:04 +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 36BEEQJH018476; Tue, 11 Jul 2023 15:41:03 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3rqmu0r59r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Jul 2023 15:41:03 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 36BFf14Q13501056 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Jul 2023 15:41:01 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9222220040; Tue, 11 Jul 2023 15:41:01 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E40642004B; Tue, 11 Jul 2023 15:40:58 +0000 (GMT) Received: from [9.43.86.43] (unknown [9.43.86.43]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 11 Jul 2023 15:40:58 +0000 (GMT) Message-ID: <006e24f1-1261-1018-4125-02dd354da519@linux.ibm.com> Date: Tue, 11 Jul 2023 21:10:57 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v3 5/7] powerpc/book3s64/memhotplug: Enable memmap on memory for radix Content-Language: en-US To: David Hildenbrand , 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 , Michal Hocko , Vishal Verma References: <20230711044834.72809-1-aneesh.kumar@linux.ibm.com> <20230711044834.72809-6-aneesh.kumar@linux.ibm.com> <98285185-170f-10fb-67a7-09e35ab47650@redhat.com> From: Aneesh Kumar K V In-Reply-To: <98285185-170f-10fb-67a7-09e35ab47650@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: fSg6mmAw1MeUYfKyZxcvArf24p_UuVTa X-Proofpoint-GUID: Y2wf3quj-g9xFrS6D1RiD9385B4zgS1h 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_08,2023-07-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 spamscore=0 adultscore=0 impostorscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 phishscore=0 suspectscore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307110139 X-Rspamd-Queue-Id: 1AE6B160018 X-Rspam-User: X-Stat-Signature: di4d67cyomt84nrwtu6m8icintxqk7xs X-Rspamd-Server: rspam03 X-HE-Tag: 1689090073-297762 X-HE-Meta: U2FsdGVkX1/EHaOTa6aOBQHP1kGZmgGZ/R1i6VS0OB+A+yRYk6/dJpcOGS+l+SEqirOoNkIEWg4TLbrWhnusssbtQtugoga0SFdKxhGDBaLeWlRojjU4mP///BYjfi3PZwR8LBy3WY5E5l0hPYe8NSCYQL1AFqOclx8oOoT1boSOkKXSg4WLm73BPAjVKTQ2iaMP7FY8PL+0BXo7oSfDEVL6Ne87HkWaGAFSpOJYfNrtnek650hxwVE0Bkz1LI0wlM6wuNLnLaEUOn5voyTWI3tkSxVQ+nO6ht+mJZvHxMC+n0sQlpYEKn7z6JedO0rXcO33veeKhP4sNy89UIrfHL4Kgi0hyQJxoI57xZnM1v5CANUXLcnA+bZVb4kPOG7OZ9xjU5EqerHmgQgtv0O2FyWYGswCYz0MvkeaXtFd4h+G2wa5MWzNWM1iTWftzkEn43mlRu0XPn6dGD/NhAB3nOPevZ09c6J1Mb0ds6OBvRE8R1TaMM/TeemBmUdPJ9S7msYg1epQ7oHRZWI0e3kFvllnwLkwkG0XFYNJhZxWvh2dgNwrICLr5SEwVM1QGhn95RqiJckqeaIZLoTKZKIEsz90SjOae79HtZ1chZDrQVLXWURmnVyURitbLi9vwxOJsarLh3Uq1W/xISTjSZXds/2bK8zAPip0zRbx00es+iMbwTh5fAKMdN9O06oEl5ZRtdHsf8FbTRn/eEuItEtb5LE+uZ13Iki/VUTbuUPwjtbXlvOFCLDY4dDm9gjZb9bmpjSVESpboG8B7kwdZZ7mxKjGzDYdg8ayJGIMRuxkYOOFo0rQ2qBFOYN3sx4DRWzQ3E2bHOA9dRt+yrX8ecoSuFvw06iRt4UiHFyIEf7uthSUG+lUTbOj7guKMnbPgAAyNyKDxZFCxwL6aOicNC1e67OaNVjQIhR7PtJQFXJcmi4lKGHdWwrhsi4fpcgQYnRYAAHabgUO3390yA7pJQA dM5StyKu voupQC/CYGUpchgLtXdyzPBmoilWXNbJHb69Is+IX/p5Q5iVOMfqCksPuR+fWk1fnqgjGkU4xwrkHi2v6NIfTisWngy+ZrOXz/T078QIyd6wos1WV9qRZwMIKW8gQ6TRto97IDECdGRS/ptN8utAXM0oSf5GJlV7FH8f7NkIQL/RJsGdaslhxu1CPYM225yM4cX2TTH2FYHkyLo9Ew5bd5piYpzH+SvgTR16FjlDhOiIiU0UQEpYRmV4HcA== 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: On 7/11/23 8:56 PM, David Hildenbrand wrote: > On 11.07.23 06:48, Aneesh Kumar K.V wrote: >> 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); > > Can we move that check into common code as well? > > If our (original) vmemmap size would not fit into a single page, we would be in trouble on any architecture. Did not check if it would be an issue for arm64 as well in case we would allow eventually wasting memory. > For x86 and arm we already do IS_ALIGNED(vmemmap_size, PMD_SIZE); in arch_supports_memmap_on_memory(). That should imply PAGE_SIZE alignment. If arm64 allow the usage of altmap.reserve, I would expect the arch_supports_memmap_on_memory to have the PAGE_SIZE check. Adding the PAGE_SIZE check in mhp_supports_memmap_on_memory() makes it redundant check for x86 and arm currently? modified mm/memory_hotplug.c @@ -1293,6 +1293,13 @@ static bool mhp_supports_memmap_on_memory(unsigned long size) */ if (!mhp_memmap_on_memory() || size != memory_block_size_bytes()) return false; + + /* + * Make sure the vmemmap allocation is fully contianed + * so that we always allocate vmemmap memory from altmap area. + */ + if (!IS_ALIGNED(vmemmap_size, PAGE_SIZE)) + return false; /* * Without page reservation remaining pages should be pageblock aligned. */