• Oded Gabbay's avatar
    habanalabs: prevent race between fd close/open · c1904127
    Oded Gabbay authored
    The driver allows only a single process to open a device's FD at any
    single time. This is done by checking "hdev->compute_ctx" under mutex.
    
    Therefore, to prevent a race between the moment a user closes it's FD
    and when another user tries to open the device, we need to make sure
    that clearing this variable is the very last thing that is done in the
    code of the FD's release.
    
    I'm moving the idle check before clearing this variable and the
    "reset on device release". btw, if the reset happens it will prevent
    any other user from opening the device until the reset is finished.
    
    An important thing to note is that we need to remove the user process
    that is closing the device from the process list BEFORE calling the
    reset function. That is to prevent a case where the reset code will
    try to kill that user process and it is unnecessary as the process
    doesn't hold any device/driver resources anymore.
    Signed-off-by: default avatarOded Gabbay <ogabbay@kernel.org>
    c1904127
device.c 42 KB