From nobody Wed Dec 17 17:30:49 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D3D015217A; Mon, 8 Jul 2024 23:07:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720480025; cv=none; b=ljaMpgfwRyXiepUhi8b8y4fM/YHrchoA/7Kjzl0thS2D2Dp1XbdsGrpvpvQqsRjjBjb7A/hhU7IN16FZewWBwLy9uDSb46ymiPzxcCOHpjDKVZI/PsHHT4bQCHbo24we1IksBQytTjLbQFx4l9aZzKJtT21xZ5nkpBanoTUpbrI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720480025; c=relaxed/simple; bh=qAotXApEBKYcIPDOzYD1J5xTTBY7cx5D4CJnoNaSCI4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fb42R9tN0J0B/Sf3x7KRXgPzBA8YvD2nG3J3Xl/g+8b52E+J0Nog825S817xGlJJajvbNhLfWshNkpArAe4S+u8iAEfJELEfHvrRRXy5AEQy478QGpPwhly42FB4qUrJkyXG9yvEZbd8VtAXbACZrYIs+ow9Tq1uMIemnVNJHW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=FFuxzUb1; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="FFuxzUb1" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 468MqHMQ001076; Mon, 8 Jul 2024 23:06:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= Rn+gzeF51A64pAxmwb0k2S+UtKezO+Y/dzS+iADQdzY=; b=FFuxzUb1sXKe6caL PPIVJ0rOb3Dj3WK2PD8XNOb9YhulvGOk2B4Q5uJypIeXkRkbbXiOamgLZb8L2vQ8 lqS3TxAMeiD8ObRfCRgLrTkXVMf/zQshkkCOle/hJROVGYaiL0xCxz0VeG6KsfB1 xs72Z53P/Ei/5ZIQDdIQ4L89NJIcGRGvgwMfINgxPZarZSYBbOvB/sj417+DIyhR E8O06eknmCKeyVm/RXmMRFHXhcF0UGZ5vyvOS0Eob2XqqmPqD6z3WdMYblx3SS2t WYCrjR5DSHgP7QqvjdFA88bW0S5afVVxID2a+DYYBZpTX602THjisVDAy0zzS8Ys C8fGmQ== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 406x514wxx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Jul 2024 23:06:44 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.19/8.17.1.19) with ESMTPS id 468N6hrK030810 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 8 Jul 2024 23:06:43 GMT Received: from hu-obabatun-lv.qualcomm.com (10.80.80.8) 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.1544.9; Mon, 8 Jul 2024 16:06:40 -0700 From: Oreoluwa Babatunde To: , , , CC: , , , , , , , , , Oreoluwa Babatunde Subject: [PATCH 1/4] Revert "of: reserved_mem: Restructure code to call reserved mem init functions earlier" Date: Mon, 8 Jul 2024 16:06:10 -0700 Message-ID: <20240708230613.448846-2-quic_obabatun@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240708230613.448846-1-quic_obabatun@quicinc.com> References: <20240708230613.448846-1-quic_obabatun@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) 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: uGO7mNtF0tyaXgwokbgg9UrIHHtDWOx- X-Proofpoint-ORIG-GUID: uGO7mNtF0tyaXgwokbgg9UrIHHtDWOx- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-08_13,2024-07-05_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 suspectscore=0 impostorscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2407080172 Content-Type: text/plain; charset="utf-8" This reverts commit f2a524d9ef5b2cf9b06c4a59374bb5efbf697ba0. With recent changes made to initialize the cma regions before the page tables are setup, commit f2a524d9ef5b ("of: reserved_mem: Restructure code to call reserved mem init functions earlier"), an issue was introduced where the initialization of the cma regions fail and are initialized as "non-reusable" regions instead of "reusable". This issue occurs because the device_node of the regions are not yet created by the time the cma regions are being initialized. The cma regions need to be initialized before the page tables are setup for them to be configured correctly as was realized in [1]. Hence, since the unflatten_devicetree APIs are not available until after the page tables have been setup, revert back to using the fdt APIs. This makes it possible to store a reference to each cma node in the reserved_mem array by the time it is needed in their init function. Since this fix is based on changes that were made to use the unflatten_devicetree APIs, revert it. The fix will be reapplied with the relevant changes needed to make use of the fdt APIs instead. [1] https://lore.kernel.org/all/20240610213403.GA1697364@thelio-3990X/ Signed-off-by: Oreoluwa Babatunde Tested-by: Klara Modin --- drivers/of/fdt.c | 2 +- drivers/of/of_private.h | 2 +- drivers/of/of_reserved_mem.c | 83 +++++++++++++++--------------------- 3 files changed, 37 insertions(+), 50 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index ea2dff0478c7..9cde2abd2fc0 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1239,7 +1239,7 @@ void __init unflatten_device_tree(void) unittest_unflatten_overlay_base(); =20 /* initialize the reserved memory regions */ - of_scan_reserved_mem_reg_nodes(); + of_init_reserved_mem(); } =20 /** diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 7412aed903df..01b33c4b1e9f 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -181,7 +181,7 @@ static inline struct device_node *__of_get_dma_parent(c= onst struct device_node * #endif =20 int fdt_scan_reserved_mem(void); -void of_scan_reserved_mem_reg_nodes(void); +void of_init_reserved_mem(void); =20 bool of_fdt_device_is_available(const void *blob, unsigned long node); =20 diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index b31001728866..eb54490a0a11 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -97,8 +97,6 @@ static void __init alloc_reserved_mem_array(void) reserved_mem =3D new_array; } =20 -static void __init of_init_reserved_mem_node(struct reserved_mem *rmem); - /* * of_reserved_mem_save_node() - save fdt node for second pass initializat= ion */ @@ -117,12 +115,6 @@ static void __init of_reserved_mem_save_node(struct de= vice_node *node, const cha rmem->base =3D base; rmem->size =3D size; =20 - /* - * Run the region specific initialization function for the rmem - * node. - */ - of_init_reserved_mem_node(rmem); - reserved_mem_count++; return; } @@ -209,8 +201,6 @@ static int __init __fdt_reserved_mem_check_root(unsigne= d long node) return 0; } =20 -static void __init __rmem_check_for_overlap(void); - /** * of_scan_reserved_mem_reg_nodes() - Store info for the "reg" defined * reserved memory regions. @@ -221,7 +211,7 @@ static void __init __rmem_check_for_overlap(void); * size are all stored in the reserved_mem array by calling the * of_reserved_mem_save_node() function. */ -void __init of_scan_reserved_mem_reg_nodes(void) +static void __init of_scan_reserved_mem_reg_nodes(void) { struct device_node *node, *child; phys_addr_t base, size; @@ -232,13 +222,6 @@ void __init of_scan_reserved_mem_reg_nodes(void) return; } =20 - /* - * Before moving forward, allocate the exact size needed for the - * reserved_mem array and copy all previously saved contents - * into the new array if successful. - */ - alloc_reserved_mem_array(); - for_each_child_of_node(node, child) { int ret =3D 0; const char *uname; @@ -263,8 +246,6 @@ void __init of_scan_reserved_mem_reg_nodes(void) if (size) of_reserved_mem_save_node(child, uname, base, size); } - /* check for overlapping reserved regions */ - __rmem_check_for_overlap(); } =20 static int __init __reserved_mem_alloc_size(unsigned long node, const char= *uname); @@ -545,38 +526,44 @@ static void __init __rmem_check_for_overlap(void) } =20 /** - * of_init_reserved_mem_node() - Initialize a saved reserved memory region. - * @rmem: reserved_mem object of the memory region to be initialized. - * - * This function is used to call the region specific initialization - * function on the rmem object passed as an argument. The rmem object - * will contain the base address, size, node name, and device_node of - * the reserved memory region to be initialized. + * of_init_reserved_mem() - allocate and init all saved reserved memory re= gions */ -static void __init of_init_reserved_mem_node(struct reserved_mem *rmem) +void __init of_init_reserved_mem(void) { - int err; - bool nomap; - struct device_node *node =3D rmem->dev_node; + int i; + + alloc_reserved_mem_array(); =20 - nomap =3D of_property_present(node, "no-map"); + of_scan_reserved_mem_reg_nodes(); =20 - err =3D __reserved_mem_init_node(rmem); - if (err !=3D 0 && err !=3D -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 =3D rmem->base + rmem->size - 1; - bool reusable =3D of_property_present(node, "reusable"); - - 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"); + /* check for overlapping reserved regions */ + __rmem_check_for_overlap(); + + for (i =3D 0; i < reserved_mem_count; i++) { + struct reserved_mem *rmem =3D &reserved_mem[i]; + struct device_node *node =3D rmem->dev_node; + int err =3D 0; + bool nomap; + + nomap =3D of_property_present(node, "no-map"); + + err =3D __reserved_mem_init_node(rmem); + if (err !=3D 0 && err !=3D -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 =3D rmem->base + rmem->size - 1; + bool reusable =3D of_property_present(node, "reusable"); + + 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"); + } } } =20 --=20 2.34.1 From nobody Wed Dec 17 17:30:49 2025 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28D2615099A; Mon, 8 Jul 2024 23:07:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720480024; cv=none; b=RNG6wGRD+M+4FB/KAB+b14js/ndxDXtgOZAibhyHxgzPtbGrGP88+10CsPx4MJe39CVwMYKLRscFlKG+OOKV25XEWYQddi3NnPm/izpp93walfApHFVHIfQIqLiKyJcfw/yMBwVUatdHrwsCrHj0E5Ng62K0/N/nPA4wjXH1ZYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720480024; c=relaxed/simple; bh=i4QsWEm3fx5o3M+X1H/cVzucI7u4tAyUy4uUwXPWnn0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ehTQAtNu2lcZ3jsuYXhHZSF0WHoYF6lcE/Pd4a37AyJD75IyLcjVPCx3uBuHNS9Kf90HU22KmeMlA4i/xGF0yYzxAvuPsrbyDbCcDKCpKr7JH/BlLFohGEMLKMnE22NpQysa5OhlgLgL+c8n7K5pAJbgM29ndi5xab2ncWceVVU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=V4UWKXIA; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="V4UWKXIA" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 468AVBgH024152; Mon, 8 Jul 2024 23:06:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= UX1TM2/EIhsljzM5TeftzHEHG+pICaapDVK47aGRIIM=; b=V4UWKXIA8phgWIpd M8Y0D+anpCLdhNjq0MRFqFwBS2EJHU68c73GX7QOZEA/gi07HfDyUjgLTpBEKFvv PpOIX3y+o3w7UI3Tw4QmW+X3FXRgiLHoOi6h8zSzWLVVNI55u9JfBGqO5BIniuII m4epHyLOkKdM8EehfzyI/9on/BQgUj3aywg1e8b9oRK9w/wfoD3ao/0wDNJ88Ywb 2lvQrnAha0+rcDmW07WyN3D8Ok9z7ufjb7ldXRgYcRfwjeHnqeH0UbK0xeDb9Zda VZtIzdgwF/t4LO7UHpg1jIuxGpyM3/VELYvzJHbHgM0HzUuY7pkP2LGaES6tzfC0 zCDYdQ== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 406x0t4y06-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Jul 2024 23:06:45 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.19/8.17.1.19) with ESMTPS id 468N6ibj002216 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 8 Jul 2024 23:06:44 GMT Received: from hu-obabatun-lv.qualcomm.com (10.80.80.8) 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.1544.9; Mon, 8 Jul 2024 16:06:40 -0700 From: Oreoluwa Babatunde To: , , , CC: , , , , , , , , , Oreoluwa Babatunde Subject: [PATCH 2/4] Revert "of: reserved_mem: Rename fdt_* functions to refelct the change from using fdt APIs" Date: Mon, 8 Jul 2024 16:06:11 -0700 Message-ID: <20240708230613.448846-3-quic_obabatun@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240708230613.448846-1-quic_obabatun@quicinc.com> References: <20240708230613.448846-1-quic_obabatun@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) 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: 4ALZVNI4jzd8LHgY3Tywp5F2VrZqQnHl X-Proofpoint-ORIG-GUID: 4ALZVNI4jzd8LHgY3Tywp5F2VrZqQnHl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-08_12,2024-07-05_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 lowpriorityscore=0 impostorscore=0 adultscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 priorityscore=1501 malwarescore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2407080171 Content-Type: text/plain; charset="utf-8" This reverts commit fec32ea96dd90bf0af97e001f380d4a240013aa0. With recent changes made to initialize the cma regions before the page tables are setup, commit f2a524d9ef5b ("of: reserved_mem: Restructure code to call reserved mem init functions earlier"), an issue was introduced where the initialization of the cma regions fail and are initialized as "non-reusable" regions instead of "reusable". This issue occurs because the device_node of the regions are not yet created by the time the cma regions are being initialized. The cma regions need to be initialized before the page tables are setup for them to be configured correctly as was realized in [1]. Hence, since the unflatten_devicetree APIs are not available until after the page tables have been setup, revert back to using the fdt APIs. This makes it possible to store a reference to each cma node in the reserved_mem array by the time it is needed in their init function. [1] https://lore.kernel.org/all/20240610213403.GA1697364@thelio-3990X/ Signed-off-by: Oreoluwa Babatunde Tested-by: Klara Modin --- drivers/of/fdt.c | 2 +- drivers/of/of_private.h | 2 +- drivers/of/of_reserved_mem.c | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 9cde2abd2fc0..e0f93886cc17 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1239,7 +1239,7 @@ void __init unflatten_device_tree(void) unittest_unflatten_overlay_base(); =20 /* initialize the reserved memory regions */ - of_init_reserved_mem(); + fdt_init_reserved_mem(); } =20 /** diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 01b33c4b1e9f..32b10d45b558 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -181,7 +181,7 @@ static inline struct device_node *__of_get_dma_parent(c= onst struct device_node * #endif =20 int fdt_scan_reserved_mem(void); -void of_init_reserved_mem(void); +void fdt_init_reserved_mem(void); =20 bool of_fdt_device_is_available(const void *blob, unsigned long node); =20 diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index eb54490a0a11..784a49a27e7f 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -98,10 +98,10 @@ static void __init alloc_reserved_mem_array(void) } =20 /* - * of_reserved_mem_save_node() - save fdt node for second pass initializat= ion + * fdt_reserved_mem_save_node() - save fdt node for second pass initializa= tion */ -static void __init of_reserved_mem_save_node(struct device_node *node, con= st char *uname, - phys_addr_t base, phys_addr_t size) +static void __init fdt_reserved_mem_save_node(struct device_node *node, co= nst char *uname, + phys_addr_t base, phys_addr_t size) { struct reserved_mem *rmem =3D &reserved_mem[reserved_mem_count]; =20 @@ -202,16 +202,16 @@ static int __init __fdt_reserved_mem_check_root(unsig= ned long node) } =20 /** - * of_scan_reserved_mem_reg_nodes() - Store info for the "reg" defined + * fdt_scan_reserved_mem_reg_nodes() - Store info for the "reg" defined * reserved memory regions. * * This function is used to scan through the DT and store the * information for the reserved memory regions that are defined using * the "reg" property. The region node number, name, base address, and * size are all stored in the reserved_mem array by calling the - * of_reserved_mem_save_node() function. + * fdt_reserved_mem_save_node() function. */ -static void __init of_scan_reserved_mem_reg_nodes(void) +static void __init fdt_scan_reserved_mem_reg_nodes(void) { struct device_node *node, *child; phys_addr_t base, size; @@ -244,7 +244,7 @@ static void __init of_scan_reserved_mem_reg_nodes(void) size =3D res.end - res.start + 1; =20 if (size) - of_reserved_mem_save_node(child, uname, base, size); + fdt_reserved_mem_save_node(child, uname, base, size); } } =20 @@ -442,7 +442,7 @@ static int __init __reserved_mem_alloc_size(unsigned lo= ng node, const char *unam uname, (unsigned long)(size / SZ_1M)); return -ENOMEM; } - of_reserved_mem_save_node(NULL, uname, base, size); + fdt_reserved_mem_save_node(NULL, uname, base, size); return 0; } =20 @@ -526,15 +526,15 @@ static void __init __rmem_check_for_overlap(void) } =20 /** - * of_init_reserved_mem() - allocate and init all saved reserved memory re= gions + * fdt_init_reserved_mem() - allocate and init all saved reserved memory r= egions */ -void __init of_init_reserved_mem(void) +void __init fdt_init_reserved_mem(void) { int i; =20 alloc_reserved_mem_array(); =20 - of_scan_reserved_mem_reg_nodes(); + fdt_scan_reserved_mem_reg_nodes(); =20 /* check for overlapping reserved regions */ __rmem_check_for_overlap(); --=20 2.34.1 From nobody Wed Dec 17 17:30:49 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B078153582; Mon, 8 Jul 2024 23:07:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720480029; cv=none; b=msp2Xw08DYnkQH6Fwuuom4mKbue4s9Atqy4/cGkqQQNT2ONihQ0ftWO5yAQ04KVwis7Add/B6NicFLPDsPi81XzvKnFSQLfUZ82eiX1TBKcqKqPrj147t0T9TE5vdCCUyQxMfbvPDeu5iGF9beDNuq63a0r/sDhwbzPucMXsyGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720480029; c=relaxed/simple; bh=dqk74/g8hw83ErxVO4HV0rE2l5zJbF00MbBjhU5pCG0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LMK1W01Qv2mzBmWBgfdsk63KK96IVCY60nJoUxy7RrmuQyCM3m3lx714Smk1PJxBHGz+P4vwGvblNt7YtasHpANIHAt1KbeazlFrhRy+as1DkaOSupIpbPK7YuxzPPo8fMFDATs14sk9HewS+dIphrHxUSfYDycpr41O+DD+Qj8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=LArWB2gx; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="LArWB2gx" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 468BjZEA012919; Mon, 8 Jul 2024 23:06:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= /Q4au3A0R0Dk0sLYiC1R6AlcGeFfXEO58uJl2/cskKs=; b=LArWB2gxQjK2qmpP 68K66ExLQUYGnwbi9TmHfwE2QSCE4Ss5orDO9Z2q5wgtjruAQ7lARvVTmVgBI7yU nuoJsNskG08JRsDJj9nFvXXBf90+jWPvE7s5dq8Tyu9nbIB+2bOwxwLStMiZkD6A HuzSrz0s4UHj1z/IMImpq9GD1FcT2Eb3teC5QJc2VMzM7TmFnRkDZZgtJrXfFbw3 Q/D6f5RVaraxxlYIFBpgtcKUdbmbNYLC+ITqEt70+EikPI0wV/d8AZPkdUgLY3d/ qM2a14sb71JtRzqKkQk5pnKQwC1FtSIcGh0bjqG4qkKqNtLu+xtnjehke0mZr1A/ RxbAqg== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 406x514wxy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Jul 2024 23:06:45 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.19/8.17.1.19) with ESMTPS id 468N6jXn002225 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 8 Jul 2024 23:06:45 GMT Received: from hu-obabatun-lv.qualcomm.com (10.80.80.8) 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.1544.9; Mon, 8 Jul 2024 16:06:41 -0700 From: Oreoluwa Babatunde To: , , , CC: , , , , , , , , , Oreoluwa Babatunde Subject: [PATCH 3/4] Revert "of: reserved_mem: Use unflatten_devicetree APIs to scan reserved memory nodes" Date: Mon, 8 Jul 2024 16:06:12 -0700 Message-ID: <20240708230613.448846-4-quic_obabatun@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240708230613.448846-1-quic_obabatun@quicinc.com> References: <20240708230613.448846-1-quic_obabatun@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) 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: 4PkZwP92vBgTEgi0zHUFBvAexrs2r8hH X-Proofpoint-ORIG-GUID: 4PkZwP92vBgTEgi0zHUFBvAexrs2r8hH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-08_13,2024-07-05_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 suspectscore=0 impostorscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2407080172 Content-Type: text/plain; charset="utf-8" This reverts commit 59d2c3cbcb5a47483629d8d992886e2650d786df. With recent changes made to initialize the cma regions before the page tables are setup, commit f2a524d9ef5b ("of: reserved_mem: Restructure code to call reserved mem init functions earlier"), an issue was introduced where the initialization of the cma regions fail and are initialized as "non-reusable" regions instead of "reusable". This issue occurs because the device_node of the regions are not yet created by the time the cma regions are being initialized. The cma regions need to be initialized before the page tables are setup for them to be configured correctly as was realized in [1]. Hence, since the unflatten_devicetree APIs are not available until after the page tables have been setup, revert back to using the fdt APIs. This makes it possible to store a reference to each cma node in the reserved_mem array by the time it is needed in their init function. [1] https://lore.kernel.org/all/20240610213403.GA1697364@thelio-3990X/ Signed-off-by: Oreoluwa Babatunde Tested-by: Klara Modin --- drivers/of/of_reserved_mem.c | 67 +++++++++++++++++++-------------- include/linux/of_reserved_mem.h | 2 +- kernel/dma/coherent.c | 10 +++-- kernel/dma/contiguous.c | 8 ++-- kernel/dma/swiotlb.c | 10 ++--- 5 files changed, 55 insertions(+), 42 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 784a49a27e7f..113d593ea031 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -100,7 +99,7 @@ static void __init alloc_reserved_mem_array(void) /* * fdt_reserved_mem_save_node() - save fdt node for second pass initializa= tion */ -static void __init fdt_reserved_mem_save_node(struct device_node *node, co= nst char *uname, +static void __init fdt_reserved_mem_save_node(unsigned long node, const ch= ar *uname, phys_addr_t base, phys_addr_t size) { struct reserved_mem *rmem =3D &reserved_mem[reserved_mem_count]; @@ -110,7 +109,7 @@ static void __init fdt_reserved_mem_save_node(struct de= vice_node *node, const ch return; } =20 - rmem->dev_node =3D node; + rmem->fdt_node =3D node; rmem->name =3D uname; rmem->base =3D base; rmem->size =3D size; @@ -179,11 +178,11 @@ static int __init __reserved_mem_reserve_reg(unsigned= long node, } =20 /* - * __fdt_reserved_mem_check_root() - check if #size-cells, #address-cells = provided + * __reserved_mem_check_root() - check if #size-cells, #address-cells prov= ided * in /reserved-memory matches the values supported by the current impleme= ntation, * also check if ranges property has been provided */ -static int __init __fdt_reserved_mem_check_root(unsigned long node) +static int __init __reserved_mem_check_root(unsigned long node) { const __be32 *prop; =20 @@ -213,35 +212,41 @@ static int __init __fdt_reserved_mem_check_root(unsig= ned long node) */ static void __init fdt_scan_reserved_mem_reg_nodes(void) { - struct device_node *node, *child; + int t_len =3D (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); + const void *fdt =3D initial_boot_params; phys_addr_t base, size; + const __be32 *prop; + int node, child; + int len; =20 - node =3D of_find_node_by_path("/reserved-memory"); - if (!node) { + node =3D fdt_path_offset(fdt, "/reserved-memory"); + if (node < 0) { pr_info("Reserved memory: No reserved-memory node in the DT\n"); return; } =20 - for_each_child_of_node(node, child) { - int ret =3D 0; + if (__reserved_mem_check_root(node)) { + pr_err("Reserved memory: unsupported node format, ignoring\n"); + return; + } + + fdt_for_each_subnode(child, fdt, node) { const char *uname; - struct resource res; - struct reserved_mem *rmem; =20 - if (!of_device_is_available(child)) + prop =3D of_get_flat_dt_prop(child, "reg", &len); + if (!prop) + continue; + if (!of_fdt_device_is_available(fdt, child)) continue; =20 - ret =3D of_address_to_resource(child, 0, &res); - if (ret) { - rmem =3D of_reserved_mem_lookup(child); - if (rmem) - rmem->dev_node =3D child; + uname =3D fdt_get_name(fdt, child, NULL); + if (len && len % t_len !=3D 0) { + pr_err("Reserved memory: invalid reg property in '%s', skipping node.\n= ", + uname); continue; } - uname =3D of_node_full_name(child); - - base =3D res.start; - size =3D res.end - res.start + 1; + base =3D dt_mem_next_cell(dt_root_addr_cells, &prop); + size =3D dt_mem_next_cell(dt_root_size_cells, &prop); =20 if (size) fdt_reserved_mem_save_node(child, uname, base, size); @@ -264,7 +269,7 @@ int __init fdt_scan_reserved_mem(void) if (node < 0) return -ENODEV; =20 - if (__fdt_reserved_mem_check_root(node) !=3D 0) { + if (__reserved_mem_check_root(node) !=3D 0) { pr_err("Reserved memory: unsupported node format, ignoring\n"); return -EINVAL; } @@ -442,7 +447,7 @@ static int __init __reserved_mem_alloc_size(unsigned lo= ng node, const char *unam uname, (unsigned long)(size / SZ_1M)); return -ENOMEM; } - fdt_reserved_mem_save_node(NULL, uname, base, size); + fdt_reserved_mem_save_node(node, uname, base, size); return 0; } =20 @@ -462,7 +467,7 @@ static int __init __reserved_mem_init_node(struct reser= ved_mem *rmem) reservedmem_of_init_fn initfn =3D i->data; const char *compat =3D i->compatible; =20 - if (!of_device_is_compatible(rmem->dev_node, compat)) + if (!of_flat_dt_is_compatible(rmem->fdt_node, compat)) continue; =20 ret =3D initfn(rmem); @@ -495,6 +500,11 @@ static int __init __rmem_cmp(const void *a, const void= *b) if (ra->size > rb->size) return 1; =20 + if (ra->fdt_node < rb->fdt_node) + return -1; + if (ra->fdt_node > rb->fdt_node) + return 1; + return 0; } =20 @@ -541,11 +551,11 @@ void __init fdt_init_reserved_mem(void) =20 for (i =3D 0; i < reserved_mem_count; i++) { struct reserved_mem *rmem =3D &reserved_mem[i]; - struct device_node *node =3D rmem->dev_node; + unsigned long node =3D rmem->fdt_node; int err =3D 0; bool nomap; =20 - nomap =3D of_property_present(node, "no-map"); + nomap =3D of_get_flat_dt_prop(node, "no-map", NULL) !=3D NULL; =20 err =3D __reserved_mem_init_node(rmem); if (err !=3D 0 && err !=3D -ENOENT) { @@ -556,7 +566,8 @@ void __init fdt_init_reserved_mem(void) memblock_phys_free(rmem->base, rmem->size); } else { phys_addr_t end =3D rmem->base + rmem->size - 1; - bool reusable =3D of_property_present(node, "reusable"); + bool reusable =3D + (of_get_flat_dt_prop(node, "reusable", NULL)) !=3D NULL; =20 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_reserved_mem.h b/include/linux/of_reserved_me= m.h index 769b8f67c8d3..e338282da652 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -10,7 +10,7 @@ struct reserved_mem_ops; =20 struct reserved_mem { const char *name; - struct device_node *dev_node; + unsigned long fdt_node; const struct reserved_mem_ops *ops; phys_addr_t base; phys_addr_t size; diff --git a/kernel/dma/coherent.c b/kernel/dma/coherent.c index 8f99586204fb..ff5683a57f77 100644 --- a/kernel/dma/coherent.c +++ b/kernel/dma/coherent.c @@ -362,18 +362,20 @@ static const struct reserved_mem_ops rmem_dma_ops =3D= { =20 static int __init rmem_dma_setup(struct reserved_mem *rmem) { - struct device_node *node =3D rmem->dev_node; + unsigned long node =3D rmem->fdt_node; =20 - if (of_property_present(node, "reusable")) + if (of_get_flat_dt_prop(node, "reusable", NULL)) return -EINVAL; =20 - if (IS_ENABLED(CONFIG_ARM) && !of_property_present(node, "no-map")) { +#ifdef CONFIG_ARM + if (!of_get_flat_dt_prop(node, "no-map", NULL)) { pr_err("Reserved memory: regions without no-map are not yet supported\n"= ); return -EINVAL; } +#endif =20 #ifdef CONFIG_DMA_GLOBAL_POOL - if (of_property_present(node, "linux,dma-default")) { + if (of_get_flat_dt_prop(node, "linux,dma-default", NULL)) { WARN(dma_reserved_default_memory, "Reserved memory: region for default DMA coherent area is redefined= \n"); dma_reserved_default_memory =3D rmem; diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index 450e9e4be79c..055da410ac71 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -456,8 +456,8 @@ static const struct reserved_mem_ops rmem_cma_ops =3D { =20 static int __init rmem_cma_setup(struct reserved_mem *rmem) { - struct device_node *node =3D rmem->dev_node; - bool default_cma =3D of_property_read_bool(node, "linux,cma-default"); + unsigned long node =3D rmem->fdt_node; + bool default_cma =3D of_get_flat_dt_prop(node, "linux,cma-default", NULL); struct cma *cma; int err; =20 @@ -467,8 +467,8 @@ static int __init rmem_cma_setup(struct reserved_mem *r= mem) return -EBUSY; } =20 - if (!of_property_present(node, "reusable") || - of_property_present(node, "no-map")) + if (!of_get_flat_dt_prop(node, "reusable", NULL) || + of_get_flat_dt_prop(node, "no-map", NULL)) return -EINVAL; =20 if (!IS_ALIGNED(rmem->base | rmem->size, CMA_MIN_ALIGNMENT_BYTES)) { diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 9949ddc14272..fe1ccb53596f 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -1859,12 +1859,12 @@ static const struct reserved_mem_ops rmem_swiotlb_o= ps =3D { =20 static int __init rmem_swiotlb_setup(struct reserved_mem *rmem) { - struct device_node *node =3D rmem->dev_node; + unsigned long node =3D rmem->fdt_node; =20 - if (of_property_present(node, "reusable") || - of_property_present(node, "linux,cma-default") || - of_property_present(node, "linux,dma-default") || - of_property_present(node, "no-map")) + 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)) return -EINVAL; =20 rmem->ops =3D &rmem_swiotlb_ops; --=20 2.34.1 From nobody Wed Dec 17 17:30:49 2025 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4071715253F; Mon, 8 Jul 2024 23:07:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720480026; cv=none; b=UeR64Xzx1jst48OwrOvUReZREwoORCRH9PH25RgW+SbN7S5dGFj8YMAM9BWxcAyNZlSCfhHcR/kp22jNNq62E5HH1ztKg8Jm+puj4o6rhT8uGPbTVbRlQWw9IM8j37phs5FF5SlJdtk3Gl73gBfmDFy5zicqkt6LAhXat6uHSgs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720480026; c=relaxed/simple; bh=zGSc/L8jzl/pQVdLr9FvQQTeChDw0MR1gGzmyJO3vr0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SCwq6dLQDHKqrNNfofVl1+Vmg4eCDWgHlvPdO6AN4Ei2kEMUAuoz4sfEKsINIT1AlIj5VIZ2mq3t6wrwPFcVMw8GKQDXQet3vMB1Xen1p1K3imPQD/7Fwst2OWMZ0TIbyujteNzyA4Crq5I4fTcNRqdjJJl8XPAeYj8iH0a1nfk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=TteSwMk3; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="TteSwMk3" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 468Ae5qQ031488; Mon, 8 Jul 2024 23:06:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 0koejm4VGDSM/h2pnzdW2EIsVKC+/j5rOi0OvCOvocE=; b=TteSwMk3VqrE/ih6 j98SlpskCjKIoxqyxdb+tK/RZSr/+zduOzsQGcY0iu1QlCodo92lZVNoeiKZWkHv lsdGC3SDb/txyaMp4KT6gFaCa+dLrs794b5/XG6RVDiHcvEJUrxlt7sap+u72TRy J8RB3Sf/cOoUYllLRt5wOa3gOnmrckMhUFywLvKlfFUCQShRl5Nf4Z/mimnmz6CO W7Bq7ett9RDQkjJeY7MD24WpG3jPUjyCN+qvdHVGhFZBdnB3dhYMr7XKe9geZXDy 0Gr48DEzz7jtHGAc4yuvCvSpd4pjSub4lMYf/yqkIBFdW9MNuAQfbGac9SLvqLoM Q9pg1w== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 406wgwmu31-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Jul 2024 23:06:47 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.19/8.17.1.19) with ESMTPS id 468N6jWX030833 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 8 Jul 2024 23:06:46 GMT Received: from hu-obabatun-lv.qualcomm.com (10.80.80.8) 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.1544.9; Mon, 8 Jul 2024 16:06:41 -0700 From: Oreoluwa Babatunde To: , , , CC: , , , , , , , , , Oreoluwa Babatunde Subject: [PATCH 4/4] of: reserved_mem: Restructure code to call rmem init functions earlier Date: Mon, 8 Jul 2024 16:06:13 -0700 Message-ID: <20240708230613.448846-5-quic_obabatun@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240708230613.448846-1-quic_obabatun@quicinc.com> References: <20240708230613.448846-1-quic_obabatun@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) 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: VTB4CDXzZKMbfIHnLPt8VscNCrm-yE2u X-Proofpoint-ORIG-GUID: VTB4CDXzZKMbfIHnLPt8VscNCrm-yE2u X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-08_12,2024-07-05_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2407080171 Content-Type: text/plain; charset="utf-8" This reapplies the fix from commit f2a524d9ef5b ("of: reserved_mem: Restructure code to call reserved mem init functions earlier") which now uses the fdt APIs instead of the unflatten_devicetree APIs. Signed-off-by: Oreoluwa Babatunde Tested-by: Klara Modin --- drivers/of/fdt.c | 2 +- drivers/of/of_private.h | 2 +- drivers/of/of_reserved_mem.c | 79 ++++++++++++++++++++---------------- 3 files changed, 45 insertions(+), 38 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index e0f93886cc17..b5b1c9c8ed0a 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1239,7 +1239,7 @@ void __init unflatten_device_tree(void) unittest_unflatten_overlay_base(); =20 /* initialize the reserved memory regions */ - fdt_init_reserved_mem(); + fdt_scan_reserved_mem_reg_nodes(); } =20 /** diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 32b10d45b558..7ee11623612e 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -181,7 +181,7 @@ static inline struct device_node *__of_get_dma_parent(c= onst struct device_node * #endif =20 int fdt_scan_reserved_mem(void); -void fdt_init_reserved_mem(void); +void fdt_scan_reserved_mem_reg_nodes(void); =20 bool of_fdt_device_is_available(const void *blob, unsigned long node); =20 diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 113d593ea031..3fa06670f751 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -96,6 +96,7 @@ static void __init alloc_reserved_mem_array(void) reserved_mem =3D new_array; } =20 +static void __init fdt_init_reserved_mem_node(struct reserved_mem *rmem); /* * fdt_reserved_mem_save_node() - save fdt node for second pass initializa= tion */ @@ -114,6 +115,7 @@ static void __init fdt_reserved_mem_save_node(unsigned = long node, const char *un rmem->base =3D base; rmem->size =3D size; =20 + fdt_init_reserved_mem_node(rmem); reserved_mem_count++; return; } @@ -200,6 +202,7 @@ static int __init __reserved_mem_check_root(unsigned lo= ng node) return 0; } =20 +static void __init __rmem_check_for_overlap(void); /** * fdt_scan_reserved_mem_reg_nodes() - Store info for the "reg" defined * reserved memory regions. @@ -210,7 +213,7 @@ static int __init __reserved_mem_check_root(unsigned lo= ng node) * size are all stored in the reserved_mem array by calling the * fdt_reserved_mem_save_node() function. */ -static void __init fdt_scan_reserved_mem_reg_nodes(void) +void __init fdt_scan_reserved_mem_reg_nodes(void) { int t_len =3D (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); const void *fdt =3D initial_boot_params; @@ -230,6 +233,13 @@ static void __init fdt_scan_reserved_mem_reg_nodes(voi= d) return; } =20 + /* + * Allocate the exact size needed for the reserved_mem array and + * copy all the contents from the previous array if allocation + * is successful. + */ + alloc_reserved_mem_array(); + fdt_for_each_subnode(child, fdt, node) { const char *uname; =20 @@ -251,6 +261,9 @@ static void __init fdt_scan_reserved_mem_reg_nodes(void) if (size) fdt_reserved_mem_save_node(child, uname, base, size); } + + /* check for overlapping reserved regions */ + __rmem_check_for_overlap(); } =20 static int __init __reserved_mem_alloc_size(unsigned long node, const char= *uname); @@ -536,45 +549,39 @@ static void __init __rmem_check_for_overlap(void) } =20 /** - * fdt_init_reserved_mem() - allocate and init all saved reserved memory r= egions + * fdt_init_reserved_mem_node() - allocate and init an rmem memory region + * @rmem: reserved_mem object of the memory region to be initialized. + * + * This function is used to call the region specific initialization + * function on the rmem object passed as an argument. The rmem object + * will contain the base address, size, node name, and device_node of + * the reserved memory region to be initialized. */ -void __init fdt_init_reserved_mem(void) +static void __init fdt_init_reserved_mem_node(struct reserved_mem *rmem) { - int i; - - alloc_reserved_mem_array(); - - fdt_scan_reserved_mem_reg_nodes(); + unsigned long node =3D rmem->fdt_node; + int err =3D 0; + bool nomap; =20 - /* check for overlapping reserved regions */ - __rmem_check_for_overlap(); + nomap =3D of_get_flat_dt_prop(node, "no-map", NULL) !=3D NULL; =20 - for (i =3D 0; i < reserved_mem_count; i++) { - struct reserved_mem *rmem =3D &reserved_mem[i]; - unsigned long node =3D rmem->fdt_node; - int err =3D 0; - bool nomap; - - nomap =3D of_get_flat_dt_prop(node, "no-map", NULL) !=3D NULL; - - err =3D __reserved_mem_init_node(rmem); - if (err !=3D 0 && err !=3D -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 =3D rmem->base + rmem->size - 1; - bool reusable =3D - (of_get_flat_dt_prop(node, "reusable", NULL)) !=3D 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 =3D __reserved_mem_init_node(rmem); + if (err !=3D 0 && err !=3D -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 =3D rmem->base + rmem->size - 1; + bool reusable =3D + (of_get_flat_dt_prop(node, "reusable", NULL)) !=3D 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"); } } =20 --=20 2.34.1