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 AE389C19F32 for ; Wed, 5 Mar 2025 18:59:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 28ED3280008; Wed, 5 Mar 2025 13:59:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 240C5280003; Wed, 5 Mar 2025 13:59:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1072C280008; Wed, 5 Mar 2025 13:59:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E55DC280003 for ; Wed, 5 Mar 2025 13:59:50 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0E659C09B7 for ; Wed, 5 Mar 2025 18:59:50 +0000 (UTC) X-FDA: 83188411782.21.9BB4776 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf19.hostedemail.com (Postfix) with ESMTP id 4297F1A000F for ; Wed, 5 Mar 2025 18:59:49 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf19.hostedemail.com: domain of cmarinas@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741201189; a=rsa-sha256; cv=none; b=A3tf1ioUViiB7fRA4amuSocnvfRpPfVr3doIysHhenFa/mpzmCCToNU/Qz18hKsttvAar1 32MLzhskbv2cjJAPfv5G9c6PrG9088I6+r5BPhB0TaE+zZ0jcatI4yefxWT6wfqV9Colvm 3a0FyzSzkpOWBLVHUBAe7H3xZrg1aRc= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf19.hostedemail.com: domain of cmarinas@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741201189; 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: in-reply-to:in-reply-to:references:references; bh=CTT4VlJeLCC6/l/jodN5fkT+Y2Y1zsiD3qYQ2wYCV1c=; b=vPHth/CZRtu+mXqbWCEq4cykDZaP2Tu7RFTDCeTXuMO61nwbouqVr1cG+6vZ7u20B6wjzH rroDj3mJYuWFcgHDtLxVISjMkfdAXvwN/ccsTIOKNkT+3SAnE3eImqir2UX1tXMr0utWbU Fn2SN67N9qlQmUaaoua16HmE7SkX0kg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id BA10DA45F6E; Wed, 5 Mar 2025 18:54:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5ADD8C4CED1; Wed, 5 Mar 2025 18:59:45 +0000 (UTC) Date: Wed, 5 Mar 2025 18:59:43 +0000 From: Catalin Marinas To: Zhenhua Huang Cc: anshuman.khandual@arm.com, david@redhat.com, will@kernel.org, ardb@kernel.org, ryan.roberts@arm.com, mark.rutland@arm.com, joey.gouly@arm.com, dave.hansen@linux.intel.com, akpm@linux-foundation.org, chenfeiyang@loongson.cn, chenhuacai@kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, quic_tingweiz@quicinc.com, stable@vger.kernel.org Subject: Re: [PATCH v9] arm64: mm: Populate vmemmap at the page level if not section aligned Message-ID: References: <20250304072700.3405036-1-quic_zhenhuah@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250304072700.3405036-1-quic_zhenhuah@quicinc.com> X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 4297F1A000F X-Stat-Signature: ncfgit7intqcy68anwdp8w3c77pifo4w X-Rspam-User: X-HE-Tag: 1741201189-529892 X-HE-Meta: U2FsdGVkX194mMYMhiR+6H3BkpWF2KzFisGp8MdDtvgJRtN/8hLisYF0uKvjYOgGDjg2OPQSDUd+BJG9eKe3oXTLp2rEyvI5H2HsxNGtITlma6zE2yhuVS+VSOQNXXYHIqZVzSk+BqDm5G60TCTqT0nBo/FUtcFKcG+ZgzocRc+UGVuPEh6zmIJfK1KnDt0GCUqgQT3tjr+jkfflhMKTdtDFmAj7tu9gTGxbHz7XIbHQS5qhjU0Etm0OvsnaxBBPkGsEzAHRaw9o+4BDLDHkV7HKzMreTU6DxX8Dl2gK7LI5vrfUDhdLQBzalFlK9SGQBOtR0vrFqqJzYZzWWQ6UdAUhZOo0k4o3hFPS8MO0n6KoAxI0WwJPyW+d224f7t191yWnICVKvoKAjjwDUvTddWOYt7PDwqFQ6eHxuq1ZCqZZjQT/F3XvTqxdbLCcTldc0l8Rp6Nls1pzKPPoUUbxbvM9tQEjXfkVVi6U7IhUMC8x9S9RfLGWuPDSyqvA7oWUbgpHoQpd1ZgR2dmrkrp95+jgkr/t42+WAHcJS8BtwnqHKzh/iylM5/ayt/UmwULfTnTegLH8+GIN0IoidRJlG1M2j/Qg/kj8yZd8M37d/7ddoAXQBul5bXKgyL56N2rqZ6TddyLH+f2GIODIrd70TZ0vULl9zJo//+WJmVSunpw+jALJ/RaVWghexnoYzhy5ZsmiLV1NSEFsRGWdZVXSOlgbOuNy06pUo8tpVnoxvW2F5NrvD4TWY9MxAh/ayZotT2r9LO9a7v5//2/Qqp6URFjDYywv9tT1PtKcOoTCVF0bx4HITr23rDSp56zNMPE/SXwRD3YCsCGbFpxnJlWAklLeLUFdpHTusINze2aiA+V5hytdaQVXZk/MoGdO24ngEHAmQ/ETvEdrg7EFjVaqwTJOA6VnpCQ0ESr7dP6oVRFm0m9DgdusGpgzT90EgGkkBahO/comINAJMdFAGwC Ww3DrpUC D9vWGbycNeA6wI8VutQXY/mRBYFVg5S6ZoCfNTa8BoNckOq5flzDTASU5DO4VCPjPWMgwtfAwNglmY8l5ferDA0r7SGrFsGfg9619xzvxk/pZcP5OZYGkS79BMG+m7unzC5TdHdZPK44GFYjzNfHdmTA+J8/q2QrTPQ2CEoIIYUPDemGybMLfR1CjFnnLhW+Ldi/RLTa4rkgwkzeD9w5j3MaIoIA4/+jRy7Ziq7I2woANz9APA+fnNNLAYxqJP+luy12JFFPMHCWNDXq+o7XiK0oU35vKEhoN9aTtfoV3MIs1uGv8qn4utK+18E4mfDpNIBx+DiTiNOFK1Mhql4+siequgWnVKuxfTCRJjlODdm+3icRuXIk/SCjwYfBL0HWrh6J2X3Z9lDZHabJhuZhs9Wtjoy2Mg9t5QB/AEWdrWGwu0I53zZrAEEV+ORaOkA8nreEA4sb2+/gJjB84mQ0YI/BD5U5vvW++9OqJtiHovLtp8zCimStg0/2t3wR3hGYwmNI3 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: List-Subscribe: List-Unsubscribe: On Tue, Mar 04, 2025 at 03:27:00PM +0800, Zhenhua Huang wrote: > On the arm64 platform with 4K base page config, SECTION_SIZE_BITS is set > to 27, making one section 128M. The related page struct which vmemmap > points to is 2M then. > Commit c1cc1552616d ("arm64: MMU initialisation") optimizes the > vmemmap to populate at the PMD section level which was suitable > initially since hot plug granule is always one section(128M). However, > commit ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug") > introduced a 2M(SUBSECTION_SIZE) hot plug granule, which disrupted the > existing arm64 assumptions. > > The first problem is that if start or end is not aligned to a section > boundary, such as when a subsection is hot added, populating the entire > section is wasteful. > > The next problem is if we hotplug something that spans part of 128 MiB > section (subsections, let's call it memblock1), and then hotplug something > that spans another part of a 128 MiB section(subsections, let's call it > memblock2), and subsequently unplug memblock1, vmemmap_free() will clear > the entire PMD entry which also supports memblock2 even though memblock2 > is still active. > > Assuming hotplug/unplug sizes are guaranteed to be symmetric. Do the > fix similar to x86-64: populate to pages levels if start/end is not aligned > with section boundary. > > Cc: # v5.4+ > Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug") > Acked-by: David Hildenbrand > Signed-off-by: Zhenhua Huang > --- > arch/arm64/mm/mmu.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) Reviewed-by: Catalin Marinas Will, another bug that has been around for ages. Do you want to take it as a fix? > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > index b4df5bc5b1b8..1dfe1a8efdbe 100644 > --- a/arch/arm64/mm/mmu.c > +++ b/arch/arm64/mm/mmu.c > @@ -1177,8 +1177,11 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node, > struct vmem_altmap *altmap) > { > WARN_ON((start < VMEMMAP_START) || (end > VMEMMAP_END)); > + /* [start, end] should be within one section */ > + WARN_ON_ONCE(end - start > PAGES_PER_SECTION * sizeof(struct page)); > > - if (!IS_ENABLED(CONFIG_ARM64_4K_PAGES)) > + if (!IS_ENABLED(CONFIG_ARM64_4K_PAGES) || > + (end - start < PAGES_PER_SECTION * sizeof(struct page))) > return vmemmap_populate_basepages(start, end, node, altmap); > else > return vmemmap_populate_hugepages(start, end, node, altmap); > -- > 2.25.1 > -- Catalin