Received: by 10.192.165.156 with SMTP id m28csp1137751imm; Mon, 16 Apr 2018 14:56:30 -0700 (PDT) X-Google-Smtp-Source: AIpwx49aU9ErMX29K3z4b5vhyxK/6hJWYTYoVE8PYm057uzmcV8elxErIuynLXAmg8KSP8yuOi+l X-Received: by 2002:a17:902:b40d:: with SMTP id x13-v6mr16603804plr.167.1523915790505; Mon, 16 Apr 2018 14:56:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523915790; cv=none; d=google.com; s=arc-20160816; b=qo0ejI2aR4Pf5kiuEKo+dMhIBFLaWTsTpxW1IT318C0bxlAVqAGb5dQPjzPmHJexDS gTVvr+k6XcO0XDzvV+bj0EqbOMxZqSx06gowy0rsQcmwYK55FbDxLN1nrOl7CqA4jZuj tLAUDELIKqFmw4JeoFkD1av6Q3otrTxL/EySfdcmWwSvnNB1Yk7iiS8j5qLyVHVp655z H/FsjnpIogovwIlL5TbHaeYlT5L6vW9sYT4I8ijHZxU5gDycn0QBDOK6LP9Q32/rGzNk Zeac2CaHhJRmaGCpFjdW7IaCm7bCp6WMog3jraBQ9pxNKqQ0NRrEjqXim+wJC8x3kEAv yHYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=yNFcFf2wjU4UoCtryOlfUbFnXsnimsM7vNUH+5Ywy1c=; b=yfsB+ufxhnE64nngPAtnpRiX+Luu+WbqcJPcrR7/8BPLkSfWX0dIbCwvTksNlu/maf gIcnRtVKccMMQbTpMngl/wTM5z04Xh290ojnC7fF11iyS6ivpZEReBO5TdnF3dnqkcYH xIbU8Rwgfyp/USCT7hVrIfJCuDP+E1uHbbblNj1yCuaGKnA9wa+fQayAoEw7Sv5Dfo6x Ghf0hJrRSnOSMCNFIvdrS0JTx25aVRrNwltHqUSm03QNvnT+lPadCOMi6SOeQZWJ3FPb nk6ZsKQv8O2of7V+DXtnZDuBew69krcZ+G3qo2KooozUQ1yauKC8nWf0nvjHvnzmZiVd PD5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h17si8896983pgv.223.2018.04.16.14.56.16; Mon, 16 Apr 2018 14:56:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753182AbeDPVyz (ORCPT + 99 others); Mon, 16 Apr 2018 17:54:55 -0400 Received: from mga09.intel.com ([134.134.136.24]:12290 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751870AbeDPVqn (ORCPT ); Mon, 16 Apr 2018 17:46:43 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Apr 2018 14:46:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,460,1517904000"; d="scan'208";a="34740133" Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga006.jf.intel.com with ESMTP; 16 Apr 2018 14:46:42 -0700 From: Jacob Pan To: iommu@lists.linux-foundation.org, LKML , Joerg Roedel , David Woodhouse , Greg Kroah-Hartman , Alex Williamson , Jean-Philippe Brucker Cc: Rafael Wysocki , "Liu, Yi L" , "Tian, Kevin" , Raj Ashok , Jean Delvare , "Christoph Hellwig" , "Lu Baolu" , Jacob Pan , Liu@vger.kernel.org, Yi L Subject: [PATCH v4 01/22] iommu: introduce bind_pasid_table API function Date: Mon, 16 Apr 2018 14:48:50 -0700 Message-Id: <1523915351-54415-2-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523915351-54415-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1523915351-54415-1-git-send-email-jacob.jun.pan@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Virtual IOMMU was proposed to support Shared Virtual Memory (SVM) use in the guest: https://lists.gnu.org/archive/html/qemu-devel/2016-11/msg05311.html As part of the proposed architecture, when an SVM capable PCI device is assigned to a guest, nested mode is turned on. Guest owns the first level page tables (request with PASID) which performs GVA->GPA translation. Second level page tables are owned by the host for GPA->HPA translation for both request with and without PASID. A new IOMMU driver interface is therefore needed to perform tasks as follows: * Enable nested translation and appropriate translation type * Assign guest PASID table pointer (in GPA) and size to host IOMMU This patch introduces new API functions to perform bind/unbind guest PASID tables. Based on common data, model specific IOMMU drivers can be extended to perform the specific steps for binding pasid table of assigned devices. Signed-off-by: Jean-Philippe Brucker Signed-off-by: Liu, Yi L Signed-off-by: Ashok Raj Signed-off-by: Jacob Pan --- drivers/iommu/iommu.c | 19 +++++++++++++++++++ include/linux/iommu.h | 24 ++++++++++++++++++++++++ include/uapi/linux/iommu.h | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 include/uapi/linux/iommu.h diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index d2aa2320..3a69620 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1325,6 +1325,25 @@ int iommu_attach_device(struct iommu_domain *domain, struct device *dev) } EXPORT_SYMBOL_GPL(iommu_attach_device); +int iommu_bind_pasid_table(struct iommu_domain *domain, struct device *dev, + struct pasid_table_config *pasidt_binfo) +{ + if (unlikely(!domain->ops->bind_pasid_table)) + return -ENODEV; + + return domain->ops->bind_pasid_table(domain, dev, pasidt_binfo); +} +EXPORT_SYMBOL_GPL(iommu_bind_pasid_table); + +void iommu_unbind_pasid_table(struct iommu_domain *domain, struct device *dev) +{ + if (unlikely(!domain->ops->unbind_pasid_table)) + return; + + domain->ops->unbind_pasid_table(domain, dev); +} +EXPORT_SYMBOL_GPL(iommu_unbind_pasid_table); + static void __iommu_detach_device(struct iommu_domain *domain, struct device *dev) { diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 19938ee..8ad111f 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -25,6 +25,7 @@ #include #include #include +#include #define IOMMU_READ (1 << 0) #define IOMMU_WRITE (1 << 1) @@ -187,6 +188,8 @@ 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 + * @bind_pasid_table: bind pasid table pointer for guest SVM + * @unbind_pasid_table: unbind pasid table pointer and restore defaults */ struct iommu_ops { bool (*capable)(enum iommu_cap); @@ -233,8 +236,14 @@ struct iommu_ops { u32 (*domain_get_windows)(struct iommu_domain *domain); int (*of_xlate)(struct device *dev, struct of_phandle_args *args); + bool (*is_attach_deferred)(struct iommu_domain *domain, struct device *dev); + int (*bind_pasid_table)(struct iommu_domain *domain, struct device *dev, + struct pasid_table_config *pasidt_binfo); + void (*unbind_pasid_table)(struct iommu_domain *domain, + struct device *dev); + unsigned long pgsize_bitmap; }; @@ -296,6 +305,10 @@ extern int iommu_attach_device(struct iommu_domain *domain, struct device *dev); extern void iommu_detach_device(struct iommu_domain *domain, struct device *dev); +extern int iommu_bind_pasid_table(struct iommu_domain *domain, + struct device *dev, struct pasid_table_config *pasidt_binfo); +extern void iommu_unbind_pasid_table(struct iommu_domain *domain, + struct device *dev); extern struct iommu_domain *iommu_get_domain_for_dev(struct device *dev); extern int iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t size, int prot); @@ -696,6 +709,17 @@ const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode) return NULL; } +static inline +int iommu_bind_pasid_table(struct iommu_domain *domain, struct device *dev, + struct pasid_table_config *pasidt_binfo) +{ + return -EINVAL; +} +static inline +void iommu_unbind_pasid_table(struct iommu_domain *domain, struct device *dev) +{ +} + #endif /* CONFIG_IOMMU_API */ #endif /* __LINUX_IOMMU_H */ diff --git a/include/uapi/linux/iommu.h b/include/uapi/linux/iommu.h new file mode 100644 index 0000000..9f7a6bf --- /dev/null +++ b/include/uapi/linux/iommu.h @@ -0,0 +1,32 @@ +/* + * IOMMU user API definitions + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef _UAPI_IOMMU_H +#define _UAPI_IOMMU_H + +#include + +/** + * PASID table data used to bind guest PASID table to the host IOMMU. This will + * enable guest managed first level page tables. + * @version: for future extensions and identification of the data format + * @bytes: size of this structure + * @base_ptr: PASID table pointer + * @pasid_bits: number of bits supported in the guest PASID table, must be less + * or equal than the host supported PASID size. + */ +struct pasid_table_config { + __u32 version; +#define PASID_TABLE_CFG_VERSION 1 + __u32 bytes; + __u64 base_ptr; + __u8 pasid_bits; +}; + +#endif /* _UAPI_IOMMU_H */ -- 2.7.4