Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1178703rwl; Fri, 7 Apr 2023 11:07:16 -0700 (PDT) X-Google-Smtp-Source: AKy350YP0m4dMNwbVc09bv/C+xsjmX6DaxoQwaOyDGCwlq9nUsMm456zEilu9/2ax/zEgw9LN1Jb X-Received: by 2002:a17:902:ea0a:b0:19a:b588:6fe2 with SMTP id s10-20020a170902ea0a00b0019ab5886fe2mr10859434plg.13.1680890836154; Fri, 07 Apr 2023 11:07:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680890836; cv=none; d=google.com; s=arc-20160816; b=IWxs4p52KLZ3HBjYwVWKYRBErhVI9BCv9wMDSInkf4+abhIJCwZIpCwRbu3nm1LgKD PEDsiRJ2+YGQHvVqIqeXy+nN39PydNnSJPTDcs9YYchFLWH4TmBmkV+wRHYvw1TptSl1 +QEhRZClMbKas+eHtSULcZwLcYgOcrqBz6XqqGm7Y8rMAOhOhieJAFxV4Bqj53NtSbEd RV+NBLEZ+9BbYNTKfnvj/ZTGWeHvZNxEytgYQW7PBxlHCILVU7ZcTMQ6gm1w3drGwOaF f518w38U2sLOeX+TG3LX976ijmwH8lDdLw/9OvhY1RpT687eoxre3lbXPDy343WFAWtq b8jw== 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=IhYO/q1CJYBm0flx4huprOLTDwM5ie1n4f2bfr6Fp4A=; b=Jgem+3QfhQp7pkGmdgameDbxWIzUPsXMkl47+0bVSyvtdueQ9IMSVQiawhpK40y82q ibh6JlCKuTfFNx2PODWs1ESpZh3El0pdu9ndjnrZ3n1TnuEO2xGZrvqDvXZzm7AE1MeU ESdjcrNeNvXi04CidFblxefd9P2LJvChcdfU0dGcHiE/sD/cyAbNgK/TR5AJ7jSAer8E O95daceCG3WY0Pn8JQvGQZAPYrevyVpqv2q527Q5S3ftqjkZWgf2p/hTquzWGmVb2vcj Y3m13Jhm+RhZ3DD3HgV0TmbojJQNUAjYIy1EFrEsNMu+Qt9fppYQ4qzmhTQe2oQAs7kF ItVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=B9pPDXd5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n2-20020a654882000000b005131739af72si3921101pgs.755.2023.04.07.11.07.04; Fri, 07 Apr 2023 11:07:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=B9pPDXd5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231610AbjDGSCL (ORCPT + 99 others); Fri, 7 Apr 2023 14:02:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231390AbjDGSB5 (ORCPT ); Fri, 7 Apr 2023 14:01:57 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C8BDBB8F; Fri, 7 Apr 2023 11:01:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680890515; x=1712426515; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uSXXj/CzihsdqWSIfoULHyCBzlYtwHCX/EZVzgaBP38=; b=B9pPDXd5A5LkYrD6YXc5hailB3t5/SymGufTyp1BfV3ewuMvESWHqT9D HyQMdGEdWf6mLO3cAjRatfklP9HnBe39mHLkq5tfAH7dTlGIQ7P1PKdXb SkAlyiPzJqNXs/0/z2VToZJ7tKEkZnrXS/0Lykotv3xODCiX8/ilhFWZP C4XueXv3QMWU2qpKJLPjbfb08C50NI9p/J0lZ2t1z6NueQNnOIlJPlNO1 qMeAZ7blygjG8RcILVVTLSP4St1em5sWx7gkxx1Du0Fwb+RsQKdzUc8Hs zXyafJ/nSec9VjjMteiojA2eLnd+cWYY6IHH/6E9P6gyec8sU8kO/Ro4O A==; X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="343046510" X-IronPort-AV: E=Sophos;i="5.98,327,1673942400"; d="scan'208";a="343046510" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2023 11:01:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="776910092" X-IronPort-AV: E=Sophos;i="5.98,327,1673942400"; d="scan'208";a="776910092" Received: from srinivas-otcpl-7600.jf.intel.com (HELO jacob-builder.jf.intel.com) ([10.54.39.106]) by FMSMGA003.fm.intel.com with ESMTP; 07 Apr 2023 11:01:52 -0700 From: Jacob Pan To: LKML , iommu@lists.linux.dev, "Robin Murphy" , Jason Gunthorpe , "Lu Baolu" , Joerg Roedel , dmaengine@vger.kernel.org, vkoul@kernel.org Cc: "Will Deacon" , David Woodhouse , Raj Ashok , "Tian, Kevin" , Yi Liu , "Yu, Fenghua" , Dave Jiang , Tony Luck , "Zanussi, Tom" , Jacob Pan Subject: [PATCH v4 6/7] iommu/vt-d: Implement set_dev_pasid domain op Date: Fri, 7 Apr 2023 11:05:53 -0700 Message-Id: <20230407180554.2784285-7-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230407180554.2784285-1-jacob.jun.pan@linux.intel.com> References: <20230407180554.2784285-1-jacob.jun.pan@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Devices that use ENQCMDS to submit work on buffers mapped by DMA API must attach a PASID to the default domain of the device. In preparation for this use case, this patch implements set_dev_pasid() for the default_domain_ops. If the device context has not been set up prior to this call, this will set up the device context in addition to PASID attachment. Signed-off-by: Jacob Pan --- drivers/iommu/intel/iommu.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 52b9d0d3a02c..1ad9c5a4bd8f 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4784,6 +4784,26 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid) domain_detach_iommu(dmar_domain, info->iommu); } +static int intel_iommu_attach_device_pasid(struct iommu_domain *domain, + struct device *dev, ioasid_t pasid) +{ + struct device_domain_info *info = dev_iommu_priv_get(dev); + struct dmar_domain *dmar_domain = to_dmar_domain(domain); + struct intel_iommu *iommu = info->iommu; + int ret; + + if (!pasid_supported(iommu)) + return -ENODEV; + + ret = prepare_domain_attach_device(domain, dev); + if (ret) + return ret; + + return dmar_domain_attach_device_pasid(dmar_domain, dev, pasid); +} + + + const struct iommu_ops intel_iommu_ops = { .capable = intel_iommu_capable, .domain_alloc = intel_iommu_domain_alloc, @@ -4803,6 +4823,7 @@ const struct iommu_ops intel_iommu_ops = { #endif .default_domain_ops = &(const struct iommu_domain_ops) { .attach_dev = intel_iommu_attach_device, + .set_dev_pasid = intel_iommu_attach_device_pasid, .map_pages = intel_iommu_map_pages, .unmap_pages = intel_iommu_unmap_pages, .iotlb_sync_map = intel_iommu_iotlb_sync_map, -- 2.25.1