From nobody Wed Jun 17 06:02:59 2026 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 E764A373BF4 for ; Thu, 23 Apr 2026 10:09:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776938979; cv=none; b=rUzUJWdOnNC0aEVO2ozDr8sy5IjK5jpVQY5Qz6prr5Rw4kBJg6wt6CJceBltDVAN0DK9dpvg4SGqnTuwsfVNUoqF1rtUYkoo0/UgaRyJFBVfLO2VbMJznALIUSJ6oypvEvBlYratomS94Evuje/Q5T5GHrbOXV605ci+/LLg5Sk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776938979; c=relaxed/simple; bh=UTlbVQte9MXWRTLRKgI2LMgHRO0jaYQooyHaYcX98aU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=H85sW/1rVUEZlf5Xl3EUqSdOag8yqTNeONmHlKHKwi3++SJva3Oelb48NLYIKBv3fZf5zm7u78r+KZnZ7X1qDjJsjycEEMcRlGITIOnoJFeFcdTWeZT/UDp2td/DyOjCNNZ31MvfWzOlskoj3sZpF5MRCdiyjI/r06qwrgLTHwo= 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=juohZ7uP; arc=none smtp.client-ip=209.85.216.46 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="juohZ7uP" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-35fb166b0c6so3749028a91.0 for ; Thu, 23 Apr 2026 03:09:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776938977; x=1777543777; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9hw3+dt4upvwPZbcilhyfG5LgQIqATsWm5ea0NmPrr4=; b=juohZ7uP31L4eLYx2MIWQQo2PZjSza5N3Mu6X7d0r5Br4kpMrF5nMo+ATaiZloSw0O rrij3dT6pZg/QV8USUVwVjrm09qL1qNxrzAiEu8RVk5vlzVtjR5X8137uTTWIRrRmqzA XOgSCJqQVmhTCUFjBEjqmworhx+HZ/pzTh0FTdkx/4VkLa5sgj6z8QISAwNxAzmYvr5w aiC+swWNcbtf/NAAwJiPl9dd9T6Qbe5HYLdAL/ms0f4M4WTCWteK+JGUJZACClvw08ka DDyx7y1vL//i9lCjOzxVKe8dejt+g3PJUiuuJtAQP962bjam0tmjtHRM4krKlLG8/Pbf XKOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776938977; x=1777543777; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=9hw3+dt4upvwPZbcilhyfG5LgQIqATsWm5ea0NmPrr4=; b=OA95VRCIXvPdIwOBSR1eadbuj2h089MmWLxOrfgV5Gh0W/V8QhmWVhg3mnlwF9xGIL EBZ9OzTRE8QBvT9nRlOqAcKympTM3gV8HGdypeqI+2AnZPDWcfJUoJwTmDmRDbvLmgeB 8iYFyEm/k9f4tMFeTuPjhFZE9Erb8gEwB7hB9i+MnrxwGSW4W7W2ATp2wYPWRQCyi4C8 vSL1r1XzNYcUDvUuh1lZEixXePFzPZNrIz65YGcV78aa0Yk4ptd6Rxuuskx9NMpqoIOg DZwK3QNNk3stCH3XyPvKo2s2m6VDoWi4Xkc54AJXEvT7p5m0sL2nWGiY39dwgfICCOy7 y5kQ== X-Forwarded-Encrypted: i=1; AFNElJ+m3tmO5NxzHXlMiPf+CAWuqpwAdGzhf6Y6t/8+VX0LJ5lbvtiFutqSxUzzJQIMu2abKCbo1V2RHOS+MUI=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2MOjgNL5bOpod1iNHnuUELxnE00o+0YsmDi+5MQlwspA/SK/J UYFynKq4yCxBPz5uDgTZz8KZlkA1aLniIgmomxw9J4pWEDoUN9Z/h+4g X-Gm-Gg: AeBDiesTR2TWSL5JFdOEXR2Btt2LEBUgHsTG7Dku6gEQWFKKTCHTJLt65MSu16BGnaF UIXP7inXgwJMtXMUYenCiu0E+g2kKFl36AYXk8FZA47rnQLrQiOl9+6xonXdhmVsEXCu0qahiyD rDWitfqbZoCkAFTD0S0iOkUjY8yQR8iVBX+AdzNxLY60P8KRM1HYd9jkMQm4JpYP/To5Q2KblCw NkGHWOPDQOJJz7l70EGEe1pMw24x7hg/KvnuXPFifgXOeXjmQjny2jthEBbi+BF0MpXDrlFIs3U 7SPBPZciv56xO5U2ONCV7o1i4Yxg32T5ypGy1yDuG2fHcjcs8NIfHuim5GQZYUZ9mkHdV6LMNaJ mbJosx+JlrRQOWDyx8LsebS084kJ6GqYEliooseCW+x8e47O3obxeAfBQ3g149GdXEFfKkttd7W 0Hz2ZSet2LNzP22Hvsyb0LtVhKX5oLdpvesA== X-Received: by 2002:a17:90b:4b83:b0:356:21e9:73ff with SMTP id 98e67ed59e1d1-361402ebfebmr20950907a91.11.1776938977213; Thu, 23 Apr 2026 03:09:37 -0700 (PDT) Received: from fedora ([2401:4900:1cbc:314:9667:4972:a94c:125a]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36140fc5d94sm25275714a91.2.2026.04.23.03.09.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 03:09:36 -0700 (PDT) From: avinash pal To: David Woodhouse Cc: Lu Baolu , Joerg Roedel , Will Deacon , Robin Murphy , avinash pal , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Giovanni Pancotti Subject: [PATCH stable 6.12 1/2] iommu/vt-d: fail map loudly on stale DMA PTE Date: Thu, 23 Apr 2026 15:39:03 +0530 Message-ID: <20260423100904.5966-2-avinashpal441@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260423100904.5966-1-avinashpal441@gmail.com> References: <20260423100904.5966-1-avinashpal441@gmail.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: quoted-printable In __domain_mapping(), when dma_pte_present(pte) is true the existing WARN continues execution, leaving the domain in an inconsistent state: a new PTE is silently installed on top of a live one. Replace it with: - pr_err_ratelimited: prints conflicting vPFN + old PTE value - WARN_ON_ONCE: one-shot kernel warning with stack trace - return -EEXIST: abort the bad map; no silent corruption The root cause is in the unmap path =E2=80=94 see the companion dma-iommu.c= fix. Reported-by: Giovanni Pancotti Link: https://bugzilla.kernel.org/show_bug.cgi?id=3D221389 Cc: stable@vger.kernel.org Signed-off-by: avinash pal --- drivers/iommu/intel/iommu.c | 50 ++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index c799cc67d..4a8937b44 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1777,14 +1777,25 @@ static void switch_to_super_page(struct dmar_domain= *domain, pte =3D pfn_to_dma_pte(domain, start_pfn, &level, GFP_ATOMIC); =20 - if (dma_pte_present(pte)) { - dma_pte_free_pagetable(domain, start_pfn, - start_pfn + lvl_pages - 1, - level + 1); - - cache_tag_flush_range(domain, start_pfn << VTD_PAGE_SHIFT, - end_pfn << VTD_PAGE_SHIFT, 0); - } + if (dma_pte_present(pte)) { + /* + * A live DMA PTE is already installed at this vPFN. + * This violates the map/unmap contract: an IOVA must be + * fully unmapped and the IOTLB drained before reuse. + * + * Root cause: missing iommu_iotlb_sync() before + * free_iova_fast() in __iommu_dma_unmap_sg() on the + * lazy-flush path. The companion patch in dma-iommu.c + * fixes that; this guard makes the violation explicit. + */ + pr_err_ratelimited( + "DMAR: stale PTE at vPFN 0x%lx (val=3D0x%016llx) " + "-- IOVA reused before IOTLB drain +", + iov_pfn, (unsigned long long)pte->val); + WARN_ON_ONCE(1); + return -EEXIST; + } =20 pte++; start_pfn +=3D lvl_pages; @@ -3663,10 +3674,25 @@ int prepare_domain_attach_device(struct iommu_domai= n *domain, struct dma_pte *pte; =20 pte =3D dmar_domain->pgd; - if (dma_pte_present(pte)) { - dmar_domain->pgd =3D phys_to_virt(dma_pte_addr(pte)); - iommu_free_page(pte); - } + if (dma_pte_present(pte)) { + /* + * A live DMA PTE is already installed at this vPFN. + * This violates the map/unmap contract: an IOVA must be + * fully unmapped and the IOTLB drained before reuse. + * + * Root cause: missing iommu_iotlb_sync() before + * free_iova_fast() in __iommu_dma_unmap_sg() on the + * lazy-flush path. The companion patch in dma-iommu.c + * fixes that; this guard makes the violation explicit. + */ + pr_err_ratelimited( + "DMAR: stale PTE at vPFN 0x%lx (val=3D0x%016llx) " + "-- IOVA reused before IOTLB drain +", + iov_pfn, (unsigned long long)pte->val); + WARN_ON_ONCE(1); + return -EEXIST; + } dmar_domain->agaw--; } =20 --=20 2.53.0 From nobody Wed Jun 17 06:02:59 2026 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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 4A90237AA70 for ; Thu, 23 Apr 2026 10:14:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776939256; cv=none; b=VeOk8jpUtJoP7Narxf5CSzMfTG4y6DlTsYvRzPXY+9n/TO77ZWkIgnQ5PaE94H6PgqcFALUyn0ARnt8Nolqi3lz+TOuuLmyJUB5dTWYdVQXE4G0XonlvMSIYNxUwcBtON4JYYOCAMKC4RLYbJU2KcUSuJ5bPcX7+2MOZYoGdkIY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776939256; c=relaxed/simple; bh=bfflzEHdpLESHwzPVr7kcu++Rfuj6zUYLaa4J7zWLPM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UwPt+0jNhfpfm+V4In98QxL1GB/V4vahVKchCdc2/0eepvWmNI/gFyP1QEzOrhavzIO0t72Gq7EHxoo7SJ00mkPioPeBhCh1X+bhVyOcrcYgP+jFACxwmbdLkjtlyUTDX5nNqzQRRgR0k2x6UIcnUClANoivv7iJ3IkhrHqMa7k= 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=mmcAkOdf; arc=none smtp.client-ip=209.85.215.172 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="mmcAkOdf" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-c79506f3c40so2373462a12.1 for ; Thu, 23 Apr 2026 03:14:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776939254; x=1777544054; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D105fItJZxsqyXtCtVn6aQ3UIkkHqVrtT7Vq4lq6K4g=; b=mmcAkOdfAILC0KYFpuH/oHKxF8UBpCQC5d75oANoeRSziiUMzMbiPkqiSEb95zGoLl bAJJXjtMlulUh5DYxpUymeXGNj8XeWbwbHu4drad8zLwFyVu9CUh3qv6aMVYoY47ZTfm lWpRbESERoyVIA41knIuRQQP/w0L+wnBtJxEjHnWrGJ4hzuIYIvzg+YM+DH/fhABZ56G B6wAub5wPrx7MkwSy9LAEXmEGEpmnHz3k+Oe1/wlfRrrkEHykB8t9/72dV3MfP3NWBiM nbwINtmp1+sF8V3277jQM1PQz8sXCNhyNWY6HGnfiAiAyvprO0u2TuJxKL7thHHbkSQt cJDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776939254; x=1777544054; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=D105fItJZxsqyXtCtVn6aQ3UIkkHqVrtT7Vq4lq6K4g=; b=TQDowzNC8RpaIGCh8fsImoj+BBomwOwBwvxjpVegqf4sR0Y29JdSmcB7hZGaI+cUyi 3Gy8gfX+ab2icvJfyu61Cx95iyg7pc5xKb++DdpDtdpI0Pv6lc0CBa1xZSW7rnf0MA6T ik7QJn6NcthnNiASDdAlVUP0sbIBR2XiQEUsKal1HR7JTR1spuZQDJgWPqXWzD4cKSD8 c28LF9sC+rATxQ1kjuUvg0EtHybLYoZyNhvsnkNlMF6pjzCY8qgtLN5g9DM+2htlXsTa cOF+e6aTbxUGnutLvaJNSZZU0PbcmCgkLIJcib+Cl7/q6Zc1KzCH3eO+/T3idycZt/Ro tIvQ== X-Forwarded-Encrypted: i=1; AFNElJ9rdX46fW56oXfoJmTSXldtgUMzQCw48wCmYbyQwzYgO39EWoVbUuf/Z+EgkKwGXTQDuPyB4qBvJN7L4JA=@vger.kernel.org X-Gm-Message-State: AOJu0YwMQNQyKytBNVcxUK+qXLPhRnf5xaDFjNGd19CMkB5mtUzqEY6C I/tnlx075wzGGjms5R7RzcXTcNtlfSmpGpWEIdJtFmy+kBIV9uNV9exZ X-Gm-Gg: AeBDievIwy5arUI47JjzyPx7uTELL55xyhS4gsKz++W/9Fste3U2FIZ5sYTnARXvSei iHVq0EAS588u4sifFlvF4iBaB3mlZJ6LZcn0kH4SK97muyedwEhr+04POAkXvvZMqmpenn/djQY 9YaNomlTBJshTYfDWY0alJFcJ40DcSNLQA9BX8Fz4HMsmCEe/sgTor/Z/fUzy9Nz2akUpeWChe+ 2/GVGb7EV12aNHzxgGaR72yEaGguLDZPCB+xBE2zJBYoEdp9lnjocDUQBGN6/7fELi8Msj5MuhK plmosccf1mg3Iffz1VxNK8VTVFjvSlur1bdzofcXip3ztkKC5iH6EOa+ZKf4XoJA853JmbjiLY+ a0D4zL9H6V6mOp36oSvrrtHVmQ/QKQH9ThwjNFcwGfvdA9ocMSy3GgQrMdAAifP0xoxqIn3f4Ys dznMzNCB+2PrdkvauzLVrQ6WvxDliT7pj1jw== X-Received: by 2002:a17:90b:4b49:b0:35d:9560:3f09 with SMTP id 98e67ed59e1d1-361404b8efbmr26679621a91.24.1776939254431; Thu, 23 Apr 2026 03:14:14 -0700 (PDT) Received: from fedora ([2401:4900:1cbc:314:9667:4972:a94c:125a]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36140fc5d94sm25275714a91.2.2026.04.23.03.14.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 03:14:14 -0700 (PDT) From: avinash pal To: David Woodhouse Cc: Lu Baolu , Joerg Roedel , Will Deacon , Robin Murphy , avinash pal , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Giovanni Pancotti Subject: [PATCH stable 6.12 2/2] iommu/dma: sync IOTLB before releasing IOVA on sg unmap Date: Thu, 23 Apr 2026 15:39:04 +0530 Message-ID: <20260423100904.5966-3-avinashpal441@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260423100904.5966-1-avinashpal441@gmail.com> References: <20260423100904.5966-1-avinashpal441@gmail.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: quoted-printable On the lazy-flush path, __iommu_dma_unmap_sg() calls free_iova_fast() before iommu_iotlb_sync() has drained the old mapping from hardware. A concurrent dma_map_sg() can then allocate the same IOVA and hit the stale-PTE WARN_ON in __domain_mapping() / intel_iommu_map_pages(): CPU 0 (unmap, lazy) CPU 1 (map) =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80 =E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80 iommu_unmap(iova) free_iova_fast(iova) =E2=86=90 live! alloc_iova_fast() =E2=86=92 same iova __domain_mapping() dma_pte_present() =3D=3D true =E2=86= =90 WARN Fix: insert iommu_iotlb_sync() immediately before free_iova_fast() on the lazy path so the IOTLB is fully drained before IOVA reuse. The strict-mode path already serialises here; this closes the same gap for lazy/deferred flushing (regression introduced between v6.12.74 and v6.12.76 =E2=80=94 confirmed by reporter). Reported-by: Giovanni Pancotti Link: https://bugzilla.kernel.org/show_bug.cgi?id=3D221389 Fixes: Cc: stable@vger.kernel.org Signed-off-by: avinash pal --- drivers/iommu/dma-iommu.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 0f0caf590..90071cf4a 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -159,6 +159,15 @@ static void fq_ring_free_locked(struct iommu_dma_cooki= e *cookie, struct iova_fq break; =20 iommu_put_pages_list(&fq->entries[idx].freelist); +/* + * Bug fix (Bugzilla #221389, regression v6.12.75/v6.12.76): + * Drain the IOTLB before handing the IOVA back to the allocator. + * On the lazy-flush path, free_iova_fast() makes the IOVA + * immediately reusable. A concurrent map() call can then receive + * the same IOVA while the old PTE is still live in hardware, + * triggering a stale-PTE WARN in __domain_mapping(). + */ +iommu_iotlb_sync(domain, &iotlb_gather); free_iova_fast(&cookie->iovad, fq->entries[idx].iova_pfn, fq->entries[idx].pages); --=20 2.53.0