Re: 2.4.27 Potential race in n_tty.c:write_chan()

From: Paul Fulghum (paulkf_at_microgate.com)
Date: 12/05/04

  • Next message: Paul E. McKenney: "Fw: [RFC] Strange code in cpu_idle()"
    To: Ryan Reading <rreading@msm.umr.edu>
    Date:	Sun, 05 Dec 2004 16:40:20 -0600
    
    

    On Sun, 2004-12-05 at 15:54 -0500, Ryan Reading wrote:
    > So when write_chan() calls usb_driver::write(), typically the driver
    > calls usb_submit_urb(). The write() call then returns immediately
    > indicating that all of the data has been written (assuming it is less
    > than the USB packets size). The driver however is still waiting for an
    > interrupt to complete the write and wakeup the current kernel path. If
    > write_chan() is called again and the interrupt is received within the
    > window I outlined above, the current_state will be reset to TASK_RUNNING
    > before the next usb_driver::write() is ever called! If this happens, it
    > seems that we would lose synchronisity and potentially lock the kernel
    > path.

    The line discipline write routine is serialized
    on a per tty basis in do_tty_write() of tty_io.c
    using tty->atomic_write semaphore, so you will not
    reenter write_chan() for a particular tty instance.

    Even if this were not the case, if the task state
    changes to TASK_RUNNING inside the window
    you describe, the only thing that happens is the loop
    executes again. The driver must decide if it can accept
    more data or not and return the appropriate value.

    There is no potential for deadlock.

    > It is also my understanding that the usb interrupt is generated from the
    > ACK/NAK of the original usb_submit_urb(). If the driver is returning
    > immediately without waiting on the interrupt and schedule() is never
    > being called, there is no guarantee that the write() happened
    > successfully (although we return that it has). It seems if a driver
    > wanted to guarantee this, it would have to artificially wait of the
    > interrupt before returning.

    True, but this is a matter of layering.

    The line discipline knows nothing about the driver's concept
    of write completion apart from the driver's write method
    return value. If it is critical for the write not to complete
    until the URB is sent, it is up to the driver to block
    and return the appropriate return value.
     

    --
    Paul Fulghum
    paulkf@microgate.com
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at  http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at  http://www.tux.org/lkml/
    

  • Next message: Paul E. McKenney: "Fw: [RFC] Strange code in cpu_idle()"

    Relevant Pages

    • Re: 2.6.19 and up to 2.6.20-rc2 Ethernet problems x86_64
      ... If the system fails in ACPI mode, but works in non-ACPI mode, ... Using ACPI for SMP configuration information ... Using IOAPIC for interrupt routing ... Non-volatile memory driver v1.2 ...
      (Linux-Kernel)
    • Re: [PATCH] uio: User IRQ Mode
      ... This patch adds a "User IRQ Mode" to UIO. ... In this mode the user space driver ... is responsible for acknowledging and re-enabling the interrupt. ...
      (Linux-Kernel)
    • PANIC [2.4.27] usb-storage
      ... PCI Interrupt Link enabled at IRQ 3 ... switching to colour frame buffer device 100x37 ... RAMDISK driver initialized: 16 RAM disks of 32000K size 1024 blocksize ... Initializing USB Mass Storage driver... ...
      (Linux-Kernel)
    • Re: Assembling Visual Studio generated listing files
      ... card issues an interrupt each time it has a new position for any one ... An ISR is constrained to act in < 10us, and for most modern machines, 12.5us is a very ... Without MASM and in pure C or C++ and without any Windows API/MFC, ... This is a device driver. ...
      (microsoft.public.vc.mfc)
    • Re: [PATCH] uio: User IRQ Mode
      ... This patch adds a "User IRQ Mode" to UIO. ... In this mode the user space driver ... is responsible for acknowledging and re-enabling the interrupt. ...
      (Linux-Kernel)