From: Mike Waychison <mikew@google.com>
To: simon.kagstrom@netinsight.net, davem@davemloft.net,
nhorman@tuxdriver.com, Matt Mackall <mpm@selenic.com>
Cc: adurbin@google.com, linux-kernel@vger.kernel.org,
chavey@google.com, "Greg KH" <greg@kroah.com>,
"Américo Wang" <xiyou.wangcong@gmail.com>,
akpm@linux-foundation.org, linux-api@vger.kernel.org
Subject: [PATCH v2 19/23] netoops: add core functionality
Date: Mon, 08 Nov 2010 12:33:29 -0800 [thread overview]
Message-ID: <20101108203328.22479.53815.stgit@crlf.mtv.corp.google.com> (raw)
In-Reply-To: <20101108203120.22479.19708.stgit@crlf.mtv.corp.google.com>
The kernel network dumper provides information about a crashed machine
on the network.
On a crash, the kernel spits out the contents of the kernel message buffer
along with a few other useful tidbits of information via netpoll UDP.
Each packet is sent a total of three times to deal with packet loss on the
connection. Furthermore a small amount critical data is present in every
packet, so even if only a single packet gets through, we still witness the
crash. In the same vein, we send packet in reverse order to handle cases where
the kernel fatally crashes before transmission can be completed because often
the most interesting bits of a crash can be found in the tail of the log.
Configuration of the netoops device currently uses the same mechanism as
netpoll, that is, it uses a directory in configfs called "netpoll" that
users can create new targets. It also supports targets as a module
parameter and as a kernel command line when built in.
Signed-off-by: Mike Waychison <mikew@google.com>
---
Changelog:
- v2
- Now uses netpoll_targets abstracted from netconsole.
- As a side effect, we now don't have to hardcode port numbers; they
are user overridable.
- Compiles as a module in this patch.
Notes:
The packet format described in this and subsequent patches currently represent
the packet format used by Google. It is _not_ generally applicable though, as
it does contain several fields that are x86 specific. I've included them here
nevertheless to foster discussion as to how best to abstract this sort of
information away.
In this commit, there are several fields that are marked "__reserved*" in the
packet header. These are replaced with actual definitions in later commits.
---
drivers/net/Kconfig | 10 ++
drivers/net/Makefile | 1
drivers/net/netoops.c | 235 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 246 insertions(+), 0 deletions(-)
create mode 100644 drivers/net/netoops.c
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index b014cd6..0aa8dfc 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -3382,6 +3382,16 @@ config NETCONSOLE_DYNAMIC
at runtime through a userspace interface exported using configfs.
See <file:Documentation/networking/netconsole.txt> for details.
+config NETOOPS
+ tristate "Network oops support"
+ depends on PROC_FS
+ select NETPOLL_TARGETS_DYNAMIC
+ help
+ This option enables the ability to have the kernel logs emitted on
+ the network when a machine Oopses or Panics. Configuration of this
+ option is done at runtime by configuring a destination IP address.
+ If unsure, say N.
+
config NETPOLL
def_bool false
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 652fc6b..5285e18 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -288,6 +288,7 @@ obj-$(CONFIG_ETRAX_ETHERNET) += cris/
obj-$(CONFIG_ENP2611_MSF_NET) += ixp2000/
obj-$(CONFIG_NETCONSOLE) += netconsole.o
+obj-$(CONFIG_NETOOPS) += netoops.o
obj-$(CONFIG_FS_ENET) += fs_enet/
diff --git a/drivers/net/netoops.c b/drivers/net/netoops.c
new file mode 100644
index 0000000..dc1ee97
--- /dev/null
+++ b/drivers/net/netoops.c
@@ -0,0 +1,235 @@
+/*
+ * drivers/net/netoops.c
+ * Copyright (C) 2004 and beyond Google Inc.
+ *
+ * Original Author Ross Biro
+ * Revisions Rebecca Schultz
+ * Cleaned up by Mike Waychison <mikew@google.com>
+ *
+ * This is very simple code to use the polling
+ * mode of the network drivers to send the
+ * contents of the printk buffer via udp w/o
+ * checksum to a unicast address.
+ */
+
+#include <linux/in.h>
+#include <linux/notifier.h>
+#include <linux/kernel.h>
+#include <linux/netpoll.h>
+#include <linux/nmi.h>
+#include <linux/utsname.h>
+#include <linux/watchdog.h>
+#include <linux/kobject.h>
+#include <linux/sysfs.h>
+#include <linux/kmsg_dump.h>
+#include <linux/netpoll_targets.h>
+
+#define NETOOPS_TYPE_PRINTK_BUFFER 1
+#define NETOOPS_TYPE_PRINTK_BUFFER_SOFT 3
+#define NETOOPS_VERSION 0x0002
+#define NETOOPS_PORT 2004
+#define NETOOPS_RETRANSMIT_COUNT 3
+
+#if defined(__i386__) || defined(__x86_64__)
+#define NETOOPS_ARCH 2
+#else
+#error "unsupported architecture"
+#endif
+
+#define MAX_PARAM_LENGTH 256
+
+static DEFINE_NETPOLL_TARGETS(targets);
+
+static char __initdata config[MAX_PARAM_LENGTH];
+module_param_string(netoops, config, MAX_PARAM_LENGTH, 0);
+MODULE_PARM_DESC(netoops, " netoops=[src-port]@[src-ip]/[dev],[tgt-port]@<tgt-ip>/[tgt-macaddr]");
+
+#ifndef MODULE
+static int __init option_setup(char *opt)
+{
+ strlcpy(config, opt, MAX_PARAM_LENGTH);
+ return 1;
+}
+__setup("netoops=", option_setup);
+#endif /* MODULE */
+
+
+#define NETOOPS_DATA_BYTES 1024
+
+struct netoops_msg {
+ struct {
+ u16 version; /* MUST be @ offset 0 */
+ /*
+ * Size of this header before data[] starts.
+ */
+ u16 header_size;
+ u16 arch;
+ u16 dump_id; /* MUST be @ offset 6 */
+ u16 type;
+ u32 packet_count;
+ u32 packet_no;
+ u32 __reserved1;
+ u8 __reserved2;
+ u8 __reserved3;
+ u8 __reserved4;
+ /*
+ * NOTE: fixed length strings for a packet. NULL
+ * termination not required.
+ */
+ char kernel_version[64];
+ char __reserved5[64];
+ char __reserved6[64];
+ } __attribute__ ((packed)) header;
+ char data[NETOOPS_DATA_BYTES];
+} __attribute__ ((packed));
+
+static struct netoops_msg msg;
+
+static void setup_packet_header(int packet_count, int soft_dump)
+{
+ msg.header.version = NETOOPS_VERSION;
+ msg.header.arch = NETOOPS_ARCH;
+ msg.header.type = soft_dump ? NETOOPS_TYPE_PRINTK_BUFFER_SOFT :
+ NETOOPS_TYPE_PRINTK_BUFFER;
+ msg.header.dump_id = (jiffies/HZ) & 0xffff;
+ msg.header.packet_count = packet_count;
+ msg.header.header_size = sizeof(msg.header);
+ strncpy(msg.header.kernel_version,
+ utsname()->release,
+ min(sizeof(msg.header.kernel_version),
+ sizeof(utsname()->release)));
+}
+
+static int packet_count_from_length(unsigned long l)
+{
+ return (l + NETOOPS_DATA_BYTES - 1) / NETOOPS_DATA_BYTES;
+}
+
+/* Send the packet to all targets */
+static void netoops_send_packet(int packet_nr)
+{
+ struct netpoll_target *nt;
+
+ msg.header.packet_no = packet_nr;
+
+ list_for_each_entry(nt, &targets.list, list) {
+ if (nt->np_state == NETPOLL_ENABLED
+ && netif_running(nt->np.dev)) {
+ netpoll_send_udp(&nt->np, (char *)&msg, sizeof(msg));
+ }
+ }
+
+}
+
+/*
+ * Send the passed in segment of kmsg via netpoll. Packets are sent in reverse
+ * order, with the tail packet (the first one transmitted) zero-padded.
+ */
+static void netoops_send_segment(int packet_offset,
+ const char *s, unsigned long l)
+{
+ int packet_count = packet_count_from_length(l);
+ size_t data_length;
+ int i;
+
+ for (i = packet_count - 1; i >= 0; i--) {
+ /* Usually messages completely fill the data field */
+ data_length = NETOOPS_DATA_BYTES;
+ if (i == packet_count - 1) {
+ /* Except the tail packet, which is zero-padded */
+ data_length = l % NETOOPS_DATA_BYTES;
+ memset(msg.data + data_length, 0,
+ NETOOPS_DATA_BYTES - data_length);
+ }
+ BUG_ON(data_length > NETOOPS_DATA_BYTES);
+
+ /* Copy the payload into the packet and send */
+ memcpy(msg.data, s + (i * NETOOPS_DATA_BYTES), data_length);
+ netoops_send_packet((packet_count - i - 1) + packet_offset);
+
+ touch_nmi_watchdog();
+ }
+}
+
+/*
+ * Callback used by the kmsg_dumper.
+ *
+ * Called with interrupts disabled locally.
+ */
+static void netoops(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason,
+ struct pt_regs *regs,
+ const char *s1, unsigned long l1,
+ const char *s2, unsigned long l2) {
+ unsigned long flags;
+ int packet_count_1, packet_count_2;
+ int soft_dump = 0;
+ int i;
+
+ /* Only handle fatal problems */
+ if (reason != KMSG_DUMP_OOPS
+ && reason != KMSG_DUMP_PANIC
+ && reason != KMSG_DUMP_SOFT)
+ return;
+
+ if (reason == KMSG_DUMP_SOFT)
+ soft_dump = 1;
+
+ spin_lock_irqsave(&targets.lock, flags);
+
+ /* compute total length of the message we are going to send */
+ packet_count_1 = packet_count_from_length(l1);
+ packet_count_2 = packet_count_from_length(l2);
+
+ /* setup the non varying parts of the message */
+ memset(&msg, 0, sizeof(msg));
+ setup_packet_header(packet_count_1 + packet_count_2, soft_dump);
+
+ /* Transmission loop */
+ for (i = 0; i < NETOOPS_RETRANSMIT_COUNT; i++) {
+ /* Send the full packets from the second segment */
+ netoops_send_segment(0, s2, l2);
+ netoops_send_segment(packet_count_2, s1, l1);
+ }
+
+ spin_unlock_irqrestore(&targets.lock, flags);
+}
+
+static struct kmsg_dumper netoops_dumper = {
+ .dump = netoops,
+};
+
+static int __init netoops_init(void)
+{
+ int retval = -EINVAL;
+
+ BUILD_BUG_ON(offsetof(struct netoops_msg, header.version) != 0);
+ BUILD_BUG_ON(offsetof(struct netoops_msg, header.dump_id) != 6);
+
+ targets.default_local_port = NETOOPS_PORT;
+ targets.default_remote_port = NETOOPS_PORT;
+
+ config[MAX_PARAM_LENGTH - 1] = '\0';
+ retval = register_netpoll_targets("netoops", &targets, config);
+ if (retval)
+ goto out;
+
+ retval = kmsg_dump_register(&netoops_dumper);
+ if (retval)
+ goto out_targets;
+
+ return 0;
+out_targets:
+ unregister_netpoll_targets(&targets);
+out:
+ return retval;
+}
+
+static void __exit netoops_exit(void)
+{
+ kmsg_dump_unregister(&netoops_dumper);
+ unregister_netpoll_targets(&targets);
+}
+
+module_init(netoops_init);
+module_exit(netoops_exit);
+MODULE_LICENSE("GPL");
next prev parent reply other threads:[~2010-11-08 20:34 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-08 20:31 [PATCH v2 00/23] netoops support Mike Waychison
2010-11-08 20:31 ` [PATCH v2 01/23] netconsole: Remove unneeded reference counting Mike Waychison
2010-11-08 20:31 ` [PATCH v2 02/23] netconsole: Introduce locking over the netpoll fields Mike Waychison
2010-11-08 20:31 ` [PATCH v2 03/23] netconsole: Introduce 'enabled' state-machine Mike Waychison
2010-11-08 20:32 ` [PATCH v2 04/23] netconsole: Call netpoll_cleanup() in process context Mike Waychison
2010-11-09 12:07 ` Neil Horman
2010-11-09 17:18 ` Mike Waychison
2010-11-09 19:33 ` Neil Horman
2010-11-08 20:32 ` [PATCH v2 05/23] netconsole: Wrap the list and locking in a structure Mike Waychison
2010-11-08 20:32 ` [PATCH v2 06/23] netconsole: Push configfs_subsystem into netpoll_targets Mike Waychison
2010-11-08 20:32 ` [PATCH v2 07/23] netconsole: Move netdev_notifier " Mike Waychison
2010-11-08 20:32 ` [PATCH v2 08/23] netconsole: Split out netpoll_targets init/exit Mike Waychison
2010-11-08 20:32 ` [PATCH v2 09/23] netconsole: Add pointer to netpoll_targets Mike Waychison
2010-11-08 20:32 ` [PATCH v2 10/23] netconsole: Rename netconsole_target -> netpoll_target Mike Waychison
2010-11-08 20:32 ` [PATCH v2 11/23] netconsole: Abstract away the subsystem name Mike Waychison
2010-11-08 20:32 ` [PATCH v2 12/23] netpoll: Introduce netpoll_target configs Mike Waychison
2010-11-09 3:30 ` Américo Wang
2010-11-09 4:27 ` Américo Wang
2010-11-09 8:34 ` Mike Waychison
2010-11-09 9:06 ` Américo Wang
2010-11-09 9:38 ` [RFC PATCH] configfs: make it not be a module any more Américo Wang
2010-11-09 14:20 ` [PATCH v2 12/23] netpoll: Introduce netpoll_target configs Greg KH
2010-11-09 17:24 ` Mike Waychison
2010-11-09 17:27 ` Greg KH
2010-11-08 20:32 ` [PATCH v2 13/23] netconsole: Move setting of default ports Mike Waychison
2010-11-08 20:32 ` [PATCH v2 14/23] netpoll: Move target code into netpoll_targets.c Mike Waychison
2010-11-08 20:33 ` [PATCH v2 15/23] Oops: Pass regs to oops_exit() Mike Waychison
2010-11-08 20:33 ` [PATCH v2 16/23] kmsg_dumper: Pass pt_regs along to dumpers Mike Waychison
2010-11-08 20:33 ` [PATCH v2 17/23] kmsg_dumper: Introduce a new 'SOFT' dump reason Mike Waychison
2010-11-09 5:49 ` KOSAKI Motohiro
2010-11-09 5:54 ` KOSAKI Motohiro
2010-11-08 20:33 ` [PATCH v2 18/23] sys-rq: Add option to soft dump Mike Waychison
2010-11-08 21:09 ` Randy Dunlap
2010-11-08 22:27 ` Mike Waychison
2010-11-08 22:31 ` Randy Dunlap
2010-11-08 20:33 ` Mike Waychison [this message]
2010-11-08 20:33 ` [PATCH v2 20/23] netoops: Add x86 specific bits to packet headers Mike Waychison
2010-11-09 14:22 ` Neil Horman
2010-11-09 17:56 ` Mike Waychison
2010-11-08 20:33 ` [PATCH v2 21/23] netoops: Add user programmable fields to the netoops packet Mike Waychison
2010-11-08 20:33 ` [PATCH v2 22/23] netoops: Add one-shot mode Mike Waychison
2010-11-08 20:33 ` [PATCH v2 23/23] netoops: Add an interface to trigger various types of crashes Mike Waychison
2010-11-08 20:55 ` [PATCH v2 00/23] netoops support Matt Mackall
2010-11-08 21:20 ` David Miller
2010-11-08 21:43 ` Mike Waychison
2010-11-09 1:28 ` Andi Kleen
2010-11-09 4:25 ` Américo Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101108203328.22479.53815.stgit@crlf.mtv.corp.google.com \
--to=mikew@google.com \
--cc=adurbin@google.com \
--cc=akpm@linux-foundation.org \
--cc=chavey@google.com \
--cc=davem@davemloft.net \
--cc=greg@kroah.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mpm@selenic.com \
--cc=nhorman@tuxdriver.com \
--cc=simon.kagstrom@netinsight.net \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome