From patchwork Mon Aug 7 07:25:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 798494 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=kvm-ppc-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xQq5S3r55z9sQl for ; Mon, 7 Aug 2017 17:33:32 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752090AbdHGHdb (ORCPT ); Mon, 7 Aug 2017 03:33:31 -0400 Received: from ozlabs.ru ([107.173.13.209]:50888 "EHLO ozlabs.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751560AbdHGHda (ORCPT ); Mon, 7 Aug 2017 03:33:30 -0400 X-Greylist: delayed 453 seconds by postgrey-1.27 at vger.kernel.org; Mon, 07 Aug 2017 03:33:30 EDT Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 7BF3A3A60030; Mon, 7 Aug 2017 03:26:56 -0400 (EDT) From: Alexey Kardashevskiy To: linuxppc-dev@lists.ozlabs.org Cc: Alexey Kardashevskiy , David Gibson , kvm-ppc@vger.kernel.org, kvm@vger.kernel.org, Yongji Xie , Eric Auger , Kyle Mahlkuch , Alex Williamson , Jike Song , Bjorn Helgaas , Robin Murphy , Joerg Roedel , Arvind Yadav , Benjamin Herrenschmidt , David Woodhouse , Kirti Wankhede , Mauricio Faria de Oliveira , Neo Jia , Paul Mackerras , Vlad Tsyrklevich , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v5 1/5] iommu: Add capabilities to a group Date: Mon, 7 Aug 2017 17:25:44 +1000 Message-Id: <20170807072548.3023-2-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170807072548.3023-1-aik@ozlabs.ru> References: <20170807072548.3023-1-aik@ozlabs.ru> Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org This introduces capabilities to IOMMU groups. The first defined capability is IOMMU_GROUP_CAP_ISOLATE_MSIX which tells the IOMMU group users that a particular IOMMU group is capable of MSIX message filtering; this is useful when deciding whether or not to allow mapping of MSIX table to the userspace. Various architectures will enable it when they decide that it is safe to do so. Signed-off-by: Alexey Kardashevskiy Reviewed-by: David Gibson --- include/linux/iommu.h | 20 ++++++++++++++++++++ drivers/iommu/iommu.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 2cb54adc4a33..6b6f3c2f4904 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -155,6 +155,9 @@ struct iommu_resv_region { enum iommu_resv_type type; }; +/* IOMMU group capabilities */ +#define IOMMU_GROUP_CAP_ISOLATE_MSIX (1U) + #ifdef CONFIG_IOMMU_API /** @@ -312,6 +315,11 @@ extern void *iommu_group_get_iommudata(struct iommu_group *group); extern void iommu_group_set_iommudata(struct iommu_group *group, void *iommu_data, void (*release)(void *iommu_data)); +extern void iommu_group_set_caps(struct iommu_group *group, + unsigned long clearcaps, + unsigned long setcaps); +extern bool iommu_group_is_capable(struct iommu_group *group, + unsigned long cap); extern int iommu_group_set_name(struct iommu_group *group, const char *name); extern int iommu_group_add_device(struct iommu_group *group, struct device *dev); @@ -513,6 +521,18 @@ static inline void iommu_group_set_iommudata(struct iommu_group *group, { } +static inline void iommu_group_set_caps(struct iommu_group *group, + unsigned long clearcaps, + unsigned long setcaps) +{ +} + +static inline bool iommu_group_is_capable(struct iommu_group *group, + unsigned long cap) +{ + return false; +} + static inline int iommu_group_set_name(struct iommu_group *group, const char *name) { diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 3f6ea160afed..6b2c34fe2c3d 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -52,6 +52,7 @@ struct iommu_group { void (*iommu_data_release)(void *iommu_data); char *name; int id; + unsigned long caps; struct iommu_domain *default_domain; struct iommu_domain *domain; }; @@ -447,6 +448,33 @@ void iommu_group_set_iommudata(struct iommu_group *group, void *iommu_data, EXPORT_SYMBOL_GPL(iommu_group_set_iommudata); /** + * iommu_group_set_caps - Change the group capabilities + * @group: the group + * @clearcaps: capabilities mask to remove + * @setcaps: capabilities mask to add + * + * IOMMU groups can be capable of various features which device drivers + * may read and adjust the behavior. + */ +void iommu_group_set_caps(struct iommu_group *group, + unsigned long clearcaps, unsigned long setcaps) +{ + group->caps &= ~clearcaps; + group->caps |= setcaps; +} +EXPORT_SYMBOL_GPL(iommu_group_set_caps); + +/** + * iommu_group_is_capable - Returns if a group capability is present + * @group: the group + */ +bool iommu_group_is_capable(struct iommu_group *group, unsigned long cap) +{ + return !!(group->caps & cap); +} +EXPORT_SYMBOL_GPL(iommu_group_is_capable); + +/** * iommu_group_set_name - set name for a group * @group: the group * @name: name