Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2179511rdb; Tue, 20 Feb 2024 22:18:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU4Ut02cEsXUIODR0au98ur3bgyKixawO0ZpZ+gMJbAps9a7vV3rB5IOWXOALZILF9xU6AVuog9UsMlmueU6ncRfeOTsiLHzlQ4DMYxhQ== X-Google-Smtp-Source: AGHT+IEUGE95bLYN3j9lbZHGOXvgINDV/Wo3AL1QzxJbJTEwuE8qXDDdDnDGUSiqKfh+5gMIhW23 X-Received: by 2002:a05:6512:602:b0:511:ad0a:3575 with SMTP id b2-20020a056512060200b00511ad0a3575mr11549532lfe.41.1708496331293; Tue, 20 Feb 2024 22:18:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708496331; cv=pass; d=google.com; s=arc-20160816; b=zWw15TMVJRRvgpIk/QYMcjzMXsoZUvS9jKLMVYxATWiTCT77Z1rqFwcVwgXx3CO8cv lKeaNlvPQTheYTBZxgxYprS+DhyDHzzdjF1f1o2gXxeVxkZPh1cV1ndSpBA3qEpXt9v4 HhWo2G8Bh+avAiHDyRJ8cF5vHPZpTA/woaG4KiPhS/vKSfVH+HyVaWFGgizcnQGMngL+ w6poMYhTtoLOIAZ13DnP2c+xTtusVA/NkbPpMjvMXV73oZgLa+E+7yvZuJQAUYAs9f/T Qwe5W68i5zxWAdd1nC1IZw+1mJupGUZx4QgjVEzAMGIpurFYRtPFfsDpiVrgTrJcpr1a latQ== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74135-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f20-20020a170906391400b00a3e92827319si2579965eje.32.2024.02.20.22.18.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 22:18:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74135-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74135-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 0E8181F22536 for ; Wed, 21 Feb 2024 06:18:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 152313A1A8; Wed, 21 Feb 2024 06:18:43 +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 ; 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 ; 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 To: Joerg Roedel , Will Deacon , jean-philippe , Jason Gunthorpe , baolu.lu@linux.intel.com, "Zhang, Tina" Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Zhangfei Gao 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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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; } @@ -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