lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 7 Aug 2023 09:02:47 -0500
From:   Nishanth Menon <nm@...com>
To:     Mathieu Poirier <mathieu.poirier@...aro.org>,
        Bjorn Andersson <andersson@...nel.org>
CC:     <linux-kernel@...r.kernel.org>, <linux-remoteproc@...r.kernel.org>,
        <linux-arm-kernel@...ts.infradead.org>, Nishanth Menon <nm@...com>,
        Robert Nelson <robertcnelson@...il.com>,
        Kevin Cahalan <kevinacahalan@...il.com>
Subject: [PATCH] remoteproc: core: Honor device tree /alias entries when assigning IDs

On many platforms, such as Beaglebone-AI64 with many remote
processors, firmware configurations provided by the distributions can
vary substantially depending on the distribution build's functionality
and the specific remote cores enabled in that variant. Ensuring
consistent udev rules mapping remoteproc nodes to constant remote
proc device indices across distributions (yocto, ubuntu, debian and
it's variants, ...) on a board basis can be challenging due to the
various functions of these distributions. Varied device node paths
create challenges for applications that operate on remote processors,
especially in minimal embedded systems(initrd like) that may not
have udev-like capabilities and rely on a more straightforward bare
filesystem. This challenge is similar to that faced by I2C, RTC or the
GPIO subsystems.

Assign remoteproc device IDs based on device tree /aliases entries if
present, falling back to the existing numbering scheme if there is no
/aliases entry (which includes when the system isn't booted using DT)
or a numbering conflict. If the alias node is not present, the driver
behaves as before.

Cc: Robert Nelson <robertcnelson@...il.com>
Reported-by: Kevin Cahalan <kevinacahalan@...il.com>
Signed-off-by: Nishanth Menon <nm@...com>
---
Test log: Beaglebone-AI64
https://gist.github.com/nmenon/365cf80d6c0685dd9be7c2cb18d7c937 (along
with a test change to force the sequence of initialization)

The report occurred on Beagle discord channel - so I am not
sure how to share the logs of the report.

 drivers/remoteproc/remoteproc_core.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 695cce218e8c..a12f3d37b8de 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -19,6 +19,7 @@
 #include <linux/delay.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/device.h>
 #include <linux/panic_notifier.h>
 #include <linux/slab.h>
@@ -2417,6 +2418,25 @@ static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops)
 	return 0;
 }
 
+static int rproc_device_get_id(struct device *dev)
+{
+	int of_id = -1, id = -1;
+
+	if (dev->of_node)
+		of_id = of_alias_get_id(dev->of_node, "remoteproc");
+
+	if (of_id >= 0) {
+		id = ida_simple_get(&rproc_dev_index, of_id, of_id + 1, GFP_KERNEL);
+		if (id < 0)
+			dev_warn(dev, "/aliases ID %d not available\n", of_id);
+	}
+
+	if (id < 0)
+		id = ida_alloc(&rproc_dev_index, GFP_KERNEL);
+
+	return id;
+}
+
 /**
  * rproc_alloc() - allocate a remote processor handle
  * @dev: the underlying device
@@ -2476,7 +2496,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
 		goto put_device;
 
 	/* Assign a unique device index and name */
-	rproc->index = ida_alloc(&rproc_dev_index, GFP_KERNEL);
+	rproc->index = rproc_device_get_id(dev);
 	if (rproc->index < 0) {
 		dev_err(dev, "ida_alloc failed: %d\n", rproc->index);
 		goto put_device;
-- 
2.40.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ