[PATCH 5/6] bus: fsl-mc: move uapi misc dev create/remove in probe and remove

From: laurentiu . tudor
Date: Tue Feb 08 2022 - 10:00:15 EST


From: Laurentiu Tudor <laurentiu.tudor@xxxxxxx>

When devices are owned by VFIO lets not allow user-space to play with
them through the restool management interface thus breaking isolation.
Drop restool misc device creation and destruction from the common
dprc_setup() and dprc_cleanup() functions (shared with fsl-mc VFIO)
and open code it drpc driver's probe and remove ops.

Signed-off-by: Laurentiu Tudor <laurentiu.tudor@xxxxxxx>
---
drivers/bus/fsl-mc/dprc-driver.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/bus/fsl-mc/dprc-driver.c b/drivers/bus/fsl-mc/dprc-driver.c
index 8482c4fca835..82bf3fe09273 100644
--- a/drivers/bus/fsl-mc/dprc-driver.c
+++ b/drivers/bus/fsl-mc/dprc-driver.c
@@ -618,7 +618,6 @@ int dprc_setup(struct fsl_mc_device *mc_dev)
struct irq_domain *mc_msi_domain;
bool mc_io_created = false;
bool msi_domain_set = false;
- bool uapi_created = false;
u16 major_ver, minor_ver;
size_t region_size;
int error;
@@ -651,11 +650,6 @@ int dprc_setup(struct fsl_mc_device *mc_dev)
return error;

mc_io_created = true;
- } else {
- error = fsl_mc_uapi_create_device_file(mc_bus);
- if (error < 0)
- return -EPROBE_DEFER;
- uapi_created = true;
}

mc_msi_domain = fsl_mc_find_msi_domain(&mc_dev->dev);
@@ -713,9 +707,6 @@ int dprc_setup(struct fsl_mc_device *mc_dev)
mc_dev->mc_io = NULL;
}

- if (uapi_created)
- fsl_mc_uapi_remove_device_file(mc_bus);
-
return error;
}
EXPORT_SYMBOL_GPL(dprc_setup);
@@ -734,9 +725,15 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
{
int error;

+ if (fsl_mc_is_root_dprc(&mc_dev->dev)) {
+ error = fsl_mc_uapi_create_device_file(to_fsl_mc_bus(mc_dev));
+ if (error < 0)
+ return -EPROBE_DEFER;
+ }
+
error = dprc_setup(mc_dev);
if (error < 0)
- return error;
+ goto uapi_cleanup;

/*
* Discover MC objects in DPRC object:
@@ -759,6 +756,10 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove);
dprc_cleanup:
dprc_cleanup(mc_dev);
+uapi_cleanup:
+ if (fsl_mc_is_root_dprc(&mc_dev->dev))
+ fsl_mc_uapi_remove_device_file(to_fsl_mc_bus(mc_dev));
+
return error;
}

@@ -792,7 +793,6 @@ static void dprc_teardown_irq(struct fsl_mc_device *mc_dev)

int dprc_cleanup(struct fsl_mc_device *mc_dev)
{
- struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev);
int error;

/* this function should be called only for DPRCs, it
@@ -821,8 +821,6 @@ int dprc_cleanup(struct fsl_mc_device *mc_dev)
if (!fsl_mc_is_root_dprc(&mc_dev->dev)) {
fsl_destroy_mc_io(mc_dev->mc_io);
mc_dev->mc_io = NULL;
- } else {
- fsl_mc_uapi_remove_device_file(mc_bus);
}

return 0;
@@ -854,6 +852,9 @@ static int dprc_remove(struct fsl_mc_device *mc_dev)

device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove);

+ if (fsl_mc_is_root_dprc(&mc_dev->dev))
+ fsl_mc_uapi_remove_device_file(to_fsl_mc_bus(mc_dev));
+
dprc_cleanup(mc_dev);

dev_info(&mc_dev->dev, "DPRC device unbound from driver");
--
2.17.1