From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E8C926B08F; Thu, 13 Feb 2025 15:00:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739458842; cv=none; b=hfK73vxBzTxDXuWjGt5OerKqOw7NWNLQ6JNjnDSW8eVMkgxKC03XrXvy/JtnLF/MBnnVEwAcJhuKLOiOPN3g9zpLsD0rEbGZ4dnAPLeDhe51TmOW/OYeAiBnILoAczmL9fsRUn6kYz/OPo7wdbzLIZhU0vbYJavEbL5HioGFHJw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739458842; c=relaxed/simple; bh=TIzFIVrWo2yCv/ZpctbHjoMifdOA3b8cAWXVWdkfShE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YpFo3nujRuCZ/1qjMmT2H8CEVO9R1BvEGfG79SmD1uEsWMOSL+N/xSjhCBRJvPX1JAUrVAPqzm3J85LdEjTo2n/W7hZpg25ljny2HfvRp/emqcvluX3sTVDgmK7LcrCaZA3Wm6LAJua+IyFm4/DSWUJCLCD9WKvrSDPrfZBqx7s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=KqyXHd6N; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="KqyXHd6N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FFD2C4CED1; Thu, 13 Feb 2025 15:00:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1739458841; bh=TIzFIVrWo2yCv/ZpctbHjoMifdOA3b8cAWXVWdkfShE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KqyXHd6N1DySaooqsILeaYCI5eNYLYDGFoWlXk4cxWfboDmvAY5c8a3X+fV3rMmxg crWmeep0fMoSich9w5sSyseh0vRdg8uzFFHZlNreUHHkw3xrpuHLYMmRBW7MOh3IJd Ooz8VLYO33NWFDzGX4cJ8FImvZLEkUZYA7RVjHrI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Robin Murphy , Will Deacon , Sasha Levin Subject: [PATCH 6.13 092/443] iommu/arm-smmu-v3: Clean up more on probe failure Date: Thu, 13 Feb 2025 15:24:17 +0100 Message-ID: <20250213142444.160408396@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250213142440.609878115@linuxfoundation.org> References: <20250213142440.609878115@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.13-stable review patch. If anyone has any objections, please let me know. ------------------ 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 6d15405f0ea3e..42a89d499cda8 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -4670,7 +4670,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); @@ -4681,22 +4681,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