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: 15635 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp585794vqb; Thu, 19 Oct 2023 11:49:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6geMkyDjVOjrFdkbMiKHBRLmVbmx4G5m7zx18nlwPyP3blL5RFe0jHYqH0Ez4FQ1YKW4k X-Received: by 2002:a05:6e02:1e0b:b0:34c:e84b:4c5c with SMTP id g11-20020a056e021e0b00b0034ce84b4c5cmr4087603ila.27.1697741395844; Thu, 19 Oct 2023 11:49:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697741395; cv=none; d=google.com; s=arc-20160816; b=eZg6w+CYz5Jastd2wldsn74rIW5bo+2bC9hC7AdaxxO/fg8iOtkXEV6a85k/0Gyfzk QNryGZkT1vUYgVWXGug+8SUhc4orUQGsdKqsW3kI3ihONZknmikwQf35BnUs6XJTHSfN meuOd8n4KtzbWZT9Dla2p05HpBOmgFceiRootVWeHBvtyJ19ZljVsyx+zC+C2db79uXX SeNRUPbxrL7QB25dHzm3euC83+Y69ux3H+a7x1xecF6jBwbEGcnf0PG0u/saL8n2PNx7 QkIsAesrXkB2dEboHQELqxdiZeoNHybYIjK57L4KBaFt+Eej8HZ2Jt3cNXCJwPQy+mYw mdgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=eR7b89cZuKnf9caCq0WosvPgiZRtOTipOcLHpDu5GsI=; fh=JCb6YaKmbUpp/1fFgtqOrlyOUwhehZd1rxGbEgdh7vM=; b=jOWBt/5Y89zTrPmdBXQyobOa2O3ZggoGDWTXt4j0IPi9Uounpv87Pw//WH7hKK4TQQ cjcQXlHQCWvB5mp/VKyowMM3sXp+rh/xTRwVLFRi+WLm95NOPkgVZUFT5z956o4FC158 9aGHNdfOpIDtkWzxFaCXehC2qFaA9fOiBjnIfNSSYNodDN4iUaTj2PIi2ce770hZSUgk QA5LpUtfb68Exz01gsa0l8ElOXl+l/ht8Lc+XC5nNf3vHZ9GcY0H08KWUc4v8wAbNYBE 46lZdNDelYYNcZ1Vlfd2YBemsCvGdWFvBZZRfiu1rSNutNQ1I3DkSub0dr/FnO/SCKF2 8ssw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=OT7bsnQN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id h8-20020a056a00230800b006b6cc63a79csi245465pfh.330.2023.10.19.11.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 11:49:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=OT7bsnQN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 35D3583594B8; Thu, 19 Oct 2023 11:49:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345261AbjJSStf (ORCPT + 26 others); Thu, 19 Oct 2023 14:49:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233020AbjJSSta (ORCPT ); Thu, 19 Oct 2023 14:49:30 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BC02CA; Thu, 19 Oct 2023 11:49:29 -0700 (PDT) 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-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 19 Oct 2023 11:49:50 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780210881693893023 X-GMAIL-MSGID: 1780210881693893023 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(-)