Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2212566rdb; Tue, 20 Feb 2024 23:57:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWvg81EKaKmBxwIhZiEs2ugHKne8fAD8GmzxMxSUEMc41swiNNadYCkFEVpmtXnGKZcZxy+9LgPOC9UXT1YI3vECxGOt9G8ddnL127DHQ== X-Google-Smtp-Source: AGHT+IHdWdoJKePJvNhfiVsXM12rSS+r5GCRzFWm+d1F24oYy+PGPhLNYTSUoaVif7m3h/YHdxl7 X-Received: by 2002:ad4:5aa7:0:b0:68f:52a9:3b24 with SMTP id u7-20020ad45aa7000000b0068f52a93b24mr11171444qvg.29.1708502260323; Tue, 20 Feb 2024 23:57:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708502260; cv=pass; d=google.com; s=arc-20160816; b=Ghg+CyCkufM2+YUGKr60b0NHeBYuhKlIJa2avx6l4beCIV4Rax5cMq3cLf+zRYEPtj gXKv7kFX0EwmgAeG3QJX9vHGO72+JrI7oChkbHwVEppNBG34UOFSTPiH+tx3IX17L6pU hWJ6mID3zrjjcO4PYIWlacTA4DBCeYdUCkpmIldhwdq8rXvYvpF15ua0Hr/rh0Km/qNm SWjGMIFoBSV8MczxeqNFrcnD0JxdJd3cisBmUrOGkGTujdo0wHvklaVmgzXsIWzdpC5V mXJMNuENv5qCCby+FSQKac990LyaiQzPCMYvxekAr4MFkmNfMLzyOUdsXtwNLAPFNc9f QSuw== 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=rIlfzaJtbpobJhT/QtQhJEs40EZRm7KSI11K44WZ/H0=; fh=7MErujA9fK2mFuTAkw1MKWWnjcoT599EH6VPTC8AcBg=; b=j3yAA6KjM8OEmAfZRTmft6yhvsNFcgxR6qig/h0QzDZkkTii+k6iCH2HnPt7v2fUNl woqkCcUBrATow+UCUD5tydZ89NeAKVIWso8wXqaT/o7t5BcxHeHPxYtLWK80nhIOLwbS Dc4TYeSN/dN76iIs1qMi5P+yZtVb2hnbQSNpiec+Hxd53dJ5amZo6/WN4JC5WQ/T60SW DyIuzMqQ7s1adxXkN6WgKUygWz1DM52f5TcdMxTDExejiIY3fVC9D/nLAFiWCeKOswRY GeHVSbyHA6gj7aesZG0vnQAghVjdDqUVzCfm2cShr2v3wGxngHxv/NJZuGu5MCZEd287 VIDg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hw98evi+; 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-74273-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74273-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id e1-20020a0562140d8100b0068cb9e119b8si10157977qve.576.2024.02.20.23.57.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 23:57:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74273-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hw98evi+; 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-74273-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74273-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E2E741C226A3 for ; Wed, 21 Feb 2024 07:57:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 90BA23B78D; Wed, 21 Feb 2024 07:57:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Hw98evi+" Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 E5AA63A269 for ; Wed, 21 Feb 2024 07:57:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708502253; cv=none; b=nSxn02tdItNQEYwX68SZD9bhSt78E0zTFNraW2S5+z7E3LYFbXEfoJ2mPf2kwZNSFbj7mF5hHwbn4Ey8lFZy0VOz3nHb/5iEld7sOxVK5i57uFQr0JilKOQa1nUTpL0/G6NQq/kNa2kJxyDDE1BeEs3qRsjznTKRJrDor3OaDmE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708502253; c=relaxed/simple; bh=AB54ClpKXDvpnrBLD+hTBZ/toGRg4PgxYjTpJQsitZk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=WDx92jmuo+kUyFqWJGpLIU3Dqc5ZBWQoIQsBbRpUND5S+NiWZzXev8wCzXgzo2z4JA9txXKuCea5sWm/KdeJlmp76DJ1sJeqZGMkYbBYNhNgcW4SvKOLYCWm1QpkjqaQIOJIK7pPHN3vG81MJwPTWqMAJajaeZ3Yck03HuPAchY= 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=Hw98evi+; arc=none smtp.client-ip=209.85.208.177 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-f177.google.com with SMTP id 38308e7fff4ca-2d1094b5568so83437401fa.1 for ; Tue, 20 Feb 2024 23:57:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708502250; x=1709107050; 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=rIlfzaJtbpobJhT/QtQhJEs40EZRm7KSI11K44WZ/H0=; b=Hw98evi+Cbg3rz8tEpW4wffNzcGFFMwRwoz32v+o4tipPkNuhYivUJ6GCqhhh2MjVY Z6lxFS0nvxpn5FiiD7ZozJHK2I2eo8EWDgv0eRXw0aGpLNFjxZC/DuF71X4kLUOu4qcp TeQqhbFU5yDqpMaOM4loKpiXcQ/iNhS/R7kgDj3l32TEnNYZzUc4q2dIv2qYG9ky71z1 CXZAsinK/hqbm0gkT08bJupJd+URmqQNcd3Jyx7J8CceJ8YJMcP1eT0mQKla8P4tNMNi FGEQ2QXjG2/5fgsXipEXr9p8+X+bNnbE9ZD81f1DzKlMLbaiGALEhXftNvnPIbtFx6xx MzjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708502250; x=1709107050; 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=rIlfzaJtbpobJhT/QtQhJEs40EZRm7KSI11K44WZ/H0=; b=RGDq1sTMaYFaPcK351KkG6fFvH7bCgBZo5YefOWvBdeCfR2uuxJWP675TnMAD8HGWL NS2gjSvuU2hqaSSwIyyVxw9Ld+IfMCabKCU0jufOuQa5t7snO9un4ABO3b/cDezDyav0 RijLZebZFQeNcGydkILOtjjtzNoCsyxEexZ+1AgQZ9Lfo0LOrnMwcFCUMzV5oiu/zRpO WFPiR+6JUf+YNq6neNgchizJJPZ6HbIB7NEl5wka01adt76GMTYel4PZ6t+a8Z9epqYb ewZD4v5FVDliq3Pu/rvpDCKVyKyZldzO0/9vT8G9QH/JanLptCawwkdiP7TtZs3v/a/b 45Kg== X-Forwarded-Encrypted: i=1; AJvYcCU1GYz7kgJivYWiqDEAXuqKQ9na/f/iB5cAMs0VSmZgjR+BW5CZulzls/O1KOmtqRue3Bzd/pQ+TTs0z6czM1EieOsrN0/TPt1P+3NQ X-Gm-Message-State: AOJu0YzJF8M1QwH6s85VoIx7tgYKt8vZJrpdZdNQv1uvHOBB0vwfQiGD wIn5ZeRhdV86zZh3/lbfIH6AWuEky7noWo8dtQSaoF6+r2I10++h/Zg/+vg9Q+R6KIGDiHacwWK KXccXZ5/eimnHlr/PRCQGLcU4IPFvJN/rf4k5Mg== X-Received: by 2002:a2e:9256:0:b0:2d2:51c9:ef4e with SMTP id v22-20020a2e9256000000b002d251c9ef4emr1078626ljg.11.1708502250005; Tue, 20 Feb 2024 23:57:30 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240221061832.430-1-zhangfei.gao@linaro.org> In-Reply-To: From: Zhangfei Gao Date: Wed, 21 Feb 2024 15:57:18 +0800 Message-ID: Subject: Re: [PATCH] iommu: Fix iommu_sva_bind_device to the same domain To: "Tian, Kevin" Cc: Joerg Roedel , Will Deacon , jean-philippe , Jason Gunthorpe , "baolu.lu@linux.intel.com" , "Zhang, Tina" , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" On Wed, 21 Feb 2024 at 15:09, Tian, Kevin wrote: > > > From: Zhangfei Gao > > Sent: Wednesday, February 21, 2024 2:19 PM > > > > The accelerator dev can provide multi-queue and bind to > > the same domain in multi-thread for better performance, > > and domain refcount takes care of it. > > > > 'commit 092edaddb660 ("iommu: Support mm PASID 1:n with sva domains")' > > removes the possibility, so fix it > > > > Fixs: '092edaddb660 ("iommu: Support mm PASID 1:n with sva domains")' > > Signed-off-by: Zhangfei Gao > > --- > > drivers/iommu/iommu-sva.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c > > index c3fc9201d0be..a95c8f3a5407 100644 > > --- a/drivers/iommu/iommu-sva.c > > +++ b/drivers/iommu/iommu-sva.c > > @@ -91,7 +91,7 @@ struct iommu_sva *iommu_sva_bind_device(struct > > device *dev, struct mm_struct *mm > > /* 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); > > - if (!ret) { > > + if (!ret || ret == -EBUSY) { > > domain->users++; > > goto out; > > -EBUSY is not a right indicator for reuse. > > It may simply indicate that the pasid has been used for other purposes > e.g. attached to a domain different from what the caller expects here. Thanks Kevin. How about this diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c index c3fc9201d0be..20b232c7675d 100644 --- a/drivers/iommu/iommu-sva.c +++ b/drivers/iommu/iommu-sva.c @@ -141,8 +141,8 @@ void iommu_sva_unbind_device(struct iommu_sva *handle) struct device *dev = handle->dev; mutex_lock(&iommu_sva_lock); - iommu_detach_device_pasid(domain, dev, iommu_mm->pasid); if (--domain->users == 0) { + iommu_detach_device_pasid(domain, dev, iommu_mm->pasid); list_del(&domain->next); iommu_domain_free(domain); } diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index d14413916f93..a16ade93db25 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3551,7 +3551,7 @@ int iommu_attach_device_pasid(struct iommu_domain *domain, mutex_lock(&group->mutex); curr = xa_cmpxchg(&group->pasid_array, pasid, NULL, domain, GFP_KERNEL); if (curr) { - ret = xa_err(curr) ? : -EBUSY; + ret = xa_err(curr) ? : 0; goto out_unlock; } if pasid is already attached, does not treat as error, and domain->user++ in iommu_sva_bind_device. Thanks