From patchwork Mon Feb 17 09:29:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenhua Huang X-Patchwork-Id: 13977369 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 9AFD4C021A0 for ; Mon, 17 Feb 2025 09:29:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 85A426B00FF; Mon, 17 Feb 2025 04:29:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 80A186B0100; Mon, 17 Feb 2025 04:29:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6AABB6B0101; Mon, 17 Feb 2025 04:29:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4D4AD6B00FF for ; Mon, 17 Feb 2025 04:29:36 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E111681E0A for ; Mon, 17 Feb 2025 09:29:35 +0000 (UTC) X-FDA: 83128913910.21.95FDB9E Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf26.hostedemail.com (Postfix) with ESMTP id 78AE1140006 for ; Mon, 17 Feb 2025 09:29:33 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b="O6yFe/aE"; spf=pass (imf26.hostedemail.com: domain of quic_zhenhuah@quicinc.com designates 205.220.168.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=1739784573; 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: references:dkim-signature; bh=MMb+tLlYn6VHNWNF2n/4Z/lgRcF295GIGpb11Gobqag=; b=arZjLKYWx0ksWuoU/BPRDl753XYOviqv1dCLpM2R8yp2hAOBnHgKpVd4GCAit+OyPb3S2N J0oZ1nGGiPsKII21CcOsXpEsY2ue9UDqiX4/XXSyMEAeifliAfJ9DYCpwD3qQIqPjYMyj9 2wcH6O2avOmtz+xSTlrhE9Diu2VjiIM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b="O6yFe/aE"; spf=pass (imf26.hostedemail.com: domain of quic_zhenhuah@quicinc.com designates 205.220.168.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=1739784573; a=rsa-sha256; cv=none; b=lAThECvl9zHEC2Z8AT+/iHulQyXm01x/Q6ucQolvt/xNVx3S9QFHq/FInt6FZlkIwfb3M2 0lGeSwLP7TSsakKbIJE4gmU3g+ZM/A0YocZMJ1WfxjLNHq+DhUQo2HlaeWtKDJZM0bCUlX r5pzNbMPqacL5becD7zCgwX5As+IkpI= Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51H034L8022247; Mon, 17 Feb 2025 09:29:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=qcppdkim1; bh=MMb+tLlYn6VHNWNF2n/4Z/ lgRcF295GIGpb11Gobqag=; b=O6yFe/aEeENcOhSuFPpJ3DsB3ITW/m+5/wmpoo GmJ6MA0nX8NiDG7XCKFy/t1s1pJR/GoMKSDmEmf7bZq83ogmhwMuqNgTydhasFSw kTc1bLYe1H6yTdlwwMU8Op8K/5SmjaRhH9Ha7lcCWjYEk/8ZA18kHFByykIjxP41 UV4dT5D4FS8r2B22TQGCaxtuVpps4iE4MlKQudMoYwvBp+dtJC08G8LGREGmo6nj NVrDt6/FJ1rj0BrWVF1MwCYzNlwLTeHlRZjtSOVGSlOVCgtBg/Uw/1O6cx0hB28h FMiQ/b1xMuekjRyzz3rc7K9Q0mZYkDmduCxxnHYE4ofBHFug== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 44ut7u955s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Feb 2025 09:29:25 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA05.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 51H9TO53004284 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Feb 2025 09:29:24 GMT Received: from ap-kernel-sh01-lnx.qualcomm.com (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; Mon, 17 Feb 2025 01:29:20 -0800 From: Zhenhua Huang To: , , CC: , , , , , , , , , , , , , Zhenhua Huang Subject: [PATCH v7] arm64: mm: Populate vmemmap at the page level if not section aligned Date: Mon, 17 Feb 2025 17:29:07 +0800 Message-ID: <20250217092907.3474806-1-quic_zhenhuah@quicinc.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 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: ZOKV0jmXvUiSquowFIyeXjllNSgPbq_O X-Proofpoint-ORIG-GUID: ZOKV0jmXvUiSquowFIyeXjllNSgPbq_O X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-17_04,2025-02-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 mlxlogscore=999 spamscore=0 priorityscore=1501 phishscore=0 clxscore=1015 bulkscore=0 adultscore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2501170000 definitions=main-2502170083 X-Rspam-User: X-Rspamd-Queue-Id: 78AE1140006 X-Stat-Signature: gmkenhr5asfegjhnkgm9ywozecrwsqoc X-Rspamd-Server: rspam03 X-HE-Tag: 1739784573-31759 X-HE-Meta: U2FsdGVkX1827W4gcREPM0ooiYlUza2DqMuJfCHYfo9cMvEaZ7CSIKHHDPqTylBzJ3QytU3+WmGs5qCNlfply7nnbmAMhp4qbbHBcCB9Moicu8Jj/8KS97BEr4PtOZ64syiXQEbBPDKjFU0tcAafC67GNQ9wvhuLgesG8XwYjIrSb4T9M09uBsXtMSJoBq+xMM3CSoKIYqutMmBVK8k8xWpovm/6mWYw0CgeEj7vCtZc2rIrrp1B/WlnqwbLShIdioMYrT3Fsqw3nWN11dGgIDV8/mog8+a6wgWdhO1hDZVk7HPdG0Am+jRpy6oYokW2etaIKGp53n6pWCyHgsWn6EjAOw/G/uB5qabntnG3nGd8CwYQn/UTcqDXTU5F81rsZA0g4SyxcCscDTDAkB27eNxsV66aVaS4050RsHft13FUVq1D3EgcX54V0Zgv9B2k5jrKJWV6V/pYswlQeJDT8B6K48foUruu89xzR07t6a02L4NPZoDp0ITY+m/Eo50QVYshDOZCpvdwbU0/U5w4Bfr+0sMERkKmNh4tsfbMz+EWBmvq5XRQcY3RuJk8yjPy4irWHwCa82BbdpJ0cdgT1LWhvt38o/kntsxq0BmTIrQP55e+YoVY2kwEinvMvaaEN6JtubTBycvh5XCKMbG/q5c3BYOXYmsSVXfcQqa9qZh7HYvf0LHXE0XTVsB+qLOGqGuuopd3WV5php/IBuA9wlQ5jXAjtOzY5GrMKQWXE1h4Ig1Fibq2ntsJLzWyN2xc7nuIHkOt3WL9nyfoNLWRWvtmMg6bdORSGZjfqaEwltcdXH2/o+INxqR8x0T+Twp6lsImmgrRuPHdqnmv9FWYtYhoAuOHoWVZ0lVQ5QtqDUWlNPhzIg8WXSTBnab0JJJVHMmO1wMtHsVWdocovt9ayNXipXKvKxhEBiHLUrPQdVeTOqB3bjfUuHAXHrGS7FjsvbIl4KOePkLfU+i8CmI 6KtwYyqp E5ceCTMbUC5kVDgZtpG+ZjyawUmHrTvT1IO1n5iGaSGH5ewY2nZJ2mzzP6tlUAqY/pPsi868zz+1/PGTsQuGWy/7WcWXRoQaUsIT2mzNFoSmN/CQNhT0W10x6rwh0T/K2VVEvijracNP9aBJW/AZkYpQ0iptDBVtZxPxyfjGNt1pkmKidBJWuZjIaytdzKzWOXJ/mDP7BnzP6kvEZ0wykRqRMlpqwB1xiyoXu4lwlWMwJmNg4V1TIkTXMastHN3usOdBYneHM+QfM4L2gCQwUd+7wcsOefRQ/k6UA38MYBDtpiHpJ5Oj4AN869oS6+YbNT240 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 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. Signed-off-by: Zhenhua Huang --- arch/arm64/mm/mmu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index b4df5bc5b1b8..eec1666da368 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1178,7 +1178,8 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node, { WARN_ON((start < VMEMMAP_START) || (end > VMEMMAP_END)); - 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);