From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 13BA5430781 for ; Tue, 4 Aug 2026 02:49:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785811747; cv=none; b=b9tab3Ix5M+ZNS0EgthyZ3rN+yK+EzbU0L9qjsF+7SKk22y1YfmbIhCe6BZ5w2HcQsqAYMy1U92jvjMWRGzpaZaIHWxWt2JVrPQLnQPGdK4qJBigxXnt+9H27AKjonEg3tlC6nu4Mz9/VD3aHrQloBc+Nctp4qF7tA0QhYc7w/s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785811747; c=relaxed/simple; bh=pnwJe36D1sL/gNEszmY3UecgU2zT9dRDC3/tQgH4P6c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mN3USMV6AxvKp6NxE5gfaq+FH158ve2mkIPoqcczjhsqGUHF7skE/5BHOMJlOg6kdQVzDnXJkPxWDeREUfslgHwL0F2fAEgzM8lUFXbiQqwck6gLjI/jSHvIaAu833Iz0+n6qDtMGK1Eu9bZi3BIkg+9iQucU7yaij70FDLZ95I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Yfbjdol1; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Yfbjdol1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1785811746; x=1817347746; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pnwJe36D1sL/gNEszmY3UecgU2zT9dRDC3/tQgH4P6c=; b=Yfbjdol1hfDrCeqcG5Woojrsge2bqaU/RW/HxwCoMlf3KYCoOxEx+PYq PK8OA7z88Wfen/PRPB28MfUGBT7hCxiCSHauOu7pbi4CRVLWdR/6P4oaQ ZqSvrMJ/2ptEoXZXhOg/YCD9WSWH9I7RT5Ofx+4Rv88zWdnIv2S6ydceB OVfmkkjf71OJkhIh8FyTSjxl6/tQtMfXepx4SWDDpkxZf4Y6N3To9Pnub SLlQXH04/llSrMtGQ0rdgFP1pSoq25C55HtwhMiE8H3VbiF1kEIMmt3qT //IIWrTM1FD46jd+ZqRGmwCPOv8SDlPhymWkez4GfxYWszI8ya+5JTvFE A==; X-CSE-ConnectionGUID: IW7FA+8YQs+PEtRW2Vni9A== X-CSE-MsgGUID: B+m/RgKrQ0OJREBWHBN1ww== X-IronPort-AV: E=McAfee;i="6800,10657,11864"; a="86231383" X-IronPort-AV: E=Sophos;i="6.25,203,1779174000"; d="scan'208";a="86231383" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2026 19:49:06 -0700 X-CSE-ConnectionGUID: d2ixe8DhRsm+bxtHqPRcVw== X-CSE-MsgGUID: FtOQCQoqTYaFlF+btNPIQg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,203,1779174000"; d="scan'208";a="259587644" Received: from allen-box.sh.intel.com ([10.239.159.52]) by orviesa006.jf.intel.com with ESMTP; 03 Aug 2026 19:49:04 -0700 From: Lu Baolu To: Joerg Roedel Cc: ZhaoJinming , Kevin Tian , Dmitry Antipov , Guanghui Feng , Li RongQing , Desnes Nunes , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 19/20] iommu/vt-d: Tear down scalable-mode context on probe failure Date: Tue, 4 Aug 2026 10:37:13 +0800 Message-ID: <20260804023714.3080506-20-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260804023714.3080506-1-baolu.lu@linux.intel.com> References: <20260804023714.3080506-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- drivers/iommu/intel/iommu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 9003783d02bc..489bab4999fb 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3333,6 +3333,7 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev) return &iommu->iommu; free_table: + intel_pasid_teardown_sm_context(dev); intel_pasid_free_table(dev); clear_rbtree: device_rbtree_remove(info); -- 2.43.0