Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3720012rwe; Mon, 29 Aug 2022 18:49:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR55HV1FuwyafpmoNIp910jeRIHlW4JRPMeJSYFNUChNpjc0rI0w9VfQsZ23W2tVfAsBq71w X-Received: by 2002:a17:906:fc6:b0:72f:d080:416 with SMTP id c6-20020a1709060fc600b0072fd0800416mr15493618ejk.1.1661824182352; Mon, 29 Aug 2022 18:49:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661824182; cv=none; d=google.com; s=arc-20160816; b=YAnSGpo7LFUG8C21ZOFwMVZ789SH83l+QRyajqorKVIgwkRB94AnzREJdnyKXLJhGP 0f+2s/3qX1Ca7hwCvVJKF7PgB68BfL9VCDKgrgku8P41ZFyjQiIrqimKAk5TLlxYK8xP 0grdUmCrCf4pbvpWzI7VRaSEcEm4QCR86PObLSQeknVItbRjSYsfzyabUGwcnMUoUuBW 9aY1iEnMVpUctl2m94qZtUU1hI1L0PRNUkhQA089ljnnVFseL/pJ6iW1+iMQDurW31q9 zx34FPP/zPCmGtJT+2eeEympQTARbQqZDcc820ueiSxrqe7ygUtvB7oYwJ9a9tIGhKwA eLDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=4XlJ0HLt/16UFhO2dISm2AjhZ6nQx1fdRCI9NvchoZQ=; b=ULlFHw2g154mxCoMP9sfcdnCAU2rHQKXqdcp0mxwhRPs9RLxO3PgVHYT9jXq17897y KhQdG3etYtGKK0lBDe8kbWGwEfE4pc7NA0d9oS2ukP7xbk0rIlVLZr7PjkAWZ2bAOO+k EP6f9GXAmb7f90KVPE1Foe+dxnrRgF2eP2kQLOaaQO/s0Bx4wSbMuztV6SAK1pGBEJto 9aw5/Bq/hxh28tLi+jbmKG1USUkhckXzIowK1Gf7Ph+Mvza3MafShn7OrZx42NdFJbWW daWAggtSVixgRjgq4pGkdxNoJ4HtQhOmStgQHBdv93FWTgK1xHhlQcr2OK+g63r0pLnB xxWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="mZPRa/Rn"; 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 m12-20020a170906258c00b0073d1748a820si7137638ejb.199.2022.08.29.18.49.16; Mon, 29 Aug 2022 18:49:42 -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="mZPRa/Rn"; 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 S229513AbiH3BqR (ORCPT + 99 others); Mon, 29 Aug 2022 21:46:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbiH3BqO (ORCPT ); Mon, 29 Aug 2022 21:46:14 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1E637170A; Mon, 29 Aug 2022 18:46:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661823973; x=1693359973; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=g/WWeE3dDMjzGcqcOmiQkfDtGDanYr/MP7cytR+qkDw=; b=mZPRa/RnAgJ/nyKFtRB7qE2cXp/iGGrSiSRjk9a8L2dY3SSj6+9dKQNM tN3S7rsTC3M5FtLCBq1RNxUx80KKnCHwnHd90nmA6QcAe58d8HUAPDrj5 +I0Eua/WlDfoYvYulF6GZtY5WbJ3OnKSbqNp3xW4+GdKZ2hz5kWXRT+JK QLp4xdgrCopiDOQGm0GK6B3ekveDS4N/lXG6jDthdYUUa7yUIbUxXu1xT laTaD1RPnQMtIc532vKOY9Fl5HmoOXuNuLovXC2LZF0imbokHTF5T0z+I 5YCRCKIIYlj4D/xdgUz4JMNQuwtAW0+nTrs/j0X8+8vzibreIRJzzqcOv w==; X-IronPort-AV: E=McAfee;i="6500,9779,10454"; a="295053764" X-IronPort-AV: E=Sophos;i="5.93,274,1654585200"; d="scan'208";a="295053764" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2022 18:46:10 -0700 X-IronPort-AV: E=Sophos;i="5.93,274,1654585200"; d="scan'208";a="672621796" Received: from hhuan14-mobl1.ccr.corp.intel.com (HELO [10.254.215.208]) ([10.254.215.208]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2022 18:46:04 -0700 Message-ID: Date: Tue, 30 Aug 2022 09:46:01 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Cc: baolu.lu@linux.intel.com, Joerg Roedel , Christoph Hellwig , Bjorn Helgaas , Kevin Tian , Ashok Raj , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Dave Jiang , Fenghua Yu , Vinod Koul , Eric Auger , Liu Yi L , Jacob jun Pan , Zhangfei Gao , Zhu Tony , iommu@lists.linux.dev, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v12 07/17] iommu: Try to allocate blocking domain when probing device Content-Language: en-US To: Jason Gunthorpe References: <20220826121141.50743-1-baolu.lu@linux.intel.com> <20220826121141.50743-8-baolu.lu@linux.intel.com> <316f6575-59ea-08e3-aaaf-bc1e4f42a574@linux.intel.com> From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 On 2022/8/30 01:27, Jason Gunthorpe wrote: > On Mon, Aug 29, 2022 at 11:40:24AM +0800, Baolu Lu wrote: >> On 2022/8/26 22:52, Jason Gunthorpe wrote: >>> On Fri, Aug 26, 2022 at 08:11:31PM +0800, Lu Baolu wrote: >>>> Allocate the blocking domain when probing devices if the driver supports >>>> blocking domain allocation. Otherwise, revert to the previous behavior, >>>> that is, use UNMANAGED domain instead when the blocking domain is needed. >>>> >>>> Signed-off-by: Lu Baolu >>>> Tested-by: Zhangfei Gao >>>> Tested-by: Tony Zhu >>>> --- >>>> drivers/iommu/iommu.c | 29 +++++++++++++++++------------ >>>> 1 file changed, 17 insertions(+), 12 deletions(-) >>> This seems like a lot of overhead to allocate these things for every >>> group? >>> >>> Why not add a simple refcount on the blocking domain instead and >>> allocate the domain on the pasid attach like we do for ownership? >> >> I am working towards implementing static instance of blocking domain for >> each IOMMU driver, and then, there's no much overhead to allocate it in >> the probing device path. > > Well, I thought about that and I don't think we can get > there in a short order. Yes. Fair enough. > Would rather you progress this series without > getting entangled in such a big adventure Agreed. I will drop this patch and add below code in the iommu interface: --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3219,6 +3219,26 @@ int iommu_attach_device_pasid(struct iommu_domain *domain, return -ENODEV; mutex_lock(&group->mutex); + + /* + * The underlying IOMMU driver needs to support blocking domain + * allocation and the callback to block DMA transactions with a + * specific PASID. + */ + if (!group->blocking_domain) { + group->blocking_domain = __iommu_domain_alloc(dev->bus, + IOMMU_DOMAIN_BLOCKED); + if (!group->blocking_domain) { + ret = -ENODEV; + goto out_unlock; + } + } + + if (!group->blocking_domain->ops->set_dev_pasid) { + ret = -EOPNOTSUPP; + goto out_unlock; + } + curr = xa_cmpxchg(&group->pasid_array, pasid, NULL, domain, GFP_KERNEL); if (curr) { ret = xa_err(curr) ? : -EBUSY; Currently both ARM SMMUv3 and VT-d drivers use static blocking domain. Hence I didn't use a refcount for blocking domain release here. Best regards, baolu