• James Houghton's avatar
    mm: add an explicit smp_wmb() to UFFDIO_CONTINUE · b14d1671
    James Houghton authored
    Users of UFFDIO_CONTINUE may reasonably assume that a write memory barrier
    is included as part of UFFDIO_CONTINUE.  That is, a user may believe that
    all writes it has done to a page that it is now UFFDIO_CONTINUE'ing are
    guaranteed to be visible to anyone subsequently reading the page through
    the newly mapped virtual memory region.
    
    Today, such a user happens to be correct.  mmget_not_zero(), for example,
    is called as part of UFFDIO_CONTINUE (and comes before any PTE updates),
    and it implicitly gives us a write barrier.
    
    To be resilient against future changes, include an explicit smp_wmb(). 
    While we're at it, optimize the smp_wmb() that is already incidentally
    present for the HugeTLB case.
    
    Merely making a syscall does not generally imply the memory ordering
    constraints that we need (including on x86).
    
    Link: https://lkml.kernel.org/r/20240307010250.3847179-1-jthoughton@google.comSigned-off-by: default avatarJames Houghton <jthoughton@google.com>
    Reviewed-by: default avatarPeter Xu <peterx@redhat.com>
    Cc: Axel Rasmussen <axelrasmussen@google.com>
    Cc: Muchun Song <songmuchun@bytedance.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    b14d1671
hugetlb.c 219 KB