From patchwork Sun Jul 22 06:09:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 10539177 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 21F1D14BC for ; Sun, 22 Jul 2018 06:11:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 105802785D for ; Sun, 22 Jul 2018 06:11:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 047FE2793A; Sun, 22 Jul 2018 06:11:52 +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 935032785D for ; Sun, 22 Jul 2018 06:11:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729316AbeGVHHJ (ORCPT ); Sun, 22 Jul 2018 03:07:09 -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 S1729296AbeGVHHI (ORCPT ); Sun, 22 Jul 2018 03:07:08 -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:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,388,1526367600"; d="scan'208";a="218015952" Received: from allen-box.sh.intel.com ([10.239.48.172]) by orsmga004.jf.intel.com with ESMTP; 21 Jul 2018 23:11:34 -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 09/10] vfio/mdev: Add mediated device domain type Date: Sun, 22 Jul 2018 14:09:32 +0800 Message-Id: <1532239773-15325-10-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 A parent device might create different types of mediated devices. For example, a mediated device could be created on the parent device with a PASID tagged. When the iommu supports PASID-granular translations, the mediated device is individually protected and isolated by the iommu. It's hence possible to allocate a domain for each such device. This patch defines the domain types of a mediated device and allows the parent driver to specify this attribute after a mdev is actually created. Cc: Ashok Raj Cc: Jacob Pan Cc: Kevin Tian Cc: Liu Yi L Suggested-by: Kevin Tian Signed-off-by: Lu Baolu --- drivers/vfio/mdev/mdev_core.c | 21 +++++++++++++++++++++ drivers/vfio/mdev/mdev_private.h | 1 + include/linux/mdev.h | 22 ++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index d8f19ba..4d82b36 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -391,6 +391,27 @@ int mdev_device_remove(struct device *dev, bool force_remove) return 0; } +int mdev_set_domain_type(struct device *dev, enum mdev_domain_type type) +{ + struct mdev_device *mdev = to_mdev_device(dev); + + if (type == DOMAIN_TYPE_PRIVATE && !iommu_present(&mdev_bus_type)) + return -EINVAL; + + mdev->domain_type = type; + + return 0; +} +EXPORT_SYMBOL(mdev_set_domain_type); + +enum mdev_domain_type mdev_get_domain_type(struct device *dev) +{ + struct mdev_device *mdev = to_mdev_device(dev); + + return mdev->domain_type; +} +EXPORT_SYMBOL(mdev_get_domain_type); + static int __init mdev_init(void) { int ret; diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h index b5819b7..d47a670 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -34,6 +34,7 @@ struct mdev_device { struct list_head next; struct kobject *type_kobj; bool active; + int domain_type; }; #define to_mdev_device(dev) container_of(dev, struct mdev_device, dev) diff --git a/include/linux/mdev.h b/include/linux/mdev.h index b6e048e..5d862b0 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -15,6 +15,28 @@ struct mdev_device; +enum mdev_domain_type { + DOMAIN_TYPE_EXTERNAL, /* Use the external domain and all + * IOMMU staff controlled by the + * parent device driver. + */ + DOMAIN_TYPE_INHERITANCE,/* Use the same domain as the parent device. */ + DOMAIN_TYPE_PRIVATE, /* Capable of having a private domain. For an + * example, the parent device is able to bind + * a specific PASID for a mediated device and + * transferring data with the asigned PASID. + */ +}; + +/* + * Called by the parent device driver to set the domain type. + * By default, the domain type is set to DOMAIN_TYPE_EXTERNAL. + */ +int mdev_set_domain_type(struct device *dev, enum mdev_domain_type type); + +/* Check the domain type. */ +enum mdev_domain_type mdev_get_domain_type(struct device *dev); + /** * struct mdev_parent_ops - Structure to be registered for each parent device to * register the device to mdev module.