Re: [PATCH 1/6] generic_pt: allow missing sw bit in DMA_INCOHERENT case
From: Jason Gunthorpe
Date: Sun Jul 12 2026 - 18:01:02 EST
On Sun, Jul 12, 2026 at 10:18:51PM +0100, Daniel Drake wrote:
> When working with a iommu with PT_FEAT_DMA_INCOHERENT set, generic_pt
> will attempt to use a spare "SW" bit in the hardware page tables to
> denote when a thread has flushed the CPU cache after modifying an entry.
>
> This means that other threads know that they are not working with
> cached/unflushed data, if they come across the same entry.
>
> In the case where no SW bit is available, two things happen:
>
> 1. __map_range() defensively flushes every time it reads the PT.
> This ensures all data that may have just been manipulated by another
> thread gets flushed and made iommu-visible immediately.
>
> 2. An undefined reference to __pt_no_sw_bit() is created, causing a
> linker error in order to alert the developer that they are going
> to suffer a performance penalty in the previous point.
Ah, actually this is all setup like this because it doesn't have an
implementation for supporting no-SW bit versions right now. That a
mandatory flush happens is not something I thought about, my original
plan was to put the SW bit into the struct page memory instead and
have some extra barriers..
It would be better to not call the SW bit code at all if
PT_SW_BIT_NOT_PRESENT so we have a clear algorithm that explains how
it is intended to work (ie mandatory flush) in this case instead of
disabling the linker safety check of using SW bit without support
Jason