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 B8A18C02198 for ; Wed, 12 Feb 2025 18:28:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 502A96B0082; Wed, 12 Feb 2025 13:28:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B2886B0083; Wed, 12 Feb 2025 13:28:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A0F46B0085; Wed, 12 Feb 2025 13:28:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1C4F46B0082 for ; Wed, 12 Feb 2025 13:28:49 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BC22FA028A for ; Wed, 12 Feb 2025 18:28:48 +0000 (UTC) X-FDA: 83112128736.20.DD7AD4E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id F33F58000D for ; Wed, 12 Feb 2025 18:28:46 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1739384927; 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=uy7nNmG2QRu1VTT14GwdMWSLsoZv24r+YKj1EbV0UcE=; b=NijN4vun1cIXxcOBzCwlVyJcEKJthMtlijT1zSKOP2We6NnsVyyO6orD5OEomfxpObSbtu l0W8pqKVHp94yFQ3EVpZUplli6SqfyLrUMz49OlDgaxuVVlxHvnnPTd77CVCbA1qhh2kmv fV7HLgGisar+m0mBIdKVU3aQB7Jp8sA= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739384927; a=rsa-sha256; cv=none; b=K6OKBjbhzwgkhy+Bvhrxq69iFEsEIG9UirOaLUq6t1RX3rO+KmeQyFx1GUp2HeVnQPHOkw +oQwzi4AulCjBS9aR3sP1cQGp/izYNQdtZ4ILt+Zv5yieIZJqXKievCrWk52WIKnC2Wnz6 +6tLH4APqm8cDPPL7Q17aDhcP36ymO8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 833105C4B58; Wed, 12 Feb 2025 18:28:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CD73C4CEDF; Wed, 12 Feb 2025 18:28:42 +0000 (UTC) Date: Wed, 12 Feb 2025 18:28:40 +0000 From: Catalin Marinas To: Zhenhua Huang Cc: anshuman.khandual@arm.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 v5] arm64: mm: Populate vmemmap/linear at the page level for hotplugged sections Message-ID: References: <20250109093824.452925-1-quic_zhenhuah@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250109093824.452925-1-quic_zhenhuah@quicinc.com> X-Rspamd-Queue-Id: F33F58000D X-Stat-Signature: 5e6o3u89qya3a7cy35e5m6nbk6ceb8dy X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1739384926-931163 X-HE-Meta: U2FsdGVkX19yKAphWOkfZyyFo0Jlby5WopIOBRWH0ceDjjc7oj5fa1Pvpab10VoKZJJsiXmrRDsDNbCsVXm6VjV6fKsGBSSrQ40ipcl7mnCg00qNI3ZsAVv5FufsYgYmIJkClE0XPh0tsl2/ojx9a8VoiVjhT+eVexFHMIQ2weoWh44xz6zL6i2kZrNzvdMtAMEwzrd62biX3ehIaejcJryPxVE6vK278pRnrh7XL9v4N83DC+VJnV+yz1q9NgiMicuXDWGbqLWB7y1UeFkCAgxiglDXZugz/b83vMb2DZ3q4C+H1NowgJsOX0Xr6Ef9iPvQBObLRS8UgbFuUdo/kpxgPD5loniBSq3j17cIN5zoNwd9YpAJpyv1UMCgt/dVMjs5BgTkIIxzbHSSeu4+hfbw17ETNjMpNiCVUQooD0VCI24FNk4kWH/6lJKmRgjx/jT+EPKSHbkTWHLrW4qTP5SThLCF7MR3IkCi8L1dhab5f5wNJHsf5zBuBN9botbVhRzwEfZsP8qDyBW7rQyH/+hudbdTcSLCS7KDySlMEVPu+dugZNVSzCd9loVCIQiDlED4rahyrxvehU9jh9Yl+4JwxQH8Wo2uoX1C9YDXGTlMPIHsxKCb0eWqHkfAIBNDxm/xAg6s4rGWQf2YOjf8I+O0U2QoLij9StQ8MJqnLkNGyCnhYVikZFXVdAorxbbAjiDA497TLd6qT0z5YPxpj0xxdx4v+7JHWahkNqdGFQ2mh0NCv2HuXaqnSteWaGS3FZ9onHqtLFbgGvdaVQZo971VMYMaxwil5FkVNmci5AT7422Wsp3Uz1fmRgeGKIckC2K28+WvkGHc/fA1M9ug4KnwgNnpK6Zn+JJpPZJcpENTRRLfAp3S84FmwM9dHug9gmI3cjRY3bS9d0WunWFytvpZCq4GsRs0+nBzV1bLREiQKSNazkvyfQxES468R58XQgxGYAwKE53KcSrr3KM pv+khJ+7 jq2THhCY62zxomjhGEkaLj+TO/0ADc/NO38aIbQI5ASMDrsA+o/wHPjz4VlKmN5X/26bukC5x0l+NPSsEwGzvzyDoxm3w3tHYwGKLoK9zXMxJNagdhb9Nr+aRWaMIt9bOe9Whiiq8TiFzno3zcGNBTWnU+qbSBO//5DsYPGT2FzYYfH5Qk2QIoWUXv8GwdSVvUpsiEzjN/gq8V4XjTy1HJvwD3RLppusTKnc9zV5RBR0+JSKeX/Ds4x86xHRZPqBpKjwWOnX0cdjtmCQD4ZTYfTpq3aGp/ci/w61vEYtcQzsSHauhkGODlEGVOgVoq4tsOUhE/G2UYLVrpu0dYJ8gs0Uf6iGQpGHa8HcfAKOf4oeLTAPhF2JcbDBxSbeKMaHjzDozyOWvPTD5GeIvROEyNUVhEL6EXz+PlFXA7Z/DP5sxj9c5G45i19jwWrqE+dwcbI7j/pJkXU4wbWtK2iRfhEQ8bGG5SDwfu0W0l31bDc37mDA= 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 Thu, Jan 09, 2025 at 05:38:24PM +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. > > Considering the vmemmap_free -> unmap_hotplug_pmd_range path, when > pmd_sect() is true, the entire PMD section is cleared, even if there is > other effective subsection. For example page_struct_map1 and > page_strcut_map2 are part of a single PMD entry and they are hot-added > sequentially. Then page_struct_map1 is removed, vmemmap_free() will clear > the entire PMD entry freeing the struct page map for the whole section, > even though page_struct_map2 is still active. Similar problem exists > with linear mapping as well, for 16K base page(PMD size = 32M) or 64K > base page(PMD = 512M), their block mappings exceed SUBSECTION_SIZE. > Tearing down the entire PMD mapping too will leave other subsections > unmapped in the linear mapping. > > To address the issue, we need to prevent PMD/PUD/CONT mappings for both > linear and vmemmap for non-boot sections if corresponding size on the > given base page exceeds SUBSECTION_SIZE(2MB now). > > Cc: stable@vger.kernel.org # v5.4+ > Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug") > Signed-off-by: Zhenhua Huang > --- > Hi Catalin and Anshuman, > I have addressed comments so far, please help review. > One outstanding point which not finalized is in vmemmap_populate(): how to judge hotplug > section. Currently I am using system_state, discussion: > https://lore.kernel.org/linux-mm/1515dae4-cb53-4645-8c72-d33b27ede7eb@quicinc.com/ The patch looks fine to me, apart from one nit and a question below: > @@ -1339,9 +1349,27 @@ int arch_add_memory(int nid, u64 start, u64 size, > struct mhp_params *params) > { > int ret, flags = NO_EXEC_MAPPINGS; > + unsigned long start_pfn = PFN_DOWN(start); > + struct mem_section *ms = __pfn_to_section(start_pfn); > > VM_BUG_ON(!mhp_range_allowed(start, size, true)); > > + /* should not be invoked by early section */ > + WARN_ON(early_section(ms)); I don't remember the discussion, do we still need this warning here if the sections are not marked as early? I guess we can keep it if one does an arch_add_memory() on an early section. I think I suggested to use a WARN_ON_ONCE(!present_section()) but I completely forgot the memory hotplug code paths. > + > + /* > + * Disallow BlOCK/CONT mappings if the corresponding size exceeds Nit: capital L in BlOCK. Either way, Reviewed-by: Catalin Marinas