Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1606267imm; Wed, 1 Aug 2018 20:18:55 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc35fmi1OFwN9n2GLtaYKHUo4pFV6IWGK/dkI1EG/EFGfY/HvS8bELqBLMwAAxX2C6w+NYn X-Received: by 2002:a63:b445:: with SMTP id n5-v6mr995127pgu.104.1533179935435; Wed, 01 Aug 2018 20:18:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533179935; cv=none; d=google.com; s=arc-20160816; b=nTxA1574qJ4oG/ZdCPwXKJOJF9tmX5kI3oZkajyXYRf95JrJU45jppdQpabF1wNGUJ WvrJan73gAv0bRR8pVYE8IDPoBszLOWSpcbpSz6JUkd56TxyiHw4eVloqUBYTBzakgRn l0dZ904bW3c0g+FKErCVSP9lJeStRwxPpEcNWC2MBW5TEiD9CFy226ORmA2zkGcrHEUC M0D1Ej8r8m90Y7WvPLqndRnOGusYe0oq05+01+TuYhwhuHhIQfG4QrPPKh4X0cr05Dtp eQGcubnuij2EJptIjw5BbIAfz4iXc5yEGKBL5KFrtQl0VxQyJ21CKjipYaKrJfJSDQsa X3kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :dlp-reaction:dlp-version:dlp-product:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:arc-authentication-results; bh=w8l3s5Apr3dTIVzCOcVckMn4qcwa6ZoWQOnzshpybEs=; b=d5+oERTUJKU7dVMRHAAEqEYymUHwH0hniwGFdUoSQQcP3tZa8gFQn1uqkKGBjaBXxK 8nzeVOVG3Uwsl8q0pCuw1EHi30uTkVp3IEcNFmtsFYp5LrqsuA2GbtGLN9H0NDM75gdi 4rGcxnNK/Yc6gtUUt4J8hXm263STlFtbtghLSBxowNhwUiop6NSLNtAtD1Uv0ngQW5tw SOxAYOZ7MxhmbgGvlYsodojFxVBqWfZA/lPn8KjoE7FAAbkYWPmP6LOHJqAvmKKFMHKR c5uSbVhslq0LkY7Nj0B7y89Z5Kk8xnmAKCK7RgM/OD9nr/nDRfN9MtzYJfqwk7Gfzuun nxUQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h65-v6si803057pfg.197.2018.08.01.20.18.41; Wed, 01 Aug 2018 20:18:55 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726702AbeHBFGc convert rfc822-to-8bit (ORCPT + 99 others); Thu, 2 Aug 2018 01:06:32 -0400 Received: from mga01.intel.com ([192.55.52.88]:39079 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726267AbeHBFGb (ORCPT ); Thu, 2 Aug 2018 01:06:31 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Aug 2018 20:17:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,434,1526367600"; d="scan'208";a="71886148" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga003.jf.intel.com with ESMTP; 01 Aug 2018 20:17:07 -0700 Received: from fmsmsx154.amr.corp.intel.com (10.18.116.70) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 1 Aug 2018 20:17:07 -0700 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by FMSMSX154.amr.corp.intel.com (10.18.116.70) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 1 Aug 2018 20:17:07 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.57]) by shsmsx102.ccr.corp.intel.com ([169.254.2.124]) with mapi id 14.03.0319.002; Thu, 2 Aug 2018 11:17:05 +0800 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 Thread-Topic: [RFC PATCH 2/7] iommu: Add share domain interface in iommu for spimdev Thread-Index: AQHUKYHWQk1Lvdz7XEqv7xkSwudUdqSryvAw Date: Thu, 2 Aug 2018 03:17:03 +0000 Message-ID: References: <20180801102221.5308-1-nek.in.cn@gmail.com> <20180801102221.5308-3-nek.in.cn@gmail.com> In-Reply-To: <20180801102221.5308-3-nek.in.cn@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNzJkMWU2MzQtYTg1NS00YWFmLWJkMjctMWQ3YjE3MGU3NDdjIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiK2FvWVNXTG4zKzVFQUJYK3dZK0lzK0JiZGI2eXNocjZxQlFWZXpYTGk4MnA2Zm5VSDBtNDZSc2UySTJQbkVhaiJ9 dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > 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? > > 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