* [PATCH net-next v4 0/2] netcons: Add udp send fail statistics to netconsole
@ 2024-10-27 19:59 Maksym Kutsevol
2024-10-27 19:59 ` [PATCH net-next v4 1/2] netpoll: Make netpoll_send_udp return status instead of void Maksym Kutsevol
2024-10-27 19:59 ` [PATCH net-next v4 2/2] netcons: Add udp send fail statistics to netconsole Maksym Kutsevol
0 siblings, 2 replies; 8+ messages in thread
From: Maksym Kutsevol @ 2024-10-27 19:59 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Jonathan Corbet, Andrew Lunn, Breno Leitao
Cc: netdev, linux-kernel, linux-doc, Maksym Kutsevol
Enhance observability of netconsole. Packet sends can fail.
Start tracking at least two failure possibilities: ENOMEM and
NET_XMIT_DROP for every target. Stats are exposed via an additional
attribute in CONFIGFS.
The exposed statistics allows easier debugging of cases when netconsole
messages were not seen by receivers, eliminating the guesswork if the
sender thinks that messages in question were sent out.
Stats are not reset on enable/disable/change remote ip/etc, they
belong to the netcons target itself.
Reported-by: Breno Leitao <leitao@debian.org>
Closes: https://lore.kernel.org/all/ZsWoUzyK5du9Ffl+@gmail.com/
Signed-off-by: Maksym Kutsevol <max@kutsevol.com>
---
Changelog:
v4:
* Rebased after
https://lore.kernel.org/netdev/20241017095028.3131508-1-leitao@debian.org/
was merged
* cc doc maintainers.
* adhere to 80 columns. Learn that checkpatch defaults to 100. Okay :)
v3:
* https://lore.kernel.org/netdev/20240912173608.1821083-2-max@kutsevol.com/
* cleanup the accidental slip of debugging addons.
* use IS_ENABLED() instead of #ifdef. Always have stats field.
v2:
* https://lore.kernel.org/netdev/20240828214524.1867954-2-max@kutsevol.com/
* fixed commit message wording and reported-by reference.
* not hiding netconsole_target_stats when CONFIG_NETCONSOLE_DYNAMIC
is not enabled.
* rename stats attribute in configfs to transmit_errors and make it
a single u64 value, which is a sum of errors that occured.
* make a wrapper function to count errors instead of a return result
classifier one.
* use u64_stats_sync.h to manage stats.
v1:
* https://lore.kernel.org/netdev/20240824215130.2134153-2-max@kutsevol.com/
---
Maksym Kutsevol (2):
netpoll: Make netpoll_send_udp return status instead of void
netcons: Add udp send fail statistics to netconsole
Documentation/networking/netconsole.rst | 5 +--
drivers/net/netconsole.c | 61 +++++++++++++++++++++++++++++++--
include/linux/netpoll.h | 2 +-
net/core/netpoll.c | 6 ++--
4 files changed, 65 insertions(+), 9 deletions(-)
---
base-commit: 03fc07a24735e0be8646563913abf5f5cb71ad19
change-id: 20241027-netcons-add-udp-send-fail-statistics-to-netconsole-dc9a5a9f9139
Best regards,
--
Maksym Kutsevol <max@kutsevol.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH net-next v4 1/2] netpoll: Make netpoll_send_udp return status instead of void
2024-10-27 19:59 [PATCH net-next v4 0/2] netcons: Add udp send fail statistics to netconsole Maksym Kutsevol
@ 2024-10-27 19:59 ` Maksym Kutsevol
2024-10-28 10:45 ` Breno Leitao
2024-10-27 19:59 ` [PATCH net-next v4 2/2] netcons: Add udp send fail statistics to netconsole Maksym Kutsevol
1 sibling, 1 reply; 8+ messages in thread
From: Maksym Kutsevol @ 2024-10-27 19:59 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Jonathan Corbet, Andrew Lunn, Breno Leitao
Cc: netdev, linux-kernel, linux-doc, Maksym Kutsevol
netpoll_send_udp can return if send was successful.
It will allow client code to be aware of the send status.
Possible return values are the result of __netpoll_send_skb (cast to int)
and -ENOMEM. This doesn't cover the case when TX was not successful
instantaneously and was scheduled for later, __netpoll__send_skb returns
success in that case.
Signed-off-by: Maksym Kutsevol <max@kutsevol.com>
---
include/linux/netpoll.h | 2 +-
net/core/netpoll.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h
index cd4e28db0cbd..b1ba8d6331a5 100644
--- a/include/linux/netpoll.h
+++ b/include/linux/netpoll.h
@@ -56,7 +56,7 @@ static inline void netpoll_poll_disable(struct net_device *dev) { return; }
static inline void netpoll_poll_enable(struct net_device *dev) { return; }
#endif
-void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
+int netpoll_send_udp(struct netpoll *np, const char *msg, int len);
void netpoll_print_options(struct netpoll *np);
int netpoll_parse_options(struct netpoll *np, char *opt);
int __netpoll_setup(struct netpoll *np, struct net_device *ndev);
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index 94b7f07a952f..1f36f351b5f9 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -390,7 +390,7 @@ netdev_tx_t netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
}
EXPORT_SYMBOL(netpoll_send_skb);
-void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
+int netpoll_send_udp(struct netpoll *np, const char *msg, int len)
{
int total_len, ip_len, udp_len;
struct sk_buff *skb;
@@ -414,7 +414,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
skb = find_skb(np, total_len + np->dev->needed_tailroom,
total_len - len);
if (!skb)
- return;
+ return -ENOMEM;
skb_copy_to_linear_data(skb, msg, len);
skb_put(skb, len);
@@ -490,7 +490,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
skb->dev = np->dev;
- netpoll_send_skb(np, skb);
+ return (int)netpoll_send_skb(np, skb);
}
EXPORT_SYMBOL(netpoll_send_udp);
--
2.43.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next v4 2/2] netcons: Add udp send fail statistics to netconsole
2024-10-27 19:59 [PATCH net-next v4 0/2] netcons: Add udp send fail statistics to netconsole Maksym Kutsevol
2024-10-27 19:59 ` [PATCH net-next v4 1/2] netpoll: Make netpoll_send_udp return status instead of void Maksym Kutsevol
@ 2024-10-27 19:59 ` Maksym Kutsevol
2024-10-28 10:45 ` Breno Leitao
2024-10-31 1:49 ` Jakub Kicinski
1 sibling, 2 replies; 8+ messages in thread
From: Maksym Kutsevol @ 2024-10-27 19:59 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Jonathan Corbet, Andrew Lunn, Breno Leitao
Cc: netdev, linux-kernel, linux-doc, Maksym Kutsevol
Enhance observability of netconsole. Packet sends can fail.
Start tracking at least two failure possibilities: ENOMEM and
NET_XMIT_DROP for every target. Stats are exposed via an additional
attribute in CONFIGFS.
The exposed statistics allows easier debugging of cases when netconsole
messages were not seen by receivers, eliminating the guesswork if the
sender thinks that messages in question were sent out.
Stats are not reset on enable/disable/change remote ip/etc, they
belong to the netcons target itself.
Reported-by: Breno Leitao <leitao@debian.org>
Closes: https://lore.kernel.org/all/ZsWoUzyK5du9Ffl+@gmail.com/
Signed-off-by: Maksym Kutsevol <max@kutsevol.com>
---
Documentation/networking/netconsole.rst | 5 +--
drivers/net/netconsole.c | 61 +++++++++++++++++++++++++++++++--
2 files changed, 61 insertions(+), 5 deletions(-)
diff --git a/Documentation/networking/netconsole.rst b/Documentation/networking/netconsole.rst
index d55c2a22ec7a..94c4680fdf3e 100644
--- a/Documentation/networking/netconsole.rst
+++ b/Documentation/networking/netconsole.rst
@@ -124,7 +124,7 @@ To remove a target::
The interface exposes these parameters of a netconsole target to userspace:
- ============== ================================= ============
+ =============== ================================= ============
enabled Is this target currently enabled? (read-write)
extended Extended mode enabled (read-write)
release Prepend kernel release to message (read-write)
@@ -135,7 +135,8 @@ The interface exposes these parameters of a netconsole target to userspace:
remote_ip Remote agent's IP address (read-write)
local_mac Local interface's MAC address (read-only)
remote_mac Remote agent's MAC address (read-write)
- ============== ================================= ============
+ transmit_errors Number of packet send errors (read-only)
+ =============== ================================= ============
The "enabled" attribute is also used to control whether the parameters of
a target can be updated or not -- you can modify the parameters of only
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 4ea44a2f48f7..5f5e5a8cd896 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -36,6 +36,7 @@
#include <linux/inet.h>
#include <linux/configfs.h>
#include <linux/etherdevice.h>
+#include <linux/u64_stats_sync.h>
#include <linux/utsname.h>
#include <linux/rtnetlink.h>
@@ -90,6 +91,12 @@ static DEFINE_MUTEX(target_cleanup_list_lock);
*/
static struct console netconsole_ext;
+struct netconsole_target_stats {
+ u64_stats_t xmit_drop_count;
+ u64_stats_t enomem_count;
+ struct u64_stats_sync syncp;
+} __aligned(2 * sizeof(u64));
+
/**
* struct netconsole_target - Represents a configured netconsole target.
* @list: Links this target into the target_list.
@@ -97,6 +104,7 @@ static struct console netconsole_ext;
* @userdata_group: Links to the userdata configfs hierarchy
* @userdata_complete: Cached, formatted string of append
* @userdata_length: String length of userdata_complete
+ * @stats: Packet send stats for the target. Used for debugging.
* @enabled: On / off knob to enable / disable target.
* Visible from userspace (read-write).
* We maintain a strict 1:1 correspondence between this and
@@ -124,6 +132,7 @@ struct netconsole_target {
char userdata_complete[MAX_USERDATA_ENTRY_LENGTH * MAX_USERDATA_ITEMS];
size_t userdata_length;
#endif
+ struct netconsole_target_stats stats;
bool enabled;
bool extended;
bool release;
@@ -262,6 +271,7 @@ static void netconsole_process_cleanups_core(void)
* | remote_ip
* | local_mac
* | remote_mac
+ * | transmit_errors
* | userdata/
* | <key>/
* | value
@@ -371,6 +381,21 @@ static ssize_t remote_mac_show(struct config_item *item, char *buf)
return sysfs_emit(buf, "%pM\n", to_target(item)->np.remote_mac);
}
+static ssize_t transmit_errors_show(struct config_item *item, char *buf)
+{
+ struct netconsole_target *nt = to_target(item);
+ u64 xmit_drop_count, enomem_count;
+ unsigned int start;
+
+ do {
+ start = u64_stats_fetch_begin(&nt->stats.syncp);
+ xmit_drop_count = u64_stats_read(&nt->stats.xmit_drop_count);
+ enomem_count = u64_stats_read(&nt->stats.enomem_count);
+ } while (u64_stats_fetch_retry(&nt->stats.syncp, start));
+
+ return sysfs_emit(buf, "%llu\n", xmit_drop_count + enomem_count);
+}
+
/*
* This one is special -- targets created through the configfs interface
* are not enabled (and the corresponding netpoll activated) by default.
@@ -842,6 +867,7 @@ CONFIGFS_ATTR(, remote_ip);
CONFIGFS_ATTR_RO(, local_mac);
CONFIGFS_ATTR(, remote_mac);
CONFIGFS_ATTR(, release);
+CONFIGFS_ATTR_RO(, transmit_errors);
static struct configfs_attribute *netconsole_target_attrs[] = {
&attr_enabled,
@@ -854,6 +880,7 @@ static struct configfs_attribute *netconsole_target_attrs[] = {
&attr_remote_ip,
&attr_local_mac,
&attr_remote_mac,
+ &attr_transmit_errors,
NULL,
};
@@ -1058,6 +1085,34 @@ static struct notifier_block netconsole_netdev_notifier = {
.notifier_call = netconsole_netdev_event,
};
+/**
+ * netpoll_send_udp_count_errs - Wrapper for netpoll_send_udp that counts errors
+ * @nt: target to send message to
+ * @msg: message to send
+ * @len: length of message
+ *
+ * Calls netpoll_send_udp and classifies the return value. If an error
+ * occurred it increments statistics in nt->stats accordingly.
+ * Only calls netpoll_send_udp if CONFIG_NETCONSOLE_DYNAMIC is disabled.
+ */
+static void netpoll_send_udp_count_errs(struct netconsole_target *nt,
+ const char *msg, int len)
+{
+ int result = netpoll_send_udp(&nt->np, msg, len);
+
+ if (IS_ENABLED(CONFIG_NETCONSOLE_DYNAMIC)) {
+ if (result == NET_XMIT_DROP) {
+ u64_stats_update_begin(&nt->stats.syncp);
+ u64_stats_inc(&nt->stats.xmit_drop_count);
+ u64_stats_update_end(&nt->stats.syncp);
+ } else if (result == -ENOMEM) {
+ u64_stats_update_begin(&nt->stats.syncp);
+ u64_stats_inc(&nt->stats.enomem_count);
+ u64_stats_update_end(&nt->stats.syncp);
+ }
+ }
+}
+
static void send_msg_no_fragmentation(struct netconsole_target *nt,
const char *msg,
int msg_len,
@@ -1085,7 +1140,7 @@ static void send_msg_no_fragmentation(struct netconsole_target *nt,
MAX_PRINT_CHUNK - msg_len,
"%s", userdata);
- netpoll_send_udp(&nt->np, buf, msg_len);
+ netpoll_send_udp_count_errs(nt, buf, msg_len);
}
static void append_release(char *buf)
@@ -1178,7 +1233,7 @@ static void send_fragmented_body(struct netconsole_target *nt, char *buf,
this_offset += this_chunk;
}
- netpoll_send_udp(&nt->np, buf, this_header + this_offset);
+ netpoll_send_udp_count_errs(nt, buf, this_header + this_offset);
offset += this_offset;
}
}
@@ -1288,7 +1343,7 @@ static void write_msg(struct console *con, const char *msg, unsigned int len)
tmp = msg;
for (left = len; left;) {
frag = min(left, MAX_PRINT_CHUNK);
- netpoll_send_udp(&nt->np, tmp, frag);
+ netpoll_send_udp_count_errs(nt, tmp, frag);
tmp += frag;
left -= frag;
}
--
2.43.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net-next v4 2/2] netcons: Add udp send fail statistics to netconsole
2024-10-27 19:59 ` [PATCH net-next v4 2/2] netcons: Add udp send fail statistics to netconsole Maksym Kutsevol
@ 2024-10-28 10:45 ` Breno Leitao
2024-10-31 1:49 ` Jakub Kicinski
1 sibling, 0 replies; 8+ messages in thread
From: Breno Leitao @ 2024-10-28 10:45 UTC (permalink / raw)
To: Maksym Kutsevol
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Jonathan Corbet, Andrew Lunn, netdev, linux-kernel,
linux-doc
On Sun, Oct 27, 2024 at 12:59:42PM -0700, Maksym Kutsevol wrote:
> Enhance observability of netconsole. Packet sends can fail.
> Start tracking at least two failure possibilities: ENOMEM and
> NET_XMIT_DROP for every target. Stats are exposed via an additional
> attribute in CONFIGFS.
>
> The exposed statistics allows easier debugging of cases when netconsole
> messages were not seen by receivers, eliminating the guesswork if the
> sender thinks that messages in question were sent out.
>
> Stats are not reset on enable/disable/change remote ip/etc, they
> belong to the netcons target itself.
>
> Reported-by: Breno Leitao <leitao@debian.org>
> Closes: https://lore.kernel.org/all/ZsWoUzyK5du9Ffl+@gmail.com/
> Signed-off-by: Maksym Kutsevol <max@kutsevol.com>
Reviewed-by: Breno Leitao <leitao@debian.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next v4 1/2] netpoll: Make netpoll_send_udp return status instead of void
2024-10-27 19:59 ` [PATCH net-next v4 1/2] netpoll: Make netpoll_send_udp return status instead of void Maksym Kutsevol
@ 2024-10-28 10:45 ` Breno Leitao
0 siblings, 0 replies; 8+ messages in thread
From: Breno Leitao @ 2024-10-28 10:45 UTC (permalink / raw)
To: Maksym Kutsevol
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Jonathan Corbet, Andrew Lunn, netdev, linux-kernel,
linux-doc
On Sun, Oct 27, 2024 at 12:59:41PM -0700, Maksym Kutsevol wrote:
> netpoll_send_udp can return if send was successful.
> It will allow client code to be aware of the send status.
>
> Possible return values are the result of __netpoll_send_skb (cast to int)
> and -ENOMEM. This doesn't cover the case when TX was not successful
> instantaneously and was scheduled for later, __netpoll__send_skb returns
> success in that case.
>
> Signed-off-by: Maksym Kutsevol <max@kutsevol.com>
Reviewed-by: Breno Leitao <leitao@debian.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next v4 2/2] netcons: Add udp send fail statistics to netconsole
2024-10-27 19:59 ` [PATCH net-next v4 2/2] netcons: Add udp send fail statistics to netconsole Maksym Kutsevol
2024-10-28 10:45 ` Breno Leitao
@ 2024-10-31 1:49 ` Jakub Kicinski
2024-11-01 1:19 ` Maksym Kutsevol
1 sibling, 1 reply; 8+ messages in thread
From: Jakub Kicinski @ 2024-10-31 1:49 UTC (permalink / raw)
To: Maksym Kutsevol
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Jonathan Corbet, Andrew Lunn, Breno Leitao, netdev, linux-kernel,
linux-doc
On Sun, 27 Oct 2024 12:59:42 -0700 Maksym Kutsevol wrote:
> +struct netconsole_target_stats {
> + u64_stats_t xmit_drop_count;
> + u64_stats_t enomem_count;
> + struct u64_stats_sync syncp;
> +} __aligned(2 * sizeof(u64));
Why the alignment?
> +static void netpoll_send_udp_count_errs(struct netconsole_target *nt,
> + const char *msg, int len)
This is defined in the netconsole driver, it should not use the
netpoll_ prefix for the function name.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next v4 2/2] netcons: Add udp send fail statistics to netconsole
2024-10-31 1:49 ` Jakub Kicinski
@ 2024-11-01 1:19 ` Maksym Kutsevol
2024-11-01 1:49 ` Jakub Kicinski
0 siblings, 1 reply; 8+ messages in thread
From: Maksym Kutsevol @ 2024-11-01 1:19 UTC (permalink / raw)
To: Jakub Kicinski
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Jonathan Corbet, Andrew Lunn, Breno Leitao, netdev, linux-kernel,
linux-doc
On Wed, Oct 30, 2024 at 9:49 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Sun, 27 Oct 2024 12:59:42 -0700 Maksym Kutsevol wrote:
> > +struct netconsole_target_stats {
> > + u64_stats_t xmit_drop_count;
> > + u64_stats_t enomem_count;
> > + struct u64_stats_sync syncp;
> > +} __aligned(2 * sizeof(u64));
>
> Why the alignment?
Hi Jakub,
Thanks for looking into this!
Parroting examples, e.g.
struct pcpu_lstats {
u64_stats_t packets;
u64_stats_t bytes;
struct u64_stats_sync syncp;
} __aligned(2 * sizeof(u64));
in netdevice.h https://github.com/torvalds/linux/blob/master/include/linux/netdevice.h#L2743-L2747
I don't have any strongly held opinion about this. I'd appreciate an
explanation (a link would suffice) why this is a bad idea.
> > +static void netpoll_send_udp_count_errs(struct netconsole_target *nt,
> > + const char *msg, int len)
>
> This is defined in the netconsole driver, it should not use the
> netpoll_ prefix for the function name.'
netconsole_send_udp_count_errs sounds better?
Regards,
Maksym
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next v4 2/2] netcons: Add udp send fail statistics to netconsole
2024-11-01 1:19 ` Maksym Kutsevol
@ 2024-11-01 1:49 ` Jakub Kicinski
0 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2024-11-01 1:49 UTC (permalink / raw)
To: Maksym Kutsevol
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Jonathan Corbet, Andrew Lunn, Breno Leitao, netdev, linux-kernel,
linux-doc
On Thu, 31 Oct 2024 21:19:26 -0400 Maksym Kutsevol wrote:
> Thanks for looking into this!
>
> Parroting examples, e.g.
> struct pcpu_lstats {
> u64_stats_t packets;
> u64_stats_t bytes;
> struct u64_stats_sync syncp;
> } __aligned(2 * sizeof(u64));
>
> in netdevice.h https://github.com/torvalds/linux/blob/master/include/linux/netdevice.h#L2743-L2747
> I don't have any strongly held opinion about this. I'd appreciate an
> explanation (a link would suffice) why this is a bad idea.
No entirely sure why the pcpu stats in netdev are aligned like this,
but yours are not per cpu, and not fast path of any sort. So aligning
is a premature optimization in the first place.
> > > +static void netpoll_send_udp_count_errs(struct netconsole_target *nt,
> > > + const char *msg, int len)
> >
> > This is defined in the netconsole driver, it should not use the
> > netpoll_ prefix for the function name.'
>
> netconsole_send_udp_count_errs sounds better?
I don't think the _count_errs() suffix is needed any more
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-11-01 1:49 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-27 19:59 [PATCH net-next v4 0/2] netcons: Add udp send fail statistics to netconsole Maksym Kutsevol
2024-10-27 19:59 ` [PATCH net-next v4 1/2] netpoll: Make netpoll_send_udp return status instead of void Maksym Kutsevol
2024-10-28 10:45 ` Breno Leitao
2024-10-27 19:59 ` [PATCH net-next v4 2/2] netcons: Add udp send fail statistics to netconsole Maksym Kutsevol
2024-10-28 10:45 ` Breno Leitao
2024-10-31 1:49 ` Jakub Kicinski
2024-11-01 1:19 ` Maksym Kutsevol
2024-11-01 1:49 ` Jakub Kicinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).