On Mon, Sep 08, 2025 at 03:47:34PM +0100, Lorenzo Stoakes wrote: > On Mon, Sep 08, 2025 at 11:20:11AM -0300, Jason Gunthorpe wrote: > > On Mon, Sep 08, 2025 at 03:09:43PM +0100, Lorenzo Stoakes wrote: > > > > Perhaps > > > > > > > > !vma_desc_cowable() > > > > > > > > Is what many drivers are really trying to assert. > > > > > > Well no, because: > > > > > > static inline bool is_cow_mapping(vm_flags_t flags) > > > { > > > return (flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE; > > > } > > > > > > Read-only means !CoW. > > > > What drivers want when they check SHARED is to prevent COW. It is COW > > that causes problems for whatever the driver is doing, so calling the > > helper cowable and making the test actually right for is a good thing. > > > > COW of this VMA, and no possibilty to remap/mprotect/fork/etc it into > > something that is COW in future. > > But you can't do that if !VM_MAYWRITE. See this is my fear, the drivers are wrong and you are talking about edge cases nobody actually knows about. The need is the created VMA, and its dups, never, ever becomes COWable. This is what drivers actually want. We need to give them a clear test to do that. Anything using remap and checking for SHARED almost certainly falls into this category as COWing remapped memory is rare and weird. > I mean probably the driver's just wrong and should use > is_cow_mapping() tbh. Maybe. > I think we need to be cautious of scope here :) I don't want to > accidentally break things this way. IMHO it is worth doing when you get into more driver places it is far more obvious why the VM_SHARED is being checked. > OK I think a sensible way forward - How about I add desc_is_cowable() or > vma_desc_cowable() and only set this if I'm confident it's correct? I'm thinking to call it vma_desc_never_cowable() as that is much much clear what the purpose is. I think anyone just checking VM_SHARED should be changed over.. Jason