From patchwork Mon Dec 4 20:39:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13479081 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="KlNZO61W" Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B7EB6A65 for ; Mon, 4 Dec 2023 12:39:40 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1d0b0334ffcso9459055ad.1 for ; Mon, 04 Dec 2023 12:39:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1701722380; x=1702327180; 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=8DGOijOKJdOqvHyhZyvR9Q5yxUXm8+4SFnahsPvs8Go=; b=KlNZO61WYXVMjRwek0dln31VZ/510Z3o1YWc5xMgjbm7o1nDuMdz/MH1rht4psdy/x 6zgDI8XCMsdBhSXHq8b797c+XvdMe8Ee+x9BJPfTrZWCg7ZEjTdYM4804FPd7NPf/5DS khXrTlB1VZpOkMNP08kG9PqGtCzcFOoiZJtgBj/0KENjU1jbSmwPrOtCu0BQC9uNARAg DH7f7m2yeV/SoGjDGmzNJnswcV3Bu/aGt1AGpLGjMcx/bxeNBOs5SW7MInLuWbFEM+Sg 69ojLciwWDOXRAY7HNSwllQUVvYq5vm5kl6/0D0sJVOqXCTy/w8r0tCPX9WYe9rn7M5o spIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701722380; x=1702327180; 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=8DGOijOKJdOqvHyhZyvR9Q5yxUXm8+4SFnahsPvs8Go=; b=bG+ldR11SrMWmZ7Dkkl1MXJl9tb0w3IxqB0FAOSPJ89wdA3kQM1Tg0ESX6ArDSBuZ7 jI2An3/tL+BSqkF2siw3puw0pFyh486ZSSI9xfpHdGsAJqoJaHr8bxCPNCzvIUheZ8Dn PIrsimf1AjMEEfvkfeCT9CAvCLOm3t06DCh21UoyTptNA5VzJfHqEDxIGQ+fM5ugwfYo 5TDG5JqmyJfKSG34vW4zKKQw3IXh9eiPZjdvBdsxmJUrHPB6x9Wym+oOKVrhZ3Z9KiMs m8lzrgi3+V9B3PyY782r+ilTJENNba5Sl68BSoc6B+g40emkDfx9O9jzuVQLHwnKKHAn EFWQ== X-Gm-Message-State: AOJu0YyozERK4aWKaqqkAACPx5Io4qM8SsYMT3pjqxD1Ob2C37RuLbEu LsyUd3C2/eCZIxIkQi/h3hPCvzz/MY0u0rSpHjo= X-Google-Smtp-Source: AGHT+IEAqhQ+3guO1Q3e85xUsE/+b3DQb0U07qxoCfwQ0ILo8r3+akmTW4A4X1aFdOt4woFlZp3qyQ== X-Received: by 2002:a17:902:d48b:b0:1d0:7232:474c with SMTP id c11-20020a170902d48b00b001d07232474cmr4924947plg.25.1701722379729; Mon, 04 Dec 2023 12:39:39 -0800 (PST) Received: from rogue-one.tail33bf8.ts.net ([201.17.86.134]) by smtp.gmail.com with ESMTPSA id f7-20020a170902ce8700b001cf83962743sm2669584plg.250.2023.12.04.12.39.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 12:39:39 -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 , Pedro Tammela Subject: [PATCH net-next v2 1/5] rtnl: add helper to check if rtnl group has listeners Date: Mon, 4 Dec 2023 17:39:03 -0300 Message-Id: <20231204203907.413435-2-pctammela@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231204203907.413435-1-pctammela@mojatatu.com> References: <20231204203907.413435-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. Signed-off-by: Jamal Hadi Salim Signed-off-by: Victor Nogueira Signed-off-by: Pedro Tammela Reviewed-by: Jiri Pirko --- 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 Mon Dec 4 20:39:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13479082 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="MQvV3KOW" Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8ED8D6EA0 for ; Mon, 4 Dec 2023 12:39:44 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6ce3935ffedso2224178b3a.1 for ; Mon, 04 Dec 2023 12:39:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1701722383; x=1702327183; 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=w1rQLF2FFD9E9m66wLjUc3Aw8DImxClYa4KknzX7ZPc=; b=MQvV3KOWlptRlrsOFrf7cN1HLjPOQEnh+ZmvLp3AhOXzwO4vexatJPesahiAAhOxju vfLnHOSdZQxkI5djFW4TmOTLOO2gHwXnyvwbMV1NcASb/O+kjF5UyaCe4Ij7dFABTOCU UTBX1/8IiPgDepu46fP8XPL8DCzBOWJy4/6N8aMgX/NvwJV/9rUq8pliK5xl8rzqYGq4 PwPkAPBqRb+wPVGXcdDmdO1Liycr9H7QvZnBxXao5JfJpl2fScnfJo0/gUUchxxHlF6J yUGeJH3g+wrDv4z8RlI9kHTfzQpMYRemD1ommDCN2GCM/V0IQmLTh/ReW627WVMxluUt fsxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701722383; x=1702327183; 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=w1rQLF2FFD9E9m66wLjUc3Aw8DImxClYa4KknzX7ZPc=; b=U+qEnqX/hcXYVJ9DJiVJCHw5n4IaTgXvlFd+GgOGlU6+uhn69bL+n/AqTVt7ICiJ76 5RZkqOIMJTT2TLDWd/GpLg+C5X6xpOixobfqYQ8GHFZeNpYEVzGMLwMi3mYx7vLpsFR9 /jAIan8LD3dYxyCUWsRj1kKkGbG5Taddy5EV6MFUvg/ZxI8DaSIcSxjCHfDg/TJrHJvq ZC6N9ms/BG0pzYRl32zYlFop9P0egrvlPoYJXzu55bIGIbapLsW7VEcZ6ZxyaouD6dug yy3PY7Xm8NiR5qMUwLUN7yg5Cn2cJutOtKZhHHucHyrDdIMgwiwfxJh3ca1s/DvS3Sui b+1A== X-Gm-Message-State: AOJu0Yy/zpEOmVlbJV56RYjDHifqpSJxGF6h2vdgKBv6OUMZvztziOnP Q6lJH6X44CC489mY6m3lznHKfIG4H/ydubHxETY= X-Google-Smtp-Source: AGHT+IHGyd8K3Y6B69VAbtwSRj5Pj5MCzjstPEUKx11DZq7gvtla42W73IpYRMQy6Ih6kaX6SLVXZA== X-Received: by 2002:a17:903:244d:b0:1d0:53b1:400 with SMTP id l13-20020a170903244d00b001d053b10400mr4419483pls.68.1701722383609; Mon, 04 Dec 2023 12:39:43 -0800 (PST) Received: from rogue-one.tail33bf8.ts.net ([201.17.86.134]) by smtp.gmail.com with ESMTPSA id f7-20020a170902ce8700b001cf83962743sm2669584plg.250.2023.12.04.12.39.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 12:39:43 -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 , Pedro Tammela Subject: [PATCH net-next v2 2/5] rtnl: add helper to check if a notification is needed Date: Mon, 4 Dec 2023 17:39:04 -0300 Message-Id: <20231204203907.413435-3-pctammela@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231204203907.413435-1-pctammela@mojatatu.com> References: <20231204203907.413435-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. Signed-off-by: Victor Nogueira Signed-off-by: Pedro Tammela Reviewed-by: Jiri Pirko --- 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 Mon Dec 4 20:39:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13479083 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="ypw5OdG3" Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF456D72 for ; Mon, 4 Dec 2023 12:39:47 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1cfabcbda7bso24123275ad.0 for ; Mon, 04 Dec 2023 12:39:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1701722387; x=1702327187; 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=6381YJ0fxKfyYq1VUroGWEYeqoymWgXS4fp6IpGoYHE=; b=ypw5OdG3wVlQJ/B+BoULfdCr12/U/u4eBnK5Ldm/+62j9241JIv91GcfMuS10zSgM6 56rm6eHfmODWh4+GXkSxEI3tPFiges4HJkbrfDjUnq0VSQut/OCc4sH1wbBcpcpF0qx/ UpHAMrg/zYIwex7emyi+ti5kOt4a0/jddM4PCFxdPya/VrIRX5hQBNv+0UwKiaLYUjIW aLFEjoR97I9kgtd6aMK1uisvNnQ4oH+nVQyyU7urZDP7AU/nP+FWUmh6q90VerxutEgj QuJjhgm5m8ZsozmXUOpl/TyrYvthBk6lFwjPR/BKn2fmAQS4s4pXTuU1rGfKpBkCXTsZ BVtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701722387; x=1702327187; 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=6381YJ0fxKfyYq1VUroGWEYeqoymWgXS4fp6IpGoYHE=; b=Z6x642g13ercw0MWsczoyQodQZWHa4yYIvBZOeWOLSr/wY4PSkMTJqiU9D+h0+tlOZ cMCn9kcJ2GoOm7NMlnijDGnFWmRK7UJ24DsEKfpbuCTx0zd/mpLAcL1Q+hhtIdlaHy/4 7pOz8hzGgW3fLzQMXQO+o6b5sPNZm1cS1e0Nzgr8gSe0Q/THcOJZF3+JX7Q0wL8qr30M CV10aOFRi3Qt7EecYH5AGc45lfQBvvmhox+K6wqrCjTFXHIOuAV1SF3JjlVnfJLz4d/m F3iIZ0tnDCK904cYO6LKp+vKZFAyw0gJqAKmqFdOiHh5aTF6m2AM5xkyLa3x1x+wmt8h bOVw== X-Gm-Message-State: AOJu0YzFZRvCH4YOP4Jm7ONSw+o8+C/HPtHxsi6VLhazifXpgXUtAYbd RwpHD1nPXmNWKQPtoMTX8/pp1d+GAAO70x/izJM= X-Google-Smtp-Source: AGHT+IF5yhZcfdAjBNlqbtn76TzLizUPC0kmMNUGLLUpBRRTMwzjLLoGJyPqhP6GTC8Zp1SflGFSSw== X-Received: by 2002:a17:902:c283:b0:1cf:b413:8baa with SMTP id i3-20020a170902c28300b001cfb4138baamr380889pld.25.1701722387120; Mon, 04 Dec 2023 12:39:47 -0800 (PST) Received: from rogue-one.tail33bf8.ts.net ([201.17.86.134]) by smtp.gmail.com with ESMTPSA id f7-20020a170902ce8700b001cf83962743sm2669584plg.250.2023.12.04.12.39.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 12:39: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, Pedro Tammela Subject: [PATCH net-next v2 3/5] rtnl: add helper to send if skb is not null Date: Mon, 4 Dec 2023 17:39:05 -0300 Message-Id: <20231204203907.413435-4-pctammela@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231204203907.413435-1-pctammela@mojatatu.com> References: <20231204203907.413435-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(...) Signed-off-by: Pedro Tammela Reviewed-by: Jiri Pirko --- 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 Mon Dec 4 20:39:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13479084 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="s88fGfv+" Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5409199F for ; Mon, 4 Dec 2023 12:39:51 -0800 (PST) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1d0a7b72203so11601405ad.2 for ; Mon, 04 Dec 2023 12:39:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1701722391; x=1702327191; 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=nfPn3jUpd+FkBKVUlgJ5ullBszjYg7J/rYTarHELt38=; b=s88fGfv+lBUTraDN67ByI9lidHOY+BtG0FKFW9JVgOTOrcHjIRNL+4RcFTgAMMGmRm g6Chxy5nz1R/n8K7B36C+8ro91vxmOwbV3MXV/FYYA8HQEFjiZm16wA+A17mNBjjLWxh nSZtwYedvLe7T9QveokQeBHnPljYg/X2MlQ+Cowep0c1tbqIypX4du12OoQZ/MG+/3Zf Ku3T1qTXPEZvf4BXFF9oylEeOYN1GfMpxXE2BNlgo3AgekC+lpRujHt7MQ+Qd1YmBQSl ewOqrTB4XJQ12/Ttn9izH7E8bfyY7b6YVp1a2CyF+VKqMtZlIXZeEc7k1CMvvf1vvpFS b9Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701722391; x=1702327191; 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=nfPn3jUpd+FkBKVUlgJ5ullBszjYg7J/rYTarHELt38=; b=jGNVPYznQ0INWeoqV35JaMwL3WqWRp8SzRqUFoo9QBiFTLqER5qUeL3QMLuOjtqCvb +hdbzLXnJ9moKVLqMnQx9cRavMtsc7ttKhXoIBlR0rNH+Q06D1rp5Qqhopl2ryNBLPXF CIgruXPPDhTdAeLudSc12pg4VpbDya3l4J4yXunKbwMSM1dts66XXU3V5noccEiYpAsk akZtdXH8yNLfKG3fHZLJt+niG8bXS3WYzdcmz7AkJrUvT5VihIUAUyFiexmaaxYymxH2 t2QvD8FXk02OVOcmIHfOPowJnr2v5SXc4OKjIfIZTv15CwPr7QupaJk4oOZK7z14eLgR Zlcg== X-Gm-Message-State: AOJu0Yw/OOgRmO2lk8t8mn2/KxGULiF83uh+5wUQhz+aLmRpfWGZZs3W k0VIqY6Nl+f6R/YawqtQcJv1idTJ0Ty4Rz7P8Ek= X-Google-Smtp-Source: AGHT+IFdoTl63x8XtkrDbFZ+oravMXurKycW6VizqKyDyPYv6sXwbwETuwerOKN4kyiE5724yDaCUg== X-Received: by 2002:a17:902:ec8e:b0:1d0:98bf:f9ff with SMTP id x14-20020a170902ec8e00b001d098bff9ffmr3107298plg.117.1701722390850; Mon, 04 Dec 2023 12:39:50 -0800 (PST) Received: from rogue-one.tail33bf8.ts.net ([201.17.86.134]) by smtp.gmail.com with ESMTPSA id f7-20020a170902ce8700b001cf83962743sm2669584plg.250.2023.12.04.12.39.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 12:39: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 Subject: [PATCH net-next v2 4/5] net/sched: act_api: conditional notification of events Date: Mon, 4 Dec 2023 17:39:06 -0300 Message-Id: <20231204203907.413435-5-pctammela@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231204203907.413435-1-pctammela@mojatatu.com> References: <20231204203907.413435-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 tc_should_notify 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 c39252d61ebb..55c62a8e8803 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -1780,31 +1780,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); } @@ -1870,25 +1884,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) { @@ -1897,9 +1928,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 @@ -1950,26 +1980,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 Mon Dec 4 20:39:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13479085 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="XBdvXy+A" Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2F39198C for ; Mon, 4 Dec 2023 12:39:54 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1d04d286bc0so19199995ad.3 for ; Mon, 04 Dec 2023 12:39:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1701722394; x=1702327194; 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=UMo/Bue1/I17ArEtSrp6d+C4Ij0UdWh9rH9ZmG0aZbE=; b=XBdvXy+Ate0uAaGCNeYKtxHNCdy79ia8JpfSVFnBAb0I0Z6Iz1tbNrUM1/Z7d+mn8n xqdbsyJ/rFVynlzA+ptzBEYEsK1Bfvxn/zeOhNyUDgBZHpWsJdifvtguy/RUgKYXle+s dpLSPyNmTLspMH933dGZzJbQB24V6OhI0wnW3RslZooDR8Uwg1kvVZw5M+nKP5vC31qE MHnmubS3Vd52gaXId23Zh++lAwkKFuS7rSIcDRkmVS1SL71CrYlnBo/ALr6lJKMUpPz2 RGs49VcZD7AiNLP+oTMZFimaHpO8FJDmr3o6B/xXLBlgDJ1UzxoZgbkU1+C1ZKGq3VJy XBdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701722394; x=1702327194; 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=UMo/Bue1/I17ArEtSrp6d+C4Ij0UdWh9rH9ZmG0aZbE=; b=XhRf2Xk30wu5cab2RGu12ypPrao5XRPpqq09rmC2x98wj0m2QUfGyYtl1lOp7I77SH JrqA6+ldQK3sIWsO8Cn+08q9+Ao6mFlxIKwYjcIN5Hv7Ihcm9/QrhzER/o6yFStWJq92 1ISn0OOIKa3bwcYO9qT2fWHzjnZxaup2Zvgq/cGvQyxMJTbKpmQR0S8W/pqMscTxXFcg FcvUONK9yeYHT73U5zceXPAyrgxNtrgapG3E2SUDVYG/Zfcrwp6eTYIipEX4V8+G631R /pqRU2/QlZQb4BsriTw2RdWiEo0FyiYIErxgCWxKoSaZGB0lQB3MXkrV0xN1dVy4UhPa SHGg== X-Gm-Message-State: AOJu0YzI7bBtIIRMuNscoszLVEPtmegAfwZhj77K1KgwmyV+150IsOsf vKwBe4sAypNEwBz+BEUWQD26P3pakUyakc1bcy0= X-Google-Smtp-Source: AGHT+IFMMLYdT+Twoq0avmbhpQ7U7RsbLhS54sdn1+LHeoSELg7X+q/ecZCyKuSvjXHJKS0oTpsAeA== X-Received: by 2002:a17:902:ec87:b0:1d0:bcb2:b90f with SMTP id x7-20020a170902ec8700b001d0bcb2b90fmr979390plg.83.1701722394210; Mon, 04 Dec 2023 12:39:54 -0800 (PST) Received: from rogue-one.tail33bf8.ts.net ([201.17.86.134]) by smtp.gmail.com with ESMTPSA id f7-20020a170902ce8700b001cf83962743sm2669584plg.250.2023.12.04.12.39.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 12:39:53 -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 v2 5/5] net/sched: cls_api: conditional notification of events Date: Mon, 4 Dec 2023 17:39:07 -0300 Message-Id: <20231204203907.413435-6-pctammela@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231204203907.413435-1-pctammela@mojatatu.com> References: <20231204203907.413435-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 tc_should_notify 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. Signed-off-by: Pedro Tammela Reviewed-by: Jiri Pirko --- 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;