summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKay Sievers <kay@vrfy.org>2012-05-14 02:07:12 +0200
committerKay Sievers <kay@vrfy.org>2012-05-14 02:07:12 +0200
commita5a8a9cadc5ef36a62de517060fc866e2b77a16e (patch)
treef64eb58ad5ebb23ff7127a261c8dd75ced3920bd
parent0997e9ee6f26084c4b78e52e2d90f68fb4f498d9 (diff)
downloadpatches-a5a8a9cadc5ef36a62de517060fc866e2b77a16e.tar.gz
rebase against driver-core tree
-rw-r--r--cont.patch69
-rw-r--r--devpts.patch447
-rw-r--r--kern-cont-acpi.patch74
-rw-r--r--kern-cont-mm.patch27
-rw-r--r--kern-cont-parport.patch78
-rw-r--r--kmsg-docs.patch114
-rw-r--r--kmsg-fix64bit-division.patch36
-rw-r--r--kmsg-multiline.patch243
-rw-r--r--kmsg-off.patch108
-rw-r--r--kmsg-sep-cont.patch211
-rw-r--r--printk-dev_printk.patch94
-rw-r--r--printk-devkmsg.patch463
-rw-r--r--printk-race.patch101
-rw-r--r--printk-records.patch1427
-rw-r--r--printk-time.patch122
-rw-r--r--series15
16 files changed, 558 insertions, 3071 deletions
diff --git a/cont.patch b/cont.patch
deleted file mode 100644
index 3fc2406..0000000
--- a/cont.patch
+++ /dev/null
@@ -1,69 +0,0 @@
-From: Kay Sievers <kay@vrfy.org>
-Subject: printk() - do not merge continuation lines of different threads
-
-This prevents the merging of printk() continuation lines of different
-threads, in the case they race against each other.
-
-It should properly isolate "atomic" single-line printk() users from
-continuation users, to make sure the single-line users will never be
-merged with the racy continuation ones.
-
-Signed-off-by: Kay Sievers <kay@vrfy.org>
----
-
- kernel/printk.c | 19 ++++++++++---------
- 1 file changed, 10 insertions(+), 9 deletions(-)
-
---- a/kernel/printk.c
-+++ b/kernel/printk.c
-@@ -1230,12 +1230,13 @@ asmlinkage int vprintk_emit(int facility
- static size_t buflen;
- static int buflevel;
- static char textbuf[LOG_LINE_MAX];
-+ static struct task_struct *cont;
- char *text = textbuf;
- size_t textlen;
- unsigned long flags;
- int this_cpu;
- bool newline = false;
-- bool cont = false;
-+ bool prefix = false;
- int printed_len = 0;
-
- boot_delay_msec();
-@@ -1295,20 +1296,16 @@ asmlinkage int vprintk_emit(int facility
- case '0' ... '7':
- if (level == -1)
- level = text[1] - '0';
-- text += 3;
-- textlen -= 3;
-- break;
-- case 'c': /* KERN_CONT */
-- cont = true;
- case 'd': /* KERN_DEFAULT */
-+ prefix = true;
-+ case 'c': /* KERN_CONT */
- text += 3;
- textlen -= 3;
-- break;
- }
- }
-
-- if (buflen && (!cont || dict)) {
-- /* no continuation; flush existing buffer */
-+ if (buflen && (prefix || dict || cont != current)) {
-+ /* flush existing buffer */
- log_store(facility, buflevel, NULL, 0, buf, buflen);
- printed_len += buflen;
- buflen = 0;
-@@ -1342,6 +1339,10 @@ asmlinkage int vprintk_emit(int facility
- dict, dictlen, text, textlen);
- printed_len += textlen;
- }
-+ cont = NULL;
-+ } else {
-+ /* remember thread which filled the buffer */
-+ cont = current;
- }
-
- /*
diff --git a/devpts.patch b/devpts.patch
deleted file mode 100644
index cca51dc..0000000
--- a/devpts.patch
+++ /dev/null
@@ -1,447 +0,0 @@
-Subject: devpts: properly integrate with /dev/ptmx
-
-The following patch is just to clean up the confusion about userspace
-and the unfortunate idea of legacy vs. non-legacy mount options. It is
-nowhere ready to merge, but it should make is pretty clear, that
-userspace should be left alone here, and it's a job for the kernel only.
-
-# ls -l /dev
-crw------- 1 root root 10, 1 Apr 9 14:21 psaux
-lrwxrwxrwx 1 root root 8 Apr 9 14:20 ptmx -> pts/ptmx
-drwxr-xr-x 2 root root 0 Apr 9 14:21 pts
-crw-rw-rw- 1 root root 1, 8 Apr 9 14:21 random
-
-# ls -l /dev/pts
-total 0
-crw--w---- 1 root tty 136, 0 Apr 9 14:22 0
-crw--w---- 1 kay tty 136, 1 Apr 9 14:22 1
-crw-rw-rw- 1 root tty 5, 2 Apr 9 14:22 ptmx
-
----
- drivers/base/devtmpfs.c | 60 ++++++++++++++++++++++++-
- drivers/tty/Kconfig | 11 ----
- drivers/tty/pty.c | 3 -
- fs/devpts/inode.c | 112 +++++++-----------------------------------------
- include/linux/device.h | 2
- 5 files changed, 76 insertions(+), 112 deletions(-)
-
---- a/drivers/base/devtmpfs.c
-+++ b/drivers/base/devtmpfs.c
-@@ -40,6 +40,7 @@ static struct req {
- struct completion done;
- int err;
- const char *name;
-+ const char *target;
- umode_t mode; /* 0 => delete */
- struct device *dev;
- } *requests;
-@@ -84,7 +85,7 @@ int devtmpfs_create_node(struct device *
- if (!thread)
- return 0;
-
-- req.mode = 0;
-+ memset(&req, 0, sizeof(struct req));
- req.name = device_get_devnode(dev, &req.mode, &tmp);
- if (!req.name)
- return -ENOMEM;
-@@ -113,6 +114,31 @@ int devtmpfs_create_node(struct device *
- return req.err;
- }
-
-+int devtmpfs_create_link(const char *name, const char *target)
-+{
-+ struct req req;
-+
-+ if (!thread)
-+ return 0;
-+
-+ memset(&req, 0, sizeof(struct req));
-+ req.mode = 0666;
-+ req.name = name;
-+ req.target = target;
-+
-+ init_completion(&req.done);
-+
-+ spin_lock(&req_lock);
-+ req.next = requests;
-+ requests = &req;
-+ spin_unlock(&req_lock);
-+
-+ wake_up_process(thread);
-+ wait_for_completion(&req.done);
-+
-+ return req.err;
-+}
-+
- int devtmpfs_delete_node(struct device *dev)
- {
- const char *tmp = NULL;
-@@ -121,11 +147,11 @@ int devtmpfs_delete_node(struct device *
- if (!thread)
- return 0;
-
-+ memset(&req, 0, sizeof(struct req));
- req.name = device_get_devnode(dev, NULL, &tmp);
- if (!req.name)
- return -ENOMEM;
-
-- req.mode = 0;
- req.dev = dev;
-
- init_completion(&req.done);
-@@ -225,6 +251,28 @@ static int handle_create(const char *nod
- return err;
- }
-
-+static int handle_create_link(const char *name, const char *target)
-+{
-+ struct dentry *dentry;
-+ struct path path;
-+ int err;
-+
-+ dentry = kern_path_create(AT_FDCWD, name, &path, 0);
-+ if (dentry == ERR_PTR(-ENOENT)) {
-+ create_path(name);
-+ dentry = kern_path_create(AT_FDCWD, name, &path, 0);
-+ }
-+ if (IS_ERR(dentry))
-+ return PTR_ERR(dentry);
-+
-+ err = vfs_symlink(path.dentry->d_inode, dentry, target);
-+ dput(dentry);
-+
-+ mutex_unlock(&path.dentry->d_inode->i_mutex);
-+ path_put(&path);
-+ return err;
-+}
-+
- static int dev_rmdir(const char *name)
- {
- struct nameidata nd;
-@@ -378,8 +426,11 @@ int devtmpfs_mount(const char *mntdir)
-
- static DECLARE_COMPLETION(setup_done);
-
--static int handle(const char *name, umode_t mode, struct device *dev)
-+static int handle(const char *name, umode_t mode,
-+ struct device *dev, const char *target)
- {
-+ if (target)
-+ return handle_create_link(name, target);
- if (mode)
- return handle_create(name, mode, dev);
- else
-@@ -407,7 +458,8 @@ static int devtmpfsd(void *p)
- spin_unlock(&req_lock);
- while (req) {
- struct req *next = req->next;
-- req->err = handle(req->name, req->mode, req->dev);
-+ req->err = handle(req->name, req->mode,
-+ req->dev, req->target);
- complete(&req->done);
- req = next;
- }
---- a/drivers/tty/Kconfig
-+++ b/drivers/tty/Kconfig
-@@ -109,17 +109,6 @@ config UNIX98_PTYS
- All modern Linux systems use the Unix98 ptys. Say Y unless
- you're on an embedded system and want to conserve memory.
-
--config DEVPTS_MULTIPLE_INSTANCES
-- bool "Support multiple instances of devpts"
-- depends on UNIX98_PTYS
-- default n
-- ---help---
-- Enable support for multiple instances of devpts filesystem.
-- If you want to have isolated PTY namespaces (eg: in containers),
-- say Y here. Otherwise, say N. If enabled, each mount of devpts
-- filesystem with the '-o newinstance' option will create an
-- independent PTY namespace.
--
- config LEGACY_PTYS
- bool "Legacy (BSD) PTY support"
- default y
---- a/drivers/tty/pty.c
-+++ b/drivers/tty/pty.c
-@@ -706,7 +706,7 @@ static void __init unix98_pty_init(void)
- if (tty_register_driver(pts_driver))
- panic("Couldn't register Unix98 pts driver");
-
-- /* Now create the /dev/ptmx special device */
-+ /* Hook up the ptmx cdev which lives inside the devpts filesystem */
- tty_default_fops(&ptmx_fops);
- ptmx_fops.open = ptmx_open;
-
-@@ -714,7 +714,6 @@ static void __init unix98_pty_init(void)
- if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
- register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
- panic("Couldn't register /dev/ptmx driver\n");
-- device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx");
- }
-
- #else
---- a/fs/devpts/inode.c
-+++ b/fs/devpts/inode.c
-@@ -26,15 +26,9 @@
- #include <linux/fsnotify.h>
- #include <linux/seq_file.h>
-
--#define DEVPTS_DEFAULT_MODE 0600
--/*
-- * ptmx is a new node in /dev/pts and will be unused in legacy (single-
-- * instance) mode. To prevent surprises in user space, set permissions of
-- * ptmx to 0. Use 'chmod' or remount with '-o ptmxmode' to set meaningful
-- * permissions.
-- */
--#define DEVPTS_DEFAULT_PTMX_MODE 0000
--#define PTMX_MINOR 2
-+#define DEVPTS_DEFAULT_MODE 0600
-+#define DEVPTS_DEFAULT_PTMX_MODE 0666
-+#define PTMX_MINOR 2
-
- /*
- * sysctl support for setting limits on the number of Unix98 ptys allocated.
-@@ -102,24 +96,19 @@ struct pts_mount_opts {
- gid_t gid;
- umode_t mode;
- umode_t ptmxmode;
-- int newinstance;
- int max;
- };
-
- enum {
-- Opt_uid, Opt_gid, Opt_mode, Opt_ptmxmode, Opt_newinstance, Opt_max,
-- Opt_err
-+ Opt_uid, Opt_gid, Opt_mode, Opt_ptmxmode, Opt_max, Opt_err
- };
-
- static const match_table_t tokens = {
- {Opt_uid, "uid=%u"},
- {Opt_gid, "gid=%u"},
- {Opt_mode, "mode=%o"},
--#ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
- {Opt_ptmxmode, "ptmxmode=%o"},
-- {Opt_newinstance, "newinstance"},
- {Opt_max, "max=%d"},
--#endif
- {Opt_err, NULL}
- };
-
-@@ -136,10 +125,8 @@ static inline struct pts_fs_info *DEVPTS
-
- static inline struct super_block *pts_sb_from_inode(struct inode *inode)
- {
--#ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
- if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC)
- return inode->i_sb;
--#endif
- return devpts_mnt->mnt_sb;
- }
-
-@@ -149,9 +136,7 @@ static inline struct super_block *pts_sb
- /*
- * parse_mount_options():
- * Set @opts to mount options specified in @data. If an option is not
-- * specified in @data, set it to its default value. The exception is
-- * 'newinstance' option which can only be set/cleared on a mount (i.e.
-- * cannot be changed during remount).
-+ * specified in @data, set it to its default value.\
- *
- * Note: @data may be NULL (in which case all options are set to default).
- */
-@@ -167,10 +152,6 @@ static int parse_mount_options(char *dat
- opts->ptmxmode = DEVPTS_DEFAULT_PTMX_MODE;
- opts->max = NR_UNIX98_PTY_MAX;
-
-- /* newinstance makes sense only on initial mount */
-- if (op == PARSE_MOUNT)
-- opts->newinstance = 0;
--
- while ((p = strsep(&data, ",")) != NULL) {
- substring_t args[MAX_OPT_ARGS];
- int token;
-@@ -198,24 +179,17 @@ static int parse_mount_options(char *dat
- return -EINVAL;
- opts->mode = option & S_IALLUGO;
- break;
--#ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
- case Opt_ptmxmode:
- if (match_octal(&args[0], &option))
- return -EINVAL;
- opts->ptmxmode = option & S_IALLUGO;
- break;
-- case Opt_newinstance:
-- /* newinstance makes sense only on initial mount */
-- if (op == PARSE_MOUNT)
-- opts->newinstance = 1;
-- break;
- case Opt_max:
- if (match_int(&args[0], &option) ||
- option < 0 || option > NR_UNIX98_PTY_MAX)
- return -EINVAL;
- opts->max = option;
- break;
--#endif
- default:
- printk(KERN_ERR "devpts: called with bogus options\n");
- return -EINVAL;
-@@ -225,7 +199,6 @@ static int parse_mount_options(char *dat
- return 0;
- }
-
--#ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
- static int mknod_ptmx(struct super_block *sb)
- {
- int mode;
-@@ -260,6 +233,8 @@ static int mknod_ptmx(struct super_block
- goto out;
- }
-
-+ if (opts->setgid)
-+ inode->i_gid = opts->gid;
- inode->i_ino = 2;
- inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
-
-@@ -283,12 +258,6 @@ static void update_ptmx_mode(struct pts_
- inode->i_mode = S_IFCHR|fsi->mount_opts.ptmxmode;
- }
- }
--#else
--static inline void update_ptmx_mode(struct pts_fs_info *fsi)
--{
-- return;
--}
--#endif
-
- static int devpts_remount(struct super_block *sb, int *flags, char *data)
- {
-@@ -319,11 +288,9 @@ static int devpts_show_options(struct se
- if (opts->setgid)
- seq_printf(seq, ",gid=%u", opts->gid);
- seq_printf(seq, ",mode=%03o", opts->mode);
--#ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
- seq_printf(seq, ",ptmxmode=%03o", opts->ptmxmode);
- if (opts->max < NR_UNIX98_PTY_MAX)
- seq_printf(seq, ",max=%d", opts->max);
--#endif
-
- return 0;
- }
-@@ -384,43 +351,8 @@ fail:
- return -ENOMEM;
- }
-
--#ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
--static int compare_init_pts_sb(struct super_block *s, void *p)
--{
-- if (devpts_mnt)
-- return devpts_mnt->mnt_sb == s;
-- return 0;
--}
--
--/*
-- * devpts_mount()
-- *
-- * If the '-o newinstance' mount option was specified, mount a new
-- * (private) instance of devpts. PTYs created in this instance are
-- * independent of the PTYs in other devpts instances.
-- *
-- * If the '-o newinstance' option was not specified, mount/remount the
-- * initial kernel mount of devpts. This type of mount gives the
-- * legacy, single-instance semantics.
-- *
-- * The 'newinstance' option is needed to support multiple namespace
-- * semantics in devpts while preserving backward compatibility of the
-- * current 'single-namespace' semantics. i.e all mounts of devpts
-- * without the 'newinstance' mount option should bind to the initial
-- * kernel mount, like mount_single().
-- *
-- * Mounts with 'newinstance' option create a new, private namespace.
-- *
-- * NOTE:
-- *
-- * For single-mount semantics, devpts cannot use mount_single(),
-- * because mount_single()/sget() find and use the super-block from
-- * the most recent mount of devpts. But that recent mount may be a
-- * 'newinstance' mount and mount_single() would pick the newinstance
-- * super-block instead of the initial super-block.
-- */
- static struct dentry *devpts_mount(struct file_system_type *fs_type,
-- int flags, const char *dev_name, void *data)
-+ int flags, const char *dev_name, void *data)
- {
- int error;
- struct pts_mount_opts opts;
-@@ -430,10 +362,7 @@ static struct dentry *devpts_mount(struc
- if (error)
- return ERR_PTR(error);
-
-- if (opts.newinstance)
-- s = sget(fs_type, NULL, set_anon_super, NULL);
-- else
-- s = sget(fs_type, compare_init_pts_sb, set_anon_super, NULL);
-+ s = sget(fs_type, NULL, set_anon_super, NULL);
-
- if (IS_ERR(s))
- return ERR_CAST(s);
-@@ -459,18 +388,6 @@ out_undo_sget:
- return ERR_PTR(error);
- }
-
--#else
--/*
-- * This supports only the legacy single-instance semantics (no
-- * multiple-instance semantics)
-- */
--static struct dentry *devpts_mount(struct file_system_type *fs_type, int flags,
-- const char *dev_name, void *data)
--{
-- return mount_single(fs_type, flags, data, devpts_fill_super);
--}
--#endif
--
- static void devpts_kill_sb(struct super_block *sb)
- {
- struct pts_fs_info *fsi = DEVPTS_SB(sb);
-@@ -502,8 +419,7 @@ retry:
- return -ENOMEM;
-
- mutex_lock(&allocated_ptys_lock);
-- if (pty_count >= pty_limit -
-- (fsi->mount_opts.newinstance ? pty_reserve : 0)) {
-+ if (pty_count >= pty_limit - pty_reserve) {
- mutex_unlock(&allocated_ptys_lock);
- return -ENOSPC;
- }
-@@ -629,9 +545,15 @@ void devpts_pty_kill(struct tty_struct *
-
- static int __init init_devpts_fs(void)
- {
-- int err = register_filesystem(&devpts_fs_type);
-+ int err;
- struct ctl_table_header *table;
-
-+ err = devtmpfs_create_link("ptmx", "pts/ptmx");
-+ if (err)
-+ return err;
-+
-+ err = register_filesystem(&devpts_fs_type);
-+
- if (!err) {
- table = register_sysctl_table(pty_root_table);
- devpts_mnt = kern_mount(&devpts_fs_type);
---- a/include/linux/device.h
-+++ b/include/linux/device.h
-@@ -858,10 +858,12 @@ extern void put_device(struct device *de
- extern void wait_for_device_probe(void);
-
- #ifdef CONFIG_DEVTMPFS
-+extern int devtmpfs_create_link(const char *name, const char *target);
- extern int devtmpfs_create_node(struct device *dev);
- extern int devtmpfs_delete_node(struct device *dev);
- extern int devtmpfs_mount(const char *mntdir);
- #else
-+static int devtmpfs_create_link(const char *name, const char *target) { return 0; }
- static inline int devtmpfs_create_node(struct device *dev) { return 0; }
- static inline int devtmpfs_delete_node(struct device *dev) { return 0; }
- static inline int devtmpfs_mount(const char *mountpoint) { return 0; }
diff --git a/kern-cont-acpi.patch b/kern-cont-acpi.patch
deleted file mode 100644
index adb5516..0000000
--- a/kern-cont-acpi.patch
+++ /dev/null
@@ -1,74 +0,0 @@
-From: Kay Sievers <kay@vrfy.org>
-Subject: acpi: use KERN_CONT in printk() continuation lines
-
-Cc: Len Brown <lenb@kernel.org>
-Signed-off-by: Kay Sievers <kay@vrfy.org>
----
- drivers/acpi/pci_link.c | 12 ++++++------
- drivers/acpi/sleep.c | 8 ++++----
- 2 files changed, 10 insertions(+), 10 deletions(-)
-
---- a/drivers/acpi/pci_link.c
-+++ b/drivers/acpi/pci_link.c
-@@ -720,21 +720,21 @@ static int acpi_pci_link_add(struct acpi
- acpi_device_bid(device));
- for (i = 0; i < link->irq.possible_count; i++) {
- if (link->irq.active == link->irq.possible[i]) {
-- printk(" *%d", link->irq.possible[i]);
-+ printk(KERN_CONT " *%d", link->irq.possible[i]);
- found = 1;
- } else
-- printk(" %d", link->irq.possible[i]);
-+ printk(KERN_CONT " %d", link->irq.possible[i]);
- }
-
-- printk(")");
-+ printk(KERN_CONT ")");
-
- if (!found)
-- printk(" *%d", link->irq.active);
-+ printk(KERN_CONT " *%d", link->irq.active);
-
- if (!link->device->status.enabled)
-- printk(", disabled.");
-+ printk(KERN_CONT ", disabled.");
-
-- printk("\n");
-+ printk(KERN_CONT "\n");
-
- list_add_tail(&link->list, &acpi_link_list);
-
---- a/drivers/acpi/sleep.c
-+++ b/drivers/acpi/sleep.c
-@@ -887,7 +887,7 @@ int __init acpi_sleep_init(void)
- status = acpi_get_sleep_type_data(i, &type_a, &type_b);
- if (ACPI_SUCCESS(status)) {
- sleep_states[i] = 1;
-- printk(" S%d", i);
-+ printk(KERN_CONT " S%d", i);
- }
- }
-
-@@ -901,7 +901,7 @@ int __init acpi_sleep_init(void)
- hibernation_set_ops(old_suspend_ordering ?
- &acpi_hibernation_ops_old : &acpi_hibernation_ops);
- sleep_states[ACPI_STATE_S4] = 1;
-- printk(" S4");
-+ printk(KERN_CONT " S4");
- if (!nosigcheck) {
- acpi_get_table(ACPI_SIG_FACS, 1,
- (struct acpi_table_header **)&facs);
-@@ -914,11 +914,11 @@ int __init acpi_sleep_init(void)
- status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
- if (ACPI_SUCCESS(status)) {
- sleep_states[ACPI_STATE_S5] = 1;
-- printk(" S5");
-+ printk(KERN_CONT " S5");
- pm_power_off_prepare = acpi_power_off_prepare;
- pm_power_off = acpi_power_off;
- }
-- printk(")\n");
-+ printk(KERN_CONT ")\n");
- /*
- * Register the tts_notifier to reboot notifier list so that the _TTS
- * object can also be evaluated when the system enters S5.
diff --git a/kern-cont-mm.patch b/kern-cont-mm.patch
deleted file mode 100644
index 1e5717b..0000000
--- a/kern-cont-mm.patch
+++ /dev/null
@@ -1,27 +0,0 @@
-From: Kay Sievers <kay@vrfy.org>
-Subject: mm: use KERN_CONT in printk() continuation lines
-
-Cc: Andrew Morton <akpm@linux-foundation.org>
-Signed-off-by: Kay Sievers <kay@vrfy.org>
----
- mm/page_alloc.c | 6 +++---
- 1 file changed, 3 insertions(+), 3 deletions(-)
-
---- a/mm/page_alloc.c
-+++ b/mm/page_alloc.c
-@@ -4763,12 +4763,12 @@ void __init free_area_init_nodes(unsigne
- for (i = 0; i < MAX_NR_ZONES; i++) {
- if (i == ZONE_MOVABLE)
- continue;
-- printk(" %-8s ", zone_names[i]);
-+ printk(KERN_CONT " %-8s ", zone_names[i]);
- if (arch_zone_lowest_possible_pfn[i] ==
- arch_zone_highest_possible_pfn[i])
-- printk("empty\n");
-+ printk(KERN_CONT "empty\n");
- else
-- printk("%0#10lx -> %0#10lx\n",
-+ printk(KERN_CONT "%0#10lx -> %0#10lx\n",
- arch_zone_lowest_possible_pfn[i],
- arch_zone_highest_possible_pfn[i]);
- }
diff --git a/kern-cont-parport.patch b/kern-cont-parport.patch
deleted file mode 100644
index 8c7b637..0000000
--- a/kern-cont-parport.patch
+++ /dev/null
@@ -1,78 +0,0 @@
-From: Kay Sievers <kay@vrfy.org>
-Subject: parport: use KERN_CONT in printk() continuation lines
-
-On Tue, May 8, 2012 at 10:48 AM, Sasha Levin <levinsasha928@gmail.com> wrote:
-> Before:
-> [ 10.110626] parport0: PC-style at 0x378, irq 7 [PCSPP,TRISTATE]
->
-> After:
-> parport0: PC-style at 0x378
-> , irq 7
-> [
-> PCSPP
-> ,TRISTATE
-> ]
-
-Signed-off-by: Kay Sievers <kay@vrfy.org>
----
- drivers/parport/parport_pc.c | 16 ++++++++--------
- 1 file changed, 8 insertions(+), 8 deletions(-)
-
---- a/drivers/parport/parport_pc.c
-+++ b/drivers/parport/parport_pc.c
-@@ -2351,7 +2351,7 @@ struct parport *parport_pc_probe_port(un
-
- printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base);
- if (p->base_hi && priv->ecr)
-- printk(" (0x%lx)", p->base_hi);
-+ printk(KERN_CONT " (0x%lx)", p->base_hi);
- if (p->irq == PARPORT_IRQ_AUTO) {
- p->irq = PARPORT_IRQ_NONE;
- parport_irq_probe(p);
-@@ -2362,7 +2362,7 @@ struct parport *parport_pc_probe_port(un
- p->irq = PARPORT_IRQ_NONE;
- }
- if (p->irq != PARPORT_IRQ_NONE) {
-- printk(", irq %d", p->irq);
-+ printk(KERN_CONT ", irq %d", p->irq);
- priv->ctr_writable |= 0x10;
-
- if (p->dma == PARPORT_DMA_AUTO) {
-@@ -2386,21 +2386,21 @@ struct parport *parport_pc_probe_port(un
- /* p->ops->ecp_read_data = parport_pc_ecp_read_block_pio; */
- #endif /* IEEE 1284 support */
- if (p->dma != PARPORT_DMA_NONE) {
-- printk(", dma %d", p->dma);
-+ printk(KERN_CONT ", dma %d", p->dma);
- p->modes |= PARPORT_MODE_DMA;
- } else
-- printk(", using FIFO");
-+ printk(KERN_CONT ", using FIFO");
- } else
- /* We can't use the DMA channel after all. */
- p->dma = PARPORT_DMA_NONE;
- #endif /* Allowed to use FIFO/DMA */
-
-- printk(" [");
-+ printk(KERN_CONT " [");
-
- #define printmode(x) \
- {\
- if (p->modes & PARPORT_MODE_##x) {\
-- printk("%s%s", f ? "," : "", #x);\
-+ printk(KERN_CONT "%s%s", f ? "," : "", #x);\
- f++;\
- } \
- }
-@@ -2416,9 +2416,9 @@ struct parport *parport_pc_probe_port(un
- }
- #undef printmode
- #ifndef CONFIG_PARPORT_1284
-- printk("(,...)");
-+ printk(KERN_CONT "(,...)");
- #endif /* CONFIG_PARPORT_1284 */
-- printk("]\n");
-+ printk(KERN_CONT "]\n");
- if (probedirq != PARPORT_IRQ_NONE)
- printk(KERN_INFO "%s: irq %d detected\n", p->name, probedirq);
-
diff --git a/kmsg-docs.patch b/kmsg-docs.patch
deleted file mode 100644
index 50fcb4f..0000000
--- a/kmsg-docs.patch
+++ /dev/null
@@ -1,114 +0,0 @@
-From: Kay Sievers <kay@vrfy.org>
-Subject: kmsg - add Documentation/ABI/testing/dev-kmsg
-
-Signed-off-by: Kay Sievers <kay@vrfy.org>
----
- Documentation/ABI/testing/dev-kmsg | 90 +++++++++++++++++++++++++++++++++++++
- Documentation/devices.txt | 3 -
- 2 files changed, 92 insertions(+), 1 deletion(-)
-
---- /dev/null
-+++ b/Documentation/ABI/testing/dev-kmsg
-@@ -0,0 +1,90 @@
-+What: /dev/kmsg
-+Date: Mai 2012
-+KernelVersion: 3.4
-+Contact: Kay Sievers <kay@vrfy.org>
-+Description: The /dev/kmsg character device node provides userspace access
-+ to the kernel's printk buffer.
-+
-+ Injecting messages:
-+ Every write() to the opened device node places a log entry in
-+ the kernel's printk buffer.
-+
-+ The logged line can be prefixed with a <N> syslog prefix, which
-+ carries the syslog priority and facility. The single decimal
-+ prefix number is composed of the 3 lowest bits being the syslog
-+ priority and the higher bits the syslog facility number.
-+
-+ If no prefix is given, the priority number is the default kernel
-+ log priority and the facility number is set to LOG_USER (1). It
-+ is not possible to inject messages from userspace with the
-+ facility number LOG_KERN (0), to make sure that the origin of
-+ the messages can always be reliably determined.
-+
-+ Accessing the buffer:
-+ Every read() from the opened device node receives one record
-+ of the kernel's printk buffer.
-+
-+ The first read() directly following an open() always returns
-+ first message in the buffer; there is no kernel-internal
-+ persistent state; many readers can concurrently open the device
-+ and read from it, without affecting other readers.
-+
-+ Every read() will receive the next available record. If no more
-+ records are available read() will block, or if O_NONBLOCK is
-+ used -EAGAIN returned.
-+
-+ Messages in the record ring buffer get overwritten as whole,
-+ there are never partial messages received by read().
-+
-+ In case messages get overwritten in the circular buffer while
-+ the device is kept open, the next read() will return -EPIPE,
-+ and the seek position be updated to the next available record.
-+ Subsequent reads() will return available records again.
-+
-+ Unlike the classic syslog() interface, the 64 bit record
-+ sequence numbers allow to calculate the amount of lost
-+ messages, in case the buffer gets overwritten. And they allow
-+ to reconnect to the buffer and reconstruct the read position
-+ if needed, without limiting the interface to a single reader.
-+
-+ The device supports seek with the following parameters:
-+ SEEK_SET, 0
-+ seek to the first entry in the buffer
-+ SEEK_END, 0
-+ seek after the last entry in the buffer
-+ SEEK_DATA, 0
-+ seek after the last record available at the time
-+ the last SYSLOG_ACTION_CLEAR was issued.
-+
-+ The output format consists of a prefix carrying the syslog
-+ prefix including priority and facility, the 64 bit message
-+ sequence number and the monotonic timestamp in microseconds.
-+ The values are separated by a ','. Future extensions might
-+ add more comma separated values before the terminating ';'.
-+ Unknown values should be gracefully ignored.
-+
-+ The human readable text string starts directly after the ';'
-+ and is terminated by a '\n'. Untrusted values derived from
-+ hardware or other facilities are printed, therefore
-+ all non-printable characters in the log message are escaped
-+ by "\x00" C-style hex encoding.
-+
-+ A line starting with ' ', is a continuation line, adding
-+ key/value pairs to the log message, which provide the machine
-+ readable context of the message, for reliable processing in
-+ userspace.
-+
-+ Example:
-+ 7,160,424069;pci_root PNP0A03:00: host bridge window [io 0x0000-0x0cf7] (ignored)
-+ SUBSYSTEM=acpi
-+ DEVICE=+acpi:PNP0A03:00
-+ 6,339,5140900;NET: Registered protocol family 10
-+ 30,340,5690716;udevd[80]: starting version 181
-+
-+ The DEVICE= key uniquely identifies devices the following way:
-+ b12:8 - block dev_t
-+ c127:3 - char dev_t
-+ n8 - netdev ifindex
-+ +sound:card0 - subsystem:devname
-+
-+Users: dmesg(1), userspace kernel log consumers
---- a/Documentation/devices.txt
-+++ b/Documentation/devices.txt
-@@ -98,7 +98,8 @@ Your cooperation is appreciated.
- 8 = /dev/random Nondeterministic random number gen.
- 9 = /dev/urandom Faster, less secure random number gen.
- 10 = /dev/aio Asynchronous I/O notification interface
-- 11 = /dev/kmsg Writes to this come out as printk's
-+ 11 = /dev/kmsg Writes to this come out as printk's, reads
-+ export the buffered printk records.
- 12 = /dev/oldmem Used by crashdump kernels to access
- the memory of the kernel that crashed.
-
diff --git a/kmsg-fix64bit-division.patch b/kmsg-fix64bit-division.patch
deleted file mode 100644
index 89b12c7..0000000
--- a/kmsg-fix64bit-division.patch
+++ /dev/null
@@ -1,36 +0,0 @@
-From: Kay Sievers <kay@vrfy.org>
-Subject: kmsg: use do_div() to divide 64bit integer
-
-On Tue, May 8, 2012 at 10:02 AM, Stephen Rothwell <sfr@canb.auug.org.au> wrote:
-> kernel/built-in.o: In function `devkmsg_read':
-> printk.c:(.text+0x27e8): undefined reference to `__udivdi3'
-> Most probably the "msg->ts_nsec / 1000" since
-> ts_nsec is a u64 and this is a 32 bit build ...
-
-Signed-off-by: Kay Sievers <kay@vrfy.org>
----
- kernel/printk.c | 5 ++++-
- 1 file changed, 4 insertions(+), 1 deletion(-)
-
---- a/kernel/printk.c
-+++ b/kernel/printk.c
-@@ -407,6 +407,7 @@ static ssize_t devkmsg_read(struct file
- {
- struct devkmsg_user *user = file->private_data;
- struct log *msg;
-+ u64 ts_usec;
- size_t i;
- size_t len;
- ssize_t ret;
-@@ -441,8 +442,10 @@ static ssize_t devkmsg_read(struct file
- }
-
- msg = log_from_idx(user->idx);
-+ ts_usec = msg->ts_nsec;
-+ do_div(ts_usec, 1000);
- len = sprintf(user->buf, "%u,%llu,%llu;",
-- msg->level, user->seq, msg->ts_nsec / 1000);
-+ msg->level, user->seq, ts_usec);
-
- /* escape non-printable characters */
- for (i = 0; i < msg->text_len; i++) {
diff --git a/kmsg-multiline.patch b/kmsg-multiline.patch
new file mode 100644
index 0000000..46c751c
--- /dev/null
+++ b/kmsg-multiline.patch
@@ -0,0 +1,243 @@
+From: Kay Sievers <kay@vrfy.org>
+Subject: printk() - restore prefix/timestamp printing for multi-newline strings
+
+Calls like:
+ printk("\n *** DEADLOCK ***\n\n");
+will print 3 properly indented, seperated, syslog + timestamp prefixed lines in
+the log output.
+
+Reported-By: Sasha Levin <levinsasha928@gmail.com>
+Signed-off-by: Kay Sievers <kay@vrfy.org>
+---
+
+ kernel/printk.c | 133 +++++++++++++++++++++++++++++++++-----------------------
+ 1 file changed, 79 insertions(+), 54 deletions(-)
+
+--- a/kernel/printk.c
++++ b/kernel/printk.c
+@@ -448,7 +448,7 @@ static ssize_t devkmsg_read(struct file
+
+ /* escape non-printable characters */
+ for (i = 0; i < msg->text_len; i++) {
+- char c = log_text(msg)[i];
++ unsigned char c = log_text(msg)[i];
+
+ if (c < ' ' || c >= 128)
+ len += sprintf(user->buf + len, "\\x%02x", c);
+@@ -461,7 +461,7 @@ static ssize_t devkmsg_read(struct file
+ bool line = true;
+
+ for (i = 0; i < msg->dict_len; i++) {
+- char c = log_dict(msg)[i];
++ unsigned char c = log_dict(msg)[i];
+
+ if (line) {
+ user->buf[len++] = ' ';
+@@ -785,56 +785,81 @@ static bool printk_time;
+ #endif
+ module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR);
+
+-static size_t prepend_timestamp(unsigned long long t, char *buf)
++static size_t print_prefix(const struct log *msg, bool syslog, char *buf)
+ {
+- unsigned long rem_ns;
++ size_t len = 0;
+
+- if (!printk_time)
+- return 0;
++ if (syslog) {
++ if (buf) {
++ len += sprintf(buf, "<%u>", msg->level);
++ } else {
++ len += 3;
++ if (msg->level > 9)
++ len++;
++ if (msg->level > 99)
++ len++;
++ }
++ }
+
+- if (!buf)
+- return 15;
++ if (printk_time) {
++ if (buf) {
++ unsigned long long ts = msg->ts_nsec;
++ unsigned long rem_nsec = do_div(ts, 1000000000);
+
+- rem_ns = do_div(t, 1000000000);
++ len += sprintf(buf + len, "[%5lu.%06lu] ",
++ (unsigned long) ts, rem_nsec / 1000);
++ } else {
++ len += 15;
++ }
++ }
+
+- return sprintf(buf, "[%5lu.%06lu] ",
+- (unsigned long) t, rem_ns / 1000);
++ return len;
+ }
+
+-static int syslog_print_line(u32 idx, char *text, size_t size)
++static size_t msg_print_text(const struct log *msg, bool syslog,
++ char *buf, size_t size)
+ {
+- struct log *msg;
+- size_t len;
++ const char *text = log_text(msg);
++ size_t text_size = msg->text_len;
++ size_t len = 0;
++
++ do {
++ const char *next = memchr(text, '\n', text_size);
++ size_t text_len;
++
++ if (next) {
++ text_len = next - text;
++ next++;
++ text_size -= next - text;
++ } else {
++ text_len = text_size;
++ }
++
++ if (buf) {
++ if (print_prefix(msg, syslog, NULL) +
++ text_len + 1>= size - len)
++ break;
++
++ len += print_prefix(msg, syslog, buf + len);
++ memcpy(buf + len, text, text_len);
++ len += text_len;
++ buf[len++] = '\n';
++ } else {
++ /* SYSLOG_ACTION_* buffer size only calculation */
++ len += print_prefix(msg, syslog, NULL);
++ len += text_len + 1;
++ }
++
++ text = next;
++ } while (text);
+
+- msg = log_from_idx(idx);
+- if (!text) {
+- /* calculate length only */
+- len = 3;
+-
+- if (msg->level > 9)
+- len++;
+- if (msg->level > 99)
+- len++;
+- len += prepend_timestamp(0, NULL);
+-
+- len += msg->text_len;
+- len++;
+- return len;
+- }
+-
+- len = sprintf(text, "<%u>", msg->level);
+- len += prepend_timestamp(msg->ts_nsec, text + len);
+- if (len + msg->text_len > size)
+- return -EINVAL;
+- memcpy(text + len, log_text(msg), msg->text_len);
+- len += msg->text_len;
+- text[len++] = '\n';
+ return len;
+ }
+
+ static int syslog_print(char __user *buf, int size)
+ {
+ char *text;
++ struct log *msg;
+ int len;
+
+ text = kmalloc(LOG_LINE_MAX, GFP_KERNEL);
+@@ -847,7 +872,8 @@ static int syslog_print(char __user *buf
+ syslog_seq = log_first_seq;
+ syslog_idx = log_first_idx;
+ }
+- len = syslog_print_line(syslog_idx, text, LOG_LINE_MAX);
++ msg = log_from_idx(syslog_idx);
++ len = msg_print_text(msg, true, text, LOG_LINE_MAX);
+ syslog_idx = log_next(syslog_idx);
+ syslog_seq++;
+ raw_spin_unlock_irq(&logbuf_lock);
+@@ -887,14 +913,18 @@ static int syslog_print_all(char __user
+ seq = clear_seq;
+ idx = clear_idx;
+ while (seq < log_next_seq) {
+- len += syslog_print_line(idx, NULL, 0);
++ struct log *msg = log_from_idx(idx);
++
++ len += msg_print_text(msg, true, NULL, 0);
+ idx = log_next(idx);
+ seq++;
+ }
+ seq = clear_seq;
+ idx = clear_idx;
+ while (len > size && seq < log_next_seq) {
+- len -= syslog_print_line(idx, NULL, 0);
++ struct log *msg = log_from_idx(idx);
++
++ len -= msg_print_text(msg, true, NULL, 0);
+ idx = log_next(idx);
+ seq++;
+ }
+@@ -904,9 +934,10 @@ static int syslog_print_all(char __user
+
+ len = 0;
+ while (len >= 0 && seq < next_seq) {
++ struct log *msg = log_from_idx(idx);
+ int textlen;
+
+- textlen = syslog_print_line(idx, text, LOG_LINE_MAX);
++ textlen = msg_print_text(msg, true, text, LOG_LINE_MAX);
+ if (textlen < 0) {
+ len = textlen;
+ break;
+@@ -1044,7 +1075,9 @@ int do_syslog(int type, char __user *buf
+ seq = syslog_seq;
+ idx = syslog_idx;
+ while (seq < log_next_seq) {
+- error += syslog_print_line(idx, NULL, 0);
++ struct log *msg = log_from_idx(idx);
++
++ error += msg_print_text(msg, true, NULL, 0);
+ idx = log_next(idx);
+ seq++;
+ }
+@@ -1439,10 +1472,8 @@ static struct log *log_from_idx(u32 idx)
+ static u32 log_next(u32 idx) { return 0; }
+ static char *log_text(const struct log *msg) { return NULL; }
+ static void call_console_drivers(int level, const char *text, size_t len) {}
+-static size_t prepend_timestamp(unsigned long long t, char *buf)
+-{
+- return 0;
+-}
++static size_t msg_print_text(const struct log *msg, bool syslog,
++ char *buf, size_t size) { return 0; }
+
+ #endif /* CONFIG_PRINTK */
+
+@@ -1750,7 +1781,7 @@ again:
+ for (;;) {
+ struct log *msg;
+ static char text[LOG_LINE_MAX];
+- size_t len, l;
++ size_t len;
+ int level;
+
+ raw_spin_lock_irqsave(&logbuf_lock, flags);
+@@ -1771,13 +1802,7 @@ again:
+ msg = log_from_idx(console_idx);
+ level = msg->level & 7;
+
+- len = prepend_timestamp(msg->ts_nsec, text);
+- l = msg->text_len;
+- if (len + l + 1 >= sizeof(text))
+- l = sizeof(text) - len - 1;
+- memcpy(text + len, log_text(msg), l);
+- len += l;
+- text[len++] = '\n';
++ len = msg_print_text(msg, false, text, sizeof(text));
+
+ console_idx = log_next(console_idx);
+ console_seq++;
diff --git a/kmsg-off.patch b/kmsg-off.patch
deleted file mode 100644
index ccf51a0..0000000
--- a/kmsg-off.patch
+++ /dev/null
@@ -1,108 +0,0 @@
-From: Kay Sievers <kay@vrfy.org>
-Subject: printk - fix compilation for CONFIG_PRINTK=n
-
-Signed-off-by: Kay Sievers <kay@vrfy.org>
----
- drivers/char/mem.c | 2 ++
- kernel/printk.c | 41 ++++++++++++++++++++++-------------------
- 2 files changed, 24 insertions(+), 19 deletions(-)
-
---- a/drivers/char/mem.c
-+++ b/drivers/char/mem.c
-@@ -825,7 +825,9 @@ static const struct memdev {
- [7] = { "full", 0666, &full_fops, NULL },
- [8] = { "random", 0666, &random_fops, NULL },
- [9] = { "urandom", 0666, &urandom_fops, NULL },
-+#ifdef CONFIG_PRINTK
- [11] = { "kmsg", 0644, &kmsg_fops, NULL },
-+#endif
- #ifdef CONFIG_CRASH_DUMP
- [12] = { "oldmem", 0, &oldmem_fops, NULL },
- #endif
---- a/kernel/printk.c
-+++ b/kernel/printk.c
-@@ -126,7 +126,6 @@ EXPORT_SYMBOL(console_set_on_cmdline);
- /* Flag: console code may call schedule() */
- static int console_may_schedule;
-
--#ifdef CONFIG_PRINTK
- /*
- * The printk log buffer consists of a chain of concatenated variable
- * length records. Every record starts with a record header, containing
-@@ -208,16 +207,9 @@ struct log {
- */
- static DEFINE_RAW_SPINLOCK(logbuf_lock);
-
--/* cpu currently holding logbuf_lock */
--static volatile unsigned int logbuf_cpu = UINT_MAX;
--
--#define LOG_LINE_MAX 1024
--
--/* record buffer */
--#define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT)
--static char __log_buf[__LOG_BUF_LEN];
--static char *log_buf = __log_buf;
--static u32 log_buf_len = __LOG_BUF_LEN;
-+/* the next printk record to read by syslog(READ) or /proc/kmsg */
-+static u64 syslog_seq;
-+static u32 syslog_idx;
-
- /* index and sequence number of the first record stored in the buffer */
- static u64 log_first_seq;
-@@ -225,15 +217,23 @@ static u32 log_first_idx;
-
- /* index and sequence number of the next record to store in the buffer */
- static u64 log_next_seq;
-+#ifdef CONFIG_PRINTK
- static u32 log_next_idx;
-
- /* the next printk record to read after the last 'clear' command */
- static u64 clear_seq;
- static u32 clear_idx;
-
--/* the next printk record to read by syslog(READ) or /proc/kmsg */
--static u64 syslog_seq;
--static u32 syslog_idx;
-+#define LOG_LINE_MAX 1024
-+
-+/* record buffer */
-+#define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT)
-+static char __log_buf[__LOG_BUF_LEN];
-+static char *log_buf = __log_buf;
-+static u32 log_buf_len = __LOG_BUF_LEN;
-+
-+/* cpu currently holding logbuf_lock */
-+static volatile unsigned int logbuf_cpu = UINT_MAX;
-
- /* human readable text of the record */
- static char *log_text(const struct log *msg)
-@@ -1425,13 +1425,16 @@ asmlinkage int printk(const char *fmt, .
- return r;
- }
- EXPORT_SYMBOL(printk);
-+
- #else
-
--static void call_console_drivers(int level, const char *text, size_t len)
--{
--}
-+#define LOG_LINE_MAX 0
-+static struct log *log_from_idx(u32 idx) { return NULL; }
-+static u32 log_next(u32 idx) { return 0; }
-+static char *log_text(const struct log *msg) { return NULL; }
-+static void call_console_drivers(int level, const char *text, size_t len) {}
-
--#endif
-+#endif /* CONFIG_PRINTK */
-
- static int __add_preferred_console(char *name, int idx, char *options,
- char *brl_options)
-@@ -1715,7 +1718,7 @@ static u32 console_idx;
- * by printk(). If this is the case, console_unlock(); emits
- * the output prior to releasing the lock.
- *
-- * If there is output waiting, we wake it /dev/kmsg and syslog() users.
-+ * If there is output waiting, we wake /dev/kmsg and syslog() users.
- *
- * console_unlock(); may be called from any context.
- */
diff --git a/kmsg-sep-cont.patch b/kmsg-sep-cont.patch
new file mode 100644
index 0000000..c7457ea
--- /dev/null
+++ b/kmsg-sep-cont.patch
@@ -0,0 +1,211 @@
+From: Kay Sievers <kay@vrfy.org>
+Subject: printk() - isolate KERN_CONT users from ordinary complete lines
+
+Arrange the contination printk() buffering to be fully separated from the
+ordinary full line users.
+
+Limit the exposure to races and wrong printk() line merges to users of
+continuation only. Ordinary users racing against continuation users will
+no longer affect each other.
+
+Multiple continuation users from differnt threads, racing against each
+other will not wrongly be merged into a single line, but printed as
+separate lines.
+
+Test output of a kernel module which starts two separate threads which
+race against each other, one of them printing a single full terminated
+line:
+ printk("(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)\n");
+
+The other one printing a line in a continuation loop:
+ printk("(C");
+ for (i = 0; i < 58; i++)
+ printk(KERN_CONT "C");
+ printk(KERN_CONT "C)\n");
+
+Behavior of single and non-thread-aware printk() buffer:
+ # modprobe printk-race
+ printk test init
+ (CC(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
+ C(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
+ CC(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
+ C(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
+ CC(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
+ C(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
+ C(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
+ CC(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
+ C(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
+ C(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
+ CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC)
+ (CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC)
+
+New behavior with separate and thread-aware continuation buffer:
+ # modprobe printk-race
+ printk test init
+ (AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
+ (AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
+ (AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
+ (CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC)
+ (AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
+ (AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
+ (AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
+ (AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
+ (CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC)
+ (CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC)
+
+Signed-off-by: Kay Sievers <kay@vrfy.org>
+---
+
+ kernel/printk.c | 108 +++++++++++++++++++++++++++++++-------------------------
+ 1 file changed, 60 insertions(+), 48 deletions(-)
+
+--- a/kernel/printk.c
++++ b/kernel/printk.c
+@@ -1264,13 +1264,13 @@ asmlinkage int vprintk_emit(int facility
+ const char *fmt, va_list args)
+ {
+ static int recursion_bug;
+- static char buf[LOG_LINE_MAX];
+- static size_t buflen;
+- static int buflevel;
++ static char cont_buf[LOG_LINE_MAX];
++ static size_t cont_len;
++ static int cont_level;
++ static struct task_struct *cont_task;
+ static char textbuf[LOG_LINE_MAX];
+- static struct task_struct *cont;
+ char *text = textbuf;
+- size_t textlen;
++ size_t text_len;
+ unsigned long flags;
+ int this_cpu;
+ bool newline = false;
+@@ -1320,15 +1320,15 @@ asmlinkage int vprintk_emit(int facility
+ * The printf needs to come first; we need the syslog
+ * prefix which might be passed-in as a parameter.
+ */
+- textlen = vscnprintf(text, sizeof(textbuf), fmt, args);
++ text_len = vscnprintf(text, sizeof(textbuf), fmt, args);
+
+ /* mark and strip a trailing newline */
+- if (textlen && text[textlen-1] == '\n') {
+- textlen--;
++ if (text_len && text[text_len-1] == '\n') {
++ text_len--;
+ newline = true;
+ }
+
+- /* strip syslog prefix and extract log level or flags */
++ /* strip syslog prefix and extract log level or control flags */
+ if (text[0] == '<' && text[1] && text[2] == '>') {
+ switch (text[1]) {
+ case '0' ... '7':
+@@ -1338,49 +1338,62 @@ asmlinkage int vprintk_emit(int facility
+ prefix = true;
+ case 'c': /* KERN_CONT */
+ text += 3;
+- textlen -= 3;
++ text_len -= 3;
+ }
+ }
+
+- if (buflen && (prefix || dict || cont != current)) {
+- /* flush existing buffer */
+- log_store(facility, buflevel, NULL, 0, buf, buflen);
+- printed_len += buflen;
+- buflen = 0;
+- }
+-
+- if (buflen == 0) {
+- /* remember level for first message in the buffer */
+- if (level == -1)
+- buflevel = default_message_loglevel;
+- else
+- buflevel = level;
+- }
+-
+- if (buflen || !newline) {
+- /* append to existing buffer, or buffer until next message */
+- if (buflen + textlen > sizeof(buf))
+- textlen = sizeof(buf) - buflen;
+- memcpy(buf + buflen, text, textlen);
+- buflen += textlen;
+- }
+-
+- if (newline) {
+- /* end of line; flush buffer */
+- if (buflen) {
+- log_store(facility, buflevel,
+- dict, dictlen, buf, buflen);
+- printed_len += buflen;
+- buflen = 0;
+- } else {
+- log_store(facility, buflevel,
+- dict, dictlen, text, textlen);
+- printed_len += textlen;
++ if (level == -1)
++ level = default_message_loglevel;
++
++ if (!newline) {
++ if (cont_len && (prefix || cont_task != current)) {
++ /*
++ * Flush earlier buffer, which is either from a
++ * different thread, or when we got a new prefix.
++ */
++ log_store(facility, cont_level, NULL, 0, cont_buf, cont_len);
++ cont_len = 0;
++ }
++
++ if (!cont_len) {
++ cont_level = level;
++ cont_task = current;
+ }
+- cont = NULL;
++
++ /* buffer or append to earlier buffer from the same thread */
++ if (cont_len + text_len > sizeof(cont_buf))
++ text_len = sizeof(cont_buf) - cont_len;
++ memcpy(cont_buf + cont_len, text, text_len);
++ cont_len += text_len;
+ } else {
+- /* remember thread which filled the buffer */
+- cont = current;
++ if (cont_len && cont_task == current) {
++ if (prefix) {
++ /*
++ * New prefix from the same thread; flush. We
++ * either got no earlier newline, or we race
++ * with an interrupt.
++ */
++ log_store(facility, cont_level,
++ NULL, 0, cont_buf, cont_len);
++ cont_len = 0;
++ }
++
++ /* append to the earlier buffer and flush */
++ if (cont_len + text_len > sizeof(cont_buf))
++ text_len = sizeof(cont_buf) - cont_len;
++ memcpy(cont_buf + cont_len, text, text_len);
++ cont_len += text_len;
++ log_store(facility, cont_level,
++ NULL, 0, cont_buf, cont_len);
++ cont_len = 0;
++ cont_task = NULL;
++ printed_len = cont_len;
++ } else {
++ /* ordinary single and terminated line */
++ log_store(facility, level,
++ dict, dictlen, text, text_len);
++ printed_len = text_len;
++ }
+ }
+
+ /*
+@@ -1470,7 +1483,6 @@ EXPORT_SYMBOL(printk);
+ #define LOG_LINE_MAX 0
+ static struct log *log_from_idx(u32 idx) { return NULL; }
+ static u32 log_next(u32 idx) { return 0; }
+-static char *log_text(const struct log *msg) { return NULL; }
+ static void call_console_drivers(int level, const char *text, size_t len) {}
+ static size_t msg_print_text(const struct log *msg, bool syslog,
+ char *buf, size_t size) { return 0; }
diff --git a/printk-dev_printk.patch b/printk-dev_printk.patch
deleted file mode 100644
index 935d913..0000000
--- a/printk-dev_printk.patch
+++ /dev/null
@@ -1,94 +0,0 @@
-From: Kay Sievers <kay@vrfy.org>
-Subject: driver-core: extend dev_printk() to pass structured data
-
-Extends dev_printk() to attach a dictionary with a device identifier
-and the driver core subsystem name to logged messages, which makes
-dev_prink() reliable machine-readable. In addition to the printed
-plain text message, it creates these properties:
- SUBSYSTEM= - the driver-core subsytem name
- DEVICE=
- b12:8 - block dev_t
- c127:3 - char dev_t
- n8 - netdev ifindex
- +sound:card0 - subsystem:devname
-
-Tested-by: William Douglas <william.douglas@intel.com>
-Signed-off-by: Kay Sievers <kay@vrfy.org>
----
- drivers/base/core.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++---
- 1 file changed, 49 insertions(+), 3 deletions(-)
-
---- a/drivers/base/core.c
-+++ b/drivers/base/core.c
-@@ -25,6 +25,7 @@
- #include <linux/mutex.h>
- #include <linux/async.h>
- #include <linux/pm_runtime.h>
-+#include <linux/netdevice.h>
-
- #include "base.h"
- #include "power/power.h"
-@@ -1843,15 +1844,60 @@ void device_shutdown(void)
- */
-
- #ifdef CONFIG_PRINTK
--
- int __dev_printk(const char *level, const struct device *dev,
- struct va_format *vaf)
- {
-+ char dict[128];
-+ size_t dictlen = 0;
-+ const char *subsys;
-+
- if (!dev)
- return printk("%s(NULL device *): %pV", level, vaf);
-
-- return printk("%s%s %s: %pV",
-- level, dev_driver_string(dev), dev_name(dev), vaf);
-+ if (dev->class)
-+ subsys = dev->class->name;
-+ else if (dev->bus)
-+ subsys = dev->bus->name;
-+ else
-+ goto skip;
-+
-+ dictlen += snprintf(dict + dictlen, sizeof(dict) - dictlen,
-+ "SUBSYSTEM=%s", subsys);
-+
-+ /*
-+ * Add device identifier DEVICE=:
-+ * b12:8 block dev_t
-+ * c127:3 char dev_t
-+ * n8 netdev ifindex
-+ * +sound:card0 subsystem:devname
-+ */
-+ if (MAJOR(dev->devt)) {
-+ char c;
-+
-+ if (strcmp(subsys, "block") == 0)
-+ c = 'b';
-+ else
-+ c = 'c';
-+ dictlen++;
-+ dictlen += snprintf(dict + dictlen, sizeof(dict) - dictlen,
-+ "DEVICE=%c%u:%u",
-+ c, MAJOR(dev->devt), MINOR(dev->devt));
-+ } else if (strcmp(subsys, "net") == 0) {
-+ struct net_device *net = to_net_dev(dev);
-+
-+ dictlen++;
-+ dictlen += snprintf(dict + dictlen, sizeof(dict) - dictlen,
-+ "DEVICE=n%u", net->ifindex);
-+ } else {
-+ dictlen++;
-+ dictlen += snprintf(dict + dictlen, sizeof(dict) - dictlen,
-+ "DEVICE=+%s:%s", subsys, dev_name(dev));
-+ }
-+skip:
-+ return printk_emit(0, level[1] - '0',
-+ dictlen ? dict : NULL, dictlen,
-+ "%s %s: %pV",
-+ dev_driver_string(dev), dev_name(dev), vaf);
- }
- EXPORT_SYMBOL(__dev_printk);
-
diff --git a/printk-devkmsg.patch b/printk-devkmsg.patch
deleted file mode 100644
index 6edc524..0000000
--- a/printk-devkmsg.patch
+++ /dev/null
@@ -1,463 +0,0 @@
-From: Kay Sievers <kay@vrfy.org>
-Subject: kmsg: export printk records to the /dev/kmsg interface
-
-Support for multiple concurrent readers of /dev/kmsg, with read(),
-seek(), poll() support. Output of message sequence numbers, to allow
-userspace log consumers to reliably reconnect and reconstruct their
-state at any given time. After open("/dev/kmsg"), read() always
-returns *all* buffered records. If only future messages should be
-read, SEEK_END can be used. In case records get overwritten while
-/dev/kmsg is held open, or records get faster overwritten than they
-are read, the next read() will return -EPIPE and the current reading
-position gets updated to the next available record. The passed
-sequence numbers allow the log consumer to calculate the amount of
-lost messages.
-
- [root@mop ~]# cat /dev/kmsg
- 5,0,0;Linux version 3.4.0-rc1+ (kay@mop) (gcc version 4.7.0 20120315 ...
- 6,159,423091;ACPI: PCI Root Bridge [PCI0] (domain 0000 [bus 00-ff])
- 7,160,424069;pci_root PNP0A03:00: host bridge window [io 0x0000-0x0cf7] (ignored)
- SUBSYSTEM=acpi
- DEVICE=+acpi:PNP0A03:00
- 6,339,5140900;NET: Registered protocol family 10
- 30,340,5690716;udevd[80]: starting version 181
- 6,341,6081421;FDC 0 is a S82078B
- 6,345,6154686;microcode: CPU0 sig=0x623, pf=0x0, revision=0x0
- 7,346,6156968;sr 1:0:0:0: Attached scsi CD-ROM sr0
- SUBSYSTEM=scsi
- DEVICE=+scsi:1:0:0:0
- 6,347,6289375;microcode: CPU1 sig=0x623, pf=0x0, revision=0x0
-
-Cc: Karel Zak <kzak@redhat.com>
-Tested-by: William Douglas <william.douglas@intel.com>
-Signed-off-by: Kay Sievers <kay@vrfy.org>
----
- drivers/char/mem.c | 61 ---------
- include/linux/printk.h | 2
- kernel/printk.c | 313 +++++++++++++++++++++++++++++++++++++++++++++++++
- 3 files changed, 316 insertions(+), 60 deletions(-)
-
---- a/drivers/char/mem.c
-+++ b/drivers/char/mem.c
-@@ -807,65 +807,6 @@ static const struct file_operations oldm
- };
- #endif
-
--static ssize_t kmsg_writev(struct kiocb *iocb, const struct iovec *iv,
-- unsigned long count, loff_t pos)
--{
-- char *buf, *line;
-- int i;
-- int level = default_message_loglevel;
-- int facility = 1; /* LOG_USER */
-- size_t len = iov_length(iv, count);
-- ssize_t ret = len;
--
-- if (len > 1024)
-- return -EINVAL;
-- buf = kmalloc(len+1, GFP_KERNEL);
-- if (buf == NULL)
-- return -ENOMEM;
--
-- line = buf;
-- for (i = 0; i < count; i++) {
-- if (copy_from_user(line, iv[i].iov_base, iv[i].iov_len))
-- goto out;
-- line += iv[i].iov_len;
-- }
--
-- /*
-- * Extract and skip the syslog prefix <[0-9]*>. Coming from userspace
-- * the decimal value represents 32bit, the lower 3 bit are the log
-- * level, the rest are the log facility.
-- *
-- * If no prefix or no userspace facility is specified, we
-- * enforce LOG_USER, to be able to reliably distinguish
-- * kernel-generated messages from userspace-injected ones.
-- */
-- line = buf;
-- if (line[0] == '<') {
-- char *endp = NULL;
--
-- i = simple_strtoul(line+1, &endp, 10);
-- if (endp && endp[0] == '>') {
-- level = i & 7;
-- if (i >> 3)
-- facility = i >> 3;
-- endp++;
-- len -= endp - line;
-- line = endp;
-- }
-- }
-- line[len] = '\0';
--
-- printk_emit(facility, level, NULL, 0, "%s", line);
--out:
-- kfree(buf);
-- return ret;
--}
--
--static const struct file_operations kmsg_fops = {
-- .aio_write = kmsg_writev,
-- .llseek = noop_llseek,
--};
--
- static const struct memdev {
- const char *name;
- umode_t mode;
-@@ -884,7 +825,7 @@ static const struct memdev {
- [7] = { "full", 0666, &full_fops, NULL },
- [8] = { "random", 0666, &random_fops, NULL },
- [9] = { "urandom", 0666, &urandom_fops, NULL },
-- [11] = { "kmsg", 0, &kmsg_fops, NULL },
-+ [11] = { "kmsg", 0644, &kmsg_fops, NULL },
- #ifdef CONFIG_CRASH_DUMP
- [12] = { "oldmem", 0, &oldmem_fops, NULL },
- #endif
---- a/include/linux/printk.h
-+++ b/include/linux/printk.h
-@@ -300,6 +300,8 @@ extern void dump_stack(void) __cold;
- no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
- #endif
-
-+extern const struct file_operations kmsg_fops;
-+
- enum {
- DUMP_PREFIX_NONE,
- DUMP_PREFIX_ADDRESS,
---- a/kernel/printk.c
-+++ b/kernel/printk.c
-@@ -41,6 +41,7 @@
- #include <linux/cpu.h>
- #include <linux/notifier.h>
- #include <linux/rculist.h>
-+#include <linux/poll.h>
-
- #include <asm/uaccess.h>
-
-@@ -149,6 +150,48 @@ static int console_may_schedule;
- * length of the message text is stored in the header, the stored message
- * is not terminated.
- *
-+ * Optionally, a message can carry a dictionary of properties (key/value pairs),
-+ * to provide userspace with a machine-readable message context.
-+ *
-+ * Examples for well-defined, commonly used property names are:
-+ * DEVICE=b12:8 device identifier
-+ * b12:8 block dev_t
-+ * c127:3 char dev_t
-+ * n8 netdev ifindex
-+ * +sound:card0 subsystem:devname
-+ * SUBSYSTEM=pci driver-core subsystem name
-+ *
-+ * Valid characters in property names are [a-zA-Z0-9.-_]. The plain text value
-+ * follows directly after a '=' character. Every property is terminated by
-+ * a '\0' character. The last property is not terminated.
-+ *
-+ * Example of a message structure:
-+ * 0000 ff 8f 00 00 00 00 00 00 monotonic time in nsec
-+ * 0008 34 00 record is 52 bytes long
-+ * 000a 0b 00 text is 11 bytes long
-+ * 000c 1f 00 dictionary is 23 bytes long
-+ * 000e 03 00 LOG_KERN (facility) LOG_ERR (level)
-+ * 0010 69 74 27 73 20 61 20 6c "it's a l"
-+ * 69 6e 65 "ine"
-+ * 001b 44 45 56 49 43 "DEVIC"
-+ * 45 3d 62 38 3a 32 00 44 "E=b8:2\0D"
-+ * 52 49 56 45 52 3d 62 75 "RIVER=bu"
-+ * 67 "g"
-+ * 0032 00 00 00 padding to next message header
-+ *
-+ * The 'struct log' buffer header must never be directly exported to
-+ * userspace, it is a kernel-private implementation detail that might
-+ * need to be changed in the future, when the requirements change.
-+ *
-+ * /dev/kmsg exports the structured data in the following line format:
-+ * "level,sequnum,timestamp;<message text>\n"
-+ *
-+ * The optional key/value pairs are attached as continuation lines starting
-+ * with a space character and terminated by a newline. All possible
-+ * non-prinatable characters are escaped in the "\xff" notation.
-+ *
-+ * Users of the export format should ignore possible additional values
-+ * separated by ',', and find the message after the ';' character.
- */
-
- struct log {
-@@ -297,6 +340,276 @@ static void log_store(int facility, int
- log_next_seq++;
- }
-
-+/* /dev/kmsg - userspace message inject/listen interface */
-+struct devkmsg_user {
-+ u64 seq;
-+ u32 idx;
-+ struct mutex lock;
-+ char buf[8192];
-+};
-+
-+static ssize_t devkmsg_writev(struct kiocb *iocb, const struct iovec *iv,
-+ unsigned long count, loff_t pos)
-+{
-+ char *buf, *line;
-+ int i;
-+ int level = default_message_loglevel;
-+ int facility = 1; /* LOG_USER */
-+ size_t len = iov_length(iv, count);
-+ ssize_t ret = len;
-+
-+ if (len > LOG_LINE_MAX)
-+ return -EINVAL;
-+ buf = kmalloc(len+1, GFP_KERNEL);
-+ if (buf == NULL)
-+ return -ENOMEM;
-+
-+ line = buf;
-+ for (i = 0; i < count; i++) {
-+ if (copy_from_user(line, iv[i].iov_base, iv[i].iov_len))
-+ goto out;
-+ line += iv[i].iov_len;
-+ }
-+
-+ /*
-+ * Extract and skip the syslog prefix <[0-9]*>. Coming from userspace
-+ * the decimal value represents 32bit, the lower 3 bit are the log
-+ * level, the rest are the log facility.
-+ *
-+ * If no prefix or no userspace facility is specified, we
-+ * enforce LOG_USER, to be able to reliably distinguish
-+ * kernel-generated messages from userspace-injected ones.
-+ */
-+ line = buf;
-+ if (line[0] == '<') {
-+ char *endp = NULL;
-+
-+ i = simple_strtoul(line+1, &endp, 10);
-+ if (endp && endp[0] == '>') {
-+ level = i & 7;
-+ if (i >> 3)
-+ facility = i >> 3;
-+ endp++;
-+ len -= endp - line;
-+ line = endp;
-+ }
-+ }
-+ line[len] = '\0';
-+
-+ printk_emit(facility, level, NULL, 0, "%s", line);
-+out:
-+ kfree(buf);
-+ return ret;
-+}
-+
-+static ssize_t devkmsg_read(struct file *file, char __user *buf,
-+ size_t count, loff_t *ppos)
-+{
-+ struct devkmsg_user *user = file->private_data;
-+ struct log *msg;
-+ size_t i;
-+ size_t len;
-+ ssize_t ret;
-+
-+ if (!user)
-+ return -EBADF;
-+
-+ mutex_lock(&user->lock);
-+ raw_spin_lock(&logbuf_lock);
-+ while (user->seq == log_next_seq) {
-+ if (file->f_flags & O_NONBLOCK) {
-+ ret = -EAGAIN;
-+ raw_spin_unlock(&logbuf_lock);
-+ goto out;
-+ }
-+
-+ raw_spin_unlock(&logbuf_lock);
-+ ret = wait_event_interruptible(log_wait,
-+ user->seq != log_next_seq);
-+ if (ret)
-+ goto out;
-+ raw_spin_lock(&logbuf_lock);
-+ }
-+
-+ if (user->seq < log_first_seq) {
-+ /* our last seen message is gone, return error and reset */
-+ user->idx = log_first_idx;
-+ user->seq = log_first_seq;
-+ ret = -EPIPE;
-+ raw_spin_unlock(&logbuf_lock);
-+ goto out;
-+ }
-+
-+ msg = log_from_idx(user->idx);
-+ len = sprintf(user->buf, "%u,%llu,%llu;",
-+ msg->level, user->seq, msg->ts_nsec / 1000);
-+
-+ /* escape non-printable characters */
-+ for (i = 0; i < msg->text_len; i++) {
-+ char c = log_text(msg)[i];
-+
-+ if (c < ' ' || c >= 128)
-+ len += sprintf(user->buf + len, "\\x%02x", c);
-+ else
-+ user->buf[len++] = c;
-+ }
-+ user->buf[len++] = '\n';
-+
-+ if (msg->dict_len) {
-+ bool line = true;
-+
-+ for (i = 0; i < msg->dict_len; i++) {
-+ char c = log_dict(msg)[i];
-+
-+ if (line) {
-+ user->buf[len++] = ' ';
-+ line = false;
-+ }
-+
-+ if (c == '\0') {
-+ user->buf[len++] = '\n';
-+ line = true;
-+ continue;
-+ }
-+
-+ if (c < ' ' || c >= 128) {
-+ len += sprintf(user->buf + len, "\\x%02x", c);
-+ continue;
-+ }
-+
-+ user->buf[len++] = c;
-+ }
-+ user->buf[len++] = '\n';
-+ }
-+
-+ user->idx = log_next(user->idx);
-+ user->seq++;
-+ raw_spin_unlock(&logbuf_lock);
-+
-+ if (len > count) {
-+ ret = -EINVAL;
-+ goto out;
-+ }
-+
-+ if (copy_to_user(buf, user->buf, len)) {
-+ ret = -EFAULT;
-+ goto out;
-+ }
-+ ret = len;
-+out:
-+ mutex_unlock(&user->lock);
-+ return ret;
-+}
-+
-+static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
-+{
-+ struct devkmsg_user *user = file->private_data;
-+ loff_t ret = 0;
-+
-+ if (!user)
-+ return -EBADF;
-+ if (offset)
-+ return -ESPIPE;
-+
-+ raw_spin_lock(&logbuf_lock);
-+ switch (whence) {
-+ case SEEK_SET:
-+ /* the first record */
-+ user->idx = log_first_idx;
-+ user->seq = log_first_seq;
-+ break;
-+ case SEEK_DATA:
-+ /*
-+ * The first record after the last SYSLOG_ACTION_CLEAR,
-+ * like issued by 'dmesg -c'. Reading /dev/kmsg itself
-+ * changes no global state, and does not clear anything.
-+ */
-+ user->idx = clear_idx;
-+ user->seq = clear_seq;
-+ break;
-+ case SEEK_END:
-+ /* after the last record */
-+ user->idx = log_next_idx;
-+ user->seq = log_next_seq;
-+ break;
-+ default:
-+ ret = -EINVAL;
-+ }
-+ raw_spin_unlock(&logbuf_lock);
-+ return ret;
-+}
-+
-+static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
-+{
-+ struct devkmsg_user *user = file->private_data;
-+ int ret = 0;
-+
-+ if (!user)
-+ return POLLERR|POLLNVAL;
-+
-+ poll_wait(file, &log_wait, wait);
-+
-+ raw_spin_lock(&logbuf_lock);
-+ if (user->seq < log_next_seq) {
-+ /* return error when data has vanished underneath us */
-+ if (user->seq < log_first_seq)
-+ ret = POLLIN|POLLRDNORM|POLLERR|POLLPRI;
-+ ret = POLLIN|POLLRDNORM;
-+ }
-+ raw_spin_unlock(&logbuf_lock);
-+
-+ return ret;
-+}
-+
-+static int devkmsg_open(struct inode *inode, struct file *file)
-+{
-+ struct devkmsg_user *user;
-+ int err;
-+
-+ /* write-only does not need any file context */
-+ if ((file->f_flags & O_ACCMODE) == O_WRONLY)
-+ return 0;
-+
-+ err = security_syslog(SYSLOG_ACTION_READ_ALL);
-+ if (err)
-+ return err;
-+
-+ user = kmalloc(sizeof(struct devkmsg_user), GFP_KERNEL);
-+ if (!user)
-+ return -ENOMEM;
-+
-+ mutex_init(&user->lock);
-+
-+ raw_spin_lock(&logbuf_lock);
-+ user->idx = log_first_idx;
-+ user->seq = log_first_seq;
-+ raw_spin_unlock(&logbuf_lock);
-+
-+ file->private_data = user;
-+ return 0;
-+}
-+
-+static int devkmsg_release(struct inode *inode, struct file *file)
-+{
-+ struct devkmsg_user *user = file->private_data;
-+
-+ if (!user)
-+ return 0;
-+
-+ mutex_destroy(&user->lock);
-+ kfree(user);
-+ return 0;
-+}
-+
-+const struct file_operations kmsg_fops = {
-+ .open = devkmsg_open,
-+ .read = devkmsg_read,
-+ .aio_write = devkmsg_writev,
-+ .llseek = devkmsg_llseek,
-+ .poll = devkmsg_poll,
-+ .release = devkmsg_release,
-+};
-+
- #ifdef CONFIG_KEXEC
- /*
- * This appends the listed symbols to /proc/vmcoreinfo
diff --git a/printk-race.patch b/printk-race.patch
new file mode 100644
index 0000000..fff4e95
--- /dev/null
+++ b/printk-race.patch
@@ -0,0 +1,101 @@
+---
+ drivers/misc/Kconfig | 6 +++
+ drivers/misc/Makefile | 1
+ drivers/misc/printk-race.c | 70 +++++++++++++++++++++++++++++++++++++++++++++
+ 3 files changed, 77 insertions(+)
+
+--- a/drivers/misc/Kconfig
++++ b/drivers/misc/Kconfig
+@@ -490,6 +490,12 @@ config USB_SWITCH_FSA9480
+ stereo and mono audio, video, microphone and UART data to use
+ a common connector port.
+
++config PRINTK_RACE
++ tristate "printk race test"
++ help
++ Prints tests strings which race agains each other and
++ get interleaved or not.
++
+ source "drivers/misc/c2port/Kconfig"
+ source "drivers/misc/eeprom/Kconfig"
+ source "drivers/misc/cb710/Kconfig"
+--- a/drivers/misc/Makefile
++++ b/drivers/misc/Makefile
+@@ -48,3 +48,4 @@ obj-y += lis3lv02d/
+ obj-y += carma/
+ obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o
+ obj-$(CONFIG_ALTERA_STAPL) +=altera-stapl/
++obj-$(CONFIG_PRINTK_RACE) +=printk-race.o
+--- /dev/null
++++ b/drivers/misc/printk-race.c
+@@ -0,0 +1,70 @@
++#include <linux/module.h>
++#include <linux/kernel.h>
++#include <linux/init.h>
++#include <linux/delay.h>
++
++static void print_cont(char c)
++{
++ int i;
++
++ for (i = 0; i < 100; i++) {
++ int k;
++
++ printk("(%c", c);
++ for (k = 0; k < 58; k++) {
++ printk(KERN_CONT "%c", c);
++ msleep(1);
++ }
++ printk(KERN_CONT "%c)\n", c);
++ }
++}
++
++static void print_c(struct work_struct *work)
++{
++ print_cont('C');
++}
++
++static void print_x(struct work_struct *work)
++{
++ print_cont('X');
++}
++
++static void print_atomic(struct work_struct *work)
++{
++ int i;
++
++ for (i = 0; i < 100; i++) {
++ printk("(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)\n");
++ msleep(1);
++ }
++}
++
++
++static int __init printk_race_init(void)
++{
++ struct work_struct a_work;
++ struct work_struct c_work;
++ struct work_struct x_work;
++
++ printk(KERN_DEFAULT "printk test init\n");
++
++ INIT_WORK(&a_work, print_atomic);
++ INIT_WORK(&c_work, print_c);
++ INIT_WORK(&x_work, print_x);
++
++ schedule_work(&a_work);
++ schedule_work(&c_work);
++ schedule_work(&x_work);
++
++ flush_work_sync(&a_work);
++ flush_work_sync(&c_work);
++ flush_work_sync(&x_work);
++
++ printk(KERN_DEFAULT "printk test cleanup\n");
++ return -EINVAL;
++}
++
++module_init(printk_race_init);
++MODULE_LICENSE("GPL");
++MODULE_AUTHOR("Kay Sievers <kay@vrfy.org>");
++MODULE_DESCRIPTION("printk race test");
diff --git a/printk-records.patch b/printk-records.patch
deleted file mode 100644
index 9caaf8e..0000000
--- a/printk-records.patch
+++ /dev/null
@@ -1,1427 +0,0 @@
-From: Kay Sievers <kay@vrfy.org>
-Subject: printk: convert byte-buffer to variable-length record buffer
-
-- Record-based stream instead of the traditional byte stream
- buffer. All records carry a 64 bit timestamp, the syslog facility
- and priority in the record header.
-
-- Records consume almost the same amount, sometimes less memory than
- the traditional byte stream buffer (if printk_time is enabled). The record
- header is 16 bytes long, plus some padding bytes at the end if needed.
- The byte-stream buffer needed 3 chars for the syslog prefix, 15 char for
- the timestamp and a newline.
-
-- Buffer management is based on message sequence numbers. When records
- need to be discarded, the reading heads move on to the next full
- record. Unlike the byte-stream buffer, no old logged lines get
- truncated or partly overwritten by new ones. Sequence numbers also
- allow consumers of the log stream to get notified if any message in
- the stream they are about to read gets discarded during the time
- of reading.
-
-- Better buffered IO support for KERN_CONT continuation lines, when printk()
- is called multiple times for a single line. The use of KERN_CONT is now
- mandatory to use continuation; a few places in the kernel need trivial fixes
- here. The buffering could possibly be extended to per-cpu variables to allow
- better thread-safety for multiple printk() invocations for a single line.
-
-- Full-featured syslog facility value support. Different facilities
- can tag their messages. All userspace-injected messages enforce a
- facility value > 0 now, to be able to reliably distinguish them from
- the kernel-generated messages. Independent subsystems like a
- baseband processor running its own firmware, or a kernel-related
- userspace process can use their own unique facility values. Multiple
- independent log streams can co-exist that way in the same
- buffer. All share the same global sequence number counter to ensure
- proper ordering (and interleaving) and to allow the consumers of the
- log to reliably correlate the events from different facilities.
-
-Tested-by: William Douglas <william.douglas@intel.com>
-Signed-off-by: Kay Sievers <kay@vrfy.org>
----
- drivers/char/mem.c | 55 +-
- include/linux/printk.h | 11
- kernel/printk.c | 1020 ++++++++++++++++++++++++++++---------------------
- 3 files changed, 642 insertions(+), 444 deletions(-)
-
---- a/drivers/char/mem.c
-+++ b/drivers/char/mem.c
-@@ -810,33 +810,54 @@ static const struct file_operations oldm
- static ssize_t kmsg_writev(struct kiocb *iocb, const struct iovec *iv,
- unsigned long count, loff_t pos)
- {
-- char *line, *p;
-+ char *buf, *line;
- int i;
-- ssize_t ret = -EFAULT;
-+ int level = default_message_loglevel;
-+ int facility = 1; /* LOG_USER */
- size_t len = iov_length(iv, count);
-+ ssize_t ret = len;
-
-- line = kmalloc(len + 1, GFP_KERNEL);
-- if (line == NULL)
-+ if (len > 1024)
-+ return -EINVAL;
-+ buf = kmalloc(len+1, GFP_KERNEL);
-+ if (buf == NULL)
- return -ENOMEM;
-
-- /*
-- * copy all vectors into a single string, to ensure we do
-- * not interleave our log line with other printk calls
-- */
-- p = line;
-+ line = buf;
- for (i = 0; i < count; i++) {
-- if (copy_from_user(p, iv[i].iov_base, iv[i].iov_len))
-+ if (copy_from_user(line, iv[i].iov_base, iv[i].iov_len))
- goto out;
-- p += iv[i].iov_len;
-+ line += iv[i].iov_len;
-+ }
-+
-+ /*
-+ * Extract and skip the syslog prefix <[0-9]*>. Coming from userspace
-+ * the decimal value represents 32bit, the lower 3 bit are the log
-+ * level, the rest are the log facility.
-+ *
-+ * If no prefix or no userspace facility is specified, we
-+ * enforce LOG_USER, to be able to reliably distinguish
-+ * kernel-generated messages from userspace-injected ones.
-+ */
-+ line = buf;
-+ if (line[0] == '<') {
-+ char *endp = NULL;
-+
-+ i = simple_strtoul(line+1, &endp, 10);
-+ if (endp && endp[0] == '>') {
-+ level = i & 7;
-+ if (i >> 3)
-+ facility = i >> 3;
-+ endp++;
-+ len -= endp - line;
-+ line = endp;
-+ }
- }
-- p[0] = '\0';
-+ line[len] = '\0';
-
-- ret = printk("%s", line);
-- /* printk can add a prefix */
-- if (ret > len)
-- ret = len;
-+ printk_emit(facility, level, NULL, 0, "%s", line);
- out:
-- kfree(line);
-+ kfree(buf);
- return ret;
- }
-
---- a/include/linux/printk.h
-+++ b/include/linux/printk.h
-@@ -95,8 +95,19 @@ extern int printk_needs_cpu(int cpu);
- extern void printk_tick(void);
-
- #ifdef CONFIG_PRINTK
-+asmlinkage __printf(5, 0)
-+int vprintk_emit(int facility, int level,
-+ const char *dict, size_t dictlen,
-+ const char *fmt, va_list args);
-+
- asmlinkage __printf(1, 0)
- int vprintk(const char *fmt, va_list args);
-+
-+asmlinkage __printf(5, 6) __cold
-+asmlinkage int printk_emit(int facility, int level,
-+ const char *dict, size_t dictlen,
-+ const char *fmt, ...);
-+
- asmlinkage __printf(1, 2) __cold
- int printk(const char *fmt, ...);
-
---- a/kernel/printk.c
-+++ b/kernel/printk.c
-@@ -54,8 +54,6 @@ void asmlinkage __attribute__((weak)) ea
- {
- }
-
--#define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT)
--
- /* printk's without a loglevel use this.. */
- #define DEFAULT_MESSAGE_LOGLEVEL CONFIG_DEFAULT_MESSAGE_LOGLEVEL
-
-@@ -99,24 +97,6 @@ EXPORT_SYMBOL_GPL(console_drivers);
- static int console_locked, console_suspended;
-
- /*
-- * logbuf_lock protects log_buf, log_start, log_end, con_start and logged_chars
-- * It is also used in interesting ways to provide interlocking in
-- * console_unlock();.
-- */
--static DEFINE_RAW_SPINLOCK(logbuf_lock);
--
--#define LOG_BUF_MASK (log_buf_len-1)
--#define LOG_BUF(idx) (log_buf[(idx) & LOG_BUF_MASK])
--
--/*
-- * The indices into log_buf are not constrained to log_buf_len - they
-- * must be masked before subscripting
-- */
--static unsigned log_start; /* Index into log_buf: next char to be read by syslog() */
--static unsigned con_start; /* Index into log_buf: next char to be sent to consoles */
--static unsigned log_end; /* Index into log_buf: most-recently-written-char + 1 */
--
--/*
- * If exclusive_console is non-NULL then only this console is to be printed to.
- */
- static struct console *exclusive_console;
-@@ -146,12 +126,176 @@ EXPORT_SYMBOL(console_set_on_cmdline);
- static int console_may_schedule;
-
- #ifdef CONFIG_PRINTK
-+/*
-+ * The printk log buffer consists of a chain of concatenated variable
-+ * length records. Every record starts with a record header, containing
-+ * the overall length of the record.
-+ *
-+ * The heads to the first and last entry in the buffer, as well as the
-+ * sequence numbers of these both entries are maintained when messages
-+ * are stored..
-+ *
-+ * If the heads indicate available messages, the length in the header
-+ * tells the start next message. A length == 0 for the next message
-+ * indicates a wrap-around to the beginning of the buffer.
-+ *
-+ * Every record carries the monotonic timestamp in microseconds, as well as
-+ * the standard userspace syslog level and syslog facility. The usual
-+ * kernel messages use LOG_KERN; userspace-injected messages always carry
-+ * a matching syslog facility, by default LOG_USER. The origin of every
-+ * message can be reliably determined that way.
-+ *
-+ * The human readable log message directly follows the message header. The
-+ * length of the message text is stored in the header, the stored message
-+ * is not terminated.
-+ *
-+ */
-+
-+struct log {
-+ u64 ts_nsec; /* timestamp in nanoseconds */
-+ u16 len; /* length of entire record */
-+ u16 text_len; /* length of text buffer */
-+ u16 dict_len; /* length of dictionary buffer */
-+ u16 level; /* syslog level + facility */
-+};
-+
-+/*
-+ * The logbuf_lock protects kmsg buffer, indices, counters. It is also
-+ * used in interesting ways to provide interlocking in console_unlock();
-+ */
-+static DEFINE_RAW_SPINLOCK(logbuf_lock);
-+
-+/* cpu currently holding logbuf_lock */
-+static volatile unsigned int logbuf_cpu = UINT_MAX;
-+
-+#define LOG_LINE_MAX 1024
-
-+/* record buffer */
-+#define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT)
- static char __log_buf[__LOG_BUF_LEN];
- static char *log_buf = __log_buf;
--static int log_buf_len = __LOG_BUF_LEN;
--static unsigned logged_chars; /* Number of chars produced since last read+clear operation */
--static int saved_console_loglevel = -1;
-+static u32 log_buf_len = __LOG_BUF_LEN;
-+
-+/* index and sequence number of the first record stored in the buffer */
-+static u64 log_first_seq;
-+static u32 log_first_idx;
-+
-+/* index and sequence number of the next record to store in the buffer */
-+static u64 log_next_seq;
-+static u32 log_next_idx;
-+
-+/* the next printk record to read after the last 'clear' command */
-+static u64 clear_seq;
-+static u32 clear_idx;
-+
-+/* the next printk record to read by syslog(READ) or /proc/kmsg */
-+static u64 syslog_seq;
-+static u32 syslog_idx;
-+
-+/* human readable text of the record */
-+static char *log_text(const struct log *msg)
-+{
-+ return (char *)msg + sizeof(struct log);
-+}
-+
-+/* optional key/value pair dictionary attached to the record */
-+static char *log_dict(const struct log *msg)
-+{
-+ return (char *)msg + sizeof(struct log) + msg->text_len;
-+}
-+
-+/* get record by index; idx must point to valid msg */
-+static struct log *log_from_idx(u32 idx)
-+{
-+ struct log *msg = (struct log *)(log_buf + idx);
-+
-+ /*
-+ * A length == 0 record is the end of buffer marker. Wrap around and
-+ * read the message at the start of the buffer.
-+ */
-+ if (!msg->len)
-+ return (struct log *)log_buf;
-+ return msg;
-+}
-+
-+/* get next record; idx must point to valid msg */
-+static u32 log_next(u32 idx)
-+{
-+ struct log *msg = (struct log *)(log_buf + idx);
-+
-+ /* length == 0 indicates the end of the buffer; wrap */
-+ /*
-+ * A length == 0 record is the end of buffer marker. Wrap around and
-+ * read the message at the start of the buffer as *this* one, and
-+ * return the one after that.
-+ */
-+ if (!msg->len) {
-+ msg = (struct log *)log_buf;
-+ return msg->len;
-+ }
-+ return idx + msg->len;
-+}
-+
-+#if !defined(CONFIG_64BIT) || defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
-+#define LOG_ALIGN 4
-+#else
-+#define LOG_ALIGN 8
-+#endif
-+
-+/* insert record into the buffer, discard old ones, update heads */
-+static void log_store(int facility, int level,
-+ const char *dict, u16 dict_len,
-+ const char *text, u16 text_len)
-+{
-+ struct log *msg;
-+ u32 size, pad_len;
-+
-+ /* number of '\0' padding bytes to next message */
-+ size = sizeof(struct log) + text_len + dict_len;
-+ pad_len = (-size) & (LOG_ALIGN - 1);
-+ size += pad_len;
-+
-+ while (log_first_seq < log_next_seq) {
-+ u32 free;
-+
-+ if (log_next_idx > log_first_idx)
-+ free = max(log_buf_len - log_next_idx, log_first_idx);
-+ else
-+ free = log_first_idx - log_next_idx;
-+
-+ if (free > size + sizeof(struct log))
-+ break;
-+
-+ /* drop old messages until we have enough contiuous space */
-+ log_first_idx = log_next(log_first_idx);
-+ log_first_seq++;
-+ }
-+
-+ if (log_next_idx + size + sizeof(struct log) >= log_buf_len) {
-+ /*
-+ * This message + an additional empty header does not fit
-+ * at the end of the buffer. Add an empty header with len == 0
-+ * to signify a wrap around.
-+ */
-+ memset(log_buf + log_next_idx, 0, sizeof(struct log));
-+ log_next_idx = 0;
-+ }
-+
-+ /* fill message */
-+ msg = (struct log *)(log_buf + log_next_idx);
-+ memcpy(log_text(msg), text, text_len);
-+ msg->text_len = text_len;
-+ memcpy(log_dict(msg), dict, dict_len);
-+ msg->dict_len = dict_len;
-+ msg->level = (facility << 3) | (level & 7);
-+ msg->ts_nsec = local_clock();
-+ memset(log_dict(msg) + dict_len, 0, pad_len);
-+ msg->len = sizeof(struct log) + text_len + dict_len + pad_len;
-+
-+ /* insert message */
-+ log_next_idx += msg->len;
-+ log_next_seq++;
-+}
-
- #ifdef CONFIG_KEXEC
- /*
-@@ -165,9 +309,9 @@ static int saved_console_loglevel = -1;
- void log_buf_kexec_setup(void)
- {
- VMCOREINFO_SYMBOL(log_buf);
-- VMCOREINFO_SYMBOL(log_end);
- VMCOREINFO_SYMBOL(log_buf_len);
-- VMCOREINFO_SYMBOL(logged_chars);
-+ VMCOREINFO_SYMBOL(log_first_idx);
-+ VMCOREINFO_SYMBOL(log_next_idx);
- }
- #endif
-
-@@ -191,7 +335,6 @@ early_param("log_buf_len", log_buf_len_s
- void __init setup_log_buf(int early)
- {
- unsigned long flags;
-- unsigned start, dest_idx, offset;
- char *new_log_buf;
- int free;
-
-@@ -219,20 +362,8 @@ void __init setup_log_buf(int early)
- log_buf_len = new_log_buf_len;
- log_buf = new_log_buf;
- new_log_buf_len = 0;
-- free = __LOG_BUF_LEN - log_end;
--
-- offset = start = min(con_start, log_start);
-- dest_idx = 0;
-- while (start != log_end) {
-- unsigned log_idx_mask = start & (__LOG_BUF_LEN - 1);
--
-- log_buf[dest_idx] = __log_buf[log_idx_mask];
-- start++;
-- dest_idx++;
-- }
-- log_start -= offset;
-- con_start -= offset;
-- log_end -= offset;
-+ free = __LOG_BUF_LEN - log_next_idx;
-+ memcpy(log_buf, __log_buf, __LOG_BUF_LEN);
- raw_spin_unlock_irqrestore(&logbuf_lock, flags);
-
- pr_info("log_buf_len: %d\n", log_buf_len);
-@@ -332,11 +463,165 @@ static int check_syslog_permissions(int
- return 0;
- }
-
-+#if defined(CONFIG_PRINTK_TIME)
-+static bool printk_time = 1;
-+#else
-+static bool printk_time;
-+#endif
-+module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR);
-+
-+static int syslog_print_line(u32 idx, char *text, size_t size)
-+{
-+ struct log *msg;
-+ size_t len;
-+
-+ msg = log_from_idx(idx);
-+ if (!text) {
-+ /* calculate length only */
-+ len = 3;
-+
-+ if (msg->level > 9)
-+ len++;
-+ if (msg->level > 99)
-+ len++;
-+
-+ if (printk_time)
-+ len += 15;
-+
-+ len += msg->text_len;
-+ len++;
-+ return len;
-+ }
-+
-+ len = sprintf(text, "<%u>", msg->level);
-+
-+ if (printk_time) {
-+ unsigned long long t = msg->ts_nsec;
-+ unsigned long rem_ns = do_div(t, 1000000000);
-+
-+ len += sprintf(text + len, "[%5lu.%06lu] ",
-+ (unsigned long) t, rem_ns / 1000);
-+ }
-+
-+ if (len + msg->text_len > size)
-+ return -EINVAL;
-+ memcpy(text + len, log_text(msg), msg->text_len);
-+ len += msg->text_len;
-+ text[len++] = '\n';
-+ return len;
-+}
-+
-+static int syslog_print(char __user *buf, int size)
-+{
-+ char *text;
-+ int len;
-+
-+ text = kmalloc(LOG_LINE_MAX, GFP_KERNEL);
-+ if (!text)
-+ return -ENOMEM;
-+
-+ raw_spin_lock_irq(&logbuf_lock);
-+ if (syslog_seq < log_first_seq) {
-+ /* messages are gone, move to first one */
-+ syslog_seq = log_first_seq;
-+ syslog_idx = log_first_idx;
-+ }
-+ len = syslog_print_line(syslog_idx, text, LOG_LINE_MAX);
-+ syslog_idx = log_next(syslog_idx);
-+ syslog_seq++;
-+ raw_spin_unlock_irq(&logbuf_lock);
-+
-+ if (len > 0 && copy_to_user(buf, text, len))
-+ len = -EFAULT;
-+
-+ kfree(text);
-+ return len;
-+}
-+
-+static int syslog_print_all(char __user *buf, int size, bool clear)
-+{
-+ char *text;
-+ int len = 0;
-+
-+ text = kmalloc(LOG_LINE_MAX, GFP_KERNEL);
-+ if (!text)
-+ return -ENOMEM;
-+
-+ raw_spin_lock_irq(&logbuf_lock);
-+ if (buf) {
-+ u64 next_seq;
-+ u64 seq;
-+ u32 idx;
-+
-+ if (clear_seq < log_first_seq) {
-+ /* messages are gone, move to first available one */
-+ clear_seq = log_first_seq;
-+ clear_idx = log_first_idx;
-+ }
-+
-+ /*
-+ * Find first record that fits, including all following records,
-+ * into the user-provided buffer for this dump.
-+ */
-+ seq = clear_seq;
-+ idx = clear_idx;
-+ while (seq < log_next_seq) {
-+ len += syslog_print_line(idx, NULL, 0);
-+ idx = log_next(idx);
-+ seq++;
-+ }
-+ seq = clear_seq;
-+ idx = clear_idx;
-+ while (len > size && seq < log_next_seq) {
-+ len -= syslog_print_line(idx, NULL, 0);
-+ idx = log_next(idx);
-+ seq++;
-+ }
-+
-+ /* last message in this dump */
-+ next_seq = log_next_seq;
-+
-+ len = 0;
-+ while (len >= 0 && seq < next_seq) {
-+ int textlen;
-+
-+ textlen = syslog_print_line(idx, text, LOG_LINE_MAX);
-+ if (textlen < 0) {
-+ len = textlen;
-+ break;
-+ }
-+ idx = log_next(idx);
-+ seq++;
-+
-+ raw_spin_unlock_irq(&logbuf_lock);
-+ if (copy_to_user(buf + len, text, textlen))
-+ len = -EFAULT;
-+ else
-+ len += textlen;
-+ raw_spin_lock_irq(&logbuf_lock);
-+
-+ if (seq < log_first_seq) {
-+ /* messages are gone, move to next one */
-+ seq = log_first_seq;
-+ idx = log_first_idx;
-+ }
-+ }
-+ }
-+
-+ if (clear) {
-+ clear_seq = log_next_seq;
-+ clear_idx = log_next_idx;
-+ }
-+ raw_spin_unlock_irq(&logbuf_lock);
-+
-+ kfree(text);
-+ return len;
-+}
-+
- int do_syslog(int type, char __user *buf, int len, bool from_file)
- {
-- unsigned i, j, limit, count;
-- int do_clear = 0;
-- char c;
-+ bool clear = false;
-+ static int saved_console_loglevel = -1;
- int error;
-
- error = check_syslog_permissions(type, from_file);
-@@ -364,28 +649,14 @@ int do_syslog(int type, char __user *buf
- goto out;
- }
- error = wait_event_interruptible(log_wait,
-- (log_start - log_end));
-+ syslog_seq != log_next_seq);
- if (error)
- goto out;
-- i = 0;
-- raw_spin_lock_irq(&logbuf_lock);
-- while (!error && (log_start != log_end) && i < len) {
-- c = LOG_BUF(log_start);
-- log_start++;
-- raw_spin_unlock_irq(&logbuf_lock);
-- error = __put_user(c,buf);
-- buf++;
-- i++;
-- cond_resched();
-- raw_spin_lock_irq(&logbuf_lock);
-- }
-- raw_spin_unlock_irq(&logbuf_lock);
-- if (!error)
-- error = i;
-+ error = syslog_print(buf, len);
- break;
- /* Read/clear last kernel messages */
- case SYSLOG_ACTION_READ_CLEAR:
-- do_clear = 1;
-+ clear = true;
- /* FALL THRU */
- /* Read last kernel messages */
- case SYSLOG_ACTION_READ_ALL:
-@@ -399,52 +670,11 @@ int do_syslog(int type, char __user *buf
- error = -EFAULT;
- goto out;
- }
-- count = len;
-- if (count > log_buf_len)
-- count = log_buf_len;
-- raw_spin_lock_irq(&logbuf_lock);
-- if (count > logged_chars)
-- count = logged_chars;
-- if (do_clear)
-- logged_chars = 0;
-- limit = log_end;
-- /*
-- * __put_user() could sleep, and while we sleep
-- * printk() could overwrite the messages
-- * we try to copy to user space. Therefore
-- * the messages are copied in reverse. <manfreds>
-- */
-- for (i = 0; i < count && !error; i++) {
-- j = limit-1-i;
-- if (j + log_buf_len < log_end)
-- break;
-- c = LOG_BUF(j);
-- raw_spin_unlock_irq(&logbuf_lock);
-- error = __put_user(c,&buf[count-1-i]);
-- cond_resched();
-- raw_spin_lock_irq(&logbuf_lock);
-- }
-- raw_spin_unlock_irq(&logbuf_lock);
-- if (error)
-- break;
-- error = i;
-- if (i != count) {
-- int offset = count-error;
-- /* buffer overflow during copy, correct user buffer. */
-- for (i = 0; i < error; i++) {
-- if (__get_user(c,&buf[i+offset]) ||
-- __put_user(c,&buf[i])) {
-- error = -EFAULT;
-- break;
-- }
-- cond_resched();
-- }
-- }
-+ error = syslog_print_all(buf, len, clear);
- break;
- /* Clear ring buffer */
- case SYSLOG_ACTION_CLEAR:
-- logged_chars = 0;
-- break;
-+ syslog_print_all(NULL, 0, true);
- /* Disable logging to console */
- case SYSLOG_ACTION_CONSOLE_OFF:
- if (saved_console_loglevel == -1)
-@@ -472,7 +702,33 @@ int do_syslog(int type, char __user *buf
- break;
- /* Number of chars in the log buffer */
- case SYSLOG_ACTION_SIZE_UNREAD:
-- error = log_end - log_start;
-+ raw_spin_lock_irq(&logbuf_lock);
-+ if (syslog_seq < log_first_seq) {
-+ /* messages are gone, move to first one */
-+ syslog_seq = log_first_seq;
-+ syslog_idx = log_first_idx;
-+ }
-+ if (from_file) {
-+ /*
-+ * Short-cut for poll(/"proc/kmsg") which simply checks
-+ * for pending data, not the size; return the count of
-+ * records, not the length.
-+ */
-+ error = log_next_idx - syslog_idx;
-+ } else {
-+ u64 seq;
-+ u32 idx;
-+
-+ error = 0;
-+ seq = syslog_seq;
-+ idx = syslog_idx;
-+ while (seq < log_next_seq) {
-+ error += syslog_print_line(idx, NULL, 0);
-+ idx = log_next(idx);
-+ seq++;
-+ }
-+ }
-+ raw_spin_unlock_irq(&logbuf_lock);
- break;
- /* Size of the log buffer */
- case SYSLOG_ACTION_SIZE_BUFFER:
-@@ -501,29 +757,11 @@ void kdb_syslog_data(char *syslog_data[4
- {
- syslog_data[0] = log_buf;
- syslog_data[1] = log_buf + log_buf_len;
-- syslog_data[2] = log_buf + log_end -
-- (logged_chars < log_buf_len ? logged_chars : log_buf_len);
-- syslog_data[3] = log_buf + log_end;
-+ syslog_data[2] = log_buf + log_first_idx;
-+ syslog_data[3] = log_buf + log_next_idx;
- }
- #endif /* CONFIG_KGDB_KDB */
-
--/*
-- * Call the console drivers on a range of log_buf
-- */
--static void __call_console_drivers(unsigned start, unsigned end)
--{
-- struct console *con;
--
-- for_each_console(con) {
-- if (exclusive_console && con != exclusive_console)
-- continue;
-- if ((con->flags & CON_ENABLED) && con->write &&
-- (cpu_online(smp_processor_id()) ||
-- (con->flags & CON_ANYTIME)))
-- con->write(con, &LOG_BUF(start), end - start);
-- }
--}
--
- static bool __read_mostly ignore_loglevel;
-
- static int __init ignore_loglevel_setup(char *str)
-@@ -540,142 +778,33 @@ MODULE_PARM_DESC(ignore_loglevel, "ignor
- "print all kernel messages to the console.");
-
- /*
-- * Write out chars from start to end - 1 inclusive
-- */
--static void _call_console_drivers(unsigned start,
-- unsigned end, int msg_log_level)
--{
-- trace_console(&LOG_BUF(0), start, end, log_buf_len);
--
-- if ((msg_log_level < console_loglevel || ignore_loglevel) &&
-- console_drivers && start != end) {
-- if ((start & LOG_BUF_MASK) > (end & LOG_BUF_MASK)) {
-- /* wrapped write */
-- __call_console_drivers(start & LOG_BUF_MASK,
-- log_buf_len);
-- __call_console_drivers(0, end & LOG_BUF_MASK);
-- } else {
-- __call_console_drivers(start, end);
-- }
-- }
--}
--
--/*
-- * Parse the syslog header <[0-9]*>. The decimal value represents 32bit, the
-- * lower 3 bit are the log level, the rest are the log facility. In case
-- * userspace passes usual userspace syslog messages to /dev/kmsg or
-- * /dev/ttyprintk, the log prefix might contain the facility. Printk needs
-- * to extract the correct log level for in-kernel processing, and not mangle
-- * the original value.
-- *
-- * If a prefix is found, the length of the prefix is returned. If 'level' is
-- * passed, it will be filled in with the log level without a possible facility
-- * value. If 'special' is passed, the special printk prefix chars are accepted
-- * and returned. If no valid header is found, 0 is returned and the passed
-- * variables are not touched.
-- */
--static size_t log_prefix(const char *p, unsigned int *level, char *special)
--{
-- unsigned int lev = 0;
-- char sp = '\0';
-- size_t len;
--
-- if (p[0] != '<' || !p[1])
-- return 0;
-- if (p[2] == '>') {
-- /* usual single digit level number or special char */
-- switch (p[1]) {
-- case '0' ... '7':
-- lev = p[1] - '0';
-- break;
-- case 'c': /* KERN_CONT */
-- case 'd': /* KERN_DEFAULT */
-- sp = p[1];
-- break;
-- default:
-- return 0;
-- }
-- len = 3;
-- } else {
-- /* multi digit including the level and facility number */
-- char *endp = NULL;
--
-- lev = (simple_strtoul(&p[1], &endp, 10) & 7);
-- if (endp == NULL || endp[0] != '>')
-- return 0;
-- len = (endp + 1) - p;
-- }
--
-- /* do not accept special char if not asked for */
-- if (sp && !special)
-- return 0;
--
-- if (special) {
-- *special = sp;
-- /* return special char, do not touch level */
-- if (sp)
-- return len;
-- }
--
-- if (level)
-- *level = lev;
-- return len;
--}
--
--/*
- * Call the console drivers, asking them to write out
- * log_buf[start] to log_buf[end - 1].
- * The console_lock must be held.
- */
--static void call_console_drivers(unsigned start, unsigned end)
-+static void call_console_drivers(int level, const char *text, size_t len)
- {
-- unsigned cur_index, start_print;
-- static int msg_level = -1;
-+ struct console *con;
-
-- BUG_ON(((int)(start - end)) > 0);
-+ trace_console(text, 0, len, len);
-
-- cur_index = start;
-- start_print = start;
-- while (cur_index != end) {
-- if (msg_level < 0 && ((end - cur_index) > 2)) {
-- /* strip log prefix */
-- cur_index += log_prefix(&LOG_BUF(cur_index), &msg_level, NULL);
-- start_print = cur_index;
-- }
-- while (cur_index != end) {
-- char c = LOG_BUF(cur_index);
--
-- cur_index++;
-- if (c == '\n') {
-- if (msg_level < 0) {
-- /*
-- * printk() has already given us loglevel tags in
-- * the buffer. This code is here in case the
-- * log buffer has wrapped right round and scribbled
-- * on those tags
-- */
-- msg_level = default_message_loglevel;
-- }
-- _call_console_drivers(start_print, cur_index, msg_level);
-- msg_level = -1;
-- start_print = cur_index;
-- break;
-- }
-- }
-- }
-- _call_console_drivers(start_print, end, msg_level);
--}
-+ if (level >= console_loglevel && !ignore_loglevel)
-+ return;
-+ if (!console_drivers)
-+ return;
-
--static void emit_log_char(char c)
--{
-- LOG_BUF(log_end) = c;
-- log_end++;
-- if (log_end - log_start > log_buf_len)
-- log_start = log_end - log_buf_len;
-- if (log_end - con_start > log_buf_len)
-- con_start = log_end - log_buf_len;
-- if (logged_chars < log_buf_len)
-- logged_chars++;
-+ for_each_console(con) {
-+ if (exclusive_console && con != exclusive_console)
-+ continue;
-+ if (!(con->flags & CON_ENABLED))
-+ continue;
-+ if (!con->write)
-+ continue;
-+ if (!cpu_online(smp_processor_id()) &&
-+ !(con->flags & CON_ANYTIME))
-+ continue;
-+ con->write(con, text, len);
-+ }
- }
-
- /*
-@@ -700,16 +829,6 @@ static void zap_locks(void)
- sema_init(&console_sem, 1);
- }
-
--#if defined(CONFIG_PRINTK_TIME)
--static bool printk_time = 1;
--#else
--static bool printk_time = 0;
--#endif
--module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR);
--
--static bool always_kmsg_dump;
--module_param_named(always_kmsg_dump, always_kmsg_dump, bool, S_IRUGO | S_IWUSR);
--
- /* Check if we have any console registered that can be called early in boot. */
- static int have_callable_console(void)
- {
-@@ -722,51 +841,6 @@ static int have_callable_console(void)
- return 0;
- }
-
--/**
-- * printk - print a kernel message
-- * @fmt: format string
-- *
-- * This is printk(). It can be called from any context. We want it to work.
-- *
-- * We try to grab the console_lock. If we succeed, it's easy - we log the output and
-- * call the console drivers. If we fail to get the semaphore we place the output
-- * into the log buffer and return. The current holder of the console_sem will
-- * notice the new output in console_unlock(); and will send it to the
-- * consoles before releasing the lock.
-- *
-- * One effect of this deferred printing is that code which calls printk() and
-- * then changes console_loglevel may break. This is because console_loglevel
-- * is inspected when the actual printing occurs.
-- *
-- * See also:
-- * printf(3)
-- *
-- * See the vsnprintf() documentation for format string extensions over C99.
-- */
--
--asmlinkage int printk(const char *fmt, ...)
--{
-- va_list args;
-- int r;
--
--#ifdef CONFIG_KGDB_KDB
-- if (unlikely(kdb_trap_printk)) {
-- va_start(args, fmt);
-- r = vkdb_printf(fmt, args);
-- va_end(args);
-- return r;
-- }
--#endif
-- va_start(args, fmt);
-- r = vprintk(fmt, args);
-- va_end(args);
--
-- return r;
--}
--
--/* cpu currently holding logbuf_lock */
--static volatile unsigned int printk_cpu = UINT_MAX;
--
- /*
- * Can we actually use the console at this time on this cpu?
- *
-@@ -810,17 +884,12 @@ static int console_trylock_for_printk(un
- retval = 0;
- }
- }
-- printk_cpu = UINT_MAX;
-+ logbuf_cpu = UINT_MAX;
- if (wake)
- up(&console_sem);
- raw_spin_unlock(&logbuf_lock);
- return retval;
- }
--static const char recursion_bug_msg [] =
-- KERN_CRIT "BUG: recent printk recursion!\n";
--static int recursion_bug;
--static int new_text_line = 1;
--static char printk_buf[1024];
-
- int printk_delay_msec __read_mostly;
-
-@@ -836,15 +905,22 @@ static inline void printk_delay(void)
- }
- }
-
--asmlinkage int vprintk(const char *fmt, va_list args)
--{
-- int printed_len = 0;
-- int current_log_level = default_message_loglevel;
-+asmlinkage int vprintk_emit(int facility, int level,
-+ const char *dict, size_t dictlen,
-+ const char *fmt, va_list args)
-+{
-+ static int recursion_bug;
-+ static char buf[LOG_LINE_MAX];
-+ static size_t buflen;
-+ static int buflevel;
-+ static char textbuf[LOG_LINE_MAX];
-+ char *text = textbuf;
-+ size_t textlen;
- unsigned long flags;
- int this_cpu;
-- char *p;
-- size_t plen;
-- char special;
-+ bool newline = false;
-+ bool cont = false;
-+ int printed_len = 0;
-
- boot_delay_msec();
- printk_delay();
-@@ -856,7 +932,7 @@ asmlinkage int vprintk(const char *fmt,
- /*
- * Ouch, printk recursed into itself!
- */
-- if (unlikely(printk_cpu == this_cpu)) {
-+ if (unlikely(logbuf_cpu == this_cpu)) {
- /*
- * If a crash is occurring during printk() on this CPU,
- * then try to get the crash message out but make sure
-@@ -873,97 +949,92 @@ asmlinkage int vprintk(const char *fmt,
-
- lockdep_off();
- raw_spin_lock(&logbuf_lock);
-- printk_cpu = this_cpu;
-+ logbuf_cpu = this_cpu;
-
- if (recursion_bug) {
-+ static const char recursion_msg[] =
-+ "BUG: recent printk recursion!";
-+
- recursion_bug = 0;
-- strcpy(printk_buf, recursion_bug_msg);
-- printed_len = strlen(recursion_bug_msg);
-- }
-- /* Emit the output into the temporary buffer */
-- printed_len += vscnprintf(printk_buf + printed_len,
-- sizeof(printk_buf) - printed_len, fmt, args);
--
-- p = printk_buf;
--
-- /* Read log level and handle special printk prefix */
-- plen = log_prefix(p, &current_log_level, &special);
-- if (plen) {
-- p += plen;
--
-- switch (special) {
-- case 'c': /* Strip <c> KERN_CONT, continue line */
-- plen = 0;
-- break;
-- case 'd': /* Strip <d> KERN_DEFAULT, start new line */
-- plen = 0;
-- default:
-- if (!new_text_line) {
-- emit_log_char('\n');
-- new_text_line = 1;
-- }
-- }
-+ printed_len += strlen(recursion_msg);
-+ /* emit KERN_CRIT message */
-+ log_store(0, 2, NULL, 0, recursion_msg, printed_len);
- }
-
- /*
-- * Copy the output into log_buf. If the caller didn't provide
-- * the appropriate log prefix, we insert them here
-+ * The printf needs to come first; we need the syslog
-+ * prefix which might be passed-in as a parameter.
- */
-- for (; *p; p++) {
-- if (new_text_line) {
-- new_text_line = 0;
--
-- if (plen) {
-- /* Copy original log prefix */
-- int i;
--
-- for (i = 0; i < plen; i++)
-- emit_log_char(printk_buf[i]);
-- printed_len += plen;
-- } else {
-- /* Add log prefix */
-- emit_log_char('<');
-- emit_log_char(current_log_level + '0');
-- emit_log_char('>');
-- printed_len += 3;
-- }
-+ textlen = vscnprintf(text, sizeof(textbuf), fmt, args);
-
-- if (printk_time) {
-- /* Add the current time stamp */
-- char tbuf[50], *tp;
-- unsigned tlen;
-- unsigned long long t;
-- unsigned long nanosec_rem;
--
-- t = cpu_clock(printk_cpu);
-- nanosec_rem = do_div(t, 1000000000);
-- tlen = sprintf(tbuf, "[%5lu.%06lu] ",
-- (unsigned long) t,
-- nanosec_rem / 1000);
--
-- for (tp = tbuf; tp < tbuf + tlen; tp++)
-- emit_log_char(*tp);
-- printed_len += tlen;
-- }
-+ /* mark and strip a trailing newline */
-+ if (textlen && text[textlen-1] == '\n') {
-+ textlen--;
-+ newline = true;
-+ }
-
-- if (!*p)
-- break;
-+ /* strip syslog prefix and extract log level or flags */
-+ if (text[0] == '<' && text[1] && text[2] == '>') {
-+ switch (text[1]) {
-+ case '0' ... '7':
-+ if (level == -1)
-+ level = text[1] - '0';
-+ text += 3;
-+ textlen -= 3;
-+ break;
-+ case 'c': /* KERN_CONT */
-+ cont = true;
-+ case 'd': /* KERN_DEFAULT */
-+ text += 3;
-+ textlen -= 3;
-+ break;
- }
-+ }
-
-- emit_log_char(*p);
-- if (*p == '\n')
-- new_text_line = 1;
-+ if (buflen && (!cont || dict)) {
-+ /* no continuation; flush existing buffer */
-+ log_store(facility, buflevel, NULL, 0, buf, buflen);
-+ printed_len += buflen;
-+ buflen = 0;
-+ }
-+
-+ if (buflen == 0) {
-+ /* remember level for first message in the buffer */
-+ if (level == -1)
-+ buflevel = default_message_loglevel;
-+ else
-+ buflevel = level;
-+ }
-+
-+ if (buflen || !newline) {
-+ /* append to existing buffer, or buffer until next message */
-+ if (buflen + textlen > sizeof(buf))
-+ textlen = sizeof(buf) - buflen;
-+ memcpy(buf + buflen, text, textlen);
-+ buflen += textlen;
-+ }
-+
-+ if (newline) {
-+ /* end of line; flush buffer */
-+ if (buflen) {
-+ log_store(facility, buflevel,
-+ dict, dictlen, buf, buflen);
-+ printed_len += buflen;
-+ buflen = 0;
-+ } else {
-+ log_store(facility, buflevel,
-+ dict, dictlen, text, textlen);
-+ printed_len += textlen;
-+ }
- }
-
- /*
-- * Try to acquire and then immediately release the
-- * console semaphore. The release will do all the
-- * actual magic (print out buffers, wake up klogd,
-- * etc).
-+ * Try to acquire and then immediately release the console semaphore.
-+ * The release will print out buffers and wake up /dev/kmsg and syslog()
-+ * users.
- *
-- * The console_trylock_for_printk() function
-- * will release 'logbuf_lock' regardless of whether it
-- * actually gets the semaphore or not.
-+ * The console_trylock_for_printk() function will release 'logbuf_lock'
-+ * regardless of whether it actually gets the console semaphore or not.
- */
- if (console_trylock_for_printk(this_cpu))
- console_unlock();
-@@ -974,12 +1045,73 @@ out_restore_irqs:
-
- return printed_len;
- }
--EXPORT_SYMBOL(printk);
-+EXPORT_SYMBOL(vprintk_emit);
-+
-+asmlinkage int vprintk(const char *fmt, va_list args)
-+{
-+ return vprintk_emit(0, -1, NULL, 0, fmt, args);
-+}
- EXPORT_SYMBOL(vprintk);
-
-+asmlinkage int printk_emit(int facility, int level,
-+ const char *dict, size_t dictlen,
-+ const char *fmt, ...)
-+{
-+ va_list args;
-+ int r;
-+
-+ va_start(args, fmt);
-+ r = vprintk_emit(facility, level, dict, dictlen, fmt, args);
-+ va_end(args);
-+
-+ return r;
-+}
-+EXPORT_SYMBOL(printk_emit);
-+
-+/**
-+ * printk - print a kernel message
-+ * @fmt: format string
-+ *
-+ * This is printk(). It can be called from any context. We want it to work.
-+ *
-+ * We try to grab the console_lock. If we succeed, it's easy - we log the
-+ * output and call the console drivers. If we fail to get the semaphore, we
-+ * place the output into the log buffer and return. The current holder of
-+ * the console_sem will notice the new output in console_unlock(); and will
-+ * send it to the consoles before releasing the lock.
-+ *
-+ * One effect of this deferred printing is that code which calls printk() and
-+ * then changes console_loglevel may break. This is because console_loglevel
-+ * is inspected when the actual printing occurs.
-+ *
-+ * See also:
-+ * printf(3)
-+ *
-+ * See the vsnprintf() documentation for format string extensions over C99.
-+ */
-+asmlinkage int printk(const char *fmt, ...)
-+{
-+ va_list args;
-+ int r;
-+
-+#ifdef CONFIG_KGDB_KDB
-+ if (unlikely(kdb_trap_printk)) {
-+ va_start(args, fmt);
-+ r = vkdb_printf(fmt, args);
-+ va_end(args);
-+ return r;
-+ }
-+#endif
-+ va_start(args, fmt);
-+ r = vprintk_emit(0, -1, NULL, 0, fmt, args);
-+ va_end(args);
-+
-+ return r;
-+}
-+EXPORT_SYMBOL(printk);
- #else
-
--static void call_console_drivers(unsigned start, unsigned end)
-+static void call_console_drivers(int level, const char *text, size_t len)
- {
- }
-
-@@ -1217,7 +1349,7 @@ int is_console_locked(void)
- }
-
- /*
-- * Delayed printk facility, for scheduler-internal messages:
-+ * Delayed printk version, for scheduler-internal messages:
- */
- #define PRINTK_BUF_SIZE 512
-
-@@ -1253,6 +1385,10 @@ void wake_up_klogd(void)
- this_cpu_or(printk_pending, PRINTK_PENDING_WAKEUP);
- }
-
-+/* the next printk record to write to the console */
-+static u64 console_seq;
-+static u32 console_idx;
-+
- /**
- * console_unlock - unlock the console system
- *
-@@ -1263,15 +1399,16 @@ void wake_up_klogd(void)
- * by printk(). If this is the case, console_unlock(); emits
- * the output prior to releasing the lock.
- *
-- * If there is output waiting for klogd, we wake it up.
-+ * If there is output waiting, we wake it /dev/kmsg and syslog() users.
- *
- * console_unlock(); may be called from any context.
- */
- void console_unlock(void)
- {
-+ static u64 seen_seq;
- unsigned long flags;
-- unsigned _con_start, _log_end;
-- unsigned wake_klogd = 0, retry = 0;
-+ bool wake_klogd = false;
-+ bool retry;
-
- if (console_suspended) {
- up(&console_sem);
-@@ -1281,17 +1418,41 @@ void console_unlock(void)
- console_may_schedule = 0;
-
- again:
-- for ( ; ; ) {
-+ for (;;) {
-+ struct log *msg;
-+ static char text[LOG_LINE_MAX];
-+ size_t len;
-+ int level;
-+
- raw_spin_lock_irqsave(&logbuf_lock, flags);
-- wake_klogd |= log_start - log_end;
-- if (con_start == log_end)
-- break; /* Nothing to print */
-- _con_start = con_start;
-- _log_end = log_end;
-- con_start = log_end; /* Flush */
-+ if (seen_seq != log_next_seq) {
-+ wake_klogd = true;
-+ seen_seq = log_next_seq;
-+ }
-+
-+ if (console_seq < log_first_seq) {
-+ /* messages are gone, move to first one */
-+ console_seq = log_first_seq;
-+ console_idx = log_first_idx;
-+ }
-+
-+ if (console_seq == log_next_seq)
-+ break;
-+
-+ msg = log_from_idx(console_idx);
-+ level = msg->level & 7;
-+ len = msg->text_len;
-+ if (len+1 >= sizeof(text))
-+ len = sizeof(text)-1;
-+ memcpy(text, log_text(msg), len);
-+ text[len++] = '\n';
-+
-+ console_idx = log_next(console_idx);
-+ console_seq++;
- raw_spin_unlock(&logbuf_lock);
-+
- stop_critical_timings(); /* don't trace print latency */
-- call_console_drivers(_con_start, _log_end);
-+ call_console_drivers(level, text, len);
- start_critical_timings();
- local_irq_restore(flags);
- }
-@@ -1312,8 +1473,7 @@ again:
- * flush, no worries.
- */
- raw_spin_lock(&logbuf_lock);
-- if (con_start != log_end)
-- retry = 1;
-+ retry = console_seq != log_next_seq;
- raw_spin_unlock_irqrestore(&logbuf_lock, flags);
-
- if (retry && console_trylock())
-@@ -1549,7 +1709,8 @@ void register_console(struct console *ne
- * for us.
- */
- raw_spin_lock_irqsave(&logbuf_lock, flags);
-- con_start = log_start;
-+ console_seq = syslog_seq;
-+ console_idx = syslog_idx;
- raw_spin_unlock_irqrestore(&logbuf_lock, flags);
- /*
- * We're about to replay the log buffer. Only do this to the
-@@ -1758,6 +1919,9 @@ int kmsg_dump_unregister(struct kmsg_dum
- }
- EXPORT_SYMBOL_GPL(kmsg_dump_unregister);
-
-+static bool always_kmsg_dump;
-+module_param_named(always_kmsg_dump, always_kmsg_dump, bool, S_IRUGO | S_IWUSR);
-+
- /**
- * kmsg_dump - dump kernel log to kernel message dumpers.
- * @reason: the reason (oops, panic etc) for dumping
-@@ -1767,8 +1931,7 @@ EXPORT_SYMBOL_GPL(kmsg_dump_unregister);
- */
- void kmsg_dump(enum kmsg_dump_reason reason)
- {
-- unsigned long end;
-- unsigned chars;
-+ u64 idx;
- struct kmsg_dumper *dumper;
- const char *s1, *s2;
- unsigned long l1, l2;
-@@ -1780,24 +1943,27 @@ void kmsg_dump(enum kmsg_dump_reason rea
- /* Theoretically, the log could move on after we do this, but
- there's not a lot we can do about that. The new messages
- will overwrite the start of what we dump. */
-- raw_spin_lock_irqsave(&logbuf_lock, flags);
-- end = log_end & LOG_BUF_MASK;
-- chars = logged_chars;
-- raw_spin_unlock_irqrestore(&logbuf_lock, flags);
-
-- if (chars > end) {
-- s1 = log_buf + log_buf_len - chars + end;
-- l1 = chars - end;
-+ raw_spin_lock_irqsave(&logbuf_lock, flags);
-+ if (syslog_seq < log_first_seq)
-+ idx = syslog_idx;
-+ else
-+ idx = log_first_idx;
-+
-+ if (idx > log_next_idx) {
-+ s1 = log_buf;
-+ l1 = log_next_idx;
-
-- s2 = log_buf;
-- l2 = end;
-+ s2 = log_buf + idx;
-+ l2 = log_buf_len - idx;
- } else {
- s1 = "";
- l1 = 0;
-
-- s2 = log_buf + end - chars;
-- l2 = chars;
-+ s2 = log_buf + idx;
-+ l2 = log_next_idx - idx;
- }
-+ raw_spin_unlock_irqrestore(&logbuf_lock, flags);
-
- rcu_read_lock();
- list_for_each_entry_rcu(dumper, &dump_list, list)
diff --git a/printk-time.patch b/printk-time.patch
deleted file mode 100644
index d90ece5..0000000
--- a/printk-time.patch
+++ /dev/null
@@ -1,122 +0,0 @@
-From: Kay Sievers <kay@vrfy.org>
-Subject: printk() - restore timestamp printing at console output
-
-The output of the timestamps got lost with the conversion of the
-kmsg buffer to records; restore the old behavior.
-
-Document, that CONFIG_PRINTK_TIME now only controls the output of
-the timestamps in the syslog() system call and on the console, and
-not the recording of the timestamps.
-
-Signed-off-by: Kay Sievers <kay@vrfy.org>
----
-
- kernel/printk.c | 43 ++++++++++++++++++++++++++-----------------
- lib/Kconfig.debug | 16 ++++++++++------
- 2 files changed, 36 insertions(+), 23 deletions(-)
-
---- a/kernel/printk.c
-+++ b/kernel/printk.c
-@@ -786,6 +786,22 @@ static bool printk_time;
- #endif
- module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR);
-
-+static size_t prepend_timestamp(unsigned long long t, char *buf)
-+{
-+ unsigned long rem_ns;
-+
-+ if (!printk_time)
-+ return 0;
-+
-+ if (!buf)
-+ return 15;
-+
-+ rem_ns = do_div(t, 1000000000);
-+
-+ return sprintf(buf, "[%5lu.%06lu] ",
-+ (unsigned long) t, rem_ns / 1000);
-+}
-+
- static int syslog_print_line(u32 idx, char *text, size_t size)
- {
- struct log *msg;
-@@ -800,9 +816,7 @@ static int syslog_print_line(u32 idx, ch
- len++;
- if (msg->level > 99)
- len++;
--
-- if (printk_time)
-- len += 15;
-+ len += prepend_timestamp(0, NULL);
-
- len += msg->text_len;
- len++;
-@@ -810,15 +824,7 @@ static int syslog_print_line(u32 idx, ch
- }
-
- len = sprintf(text, "<%u>", msg->level);
--
-- if (printk_time) {
-- unsigned long long t = msg->ts_nsec;
-- unsigned long rem_ns = do_div(t, 1000000000);
--
-- len += sprintf(text + len, "[%5lu.%06lu] ",
-- (unsigned long) t, rem_ns / 1000);
-- }
--
-+ len += prepend_timestamp(msg->ts_nsec, text + len);
- if (len + msg->text_len > size)
- return -EINVAL;
- memcpy(text + len, log_text(msg), msg->text_len);
-@@ -1741,7 +1747,7 @@ again:
- for (;;) {
- struct log *msg;
- static char text[LOG_LINE_MAX];
-- size_t len;
-+ size_t len, l;
- int level;
-
- raw_spin_lock_irqsave(&logbuf_lock, flags);
-@@ -1761,10 +1767,13 @@ again:
-
- msg = log_from_idx(console_idx);
- level = msg->level & 7;
-- len = msg->text_len;
-- if (len+1 >= sizeof(text))
-- len = sizeof(text)-1;
-- memcpy(text, log_text(msg), len);
-+
-+ len = prepend_timestamp(msg->ts_nsec, text);
-+ l = msg->text_len;
-+ if (len + l + 1 >= sizeof(text))
-+ l = sizeof(text) - len - 1;
-+ memcpy(text + len, log_text(msg), l);
-+ len += l;
- text[len++] = '\n';
-
- console_idx = log_next(console_idx);
---- a/lib/Kconfig.debug
-+++ b/lib/Kconfig.debug
-@@ -3,12 +3,16 @@ config PRINTK_TIME
- bool "Show timing information on printks"
- depends on PRINTK
- help
-- Selecting this option causes timing information to be
-- included in printk output. This allows you to measure
-- the interval between kernel operations, including bootup
-- operations. This is useful for identifying long delays
-- in kernel startup. Or add printk.time=1 at boot-time.
-- See Documentation/kernel-parameters.txt
-+ Selecting this option causes time stamps of the printk()
-+ messages to be added to the output of the syslog() system
-+ call and at the console.
-+
-+ The timestamp is always recorded internally, and exported
-+ to /dev/kmsg. This flag just specifies if the timetamp should
-+ be included, not that the timestamp is recorded.
-+
-+ The behaviour is also controlled by the kernel command line
-+ parameter printk.time=1. See Documentation/kernel-parameters.txt
-
- config DEFAULT_MESSAGE_LOGLEVEL
- int "Default message log level (1-7)"
diff --git a/series b/series
index ca6cad3..1dc45ba 100644
--- a/series
+++ b/series
@@ -1,12 +1,3 @@
-#devpts.patch
-
-printk-records.patch
-printk-devkmsg.patch
-printk-dev_printk.patch
-kmsg-fix64bit-division.patch
-kern-cont-parport.patch
-kern-cont-mm.patch
-kmsg-docs.patch
-kmsg-off.patch
-cont.patch
-printk-time.patch
+printk-race.patch
+kmsg-multiline.patch
+kmsg-sep-cont.patch