From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385099; b=zqkU52a9P/fIZR0kkxnqVBfDvcjcMvU5mx0GwhvPHeX0JYMaYLt2LU1PQNSouJLDQZZZ +1AJ+aRckOhAb8c61WlCRLoPlJ6gUvrEsf0L3E6GcZPyv3xTJjj4fcApoQ+4hVUNsMab7 5DHUQG8J8P/nDYqav+Go1id0J13hsefuU6gszH5/Xcvz+a8TF+dGQzD5fxC2VDnLWhyFS Qp3x/vrDZwG+N7G8a5yX9uhNnZBMPrN1eI64yT553r1iK48XgAVRQI1umaimz/GqtqeE8 Hl/Frh12OKp7PJkHwgZnhjDr3bs/ou91wHNGrMj5jNMrHe3JikTxUiyXAkW/HMza1OQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385099; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=fg9IpyNvNnJKMdeW/hhryKH9vHg14iSA2okmeU23JKM=; b=XttLzZe9qbX5mlxwwydQJ7kygcKxQc/QSjuI21S8C0x1AWW5DrUVVgBmeD3jzZSyyezC i0s02LMgL5myHW6DMW86XRBeWnOwHxg7zcBE2Tc59n+JB63EzCMXlT2/iaZjbbd7zThB7 6vAorVPRK0YGizMHbViUIvZSaDsHFvTn89dP0Uk1+p+BNUu8kBfz6G3cTKpllGj3/Pvxb 2O3G2ldFz2Ggoj8aIxvpXQ90WQ4WDqaQF1uZP8NY6SxBAFc7HEa5Ldf3mm7D/X7GeQwxI +xs3PytH0xdJUxMoCUYrX8gcEFy/qpxzTDp6PctCwnNDFqGZ2HUBdY3QNRzZV8utfBA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=WzowPjlT; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59FAC606A33C; Fri, 4 Dec 2026 11:51:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=WzowPjlT Received: by smtp.kernel.org (Postfix) with ESMTPSA id B78461F00A08; Fri, 4 Dec 2026 11:51:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385099; bh=fg9IpyNvNnJKMdeW/hhryKH9vHg14iSA2okmeU23JKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WzowPjlTH/Ny+zdLRvv4vsrZW/qKS6XQkK32oLP7fDggo1Z1W4InPAy3DfKHqd4YX d8gLcv0PABi4UycgbPgsOVSM5rbkIWvW6g57KTqYf/lnDtZNd5r7f40zdKUg3zts7y Bo9b9bEtNJjIcrIy0RG0q9Gv1L1btCNSKpj/LN3E= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Nicolin Chen , Mostafa Saleh , Will Deacon , Sasha Levin Subject: [PATCH 6.6 0367/1167] iommu/arm-smmu-v3: Dont rb_erase() a never-inserted stream node Date: Fri, 4 Dec 2026 18:56:34 +0900 Message-ID: <20261204100711.544835610@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Nicolin Chen [ Upstream commit 2888520bdcbe0599cfc77b2fad8dc6c95505a3cb ] arm_smmu_insert_master() skips inserting a stream whose StreamID duplicates one the same master already owns (bridged PCI devices can present duplicate IDs), leaving that master->streams[i].node zeroed and unlinked from the smmu->streams rb-tree. Both the insert error-rollback loop and arm_smmu_remove_master() then call rb_erase() on every master->streams[i].node unconditionally. rb_erase() on a zeroed node sees a NULL parent, treats the node as the tree root and sets root->rb_node = NULL, silently emptying the whole SID tree and breaking SID lookups (and DMA) for every other master on the SMMU. Mark each node with RB_CLEAR_NODE() after sort_nonatomic() reorders the array, since sorting relocates the entries and would leave the earlier self-referential RB_CLEAR_NODE() pointer stale. An un-inserted node then stays RB_EMPTY_NODE() and is skipped in both erase loops; inserted nodes are linked by rb_find_add() and erased as before. Fixes: b00d24997a11 ("iommu/arm-smmu-v3: Fix iommu_device_probe bug due to duplicated stream ids") Assisted-by: LLM Signed-off-by: Nicolin Chen Reviewed-by: Mostafa Saleh Signed-off-by: Will Deacon [ sashal: Placed the RB_CLEAR_NODE() loop right after master->num_streams is set, since this tree has no sort() call, no up-front ID fill and no build_invs, and dropped the sort comment. ] Signed-off-by: Sasha Levin --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 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 b9b1703a0132c..3131f86f143c2 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2611,6 +2611,9 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu, return -ENOMEM; master->num_streams = fwspec->num_ids; + for (i = 0; i < fwspec->num_ids; i++) + RB_CLEAR_NODE(&master->streams[i].node); + mutex_lock(&smmu->streams_mutex); for (i = 0; i < fwspec->num_ids; i++) { struct arm_smmu_stream *new_stream = &master->streams[i]; @@ -2646,7 +2649,9 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu, if (ret) { for (i--; i >= 0; i--) - rb_erase(&master->streams[i].node, &smmu->streams); + if (!RB_EMPTY_NODE(&master->streams[i].node)) + rb_erase(&master->streams[i].node, + &smmu->streams); kfree(master->streams); } mutex_unlock(&smmu->streams_mutex); @@ -2665,7 +2670,8 @@ static void arm_smmu_remove_master(struct arm_smmu_master *master) mutex_lock(&smmu->streams_mutex); for (i = 0; i < fwspec->num_ids; i++) - rb_erase(&master->streams[i].node, &smmu->streams); + if (!RB_EMPTY_NODE(&master->streams[i].node)) + rb_erase(&master->streams[i].node, &smmu->streams); mutex_unlock(&smmu->streams_mutex); kfree(master->streams); -- 2.53.0