From nobody Mon Jun 8 16:28:21 2026 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 229DE17B425 for ; Thu, 28 May 2026 02:56:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779936977; cv=none; b=tXf7xhETk1JnVtodGJlWs5qmxA4T82m98Hw56M7+gjn/DJoaOrlEiVf3mXKB6BoFOhkAptN03No47Y8rms4OsU7s+bFz2HHnWz0hOrYT5JzTvzEpkGlrjdXBijtkxzMpNQcJpq3xInZD1RUm27LtwIi6oyKe5WMj8YvWtfMTyW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779936977; c=relaxed/simple; bh=b23qsbPX6e2MSdXnbKgH6veJevmyNVpkSiIDY1F7Y0E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=PfBNn3Znu7G2i4u8AKt4nCq3upBmNmDZfUtFELWMrjZBaSoYFX+9KPSp/4G5aMir8vPyEyBHfoyoxxA25XR8/cZui0HiHEQ2tm1OYnjm7NesGvPkDHLmcxPKXA5G5dwtsD/+wK2/zPL5fF+vOfcxly7/IL63ntbFJoEKTsCIW9M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KuHlBFOb; arc=none smtp.client-ip=209.85.160.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KuHlBFOb" Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-5148cbdea08so102305361cf.2 for ; Wed, 27 May 2026 19:56:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779936975; x=1780541775; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=JYBoL5jG1iN0eoFpALE/QB8NqS4xj7k8hYReouwIAOI=; b=KuHlBFObFerNmEjMdbQKzbKLXX4UFs4OMlNNlwIFcgUvALewyoFmsn/0qITCRlt523 SzDLi/vkzrQwV6rvNVZoqMt4NgDu9hjmH7tsehB5doSwBTO33TTEXXTbJQXEQWSd5If8 K9qJXq6eTru6yyB1vpJ7YvKNzW8fUQxY4V759EIXtalL7Mmx5OXcq/FLgQ5vyI45ihXS dBPoYK5ahaba+nKoKpw9vWjhx9jFSxZzoYhjXIQxm1rPmhviGaEXVZE+i+mRjvos9mK8 pGVj+7CyODJy5L9jei+teF/mPtcBkYMOJWEpjnt67ulegIQmEJdVtIrD5F9gFovA8U15 uJKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779936975; x=1780541775; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=JYBoL5jG1iN0eoFpALE/QB8NqS4xj7k8hYReouwIAOI=; b=VADxtO1yBjbkMognnTfQX+uFV99kczDFzJObAOZ3I9lOKInV6BIZx3OAD9XQLUF9oq fEGFB5Qr/DkOFOh/7CGKFfTLt906PyFtkOJrK4h9pMcrr7UZC4BdfNq46Zm1JHo9yx0K IONpTcvvJMHYcho5ojBi+hpGSfeydNvQpVqeC97FxAEMjiqxgegpYoBjxPtGa6uAvOk/ VMv0h/VFzonPDYj0Lips3+4Rj6YQTxwpcSzN2VFG8XBDAMOQkpadC+k24Q5fUN2rgAuY cRVl54KX7sFM9cbQfWIK2Czwfp1XPP6JTjh8Vjf57w52b/o0POg/oevNtds3aMDvoKiT rH/A== X-Forwarded-Encrypted: i=1; AFNElJ/rm2OyHbWuuRPKp3TBAxiCydskLzBxIWLC5scPWIynTzij+D3JA3BqZG9MyVjvrYNPPHtif5yzbyAgiUY=@vger.kernel.org X-Gm-Message-State: AOJu0YwsHjauCj/jNrfs3j2moKfaFAHl3fBThQCKsEDYnK0tUTbjzimY 9Kmf9hM/A0fikI/2m30Eaqzg8I9sAkQmcBg0LOd3c+/mUxIP5oIvlBnKbGY+mpnk65E= X-Gm-Gg: Acq92OHa2VB3tTfDvEN1fCUwUiHQrtXtjOP50E2xD0nMtrVjnEE/MwQWB0rhgRRlNk5 O8UUX/RpYKFSH9uV3l4R8y5urgWJgu/TrXgk8oGNSrHvk5hrAQHySf3ycz1l3LKI6ibPJfemH79 poC8nwRHFBFKdn2VsdpbFpwePQSZNQKsLvm63hZNgLtV6aZC1ll5LCXAYA5Y/Hzxuw+mg/QLYfA yLbLkxOHDA1iHbcNyZF1SEGpfNbhVzMebjLgJ791MqaxeuyjZ+vp58UGrPEchCM78smK0rflmc+ xqUvkYcVaZBzWHVN6XXDhfdjtfLzVnZJNBybnWuRTh9htT10RvrrA1XeQ3K/X1MG2rGBfi0wUF1 yQe3+d0gse0hsKBatH29J6CLTmwz8aM4TcpdHELkqwo3zDP5mavM6xr8ugO80RcVRCRkje8N4cR m2gh3IeekN6e0RZM1gR0Pmd9X7yKetD6iXhq2qFbXyBQtHXpz7M6IxybILoaiAL2/wu6ZXeAG1g 9B2FDwog3FQ6dfzjpMbLJo7MiPABvg= X-Received: by 2002:a05:622a:1104:b0:516:dba2:143a with SMTP id d75a77b69052e-516dba23d77mr330748821cf.51.1779936975106; Wed, 27 May 2026 19:56:15 -0700 (PDT) Received: from server0 (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-517069f2d2fsm67556291cf.3.2026.05.27.19.56.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 19:56:14 -0700 (PDT) From: Michael Bommarito To: Lu Baolu , David Woodhouse , Joerg Roedel Cc: Will Deacon , Robin Murphy , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH] iommu/vt-d: Clear Present bit before tearing down scalable-mode context entry Date: Wed, 27 May 2026 22:55:57 -0400 Message-ID: <20260528025557.3209367-1-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" device_pasid_table_teardown() zeroes the 128-bit scalable-mode context entry with context_clear_entry() while the Present bit is still set. This creates a window where the hardware can fetch a torn entry, with some fields already zeroed while Present is still set, leading to unpredictable behavior or spurious faults. The context-cache invalidation is issued only after the entry has been zeroed, and intel_pasid_free_table() then frees the PASID directory pages, so the IOMMU can keep walking a stale Present=3D1 entry that points at freed memory. While x86 provides strong write ordering, the compiler may reorder the two 64-bit writes to the entry, and the hardware fetch is not guaranteed to be atomic with respect to multiple CPU writes. Commit c1e4f1dccbe9d ("iommu/vt-d: Clear Present bit before tearing down context entry") fixed this exact pattern in domain_context_clear_one() and the copied-context path, but device_pasid_table_teardown() was not converted. Align it with the "Guidance to Software for Invalidations" in the VT-d spec, Section 6.5.3.3, using the same ownership handshake as the sibling fix: clear only the Present bit, flush it to the IOMMU, perform the context-cache invalidation, and only then zero the rest of the entry. Fixes: 81e921fd32161 ("iommu/vt-d: Fix NULL domain on device release") Signed-off-by: Michael Bommarito Assisted-by: Claude:claude-opus-4-7 --- Found by static analysis while auditing the callers of context_clear_entry() for the same teardown ordering that c1e4f1dccbe9d addressed. This site is reachable only in scalable mode, so it does not manifest on the legacy-mode hardware available to me; I could not trigger a runtime fault and the change is verified by code inspection only, on the same basis as the sibling fix. Compile-tested on x86_64 with CONFIG_INTEL_IOMMU; no new warnings. drivers/iommu/intel/pasid.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index 89541b74ab8ca..40910dc7363b1 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -748,10 +748,12 @@ static void device_pasid_table_teardown(struct device= *dev, u8 bus, u8 devfn) } =20 did =3D context_domain_id(context); - context_clear_entry(context); + context_clear_present(context); __iommu_flush_cache(iommu, context, sizeof(*context)); spin_unlock(&iommu->lock); intel_context_flush_no_pasid(info, context, did); + context_clear_entry(context); + __iommu_flush_cache(iommu, context, sizeof(*context)); } =20 static int pci_pasid_table_teardown(struct pci_dev *pdev, u16 alias, void = *data) base-commit: 5200f5f493f79f14bbdc349e402a40dfb32f23c8 --=20 2.53.0