jeanc
jeanc

Reputation: 4833

How to know if a kernel code is atomic or not?

I am writing a kernel module where I implement some functions that are going to be used from another modules I have modified. When testing the system crashes. I get a "scheduling while atomic" error.

After debugging, I realized that the system crashes when a atomic_set() is called. It means that I am calling an atomic function from a non-atomic function? can't I use atomic_set() in this case? What should I use instead?

Also, as I said, I modified some original kernel files for calling my function. How could I know if where I am working is atomic code or not?

EDIT: Adding the actual code

In net/netfilter/ipvs/ip_vs_core.c line 451, I call my function:

my_callback(svc, skb);

Then, in another file I have:

int my_callback(struct ip_vs_service *svc, struct sk_buff *skb)
{
        int swto;

        printk(KERN_INFO "callback called \n");

        swto = swtoing(svc);
        return swto;
}

My swtoing() function is a bit long, but I had debugged a lot, and have figured out that the system does not crash if I comment a line within swtoing() with a atomic_set()...

Any help?

EDIT 2: More info

I realized that the kernel modules I am modifying are FULL of spin_locks and stuff like that... So I think (forgive me if I am wrong) that I must do something in the functions that I am creating, in order to keep the locking/atomic stuff... but I don't know what :(

Upvotes: 5

Views: 2504

Answers (1)

Ilya Matveychikov
Ilya Matveychikov

Reputation: 4024

You can use in_atomic macro but is has some restrictions. See the comment.

Upvotes: 1

Related Questions