From patchwork Tue Sep 5 11:49:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Shavit X-Patchwork-Id: 13374444 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 30AB5C83F33 for ; Tue, 5 Sep 2023 11:51:19 +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=8+px6YwPtgtVc+ikiAiN8oytlJaDRoyNudHbRgxKL1g=; b=db6xSVX4XtIPhj6kzxYkncNi2d +IWg4oEoUwBZd7oQDcmGRwyLvr+U2WzFXRDi13tl5CwYYzdmaKXqE+IOw8AKFBh2O9UJPRH9W/h83 mr0kyDur+4h0Z1JD0unfNDv/b70BPI0heJzcHzcicB2XZQY6EKUc9nZpE90/wIbniqGaF+zKDn5eM W32TeLPYhYxUrs0HMCW+jbFmPblYG2YZFXxxWVCnjqDzEkpS2tgvzU7KHt+/L3PQRAd+B8iRiQG8s gLKqfzdaFVGl4eIrDdgt5hr/pBa89f3lXBFQ+ZZlJPGWwysFnBAoC3/ZYVaz4z3nZb8psAy/ohYyg uTk+qJkg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qdUa5-005wkQ-2J; Tue, 05 Sep 2023 11:50:53 +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 1qdUa2-005wiE-0n for linux-arm-kernel@lists.infradead.org; Tue, 05 Sep 2023 11:50:51 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5925f39aa5cso39146457b3.1 for ; Tue, 05 Sep 2023 04:50:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693914647; x=1694519447; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=kiLWhPR0jjr+cIjF17/kc7vpb8l797DMDN7j160OqHY=; b=AE4b+yLBF67FDVMa0rFUd2H9GO3sWF590HHCsk6CPqN5RcfmMp0YRz9JUsqJmoMysq j+qfe+SsKXcYrI7YMGxJLGUQdbMfH3pYL/c+57eelB6AVCty0HgwQL0Ud/oRE9w4drJL 7aplFhOotfaxRAwzDzoIIufhSadmw/tgAEMZ0avDmiOjjy8uvsWmUMsbAmW1mBG9g/ND bfAiL8M5vDP47Itr+L7XZsiZoTEou907U+ZdoJWGk/GUQJZl3NveO2qcWlJ5d1zXNdeZ ykR1HMhq8p8LSke2ldNmTUPMT/K9TMMXQyWkHvf+7Mxjp0s6METu4/pX5bnWP8wwH7qN HruA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693914647; x=1694519447; 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=kiLWhPR0jjr+cIjF17/kc7vpb8l797DMDN7j160OqHY=; b=CDJTHeBpGu8MiRKZRb5BwTltJP7cQbBsTeGkqW1MRVj/yjfyq0//QJzTZlWAzfdDvD nvLVAIiGiaecjY3uLZtrGZmXTwG7aL67DMLG0FQJD8/oqpZPueM7VepWzgxjQftdSQpC 8qboEP/i2gnT4eTPjPUMuZ2zB1D3ukjjxBm1J5CMAeHGjb24rspX2IMVKwwi0KELjL1E D+nbKZuL5w8P8ipBagnozjYbeXVMiX9QBqlFaHTk9FZ06XsKCf7Rz5oZ3DW1mXdq0khm lFPSpgD3DedKKpA6yXNfOWuEweVH6pQBuh7PUHdN9dT5vHLPB2D5O1EADUFWtHnk+CPV GCVw== X-Gm-Message-State: AOJu0YzgSOC5G4gLmkRK+HGHLHynkQqoXWGcmPQ5MA4DmIlVf4u8SsAv Y+hUPIggCUlFvka+4rWuSankYapBMjyD X-Google-Smtp-Source: AGHT+IGymTxyTPXDcoYXyE6qZoihZHB7S/W+Yq4eYVfv8eLSmaPP4Buo5WAaDyqII2ZPuy1FBGzp51eq/fFg X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:c4a8:fdce:d8d3:7b02]) (user=mshavit job=sendgmr) by 2002:a05:690c:2b8b:b0:594:f596:e232 with SMTP id en11-20020a05690c2b8b00b00594f596e232mr325586ywb.2.1693914647753; Tue, 05 Sep 2023 04:50:47 -0700 (PDT) Date: Tue, 5 Sep 2023 19:49:13 +0800 In-Reply-To: <20230905115013.1572240-1-mshavit@google.com> Mime-Version: 1.0 References: <20230905115013.1572240-1-mshavit@google.com> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230905194849.v1.2.Id3ab7cf665bcead097654937233a645722a4cce3@changeid> Subject: [PATCH v1 2/3] iommu/arm-smmu-v3-sva: Remove bond refcount From: Michael Shavit To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: will@kernel.org, robin.murphy@arm.com, nicolinc@nvidia.com, jean-philippe@linaro.org, jgg@nvidia.com, tina.zhang@intel.com, Michael Shavit , Jason Gunthorpe , Joerg Roedel , Kevin Tian , "Kirill A. Shutemov" , Lu Baolu , Mark Brown , Tomas Krcka , Yicong Yang X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230905_045050_284869_B9CDDADA X-CRM114-Status: GOOD ( 15.62 ) 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 Always allocate a new arm_smmu_bond in __arm_smmu_sva_bind and remove the bond refcount since arm_smmu_bond can never be shared across calls to __arm_smmu_sva_bind. The iommu framework will not allocate multiple SVA domains for the same (device/mm) pair, nor will it call set_dev_pasid for a device if a domain is already attached on the given pasid. There's also a one-to-one mapping between MM and PASID. __arm_smmu_sva_bind is therefore never called with the same (device/mm) pair, and so there's no reason to try and normalize allocations of the arm_smmu_bond struct for a (device/mm) pair across set_dev_pasid. Signed-off-by: Michael Shavit Reviewed-by: Jason Gunthorpe --- Note that this is true today because iommu_sva_bind_device calls iommu_get_domain_for_dev_pasid to elude the iommu_attach_device_pasid if a domain is already attached. But even with Tina's patch series where iommu_get_domain_for_dev_pasid is no longer used, iommu_attach_device_pasid also checks whether a domain is already attached in the group's pasid_array. 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 32784758ccce6..9fb6907c5e7d4 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 @@ -28,7 +28,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) \ @@ -330,20 +329,11 @@ static int __arm_smmu_sva_bind(struct device *dev, struct mm_struct *mm) if (!master || !master->sva_enabled) return -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 -ENOMEM; bond->mm = mm; - refcount_set(&bond->refs, 1); bond->smmu_mn = arm_smmu_mmu_notifier_get(smmu_domain, mm); if (IS_ERR(bond->smmu_mn)) { @@ -522,7 +512,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);