0

I working on a Linux kernel project. In my project I modified the kernel so that copy_process is called from one of my modules that responds to writes to a proc file entry. In essence, things look liks:

int procfile_write(struct file *file, const char *buffer, unsigned long count,
           void *data)
{
    //...more code
    copy_process(...);
    //...more code
}

int init_module()
{
    /* create the /proc file */
    Our_Proc_File = create_proc_entry(PROCFS_NAME, 0644, NULL);
    // more code
    Our_Proc_File->write_proc = procfile_write;
    return 0;   /* everything is ok */
}

My problem is that the kernel hangs inside copy_process when it hits the line:

write_lock_irq(&tasklist_lock);

Now, I know this function is being called all the time from do_fork. Which happens inside a system call.

My questions:

  1. Am I on the right path thinking this has to do with writing to a proc file entry vs system calls?
  2. What IRQs have to do with writing to proc file entries?
  3. Is writing to a proc file entry actually different from a system call? I mean in the way it is handled and in the context it is invoked?

Thank you!

UPDATE: I converted the way my code is called from being called while handling a write to a proc file to being called from a system call. Nothing changed. Still hangs when getting to the same line (i.e. locking tasklist_lock). Now, my problem is why it hangs there? and how to fix this issue?

feeling_lonely
  • 6,665
  • 4
  • 27
  • 53
  • Can you post the code where `tasklist_lock` is declared and initialized? – Peter L. Apr 28 '15 at 21:28
  • This is in plain linux kernel see declaration in /include/linux/sched.h and definition in /kernel/fork.c – feeling_lonely Apr 28 '15 at 21:34
  • Is the symbol `lockdep_tasklist_lock_is_held` available in your kernel? If so, you may try checking it before calling `copy_process()`. – Peter L. Apr 28 '15 at 22:05
  • my concern is: is the problem related to the lock being already held or is it related to disabling the IRQ. Note the use of write_lock_irq() instead of using the write_lock() – feeling_lonely Apr 28 '15 at 23:43
  • Yes, and you could test that concern by just disabling/enabling IRQs and not calling `copy_process()` and see if it still locks up. – Peter L. Apr 29 '15 at 00:59
  • I converted it from a write to a proc file into a system call. did not work...still locks up. I also added an if statement to skip locking if copy_process was called from my code and that locks up too. – feeling_lonely Apr 29 '15 at 23:00

0 Answers0