locking spinlocks during copy_to_user, copy_from_user

Valdis.Kletnieks at vt.edu Valdis.Kletnieks at vt.edu
Fri Jan 25 11:58:00 EST 2013


On Fri, 25 Jan 2013 09:58:42 -0300, Pablo Pessolani said:
> My question is: Is there any know consequence if I enable preemption before
> copy_to_user/copy_from user (keeping the spinlock locked) and then disable
> preemption again after the copy?????

Well, at that point, you potentially have "a spinlock locked during operations
that can be preempted", which you noted is "not recommended".

The generic problem is that while you're spinning, you can get hit with
a preempt, which ends up rescheduling or other fun stuff, and the preempting
thread ends up calling into the same code - at which point you'll possibly
deadlock because the second thread is now blocked on the spinlock that the
first thread holds...

You're much better off either restructuring your code so you don't do
anything that can preempt, or fix your locking in other ways so the
problem can't arise.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130125/6fe067ae/attachment.bin 


More information about the Kernelnewbies mailing list