Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, Since 2.6.18 and above kernel not exporting symbol table and tasklist_lock , I have patched the vanilla kernel to export them manually. Now I am rewriting the fork method ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2010
    Posts
    8

    Talking Why the funny kernel always crashes ??


    Hi,

    Since 2.6.18 and above kernel not exporting symbol table and tasklist_lock , I have patched the vanilla kernel to export them manually. Now I am rewriting the fork method , My code compiles fine and works properly for a program which has single fork, when program calls repeatedly called fork without latency , my system crashes , I am sure that the code breaks within the list loop .My pseudo code is as follows

    asmlinkage int my_fork(struct pt_regs regs)
    {
    int ret;

    ret = call_original_fork(fork_saved, regs);
    if (ret > 0) {
    struct list_head *this,*next;
    struct task_struct *child_task= NULL;
    lock_kernel();
    read_lock(&tasklist_lock);

    list_for_each_safe(this, next, &current->children) {
    child_task = list_entry(this, struct task_struct, sibling);
    if (child_task->pid == ret) {
    /* This guy is still running, even though it got waited? */
    printkDEBUG("Yes we found a match\n");
    break;
    }
    }
    unlock_kernel();
    read_unlock(&tasklist_lock);
    return ret;
    }

    Please let us know if you need any more info.

    Thanks in Advance,
    Jai

  2. #2
    Just Joined!
    Join Date
    Feb 2010
    Posts
    8

    Unhappy Little help will get me out of it

    Hi geeks,

    Today I found out the cause is because of write lock . Let myself be more clear .

    1) I have kernel 2.6.18 with SMP enabled (CONFIG_SMP =Y}
    2) I am writing a kernel module to manipulate the fork system call (Just to keep track of all forks happening in my system) .

    This is my code for fork call, I am exporting the symbol table and everytime I call fork in my user program this method gets called without any issue .

    asmlinkage int my_fork(struct pt_regs regs)
    {
    int ret;
    rwlock_t chroots_lock = RW_LOCK_UNLOCKED;
    unsigned long flags;
    ret = call_original_fork(fork_saved, regs);
    if (ret > 0) {

    struct task_struct *child_task= NULL;

    //READ LOCKING

    lock_kernel();
    read_lock_irqsave(&chroots_lock,flags);
    child_task = find_task_by_pid (ret);
    unlock_kernel();
    read_lock_irqsave(&chroots_lock,flags);

    //WRITE LCOKING cool the problem is here

    lock_kernel();
    write_lock_irqsave(&chroots_lock,flags);
    //Add the child_task to main list (I am 100 % sure this method is working fine )
    write_lock_irqrestore(&chroots_lock,flags);
    unlock_kernel();
    return ret;

    }

    }

    This module and everything worked fine , until 2.4 kernel now I am migrating to 2.6 kernel where after making few changes to code it get compiled and loads fine. I didn't touch the locking part of the code after this migration.

    After loading the module , even now it works fine for example 1( delays between the fork calls) , but the system hangs for the example 2 when there is no delay between the fork calls.

    Example 1: prog1.pl

    fork();
    sleep(5);
    fork();
    sleep(5);
    fork();

    Example 2:

    fork();
    fork();
    fork();


    Does anything I need to change in my locking part of code to make it work as expected in 2.6 kernel . Any little help will be great for me , Please let me know if you need any more info.

    Thanks,
    Jai

  3. #3
    Just Joined!
    Join Date
    Feb 2010
    Posts
    8
    Hi guys,
    My module was intended to run on Uniprocessor machine, but I compiled the kernel with SMP mode . This all caused the issue, I just recompiled with SMP disabled. Now it looks little ok but not 100% .

    ~Jai

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •