From patchwork Thu May 2 11:37:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13651634 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B0E16311D for ; Thu, 2 May 2024 11:37:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714649874; cv=none; b=ITbxtqu0eWyiBtCYLj9pEDajI8GNTgZngAO/IGQ0SXU6dAgwaWBmnd2tnWzBlxw8LVlAIv3qO0uNfBylhvERI1AtEoLchCS25lkzq1LY4Al0efK802WofwRi86A943+zcuy3UQUo3e/eT4rEQTfikHBaaIdnMtLt4bKllkSLoqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714649874; c=relaxed/simple; bh=xIHjocbgszmfyDtuurzXnAmYJn6QWsMg9/abCf2zLvg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bs2XygbqN83nEgZ1gSrRIU0/fdeXA3sfP2uVSijurz1auqrnNrBq/I/JJRjsi+0HbQDCNIyeagVx3Px1kB+Tb90qCKm/14CuUDvWeIBNo6/D6UoZZwVw/8C4Pw4+viPvQFAWWWE6ihdbZ7Koz6FiSNwGd65yTNsPFZOEgbBmlaU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WtWLQ1Lp; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WtWLQ1Lp" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de5a378a948so11173318276.2 for ; Thu, 02 May 2024 04:37:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714649872; x=1715254672; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=r8Dlb+nHCm5N75ex/YXHeeowj6Ag/bumdSsAcL2Icvc=; b=WtWLQ1LpImwKPHdc6cPqlHw4stVKffkAbeIaEkr+eovZZ/SU9eNqBuzyc1KRm+Liqy UE+u5HNDzZvI38ZXFzNIYwukVKyzMVPwdNvYZnx/wJBXX8mW4CIWLt/QIgs9aWqgPmnm WznODlWX3wka9Llong+Cy/fVAtmLkzWxCXaqK6gxwZYeQ2TPxHo0VYDZRz44hh5QShkV Vy7Z7ks1XURH4EYXaXmPEoM3bPTteZIf2DFoEQ63dWDw6LyzxQUwnSEEOfcFlxyxmdf4 Pu5QTZS5r/n9o15J8z01n5uc0NHrbAnXGMV8w2u2WBcgAsyERKCR3s8a3Kug17+0cgEM vZPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714649872; x=1715254672; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=r8Dlb+nHCm5N75ex/YXHeeowj6Ag/bumdSsAcL2Icvc=; b=MtLytctCT5YH9GOZ2p1ZVW1tyO7C+GK9sHpe/hZkHiqHkSUWub5A4P8L60UrIkclsd UKzoq3s78xV0hcKMLTeMIX0nhLXcICfwctcAkMX+OobU6LLI9rUyCsi1Mn5k9doZV7Da Btr8lkF+F/lYql8A4mjCcIzvZAL5JqFWT2L+qJ5jmj4INgikh8A5T1JuQlh6YcANNkpL 9yc50tfVhKCS4ovKgfU3dxcnimxvvDqqwBNVTyrFtTVf+OAlZKz0hLLC2OAAXzpANgZ7 Y8kxZWVKMkgfll9w1TIiuDoa9KsocxD1gfZVKGrUE5e4vHIkZwa++WX3eN7x1FJJonib fwZg== X-Gm-Message-State: AOJu0YyWLX7t/EDgrnvg3e5hKRLUD1bkLD3gUegTTsXyuQfJJXD0wRC2 3ME2AkPRx65PiYkqVkQHHT6zjOSpED/ItiSgLlp2i6+C6TRnLVJ1G2fgw6RUtFRIxiaAai29E20 pSXFQMNk8iA== X-Google-Smtp-Source: AGHT+IGossF5WzSymkRtVotSGLHzM5DzszNARnJ87o9rioyWIBAM6Usi2HCq3Bsec+RC5f4HXFrXkubI9HLlIw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:100d:b0:dce:30f5:6bc5 with SMTP id w13-20020a056902100d00b00dce30f56bc5mr611001ybt.4.1714649872115; Thu, 02 May 2024 04:37:52 -0700 (PDT) Date: Thu, 2 May 2024 11:37:47 +0000 In-Reply-To: <20240502113748.1622637-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240502113748.1622637-1-edumazet@google.com> X-Mailer: git-send-email 2.45.0.rc0.197.gbae5840b3b-goog Message-ID: <20240502113748.1622637-2-edumazet@google.com> Subject: [PATCH net-next 1/2] rtnetlink: change rtnl_stats_dump() return value From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Ido Schimmel , Jiri Pirko , Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org By returning 0 (or an error) instead of skb->len, we allow NLMSG_DONE to be appended to the current skb at the end of a dump, saving a couple of recvmsg() system calls. Signed-off-by: Eric Dumazet Reviewed-by: David Ahern --- net/core/rtnetlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 283e42f48af68504af193ed5763d4e0fcd667d99..88980c8bcf334079e2d19cbcfb3f10fc05e3c19b 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -6024,7 +6024,7 @@ static int rtnl_stats_dump(struct sk_buff *skb, struct netlink_callback *cb) cb->args[1] = idx; cb->args[0] = h; - return skb->len; + return err; } void rtnl_offload_xstats_notify(struct net_device *dev) From patchwork Thu May 2 11:37:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13651635 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97F06664DD for ; Thu, 2 May 2024 11:37:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714649876; cv=none; b=ElZiyoXt38T/ykDvO5fYUJR5ZDBK9VuYSIyuj2ngecxqj7eSlDXpLlUhq1w3OBz65K0Ot/DH0MOpoCZt84l224qrxofTom8i6RBv+scoVKGR1jD/0EnjOIBw54NzXAwjv99ICsD1iqkkL26OU7UPRzZDkeCZtJWP60AgQ4uxUFo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714649876; c=relaxed/simple; bh=jpUaNxwwT/shZg223A0GbgbWTEn+c7tYxFcKwYZ5BCY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=vDPxEo2Upc0QmwCQtc61/gx7dxjNTwdvP1auns/gEmOCnqyI8k+4Z9GpJGn6c2a8NC7M4VPmmTXCpkuRs8APAibHvTk4UUWFO/zaUoRAIJdacP1trC/pJ+fu3xpZOY8nU1Cp3fI7JTCHt4K1Lsm44YRPXBYKB4NYYH64pt4/XKY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=hfVoda4M; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hfVoda4M" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61e0c1f7169so9207387b3.0 for ; Thu, 02 May 2024 04:37:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714649873; x=1715254673; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=iOWS65CjuyWfP5oa7h+vEdFZ/FCeN21iOlDI8UKu3VE=; b=hfVoda4M0TOBKrICMXCOZ0pseoUYc2jQSk8kFz3j8xDjtYtnB1K7Y9MQIsNxTMD4X9 hMA6XyZZponHuvT9sjUJdWI96hgHxdic+ihRqdwCJMdzQlTWGC4xhpOwZmN/NKXLbajD iJ+274ooRw/LIjlDrcdecq1FJ1i8oewQG2i3fQVZ0a/xO2rfUCINrlLBY5CFw4vVYKqN N6bnxbmpD1mq3I29AGVzIWcvMteICeR916zBMdFmiZGGJ+9vKpPWL/FV8niQ9TtmJhzD EHAXrmXuh42bE7oSm2QVwB/VjivSltWliMOmW0DtHMQeIXenq4dw0G3RvtD8ZCM9fgPD JJaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714649873; x=1715254673; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iOWS65CjuyWfP5oa7h+vEdFZ/FCeN21iOlDI8UKu3VE=; b=Cudq8SuxOxmS4AMhupwKIPIgDA8Rdqkwbz+7l++vABZgbuCmcSr+O6Iyo3yF3qXENO eTbf/5YTj+eQM4eRDULc4WbPW5+kbVphbCkSlaX+3mIRHyL42yGPKqXImHk4e92p0AH2 TQFfCpF5v4+Z5h5IOYsEmjRNIKjv7OerGSX1ODs/VW1HuE3jO6CJ1T5X9DrkuYmYl8Sx zKAT9f+tS4FDXdmRUmpfnMLvl3gCnLRqMzvrhj09a11lGKxZrkCzs5py0k03m9rSO5Qc /TeP2LFDDAcazxwWBhAQqvHbg6n57ErP07hlWouSf5nuVTUdNnSs3GmpPhnAX206Wkvd eORA== X-Gm-Message-State: AOJu0YzcU2YVoMutWu30kA//3gMNWhvTP8iW8LVCdkmKw0dLIBy2/RJF qyWJStNEQmywY6O2HLLScPJHPHnlVZ8dk8XBG3KY3916i+G5BfsaO9141GWP24hA5udni3A98OP ZaOpirSog5A== X-Google-Smtp-Source: AGHT+IHIGtazm4EeudWZbLFK5YfvR5rKZJ3XKUm8YCJzxVyufTl5+1BGki9Oild36G2qQgsrISJLFe7R28rijg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:6642:0:b0:de5:dcb8:5c8a with SMTP id z2-20020a256642000000b00de5dcb85c8amr569454ybm.2.1714649873612; Thu, 02 May 2024 04:37:53 -0700 (PDT) Date: Thu, 2 May 2024 11:37:48 +0000 In-Reply-To: <20240502113748.1622637-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240502113748.1622637-1-edumazet@google.com> X-Mailer: git-send-email 2.45.0.rc0.197.gbae5840b3b-goog Message-ID: <20240502113748.1622637-3-edumazet@google.com> Subject: [PATCH net-next 2/2] rtnetlink: use for_each_netdev_dump() in rtnl_stats_dump() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Ido Schimmel , Jiri Pirko , Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Switch rtnl_stats_dump() to use for_each_netdev_dump() instead of net->dev_index_head[] hash table. This makes the code much easier to read, and fixes scalability issues. Signed-off-by: Eric Dumazet Reviewed-by: David Ahern --- net/core/rtnetlink.c | 59 +++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 88980c8bcf334079e2d19cbcfb3f10fc05e3c19b..28050e53ecb025f8d207f4b38805fb108799ca65 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -5961,19 +5961,17 @@ static int rtnl_stats_get(struct sk_buff *skb, struct nlmsghdr *nlh, static int rtnl_stats_dump(struct sk_buff *skb, struct netlink_callback *cb) { struct netlink_ext_ack *extack = cb->extack; - int h, s_h, err, s_idx, s_idxattr, s_prividx; struct rtnl_stats_dump_filters filters; struct net *net = sock_net(skb->sk); unsigned int flags = NLM_F_MULTI; struct if_stats_msg *ifsm; - struct hlist_head *head; + struct { + unsigned long ifindex; + int idxattr; + int prividx; + } *ctx = (void *)cb->ctx; struct net_device *dev; - int idx = 0; - - s_h = cb->args[0]; - s_idx = cb->args[1]; - s_idxattr = cb->args[2]; - s_prividx = cb->args[3]; + int err; cb->seq = net->dev_base_seq; @@ -5992,37 +5990,24 @@ static int rtnl_stats_dump(struct sk_buff *skb, struct netlink_callback *cb) if (err) return err; - for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) { - idx = 0; - head = &net->dev_index_head[h]; - hlist_for_each_entry(dev, head, index_hlist) { - if (idx < s_idx) - goto cont; - err = rtnl_fill_statsinfo(skb, dev, RTM_NEWSTATS, - NETLINK_CB(cb->skb).portid, - cb->nlh->nlmsg_seq, 0, - flags, &filters, - &s_idxattr, &s_prividx, - extack); - /* If we ran out of room on the first message, - * we're in trouble - */ - WARN_ON((err == -EMSGSIZE) && (skb->len == 0)); + for_each_netdev_dump(net, dev, ctx->ifindex) { + err = rtnl_fill_statsinfo(skb, dev, RTM_NEWSTATS, + NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, 0, + flags, &filters, + &ctx->idxattr, &ctx->prividx, + extack); + /* If we ran out of room on the first message, + * we're in trouble. + */ + WARN_ON((err == -EMSGSIZE) && (skb->len == 0)); - if (err < 0) - goto out; - s_prividx = 0; - s_idxattr = 0; - nl_dump_check_consistent(cb, nlmsg_hdr(skb)); -cont: - idx++; - } + if (err < 0) + break; + ctx->prividx = 0; + ctx->idxattr = 0; + nl_dump_check_consistent(cb, nlmsg_hdr(skb)); } -out: - cb->args[3] = s_prividx; - cb->args[2] = s_idxattr; - cb->args[1] = idx; - cb->args[0] = h; return err; }