All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 5/5] vfio/iommu_type1: Simplify group attachment
  2022-06-06  6:19   ` Nicolin Chen via iommu
@ 2022-06-13 13:42 ` Dan Carpenter
  -1 siblings, 0 replies; 138+ messages in thread
From: kernel test robot @ 2022-06-10 16:39 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 8261 bytes --]

CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
In-Reply-To: <20220606061927.26049-6-nicolinc@nvidia.com>
References: <20220606061927.26049-6-nicolinc@nvidia.com>
TO: Nicolin Chen <nicolinc@nvidia.com>
TO: jgg(a)nvidia.com
TO: joro(a)8bytes.org
TO: will(a)kernel.org
TO: marcan(a)marcan.st
TO: sven(a)svenpeter.dev
TO: robin.murphy(a)arm.com
TO: robdclark(a)gmail.com
TO: m.szyprowski(a)samsung.com
TO: krzysztof.kozlowski(a)linaro.org
TO: baolu.lu(a)linux.intel.com
TO: agross(a)kernel.org
TO: bjorn.andersson(a)linaro.org
TO: matthias.bgg(a)gmail.com
TO: heiko(a)sntech.de
TO: orsonzhai(a)gmail.com
TO: baolin.wang7(a)gmail.com
TO: zhang.lyra(a)gmail.com
TO: wens(a)csie.org
TO: jernej.skrabec(a)gmail.com
TO: samuel(a)sholland.org
TO: jean-philippe(a)linaro.org
TO: alex.williamson(a)redhat.com
CC: suravee.suthikulpanit(a)amd.com
CC: alyssa(a)rosenzweig.io
CC: alim.akhtar(a)samsung.com
CC: dwmw2(a)infradead.org
CC: yong.wu(a)mediatek.com
CC: mjrosato(a)linux.ibm.com
CC: gerald.schaefer(a)linux.ibm.com
CC: thierry.reding(a)gmail.com

Hi Nicolin,

I love your patch! Perhaps something to improve:

[auto build test WARNING on joro-iommu/next]
[also build test WARNING on tegra/for-next v5.19-rc1 next-20220610]
[cannot apply to awilliam-vfio/next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Nicolin-Chen/Simplify-vfio_iommu_type1-attach-detach-routine/20220606-143004
base:   https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next
:::::: branch date: 4 days ago
:::::: commit date: 4 days ago
config: i386-randconfig-m021 (https://download.01.org/0day-ci/archive/20220611/202206110041.8CaoeVuj-lkp(a)intel.com/config)
compiler: gcc-11 (Debian 11.3.0-3) 11.3.0

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/vfio/vfio_iommu_type1.c:2229 vfio_iommu_alloc_attach_domain() error: we previously assumed 'domain' could be null (see line 2191)
drivers/vfio/vfio_iommu_type1.c:2229 vfio_iommu_alloc_attach_domain() error: dereferencing freed memory 'domain'

vim +/domain +2229 drivers/vfio/vfio_iommu_type1.c

572f64c71e0fe3 Zenghui Yu   2020-10-22  2156  
c1a4076891cf18 Nicolin Chen 2022-06-05  2157  static struct vfio_domain *
c1a4076891cf18 Nicolin Chen 2022-06-05  2158  vfio_iommu_alloc_attach_domain(struct bus_type *bus, struct vfio_iommu *iommu,
c1a4076891cf18 Nicolin Chen 2022-06-05  2159  			       struct vfio_iommu_group *group)
c1a4076891cf18 Nicolin Chen 2022-06-05  2160  {
c1a4076891cf18 Nicolin Chen 2022-06-05  2161  	struct iommu_domain *new_domain;
c1a4076891cf18 Nicolin Chen 2022-06-05  2162  	struct vfio_domain *domain;
c1a4076891cf18 Nicolin Chen 2022-06-05  2163  	int ret = 0;
c1a4076891cf18 Nicolin Chen 2022-06-05  2164  
c1a4076891cf18 Nicolin Chen 2022-06-05  2165  	/* Try to match an existing compatible domain */
c1a4076891cf18 Nicolin Chen 2022-06-05  2166  	list_for_each_entry (domain, &iommu->domain_list, next) {
c1a4076891cf18 Nicolin Chen 2022-06-05  2167  		ret = iommu_attach_group(domain->domain, group->iommu_group);
c1a4076891cf18 Nicolin Chen 2022-06-05  2168  		if (ret == -EMEDIUMTYPE)
c1a4076891cf18 Nicolin Chen 2022-06-05  2169  			continue;
c1a4076891cf18 Nicolin Chen 2022-06-05  2170  		if (ret)
c1a4076891cf18 Nicolin Chen 2022-06-05  2171  			return ERR_PTR(ret);
c1a4076891cf18 Nicolin Chen 2022-06-05  2172  		list_add(&group->next, &domain->group_list);
c1a4076891cf18 Nicolin Chen 2022-06-05  2173  		return domain;
c1a4076891cf18 Nicolin Chen 2022-06-05  2174  	}
c1a4076891cf18 Nicolin Chen 2022-06-05  2175  
c1a4076891cf18 Nicolin Chen 2022-06-05  2176  	new_domain = iommu_domain_alloc(bus);
c1a4076891cf18 Nicolin Chen 2022-06-05  2177  	if (!new_domain)
c1a4076891cf18 Nicolin Chen 2022-06-05  2178  		return ERR_PTR(-EIO);
c1a4076891cf18 Nicolin Chen 2022-06-05  2179  
c1a4076891cf18 Nicolin Chen 2022-06-05  2180  	if (iommu->nesting) {
c1a4076891cf18 Nicolin Chen 2022-06-05  2181  		ret = iommu_enable_nesting(new_domain);
c1a4076891cf18 Nicolin Chen 2022-06-05  2182  		if (ret)
c1a4076891cf18 Nicolin Chen 2022-06-05  2183  			goto out_free_iommu_domain;
c1a4076891cf18 Nicolin Chen 2022-06-05  2184  	}
c1a4076891cf18 Nicolin Chen 2022-06-05  2185  
c1a4076891cf18 Nicolin Chen 2022-06-05  2186  	ret = iommu_attach_group(new_domain, group->iommu_group);
c1a4076891cf18 Nicolin Chen 2022-06-05  2187  	if (ret)
c1a4076891cf18 Nicolin Chen 2022-06-05  2188  		goto out_free_iommu_domain;
c1a4076891cf18 Nicolin Chen 2022-06-05  2189  
c1a4076891cf18 Nicolin Chen 2022-06-05  2190  	domain = kzalloc(sizeof(*domain), GFP_KERNEL);
c1a4076891cf18 Nicolin Chen 2022-06-05 @2191  	if (!domain) {
c1a4076891cf18 Nicolin Chen 2022-06-05  2192  		ret = -ENOMEM;
c1a4076891cf18 Nicolin Chen 2022-06-05  2193  		goto out_detach;
c1a4076891cf18 Nicolin Chen 2022-06-05  2194  	}
c1a4076891cf18 Nicolin Chen 2022-06-05  2195  
c1a4076891cf18 Nicolin Chen 2022-06-05  2196  	domain->domain = new_domain;
c1a4076891cf18 Nicolin Chen 2022-06-05  2197  	vfio_test_domain_fgsp(domain);
c1a4076891cf18 Nicolin Chen 2022-06-05  2198  
c1a4076891cf18 Nicolin Chen 2022-06-05  2199  	/*
c1a4076891cf18 Nicolin Chen 2022-06-05  2200  	 * If the IOMMU can block non-coherent operations (ie PCIe TLPs with
c1a4076891cf18 Nicolin Chen 2022-06-05  2201  	 * no-snoop set) then VFIO always turns this feature on because on Intel
c1a4076891cf18 Nicolin Chen 2022-06-05  2202  	 * platforms it optimizes KVM to disable wbinvd emulation.
c1a4076891cf18 Nicolin Chen 2022-06-05  2203  	 */
c1a4076891cf18 Nicolin Chen 2022-06-05  2204  	if (new_domain->ops->enforce_cache_coherency)
c1a4076891cf18 Nicolin Chen 2022-06-05  2205  		domain->enforce_cache_coherency =
c1a4076891cf18 Nicolin Chen 2022-06-05  2206  			new_domain->ops->enforce_cache_coherency(new_domain);
c1a4076891cf18 Nicolin Chen 2022-06-05  2207  
c1a4076891cf18 Nicolin Chen 2022-06-05  2208  	/* replay mappings on new domains */
c1a4076891cf18 Nicolin Chen 2022-06-05  2209  	ret = vfio_iommu_replay(iommu, domain);
c1a4076891cf18 Nicolin Chen 2022-06-05  2210  	if (ret)
c1a4076891cf18 Nicolin Chen 2022-06-05  2211  		goto out_free_domain;
c1a4076891cf18 Nicolin Chen 2022-06-05  2212  
c1a4076891cf18 Nicolin Chen 2022-06-05  2213  	/*
c1a4076891cf18 Nicolin Chen 2022-06-05  2214  	 * An iommu backed group can dirty memory directly and therefore
c1a4076891cf18 Nicolin Chen 2022-06-05  2215  	 * demotes the iommu scope until it declares itself dirty tracking
c1a4076891cf18 Nicolin Chen 2022-06-05  2216  	 * capable via the page pinning interface.
c1a4076891cf18 Nicolin Chen 2022-06-05  2217  	 */
c1a4076891cf18 Nicolin Chen 2022-06-05  2218  	iommu->num_non_pinned_groups++;
c1a4076891cf18 Nicolin Chen 2022-06-05  2219  
c1a4076891cf18 Nicolin Chen 2022-06-05  2220  	INIT_LIST_HEAD(&domain->group_list);
c1a4076891cf18 Nicolin Chen 2022-06-05  2221  	list_add(&group->next, &domain->group_list);
c1a4076891cf18 Nicolin Chen 2022-06-05  2222  	list_add(&domain->next, &iommu->domain_list);
c1a4076891cf18 Nicolin Chen 2022-06-05  2223  	vfio_update_pgsize_bitmap(iommu);
c1a4076891cf18 Nicolin Chen 2022-06-05  2224  	return domain;
c1a4076891cf18 Nicolin Chen 2022-06-05  2225  
c1a4076891cf18 Nicolin Chen 2022-06-05  2226  out_free_domain:
c1a4076891cf18 Nicolin Chen 2022-06-05  2227  	kfree(domain);
c1a4076891cf18 Nicolin Chen 2022-06-05  2228  out_detach:
c1a4076891cf18 Nicolin Chen 2022-06-05 @2229  	iommu_detach_group(domain->domain, group->iommu_group);
c1a4076891cf18 Nicolin Chen 2022-06-05  2230  out_free_iommu_domain:
c1a4076891cf18 Nicolin Chen 2022-06-05  2231  	iommu_domain_free(new_domain);
c1a4076891cf18 Nicolin Chen 2022-06-05  2232  	return ERR_PTR(ret);
c1a4076891cf18 Nicolin Chen 2022-06-05  2233  }
c1a4076891cf18 Nicolin Chen 2022-06-05  2234  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 138+ messages in thread
* [PATCH 0/5] Simplify vfio_iommu_type1 attach/detach routine
@ 2022-06-06  6:19 ` Nicolin Chen
  0 siblings, 0 replies; 138+ messages in thread
From: Nicolin Chen @ 2022-06-06  6:19 UTC (permalink / raw)
  To: jgg, joro, will, marcan, sven, robin.murphy, robdclark,
	m.szyprowski, krzysztof.kozlowski, baolu.lu, agross,
	bjorn.andersson, matthias.bgg, heiko, orsonzhai, baolin.wang7,
	zhang.lyra, wens, jernej.skrabec, samuel, jean-philippe,
	alex.williamson
  Cc: suravee.suthikulpanit, alyssa, alim.akhtar, dwmw2, yong.wu,
	mjrosato, gerald.schaefer, thierry.reding, vdumpa, jonathanh,
	cohuck, iommu, linux-kernel, linux-arm-kernel, linux-arm-msm,
	linux-samsung-soc, linux-mediatek, linux-rockchip, linux-s390,
	linux-sunxi, linux-tegra, virtualization, kvm

This is a preparatory series for IOMMUFD v2 patches. It enforces error
code -EMEDIUMTYPE in iommu_attach_device() and iommu_attach_group() when
an IOMMU domain and a device/group are incompatible. It also moves the
domain->ops check into __iommu_attach_device(). These allow VFIO iommu
code to simplify its group attachment routine, by avoiding the extra
IOMMU domain allocations and attach/detach sequences of the old code.

Worths mentioning the exact match for enforce_cache_coherency is removed
with this series, since there's very less value in doing that since KVM
won't be able to take advantage of it -- this just wastes domain memory.
Instead, we rely on Intel IOMMU driver taking care of that internally.

This is on github: https://github.com/nicolinc/iommufd/commits/vfio_iommu_attach

Jason Gunthorpe (1):
  vfio/iommu_type1: Prefer to reuse domains vs match enforced cache
    coherency

Nicolin Chen (4):
  iommu: Return -EMEDIUMTYPE for incompatible domain and device/group
  iommu: Ensure device has the same iommu_ops as the domain
  vfio/iommu_type1: Clean up update_dirty_scope in detach_group()
  vfio/iommu_type1: Simplify group attachment

 drivers/iommu/amd/iommu.c                   |   3 +-
 drivers/iommu/apple-dart.c                  |   5 +-
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c |   7 +-
 drivers/iommu/arm/arm-smmu/arm-smmu.c       |   1 +
 drivers/iommu/arm/arm-smmu/qcom_iommu.c     |   3 +-
 drivers/iommu/exynos-iommu.c                |   1 +
 drivers/iommu/fsl_pamu_domain.c             |   1 +
 drivers/iommu/intel/iommu.c                 |   5 +-
 drivers/iommu/iommu.c                       |  26 ++
 drivers/iommu/ipmmu-vmsa.c                  |   3 +-
 drivers/iommu/msm_iommu.c                   |   1 +
 drivers/iommu/mtk_iommu.c                   |   1 +
 drivers/iommu/mtk_iommu_v1.c                |   1 +
 drivers/iommu/omap-iommu.c                  |   3 +-
 drivers/iommu/rockchip-iommu.c              |   1 +
 drivers/iommu/s390-iommu.c                  |   1 +
 drivers/iommu/sprd-iommu.c                  |   1 +
 drivers/iommu/sun50i-iommu.c                |   1 +
 drivers/iommu/tegra-gart.c                  |   1 +
 drivers/iommu/tegra-smmu.c                  |   1 +
 drivers/iommu/virtio-iommu.c                |   3 +-
 drivers/vfio/vfio_iommu_type1.c             | 315 ++++++++++----------
 include/linux/iommu.h                       |   2 +
 23 files changed, 223 insertions(+), 164 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 138+ messages in thread

end of thread, other threads:[~2022-06-15 23:13 UTC | newest]

Thread overview: 138+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-10 16:39 [PATCH 5/5] vfio/iommu_type1: Simplify group attachment kernel test robot
2022-06-13 13:42 ` Dan Carpenter
  -- strict thread matches above, loose matches on Subject: below --
2022-06-06  6:19 [PATCH 0/5] Simplify vfio_iommu_type1 attach/detach routine Nicolin Chen
2022-06-06  6:19 ` Nicolin Chen
2022-06-06  6:19 ` Nicolin Chen
2022-06-06  6:19 ` Nicolin Chen via iommu
2022-06-06  6:19 ` Nicolin Chen
2022-06-06  6:19 ` [PATCH 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen via iommu
2022-06-06  6:19   ` Nicolin Chen
2022-06-07  3:23   ` Baolu Lu
2022-06-07  3:23     ` Baolu Lu
2022-06-07  3:23     ` Baolu Lu
2022-06-07  3:23     ` Baolu Lu
2022-06-07  3:23     ` Baolu Lu
2022-06-07  4:03     ` Nicolin Chen
2022-06-07  4:03       ` Nicolin Chen
2022-06-07  4:03       ` Nicolin Chen
2022-06-07  4:03       ` Nicolin Chen via iommu
2022-06-07  4:03       ` Nicolin Chen
2022-06-08  7:49   ` Tian, Kevin
2022-06-08  7:49     ` Tian, Kevin
2022-06-08  7:49     ` Tian, Kevin
2022-06-08  7:49     ` Tian, Kevin
2022-06-08  7:49     ` Tian, Kevin
2022-06-08  7:49     ` Tian, Kevin
2022-06-08 17:38     ` Nicolin Chen
2022-06-08 17:38       ` Nicolin Chen
2022-06-08 17:38       ` Nicolin Chen
2022-06-08 17:38       ` Nicolin Chen
2022-06-08 17:38       ` Nicolin Chen via iommu
2022-06-06  6:19 ` [PATCH 2/5] iommu: Ensure device has the same iommu_ops as the domain Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen via iommu
2022-06-06 14:33   ` Robin Murphy
2022-06-06 14:33     ` Robin Murphy
2022-06-06 14:33     ` Robin Murphy
2022-06-06 14:33     ` Robin Murphy
2022-06-06 14:33     ` Robin Murphy
2022-06-06 14:33     ` Robin Murphy
2022-06-06 16:51     ` Nicolin Chen
2022-06-06 16:51       ` Nicolin Chen
2022-06-06 16:51       ` Nicolin Chen
2022-06-06 16:51       ` Nicolin Chen
2022-06-06 16:51       ` Nicolin Chen via iommu
2022-06-06 17:50       ` Robin Murphy
2022-06-06 17:50         ` Robin Murphy
2022-06-06 17:50         ` Robin Murphy
2022-06-06 17:50         ` Robin Murphy
2022-06-06 17:50         ` Robin Murphy
2022-06-06 17:50         ` Robin Murphy
2022-06-06 18:28         ` Nicolin Chen
2022-06-06 18:28           ` Nicolin Chen
2022-06-06 18:28           ` Nicolin Chen
2022-06-06 18:28           ` Nicolin Chen via iommu
2022-06-06 18:28           ` Nicolin Chen
2022-06-06 18:52           ` Jason Gunthorpe
2022-06-06 18:52             ` Jason Gunthorpe
2022-06-06 18:52             ` Jason Gunthorpe
2022-06-06 18:52             ` Jason Gunthorpe
2022-06-06 18:52             ` Jason Gunthorpe via iommu
2022-06-06  6:19 ` [PATCH 3/5] vfio/iommu_type1: Prefer to reuse domains vs match enforced cache coherency Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen via iommu
2022-06-08  8:28   ` Tian, Kevin
2022-06-08  8:28     ` Tian, Kevin
2022-06-08  8:28     ` Tian, Kevin
2022-06-08  8:28     ` Tian, Kevin
2022-06-08  8:28     ` Tian, Kevin
2022-06-08  8:28     ` Tian, Kevin
2022-06-08 11:17     ` Jason Gunthorpe
2022-06-08 11:17       ` Jason Gunthorpe
2022-06-08 11:17       ` Jason Gunthorpe
2022-06-08 11:17       ` Jason Gunthorpe via iommu
2022-06-08 11:17       ` Jason Gunthorpe
2022-06-08 23:48       ` Tian, Kevin
2022-06-08 23:48         ` Tian, Kevin
2022-06-08 23:48         ` Tian, Kevin
2022-06-08 23:48         ` Tian, Kevin
2022-06-08 23:48         ` Tian, Kevin
2022-06-08 23:48         ` Tian, Kevin
2022-06-14 20:45         ` Nicolin Chen
2022-06-14 20:45           ` Nicolin Chen
2022-06-14 20:45           ` Nicolin Chen
2022-06-14 20:45           ` Nicolin Chen via iommu
2022-06-14 20:45           ` Nicolin Chen
2022-06-15  7:35           ` Tian, Kevin
2022-06-15  7:35             ` Tian, Kevin
2022-06-15  7:35             ` Tian, Kevin
2022-06-15  7:35             ` Tian, Kevin
2022-06-15  7:35             ` Tian, Kevin
2022-06-15  7:35             ` Tian, Kevin
2022-06-15 23:12             ` Nicolin Chen
2022-06-15 23:12               ` Nicolin Chen
2022-06-15 23:12               ` Nicolin Chen via iommu
2022-06-15 23:12               ` Nicolin Chen
2022-06-06  6:19 ` [PATCH 4/5] vfio/iommu_type1: Clean up update_dirty_scope in detach_group() Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen via iommu
2022-06-08  8:35   ` Tian, Kevin
2022-06-08  8:35     ` Tian, Kevin
2022-06-08  8:35     ` Tian, Kevin
2022-06-08  8:35     ` Tian, Kevin
2022-06-08  8:35     ` Tian, Kevin
2022-06-08  8:35     ` Tian, Kevin
2022-06-08 17:46     ` Nicolin Chen
2022-06-08 17:46       ` Nicolin Chen
2022-06-08 17:46       ` Nicolin Chen
2022-06-08 17:46       ` Nicolin Chen
2022-06-08 17:46       ` Nicolin Chen via iommu
2022-06-06  6:19 ` [PATCH 5/5] vfio/iommu_type1: Simplify group attachment Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen
2022-06-06  6:19   ` Nicolin Chen via iommu
2022-06-07  7:44 ` [PATCH 0/5] Simplify vfio_iommu_type1 attach/detach routine Baolu Lu
2022-06-07  7:44   ` Baolu Lu
2022-06-07  7:44   ` Baolu Lu
2022-06-07  7:44   ` Baolu Lu
2022-06-07  7:44   ` Baolu Lu
2022-06-07 11:58   ` Jason Gunthorpe
2022-06-07 11:58     ` Jason Gunthorpe
2022-06-07 11:58     ` Jason Gunthorpe
2022-06-07 11:58     ` Jason Gunthorpe
2022-06-07 11:58     ` Jason Gunthorpe via iommu
2022-06-07 12:42     ` Baolu Lu
2022-06-07 12:42       ` Baolu Lu
2022-06-07 12:42       ` Baolu Lu
2022-06-07 12:42       ` Baolu Lu
2022-06-07 12:42       ` Baolu Lu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.