Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3435229pxp; Tue, 8 Mar 2022 14:27:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJx2mZ7Uc0RZ13xDe9b5BaGMlKW0h9FK7lJTQji4q+a52j9QxCfJZt7cXYhYbo8+nNroLS5E X-Received: by 2002:a05:6402:26d0:b0:416:7165:269a with SMTP id x16-20020a05640226d000b004167165269amr4707977edd.61.1646778456389; Tue, 08 Mar 2022 14:27:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646778456; cv=none; d=google.com; s=arc-20160816; b=RviGS8W/OzH++XnvKR5e6/nuQTg623Z/2QZugOCYmuPPF3kI6HuA5lNWMJhycMjgxT VNoKeRJ6masaz5MGrlVZsq8/gzuMN9TBmr62QguR1UUDmG4PzsbDaPpV6hYKfdrUTSGP 0/E0Mg+etT227GMX+vyjogPGf4DZL3AHptJDrix8LZsCTp0gJY4wEvv/t7u+4Z15QyMg hA8vjakBaE1h74QoPYBXa3VLloKSXByMYwgMXnbkIH0Ym71gzRpvRoledjQgYpBCsd4M JY2+7AWLS3XfJJGQzxwSgO5btmIOvREF7Tt8VMQTVnu6gKOCTYMj17SsZMSgfXG6SIPq DagA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QTFxnXfGyKpGNLvWpzQQ4FepIwpps8G2FUykGZfgzRo=; b=dGdfCbftQrQD2/E9yOQGZiMWYV5YDnpSt7KTqwIUKXbTi8YQWisHnFEtNBaWZcIuNs S0PNvuv9PXtzH7jI2x8L9oIJH0WRzQsu0y3d73j287NqZqw7S/aE3765CkSev+Hr0wpw vrhDKPtLQwG/RUDv1BDlGLhYlTbbKBhJ8ulaq6MorngnhltNQtvrFeBCpVobJgTI+xsG HD2/MQzYNqSzDZT4WUOKEm+kJdNd7G/Q6M5N4s98FxrKHcqYazIZyxVCCNj0oND0ET+U JPIWpMuIJOopDsLrALr/Djr+yf+LC/AijQ35KLa7zM0Lgtbyt6CEKqvsAdqgXL8dh03x zldg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PEavtUqr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n15-20020a170906164f00b006ceeacacf9asi73517ejd.139.2022.03.08.14.27.13; Tue, 08 Mar 2022 14:27:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PEavtUqr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344327AbiCHFrx (ORCPT + 99 others); Tue, 8 Mar 2022 00:47:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343788AbiCHFrp (ORCPT ); Tue, 8 Mar 2022 00:47:45 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EDE73BBF7; Mon, 7 Mar 2022 21:46:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646718409; x=1678254409; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FFVFu1/gLNtyq5Heu6S1wXB406UqdvSLzskp+SBaVXQ=; b=PEavtUqrb176/V+Rf2x0g8PiWuKoszYoDciwJ2iYpT5lHAW4cQPn+u+I hFmP0kfL4B+tuQCAHT2qZNJ81fq9dZe0YkEG6CI753/iLTkxeuAl4sYns JeqOY5JT6DXpj+EMgQ0q1GfO5Icmy89Ntim8/HtLgk4P2yITdaNuGD1BI bbp4IkAjE9/JgrBETTh7Wlb8HFprzfTC76PMQQJgQvobLzGciSvJ49lBA +OZ56pRid2o/EX1dyHZjD5vvMRGoSppj27HB+I956rlYi8aTVsYaMy1aU mXOtCRmE6PrVUK7Oht0mjKhb1Z3+ciBmZ9No5jw0PJy7RU8Z7tTk3PSgu g==; X-IronPort-AV: E=McAfee;i="6200,9189,10279"; a="234553173" X-IronPort-AV: E=Sophos;i="5.90,163,1643702400"; d="scan'208";a="234553173" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2022 21:46:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,163,1643702400"; d="scan'208";a="537430218" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 07 Mar 2022 21:46:42 -0800 From: Lu Baolu To: Greg Kroah-Hartman , Joerg Roedel , Alex Williamson , Bjorn Helgaas , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj Cc: Will Deacon , Robin Murphy , Dan Williams , rafael@kernel.org, Diana Craciun , Cornelia Huck , Eric Auger , Liu Yi L , Jacob jun Pan , Chaitanya Kulkarni , Stuart Yoder , Laurentiu Tudor , Thierry Reding , David Airlie , Daniel Vetter , Jonathan Hunter , Li Yang , Dmitry Osipenko , iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v8 06/11] PCI: portdrv: Set driver_managed_dma Date: Tue, 8 Mar 2022 13:44:16 +0800 Message-Id: <20220308054421.847385-7-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308054421.847385-1-baolu.lu@linux.intel.com> References: <20220308054421.847385-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If a switch lacks ACS P2P Request Redirect, a device below the switch can bypass the IOMMU and DMA directly to other devices below the switch, so all the downstream devices must be in the same IOMMU group as the switch itself. The existing VFIO framework allows the portdrv driver to be bound to the bridge while its downstream devices are assigned to user space. The pci_dma_configure() marks the IOMMU group as containing only devices with kernel drivers that manage DMA. Avoid this default behavior for the portdrv driver in order for compatibility with the current VFIO usage. We achieve this by setting ".driver_managed_dma = true" in pci_driver structure. It is safe because the portdrv driver meets below criteria: - This driver doesn't use DMA, as you can't find any related calls like pci_set_master() or any kernel DMA API (dma_map_*() and etc.). - It doesn't use MMIO as you can't find ioremap() or similar calls. It's tolerant to userspace possibly also touching the same MMIO registers via P2P DMA access. Suggested-by: Jason Gunthorpe Suggested-by: Kevin Tian Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Acked-by: Bjorn Helgaas --- drivers/pci/pcie/portdrv_pci.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c index 35eca6277a96..6b2adb678c21 100644 --- a/drivers/pci/pcie/portdrv_pci.c +++ b/drivers/pci/pcie/portdrv_pci.c @@ -202,6 +202,8 @@ static struct pci_driver pcie_portdriver = { .err_handler = &pcie_portdrv_err_handler, + .driver_managed_dma = true, + .driver.pm = PCIE_PORTDRV_PM_OPS, }; -- 2.25.1