2023-02-08 15:40:15

by Oleksandr Tyshchenko

[permalink] [raw]
Subject: [PATCH] xen/grant-dma-iommu: Implement a dummy probe_device() callback

From: Oleksandr Tyshchenko <[email protected]>

Update stub IOMMU driver (which main purpose is to reuse generic
IOMMU device-tree bindings by Xen grant DMA-mapping layer on Arm)
according to the recent changes done in the following
commit 57365a04c921 ("iommu: Move bus setup to IOMMU device registration").

With probe_device() callback being called during IOMMU device registration,
the uninitialized callback just leads to the "kernel NULL pointer
dereference" issue during boot. Fix that by adding a dummy callback.

Looks like the release_device() callback is not mandatory to be
implemented as IOMMU framework makes sure that callback is initialized
before dereferencing.

Reported-by: Viresh Kumar <[email protected]>
Signed-off-by: Oleksandr Tyshchenko <[email protected]>
---
drivers/xen/grant-dma-iommu.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/xen/grant-dma-iommu.c b/drivers/xen/grant-dma-iommu.c
index 16b8bc0c0b33..6a9fe02c6bfc 100644
--- a/drivers/xen/grant-dma-iommu.c
+++ b/drivers/xen/grant-dma-iommu.c
@@ -16,8 +16,15 @@ struct grant_dma_iommu_device {
struct iommu_device iommu;
};

-/* Nothing is really needed here */
-static const struct iommu_ops grant_dma_iommu_ops;
+static struct iommu_device *grant_dma_iommu_probe_device(struct device *dev)
+{
+ return ERR_PTR(-ENODEV);
+}
+
+/* Nothing is really needed here except a dummy probe_device callback */
+static const struct iommu_ops grant_dma_iommu_ops = {
+ .probe_device = grant_dma_iommu_probe_device,
+};

static const struct of_device_id grant_dma_iommu_of_match[] = {
{ .compatible = "xen,grant-dma" },
--
2.34.1



2023-02-09 05:54:19

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH] xen/grant-dma-iommu: Implement a dummy probe_device() callback

On 08-02-23, 17:36, Oleksandr Tyshchenko wrote:
> From: Oleksandr Tyshchenko <[email protected]>
>
> Update stub IOMMU driver (which main purpose is to reuse generic
> IOMMU device-tree bindings by Xen grant DMA-mapping layer on Arm)
> according to the recent changes done in the following
> commit 57365a04c921 ("iommu: Move bus setup to IOMMU device registration").
>
> With probe_device() callback being called during IOMMU device registration,
> the uninitialized callback just leads to the "kernel NULL pointer
> dereference" issue during boot. Fix that by adding a dummy callback.
>
> Looks like the release_device() callback is not mandatory to be
> implemented as IOMMU framework makes sure that callback is initialized
> before dereferencing.
>
> Reported-by: Viresh Kumar <[email protected]>
> Signed-off-by: Oleksandr Tyshchenko <[email protected]>
> ---
> drivers/xen/grant-dma-iommu.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)

Tested-by: Viresh Kumar <[email protected]>

--
viresh

2023-02-10 23:34:08

by Stefano Stabellini

[permalink] [raw]
Subject: Re: [PATCH] xen/grant-dma-iommu: Implement a dummy probe_device() callback

On Wed, 8 Feb 2023, Oleksandr Tyshchenko wrote:
> From: Oleksandr Tyshchenko <[email protected]>
>
> Update stub IOMMU driver (which main purpose is to reuse generic
> IOMMU device-tree bindings by Xen grant DMA-mapping layer on Arm)
> according to the recent changes done in the following
> commit 57365a04c921 ("iommu: Move bus setup to IOMMU device registration").
>
> With probe_device() callback being called during IOMMU device registration,
> the uninitialized callback just leads to the "kernel NULL pointer
> dereference" issue during boot. Fix that by adding a dummy callback.
>
> Looks like the release_device() callback is not mandatory to be
> implemented as IOMMU framework makes sure that callback is initialized
> before dereferencing.
>
> Reported-by: Viresh Kumar <[email protected]>
> Signed-off-by: Oleksandr Tyshchenko <[email protected]>

Reviewed-by: Stefano Stabellini <[email protected]>


> ---
> drivers/xen/grant-dma-iommu.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/xen/grant-dma-iommu.c b/drivers/xen/grant-dma-iommu.c
> index 16b8bc0c0b33..6a9fe02c6bfc 100644
> --- a/drivers/xen/grant-dma-iommu.c
> +++ b/drivers/xen/grant-dma-iommu.c
> @@ -16,8 +16,15 @@ struct grant_dma_iommu_device {
> struct iommu_device iommu;
> };
>
> -/* Nothing is really needed here */
> -static const struct iommu_ops grant_dma_iommu_ops;
> +static struct iommu_device *grant_dma_iommu_probe_device(struct device *dev)
> +{
> + return ERR_PTR(-ENODEV);
> +}
> +
> +/* Nothing is really needed here except a dummy probe_device callback */
> +static const struct iommu_ops grant_dma_iommu_ops = {
> + .probe_device = grant_dma_iommu_probe_device,
> +};
>
> static const struct of_device_id grant_dma_iommu_of_match[] = {
> { .compatible = "xen,grant-dma" },
> --
> 2.34.1
>

2023-02-13 08:20:18

by Juergen Gross

[permalink] [raw]
Subject: Re: [PATCH] xen/grant-dma-iommu: Implement a dummy probe_device() callback

On 08.02.23 16:36, Oleksandr Tyshchenko wrote:
> From: Oleksandr Tyshchenko <[email protected]>
>
> Update stub IOMMU driver (which main purpose is to reuse generic
> IOMMU device-tree bindings by Xen grant DMA-mapping layer on Arm)
> according to the recent changes done in the following
> commit 57365a04c921 ("iommu: Move bus setup to IOMMU device registration").
>
> With probe_device() callback being called during IOMMU device registration,
> the uninitialized callback just leads to the "kernel NULL pointer
> dereference" issue during boot. Fix that by adding a dummy callback.
>
> Looks like the release_device() callback is not mandatory to be
> implemented as IOMMU framework makes sure that callback is initialized
> before dereferencing.
>
> Reported-by: Viresh Kumar <[email protected]>
> Signed-off-by: Oleksandr Tyshchenko <[email protected]>

Pushed-to: xen/tip.git for-linus-6.3


Juergen


Attachments:
OpenPGP_0xB0DE9DD628BF132F.asc (3.03 kB)
OpenPGP public key
OpenPGP_signature (495.00 B)
OpenPGP digital signature
Download all attachments