• Douglas Anderson's avatar
    kgdboc: Use a platform device to handle tty drivers showing up late · 68e55f61
    Douglas Anderson authored
    If you build CONFIG_KGDB_SERIAL_CONSOLE into the kernel then you
    should be able to have KGDB init itself at bootup by specifying the
    "kgdboc=..." kernel command line parameter.  This has worked OK for me
    for many years, but on a new device I switched to it stopped working.
    
    The problem is that on this new device the serial driver gets its
    probe deferred.  Now when kgdb initializes it can't find the tty
    driver and when it gives up it never tries again.
    
    We could try to find ways to move up the initialization of the serial
    driver and such a thing might be worthwhile, but it's nice to be
    robust against serial drivers that load late.  We could move kgdb to
    init itself later but that penalizes our ability to debug early boot
    code on systems where the driver inits early.  We could roll our own
    system of detecting when new tty drivers get loaded and then use that
    to figure out when kgdb can init, but that's ugly.
    
    Instead, let's jump on the -EPROBE_DEFER bandwagon.  We'll create a
    singleton instance of a "kgdboc" platform device.  If we can't find
    our tty device when the singleton "kgdboc" probes we'll return
    -EPROBE_DEFER which means that the system will call us back later to
    try again when the tty device might be there.
    
    We won't fully transition all of the kgdboc to a platform device
    because early kgdb initialization (via the "ekgdboc" kernel command
    line parameter) still runs before the platform device has been
    created.  The kgdb platform device is merely used as a convenient way
    to hook into the system's normal probe deferral mechanisms.
    
    As part of this, we'll ever-so-slightly change how the "kgdboc=..."
    kernel command line parameter works.  Previously if you booted up and
    kgdb couldn't find the tty driver then later reading
    '/sys/module/kgdboc/parameters/kgdboc' would return a blank string.
    Now kgdb will keep track of the string that came as part of the
    command line and give it back to you.  It's expected that this should
    be an OK change.
    Signed-off-by: default avatarDouglas Anderson <dianders@chromium.org>
    Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    Reviewed-by: default avatarDaniel Thompson <daniel.thompson@linaro.org>
    Link: https://lore.kernel.org/r/20200507130644.v4.3.I4a493cfb0f9f740ce8fd2ab58e62dc92d18fed30@changeid
    [daniel.thompson@linaro.org: Make config_mutex static]
    Signed-off-by: default avatarDaniel Thompson <daniel.thompson@linaro.org>
    68e55f61
kgdboc.c 9.38 KB