lkml.org 
[lkml]   [1999]   [Nov]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [question/comment/help] pseudo function-call from kernel to a user-process
On Tue, 9 Nov 1999, Marcel Lanz wrote:
[SNIPPED]

> - as you can see int the code, I tried to use a self-defined spinlock to
> protect the area, but that doesn't work, why? aren't spinlocks like
> semaphores or mutex'es?
> - are there any pitfalls ?


>
> switch(cmd) {
> case DKM_MAP_REQ:
> spin_lock_irqsave(&dkm_map_lock, flags);
> down(&dkm_map_sema);
> copy_to_user((char*)arg, "filename", 9);
> break;
>

You can never copy to user under a spin-lock. The user's page(s) might
not be present and you need to page-fault which can't happen under the
spin-lock.

Instead, if you are copying something that can change, so you need a
spin-lock, do:

spin_lock_irqsave(&lock_flag, flags);
memcpy(tmp_buf, volatile_buf, len);
spin_unlock(&lock_flag, flags);

copy_to_user(user_buf, tmp_buf, len);

Stuff that can't possibly change during the operation, requires no
spin-locks at all. In your code snippet retained above, everything is
a constant. It needs no lock.


Cheers,
Dick Johnson

Penguin : Linux version 2.3.13 on an i686 machine (400.59 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:54    [W:0.062 / U:0.140 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site