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 8990A429000; Sat, 12 Sep 2026 13:01:05 +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=1789218066; cv=none; b=oVjCNPSUzBAIF7Czfbqz385jOItLWAUvDEEnMQ9VRP1r+Nw+nNcfkSDVLSAgshzbpBhwL8/vWHIMjwpbgnKfUeGR1xeg6aBDsnBkgLy4C/DNrGht1WGqhqiHEi958H6caou0B5HBB21Tl6tQMZpSVRDF3dGn8dhfTRtptiOSdoc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789218066; c=relaxed/simple; bh=4cYBez3V8vZydDyk/Y0wjR7SfF7piX/n6nB72rDH9rk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nM3+jCYHZZt4uuYHPtA2wcuvSR7iMfs3Cdqbf+ZRADFMWnRrj/1zy2eI77SuvqjVIUsDwRea/VYXFcb0SN1FM3vkDe/PhaFGRg9zNSxMQYxJr68nTZpiVVrp1bu4HwwwARX1Im+rVyCwUPXpsueFkgFTyJcnupDxOTQXyucGGF4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=tqPxPdPO; 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="tqPxPdPO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D5221F000FF; Sat, 12 Sep 2026 13:01:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789218065; bh=TBphI9TFIFTuIlqkXlo8IapWZSRmDSI0x+ieycYFCOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=tqPxPdPORf3WdNvnox9g/DrcFBvuCfMwYWbbKcMLv4p0R+twfRZcH8DavNkMXf3s7 P99anTpfBfE2PK6Dt8wgvzskpmFMmu9agSwgKcok41U25F+Xjco5RZkWJWd2xEcyZa eAjPxBqkssPSrwQjsqGHLefvZS7LFBIaI/7l/se8= 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 1025/1376] iommu/vt-d: Clear Present bit before tearing down copied context entry Date: Sat, 12 Sep 2026 08:57:31 +0200 Message-ID: <20260912065630.407327169@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-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lu Baolu [ Upstream commit f532c57985b1a7d6b7e37e05506b46d413e5cca4 ] copied_context_tear_down() zeroes the 128-bit context entry with context_clear_entry() while the Present bit is still set, and only then issues the context-cache and IOTLB invalidations. This leaves a window in which hardware can fetch a torn entry, with some fields already zeroed while Present is still set, leading to unpredictable behaviour or spurious faults. While x86 provides strong write ordering, the compiler may reorder the writes to the two 64-bit halves of the entry, and the hardware fetch is not guaranteed to be atomic with respect to multiple CPU writes. There is no cacheline flush before the invalidation either, so on an IOMMU without coherent access to the context table the zeroed entry may not be visible to hardware at the point the invalidation is submitted. Apply the same ownership handshake described in the VT-d spec, Section 6.5.3.3 ("Guidance to Software for Invalidations"): clear only the Present bit, flush it out to the IOMMU, perform the invalidations, and only then zero the remainder of the entry. Fixes: c7191984e5aad ("iommu/vt-d: Factor out helpers from domain_context_mapping_one()") 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1607,7 +1607,8 @@ static void copied_context_tear_down(str assert_spin_locked(&iommu->lock); did_old = context_domain_id(context); - context_clear_entry(context); + context_clear_present(context); + __iommu_flush_cache(iommu, context, sizeof(*context)); if (did_old < cap_ndoms(iommu->cap)) { iommu->flush.flush_context(iommu, did_old, @@ -1618,6 +1619,9 @@ static void copied_context_tear_down(str DMA_TLB_DSI_FLUSH); } + context_clear_entry(context); + __iommu_flush_cache(iommu, context, sizeof(*context)); + clear_context_copied(iommu, bus, devfn); }