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-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240917093851.990344-2-eric.auger@redhat.com>
Date: Tue, 17 Sep 2024 11:38:09 +0200
From: Eric Auger <eric.auger@...hat.com>
To: eric.auger.pro@...il.com,
	eric.auger@...hat.com,
	treding@...dia.com,
	vbhadram@...dia.com,
	jonathanh@...dia.com,
	mperttunen@...dia.com,
	linux-kernel@...r.kernel.org,
	kvm@...r.kernel.org,
	alex.williamson@...hat.com,
	clg@...hat.com,
	alexandre.torgue@...s.st.com,
	joabreu@...opsys.com
Cc: msalter@...hat.com
Subject: [RFC PATCH v2 1/6] vfio_platform: Introduce vfio_platform_get_region helper

Reset modules need to access some specific regions. It may
easier and safer to refer to those regions using their
name instead of relying on their index.

So let's introduce a helper that looks for the
struct vfio_platform_region with a given name.

Signed-off-by: Eric Auger <eric.auger@...hat.com>

---

I don't know if reg names described in binding yaml are guaranteed to
appear in the listed order. I guess no, hence the reg-names.
In my case, for the host tegra234 dt node, regs I even observe regs that
are not documented in the yaml:
mac, xpcs, macsec-base, hypervisor whereas yaml only describes
hypervisor, mac, xpcs
---
 drivers/vfio/platform/vfio_platform_common.c  | 14 ++++++++++++++
 drivers/vfio/platform/vfio_platform_private.h |  5 +++++
 2 files changed, 19 insertions(+)

diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c
index e53757d1d095..6861f977fd5b 100644
--- a/drivers/vfio/platform/vfio_platform_common.c
+++ b/drivers/vfio/platform/vfio_platform_common.c
@@ -153,6 +153,7 @@ static int vfio_platform_regions_init(struct vfio_platform_device *vdev)
 		vdev->regions[i].addr = res->start;
 		vdev->regions[i].size = resource_size(res);
 		vdev->regions[i].flags = 0;
+		vdev->regions[i].name = res->name;
 
 		switch (resource_type(res)) {
 		case IORESOURCE_MEM:
@@ -188,6 +189,19 @@ static int vfio_platform_regions_init(struct vfio_platform_device *vdev)
 	return -EINVAL;
 }
 
+struct vfio_platform_region*
+vfio_platform_get_region(struct vfio_platform_device *vdev, const char *name)
+{
+	int i;
+
+	for (i = 0; i < vdev->num_regions; i++) {
+		if (!strcmp(vdev->regions[i].name, name))
+			return &vdev->regions[i];
+	}
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(vfio_platform_get_region);
+
 static void vfio_platform_regions_cleanup(struct vfio_platform_device *vdev)
 {
 	int i;
diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h
index 8d8fab516849..20d67634bc41 100644
--- a/drivers/vfio/platform/vfio_platform_private.h
+++ b/drivers/vfio/platform/vfio_platform_private.h
@@ -37,6 +37,7 @@ struct vfio_platform_region {
 	resource_size_t		size;
 	u32			flags;
 	u32			type;
+	const char		*name;
 #define VFIO_PLATFORM_REGION_TYPE_MMIO	1
 #define VFIO_PLATFORM_REGION_TYPE_PIO	2
 	void __iomem		*ioaddr;
@@ -104,6 +105,10 @@ int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev,
 void __vfio_platform_register_reset(struct vfio_platform_reset_node *n);
 void vfio_platform_unregister_reset(const char *compat,
 				    vfio_platform_reset_fn_t fn);
+
+struct vfio_platform_region *
+vfio_platform_get_region(struct vfio_platform_device *vdev, const char *name);
+
 #define vfio_platform_register_reset(__compat, __reset)		\
 static struct vfio_platform_reset_node __reset ## _node = {	\
 	.owner = THIS_MODULE,					\
-- 
2.41.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ