From patchwork Wed Dec 6 16:44:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13482028 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mojatatu-com.20230601.gappssmtp.com header.i=@mojatatu-com.20230601.gappssmtp.com header.b="x4pwIHGn" Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA9FCD3 for ; Wed, 6 Dec 2023 08:44:42 -0800 (PST) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1d048c171d6so51167155ad.1 for ; Wed, 06 Dec 2023 08:44:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1701881082; x=1702485882; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i1n+hUHrQ3jdYpTFXY4hRVwRAm0ea6knPIuI4zsgLEY=; b=x4pwIHGneJt6WLef0XEWObvXwpjW93klDrKv8nw7M7ezG9mulRA4OBYQ/jyZmk2fl0 ZXGE1Bb/gstIX5V+3Qo99mDjMyGozXQNzUWqclaL39sO2Qir7m4WSFE7C1ufKotZkq3/ qQtOcVnBRGAECNbLeiJ0WOoPkzCu/X2lXAV2gTkI2yg4FkYC5yxUjs/AAjbYTeEdxgUC h0CrFCY5vnxd6JR8CaoSf4GagGMPzeAesdCjjcd5AIK75AKr+sshfnDLiPq5Rz1rLko0 LyMCVJl/I3WO8JuOBWpfrxY8JMUsQfo7Raiq3WW6RduSwzX2G8daWvey+IjhaXCxMDK2 H3Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701881082; x=1702485882; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i1n+hUHrQ3jdYpTFXY4hRVwRAm0ea6knPIuI4zsgLEY=; b=OT4NabsZexY1CuFLcrpTgk+Vj7h0IaGhAX4hRtYgCJSzLxXlzPaF9W1Wz8smdc5orn TXJ4s3CCjHDX46j6rf4icy2/f9pZnzDZHBfAyKFxM799eC0VQD0saxB8KLk4LWKRBI6F XyTDFbndqDlATaKfoeujYx0jI3LeseWXPliNzd2tPHl2YhTgw0/x2LueC25uLvk6TN0z VFFq4qayjfCXdNn+y/oQejruFTVGM2lwr6Dsjz6M3gfReOYFYKpfgUHwWQ3V9dlPK1iI N2hs2juB+Xu3VJtK6vgD/6yyVijUgpDeZ7uHcsMAm4/iayw9Uth1rDmO4yixwm9EoKY0 h3rQ== X-Gm-Message-State: AOJu0YxQBhvNGXfAzRiM/pSslQ+s07q6nAabwZOkqfhbV2hvscsOEn+L CciWex0efJPR8bTr1eU2iaW6r2iiZ/dbjU7W76Y= X-Google-Smtp-Source: AGHT+IGZ/SOLjkZ3FCy4v/KN/ZPXD0BaC6UPAJ0G10qWDS0CVww7VfaNlQI4NByc/By8a9NHnyMAhw== X-Received: by 2002:a17:902:e882:b0:1d0:b3f5:c318 with SMTP id w2-20020a170902e88200b001d0b3f5c318mr1292638plg.106.1701881081988; Wed, 06 Dec 2023 08:44:41 -0800 (PST) Received: from rogue-one.tail33bf8.ts.net ([201.17.86.134]) by smtp.gmail.com with ESMTPSA id g1-20020a170902740100b001cfc3f73920sm36719pll.227.2023.12.06.08.44.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 08:44:41 -0800 (PST) From: Pedro Tammela To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, marcelo.leitner@gmail.com, vladbu@nvidia.com, Jiri Pirko , Victor Nogueira , Pedro Tammela Subject: [PATCH net-next v3 1/5] rtnl: add helper to check if rtnl group has listeners Date: Wed, 6 Dec 2023 13:44:12 -0300 Message-Id: <20231206164416.543503-2-pctammela@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231206164416.543503-1-pctammela@mojatatu.com> References: <20231206164416.543503-1-pctammela@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jamal Hadi Salim As of today, rtnl code creates a new skb and unconditionally fills and broadcasts it to the relevant group. For most operations this is okay and doesn't waste resources in general. When operations are done without the rtnl_lock, as in tc-flower, such skb allocation, message fill and no-op broadcasting can happen in all cores of the system, which contributes to system pressure and wastes precious cpu cycles when no one will receive the built message. Introduce this helper so rtnetlink operations can simply check if someone is listening and then proceed if necessary. Reviewed-by: Jiri Pirko Signed-off-by: Jamal Hadi Salim Signed-off-by: Victor Nogueira Signed-off-by: Pedro Tammela Reviewed-by: Simon Horman --- include/linux/rtnetlink.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h index 3d6cf306cd55..a7d757e96c55 100644 --- a/include/linux/rtnetlink.h +++ b/include/linux/rtnetlink.h @@ -130,4 +130,11 @@ extern int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, extern void rtnl_offload_xstats_notify(struct net_device *dev); +static inline int rtnl_has_listeners(const struct net *net, u32 group) +{ + struct sock *rtnl = net->rtnl; + + return netlink_has_listeners(rtnl, group); +} + #endif /* __LINUX_RTNETLINK_H */ From patchwork Wed Dec 6 16:44:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13482029 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mojatatu-com.20230601.gappssmtp.com header.i=@mojatatu-com.20230601.gappssmtp.com header.b="afAaNNSC" Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EC89FA for ; Wed, 6 Dec 2023 08:44:47 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1d0521554ddso38042485ad.2 for ; Wed, 06 Dec 2023 08:44:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1701881086; x=1702485886; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G7VceqgJeN9nR+D8xWxcQGhtI4oSAvnc7Keqe8LqyhQ=; b=afAaNNSCUPWgAdLdLA16HK5w+qxBYeOMp+wPixATkOGpRAHew2d2XsDPgtkYIrqsvD PAU0lNFp4dWxsFfeQnW4y3jIKIjcALBNbSjRuzhhCgLNiXpPrsaI04gIFacsclCS5qhY PzemMkuZMNLuM7nKcX8whA/6m4JvVlUOZPhhLkQoB7Op8pcxW1wg+AGFYnebxdgtBuxs c686jqIoItXmIWX+DWK4AKTHCJGF7hQuCvA0CoYft3qwJ3t3OHd6cfLZrqe6VdjUSKCP A+cmELE3u4SBJ2vz0rHiivRvNx2vu8InC99R77imQs/bWB0gf8DP6Wp4HgCLPezK2mKw FWxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701881086; x=1702485886; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G7VceqgJeN9nR+D8xWxcQGhtI4oSAvnc7Keqe8LqyhQ=; b=N8cYgrGGwiYmnrSyW2/n+uaCTBZ3+P+V/mI3dmCMqnnzfuI1gehryA+D3nvOLlYpy8 QuC4JzmQIALahsCd6pVH5LKLl6Ces7u1auyQmRYiuxDzY96Pw63UUcr55P3+SXGgp52Q WhWN7Te1y/m6zLzEFLTEdqXzknS6iM3zOVUhhc+OKaKpkj9LH8Crvssvy41XB2OQl8u8 svPaVUhhccXtRmVsgtn1H6Nis7+Jb0TQHy4QFtY0sHNkN8bccKtHNDCnaldTenf7vhN4 ClNhEmxzrWpshPRBjSTRDaAXDNn1GBsrLmsbwQY3Pca6vJwgHIsxL4LXZCQ3UKzIrPDh Ykuw== X-Gm-Message-State: AOJu0YxxnbIYQeeKkAFx3f0nG+FpRkYWarkJe1m0zdJYZkfWoxCy+uw/ Lxb44Qg/uWdTkgsHcJVuP0sex8sI4tfjWsKR2h8= X-Google-Smtp-Source: AGHT+IGbpUOyggOPeTVQ39UeACFhf6IiKLNqSE0Bjy4KObEZryI6ey00sQUOPCpAUPu9qr9E98/cpw== X-Received: by 2002:a17:902:d4c8:b0:1cc:32df:40e7 with SMTP id o8-20020a170902d4c800b001cc32df40e7mr974981plg.66.1701881086577; Wed, 06 Dec 2023 08:44:46 -0800 (PST) Received: from rogue-one.tail33bf8.ts.net ([201.17.86.134]) by smtp.gmail.com with ESMTPSA id g1-20020a170902740100b001cfc3f73920sm36719pll.227.2023.12.06.08.44.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 08:44:46 -0800 (PST) From: Pedro Tammela To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, marcelo.leitner@gmail.com, vladbu@nvidia.com, Victor Nogueira , Jiri Pirko , Pedro Tammela Subject: [PATCH net-next v3 2/5] rtnl: add helper to check if a notification is needed Date: Wed, 6 Dec 2023 13:44:13 -0300 Message-Id: <20231206164416.543503-3-pctammela@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231206164416.543503-1-pctammela@mojatatu.com> References: <20231206164416.543503-1-pctammela@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Victor Nogueira Building on the rtnl_has_listeners helper, add the rtnl_notify_needed helper to check if we can bail out early in the notification routines. Reviewed-by: Jiri Pirko Signed-off-by: Victor Nogueira Signed-off-by: Pedro Tammela Reviewed-by: Simon Horman --- include/linux/rtnetlink.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h index a7d757e96c55..0cbbbded0331 100644 --- a/include/linux/rtnetlink.h +++ b/include/linux/rtnetlink.h @@ -137,4 +137,19 @@ static inline int rtnl_has_listeners(const struct net *net, u32 group) return netlink_has_listeners(rtnl, group); } +/** + * rtnl_notify_needed - check if notification is needed + * @net: Pointer to the net namespace + * @nlflags: netlink ingress message flags + * @group: rtnl group + * + * Based on the ingress message flags and rtnl group, returns true + * if a notification is needed, false otherwise. + */ +static inline bool +rtnl_notify_needed(const struct net *net, u16 nlflags, u32 group) +{ + return (nlflags & NLM_F_ECHO) || rtnl_has_listeners(net, group); +} + #endif /* __LINUX_RTNETLINK_H */ From patchwork Wed Dec 6 16:44:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13482030 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mojatatu-com.20230601.gappssmtp.com header.i=@mojatatu-com.20230601.gappssmtp.com header.b="VNutshcp" Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0C30FA for ; Wed, 6 Dec 2023 08:44:51 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1cfc9c4acb6so36577775ad.0 for ; Wed, 06 Dec 2023 08:44:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1701881091; x=1702485891; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q50gZgjqvdcFJYKqj0O7rtzQrOsxGSudN/5LRmofnmw=; b=VNutshcppz5Nn1McpesvlaNZcj/e0ywDZmr8RWqDlNIwqIWWFyx+IPUbDhuOG1LJvc aF+A4obDMt6FLuMTf6xUmxjaA+6A9NKdifNv3zYTVkYcLSI55s9MOD2zcQy99rt74WgK tTHqK3UEsu5VGgUCj/6fcJckZ6zUET3Apv+W6pHdb/MwkYm9+J/30PKSmi+TYBlO7nM5 cTh5Ifd7ONBYrGOFgKMlcfx0p4q2d4YIzFTF6E8jr5WPOPWv/lqh+ci76EXiIxnsHRQq GzkZ8UDT/Mqb5aJMuG8JRoRqMjwTaUXoe4J+zXE1R08hYTyGSduz1toacVl/JpwkSo0f P2pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701881091; x=1702485891; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q50gZgjqvdcFJYKqj0O7rtzQrOsxGSudN/5LRmofnmw=; b=aKa/hitMKLIXf0LBoJwzGYFAOUqSQU1bckIH4sWdzMGV5UY4Fl9I3mFwbzuqmOzexN SMT0okHP+m1PGH07iUyG0rwdUHaxsCcjGssIFSUbBIO72UbOamENmGpGVchnCv8vuFYo 3PuEmumSHWt8M2YKfYFvSw+rbJsozMGpQXT6DpAbESqUZeGPmAaAIrO2PEZ3LJCawz5N o8pzXrkCoZftAizXlIn3Nq8VWCk2YTHoFqaO5+SftzuyyDA3ntRKFklhSeFsC5fmXSeu eFqmtq+8X8LgrlFlFoWqp88SBrBwFyK23jwahNf/Vqg42FXxq3fQw0VnXm7aoo2TY/Q/ E/qQ== X-Gm-Message-State: AOJu0Yww33Hv/uQJqQzwrq8ZPRHB4UmdHdaXWpc2k3oM/CUjVwWjGKV9 pHT8G0PVaCK0ObxkiRXr2vnHRsyT7878MEZ6BgY= X-Google-Smtp-Source: AGHT+IHFxJwMqYGvZaD0RrIkn3oqW0lBit4RMEOFaL426QuxWZx45P8U3X8nHEAl9lxBeqZIG8xDJQ== X-Received: by 2002:a17:902:d48a:b0:1d0:6ffd:6e7e with SMTP id c10-20020a170902d48a00b001d06ffd6e7emr1135046plg.118.1701881090945; Wed, 06 Dec 2023 08:44:50 -0800 (PST) Received: from rogue-one.tail33bf8.ts.net ([201.17.86.134]) by smtp.gmail.com with ESMTPSA id g1-20020a170902740100b001cfc3f73920sm36719pll.227.2023.12.06.08.44.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 08:44:50 -0800 (PST) From: Pedro Tammela To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, marcelo.leitner@gmail.com, vladbu@nvidia.com, Pedro Tammela , Jiri Pirko Subject: [PATCH net-next v3 3/5] rtnl: add helper to send if skb is not null Date: Wed, 6 Dec 2023 13:44:14 -0300 Message-Id: <20231206164416.543503-4-pctammela@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231206164416.543503-1-pctammela@mojatatu.com> References: <20231206164416.543503-1-pctammela@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org This is a convenience helper for routines handling conditional rtnl events, that is code that might send a notification depending on rtnl_has_listeners/rtnl_notify_needed. Instead of: if (skb) rtnetlink_send(...) Use: rtnetlink_maybe_send(...) Reviewed-by: Jiri Pirko Signed-off-by: Pedro Tammela Reviewed-by: Simon Horman --- include/linux/rtnetlink.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h index 0cbbbded0331..6a8543b34e2c 100644 --- a/include/linux/rtnetlink.h +++ b/include/linux/rtnetlink.h @@ -10,6 +10,13 @@ #include extern int rtnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, u32 group, int echo); + +static inline int rtnetlink_maybe_send(struct sk_buff *skb, struct net *net, + u32 pid, u32 group, int echo) +{ + return !skb ? 0 : rtnetlink_send(skb, net, pid, group, echo); +} + extern int rtnl_unicast(struct sk_buff *skb, struct net *net, u32 pid); extern void rtnl_notify(struct sk_buff *skb, struct net *net, u32 pid, u32 group, const struct nlmsghdr *nlh, gfp_t flags); From patchwork Wed Dec 6 16:44:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13482031 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mojatatu-com.20230601.gappssmtp.com header.i=@mojatatu-com.20230601.gappssmtp.com header.b="WRJaLj7V" Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C684DB2 for ; Wed, 6 Dec 2023 08:44:55 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1d04c097e34so192255ad.0 for ; Wed, 06 Dec 2023 08:44:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1701881095; x=1702485895; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o9UQsQtqVfjzD1Fk+nJ3moPqgMdm4wuaaVHtwNrfaOA=; b=WRJaLj7VXymbXxGiiLtlS3Vq2+8O98sIuRDV3uDhfiK0jWqo2RFTPhwjQi/nZXrPwK DY4BMfxo5joDiRfYKwPNI0BCjXFVJVABy8Vsy86SS2I+NaVcZHWPKaWz9v9iQANHhQWs Qz9GHhD9pvX+uweSgf8nGuTXK0MJqKR0BkqydfIuVMhlODQd4qLjXPYmk+ArNBxcz3WK evbE3fFt8JaaC5iZs02lK+tkQg4Dg93lrF1mSosFHGNf/ZJsOYLkf0PC7CuUi0G4Bfo4 97LS8MRWbxvM8NadSkBQ+tkJtXrFg2kMFTMgfwZkU36MgyONWkynWQgG1EgiFUiuzJ23 L5Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701881095; x=1702485895; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o9UQsQtqVfjzD1Fk+nJ3moPqgMdm4wuaaVHtwNrfaOA=; b=L5lUtG6zWa+qTZgtfS62rImd1hviUTJSIFU4iApXYbPw7KOi7joPe6+y2xKm06HAg2 t+jHr44AiEipIgBIKfHtB6IHPIHEsSSskEtvUZvzNXpP1K/wGlVgxlnVKb9IUgYvmLpI AnDHI54c48LDR6HkSZj5qlLxejjUE8RRbqNVVd3mq/Rlff8J/rVuBZo1i22OJNhDqNWN K8xSFoFZHL8EIWTseeZyHg119LBXp567+RTBaM8uZ3Tr5IuRpw1fRZcmgcV/1tozbOZQ HwDuyjs+6XHaJE2dNG6Jbt7P08Bl2L3anSX5Wlr+SHscv5CXKkIOrvlx11wNTgNRYLdf 0VVw== X-Gm-Message-State: AOJu0YwvCEBXi209CZHl6QzbxI5LFW9T/M1bPTeHW22UzWtGlwgA423C grQV51SK6fY4w/ciAcgKQkwwB2tDvaTZfvFZ7R0= X-Google-Smtp-Source: AGHT+IHaoMM7ydm71e3XNrRvikFKgDcIqvzNcmPAmC4YeKEqI3xZsJPCgi5M1ZecgUyXP8+6l4+ccw== X-Received: by 2002:a17:903:200d:b0:1d0:700b:3f71 with SMTP id s13-20020a170903200d00b001d0700b3f71mr3686958pla.43.1701881094981; Wed, 06 Dec 2023 08:44:54 -0800 (PST) Received: from rogue-one.tail33bf8.ts.net ([201.17.86.134]) by smtp.gmail.com with ESMTPSA id g1-20020a170902740100b001cfc3f73920sm36719pll.227.2023.12.06.08.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 08:44:54 -0800 (PST) From: Pedro Tammela To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, marcelo.leitner@gmail.com, vladbu@nvidia.com, Pedro Tammela Subject: [PATCH net-next v3 4/5] net/sched: act_api: conditional notification of events Date: Wed, 6 Dec 2023 13:44:15 -0300 Message-Id: <20231206164416.543503-5-pctammela@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231206164416.543503-1-pctammela@mojatatu.com> References: <20231206164416.543503-1-pctammela@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org As of today tc-action events are unconditionally built and sent to RTNLGRP_TC. As with the introduction of rtnl_notify_needed we can check before-hand if they are really needed. Signed-off-by: Pedro Tammela --- net/sched/act_api.c | 105 ++++++++++++++++++++++++++++++++------------ 1 file changed, 76 insertions(+), 29 deletions(-) diff --git a/net/sched/act_api.c b/net/sched/act_api.c index abec5c45b5a4..c15c2083ac84 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -1785,31 +1785,45 @@ static int tcf_action_delete(struct net *net, struct tc_action *actions[]) return 0; } -static int -tcf_reoffload_del_notify(struct net *net, struct tc_action *action) +static struct sk_buff *tcf_reoffload_del_notify_msg(struct net *net, + struct tc_action *action) { size_t attr_size = tcf_action_fill_size(action); struct tc_action *actions[TCA_ACT_MAX_PRIO] = { [0] = action, }; - const struct tc_action_ops *ops = action->ops; struct sk_buff *skb; - int ret; - skb = alloc_skb(attr_size <= NLMSG_GOODSIZE ? NLMSG_GOODSIZE : attr_size, - GFP_KERNEL); + skb = alloc_skb(max(attr_size, NLMSG_GOODSIZE), GFP_KERNEL); if (!skb) - return -ENOBUFS; + return ERR_PTR(-ENOBUFS); if (tca_get_fill(skb, actions, 0, 0, 0, RTM_DELACTION, 0, 1, NULL) <= 0) { kfree_skb(skb); - return -EINVAL; + return ERR_PTR(-EINVAL); } + return skb; +} + +static int tcf_reoffload_del_notify(struct net *net, struct tc_action *action) +{ + const struct tc_action_ops *ops = action->ops; + struct sk_buff *skb = NULL; + int ret; + + if (!rtnl_notify_needed(net, 0, RTNLGRP_TC)) + goto skip_msg; + + skb = tcf_reoffload_del_notify_msg(net, action); + if (IS_ERR(skb)) + return PTR_ERR(skb); + +skip_msg: ret = tcf_idr_release_unsafe(action); if (ret == ACT_P_DELETED) { module_put(ops->owner); - ret = rtnetlink_send(skb, net, 0, RTNLGRP_TC, 0); + ret = rtnetlink_maybe_send(skb, net, 0, RTNLGRP_TC, 0); } else { kfree_skb(skb); } @@ -1875,25 +1889,42 @@ int tcf_action_reoffload_cb(flow_indr_block_bind_cb_t *cb, return 0; } -static int -tcf_del_notify(struct net *net, struct nlmsghdr *n, struct tc_action *actions[], - u32 portid, size_t attr_size, struct netlink_ext_ack *extack) +static struct sk_buff *tcf_del_notify_msg(struct net *net, struct nlmsghdr *n, + struct tc_action *actions[], + u32 portid, size_t attr_size, + struct netlink_ext_ack *extack) { - int ret; struct sk_buff *skb; - skb = alloc_skb(attr_size <= NLMSG_GOODSIZE ? NLMSG_GOODSIZE : attr_size, - GFP_KERNEL); + skb = alloc_skb(max(attr_size, NLMSG_GOODSIZE), GFP_KERNEL); if (!skb) - return -ENOBUFS; + return ERR_PTR(-ENOBUFS); if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, 0, RTM_DELACTION, 0, 2, extack) <= 0) { NL_SET_ERR_MSG(extack, "Failed to fill netlink TC action attributes"); kfree_skb(skb); - return -EINVAL; + return ERR_PTR(-EINVAL); } + return skb; +} + +static int tcf_del_notify(struct net *net, struct nlmsghdr *n, + struct tc_action *actions[], u32 portid, + size_t attr_size, struct netlink_ext_ack *extack) +{ + struct sk_buff *skb = NULL; + int ret; + + if (!rtnl_notify_needed(net, n->nlmsg_flags, RTNLGRP_TC)) + goto skip_msg; + + skb = tcf_del_notify_msg(net, n, actions, portid, attr_size, extack); + if (IS_ERR(skb)) + return PTR_ERR(skb); + +skip_msg: /* now do the delete */ ret = tcf_action_delete(net, actions); if (ret < 0) { @@ -1902,9 +1933,8 @@ tcf_del_notify(struct net *net, struct nlmsghdr *n, struct tc_action *actions[], return ret; } - ret = rtnetlink_send(skb, net, portid, RTNLGRP_TC, - n->nlmsg_flags & NLM_F_ECHO); - return ret; + return rtnetlink_maybe_send(skb, net, portid, RTNLGRP_TC, + n->nlmsg_flags & NLM_F_ECHO); } static int @@ -1955,26 +1985,43 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n, return ret; } -static int -tcf_add_notify(struct net *net, struct nlmsghdr *n, struct tc_action *actions[], - u32 portid, size_t attr_size, struct netlink_ext_ack *extack) +static struct sk_buff *tcf_add_notify_msg(struct net *net, struct nlmsghdr *n, + struct tc_action *actions[], + u32 portid, size_t attr_size, + struct netlink_ext_ack *extack) { struct sk_buff *skb; - skb = alloc_skb(attr_size <= NLMSG_GOODSIZE ? NLMSG_GOODSIZE : attr_size, - GFP_KERNEL); + skb = alloc_skb(max(attr_size, NLMSG_GOODSIZE), GFP_KERNEL); if (!skb) - return -ENOBUFS; + return ERR_PTR(-ENOBUFS); if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, n->nlmsg_flags, RTM_NEWACTION, 0, 0, extack) <= 0) { NL_SET_ERR_MSG(extack, "Failed to fill netlink attributes while adding TC action"); kfree_skb(skb); - return -EINVAL; + return ERR_PTR(-EINVAL); } - return rtnetlink_send(skb, net, portid, RTNLGRP_TC, - n->nlmsg_flags & NLM_F_ECHO); + return skb; +} + +static int tcf_add_notify(struct net *net, struct nlmsghdr *n, + struct tc_action *actions[], u32 portid, + size_t attr_size, struct netlink_ext_ack *extack) +{ + struct sk_buff *skb = NULL; + + if (!rtnl_notify_needed(net, n->nlmsg_flags, RTNLGRP_TC)) + goto skip_msg; + + skb = tcf_add_notify_msg(net, n, actions, portid, attr_size, extack); + if (IS_ERR(skb)) + return PTR_ERR(skb); + +skip_msg: + return rtnetlink_maybe_send(skb, net, portid, RTNLGRP_TC, + n->nlmsg_flags & NLM_F_ECHO); } static int tcf_action_add(struct net *net, struct nlattr *nla, From patchwork Wed Dec 6 16:44:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13482032 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mojatatu-com.20230601.gappssmtp.com header.i=@mojatatu-com.20230601.gappssmtp.com header.b="RX29IpPS" Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02BD7B2 for ; Wed, 6 Dec 2023 08:45:00 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1d0521554ddso38044185ad.2 for ; Wed, 06 Dec 2023 08:44:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1701881099; x=1702485899; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UpDVBWMk5yuVPMRwRZ/2oDezmX4qoKdeeTDdK45wJTg=; b=RX29IpPSrDQHHB4NdJec1i8+xhFdNnbaVZyn9QkdDLevG+pjswY49m6+ywCFfq97W1 xM0d7jw9jjO+SIduB0ziyD6U80/j+0ionypQmj4FBLNDaxw8dw+0Jd3CjdkT3zLindd2 gPz7/MOyVatcuPiUhPVNSnxirjg03BYtJppPwDadNmYi1b6y+ZULKE9l1CyeG/QjiLFS Q1LInjYR1MMR50MD9p+gM6rGm3CV/Hc9xHaOmaEXWSktrNaUKYoS1/wAxUpvZTcoRyQn U1LW5E2/YWv7UkW93dvLIYDmncNfdpdxZQp7iOlfZVZNJPo0d/lmM1MaJjjGIlFifwKt emZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701881099; x=1702485899; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UpDVBWMk5yuVPMRwRZ/2oDezmX4qoKdeeTDdK45wJTg=; b=dzPHwIBrTzB570dbu41rcM9WvEeIf5zlzIcYwgvZT65tvmiHIpC4vhCFj3FTiZ8W/k WNjWCgqf8qZO0YpL8JAIm7kUqVATCvyVUcAd5TatgrDsswDzC4ERkh90b0QqgiZ7zN2M 1ezcF04ZncC1EIP76tfc06rLQU9En8joOUOlR8nGsLgNQ6Hq3gsSpAZf8+DAjKctPcHj AZnfjRGUzwclFv00L09AY8CvZt7H3riEs6OkCCFQMoRpvQgzoofeeh/ISbYSDHMLRWP+ 2GXqd/wvsmaqYPxHB5YYFz7oXpjLS/WCS540Fx4jKS5K3QpJ1yjdLPeBqthsrGs+ot+6 bQ5w== X-Gm-Message-State: AOJu0YynWfrLEaKzwGVNOdIpnQBWJkIRsfda6oJftu4TJ6e4eyWEoUAd IcduK8RMq81zzD7ZHUbML9aWYhLQam42Q/bEHa0= X-Google-Smtp-Source: AGHT+IFAy1DR1SGkHR327ZeNsXgIP6Cj4Nl0JI0TQQF4SHW7LFiBg49YWnIIixg+t0faqr+R8sLo0g== X-Received: by 2002:a17:902:d4c5:b0:1d0:c5f8:22d8 with SMTP id o5-20020a170902d4c500b001d0c5f822d8mr972012plg.37.1701881099255; Wed, 06 Dec 2023 08:44:59 -0800 (PST) Received: from rogue-one.tail33bf8.ts.net ([201.17.86.134]) by smtp.gmail.com with ESMTPSA id g1-20020a170902740100b001cfc3f73920sm36719pll.227.2023.12.06.08.44.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 08:44:59 -0800 (PST) From: Pedro Tammela To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, marcelo.leitner@gmail.com, vladbu@nvidia.com, Pedro Tammela , Jiri Pirko Subject: [PATCH net-next v3 5/5] net/sched: cls_api: conditional notification of events Date: Wed, 6 Dec 2023 13:44:16 -0300 Message-Id: <20231206164416.543503-6-pctammela@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231206164416.543503-1-pctammela@mojatatu.com> References: <20231206164416.543503-1-pctammela@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org As of today tc-filter/chain events are unconditionally built and sent to RTNLGRP_TC. As with the introduction of rtnl_notify_needed we can check before-hand if they are really needed. This will help to alleviate system pressure when filters are concurrently added without the rtnl lock as in tc-flower. Reviewed-by: Jiri Pirko Signed-off-by: Pedro Tammela Reviewed-by: Simon Horman --- net/sched/cls_api.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index 1976bd163986..123185907ebd 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -2053,6 +2053,9 @@ static int tfilter_notify(struct net *net, struct sk_buff *oskb, u32 portid = oskb ? NETLINK_CB(oskb).portid : 0; int err = 0; + if (!unicast && !rtnl_notify_needed(net, n->nlmsg_flags, RTNLGRP_TC)) + return 0; + skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); if (!skb) return -ENOBUFS; @@ -2082,6 +2085,9 @@ static int tfilter_del_notify(struct net *net, struct sk_buff *oskb, u32 portid = oskb ? NETLINK_CB(oskb).portid : 0; int err; + if (!unicast && !rtnl_notify_needed(net, n->nlmsg_flags, RTNLGRP_TC)) + return tp->ops->delete(tp, fh, last, rtnl_held, extack); + skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); if (!skb) return -ENOBUFS; @@ -2906,6 +2912,9 @@ static int tc_chain_notify(struct tcf_chain *chain, struct sk_buff *oskb, struct sk_buff *skb; int err = 0; + if (!unicast && !rtnl_notify_needed(net, flags, RTNLGRP_TC)) + return 0; + skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); if (!skb) return -ENOBUFS; @@ -2935,6 +2944,9 @@ static int tc_chain_notify_delete(const struct tcf_proto_ops *tmplt_ops, struct net *net = block->net; struct sk_buff *skb; + if (!unicast && !rtnl_notify_needed(net, flags, RTNLGRP_TC)) + return 0; + skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); if (!skb) return -ENOBUFS;