Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6333

Using mutex to synchronize two kernel threads causes a system panic

$
0
0

I used the following code to synchronize the two kernel threads. After running, panic occurred in the system and abnormal memory was found in mutex by kdump. What is the reason for this?

struct request {    ... ...    struct mutex lock;    bool finish;    ... ...};

kthread1

int wait_request(struct request *request){    while (1)    {        mutex_lock(&request->lock);        if(request->finish)        {            mutex_unlock(&request->lock);            break;        }        mutex_unlock(&request->lock);    }    return SUCCESS;}

kthread2

void request_process(void *date){    struct request *request = (struct request *)date;    mutex_lock(&request->lock);    request->finish = true;    mutex_unlock(&request->lock);}

The details are in this picture

[  213.738777]  [<ffffffffa9711b2e>] __mutex_unlock_slowpath+0x5e/0x90[  213.738800]  [<ffffffffa9710fab>] mutex_unlock+0x1b/0x20[  213.738820]  [<ffffffffc0baa109>] request_process+0x29/0x30 [kdemo][  213.738843]  [<ffffffffc0baa1c1>] queue_fn+0xb1/0x130 [kdemo][  213.738863]  [<ffffffffc0baa110>] ? request_process+0x30/0x30 [kdemo][  213.738887]  [<ffffffffa90bae31>] kthread+0xd1/0xe0[  213.738906]  [<ffffffffa90bad60>] ? insert_kthread_work+0x40/0x40[  213.738928]  [<ffffffffa971f61d>] ret_from_fork_nospec_begin+0x7/0x21[  213.738951]  [<ffffffffa90bad60>] ? insert_kthread_work+0x40/0x40[  213.738971] Code: 09 00 00 31 c9 31 d2 e8 18 41 ff ff eb e4 66 0f 1f 44 00 00 0f 1f 44 00 00 55 48 8d 8e b0 0f 00 00 31 c0 ba 01 00 00 00 48 89 e5 <f0> 48 0f b1 96 b0 0f 00 00 48 85 c0 74 0b 5d c3 66 0f 1f 84 00[  213.739134] RIP  [<ffffffffa90caa47>] wake_q_add+0x17/0x50[  213.739155]  RSP <ffff8a5e25adfe00>[  213.739168] CR2: 0000000000000fb0

Viewing all articles
Browse latest Browse all 6333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>