From patchwork Mon Dec 4 04:13:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oreoluwa Babatunde X-Patchwork-Id: 173064 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2542061vqy; Sun, 3 Dec 2023 20:15:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHmu0GZxeYBeSqoeYQdrO6kM36bnCSXGhsjGo4KSIslec+fEhgm/OJCXaPtaQDhqIE7TLHW X-Received: by 2002:a05:6358:f653:b0:170:17eb:14bb with SMTP id ky19-20020a056358f65300b0017017eb14bbmr970861rwb.43.1701663338031; Sun, 03 Dec 2023 20:15:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701663337; cv=none; d=google.com; s=arc-20160816; b=yvJdvod7yIMgaQmkKsT0krAKQe2BbjPj0YzTnlN46g6uVMTeEYo/hQwe/iU55jc89R fh4xN//rom2nGhQa/KWlQq1JAs4T3pjaIo4eC6acoUWaKJaLvNHB7CNtqFotbhZNJtSk berZNuqjDEeErAawEr/GUXbJjW8g+fhG2DmwJ91q8PQce0hIChTM78uUGwQIbyNh5zRx v5n07L1Bebd9tfLlTzaiZapsjiaMCrkx33QgBGPizgQtruMTRgTGq3/4LYjsFpAbR57S +P3n2az9qqD6GTQ+D5Rb7UR8pkKb/CDgFQnCct1/6E9Vz0VXpUMU8qeB6O+R1O7nabv0 frUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=68XQWt2ukXHAU7islNTLqvCEjilOcERTt9Qh8Q/Ie0U=; fh=JCb6YaKmbUpp/1fFgtqOrlyOUwhehZd1rxGbEgdh7vM=; b=mJwyT1WnX7zKTqXA92Cz2uEA5SO66JitkrdgFtUuJHG1LHO6Xy4Mx9bvuTQjKcIbZC 9O1LOeTzwNU2GajM2l4HAREv2wgMNmu9Ek435Wxow0QuIBbfLM/KzuP++QYGg6/c/lgx aWSvQIyA3xy33hhU7qIwchuFl5648szuHpxrWmgypnWDFS8qaHq1bnas/xzYuRSET9m6 ov40nknnJDchWNdx+qQi2urUTBCZ+EiVyISLUnMg21CUjZtzAjfQvFtv82x+cCkCcrrv TUiZ5mhEh9dKH/bxyRIE/obnggOFhmEOr15a5dDLoanBrvezIjfEy+KqQJCNVJtnmhfD WqjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Lc6j53mQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id px17-20020a17090b271100b002774d978e19si7251570pjb.175.2023.12.03.20.15.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 20:15:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Lc6j53mQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 4D6698060831; Sun, 3 Dec 2023 20:15:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234584AbjLDEPP (ORCPT + 99 others); Sun, 3 Dec 2023 23:15:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234499AbjLDEPB (ORCPT ); Sun, 3 Dec 2023 23:15:01 -0500 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B096910E; Sun, 3 Dec 2023 20:14:47 -0800 (PST) Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B42tYN9015981; Mon, 4 Dec 2023 04:14:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=68XQWt2ukXHAU7islNTLqvCEjilOcERTt9Qh8Q/Ie0U=; b=Lc6j53mQtxmBjm869hn95g7jDNEP2x/qMr1bVxIkgotSiEEdKyq48xmQw+6+UIMftE/2 2zuL+UWj7uSNmXycmoKgmDfVvGE6YypWRdNX5UIQ6Cs4x206Ps0bQqGnQ2uWbleuaXCt 5tqiYP1zNXt7uME4Jj5hLRM4Z8q3BSU7FLxWEHGj3irC/BO05a0jkYWDhNHrZJ7PWHL1 Nvem1G7zAl0rwOWinTa8Uj2Jn+lq7SLSaZAie7KGJ+tS6dbulnOdVDFwH095srDAT3/V bhMBpcynnJqGoZFe4ldI9Ncl7lXZOZKr0dTNZSwsJOQBfbtAWrG/YMhApjXeaEIytyKu Rg== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3uqwrvtrp7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 04 Dec 2023 04:14:36 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3B44E0XW004714 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 4 Dec 2023 04:14:00 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.40; Sun, 3 Dec 2023 20:13:57 -0800 From: Oreoluwa Babatunde To: , , , CC: , , , , , Oreoluwa Babatunde Subject: [RFC PATCH v2 1/6] of: reserved_mem: Change the order that reserved_mem regions are stored Date: Sun, 3 Dec 2023 20:13:34 -0800 Message-ID: <20231204041339.9902-2-quic_obabatun@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231204041339.9902-1-quic_obabatun@quicinc.com> References: <20231204041339.9902-1-quic_obabatun@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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-ORIG-GUID: 9QOo5EJW0eVhJNApmAfixljyAdyc76hs X-Proofpoint-GUID: 9QOo5EJW0eVhJNApmAfixljyAdyc76hs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-04_02,2023-11-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 bulkscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 priorityscore=1501 mlxscore=0 spamscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2312040031 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Sun, 03 Dec 2023 20:15:34 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784323336736093313 X-GMAIL-MSGID: 1784323336736093313 The dynamic allocation of the reserved_mem array needs to be done after paging_init() is called because memory allocated using memblock_alloc() is not writeable before that. Statically-placed reserved memory regions can wait until after paging_init() to be stored in the array because the starting address and size information is already specified in the DT. Dynamically-placed regions on the other hand does not have its starting address specified in the DT because it is allocated at runtime. Hence, the starting address of these regions need to be stored somewhere. The allocation of dynamically-placed regions cannot be done after paging_init() either to avoid getting regions that are already added to the page table mappings. Hence, change the code to: 1. Before paging_init(), allocate and store information for the dynamically-placed reserved memory regions. 2. After paging_init(), store the information for the statically placed reserved memory regions in the array. All the regions are also reserved or marked as nomap as needed before paging_init(). Signed-off-by: Oreoluwa Babatunde --- drivers/of/fdt.c | 63 ++++++++++++++++++++++++++++----- drivers/of/of_reserved_mem.c | 53 ++++++++++++--------------- include/linux/of_fdt.h | 1 + include/linux/of_reserved_mem.h | 6 ++++ 4 files changed, 84 insertions(+), 39 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index bf502ba8da95..34223c249914 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -504,7 +504,6 @@ static int __init __reserved_mem_reserve_reg(unsigned long node, phys_addr_t base, size; int len; const __be32 *prop; - int first = 1; bool nomap; prop = of_get_flat_dt_prop(node, "reg", &len); @@ -532,10 +531,6 @@ static int __init __reserved_mem_reserve_reg(unsigned long node, uname, &base, (unsigned long)(size / SZ_1M)); len -= t_len; - if (first) { - fdt_reserved_mem_save_node(node, uname, base, size); - first = 0; - } } return 0; } @@ -564,7 +559,56 @@ static int __init __reserved_mem_check_root(unsigned long node) } /* - * fdt_scan_reserved_mem() - scan a single FDT node for reserved memory + * Save the reserved_mem reg nodes in the reserved_mem array + */ +void __init fdt_scan_reserved_mem_reg_nodes(void) + +{ + int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); + const void *fdt = initial_boot_params; + phys_addr_t base, size; + const __be32 *prop; + int node, child; + int len; + + node = fdt_path_offset(fdt, "/reserved-memory"); + if (node < 0) { + pr_err("Reserved memory: Did not find reserved-memory node\n"); + return; + } + + if (__reserved_mem_check_root(node) != 0) { + pr_err("Reserved memory: unsupported node format, ignoring\n"); + return; + } + + fdt_for_each_subnode(child, fdt, node) { + const char *uname; + + prop = of_get_flat_dt_prop(child, "reg", &len); + if (!prop) + continue; + + if (!of_fdt_device_is_available(fdt, child)) + continue; + + uname = fdt_get_name(fdt, child, NULL); + if (len && len % t_len != 0) { + pr_err("Reserved memory: invalid reg property in '%s', skipping node.\n", + uname); + continue; + } + + base = dt_mem_next_cell(dt_root_addr_cells, &prop); + size = dt_mem_next_cell(dt_root_size_cells, &prop); + + if (size) + fdt_reserved_mem_save_node(child, uname, base, size); + } +} + +/* + * fdt_scan_reserved_mem() - scan a single FDT node for reserved memory. */ static int __init fdt_scan_reserved_mem(void) { @@ -591,7 +635,7 @@ static int __init fdt_scan_reserved_mem(void) err = __reserved_mem_reserve_reg(child, uname); if (err == -ENOENT && of_get_flat_dt_prop(child, "size", NULL)) - fdt_reserved_mem_save_node(child, uname, 0, 0); + __reserved_mem_alloc_size(child, uname); } return 0; } @@ -645,8 +689,6 @@ void __init early_init_fdt_scan_reserved_mem(void) break; memblock_reserve(base, size); } - - fdt_init_reserved_mem(); } /** @@ -1335,6 +1377,9 @@ void __init unflatten_device_tree(void) of_alias_scan(early_init_dt_alloc_memory_arch); unittest_unflatten_overlay_base(); + + /*Initialize the reserved_mem regions*/ + fdt_init_reserved_mem(); } /** diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 7ec94cfcbddb..8bd8bbc3aaec 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -132,8 +132,7 @@ static int __init __reserved_mem_alloc_in_range(phys_addr_t size, * __reserved_mem_alloc_size() - allocate reserved memory described by * 'size', 'alignment' and 'alloc-ranges' properties. */ -static int __init __reserved_mem_alloc_size(unsigned long node, - const char *uname, phys_addr_t *res_base, phys_addr_t *res_size) +int __init __reserved_mem_alloc_size(unsigned long node, const char *uname) { int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); phys_addr_t start = 0, end = 0; @@ -212,10 +211,7 @@ static int __init __reserved_mem_alloc_size(unsigned long node, uname, (unsigned long)(size / SZ_1M)); return -ENOMEM; } - - *res_base = base; - *res_size = size; - + fdt_reserved_mem_save_node(node, uname, base, size); return 0; } @@ -310,6 +306,8 @@ void __init fdt_init_reserved_mem(void) { int i; + fdt_scan_reserved_mem_reg_nodes(); + /* check for overlapping reserved regions */ __rmem_check_for_overlap(); @@ -328,30 +326,25 @@ void __init fdt_init_reserved_mem(void) if (prop) rmem->phandle = of_read_number(prop, len/4); - if (rmem->size == 0) - err = __reserved_mem_alloc_size(node, rmem->name, - &rmem->base, &rmem->size); - if (err == 0) { - err = __reserved_mem_init_node(rmem); - if (err != 0 && err != -ENOENT) { - pr_info("node %s compatible matching fail\n", - rmem->name); - if (nomap) - memblock_clear_nomap(rmem->base, rmem->size); - else - memblock_phys_free(rmem->base, - rmem->size); - } else { - phys_addr_t end = rmem->base + rmem->size - 1; - bool reusable = - (of_get_flat_dt_prop(node, "reusable", NULL)) != NULL; - - pr_info("%pa..%pa (%lu KiB) %s %s %s\n", - &rmem->base, &end, (unsigned long)(rmem->size / SZ_1K), - nomap ? "nomap" : "map", - reusable ? "reusable" : "non-reusable", - rmem->name ? rmem->name : "unknown"); - } + err = __reserved_mem_init_node(rmem); + if (err != 0 && err != -ENOENT) { + pr_info("node %s compatible matching fail\n", + rmem->name); + if (nomap) + memblock_clear_nomap(rmem->base, rmem->size); + else + memblock_phys_free(rmem->base, + rmem->size); + } else { + phys_addr_t end = rmem->base + rmem->size - 1; + bool reusable = + (of_get_flat_dt_prop(node, "reusable", NULL)) != NULL; + + pr_info("%pa..%pa (%lu KiB) %s %s %s\n", + &rmem->base, &end, (unsigned long)(rmem->size / SZ_1K), + nomap ? "nomap" : "map", + reusable ? "reusable" : "non-reusable", + rmem->name ? rmem->name : "unknown"); } } } diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index d69ad5bb1eb1..7b2a5d93d719 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -73,6 +73,7 @@ extern int early_init_dt_scan_root(void); extern bool early_init_dt_scan(void *params); extern bool early_init_dt_verify(void *params); extern void early_init_dt_scan_nodes(void); +extern void fdt_scan_reserved_mem_reg_nodes(void); extern const char *of_flat_dt_get_machine_name(void); extern const void *of_flat_dt_match_machine(const void *default_match, diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h index 4de2a24cadc9..dc13bcd04b12 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -38,6 +38,7 @@ int of_reserved_mem_device_init_by_name(struct device *dev, struct device_node *np, const char *name); void of_reserved_mem_device_release(struct device *dev); +int __reserved_mem_alloc_size(unsigned long node, const char *uname); struct reserved_mem *of_reserved_mem_lookup(struct device_node *np); #else @@ -60,6 +61,11 @@ static inline int of_reserved_mem_device_init_by_name(struct device *dev, static inline void of_reserved_mem_device_release(struct device *pdev) { } +static inline int __reserved_mem_alloc_size(unsigned long node, const char *uname) +{ + return -ENOSYS; +} + static inline struct reserved_mem *of_reserved_mem_lookup(struct device_node *np) { return NULL; From patchwork Mon Dec 4 04:13:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oreoluwa Babatunde X-Patchwork-Id: 173066 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2542092vqy; Sun, 3 Dec 2023 20:15:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6mmjjsM8iU/pPz5Jqa6GcXwzlHVwF32xDjbArujQn9FxBsTJPHX5NMBL4cMiFY69UOPe5 X-Received: by 2002:a17:90b:1b03:b0:286:54d3:3a1b with SMTP id nu3-20020a17090b1b0300b0028654d33a1bmr2302893pjb.35.1701663346735; Sun, 03 Dec 2023 20:15:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701663346; cv=none; d=google.com; s=arc-20160816; b=TvRQ3yaG3KnmI/HCr1GDJUK/ArjeMrmw3SsLP5O05FPQUnm/1P4JSj6Qq74GCDpA4D RWXtHY9Twuu9+O8EwKNnOOrhSJbkD9mPv6GjM0EW6dx4CEyHZxX95ww2/b2JU9SCjkdp FX/uiD6GfMlu9G40nJUvxgmmOSWQVZUffe8/YD7EF/csDY+pyq+Lw/4X0bdOHwh+TOdB ZfRoPTRg9qYiljI1F6EPx2Z0aoFrQIDSAQH7Q0PvtTtKk7W49T39bC7hYzqFf6AjvA0K bLG0ArR6W6bCW7heHSQgUpBUIe72/4rI/c/XEt1Uw/ixLCOX4shi7sfml4Vz3KL30aca l9Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=yQL2YJJVy58jFgjIEOr/uJ8lGherBllTmSyKC9ZlwS4=; fh=JCb6YaKmbUpp/1fFgtqOrlyOUwhehZd1rxGbEgdh7vM=; b=s1lFTb3WnFgWT+HF7z/rBc98cjLlDIevt3GYUSMMUx0GNQYaT2oSZbreb/7hj7p9da m9JL+xscMatQvNlezxnovX7ynT9tGfHYcnYF0Kif45OCsOYCiv3cEI5ww0UC83XkFQLA 65STf5UxBaJBdw1wfL5MzZ432MCnuL137eWKfhzCPPKeq/RYu6bOoMws7Q3E3E4sEPb/ tBsT3ioOUWS2+gxzKstaQtiyREw8QRkopn6suthP0sJ5nuVAEfmAgHKiIfi+w+lvSjSt ameLBuZuzg7MbVMo0xVys4tp7+6WTGvO/72V/eKjCKaCdY6nvWx1tPl2WBsqyjz50RRH NQpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=eeB5IzXG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id v16-20020a17090a899000b002868673f28dsi2318091pjn.156.2023.12.03.20.15.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 20:15:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=eeB5IzXG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 3EE70807C5C8; Sun, 3 Dec 2023 20:15:23 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234541AbjLDEOs (ORCPT + 99 others); Sun, 3 Dec 2023 23:14:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234543AbjLDEOk (ORCPT ); Sun, 3 Dec 2023 23:14:40 -0500 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13F871B2; Sun, 3 Dec 2023 20:14:39 -0800 (PST) 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 3B4423Wo013923; Mon, 4 Dec 2023 04:14:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=yQL2YJJVy58jFgjIEOr/uJ8lGherBllTmSyKC9ZlwS4=; b=eeB5IzXGYVq4cSJ2YpwFoZ20hckOd7zne1eApX4ZVwwsnfoZA+DVqZGoSUHRE9JDzaj9 apP7Er9MsUibLUESw/WaNJH9ODFTmQIadCBVYzW5P31EntwIGnlaWG4Rz2+KWzhjfOE3 FmD53TY3eK128YNxfBktMnmFLhp+rR2i+2i1sT394CCTCA3QtAi+j8/zg06AJN4mLd4Z 8ZRSKo5IMH/jEqlVj51OXN5FYm/vWoMVUGU8FLWlovLTy8f++B+TBjd3RV3xEMwSjC8A uTef6YQpilnKhQqYlb7ditm1tNkBRo/E8iYfVN/2jETcUpqjatSB0eJih8NfuZPh5dGd Lw== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3uqvp12w3w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 04 Dec 2023 04:14:03 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3B44E24Y026255 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 4 Dec 2023 04:14:02 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.40; Sun, 3 Dec 2023 20:13:58 -0800 From: Oreoluwa Babatunde To: , , , CC: , , , , , Oreoluwa Babatunde Subject: [RFC PATCH v2 2/6] of: reserved_mem: Swicth call to unflatten_device_tree() to after paging_init() Date: Sun, 3 Dec 2023 20:13:35 -0800 Message-ID: <20231204041339.9902-3-quic_obabatun@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231204041339.9902-1-quic_obabatun@quicinc.com> References: <20231204041339.9902-1-quic_obabatun@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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: BJs88xF2E2BCiNw5c2Z6esPYLn8k0GMV X-Proofpoint-ORIG-GUID: BJs88xF2E2BCiNw5c2Z6esPYLn8k0GMV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-04_01,2023-11-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 impostorscore=0 suspectscore=0 malwarescore=0 phishscore=0 spamscore=0 clxscore=1015 priorityscore=1501 adultscore=0 mlxscore=0 lowpriorityscore=0 mlxlogscore=873 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2312040029 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Sun, 03 Dec 2023 20:15:23 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784323345808394289 X-GMAIL-MSGID: 1784323345808394289 Switch call to unflatten_device_tree() to after paging_init() on other archs to follow new order in which the reserved_mem regions are processed. Signed-off-by: Oreoluwa Babatunde --- arch/loongarch/kernel/setup.c | 2 +- arch/mips/kernel/setup.c | 3 ++- arch/nios2/kernel/setup.c | 4 ++-- arch/openrisc/kernel/setup.c | 4 ++-- arch/powerpc/kernel/setup-common.c | 3 +++ arch/sh/kernel/setup.c | 5 ++--- arch/um/kernel/dtb.c | 1 - arch/um/kernel/um_arch.c | 2 ++ arch/xtensa/kernel/setup.c | 4 +++- 9 files changed, 17 insertions(+), 11 deletions(-) diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c index d183a745fb85..a01051b0f9e0 100644 --- a/arch/loongarch/kernel/setup.c +++ b/arch/loongarch/kernel/setup.c @@ -366,7 +366,6 @@ void __init platform_init(void) acpi_gbl_use_default_register_widths = false; acpi_boot_table_init(); #endif - unflatten_and_copy_device_tree(); #ifdef CONFIG_NUMA init_numa_memory(); @@ -626,6 +625,7 @@ void __init setup_arch(char **cmdline_p) paging_init(); + unflatten_and_copy_device_tree(); #ifdef CONFIG_KASAN kasan_init(); #endif diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 2d2ca024bd47..d3b6c86a8037 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -667,7 +667,6 @@ static void __init arch_mem_init(char **cmdline_p) mips_reserve_vmcore(); mips_parse_crashkernel(); - device_tree_init(); /* * In order to reduce the possibility of kernel panic when failed to @@ -798,6 +797,8 @@ void __init setup_arch(char **cmdline_p) cpu_cache_init(); paging_init(); + device_tree_init(); + memblock_dump_all(); setup_rng_seed(); diff --git a/arch/nios2/kernel/setup.c b/arch/nios2/kernel/setup.c index da122a5fa43b..6f1a4232b8f0 100644 --- a/arch/nios2/kernel/setup.c +++ b/arch/nios2/kernel/setup.c @@ -169,8 +169,6 @@ void __init setup_arch(char **cmdline_p) early_init_fdt_reserve_self(); early_init_fdt_scan_reserved_mem(); - unflatten_and_copy_device_tree(); - setup_cpuinfo(); copy_exception_handler(cpuinfo.exception_addr); @@ -189,4 +187,6 @@ void __init setup_arch(char **cmdline_p) * get kmalloc into gear */ paging_init(); + + unflatten_and_copy_device_tree(); } diff --git a/arch/openrisc/kernel/setup.c b/arch/openrisc/kernel/setup.c index 9cf7fb60441f..fcda33bdca19 100644 --- a/arch/openrisc/kernel/setup.c +++ b/arch/openrisc/kernel/setup.c @@ -255,8 +255,6 @@ void calibrate_delay(void) void __init setup_arch(char **cmdline_p) { - unflatten_and_copy_device_tree(); - setup_cpuinfo(); #ifdef CONFIG_SMP @@ -284,6 +282,8 @@ void __init setup_arch(char **cmdline_p) /* paging_init() sets up the MMU and marks all pages as reserved */ paging_init(); + unflatten_and_copy_device_tree(); + *cmdline_p = boot_command_line; printk(KERN_INFO "OpenRISC Linux -- http://openrisc.io\n"); diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c index 9b142b9d5187..58da58d02652 100644 --- a/arch/powerpc/kernel/setup-common.c +++ b/arch/powerpc/kernel/setup-common.c @@ -986,6 +986,9 @@ void __init setup_arch(char **cmdline_p) paging_init(); + /* Unflatten the device-tree passed by prom_init or kexec */ + unflatten_device_tree(); + /* Initialize the MMU context management stuff. */ mmu_context_init(); diff --git a/arch/sh/kernel/setup.c b/arch/sh/kernel/setup.c index 3d80515298d2..2553696af21b 100644 --- a/arch/sh/kernel/setup.c +++ b/arch/sh/kernel/setup.c @@ -322,6 +322,8 @@ void __init setup_arch(char **cmdline_p) /* Let earlyprintk output early console messages */ sh_early_platform_driver_probe("earlyprintk", 1, 1); + paging_init(); + #ifdef CONFIG_OF_EARLY_FLATTREE #ifdef CONFIG_USE_BUILTIN_DTB unflatten_and_copy_device_tree(); @@ -329,9 +331,6 @@ void __init setup_arch(char **cmdline_p) unflatten_device_tree(); #endif #endif - - paging_init(); - /* Perform the machine specific initialisation */ if (likely(sh_mv.mv_setup)) sh_mv.mv_setup(cmdline_p); diff --git a/arch/um/kernel/dtb.c b/arch/um/kernel/dtb.c index 484141b06938..04b0ada3b929 100644 --- a/arch/um/kernel/dtb.c +++ b/arch/um/kernel/dtb.c @@ -26,7 +26,6 @@ void uml_dtb_init(void) } early_init_fdt_scan_reserved_mem(); - unflatten_device_tree(); } static int __init uml_dtb_setup(char *line, int *add) diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c index b1bfed0c8528..fe6ecaa12ef2 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -421,6 +422,7 @@ void __init setup_arch(char **cmdline_p) read_initrd(); paging_init(); + unflatten_device_tree(); strscpy(boot_command_line, command_line, COMMAND_LINE_SIZE); *cmdline_p = command_line; setup_hostinfo(host_info, sizeof host_info); diff --git a/arch/xtensa/kernel/setup.c b/arch/xtensa/kernel/setup.c index bdec4a773af0..d20c56b4182e 100644 --- a/arch/xtensa/kernel/setup.c +++ b/arch/xtensa/kernel/setup.c @@ -355,13 +355,15 @@ void __init setup_arch(char **cmdline_p) parse_early_param(); bootmem_init(); kasan_init(); - unflatten_and_copy_device_tree(); #ifdef CONFIG_SMP smp_init_cpus(); #endif paging_init(); + + unflatten_and_copy_device_tree(); + zones_init(); #ifdef CONFIG_VT From patchwork Mon Dec 4 04:13:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oreoluwa Babatunde X-Patchwork-Id: 173061 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2541782vqy; Sun, 3 Dec 2023 20:14:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHzYkW3msB6mkGreEAh71FOcK1RJSdQJFTyymm7vnOlLRBWdLV/XGMqvnQDyFC86P85zBvz X-Received: by 2002:a17:90a:f507:b0:285:80d5:6e51 with SMTP id cs7-20020a17090af50700b0028580d56e51mr1217508pjb.21.1701663277067; Sun, 03 Dec 2023 20:14:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701663277; cv=none; d=google.com; s=arc-20160816; b=ue/44OxOIT0r7RfNkl5ho0763Gm7rJfsSjkv1z9RZ5ertXNgfYXzUzoQM8vaXuDsJn Jl+Aw7wt9hQaYE/pwLDDYyRkt40uhpX8gg82YlVprP31CGcCvr+DpK1Q+ZawGtig7Kyz STg4ykj3j6k/fgvKSwS6qiZA1F3aCJvBkruyATFrct79MsvXE5F4ZC+Qnf40Wpor80Ab hGCUJFu4O13ha5hy6Ri9dYsOdE8uv9RwL9COA0sTjzokmsgNiQAyqCeQjaOlgLPbn96/ vUsJvRuYK3pm5fJWCD5yVHxt3mUrCZhTLQd4O7Cxzk68888bTqewl0yXqEDpB+0pZg5F nAcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=n6Lojg+3L7EfygQUx0vRNm4ETKLDPxcnSDHlrIicw7Y=; fh=JCb6YaKmbUpp/1fFgtqOrlyOUwhehZd1rxGbEgdh7vM=; b=dlwn1+qdU0jX6w7xGVAMKb9FhgJqumMnJpRkWjBtdBTOs5YBkS337ed9iw5y07a2dq QISKkO65ZKeaYqsGh7sGTpx2i3v6SCTlbYbSkCQBAPy9Dz5uVVaxEYFvqf7wH6d1Le7i Xa1TaOj+ef9X6yBk+MYfzaJMBuSydm5iXYPgpovVZjQdN+wKAPO2wNhKpNGQlihizY9r Abzb/vOe104jCOi6HjlofVYKbjXO54K9H6SkZ01dL1WxzzzyvgovcrqMbX92rw7hn1az EXY+byYsILDsXexd2hojWQeMQA0CGRx1YsB6bB53frdr9z3ZsEO2F8fG+rxI3OeS8wFs Rcbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VmOJFvMH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id bj21-20020a17090b089500b0028655f194afsi5283004pjb.184.2023.12.03.20.14.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 20:14:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VmOJFvMH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 99C49808D2BA; Sun, 3 Dec 2023 20:14:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234416AbjLDEOV (ORCPT + 99 others); Sun, 3 Dec 2023 23:14:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229510AbjLDEOU (ORCPT ); Sun, 3 Dec 2023 23:14:20 -0500 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE91ED5; Sun, 3 Dec 2023 20:14:25 -0800 (PST) Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B43JNgi017074; Mon, 4 Dec 2023 04:14:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=n6Lojg+3L7EfygQUx0vRNm4ETKLDPxcnSDHlrIicw7Y=; b=VmOJFvMHFxynJ+ToxMLT5Zer93ebl8KfK+616vLcbl9fCvtEYO7sMzG++5RZfeSYdqIb LIOze6OmKu1o3ydGtf0xP+9bfYJ5csprDyoNSNpumvg95xqjLEhKstf5/De0Gosl4XO1 pJoq+9peZ52tw4YQmbv419oAi8ldhFxsmA+vxiTOOLy1+9qrnV4oMtwZZ4bjFCwMxuN5 lxaxDjg2QZiyp4hnQXPWHRr0MRACDl0KVSznSN2YtZUqZspQkgy9fBFYn3v2DlCyIet9 +5o39QZf9SHJfJGOrOXg4sJtLyHDtZyuUR3/8j+tpehg9peg/gFuFaikF/iYXWN6xVmT GA== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3uqvyetutq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 04 Dec 2023 04:14:04 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3B44E3qs004866 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 4 Dec 2023 04:14:03 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.40; Sun, 3 Dec 2023 20:14:00 -0800 From: Oreoluwa Babatunde To: , , , CC: , , , , , Oreoluwa Babatunde Subject: [RFC PATCH v2 3/6] of: resevred_mem: Delay allocation of memory for dynamic regions Date: Sun, 3 Dec 2023 20:13:36 -0800 Message-ID: <20231204041339.9902-4-quic_obabatun@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231204041339.9902-1-quic_obabatun@quicinc.com> References: <20231204041339.9902-1-quic_obabatun@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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-ORIG-GUID: J0Gc84gPalOhRT044WtmVIv8ubGb7E1a X-Proofpoint-GUID: J0Gc84gPalOhRT044WtmVIv8ubGb7E1a X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-04_01,2023-11-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 mlxlogscore=807 bulkscore=0 suspectscore=0 clxscore=1015 spamscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2312040029 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Sun, 03 Dec 2023 20:14:32 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784323272354981705 X-GMAIL-MSGID: 1784323272354981705 Defer the allocation of memory for the dynamically-placed reserved memory regions until after the statically-placed reserved memory regions have been reserved or marked as nomap in memblock. This is to avoid allocating from regions that will later turn out to have been reserved by other nodes. Signed-off-by: Oreoluwa Babatunde --- drivers/of/fdt.c | 18 ++++++++++++++++-- drivers/of/of_private.h | 1 + drivers/of/of_reserved_mem.c | 1 - 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 34223c249914..46adce306bbd 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -613,6 +613,8 @@ void __init fdt_scan_reserved_mem_reg_nodes(void) static int __init fdt_scan_reserved_mem(void) { int node, child; + int dynamic_nodes_cnt = 0; + int dynamic_nodes[MAX_RESERVED_REGIONS]; const void *fdt = initial_boot_params; node = fdt_path_offset(fdt, "/reserved-memory"); @@ -634,8 +636,20 @@ static int __init fdt_scan_reserved_mem(void) uname = fdt_get_name(fdt, child, NULL); err = __reserved_mem_reserve_reg(child, uname); - if (err == -ENOENT && of_get_flat_dt_prop(child, "size", NULL)) - __reserved_mem_alloc_size(child, uname); + + if (err == -ENOENT && of_get_flat_dt_prop(child, "size", NULL)) { + dynamic_nodes[dynamic_nodes_cnt] = child; + dynamic_nodes_cnt++; + } + } + + for (int i = 0; i < dynamic_nodes_cnt; i++) { + const char *uname; + + child = dynamic_nodes[i]; + uname = fdt_get_name(fdt, child, NULL); + + __reserved_mem_alloc_size(child, uname); } return 0; } diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index f38397c7b582..57694a704b00 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -36,6 +36,7 @@ struct alias_prop { #endif #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 +#define MAX_RESERVED_REGIONS 64 extern struct mutex of_mutex; extern raw_spinlock_t devtree_lock; diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 8bd8bbc3aaec..d62f1956024c 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -26,7 +26,6 @@ #include "of_private.h" -#define MAX_RESERVED_REGIONS 64 static struct reserved_mem reserved_mem[MAX_RESERVED_REGIONS]; static int reserved_mem_count; From patchwork Mon Dec 4 04:13:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oreoluwa Babatunde X-Patchwork-Id: 173062 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2541827vqy; Sun, 3 Dec 2023 20:14:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEPW4kDy6xGaUCncPxTMK3Yd7Nc+q68liqXId/0VW94R+NatlFLYgnw/5mi6qr7aBVshYxa X-Received: by 2002:a05:6a20:840d:b0:18d:1e16:8017 with SMTP id c13-20020a056a20840d00b0018d1e168017mr11728111pzd.8.1701663288399; Sun, 03 Dec 2023 20:14:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701663288; cv=none; d=google.com; s=arc-20160816; b=YM+FbVBH/uPQ+KALZMcJAbTewarLweEltSMqjBod2XcoznsglLml9vi6WexoCGrPd1 Y3SzCcHm1KLHbpUXnK9IJgllWLxGHCpb9H+UvD9SU4oPBalRyfP5jKDKipUrVDxMsHp8 eKkl54Y65xOqRcbA//VvrcSHT3ErrFqME45ZqcR3tFqf4JJmr4KiQM37DtdvT9msxJCN s1iUFr1/JhOAiM20Zn7DYZp8Q5gWxNPbPDyoXXj7wufX2yNu2LfKw4EJ9mandaGUNWJL 6+KPEXCfg5z7PMBsOt2+h6M/2icKWVL3hGfh28MXcjPNqroquFgE4Dxj352ympnQzQgM TdjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=DGp7GypliVESVnbAw1V5x8IdWqqOnrDZe/rDVpEhIE0=; fh=JCb6YaKmbUpp/1fFgtqOrlyOUwhehZd1rxGbEgdh7vM=; b=b/UgihdDQEoXGSvQxiYZz07X5ZdDxrzC/YxNwClQGz3bM8IBFaynECtN8BdDJEdCff rubU/Ggye2Ahc5Vwa9w8lw6lTpmMkCM+YwUeumsXX59ymr1+C777D6tz9muIrjymqXnf 3o2rTa90R800Yn8fQN7DDIC25bubpg0ADIukG5blJEvSr0vDdaxCo10kHYHsj92sRPct blA5B3RT1jbk4PTRjIXKU/Jt2d8btoRUuB7LfOAU0GVofyZ+VYYKKV4zkXkgK7RVrzF/ 14OaQaeJgIjJx/CKlA4QNVu8bCopWFthrsRMnJO77B9IoN5NIAiDUNLhdQhaBpiPR052 PeXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=SIR3yFUz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id m10-20020a170902db0a00b001d0b0660f8dsi512260plx.493.2023.12.03.20.14.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 20:14:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=SIR3yFUz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 295C7805F9C1; Sun, 3 Dec 2023 20:14:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234503AbjLDEOa (ORCPT + 99 others); Sun, 3 Dec 2023 23:14:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234451AbjLDEO0 (ORCPT ); Sun, 3 Dec 2023 23:14:26 -0500 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74FB2D7; Sun, 3 Dec 2023 20:14:32 -0800 (PST) Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B43TDCM032692; Mon, 4 Dec 2023 04:14:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=DGp7GypliVESVnbAw1V5x8IdWqqOnrDZe/rDVpEhIE0=; b=SIR3yFUzuuLki5ZItt2TiT3CpU4ziULwN0ZaDUf7ugmI8Vl02Fr2SNVgZXhWPaTbJpSF d2rRAvaG96HIUCT0fwnlqfpZGyZni9BFJzd0AFzdiyIj+RnjNdjxS7z5BU0A2lnT5h18 ir8sO6w9qA7Cx7Wd5LhMoK8KeYkRhsxp8+8+LbqEI87UTeD21HwB23C6BmAR7GUtTGm7 M1Hp8xBzwsJmr97QZ1POlnPrI+GTWJU/nurgiPJxpHiEuPuInYvQYbvQUzBleGyuPB54 S7zKq//WzQmRNJ1O4G8Y1qNwVh1oSnPi0tRRorrfY1oXcPa68VYHVfc8nL2gPcp//Yvy vw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3uqv672wk1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 04 Dec 2023 04:14:05 +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 3B44E43a001538 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 4 Dec 2023 04:14:04 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.40; Sun, 3 Dec 2023 20:14:01 -0800 From: Oreoluwa Babatunde To: , , , CC: , , , , , Oreoluwa Babatunde Subject: [RFC PATCH v2 4/6] of: reserved_mem: Add code to use unflattened DT for reserved_mem nodes Date: Sun, 3 Dec 2023 20:13:37 -0800 Message-ID: <20231204041339.9902-5-quic_obabatun@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231204041339.9902-1-quic_obabatun@quicinc.com> References: <20231204041339.9902-1-quic_obabatun@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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-ORIG-GUID: BpblN0kxGe719fkD9M5twh5uFLLEWlhS X-Proofpoint-GUID: BpblN0kxGe719fkD9M5twh5uFLLEWlhS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-04_01,2023-11-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 clxscore=1015 mlxscore=0 spamscore=0 suspectscore=0 adultscore=0 mlxlogscore=508 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2312040029 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Sun, 03 Dec 2023 20:14:47 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784323284467451546 X-GMAIL-MSGID: 1784323284467451546 The unflattened devicetree APIs are available to be used right after paging_init() runs. Therefore, use the unflattened devicetree APIs to process the reserved memory regions from this point. Using the unflattened devicetree APIs is more efficient than using the flattened devicetree APIs. Signed-off-by: Oreoluwa Babatunde --- drivers/of/fdt.c | 51 +-------------------- drivers/of/of_private.h | 4 +- drivers/of/of_reserved_mem.c | 79 +++++++++++++++++++++++++-------- include/linux/of_fdt.h | 1 - include/linux/of_reserved_mem.h | 2 +- kernel/dma/coherent.c | 4 +- kernel/dma/contiguous.c | 8 ++-- kernel/dma/swiotlb.c | 10 ++--- 8 files changed, 76 insertions(+), 83 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 46adce306bbd..12769dd53c34 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -558,55 +558,6 @@ static int __init __reserved_mem_check_root(unsigned long node) return 0; } -/* - * Save the reserved_mem reg nodes in the reserved_mem array - */ -void __init fdt_scan_reserved_mem_reg_nodes(void) - -{ - int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); - const void *fdt = initial_boot_params; - phys_addr_t base, size; - const __be32 *prop; - int node, child; - int len; - - node = fdt_path_offset(fdt, "/reserved-memory"); - if (node < 0) { - pr_err("Reserved memory: Did not find reserved-memory node\n"); - return; - } - - if (__reserved_mem_check_root(node) != 0) { - pr_err("Reserved memory: unsupported node format, ignoring\n"); - return; - } - - fdt_for_each_subnode(child, fdt, node) { - const char *uname; - - prop = of_get_flat_dt_prop(child, "reg", &len); - if (!prop) - continue; - - if (!of_fdt_device_is_available(fdt, child)) - continue; - - uname = fdt_get_name(fdt, child, NULL); - if (len && len % t_len != 0) { - pr_err("Reserved memory: invalid reg property in '%s', skipping node.\n", - uname); - continue; - } - - base = dt_mem_next_cell(dt_root_addr_cells, &prop); - size = dt_mem_next_cell(dt_root_size_cells, &prop); - - if (size) - fdt_reserved_mem_save_node(child, uname, base, size); - } -} - /* * fdt_scan_reserved_mem() - scan a single FDT node for reserved memory. */ @@ -1393,7 +1344,7 @@ void __init unflatten_device_tree(void) unittest_unflatten_overlay_base(); /*Initialize the reserved_mem regions*/ - fdt_init_reserved_mem(); + init_reserved_mem(); } /** diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 57694a704b00..575e2b4119e0 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -176,8 +176,8 @@ static inline struct device_node *__of_get_dma_parent(const struct device_node * } #endif -void fdt_init_reserved_mem(void); -void fdt_reserved_mem_save_node(unsigned long node, const char *uname, +void init_reserved_mem(void); +void dt_reserved_mem_save_node(struct device_node *node, const char *uname, phys_addr_t base, phys_addr_t size); #endif /* _LINUX_OF_PRIVATE_H */ diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index d62f1956024c..2ef9edcb8c93 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -55,9 +55,9 @@ static int __init early_init_dt_alloc_reserved_memory_arch(phys_addr_t size, } /* - * fdt_reserved_mem_save_node() - save fdt node for second pass initialization + * dt_reserved_mem_save_node() - save dt node for second pass initialization */ -void __init fdt_reserved_mem_save_node(unsigned long node, const char *uname, +void __init dt_reserved_mem_save_node(struct device_node *node, const char *uname, phys_addr_t base, phys_addr_t size) { struct reserved_mem *rmem = &reserved_mem[reserved_mem_count]; @@ -67,7 +67,7 @@ void __init fdt_reserved_mem_save_node(unsigned long node, const char *uname, return; } - rmem->fdt_node = node; + rmem->dev_node = node; rmem->name = uname; rmem->base = base; rmem->size = size; @@ -76,6 +76,54 @@ void __init fdt_reserved_mem_save_node(unsigned long node, const char *uname, return; } +/* + * Save the reserved_mem reg nodes in the reserved_mem array + */ +static void __init scan_reserved_mem_reg_nodes(void) + +{ + int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); + struct device_node *node, *child; + phys_addr_t base, size; + const __be32 *prop; + int len; + + node = of_find_node_by_path("/reserved-memory"); + if (node < 0) { + pr_err("Reserved memory: Did not find reserved-memory node\n"); + return; + } + + for_each_child_of_node(node, child) { + const char *uname; + struct reserved_mem *rmem; + + if (!of_device_is_available(child)) + continue; + + prop = of_get_property(child, "reg", &len); + if (!prop) { + rmem = of_reserved_mem_lookup(child); + if (rmem) + rmem->dev_node = child; + continue; + } + + uname = of_node_full_name(child); + if (len && len % t_len != 0) { + pr_err("Reserved memory: invalid reg property in '%s', skipping node.\n", + uname); + continue; + } + + base = dt_mem_next_cell(dt_root_addr_cells, &prop); + size = dt_mem_next_cell(dt_root_size_cells, &prop); + + if (size) + dt_reserved_mem_save_node(child, uname, base, size); + } +} + /* * __reserved_mem_alloc_in_range() - allocate reserved memory described with * 'alloc-ranges'. Choose bottom-up/top-down depending on nearby existing @@ -210,7 +258,7 @@ int __init __reserved_mem_alloc_size(unsigned long node, const char *uname) uname, (unsigned long)(size / SZ_1M)); return -ENOMEM; } - fdt_reserved_mem_save_node(node, uname, base, size); + dt_reserved_mem_save_node(NULL, uname, base, size); return 0; } @@ -230,7 +278,7 @@ static int __init __reserved_mem_init_node(struct reserved_mem *rmem) reservedmem_of_init_fn initfn = i->data; const char *compat = i->compatible; - if (!of_flat_dt_is_compatible(rmem->fdt_node, compat)) + if (!of_device_is_compatible(rmem->dev_node, compat)) continue; ret = initfn(rmem); @@ -263,11 +311,6 @@ static int __init __rmem_cmp(const void *a, const void *b) if (ra->size > rb->size) return 1; - if (ra->fdt_node < rb->fdt_node) - return -1; - if (ra->fdt_node > rb->fdt_node) - return 1; - return 0; } @@ -299,29 +342,29 @@ static void __init __rmem_check_for_overlap(void) } /** - * fdt_init_reserved_mem() - allocate and init all saved reserved memory regions + * init_reserved_mem() - allocate and init all saved reserved memory regions */ -void __init fdt_init_reserved_mem(void) +void __init init_reserved_mem(void) { int i; - fdt_scan_reserved_mem_reg_nodes(); + scan_reserved_mem_reg_nodes(); /* check for overlapping reserved regions */ __rmem_check_for_overlap(); for (i = 0; i < reserved_mem_count; i++) { struct reserved_mem *rmem = &reserved_mem[i]; - unsigned long node = rmem->fdt_node; + struct device_node *node = rmem->dev_node; int len; const __be32 *prop; int err = 0; bool nomap; - nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL; - prop = of_get_flat_dt_prop(node, "phandle", &len); + nomap = of_get_property(node, "no-map", NULL) != NULL; + prop = of_get_property(node, "phandle", &len); if (!prop) - prop = of_get_flat_dt_prop(node, "linux,phandle", &len); + prop = of_get_property(node, "linux,phandle", &len); if (prop) rmem->phandle = of_read_number(prop, len/4); @@ -337,7 +380,7 @@ void __init fdt_init_reserved_mem(void) } else { phys_addr_t end = rmem->base + rmem->size - 1; bool reusable = - (of_get_flat_dt_prop(node, "reusable", NULL)) != NULL; + (of_get_property(node, "reusable", NULL)) != NULL; pr_info("%pa..%pa (%lu KiB) %s %s %s\n", &rmem->base, &end, (unsigned long)(rmem->size / SZ_1K), diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index 7b2a5d93d719..d69ad5bb1eb1 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -73,7 +73,6 @@ extern int early_init_dt_scan_root(void); extern bool early_init_dt_scan(void *params); extern bool early_init_dt_verify(void *params); extern void early_init_dt_scan_nodes(void); -extern void fdt_scan_reserved_mem_reg_nodes(void); extern const char *of_flat_dt_get_machine_name(void); extern const void *of_flat_dt_match_machine(const void *default_match, diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h index dc13bcd04b12..2b205ce6beb9 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -10,7 +10,7 @@ struct reserved_mem_ops; struct reserved_mem { const char *name; - unsigned long fdt_node; + struct device_node *dev_node; unsigned long phandle; const struct reserved_mem_ops *ops; phys_addr_t base; diff --git a/kernel/dma/coherent.c b/kernel/dma/coherent.c index c21abc77c53e..3eba9678dc33 100644 --- a/kernel/dma/coherent.c +++ b/kernel/dma/coherent.c @@ -360,9 +360,9 @@ static const struct reserved_mem_ops rmem_dma_ops = { static int __init rmem_dma_setup(struct reserved_mem *rmem) { - unsigned long node = rmem->fdt_node; + struct device_node *node = rmem->dev_node; - if (of_get_flat_dt_prop(node, "reusable", NULL)) + if (of_get_property(node, "reusable", NULL)) return -EINVAL; #ifdef CONFIG_ARM diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index f005c66f378c..b54cf128a9d9 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -462,8 +462,8 @@ static const struct reserved_mem_ops rmem_cma_ops = { static int __init rmem_cma_setup(struct reserved_mem *rmem) { - unsigned long node = rmem->fdt_node; - bool default_cma = of_get_flat_dt_prop(node, "linux,cma-default", NULL); + struct device_node *node = rmem->dev_node; + bool default_cma = of_get_property(node, "linux,cma-default", NULL); struct cma *cma; int err; @@ -473,8 +473,8 @@ static int __init rmem_cma_setup(struct reserved_mem *rmem) return -EBUSY; } - if (!of_get_flat_dt_prop(node, "reusable", NULL) || - of_get_flat_dt_prop(node, "no-map", NULL)) + if (!of_get_property(node, "reusable", NULL) || + of_get_property(node, "no-map", NULL)) return -EINVAL; if (!IS_ALIGNED(rmem->base | rmem->size, CMA_MIN_ALIGNMENT_BYTES)) { diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 33d942615be5..14840a58a6e6 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -1709,12 +1709,12 @@ static const struct reserved_mem_ops rmem_swiotlb_ops = { static int __init rmem_swiotlb_setup(struct reserved_mem *rmem) { - unsigned long node = rmem->fdt_node; + struct device_node *node = rmem->dev_node; - if (of_get_flat_dt_prop(node, "reusable", NULL) || - of_get_flat_dt_prop(node, "linux,cma-default", NULL) || - of_get_flat_dt_prop(node, "linux,dma-default", NULL) || - of_get_flat_dt_prop(node, "no-map", NULL)) + if (of_get_property(node, "reusable", NULL) || + of_get_property(node, "linux,cma-default", NULL) || + of_get_property(node, "linux,dma-default", NULL) || + of_get_property(node, "no-map", NULL)) return -EINVAL; rmem->ops = &rmem_swiotlb_ops; From patchwork Mon Dec 4 04:13:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oreoluwa Babatunde X-Patchwork-Id: 173065 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2542077vqy; Sun, 3 Dec 2023 20:15:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFrUdd9LrsuoVr0PE3RW8nv8qrfdKmw/mex1ZS7zoK3VoD3tqhaQRD0ZkxsqLEjLC4H0zjK X-Received: by 2002:a05:6a20:daa5:b0:18f:97c:8a22 with SMTP id iy37-20020a056a20daa500b0018f097c8a22mr5034438pzb.77.1701663344031; Sun, 03 Dec 2023 20:15:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701663344; cv=none; d=google.com; s=arc-20160816; b=N/WKPGcWXsxYZQivsMdV2CGr5NA/PqLmV2c4VTp0scS4eu8u79/R1BUqOyLnx9VEEj /gKdnhCf+LIxAi3bUY6buF9njtTUhvMnhrhuQDLEhKhCWZUyZpFURe+fz1GwN34q7f67 bYqN8+0R4M66CxajSqyd/6CihvAJZC/nI7p0lb1VXLiHz63RCkUOLXJe9xMxnUCy26A1 PGRloVaa7+gZkxVSGPKCoZickFLSgRf1+1CCIyHO3VlWlz0KhSXAPPdD0z34jTjP9EU4 +DTekvIIT3bOTSg6WkGPHH8ygdAVz1BFR1E5BrYVj/iYqJlpmpJwKIJBP2+ppAi0X48p Ezfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=tS6apyrTUM2UpfFkK9FWe2t5HNwAaHbTSnhZYJs1TBE=; fh=JCb6YaKmbUpp/1fFgtqOrlyOUwhehZd1rxGbEgdh7vM=; b=S2h+3naYqYuMNHP/tUopKrUttJzvzl32tZepEZHiGBFtp2r53T0qUZgJS6/XJieeZe Q+9W0uvXfn+fBtGezhzm67XYtArnjKMQbk2vYJ6wtxSnuoIfNW32pg+yisZZCaxBpbXI Pa7pclI+xiTzSFdXicdGQg9xGeEQNfzs7ikP3WLdI+k/pgZISp4LELD6mJoHimGDdR6o BBo+sdNLo8BQuxDazluafF1FPEP4mF72R2CbJFXw98O4XMSzv0or1pKd6DmxvuknRCw9 TVTuGfl6hlxWxuAMKPH8j4JEKyOFg1hbB5T3KlEJzS89DockoXmlKw4PDyXLKHAfWM5a D8yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VZQJgduZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id l13-20020a170903120d00b001cfb316a183si7342328plh.141.2023.12.03.20.15.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 20:15:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VZQJgduZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id A9C8D807931D; Sun, 3 Dec 2023 20:15:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234457AbjLDEO1 (ORCPT + 99 others); Sun, 3 Dec 2023 23:14:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234444AbjLDEOY (ORCPT ); Sun, 3 Dec 2023 23:14:24 -0500 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAD08D5; Sun, 3 Dec 2023 20:14:30 -0800 (PST) Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B41lTrQ021618; Mon, 4 Dec 2023 04:14:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=tS6apyrTUM2UpfFkK9FWe2t5HNwAaHbTSnhZYJs1TBE=; b=VZQJgduZ84HbASKD4Pl1j4WhYG9QKpmmn3OZvqLGxZr9/5yPLwsFlUr3rzdR085ClezV 8wkejFBunVRQJVnooOgLeb6lk89HxlV4DO8d5HaQuC48fbOpVx0SOCNIi3zdsmqiU0px AtxVKjQfo0qTll4d9mcO0OFuLW78vs0q017x6TZWuxofWP/QM/Ubwu7S3bcZkmhU5eKs dWlS6BziwCG1XZhMqy20o2IR2HBt7KhCQkz+pb5PMn4IKK2mLbq2VYrr8IOtpt/LOgrs TeCLH1yA/nRuDheVCqEIKYxQITYtno3sWoZlKwbpxWpfU/Nnu9XpZslIDBNHb+pZULUL iw== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3uqsxw357w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 04 Dec 2023 04:14:06 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3B44E55B026344 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 4 Dec 2023 04:14:05 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.40; Sun, 3 Dec 2023 20:14:02 -0800 From: Oreoluwa Babatunde To: , , , CC: , , , , , Oreoluwa Babatunde Subject: [RFC PATCH v2 5/6] of: reserved_mem: Add code to dynamically allocate reserved_mem array Date: Sun, 3 Dec 2023 20:13:38 -0800 Message-ID: <20231204041339.9902-6-quic_obabatun@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231204041339.9902-1-quic_obabatun@quicinc.com> References: <20231204041339.9902-1-quic_obabatun@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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-ORIG-GUID: A8SsO6wWn22noIW1LxRR94xcAmw0O5LG X-Proofpoint-GUID: A8SsO6wWn22noIW1LxRR94xcAmw0O5LG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-04_01,2023-11-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 suspectscore=0 mlxscore=0 bulkscore=0 spamscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=633 malwarescore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2312040029 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Sun, 03 Dec 2023 20:15:16 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784323342442301363 X-GMAIL-MSGID: 1784323342442301363 The reserved_mem array is statically allocated with a size of MAX_RESERVED_REGIONS(64). Therefore, if the number of reserved_mem regions exceeds this size, there will not be enough space to store all the data. Therefore, extend the use of the static array by introducing a dynamically allocated array based on the number of reserved memory regions specified in the DT. Before paging_init() runs, the static array is used to store the dynamically-placed regions. After paging_init(), memory is dynamically allocated for the reserved_mem array, and all entries from the static array is copied over to the new array, and all other statically-placed regions are added in as well. Signed-off-by: Oreoluwa Babatunde --- drivers/of/fdt.c | 13 +++++++--- drivers/of/of_private.h | 1 + drivers/of/of_reserved_mem.c | 48 +++++++++++++++++++++++++++++++++--- 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 12769dd53c34..2f1eabbd6869 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -563,8 +563,8 @@ static int __init __reserved_mem_check_root(unsigned long node) */ static int __init fdt_scan_reserved_mem(void) { - int node, child; - int dynamic_nodes_cnt = 0; + int node, child, err = 0; + int dynamic_nodes_cnt = 0, count = 0; int dynamic_nodes[MAX_RESERVED_REGIONS]; const void *fdt = initial_boot_params; @@ -579,7 +579,6 @@ static int __init fdt_scan_reserved_mem(void) fdt_for_each_subnode(child, fdt, node) { const char *uname; - int err; if (!of_fdt_device_is_available(fdt, child)) continue; @@ -587,6 +586,8 @@ static int __init fdt_scan_reserved_mem(void) uname = fdt_get_name(fdt, child, NULL); err = __reserved_mem_reserve_reg(child, uname); + if (!err) + count++; if (err == -ENOENT && of_get_flat_dt_prop(child, "size", NULL)) { dynamic_nodes[dynamic_nodes_cnt] = child; @@ -600,8 +601,12 @@ static int __init fdt_scan_reserved_mem(void) child = dynamic_nodes[i]; uname = fdt_get_name(fdt, child, NULL); - __reserved_mem_alloc_size(child, uname); + err = __reserved_mem_alloc_size(child, uname); + if (!err) + count++; } + update_reserved_mem_max_cnt(count); + return 0; } diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 575e2b4119e0..ef56b2ea185c 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -179,5 +179,6 @@ static inline struct device_node *__of_get_dma_parent(const struct device_node * void init_reserved_mem(void); void dt_reserved_mem_save_node(struct device_node *node, const char *uname, phys_addr_t base, phys_addr_t size); +void update_reserved_mem_max_cnt(int max_count); #endif /* _LINUX_OF_PRIVATE_H */ diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 2ef9edcb8c93..01cd6a571dc2 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -26,7 +26,9 @@ #include "of_private.h" -static struct reserved_mem reserved_mem[MAX_RESERVED_REGIONS]; +static struct reserved_mem reserved_mem_array[MAX_RESERVED_REGIONS]; +static struct reserved_mem *reserved_mem = reserved_mem_array; +static int total_reserved_mem_cnt = MAX_RESERVED_REGIONS; static int reserved_mem_count; static int __init early_init_dt_alloc_reserved_memory_arch(phys_addr_t size, @@ -54,6 +56,42 @@ static int __init early_init_dt_alloc_reserved_memory_arch(phys_addr_t size, return err; } +void __init update_reserved_mem_max_cnt(int max_count) +{ + total_reserved_mem_cnt = max_count; +} + +static int alloc_reserved_mem_array(void) +{ + struct reserved_mem *new_array; + size_t alloc_size, copy_size, memset_size; + + alloc_size = array_size(total_reserved_mem_cnt, sizeof(*new_array)); + if (alloc_size == SIZE_MAX) + return -1; + + new_array = memblock_alloc(alloc_size, SMP_CACHE_BYTES); + if (!new_array) + return -ENOMEM; + + copy_size = array_size(reserved_mem_count, sizeof(*new_array)); + if (copy_size == SIZE_MAX) + goto overlow_err; + + memset_size = alloc_size - copy_size; + + memcpy(new_array, reserved_mem, copy_size); + memset(new_array + reserved_mem_count, 0, memset_size); + + reserved_mem = new_array; + return 0; + +overlow_err: + memblock_free(new_array, alloc_size); + total_reserved_mem_cnt = MAX_RESERVED_REGIONS; + return -1; +} + /* * dt_reserved_mem_save_node() - save dt node for second pass initialization */ @@ -62,7 +100,7 @@ void __init dt_reserved_mem_save_node(struct device_node *node, const char *unam { struct reserved_mem *rmem = &reserved_mem[reserved_mem_count]; - if (reserved_mem_count == ARRAY_SIZE(reserved_mem)) { + if (reserved_mem_count == total_reserved_mem_cnt) { pr_err("not enough space for all defined regions.\n"); return; } @@ -346,7 +384,11 @@ static void __init __rmem_check_for_overlap(void) */ void __init init_reserved_mem(void) { - int i; + int i, ret; + + ret = alloc_reserved_mem_array(); + if (ret) + pr_err("Failed to allocate memory for reserved_mem array with err: %d", ret); scan_reserved_mem_reg_nodes(); From patchwork Mon Dec 4 04:13:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oreoluwa Babatunde X-Patchwork-Id: 173063 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2541844vqy; Sun, 3 Dec 2023 20:14:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IEotif09mU4dEt0AO01Jh+oG5ylBnjv3yIKnIAyJzawSGOXEI2oqaXQz926mOtU6ZBGWA3O X-Received: by 2002:a05:6870:499a:b0:1fa:d852:43f9 with SMTP id ho26-20020a056870499a00b001fad85243f9mr4879772oab.28.1701663291603; Sun, 03 Dec 2023 20:14:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701663291; cv=none; d=google.com; s=arc-20160816; b=pfkulON8ZPNeAvoEZau5a2hkqIAKKy/orgb/hQg2A9tam1nuJvMqXAyfNh4bWoN92z MDak4pirZA8r+b7ToragouvJr8Zlt8qmfPFwpGc2L4O2i7Tk4C72ycEcDXuO6BbI6ZdU yLgla1kzJGJmJ6Jg/DGEnbaoEM4Wxqsfj3zZiDM3C93LNTK7tDQLIVD0HfxIQH6MJytX u/Tano3yRPaJ6YKiAbUkbU+gZ5x9BxaLSZhnvnMG+IWfWqlItpgaXAzhwmxpYHz7o96E +0Yo44J2eGiajKG7LV9UqAff2b4XEDO4e/bv6UkQSnIFf8TM7u8uMhxM20UJjWoxVdjU YmpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=w2Yu1aSNbKM1bL03R+vVvqY0inOjKskU3INa/KEM2Nc=; fh=JCb6YaKmbUpp/1fFgtqOrlyOUwhehZd1rxGbEgdh7vM=; b=Hb4U8a4yXaZFIBldJBFIjXsmjstfloKbRYGJl11OAo7+44iQ216fAHVIn9+R0mEMTn e+AOZwYI4SpbhWENuh5ww+TnlLoYlsoWw0L8drH1SeC9XlSBd0ywwJ+UJnq02NcNu4tw MGpRKMWxl3z4xOrXzpFHfhhs7W5zYQQhOOCNwxdB+AXDJhj44x/Nj6+RIrdGRRLlZSmu bPx+JKjqL1mfxtgvk4mobOU58Xj/6mfjtfi5Scu84N9C9/rc/LJj/xd0HG3dqth4GQ0u RbNmi261+WXNtnmymlOJVBDcf7E+sswATiS4F9YgO1NA7rW83ZuSwuVGBoZ30bXXBI8Q 5GOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=FpkpnZSi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id f10-20020a63de0a000000b005c65bbc794asi3465241pgg.53.2023.12.03.20.14.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 20:14:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=FpkpnZSi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 107EC806086A; Sun, 3 Dec 2023 20:14:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234433AbjLDEOW (ORCPT + 99 others); Sun, 3 Dec 2023 23:14:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229839AbjLDEOU (ORCPT ); Sun, 3 Dec 2023 23:14:20 -0500 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D87F5D7; Sun, 3 Dec 2023 20:14:25 -0800 (PST) Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B42kqko020227; Mon, 4 Dec 2023 04:14:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=w2Yu1aSNbKM1bL03R+vVvqY0inOjKskU3INa/KEM2Nc=; b=FpkpnZSiHCf7GfCUTSgpN3SGQ/bEaqtqBSnxYo4vwU3gwMSk5kbz/EELMPGlFbsoLN/x 8LCdRBAAqhO/bHWBIT0tS1xq9xmwd4yoTk6kgkhOSpbknsC/a4LM7mQUx5oZI/ZOuogi AfuBW2/et1sRkofR1IHIqAI0Lz78jZzLN5387Zevgs+7QFtWb1e7LNi0aMKcbwXDpOsN wnsINpHION2o1yBEfMURL2zH447jgQuLxpVdPodchvoxUitTkQxJl9Wunv5vIQU/Bo5P 2W9b+9WOk86ZL5HgKcqNk+R/QHOgradurLhrk8rwFl5W4IkE2VuSGsILEdNud4GCIo+z xw== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3uqvyetuts-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 04 Dec 2023 04:14:07 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3B44E6fu026363 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 4 Dec 2023 04:14:06 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.40; Sun, 3 Dec 2023 20:14:03 -0800 From: Oreoluwa Babatunde To: , , , CC: , , , , , Oreoluwa Babatunde Subject: [RFC PATCH v2 6/6] of: reserved_mem: Make MAX_RESERVED_REGIONS a config option Date: Sun, 3 Dec 2023 20:13:39 -0800 Message-ID: <20231204041339.9902-7-quic_obabatun@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231204041339.9902-1-quic_obabatun@quicinc.com> References: <20231204041339.9902-1-quic_obabatun@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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-ORIG-GUID: UFkQnKkOX_ktNu2ii40nuqy9eFgNGJYe X-Proofpoint-GUID: UFkQnKkOX_ktNu2ii40nuqy9eFgNGJYe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-04_01,2023-11-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 mlxlogscore=907 bulkscore=0 suspectscore=0 clxscore=1015 spamscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2312040029 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Sun, 03 Dec 2023 20:14:44 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784323287435700537 X-GMAIL-MSGID: 1784323287435700537 Make the value of MAX_RESERVED_REGIONS a config option which can be modified based on user requirements. The reserved_mem_array is required during device bootup to store the information of the dynamically-placed reserved memory regions. After paging_init(), this information is transferred to another array which is dynamically allocated and used to store all the reserved memory regions. There is currently no obvious way to free the memory for the static array after its contents are copied over to the dynamically allocated array, but since the size required for the reserved_mem_array can vary from device to device depending on the number of dynamically-placed reserved memory regions, make the size of the array configurable in an attempt to save some memory. Signed-off-by: Oreoluwa Babatunde --- drivers/of/Kconfig | 13 +++++++++++++ drivers/of/of_private.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index da9826accb1b..409ce2527461 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -102,4 +102,17 @@ config OF_OVERLAY config OF_NUMA bool +config OF_MAX_RESERVED_REGIONS + int "OF resvered_mem array size" + default "64" + range 1 64 + help + The reserved_mem_array is used to store information about the dynamically + placed reserved memory regions before we are able to allocate the memory + needed to store all the reserved memory regions defined in the DT. + Because the amount of memory needed initially for this array could vary, + make the size of the reserved_mem_array configurable in an attempt to + save some memory when possible. + if unsure, leave as default value. + endif # OF diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index ef56b2ea185c..278038bce0c0 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -36,7 +36,7 @@ struct alias_prop { #endif #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 -#define MAX_RESERVED_REGIONS 64 +#define MAX_RESERVED_REGIONS CONFIG_OF_MAX_RESERVED_REGIONS extern struct mutex of_mutex; extern raw_spinlock_t devtree_lock;