2.6 must-fix list - kernel error reporting
Subsystems (2)
RFC PATCH 1/2 2.6 must-fix list - kernel error reporting
Andrew Morton's 2.6 must-fix list includes the following item:
Quoted 4 lines
o We need a kernel side API for reporting error events to userspace (could be async to 2.6 itself)
(Prototype core based on netlink exists)
The enclosed patches provide a mechanism for reporting error events to user-mode applications via netlink. This mechanism supplements the text-oriented printk mechanism, providing a way to log binary data or a mixture of text+binary.
Patch #1, closely based on a prototype by Dave Miller, implements the NETLINK_KERROR protocol for AF_NETLINK sockets. It provides two functions for broadcasting data packets to user-mode applications:
in one, the caller provides a single data buffer, and in the other, the caller provides an iovec[].
Patch #2 (see accompanying post) provides an API built on patch #1's infrastructure. Patch #2's functions capture context about the error (e.g., driver/module, severity level, in interrupt or not, pid/uid/gid, CPU ID), pack this information into a header, add the error-specific data, and send the resulting packet via netlink. The two principal functions are:
- evl_write(), which accepts an arbitrarily defined buffer of error-specific data; and
- evl_printf(), which accepts a format string plus args, printk-style. Rather than combining the format and args, evl_printf() keeps them separate, as various developers have suggested. Thus the receiving application can easily determine both the type of error (as indicated by the raw format string) and the args' values, without parsing the message string.
Applications that respond to kernel errors can establish AF_NETLINK/NETLINK_KERROR sockets and receive the error packets directly; or they can register with an event subsystem (e.g., see evlog.sourceforge.net), which will deliver events that match specific criteria.
These patches are posted on evlog.sourceforge.net. (Click on "Latest Release"; then scroll down to "evlog-2.5_kernel/evlog + netlink". Or just follow the links posted below.) Also posted there is a tar file, kerrord.tar.gz, which contains:
- a sample module that logs errors using evl_write() and evl_printf(); and
- a sample daemon that reads such errors from netlink and logs them.
Jim Keniston
IBM Linux Technology Center
http://prdownloads.sourceforge.net/evlog/kerror-2.5.74.patch?download
http://prdownloads.sourceforge.net/evlog/evlog-2.5.74.patch?download
http://prdownloads.sourceforge.net/evlog/kerrord.tar.gz?download
-----
include/linux/kerror.h +27 -0
@@ -0,0 +1,27 @@ +#ifndef _KERROR_H +#define _KERROR_H + +#ifdef __KERNEL__ +#include <linux/config.h> +#include <linux/uio.h> +#include <asm/types.h> + +#ifdef CONFIG_NET +extern int kernel_error_event (void *data,size_t len,__u32 groups); +extern int kernel_error_event_iov (const struct iovec *iov, +unsigned int nseg,__u32 groups); +#else +static inline int kernel_error_event (void *data,size_t len,__u32 groups) + {return -ENOSYS ; } +static inline int kernel_error_event_iov (const struct iovec *iov, +unsigned int nseg,__u32 groups) + {return -ENOSYS ; } +#endif /* CONFIG_NET */ +#endif /* __KERNEL__ */ + +#define KERROR_GROUP_RAW 0x00000001 +#define KERROR_GROUP_EVLOG 0x00000002 + +#define KERROR_GROUP_ALL (~(u32)0) + +#endif /* _KERROR_H */
include/linux/netlink.h +1 -0
@@ -10,6 +10,7 @@#define NETLINK_TCPDIAG 4/* TCP socket monitoring */ #define NETLINK_NFLOG 5/* netfilter/iptables ULOG */ #define NETLINK_XFRM 6/* ipsec */ +#define NETLINK_KERROR 7/* kernel error event facility */ #define NETLINK_ARPD 8#define NETLINK_ROUTE6 11/* af_inet6 route comm channel */ #define NETLINK_IP6_FW 13
net/netlink/Makefile +1 -1
@@ -2,5 +2,5 @@ # Makefile for the netlink driver. # -obj-y := af_netlink.o +obj-y := af_netlink.o kerror.o obj-$(CONFIG_NETLINK_DEV) += netlink_dev.o
net/netlink/kerror.c +110 -0
110 lines not on this page · raw message
net/netsyms.c +3 -0
@@ -83,6 +83,7 @@#endif #include <linux/rtnetlink.h> +#include <linux/kerror.h> #ifdef CONFIG_IPX_MODULE extern struct datalink_proto *make_EII_client (void );
@@ -505,6 +506,8 @@EXPORT_SYMBOL (netlink_set_nonroot);EXPORT_SYMBOL (netlink_register_notifier);EXPORT_SYMBOL (netlink_unregister_notifier); +EXPORT_SYMBOL (kernel_error_event); +EXPORT_SYMBOL (kernel_error_event_iov);#if defined(CONFIG_NETLINK_DEV ) || defined(CONFIG_NETLINK_DEV_MODULE )EXPORT_SYMBOL (netlink_attach);EXPORT_SYMBOL (netlink_detach);
Quoted 3 lines · Jim Keniston
The enclosed patches provide a mechanism for reporting error events to user-mode applications via netlink.
Seems sane to me.
It needs to handle %z as well as %Z.
The layout of `struct kern_log_entry' may be problematic. Think of the situation where a 64-bit kernel constructs one of these and sends it up to 32-bit userspace. Will the structure layout be the same under the 32-bit compiler as under the 64-bit one?
How do you actually intend to use this? Will it be by adding new evt_printf() calls to particular drivers, or replacing existing printk's or both?
Would it make sense for evt_printf() to fall back to printk() if nobody is listening to the log stream?
Quoted 9 lines · Andrew Morton
Quoted 3 lines · Jim Keniston
The enclosed patches provide a mechanism for reporting error events to user-mode applications via netlink.
Seems sane to me.
It needs to handle %z as well as %Z.
Yes, thanks. I missed that change to vsnprintf().
Quoted 5 lines
The layout of `struct
kern_log_entry' may be problematic. Think of the situation where a 64-bit kernel constructs one of these and sends it up to 32-bit userspace. Will the structure layout be the same under the 32-bit compiler as under the 64-bit one?
I think so. Nothing is bigger than 4 bytes except log_facility[] (16-byte array of char, which doesn't induce padding at all on i386). But I will find a 64K/32U ppc machine and check that.
Quoted 2 lines
How do you actually intend to use this?
I envision it being used by a configuration/status-monitoring system that monitors hotplug events, sysfs, etc. for configuration changes, and listens to the proposed interface for error events. Binary-only events (logged with evl_write()) would have to be interpreted based on knowledge existing entirely in user space (either coded into the monitor program, or provided as supplementary information via a formatting template or some such). PRINTF-format events can carry and/or be supplemented with similar info, but have the error message built in.
Quoted 3 lines
Will it be by adding new
evt_printf()calls to particular drivers, or replacing existing printk's or both?
There have been a variety of suggestions for how error reporting could be improved. Two common ones are:
1. Leave printks alone, and log additional info in whatever format you want via netlink. (E.g., Dave Miller recommended something like this.) This proposal supports that.
2. Migrate from raw printks to "smarter" versions -- e.g., dev_printk and friends, or the proposed netdev_printk. Such macros now call just printk (after adding relevant info), but could be modified to call evl_printk as well with the same args.
There are a zillion variations on this, of course...
Quoted 3 lines
Would it make sense for
evt_printf()to fall back toprintk()if nobody is listening to the log stream?
That certainly makes sense for evl_printf. For evl_write, just do a hex dump or something. So evlog.c would query kerror.c to see if anybody's listening. Would kerror.c consult nl_table[] directly, or is there an anybody_listening() function that does this?
Jim
If you're going to reply to this, please change "[email protected]" to "[email protected]" in your cc list. My apologies for the error.
Jim
On Tue, 8 Jul 2003, Jim Keniston wrote:
+ kerror_nl = netlink_kernel_create(NETLINK_KERROR, kerror_netlink_rcv);
+ if (kerror_nl == NULL)
+ panic("kerror_init: cannot initialize kerror_nl\n");
You can simply use NULL instead of passing the dummy kerror_netlink_rcv function.
+struct kern_log_entry {
+ __u16 log_kmagic; /* always LOGREC_KMAGIC */ + __u16 log_kversion; /* which version of this struct? */ + char log_facility[FACILITY_MAXLEN]; /* e.g., driver name */
These fields should generally be specified in ascending order to help with alignment.
It may also be worth looking at how the ULOG code batches messages to improve peformance.
- James
Signature · 2 lines
James Morris <[email protected]>
Quoted 9 lines · James Morris
On Tue, 8 Jul 2003, Jim Keniston wrote:
net/netlink/kerror.c +3
-0+ kerror_nl =netlink_kernel_create (NETLINK_KERROR , kerror_netlink_rcv); +if (kerror_nl ==NULL ) +panic ("kerror_init: cannot initialize kerror_nl\n" );You can simply use NULL instead of passing the dummy
kerror_netlink_rcvfunction.
That begs the question: do we trust that nobody but the kernel will send packets to a NETLINK_KERROR socket? Ordinary users can't, but any root application can. Without kerror_netlink_rcv(), such packets don't get dequeued.
Quoted 8 lines
(quoted diff) +4
-0+struct kern_log_entry { + __u16 log_kmagic; /* always LOGREC_KMAGIC */ + __u16 log_kversion; /* which version of this struct? */ + char log_facility[FACILITY_MAXLEN]; /* e.g., driver name */These fields should generally be specified in ascending order to help with alignment.
We include log_kmagic and log_kversion so the receiving app (e.g. the evlog daemon) can figure out which version of the kernel header it's getting. Note that we're up to #3 (going on #4, with the changes you and others have suggested). As long as we have to include log_kmagic and log_kversion, they need to be first.
That said, I get the impression that people would be more comfortable if log_facility[] were moved to the end. Other than that, can anybody point out a specific area where there's likely to be an alignment problem? The various members' offsets are the same on i386, ppc32, and ppc64. This should also be true for s390 and s390x. I'd think it'd really matter only when kernel and user on the same system are different architectures. ppc64K/ppc32U, at least, works.
Quoted 3 lines
It may also be worth looking at how the ULOG code batches messages to improve peformance.
Thanks for the pointer. Looks nice. If performance turns out to be an issue (e.g., if for some reason people want to cc all printk messages through this interface), I'll keep that in mind.
Quoted 5 lines
- James
--
James Morris
<[email protected]>
Jim K.
Quoted 8 lines · Jim Keniston
Quoted 7 lines · James Morris
On Tue, 8 Jul 2003, Jim Keniston wrote:
net/netlink/kerror.c +3
-0+ kerror_nl =netlink_kernel_create (NETLINK_KERROR , kerror_netlink_rcv); +if (kerror_nl ==NULL ) +panic ("kerror_init: cannot initialize kerror_nl\n" );
Quoted 7 lines
Quoted 2 lines
You can simply use NULL instead of passing the dummy
kerror_netlink_rcvfunction.That begs the question: do we trust that nobody but the kernel will send packets to a
NETLINK_KERRORsocket? Ordinary users can't, but any root application can. Withoutkerror_netlink_rcv(), such packets don't get dequeued.
Indeed, the kernel socket buffer fills up.
I think this needs to be addressed in the netlink code, per the patch below.
Comments?
- James
Signature · 17 lines
James Morris <[email protected]> diff -NurX dontdiff linux-2.5.75.orig/net/netlink/af_netlink.c linux-2.5.75.w1/net/netlink/af_netlink.c --- linux-2.5.75.orig/net/netlink/af_netlink.c 2003-06-26 12:43:45.000000000 +1000 +++ linux-2.5.75.w1/net/netlink/af_netlink.c 2003-07-12 01:23:49.708254261 +1000 @@ -430,6 +430,10 @@ goto no_dst; nlk = nlk_sk(sk); + /* Don't bother queuing skb if kernel socket has no input function */ + if (nlk->pid == 0 && !nlk->data_ready) + goto no_dst; + #ifdef NL_EMULATE_DEV if (nlk->handler) { skb_orphan(skb);
Quoted 11 lines · On Sat, 12 Jul 2003 01:37:44 +1000 (EST) James Morris…
Quoted 4 lines · Jim Keniston
That begs the question: do we trust that nobody but the kernel will send packets to a
NETLINK_KERRORsocket? Ordinary users can't, but any root application can. Withoutkerror_netlink_rcv(), such packets don't get dequeued.Indeed, the kernel socket buffer fills up.
I think this needs to be addressed in the netlink code, per the patch below.
Looks good, I'll apply this.
Quoted 4 lines · On Sat, 12 Jul 2003 01:37:44 +1000 (EST) James Morris…
Indeed, the kernel socket buffer fills up.
I think this needs to be addressed in the netlink code, per the patch below.
...
Review
Quoted 4 lines
(quoted diff) +4
-0+ /* Don't bother queuing skb if kernel socket has no input function */ + if (nlk->pid == 0 && !nlk->data_ready) + goto no_dst; +
Oops, turns out this doesn't work. data_ready is never NULL, look at how netlink_kernel_create() works.
Also, the broadcast case probably needs to be handled too?
As an aside, to be honest what's so wrong with the socket receive buffer filling up? The damage is limited to the receive buffer size of the kernel netlink socket, but that's it.
Quoted 7 lines · David S. Miller
Review
Quoted 4 lines
(quoted diff) +4
-0+ /* Don't bother queuing skb if kernel socket has no input function */ + if (nlk->pid == 0 && !nlk->data_ready) + goto no_dst; +Oops, turns out this doesn't work.
data_readyis never NULL, look at hownetlink_kernel_create()works.
It's ok: sk->data_ready is never null, but nlk_sk(sk)->data_ready will be null unless an input function is provided there.
Quoted 2 lines
Also, the broadcast case probably needs to be handled too?
Netlink sockets created by netlink_kernel_create() do not subscribe to any groups and are not broadcast to.
Quoted 3 lines
As an aside, to be honest what's so wrong with the socket receive buffer filling up? The damage is limited to the receive buffer size of the kernel netlink socket, but that's it.
Agreed, it's not really harmful, but it's sloppy. Better to let the application know that it can't send to the socket rather than let it keep sending (with successful return codes) until the kernel socket buffer fills up.
- James
Signature · 2 lines
James Morris <[email protected]>
Quoted 5 lines · On Sun, 13 Jul 2003 11:17:35 +1000 (EST) James Morris…
Quoted 2 lines · David S. Miller
Oops, turns out this doesn't work.
data_readyis never NULL, look at hownetlink_kernel_create()works.
Quoted 8 lines
It's ok:
sk->data_readyis never null, but nlk_sk(sk)->data_ready will be null unless an input function is provided there.Quoted 2 lines
Also, the broadcast case probably needs to be handled too?
Netlink sockets created by
netlink_kernel_create()do not subscribe to any groups and are not broadcast to.
Oops, you're right on both counts, I brainfarted here.
I'll apply your original patch, thanks.
PATCH 1/2 kernel error reporting (revised)
In reply to James MorrisQuoted 6 lines · Jim Keniston
Subject: [PATCH - RFC] [1/2] 2.6 must-fix list - kernel error reporting
Andrew Morton's 2.6 must-fix list includes the following item:
Quoted 3 lines
o We need a kernel side API for reporting error events to userspace (could be async to 2.6 itself)
Quoted 8 lines
Quoted 1 line
(Prototype core based on netlink exists)
The enclosed patches provide a mechanism for reporting error events to user-mode applications via netlink. This mechanism supplements the text-oriented printk mechanism, providing a way to log binary data or a mixture of text+binary.
...
Here are updated patches, reflecting the following changes:
Patch #1 (kerror.c et al):
- Given James Morris's patch to af_netlink.c (Rev 1.30 in BitKeeper), I was able to remove kerror_netlink_rcv(). (My patches work fine without this, except that any packets sent to the NETLINK_KERROR socket by an ill-behaved, root-owned application would accumulate in the kernel's socket buffer.)
Patch #2 (evlog.c et al -- see accompanying post):
- Paraphrase dropped packets via printk() when nobody's listening to netlink socket.
- Added support for 'z' qualifier, to resync with vsnprintf().
- In evlog.h, reordered members of struct kern_log_entry to address alignment worries.
These patches work for both 2.5.74 and 2.5.75.
Jim Keniston
IBM Linux Technology Center
http://prdownloads.sourceforge.net/evlog/kerror-2.5.75.patch?download
http://prdownloads.sourceforge.net/evlog/evlog-2.5.75.patch?download
http://prdownloads.sourceforge.net/evlog/kerrord.tar.gz?download
include/linux/kerror.h +27 -0
@@ -0,0 +1,27 @@ +#ifndef _KERROR_H +#define _KERROR_H + +#ifdef __KERNEL__ +#include <linux/config.h> +#include <linux/uio.h> +#include <asm/types.h> + +#ifdef CONFIG_NET +extern int kernel_error_event (void *data,size_t len,__u32 groups); +extern int kernel_error_event_iov (const struct iovec *iov, +unsigned int nseg,__u32 groups); +#else +static inline int kernel_error_event (void *data,size_t len,__u32 groups) + {return -ENOSYS ; } +static inline int kernel_error_event_iov (const struct iovec *iov, +unsigned int nseg,__u32 groups) + {return -ENOSYS ; } +#endif /* CONFIG_NET */ +#endif /* __KERNEL__ */ + +#define KERROR_GROUP_RAW 0x00000001 +#define KERROR_GROUP_EVLOG 0x00000002 + +#define KERROR_GROUP_ALL (~(u32)0) + +#endif /* _KERROR_H */
include/linux/netlink.h +1 -0
@@ -10,6 +10,7 @@#define NETLINK_TCPDIAG 4/* TCP socket monitoring */ #define NETLINK_NFLOG 5/* netfilter/iptables ULOG */ #define NETLINK_XFRM 6/* ipsec */ +#define NETLINK_KERROR 7/* kernel error event facility */ #define NETLINK_ARPD 8#define NETLINK_ROUTE6 11/* af_inet6 route comm channel */ #define NETLINK_IP6_FW 13
net/netlink/Makefile +1 -1
@@ -2,5 +2,5 @@ # Makefile for the netlink driver. # -obj-y := af_netlink.o +obj-y := af_netlink.o kerror.o obj-$(CONFIG_NETLINK_DEV) += netlink_dev.o
net/netlink/kerror.c +97 -0
97 lines not on this page · raw message
net/netsyms.c +3 -0
@@ -83,6 +83,7 @@#endif #include <linux/rtnetlink.h> +#include <linux/kerror.h> #ifdef CONFIG_IPX_MODULE extern struct datalink_proto *make_EII_client (void );
@@ -505,6 +506,8 @@EXPORT_SYMBOL (netlink_set_nonroot);EXPORT_SYMBOL (netlink_register_notifier);EXPORT_SYMBOL (netlink_unregister_notifier); +EXPORT_SYMBOL (kernel_error_event); +EXPORT_SYMBOL (kernel_error_event_iov);#if defined(CONFIG_NETLINK_DEV ) || defined(CONFIG_NETLINK_DEV_MODULE )EXPORT_SYMBOL (netlink_attach);EXPORT_SYMBOL (netlink_detach);
Re: [PATCH] [2/2] kernel error reporting (revised)
This patch is described in the previous post.
Jim Keniston
IBM Linux Technology Center
include/linux/evlog.h +109 -0
@@ -0,0 +1,109 @@ +/* +* Linux Event Logging +* Copyright (c) International Business Machines Corp., 2001 +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +* Please send e-mail to [email protected] if you have +* questions or comments. +* +* Project Website: http://evlog.sourceforge.net/ +*/ + +#ifndef _LINUX_EVLOG_H +#define _LINUX_EVLOG_H + +#include <stdarg.h> +#include <linux/types.h> +#include <asm/types.h> + +/* Values for log_flags member */ +#define EVL_TRUNCATE 0x1 +#define EVL_KERNEL_EVENT 0x2 +#define EVL_INTERRUPT 0x10/* Logged from interrupt context */ +#define EVL_PRINTK 0x20/* Strip leading <n> when formatting */ +#define EVL_EVTYCRC 0x40/* Daemon will set event type = CRC */ +/* of format string. */ + +/* Formats for optional portion of record. */ +#define EVL_NODATA 0 +#define EVL_BINARY 1 +#define EVL_STRING 2 +#define EVL_PRINTF 3 + +/* Maximum length of variable portion of record */ +#define EVL_ENTRY_MAXLEN (8 * 1024) + +/* Facility (e.g., driver) names are truncated to 15+null. */ +#define FACILITY_MAXLEN 16 + +/* +* struct kern_log_entry - kernel record header +* Each record sent to group KERROR_GROUP_EVLOG begins with this header. +*/ +struct kern_log_entry { +__u16 log_kmagic;/* always LOGREC_KMAGIC */ +__u16 log_kversion;/* which version of this struct? */ +__u16 log_size;/* # bytes in variable part of record */ +__s8 log_format;/* BINARY, STRING, PRINTF, NODATA */ +__s8 log_severity;/* DEBUG, INFO, NOTICE, WARN, etc. */ +__s32 log_event_type;/* facility-specific event ID */ +__u32 log_flags;/* EVL_TRUNCATE, etc. */ +__s32 log_processor;/* CPU ID */ +uid_t log_uid;/* event context... */ +gid_t log_gid; +pid_t log_pid; +pid_t log_pgrp; +char log_facility[FACILITY_MAXLEN ];/* e.g., driver name */ +}; + +#define LOGREC_KMAGIC 0x7af8 +#define LOGREC_KVERSION 3 + +#ifdef __KERNEL__ +/* +* severities, AKA priorities +*/ +#define LOG_EMERG 0/* system is unusable */ +#define LOG_ALERT 1/* action must be taken immediately */ +#define LOG_CRIT 2/* critical conditions */ +#define LOG_ERR 3/* error conditions */ +#define LOG_WARNING 4/* warning conditions */ +#define LOG_NOTICE 5/* normal but significant condition */ +#define LOG_INFO 6/* informational */ +#define LOG_DEBUG 7/* debug-level messages */ + +#ifdef CONFIG_NET +extern int evl_write (const char *facility,int event_type, +int severity,const void *buf,size_t len,int format); +extern int evl_printf (const char *facility,int event_type,int sev, +const char *fmt, ...); +extern int evl_vprintf (const char *facility,int event_type,int sev, +const char *fmt,va_list args); +#else /* ! CONFIG_NET */ +static inline int evl_write (const char *facility,int event_type, +int severity,const void *buf,size_t len,int format) + {return -ENOSYS ; } +static inline int evl_printf (const char *facility,int event_type,int sev, +const char *fmt, ...); + {return -ENOSYS ; } +static inline int evl_vprintf (const char *facility,int event_type,int sev, +const char *fmt,va_list args) + {return -ENOSYS ; } +#endif /* CONFIG_NET */ + +#endif /* __KERNEL__ */ + +#endif /* _LINUX_EVLOG_H */
kernel/Makefile +1 -0
@@ -19,6 +19,7 @@ obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o obj-$(CONFIG_SOFTWARE_SUSPEND) += suspend.o obj-$(CONFIG_COMPAT) += compat.o +obj-$(CONFIG_NET) += evlog.o ifneq ($(CONFIG_IA64),y) # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/evlog.c +542 -0
542 lines not on this page · raw message
Re: [PATCH] [1/2] kernel error reporting (revised)
In reply to Jim Kenistonnet/netlink/kerror.c line 57
Quoted 7 lines · Jim Keniston
net/netlink/kerror.c +5
-0+int kernel_error_event_iov (const struct iovec *iov,unsigned int nseg, +u32 groups) +{ + +return netlink_broadcast (kerror_nl, skb,0 , ~0 ,GFP_ATOMIC );
This appears to be deadlocky when called from interrupt handlers.
netlink_broadcast() does read_lock(&nl_table_lock). But nl_table_lock is not an irq-safe lock.
Possibly netlink_broadcast() can be made callable from hardirq context, but it looks to be non trivial. The various error and delivery handlers need to be reviewed, the kfree_skb() calls should be thought about, etc.
Re: [PATCH] [1/2] kernel error reporting (revised)
Hello!
Quoted 2 lines
netlink_broadcast()doesread_lock(&nl_table_lock). Butnl_table_lockis not an irq-safe lock.
Just as reminder, there are _no_ irq safe locks in net/*. A few of local_irq_disable()s are segregated in interface to device drivers.
Quoted 2 lines
Possibly
netlink_broadcast()can be made callable from hardirq context, but it looks to be non trivial.
Trivial or non-trivial, before all this is highly not desired. net/* is better to remain in the form free of knowledge of hardirqs.
Alexey
Re: [PATCH] [1/2] kernel error reporting (revised)
In reply to Andrew MortonQuoted 12 lines · Andrew Morton
Review
Quoted 7 lines · Jim Keniston
(quoted diff) +5
-0+int kernel_error_event_iov(const struct iovec *iov, unsigned int nseg, + u32 groups) +{ + + return netlink_broadcast(kerror_nl, skb, 0, ~0, GFP_ATOMIC);This appears to be deadlocky when called from interrupt handlers.
Quoted 6 lines
netlink_broadcast()doesread_lock(&nl_table_lock). Butnl_table_lockis not an irq-safe lock.Possibly
netlink_broadcast()can be made callable from hardirq context, but it looks to be non trivial. The various error and delivery handlers need to be reviewed,
Yes indeed. I believe this issue is resolved by detecting that we're in an interrupt handler and delaying the call to netlink_broadcast() via a tasklet. See the enclosed patch to the previously posted rev. I'll update the full patch at
http://prdownloads.sourceforge.net/evlog/kerror-2.5.75.patch?download
An issue remains: what, if anything, to tell the caller if the delayed netlink_broadcast() fails. See below for further thoughts.
Quoted 1 line
the
kfree_skb()calls should be thought about, etc.
I've thought about them. :-) Given the aforementioned solution, I don't think kfree_skb() is an issue, because it's called as needed by netlink_broadcast(). If I'm missing something here, feel free to clarify.
Thanks.
Jim
WHAT IF THE DELAYED netlink_broadcast() CALL FAILS?
1. Can we detect from IRQ context that nobody is listening, and thereby return -ESRCH to the caller? No, to do that would require perusing the nl_table[NETLINK_KERROR] list. We can't do that for the same reason we can't call netlink_broadcast(). So kernel_error_event_iov() now returns -EINPROGRESS if it had to delay the netlink_broadcast() call.
2. Could the tasklet report netlink_broadcast() failures back to the higher-level code? Yes, we could implement a per-group callback to handle that. Current thinking is that it's overkill. But it would resolve the next issue...
3. Given the above, what should the evlog.c caller do when kernel_error_event_iov() returns -EINPROGRESS?
a. Nothing. Figure the packet will probably get logged.
b. Just to be safe, report it via printk, the same way we report dropped packets.
We currently do (a). (b) would mean that every event logged from IRQ context would be cc-ed to printk.
-----
kerror.c renamed from kerror.c.old +35 -0
@@ -3,10 +3,12 @@* Copyright (C) 2003 David S. Miller ([email protected]) * June 2003 - Jim Keniston and Dan Stekloff (kenistoj and [email protected]) * Fixed a couple of bugs and added iovec interface. +* July 2003 - Jim Keniston - Added handling of packets logged from IRQ context. */ #include <linux/kernel.h> #include <linux/types.h> +#include <linux/interrupt.h> #include <linux/skbuff.h> #include <linux/socket.h> #include <linux/netlink.h>
@@ -17,6 +19,33 @@static struct sock *kerror_nl; +/* Packets logged from IRQ context are queued for broadcast by a tasklet. */ +static struct sk_buff_head delayed_pkts; +static void broadcast_delayed_pkts (unsigned long ); +static DECLARE_TASKLET(delayed_pkts_tasklet, broadcast_delayed_pkts, 0); + +/** +* delayed_broadcast() - Schedule a tasklet to broadcast a packet. +* We want to broadcast the indicated packet, but can't because we're +* in a hardware interrupt and so can't call netlink_broadcast(). +* Schedule a tasklet to do the job. +* +* @skb: the socket buffer to broadcast +*/ +static void delayed_broadcast (struct sk_buff *skb) +{ +skb_queue_tail (&delayed_pkts, skb); +tasklet_schedule (&delayed_pkts_tasklet); +} + +static void broadcast_delayed_pkts (unsigned long ignored) +{ +struct sk_buff *skb; +while ((skb =skb_dequeue (&delayed_pkts)) !=NULL ) { + (void )netlink_broadcast (kerror_nl, skb,0 , ~0 ,GFP_ATOMIC ); + } +} +/** * kernel_error_event_iov() - Broadcast packet to NETLINK_KERROR sockets. * @iov: the packet's data
@@ -54,6 +83,11 @@NETLINK_CB (skb).dst_groups = groups; +if (in_irq ()) { +delayed_broadcast (skb); +return -EINPROGRESS ; + } +return netlink_broadcast (kerror_nl, skb,0 , ~0 ,GFP_ATOMIC ); nlmsg_failure:
@@ -85,6 +119,7 @@if (kerror_nl ==NULL )panic ("kerror_init: cannot initialize kerror_nl\n" ); +skb_queue_head_init (&delayed_pkts);return 0 ; }
Re: [PATCH] [1/2] kernel error reporting (revised)
Quoted 7 lines · Jim Keniston
3. Given the above, what should the
evlog.ccaller do whenkernel_error_event_iov()returns-EINPROGRESS?
a. Nothing. Figure the packet will probably get logged.
b. Just to be safe, report it via printk, the same way we report dropped packets.
We currently do (a). (b) would mean that every event logged from IRQ context would be cc-ed to printk.
I don't think this irq detection logic should be added at all here, let the caller reschedule its logging if running in irq context.
- James
Signature · 2 lines
James Morris <[email protected]>
Re: [PATCH] [1/2] kernel error reporting (revised)
Quoted 11 lines · James Morris
Quoted 7 lines · Jim Keniston
3. Given the above, what should the
evlog.ccaller do whenkernel_error_event_iov()returns-EINPROGRESS?
a. Nothing. Figure the packet will probably get logged.
b. Just to be safe, report it via printk, the same way we report dropped packets.
We currently do (a). (b) would mean that every event logged from IRQ context would be cc-ed to printk.
Quoted 7 lines
I don't think this irq detection logic should be added at all here, let the caller reschedule its logging if running in irq context.
- James
--
James Morris
<[email protected]>
Yes, this makes sense. At the kerror.c level, just return -EDEADLK if in_irq(). Delay packet delivery (via a tasklet, as before) at the evlog.c level instead. That way, we know at the evlog.c level (in the tasklet) whether the event packet was delivered to anybody, and can paraphrase it to printk if it wasn't.
Is this the sort of thing you had in mind?
Jim K
Re: [PATCH] [1/2] kernel error reporting (revised)
In reply to James MorrisQuoted 20 lines · Jim Keniston
Quoted 11 lines · James Morris
Quoted 7 lines · Jim Keniston
3. Given the above, what should the
evlog.ccaller do whenkernel_error_event_iov()returns-EINPROGRESS?
a. Nothing. Figure the packet will probably get logged.
b. Just to be safe, report it via printk, the same way we report dropped packets.
We currently do (a). (b) would mean that every event logged from IRQ context would be cc-ed to printk.Quoted 7 lines
I don't think this irq detection logic should be added at all here, let the caller reschedule its logging if running in irq context.
- James
--
James Morris
<[email protected]>
Quoted 7 lines
Yes, this makes sense. At the
kerror.clevel, just return-EDEADLKifin_irq(). Delay packet delivery (via a tasklet, as before) at theevlog.clevel instead. That way, we know at theevlog.clevel (in the tasklet) whether the event packet was delivered to anybody, and can paraphrase it to printk if it wasn't.Is this the sort of thing you had in mind?
Jim K
I implemented the above change. Now, an event logged from an interrupt handler when nobody's listening to our socket (e.g., during boot) is paraphrased to printk. Here are the updated patches:
http://prdownloads.sourceforge.net/evlog/kerror-2.5.75.patch?download
http://prdownloads.sourceforge.net/evlog/evlog-2.5.75.patch?download
http://prdownloads.sourceforge.net/evlog/kerrord.tar.gz?download
Jim K
Re: [PATCH] [1/2] kernel error reporting (revised)
Quoted 6 lines · Jim Keniston
Quoted 6 lines
Yes, this makes sense. At the
kerror.clevel, just return-EDEADLKifin_irq(). Delay packet delivery (via a tasklet, as before) at theevlog.clevel instead. That way, we know at theevlog.clevel (in the tasklet) whether the event packet was delivered to anybody, and can paraphrase it to printk if it wasn't.Is this the sort of thing you had in mind?
Not exactly -- I don't think the logging framework should do any irq detection. The caller should either know if its in an interrupt, or do the detection itself.
- James
Signature · 2 lines
James Morris <[email protected]>