From patchwork Wed Jun 14 15:42:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Shavit X-Patchwork-Id: 13280162 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 159AFEB64D8 for ; Wed, 14 Jun 2023 15:45:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=FUDd86Bbj/aoLrC28fhzeglulWpVPOmujdqZLoA4HpU=; b=PeQo3sLhyCT9jvsRGAxLkvPBKz lAdUraOyx8mSyu/+szM5dxEJMfQ6nH3udTWiR2dNasgit15tiY48YuFMd6PAlJ08JzzVVQLxZuau5 7El1EhzlJsPks/RKZOO28hglJW1kStqmpo2Wauzv2maaQSjK4IFjP1WlocbzwdQKg25n9irNo1lLn bhnxzpExE7LXCY0FhPEj6Xck93IiFk4abM25HFL8xJLJR5E/rZei28jeKSYamIxBXtM0J5+VKpVh0 +vEea3aqPbFFMD06gJVugfQwGvMQ8B1bVC/Ntp4CreL3KbGCnc49477KY2VTN87iVBo1nj3SgCZCq tJd6qjkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q9Sfx-00C6fg-39; Wed, 14 Jun 2023 15:44:49 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q9Sfv-00C6e6-2Z for linux-arm-kernel@lists.infradead.org; Wed, 14 Jun 2023 15:44:49 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-561ceb5b584so12010717b3.3 for ; Wed, 14 Jun 2023 08:44:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686757486; x=1689349486; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=tvomj7iW2UACU6/yECNbFWEXmb4EH1aV19zctsWiNw0=; b=vuL1XrQpU5Uq0e2ygjk0DfQm99VPq2z9YNT+avIv27XZ5urDEgwpmKbViVzjQ8Ors2 T0rraZDZVM0ODSgkQTw6g6hdTWSyZHC/ZwHObRZETsh7v9KsqI7mfjRVjTddqwb75Yd6 PkKi9NkGSgecoW5IThOwn0gGyOxQIy0qaPS8Ued69ldHUGXC3bEZuqzTL/jNRXCrcJi3 uAxDiKxWDeKXd8Icj/EZsPQK5O6GRp7wJwAZct0hM+oyxo3a3VP2+SBs18GWULEH6AcA +Q3vGN3bOvN8pQVCjBFeK+N8axcpPszN+TMygeq+12fShtLMkNw5EOWGCZf8F5q4Py43 k0CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686757486; x=1689349486; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tvomj7iW2UACU6/yECNbFWEXmb4EH1aV19zctsWiNw0=; b=hqz9SbE1Y1B1nbuLB1X1aYZTy1MfzB1FweWaP2RRrAihw4AZ4brk7GdQmevTCqugE6 QqJebOpZuyrDL2sofu9wuL6zEjbm8BMDfw8iXCfDIXJ6I4dTIXiKbe6D64FTTY0cl0KQ N9vH6h7IiX7hV7xH6/Y0xkoXOwH91CATUHeAq9gn2I7Bdg8hO+kKCwqkJwwiiYS2C+RD dwv0HGYxY0hESUFNj8Z6szJNtbcKpOvm9JCiEvd0zHNsMW7IStu3+PgB5lBjgKbNP5LU jFy5eNHeMZRsJEjIAdk1UiVr/LPU1q5To1P8Ppcf9lfP1NwB3DrRFX9BHvBnFhqev8Ra 8HvA== X-Gm-Message-State: AC+VfDyznxcItNkMxV8yrBDNcQBbfZNnhcRgmtgFC1brPs2vccGCUdk3 oiMlFIV6ZahM0FCwHQ+0kUrXz1avA6Zg X-Google-Smtp-Source: ACHHUZ6PWgAWHwE/x5mre24ZvBjK+WBUn1h6Ifenl3MHyaJYnWLa0SO3LQyqPPJbjhH7MP8WEYsBnUmWbutp X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:c6e6:49bf:5c44:5965]) (user=mshavit job=sendgmr) by 2002:a81:440c:0:b0:56d:791:d1a4 with SMTP id r12-20020a81440c000000b0056d0791d1a4mr1051771ywa.7.1686757486567; Wed, 14 Jun 2023 08:44:46 -0700 (PDT) Date: Wed, 14 Jun 2023 23:42:02 +0800 In-Reply-To: <20230614154304.2860121-1-mshavit@google.com> Mime-Version: 1.0 References: <20230614154304.2860121-1-mshavit@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230614154304.2860121-11-mshavit@google.com> Subject: [PATCH v3 10/13] iommu/arm-smmu-v3-sva: Remove bond refcount From: Michael Shavit To: Will Deacon , Robin Murphy , Joerg Roedel Cc: Michael Shavit , jean-philippe@linaro.org, nicolinc@nvidia.com, jgg@nvidia.com, baolu.lu@linux.intel.com, linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230614_084447_833321_75DC1D73 X-CRM114-Status: GOOD ( 13.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The iommu-sva framework checks if a bond between a device and mm already exists and handles refcounting at the iommu_domain level. __arm_smmu_sva_bind is therefore only called once for a device/mm pair. Signed-off-by: Michael Shavit --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index d07c08b53c5cf..20301d0a2c0b0 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -29,7 +29,6 @@ struct arm_smmu_bond { struct mm_struct *mm; struct arm_smmu_mmu_notifier *smmu_mn; struct list_head list; - refcount_t refs; }; #define sva_to_bond(handle) \ @@ -377,21 +376,12 @@ __arm_smmu_sva_bind(struct device *dev, struct mm_struct *mm) if (!master || !master->sva_enabled) return ERR_PTR(-ENODEV); - /* If bind() was already called for this {dev, mm} pair, reuse it. */ - list_for_each_entry(bond, &master->bonds, list) { - if (bond->mm == mm) { - refcount_inc(&bond->refs); - return &bond->sva; - } - } - bond = kzalloc(sizeof(*bond), GFP_KERNEL); if (!bond) return ERR_PTR(-ENOMEM); bond->mm = mm; bond->sva.dev = dev; - refcount_set(&bond->refs, 1); bond->smmu_mn = arm_smmu_mmu_notifier_get(smmu_domain, mm); if (IS_ERR(bond->smmu_mn)) { @@ -570,7 +560,7 @@ void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, } } - if (!WARN_ON(!bond) && refcount_dec_and_test(&bond->refs)) { + if (!WARN_ON(!bond)) { list_del(&bond->list); arm_smmu_mmu_notifier_put(bond->smmu_mn); kfree(bond);