From patchwork Fri Dec 8 19:28:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13485800 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="MshjRT8A" Received: from mail-oo1-xc30.google.com (mail-oo1-xc30.google.com [IPv6:2607:f8b0:4864:20::c30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D14C91706 for ; Fri, 8 Dec 2023 11:29:10 -0800 (PST) Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-5906e03a7a4so1132805eaf.1 for ; Fri, 08 Dec 2023 11:29:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1702063750; x=1702668550; 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=mu2C9stAvSzwn5q9XEHwvSeI2bjAbMFJRXH67Gr9vKk=; b=MshjRT8A1nzfw+tj1WD5fQNeJZWKqt95yI3WiXIirVTqIxr9PxMOgKsLazuifYgzGt BYMa5x/agvpDuxWQ3ph8AEt9pW4PY3CTS99BPSBby7bBgTReXxVGnkMFJ3gwPK7xx4r4 O1Ecbe/r3zlRrnAjG35/GWoDkQYh7sfdwahrnum/7gE4zPs/cLtLagD9J7Dv0VhplSLE HdwTEGGPmfTMqwaa9L1au/RpxrjHVatd5GAgszrFNBr8lpUQYrwEYKI6OoKxA/B2ZOYn f7t8biQRjdJQoopUPN4KBd+1u3nIoGQ4F00CS4OxkVn4VTnI7MmDhE0hcd0m/WHyPbsj UjpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702063750; x=1702668550; 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=mu2C9stAvSzwn5q9XEHwvSeI2bjAbMFJRXH67Gr9vKk=; b=WopxR1yQ15UZ31NTwKqiLxpN5acxRxpiJVU/BRzgfsa6CYZwCfidCx1D+d08BfSdBS j8UscqTb6nNejMgEKB4EvG7VPU6Mrtj6BFlRRBj/snR18vANCb+4b65+u5ymXgV/YjyD Zewq/rjTZNyJsVRWlL5ejuIX3NWLQ6uZcikvNruaXTVJ5+W7ErRjfbJhHuplZdfXNkP0 GOV0w3+LWoOlVlGncsPMuoG9nrz7YgC/0wRykevpFwBAIFAtzvQurXF6x6gLsn02nzAT bnIMRbJ779wcMc43SqYCg40P5pb5HMRVhpc0iU8vz5qw7I0bnOXeYrD1tqKVcQ9D+Bp0 Deyw== X-Gm-Message-State: AOJu0Yws3JVa16PDGJSaxiRkkShgH8uP5dDvz+XlQW723VTv+7UIAtiy zTGQ2XXl7o0JVCmUFepVYWeb2BJxfMVVN78V5QE= X-Google-Smtp-Source: AGHT+IGKrkTDbUWaxyrNxJsftZgO42L8S4Dnax+v7gpet3RPuJe27T1Nvoo7KeW3jKJzPcR8qQqDqQ== X-Received: by 2002:a05:6358:339e:b0:16e:29bd:37be with SMTP id i30-20020a056358339e00b0016e29bd37bemr429178rwd.28.1702063749956; Fri, 08 Dec 2023 11:29:09 -0800 (PST) Received: from rogue-one.tail33bf8.ts.net ([201.17.86.134]) by smtp.gmail.com with ESMTPSA id p4-20020a634204000000b005b856fab5e9sm1916787pga.18.2023.12.08.11.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 11:29:09 -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, horms@kernel.org, Jiri Pirko , Victor Nogueira , Pedro Tammela Subject: [PATCH net-next v4 1/7] rtnl: add helper to check if rtnl group has listeners Date: Fri, 8 Dec 2023 16:28:41 -0300 Message-Id: <20231208192847.714940-2-pctammela@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231208192847.714940-1-pctammela@mojatatu.com> References: <20231208192847.714940-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 Reviewed-by: Simon Horman Signed-off-by: Jamal Hadi Salim Signed-off-by: Victor Nogueira Signed-off-by: Pedro Tammela --- 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 Fri Dec 8 19:28:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13485801 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="KDmyudXu" Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 857CB1706 for ; Fri, 8 Dec 2023 11:29:14 -0800 (PST) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6ceba6c4b8dso1634588b3a.1 for ; Fri, 08 Dec 2023 11:29:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1702063754; x=1702668554; 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=Ud0m8KbKukOW7r18Hnr/+4q4W5vHibKlr9LNz94nyfE=; b=KDmyudXuRZKLtQYJ9qPdzC7mqEtk5prGXG+oxKZeKnAXr2Qb9Hi9SjXy4NUQjOUBuu jBxj5Oa/nHnXcgTWp2TOb/e16nc0jEX+0ju+5Wkoe/PCWDhmsrTCz65P6i+iXLCSlPAn LD6mmDl6aQi56sVRRcE4gqqNmFQBP5S6wVqTdxJ2nGy/Dn6LMh0feEg65bOC5rz5jo1Z 0OOk3OwUR3IgkimEl9amvUwbDtoK+jL4CAvZ3GVsRPaGB8JWC1P0dqc/zZ0ON20f5hJf dgb/mdI2UC8xKq+CwL7omc6wBSIOv4n5TUeqYZIvejiKFIA7AK6W4CpnGIw/tY/uz/rj VZzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702063754; x=1702668554; 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=Ud0m8KbKukOW7r18Hnr/+4q4W5vHibKlr9LNz94nyfE=; b=f+XT77UXVn5+zKq+8ypDoZNGPRKz5t12JuVIhJK3fO1J2NBc3Zb5YlN9Fp+nvim01X Zh3kwvImjqGs8Xp2U97qxjUoubf88XaCoM6UP7G4HpaI3iKWryG5pdqUr3JNLN+6T60E VhhSLIDNz6Gh/VhzhRzxIadHiyDbHWAxUxFpQIj4JF/SgPRXw8NvvHYsglYWFuaFha9l 485KqDOCzkpn3c+hnPK3G/Ygm6cxT7pkVl4vnIucQkSNDIe4f4BvavdNtofZDaMVdmF6 69zEIezu4QFhouIcrZiBNlEiubuBt6gE2R0cp7kfm0Zp40XIiT7hEIJpqUDAmhGSLFzy ALeg== X-Gm-Message-State: AOJu0YxDDbI5myOOtDrY0DZSfGWgAYB7heC6FqB6KvKf5NsndOayHAz4 NJNloxDwS4xEbukzN49KCvBtTcFf49Y6xRF9Hq0= X-Google-Smtp-Source: AGHT+IF3NrNTw5CM9dsGyEItJ9hCToYawrUzvaKNaSJDis9h2rDlWxNGKu9NnuLo7IJVYUKmlBrQtA== X-Received: by 2002:a05:6a00:a8a:b0:6ce:546e:eb1 with SMTP id b10-20020a056a000a8a00b006ce546e0eb1mr599882pfl.39.1702063753881; Fri, 08 Dec 2023 11:29:13 -0800 (PST) Received: from rogue-one.tail33bf8.ts.net ([201.17.86.134]) by smtp.gmail.com with ESMTPSA id p4-20020a634204000000b005b856fab5e9sm1916787pga.18.2023.12.08.11.29.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 11:29:13 -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, horms@kernel.org, Victor Nogueira , Jiri Pirko , Pedro Tammela Subject: [PATCH net-next v4 2/7] rtnl: add helper to check if a notification is needed Date: Fri, 8 Dec 2023 16:28:42 -0300 Message-Id: <20231208192847.714940-3-pctammela@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231208192847.714940-1-pctammela@mojatatu.com> References: <20231208192847.714940-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 Reviewed-by: Simon Horman Signed-off-by: Victor Nogueira Signed-off-by: Pedro Tammela --- 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 Fri Dec 8 19:28:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13485802 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="tsNt7n9E" Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 357AD1712 for ; Fri, 8 Dec 2023 11:29:18 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6cebbf51742so1515332b3a.1 for ; Fri, 08 Dec 2023 11:29:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1702063757; x=1702668557; 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=Rbqb8Cc3CExBuuVs8fbrLNJK62w6f5syo5JgiMxd5O8=; b=tsNt7n9EgenyF9kzCIit53XzWaWtg+XErev6yMwQVZLd9wkgKSLiAEocF8HfABdgwZ K8rsPg3Ho98PvBbJ7+IL2GaZdKTRzRi8nJTQ/UVTf7SpkkZZeRdCmu9O8wOwWIdFDvbI hkk5AQdqfImPX+BazlXrPE2lRe3S5Nl6Aepy2cYGuYvsBXj+iwnrq7w8w0S3G//3Het7 rDwRYj8nB1U6DpKVi+bzWh+4u0WKEzMNfgiWGHVsgPIbWuMr1WnLEJoG+t4oyhqMWL2w ZNyrqYLyCW21TrXR1daXv6ONwWj6JKwl4vF53+yrF3XG6+i/jfSCCUUrk2AWZhttw8FF LVEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702063757; x=1702668557; 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=Rbqb8Cc3CExBuuVs8fbrLNJK62w6f5syo5JgiMxd5O8=; b=lrg8c1cfhWd5hVUBOVTTzyyzR4LjKCVN3cFGWGNsqmRpiUv4MOm/5vCYy52NmPafPM m8DzvFJHTW3mBNGz7pQvzZ7dr6q1Wbh25cSRxEg/BsbEY2SiTcTfpVh7ek6DwFxf09Vv lhu8/Irqt+NnCm51SKwN0ZRvrvL1+MTkzhksDBE4/YbXMtyxUFAlPqa2dae0tgtz1dEv XMsyIdSJsNBljkIHgA3JcowULeQ3lnV5jfj7VbrU4eCeQc4Oa8jea8BwxcoCiTuNZ8IS fWTy0YQs7GNxlQJ7rhv+2cIwy4vKivyHBYJUlaHlWzmafhqqq9WSfN55qvgQqE3wZdpM ss0A== X-Gm-Message-State: AOJu0YxBCFXLPd+K91Bbk3I9QKJzsML+O0Z3q+9Ffu6upV4F0t8po7UZ o7StPNkI4Y2rb6Dc5ZX35bwV94afa4zz3R+vlH4= X-Google-Smtp-Source: AGHT+IG6DfJO5kQya5NbcC0yiTdVcaUMT2kyuXASQAEf/p1l1/eP7heCd92rPMfbNJsn9zzNfVuqRw== X-Received: by 2002:aa7:888b:0:b0:6ce:6448:4961 with SMTP id z11-20020aa7888b000000b006ce64484961mr1801300pfe.12.1702063757446; Fri, 08 Dec 2023 11:29:17 -0800 (PST) Received: from rogue-one.tail33bf8.ts.net ([201.17.86.134]) by smtp.gmail.com with ESMTPSA id p4-20020a634204000000b005b856fab5e9sm1916787pga.18.2023.12.08.11.29.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 11:29:17 -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, horms@kernel.org, Pedro Tammela , Jiri Pirko Subject: [PATCH net-next v4 3/7] rtnl: add helper to send if skb is not null Date: Fri, 8 Dec 2023 16:28:43 -0300 Message-Id: <20231208192847.714940-4-pctammela@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231208192847.714940-1-pctammela@mojatatu.com> References: <20231208192847.714940-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 Reviewed-by: Simon Horman Signed-off-by: Pedro Tammela --- 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 Fri Dec 8 19:28:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13485803 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="ixYdb4q+" 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 C0E0F1706 for ; Fri, 8 Dec 2023 11:29:21 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6ce6dd83945so1927000b3a.3 for ; Fri, 08 Dec 2023 11:29:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1702063761; x=1702668561; 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=Za2V75/z2cG6z3Uv2O/AbEjyUwvGaFrmvQ0ExBrI0mg=; b=ixYdb4q+nIZ3i0oGRkoIDA4cny3MV2awWkP95hJQdUZyWWnXlNfZzui8DrFQX9nf6g Ol2U8yFZFR/B5GgNFD50+muMt2eN0vrufOZgwGdSELFLBnNUweRYqUJO8MlBDhqtIw37 jmvNehwROqgncbFnG2chB64HkNDuVQ3OVVOf5ndLuibvmnsVa5b8ulKFbprDnC1EQqKr k/tIayOpqanjw9dL1Px1S43duNsLKIy7tGHrsWd8wkZFTulP9DsvTJ4h+zEfQ9LX08bV 8IMG9E4MjyX9Ueo5S0fwcbInsTQIZ8Kf/G1PYLLN3EHCRMWTi0cQCdbdftdah1HRqjE0 aTGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702063761; x=1702668561; 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=Za2V75/z2cG6z3Uv2O/AbEjyUwvGaFrmvQ0ExBrI0mg=; b=T8n5ta4wWO7gSMQSOxmvjF9qFE3hFK7Cv4kmPR9mvJKWv0Vlnf5wh7ldowwdA4O9sR hN/exP3OGI7CUUbq7vMQ7XqY18DOsJDslUz+va6CoxYt34vsmIX+P1ti04d7hCRj6mxJ jiRCyY2rHPeIMEdvV5hjWjf8BEuvtq/51tfm/E32EJ9XulP6uwWQPuMUiL1xcK2xQUx5 MKjaeUTzb/62JtWtXjGzJBPYuOyG5g6GpRuQIVYx3KVRwMrCKrM76QiC/vtH2mCuVFcr vVIyGlwJf+oy5gQB0jq9wK8vfPhIJ9RbC/ak/Srsh1Pc9iu4oMuwmarcy6CgbbQ5kRl8 nVxA== X-Gm-Message-State: AOJu0YxqzHL8S1BaO4P/TxNFlULPgFrlYFl3aS8+Y/8tgnQowjwVt5eA e5hFsjFu56Av6qIbYNy3Uo/2VUo3WOlA7EmWouc= X-Google-Smtp-Source: AGHT+IGW8RL5rUSEeSV/aV28GmrFPXWY1HVxNE4PYTHpELvnTHG+PDWl1i9OlhFLbxjKCVCWCAiX/A== X-Received: by 2002:a05:6a00:27a0:b0:6ce:3f6b:638a with SMTP id bd32-20020a056a0027a000b006ce3f6b638amr494247pfb.48.1702063760989; Fri, 08 Dec 2023 11:29:20 -0800 (PST) Received: from rogue-one.tail33bf8.ts.net ([201.17.86.134]) by smtp.gmail.com with ESMTPSA id p4-20020a634204000000b005b856fab5e9sm1916787pga.18.2023.12.08.11.29.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 11:29:20 -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, horms@kernel.org, Pedro Tammela Subject: [PATCH net-next v4 4/7] net/sched: act_api: don't open code max() Date: Fri, 8 Dec 2023 16:28:44 -0300 Message-Id: <20231208192847.714940-5-pctammela@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231208192847.714940-1-pctammela@mojatatu.com> References: <20231208192847.714940-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 Use max() in a couple of places that are open coding it with the ternary operator. Signed-off-by: Pedro Tammela Reviewed-by: Jiri Pirko --- net/sched/act_api.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/net/sched/act_api.c b/net/sched/act_api.c index abec5c45b5a4..4f295ae4e152 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -1796,8 +1796,7 @@ tcf_reoffload_del_notify(struct net *net, struct tc_action *action) 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; @@ -1882,8 +1881,7 @@ tcf_del_notify(struct net *net, struct nlmsghdr *n, struct tc_action *actions[], 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; @@ -1961,8 +1959,7 @@ tcf_add_notify(struct net *net, struct nlmsghdr *n, struct tc_action *actions[], { 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; From patchwork Fri Dec 8 19:28:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13485804 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="mB+PFcnD" Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 277281712 for ; Fri, 8 Dec 2023 11:29:25 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-5c664652339so1903452a12.1 for ; Fri, 08 Dec 2023 11:29:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1702063764; x=1702668564; 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=1HmpdmpOzS9YE2nfKm05Yn+Grb6i0nlVwnqk8LBWeCw=; b=mB+PFcnD01cT9Sha0No5EI+6fKL9jtRH/2v8H0DW7zPJK0Xkto/vC8JTZmKKBXVKBp VxT5hZBvywZdU0WCJiPVDgwr5gJslJnjrBzZD5k50AU9+bpaxLb0456fj8Kj7tCORCgs HKbBfkkn8kfpAw6Z9B2CZpeTp+X2hWc/MOw43zWp/R3aT+IH/85M9iJjbGhyUzyXs24I 0Zw8hCCDW7tgOrb4pys2yhxOoXQX0l1rX+K32LkhqBw/IC5e6LAapc8t6LKbEJJlxPdl zFx7qu45jh/VF7yW4MMoZmJ6bafKJL7sJPr7aQsGrklJZClhh14YI2wK3RfCGWndlhyN Ro6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702063764; x=1702668564; 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=1HmpdmpOzS9YE2nfKm05Yn+Grb6i0nlVwnqk8LBWeCw=; b=FadwEjEvPPqxqdgQC2cEPEr7xV8hcEjjDCMAi8gpgCHQtOnqVvp1L3I8IfUxkuE981 MlwCtAX+UKxucU0Oee+SF0mYsuJpyQfv44KgO5rFKuNaC0oIuCxohY6jt0FH8JWHmk/d kcohq0O3ccItsz/1Ra7GEvtL7cxJV3fOcaJVoK1Zyt3zrMiHWoGFeYrE5D0atood2Kza h47O5zlaFtcKuksi1Pmo+LVs5TL3Je/wYxE7ohO9cmUmZEz7digKqV8IgNbbmeEWD00o DoJiDt28K51nYGbvRv+pmk1Zlsj4JjibrinuOJV9S1eKkEsN7/SVqJqXDFk+os2uhMwH DfpQ== X-Gm-Message-State: AOJu0YwrAJ0rO2qFCq66C6U3TBBStVYW6u3k42RAqhwiQRxkFmibmnmU 1ATWUkKgpA88bWz+Qb6O3msDkWu9VPgd1LG7HEs= X-Google-Smtp-Source: AGHT+IH8c+2DK8mCydUTNL01Qgv7kDVtX6L1i4+gB1C1GRtq048wwwrG7R460Foe1umsMX7FA8pR1w== X-Received: by 2002:a05:6a20:748f:b0:18f:ea5b:6830 with SMTP id p15-20020a056a20748f00b0018fea5b6830mr624110pzd.40.1702063764532; Fri, 08 Dec 2023 11:29:24 -0800 (PST) Received: from rogue-one.tail33bf8.ts.net ([201.17.86.134]) by smtp.gmail.com with ESMTPSA id p4-20020a634204000000b005b856fab5e9sm1916787pga.18.2023.12.08.11.29.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 11:29:24 -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, horms@kernel.org, Pedro Tammela Subject: [PATCH net-next v4 5/7] net/sched: act_api: conditional notification of events Date: Fri, 8 Dec 2023 16:28:45 -0300 Message-Id: <20231208192847.714940-6-pctammela@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231208192847.714940-1-pctammela@mojatatu.com> References: <20231208192847.714940-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 Reviewed-by: Jiri Pirko --- net/sched/act_api.c | 98 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 75 insertions(+), 23 deletions(-) diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 4f295ae4e152..6611f292b6cb 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -1785,30 +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(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; + int ret; + + if (!rtnl_notify_needed(net, 0, RTNLGRP_TC)) { + skb = NULL; + } else { + skb = tcf_reoffload_del_notify_msg(net, action); + if (IS_ERR(skb)) + return PTR_ERR(skb); } 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); } @@ -1874,22 +1889,41 @@ 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(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; + int ret; + + if (!rtnl_notify_needed(net, n->nlmsg_flags, RTNLGRP_TC)) { + skb = NULL; + } else { + skb = tcf_del_notify_msg(net, n, actions, portid, attr_size, + extack); + if (IS_ERR(skb)) + return PTR_ERR(skb); } /* now do the delete */ @@ -1900,9 +1934,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 @@ -1953,25 +1986,44 @@ 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(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 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; + + if (!rtnl_notify_needed(net, n->nlmsg_flags, RTNLGRP_TC)) { + skb = NULL; + } else { + skb = tcf_add_notify_msg(net, n, actions, portid, attr_size, + extack); + if (IS_ERR(skb)) + return PTR_ERR(skb); } - return rtnetlink_send(skb, net, portid, RTNLGRP_TC, - n->nlmsg_flags & NLM_F_ECHO); + 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 Fri Dec 8 19:28:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13485805 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="hTrU6uID" Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8E621706 for ; Fri, 8 Dec 2023 11:29:28 -0800 (PST) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6cdea2f5918so1707343b3a.2 for ; Fri, 08 Dec 2023 11:29:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1702063768; x=1702668568; 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=EZK7Q8Zc8sne+UmGV8dWYwVR9BA2654LY3Kv0f39VPw=; b=hTrU6uIDKbSMOAqNH6QoZuVWKYoSXhX03P3ZWzxZKSOSzQhzNwbnoGpkASD844fadr R9YLO+p9pz+0D3ZCodwGSJiwfxuhY/h82Y3RdBenX1VNnz9Q7KKJdrNUhdyP3ZnNFgIq 9DZr24w/ATtP20iLTuc/U8tRLBLPvgHNwxSF+Sb+B3FEJ9CV9h9hgUHVFmWtORP1IqSl IEehyvZdWV7W+/WAw7GKo6JyPy6D1uVHcb74LbmH2QWak8Vgd9ahj215hC0E4u8p3DXw V6R4xaVIUUksmDUhLtXz9t0MxmkwLkyHYStAZmuRUvHSSuUBDbm7wj4WLt30Unz5gSPA jyVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702063768; x=1702668568; 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=EZK7Q8Zc8sne+UmGV8dWYwVR9BA2654LY3Kv0f39VPw=; b=PzIWgRSG+ZB9iqxA/P+vdMT/bA71iDtOkPX2BKKUTp0FLZiXFFyOqCss4PHgO6VZd1 ue1VnwGkGGW+0DUbOZuXEAb7sOulu7rgk4E4WBwXcaGHJOmvs1i9SZfhRTOGbc9uMCuC p+FF7X1xKKzQ1WkECycthmhNGXSAdHBEb4S/U89dsqksRnignQsV1W/dkM7oWmHD8B3y zSvXBqG5n8g0v3hPucP8VC/1VJuA+gAPqRCyyh0xGvJFx210f4yXt5wLqMqW40SD6uTX oxhZERP43AfQgytoKQyYhIDialFhOnzzgpWYJ8+zLDzp1qz/rfg4DM+MELfTuky0ZcAu myxQ== X-Gm-Message-State: AOJu0YyHJ3hKHE6qPJDS21saaPkEVFmDOVJSYwXILndqob2VP8wbpmIY 4V2ClmyEKNfyb4L1izNB5xTLf82qowSeXcXhEj4= X-Google-Smtp-Source: AGHT+IFqTk8I3Hhg6UeW32Y56R+0E1hK4O0Evf130wfUGnqBL1DWDC5Hl0aMvnMMVWiba41fhakGtg== X-Received: by 2002:a05:6a00:1143:b0:6ce:2d6d:24a6 with SMTP id b3-20020a056a00114300b006ce2d6d24a6mr516115pfm.19.1702063767971; Fri, 08 Dec 2023 11:29:27 -0800 (PST) Received: from rogue-one.tail33bf8.ts.net ([201.17.86.134]) by smtp.gmail.com with ESMTPSA id p4-20020a634204000000b005b856fab5e9sm1916787pga.18.2023.12.08.11.29.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 11:29:27 -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, horms@kernel.org, Pedro Tammela Subject: [PATCH net-next v4 6/7] net/sched: cls_api: remove 'unicast' argument from delete notification Date: Fri, 8 Dec 2023 16:28:46 -0300 Message-Id: <20231208192847.714940-7-pctammela@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231208192847.714940-1-pctammela@mojatatu.com> References: <20231208192847.714940-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 argument is never called while set to true, so remove it as there's no need for it. Signed-off-by: Pedro Tammela Reviewed-by: Jiri Pirko --- net/sched/cls_api.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index 1976bd163986..4050215a532d 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -650,7 +650,7 @@ static void tc_chain_tmplt_del(const struct tcf_proto_ops *tmplt_ops, static int tc_chain_notify_delete(const struct tcf_proto_ops *tmplt_ops, void *tmplt_priv, u32 chain_index, struct tcf_block *block, struct sk_buff *oskb, - u32 seq, u16 flags, bool unicast); + u32 seq, u16 flags); static void __tcf_chain_put(struct tcf_chain *chain, bool by_act, bool explicitly_created) @@ -685,8 +685,7 @@ static void __tcf_chain_put(struct tcf_chain *chain, bool by_act, if (non_act_refcnt == chain->explicitly_created && !by_act) { if (non_act_refcnt == 0) tc_chain_notify_delete(tmplt_ops, tmplt_priv, - chain->index, block, NULL, 0, 0, - false); + chain->index, block, NULL, 0, 0); /* Last reference to chain, no need to lock. */ chain->flushing = false; } @@ -2075,8 +2074,8 @@ static int tfilter_notify(struct net *net, struct sk_buff *oskb, static int tfilter_del_notify(struct net *net, struct sk_buff *oskb, struct nlmsghdr *n, struct tcf_proto *tp, struct tcf_block *block, struct Qdisc *q, - u32 parent, void *fh, bool unicast, bool *last, - bool rtnl_held, struct netlink_ext_ack *extack) + u32 parent, void *fh, bool *last, bool rtnl_held, + struct netlink_ext_ack *extack) { struct sk_buff *skb; u32 portid = oskb ? NETLINK_CB(oskb).portid : 0; @@ -2100,11 +2099,8 @@ static int tfilter_del_notify(struct net *net, struct sk_buff *oskb, return err; } - if (unicast) - err = rtnl_unicast(skb, net, portid); - else - err = rtnetlink_send(skb, net, portid, RTNLGRP_TC, - n->nlmsg_flags & NLM_F_ECHO); + err = rtnetlink_send(skb, net, portid, RTNLGRP_TC, + n->nlmsg_flags & NLM_F_ECHO); if (err < 0) NL_SET_ERR_MSG(extack, "Failed to send filter delete notification"); @@ -2499,9 +2495,8 @@ static int tc_del_tfilter(struct sk_buff *skb, struct nlmsghdr *n, } else { bool last; - err = tfilter_del_notify(net, skb, n, tp, block, - q, parent, fh, false, &last, - rtnl_held, extack); + err = tfilter_del_notify(net, skb, n, tp, block, q, parent, fh, + &last, rtnl_held, extack); if (err) goto errout; @@ -2929,7 +2924,7 @@ static int tc_chain_notify(struct tcf_chain *chain, struct sk_buff *oskb, static int tc_chain_notify_delete(const struct tcf_proto_ops *tmplt_ops, void *tmplt_priv, u32 chain_index, struct tcf_block *block, struct sk_buff *oskb, - u32 seq, u16 flags, bool unicast) + u32 seq, u16 flags) { u32 portid = oskb ? NETLINK_CB(oskb).portid : 0; struct net *net = block->net; @@ -2945,9 +2940,6 @@ static int tc_chain_notify_delete(const struct tcf_proto_ops *tmplt_ops, return -EINVAL; } - if (unicast) - return rtnl_unicast(skb, net, portid); - return rtnetlink_send(skb, net, portid, RTNLGRP_TC, flags & NLM_F_ECHO); } From patchwork Fri Dec 8 19:28:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13485806 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="B4LUPAgz" Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54DE01706 for ; Fri, 8 Dec 2023 11:29:32 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-5c65ca2e1eeso1743995a12.2 for ; Fri, 08 Dec 2023 11:29:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1702063771; x=1702668571; 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=/m2C8F8TxO/qe6PLr2tyxnYNhWwE8d63+ZuL37T31g8=; b=B4LUPAgzpadDOccMVo9dlPODHpAEl0jbMZbYuAvk3adaj8Di6rR177ieqiPIGU4vz0 lkMKSMrqjVAGF3TFr6H5k30xZWRTRIlYjEgk7y9tLTpgTcB6fGHSQIQb+VLYu+bcg3E5 yJ2gQ+qCab/qqHh1gW7pok+0tvAtBXKnRSDH/QfLy6dGEIobG/h0sAWTb0lnuDatfFjY 817hcg+MdOe00JMPIT1AygZwWN39m87VREzTZWFeQT9tUcO1jsncibxTrt7wq8X77Uqz W0bxP+tVZOlfVjQuuxGa2oSdVaPybCfFSvjpb2HIKYCoLH2YlfnTTL/SwwF2ddLcUTEr 5J2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702063771; x=1702668571; 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=/m2C8F8TxO/qe6PLr2tyxnYNhWwE8d63+ZuL37T31g8=; b=KuS6xpQPNia7/T93/S5+KWVo2rfLzqLMmwok7FJhzZQuNRRBPCvxQHAXgboD5qxJKJ 30C3AShEaXLuxIOHtqDJy2HFyrJYGChU7m2wQPGVHmBNzrdTGKdwhVs17lhGBD4W8ehc 2uBDS+HRtrnXx+M/RuGLLolC2zEDPprNlDkKn3ECTSmrBH89mAoxVQVRJWOHDpUhhdZ/ KU0BJzl0UhmBXETSfbHh69wmZwSOdpRx/Bjs9h/iSGI9EDLfJIPYX5E4tN6JN9ckrXfk /+4xII8KUk3/uKStyoc6b0ZiL4OUz/lZ0AE7Q7JBDpDVi/lTQd4OhK46XhP4LovgFQ0b ikeg== X-Gm-Message-State: AOJu0YwLAt2+QoTrTXFTcDwz7w1DeIrXXenJ8R/NqTwo/39X7exNhado dXN4r8fYF4Y1/cdfIlQyEKj9m/evyQH1jvcQxDQ= X-Google-Smtp-Source: AGHT+IE1gJtgHkokh8y5ROrGapv/jMhiwOAzg0JQz7o/qOmy2yUa4ByOCAxi290PjjwHocyG1ygP5A== X-Received: by 2002:a05:6a20:8f09:b0:18c:8d0f:a7b7 with SMTP id b9-20020a056a208f0900b0018c8d0fa7b7mr632884pzk.22.1702063771585; Fri, 08 Dec 2023 11:29:31 -0800 (PST) Received: from rogue-one.tail33bf8.ts.net ([201.17.86.134]) by smtp.gmail.com with ESMTPSA id p4-20020a634204000000b005b856fab5e9sm1916787pga.18.2023.12.08.11.29.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 11:29:31 -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, horms@kernel.org, Pedro Tammela , Jiri Pirko Subject: [PATCH net-next v4 7/7] net/sched: cls_api: conditional notification of events Date: Fri, 8 Dec 2023 16:28:47 -0300 Message-Id: <20231208192847.714940-8-pctammela@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231208192847.714940-1-pctammela@mojatatu.com> References: <20231208192847.714940-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 Reviewed-by: Simon Horman Signed-off-by: Pedro Tammela --- 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 4050215a532d..437daebc1fc4 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -2052,6 +2052,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; @@ -2081,6 +2084,9 @@ static int tfilter_del_notify(struct net *net, struct sk_buff *oskb, u32 portid = oskb ? NETLINK_CB(oskb).portid : 0; int err; + if (!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; @@ -2901,6 +2907,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; @@ -2930,6 +2939,9 @@ static int tc_chain_notify_delete(const struct tcf_proto_ops *tmplt_ops, struct net *net = block->net; struct sk_buff *skb; + if (!rtnl_notify_needed(net, flags, RTNLGRP_TC)) + return 0; + skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); if (!skb) return -ENOBUFS;