Re: [question/comment/help] pseudo function-call from kernel to a user-process

Richard B. Johnson (root@chaos.analogic.com)
Tue, 9 Nov 1999 13:49:28 -0500 (EST)


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/