Commit a460ef8d authored by Dean Nelson's avatar Dean Nelson Committed by Tony Luck

[IA64] fix possible XPC deadlock when disconnecting

This patch eliminates a potential deadlock that is possible when XPC
disconnects a channel to a partition that has gone down. This deadlock will
occur if at least one of the kthreads created by XPC for the purpose of making
callouts to the channel's registerer is detained in the registerer and will
not be returning back to XPC until some registerer request occurs on the now
downed partition. The potential for a deadlock is removed by ensuring that
there always is a kthread available to make the channel disconnecting callout
to the registerer.
Signed-off-by: default avatarDean Nelson <dcn@sgi.com>
Signed-off-by: default avatarTony Luck <tony.luck@intel.com>
parent 1cf24bdb
...@@ -632,7 +632,7 @@ xpc_process_connect(struct xpc_channel *ch, unsigned long *irq_flags) ...@@ -632,7 +632,7 @@ xpc_process_connect(struct xpc_channel *ch, unsigned long *irq_flags)
ch->number, ch->partid); ch->number, ch->partid);
spin_unlock_irqrestore(&ch->lock, *irq_flags); spin_unlock_irqrestore(&ch->lock, *irq_flags);
xpc_create_kthreads(ch, 1); xpc_create_kthreads(ch, 1, 0);
spin_lock_irqsave(&ch->lock, *irq_flags); spin_lock_irqsave(&ch->lock, *irq_flags);
} }
...@@ -754,12 +754,12 @@ xpc_process_disconnect(struct xpc_channel *ch, unsigned long *irq_flags) ...@@ -754,12 +754,12 @@ xpc_process_disconnect(struct xpc_channel *ch, unsigned long *irq_flags)
/* make sure all activity has settled down first */ /* make sure all activity has settled down first */
if (atomic_read(&ch->references) > 0 || if (atomic_read(&ch->kthreads_assigned) > 0 ||
((ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) && atomic_read(&ch->references) > 0) {
!(ch->flags & XPC_C_DISCONNECTINGCALLOUT_MADE))) {
return; return;
} }
DBUG_ON(atomic_read(&ch->kthreads_assigned) != 0); DBUG_ON((ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) &&
!(ch->flags & XPC_C_DISCONNECTINGCALLOUT_MADE));
if (part->act_state == XPC_P_DEACTIVATING) { if (part->act_state == XPC_P_DEACTIVATING) {
/* can't proceed until the other side disengages from us */ /* can't proceed until the other side disengages from us */
...@@ -1651,6 +1651,11 @@ xpc_disconnect_channel(const int line, struct xpc_channel *ch, ...@@ -1651,6 +1651,11 @@ xpc_disconnect_channel(const int line, struct xpc_channel *ch,
/* wake all idle kthreads so they can exit */ /* wake all idle kthreads so they can exit */
if (atomic_read(&ch->kthreads_idle) > 0) { if (atomic_read(&ch->kthreads_idle) > 0) {
wake_up_all(&ch->idle_wq); wake_up_all(&ch->idle_wq);
} else if ((ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) &&
!(ch->flags & XPC_C_DISCONNECTINGCALLOUT)) {
/* start a kthread that will do the xpcDisconnecting callout */
xpc_create_kthreads(ch, 1, 1);
} }
/* wake those waiting to allocate an entry from the local msg queue */ /* wake those waiting to allocate an entry from the local msg queue */
......
...@@ -681,7 +681,7 @@ xpc_activate_kthreads(struct xpc_channel *ch, int needed) ...@@ -681,7 +681,7 @@ xpc_activate_kthreads(struct xpc_channel *ch, int needed)
dev_dbg(xpc_chan, "create %d new kthreads, partid=%d, channel=%d\n", dev_dbg(xpc_chan, "create %d new kthreads, partid=%d, channel=%d\n",
needed, ch->partid, ch->number); needed, ch->partid, ch->number);
xpc_create_kthreads(ch, needed); xpc_create_kthreads(ch, needed, 0);
} }
...@@ -775,7 +775,8 @@ xpc_daemonize_kthread(void *args) ...@@ -775,7 +775,8 @@ xpc_daemonize_kthread(void *args)
xpc_kthread_waitmsgs(part, ch); xpc_kthread_waitmsgs(part, ch);
} }
if (atomic_dec_return(&ch->kthreads_assigned) == 0) { /* let registerer know that connection is disconnecting */
spin_lock_irqsave(&ch->lock, irq_flags); spin_lock_irqsave(&ch->lock, irq_flags);
if ((ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) && if ((ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) &&
!(ch->flags & XPC_C_DISCONNECTINGCALLOUT)) { !(ch->flags & XPC_C_DISCONNECTINGCALLOUT)) {
...@@ -788,13 +789,14 @@ xpc_daemonize_kthread(void *args) ...@@ -788,13 +789,14 @@ xpc_daemonize_kthread(void *args)
ch->flags |= XPC_C_DISCONNECTINGCALLOUT_MADE; ch->flags |= XPC_C_DISCONNECTINGCALLOUT_MADE;
} }
spin_unlock_irqrestore(&ch->lock, irq_flags); spin_unlock_irqrestore(&ch->lock, irq_flags);
if (atomic_dec_return(&ch->kthreads_assigned) == 0) {
if (atomic_dec_return(&part->nchannels_engaged) == 0) { if (atomic_dec_return(&part->nchannels_engaged) == 0) {
xpc_mark_partition_disengaged(part); xpc_mark_partition_disengaged(part);
xpc_IPI_send_disengage(part); xpc_IPI_send_disengage(part);
} }
} }
xpc_msgqueue_deref(ch); xpc_msgqueue_deref(ch);
dev_dbg(xpc_chan, "kthread exiting, partid=%d, channel=%d\n", dev_dbg(xpc_chan, "kthread exiting, partid=%d, channel=%d\n",
...@@ -818,7 +820,8 @@ xpc_daemonize_kthread(void *args) ...@@ -818,7 +820,8 @@ xpc_daemonize_kthread(void *args)
* partition. * partition.
*/ */
void void
xpc_create_kthreads(struct xpc_channel *ch, int needed) xpc_create_kthreads(struct xpc_channel *ch, int needed,
int ignore_disconnecting)
{ {
unsigned long irq_flags; unsigned long irq_flags;
pid_t pid; pid_t pid;
...@@ -833,16 +836,38 @@ xpc_create_kthreads(struct xpc_channel *ch, int needed) ...@@ -833,16 +836,38 @@ xpc_create_kthreads(struct xpc_channel *ch, int needed)
* kthread. That kthread is responsible for doing the * kthread. That kthread is responsible for doing the
* counterpart to the following before it exits. * counterpart to the following before it exits.
*/ */
(void) xpc_part_ref(part); if (ignore_disconnecting) {
xpc_msgqueue_ref(ch); if (!atomic_inc_not_zero(&ch->kthreads_assigned)) {
if (atomic_inc_return(&ch->kthreads_assigned) == 1 && /* kthreads assigned had gone to zero */
atomic_inc_return(&part->nchannels_engaged) == 1) { BUG_ON(!(ch->flags &
XPC_C_DISCONNECTINGCALLOUT_MADE));
break;
}
} else if (ch->flags & XPC_C_DISCONNECTING) {
break;
} else if (atomic_inc_return(&ch->kthreads_assigned) == 1) {
if (atomic_inc_return(&part->nchannels_engaged) == 1)
xpc_mark_partition_engaged(part); xpc_mark_partition_engaged(part);
} }
(void) xpc_part_ref(part);
xpc_msgqueue_ref(ch);
pid = kernel_thread(xpc_daemonize_kthread, (void *) args, 0); pid = kernel_thread(xpc_daemonize_kthread, (void *) args, 0);
if (pid < 0) { if (pid < 0) {
/* the fork failed */ /* the fork failed */
/*
* NOTE: if (ignore_disconnecting &&
* !(ch->flags & XPC_C_DISCONNECTINGCALLOUT)) is true,
* then we'll deadlock if all other kthreads assigned
* to this channel are blocked in the channel's
* registerer, because the only thing that will unblock
* them is the xpcDisconnecting callout that this
* failed kernel_thread would have made.
*/
if (atomic_dec_return(&ch->kthreads_assigned) == 0 && if (atomic_dec_return(&ch->kthreads_assigned) == 0 &&
atomic_dec_return(&part->nchannels_engaged) == 0) { atomic_dec_return(&part->nchannels_engaged) == 0) {
xpc_mark_partition_disengaged(part); xpc_mark_partition_disengaged(part);
...@@ -857,9 +882,6 @@ xpc_create_kthreads(struct xpc_channel *ch, int needed) ...@@ -857,9 +882,6 @@ xpc_create_kthreads(struct xpc_channel *ch, int needed)
* Flag this as an error only if we have an * Flag this as an error only if we have an
* insufficient #of kthreads for the channel * insufficient #of kthreads for the channel
* to function. * to function.
*
* No xpc_msgqueue_ref() is needed here since
* the channel mgr is doing this.
*/ */
spin_lock_irqsave(&ch->lock, irq_flags); spin_lock_irqsave(&ch->lock, irq_flags);
XPC_DISCONNECT_CHANNEL(ch, xpcLackOfResources, XPC_DISCONNECT_CHANNEL(ch, xpcLackOfResources,
......
...@@ -673,7 +673,7 @@ extern irqreturn_t xpc_notify_IRQ_handler(int, void *); ...@@ -673,7 +673,7 @@ extern irqreturn_t xpc_notify_IRQ_handler(int, void *);
extern void xpc_dropped_IPI_check(struct xpc_partition *); extern void xpc_dropped_IPI_check(struct xpc_partition *);
extern void xpc_activate_partition(struct xpc_partition *); extern void xpc_activate_partition(struct xpc_partition *);
extern void xpc_activate_kthreads(struct xpc_channel *, int); extern void xpc_activate_kthreads(struct xpc_channel *, int);
extern void xpc_create_kthreads(struct xpc_channel *, int); extern void xpc_create_kthreads(struct xpc_channel *, int, int);
extern void xpc_disconnect_wait(int); extern void xpc_disconnect_wait(int);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment