From patchwork Fri Dec 15 17:07:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 179433 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9436340dys; Fri, 15 Dec 2023 09:16:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHaUdQe6QpNpq5l/lbPCFaO3tOh1xFVzbRC2G8APHh3C9iazEAgp4j31yOTDi4PiyE2UEth X-Received: by 2002:a2e:83d6:0:b0:2cc:55da:99f0 with SMTP id s22-20020a2e83d6000000b002cc55da99f0mr213563ljh.7.1702660607799; Fri, 15 Dec 2023 09:16:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702660607; cv=none; d=google.com; s=arc-20160816; b=lpHT4iFPFTGV87n7dM66MLNSho3oK8orirWBOecH+krquvTEGVbMRVMBUavH39wrNo aMhiG1JB01mmnNIdASqpv+3Q89hrV093id0HPW2ehjx4wzHoVc1tfpAwdQW1KryGgo5o 1YI/rennt1iCGNZxZegmFG6KdExHTJISiuPjLmhIVkiI1ZcEHZPg5n3bInBV9QQH4pJP 64YhzQ9tRE7EaSd1TJFBlltpmcIDmmXpOqJb5dMg2zwdYX1WubluY+hgkUdqq/zNUDxh k3tjjBK+Ig00HJUjRShUKjQQdUljXtP/vvct3hU8rp/gaWVvsiEtre2M8kkVtEJ7ppE1 hI0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=9YY938P41v7tgAkEsD/QoBSvsRcX+2kJhvYsQnrL6Aw=; fh=mRMHo6FEBd+e0N/0wwmt9BaEcwCnNTE8npQn9DDRWX4=; b=o8+VsdpLT++nDY9LISJVn7XMlLDxv31WQVi5enJSdMPAWMEt1opL7f6+M06ThBZb6c DylQXsNV+deXF48Cm44oPDWQiubQjcL2tF6c4o15n3MMX48G+OsrTAp4Z1I3REXiZ1an 9XJCRp3of9+eFdXOXlj6T2DPeK66Am438uSiwMYNv/YQx/HJ0bCCzkJsPzp/028p695m QR0QBRbNwlwE9FrwYED32LqPHvdtyRTOLWZ3fmWcZdElWExV12DbDKkq0eeNfYDBpRML RUHYDtqkHx3xM7jgHyA0Q1TM7pC7ghMuFxfiC88vLi1NL2u1EIMdHEY+XsJpRXKXP46o xvxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Z1v8qLCV; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-1376-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1376-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i2-20020a50d742000000b005529df20493si922178edj.625.2023.12.15.09.16.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 09:16:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1376-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Z1v8qLCV; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-1376-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1376-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 591791F256DB for ; Fri, 15 Dec 2023 17:16:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8564A6ABA8; Fri, 15 Dec 2023 17:10:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Z1v8qLCV"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="/c5A367j" X-Original-To: linux-kernel@vger.kernel.org Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 0FE3045BFF; Fri, 15 Dec 2023 17:10:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1702660235; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9YY938P41v7tgAkEsD/QoBSvsRcX+2kJhvYsQnrL6Aw=; b=Z1v8qLCV+RLJiu/rblvMSN7tDD7HRrKGxcYCmF6KGyzzTfhi6Q3gCjZ2PZbm0ZRBM/spAv ndtFcpvAwtAlsxq8x5U6GZitY00Ew6iA944vQ8aHBvXItZiqelQzXMTSwrjDPBOKuj8nkH 2iH46n9ufTFdXcQW8jctOXi+eYFnf0iYV5jmePGS2f2zJpj3RbKec60JnNyyiKiw6LeE+M RhEhBWk6qdox8FeyxSq+zREuIVlDQr0ndyST6W3yM0MMWWuDEub7tpHAKxhlVJSANoSltD axHeE592+spSZ/XKkMJkCk7lg4hnarGZb/7qz6bZV8m2T2NJ2VF00LLIcEw2/Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702660235; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9YY938P41v7tgAkEsD/QoBSvsRcX+2kJhvYsQnrL6Aw=; b=/c5A367jYpvBJ4WRTOzeEQIOJO45jcSIQ5G1gX8QMVs1c5Ii4wETrzynloABIM3EJhrHB8 +pkzwyAzbFNjYMAQ== To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: "David S. Miller" , Boqun Feng , Daniel Borkmann , Eric Dumazet , Frederic Weisbecker , Ingo Molnar , Jakub Kicinski , Paolo Abeni , Peter Zijlstra , Thomas Gleixner , Waiman Long , Will Deacon , Sebastian Andrzej Siewior Subject: [PATCH net-next 10/24] dev: Use nested-BH locking for softnet_data.process_queue. Date: Fri, 15 Dec 2023 18:07:29 +0100 Message-ID: <20231215171020.687342-11-bigeasy@linutronix.de> In-Reply-To: <20231215171020.687342-1-bigeasy@linutronix.de> References: <20231215171020.687342-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785369049417096516 X-GMAIL-MSGID: 1785369049417096516 softnet_data::process_queue is a per-CPU variable and relies on disabled BH for its locking. Without per-CPU locking in local_bh_disable() on PREEMPT_RT this data structure requires explicit locking. Add a local_lock_t to softnet_data and use local_lock_nested_bh() for locking of process_queue. This change adds only lockdep coverage and does not alter the functional behaviour for !PREEMPT_RT. Signed-off-by: Sebastian Andrzej Siewior --- include/linux/netdevice.h | 1 + net/core/dev.c | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 06436695c3679..88e27d3c39da2 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3238,6 +3238,7 @@ static inline bool dev_has_header(const struct net_device *dev) struct softnet_data { struct list_head poll_list; struct sk_buff_head process_queue; + local_lock_t process_queue_bh_lock; /* stats */ unsigned int processed; diff --git a/net/core/dev.c b/net/core/dev.c index 09232080843ee..5a0f6da7b3ae5 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -440,7 +440,9 @@ static RAW_NOTIFIER_HEAD(netdev_chain); * queue in the local softnet handler. */ -DEFINE_PER_CPU_ALIGNED(struct softnet_data, softnet_data); +DEFINE_PER_CPU_ALIGNED(struct softnet_data, softnet_data) = { + .process_queue_bh_lock = INIT_LOCAL_LOCK(process_queue_bh_lock), +}; EXPORT_PER_CPU_SYMBOL(softnet_data); #ifdef CONFIG_LOCKDEP @@ -5838,6 +5840,7 @@ static void flush_backlog(struct work_struct *work) } rps_unlock_irq_enable(sd); + local_lock_nested_bh(&softnet_data.process_queue_bh_lock); skb_queue_walk_safe(&sd->process_queue, skb, tmp) { if (skb->dev->reg_state == NETREG_UNREGISTERING) { __skb_unlink(skb, &sd->process_queue); @@ -5845,6 +5848,7 @@ static void flush_backlog(struct work_struct *work) input_queue_head_incr(sd); } } + local_unlock_nested_bh(&softnet_data.process_queue_bh_lock); local_bh_enable(); } @@ -5966,15 +5970,22 @@ static int process_backlog(struct napi_struct *napi, int quota) while (again) { struct sk_buff *skb; + local_lock_nested_bh(&softnet_data.process_queue_bh_lock); while ((skb = __skb_dequeue(&sd->process_queue))) { + local_unlock_nested_bh(&softnet_data.process_queue_bh_lock); rcu_read_lock(); __netif_receive_skb(skb); rcu_read_unlock(); + + local_lock_nested_bh(&softnet_data.process_queue_bh_lock); input_queue_head_incr(sd); - if (++work >= quota) + if (++work >= quota) { + local_unlock_nested_bh(&softnet_data.process_queue_bh_lock); return work; + } } + local_unlock_nested_bh(&softnet_data.process_queue_bh_lock); rps_lock_irq_disable(sd); if (skb_queue_empty(&sd->input_pkt_queue)) { @@ -5989,8 +6000,10 @@ static int process_backlog(struct napi_struct *napi, int quota) napi->state = 0; again = false; } else { + local_lock_nested_bh(&softnet_data.process_queue_bh_lock); skb_queue_splice_tail_init(&sd->input_pkt_queue, &sd->process_queue); + local_unlock_nested_bh(&softnet_data.process_queue_bh_lock); } rps_unlock_irq_enable(sd); }