Subject: Re: Workqueues vs. kernel threads for processing asynchronous socket events

From: Martin Sustrik <[email-masked]>
Date: Thu, 23 Dec 2010 18:54:36 +0100

On 12/10/2010 04:27 PM, Martin Lucina wrote:

> I'm trying to find the best mechanism to process events from kernel space
> sockets in an asynchronous manner. The work in progress code I have at the
> moment tries to at least call kernel_accept() on a bound TCP socket when it
> gets called by the underlying sk->sk_data_ready callback.
>
> The current approach I have is to use a workqueue and try to schedule work
> inside the callback, but this has the kernel complaining about "scheduling
> while atomic", so it doesn't look like it's the right approach? Am I
> allowed to call schedule_work() from the context of a sk->sk_data_ready
> callback or not?

It turns out that the issue was caused by kmalloc(GFP_KERNEL) in the 
callback function, not the schedule_work() function. Using GFP_ATOMIC 
instead solves the problem.

Sorry for the annoyance.
Martin