From 4b92cb702396b8f8e3ba6137434336972dc0bfcf Mon Sep 17 00:00:00 2001 From: meganz009 Date: Fri, 2 Jun 2023 20:55:33 +0800 Subject: [PATCH 1/4] signal: Revert ptrace preempt magic commit fc38cdec8c7fa26cc2b0520c1cd0eb9ff96c969a upstream. Upstream commit '53da1d9456fe7f8 fix ptrace slowness' is nothing more than a bandaid around the ptrace design trainwreck. It's not a correctness issue, it's merily a cosmetic bandaid. Signed-off-by: Thomas Gleixner --- kernel/signal.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/kernel/signal.c b/kernel/signal.c index 40cf84045394..29cab76b1058 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2111,15 +2111,7 @@ static void ptrace_stop(int exit_code, int why, int clear_code, siginfo_t *info) if (gstop_done && ptrace_reparented(current)) do_notify_parent_cldstop(current, false, why); - /* - * Don't want to allow preemption here, because - * sys_ptrace() needs this task to be inactive. - * - * XXX: implement read_unlock_no_resched(). - */ - preempt_disable(); read_unlock(&tasklist_lock); - preempt_enable_no_resched(); freezable_schedule(); } else { /* -- Gitee From fd5e2371c262f9ef053eb7941dad9069cafe9f19 Mon Sep 17 00:00:00 2001 From: meganz009 Date: Fri, 2 Jun 2023 20:56:28 +0800 Subject: [PATCH 2/4] net: sched: Use msleep() instead of yield() commit 280627bfccdc36087f174418d56e57d027552a14 upstream. On PREEMPT_RT enabled systems the interrupt handler run as threads at prio 50 (by default). If a high priority userspace process tries to shut down a busy network interface it might spin in a yield loop waiting for the device to become idle. With the interrupt thread having a lower priority than the looping process it might never be scheduled and so result in a deadlock on UP systems. With Magic SysRq the following backtrace can be produced: > test_app R running 0 174 168 0x00000000 > [] (__schedule+0x220/0x3fc) from [] (preempt_schedule_irq+0x48/0x80) > [] (preempt_schedule_irq+0x48/0x80) from [] (svc_preempt+0x8/0x20) > [] (svc_preempt+0x8/0x20) from [] (local_bh_enable+0x18/0x88) > [] (local_bh_enable+0x18/0x88) from [] (dev_deactivate_many+0x220/0x264) > [] (dev_deactivate_many+0x220/0x264) from [] (__dev_close_many+0x64/0xd4) > [] (__dev_close_many+0x64/0xd4) from [] (__dev_close+0x28/0x3c) > [] (__dev_close+0x28/0x3c) from [] (__dev_change_flags+0x88/0x130) > [] (__dev_change_flags+0x88/0x130) from [] (dev_change_flags+0x10/0x48) > [] (dev_change_flags+0x10/0x48) from [] (do_setlink+0x370/0x7ec) > [] (do_setlink+0x370/0x7ec) from [] (rtnl_newlink+0x2b4/0x450) > [] (rtnl_newlink+0x2b4/0x450) from [] (rtnetlink_rcv_msg+0x158/0x1f4) > [] (rtnetlink_rcv_msg+0x158/0x1f4) from [] (netlink_rcv_skb+0xac/0xc0) > [] (netlink_rcv_skb+0xac/0xc0) from [] (rtnetlink_rcv+0x18/0x24) > [] (rtnetlink_rcv+0x18/0x24) from [] (netlink_unicast+0x13c/0x198) > [] (netlink_unicast+0x13c/0x198) from [] (netlink_sendmsg+0x264/0x2e0) > [] (netlink_sendmsg+0x264/0x2e0) from [] (sock_sendmsg+0x78/0x98) > [] (sock_sendmsg+0x78/0x98) from [] (___sys_sendmsg.part.25+0x268/0x278) > [] (___sys_sendmsg.part.25+0x268/0x278) from [] (__sys_sendmsg+0x48/0x78) > [] (__sys_sendmsg+0x48/0x78) from [] (ret_fast_syscall+0x0/0x2c) This patch works around the problem by replacing yield() by msleep(1), giving the interrupt thread time to finish, similar to other changes contained in the rt patch set. Using wait_for_completion() instead would probably be a better solution. Signed-off-by: Marc Kleine-Budde Signed-off-by: Sebastian Andrzej Siewior --- net/sched/sch_generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c index 8a4d01e427a2..4ab20f1138fd 100644 --- a/net/sched/sch_generic.c +++ b/net/sched/sch_generic.c @@ -1204,7 +1204,7 @@ void dev_deactivate_many(struct list_head *head) /* Wait for outstanding qdisc_run calls. */ list_for_each_entry(dev, head, close_list) { while (some_qdisc_is_busy(dev)) - yield(); + msleep(1); /* The new qdisc is assigned at this point so we can safely * unwind stale skb lists and qdisc statistics */ -- Gitee From 5310c639dfb69a6c1cade6fbed69a46531b6db85 Mon Sep 17 00:00:00 2001 From: meganz009 Date: Fri, 2 Jun 2023 20:56:44 +0800 Subject: [PATCH 3/4] dm rq: remove BUG_ON(!irqs_disabled) check commit ec6350958b69d6c98248ee0871b3a7c00c5949c5 upstream. In commit 052189a2ec95 ("dm: remove superfluous irq disablement in dm_request_fn") the spin_lock_irq() was replaced with spin_lock() + a check for disabled interrupts. Later the locking part was removed in commit 2eb6e1e3aa87 ("dm: submit stacked requests in irq enabled context") but the BUG_ON() check remained. Since the original purpose for the "are-irqs-off" check is gone (the ->queue_lock has been removed) remove it. Cc: Keith Busch Cc: Mike Snitzer Signed-off-by: Sebastian Andrzej Siewior --- drivers/md/dm-rq.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c index 4d36373e1c0f..12ed08245130 100644 --- a/drivers/md/dm-rq.c +++ b/drivers/md/dm-rq.c @@ -692,7 +692,6 @@ static void dm_old_request_fn(struct request_queue *q) /* Establish tio->ti before queuing work (map_tio_request) */ tio->ti = ti; kthread_queue_work(&md->kworker, &tio->work); - BUG_ON(!irqs_disabled()); } } -- Gitee From 02ea8df2f8f12c016ab8a399ce2f56ea84821d0e Mon Sep 17 00:00:00 2001 From: meganz009 Date: Fri, 2 Jun 2023 20:57:07 +0800 Subject: [PATCH 4/4] usb: do no disable interrupts in giveback commit c5248048f310926cc88f9d625126ebb980024a51 upstream. Since commit 94dfd7ed ("USB: HCD: support giveback of URB in tasklet context") the USB code disables interrupts before invoking the complete callback. This should not be required the HCD completes the URBs either in hard-irq context or in BH context. Lockdep may report false positives if one has two HCDs (one completes in IRQ and the other in BH context) and is using the same USB driver (device) with both HCDs. This is safe since the same URBs are never mixed with those two HCDs. Longeterm we should force all HCDs to complete in the same context. Signed-off-by: Sebastian Andrzej Siewior --- drivers/usb/core/hcd.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index baf636ce00bb..f13040bc33f7 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -1737,7 +1737,6 @@ static void __usb_hcd_giveback_urb(struct urb *urb) struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); struct usb_anchor *anchor = urb->anchor; int status = urb->unlinked; - unsigned long flags; urb->hcpriv = NULL; if (unlikely((urb->transfer_flags & URB_SHORT_NOT_OK) && @@ -1765,9 +1764,7 @@ static void __usb_hcd_giveback_urb(struct urb *urb) * and no one may trigger the above deadlock situation when * running complete() in tasklet. */ - local_irq_save(flags); urb->complete(urb); - local_irq_restore(flags); usb_anchor_resume_wakeups(anchor); atomic_dec(&urb->use_count); -- Gitee