vfio, platform: add ACPI support
Subsystems (5)
v6 cover vfio, platform: add ACPI support
The device tree code checks for the presence of a reset driver and calls the of_reset function pointer by looking up the reset driver as a module.
ACPI defines _RST method to perform device level reset. After the _RST method is executed, the OS can resume using the device.
This patch checks the presence of _RST method and calls the _RST method when reset is requested.
Changes from V5:
1. Handle reset function call failures in open and release (new patch).
2. Bring out extra debug information when failure happens (new patch).
3. Address review comments from Eric in ACPI _RST patch.
Sinan Kaya (8):
vfio: platform: move reset call to a common function
vfio: platform: determine reset capability
vfio: platform: add support for ACPI probe
vfio: platform: add extra debug info argument to call reset
vfio: platform: call _RST method when using ACPI vfio, platform: make reset driver a requirement by default
vfio: platform: check reset call return code during open
vfio: platform: check reset call return code during release
drivers/vfio/platform/vfio_amba.c | 5 + drivers/vfio/platform/vfio_platform.c | 5 + drivers/vfio/platform/vfio_platform_common.c | 169 ++++++++++++++++++++++---- drivers/vfio/platform/vfio_platform_private.h | 2 + 4 files changed, 159 insertions(+), 22 deletions(-)
Signature · 1 line
1.8.2.1
PATCH v6 1/8 vfio: platform: move reset call to a common function
The reset call sequence seems to replicate itself multiple times across the file. Grouping them together for maintenance reasons.
--- drivers/vfio/platform/vfio_platform_common.c | 30 +++++++++++++--------------- 1 file changed, 14 insertions(+), 16 deletions(-)
drivers/vfio/platform/vfio_platform_common.c +14 -16
@@ -134,6 +134,17 @@ static void vfio_platform_regions_cleanup(struct vfio_platform_device *vdev)kfree (vdev->regions); } +static int vfio_platform_call_reset (struct vfio_platform_device *vdev) +{ +if (vdev->of_reset) { +dev_info (vdev->device,"reset\n" ); +return vdev->of_reset (vdev); + } + +dev_warn (vdev->device,"no reset function found!\n" ); +return -EINVAL ; +} +static void vfio_platform_release (void *device_data) {struct vfio_platform_device *vdev = device_data;
@@ -141,12 +152,7 @@ static void vfio_platform_release(void *device_data)mutex_lock (&driver_lock);if (!(--vdev->refcnt)) { -if (vdev->of_reset) { -dev_info (vdev->device,"reset\n" ); - vdev->of_reset (vdev); - }else { -dev_warn (vdev->device,"no reset function found!\n" ); - } +vfio_platform_call_reset (vdev);vfio_platform_regions_cleanup (vdev);vfio_platform_irq_cleanup (vdev); }
@@ -175,12 +181,7 @@ static int vfio_platform_open(void *device_data)if (ret) goto err_irq; -if (vdev->of_reset) { -dev_info (vdev->device,"reset\n" ); - vdev->of_reset (vdev); - }else { -dev_warn (vdev->device,"no reset function found!\n" ); - } +vfio_platform_call_reset (vdev); } vdev->refcnt++;
@@ -312,10 +313,7 @@ static long vfio_platform_ioctl(void *device_data,return ret; }else if (cmd ==VFIO_DEVICE_RESET ) { -if (vdev->of_reset) -return vdev->of_reset (vdev); -else -return -EINVAL ; +return vfio_platform_call_reset (vdev); }return -ENOTTY ;
Signature · 1 line
1.8.2.1
PATCH v6 2/8 vfio: platform: determine reset capability
In reply to Sinan KayaCreating a new function to determine if this driver supports reset function or not. This is an attempt to abstract device tree calls from the rest of the code.
--- drivers/vfio/platform/vfio_platform_common.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/vfio/platform/vfio_platform_common.c +6 -1
@@ -49,6 +49,11 @@ static vfio_platform_reset_fn_t vfio_platform_lookup_reset(const char *compat,return reset_fn; } +static bool vfio_platform_has_reset (struct vfio_platform_device *vdev) +{ +return vdev->of_reset ? true : false; +} +static void vfio_platform_get_reset (struct vfio_platform_device *vdev) { vdev->of_reset = vfio_platform_lookup_reset(vdev->compat,
@@ -214,7 +219,7 @@ static long vfio_platform_ioctl(void *device_data,if (info.argsz < minsz)return -EINVAL ; -if (vdev->of_reset) +if (vfio_platform_has_reset (vdev)) vdev->flags |=VFIO_DEVICE_FLAGS_RESET ; info.flags = vdev->flags; info.num_regions = vdev->num_regions;
Signature · 1 line
1.8.2.1
PATCH v6 3/8 vfio: platform: add support for ACPI probe
In reply to Sinan KayaThe code is using the compatible DT string to associate a reset driver with the actual device itself. The compatible string does not exist on ACPI based systems. HID is the unique identifier for a device driver instead.
--- drivers/vfio/platform/vfio_platform_common.c | 57 ++++++++++++++++++++++++--- drivers/vfio/platform/vfio_platform_private.h | 1 + 2 files changed, 53 insertions(+), 5 deletions(-)
drivers/vfio/platform/vfio_platform_common.c +52 -5
@@ -13,6 +13,7 @@*/ #include <linux/device.h> +#include <linux/acpi.h> #include <linux/iommu.h> #include <linux/module.h> #include <linux/mutex.h>
@@ -49,6 +50,37 @@ static vfio_platform_reset_fn_t vfio_platform_lookup_reset(const char *compat,return reset_fn; } +#ifdef CONFIG_ACPI +static int vfio_platform_acpi_probe (struct vfio_platform_device *vdev, +struct device *dev) +{ +struct acpi_device *adev =ACPI_COMPANION (dev); + +if (acpi_disabled) +return -ENODEV ; + +if (!adev) { +pr_err ("VFIO: ACPI companion device not found for %s\n" , + vdev->name); +return -ENODEV ; + } + + vdev->acpihid =acpi_device_hid (adev); +if (!vdev->acpihid) { +pr_err ("VFIO: cannot find ACPI HID for %s\n" , + vdev->name); +return -ENODEV ; + } +return 0 ; +} +#else +static inline int vfio_platform_acpi_probe (struct vfio_platform_device *vdev, +struct device *dev) +{ +return -ENOENT ; +} +#endif +static bool vfio_platform_has_reset (struct vfio_platform_device *vdev) {return vdev->of_reset ? true : false;
@@ -547,6 +579,20 @@ static const struct vfio_device_ops vfio_platform_ops = { .mmap = vfio_platform_mmap, }; +int vfio_platform_of_probe (struct vfio_platform_device *vdev, +struct device *dev) +{ +int ret; + + ret =device_property_read_string (dev,"compatible" , + &vdev->compat); +if (ret) +pr_err ("VFIO: cannot retrieve compat for %s\n" , + vdev->name); + +return ret; +} +int vfio_platform_probe_common (struct vfio_platform_device *vdev,struct device *dev) {
@@ -556,11 +602,12 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev,if (!vdev)return -EINVAL ; - ret =device_property_read_string (dev,"compatible" , &vdev->compat); -if (ret) { -pr_err ("VFIO: cannot retrieve compat for %s\n" , vdev->name); -return -EINVAL ; - } + ret =vfio_platform_acpi_probe (vdev, dev); +if (ret) + ret =vfio_platform_of_probe (vdev, dev); + +if (ret) +return ret; vdev->device = dev;
drivers/vfio/platform/vfio_platform_private.h +1 -0
@@ -58,6 +58,7 @@ struct vfio_platform_device {struct mutex igate;struct module *parent_module;const char *compat; +const char *acpihid;struct module *reset_module;struct device *device;
Signature · 1 line
1.8.2.1
PATCH v6 4/8 vfio: platform: add extra debug info argument to call reset
In reply to Sinan KayaGetting ready to bring out extra debug information to the caller so that more verbose information can be printed when an error is observed.
--- drivers/vfio/platform/vfio_platform_common.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/vfio/platform/vfio_platform_common.c +5 -4
@@ -171,7 +171,8 @@ static void vfio_platform_regions_cleanup(struct vfio_platform_device *vdev)kfree (vdev->regions); } -static int vfio_platform_call_reset (struct vfio_platform_device *vdev) +static int vfio_platform_call_reset (struct vfio_platform_device *vdev, +const char **extra_dbg) {if (vdev->of_reset) {dev_info (vdev->device,"reset\n" );
@@ -189,7 +190,7 @@ static void vfio_platform_release(void *device_data)mutex_lock (&driver_lock);if (!(--vdev->refcnt)) { -vfio_platform_call_reset (vdev); +vfio_platform_call_reset (vdev,NULL );vfio_platform_regions_cleanup (vdev);vfio_platform_irq_cleanup (vdev); }
@@ -218,7 +219,7 @@ static int vfio_platform_open(void *device_data)if (ret) goto err_irq; -vfio_platform_call_reset (vdev); +vfio_platform_call_reset (vdev,NULL ); } vdev->refcnt++;
@@ -350,7 +351,7 @@ static long vfio_platform_ioctl(void *device_data,return ret; }else if (cmd ==VFIO_DEVICE_RESET ) { -return vfio_platform_call_reset (vdev); +return vfio_platform_call_reset (vdev,NULL ); }return -ENOTTY ;
Signature · 1 line
1.8.2.1
PATCH v6 5/8 vfio: platform: call _RST method when using ACPI
In reply to Sinan KayaThe device tree code checks for the presence of a reset driver and calls the of_reset function pointer by looking up the reset driver as a module.
ACPI defines _RST method to perform device level reset. After the _RST method is executed, the OS can resume using the device. _RST method is expected to stop DMA transfers and IRQs.
This patch checks the presence of _RST method and calls the _RST method when reset is requested.
--- drivers/vfio/platform/vfio_platform_common.c | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
drivers/vfio/platform/vfio_platform_common.c +51 -0
@@ -73,21 +73,66 @@ static int vfio_platform_acpi_probe(struct vfio_platform_device *vdev, }return 0 ; } + +static int vfio_platform_acpi_call_reset (struct vfio_platform_device *vdev, +const char **extra_dbg) +{ +struct device *dev = vdev->device; +acpi_handle handle =ACPI_HANDLE (dev); +acpi_status acpi_ret; +unsigned long long val; + + acpi_ret =acpi_evaluate_integer (handle,"_RST" ,NULL , &val); +if (ACPI_FAILURE (acpi_ret)) { +if (extra_dbg) + *extra_dbg =acpi_format_exception (acpi_ret); +return -EINVAL ; + } + +return 0 ; +} + +static bool vfio_platform_acpi_has_reset (struct vfio_platform_device *vdev) +{ +struct device *dev = vdev->device; +acpi_handle handle =ACPI_HANDLE (dev); + +return acpi_has_method (handle,"_RST" ); +}#else static inline int vfio_platform_acpi_probe (struct vfio_platform_device *vdev,struct device *dev) {return -ENOENT ; } + +static inline +int vfio_platform_acpi_call_reset (struct vfio_platform_device *vdev, +const char **extra_dbg) +{ +return -ENOENT ; +} + +static inline +bool vfio_platform_acpi_has_reset (struct vfio_platform_device *vdev) +{ +return false; +}#endif static bool vfio_platform_has_reset (struct vfio_platform_device *vdev) { +if (vdev->acpihid) +return vfio_platform_acpi_has_reset (vdev); +return vdev->of_reset ? true : false; }static void vfio_platform_get_reset (struct vfio_platform_device *vdev) { +if (vdev->acpihid) +return ; + vdev->of_reset =vfio_platform_lookup_reset (vdev->compat, &vdev->reset_module);if (!vdev->of_reset) {
@@ -99,6 +144,9 @@ static void vfio_platform_get_reset(struct vfio_platform_device *vdev)static void vfio_platform_put_reset (struct vfio_platform_device *vdev) { +if (vdev->acpihid) +return ; +if (vdev->of_reset)module_put (vdev->reset_module); }
@@ -177,6 +225,9 @@ static int vfio_platform_call_reset(struct vfio_platform_device *vdev,if (vdev->of_reset) {dev_info (vdev->device,"reset\n" );return vdev->of_reset (vdev); + }else if (vdev->acpihid) { +dev_info (vdev->device,"reset\n" ); +return vfio_platform_acpi_call_reset (vdev, extra_dbg); }dev_warn (vdev->device,"no reset function found!\n" );
Signature · 1 line
1.8.2.1
Auger Eric
maintainerRe: [PATCH V6 5/8] vfio: platform: call _RST method when using ACPI
Hi Sinan,
Quoted 7 lines · Sinan Kaya
The device tree code checks for the presence of a reset driver and calls the
of_resetfunction pointer by looking up the reset driver as a module.ACPI defines
_RSTmethod to perform device level reset. After the_RSTmethod is executed, the OS can resume using the device._RSTmethod is expected to stop DMA transfers and IRQs.
Quoted 5 lines
This patch checks the presence of
_RSTmethod and calls the_RSTmethod when reset is requested.Signed-off-by Sinan Kaya <[email protected]>Reviewed-by Eric Auger <[email protected]>
code has changed compared to previous version and the R-b. In the future, please add change logs. Besides it looks ok to me.
Best Regards
Eric
Quoted 87 lines
--- drivers/vfio/platform/vfio_platform_common.c | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)drivers/vfio/platform/vfio_platform_common.c +48
-0@@ -73,21 +73,66 @@ static int vfio_platform_acpi_probe(struct vfio_platform_device *vdev, }return 0 ; } + +static int vfio_platform_acpi_call_reset (struct vfio_platform_device *vdev, +const char **extra_dbg) +{ +struct device *dev = vdev->device; +acpi_handle handle =ACPI_HANDLE (dev); +acpi_status acpi_ret; +unsigned long long val; + + acpi_ret =acpi_evaluate_integer (handle,"_RST" ,NULL , &val); +if (ACPI_FAILURE (acpi_ret)) { +if (extra_dbg) + *extra_dbg =acpi_format_exception (acpi_ret); +return -EINVAL ; + } + +return 0 ; +} + +static bool vfio_platform_acpi_has_reset (struct vfio_platform_device *vdev) +{ +struct device *dev = vdev->device; +acpi_handle handle =ACPI_HANDLE (dev); + +return acpi_has_method (handle,"_RST" ); +}#else static inline int vfio_platform_acpi_probe (struct vfio_platform_device *vdev,struct device *dev) {return -ENOENT ; } + +static inline +int vfio_platform_acpi_call_reset (struct vfio_platform_device *vdev, +const char **extra_dbg) +{ +return -ENOENT ; +} + +static inline +bool vfio_platform_acpi_has_reset (struct vfio_platform_device *vdev) +{ +return false; +}#endif static bool vfio_platform_has_reset (struct vfio_platform_device *vdev) { +if (vdev->acpihid) +return vfio_platform_acpi_has_reset (vdev); +return vdev->of_reset ? true : false; }static void vfio_platform_get_reset (struct vfio_platform_device *vdev) { +if (vdev->acpihid) +return ; + vdev->of_reset =vfio_platform_lookup_reset (vdev->compat, &vdev->reset_module);if (!vdev->of_reset) {@@ -99,6 +144,9 @@ static void vfio_platform_get_reset(struct vfio_platform_device *vdev)static void vfio_platform_put_reset (struct vfio_platform_device *vdev) { +if (vdev->acpihid) +return ; +if (vdev->of_reset)module_put (vdev->reset_module); }
drivers/vfio/platform/vfio_platform_common.c static int vfio_platform_call_reset(struct vfio_platform_device *vdev, · line 233
Quoted 9 lines
drivers/vfio/platform/vfio_platform_common.c +3
-0@@ -177,6 +225,9 @@ static int vfio_platform_call_reset(struct vfio_platform_device *vdev,if (vdev->of_reset) {dev_info (vdev->device,"reset\n" );return vdev->of_reset (vdev); + }else if (vdev->acpihid) { +dev_info (vdev->device,"reset\n" ); +return vfio_platform_acpi_call_reset (vdev, extra_dbg); }dev_warn (vdev->device,"no reset function found!\n" );
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Rafael J. Wysocki
maintainerRe: [PATCH V6 5/8] vfio: platform: call _RST method when using ACPI
In reply to Sinan KayaQuoted 9 lines · Sinan Kaya
The device tree code checks for the presence of a reset driver and calls the
of_resetfunction pointer by looking up the reset driver as a module.ACPI defines
_RSTmethod to perform device level reset. After the_RSTmethod is executed, the OS can resume using the device._RSTmethod is expected to stop DMA transfers and IRQs.This patch checks the presence of
_RSTmethod and calls the_RSTmethod when reset is requested.
You could check if _RST is present at probe time and store the ACPI handle of it instead of the HID pointer.
This way you wouldn't need to repeat that check every time reset is used.
Re: [PATCH V6 5/8] vfio: platform: call _RST method when using ACPI
Quoted 8 lines · Rafael J. Wysocki
Quoted 7 lines · Sinan Kaya
The device tree code checks for the presence of a reset driver and calls the
of_resetfunction pointer by looking up the reset driver as a module.ACPI defines
_RSTmethod to perform device level reset. After the_RSTmethod is executed, the OS can resume using the device._RSTmethod is expected to stop DMA transfers and IRQs.
Quoted 8 lines
Quoted 2 lines
This patch checks the presence of
_RSTmethod and calls the_RSTmethod when reset is requested.You could check if
_RSTis present at probe time and store the ACPI handle of it instead of the HID pointer.This way you wouldn't need to repeat that check every time reset is used.
Makes sense. I'll give it a shot.
Signature · 3 lines
Sinan Kaya Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH V6 5/8] vfio: platform: call _RST method when using ACPI
In reply to Rafael J. WysockiQuoted 11 lines · Rafael J. Wysocki
Quoted 9 lines · Sinan Kaya
The device tree code checks for the presence of a reset driver and calls the
of_resetfunction pointer by looking up the reset driver as a module.ACPI defines
_RSTmethod to perform device level reset. After the_RSTmethod is executed, the OS can resume using the device._RSTmethod is expected to stop DMA transfers and IRQs.This patch checks the presence of
_RSTmethod and calls the_RSTmethod when reset is requested.
A little bit of misinformation here. The current code is checking the presence during probe time. If the presence of _RST method is required then probe is aborted. Otherwise, probe will complete execution.
When reset call is to be executed, presence of _RST method is no longer checked. Instead, the method is directly called.
I was talking about the contribution of this patch as both here. I'll clarify the commit message.
Quoted 5 lines
You could check if
_RSTis present at probe time and store the ACPI handle of it instead of the HID pointer.This way you wouldn't need to repeat that check every time reset is used.
Based on the requirement that the code can be executed without the presence of _RST method for development purposes, I'm hesitant to use the handle of the reset method as a gating factor.
Signature · 3 lines
Sinan Kaya Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v6 6/8 vfio, platform: make reset driver a requirement by default
In reply to Sinan KayaThe code was allowing platform devices to be used without a supporting VFIO reset driver. The hardware can be left in some inconsistent state after a guest machine abort.
The reset driver will put the hardware back to safe state and disable interrupts before returning the control back to the host machine.
Adding a new reset_required kernel module option to AMBA and platform VFIO drivers with a default value of true.
New requirements are:
1. A reset function needs to be implemented by the corresponding driver via DT/ACPI.
2. The reset function needs to be discovered via DT/ACPI.
The probe of the driver will fail if any of the above conditions are not satisfied.
--- drivers/vfio/platform/vfio_amba.c | 5 +++++ drivers/vfio/platform/vfio_platform.c | 5 +++++ drivers/vfio/platform/vfio_platform_common.c | 14 +++++++++++--- drivers/vfio/platform/vfio_platform_private.h | 1 + 4 files changed, 22 insertions(+), 3 deletions(-)
drivers/vfio/platform/vfio_amba.c +5 -0
@@ -23,6 +23,10 @@#define DRIVER_AUTHOR "Antonios Motakis <[email protected]>"#define DRIVER_DESC "VFIO for AMBA devices - User Level meta-driver" +static bool reset_required = true; +module_param (reset_required, bool,0644 ); +MODULE_PARM_DESC (reset_required,"override reset requirement (default: 1)" ); +/* probing devices from the AMBA bus */ static struct resource *get_amba_resource(struct vfio_platform_device *vdev,
@@ -68,6 +72,7 @@ static int vfio_amba_probe(struct amba_device *adev, const struct amba_id *id) vdev->get_resource = get_amba_resource; vdev->get_irq = get_amba_irq; vdev->parent_module =THIS_MODULE ; + vdev->reset_required = reset_required; ret =vfio_platform_probe_common (vdev, &adev->dev);if (ret) {
drivers/vfio/platform/vfio_platform.c +5 -0
@@ -23,6 +23,10 @@#define DRIVER_AUTHOR "Antonios Motakis <[email protected]>"#define DRIVER_DESC "VFIO for platform devices - User Level meta-driver" +static bool reset_required = true; +module_param (reset_required, bool,0644 ); +MODULE_PARM_DESC (reset_required,"override reset requirement (default: 1)" ); +/* probing devices from the linux platform bus */ static struct resource *get_platform_resource(struct vfio_platform_device *vdev,
@@ -66,6 +70,7 @@ static int vfio_platform_probe(struct platform_device *pdev) vdev->get_resource = get_platform_resource; vdev->get_irq = get_platform_irq; vdev->parent_module =THIS_MODULE ; + vdev->reset_required = reset_required; ret =vfio_platform_probe_common (vdev, &pdev->dev);if (ret)
drivers/vfio/platform/vfio_platform_common.c +11 -3
@@ -128,10 +128,10 @@ static bool vfio_platform_has_reset(struct vfio_platform_device *vdev)return vdev->of_reset ? true : false; } -static void vfio_platform_get_reset (struct vfio_platform_device *vdev) +static int vfio_platform_get_reset (struct vfio_platform_device *vdev) {if (vdev->acpihid) -return ; +return vfio_platform_acpi_has_reset (vdev) ?0 : -ENOENT ; vdev->of_reset =vfio_platform_lookup_reset (vdev->compat, &vdev->reset_module);
@@ -140,6 +140,8 @@ static void vfio_platform_get_reset(struct vfio_platform_device *vdev) vdev->of_reset =vfio_platform_lookup_reset (vdev->compat, &vdev->reset_module); } + +return vdev->of_reset ?0 : -ENOENT ; }static void vfio_platform_put_reset (struct vfio_platform_device *vdev)
@@ -675,7 +677,13 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev,return ret; } -vfio_platform_get_reset (vdev); + ret =vfio_platform_get_reset (vdev); +if (ret && vdev->reset_required) { +pr_err ("vfio: no reset function found for device %s\n" , + vdev->name); +iommu_group_put (group); +return ret; + }mutex_init (&vdev->igate);
drivers/vfio/platform/vfio_platform_private.h +1 -0
@@ -50,6 +50,7 @@ struct vfio_platform_region { };struct vfio_platform_device { +bool reset_required;struct vfio_platform_region *regions;u32 num_regions;struct vfio_platform_irq *irqs;
Signature · 1 line
1.8.2.1
Auger Eric
maintainerRe: [PATCH V6 6/8] vfio, platform: make reset driver a requirement by default
Quoted 99 lines · Sinan Kaya
The code was allowing platform devices to be used without a supporting VFIO reset driver. The hardware can be left in some inconsistent state after a guest machine abort.
The reset driver will put the hardware back to safe state and disable interrupts before returning the control back to the host machine.
Adding a new
reset_requiredkernel module option to AMBA and platform VFIO drivers with a default value of true.New requirements are:
1. A reset function needs to be implemented by the corresponding driver via DT/ACPI.
2. The reset function needs to be discovered via DT/ACPI.The probe of the driver will fail if any of the above conditions are not satisfied.
Signed-off-by Sinan Kaya <[email protected]>--- drivers/vfio/platform/vfio_amba.c | 5 +++++ drivers/vfio/platform/vfio_platform.c | 5 +++++ drivers/vfio/platform/vfio_platform_common.c | 14 +++++++++++--- drivers/vfio/platform/vfio_platform_private.h | 1 + 4 files changed, 22 insertions(+), 3 deletions(-)drivers/vfio/platform/vfio_amba.c +5
-0@@ -23,6 +23,10 @@#define DRIVER_AUTHOR "Antonios Motakis <[email protected]>"#define DRIVER_DESC "VFIO for AMBA devices - User Level meta-driver" +static bool reset_required = true; +module_param (reset_required, bool,0644 ); +MODULE_PARM_DESC (reset_required,"override reset requirement (default: 1)" ); +/* probing devices from the AMBA bus */ static struct resource *get_amba_resource(struct vfio_platform_device *vdev,@@ -68,6 +72,7 @@ static int vfio_amba_probe(struct amba_device *adev, const struct amba_id *id) vdev->get_resource = get_amba_resource; vdev->get_irq = get_amba_irq; vdev->parent_module =THIS_MODULE ; + vdev->reset_required = reset_required; ret =vfio_platform_probe_common (vdev, &adev->dev);if (ret) {drivers/vfio/platform/vfio_platform.c +5
-0@@ -23,6 +23,10 @@#define DRIVER_AUTHOR "Antonios Motakis <[email protected]>"#define DRIVER_DESC "VFIO for platform devices - User Level meta-driver" +static bool reset_required = true; +module_param (reset_required, bool,0644 ); +MODULE_PARM_DESC (reset_required,"override reset requirement (default: 1)" ); +/* probing devices from the linux platform bus */ static struct resource *get_platform_resource(struct vfio_platform_device *vdev,@@ -66,6 +70,7 @@ static int vfio_platform_probe(struct platform_device *pdev) vdev->get_resource = get_platform_resource; vdev->get_irq = get_platform_irq; vdev->parent_module =THIS_MODULE ; + vdev->reset_required = reset_required; ret =vfio_platform_probe_common (vdev, &pdev->dev);if (ret)drivers/vfio/platform/vfio_platform_common.c +4
-2@@ -128,10 +128,10 @@ static bool vfio_platform_has_reset(struct vfio_platform_device *vdev)return vdev->of_reset ? true : false; } -static void vfio_platform_get_reset (struct vfio_platform_device *vdev) +static int vfio_platform_get_reset (struct vfio_platform_device *vdev) {if (vdev->acpihid) -return ; +return vfio_platform_acpi_has_reset (vdev) ?0 : -ENOENT ; vdev->of_reset =vfio_platform_lookup_reset (vdev->compat, &vdev->reset_module);@@ -140,6 +140,8 @@ static void vfio_platform_get_reset(struct vfio_platform_device *vdev) vdev->of_reset =vfio_platform_lookup_reset (vdev->compat, &vdev->reset_module); } + +return vdev->of_reset ?0 : -ENOENT ; }static void vfio_platform_put_reset (struct vfio_platform_device *vdev)
drivers/vfio/platform/vfio_platform_common.c int vfio_platform_probe_common(struct vfio_platform_device *vdev, · line 685
Quoted 10 lines
drivers/vfio/platform/vfio_platform_common.c +6
-1@@ -675,7 +677,13 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev,return ret; } -vfio_platform_get_reset (vdev); + ret =vfio_platform_get_reset (vdev); +if (ret && vdev->reset_required) { +pr_err ("vfio: no reset function found for device %s\n" , + vdev->name); +iommu_group_put (group); +return ret;
nit: in case you respin you can factorize the group put and return ret in a goto label (since also used above).
Besides Reviewed-by: Eric Auger <[email protected]>
Thanks
Eric
Quoted 17 lines
drivers/vfio/platform/vfio_platform_common.c +1
-0+ }mutex_init (&vdev->igate);drivers/vfio/platform/vfio_platform_private.h +1
-0@@ -50,6 +50,7 @@ struct vfio_platform_region { };struct vfio_platform_device { +bool reset_required;struct vfio_platform_region *regions;u32 num_regions;struct vfio_platform_irq *irqs;
Re: [PATCH V6 6/8] vfio, platform: make reset driver a requirement by default
Quoted 11 lines · Auger Eric
Quoted 7 lines
drivers/vfio/platform/vfio_platform_common.c +0
-1-vfio_platform_get_reset (vdev);drivers/vfio/platform/vfio_platform_common.c int vfio_platform_probe_common(struct vfio_platform_device *vdev, · line 685
Quoted 6 lines
drivers/vfio/platform/vfio_platform_common.c +6
-0+ ret =vfio_platform_get_reset (vdev); +if (ret && vdev->reset_required) { +pr_err ("vfio: no reset function found for device %s\n" , + vdev->name); +iommu_group_put (group); +return ret;nit: in case you respin you can factorize the group put and return ret in a goto label (since also used above).
Besides Reviewed-by: Eric Auger <[email protected]>
thanks, done. I'll respin with your request.
Signature · 3 lines
Sinan Kaya Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v6 7/8 vfio: platform: check reset call return code during open
In reply to Sinan KayaOpen call is ignoring the return code from reset call and can potentially continue even though reset call failed.
If reset_required module parameter is set, this patch is going to validate the return code and will abort open if reset fails.
--- drivers/vfio/platform/vfio_platform_common.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/vfio/platform/vfio_platform_common.c +8 -1
@@ -264,6 +264,8 @@ static int vfio_platform_open(void *device_data)mutex_lock (&driver_lock);if (!vdev->refcnt) { +const char *extra_dbg =NULL ; + ret =vfio_platform_regions_init (vdev);if (ret) goto err_reg;
@@ -272,7 +274,12 @@ static int vfio_platform_open(void *device_data)if (ret) goto err_irq; -vfio_platform_call_reset (vdev,NULL ); + ret =vfio_platform_call_reset (vdev, &extra_dbg); +if (ret && vdev->reset_required) { +dev_warn (vdev->device,"reset driver is required and reset call failed in open (%d) %s\n" , + ret, extra_dbg ? extra_dbg :"" ); + goto err_irq; + } } vdev->refcnt++;
Signature · 1 line
1.8.2.1
Auger Eric
maintainerRe: [PATCH V6 7/8] vfio: platform: check reset call return code during open
Hi Sinan,
Quoted 25 lines · Sinan Kaya
Open call is ignoring the return code from reset call and can potentially continue even though reset call failed.
If
reset_requiredmodule parameter is set, this patch is going to validate the return code and will abort open if reset fails.Signed-off-by Sinan Kaya <[email protected]>--- drivers/vfio/platform/vfio_platform_common.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/vfio/platform/vfio_platform_common.c +2
-0@@ -264,6 +264,8 @@ static int vfio_platform_open(void *device_data)mutex_lock (&driver_lock);if (!vdev->refcnt) { +const char *extra_dbg =NULL ; + ret =vfio_platform_regions_init (vdev);if (ret) goto err_reg;
drivers/vfio/platform/vfio_platform_common.c static int vfio_platform_open(void *device_data) · line 281
Quoted 9 lines
drivers/vfio/platform/vfio_platform_common.c +5
-1@@ -272,7 +274,12 @@ static int vfio_platform_open(void *device_data)if (ret) goto err_irq; -vfio_platform_call_reset (vdev,NULL ); + ret =vfio_platform_call_reset (vdev, &extra_dbg); +if (ret && vdev->reset_required) { +dev_warn (vdev->device,"reset driver is required and reset call failed in open (%d) %s\n" , + ret, extra_dbg ? extra_dbg :"" ); + goto err_irq;
I am afraid you need to tear down the resources allocated by vfio_platform_irq_init.
Best Regards
Eric
Quoted 5 lines
drivers/vfio/platform/vfio_platform_common.c +1
-0+ } } vdev->refcnt++;
Re: [PATCH V6 7/8] vfio: platform: check reset call return code during open
Quoted 11 lines · Auger Eric
Quoted 6 lines
drivers/vfio/platform/vfio_platform_common.c +0
-1-vfio_platform_call_reset (vdev,NULL );drivers/vfio/platform/vfio_platform_common.c static int vfio_platform_open(void *device_data) · line 281
Quoted 5 lines
drivers/vfio/platform/vfio_platform_common.c +5
-0+ ret =vfio_platform_call_reset (vdev, &extra_dbg); +if (ret && vdev->reset_required) { +dev_warn (vdev->device,"reset driver is required and reset call failed in open (%d) %s\n" , + ret, extra_dbg ? extra_dbg :"" ); + goto err_irq;I am afraid you need to tear down the resources allocated by
vfio_platform_irq_init.Best Regards
Eric
I added this to the error path and replaced the goto above with err_rst.
+err_rst:
+ vfio_platform_irq_cleanup(vdev);err_irq:
vfio_platform_regions_cleanup(vdev);
Signature · 3 lines
Sinan Kaya Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v6 8/8 vfio: platform: check reset call return code during release
In reply to Sinan KayaRelease call is ignoring the return code from reset call and can potentially continue even though reset call failed.
If reset_required module parameter is set, this patch is going to validate the return code and will cause stack dump with WARN_ON and warn the user of failure.
--- drivers/vfio/platform/vfio_platform_common.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/vfio/platform/vfio_platform_common.c +9 -1
@@ -243,7 +243,15 @@ static void vfio_platform_release(void *device_data)mutex_lock (&driver_lock);if (!(--vdev->refcnt)) { -vfio_platform_call_reset (vdev,NULL ); +const char *extra_dbg =NULL ; +int ret; + + ret =vfio_platform_call_reset (vdev, &extra_dbg); +if (ret && vdev->reset_required) { +dev_warn (vdev->device,"reset driver is required and reset call failed in release (%d) %s\n" , + ret, extra_dbg ? extra_dbg :"" ); +WARN_ON (1 ); + }vfio_platform_regions_cleanup (vdev);vfio_platform_irq_cleanup (vdev); }
Signature · 1 line
1.8.2.1
Re: [PATCH V6 8/8] vfio: platform: check reset call return code during release
Hi Sinan,
Quoted 24 lines · Sinan Kaya
Release call is ignoring the return code from reset call and can potentially continue even though reset call failed.
If
reset_requiredmodule parameter is set, this patch is going to validate the return code and will cause stack dump withWARN_ONand warn the user of failure.Signed-off-by Sinan Kaya <[email protected]>--- drivers/vfio/platform/vfio_platform_common.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/vfio/platform/vfio_platform_common.c +2
-1@@ -243,7 +243,15 @@ static void vfio_platform_release(void *device_data)mutex_lock (&driver_lock);if (!(--vdev->refcnt)) { -vfio_platform_call_reset (vdev,NULL ); +const char *extra_dbg =NULL ; +int ret;
drivers/vfio/platform/vfio_platform_common.c static void vfio_platform_release(void *device_data) · line 257
Quoted 10 lines
drivers/vfio/platform/vfio_platform_common.c +7
-0+ + ret =vfio_platform_call_reset (vdev, &extra_dbg); +if (ret && vdev->reset_required) { +dev_warn (vdev->device,"reset driver is required and reset call failed in release (%d) %s\n" , + ret, extra_dbg ? extra_dbg :"" ); +WARN_ON (1 ); + }vfio_platform_regions_cleanup (vdev);vfio_platform_irq_cleanup (vdev); }
Looks OK to me
Thanks
Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Auger Eric
maintainerHi Sinan,
Quoted 6 lines · Sinan Kaya
The device tree code checks for the presence of a reset driver and calls the
of_resetfunction pointer by looking up the reset driver as a module.ACPI defines
_RSTmethod to perform device level reset. After the_RSTmethod is executed, the OS can resume using the device.
Quoted 7 lines
This patch checks the presence of
_RSTmethod and calls the_RSTmethod when reset is requested.Changes from V5:
1. Handle reset function call failures in open and release (new patch).
2. Bring out extra debug information when failure happens (new patch).
3. Address review comments from Eric in ACPI_RSTpatch.
I think you need a respin to fix the deallocation issue in 7/8 + 1st patch missing. Afterwards I don't have any other comments at that point. I will test the dt non-regression tomorrow.
Thanks
Eric
Quoted 10 lines
Sinan Kaya (8):
vfio: platform: move reset call to a common function
vfio: platform: determine reset capability
vfio: platform: add support for ACPI probe
vfio: platform: add extra debug info argument to call reset
vfio: platform: call_RSTmethod when using ACPI vfio, platform: make reset driver a requirement by default
vfio: platform: check reset call return code during open
vfio: platform: check reset call return code during release
Quoted 6 lines
drivers/vfio/platform/vfio_amba.c | 5 + drivers/vfio/platform/vfio_platform.c | 5 + drivers/vfio/platform/vfio_platform_common.c | 169 ++++++++++++++++++++++---- drivers/vfio/platform/vfio_platform_private.h | 2 + 4 files changed, 159 insertions(+), 22 deletions(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html