From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FC20C43334 for ; Mon, 25 Jul 2022 10:22:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233419AbiGYKWR (ORCPT ); Mon, 25 Jul 2022 06:22:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230283AbiGYKWL (ORCPT ); Mon, 25 Jul 2022 06:22:11 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55F7CB84C for ; Mon, 25 Jul 2022 03:22:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658744530; x=1690280530; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=wAXUudd2bYpf3nYYKav//ZqBy0T3UuLekipqsksLhYI=; b=C1BomNv+A8WJyUXri5zr5E7MpLWib0orDjp+PFkq63wcjeQB3TyC9q8j QWKlww5+iC1r0v02jTqk3Y/0TRIh/lKOjcv6mophdpH+cqVhDwGRTV9v9 eTRapJHZOhQlTA6/6o70r3a2gHl15GsvIyVU83pulURzPrdCEwb81nQK/ rY/0CM5gHsJ3/u2NZ5o3GQM7hYcTJx260Pof+Bh25vJ6pxJVl03zNnylJ /GVm4LXKcpyQDGT2Q+BVvYvy0NU4Mu40E+eWh/GOW01BZOs2zWqreYeua Ciwkf9njScFy1xGoimYqbRDtjPW/sllvldryKBTXxHSdSeZswYA/LTOap A==; X-IronPort-AV: E=McAfee;i="6400,9594,10418"; a="349362690" X-IronPort-AV: E=Sophos;i="5.93,192,1654585200"; d="scan'208";a="349362690" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2022 03:22:09 -0700 X-IronPort-AV: E=Sophos;i="5.93,192,1654585200"; d="scan'208";a="658130002" Received: from liangk-mobl.ccr.corp.intel.com (HELO [10.255.30.67]) ([10.255.30.67]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2022 03:22:06 -0700 Message-ID: Date: Mon, 25 Jul 2022 18:22:06 +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, 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: "Tian, Kevin" , Jason Gunthorpe References: <20220705050710.2887204-1-baolu.lu@linux.intel.com> <20220705050710.2887204-9-baolu.lu@linux.intel.com> <20220723142650.GH79279@nvidia.com> From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Best regards, baolu