• Ian Munsie's avatar
    cxl: Fix issues when unmapping contexts · 0712dc7e
    Ian Munsie authored
    An issue was introduced with "cxl: Unmap MMIO regions when detaching a
    context" (b123429e) where closing a
    context normally could also unmap the problem state area of other
    contexts currently using the AFU.
    
    It was also discovered that after a context's MMIO space had been
    unmapped it would read 0s when accessing it, whereas the expected
    behaviour was for the access to fail altogether.
    
    In order to address these issues, this patch does two things:
    
    - Forced mmap unmapping is only done when we are forcefully detaching
      all contexts, and not in the normal detach path. Since the normal
      context close path is tied to the file release any mmaps must have
      already been released so we don't need to worry in that case.
    
    - The mmap path now uses a vm_operations_struct with a fault handler.
      The fault handler ensures that the context is in started state,
      otherwise it fails the access attempt with a SIGBUS.
    
    Fixes: b123429e ("cxl: Unmap MMIO regions when detaching a context")
    Signed-off-by: default avatarIan Munsie <imunsie@au1.ibm.com>
    Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
    0712dc7e
file.c 13.2 KB