[lkml]   [2000]   [Feb]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    Subject[Basics] spinlocks & copy_to_user

    What is the Right Way(tm) for a driver (in read(), write(), or ioctl(),
    etc.) to copy data, possibly modified at interrupt time, to/from a user?

    I know this is a fairly basic/fundamental question, but one I haven't
    found a direct answer to yet. (Point me to docs if you know of any good

    I need to copy information from a kernel memory buffer to a user memory
    buffer. copy_to_user() is the obvious answer. However, the kernel
    buffer can be modified at interrupt time (interrupt handler); to protect
    this, I'm using a spin_lock_irqsave(). But copy_to_user() can sleep.
    Correct me if I'm wrong, but access_ok() does not appear to worry about
    the possibility of a fault, just permissions.

    I could copy from the kernel buffer to another kernel buffer with irq's
    disabled, then copy_to_user() from the new buffer, but I was hoping to
    avoid the additional copy.

    I could access each page of the user buffer before taking the spinlock,
    but will that guarrantee the memory is still there by the time I get to
    it? Should I copy one page at a time, accessing the page outside of
    locks and with interrupts enabled each time? Is there a way to verify I
    won't get put to sleep once interrupts are disabled?

    I'm on a UP ARM, but I'd like to know the answer for UP and SMP in
    any/all archs.

    Comments, pointers, and especially answers are most welcome.

    (I'm on the list.)

    Thank you for your time,

    Eli Carter

    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    Please read the FAQ at

     \ /
      Last update: 2005-03-22 13:56    [W:0.020 / U:20.452 seconds]
    ©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site