From patchwork Sun Jul 22 06:09:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lu Baolu X-Patchwork-Id: 10539185 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EF91D174A for ; Sun, 22 Jul 2018 06:12:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDEF02785D for ; Sun, 22 Jul 2018 06:12:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D25012793A; Sun, 22 Jul 2018 06:12:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EAED2785D for ; Sun, 22 Jul 2018 06:12:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728635AbeGVHHg (ORCPT ); Sun, 22 Jul 2018 03:07:36 -0400 Received: from mga11.intel.com ([192.55.52.93]:37222 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728630AbeGVHHE (ORCPT ); Sun, 22 Jul 2018 03:07:04 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Jul 2018 23:11:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,388,1526367600"; d="scan'208";a="218015893" Received: from allen-box.sh.intel.com ([10.239.48.172]) by orsmga004.jf.intel.com with ESMTP; 21 Jul 2018 23:11:25 -0700 From: Lu Baolu To: Joerg Roedel , David Woodhouse , Alex Williamson , Kirti Wankhede Cc: ashok.raj@intel.com, sanjay.k.kumar@intel.com, jacob.jun.pan@intel.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, peterx@redhat.com, iommu@lists.linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu , Jacob Pan Subject: [RFC PATCH 06/10] iommu: Add iommu_set_bus API interface Date: Sun, 22 Jul 2018 14:09:29 +0800 Message-Id: <1532239773-15325-7-git-send-email-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1532239773-15325-1-git-send-email-baolu.lu@linux.intel.com> References: <1532239773-15325-1-git-send-email-baolu.lu@linux.intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This adds iommu_set_bus API by adding a new set_bus ops in the iommu_ops structure. A vendor IOMMU driver could either specify its callback or safely ignore it. This interface could be used to set the iommu methods used for a particular non-pci bus. One consumer of this interface could be vfio/mdev bus when the mdev devices could be exclusively protected by the IOMMU units. Cc: Ashok Raj Cc: Jacob Pan Cc: Kevin Tian Cc: Liu Yi L Signed-off-by: Lu Baolu --- drivers/iommu/iommu.c | 23 +++++++++++++++++++++++ include/linux/iommu.h | 12 ++++++++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 63b3756..b22b0a7 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1976,3 +1976,26 @@ int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids) return 0; } EXPORT_SYMBOL_GPL(iommu_fwspec_add_ids); + +int iommu_set_bus(struct bus_type *bus) +{ + struct iommu_device *iommu; + int ret = -ENODEV; + + spin_lock(&iommu_device_lock); + /* + * Iterate over iommu list and try setting bus with + * each iommu until a successful setting. + */ + list_for_each_entry(iommu, &iommu_device_list, list) { + if (iommu->ops->set_bus) { + ret = iommu->ops->set_bus(bus, iommu); + if (!ret) + break; + } + } + spin_unlock(&iommu_device_lock); + + return ret; +} +EXPORT_SYMBOL_GPL(iommu_set_bus); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 19938ee..2679796 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -48,6 +48,7 @@ struct bus_type; struct device; struct iommu_domain; struct notifier_block; +struct iommu_device; /* iommu fault flags */ #define IOMMU_FAULT_READ 0x0 @@ -187,6 +188,7 @@ struct iommu_resv_region { * @domain_get_windows: Return the number of windows for a domain * @of_xlate: add OF master IDs to iommu grouping * @pgsize_bitmap: bitmap of all possible supported page sizes + * @set_bus: set iommu ops for a non-pci bus */ struct iommu_ops { bool (*capable)(enum iommu_cap); @@ -235,6 +237,9 @@ struct iommu_ops { int (*of_xlate)(struct device *dev, struct of_phandle_args *args); bool (*is_attach_deferred)(struct iommu_domain *domain, struct device *dev); + /* Set iommu ops for a bus */ + int (*set_bus)(struct bus_type *bus, struct iommu_device *iommu); + unsigned long pgsize_bitmap; }; @@ -412,6 +417,8 @@ void iommu_fwspec_free(struct device *dev); int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids); const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode); +int iommu_set_bus(struct bus_type *bus); + #else /* CONFIG_IOMMU_API */ struct iommu_ops {}; @@ -696,6 +703,11 @@ const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode) return NULL; } +static inline int iommu_set_bus(struct bus_type *bus) +{ + return -ENODEV; +} + #endif /* CONFIG_IOMMU_API */ #endif /* __LINUX_IOMMU_H */