Message ID | 20230928071528.26258-7-yi.l.liu@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3593166vqu; Thu, 28 Sep 2023 13:55:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEdXoQPIwHLNsdxsr5ry/E9JbWZu/wEavAPO6h3xeb4BUK15EEs2dOUuFJaK8I0VDFNFKK6 X-Received: by 2002:a05:6a20:430a:b0:153:40c3:aa71 with SMTP id h10-20020a056a20430a00b0015340c3aa71mr2701357pzk.43.1695934558360; Thu, 28 Sep 2023 13:55:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695934558; cv=none; d=google.com; s=arc-20160816; b=WjGIUph6boNU/gDdidcbGm5ZNkTQdfqUOiTuLvyd5U+ozJen/+OsNRUOIejueDwXfa o3evEBxBlbEQz6o30/tA2LMoypt1eNjgkc7cnHjjbDXGcVV6rTjM8S8qcvQ1v9J+oTYO 8PpIM87+aGG3GVwFhJzL3ubk8YBXWNU0NEPq/Gw5NWkmlgiSITZTcwpT20EYBhuB14FC abQnXpUmu61iCDgDKMQhPYxgYIfdeO+sEKQWavUKkLJhXyJ5vKwZ0MY1C+Pex40Rf9yN cmuWXm91lyIgZESxUXzj5ERuIOw8xlXL2AliooY2dxInsiOIuMpZHuk9X2HGgj5M5+30 kgKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JzUKFE/KvWUYjVSFlZ4behPSUQYZski/gyvV9fUSra4=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=rQfCg4/dAwZDFwlIhWMFot0emj+3BtzRchD/nx/iwuQovVXDRXgiISh/7H2sY28zJO X1AvvGxESuaUvX78sRh3nwok8OqEcWse0FDQ9A4d3kX7NpavU11bjt3/30nqAWg+0jEE mrp/23jeWcrT59SZkTQvDRdznIzRDp0vBKk/Zn+TGcBQfVhzwa+HirJ+AHofaO6HTgQ3 w0Es/MmL2AWBxE4VWPnqvM2Qm50P5sza5vxsavZOdCo25UUbJz33tEVaY2JTT9itEWLZ sggSx2AcI1uLKMTp80sdB5UIScnXmo1yyixEGOZ6ZXhbJqhlzeZnYrDjD+5rDyQGXWsr POzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NT6bCq7u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id b14-20020a170902650e00b001c61bd7cee0si10903933plk.211.2023.09.28.13.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 13:55:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NT6bCq7u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 9E9EC819D736; Thu, 28 Sep 2023 00:17:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231548AbjI1HQF (ORCPT <rfc822;ruipengqi7@gmail.com> + 20 others); Thu, 28 Sep 2023 03:16:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231322AbjI1HPs (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 28 Sep 2023 03:15:48 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28B0AF9; Thu, 28 Sep 2023 00:15:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695885343; x=1727421343; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WOT6Nvcwlk/4tcNAsxhrAgOjJcTJ1AZiQvr9aESlkuA=; b=NT6bCq7uT3UdwoUU/nXxlVQ0NsGn+pAVRZSPbOQHs2/rYfPRoPR/aNvm VB1AVpfEpap325ejnnT22+GPfyTQi3BWpGh5J7x2ET+qdU01u2YeTEHAC gYWGW0HyxxKXcNF3Hp4btvYI0wQJF4MR5z7t5HIxPqfdyezRxnupjt4ON SAGH1osCkKZadOpuDQAyfztkPhKsLsPVOgei6fFAnOBE7vrbCgnI6Sjjv nEUh7VHIZkMPDS7TdpkavQLOTL6uBNAHXogzbf7sNl/Ed9eoi4dcyr0Qd b2/VjQT/RrYGfbMjqUSkcuBalyrCHeWyhMkTAjiWu5BRyjoGy+Nbgm2NB g==; X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="412914902" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="412914902" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2023 00:15:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="784602111" X-IronPort-AV: E=Sophos;i="6.03,183,1694761200"; d="scan'208";a="784602111" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orsmga001.jf.intel.com with ESMTP; 28 Sep 2023 00:15:41 -0700 From: Yi Liu <yi.l.liu@intel.com> To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com, joao.m.martins@oracle.com Subject: [PATCH v2 6/6] iommu/vt-d: Add domain_alloc_user op Date: Thu, 28 Sep 2023 00:15:28 -0700 Message-Id: <20230928071528.26258-7-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230928071528.26258-1-yi.l.liu@intel.com> References: <20230928071528.26258-1-yi.l.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 28 Sep 2023 00:17:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778316275832170246 X-GMAIL-MSGID: 1778316275832170246 |
Series |
iommufd support allocating nested parent domain
|
|
Commit Message
Yi Liu
Sept. 28, 2023, 7:15 a.m. UTC
This adds the domain_alloc_user op implementation. It supports allocating
domains to be used as parent under nested translation.
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
drivers/iommu/intel/iommu.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
Comments
On 9/28/23 3:15 PM, Yi Liu wrote: > This adds the domain_alloc_user op implementation. It supports allocating > domains to be used as parent under nested translation. > > Signed-off-by: Yi Liu<yi.l.liu@intel.com> > --- > drivers/iommu/intel/iommu.c | 28 ++++++++++++++++++++++++++++ > 1 file changed, 28 insertions(+) Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Best regards, baolu
> From: Liu, Yi L <yi.l.liu@intel.com> > Sent: Thursday, September 28, 2023 3:15 PM > > This adds the domain_alloc_user op implementation. It supports allocating > domains to be used as parent under nested translation. > > Signed-off-by: Yi Liu <yi.l.liu@intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com>
On Thu, Sep 28, 2023 at 12:15:28AM -0700, Yi Liu wrote: > This adds the domain_alloc_user op implementation. It supports allocating > domains to be used as parent under nested translation. > > Signed-off-by: Yi Liu <yi.l.liu@intel.com> > --- > drivers/iommu/intel/iommu.c | 28 ++++++++++++++++++++++++++++ > 1 file changed, 28 insertions(+) > > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c > index 5db283c17e0d..017aed5813d8 100644 > --- a/drivers/iommu/intel/iommu.c > +++ b/drivers/iommu/intel/iommu.c > @@ -4074,6 +4074,33 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type) > return NULL; > } > > +static struct iommu_domain * > +intel_iommu_domain_alloc_user(struct device *dev, u32 flags) > +{ > + struct iommu_domain *domain; > + struct intel_iommu *iommu; > + > + if (flags & (~IOMMU_HWPT_ALLOC_NEST_PARENT)) > + return ERR_PTR(-EOPNOTSUPP); > + > + iommu = device_to_iommu(dev, NULL, NULL); > + if (!iommu) > + return ERR_PTR(-ENODEV); Why isn't this just struct device_domain_info *info = dev_iommu_priv_get(dev) struct intel_iommu *iommu = info->iommu ??? Same question for almost all other calls to this function! The one in probe is reasonable, but I don't think it should be ever called again. I'm going to leave this, but please make a series cleaning all the device_to_iommu() stuff next cycle.. Jason
On 10/11/23 12:43 AM, Jason Gunthorpe wrote: > On Thu, Sep 28, 2023 at 12:15:28AM -0700, Yi Liu wrote: >> This adds the domain_alloc_user op implementation. It supports allocating >> domains to be used as parent under nested translation. >> >> Signed-off-by: Yi Liu<yi.l.liu@intel.com> >> --- >> drivers/iommu/intel/iommu.c | 28 ++++++++++++++++++++++++++++ >> 1 file changed, 28 insertions(+) >> >> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c >> index 5db283c17e0d..017aed5813d8 100644 >> --- a/drivers/iommu/intel/iommu.c >> +++ b/drivers/iommu/intel/iommu.c >> @@ -4074,6 +4074,33 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type) >> return NULL; >> } >> >> +static struct iommu_domain * >> +intel_iommu_domain_alloc_user(struct device *dev, u32 flags) >> +{ >> + struct iommu_domain *domain; >> + struct intel_iommu *iommu; >> + >> + if (flags & (~IOMMU_HWPT_ALLOC_NEST_PARENT)) >> + return ERR_PTR(-EOPNOTSUPP); >> + >> + iommu = device_to_iommu(dev, NULL, NULL); >> + if (!iommu) >> + return ERR_PTR(-ENODEV); > Why isn't this just > > struct device_domain_info *info = dev_iommu_priv_get(dev) > struct intel_iommu *iommu = info->iommu > > ??? > > Same question for almost all other calls to this function! The one in > probe is reasonable, but I don't think it should be ever called again. > > I'm going to leave this, but please make a series cleaning all the > device_to_iommu() stuff next cycle.. Sure. I also have a plan to do this. device_to_iommu() is only needed in the probe path. For runtime callbacks, we can just retrieve it from the device's iommu private data. Best regards, baolu
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 5db283c17e0d..017aed5813d8 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4074,6 +4074,33 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type) return NULL; } +static struct iommu_domain * +intel_iommu_domain_alloc_user(struct device *dev, u32 flags) +{ + struct iommu_domain *domain; + struct intel_iommu *iommu; + + if (flags & (~IOMMU_HWPT_ALLOC_NEST_PARENT)) + return ERR_PTR(-EOPNOTSUPP); + + iommu = device_to_iommu(dev, NULL, NULL); + if (!iommu) + return ERR_PTR(-ENODEV); + + if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !ecap_nest(iommu->ecap)) + return ERR_PTR(-EOPNOTSUPP); + + /* + * domain_alloc_user op needs to fully initialize a domain + * before return, so uses iommu_domain_alloc() here for + * simple. + */ + domain = iommu_domain_alloc(dev->bus); + if (!domain) + domain = ERR_PTR(-ENOMEM); + return domain; +} + static void intel_iommu_domain_free(struct iommu_domain *domain) { if (domain != &si_domain->domain && domain != &blocking_domain) @@ -4807,6 +4834,7 @@ const struct iommu_ops intel_iommu_ops = { .capable = intel_iommu_capable, .hw_info = intel_iommu_hw_info, .domain_alloc = intel_iommu_domain_alloc, + .domain_alloc_user = intel_iommu_domain_alloc_user, .probe_device = intel_iommu_probe_device, .probe_finalize = intel_iommu_probe_finalize, .release_device = intel_iommu_release_device,