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 090FE281353; Thu, 13 Feb 2025 14:35:27 +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=1739457327; cv=none; b=pzlWF1hJr89PW/FsyfWWQh4Rp52/1h3hbZDgkC6vQ1EfZNWDBoOUMiCCASq77n5R1Tzc823MTtrNzkN5mo7NfZSimJG9a3ctYY2lJu2Lw9fw6WnzXYUq8VyCoGUwRJmzIi8bqJN/zwoveEet7gmXWzKLnmqZG/DgOdCtudKJt1M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739457327; c=relaxed/simple; bh=mQUzw0zJxTMC6IXV8/NFeXr76szkLg8VOsWKeWVCK9A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DYqe9rVckDOzCtraufjWP5bGd7iKayKdNQ6NIR8osVtiRHlN73ofrzhixgbzZ9apqKhuF/YVuID7jXLx8GtgsrDfiSdF3UzRSmQ8USp7+2JJI3wuWICI9gNI/X4aPDDmPD8tLrVWv8vaEXKvLP0R6QxI6QX0aPmHrRh+0mH7V84= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Kq1BceQg; 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="Kq1BceQg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7699EC4CED1; Thu, 13 Feb 2025 14:35:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1739457326; bh=mQUzw0zJxTMC6IXV8/NFeXr76szkLg8VOsWKeWVCK9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kq1BceQgVP5wtz4d37alhgXWqulTSSMU7dicxaELc1bHbDxl+M+cBqZFN4Vqc3zjy VADwbPgsJOMq0hXsHLpvwAVXcWw3jyNLvWJSBIk6u84aIf21Y7DX+8r8KJURgKGdp/ weVFQw7tMSUJ998pwEdMNYk7WPyTN6ZhJzm3PT50= 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.12 080/422] iommu/arm-smmu-v3: Clean up more on probe failure Date: Thu, 13 Feb 2025 15:23:49 +0100 Message-ID: <20250213142439.641730876@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250213142436.408121546@linuxfoundation.org> References: <20250213142436.408121546@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.12-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 f1a8f8c75cb0e..6bf8ecbbe0c26 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -4616,7 +4616,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); @@ -4627,22 +4627,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