Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp517736imn; Tue, 26 Jul 2022 02:05:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s63+YCZZ54oGWe6rGHRlGXw6ks65c1gWyj2klOs7GIIt4ZcmZd9oSifBMl1UwFDeumC9vm X-Received: by 2002:aa7:db9a:0:b0:43a:76bf:5401 with SMTP id u26-20020aa7db9a000000b0043a76bf5401mr17584627edt.244.1658826299979; Tue, 26 Jul 2022 02:04:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658826299; cv=none; d=google.com; s=arc-20160816; b=HIG89950mMFM1mWlB560fpx2mcxo/mtV4ZSrsk1fRmx8ZCQrwpELdzf718b2hWlG0i iXH4PJxq81pYIU2ZlsWUyJmWlh5nEuY1yF376y9o5i7OKwe+SehVogvsZ3hENuvZ3a8S LZP6XGyZwHw+JG9QVoAUq/P5IwP9TeydCuLxgpLI/e4C3ePdfTQ+wVlTDHH5/cAnvM86 SGRGcjR34U2VRMA8YMz8FGJ1Hhiw7UDaVyN0poww/w19a/CzSvNKmEIjogLKYWB4YzXG Ai59zSkPE/ZCMwGF67j+aIE+I9pg1VXB4uTMf0Vr219Hcf/OT3/6VPGt8XQq7MZsnbZ2 vSng== 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=Sfjh8AdH+FDF5UMtY07C/1EKhTJ2lOCtA4Otb+xz7Ik=; b=vkfsZlu/8nF25ffzu5OON2uV5rcuMuVdsDAX8lMx3Hzc/E4AR89ryMppRgcWPJbE0J iUv6KXoLIASlW8izd2E8wGrlURIkU/zP5791D+SHKTiDhFdBUsIwW0LmRrYmmDHLTwQt r9s/d1I+jdAWpCenBNp043BrHrlvVTRwFjysophMsJI7HFKNNwv16UL8tuUhg4yvq9Ob DLYj76bS7yYx/XhdkzL+ZGN+lfN/JF+Ixs8HG6kLoEiYRbPgLzocbmPCTB3VFSNogvdc uo3jG12JsjSWV9MMxhk5esY3nsfZ08yV/Yt/Mvc/WCfValdVRUCdu8vucv/2NV1hED2P M5HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dTNN8ccP; 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 n9-20020a05640205c900b0043bc60cc60dsi18076398edx.188.2022.07.26.02.04.35; Tue, 26 Jul 2022 02:04:59 -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=dTNN8ccP; 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 S238496AbiGZIrJ (ORCPT + 99 others); Tue, 26 Jul 2022 04:47:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238337AbiGZIrI (ORCPT ); Tue, 26 Jul 2022 04:47:08 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 761AD2FFF0 for ; Tue, 26 Jul 2022 01:47:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658825227; x=1690361227; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=FTdA1qmyryouVTB4vR/QuyKSs43K1/v260tWZ8UUxt8=; b=dTNN8ccPXKBbyjKW6ShqXDoX9+KXSdTBL0ihfHwAjuF7NiJA/AqNCa5b 94JmdfsSlrnvOZM4lZjecJFhSVZX6VJCmJvIKsAIDuiHo8bV6AI2rcdNW 3M0vd6PGEWPHu6QjbcbvQa4tgNSC48C/cPGKvx43Otj4edFp12VLaZa3Q Xu6S4QgcmPiOcWqVJvYdvW8k63EY1PAkNdJPV8QG9U6G5bwaSKrikU9y/ h4jLP0dZQotJDSnjSBZjW0ZMgPd3kLxTkIWD3yMwSixMFbXOWEw6Cu8IO IJPhmQ9iNmtRCmTu8rGeaRoofeMW4fucOiA1UDGV2I4gGyv1lQ3NScNrZ w==; X-IronPort-AV: E=McAfee;i="6400,9594,10419"; a="287910832" X-IronPort-AV: E=Sophos;i="5.93,193,1654585200"; d="scan'208";a="287910832" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jul 2022 01:47:07 -0700 X-IronPort-AV: E=Sophos;i="5.93,193,1654585200"; d="scan'208";a="575404438" Received: from hzhi-mobl4.ccr.corp.intel.com (HELO [10.255.30.159]) ([10.255.30.159]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jul 2022 01:47:02 -0700 Message-ID: Date: Tue, 26 Jul 2022 16:47:00 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Cc: baolu.lu@linux.intel.com, "Tian, Kevin" , Joerg Roedel , Christoph Hellwig , "Raj, Ashok" , Will Deacon , Robin Murphy , Jean-Philippe Brucker , "Jiang, Dave" , Vinod Koul , Eric Auger , "Liu, Yi L" , "Pan, Jacob jun" , Zhangfei Gao , "Zhu, Tony" , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v10 08/12] iommu/sva: Refactoring iommu_sva_bind/unbind_device() Content-Language: en-US To: Jason Gunthorpe References: <20220705050710.2887204-1-baolu.lu@linux.intel.com> <20220705050710.2887204-9-baolu.lu@linux.intel.com> <20220723142650.GH79279@nvidia.com> <20220725144758.GG3747@nvidia.com> From: Baolu Lu In-Reply-To: <20220725144758.GG3747@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.6 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 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/7/25 22:47, Jason Gunthorpe wrote: > On Mon, Jul 25, 2022 at 06:22:06PM +0800, Baolu Lu wrote: >> On 2022/7/25 15:50, Tian, Kevin wrote: >>>> From: Baolu Lu >>>> Sent: Sunday, July 24, 2022 9:48 PM >>>>> >>>>> The API is really refcounting the PASID: >>>>> >>>>>> +struct iommu_sva *iommu_sva_bind_device(struct device *dev, >>>>>> + struct mm_struct *mm); >>>>>> +void iommu_sva_unbind_device(struct iommu_sva *handle); >>>>> >>>>> So what you need to do is store that 'iommu_sva' in the group's PASID >>>>> xarray. >>>>> >>>>> The bind logic would be >>>>> >>>>> sva = xa_load(group->pasid, mm->pasid) >>>>> if (sva) >>>>> refcount_inc(sva->users) >>>>> return sva >>>>> sva = kalloc >>>>> sva->domain = domain >>>>> xa_store(group->pasid, sva); >>>> >>>> Thanks for the suggestion. It makes a lot of sense to me. >>>> >>>> Furthermore, I'd like to separate the generic data from the caller- >>>> specific things because the group->pasid_array should also be able to >>>> serve other usages. Hence, the attach/detach_device_pasid interfaces >>>> might be changed like below: >>>> >>>> /* Collection of per-pasid IOMMU data */ >>>> struct group_pasid { >>>> struct iommu_domain *domain; >>>> void *priv; >>>> }; >>>> >>> >>> Is there any reason why pasid refcnt is sva specific and needs to be >>> in a priv field? >> >> I am going to store the iommu_sva data which represents the bind >> relationship between device and domain. > > Why do you need that? > > If you are starting at the pasid xarray then you already know the > group/device, so we don't need to store it again. > > The only thing needed is the refcount so just store a refcount in this > structure and be done with it. If someone needs to add something later > then we can use a union or something, but right now adding an untagged > void * is bad. Fair enough. I will update it accordingly. Best regards, baolu