From patchwork Wed Feb 12 17:43:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 13972240 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0598625E44D; Wed, 12 Feb 2025 17:43:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739382221; cv=none; b=L8nvuO89t5Hya4frJppt9iSY2Tqc0WSUmNIFR9cy3F7h1M9W6VZvxosounm4wtfMVeEUA4I58w6+btG0MBsDBNhe/LawNCb397iqCZ1JqOenvi4d+xy5n3QbOW08MX6uA1QjUjXLcJtC3idMMFgjxoE+tR9HdLdmVp2WHMTOTIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739382221; c=relaxed/simple; bh=GQmd9aEaFFJWA/wdYX4hixqzMoeMSS0iUsiiREnVfhk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CFg8asbX8VQia297hG3SS7UCFI0vgIzQvWeg/eEtVVEGAzhDbfhx/v7sPeFRlp2UqnVcJBzep1Jdb2HhutkrGBXxqz+sVc9mYpSprsinHqDO68c5cLFLEgBua5aGWPupU/aSS3aT8rpm3CmH+bTmVztTRNrWau7BsXByDaoRrbg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YibhAP9D; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YibhAP9D" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81F41C4CEE4; Wed, 12 Feb 2025 17:43:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739382220; bh=GQmd9aEaFFJWA/wdYX4hixqzMoeMSS0iUsiiREnVfhk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YibhAP9D9GHeFXcpD/BLCQRgN7CFZMO/UIImcBXHyMZapI01T6+179VRSsruoSrxw rbuln/CDTxmYTmu2ftErkjXnR5fZ9is1mMKbNTaBHHckCh0+nCJK7Yj4sRWzWPHrsM dPBiWWWFnUKq8j0vHtHr6FmhrAhvWBNqVKRMNf4fIXLFL9ldUQqqyNwMgeIKY6Exhi ddMJRdvG6mHqxnLr+5/sdXghswZyrXc+KtOqVPtYEyL/qcoJ/UuMJ7sCPwQDtrHdLn CTy5XluVYd/2taA3nW9JJ38uLl7LyKQZoOhJeGol3PpQfLtg2KPYPWJ2bXxhPNq2h7 eYSaketI4aLxw== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , Waiman Long , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Hayes Wang , linux-usb@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 1/2] net: Assert proper context while calling napi_schedule() Date: Wed, 12 Feb 2025 18:43:28 +0100 Message-ID: <20250212174329.53793-2-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250212174329.53793-1-frederic@kernel.org> References: <20250212174329.53793-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 napi_schedule() is expected to be called either: * From an interrupt, where raised softirqs are handled on IRQ exit * From a softirq disabled section, where raised softirqs are handled on the next call to local_bh_enable(). * From a softirq handler, where raised softirqs are handled on the next round in do_softirq(), or further deferred to a dedicated kthread. Other bare tasks context may end up ignoring the raised NET_RX vector until the next random softirq handling opportunity, which may not happen before a while if the CPU goes idle afterwards with the tick stopped. Report inappropriate calling contexts when neither of the three above conditions are met. Signed-off-by: Frederic Weisbecker --- include/linux/lockdep.h | 12 ++++++++++++ net/core/dev.c | 1 + 2 files changed, 13 insertions(+) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index 67964dc4db95..1bd730b881f0 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -619,6 +619,17 @@ do { \ (!in_softirq() || in_irq() || in_nmi())); \ } while (0) +/* + * Assert to be either in hardirq or in serving softirq or with + * softirqs disabled. Verifies a safe context to queue a softirq + * with __raise_softirq_irqoff(). + */ +#define lockdep_assert_in_interrupt() \ +do { \ + WARN_ON_ONCE(__lockdep_enabled && !in_interrupt()); \ +} while (0) + + extern void lockdep_assert_in_softirq_func(void); #else @@ -634,6 +645,7 @@ extern void lockdep_assert_in_softirq_func(void); # define lockdep_assert_preemption_enabled() do { } while (0) # define lockdep_assert_preemption_disabled() do { } while (0) # define lockdep_assert_in_softirq() do { } while (0) +# define lockdep_assert_in_interrupt() do { } while (0) # define lockdep_assert_in_softirq_func() do { } while (0) #endif diff --git a/net/core/dev.c b/net/core/dev.c index c0021cbd28fc..80e415ccf2c8 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4666,6 +4666,7 @@ static inline void ____napi_schedule(struct softnet_data *sd, struct task_struct *thread; lockdep_assert_irqs_disabled(); + lockdep_assert_in_interrupt(); if (test_bit(NAPI_STATE_THREADED, &napi->state)) { /* Paired with smp_mb__before_atomic() in From patchwork Wed Feb 12 17:43:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 13972241 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAA69260A2C; Wed, 12 Feb 2025 17:43:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739382223; cv=none; b=XjXLzjpQkaZ2hsWhirPuOlm4HXg/17Fe0nRwHDNLsEy6AP2t0VIx4XMbEcI53ZBrHPBIL8F6rt1DhGnyNqRLJVuLXbc0s9Rd8ZaOvuK0SfPsIe/CnVhiUmqRhpY9cAYYGJ2HQCiLK0NGC56XP6GBKWvoZSxe0qfinxl9czhGlZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739382223; c=relaxed/simple; bh=yV10f3sVYdeD/lwq8HQsrJW3zW/rQaXngqmNeXro5IY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=srf/616T1JWNCKLIO/0r6c/WZmawfrLFw1FWCB1EBBs2yr+yOhQLjkbfMuz/NsQpzoSlYk8HvKwHVw7XPT2U8Ocg1Gp+nwaHYrfPP+EEg5wJNbjfLVUnv3X0SZWq7pEalEMxkQDoBHiNkiYGD2yVWAbLSN6KRd3B5yXxMYmXacA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Cs+1l6xn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Cs+1l6xn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6313C4CEE2; Wed, 12 Feb 2025 17:43:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739382223; bh=yV10f3sVYdeD/lwq8HQsrJW3zW/rQaXngqmNeXro5IY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cs+1l6xn0g8Fm5UW9psMSwSDShIg8O/UVUUb51qgjHM+cAqDXiqIn+Fl7/8m2VrNf 5bBNz5f090veOhnot48tjJ5DMh8xUJ2AAG+WSZgiiUYf83sFg+1bbs0xX7inH5aoUy sWVb1zdGOYFK3DojvTbZ5eeNSTbyXGOglJJQ/d5SQANvCnzkKR8vMp6ngEmynCVYV9 fvHeXExBOfTsSVvM/4b8UP6wsPwWtfp8xq9boDILQvEvITP/7gyDqWhfkuK1QL8AZv 1zxRBTA77SsNXVzp25CCAgrkslA/5cYbd3X5T3763B2vRbm+JyMzMGFg7/8urx1jv2 7t+NiRG7U7gFw== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Hayes Wang , linux-usb@vger.kernel.org, netdev@vger.kernel.org, Paul Menzel Subject: [PATCH 2/2] r8152: Call napi_schedule() from proper context Date: Wed, 12 Feb 2025 18:43:29 +0100 Message-ID: <20250212174329.53793-3-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250212174329.53793-1-frederic@kernel.org> References: <20250212174329.53793-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 napi_schedule() is expected to be called either: * From an interrupt, where raised softirqs are handled on IRQ exit * Fom a softirq disabled section, where raised softirqs are handled on the next call to local_bh_enable(). * From a softirq handler, where raised softirqs are handled on the next round in do_softirq(), or further deferred to a dedicated kthread. r8152 may call napi_schedule() on device resume time from a bare task context without disabling softirqs as the following trace shows: __raise_softirq_irqoff __napi_schedule rtl8152_runtime_resume.isra.0 rtl8152_resume usb_resume_interface.isra.0 usb_resume_both __rpm_callback rpm_callback rpm_resume __pm_runtime_resume usb_autoresume_device usb_remote_wakeup hub_event process_one_work worker_thread kthread ret_from_fork ret_from_fork_asm This may result in the NET_RX softirq vector to be ignored until the next interrupt or softirq handling. The delay can be long if the above kthread leaves the CPU idle and the tick is stopped for a while, as reported with the following message: NOHZ tick-stop error: local softirq work is pending, handler #08!!! Fix this with disabling softirqs while calling napi_schedule(). The call to local_bh_enable() will take care of the NET_RX raised vector. Reported-by: Paul Menzel Closes: 354a2690-9bbf-4ccb-8769-fa94707a9340@molgen.mpg.de Signed-off-by: Frederic Weisbecker Tested-by: Paul Menzel --- drivers/net/usb/r8152.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 468c73974046..1325460ae457 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -8537,8 +8537,11 @@ static int rtl8152_runtime_resume(struct r8152 *tp) clear_bit(SELECTIVE_SUSPEND, &tp->flags); smp_mb__after_atomic(); - if (!list_empty(&tp->rx_done)) + if (!list_empty(&tp->rx_done)) { + local_bh_disable(); napi_schedule(&tp->napi); + local_bh_enable(); + } usb_submit_urb(tp->intr_urb, GFP_NOIO); } else {