Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3558166rwl; Mon, 27 Mar 2023 16:19:18 -0700 (PDT) X-Google-Smtp-Source: AKy350ZkLIvtDd/xF6nAaPu2dQWp0fwGiJqFqwlFJVrqV5v7QNJjst8yd1zTOcV4mk65j7mLCV1r X-Received: by 2002:a17:90b:4a50:b0:23d:21c9:193 with SMTP id lb16-20020a17090b4a5000b0023d21c90193mr14637595pjb.2.1679959158584; Mon, 27 Mar 2023 16:19:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679959158; cv=none; d=google.com; s=arc-20160816; b=iIezCBSY0KdQZgereM7VgYaKG1ZY05I6iT1OHgV/zenmI8DTI8y5v5J/8PnItasmcN LGcM/srwaEeMjZJuYsL5C0p1LsoSEOnAFD3bdWCr7eizXISTnckcVO7Vx1OPit2cqSYJ uViUFN/9S5d/Du+J1rgETJvC65t52OcxY/CiXPmGP9ogUEyRSYwjuTMpBuPr8Wqjfj42 SeLD9440xuPBkd69PK8/14lbV0/Iz5/B9SFfFh3Nwpw7ITw1kuKO79AlfX3lteRZPyu/ ZuTAl+hdoTbOpF10jySwUezLhx/4h7KFICT2ShJMCccEVKkqQRq4wp0kA6WvMzhBU6W5 MEMg== 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=Zc5LLXWJ68euQakeDCF0QoPjMiMoLb1Uqyh2WJhFNy8=; b=IYfmTHffqXgsxXuDNjBrLFZpnBedFDWfnDUgCLTodXkZ2GkHiy6FyYQQR5a0+TmPH5 cDWUaKPlKpWCKcHVWydLpH4+S3ytJVoZQnlK0Opj8N3lVUCdyS1tukpDY66zoYk1RCeh 2LQ10CPQEtgYSbtz3VimjXgU98yTEUsvNXJHnLM0Bi+GNUcwlzHkoEUgIWZD259tLKwt YO62Sx6mt3r/hUFS2Mpcd3emuMieGjg/2DBFBqY4DySUTkGOEX1/0r0Vgm5nGX59n2bC FirVnAj3J2N4+E7uCsvnKKyjNX5ipkU0HedCnnuY5kgZlgM77m5i1u2xArf9SXi4KZ9A NARQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XDG8Cw4f; 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 d19-20020a170903209300b0019e95180a08si26658292plc.59.2023.03.27.16.19.07; Mon, 27 Mar 2023 16:19:18 -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=XDG8Cw4f; 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 S231978AbjC0XRw (ORCPT + 99 others); Mon, 27 Mar 2023 19:17:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230432AbjC0XRm (ORCPT ); Mon, 27 Mar 2023 19:17:42 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 626EE2129; Mon, 27 Mar 2023 16:17:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679959061; x=1711495061; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+aKPPSGltRYTSFQIA0jmfTMfQ61VKUSyWFf8UtKgL5A=; b=XDG8Cw4fUCXXT2VuszsRTfpLFHOC9sz641brUwMaLfFbZlipgM9rEYgs YukmFKA5nWtJH5VxLzr8P5xWwwvJrkm9OuuasTi7U3Nwt4d/3xl3jQM+Q qExifXybV6rql5iFVxUhcHAzP79jPTrqo7HiarIwpW5ehn9pdeABI6QFP Xt4VOtGoQOgI+sonb4Z8taF6psNGuweJ+u+fsBcmRd9L53Pzy9RCR70Ih wSkQsVh+z2b85qLacuPKA1TN2g2JL4sPebUvuzMXWPIRJeE8Cs2O9Zjb5 8dEk3YpmovInVcBaKj8Hf6CpLXb175aMpMGTGr67bZ4GPGwyiA5g2e7Xt g==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="320817335" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="320817335" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 16:17:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="686144737" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="686144737" Received: from srinivas-otcpl-7600.jf.intel.com (HELO jacob-builder.jf.intel.com) ([10.54.39.106]) by fmsmga007.fm.intel.com with ESMTP; 27 Mar 2023 16:17:40 -0700 From: Jacob Pan To: LKML , iommu@lists.linux.dev, Jason Gunthorpe , "Lu Baolu" , Joerg Roedel , dmaengine@vger.kernel.org, vkoul@kernel.org Cc: "Robin Murphy" , "Will Deacon" , David Woodhouse , Raj Ashok , "Tian, Kevin" , Yi Liu , "Yu, Fenghua" , Dave Jiang , Tony Luck , "Zanussi, Tom" , Jacob Pan Subject: [PATCH v2 6/8] iommu/vt-d: Implement set_dev_pasid domain op Date: Mon, 27 Mar 2023 16:21:36 -0700 Message-Id: <20230327232138.1490712-7-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230327232138.1490712-1-jacob.jun.pan@linux.intel.com> References: <20230327232138.1490712-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. Besides PASID attachment, device will also be attached to the domain as the result of this call if the device has not been attached before. 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 0a195136bac7..652ee0ca72da 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4782,6 +4782,26 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid) intel_iommu_detach_device_pasid(domain, dev, pasid); } +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, @@ -4801,6 +4821,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