Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp172960ioo; Thu, 26 May 2022 00:38:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/uX7zBJp52tiJ1caTQ365C5NaY8QGyA1MLNVzAbeo+f85GnrbLdsngQxb53IMAAS6OL3T X-Received: by 2002:a17:907:7291:b0:6f9:a3b5:7ce4 with SMTP id dt17-20020a170907729100b006f9a3b57ce4mr32774355ejc.642.1653550713067; Thu, 26 May 2022 00:38:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653550713; cv=none; d=google.com; s=arc-20160816; b=IWg2Hp0XbA9wzDEwB/maUAhR8apa8CkxSbLrDjJegbwKGhhQPFZ3142L8P5wMphCJU YHCS+MMSUwSqcyFP1cHPakgGHya/8WQ1kHbaGcST+kCwfMg/YpQMzorBVMW+akLuCmW0 XA1jJh1h5L1lfdnkoTdvrf7oKi+jhyyl1yCqAkcyin/7Guy0pvuqyUvMq0uYjJprgV72 YYQvd9VSewYNxenX+pRl6Hiwi7IrfdP+nDVtdxMu2fBb35tfQc5iLCphxpnjiO2R68QU elDGyCAYOVqb0qZPBkie2LAqseX/HaF028Q44D3Oo6jLweWsN4qo0Tn2am6GoCHd6oeY iJWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Fka4U6j+4zi9FbIDyA05x8GB1WOLwNpWSqnnKjoitMg=; b=HfKNlt4AfJi2wzXPuq5SYYWnCTWUZ64XL+hZNC36EVU2ns/CLqMohNEQ5DAOHIAKiw CAZKuDeWAzwUVwUEwdB6e4HwVLxx4gfPt30pq3zhQbd3ogDzMPaZqVRs31oBhqDQ/sFA O/AOjRTEJm7iSf8NpqwKTeVqlGMRPVZvxZLUr1gxNZP0g9wTi0nHmJF2rV6q8npFm278 PzLoqwmKZj5GYE+bnZMCpRrSdSuNs33so9og5S9KwoLT5iYmkaoRR0661JNWfNbBN6yX 2hDwaMqBiTtJQLFj6JvcyiLiKCqYIrQvxW5aEp+QMvui+DvVdvCS/wbbumwzaAGq1QPo 5vbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oHhiDqqj; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mp9-20020a1709071b0900b006f42491e0a0si905029ejc.655.2022.05.26.00.38.06; Thu, 26 May 2022 00:38:33 -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=@linaro.org header.s=google header.b=oHhiDqqj; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244334AbiEYHaV (ORCPT + 99 others); Wed, 25 May 2022 03:30:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244330AbiEYHaR (ORCPT ); Wed, 25 May 2022 03:30:17 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8A94377F1 for ; Wed, 25 May 2022 00:30:15 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id ck4so35605713ejb.8 for ; Wed, 25 May 2022 00:30:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Fka4U6j+4zi9FbIDyA05x8GB1WOLwNpWSqnnKjoitMg=; b=oHhiDqqjJeC/j21AryPAJw+WSqZB6TeRWYeIE7HKoSC+q9ja0g9HSBtnvBHMYu/4qK GzhRInTPX2MGtp94iRzu8dw3QhI5MhKJQTalAlQ6dviuvCCuubtzBaO6QX1IKKbSNbcd 4Xbl3bMgqUoRswyFyuY+SGAzfrlG8dOOQqN62WA0cEhXzpohiCk/47gqpCEVxQwEEcmy hwYBLsRsF48EpqUqYVAooTr+CVUgZ68Xngs+fIZAodyUh68Bak1MYSTwbwQk9lesQzFG BUyXQpf8bEre+tzSh8SxbBN8eCpcT4xtFd2Ueyz+oaZbXvk6evEIWxJ5qJgI/PkSyR4N tPyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Fka4U6j+4zi9FbIDyA05x8GB1WOLwNpWSqnnKjoitMg=; b=Pqx4P0WdBPjtqMvMWKJYKk+vOxamZAgy8L5ekkBh6uVRn0bnG2AkcvMmfGwHCDPzMV CphjltJUm6olJK0dd/kvtQ0IsJSCXPjPiEMGCJPvmMDOEY5QIxe9uiuSMdMuzBpbT339 0hoSW1XUanYPETq36ar4buwdowSymGICxf+plvavPvIk84DvBQ/q+IAdAnMaM23X380e zcu4MvvMRqIcWtkNH14bex2GgbrBEokx5DmNhUBVz8C1u7FqaJDMFGLauDsQV6w9U8Xc zuT1TTXsJWIk+d/OcltGvq9OMqSSNgv7xZBrx4VTJ2PRBq6g538F5NXcilY4kDcBhpmp QNmA== X-Gm-Message-State: AOAM533FExVR1z5CO5XCsOwvPsK6FcmuTJ/vVoTVTZka1lrNTFSKOQoX lPcRx5G2rCTvRbsRuM4bLs2clA== X-Received: by 2002:a17:907:d86:b0:6ff:1557:a080 with SMTP id go6-20020a1709070d8600b006ff1557a080mr770913ejc.678.1653463814422; Wed, 25 May 2022 00:30:14 -0700 (PDT) Received: from myrica (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id q14-20020a50c34e000000b0042ba8658d1csm1095864edb.73.2022.05.25.00.30.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 00:30:14 -0700 (PDT) Date: Wed, 25 May 2022 08:29:49 +0100 From: Jean-Philippe Brucker To: "Tian, Kevin" Cc: Lu Baolu , Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , "Raj, Ashok" , Will Deacon , Robin Murphy , Jean-Philippe Brucker , "Jiang, Dave" , Vinod Koul , Eric Auger , "Liu, Yi L" , "Pan, Jacob jun" , "iommu@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v7 06/10] iommu/sva: Refactoring iommu_sva_bind/unbind_device() Message-ID: References: <20220519072047.2996983-1-baolu.lu@linux.intel.com> <20220519072047.2996983-7-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,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 Wed, May 25, 2022 at 02:04:49AM +0000, Tian, Kevin wrote: > > From: Jean-Philippe Brucker > > Sent: Tuesday, May 24, 2022 6:58 PM > > > > On Tue, May 24, 2022 at 10:22:28AM +0000, Tian, Kevin wrote: > > > > From: Lu Baolu > > > > Sent: Thursday, May 19, 2022 3:21 PM > > > > > > > > The existing iommu SVA interfaces are implemented by calling the SVA > > > > specific iommu ops provided by the IOMMU drivers. There's no need for > > > > any SVA specific ops in iommu_ops vector anymore as we can achieve > > > > this through the generic attach/detach_dev_pasid domain ops. > > > > > > set/block_pasid_dev, to be consistent. > > > > > > > + > > > > + mutex_lock(&iommu_sva_lock); > > > > + /* Search for an existing domain. */ > > > > + domain = iommu_get_domain_for_dev_pasid(dev, mm->pasid); > > > > + if (domain) { > > > > + sva_domain = to_sva_domain(domain); > > > > + refcount_inc(&sva_domain->bond.users); > > > > + goto out_success; > > > > + } > > > > + > > > > > > why would one device/pasid be bound to a mm more than once? > > > > Device drivers can call bind() multiple times for the same device and mm, > > for example if one process wants to open multiple accelerator queues. > > > > Is it clearer to have a sva_bond_get/put() pair instead of calling > bind() multiple times here? I don't think it's clearer, and it would force device drivers to keep track of {dev, mm} pairs, when the IOMMU subsystem already does that. At the moment a device driver calls bond = iommu_sva_bind_device(dev, mm) for each ADI that it wants to assign to userspace. If a process happens to want multiple ADIs on one device, then the {dev, mm} parameters are the same and bind() returns the same bond. Since the IOMMU driver needs to track these anyway, it might as well refcount them. Thanks, Jean