From patchwork Tue Mar 4 07:27:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenhua Huang X-Patchwork-Id: 14000079 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 5BB85C021B8 for ; Tue, 4 Mar 2025 07:27:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DAE6D6B0085; Tue, 4 Mar 2025 02:27:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D5F0A280001; Tue, 4 Mar 2025 02:27:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C25776B0089; Tue, 4 Mar 2025 02:27:30 -0500 (EST) 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 A594E6B0085 for ; Tue, 4 Mar 2025 02:27:30 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 52F7EA7FA3 for ; Tue, 4 Mar 2025 07:27:30 +0000 (UTC) X-FDA: 83183038260.29.A3F6708 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf29.hostedemail.com (Postfix) with ESMTP id 3D2F9120003 for ; Tue, 4 Mar 2025 07:27:28 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=MP3UWa8F; spf=pass (imf29.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=1741073248; 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=cz8mwoQe3GYg7tuptNj/Asda9H316llc4gDpuYCBPHQ=; b=g6vfdvqHBJY+XVcYZM7WK0be15qvIwMTgnC+bMqpL8rHL1FYWbwHwzSGZ3BK/l3apEsJyB tBQ27Q/P58I3MwJ7C8fXn3VwpwiPKmT7gqtREHibp5dBJjVf2Me4w/NWbaPNyyzyqx+tQ2 nOuFDFA79054rVY2PoHVd+PXAF9/SUw= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=MP3UWa8F; spf=pass (imf29.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=1741073248; a=rsa-sha256; cv=none; b=v0BlXWXdCxY3m5m9QeEyb+5cMDSETlTliGj3lPKPX+eJRPYb/i72WCap5cbwWfmRhQRM5I JfA5QF8zXw27SLyej/za+g/hzZYLYtdCe4v/paI7QX30JYxmXtBg+343b+hSwZQGB3q7sI xdxc1y8SHpmK/RKdWtn7RG55KJ6qTUQ= Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 523NXXo8007052; Tue, 4 Mar 2025 07:27:22 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=cz8mwoQe3GYg7tuptNj/As da9H316llc4gDpuYCBPHQ=; b=MP3UWa8Frj5QM1eDEGIuUVYiIGXAsQopuF5PEd lIZDU+XQE3UTR0lT1Mu1qvZyi37PboVW36HpnFHZA4rLxV9FSu1DnNaj60zVCTQO nxwOIkikHizH2RUqVtdNhvl4cjJOJA42nWHae8/9lpvWtOeDPEhelnbX85GVItsN McWWNnQUKnX645yBZvSw7W6nm5ttaxb8h4cDL5kRRNXs5EC5iu3uUd0fJreozcD1 g56Jc5BWdkP1WNz4iDYEpyS3Z4HZbyeAHGYIY9I4BmemnpkyMTw5Uy6/8GxguNg2 fGEbwST74eDKYTfrFS6zErV09yOwufH232v+H9r/C/t3DpdA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 455p6th0v8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 04 Mar 2025 07:27:22 +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 5247RLbv014113 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 4 Mar 2025 07:27:21 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, 3 Mar 2025 23:27:16 -0800 From: Zhenhua Huang To: , , CC: , , , , , , , , , , , , , Zhenhua Huang , Subject: [PATCH v9] arm64: mm: Populate vmemmap at the page level if not section aligned Date: Tue, 4 Mar 2025 15:27:00 +0800 Message-ID: <20250304072700.3405036-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: nasanex01a.na.qualcomm.com (10.52.223.231) 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-Authority-Analysis: v=2.4 cv=HZbuTjE8 c=1 sm=1 tr=0 ts=67c6ab5a cx=c_pps a=ouPCqIW2jiPt+lZRy3xVPw==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=GEpy-HfZoHoA:10 a=Vs1iUdzkB0EA:10 a=VwQbUJbxAAAA:8 a=20KFwNOVAAAA:8 a=COk6AnOGAAAA:8 a=NceqpOgtns4pJs_QtpcA:9 a=TjNXssC_j7lpFel5tvFf:22 X-Proofpoint-GUID: IPE3Tm_3UXzTcBxsIgZ8AE2r4qJy0ZOf X-Proofpoint-ORIG-GUID: IPE3Tm_3UXzTcBxsIgZ8AE2r4qJy0ZOf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-04_03,2025-03-03_04,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 mlxscore=0 spamscore=0 clxscore=1015 phishscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 suspectscore=0 malwarescore=0 mlxlogscore=999 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.19.0-2502100000 definitions=main-2503040061 X-Rspam-User: X-Stat-Signature: 5hcdu8bjmuftkiwg1n3gw31jsommcrgq X-Rspamd-Queue-Id: 3D2F9120003 X-Rspamd-Server: rspam07 X-HE-Tag: 1741073248-747643 X-HE-Meta: U2FsdGVkX18UAqnZQPAgKv9N3n3rDIqQlrE4V3EVjwpJ9Opc7DarIRmyWbV/GAlyXBCbBjzkzr35jCR5S9tsPT08Lv0gIDO+XWyUu2BrESDGe4b1greVLIKTdILMfCtq1x3KgEgfa9Zqc4/Sne2KSgN/wGkN3DMFHeF/pYj/FzTNAT8+1blppihoG0TskbbhG//AD28Zazm9n6UFyq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ph+r3x0OJRrUIT5D0KLzviS0NL6l0SFe4OHEJtkxQpPvtcGD1xzPFyVV1ktXFI81k/L499I= 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. Cc: # v5.4+ Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug") Acked-by: David Hildenbrand Signed-off-by: Zhenhua Huang Reviewed-by: Oscar Salvador --- arch/arm64/mm/mmu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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);