Message ID | 20240221061832.430-1-zhangfei.gao@linaro.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-74135-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp860703dyc; Tue, 20 Feb 2024 22:18:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWqJducT3NFe1ESRtWB7/pYYzYvK92MqVSJr5y8iTK6aIm22rJV+84VX26+PGo6bdfoBCHkTMN7Q1syQxhdiE6EoTHXtw== X-Google-Smtp-Source: AGHT+IGMo2zsEHmfTX1xsOAhZIrLwFfzBiYmIUIxXZlhS1efyq/GFyzxFOQNiuC9m6F3bYXBU0IZ X-Received: by 2002:a0c:e307:0:b0:68f:5757:c5b1 with SMTP id s7-20020a0ce307000000b0068f5757c5b1mr9509848qvl.5.1708496338901; Tue, 20 Feb 2024 22:18:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708496338; cv=pass; d=google.com; s=arc-20160816; b=d7LJk0xU5e47EwFOz0nhIx1qGmlPH7dskCVdJoCNTZsBSAg8crxaFgs67FxH1VdVDC jpaVjWYoStp7e/cF9Aun5l7qKKI0n1246FUb9NvwJdtf+r46vepf2xNu9LWjklLED6CG Vweb40yfJXHOozBs0S0Ihj7JJGRXpWwnCDnYdLyIhrQrAmp+ooNGNtIK6TsC+BSXbM/M X2t7Uk6nBf6T74oApE/l60ACQqKzDlkswXaz+OEVs66vBVBdz0lePsKoemzepCNT3e+S kxmFj+sSNLVXEPHnMKVjo+CnrMKdkeWdFR1lng4oIw/MqGoCz+WSuyddbsY0zSM0njKN lMAQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=LntZkoOS3XoaCq85kDcQo9fQHTCSCfK6GDoagwWHxow=; fh=ZxgBiogDH9g45dIne4Yyreh6f5GJh4BHdQs1RmDC6Dc=; b=vB6T6Nyck8XThxkTdxy4YTC1ZKDcsyL+3kbGVe6tT722UlSzi1sBnQpT7KpJ+HiX/k bFja7bLaIPK1wQ0deuODObdYIvsH2pVg4Luso2F9e/o9KJFz/RyKhD8LfzT4W7tGDjuH uFYiKgLomHr1voSLuVqGP05SXA18z5oUqjddTqxCkZ50qbk14HP89fXZnqHBqciimcwB XG5NTOkBt+/h+vFY25v3a1Lb3hKEeLFKKYc0fwFVaznC1l02HLaRmilQTO8ilUIYcQSy 8yuHJN3btd/ZN2Mccme9SUaXliDCH5iW0cvA5UIEG8TK0DhXWCcR5yGxQPpl9y7ZAUzz FdKw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Dm5wpxWO; 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-74135-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74135-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id j8-20020a05621419c800b0068ce3d2a9b2si10160203qvc.256.2024.02.20.22.18.58 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 22:18:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74135-ouuuleilei=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=Dm5wpxWO; 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-74135-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74135-ouuuleilei=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 7E1AB1C23C00 for <ouuuleilei@gmail.com>; Wed, 21 Feb 2024 06:18:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D9DB93A1C6; Wed, 21 Feb 2024 06:18:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Dm5wpxWO" Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 CD98439FE0 for <linux-kernel@vger.kernel.org>; Wed, 21 Feb 2024 06:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708496322; cv=none; b=SmJXDQaobNb+BzND22hpsgmTdBB8ZsbaPaoEqrPyh6ya7znbPQJJbtnwOmLbQz3YomgQeELtUP6rN4glc5aIQJhe/JSvfSaJk2mDIllt5p9ZPNOMc8nT/twDTUDPVgNjezLHIwrIsQvfL/HfT/aYfXhlkFWB28nLqNjpusN3BEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708496322; c=relaxed/simple; bh=/4RHrvnMyEixH5aM1Nq8oXQ5flTobU8B+tYnhQcL4Os=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=tG0EpkIl+7UgHdKSn+FKrDqd7aKpljRG+R4uMDRZc4xpi/Ot/MHwsC5+PzpvEDPfFtobwluFKBGuYOdKS5UbUMDvweO7BSpQKv67WTmHG5BDGJHc1ymMOQJsfg1owHlI+LY5/NkWj3g4efhgMWiA9D4rJHPIdjhq9tww3JkVFQA= 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=Dm5wpxWO; arc=none smtp.client-ip=209.85.210.170 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-pf1-f170.google.com with SMTP id d2e1a72fcca58-6e46db0cf82so195609b3a.0 for <linux-kernel@vger.kernel.org>; Tue, 20 Feb 2024 22:18:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708496320; x=1709101120; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=LntZkoOS3XoaCq85kDcQo9fQHTCSCfK6GDoagwWHxow=; b=Dm5wpxWOigGDcFHnO8g2CqDrETI4Q9cUsgTrUAMFxthVbkEuNcRfo9LSuuK0MjFPLb s7RARIwhIlggIAv5+q3Ak9mOQ+F/+4+1xAfkeNZJvIDpaDpcDTx/66UetzVwGMVXCkpW 0Oa2XqeSikpB9cmLTBkpb46jMqN9Sih9G918S5+soBdzPTpbF4H2naiWwQSr3XcOOOcP u67PU2q+BY4LrDwVvwSi7r5othjmMs7uiJj3YRArMIMHpKCJ2S7JBHR6gMfSzwHupDhj bxSFeDfCFSiK6RHSQDjCJwpE3jpsjN51VHJleDWdkNjUuAIFG0805SCoQrEv5RJPWo1S YKgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708496320; x=1709101120; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LntZkoOS3XoaCq85kDcQo9fQHTCSCfK6GDoagwWHxow=; b=RteVIHl+oBi8fQ39K27mkvemxks73g600I99QhwfzwZAfgVJOJl/bi0vAguChfUUNo +2biiNiWa+STeJ0azf2M6ZofAtgGiQdwPST8uRc/0MJktmJpooTZMKQyRFfmxAVoYbqF JPSXIJmPwphdntEamNPaTl2jETxd+5cCYjZFYU78yBRDoPvXYZgs2be53dJ7xF9pDb0s KsFWUhRPwCmM1qZiWiPiuTOu7O++rc6eEYYjwsV490LexCnnHI4NG3jYoBR5Bya1H/Wq U3KLJcMfFo/uVjbQeaglxLg0DstMiA/v4lClKuty3E8DZb+cU6qdEuqKUrb0kcLVsXc4 JY2A== X-Forwarded-Encrypted: i=1; AJvYcCW1UlpqCozyU8M6Ut49IpJF1S1Lb9k1vxptVU+pg3Cl8JQiPSM6Q2V7M5J5IYcvHYX7OsTc//IgzF8/UlTUGGkqC3ykrgwu13gc77j+ X-Gm-Message-State: AOJu0YwurgPitY+EU7RXsk05WOZfRgMeR6fOVjAf/6LMxdhI8O8H9fAv z1cbMm4RPX5eM8oqfQcR4ujPF3zyyoILWNpbnciqVyTXgNakfbL7i8UdhYa+K4ZRoMh19yaYfsp TsuLbBkLD X-Received: by 2002:a05:6a00:93a3:b0:6e4:8bb0:5f10 with SMTP id ka35-20020a056a0093a300b006e48bb05f10mr1788718pfb.17.1708496319949; Tue, 20 Feb 2024 22:18:39 -0800 (PST) Received: from localhost.localdomain ([114.103.195.43]) by smtp.gmail.com with ESMTPSA id r12-20020aa78b8c000000b006e3a9bdeb99sm6751342pfd.40.2024.02.20.22.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 22:18:39 -0800 (PST) From: Zhangfei Gao <zhangfei.gao@linaro.org> To: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>, jean-philippe <jean-philippe@linaro.org>, Jason Gunthorpe <jgg@nvidia.com>, baolu.lu@linux.intel.com, "Zhang, Tina" <tina.zhang@intel.com> Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Zhangfei Gao <zhangfei.gao@linaro.org> Subject: [PATCH] iommu: Fix iommu_sva_bind_device to the same domain Date: Wed, 21 Feb 2024 06:18:32 +0000 Message-Id: <20240221061832.430-1-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791488256860932972 X-GMAIL-MSGID: 1791488256860932972 |
Series |
iommu: Fix iommu_sva_bind_device to the same domain
|
|
Commit Message
Zhangfei Gao
Feb. 21, 2024, 6:18 a.m. UTC
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 <zhangfei.gao@linaro.org>
---
drivers/iommu/iommu-sva.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
> From: Zhangfei Gao <zhangfei.gao@linaro.org> > 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 <zhangfei.gao@linaro.org> > --- > 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.
On Wed, 21 Feb 2024 at 15:09, Tian, Kevin <kevin.tian@intel.com> wrote: > > > From: Zhangfei Gao <zhangfei.gao@linaro.org> > > 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 <zhangfei.gao@linaro.org> > > --- > > 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
Hi, > -----Original Message----- > From: Zhangfei Gao <zhangfei.gao@linaro.org> > Sent: Wednesday, February 21, 2024 2:19 PM > To: Joerg Roedel <joro@8bytes.org>; Will Deacon <will@kernel.org>; jean- > philippe <jean-philippe@linaro.org>; Jason Gunthorpe <jgg@nvidia.com>; > baolu.lu@linux.intel.com; Zhang, Tina <tina.zhang@intel.com> > Cc: iommu@lists.linux.dev; linux-kernel@vger.kernel.org; Zhangfei Gao > <zhangfei.gao@linaro.org> > Subject: [PATCH] iommu: Fix iommu_sva_bind_device to the same domain > > 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 <zhangfei.gao@linaro.org> > --- > 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) { If rebinding is allowed, how could IOMMU core know if this invocation is intended (like the multi-thread case mentioned in the commit message) or is mistakenly invoked? Thanks, -Tina > domain->users++; > goto out; > } > @@ -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); > } > -- > 2.34.1
On Wed, 21 Feb 2024 at 15:59, Zhang, Tina <tina.zhang@intel.com> wrote: > > Hi, > > > -----Original Message----- > > From: Zhangfei Gao <zhangfei.gao@linaro.org> > > Sent: Wednesday, February 21, 2024 2:19 PM > > To: Joerg Roedel <joro@8bytes.org>; Will Deacon <will@kernel.org>; jean- > > philippe <jean-philippe@linaro.org>; Jason Gunthorpe <jgg@nvidia.com>; > > baolu.lu@linux.intel.com; Zhang, Tina <tina.zhang@intel.com> > > Cc: iommu@lists.linux.dev; linux-kernel@vger.kernel.org; Zhangfei Gao > > <zhangfei.gao@linaro.org> > > Subject: [PATCH] iommu: Fix iommu_sva_bind_device to the same domain > > > > 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 <zhangfei.gao@linaro.org> > > --- > > 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) { > If rebinding is allowed, how could IOMMU core know if this invocation is intended (like the multi-thread case mentioned in the commit message) or is mistakenly invoked? I think it is the purpose of refcount, it should be no difference whether same device or not. Even different dev, IOMMU core can not make sure it is intended or mistakenly invoked. Add the limitation does not make sense. Thanks
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; } @@ -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); }