Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1643129imm; Wed, 1 Aug 2018 21:18:20 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf+14MF7OK0n0YuZVelicmBZyJKUau0RGQToYjWy5I0PtVqTKfvqqWYE/JMTLCznTdkVJBT X-Received: by 2002:a62:4ece:: with SMTP id c197-v6mr1209979pfb.240.1533183500518; Wed, 01 Aug 2018 21:18:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533183500; cv=none; d=google.com; s=arc-20160816; b=nySNnk5XtCk2Kz8U5F9SOYdCydeCjujnxxOY89nJjE+1gS/0sgF/XxvEua5ANQGS2Z VSgHgfN5GB8s2P7E+m3iJ9Kq2YOjUjr656Qt0Y831SmjqIle/m8mFCE+tyeD3d9Kbv3a axMTeo6XdK+vfB6fVb1ZcvkvWxKXehFGTbAt/h07tjHKnU+XJ3wrCGuweAoF54gv7Ruh DgSTUnMuItVUWiVQJtJ+SwbhDpk1f6pfOQ0bnES8dYKOv/Wwn9C4SNzGRrm2pV6bM4XA 3XYTKRWKh9OOfg2IKDVtSr+fY0xSkFJYQaDpIqisomLEeExXDOW+DXChfFLwCzcbCwOu yiqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=/XeUlkYrx5peoEEsWKYiUJKsTCDQQslSpntvgM7ofGg=; b=Nm7FPctPYVLOdXIH1e06mg11n0KQyfNujti5Zl/ML5xtnol2ELqf1LHK2i2ure6gjq YlVNQW3+04pwQt7YIqSku9FZ7JR8KWLlHNFtlrcne22af7Jb2eInWYVpoU4nEx0zklSm au9q42HOZR7i2AZmkGzD0mw9Re6Ivt72HI91oUYNC/AwjB7g7ExPMILXZHAfue6P57+3 NdysNZ0IKCtP4I8yqvWLdk/8NIJyR6YJZ8PFqc1FgKevDBhVMCcGNYWqmMRbxMWP6h4X PkeEAUrFoEUuM1eMcvgdaGGJKzLpS0TsfmeJdLSSOpxMFev8uwfKfdTaKvI8dB193wW8 MDLQ== 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 e186-v6si926210pfc.176.2018.08.01.21.18.05; Wed, 01 Aug 2018 21:18:20 -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 S1726221AbeHBGG1 (ORCPT + 99 others); Thu, 2 Aug 2018 02:06:27 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:10217 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725994AbeHBGG1 (ORCPT ); Thu, 2 Aug 2018 02:06:27 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 43917A0F69DE6; Thu, 2 Aug 2018 12:17:12 +0800 (CST) Received: from localhost (10.67.212.75) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server (TLS) id 14.3.399.0; Thu, 2 Aug 2018 12:17:06 +0800 Date: Thu, 2 Aug 2018 12:15:47 +0800 From: Kenneth Lee To: "Tian, Kevin" CC: Kenneth Lee , Jonathan Corbet , Herbert Xu , "David S . Miller" , Joerg Roedel , Alex Williamson , Hao Fang , Zhou Wang , Zaibo Xu , Philippe Ombredanne , Greg Kroah-Hartman , Thomas Gleixner , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-crypto@vger.kernel.org" , "iommu@lists.linux-foundation.org" , "kvm@vger.kernel.org" , "linux-accelerators@lists.ozlabs.org" , Lu Baolu , "Kumar, Sanjay K" , "linuxarm@huawei.com" Subject: Re: [RFC PATCH 2/7] iommu: Add share domain interface in iommu for spimdev Message-ID: <20180802041547.GM160746@Turing-Arch-b> References: <20180801102221.5308-1-nek.in.cn@gmail.com> <20180801102221.5308-3-nek.in.cn@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 02, 2018 at 03:17:03AM +0000, Tian, Kevin wrote: > Date: Thu, 2 Aug 2018 03:17:03 +0000 > From: "Tian, Kevin" > To: Kenneth Lee , Jonathan Corbet , > Herbert Xu , "David S . Miller" > , Joerg Roedel , Alex Williamson > , Kenneth Lee , Hao > Fang , Zhou Wang , Zaibo Xu > , Philippe Ombredanne , Greg > Kroah-Hartman , Thomas Gleixner > , "linux-doc@vger.kernel.org" > , "linux-kernel@vger.kernel.org" > , "linux-crypto@vger.kernel.org" > , "iommu@lists.linux-foundation.org" > , "kvm@vger.kernel.org" > , "linux-accelerators@lists.ozlabs.org" > , Lu Baolu > , "Kumar, Sanjay K" > CC: "linuxarm@huawei.com" > Subject: RE: [RFC PATCH 2/7] iommu: Add share domain interface in iommu for > spimdev > Message-ID: > > > From: Kenneth Lee > > Sent: Wednesday, August 1, 2018 6:22 PM > > > > From: Kenneth Lee > > > > This patch add sharing interface for a iommu_group. The new interface: > > > > iommu_group_share_domain() > > iommu_group_unshare_domain() > > > > can be used by some virtual iommu_group (such as iommu_group for > > spimdev) > > to share their parent's iommu_group. > > > > When the domain of the group is shared, it cannot be changed before > > unshared. In the future, notification can be added if update is required. > > Is it necessary or just asking VFIO to use parent domain directly? > Even we add to VFIO, the iommu still need to be changed. We can move the type1 part to VFIO if we have agreement in RFC stage. > > > > Signed-off-by: Kenneth Lee > > --- > > drivers/iommu/iommu.c | 28 +++++++++++++++++++++++++++- > > include/linux/iommu.h | 2 ++ > > 2 files changed, 29 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > > index 63b37563db7e..a832aafe660d 100644 > > --- a/drivers/iommu/iommu.c > > +++ b/drivers/iommu/iommu.c > > @@ -54,6 +54,9 @@ struct iommu_group { > > int id; > > struct iommu_domain *default_domain; > > struct iommu_domain *domain; > > + atomic_t domain_shared_ref; /* Number of user of current domain. > > + * The domain cannot be modified if ref > > > 0 > > + */ > > }; > > > > struct group_device { > > @@ -353,6 +356,7 @@ struct iommu_group *iommu_group_alloc(void) > > return ERR_PTR(ret); > > } > > group->id = ret; > > + atomic_set(&group->domain_shared_ref, 0); > > > > ret = kobject_init_and_add(&group->kobj, &iommu_group_ktype, > > NULL, "%d", group->id); > > @@ -482,6 +486,25 @@ int iommu_group_set_name(struct iommu_group > > *group, const char *name) > > } > > EXPORT_SYMBOL_GPL(iommu_group_set_name); > > > > +struct iommu_domain *iommu_group_share_domain(struct > > iommu_group *group) > > +{ > > + /* the domain can be shared only when the default domain is used > > */ > > + /* todo: more shareable check */ > > + if (group->domain != group->default_domain) > > + return ERR_PTR(-EINVAL); > > + > > + atomic_inc(&group->domain_shared_ref); > > + return group->domain; > > +} > > +EXPORT_SYMBOL_GPL(iommu_group_share_domain); > > + > > +void iommu_group_unshare_domain(struct iommu_group *group) > > +{ > > + atomic_dec(&group->domain_shared_ref); > > + WARN_ON(atomic_read(&group->domain_shared_ref) < 0); > > +} > > +EXPORT_SYMBOL_GPL(iommu_group_unshare_domain); > > + > > static int iommu_group_create_direct_mappings(struct iommu_group > > *group, > > struct device *dev) > > { > > @@ -1401,7 +1424,8 @@ static int __iommu_attach_group(struct > > iommu_domain *domain, > > { > > int ret; > > > > - if (group->default_domain && group->domain != group- > > >default_domain) > > + if ((group->default_domain && group->domain != group- > > >default_domain) || > > + atomic_read(&group->domain_shared_ref) > 0) > > return -EBUSY; > > > > ret = __iommu_group_for_each_dev(group, domain, > > @@ -1438,6 +1462,8 @@ static void __iommu_detach_group(struct > > iommu_domain *domain, > > { > > int ret; > > > > + WARN_ON(atomic_read(&group->domain_shared_ref) > 0); > > + > > if (!group->default_domain) { > > __iommu_group_for_each_dev(group, domain, > > iommu_group_do_detach_device); > > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > > index 19938ee6eb31..278d60e3ec39 100644 > > --- a/include/linux/iommu.h > > +++ b/include/linux/iommu.h > > @@ -349,6 +349,8 @@ extern int iommu_domain_get_attr(struct > > iommu_domain *domain, enum iommu_attr, > > void *data); > > extern int iommu_domain_set_attr(struct iommu_domain *domain, enum > > iommu_attr, > > void *data); > > +extern struct iommu_domain *iommu_group_share_domain(struct > > iommu_group *group); > > +extern void iommu_group_unshare_domain(struct iommu_group *group); > > > > /* Window handling function prototypes */ > > extern int iommu_domain_window_enable(struct iommu_domain > > *domain, u32 wnd_nr, > > -- > > 2.17.1 -- -Kenneth(Hisilicon) ================================================================================ 本邮件及其附件含有华为公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁 止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中 的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from HUAWEI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!