Received: by 2002:ac8:156:0:b0:3e0:cd10:60c8 with SMTP id f22csp2296944qtg; Mon, 3 Apr 2023 14:49:17 -0700 (PDT) X-Google-Smtp-Source: AKy350YQJ6KaXWavbo6uZNlJ+JjbtWlapThC1rGvDO8/ddfSm8B6kWO69wI/3wAmMCoBhIq5X4rm X-Received: by 2002:a17:907:7859:b0:931:d8db:8a2f with SMTP id lb25-20020a170907785900b00931d8db8a2fmr73765ejc.58.1680558557468; Mon, 03 Apr 2023 14:49:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680558557; cv=none; d=google.com; s=arc-20160816; b=G7/g24t5H35GxAuRZYwv7jlouMzTzt/WdnEJiVgDDDeDo3/L1UwVtxvMqkB0qXNDS+ 6EdE6Y4thezo9sixyrtLVFNchMjKQVhSqdPuUCDlR96e81ByRH2BJwI5lcx2WgRaDtdX OZe0y40F/WLVU5/uvKwZqNjPIbGsGkHTGNB+xeeGZZCsMODxvDfh7+LGEmxXAScIS4VV 1sYyArxEblN1v7pbSEjpdEhMRAe0Q+AUqkG1+Ez7+Kk8+x6Wd3EmpVPvRSbEMC8kLCJd XvQSks4MOIs/YVC1UhO5K4uSBgnvvIBxkO7DBdtSAUIdT7/uzgQrtNAgPAUy+MrWWwSd SRcA== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=TzgrVxaJPV2cJ2QZK0XK1+L6krq9ZveOg4p/bHK49bw=; b=a/H0agrTzNHo3ddZCyD8kHSR+wMCDLl0/+KSY4qnTJ2qPLr4qG+ChLAE9GGte3koBH WXch0n/CGN4aKDu5WQgVRTdI8W4exvwk8vjWN9NwfyPchM5wK12HoCPkCVtZ2KD10zBh WNCP3lqgDF8o2oRsPO1NT2tBUWWTfYOZy7z1+Hvrh8g7wptPJ3Qqwm5f0cBxLXMiQPPc EHYI6u3OlACf7ybtJOJ0DQ8yvE3CDt02A/rl5QGUjrHvXeXa2hEqjAN9AVCV4Bv1rdDF AXgj5st9wsDDC/drYhqO0g5NCBsOexRG3czg7KUL3C4dHOQXkiVuxeTuOYGm3JLlV3OL R4zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gakw99Og; 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 jj13-20020a170907984d00b00920964e7219si7988223ejc.544.2023.04.03.14.48.52; Mon, 03 Apr 2023 14:49:17 -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=gakw99Og; 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 S233413AbjDCVpk (ORCPT + 99 others); Mon, 3 Apr 2023 17:45:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232822AbjDCVpi (ORCPT ); Mon, 3 Apr 2023 17:45:38 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DBB849D9; Mon, 3 Apr 2023 14:45:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680558305; x=1712094305; h=date:from:to:cc:subject:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kNRta8Lnta0mBFF+JAUbDr7was+Q3+2h+SR8Tx/D7kI=; b=gakw99Og2P4emYXvml4wnQnqtInWQ5t5N6tFTcdfUTgFIwi9owWc9iPm 8GZ1JfkoCLgow6126a3Sd6un4wRHn8Q2vczixEbjtsM/fr4ofp15fDaaE lkFEOoGo6N4RVBMQgibvSLGsyVGaXPDwzRF1x5Jy1Zs1U47dyR/TyVqMn itjFKdgIpB51MMy4bOdkaqtspVdaupW7OIge11o3InGj3s+GogoVKNf69 TF3RVnYjLqSROKT+Ydci7KD8Fkx1q1Bm/EhK3TE19Ma5rJHhqWo5lHt83 d1K1atb3CN2XxChpFy8RlTAfhZJXdC3AVHvcpdjhAcVky4cGC27vm58lG A==; X-IronPort-AV: E=McAfee;i="6600,9927,10669"; a="404776413" X-IronPort-AV: E=Sophos;i="5.98,315,1673942400"; d="scan'208";a="404776413" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2023 14:44:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10669"; a="755406809" X-IronPort-AV: E=Sophos;i="5.98,315,1673942400"; d="scan'208";a="755406809" Received: from jacob-builder.jf.intel.com (HELO jacob-builder) ([10.24.100.114]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2023 14:44:21 -0700 Date: Mon, 3 Apr 2023 14:48:27 -0700 From: Jacob Pan To: Baolu Lu Cc: LKML , iommu@lists.linux.dev, Robin Murphy , Jason Gunthorpe , Joerg Roedel , dmaengine@vger.kernel.org, vkoul@kernel.org, Will Deacon , David Woodhouse , Raj Ashok , "Tian, Kevin" , Yi Liu , "Yu, Fenghua" , Dave Jiang , Tony Luck , "Zanussi, Tom" , jacob.jun.pan@linux.intel.com Subject: Re: [PATCH v3 6/7] iommu/vt-d: Implement set_dev_pasid domain op Message-ID: <20230403144827.7b2c1ccb@jacob-builder> In-Reply-To: References: <20230331231137.1947675-1-jacob.jun.pan@linux.intel.com> <20230331231137.1947675-7-jacob.jun.pan@linux.intel.com> Organization: OTC X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 Hi Baolu, On Sat, 1 Apr 2023 21:48:36 +0800, Baolu Lu wrote: > On 2023/4/1 7:11, Jacob Pan wrote: > > 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; > > As the domain ID will be set to the pasid entry, need to get a refcount > of the domain ID. Call domain_attach_iommu() here, and release it after > the pasid entry is torn down. dmar_domain_attach_device_pasid() below will call domain_attach_iommu() and release in intel_iommu_remove_dev_pasid(). The previous patch has consolidated the code path with device attachment. would it be sufficient? > > + 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, > > Best regards, > baolu Thanks, Jacob