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: 13977391 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6ABA3C021A0 for ; Mon, 17 Feb 2025 09:44:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=MMb+tLlYn6VHNWNF2n/4Z/lgRcF295GIGpb11Gobqag=; b=uj2bI1kIWRhYAbxMuUX/WJ6PKt aqy9Pjxu/ccVKGnMd366XdchvRF6zIkHmidBKjmj/+UtPAeYMOpoe21A06LWd+Iuiv07ywNWI+lPL W3tbUUyTEjHnoIdFiso3uDEh2mb0AcC5lVGlqWIBLuU5wLgkGFC7BchpWAiuHKNxFP6sv85zG08x/ Gkqt1do06Sy6tbVK5T7DOiWViG1Mpdkh4ZVvbJOk2j6JHw18Daa9iXBm5rO2NqTb4KrscuF1IYsY6 jt3tpwId1vmgN5JlxuMrb6julb6xNbqJAdsi1gAazDFO3AhfTwmZDz9POdj8l/eU9ZKAWNHfQkZuJ XOAqNuMw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tjxfO-00000003yZD-41ho; Mon, 17 Feb 2025 09:43:54 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tjxRi-00000003vsB-2ign for linux-arm-kernel@bombadil.infradead.org; Mon, 17 Feb 2025 09:29:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To:Content-ID: Content-Description:In-Reply-To:References; bh=MMb+tLlYn6VHNWNF2n/4Z/lgRcF295GIGpb11Gobqag=; b=W85EnauchUgoW6wOuAaOGMHR6v vl4f6LB3gJdgE95pYSwaYmGg9Q9ZVaHO1ecKYqcBP8qmTK+pqiyRwsnJGkaLqKoXgplpdOTs53SGn n6Y7gbLNy623SiXbyhJN9c1RGSnVfRV17tH18Y4qGJ4TULWcQo3UoHjdNvX7BQcxnO2tg3E6LbkEQ rXAaipRJF9yinV1xhsPVM1qP0VYuk1ryAG+/agfw9wxmY69QGWo1DqbvlveO/qjMiVZeyXf1kxD1u dXzBRB7oH1I9GS5SEVeaGXOzK9ZoLb/Rv69XjdHttxXYIkcIhw8NTtVUaPwff6rS6mo4MDA+gwCVn HQn9yx7A==; Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tjxRf-00000001kt9-1Ltb for linux-arm-kernel@lists.infradead.org; Mon, 17 Feb 2025 09:29:45 +0000 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250217_092943_790940_06D2FAA6 X-CRM114-Status: GOOD ( 14.68 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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);