• John Ogness's avatar
    printk: nbcon: Use driver synchronization while (un)registering · e55c3bcf
    John Ogness authored
    Console drivers typically have to deal with access to the
    hardware via user input/output (such as an interactive login
    shell) and output of kernel messages via printk() calls.
    
    They use some classic driver-specific locking mechanism in most
    situations. But console->write_atomic() callbacks, used by nbcon
    consoles, are synchronized only by acquiring the console
    context.
    
    The synchronization via the console context ownership is possible
    only when the console driver is registered. It is when a
    particular device driver is connected with a particular console
    driver.
    
    The two synchronization mechanisms must be synchronized between
    each other. It is tricky because the console context ownership
    is quite special. It might be taken over by a higher priority
    context. Also CPU migration must be disabled. The most tricky
    part is to (dis)connect these two mechanisms during the console
    (un)registration.
    
    Use the driver-specific locking callbacks: device_lock(),
    device_unlock(). They allow taking the device-specific lock
    while the device is being (un)registered by the related console
    driver.
    
    For example, these callbacks lock/unlock the port lock for
    serial port drivers.
    
    Note that the driver-specific locking is only needed during
    (un)register if it is an nbcon console with the write_atomic()
    callback implemented. If write_atomic() is not implemented, the
    driver should never attempt to access the hardware without
    first acquiring its driver-specific lock.
    Signed-off-by: default avatarJohn Ogness <john.ogness@linutronix.de>
    Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20240820063001.36405-10-john.ogness@linutronix.deSigned-off-by: default avatarPetr Mladek <pmladek@suse.com>
    e55c3bcf
printk.c 118 KB