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=1796387646; b=t+v2CqP6liqotdcQo6bjGjpR57UwAfanKGcVa4lek/QfghfnHjzAeEyvjmydLDriiLyn lJgg/8fsAMU9wVo4biVwI8ndwT2rpnA13zLJfQOh7W6psY3+OGQN2X6ORdRkyOFWQkT/M lDvJ7GP0/8m+veEUSPGHFXMlSZD5YX5OljDurRh4ZICMWxCXfFvX5osn6p+rcWQzA0hY6 SxJELaBrXqfa5OL/ueJW/oCO33oem9nJFZgjJzVgGn9JrkDhqC8iHBupYc3NxSBb6K7X1 E6GZq146237FMhXDTB4744AoODQ1aoZpclcFNiMSCMmOaxbsIM5mAie88Y70A6PcOlg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387646; 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=6KVEgpmXeu2Yqd3EjJZLaq+87vdnPX+ftl1uUQ7Xqe4=; b=ftBBqx4ETguTjvggeEjbc46qNDzJ+GEzTpp6wfL/DfeYjW5wjeNVdP+kQYq8pXM1wyfj 8YO89fU3t3MpYKtGclNXIF+FCyYF8bqYD4rcBsXsbetX5qtAdxURxPZ/cCfTIq6Ct5Wlo gYBOKGK9Lrxw4xQ66yukwDIbsLGvd0YDCEf2ugMzjDxiIPs+1OsU3lonUmY7DPHE8hmLy eY9EX2LkhdWOMNV8AHItYVBXoh/sEX2nQKlKAB29akM4paJHcbL306hiE/NinswjE60dJ beYD8Tx6ms1kSaxAXlWnr7M5DAoTDIRRNGzygqdkSBPLat0yHqyV1nlp6D0JLMLyjLg== 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=JJwm2Nov; 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 61DBA606A32D; Fri, 4 Dec 2026 12:34:06 +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=JJwm2Nov Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB0B61F000C2; Fri, 4 Dec 2026 12:34:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387646; bh=6KVEgpmXeu2Yqd3EjJZLaq+87vdnPX+ftl1uUQ7Xqe4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JJwm2NovaVNUdZzOzYYyWXAIh1WPWgraRh5gWyNCTq0RyZJJQ8vY2M0mvcTm1glCZ 6WSezZ6weW7tQQ4OEUwmp0Lh05Qa3wPIA+vXSIee1laWtQDZr8Si2mNAZJOrlXVBGH 5Gbpi75xq6DAU8qvR+Wdqh7hLlR5uaaU5smMKsFc= 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.1 0332/1059] iommu/arm-smmu-v3: Dont rb_erase() a never-inserted stream node Date: Fri, 4 Dec 2026 18:57:43 +0900 Message-ID: <20261204100652.866326212@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-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 before the streams_mutex lock, since this tree has no sort_nonatomic() call to anchor it after, and dropped the upstream comment about sorting. ] 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 182179d62a51c..5529bebe7bb5c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2626,6 +2626,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]; @@ -2661,7 +2664,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); @@ -2680,7 +2685,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