I have a character device that I am calling write on and which is succeeding, but which is repeatedly executing. I have hard coded the return value to one, so I don't think the userland standard library is retrying but I could be wrong. Can anybody tell me why write would be re-executed by the kernel and how to fix it? I dont actually copy_from_user, I just need this in order to signal kernel land.
On Tue, Oct 04, 2016 at 10:58:16AM -0400, Kenneth Adam Miller wrote:
I have a character device that I am calling write on and which is succeeding, but which is repeatedly executing. I have hard coded the return value to one, so I don't think the userland standard library is retrying but I could be wrong. Can anybody tell me why write would be re-executed by the kernel and how to fix it? I dont actually copy_from_user, I just need this in order to signal kernel land.
Do you have a pointer to your code somewhere? This is a very common bug that people have... thanks, greg k-h
Because the libc is calling it again based on what has been passed as argument and what was received as return value. Here is one example https://gist.github.com/gkos/5479135. I don't really know if this code is working since I made it a long time ago. Regards, 2016-10-04 12:05 GMT-03:00 Greg KH <greg@kroah.com>:
On Tue, Oct 04, 2016 at 10:58:16AM -0400, Kenneth Adam Miller wrote:
I have a character device that I am calling write on and which is succeeding, but which is repeatedly executing. I have hard coded the return value to one, so I don't think the userland standard library is retrying but I could be wrong. Can anybody tell me why write would be re-executed by the kernel and how to fix it? I dont actually copy_from_user, I just need this in order to signal kernel land.
Do you have a pointer to your code somewhere? This is a very common bug that people have...
thanks,
greg k-h
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- *"Do or do not. There is no try"* *Yoda Master*
On Tue, Oct 04, 2016 at 03:42:52PM -0300, Daniel. wrote:
Because the libc is calling it again based on what has been passed as argument and what was received as return value. Here is one example https://gist.github.com/gkos/5479135. I don't really know if this code is working since I made it a long time ago.
Your test to check wether the device is already open looks weak to me. You should rather use atomic operations such as described in [1] or mutex like in [2]. [1] http://www.oreilly.com/openbook/linuxdrive3/book/ch06.pdf p 40 [2] http://pete.akeo.ie/2011/08/writing-linux-device-driver-for-kernels.html -- François
On Tue, Oct 04, 2016 at 05:05:57PM +0200, Greg KH wrote:
On Tue, Oct 04, 2016 at 10:58:16AM -0400, Kenneth Adam Miller wrote:
I have a character device that I am calling write on and which is succeeding, but which is repeatedly executing. I have hard coded the return value to one,
Correct me if I'm wrong, I'm just a self-thought newbie, but this ^^ sounds to me like the problem. Because the write should return how many bytes were written (or error), the function is being called until it's been all written. If you just want to be called once and you don't care what the data are (which is the weird thing in the first place), I think you should return the length you got as an argument.
so I don't think the userland standard library is retrying but I could be wrong. Can anybody tell me why write would be re-executed by the kernel and how to fix it? I dont actually copy_from_user, I just need this in order to signal kernel land.
Do you have a pointer to your code somewhere? This is a very common bug that people have...
thanks,
greg k-h
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
I didn't know it, but I had my poll and write messages switched in userland under await and send signal implementations of types. Sorry, it works now, it wasn't the kernel land repeatedly executing it. I wasn't sure, so I was still debugging. Anyway, thanks a lot though. On Oct 5, 2016 2:29 AM, "Martin Kletzander" <mkletzan@redhat.com> wrote:
On Tue, Oct 04, 2016 at 05:05:57PM +0200, Greg KH wrote:
On Tue, Oct 04, 2016 at 10:58:16AM -0400, Kenneth Adam Miller wrote:
I have a character device that I am calling write on and which is succeeding, but which is repeatedly executing. I have hard coded the return value to one,
Correct me if I'm wrong, I'm just a self-thought newbie, but this ^^ sounds to me like the problem. Because the write should return how many bytes were written (or error), the function is being called until it's been all written. If you just want to be called once and you don't care what the data are (which is the weird thing in the first place), I think you should return the length you got as an argument.
so I don't think the userland standard library is retrying but I could be
wrong. Can anybody tell me why write would be re-executed by the kernel and how to fix it? I dont actually copy_from_user, I just need this in order to signal kernel land.
Do you have a pointer to your code somewhere? This is a very common bug that people have...
thanks,
greg k-h
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
participants (5)
-
Daniel. -
François -
Greg KH -
Kenneth Adam Miller -
Martin Kletzander