From: Peter Osterlund <petero2@telia.com>
To: linux-kernel@vger.kernel.org
Cc: Jens Axboe <axboe@suse.de>, Andrew Morton <akpm@osdl.org>
Subject: [PATCH] Fix race in pktcdvd kernel thread handling
Date: 04 Jul 2004 14:30:08 +0200 [thread overview]
Message-ID: <m28ye0uf8v.fsf@telia.com> (raw)
In-Reply-To: <m2lli36ec9.fsf@telia.com>
Running "pktsetup -d" immediately after running "pktsetup" can
deadlock, because if the kcdrwd thread hasn't flushed the pending
signals before pkt_remove_dev() calls kill_proc(), kcdrwd() will not
be woken up.
This patch fixes it by making sure the kcdrwd() thread has finished
its initialization before the thread creator returns from
pkt_new_dev().
Signed-off-by: Peter Osterlund <petero2@telia.com>
---
linux-petero/drivers/block/pktcdvd.c | 9 ++++++---
linux-petero/include/linux/pktcdvd.h | 2 +-
2 files changed, 7 insertions(+), 4 deletions(-)
diff -puN drivers/block/pktcdvd.c~packet-kthread-race-fix drivers/block/pktcdvd.c
--- linux/drivers/block/pktcdvd.c~packet-kthread-race-fix 2004-07-04 14:09:40.183162592 +0200
+++ linux-petero/drivers/block/pktcdvd.c 2004-07-04 14:09:40.192161224 +0200
@@ -1182,6 +1182,8 @@ static int kcdrwd(void *foobar)
siginitsetinv(¤t->blocked, sigmask(SIGKILL));
flush_signals(current);
+ up(&pd->cdrw.thr_sem);
+
for (;;) {
DECLARE_WAITQUEUE(wait, current);
@@ -1276,7 +1278,7 @@ work_to_do:
pkt_iosched_process_queue(pd);
}
- complete_and_exit(&pd->cdrw.thr_compl, 0);
+ up(&pd->cdrw.thr_sem);
return 0;
}
@@ -2407,7 +2409,7 @@ static int pkt_new_dev(struct pktcdvd_de
sprintf(pd->name, "pktcdvd%d", minor);
atomic_set(&pd->refcnt, 0);
init_waitqueue_head(&pd->wqueue);
- init_completion(&pd->cdrw.thr_compl);
+ init_MUTEX_LOCKED(&pd->cdrw.thr_sem);
pkt_init_queue(pd);
@@ -2418,6 +2420,7 @@ static int pkt_new_dev(struct pktcdvd_de
ret = -EBUSY;
goto out_thread;
}
+ down(&pd->cdrw.thr_sem);
create_proc_read_entry(pd->name, 0, pkt_proc, pkt_read_proc, pd);
DPRINTK("pktcdvd: writer %d mapped to %s\n", minor, bdevname(bdev, b));
@@ -2484,7 +2487,7 @@ static int pkt_remove_dev(struct pktcdvd
printk("pkt_remove_dev: can't kill kernel thread\n");
return ret;
}
- wait_for_completion(&pd->cdrw.thr_compl);
+ down(&pd->cdrw.thr_sem);
}
/*
diff -puN include/linux/pktcdvd.h~packet-kthread-race-fix include/linux/pktcdvd.h
--- linux/include/linux/pktcdvd.h~packet-kthread-race-fix 2004-07-04 14:09:40.185162288 +0200
+++ linux-petero/include/linux/pktcdvd.h 2004-07-04 14:09:40.192161224 +0200
@@ -140,7 +140,7 @@ struct packet_cdrw
spinlock_t active_list_lock; /* Serialize access to pkt_active_list */
pid_t pid;
int time_to_die;
- struct completion thr_compl;
+ struct semaphore thr_sem;
elevator_merge_fn *elv_merge_fn;
elevator_completed_req_fn *elv_completed_req_fn;
merge_requests_fn *merge_requests_fn;
_
--
Peter Osterlund - petero2@telia.com
http://w1.894.telia.com/~u89404340
next prev parent reply other threads:[~2004-07-04 12:41 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-01 13:34 [PATCH] CDRW packet writing support for 2.6.7-bk13 Peter Osterlund
2004-07-02 21:52 ` Peter Osterlund
2004-07-02 22:08 ` Andrew Morton
2004-07-02 22:47 ` Greg KH
2004-07-02 22:59 ` Andrew Morton
2004-07-02 23:24 ` Peter Osterlund
2004-07-02 23:51 ` Andrew Morton
2004-07-04 11:57 ` Peter Osterlund
2004-07-04 20:58 ` Andrew Morton
2004-07-04 21:06 ` Christoph Hellwig
2004-07-04 12:30 ` Peter Osterlund [this message]
2004-07-04 12:37 ` [PATCH] Fix open/close races in pktcdvd Peter Osterlund
2004-07-04 13:05 ` [PATCH] CDRW packet writing support for 2.6.7-bk13 Christoph Hellwig
2004-07-04 23:49 ` Peter Osterlund
2004-07-05 0:01 ` Peter Osterlund
2004-07-10 23:20 ` Arnd Bergmann
2004-07-10 23:27 ` Christoph Hellwig
2004-07-11 1:06 ` Peter Osterlund
2004-07-12 16:25 ` Arnd Bergmann
2004-07-12 16:34 ` Christoph Hellwig
2004-07-13 6:04 ` Jens Axboe
2004-07-14 0:06 ` [RFC][PATCH] Control pktcdvd with an auxiliary character device Peter Osterlund
2004-07-14 0:17 ` Peter Osterlund
2004-07-05 8:17 ` [PATCH] CDRW packet writing support for 2.6.7-bk13 Jens Axboe
2004-07-05 10:26 ` Christoph Hellwig
2004-07-06 8:45 ` Peter Osterlund
2004-07-07 10:06 ` Peter Osterlund
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m28ye0uf8v.fsf@telia.com \
--to=petero2@telia.com \
--cc=akpm@osdl.org \
--cc=axboe@suse.de \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome