From patchwork Wed Feb 16 17:50:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 12748902 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29DFDC433FE for ; Wed, 16 Feb 2022 17:50:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237136AbiBPRvD (ORCPT ); Wed, 16 Feb 2022 12:51:03 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:42608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232449AbiBPRvC (ORCPT ); Wed, 16 Feb 2022 12:51:02 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A1E22B0B1F; Wed, 16 Feb 2022 09:50:50 -0800 (PST) Date: Wed, 16 Feb 2022 18:50:46 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1645033847; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=YPEdXaJgjEi/SM/CGN0s0Wpl04buNzspNJbXpHNAuTU=; b=GhyB0Kl93o06tMrnWyGexxtTY3haCpMzApH8Mvauz+QyBOP/7cgsNmBTKSC4dNB5aEoP3Q 5bcQucjACMZAVO1PRTzYCW70KHvusNYfNVUZMVNZeVZBv6dASkhpKJXzWqR+Z3A4KwVdWd f6kS3X4tPsSE5MqqFRpQAqxepR2+7/FCw6NHNqqDctqYw2FQCa28/TAuT/m38gLOYzZFGD MVhvpDOiPleRj0Nnkk+W3ZkZiw+zbFo0S5l367PBSGQYq9nebYOpWkH7tXSSdyPgFF6i6N XJhCuQOCyJXqn4JP519uwWAb7CCV/crlQHd6UmU+gfljnW2Yn/CtIDdCnsKJGA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1645033847; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=YPEdXaJgjEi/SM/CGN0s0Wpl04buNzspNJbXpHNAuTU=; b=tr6SY6YlZUWYA//WWe6kGV1QcdkD2AMf8qeMCbNgKrP+4fcGvrVmal8OJeXo2g9+x9x8+Q qiUKUS988bNLfKDQ== From: Sebastian Andrzej Siewior To: Marek Szyprowski Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, "David S. Miller" , Alexei Starovoitov , Daniel Borkmann , Eric Dumazet , Jakub Kicinski , Jesper Dangaard Brouer , John Fastabend , Thomas Gleixner , Toke =?utf-8?q?H=C3=B8iland-J=C3=B8rg?= =?utf-8?q?ensen?= , Toke =?utf-8?q?H=C3=B8iland-J=C3=B8rgense?= =?utf-8?q?n?= Subject: [PATCH net-next] net: Correct wrong BH disable in hard-interrupt. Message-ID: MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org I missed the obvious case where netif_ix() is invoked from hard-IRQ context. Disabling bottom halves is only needed in process context. This ensures that the code remains on the current CPU and that the soft-interrupts are processed at local_bh_enable() time. In hard- and soft-interrupt context this is already the case and the soft-interrupts will be processed once the context is left (at irq-exit time). Disable bottom halves if neither hard-interrupts nor soft-interrupts are disabled. Update the kernel-doc, mention that interrupts must be enabled if invoked from process context. Fixes: baebdf48c3600 ("net: dev: Makes sure netif_rx() can be invoked in any context.") Reported-by: Marek Szyprowski Signed-off-by: Sebastian Andrzej Siewior Tested-by: Marek Szyprowski Tested-by: Geert Uytterhoeven --- Marek, does this work for you? net/core/dev.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 909fb38159108..87729491460fc 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4860,7 +4860,9 @@ EXPORT_SYMBOL(__netif_rx); * congestion control or by the protocol layers. * The network buffer is passed via the backlog NAPI device. Modern NIC * driver should use NAPI and GRO. - * This function can used from any context. + * This function can used from interrupt and from process context. The + * caller from process context must not disable interrupts before invoking + * this function. * * return values: * NET_RX_SUCCESS (no congestion) @@ -4870,12 +4872,15 @@ EXPORT_SYMBOL(__netif_rx); int netif_rx(struct sk_buff *skb) { int ret; + bool need_bh_off = !(hardirq_count() | softirq_count()); - local_bh_disable(); + if (need_bh_off) + local_bh_disable(); trace_netif_rx_entry(skb); ret = netif_rx_internal(skb); trace_netif_rx_exit(ret); - local_bh_enable(); + if (need_bh_off) + local_bh_enable(); return ret; } EXPORT_SYMBOL(netif_rx);