Message ID | 4-v1-5f734af130a3+34f-iommu_fwspec_jgg@nvidia.com |
---|---|
State | New |
Headers | show |
Series | Solve iommu probe races around iommu_fwspec | expand |
On Fri, Nov 03, 2023 at 01:44:49PM -0300, Jason Gunthorpe wrote: > Nothing needs this pointer. Return a normal error code with the usual > IOMMU semantic that ENODEV means 'there is no IOMMU driver'. > > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> > --- > drivers/acpi/scan.c | 24 +++++++++++++++--------- > 1 file changed, 15 insertions(+), 9 deletions(-) > ... > #else /* !CONFIG_IOMMU_API */ > @@ -1623,7 +1624,7 @@ static const struct iommu_ops *acpi_iommu_configure_id(struct device *dev, > int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr, > const u32 *input_id) > { > - const struct iommu_ops *iommu; > + int ret; > > if (attr == DEV_DMA_NOT_SUPPORTED) { > set_dma_ops(dev, &dma_dummy_ops); > @@ -1632,10 +1633,15 @@ int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr, > > acpi_arch_dma_setup(dev); > > - iommu = acpi_iommu_configure_id(dev, input_id); > - if (PTR_ERR(iommu) == -EPROBE_DEFER) > + ret = acpi_iommu_configure_id(dev, input_id); > + if (ret == -EPROBE_DEFER) > return -EPROBE_DEFER; > return ret; ? > + /* > + * Historically this routine doesn't fail driver probing due to errors > + * in acpi_iommu_configure() acpi_iommu_configure_id() > + */ > + > arch_setup_dma_ops(dev, 0, U64_MAX, attr == DEV_DMA_COHERENT); > > return 0; > -- > 2.42.0 >
On Fri, Nov 03, 2023 at 05:48:01PM -0700, Jerry Snitselaar wrote: > > @@ -1632,10 +1633,15 @@ int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr, > > > > acpi_arch_dma_setup(dev); > > > > - iommu = acpi_iommu_configure_id(dev, input_id); > > - if (PTR_ERR(iommu) == -EPROBE_DEFER) > > + ret = acpi_iommu_configure_id(dev, input_id); > > + if (ret == -EPROBE_DEFER) > > return -EPROBE_DEFER; > > > return ret; ? Maybe? Like this seemed to be a pattern in this code so I left it > > + /* > > + * Historically this routine doesn't fail driver probing due to errors > > + * in acpi_iommu_configure() > > acpi_iommu_configure_id() Thanks Jason
On Sun, Nov 05, 2023 at 09:24:09AM -0400, Jason Gunthorpe wrote: > On Fri, Nov 03, 2023 at 05:48:01PM -0700, Jerry Snitselaar wrote: > > > @@ -1632,10 +1633,15 @@ int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr, > > > > > > acpi_arch_dma_setup(dev); > > > > > > - iommu = acpi_iommu_configure_id(dev, input_id); > > > - if (PTR_ERR(iommu) == -EPROBE_DEFER) > > > + ret = acpi_iommu_configure_id(dev, input_id); > > > + if (ret == -EPROBE_DEFER) > > > return -EPROBE_DEFER; > > > > > return ret; ? > > Maybe? Like this seemed to be a pattern in this code so I left it Yeah, it is fine. I think it just caught my eye, because of this earlier bit in the patch: if (err == -EPROBE_DEFER) { - return ERR_PTR(err); + return err; which needed to get rid of the ERR_PTR. Regards, Jerry > > > > + /* > > > + * Historically this routine doesn't fail driver probing due to errors > > > + * in acpi_iommu_configure() > > > > acpi_iommu_configure_id() > > Thanks > > Jason
On Fri, Nov 3, 2023 at 5:45 PM Jason Gunthorpe <jgg@nvidia.com> wrote: > > Nothing needs this pointer. Return a normal error code with the usual > IOMMU semantic that ENODEV means 'there is no IOMMU driver'. > > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > --- > drivers/acpi/scan.c | 24 +++++++++++++++--------- > 1 file changed, 15 insertions(+), 9 deletions(-) > > diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c > index a6891ad0ceee2c..fbabde001a23a2 100644 > --- a/drivers/acpi/scan.c > +++ b/drivers/acpi/scan.c > @@ -1562,8 +1562,7 @@ static inline const struct iommu_ops *acpi_iommu_fwspec_ops(struct device *dev) > return fwspec ? fwspec->ops : NULL; > } > > -static const struct iommu_ops *acpi_iommu_configure_id(struct device *dev, > - const u32 *id_in) > +static int acpi_iommu_configure_id(struct device *dev, const u32 *id_in) > { > int err; > const struct iommu_ops *ops; > @@ -1574,7 +1573,7 @@ static const struct iommu_ops *acpi_iommu_configure_id(struct device *dev, > */ > ops = acpi_iommu_fwspec_ops(dev); > if (ops) > - return ops; > + return 0; > > err = iort_iommu_configure_id(dev, id_in); > if (err && err != -EPROBE_DEFER) > @@ -1589,12 +1588,14 @@ static const struct iommu_ops *acpi_iommu_configure_id(struct device *dev, > > /* Ignore all other errors apart from EPROBE_DEFER */ > if (err == -EPROBE_DEFER) { > - return ERR_PTR(err); > + return err; > } else if (err) { > dev_dbg(dev, "Adding to IOMMU failed: %d\n", err); > - return NULL; > + return -ENODEV; > } > - return acpi_iommu_fwspec_ops(dev); > + if (!acpi_iommu_fwspec_ops(dev)) > + return -ENODEV; > + return 0; > } > > #else /* !CONFIG_IOMMU_API */ > @@ -1623,7 +1624,7 @@ static const struct iommu_ops *acpi_iommu_configure_id(struct device *dev, > int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr, > const u32 *input_id) > { > - const struct iommu_ops *iommu; > + int ret; > > if (attr == DEV_DMA_NOT_SUPPORTED) { > set_dma_ops(dev, &dma_dummy_ops); > @@ -1632,10 +1633,15 @@ int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr, > > acpi_arch_dma_setup(dev); > > - iommu = acpi_iommu_configure_id(dev, input_id); > - if (PTR_ERR(iommu) == -EPROBE_DEFER) > + ret = acpi_iommu_configure_id(dev, input_id); > + if (ret == -EPROBE_DEFER) > return -EPROBE_DEFER; > > + /* > + * Historically this routine doesn't fail driver probing due to errors > + * in acpi_iommu_configure() > + */ > + > arch_setup_dma_ops(dev, 0, U64_MAX, attr == DEV_DMA_COHERENT); > > return 0; > -- > 2.42.0 >
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index a6891ad0ceee2c..fbabde001a23a2 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1562,8 +1562,7 @@ static inline const struct iommu_ops *acpi_iommu_fwspec_ops(struct device *dev) return fwspec ? fwspec->ops : NULL; } -static const struct iommu_ops *acpi_iommu_configure_id(struct device *dev, - const u32 *id_in) +static int acpi_iommu_configure_id(struct device *dev, const u32 *id_in) { int err; const struct iommu_ops *ops; @@ -1574,7 +1573,7 @@ static const struct iommu_ops *acpi_iommu_configure_id(struct device *dev, */ ops = acpi_iommu_fwspec_ops(dev); if (ops) - return ops; + return 0; err = iort_iommu_configure_id(dev, id_in); if (err && err != -EPROBE_DEFER) @@ -1589,12 +1588,14 @@ static const struct iommu_ops *acpi_iommu_configure_id(struct device *dev, /* Ignore all other errors apart from EPROBE_DEFER */ if (err == -EPROBE_DEFER) { - return ERR_PTR(err); + return err; } else if (err) { dev_dbg(dev, "Adding to IOMMU failed: %d\n", err); - return NULL; + return -ENODEV; } - return acpi_iommu_fwspec_ops(dev); + if (!acpi_iommu_fwspec_ops(dev)) + return -ENODEV; + return 0; } #else /* !CONFIG_IOMMU_API */ @@ -1623,7 +1624,7 @@ static const struct iommu_ops *acpi_iommu_configure_id(struct device *dev, int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr, const u32 *input_id) { - const struct iommu_ops *iommu; + int ret; if (attr == DEV_DMA_NOT_SUPPORTED) { set_dma_ops(dev, &dma_dummy_ops); @@ -1632,10 +1633,15 @@ int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr, acpi_arch_dma_setup(dev); - iommu = acpi_iommu_configure_id(dev, input_id); - if (PTR_ERR(iommu) == -EPROBE_DEFER) + ret = acpi_iommu_configure_id(dev, input_id); + if (ret == -EPROBE_DEFER) return -EPROBE_DEFER; + /* + * Historically this routine doesn't fail driver probing due to errors + * in acpi_iommu_configure() + */ + arch_setup_dma_ops(dev, 0, U64_MAX, attr == DEV_DMA_COHERENT); return 0;
Nothing needs this pointer. Return a normal error code with the usual IOMMU semantic that ENODEV means 'there is no IOMMU driver'. Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> --- drivers/acpi/scan.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)