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 79D2F2397BC; Sun, 26 Jan 2025 15:08:52 +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=1737904132; cv=none; b=ht2e21B8c76UQfS3mwzNCKjmPqb2adM9YKFQEun2gSeY1TP7nBdKf8tZg8RXtmSlRS7zAtslAQ3/fES8bfFLzwDx2pRq2Cg2zZD0vIDVdyefG2c4CyUggvQMe1wlUOuxqq6pyrzLZhLuAM4IIa3m8h1gQko4nbskvVzruUye00U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737904132; c=relaxed/simple; bh=w5ou4aymrycn9YCZ0dGlUhtssM+6saQcaT9B4ULTHdw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SqVhjxgIq2o+Rlq6E1ZNpbXbcjD6lSkLRNis8hzMPzBVctFUrsf//N7+vsY4haJ7hTPqvgyQHZKLgvEg+86Nqil3d/pO5pOMqSOvOCT+0OGKHfLGBouN443J0QadD1c3ZID+Pzk26wxhMtt4tfHueSVg8QpgkfpzqmvfpcxxZFI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l8XdL9t+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="l8XdL9t+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92B76C4CEE2; Sun, 26 Jan 2025 15:08:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737904132; bh=w5ou4aymrycn9YCZ0dGlUhtssM+6saQcaT9B4ULTHdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l8XdL9t+1BuhdslL4Bh90flbBQ17ouejul7QMpZ4ZquFYd9B/EWiTRaZ4sh2yiOTH jP5K/RtiuLFLAU3DGoMd0gsYQgPQKE3NQxZFjwoaGzTokK5C37THOv76Oz45k0fgR9 lD5n8dpz1ZdzHTX970MqhmXPdbHrGl5g9NtiSSWqtOCez7LNKarXbGfABl2EYslgH/ A3wXjHSTmYNhJte1LtiWEHBnImMUA+g4CZ7DWuUCvq0PdNuPH+cgbYTJ39lEboJYCp mZPiYeSfe2UU6gcaQ7mpci1lQ1qD59mlmVynbDk42wGxjIQBb3TnQs7VSxx4F9BmYg DlcaJMEPxX+cA== 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.6 4/9] iommu/arm-smmu-v3: Clean up more on probe failure Date: Sun, 26 Jan 2025 10:08:32 -0500 Message-Id: <20250126150839.962669-4-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250126150839.962669-1-sashal@kernel.org> References: <20250126150839.962669-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.74 Content-Transfer-Encoding: 8bit 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 68b81f9c2f4b1..6cecbac0e6bab 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3875,7 +3875,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); @@ -3886,22 +3886,29 @@ static int arm_smmu_device_probe(struct platform_device *pdev) /* Reset the device */ ret = arm_smmu_device_reset(smmu, bypass); 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