From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728378AbgDQBDq (ORCPT ); Thu, 16 Apr 2020 21:03:46 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA678C0610D5 for ; Thu, 16 Apr 2020 18:03:44 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id a32so348054pje.5 for ; Thu, 16 Apr 2020 18:03:44 -0700 (PDT) From: Daniel Drake Subject: Re: [PATCH v2 00/33] iommu: Move iommu_group setup to IOMMU core code Date: Fri, 17 Apr 2020 09:03:35 +0800 Message-Id: <20200417010335.31739-1-drake@endlessm.com> In-Reply-To: <20200414131542.25608-1-joro@8bytes.org> References: <20200414131542.25608-1-joro@8bytes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-s390-owner@vger.kernel.org List-ID: To: joro@8bytes.org Cc: agross@kernel.org, baolu.lu@linux.intel.com, bjorn.andersson@linaro.org, dwmw2@infradead.org, gerald.schaefer@de.ibm.com, heiko@sntech.de, iommu@lists.linux-foundation.org, jean-philippe@linaro.org, jonathanh@nvidia.com, kgene@kernel.org, krzk@kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-tegra@vger.kernel.org, m.szyprowski@samsung.com, matthias.bgg@gmail.com, robdclark@gmail.com, robin.murphy@arm.com, thierry.reding@gmail.com, virtualization@lists.linux-foundation.org, will@kernel.org, jonathan.derrick@intel.com Hi Joerg, > Hi, > > here is the second version of this patch-set. The first version with > some more introductory text can be found here: > > https://lore.kernel.org/lkml/20200407183742.4344-1-joro@8bytes.org/ Thanks for the continued improvements in this area! I may have spotted a problem with setups like VMD. The core PCI bus is set up during early boot. Then, for the PCI bus, we reach iommu_bus_init() -> bus_iommu_probe(). In there, we call probe_iommu_group() -> dev_iommu_get() for each PCI device, which allocates dev->iommu in each case. So far so good. The problem is that this is the last time that we'll call dev_iommu_get(). If any PCI bus devices get added after this point, they do not get passed to dev_iommu_get(). So when the vmd module gets loaded later, and creates more PCI devices, we end up in iommu_bus_notifier() -> iommu_probe_device() -> __iommu_probe_device() which does: dev->iommu->iommu_dev = iommu_dev; dev->iommu-> is a NULL dereference because dev_iommu_get() was never called for this new device. Daniel