Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 575DD429000; Sat, 12 Sep 2026 13:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789218071; cv=none; b=QB7MKEVd0QOnN17oh3O3V9/50BCyIGOy9BkjVex2/hZrHO1zlxyFxXECa0dvJYoqnc8IX6ny2LUyV97BPCtKgPk9DyxB+aPGWNSvFTzmW+M/5oI64IYYhWj0ge2EYg4qJhLd9jL+EjICRsWWwBG3h1akjZnjzN7nQwQ9CBvLFJ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789218071; c=relaxed/simple; bh=xhMBCopPpE91MDRYz3eSNyiDCg+tdReyHm2a/jt1f7U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Y84UuYryMZdRNkoA0imABOeir/OhTAYUwwz27n4Ht3l6C2rkbNQHH34hnIGWDyRdP4x0UKUsdSaYXy2g/tke2cDU7OJah5Bym4508JZuMuhgMqfExdhQOLIylqc3D9f3/LRxHtGew1OCef4y+Rz5bDdL18kPPyhMg2nWwM7UEcY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=FTgLHD01; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="FTgLHD01" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12EF21F000FF; Sat, 12 Sep 2026 13:01:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789218070; bh=+xfOo1JKS11D7LXStmdhDeaP1SLBGV/bT6g0E97gFSU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FTgLHD01HdatcLKUbtaS5RKOE4lI9hV1NsLC9G0UWTQDnNOPRKen7Hbsi6Fs3C063 0TrDRzl4JykOomCzKDL2lzUB7pQj+CuT0Luch4BRAdAPDPxIbr3SBnvMtIjNPHA8Bd eBT4Gg/vwEZA8SH5AkHa11tV/rzdZm4AcsoehC4A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Lu Baolu , Joerg Roedel , Sasha Levin Subject: [PATCH 6.12 1026/1376] iommu/vt-d: Tear down scalable-mode context on probe failure Date: Sat, 12 Sep 2026 08:57:32 +0200 Message-ID: <20260912065630.429152119@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065607.535295758@linuxfoundation.org> References: <20260912065607.535295758@linuxfoundation.org> User-Agent: quilt/0.69 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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lu Baolu [ Upstream commit c509fb73a1093a15accd7d43a61645d4b520f6ac ] intel_pasid_setup_sm_context() walks a PCI device’s DMA aliases via pci_for_each_dma_alias() and programs a scalable-mode context entry for each RID. For a device with a dma_alias_mask, the callback is invoked once for the device’s own RID and once for each alias bit, all with the same pci_dev, so device_pasid_table_setup() runs for multiple RIDs. pci_for_each_dma_alias() stops at the first callback error. Therefore, a failure partway through the walk can leave context entries for already processed RIDs present and still pointing to the device’s PASID table. On this error path, intel_iommu_probe_device() currently jumps directly to intel_pasid_free_table(), which frees the PASID table without first tearing down those context entries. The IOMMU may then walk a present context entry whose PASID table pointer references freed memory. intel_iommu_release_device() already performs teardown before freeing the table. Apply the same ordering on the probe failure path. device_pasid_table_teardown() safely handles RIDs that were never programmed: iommu_context_addr() returns NULL when no context table has been allocated, and clearing the Present bit of an already non-present entry is a no-op. So unwind is safe for both the alias that failed and any aliases not yet reached. Fixes: 301f1a80487fd ("iommu/vt-d: Setup scalable mode context entry in probe path") Reported-by: Sashiko Closes: https://sashiko.dev/#/patchset/20260602233426.357499-1-baolu.lu%40linux.intel.com Assisted-by: Claude:claude-opus-5 Signed-off-by: Lu Baolu Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/intel/iommu.c | 1 + 1 file changed, 1 insertion(+) --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3997,6 +3997,7 @@ static struct iommu_device *intel_iommu_ return &iommu->iommu; free_table: + intel_pasid_teardown_sm_context(dev); intel_pasid_free_table(dev); clear_rbtree: device_rbtree_remove(info);