Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2182098rdb; Tue, 20 Feb 2024 22:27:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXtXFKorJNF27k4Wt9X5gti4mHpOr720l1gxhf1RR6o0OfGJWnNE+I2IuG8AgUe1Lb/JH6C0BwAoLB+cDcIYnH32QvERPGCL9N/BtQVNA== X-Google-Smtp-Source: AGHT+IFMUQz8bO5MgRxEvq/r9zyl5fw0egE0nay5iDcgYDcPtV6ERXTZCbD0FEuVp2Q0NpyaCtQf X-Received: by 2002:a05:6a20:d80e:b0:19e:a2d5:2d7d with SMTP id iv14-20020a056a20d80e00b0019ea2d52d7dmr24839440pzb.37.1708496832982; Tue, 20 Feb 2024 22:27:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708496832; cv=pass; d=google.com; s=arc-20160816; b=Xy3QHj92kW3RzzvFHDG+E7m35nkh4Q5zwVp4MZ7HPBd6lKk91yo2u85SFyRYSnCloF X3ZUr6AdYy6d93b4B6Up5KyGQZXnzZ5LqfzH+bBgip8HjZ63X4k9N1ZcheG5bBfd+tuu rz4/F+TM2RuR6Ylsa9NRI4scT4l95+EP0QZkRAj6skWK2d+BvjdJVyukmqC4gcX7IbP4 3AwcMc3Qc5nhU0iYeBti6u+mQAXALCJTWUPQt9ZxXpdcQ/cgTN2ins6pxegSHfV+r9o7 o09wVnRCNn41NbbS9kqM39n9XJ/xvjuRdqHQ3JTSc0zccxCd7A29R6Fi8IrvcrwIRgQc 7J7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=O4SCakJf3fMGKD4Pc9DX3Fmx60D6/XewjZTTvU4lsUQ=; fh=1pQJhbur9kXqZ6nzx1LYNgE6TKsjfLhG+B8x8scp/Kc=; b=G7AqTMxPHgvnNYyvXAoNhPW8cON6ND4wSKNPHVVCvyI+66b6roUc8k5civuzDVEURz FmuJsX+ZdMY06STU0hwt/WXv2DNaUS8S4Pv2o3Y+JvSR/eD/4JRNighvGTcualTjDo+F 9V+NLE7k6TATmI5ouDigT+s3sFiDvBqvuwxGzAmmszF7FwJdthNtkdHMKMgtJxbEEHL8 js1o4bWjjePw/C8SzDzi66fGeGj7xyHAVuKX4ACTmRyc7WC/KJCPUSriirR0SbPYPFSX 56YsL5SzUyHUTzZZWuwn+RJUWI4OQp4xBvFIe0+kTMW3bJztRm/EU5Icwnx7loUFjKt3 VzQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X+0XEG20; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-74150-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74150-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i4-20020a170902c94400b001dbcf66bd07si6827277pla.189.2024.02.20.22.27.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 22:27:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74150-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X+0XEG20; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-74150-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74150-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A84A62849E9 for ; Wed, 21 Feb 2024 06:27:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C5403A1AF; Wed, 21 Feb 2024 06:27:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="X+0XEG20" Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47A554A1D for ; Wed, 21 Feb 2024 06:27:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708496825; cv=none; b=eQS+PQCrkLdy2Cl8V0YHC/ZiFme2SDZSLn0vmALz4OSnxmE45DGfPENL5o14pZ+A7ifnhqT+YN1I54CGLcVRM/npoTf882DsHxNvEvaj4i0tiU/0zZWzFTAZVNiC9XordAvfw5UhB9JoqGH3IIZwQfSgqQ0Njqn9FaWYisSEAWw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708496825; c=relaxed/simple; bh=/V5T+YQftfD2tRWQGhzHzmXn6qVrJBWkMhBmJM5xGrw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=fnLXwx7h3m0/dVxxxRV/kzbRanO4XAwUunRlkUIIvN+UahtzCvpb8DdyaiHdrx+n50wQrbwcRyM8aTl3zmpmsIx2Xn2yT1l2FP7RLifsgC3cwg07ylCm7fzNWxnwdMC+VqPdI4G5iW+L6NktnWCJq/a+KZenYAt+ePWbFgwVgtM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=X+0XEG20; arc=none smtp.client-ip=209.85.208.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2d1094b5568so82783051fa.1 for ; Tue, 20 Feb 2024 22:27:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708496821; x=1709101621; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=O4SCakJf3fMGKD4Pc9DX3Fmx60D6/XewjZTTvU4lsUQ=; b=X+0XEG20oH3gTiWdjKMlBQDZMej0xMp6ft+S9UPrdyFHlRb92QjNaK2SWPfQcJwZs0 ShaS0fCSywiH6R0YdhUiqAdUEc/cGqTCZtdjtDFMgNtLA2Ju/xeZdan+/XdjHdd4eghr AZXN5paPr/VDy4emRkEO9Ey1ByIIMWrrJqsKcn2x67feGW/1HHB8BfpaNbiXdr3/M63T jLWnBg50AOOkFnZ+uloZl77fh3wByQ9tlKPYgj9+CrJXTTLs1ZQAu19tciLO61gW7X1O HKqVHlTzbGjoLmo0VvU4y5U/MCu6ccQj5HLOBCA/7pOIp70z3YFAYK/7fUds/6gaDLF9 WnBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708496821; x=1709101621; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=O4SCakJf3fMGKD4Pc9DX3Fmx60D6/XewjZTTvU4lsUQ=; b=Mcn+D6EMxG+807MEQR8PJeLm0elKIojphKDs4TOEI3IW4r4qlOdp6DsvHUNZ2wUkDZ z7wj01anEyE0L3lO1sqhYAM3HJsalUIMtMqiKAIf9yPhE3H1oor/YKbNbehjSmIAYDIz uwTB866GOwk2iKpmzPj1AtHV/SKTYkXBSgvFyL9OVB2mvVdLI1P+g6dNA0f8b/HJOgqc cHIyIsFqsprOLQmWLE2dbrSvTDEu+qdyOHGjotKbCtf9CkOf8NWuY1k6szctpGvIxnVn np3M5ElFlwljFltr8FbR2NMQM5/brV4Mj2W34URea9r/8vrIDRcnyGpUEL4RnBxzWJaC sztQ== X-Forwarded-Encrypted: i=1; AJvYcCUcbvrRjhGHY/mEiQUihaS/QlArj1zTF78rHeic4dzp5xV2gWsXAETejlaMDNvmUdBukfyG2tcJYqTp3/naOvvy5kw5lJ4HGv58RKp1 X-Gm-Message-State: AOJu0YwzZI5FNyxo86syOciAPyz+OqSnDeAN2/1hf17f5vTQK+h1GqWG HW0KtyduiIuXHFCuheN0KcuxpXBOQyKxnfcwH37XCGS3sbGZg0c0xLRThHMnFTBE6Tf0qQKcNpw j3KJKdbFJuCJDjwHTKfkGzYvVQ08DJwZHMC3jKQ== X-Received: by 2002:a2e:988a:0:b0:2d2:31f1:1a2e with SMTP id b10-20020a2e988a000000b002d231f11a2emr5776674ljj.12.1708496821260; Tue, 20 Feb 2024 22:27:01 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231027000525.1278806-1-tina.zhang@intel.com> <20231027000525.1278806-6-tina.zhang@intel.com> <55a4b5e5-e0ad-4aa4-a29b-5fff4ef69063@linux.intel.com> In-Reply-To: <55a4b5e5-e0ad-4aa4-a29b-5fff4ef69063@linux.intel.com> From: Zhangfei Gao Date: Wed, 21 Feb 2024 14:26:49 +0800 Message-ID: Subject: Re: [PATCH v10 5/6] iommu: Support mm PASID 1:n with sva domains To: Baolu Lu Cc: "Zhang, Tina" , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" , David Woodhouse , Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , "Tian, Kevin" , Nicolin Chen , Michael Shavit , Vasant Hegde , Jason Gunthorpe , Jean-Philippe Brucker , Hao Fang Content-Type: text/plain; charset="UTF-8" On Wed, 21 Feb 2024 at 11:52, Baolu Lu wrote: > > On 2024/2/21 10:45, Zhangfei Gao wrote: > > On Wed, 21 Feb 2024 at 10:06, Baolu Lu > > wrote: > >> On 2024/2/21 9:28, Zhangfei Gao wrote: > >>> On Wed, 21 Feb 2024 at 07:58, Zhang, Tina > >>> wrote: > >>> > >>>>>> struct iommu_sva *iommu_sva_bind_device(struct device > >>>>>> *dev, struct mm_struct *mm) { + struct > >>>>>> iommu_mm_data *iommu_mm; struct iommu_domain *domain; > >>>>>> struct iommu_sva *handle; int ret; > >>>>>> > >>>>>> + mutex_lock(&iommu_sva_lock); + /* Allocate > >>>>>> mm->pasid if necessary. */ - ret = > >>>>>> iommu_sva_alloc_pasid(mm, dev); - if (ret) - return > >>>>>> ERR_PTR(ret); + iommu_mm = iommu_alloc_mm_data(mm, > >>>>>> dev); + if (IS_ERR(iommu_mm)) { + ret = > >>>>>> PTR_ERR(iommu_mm); + goto out_unlock; + } > >>>>>> > >>>>>> handle = kzalloc(sizeof(*handle), GFP_KERNEL); - if > >>>>>> (!handle) - return ERR_PTR(-ENOMEM); - - > >>>>>> mutex_lock(&iommu_sva_lock); - /* Search for an > >>>>>> existing domain. */ - domain = > >>>>>> iommu_get_domain_for_dev_pasid(dev, mm->pasid, - > >>>>>> IOMMU_DOMAIN_SVA); - if (IS_ERR(domain)) { - ret = > >>>>>> PTR_ERR(domain); + if (!handle) { + ret = -ENOMEM; > >>>>>> goto out_unlock; } > >>>>>> > >>>>>> - if (domain) { - domain->users++; - > >>>>>> goto out; > >>>>> Our multi bind test case broke since 6.8-rc1. The test case > >>>>> can use same domain & pasid, return different handle, 6.7 > >>>>> simply domain->users ++ and return. > >>>>> > >>>>>> + /* Search for an existing domain. */ + > >>>>>> list_for_each_entry(domain, &mm->iommu_mm->sva_domains, > >>>>>> next) > >>>>> { > >>>>>> + ret = iommu_attach_device_pasid(domain, > >>>>>> dev, + iommu_mm->pasid); > >>>>> Now iommu_attach_device_pasid return BUSY since the same > >>>>> pasid. And then iommu_sva_bind_device attach ret=-16 > >>>> Sounds like the test case tries to bind a device to a same mm > >>>> multiple times without unbinding the device and the > >>>> expectation is that it can always return a valid handle to pass > >>>> the test. Right? > >>> Yes > >>> > >>> The device can bind to the same mm multi-times and return > >>> different handle, Since the refcount, no need to unbind and bind > >>> sequently, The unbind can happen later with the handle. > >> Is there any real use case to bind an mm to the pasid of a device > >> multiple times? If there are cases, is it better to handle this in > >> the uacce driver? > > Yes, it is required for multi-thread, the device can provide > > multi-queue to speed up. > > > >> From iommu core's perspective, it doesn't make sense to attach the > >> same domain to the same device (or pasid) multiple times. > > But is it the refcount domain->user++ used for? Is there any reason > > not doing this. > > I was just thinking about whether to do this in the iommu core, or in > the upper layers, like uacce or iommufd. It seems that there is no need > to attach a domain to a device or pasid again if it has already been > attached. It would be more complicated since the return handle can be used to distinguish different queues of the device. I think domain->user should handle this case as before. Anyway, I have sent a patch to get more feedback. Thanks