From patchwork Tue Jun 6 12:07:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Shavit X-Patchwork-Id: 13269058 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 C3FB9C77B7A for ; Tue, 6 Jun 2023 12:10:57 +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=FiHDFcc2Z6Jq6ii7W3l3LTKTWwbaND7jEzApRXzCy3k=; b=xYaDVS9EoRffZIEbiqLZ1RflWg pTu+wKuHj52dGeBZ8Cr8lngWp1zrMQ/mK5ZHxRTI6FSCON9AHO0FnLZbuJl9migFE95sjxT0QxfqL ZDgpmEhsJhCR99yBpcmrCtzBHAapRJ7Ut3QUlW630HSpesQptSFFY09m0XBK1SZTnCYjtCVfCD0b9 8UWx0k8yYuO9WCWnXCm9H7+Q5YO9cVksUvFr7TpiwjUFOqRM/eC/4bN019u13QsCjo8Lt830EBk+d p0jQO9Nl/Avqn0e1z7H7tSKL61QlpSXFTPSjS5TMqJpeXPRaA1rnTC02E8PfM6K5BFCUXIIbuZlAJ 3q7R2AgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q6VWE-001ZFc-06; Tue, 06 Jun 2023 12:10:34 +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 1q6VWB-001ZCt-0s for linux-arm-kernel@lists.infradead.org; Tue, 06 Jun 2023 12:10:32 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-568ab5c813eso97967937b3.2 for ; Tue, 06 Jun 2023 05:10:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686053430; x=1688645430; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=83dlZFDhtSz2rg2AR6ggZ2Mh/ASzqdpRvSd02rbzaCk=; b=IoFA55ulrjtnJDTW5pbuUTS9XeM0qmUYpaAJ3OnF3fjh404oOtNySp8WzgeTzaaiiO mVRlBZ2obwVwh4OUFmiQJt7UUnDxoDMkllhaIBQAmBhFfw48M+MKZQjL4e//71A1xQ+M ZQe0Lx0j/uNjanZ997DNS7XHK7FjkoWOzElSxea08x+rZug6VZyihB4gEnokoKygwiFy oohF6tU936F+ATOKuIyJj4FuSck9QyYVTKPs6mJWVCMGD4SJTG4PI7zHHboXxVFaZsG2 nDS7Gx45dkGyCy6J2pqiwfXPIBXnbTfVR9nkfcP+mnZCb8QJyIFTWcKIELfCjtVWDZgK oB0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686053430; x=1688645430; 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=83dlZFDhtSz2rg2AR6ggZ2Mh/ASzqdpRvSd02rbzaCk=; b=ccreRhR1ZQ9PagnzXq2INRz2H3GCQVesX6Rs/EkWR7BhJKsfIF+mQPkzg0xWBICl+q fJWF4g7npDUyohH4r1XeyMTefhx20xP13zB4Bde+gmGWzMRrh0yejew+wocV2Gv1omXl D+7hrsyWsndvl0dvJXmx8fZ2qcSzml9glqSPt+eNQXCA7tE208H6h2Y5stObGSwJBDAc WOVDPcUUSqEVEzA7XcCSKW3lD0cOPGk45FYAz1ttgRjkorwVLZHnaM1aR7BuqjFrJAMJ 0A9WR59jb4rc+BMv/c7O2n6JrVTa3WgiTFPN7Vj4VnHLIACuZod3Mo8hWbIAOYYZ6E7x RS3w== X-Gm-Message-State: AC+VfDwperUVVlXkjJjdz3XiNcUJ1hurZR9qxXtxog/85nPfjJ9/JQKs inoa21PvMjNPo/3O9gD3C2Yyg0qGxI/8 X-Google-Smtp-Source: ACHHUZ64pvQvCxVufeRzNt0VKrbwAwJNjh5MfrOYdfJtgOmahfaQ951Oi+PY3aJvHU4m52siOi/iL4Zbsjnl X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:a615:63d5:b54e:6919]) (user=mshavit job=sendgmr) by 2002:a81:b289:0:b0:562:837:122f with SMTP id q131-20020a81b289000000b005620837122fmr942001ywh.9.1686053430214; Tue, 06 Jun 2023 05:10:30 -0700 (PDT) Date: Tue, 6 Jun 2023 20:07:46 +0800 In-Reply-To: <20230606120854.4170244-1-mshavit@google.com> Mime-Version: 1.0 References: <20230606120854.4170244-1-mshavit@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230606120854.4170244-11-mshavit@google.com> Subject: [PATCH v2 10/18] 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-20230606_051031_307054_ADC8AF2F X-CRM114-Status: GOOD ( 13.57 ) 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);