iommu: Check for deferred attach in iommu_group_do_dma_attach()
Joerg Roedel
maintainerPATCH 1/1 iommu: Check for deferred attach in iommu_group_do_dma_attach()
From: Joerg Roedel <[email protected]>
The iommu_group_do_dma_attach() must not attach devices which have deferred_attach set. Otherwise devices could cause IOMMU faults when re-initialized in a kdump kernel.
--- drivers/iommu/iommu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iommu/iommu.c +5 -1
@@ -1680,8 +1680,12 @@ static void probe_alloc_default_domain(struct bus_type *bus,static int iommu_group_do_dma_attach (struct device *dev,void *data) {struct iommu_domain *domain = data; +int ret =0 ; -return __iommu_attach_device (domain, dev); +if (!iommu_is_attach_deferred (group->domain, dev)) + ret =__iommu_attach_device (group->domain, dev); + +return ret; }static int __iommu_group_dma_attach (struct iommu_group *group)
Signature · 1 line
2.26.2
Joerg Roedel
maintainerQuoted 20 lines · Joerg Roedel
From: Joerg Roedel <[email protected]>
The
iommu_group_do_dma_attach()must not attach devices which havedeferred_attachset. Otherwise devices could cause IOMMU faults when re-initialized in a kdump kernel.Fixes deac0b3bed26 ("iommu: Split off default domain allocation from group assignment")Reported-by Jerry Snitselaar <[email protected]>Reviewed-by Jerry Snitselaar <[email protected]>Tested-by Jerry Snitselaar <[email protected]>Signed-off-by Joerg Roedel <[email protected]>--- drivers/iommu/iommu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/iommu/iommu.c +0
-0
drivers/iommu/iommu.c static void probe_alloc_default_domain(struct bus_type *bus, · line 1686
Quoted 8 lines
drivers/iommu/iommu.c +3
-1@@ -1680,8 +1680,12 @@ static void probe_alloc_default_domain(struct bus_type *bus,static int iommu_group_do_dma_attach (struct device *dev,void *data) {struct iommu_domain *domain = data; +int ret =0 ; -return __iommu_attach_device (domain, dev); +if (!iommu_is_attach_deferred (group->domain, dev)) + ret =__iommu_attach_device (group->domain, dev);
And of course with the same bug as my original diff. Fixed that up before applying it. (group->domain -> domain).
Joerg
kernel test robot
build botI love your patch! Yet something to improve:
Hi Joerg,
I love your patch! Yet something to improve:
[auto build test ERROR on iommu/next]
[also build test ERROR on next-20200604]
[cannot apply to v5.7]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Joerg-Roedel/iommu-Check-for-deferred-attach-in-iommu_group_do_dma_attach/20200604-172315 base: https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next config: arm-randconfig-s032-20200604 (attached as .config) compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.1-244-g0ee050a8-dirty # save the attached .config to linux build tree make W=1 C=1 ARCH=arm CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>, old ones prefixed by <<):
drivers/iommu/iommu.c:386:5: warning: no previous prototype for 'iommu_insert_resv_region' [-Wmissing-prototypes] 386 | int iommu_insert_resv_region(struct iommu_resv_region *new,
| ^~~~~~~~~~~~~~~~~~~~~~~~drivers/iommu/iommu.c: In function 'iommu_group_do_dma_attach':
>> drivers/iommu/iommu.c:1685:32: error: 'group' undeclared (first use in this function); did you mean 'cgroup'? 1685 | if (!iommu_is_attach_deferred(group->domain, dev)) | ^~~~~ | cgroup
drivers/iommu/iommu.c:1685:32: note: each undeclared identifier is reported only once for each function it appears in drivers/iommu/iommu.c:1682:23: warning: unused variable 'domain' [-Wunused-variable]
1682 | struct iommu_domain *domain = data;
| ^~~~~~drivers/iommu/iommu.c: At top level:drivers/iommu/iommu.c:2171:5: warning: no previous prototype for '__iommu_map' [-Wmissing-prototypes] 2171 | int __iommu_map(struct iommu_domain *domain, unsigned long iova,
| ^~~~~~~~~~~drivers/iommu/iommu.c:2322:8: warning: no previous prototype for '__iommu_map_sg' [-Wmissing-prototypes] 2322 | size_t __iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
| ^~~~~~~~~~~~~~
vim +1685 drivers/iommu/iommu.c
1679
1680 static int iommu_group_do_dma_attach(struct device *dev, void *data)
1681 {
1682 struct iommu_domain *domain = data;
1683 int ret = 0;
1684
> 1685 if (!iommu_is_attach_deferred(group->domain, dev))
1686 ret = __iommu_attach_device(group->domain, dev);
1687
1688 return ret;
1689 }
1690
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botI love your patch! Perhaps something to improve:
Hi Joerg,
I love your patch! Perhaps something to improve:
[auto build test WARNING on iommu/next]
[also build test WARNING on next-20200604]
[cannot apply to v5.7]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Joerg-Roedel/iommu-Check-for-deferred-attach-in-iommu_group_do_dma_attach/20200604-172315 base: https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next config: s390-randconfig-m031-20200604 (attached as .config) compiler: s390-linux-gcc (GCC) 9.3.0
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>, old ones prefixed by <<):
drivers/iommu/iommu.c:386:5: warning: no previous prototype for 'iommu_insert_resv_region' [-Wmissing-prototypes] 386 | int iommu_insert_resv_region(struct iommu_resv_region *new,
| ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from include/linux/dev_printk.h:14,
from include/linux/device.h:15,
from drivers/iommu/iommu.c:9:drivers/iommu/iommu.c: In function 'iommu_group_do_dma_attach':drivers/iommu/iommu.c:1685:32: error: 'group' undeclared (first use in this function); did you mean 'cgroup'? 1685 | if (!iommu_is_attach_deferred(group->domain, dev))
| ^~~~~include/linux/compiler.h:58:52: note: in definition of macro '__trace_if_var'
58 | #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
| ^~~~
>> drivers/iommu/iommu.c:1685:2: note: in expansion of macro 'if'
1685 | if (!iommu_is_attach_deferred(group->domain, dev))
| ^~drivers/iommu/iommu.c:1685:32: note: each undeclared identifier is reported only once for each function it appears in 1685 | if (!iommu_is_attach_deferred(group->domain, dev))
| ^~~~~include/linux/compiler.h:58:52: note: in definition of macro '__trace_if_var'
58 | #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
| ^~~~
>> drivers/iommu/iommu.c:1685:2: note: in expansion of macro 'if'
1685 | if (!iommu_is_attach_deferred(group->domain, dev))
| ^~drivers/iommu/iommu.c:1682:23: warning: unused variable 'domain' [-Wunused-variable] 1682 | struct iommu_domain *domain = data;
| ^~~~~~drivers/iommu/iommu.c: At top level:drivers/iommu/iommu.c:2171:5: warning: no previous prototype for '__iommu_map' [-Wmissing-prototypes] 2171 | int __iommu_map(struct iommu_domain *domain, unsigned long iova,
| ^~~~~~~~~~~drivers/iommu/iommu.c:2322:8: warning: no previous prototype for '__iommu_map_sg' [-Wmissing-prototypes] 2322 | size_t __iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
| ^~~~~~~~~~~~~~
vim +/if +1685 drivers/iommu/iommu.c
1679
1680 static int iommu_group_do_dma_attach(struct device *dev, void *data)
1681 {
1682 struct iommu_domain *domain = data;
1683 int ret = 0;
1684
> 1685 if (!iommu_is_attach_deferred(group->domain, dev))
1686 ret = __iommu_attach_device(group->domain, dev);
1687
1688 return ret;
1689 }
1690
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org