From patchwork Thu Oct 19 18:48:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oreoluwa Babatunde X-Patchwork-Id: 13429720 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 4DA54CDB465 for ; Thu, 19 Oct 2023 18:49:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=2ZoEWVeZnhLnW+eJzTBmX4aQt+QY1Sgs5V4HIYvsMhM=; b=Bi5FwPsor0uP49 8skQYl0S8O0TUwFIHjbQg9SyKXIkMLVo3poEUfe3x/JPBVnRp4HwIlf3tMb8YX6rx5/egSLt+/d/E UIUdwUhmZna3ot06EHwSv9PprxhYS2mEgf5dvsZ7aUAhDJxetpL64rTPSD0gVSyvR9NJ9OqH4U9eK 07odP2szWs9uf5tuB1sHJSMeJkyoWnk4mINJVIX1JFfJsXxURqlzu9PCnPLBc+E6tMYTzHaar/nsX kl1u/QHDJ+/mERnBQ+WpFTrwby7r6scgpjFqOAIBmvvfsHsia/eT63407Qg6mMftaZyYOLyAheeYa Fv/InVO+bW2iuYFwkPsw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtY5J-000XTY-27; Thu, 19 Oct 2023 18:49:29 +0000 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtY5G-000XSB-32 for linux-arm-kernel@lists.infradead.org; Thu, 19 Oct 2023 18:49:28 +0000 Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39JHLR8m013588; Thu, 19 Oct 2023 18:49:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=qcppdkim1; bh=eR7b89cZuKnf9caCq0WosvPgiZRtOTipOcLHpDu5GsI=; b=OT7bsnQNWU84BV9l6NtrIaqGJxjqv1iN5UR4W+9xJ+siriggN0e1U1pVgXfSN/Zf+3A2 WCzn+4V7ps4Yg++TgEfP4PUyf7/yTFrWh8on0T3vr/YLj3Nshh59O2Yu/EZYS7TAQU6J IuKoqTakT8wYxTbOzqAPfB2jOUuuKHYDx8q27lfQPPEPsV3S89qDs5tGTWlYhSXvyYvR Iim1JJZZq4t3J66JQJkbAloSQmvzYf4HQLnDzuTyYYEXOX2hlZqkvIl6xm1ZdXevXnkU x/ybVnBbR38of1ighSEK51/tjrYGpYfbM45gQ8KPKKFeFV+GV5JAKZ6ZNK1nZtv3Auy1 iA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tu14csc7m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 19 Oct 2023 18:49:16 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39JInG95015686 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 19 Oct 2023 18:49:16 GMT Received: from hu-obabatun-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.39; Thu, 19 Oct 2023 11:49:13 -0700 From: Oreoluwa Babatunde To: , , , CC: , , , , , Oreoluwa Babatunde Subject: [RFC PATCH 0/3] Dynamic allocation of reserved_mem array. Date: Thu, 19 Oct 2023 11:48:22 -0700 Message-ID: <20231019184825.9712-1-quic_obabatun@quicinc.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: KkC8AwBNYhVCWLzLADvrgaS_JCiGor3r X-Proofpoint-ORIG-GUID: KkC8AwBNYhVCWLzLADvrgaS_JCiGor3r X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-19_18,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=455 clxscore=1011 suspectscore=0 impostorscore=0 adultscore=0 bulkscore=0 mlxscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310190160 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231019_114927_114328_2203F3FC X-CRM114-Status: GOOD ( 24.96 ) 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 The reserved_mem array is used to store the data of the different reserved memory regions specified in the DT of a device. The array stores information such as the name, node, starting address, and size of a reserved memory region. The array is currently statically allocated with a size of MAX_RESERVED_REGIONS(64). This means that any system that specifies a number of reserved memory regions greater than MAX_RESERVED_REGIONS(64) will not have enough space to store the information for all the regions. Therefore, this series changes the reserved_mem array from a static array with a fixed size of MAX_RESERVED_REGIONS(64), to a dynamically allocated array, using memblock_alloc(), based on the number of reserved memory regions specified in the DT. Memory gotten from memblock_alloc() is only writable after paging_init() is called, but the reserved memory regions need to be reserved before then so that the system does not create page table mappings for them. It is possible to call memblock_resverve() and memblock_mark_nomap() on the reserved memory regions and not need to save them to the array until we dynamically allocate the array after paging_init(), but this becomes an issue with reserved memory regions that do not have their starting address specified in the DT. i.e. regions specified with the "alloc_ranges" and "size" properties. Therefore, this series achieves the allocation and population of the reserved_mem array in two steps: 1. Before paging_init() Before paging_init() is called, iterate through the reserved_mem nodes in the DT and do the following: - Allocate memory for dynamically placed reserved memory regions and store their starting address in the static allocated reserved_mem array. - Call memblock_reserve() and memblock_mark_nomap() on all the reserved memory regions. - Count the total number of reserved_mem nodes in the DT. 2. After paging_init() After paging_init() is called: - Allocate new memory for the reserved_mem array based on the number of reserved memory nodes in the DT. - Transfer all the information that was stored in the static array into the new array. - Store the rest of the reserved_mem regions in the new array. i.e. reserved memory nodes specified with the "reg" property. The static array is no longer needed after this point, but there is currently no obvious way to free the memory. Therefore, the size of the initial static array is now defined using a config option. Since its size would vary depending on the user, scaling it can help get some memory savings. Oreoluwa Babatunde (3): of: reserved_mem: Change the order that reserved_mem regions are stored of: reserved_mem: Add code to dynamically allocate reserved_mem array of: reserved_mem: Make MAX_RESERVED_REGIONS a config option arch/arm64/kernel/setup.c | 4 ++ drivers/of/Kconfig | 13 ++++ drivers/of/fdt.c | 63 +++++++++++++++---- drivers/of/of_private.h | 3 +- drivers/of/of_reserved_mem.c | 108 ++++++++++++++++++++++---------- include/linux/of_fdt.h | 1 + include/linux/of_reserved_mem.h | 9 +++ 7 files changed, 154 insertions(+), 47 deletions(-)