Message ID | 20231207021938.306738-1-baolu.lu@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4511852vqy; Wed, 6 Dec 2023 18:27:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IFf3tP5lDVqOUK/PCOfjDjZiVujcdlDBjQRmTICrkhJfGmveSTJT9mgcslOq1hgkxNLY4g0 X-Received: by 2002:a05:6358:431b:b0:170:21d7:cb5e with SMTP id r27-20020a056358431b00b0017021d7cb5emr3147068rwc.47.1701916034710; Wed, 06 Dec 2023 18:27:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701916034; cv=none; d=google.com; s=arc-20160816; b=Pm5BBUbG/mYuU/OwXlmvHgXGfQ0d/y99Uoz5KJPhPQHDYgiKv75ReeUjMfxiORmqzr F4tmvP4924AO7y2XdiGNP5ZrZZqhBRsfl7Tzi8oaV37CrKN1gLZVSrYEIFC3bxZjBuY9 DXy9fivpyWwTZRMiWHM5dluqQkmBabR8E4u2O9I5CcXXCRuvnPKpKmQoKNapr0HXP/Iy 0lAdEPb0OFVOQHoFKYMqcWh0aUCQFtV0mvbKaaMttYXWzpPZWYXu+N9Q1yJtl1Q7uwl6 UO+p22GgeFyt/1b+WORj/HTkbIC4RFKNbJx/lsL/6+9zOAZnKKvNOdQquyKUIh2ZSuNI H2uA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=DVUJAfm4eJtFBt0LqI2ry2YIH1K/XbMMzQe6ErY9dhI=; fh=5K4v/0ku97kpa0vTvhWLyUEWwXZiIFVMmzwLLirrjJ4=; b=PelQ3EbfQB8RKPub2m4eEJKHVR/Gi5H+FPpwd1u2k53fhAGJ5zdkUH3tOaAu2B/4XR 5O2d+CgfBn0T2RHMlKCgsKvoj4ZC8Na01drPk/qLL/qcPtF/zQ5//dwbzleZIh0bABMN bmz+G5IFvVlnaCwz8VP1ZYEYpoAdSGW06YeDpnagg9lYS7J39cOwxHdxc0NQlorNcCAG OoRfX8Vf5VNN+EISEmrXK/TO7KULIChdczky7xGwSxYijTYlShl0Puu/alcYOS1dBL43 0ZFNP2/ebi6lS4usyTnyjsRTiZrF+LCVlbL+f6RmBByGU7Brxqkj5ahiBb3x+ufVuaE8 fNhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DcLqoK4u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id u11-20020a056a00158b00b006ce08cdaf27si341452pfk.371.2023.12.06.18.27.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 18:27:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DcLqoK4u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 3CF2D80F5F27; Wed, 6 Dec 2023 18:27:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443019AbjLGCYM (ORCPT <rfc822;pusanteemu@gmail.com> + 99 others); Wed, 6 Dec 2023 21:24:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230385AbjLGCYL (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 6 Dec 2023 21:24:11 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F0B5D5C for <linux-kernel@vger.kernel.org>; Wed, 6 Dec 2023 18:24:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701915858; x=1733451858; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=BlyFybv+wIkSnOIH0bgSDQUnQo1Qmc4Q1qqIz58xmyg=; b=DcLqoK4uqAI3ePp5gUDv8cm6mF0CGB6ehXBTMa8cy8SZTQAYPBNfbcvf xD/Hy4NxV0dxj0d3oU+GW5OEd9E9khrH0ONj1/SolBVLXxmwHdvuZ772C SOtgYJEgYG090IXdDCpDmxxLzVj0Q8Xg4v3Zbva1PKvlv10YXoW0fh9xy Fp8SRnFlH5nkZzNa06qKMsDBI51u6fQ39WjOTZPuCL68OX0ZapiFdPY2M G65JDkVszESdOOwseIyJHgGBRfy66ZOIWHSnaE2KGJzZJ5OBnPowqB8V+ Mreu8qk4wOnG/C7Ib6ULdS4d3HL9ibbhVjkSUCmnbeYHO1MP6//IMj1+g A==; X-IronPort-AV: E=McAfee;i="6600,9927,10916"; a="391331282" X-IronPort-AV: E=Sophos;i="6.04,256,1695711600"; d="scan'208";a="391331282" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2023 18:24:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10916"; a="805848827" X-IronPort-AV: E=Sophos;i="6.04,256,1695711600"; d="scan'208";a="805848827" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orsmga001.jf.intel.com with ESMTP; 06 Dec 2023 18:24:15 -0800 From: Lu Baolu <baolu.lu@linux.intel.com> To: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>, Robin Murphy <robin.murphy@arm.com>, Jason Gunthorpe <jgg@ziepe.ca>, Kevin Tian <kevin.tian@intel.com> Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu <baolu.lu@linux.intel.com> Subject: [PATCH 1/1] iommu: Set owner token to sva and nested domains Date: Thu, 7 Dec 2023 10:19:38 +0800 Message-Id: <20231207021938.306738-1-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 06 Dec 2023 18:27:12 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784588308014938392 X-GMAIL-MSGID: 1784588308014938392 |
Series |
[1/1] iommu: Set owner token to sva and nested domains
|
|
Commit Message
Baolu Lu
Dec. 7, 2023, 2:19 a.m. UTC
Commit a9c362db3920 ("iommu: Validate that devices match domains") added
an owner token to an iommu_domain. This token is checked during domain
attachment to RID or PASID through the generic iommu interfaces.
The sva and nested domains are attached to device or PASID through the
generic iommu interfaces. Therefore, they require the owner token to be
set during allocation. Otherwise, they fail to attach.
Set the owner token for sva and nested domains.
Fixes: a9c362db3920 ("iommu: Validate that devices match domains")
Cc: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
drivers/iommu/intel/nested.c | 1 +
drivers/iommu/iommu.c | 1 +
2 files changed, 2 insertions(+)
Comments
On 2023-12-07 2:19 am, Lu Baolu wrote: > Commit a9c362db3920 ("iommu: Validate that devices match domains") added > an owner token to an iommu_domain. This token is checked during domain > attachment to RID or PASID through the generic iommu interfaces. > > The sva and nested domains are attached to device or PASID through the > generic iommu interfaces. Therefore, they require the owner token to be > set during allocation. Otherwise, they fail to attach. Oops, I missed that iommu_sva_domain_alloc() is a thing - when did we get such a confusing proliferation of domain allocation paths? Sigh... I think we should set the owner generically there, since presumably it's being missed for SMMUv3/AMD/etc. SVA domains as well. Nested domains are supposed to be OK since both ->domain_alloc_user callsites are covered, or is there some other sneaky path I've also missed? Thanks, Robin. > Set the owner token for sva and nested domains. > > Fixes: a9c362db3920 ("iommu: Validate that devices match domains") > Cc: Robin Murphy <robin.murphy@arm.com> > Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> > --- > drivers/iommu/intel/nested.c | 1 + > drivers/iommu/iommu.c | 1 + > 2 files changed, 2 insertions(+) > > diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c > index b5a5563ab32c..014d4a4e7586 100644 > --- a/drivers/iommu/intel/nested.c > +++ b/drivers/iommu/intel/nested.c > @@ -108,6 +108,7 @@ struct iommu_domain *intel_nested_domain_alloc(struct iommu_domain *parent, > domain->s1_cfg = vtd; > domain->domain.ops = &intel_nested_domain_ops; > domain->domain.type = IOMMU_DOMAIN_NESTED; > + domain->domain.owner = &intel_iommu_ops; > INIT_LIST_HEAD(&domain->devices); > INIT_LIST_HEAD(&domain->dev_pasids); > spin_lock_init(&domain->lock); > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index 0d25468d53a6..d0a28667479a 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -3617,6 +3617,7 @@ struct iommu_domain *iommu_sva_domain_alloc(struct device *dev, > domain->type = IOMMU_DOMAIN_SVA; > mmgrab(mm); > domain->mm = mm; > + domain->owner = ops; > domain->iopf_handler = iommu_sva_handle_iopf; > domain->fault_data = mm; >
On Thu, Dec 07, 2023 at 09:56:10AM +0000, Robin Murphy wrote: > On 2023-12-07 2:19 am, Lu Baolu wrote: > > Commit a9c362db3920 ("iommu: Validate that devices match domains") added > > an owner token to an iommu_domain. This token is checked during domain > > attachment to RID or PASID through the generic iommu interfaces. > > > > The sva and nested domains are attached to device or PASID through the > > generic iommu interfaces. Therefore, they require the owner token to be > > set during allocation. Otherwise, they fail to attach. > > Oops, I missed that iommu_sva_domain_alloc() is a thing - when did we get > such a confusing proliferation of domain allocation paths? Sigh... We have alot of different kinds of domains now, APIs that are giant multiplexers are not good. What I've been wanting to do for a while is to have the drivers call a helper to allocate their domain struct and the helper would initialize the common iommu_domain instead of doing this after the op returns. This is more typical kernel pattern and avoids some of the confusion about when struct members are valid or not (notice some of driver code needs iommu_domain stuff set earlier and we confusingly initialize things twice :() > I think we should set the owner generically there, since presumably it's > being missed for SMMUv3/AMD/etc. SVA domains as well. Nested domains are > supposed to be OK since both ->domain_alloc_user callsites are covered, or > is there some other sneaky path I've also missed? Indeed, I also think the first hunk is not needed, the second hunk was missed. Jason
On 12/7/23 9:36 PM, Jason Gunthorpe wrote: > On Thu, Dec 07, 2023 at 09:56:10AM +0000, Robin Murphy wrote: >> On 2023-12-07 2:19 am, Lu Baolu wrote: >>> Commit a9c362db3920 ("iommu: Validate that devices match domains") added >>> an owner token to an iommu_domain. This token is checked during domain >>> attachment to RID or PASID through the generic iommu interfaces. >>> >>> The sva and nested domains are attached to device or PASID through the >>> generic iommu interfaces. Therefore, they require the owner token to be >>> set during allocation. Otherwise, they fail to attach. >> Oops, I missed that iommu_sva_domain_alloc() is a thing - when did we get >> such a confusing proliferation of domain allocation paths? Sigh... > We have alot of different kinds of domains now, APIs that are giant > multiplexers are not good. > > What I've been wanting to do for a while is to have the drivers call a > helper to allocate their domain struct and the helper would initialize > the common iommu_domain instead of doing this after the op > returns. This is more typical kernel pattern and avoids some of the > confusion about when struct members are valid or not (notice some of > driver code needs iommu_domain stuff set earlier and we confusingly > initialize things twice :() > >> I think we should set the owner generically there, since presumably it's >> being missed for SMMUv3/AMD/etc. SVA domains as well. Nested domains are >> supposed to be OK since both ->domain_alloc_user callsites are covered, or >> is there some other sneaky path I've also missed? > Indeed, I also think the first hunk is not needed, the second hunk was > missed. Oh, yes! I overlooked that iommufd has already done that for nested domain. I will update it with a v2. Best regards, baolu
diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c index b5a5563ab32c..014d4a4e7586 100644 --- a/drivers/iommu/intel/nested.c +++ b/drivers/iommu/intel/nested.c @@ -108,6 +108,7 @@ struct iommu_domain *intel_nested_domain_alloc(struct iommu_domain *parent, domain->s1_cfg = vtd; domain->domain.ops = &intel_nested_domain_ops; domain->domain.type = IOMMU_DOMAIN_NESTED; + domain->domain.owner = &intel_iommu_ops; INIT_LIST_HEAD(&domain->devices); INIT_LIST_HEAD(&domain->dev_pasids); spin_lock_init(&domain->lock); diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 0d25468d53a6..d0a28667479a 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3617,6 +3617,7 @@ struct iommu_domain *iommu_sva_domain_alloc(struct device *dev, domain->type = IOMMU_DOMAIN_SVA; mmgrab(mm); domain->mm = mm; + domain->owner = ops; domain->iopf_handler = iommu_sva_handle_iopf; domain->fault_data = mm;