title: How to know if a kernel code is atomic or not?
body: <p>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.</p>
  
  <p>After debugging, I realized that the system crashes when a <code>atomic_set()</code> 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?</p>
  
  <p>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?</p>
  
  <p><strong>EDIT: Adding the actual code</strong></p>
  
  <p>In <a href="http://git.kernel.org/?p=linux/kernel/git/stable/linux-stable.git;a=blob;f=net/netfilter/ipvs/ip_vs_core.c;h=a54b018c6eea72fc122aa47c6f66de76676c1fa1;hb=HEAD" rel="nofollow">net/netfilter/ipvs/ip_vs_core.c</a> line 451, I call my function:</p>
  
  <pre><code>my_callback(svc, skb);
  </code></pre>
  
  <p>Then, in another file I have:</p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p>My <code>swtoing()</code> 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 <code>swtoing()</code> with a <code>atomic_set()</code>...</p>
  
  <p>Any help?</p>
  
  <p><strong>EDIT 2: More info</strong></p>
  
  <p>I realized that the kernel modules I am modifying are FULL of <code>spin_locks</code> 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 :(</p>