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 2C487E77188 for ; Wed, 8 Jan 2025 10:08:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 74D9F6B009C; Wed, 8 Jan 2025 05:08:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D5BB6B009F; Wed, 8 Jan 2025 05:08:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 503686B00A0; Wed, 8 Jan 2025 05:08:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2AFDD6B009C for ; Wed, 8 Jan 2025 05:08:10 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2F58112106B for ; Wed, 8 Jan 2025 10:08:09 +0000 (UTC) X-FDA: 82983859098.28.00B0868 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf02.hostedemail.com (Postfix) with ESMTP id D57DB8000D for ; Wed, 8 Jan 2025 10:08:06 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=CEfJkXXE; spf=pass (imf02.hostedemail.com: domain of quic_zhenhuah@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_zhenhuah@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736330887; a=rsa-sha256; cv=none; b=M4q9IO7GMQciqTAMjN979642l/l2Sw8/sjj31wO8A7CRCpe3v0kS/pRCRl5ZSj7Kr/XGiN Sjjnp/xClBcOtXqyROpbM9TD6siOyOocdeyxV8DWHLwEQbSLLMIzQDLufb4HCCkLhNSVu1 kDllFmFqTL/PrXVHJQf6oXpe+myQekI= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=CEfJkXXE; spf=pass (imf02.hostedemail.com: domain of quic_zhenhuah@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_zhenhuah@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736330887; 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=sT5CCRYl+x4dUMtMSCes2pYR6c6hZptBJnGGqNrq6lU=; b=CGKp08KWcTPqcaQkw83wJTvddRl87wumT3lujv4IR8/NOFrLCghsUDe/9sm5TLyi7zQiBq MzG2pGadqA6kgn7juhgOwxTWdqcZSJHeBuJswOFc50IKVXkUYmVKriQaWV/3EDlR4NyYu4 3oDF0RQ+5dqnxpOCAgz3d0KGkgBWp4k= Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5089AoMY010561; Wed, 8 Jan 2025 10:08:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= sT5CCRYl+x4dUMtMSCes2pYR6c6hZptBJnGGqNrq6lU=; b=CEfJkXXEDquByBeV lI9OtE+hzxpCj9ZdQ45dpLF4n2WcYh3dipYHDBoL7owkKBsUx2uzJkujv36+nEqu z+xiF+7ouA8eqiIwfxQtvG977MNLjpoUXFw2tSreDXcujUyLhr9iT4oe//OS8maT W8MYKb7hxzr6vu+7lirzyzM76mCIeEmZkj58uopaOF+IzMIIU8GO2DwD2tMugtYL Q3NBxNEJduIvIRGs/MgpQhDeyuNF6tZ7qdp268vhw9yvkGBdwupP0/YyNzbgpnmK WyJbdd6IGpFsVW9gF4Cpm48Vhx4xpa5yWwdHpatfs7DPPKN6fHZNoQDhNf+ctFxg GC/P1w== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 441pgnr4nn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Jan 2025 10:08:00 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 508A7xG0002623 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 8 Jan 2025 10:07:59 GMT Received: from [10.239.132.245] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Wed, 8 Jan 2025 02:07:55 -0800 Message-ID: <406d5113-ff3d-4c2a-81f0-de791bcbeffb@quicinc.com> Date: Wed, 8 Jan 2025 18:07:44 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4] arm64: mm: Populate vmemmap/linear at the page level for hotplugged sections To: Catalin Marinas CC: , , , , , , , , , , , , , , References: <20250107074252.1062127-1-quic_zhenhuah@quicinc.com> Content-Language: en-US From: Zhenhua Huang In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: YieeDtkFTNv0W_kqZ0sQDqfqPlypTFuo X-Proofpoint-ORIG-GUID: YieeDtkFTNv0W_kqZ0sQDqfqPlypTFuo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxlogscore=999 mlxscore=0 suspectscore=0 impostorscore=0 lowpriorityscore=0 spamscore=0 adultscore=0 phishscore=0 priorityscore=1501 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501080082 X-Rspamd-Queue-Id: D57DB8000D X-Stat-Signature: 1bsu8wgmb4dean5rshiccbgyrktrjob1 X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1736330886-894821 X-HE-Meta: U2FsdGVkX1+aWCySloVunRV9KUHOGyWfnJZ+UpHmYmi6IBZmvFFVK9vAQus0rOsMdrW33eVEoxbTSE1JYH+o2iU4no/e0kP3QeUhFQil5Dz8ufvsNYe/Sz4JVXae3lhxXI0hw343P2vGLqL/pOPLYXDNV90I6ymroo+uMj+TcI3HCQndjx8Fp1uVy0RIGhF/QIEwArAPJDHwgrlaLLoyk0edF5xoVUnvxzT9Fd2B5vUmEWxxV8gd6Y0bbEEMxVuGk+gqVFfwTsj6HjHZtybf7yUaqsv1ef8e7zcXPrJYFXYWLA2Cz+3ozkT8Qj3DG+fqxY30nbmXryKPIpJ46qFnAMgeCD3TuGr6RRFQu0IzFo1s7YRum58oeZSExluiwebId0J9spbBTMq2JaOJa8Xbai2uhAZUPVZF2mmF9HOqsUqcZaUdmmSSBrJU/hEDNthnKLZFeOtp9PukLvShiqZv4BZm0pa0SmrIe/gxIyNCE+Yv6LUF/Cx3UQ9xV060RZKCpyOXxi+QgaLC6sB8rZry1XcCvfveGmh6K3Qf7w1DFPeh59WDPJYc04CUnOEQorFeTrdKuaqkvULJmUQDBWEMZy+pY0jbHibSOEWr0r9wyidh1a4rNeapsINI4FytQOQRIXwDtrTrjsh0SONoDr0frYrjpMSXOI3sePwYpe1epgb7W8x8MEU9VXs/uWkagQjJbgIUYZwnyh+xH4u5c0y5vSHRMuzDkrJnV9pZAo8EZQSiqDjuXmoq+xviZYMIw17zU83r60sak4MCHHBDEY9RHfexjeR8IiH8rQ1mdSnYfMo+v0kLwEgx7/l3LGJnEx7PCxa5/VYJ7wYhqYcoUVcHaijY7IFt8mtcn+tMK+M/NAeOp/u676LCOLIB7s+uXcPBDrb4ryvdLqpP4xICr5ecAYfg5ywIZd35IA2vpm2y1EzaJsBperMbDjJoYSx2asJ9he0Ad9cFw8qweEz6UkU xRxiBLCT qL8fzEOIt07Kx5eFrjTRu5dK1xoFWiuKo+FthvlGzgaRouIwomQmlYghl9uU4B5RBfJ8bhXUMcDBVNFzMaV6tBhHmHmbn/qxBLAsUA/7yXx7gOh8QyPlKh2b7Vvx/sgqoXSk4F0w4M+xe7xEryf3nVwuHD5yLstKp+XUJUE0AN1avoR+FlAFYKIna0UZXV9316foVyH/XrCr2//g9JUo+TOwmzlR88g7Ia9nmV7i05QYT8mTyWfOkbIhnUbrJGuRXeCdgh4R7i1Npo8Yn3WtK9uvSMZ5mLdXljAQLxp5FSVZ2+jPjapfK5KH/3w== 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: Hi Catalin, On 2025/1/8 3:22, Catalin Marinas wrote: > On Tue, Jan 07, 2025 at 03:42:52PM +0800, Zhenhua Huang wrote: >> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c >> index e2739b69e11b..5e0f514de870 100644 >> --- a/arch/arm64/mm/mmu.c >> +++ b/arch/arm64/mm/mmu.c >> @@ -42,9 +42,11 @@ >> #include >> #include >> >> -#define NO_BLOCK_MAPPINGS BIT(0) >> -#define NO_CONT_MAPPINGS BIT(1) >> -#define NO_EXEC_MAPPINGS BIT(2) /* assumes FEAT_HPDS is not used */ >> +#define NO_PMD_BLOCK_MAPPINGS BIT(0) >> +#define NO_PUD_BLOCK_MAPPINGS BIT(1) /* Hotplug case: do not want block mapping for PUD */ >> +#define NO_BLOCK_MAPPINGS (NO_PMD_BLOCK_MAPPINGS | NO_PUD_BLOCK_MAPPINGS) > > Nit: please use a tab instead of space before (NO_PMD_...) > >> +#define NO_CONT_MAPPINGS BIT(2) >> +#define NO_EXEC_MAPPINGS BIT(3) /* assumes FEAT_HPDS is not used */ >> >> u64 kimage_voffset __ro_after_init; >> EXPORT_SYMBOL(kimage_voffset); >> @@ -254,7 +256,7 @@ static void init_pmd(pmd_t *pmdp, unsigned long addr, unsigned long end, >> >> /* try section mapping first */ >> if (((addr | next | phys) & ~PMD_MASK) == 0 && >> - (flags & NO_BLOCK_MAPPINGS) == 0) { >> + (flags & NO_PMD_BLOCK_MAPPINGS) == 0) { >> pmd_set_huge(pmdp, phys, prot); >> >> /* >> @@ -356,10 +358,11 @@ static void alloc_init_pud(p4d_t *p4dp, unsigned long addr, unsigned long end, >> >> /* >> * For 4K granule only, attempt to put down a 1GB block >> + * Hotplug case: do not attempt 1GB block >> */ > > I don't think we need this comment added here. The hotplug case is a > decision of the caller, so better to have the comment there. Yeah, will remove. > >> if (pud_sect_supported() && >> ((addr | next | phys) & ~PUD_MASK) == 0 && >> - (flags & NO_BLOCK_MAPPINGS) == 0) { >> + (flags & NO_PUD_BLOCK_MAPPINGS) == 0) { >> pud_set_huge(pudp, phys, prot); > > Nit: something wrong with the alignment here. I think the unmodified > line after the 'if' one above was misaligned before your patch. Noted and will correct in next patch. > >> >> /* >> @@ -1175,9 +1178,21 @@ int __meminit vmemmap_check_pmd(pmd_t *pmdp, int node, >> int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node, >> struct vmem_altmap *altmap) >> { >> + unsigned long start_pfn; >> + struct mem_section *ms; >> + >> WARN_ON((start < VMEMMAP_START) || (end > VMEMMAP_END)); >> >> - if (!IS_ENABLED(CONFIG_ARM64_4K_PAGES)) >> + start_pfn = page_to_pfn((struct page *)start); >> + ms = __pfn_to_section(start_pfn); > > Hmm, it would have been better if the core code provided the start pfn > as it does for vmemmap_populate_compound_pages() but I'm fine with > deducting it from 'start'. I found another bug, that even for early section, when vmemmap_populate is called, SECTION_IS_EARLY is not set. Therefore, early_section() always return false. Since vmemmap_populate() occurs during section initialization, it may be hard to say it is a bug.. However, should we instead using SECTION_MARKED_PRESENT to check? I tested well in my setup. Hot plug flow: 1. section_activate -> vmemmap_populate 2. mark PRESENT In contrast, the early flow: 1. memblocks_present -> mark PRESENT 2. __populate_section_memmap -> vmemmap_populate > >> + /* >> + * Hotplugged section does not support hugepages as >> + * PMD_SIZE (hence PUD_SIZE) section mapping covers >> + * struct page range that exceeds a SUBSECTION_SIZE >> + * i.e 2MB - for all available base page sizes. >> + */ >> + if (!IS_ENABLED(CONFIG_ARM64_4K_PAGES) || !early_section(ms)) >> return vmemmap_populate_basepages(start, end, node, altmap); >> else >> return vmemmap_populate_hugepages(start, end, node, altmap); >> @@ -1339,9 +1354,25 @@ int arch_add_memory(int nid, u64 start, u64 size, >> struct mhp_params *params) >> { >> int ret, flags = NO_EXEC_MAPPINGS; >> + unsigned long start_pfn = page_to_pfn((struct page *)start); >> + struct mem_section *ms = __pfn_to_section(start_pfn); > > This looks wrong. 'start' here is a physical address, you want > PFN_DOWN() instead. Sorry, my mistake.Thanks for catching it. > >> >> VM_BUG_ON(!mhp_range_allowed(start, size, true)); >> >> + /* should not be invoked by early section */ >> + WARN_ON(early_section(ms)); >> + >> + /* >> + * 4K base page's PMD_SIZE matches SUBSECTION_SIZE i.e 2MB. Hence >> + * PMD section mapping can be allowed, but only for 4K base pages. >> + * Where as PMD_SIZE (hence PUD_SIZE) for other page sizes exceed >> + * SUBSECTION_SIZE. >> + */ >> + if (IS_ENABLED(CONFIG_ARM64_4K_PAGES)) >> + flags |= NO_PUD_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; > > In theory we can allow contiguous PTE mappings but not PMD. You could > probably do the same as a NO_BLOCK_MAPPINGS and split it into multiple > components - NO_PTE_CONT_MAPPINGS and so on. > >> + else >> + flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; > > Similarly with 16K/64K pages we can allow contiguous PTEs as they all go > up to 2MB blocks. Yes! > > I think we should write the flags setup in a more readable way than > trying to do mental maths on the possible combinations, something like: > > flags = NO_PUD_BLOCK_MAPPINGS | NO_PMD_CONT_MAPPINGS; > if (SUBSECTION_SHIFT < PMD_SHIFT) > flags |= NO_PMD_BLOCK_MAPPINGS; > if (SUBSECTION_SHIFT < CONT_PTE_SHIFT) > flags |= NO_PTE_CONT_MAPPINGS; Good idea indeed. We no longer need to worry about PAGE SIZE CONFIG. > > This way we don't care about the page size and should cover any changes > to SUBSECTION_SHIFT making it smaller than 2MB. >