All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] x86, boot: add mmio serial during compressed boot
@ 2013-07-12 20:07 Kees Cook
  2013-07-12 20:07 ` [PATCH 2/3] serial: report base_baud after initialization Kees Cook
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Kees Cook @ 2013-07-12 20:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: Greg Kroah-Hartman, Rob Landley, H. Peter Anvin, Thomas Gleixner,
	Ingo Molnar, x86, linux-doc, linux-serial, Kees Cook

Allows "console=uart[8250],mmio[32],0xADDR[,BAUDn8[,BASE_BAUD]]" to
be recognized during compressed boot early console setup, and during
boot console setup. Replaces defines with common serial defines. Adds
suport for mmio-based serial devices to compressed-boot early console,
and plumbs support for defining the base baud rate for UART clock
calculations (since mmio serial cards may not have the standard rate,
resulting in incorrect baud rates for mmio devices).

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 Documentation/kernel-parameters.txt             |   12 ++-
 arch/x86/boot/boot.h                            |   20 +++-
 arch/x86/boot/compressed/early_serial_console.c |    5 +-
 arch/x86/boot/compressed/misc.c                 |   10 +-
 arch/x86/boot/compressed/misc.h                 |    4 +-
 arch/x86/boot/early_serial_console.c            |  122 +++++++++++++----------
 arch/x86/boot/early_serial_console.h            |   43 ++++++++
 arch/x86/boot/tty.c                             |   12 +--
 drivers/tty/serial/8250/8250_early.c            |   11 +-
 include/uapi/linux/serial_reg.h                 |    5 +-
 10 files changed, 168 insertions(+), 76 deletions(-)
 create mode 100644 arch/x86/boot/early_serial_console.h

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 15356ac..52ad7d8 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -575,11 +575,21 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			alternative.
 
 		uart[8250],io,<addr>[,options]
-		uart[8250],mmio,<addr>[,options]
+		uart[8250],mmio,<addr>[,options[,base_baud]]
 			Start an early, polled-mode console on the 8250/16550
 			UART at the specified I/O port or MMIO address,
 			switching to the matching ttyS device later.  The
 			options are the same as for ttyS, above.
+
+			For x86 early boot mmio uart consoles, the base baud
+			rate (for calculating the UART clock) can be defined
+			as well. This is done after the options above, comma
+			separated. For example "...,115200n8,4000000" would
+			use 4000000 as the base baud rate. Once the real uart
+			driver initializes, this value will be ignored, since
+			it will use the known device-specific value instead.
+			The default is 115200.
+
 		hvc<n>	Use the hypervisor console device <n>. This is for
 			both Xen and PowerPC hypervisors.
 
diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
index 5b75319..ae61c19 100644
--- a/arch/x86/boot/boot.h
+++ b/arch/x86/boot/boot.h
@@ -80,6 +80,23 @@ static inline void io_delay(void)
 	asm volatile("outb %%al,%0" : : "dN" (DELAY_PORT));
 }
 
+/* Minimal mmio functions from include/asm/io.h. */
+#define build_mmio_read(name, size, type, reg, barrier) \
+static inline type name(const volatile void __iomem *addr) \
+{ type ret; asm volatile("mov" size " %1,%0":reg (ret) \
+:"m" (*(volatile type __force *)addr) barrier); return ret; }
+
+#define build_mmio_write(name, size, type, reg, barrier) \
+static inline void name(type val, volatile void __iomem *addr) \
+{ asm volatile("mov" size " %0,%1": :reg (val), \
+"m" (*(volatile type __force *)addr) barrier); }
+
+build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
+build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
+
+build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
+build_mmio_write(writel, "l", unsigned int, "r", :"memory")
+
 /* These functions are used to reference data in other segments. */
 
 static inline u16 ds(void)
@@ -319,7 +336,8 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr);
 int validate_cpu(void);
 
 /* early_serial_console.c */
-extern int early_serial_base;
+extern unsigned long early_serial_base;
+extern int early_serial_type;
 void console_init(void);
 
 /* edd.c */
diff --git a/arch/x86/boot/compressed/early_serial_console.c b/arch/x86/boot/compressed/early_serial_console.c
index d3d003c..7b9572a 100644
--- a/arch/x86/boot/compressed/early_serial_console.c
+++ b/arch/x86/boot/compressed/early_serial_console.c
@@ -2,8 +2,9 @@
 
 #ifdef CONFIG_EARLY_PRINTK
 
-int early_serial_base;
-
 #include "../early_serial_console.c"
 
+unsigned long early_serial_base;
+int early_serial_type;
+
 #endif
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index 0319c88..3c635f0 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -125,6 +125,8 @@ static char *vidmem;
 static int vidport;
 static int lines, cols;
 
+#include "../early_serial_console.h"
+
 #ifdef CONFIG_KERNEL_GZIP
 #include "../../../../lib/decompress_inflate.c"
 #endif
@@ -158,18 +160,14 @@ static void scroll(void)
 		vidmem[i] = ' ';
 }
 
-#define XMTRDY          0x20
-
-#define TXR             0       /*  Transmit register (WRITE) */
-#define LSR             5       /*  Line Status               */
 static void serial_putchar(int ch)
 {
 	unsigned timeout = 0xffff;
 
-	while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
+	while ((early_serial_in(UART_LSR) & UART_LSR_THRE) == 0 && --timeout)
 		cpu_relax();
 
-	outb(ch, early_serial_base + TXR);
+	early_serial_out(UART_TX, ch);
 }
 
 void __putstr(const char *s)
diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
index 674019d..da0b0bc 100644
--- a/arch/x86/boot/compressed/misc.h
+++ b/arch/x86/boot/compressed/misc.h
@@ -46,13 +46,13 @@ int cmdline_find_option(const char *option, char *buffer, int bufsize);
 int cmdline_find_option_bool(const char *option);
 
 /* early_serial_console.c */
-extern int early_serial_base;
+extern unsigned long early_serial_base;
 void console_init(void);
 
 #else
 
 /* early_serial_console.c */
-static const int early_serial_base;
+static const unsigned long early_serial_base;
 static inline void console_init(void)
 { }
 
diff --git a/arch/x86/boot/early_serial_console.c b/arch/x86/boot/early_serial_console.c
index 5df2869..3483b0b7 100644
--- a/arch/x86/boot/early_serial_console.c
+++ b/arch/x86/boot/early_serial_console.c
@@ -1,43 +1,26 @@
 #include "boot.h"
+#include "early_serial_console.h"
 
-#define DEFAULT_SERIAL_PORT 0x3f8 /* ttyS0 */
-
-#define XMTRDY          0x20
-
-#define DLAB		0x80
-
-#define TXR             0       /*  Transmit register (WRITE) */
-#define RXR             0       /*  Receive register  (READ)  */
-#define IER             1       /*  Interrupt Enable          */
-#define IIR             2       /*  Interrupt ID              */
-#define FCR             2       /*  FIFO control              */
-#define LCR             3       /*  Line control              */
-#define MCR             4       /*  Modem control             */
-#define LSR             5       /*  Line Status               */
-#define MSR             6       /*  Modem Status              */
-#define DLL             0       /*  Divisor Latch Low         */
-#define DLH             1       /*  Divisor latch High        */
-
-#define DEFAULT_BAUD 9600
-
-static void early_serial_init(int port, int baud)
+static void early_serial_init(int type, unsigned long port, int baud,
+			      int base_baud)
 {
 	unsigned char c;
 	unsigned divisor;
 
-	outb(0x3, port + LCR);	/* 8n1 */
-	outb(0, port + IER);	/* no interrupt */
-	outb(0, port + FCR);	/* no fifo */
-	outb(0x3, port + MCR);	/* DTR + RTS */
-
-	divisor	= 115200 / baud;
-	c = inb(port + LCR);
-	outb(c | DLAB, port + LCR);
-	outb(divisor & 0xff, port + DLL);
-	outb((divisor >> 8) & 0xff, port + DLH);
-	outb(c & ~DLAB, port + LCR);
-
+	early_serial_type = type;
 	early_serial_base = port;
+
+	early_serial_out(UART_LCR, UART_LCR_WLEN8);	/* 8n1 */
+	early_serial_out(UART_IER, 0);			/* no interrupts */
+	early_serial_out(UART_FCR, 0);			/* no fifo */
+	early_serial_out(UART_MCR, UART_MCR_DTR | UART_MCR_RTS);
+
+	divisor	= base_baud / baud;
+	c = early_serial_in(UART_LCR);
+	early_serial_out(UART_LCR, c | UART_LCR_DLAB);
+	early_serial_out(UART_DLL, divisor & 0xff);
+	early_serial_out(UART_DLM, (divisor >> 8) & 0xff);
+	early_serial_out(UART_LCR, c & ~UART_LCR_DLAB);
 }
 
 static void parse_earlyprintk(void)
@@ -45,7 +28,7 @@ static void parse_earlyprintk(void)
 	int baud = DEFAULT_BAUD;
 	char arg[32];
 	int pos = 0;
-	int port = 0;
+	unsigned long port = 0;
 
 	if (cmdline_find_option("earlyprintk", arg, sizeof arg) > 0) {
 		char *e;
@@ -92,33 +75,47 @@ static void parse_earlyprintk(void)
 	}
 
 	if (port)
-		early_serial_init(port, baud);
+		early_serial_init(EARLY_SERIAL_IO, port, baud,
+				  SERIAL_BAUD_BASE);
 }
 
-#define BASE_BAUD (1843200/16)
-static unsigned int probe_baud(int port)
+static unsigned int probe_baud(int type, unsigned long port)
 {
 	unsigned char lcr, dll, dlh;
 	unsigned int quot;
+	int saved_type;
+	unsigned long saved_port;
 
-	lcr = inb(port + LCR);
-	outb(lcr | DLAB, port + LCR);
-	dll = inb(port + DLL);
-	dlh = inb(port + DLH);
-	outb(lcr, port + LCR);
+	saved_type = early_serial_type;
+	saved_port = early_serial_base;
+	early_serial_type = type;
+	early_serial_base = port;
+
+	lcr = early_serial_in(UART_LCR);
+	early_serial_out(UART_LCR, lcr | UART_LCR_DLAB);
+	dll = early_serial_in(UART_DLL);
+	dlh = early_serial_in(UART_DLM);
+	early_serial_out(UART_LCR, lcr);
 	quot = (dlh << 8) | dll;
 
-	return BASE_BAUD / quot;
+	early_serial_type = saved_type;
+	early_serial_base = saved_port;
+
+	return SERIAL_BAUD_BASE / quot;
 }
 
 static void parse_console_uart8250(void)
 {
 	char optstr[64], *options;
 	int baud = DEFAULT_BAUD;
-	int port = 0;
+	int base_baud = SERIAL_BAUD_BASE;
+	int type = EARLY_SERIAL_IO;
+	unsigned long port = 0;
 
 	/*
 	 * console=uart8250,io,0x3f8,115200n8
+	 * console=uart,mmio,0xe080100,115200n8
+	 * console=uart,mmio32,0xe0801000,115200n8
 	 * need to make sure it is last one console !
 	 */
 	if (cmdline_find_option("console", optstr, sizeof optstr) <= 0)
@@ -126,20 +123,41 @@ static void parse_console_uart8250(void)
 
 	options = optstr;
 
-	if (!strncmp(options, "uart8250,io,", 12))
-		port = simple_strtoull(options + 12, &options, 0);
-	else if (!strncmp(options, "uart,io,", 8))
-		port = simple_strtoull(options + 8, &options, 0);
-	else
+	if (strncmp(options, "uart", 4))
+		return;
+	options += 4;
+	if (!strncmp(options, "8250", 4))
+		options += 4;
+	if (*options++ != ',')
 		return;
 
-	if (options && (options[0] == ','))
+	if (!strncmp(options, "io,", 3))
+		port = simple_strtoull(options + 3, &options, 0);
+	else if (!strncmp(options, "mmio", 4)) {
+		options += 4;
+		type = EARLY_SERIAL_MMIO;
+		if (!strncmp(options, "32", 2)) {
+			options += 2;
+			type = EARLY_SERIAL_MMIO32;
+		}
+		if (*options++ != ',')
+			return;
+		port = simple_strtoull(options, &options, 0);
+	} else
+		return;
+
+	if (options && (options[0] == ',')) {
 		baud = simple_strtoull(options + 1, &options, 0);
+		while (*options != ' ' && *options != ',' && *options != '\0')
+			options++;
+		if (*options == ',')
+			base_baud = simple_strtoull(options + 1, &options, 0);
+	}
 	else
-		baud = probe_baud(port);
+		baud = probe_baud(type, port);
 
 	if (port)
-		early_serial_init(port, baud);
+		early_serial_init(type, port, baud, base_baud);
 }
 
 void console_init(void)
diff --git a/arch/x86/boot/early_serial_console.h b/arch/x86/boot/early_serial_console.h
new file mode 100644
index 0000000..3f7ff34
--- /dev/null
+++ b/arch/x86/boot/early_serial_console.h
@@ -0,0 +1,43 @@
+#include <linux/serial_reg.h>
+
+#define DEFAULT_SERIAL_PORT 0x3f8 /* ttyS0 */
+#define DEFAULT_BAUD 9600
+
+#define EARLY_SERIAL_IO		0
+#define EARLY_SERIAL_MMIO	1
+#define EARLY_SERIAL_MMIO32	2
+
+extern unsigned long early_serial_base;
+extern int early_serial_type;
+
+static inline unsigned int early_serial_in(int offset)
+{
+	switch (early_serial_type) {
+	case EARLY_SERIAL_IO:
+		return inb(early_serial_base + offset);
+	case EARLY_SERIAL_MMIO:
+		return readb((const volatile void *)early_serial_base +
+				offset);
+	case EARLY_SERIAL_MMIO32:
+		return readl((const volatile void *)early_serial_base +
+				(offset << 2));
+	default:
+		return 0;
+	}
+}
+
+static inline void early_serial_out(int offset, int value)
+{
+	switch (early_serial_type) {
+	case EARLY_SERIAL_IO:
+		outb(value, early_serial_base + offset);
+		break;
+	case EARLY_SERIAL_MMIO:
+		writeb(value, (volatile void *)early_serial_base + offset);
+		break;
+	case EARLY_SERIAL_MMIO32:
+		writel(value, (volatile void *)early_serial_base +
+				(offset << 2));
+		break;
+	}
+}
diff --git a/arch/x86/boot/tty.c b/arch/x86/boot/tty.c
index def2451..60dede2 100644
--- a/arch/x86/boot/tty.c
+++ b/arch/x86/boot/tty.c
@@ -15,12 +15,10 @@
 
 #include "boot.h"
 
-int early_serial_base;
+unsigned long early_serial_base;
+int early_serial_type;
 
-#define XMTRDY          0x20
-
-#define TXR             0       /*  Transmit register (WRITE) */
-#define LSR             5       /*  Line Status               */
+#include "early_serial_console.h"
 
 /*
  * These functions are in .inittext so they can be used to signal
@@ -31,10 +29,10 @@ static void __attribute__((section(".inittext"))) serial_putchar(int ch)
 {
 	unsigned timeout = 0xffff;
 
-	while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
+	while ((early_serial_in(UART_LSR) & UART_LSR_THRE) == 0 && --timeout)
 		cpu_relax();
 
-	outb(ch, early_serial_base + TXR);
+	early_serial_out(UART_TX, ch);
 }
 
 static void __attribute__((section(".inittext"))) bios_putchar(int ch)
diff --git a/drivers/tty/serial/8250/8250_early.c b/drivers/tty/serial/8250/8250_early.c
index 721904f..9526dd0 100644
--- a/drivers/tty/serial/8250/8250_early.c
+++ b/drivers/tty/serial/8250/8250_early.c
@@ -42,7 +42,7 @@
 
 struct early_serial8250_device {
 	struct uart_port port;
-	char options[16];		/* e.g., 115200n8 */
+	char options[32];		/* e.g., 115200n8 */
 	unsigned int baud;
 };
 
@@ -153,12 +153,11 @@ static int __init parse_options(struct early_serial8250_device *device,
 {
 	struct uart_port *port = &device->port;
 	int mmio, mmio32, length;
+	int base_baud = BASE_BAUD;
 
 	if (!options)
 		return -ENODEV;
 
-	port->uartclk = BASE_BAUD * 16;
-
 	mmio = !strncmp(options, "mmio,", 5);
 	mmio32 = !strncmp(options, "mmio32,", 7);
 	if (mmio || mmio32) {
@@ -195,12 +194,18 @@ static int __init parse_options(struct early_serial8250_device *device,
 		device->baud = simple_strtoul(options, NULL, 0);
 		length = min(strcspn(options, " "), sizeof(device->options));
 		strlcpy(device->options, options, length);
+		while (*options != ' ' && *options != '\0' && *options != ',')
+			options++;
+		if (*options == ',')
+			base_baud = simple_strtoul(options + 1, NULL, 0);
 	} else {
 		device->baud = probe_baud(port);
 		snprintf(device->options, sizeof(device->options), "%u",
 			device->baud);
 	}
 
+	port->uartclk = base_baud * 16;
+
 	if (mmio || mmio32)
 		printk(KERN_INFO
 		       "Early serial console at MMIO%s 0x%llx (options '%s')\n",
diff --git a/include/uapi/linux/serial_reg.h b/include/uapi/linux/serial_reg.h
index e632260..bdeaf5a 100644
--- a/include/uapi/linux/serial_reg.h
+++ b/include/uapi/linux/serial_reg.h
@@ -333,12 +333,13 @@
 
 #define UART_RSA_TCR_SWITCH (1 << 0) /* Timer on */
 
+#define SERIAL_BAUD_BASE (1843200/16)
 /*
  * The RSA DSV/II board has two fixed clock frequencies.  One is the
  * standard rate, and the other is 8 times faster.
  */
-#define SERIAL_RSA_BAUD_BASE (921600)
-#define SERIAL_RSA_BAUD_BASE_LO (SERIAL_RSA_BAUD_BASE / 8)
+#define SERIAL_RSA_BAUD_BASE_LO SERIAL_BAUD_BASE
+#define SERIAL_RSA_BAUD_BASE (SERIAL_RSA_BAUD_BASE * 8)
 
 /*
  * Extra serial register definitions for the internal UARTs
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 2/3] serial: report base_baud after initialization
  2013-07-12 20:07 [PATCH 1/3] x86, boot: add mmio serial during compressed boot Kees Cook
@ 2013-07-12 20:07 ` Kees Cook
  2013-07-12 20:07 ` [PATCH 3/3] printk: report boot console names during cut-over Kees Cook
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 17+ messages in thread
From: Kees Cook @ 2013-07-12 20:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: Greg Kroah-Hartman, Rob Landley, H. Peter Anvin, Thomas Gleixner,
	Ingo Molnar, x86, linux-doc, linux-serial, Kees Cook

Some serial ports will not use the standard base baud rate. Report
this after initialization so it might be discovered and used for early
console configuration.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/tty/serial/serial_core.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 28cdd28..0f02351 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -2095,12 +2095,12 @@ uart_report_port(struct uart_driver *drv, struct uart_port *port)
 		break;
 	}
 
-	printk(KERN_INFO "%s%s%s%d at %s (irq = %d) is a %s\n",
+	printk(KERN_INFO "%s%s%s%d at %s (irq = %d, base_baud = %d) is a %s\n",
 	       port->dev ? dev_name(port->dev) : "",
 	       port->dev ? ": " : "",
 	       drv->dev_name,
 	       drv->tty_driver->name_base + port->line,
-	       address, port->irq, uart_type(port));
+	       address, port->irq, port->uartclk / 16, uart_type(port));
 }
 
 static void
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 3/3] printk: report boot console names during cut-over
  2013-07-12 20:07 [PATCH 1/3] x86, boot: add mmio serial during compressed boot Kees Cook
  2013-07-12 20:07 ` [PATCH 2/3] serial: report base_baud after initialization Kees Cook
@ 2013-07-12 20:07 ` Kees Cook
       [not found] ` <CAGXu5jL=oSkWTGEbYLxAU1PwGbgoyeiOgFV31Gd4yj1JkDECBg@mail.gmail.com>
  2013-07-12 20:38 ` [PATCH v2 " Kees Cook
  3 siblings, 0 replies; 17+ messages in thread
From: Kees Cook @ 2013-07-12 20:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: Greg Kroah-Hartman, Rob Landley, H. Peter Anvin, Thomas Gleixner,
	Ingo Molnar, x86, linux-doc, linux-serial, Kees Cook

This reports the names of boot consoles as they're being disabled to
help identify which is which during cut-over. Helps answer the question
"which boot console actually got activated?"

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 kernel/printk.c |   16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/kernel/printk.c b/kernel/printk.c
index d37d45c..08612e0 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -2375,14 +2375,18 @@ void register_console(struct console *newcon)
 	if (bcon &&
 	    ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) &&
 	    !keep_bootcon) {
-		/* we need to iterate through twice, to make sure we print
-		 * everything out, before we unregister the console(s)
+		/* We need to iterate through all boot consoles, to make
+		 * sure we print everything out, before we unregister them.
 		 */
-		printk(KERN_INFO "console [%s%d] enabled, bootconsole disabled\n",
-			newcon->name, newcon->index);
-		for_each_console(bcon)
-			if (bcon->flags & CON_BOOT)
+		for_each_console(bcon) {
+			if (bcon->flags & CON_BOOT) {
+				printk(KERN_INFO "console [%s%d] enabled, "
+					"bootconsole [%s%d] disabled\n",
+					newcon->name, newcon->index,
+					bcon->name, bcon->index);
 				unregister_console(bcon);
+			}
+		}
 	} else {
 		printk(KERN_INFO "%sconsole [%s%d] enabled\n",
 			(newcon->flags & CON_BOOT) ? "boot" : "" ,
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/3] x86, boot: add mmio serial during compressed boot
       [not found] ` <CAGXu5jL=oSkWTGEbYLxAU1PwGbgoyeiOgFV31Gd4yj1JkDECBg@mail.gmail.com>
@ 2013-07-12 20:17   ` Kees Cook
  2013-07-12 20:20   ` H. Peter Anvin
  1 sibling, 0 replies; 17+ messages in thread
From: Kees Cook @ 2013-07-12 20:17 UTC (permalink / raw)
  To: LKML
  Cc: Greg Kroah-Hartman, Rob Landley, H. Peter Anvin, Thomas Gleixner,
	Ingo Molnar, x86, linux-doc, linux-serial, Kees Cook

[resend, gmail tricked me into HTML mode...]

On Fri, Jul 12, 2013 at 1:15 PM, Kees Cook <keescook@chromium.org> wrote:
> On Fri, Jul 12, 2013 at 1:07 PM, Kees Cook <keescook@chromium.org> wrote:
>>
>> Allows "console=uart[8250],mmio[32],0xADDR[,BAUDn8[,BASE_BAUD]]" to
>> be recognized during compressed boot early console setup, and during
>> boot console setup. Replaces defines with common serial defines. Adds
>> suport for mmio-based serial devices to compressed-boot early console,
>> and plumbs support for defining the base baud rate for UART clock
>> calculations (since mmio serial cards may not have the standard rate,
>> resulting in incorrect baud rates for mmio devices).
>>
>> Signed-off-by: Kees Cook <keescook@chromium.org>
>> ---
>> diff --git a/include/uapi/linux/serial_reg.h
>> b/include/uapi/linux/serial_reg.h
>> index e632260..bdeaf5a 100644
>> --- a/include/uapi/linux/serial_reg.h
>> +++ b/include/uapi/linux/serial_reg.h
>> @@ -333,12 +333,13 @@
>>
>>  #define UART_RSA_TCR_SWITCH (1 << 0) /* Timer on */
>>
>> +#define SERIAL_BAUD_BASE (1843200/16)
>>  /*
>>   * The RSA DSV/II board has two fixed clock frequencies.  One is the
>>   * standard rate, and the other is 8 times faster.
>>   */
>> -#define SERIAL_RSA_BAUD_BASE (921600)
>> -#define SERIAL_RSA_BAUD_BASE_LO (SERIAL_RSA_BAUD_BASE / 8)
>> +#define SERIAL_RSA_BAUD_BASE_LO SERIAL_BAUD_BASE
>> +#define SERIAL_RSA_BAUD_BASE (SERIAL_RSA_BAUD_BASE * 8)
>
>
> Argh, just found this typo during an allyesconfig build. Above should be:
>
> #define SERIAL_RSA_BAUD_BASE (SERIAL_BAUD_BASE * 8)
>
> -Kees
>
> --
> Kees Cook
> Chrome OS Security



--
Kees Cook
Chrome OS Security

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/3] x86, boot: add mmio serial during compressed boot
       [not found] ` <CAGXu5jL=oSkWTGEbYLxAU1PwGbgoyeiOgFV31Gd4yj1JkDECBg@mail.gmail.com>
  2013-07-12 20:17   ` [PATCH 1/3] x86, boot: add mmio serial during compressed boot Kees Cook
@ 2013-07-12 20:20   ` H. Peter Anvin
  1 sibling, 0 replies; 17+ messages in thread
From: H. Peter Anvin @ 2013-07-12 20:20 UTC (permalink / raw)
  To: Kees Cook, LKML
  Cc: Greg Kroah-Hartman, Rob Landley, Thomas Gleixner, Ingo Molnar,
	x86, linux-doc, linux-serial

Can you fix & resend the patch?

Kees Cook <keescook@chromium.org> wrote:

>On Fri, Jul 12, 2013 at 1:07 PM, Kees Cook <keescook@chromium.org>
>wrote:
>
>> Allows "console=uart[8250],mmio[32],0xADDR[,BAUDn8[,BASE_BAUD]]" to
>> be recognized during compressed boot early console setup, and during
>> boot console setup. Replaces defines with common serial defines. Adds
>> suport for mmio-based serial devices to compressed-boot early
>console,
>> and plumbs support for defining the base baud rate for UART clock
>> calculations (since mmio serial cards may not have the standard rate,
>> resulting in incorrect baud rates for mmio devices).
>>
>> Signed-off-by: Kees Cook <keescook@chromium.org>
>> ---
>> diff --git a/include/uapi/linux/serial_reg.h
>> b/include/uapi/linux/serial_reg.h
>> index e632260..bdeaf5a 100644
>> --- a/include/uapi/linux/serial_reg.h
>> +++ b/include/uapi/linux/serial_reg.h
>> @@ -333,12 +333,13 @@
>>
>>  #define UART_RSA_TCR_SWITCH (1 << 0) /* Timer on */
>>
>> +#define SERIAL_BAUD_BASE (1843200/16)
>>  /*
>>   * The RSA DSV/II board has two fixed clock frequencies.  One is the
>>   * standard rate, and the other is 8 times faster.
>>   */
>> -#define SERIAL_RSA_BAUD_BASE (921600)
>> -#define SERIAL_RSA_BAUD_BASE_LO (SERIAL_RSA_BAUD_BASE / 8)
>> +#define SERIAL_RSA_BAUD_BASE_LO SERIAL_BAUD_BASE
>> +#define SERIAL_RSA_BAUD_BASE (SERIAL_RSA_BAUD_BASE * 8)
>>
>
>Argh, just found this typo during an allyesconfig build. Above should
>be:
>
>#define SERIAL_RSA_BAUD_BASE (SERIAL_BAUD_BASE * 8)
>
>-Kees

-- 
Sent from my mobile phone. Please excuse brevity and lack of formatting.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v2 1/3] x86, boot: add mmio serial during compressed boot
  2013-07-12 20:07 [PATCH 1/3] x86, boot: add mmio serial during compressed boot Kees Cook
                   ` (2 preceding siblings ...)
       [not found] ` <CAGXu5jL=oSkWTGEbYLxAU1PwGbgoyeiOgFV31Gd4yj1JkDECBg@mail.gmail.com>
@ 2013-07-12 20:38 ` Kees Cook
  2013-07-13  6:47   ` Yinghai Lu
  3 siblings, 1 reply; 17+ messages in thread
From: Kees Cook @ 2013-07-12 20:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Rob Landley, H. Peter Anvin, Thomas Gleixner, Ingo Molnar, x86,
	Greg Kroah-Hartman, linux-doc, linux-serial

Allows "console=uart[8250],mmio[32],0xADDR[,BAUDn8[,BASE_BAUD]]" to
be recognized during compressed boot early console setup, and during
boot console setup. Replaces defines with common serial defines. Adds
suport for mmio-based serial devices to compressed-boot early console,
and plumbs support for defining the base baud rate for UART clock
calculations (since mmio serial cards may not have the standard rate,
resulting in incorrect baud rates for mmio devices).

Signed-off-by: Kees Cook <keescook@chromium.org>
---
v2:
 - fixed typo in SERIAL_RSA_...
---
 Documentation/kernel-parameters.txt             |   12 ++-
 arch/x86/boot/boot.h                            |   20 +++-
 arch/x86/boot/compressed/early_serial_console.c |    5 +-
 arch/x86/boot/compressed/misc.c                 |   10 +-
 arch/x86/boot/compressed/misc.h                 |    4 +-
 arch/x86/boot/early_serial_console.c            |  122 +++++++++++++----------
 arch/x86/boot/early_serial_console.h            |   43 ++++++++
 arch/x86/boot/tty.c                             |   12 +--
 drivers/tty/serial/8250/8250_early.c            |   11 +-
 include/uapi/linux/serial_reg.h                 |    5 +-
 10 files changed, 168 insertions(+), 76 deletions(-)
 create mode 100644 arch/x86/boot/early_serial_console.h

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 15356ac..52ad7d8 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -575,11 +575,21 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			alternative.
 
 		uart[8250],io,<addr>[,options]
-		uart[8250],mmio,<addr>[,options]
+		uart[8250],mmio,<addr>[,options[,base_baud]]
 			Start an early, polled-mode console on the 8250/16550
 			UART at the specified I/O port or MMIO address,
 			switching to the matching ttyS device later.  The
 			options are the same as for ttyS, above.
+
+			For x86 early boot mmio uart consoles, the base baud
+			rate (for calculating the UART clock) can be defined
+			as well. This is done after the options above, comma
+			separated. For example "...,115200n8,4000000" would
+			use 4000000 as the base baud rate. Once the real uart
+			driver initializes, this value will be ignored, since
+			it will use the known device-specific value instead.
+			The default is 115200.
+
 		hvc<n>	Use the hypervisor console device <n>. This is for
 			both Xen and PowerPC hypervisors.
 
diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
index 5b75319..ae61c19 100644
--- a/arch/x86/boot/boot.h
+++ b/arch/x86/boot/boot.h
@@ -80,6 +80,23 @@ static inline void io_delay(void)
 	asm volatile("outb %%al,%0" : : "dN" (DELAY_PORT));
 }
 
+/* Minimal mmio functions from include/asm/io.h. */
+#define build_mmio_read(name, size, type, reg, barrier) \
+static inline type name(const volatile void __iomem *addr) \
+{ type ret; asm volatile("mov" size " %1,%0":reg (ret) \
+:"m" (*(volatile type __force *)addr) barrier); return ret; }
+
+#define build_mmio_write(name, size, type, reg, barrier) \
+static inline void name(type val, volatile void __iomem *addr) \
+{ asm volatile("mov" size " %0,%1": :reg (val), \
+"m" (*(volatile type __force *)addr) barrier); }
+
+build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
+build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
+
+build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
+build_mmio_write(writel, "l", unsigned int, "r", :"memory")
+
 /* These functions are used to reference data in other segments. */
 
 static inline u16 ds(void)
@@ -319,7 +336,8 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr);
 int validate_cpu(void);
 
 /* early_serial_console.c */
-extern int early_serial_base;
+extern unsigned long early_serial_base;
+extern int early_serial_type;
 void console_init(void);
 
 /* edd.c */
diff --git a/arch/x86/boot/compressed/early_serial_console.c b/arch/x86/boot/compressed/early_serial_console.c
index d3d003c..7b9572a 100644
--- a/arch/x86/boot/compressed/early_serial_console.c
+++ b/arch/x86/boot/compressed/early_serial_console.c
@@ -2,8 +2,9 @@
 
 #ifdef CONFIG_EARLY_PRINTK
 
-int early_serial_base;
-
 #include "../early_serial_console.c"
 
+unsigned long early_serial_base;
+int early_serial_type;
+
 #endif
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index 0319c88..3c635f0 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -125,6 +125,8 @@ static char *vidmem;
 static int vidport;
 static int lines, cols;
 
+#include "../early_serial_console.h"
+
 #ifdef CONFIG_KERNEL_GZIP
 #include "../../../../lib/decompress_inflate.c"
 #endif
@@ -158,18 +160,14 @@ static void scroll(void)
 		vidmem[i] = ' ';
 }
 
-#define XMTRDY          0x20
-
-#define TXR             0       /*  Transmit register (WRITE) */
-#define LSR             5       /*  Line Status               */
 static void serial_putchar(int ch)
 {
 	unsigned timeout = 0xffff;
 
-	while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
+	while ((early_serial_in(UART_LSR) & UART_LSR_THRE) == 0 && --timeout)
 		cpu_relax();
 
-	outb(ch, early_serial_base + TXR);
+	early_serial_out(UART_TX, ch);
 }
 
 void __putstr(const char *s)
diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
index 674019d..da0b0bc 100644
--- a/arch/x86/boot/compressed/misc.h
+++ b/arch/x86/boot/compressed/misc.h
@@ -46,13 +46,13 @@ int cmdline_find_option(const char *option, char *buffer, int bufsize);
 int cmdline_find_option_bool(const char *option);
 
 /* early_serial_console.c */
-extern int early_serial_base;
+extern unsigned long early_serial_base;
 void console_init(void);
 
 #else
 
 /* early_serial_console.c */
-static const int early_serial_base;
+static const unsigned long early_serial_base;
 static inline void console_init(void)
 { }
 
diff --git a/arch/x86/boot/early_serial_console.c b/arch/x86/boot/early_serial_console.c
index 5df2869..3483b0b7 100644
--- a/arch/x86/boot/early_serial_console.c
+++ b/arch/x86/boot/early_serial_console.c
@@ -1,43 +1,26 @@
 #include "boot.h"
+#include "early_serial_console.h"
 
-#define DEFAULT_SERIAL_PORT 0x3f8 /* ttyS0 */
-
-#define XMTRDY          0x20
-
-#define DLAB		0x80
-
-#define TXR             0       /*  Transmit register (WRITE) */
-#define RXR             0       /*  Receive register  (READ)  */
-#define IER             1       /*  Interrupt Enable          */
-#define IIR             2       /*  Interrupt ID              */
-#define FCR             2       /*  FIFO control              */
-#define LCR             3       /*  Line control              */
-#define MCR             4       /*  Modem control             */
-#define LSR             5       /*  Line Status               */
-#define MSR             6       /*  Modem Status              */
-#define DLL             0       /*  Divisor Latch Low         */
-#define DLH             1       /*  Divisor latch High        */
-
-#define DEFAULT_BAUD 9600
-
-static void early_serial_init(int port, int baud)
+static void early_serial_init(int type, unsigned long port, int baud,
+			      int base_baud)
 {
 	unsigned char c;
 	unsigned divisor;
 
-	outb(0x3, port + LCR);	/* 8n1 */
-	outb(0, port + IER);	/* no interrupt */
-	outb(0, port + FCR);	/* no fifo */
-	outb(0x3, port + MCR);	/* DTR + RTS */
-
-	divisor	= 115200 / baud;
-	c = inb(port + LCR);
-	outb(c | DLAB, port + LCR);
-	outb(divisor & 0xff, port + DLL);
-	outb((divisor >> 8) & 0xff, port + DLH);
-	outb(c & ~DLAB, port + LCR);
-
+	early_serial_type = type;
 	early_serial_base = port;
+
+	early_serial_out(UART_LCR, UART_LCR_WLEN8);	/* 8n1 */
+	early_serial_out(UART_IER, 0);			/* no interrupts */
+	early_serial_out(UART_FCR, 0);			/* no fifo */
+	early_serial_out(UART_MCR, UART_MCR_DTR | UART_MCR_RTS);
+
+	divisor	= base_baud / baud;
+	c = early_serial_in(UART_LCR);
+	early_serial_out(UART_LCR, c | UART_LCR_DLAB);
+	early_serial_out(UART_DLL, divisor & 0xff);
+	early_serial_out(UART_DLM, (divisor >> 8) & 0xff);
+	early_serial_out(UART_LCR, c & ~UART_LCR_DLAB);
 }
 
 static void parse_earlyprintk(void)
@@ -45,7 +28,7 @@ static void parse_earlyprintk(void)
 	int baud = DEFAULT_BAUD;
 	char arg[32];
 	int pos = 0;
-	int port = 0;
+	unsigned long port = 0;
 
 	if (cmdline_find_option("earlyprintk", arg, sizeof arg) > 0) {
 		char *e;
@@ -92,33 +75,47 @@ static void parse_earlyprintk(void)
 	}
 
 	if (port)
-		early_serial_init(port, baud);
+		early_serial_init(EARLY_SERIAL_IO, port, baud,
+				  SERIAL_BAUD_BASE);
 }
 
-#define BASE_BAUD (1843200/16)
-static unsigned int probe_baud(int port)
+static unsigned int probe_baud(int type, unsigned long port)
 {
 	unsigned char lcr, dll, dlh;
 	unsigned int quot;
+	int saved_type;
+	unsigned long saved_port;
 
-	lcr = inb(port + LCR);
-	outb(lcr | DLAB, port + LCR);
-	dll = inb(port + DLL);
-	dlh = inb(port + DLH);
-	outb(lcr, port + LCR);
+	saved_type = early_serial_type;
+	saved_port = early_serial_base;
+	early_serial_type = type;
+	early_serial_base = port;
+
+	lcr = early_serial_in(UART_LCR);
+	early_serial_out(UART_LCR, lcr | UART_LCR_DLAB);
+	dll = early_serial_in(UART_DLL);
+	dlh = early_serial_in(UART_DLM);
+	early_serial_out(UART_LCR, lcr);
 	quot = (dlh << 8) | dll;
 
-	return BASE_BAUD / quot;
+	early_serial_type = saved_type;
+	early_serial_base = saved_port;
+
+	return SERIAL_BAUD_BASE / quot;
 }
 
 static void parse_console_uart8250(void)
 {
 	char optstr[64], *options;
 	int baud = DEFAULT_BAUD;
-	int port = 0;
+	int base_baud = SERIAL_BAUD_BASE;
+	int type = EARLY_SERIAL_IO;
+	unsigned long port = 0;
 
 	/*
 	 * console=uart8250,io,0x3f8,115200n8
+	 * console=uart,mmio,0xe080100,115200n8
+	 * console=uart,mmio32,0xe0801000,115200n8
 	 * need to make sure it is last one console !
 	 */
 	if (cmdline_find_option("console", optstr, sizeof optstr) <= 0)
@@ -126,20 +123,41 @@ static void parse_console_uart8250(void)
 
 	options = optstr;
 
-	if (!strncmp(options, "uart8250,io,", 12))
-		port = simple_strtoull(options + 12, &options, 0);
-	else if (!strncmp(options, "uart,io,", 8))
-		port = simple_strtoull(options + 8, &options, 0);
-	else
+	if (strncmp(options, "uart", 4))
+		return;
+	options += 4;
+	if (!strncmp(options, "8250", 4))
+		options += 4;
+	if (*options++ != ',')
 		return;
 
-	if (options && (options[0] == ','))
+	if (!strncmp(options, "io,", 3))
+		port = simple_strtoull(options + 3, &options, 0);
+	else if (!strncmp(options, "mmio", 4)) {
+		options += 4;
+		type = EARLY_SERIAL_MMIO;
+		if (!strncmp(options, "32", 2)) {
+			options += 2;
+			type = EARLY_SERIAL_MMIO32;
+		}
+		if (*options++ != ',')
+			return;
+		port = simple_strtoull(options, &options, 0);
+	} else
+		return;
+
+	if (options && (options[0] == ',')) {
 		baud = simple_strtoull(options + 1, &options, 0);
+		while (*options != ' ' && *options != ',' && *options != '\0')
+			options++;
+		if (*options == ',')
+			base_baud = simple_strtoull(options + 1, &options, 0);
+	}
 	else
-		baud = probe_baud(port);
+		baud = probe_baud(type, port);
 
 	if (port)
-		early_serial_init(port, baud);
+		early_serial_init(type, port, baud, base_baud);
 }
 
 void console_init(void)
diff --git a/arch/x86/boot/early_serial_console.h b/arch/x86/boot/early_serial_console.h
new file mode 100644
index 0000000..3f7ff34
--- /dev/null
+++ b/arch/x86/boot/early_serial_console.h
@@ -0,0 +1,43 @@
+#include <linux/serial_reg.h>
+
+#define DEFAULT_SERIAL_PORT 0x3f8 /* ttyS0 */
+#define DEFAULT_BAUD 9600
+
+#define EARLY_SERIAL_IO		0
+#define EARLY_SERIAL_MMIO	1
+#define EARLY_SERIAL_MMIO32	2
+
+extern unsigned long early_serial_base;
+extern int early_serial_type;
+
+static inline unsigned int early_serial_in(int offset)
+{
+	switch (early_serial_type) {
+	case EARLY_SERIAL_IO:
+		return inb(early_serial_base + offset);
+	case EARLY_SERIAL_MMIO:
+		return readb((const volatile void *)early_serial_base +
+				offset);
+	case EARLY_SERIAL_MMIO32:
+		return readl((const volatile void *)early_serial_base +
+				(offset << 2));
+	default:
+		return 0;
+	}
+}
+
+static inline void early_serial_out(int offset, int value)
+{
+	switch (early_serial_type) {
+	case EARLY_SERIAL_IO:
+		outb(value, early_serial_base + offset);
+		break;
+	case EARLY_SERIAL_MMIO:
+		writeb(value, (volatile void *)early_serial_base + offset);
+		break;
+	case EARLY_SERIAL_MMIO32:
+		writel(value, (volatile void *)early_serial_base +
+				(offset << 2));
+		break;
+	}
+}
diff --git a/arch/x86/boot/tty.c b/arch/x86/boot/tty.c
index def2451..60dede2 100644
--- a/arch/x86/boot/tty.c
+++ b/arch/x86/boot/tty.c
@@ -15,12 +15,10 @@
 
 #include "boot.h"
 
-int early_serial_base;
+unsigned long early_serial_base;
+int early_serial_type;
 
-#define XMTRDY          0x20
-
-#define TXR             0       /*  Transmit register (WRITE) */
-#define LSR             5       /*  Line Status               */
+#include "early_serial_console.h"
 
 /*
  * These functions are in .inittext so they can be used to signal
@@ -31,10 +29,10 @@ static void __attribute__((section(".inittext"))) serial_putchar(int ch)
 {
 	unsigned timeout = 0xffff;
 
-	while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
+	while ((early_serial_in(UART_LSR) & UART_LSR_THRE) == 0 && --timeout)
 		cpu_relax();
 
-	outb(ch, early_serial_base + TXR);
+	early_serial_out(UART_TX, ch);
 }
 
 static void __attribute__((section(".inittext"))) bios_putchar(int ch)
diff --git a/drivers/tty/serial/8250/8250_early.c b/drivers/tty/serial/8250/8250_early.c
index 721904f..9526dd0 100644
--- a/drivers/tty/serial/8250/8250_early.c
+++ b/drivers/tty/serial/8250/8250_early.c
@@ -42,7 +42,7 @@
 
 struct early_serial8250_device {
 	struct uart_port port;
-	char options[16];		/* e.g., 115200n8 */
+	char options[32];		/* e.g., 115200n8 */
 	unsigned int baud;
 };
 
@@ -153,12 +153,11 @@ static int __init parse_options(struct early_serial8250_device *device,
 {
 	struct uart_port *port = &device->port;
 	int mmio, mmio32, length;
+	int base_baud = BASE_BAUD;
 
 	if (!options)
 		return -ENODEV;
 
-	port->uartclk = BASE_BAUD * 16;
-
 	mmio = !strncmp(options, "mmio,", 5);
 	mmio32 = !strncmp(options, "mmio32,", 7);
 	if (mmio || mmio32) {
@@ -195,12 +194,18 @@ static int __init parse_options(struct early_serial8250_device *device,
 		device->baud = simple_strtoul(options, NULL, 0);
 		length = min(strcspn(options, " "), sizeof(device->options));
 		strlcpy(device->options, options, length);
+		while (*options != ' ' && *options != '\0' && *options != ',')
+			options++;
+		if (*options == ',')
+			base_baud = simple_strtoul(options + 1, NULL, 0);
 	} else {
 		device->baud = probe_baud(port);
 		snprintf(device->options, sizeof(device->options), "%u",
 			device->baud);
 	}
 
+	port->uartclk = base_baud * 16;
+
 	if (mmio || mmio32)
 		printk(KERN_INFO
 		       "Early serial console at MMIO%s 0x%llx (options '%s')\n",
diff --git a/include/uapi/linux/serial_reg.h b/include/uapi/linux/serial_reg.h
index e632260..1b563f9 100644
--- a/include/uapi/linux/serial_reg.h
+++ b/include/uapi/linux/serial_reg.h
@@ -333,12 +333,13 @@
 
 #define UART_RSA_TCR_SWITCH (1 << 0) /* Timer on */
 
+#define SERIAL_BAUD_BASE (1843200/16)
 /*
  * The RSA DSV/II board has two fixed clock frequencies.  One is the
  * standard rate, and the other is 8 times faster.
  */
-#define SERIAL_RSA_BAUD_BASE (921600)
-#define SERIAL_RSA_BAUD_BASE_LO (SERIAL_RSA_BAUD_BASE / 8)
+#define SERIAL_RSA_BAUD_BASE_LO SERIAL_BAUD_BASE
+#define SERIAL_RSA_BAUD_BASE (SERIAL_BAUD_BASE * 8)
 
 /*
  * Extra serial register definitions for the internal UARTs
-- 
1.7.9.5


-- 
Kees Cook
Chrome OS Security

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/3] x86, boot: add mmio serial during compressed boot
  2013-07-12 20:38 ` [PATCH v2 " Kees Cook
@ 2013-07-13  6:47   ` Yinghai Lu
  2013-07-13 14:53     ` H. Peter Anvin
  2013-07-16 19:31     ` Kees Cook
  0 siblings, 2 replies; 17+ messages in thread
From: Yinghai Lu @ 2013-07-13  6:47 UTC (permalink / raw)
  To: Kees Cook, H. Peter Anvin, Eric W. Biederman
  Cc: Linux Kernel Mailing List, Rob Landley, Thomas Gleixner,
	Ingo Molnar, the arch/x86 maintainers, Greg Kroah-Hartman,
	linux-doc, linux-serial

On Fri, Jul 12, 2013 at 1:38 PM, Kees Cook <keescook@chromium.org> wrote:
> Allows "console=uart[8250],mmio[32],0xADDR[,BAUDn8[,BASE_BAUD]]" to
> be recognized during compressed boot early console setup, and during
> boot console setup. Replaces defines with common serial defines. Adds
> suport for mmio-based serial devices to compressed-boot early console,
> and plumbs support for defining the base baud rate for UART clock
> calculations (since mmio serial cards may not have the standard rate,
> resulting in incorrect baud rates for mmio devices).
>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> v2:
>  - fixed typo in SERIAL_RSA_...
> ---
>  Documentation/kernel-parameters.txt             |   12 ++-
>  arch/x86/boot/boot.h                            |   20 +++-
>  arch/x86/boot/compressed/early_serial_console.c |    5 +-
>  arch/x86/boot/compressed/misc.c                 |   10 +-
>  arch/x86/boot/compressed/misc.h                 |    4 +-
>  arch/x86/boot/early_serial_console.c            |  122 +++++++++++++----------
>  arch/x86/boot/early_serial_console.h            |   43 ++++++++
>  arch/x86/boot/tty.c                             |   12 +--
>  drivers/tty/serial/8250/8250_early.c            |   11 +-
>  include/uapi/linux/serial_reg.h                 |    5 +-
>  10 files changed, 168 insertions(+), 76 deletions(-)
>  create mode 100644 arch/x86/boot/early_serial_console.h
>
> diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
> index 15356ac..52ad7d8 100644
> --- a/Documentation/kernel-parameters.txt
> +++ b/Documentation/kernel-parameters.txt
> @@ -575,11 +575,21 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
>                         alternative.
>
>                 uart[8250],io,<addr>[,options]
> -               uart[8250],mmio,<addr>[,options]
> +               uart[8250],mmio,<addr>[,options[,base_baud]]
>                         Start an early, polled-mode console on the 8250/16550
>                         UART at the specified I/O port or MMIO address,
>                         switching to the matching ttyS device later.  The
>                         options are the same as for ttyS, above.
> +
> +                       For x86 early boot mmio uart consoles, the base baud
> +                       rate (for calculating the UART clock) can be defined
> +                       as well. This is done after the options above, comma
> +                       separated. For example "...,115200n8,4000000" would
> +                       use 4000000 as the base baud rate. Once the real uart
> +                       driver initializes, this value will be ignored, since
> +                       it will use the known device-specific value instead.
> +                       The default is 115200.
> +
>                 hvc<n>  Use the hypervisor console device <n>. This is for
>                         both Xen and PowerPC hypervisors.
>
> diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
> index 5b75319..ae61c19 100644
> --- a/arch/x86/boot/boot.h
> +++ b/arch/x86/boot/boot.h
> @@ -80,6 +80,23 @@ static inline void io_delay(void)
>         asm volatile("outb %%al,%0" : : "dN" (DELAY_PORT));
>  }
>
> +/* Minimal mmio functions from include/asm/io.h. */
> +#define build_mmio_read(name, size, type, reg, barrier) \
> +static inline type name(const volatile void __iomem *addr) \
> +{ type ret; asm volatile("mov" size " %1,%0":reg (ret) \
> +:"m" (*(volatile type __force *)addr) barrier); return ret; }
> +
> +#define build_mmio_write(name, size, type, reg, barrier) \
> +static inline void name(type val, volatile void __iomem *addr) \
> +{ asm volatile("mov" size " %0,%1": :reg (val), \
> +"m" (*(volatile type __force *)addr) barrier); }
> +
> +build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
> +build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
> +
> +build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
> +build_mmio_write(writel, "l", unsigned int, "r", :"memory")
> +
>  /* These functions are used to reference data in other segments. */
>
>  static inline u16 ds(void)
> @@ -319,7 +336,8 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr);
>  int validate_cpu(void);
>
>  /* early_serial_console.c */
> -extern int early_serial_base;
> +extern unsigned long early_serial_base;
> +extern int early_serial_type;
>  void console_init(void);

so the mmio range is under 4G.

for 32 bit, that is ok.
for 64 bit via 32bit bootloader, arch/x86/boot/compressed/head_64.S
will set page table for first 4G still ok.
for 64 bit via 64bit loader, like kexec via bzImage64, First Kernel/Kexec only
set ident mapping for usable range, so mmio just under 64 is not mapped.

Looks like we need to update boot.txt to add requirement for 64bit bootloader
that 0-4G need to be all ident mapping?

Yinghai

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/3] x86, boot: add mmio serial during compressed boot
  2013-07-13  6:47   ` Yinghai Lu
@ 2013-07-13 14:53     ` H. Peter Anvin
  2013-07-13 21:56       ` Yinghai Lu
  2013-07-16 19:31     ` Kees Cook
  1 sibling, 1 reply; 17+ messages in thread
From: H. Peter Anvin @ 2013-07-13 14:53 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Kees Cook, Eric W. Biederman, Linux Kernel Mailing List,
	Rob Landley, Thomas Gleixner, Ingo Molnar,
	the arch/x86 maintainers, Greg Kroah-Hartman, linux-doc,
	linux-serial

On 07/12/2013 11:47 PM, Yinghai Lu wrote:
> 
> for 32 bit, that is ok.
> for 64 bit via 32bit bootloader, arch/x86/boot/compressed/head_64.S
> will set page table for first 4G still ok.
> for 64 bit via 64bit loader, like kexec via bzImage64, First Kernel/Kexec only
> set ident mapping for usable range, so mmio just under 64 is not mapped.
> 
> Looks like we need to update boot.txt to add requirement for 64bit bootloader
> that 0-4G need to be all ident mapping?
> 

I think that is an unrealistic requirement, especially if this is the
sole user.

	-hpa



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/3] x86, boot: add mmio serial during compressed boot
  2013-07-13 14:53     ` H. Peter Anvin
@ 2013-07-13 21:56       ` Yinghai Lu
  2013-07-13 22:33         ` H. Peter Anvin
  0 siblings, 1 reply; 17+ messages in thread
From: Yinghai Lu @ 2013-07-13 21:56 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Kees Cook, Eric W. Biederman, Linux Kernel Mailing List,
	Rob Landley, Thomas Gleixner, Ingo Molnar,
	the arch/x86 maintainers, Greg Kroah-Hartman, linux-doc,
	linux-serial

On Sat, Jul 13, 2013 at 7:53 AM, H. Peter Anvin <hpa@zytor.com> wrote:
> On 07/12/2013 11:47 PM, Yinghai Lu wrote:
>>
>> for 32 bit, that is ok.
>> for 64 bit via 32bit bootloader, arch/x86/boot/compressed/head_64.S
>> will set page table for first 4G still ok.
>> for 64 bit via 64bit loader, like kexec via bzImage64, First Kernel/Kexec only
>> set ident mapping for usable range, so mmio just under 64 is not mapped.
>>
>> Looks like we need to update boot.txt to add requirement for 64bit bootloader
>> that 0-4G need to be all ident mapping?
>>
>
> I think that is an unrealistic requirement, especially if this is the
> sole user.

That will cause regression for:
64bit system with kexec/kdump bzImage64.
if second kernel carry "console=uart,mmio,0xABCD0000"

or we can extend kexec-tools to make it scan second kernel command line string
and one entry into image->segment[]

Yinghai

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/3] x86, boot: add mmio serial during compressed boot
  2013-07-13 21:56       ` Yinghai Lu
@ 2013-07-13 22:33         ` H. Peter Anvin
  0 siblings, 0 replies; 17+ messages in thread
From: H. Peter Anvin @ 2013-07-13 22:33 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Kees Cook, Eric W. Biederman, Linux Kernel Mailing List,
	Rob Landley, Thomas Gleixner, Ingo Molnar,
	the arch/x86 maintainers, Greg Kroah-Hartman, linux-doc,
	linux-serial

I think we will need to map the uart explicitly, which is complex as that in turn implies seeing up something like the fixmap for the decompressor... not impossible but additional complexity to be sure.  At least on 64 bits the high half should not conflict with any physical addresses.

Either that or be able to add pagetables to map the mmio directly or via a #PF handler like we already have in the early kernel.

Yinghai Lu <yinghai@kernel.org> wrote:

>On Sat, Jul 13, 2013 at 7:53 AM, H. Peter Anvin <hpa@zytor.com> wrote:
>> On 07/12/2013 11:47 PM, Yinghai Lu wrote:
>>>
>>> for 32 bit, that is ok.
>>> for 64 bit via 32bit bootloader, arch/x86/boot/compressed/head_64.S
>>> will set page table for first 4G still ok.
>>> for 64 bit via 64bit loader, like kexec via bzImage64, First
>Kernel/Kexec only
>>> set ident mapping for usable range, so mmio just under 64 is not
>mapped.
>>>
>>> Looks like we need to update boot.txt to add requirement for 64bit
>bootloader
>>> that 0-4G need to be all ident mapping?
>>>
>>
>> I think that is an unrealistic requirement, especially if this is the
>> sole user.
>
>That will cause regression for:
>64bit system with kexec/kdump bzImage64.
>if second kernel carry "console=uart,mmio,0xABCD0000"
>
>or we can extend kexec-tools to make it scan second kernel command line
>string
>and one entry into image->segment[]
>
>Yinghai

-- 
Sent from my mobile phone. Please excuse brevity and lack of formatting.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/3] x86, boot: add mmio serial during compressed boot
  2013-07-13  6:47   ` Yinghai Lu
  2013-07-13 14:53     ` H. Peter Anvin
@ 2013-07-16 19:31     ` Kees Cook
  2013-07-16 19:36       ` H. Peter Anvin
  1 sibling, 1 reply; 17+ messages in thread
From: Kees Cook @ 2013-07-16 19:31 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: H. Peter Anvin, Eric W. Biederman, Linux Kernel Mailing List,
	Rob Landley, Thomas Gleixner, Ingo Molnar,
	the arch/x86 maintainers, Greg Kroah-Hartman, linux-doc,
	linux-serial

On Fri, Jul 12, 2013 at 11:47 PM, Yinghai Lu <yinghai@kernel.org> wrote:
> On Fri, Jul 12, 2013 at 1:38 PM, Kees Cook <keescook@chromium.org> wrote:
>> Allows "console=uart[8250],mmio[32],0xADDR[,BAUDn8[,BASE_BAUD]]" to
>> be recognized during compressed boot early console setup, and during
>> boot console setup. Replaces defines with common serial defines. Adds
>> suport for mmio-based serial devices to compressed-boot early console,
>> and plumbs support for defining the base baud rate for UART clock
>> calculations (since mmio serial cards may not have the standard rate,
>> resulting in incorrect baud rates for mmio devices).
>>
>> Signed-off-by: Kees Cook <keescook@chromium.org>
>> ---
>> v2:
>>  - fixed typo in SERIAL_RSA_...
>> ---
>>  Documentation/kernel-parameters.txt             |   12 ++-
>>  arch/x86/boot/boot.h                            |   20 +++-
>>  arch/x86/boot/compressed/early_serial_console.c |    5 +-
>>  arch/x86/boot/compressed/misc.c                 |   10 +-
>>  arch/x86/boot/compressed/misc.h                 |    4 +-
>>  arch/x86/boot/early_serial_console.c            |  122 +++++++++++++----------
>>  arch/x86/boot/early_serial_console.h            |   43 ++++++++
>>  arch/x86/boot/tty.c                             |   12 +--
>>  drivers/tty/serial/8250/8250_early.c            |   11 +-
>>  include/uapi/linux/serial_reg.h                 |    5 +-
>>  10 files changed, 168 insertions(+), 76 deletions(-)
>>  create mode 100644 arch/x86/boot/early_serial_console.h
>>
>> diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
>> index 15356ac..52ad7d8 100644
>> --- a/Documentation/kernel-parameters.txt
>> +++ b/Documentation/kernel-parameters.txt
>> @@ -575,11 +575,21 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
>>                         alternative.
>>
>>                 uart[8250],io,<addr>[,options]
>> -               uart[8250],mmio,<addr>[,options]
>> +               uart[8250],mmio,<addr>[,options[,base_baud]]
>>                         Start an early, polled-mode console on the 8250/16550
>>                         UART at the specified I/O port or MMIO address,
>>                         switching to the matching ttyS device later.  The
>>                         options are the same as for ttyS, above.
>> +
>> +                       For x86 early boot mmio uart consoles, the base baud
>> +                       rate (for calculating the UART clock) can be defined
>> +                       as well. This is done after the options above, comma
>> +                       separated. For example "...,115200n8,4000000" would
>> +                       use 4000000 as the base baud rate. Once the real uart
>> +                       driver initializes, this value will be ignored, since
>> +                       it will use the known device-specific value instead.
>> +                       The default is 115200.
>> +
>>                 hvc<n>  Use the hypervisor console device <n>. This is for
>>                         both Xen and PowerPC hypervisors.
>>
>> diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
>> index 5b75319..ae61c19 100644
>> --- a/arch/x86/boot/boot.h
>> +++ b/arch/x86/boot/boot.h
>> @@ -80,6 +80,23 @@ static inline void io_delay(void)
>>         asm volatile("outb %%al,%0" : : "dN" (DELAY_PORT));
>>  }
>>
>> +/* Minimal mmio functions from include/asm/io.h. */
>> +#define build_mmio_read(name, size, type, reg, barrier) \
>> +static inline type name(const volatile void __iomem *addr) \
>> +{ type ret; asm volatile("mov" size " %1,%0":reg (ret) \
>> +:"m" (*(volatile type __force *)addr) barrier); return ret; }
>> +
>> +#define build_mmio_write(name, size, type, reg, barrier) \
>> +static inline void name(type val, volatile void __iomem *addr) \
>> +{ asm volatile("mov" size " %0,%1": :reg (val), \
>> +"m" (*(volatile type __force *)addr) barrier); }
>> +
>> +build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
>> +build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
>> +
>> +build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
>> +build_mmio_write(writel, "l", unsigned int, "r", :"memory")
>> +
>>  /* These functions are used to reference data in other segments. */
>>
>>  static inline u16 ds(void)
>> @@ -319,7 +336,8 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr);
>>  int validate_cpu(void);
>>
>>  /* early_serial_console.c */
>> -extern int early_serial_base;
>> +extern unsigned long early_serial_base;
>> +extern int early_serial_type;
>>  void console_init(void);
>
> so the mmio range is under 4G.
>
> for 32 bit, that is ok.
> for 64 bit via 32bit bootloader, arch/x86/boot/compressed/head_64.S
> will set page table for first 4G still ok.
> for 64 bit via 64bit loader, like kexec via bzImage64, First Kernel/Kexec only
> set ident mapping for usable range, so mmio just under 64 is not mapped.
>
> Looks like we need to update boot.txt to add requirement for 64bit bootloader
> that 0-4G need to be all ident mapping?

Could the first step be documenting the limitation? I've found this
patch extremely useful for my case already, and I imagine there might
be other people that need the early mmio stuff to. Generally the
compressed boot serial console stuff is going to be used in the more
common non-kexec situations at least for a while.

Does this patch create any _problems_? Right now, neither low nor >4G
kernel can use an mmio serial port. :) This this, we'd at least gain
it for the low case.

-Kees

--
Kees Cook
Chrome OS Security

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/3] x86, boot: add mmio serial during compressed boot
  2013-07-16 19:31     ` Kees Cook
@ 2013-07-16 19:36       ` H. Peter Anvin
  2013-07-16 19:40         ` Kees Cook
  0 siblings, 1 reply; 17+ messages in thread
From: H. Peter Anvin @ 2013-07-16 19:36 UTC (permalink / raw)
  To: Kees Cook
  Cc: Yinghai Lu, Eric W. Biederman, Linux Kernel Mailing List,
	Rob Landley, Thomas Gleixner, Ingo Molnar,
	the arch/x86 maintainers, Greg Kroah-Hartman, linux-doc,
	linux-serial

On 07/16/2013 12:31 PM, Kees Cook wrote:
> 
> Could the first step be documenting the limitation? I've found this
> patch extremely useful for my case already, and I imagine there might
> be other people that need the early mmio stuff to. Generally the
> compressed boot serial console stuff is going to be used in the more
> common non-kexec situations at least for a while.
> 
> Does this patch create any _problems_? Right now, neither low nor >4G
> kernel can use an mmio serial port. :) This this, we'd at least gain
> it for the low case.
> 

Even documenting the limitation is likely to end up with a bunch of
emails asking why their kernel crashed.

I think setting up a dynamic #PF handler is the right thing for the
decompressor, we already did for the kernel proper.

	-hpa



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/3] x86, boot: add mmio serial during compressed boot
  2013-07-16 19:36       ` H. Peter Anvin
@ 2013-07-16 19:40         ` Kees Cook
  2013-07-16 19:41           ` H. Peter Anvin
  2013-07-16 21:03           ` Yinghai Lu
  0 siblings, 2 replies; 17+ messages in thread
From: Kees Cook @ 2013-07-16 19:40 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Yinghai Lu, Eric W. Biederman, Linux Kernel Mailing List,
	Rob Landley, Thomas Gleixner, Ingo Molnar,
	the arch/x86 maintainers, Greg Kroah-Hartman, linux-doc,
	linux-serial

On Tue, Jul 16, 2013 at 12:36 PM, H. Peter Anvin <hpa@zytor.com> wrote:
> On 07/16/2013 12:31 PM, Kees Cook wrote:
>>
>> Could the first step be documenting the limitation? I've found this
>> patch extremely useful for my case already, and I imagine there might
>> be other people that need the early mmio stuff to. Generally the
>> compressed boot serial console stuff is going to be used in the more
>> common non-kexec situations at least for a while.
>>
>> Does this patch create any _problems_? Right now, neither low nor >4G
>> kernel can use an mmio serial port. :) This this, we'd at least gain
>> it for the low case.
>>
>
> Even documenting the limitation is likely to end up with a bunch of
> emails asking why their kernel crashed.
>
> I think setting up a dynamic #PF handler is the right thing for the
> decompressor, we already did for the kernel proper.

I'm not sure how to accomplish this yet. I'm still trying to
understand how the page tables are arranged. :)

-Kees

--
Kees Cook
Chrome OS Security

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/3] x86, boot: add mmio serial during compressed boot
  2013-07-16 19:40         ` Kees Cook
@ 2013-07-16 19:41           ` H. Peter Anvin
  2013-07-16 21:59             ` Yinghai Lu
  2013-07-16 21:03           ` Yinghai Lu
  1 sibling, 1 reply; 17+ messages in thread
From: H. Peter Anvin @ 2013-07-16 19:41 UTC (permalink / raw)
  To: Kees Cook
  Cc: Yinghai Lu, Eric W. Biederman, Linux Kernel Mailing List,
	Rob Landley, Thomas Gleixner, Ingo Molnar,
	the arch/x86 maintainers, Greg Kroah-Hartman, linux-doc,
	linux-serial

On 07/16/2013 12:40 PM, Kees Cook wrote:
>>
>> I think setting up a dynamic #PF handler is the right thing for the
>> decompressor, we already did for the kernel proper.
> 
> I'm not sure how to accomplish this yet. I'm still trying to
> understand how the page tables are arranged. :)
> 

Look at the handler at the top of arch/x86/kernel/head64.c.

	-hpa



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/3] x86, boot: add mmio serial during compressed boot
  2013-07-16 19:40         ` Kees Cook
  2013-07-16 19:41           ` H. Peter Anvin
@ 2013-07-16 21:03           ` Yinghai Lu
  2013-07-16 22:05             ` H. Peter Anvin
  1 sibling, 1 reply; 17+ messages in thread
From: Yinghai Lu @ 2013-07-16 21:03 UTC (permalink / raw)
  To: Kees Cook
  Cc: H. Peter Anvin, Eric W. Biederman, Linux Kernel Mailing List,
	Rob Landley, Thomas Gleixner, Ingo Molnar,
	the arch/x86 maintainers, Greg Kroah-Hartman, linux-doc,
	linux-serial

On Tue, Jul 16, 2013 at 12:40 PM, Kees Cook <keescook@chromium.org> wrote:
> On Tue, Jul 16, 2013 at 12:36 PM, H. Peter Anvin <hpa@zytor.com> wrote:
>> On 07/16/2013 12:31 PM, Kees Cook wrote:
>>>
>>> Could the first step be documenting the limitation? I've found this
>>> patch extremely useful for my case already, and I imagine there might
>>> be other people that need the early mmio stuff to. Generally the
>>> compressed boot serial console stuff is going to be used in the more
>>> common non-kexec situations at least for a while.
>>>
>>> Does this patch create any _problems_? Right now, neither low nor >4G
>>> kernel can use an mmio serial port. :) This this, we'd at least gain
>>> it for the low case.
>>>
>>
>> Even documenting the limitation is likely to end up with a bunch of
>> emails asking why their kernel crashed.
>>
>> I think setting up a dynamic #PF handler is the right thing for the
>> decompressor, we already did for the kernel proper.
>
> I'm not sure how to accomplish this yet. I'm still trying to
> understand how the page tables are arranged. :)

Other way could be:

Detect if it get into misc.c directly from
arch/x86/boot/compressed/head_64.S::startup_64. that is from 64bit
bootloader.

others go through startup_32 should be 32bit bootloader.

If it with 64bit boot loader path, You can skip parsing mmio in
misc.c::console_init() calling.

Yinghai

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/3] x86, boot: add mmio serial during compressed boot
  2013-07-16 19:41           ` H. Peter Anvin
@ 2013-07-16 21:59             ` Yinghai Lu
  0 siblings, 0 replies; 17+ messages in thread
From: Yinghai Lu @ 2013-07-16 21:59 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Kees Cook, Eric W. Biederman, Linux Kernel Mailing List,
	Rob Landley, Thomas Gleixner, Ingo Molnar,
	the arch/x86 maintainers, Greg Kroah-Hartman, linux-doc,
	linux-serial

On Tue, Jul 16, 2013 at 12:41 PM, H. Peter Anvin <hpa@zytor.com> wrote:
> On 07/16/2013 12:40 PM, Kees Cook wrote:
>>>
>>> I think setting up a dynamic #PF handler is the right thing for the
>>> decompressor, we already did for the kernel proper.
>>
>> I'm not sure how to accomplish this yet. I'm still trying to
>> understand how the page tables are arranged. :)
>>
>
> Look at the handler at the top of arch/x86/kernel/head64.c.

could extract code from arch/x86/kernel/{head64.c, head_64.S},
and share them with arch/x86/boot/compressed/{misc.c, head_64.S}

Yinghai

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/3] x86, boot: add mmio serial during compressed boot
  2013-07-16 21:03           ` Yinghai Lu
@ 2013-07-16 22:05             ` H. Peter Anvin
  0 siblings, 0 replies; 17+ messages in thread
From: H. Peter Anvin @ 2013-07-16 22:05 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Kees Cook, Eric W. Biederman, Linux Kernel Mailing List,
	Rob Landley, Thomas Gleixner, Ingo Molnar,
	the arch/x86 maintainers, Greg Kroah-Hartman, linux-doc,
	linux-serial

On 07/16/2013 02:03 PM, Yinghai Lu wrote:
> 
> Other way could be:
> 
> Detect if it get into misc.c directly from
> arch/x86/boot/compressed/head_64.S::startup_64. that is from 64bit
> bootloader.
> 
> others go through startup_32 should be 32bit bootloader.
> 
> If it with 64bit boot loader path, You can skip parsing mmio in
> misc.c::console_init() calling.
> 

Don't hack around it when we can do it right.

	-hpa



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2013-07-16 22:05 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-12 20:07 [PATCH 1/3] x86, boot: add mmio serial during compressed boot Kees Cook
2013-07-12 20:07 ` [PATCH 2/3] serial: report base_baud after initialization Kees Cook
2013-07-12 20:07 ` [PATCH 3/3] printk: report boot console names during cut-over Kees Cook
     [not found] ` <CAGXu5jL=oSkWTGEbYLxAU1PwGbgoyeiOgFV31Gd4yj1JkDECBg@mail.gmail.com>
2013-07-12 20:17   ` [PATCH 1/3] x86, boot: add mmio serial during compressed boot Kees Cook
2013-07-12 20:20   ` H. Peter Anvin
2013-07-12 20:38 ` [PATCH v2 " Kees Cook
2013-07-13  6:47   ` Yinghai Lu
2013-07-13 14:53     ` H. Peter Anvin
2013-07-13 21:56       ` Yinghai Lu
2013-07-13 22:33         ` H. Peter Anvin
2013-07-16 19:31     ` Kees Cook
2013-07-16 19:36       ` H. Peter Anvin
2013-07-16 19:40         ` Kees Cook
2013-07-16 19:41           ` H. Peter Anvin
2013-07-16 21:59             ` Yinghai Lu
2013-07-16 21:03           ` Yinghai Lu
2013-07-16 22:05             ` H. Peter Anvin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.