Commit 37aadc68 authored by Peter Zijlstra's avatar Peter Zijlstra

sched: Unbreak wakeups

Remove broken task->state references and let wake_up_process() DTRT.

The anti-pattern in these patches breaks the ordering of ->state vs
COND as described in the comment near set_current_state() and can lead
to missed wakeups:

	(OoO load, observes RUNNING)<-.
	for (;;) {                    |
	  t->state = UNINTERRUPTIBLE; |
	  smp_mb();          ,----->  | (observes !COND)
                             |        /
	  if (COND) ---------'       |	COND = 1;
		break;		     `- if (t->state != RUNNING)
					  wake_up_process(t); // not done
	  schedule(); // forever waiting
	}
	t->state = TASK_RUNNING;
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarDavidlohr Bueso <dbueso@suse.de>
Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: default avatarWill Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20210611082838.160855222@infradead.org
parent b2c0931a
...@@ -653,8 +653,7 @@ qcaspi_intr_handler(int irq, void *data) ...@@ -653,8 +653,7 @@ qcaspi_intr_handler(int irq, void *data)
struct qcaspi *qca = data; struct qcaspi *qca = data;
qca->intr_req++; qca->intr_req++;
if (qca->spi_thread && if (qca->spi_thread)
qca->spi_thread->state != TASK_RUNNING)
wake_up_process(qca->spi_thread); wake_up_process(qca->spi_thread);
return IRQ_HANDLED; return IRQ_HANDLED;
...@@ -777,8 +776,7 @@ qcaspi_netdev_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -777,8 +776,7 @@ qcaspi_netdev_xmit(struct sk_buff *skb, struct net_device *dev)
netif_trans_update(dev); netif_trans_update(dev);
if (qca->spi_thread && if (qca->spi_thread)
qca->spi_thread->state != TASK_RUNNING)
wake_up_process(qca->spi_thread); wake_up_process(qca->spi_thread);
return NETDEV_TX_OK; return NETDEV_TX_OK;
......
...@@ -509,8 +509,7 @@ static irqreturn_t max3420_vbus_handler(int irq, void *dev_id) ...@@ -509,8 +509,7 @@ static irqreturn_t max3420_vbus_handler(int irq, void *dev_id)
? USB_STATE_POWERED : USB_STATE_NOTATTACHED); ? USB_STATE_POWERED : USB_STATE_NOTATTACHED);
spin_unlock_irqrestore(&udc->lock, flags); spin_unlock_irqrestore(&udc->lock, flags);
if (udc->thread_task && if (udc->thread_task)
udc->thread_task->state != TASK_RUNNING)
wake_up_process(udc->thread_task); wake_up_process(udc->thread_task);
return IRQ_HANDLED; return IRQ_HANDLED;
...@@ -529,8 +528,7 @@ static irqreturn_t max3420_irq_handler(int irq, void *dev_id) ...@@ -529,8 +528,7 @@ static irqreturn_t max3420_irq_handler(int irq, void *dev_id)
} }
spin_unlock_irqrestore(&udc->lock, flags); spin_unlock_irqrestore(&udc->lock, flags);
if (udc->thread_task && if (udc->thread_task)
udc->thread_task->state != TASK_RUNNING)
wake_up_process(udc->thread_task); wake_up_process(udc->thread_task);
return IRQ_HANDLED; return IRQ_HANDLED;
...@@ -1093,8 +1091,7 @@ static int max3420_wakeup(struct usb_gadget *gadget) ...@@ -1093,8 +1091,7 @@ static int max3420_wakeup(struct usb_gadget *gadget)
spin_unlock_irqrestore(&udc->lock, flags); spin_unlock_irqrestore(&udc->lock, flags);
if (udc->thread_task && if (udc->thread_task)
udc->thread_task->state != TASK_RUNNING)
wake_up_process(udc->thread_task); wake_up_process(udc->thread_task);
return ret; return ret;
} }
...@@ -1117,8 +1114,7 @@ static int max3420_udc_start(struct usb_gadget *gadget, ...@@ -1117,8 +1114,7 @@ static int max3420_udc_start(struct usb_gadget *gadget,
udc->todo |= UDC_START; udc->todo |= UDC_START;
spin_unlock_irqrestore(&udc->lock, flags); spin_unlock_irqrestore(&udc->lock, flags);
if (udc->thread_task && if (udc->thread_task)
udc->thread_task->state != TASK_RUNNING)
wake_up_process(udc->thread_task); wake_up_process(udc->thread_task);
return 0; return 0;
...@@ -1137,8 +1133,7 @@ static int max3420_udc_stop(struct usb_gadget *gadget) ...@@ -1137,8 +1133,7 @@ static int max3420_udc_stop(struct usb_gadget *gadget)
udc->todo |= UDC_START; udc->todo |= UDC_START;
spin_unlock_irqrestore(&udc->lock, flags); spin_unlock_irqrestore(&udc->lock, flags);
if (udc->thread_task && if (udc->thread_task)
udc->thread_task->state != TASK_RUNNING)
wake_up_process(udc->thread_task); wake_up_process(udc->thread_task);
return 0; return 0;
......
...@@ -1169,8 +1169,7 @@ max3421_irq_handler(int irq, void *dev_id) ...@@ -1169,8 +1169,7 @@ max3421_irq_handler(int irq, void *dev_id)
struct spi_device *spi = to_spi_device(hcd->self.controller); struct spi_device *spi = to_spi_device(hcd->self.controller);
struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd);
if (max3421_hcd->spi_thread && if (max3421_hcd->spi_thread)
max3421_hcd->spi_thread->state != TASK_RUNNING)
wake_up_process(max3421_hcd->spi_thread); wake_up_process(max3421_hcd->spi_thread);
if (!test_and_set_bit(ENABLE_IRQ, &max3421_hcd->todo)) if (!test_and_set_bit(ENABLE_IRQ, &max3421_hcd->todo))
disable_irq_nosync(spi->irq); disable_irq_nosync(spi->irq);
......
...@@ -76,7 +76,7 @@ static void wakeup_softirqd(void) ...@@ -76,7 +76,7 @@ static void wakeup_softirqd(void)
/* Interrupts are disabled: no need to stop preemption */ /* Interrupts are disabled: no need to stop preemption */
struct task_struct *tsk = __this_cpu_read(ksoftirqd); struct task_struct *tsk = __this_cpu_read(ksoftirqd);
if (tsk && tsk->state != TASK_RUNNING) if (tsk)
wake_up_process(tsk); wake_up_process(tsk);
} }
......
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