From mboxrd@z Thu Jan 1 00:00:00 1970 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 9BE94C02181 for ; Sun, 26 Jan 2025 15:10:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=w6j2KN3l0Bcs13d2EoJMDvXRdm5JsCvCEkqQwM97RWU=; b=paqqMRgSF8BSuvLYN9WyBAiTUV SgtmxfIB1iCxtgCn5Q9mbp+i+j57Zli7Ly1FnSIWwClazBbHG0/N3naQp3ohjxh9tfYlQAAur+2vC rtUe6aiVfetq7MTK3spgkz+MF4u67izgWQsbomuF03QX6gM6s8YDAO0cM8h40kxHP+eLFnfX1v4p4 Wd1G9y/q0bnstZapgSsyCOG6ZpA/hjtchdNCHZGjGVFKhiQ9GBJ+uyHMnRaBGrZ4QWewH1vJEunOn W8NAtgxBHk3HqW5ofR6/GN4TAgR5ndfNh4DySeFqFKxoM5nPXf4xHFCEm/Q5W3QAMt6OyhKSsVfO7 fqFMFH4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tc4HD-0000000HZak-2dY4; Sun, 26 Jan 2025 15:10:19 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tc4El-0000000HYlY-2LT4 for linux-arm-kernel@lists.infradead.org; Sun, 26 Jan 2025 15:07:48 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id DED5A5C5DD9; Sun, 26 Jan 2025 15:07:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69B3AC4CED3; Sun, 26 Jan 2025 15:07:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737904066; bh=VwtHtXRZokdyObfCFfPJnG6JQySXwP52lYn0MqDKdn4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Om1VNdi2GgGXNL/iAbl6Zw03vQo1fax2LhAl8a+F1VK281haejl7BtLJ/UezKuzu1 Vu3kESI129QEmnKu4kCQJZSOwkmBV0r/67up3g7nag/jJSbMcUh2vIXsnUxzUWiYcc Ff3CGuOg2nrmxl/FuO+dRyAIbfm3zQHrbQd5dX5x+nfqscAxexltukBstf4TL0/IFl Gvn46xdu2YU2Y4jv/BJ8fd+KgKS/jtjps7vIIzccW5ApmVsqQBMNWh0hZEub/OjMfo RolTIRBPp7gWSB/Cak8pcp8rQf78yseRxxwl2CiDB/5oZPOlB2GU6+EJUx3RwkOYXR Ynvv5Hw1fvEBw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Robin Murphy , Will Deacon , Sasha Levin , joro@8bytes.org, jgg@ziepe.ca, nicolinc@nvidia.com, mshavit@google.com, smostafa@google.com, praan@google.com, linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev Subject: [PATCH AUTOSEL 6.13 07/16] iommu/arm-smmu-v3: Clean up more on probe failure Date: Sun, 26 Jan 2025 10:07:09 -0500 Message-Id: <20250126150720.961959-7-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250126150720.961959-1-sashal@kernel.org> References: <20250126150720.961959-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.13 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250126_070747_699123_9BDC4CA8 X-CRM114-Status: GOOD ( 12.98 ) 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 From: Robin Murphy [ Upstream commit fcbd621567420b3a2f21f49bbc056de8b273c625 ] kmemleak noticed that the iopf queue allocated deep down within arm_smmu_init_structures() can be leaked by a subsequent error return from arm_smmu_device_probe(). Furthermore, after arm_smmu_device_reset() we will also leave the SMMU enabled with an empty Stream Table, silently blocking all DMA. This proves rather annoying for debugging said probe failure, so let's handle it a bit better by putting the SMMU back into (more or less) the same state as if it hadn't probed at all. Signed-off-by: Robin Murphy Link: https://lore.kernel.org/r/5137901958471cf67f2fad5c2229f8a8f1ae901a.1733406914.git.robin.murphy@arm.com Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index a5c7002ff75bb..0beb3e9ee3c67 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -4663,7 +4663,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev) /* Initialise in-memory data structures */ ret = arm_smmu_init_structures(smmu); if (ret) - return ret; + goto err_free_iopf; /* Record our private device structure */ platform_set_drvdata(pdev, smmu); @@ -4674,22 +4674,29 @@ static int arm_smmu_device_probe(struct platform_device *pdev) /* Reset the device */ ret = arm_smmu_device_reset(smmu); if (ret) - return ret; + goto err_disable; /* And we're up. Go go go! */ ret = iommu_device_sysfs_add(&smmu->iommu, dev, NULL, "smmu3.%pa", &ioaddr); if (ret) - return ret; + goto err_disable; ret = iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev); if (ret) { dev_err(dev, "Failed to register iommu\n"); - iommu_device_sysfs_remove(&smmu->iommu); - return ret; + goto err_free_sysfs; } return 0; + +err_free_sysfs: + iommu_device_sysfs_remove(&smmu->iommu); +err_disable: + arm_smmu_device_disable(smmu); +err_free_iopf: + iopf_queue_free(smmu->evtq.iopf); + return ret; } static void arm_smmu_device_remove(struct platform_device *pdev) -- 2.39.5