• Johan Hovold's avatar
    serial: qcom-geni: fix polled console corruption · 63d14d97
    Johan Hovold authored
    The polled UART operations are used by the kernel debugger (KDB, KGDB),
    which can interrupt the kernel at any point in time. The current
    Qualcomm GENI implementation does not really work when there is on-going
    serial output as it inadvertently "hijacks" the current tx command,
    which can result in both the initial debugger output being corrupted as
    well as the corruption of any on-going serial output (up to 4k
    characters) when execution resumes:
    
    0190: abcdefghijklmnopqrstuvwxyz0123456789 0190: abcdefghijklmnopqrstuvwxyz0123456789
    0191: abcdefghijklmnop[   50.825552] sysrq: DEBUG
    qrstuvwxyz0123456789 0191: abcdefghijklmnopqrstuvwxyz0123456789
    Entering kdb (current=0xffff53510b4cd280, pid 640) on processor 2 due to Keyboard Entry
    [2]kdb> go
    omlji3h3h2g2g1f1f0e0ezdzdycycxbxbwawav :t72r2rp
    o9n976k5j5j4i4i3h3h2g2g1f1f0e0ezdzdycycxbxbwawavu:t7t8s8s8r2r2q0q0p
    o9n9n8ml6k6k5j5j4i4i3h3h2g2g1f1f0e0ezdzdycycxbxbwawav v u:u:t9t0s4s4rq0p
    o9n9n8m8m7l7l6k6k5j5j40q0p                                              p o
    o9n9n8m8m7l7l6k6k5j5j4i4i3h3h2g2g1f1f0e0ezdzdycycxbxbwawav :t8t9s4s4r4r4q0q0p
    
    Fix this by making sure that the polled output implementation waits for
    the tx fifo to drain before cancelling any on-going longer transfers. As
    the polled code cannot take any locks, leave the state variables as they
    are and instead make sure that the interrupt handler always starts a new
    tx command when there is data in the write buffer.
    
    Since the debugger can interrupt the interrupt handler when it is
    writing data to the tx fifo, it is currently not possible to fully
    prevent losing up to 64 bytes of tty output on resume.
    
    Fixes: c4f52879 ("tty: serial: msm_geni_serial: Add serial driver support for GENI based QUP")
    Cc: stable@vger.kernel.org      # 4.17
    Reviewed-by: default avatarDouglas Anderson <dianders@chromium.org>
    Tested-by: default avatarNícolas F. R. A. Prado <nfraprado@collabora.com>
    Signed-off-by: default avatarJohan Hovold <johan+linaro@kernel.org>
    Link: https://lore.kernel.org/r/20240906131336.23625-9-johan+linaro@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    63d14d97
qcom_geni_serial.c 50.1 KB