Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1731934rwl; Fri, 31 Mar 2023 16:09:04 -0700 (PDT) X-Google-Smtp-Source: AKy350ZNPIRr/wJLWdBP2UM7AdziUZ+Hfk2TYzyWmYDlU8/+GSoUqxoYAU3a32IBiyA0U6GSUm6d X-Received: by 2002:a17:902:7c0d:b0:1a0:7663:731b with SMTP id x13-20020a1709027c0d00b001a07663731bmr25107898pll.5.1680304144001; Fri, 31 Mar 2023 16:09:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680304143; cv=none; d=google.com; s=arc-20160816; b=BjtV20AaJKPpXptDK6lo2uh+nDZ7sJPihXWrqH1agkunG45HQLsVQgFobDHFTMv6ef qTHM4RbaaA0K5mSWlOfrWlkfJ/YQRbn/k9yOy4bPc1RJmi4RinN/0vSgPohowYPbh6Wv uU3ZL98iCbYj7jLuXs7Ctwd80HC8MzuiLFoMjVcU0gqOwfFHXDKL+H9sxT9wQiBduETY FL52dx0acoXSDJH9pQjElAxSrg7ZXkTGF88CaG2DsiANysdxKHGrvtqn+z+rlBqgq+dd ES1ALtuil9Nz/5eEVmkPAfGyA+uNyVKSi7dua0EFJx0pTyvc7Qwbc85Z6G9WGE57XlYj 11mQ== 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=WQYKodGoCJL9HFugsTnV1weyXXnrsX3AX+hci2PQyaa/3hxi4Fu+UW+lwavmcZUi26 Uf5W1URA6tCoOCwXy08jYoLOxv0IgRLveRJrnBdwk6seRIgAkaaApVMXWiwX2Z3sT7Am 7hdjGMg2HAUT3kIN9IfKaxh9GTthKbkAIIT9tKb4sWEZzGrmaBOixKicW8hrlolfMlEx rkprwTER+wJYqGFhP/PFyFuCbQQgawZtenlk0yKqkz/94OVxAbv1kHjuX7RbmKcIA+rd GhCF/2VX0LWobJmpZ0dbmRDY/dY+DKLRG+S6Jpgj/2t+QenwCRnA5+TFbx2RSxjt2uRH r2aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=A8SohF5c; 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 b24-20020a17090a551800b0023033ddad2fsi7518735pji.73.2023.03.31.16.08.53; Fri, 31 Mar 2023 16:09:03 -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=A8SohF5c; 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 S233207AbjCaXHu (ORCPT + 99 others); Fri, 31 Mar 2023 19:07:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233099AbjCaXHg (ORCPT ); Fri, 31 Mar 2023 19:07:36 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B54411A948; Fri, 31 Mar 2023 16:07:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680304055; x=1711840055; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uSXXj/CzihsdqWSIfoULHyCBzlYtwHCX/EZVzgaBP38=; b=A8SohF5c3mkz7tyC+dl7HZ28bZjPtx1Eq6coP8QXChqS98BohuSvgHjT rBI4OEjKEATuyUb74K6Mc2rv4qcuemDTS3RJsl4erES3Ai/ZI1m0MQRaX 5rdcm40gmKsZp/ytqwPmnQlaqCwc44mcrmmyrUIdSLw18mgFbkGHD3VEC AkQH/Yltmu0cfzWdqUSzsMYW44AKbu8BubRKbcShWjIhFYdE3wOvqxWBe 6MMm3CmzhQkHRidjxgpXxFIFSyAxYD//fhQvYeK78iLqYFoYdU+6G4IbZ RRO2Yvbeqz8MKXbkm3lKffumtaykN0dNIQqVnkfM6A41br/iuKFTgS0Tb g==; X-IronPort-AV: E=McAfee;i="6600,9927,10666"; a="343245159" X-IronPort-AV: E=Sophos;i="5.98,307,1673942400"; d="scan'208";a="343245159" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Mar 2023 16:07:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10666"; a="717888352" X-IronPort-AV: E=Sophos;i="5.98,307,1673942400"; d="scan'208";a="717888352" Received: from srinivas-otcpl-7600.jf.intel.com (HELO jacob-builder.jf.intel.com) ([10.54.39.106]) by orsmga001.jf.intel.com with ESMTP; 31 Mar 2023 16:07:33 -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 v3 6/7] iommu/vt-d: Implement set_dev_pasid domain op Date: Fri, 31 Mar 2023 16:11:36 -0700 Message-Id: <20230331231137.1947675-7-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230331231137.1947675-1-jacob.jun.pan@linux.intel.com> References: <20230331231137.1947675-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,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,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