Xen virtual console driver question
Subsystems (3)
What is the plan for the future of the Xen virtual console driver? Will it continue to hijack /dev/ttyS0 or get its own device like /dev/xencons?
The reason I ask is that I need a single Linux kernel binary, including one with builtin console=X command line arguments, to run on bare hardware and as a dom0 under Xen. Xen's current approach is to disable the physical serial port drivers in the Linux .config, which I need enabled to run properly on bare JS21 blades.
I am currently using the below patch, but would really prefer not to. It's basic approach is to have the Xen virtual console driver react "gracefully" in the case that a real serial driver has already registered ttyS0-ttyS3. It's current behavior is to fail if the 8250 driver was initialized ahead of it, and console is lost. In the process I found a bug in Linux, and have included the patch for it since otherwise the Xen driver initialization will succeed but with negative side effects in the kobject subsystem.
What is the story?
---
arch/powerpc/configs/xen_maple_defconfig +9 -1
@@ -704,10 +704,18 @@ CONFIG_HW_CONSOLE=y # # Serial drivers # +CONFIG_SERIAL_8250=y +CONFIG_SERIAL_8250_CONSOLE=y +CONFIG_SERIAL_8250_PCI=y +CONFIG_SERIAL_8250_NR_UARTS=4 +CONFIG_SERIAL_8250_RUNTIME_UARTS=4 +# CONFIG_SERIAL_8250_EXTENDED is not set # # Non-8250 serial port support # +CONFIG_SERIAL_CORE=y +CONFIG_SERIAL_CORE_CONSOLE=y # CONFIG_SERIAL_ICOM is not set # CONFIG_SERIAL_JSM is not set CONFIG_UNIX98_PTYS=y
@@ -1307,7 +1315,7 @@ CONFIG_XEN_BLKDEV_FRONTEND=y CONFIG_XEN_BLKDEV_FRONTEND=y CONFIG_XEN_NETDEV_FRONTEND=y CONFIG_XEN_SCRUB_PAGES=y -CONFIG_XEN_DISABLE_SERIAL=y +# CONFIG_XEN_DISABLE_SERIAL is not set CONFIG_XEN_SYSFS=y # CONFIG_XEN_COMPAT_030002_AND_LATER is not set CONFIG_XEN_COMPAT_LATEST_ONLY=y
drivers/xen/console/console.c +11 -0
@@ -70,6 +70,7 @@*/ static enum {XC_OFF ,XC_DEFAULT ,XC_TTY ,XC_SERIAL } xc_mode =XC_DEFAULT ;static int xc_num =-1 ; +enum {XC_NUM_MAX =8 };#ifdef CONFIG_MAGIC_SYSRQ static unsigned long sysrq_requested;
@@ -576,6 +577,7 @@ static int __init xencons_init(void)xencons_ring_init (); +retry: xencons_driver =alloc_tty_driver ((xc_mode ==XC_SERIAL ) ?1 :MAX_NR_CONSOLES );if (xencons_driver ==NULL )
@@ -612,6 +614,15 @@ static int __init xencons_init(void) DRV(xencons_driver)->name_base);put_tty_driver (xencons_driver); xencons_driver =NULL ; + +/* Somebody, almost certainly the real serial port +driver, registered ahead of us, so find the first +unused minor. */ +if (xc_num <=XC_NUM_MAX ) { + xc_num++; + goto retry; + } +return rc; }
fs/char_dev.c +5 -2
@@ -111,10 +111,13 @@ __register_chrdev_region(unsigned int mafor (cp = &chrdevs[i]; *cp; cp = &(*cp)->next)if ((*cp)->major > major || - ((*cp)->major == major && (*cp)->baseminor >= baseminor)) + ((*cp)->major == major && + (((*cp)->baseminor >= baseminor) || + ((*cp)->baseminor + (*cp)->minorct > baseminor))))break ;if (*cp && (*cp)->major == major && - (*cp)->baseminor < baseminor + minorct) { + (((*cp)->baseminor < baseminor + minorct) || + ((*cp)->baseminor + (*cp)->minorct > baseminor))) { ret = -EBUSY ; goto out; }
Quoted 10 lines · Amos Waterland
I am currently using the below patch, but would really prefer not to. It's basic approach is to have the Xen virtual console driver react "gracefully" in the case that a real serial driver has already registered ttyS0-ttyS3. It's current behavior is to fail if the 8250 driver was initialized ahead of it, and console is lost. In the process I found a bug in Linux, and have included the patch for it since otherwise the Xen driver initialization will succeed but with negative side effects in the kobject subsystem.
What is the story?
We need to obtain our own device number and then patch the driver. It'd be great if someone else wants to look into this.
-- Keir
PATCH 1/1 Virtual console driver on /dev/xvc0
Quoted 10 lines · Keir Fraser
Quoted 9 lines · Amos Waterland
I am currently using the below patch, but would really prefer not to. It's basic approach is to have the Xen virtual console driver react "gracefully" in the case that a real serial driver has already registered ttyS0-ttyS3. It's current behavior is to fail if the 8250 driver was initialized ahead of it, and console is lost. In the process I found a bug in Linux, and have included the patch for it since otherwise the Xen driver initialization will succeed but with negative side effects in the kobject subsystem.
Quoted 6 lines
Quoted 1 line
What is the story?
We need to obtain our own device number and then patch the driver. It'd be great if someone else wants to look into this.
-- Keir
The below is the least invasive approach I can find, and works well on my PPC64 blades: I can boot the exact same kernel on bare hardware and as a dom0. I am sure there will be distro concerns (such as /etc/inittab and /etc/securetty), but I'd like to get the ball rolling with this initial submission.
Note that you have to put xencons=xvc0' in your Linux .config, and run mknod /dev/xvc0 c 232 0' in your rootfs.
---
drivers/xen/console/console.c | 19 +++++++++++++++++-- include/linux/major.h | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-)
drivers/xen/console/console.c +17 -2
@@ -63,12 +63,14 @@* 'xencons=off' [XC_OFF]: Console is disabled. * 'xencons=tty' [XC_TTY]: Console attached to '/dev/tty[0-9]+'. * 'xencons=ttyS' [XC_SERIAL]: Console attached to '/dev/ttyS[0-9]+'. +* 'xencons=xvc' [XC_XVC]: Console attached to '/dev/xvc[0-9]+'. * [XC_DEFAULT]: DOM0 -> XC_SERIAL ; all others -> XC_TTY. * * NB. In mode XC_TTY, we create dummy consoles for tty2-63. This suppresses * warnings from standard distro startup scripts. */ -static enum {XC_OFF ,XC_DEFAULT ,XC_TTY ,XC_SERIAL } xc_mode =XC_DEFAULT ; +static enum {XC_OFF ,XC_DEFAULT ,XC_TTY ,XC_SERIAL ,XC_XVC } + xc_mode =XC_DEFAULT ;static int xc_num =-1 ;#ifdef CONFIG_MAGIC_SYSRQ
@@ -85,6 +87,8 @@ static int __init xencons_setup(char *st xc_mode =XC_SERIAL ; else if (!strncmp(str, "tty", 3)) xc_mode =XC_TTY ; + else if (!strncmp(str, "xvc", 3)) + xc_mode =XC_XVC ; else if (!strncmp(str, "off", 3)) xc_mode =XC_OFF ;
@@ -192,7 +196,7 @@ static int __init xen_console_init(void)if (xc_mode ==XC_DEFAULT ) xc_mode =XC_SERIAL ; kcons_info.write = kcons_write_dom0; -if (xc_mode ==XC_SERIAL ) +if (xc_mode ==XC_SERIAL || xc_mode ==XC_XVC ) kcons_info.flags |=CON_ENABLED ; }else {if (xc_mode ==XC_DEFAULT )
@@ -201,6 +205,12 @@ static int __init xen_console_init(void) }switch (xc_mode) { +case XC_XVC : +strcpy (kcons_info.name,"xvc" ); +if (xc_num ==-1 ) + xc_num =0 ; +break ; +case XC_SERIAL :strcpy (kcons_info.name,"ttyS" );if (xc_num ==-1 )
@@ -597,6 +607,11 @@ static int __init xencons_init(void)DRV (xencons_driver)->name ="ttyS" ;DRV (xencons_driver)->minor_start =64 + xc_num;DRV (xencons_driver)->name_base =0 + xc_num; + }else if (xc_mode ==XC_XVC ) { +DRV (xencons_driver)->name ="xvc" ; +DRV (xencons_driver)->major =XEN_VIRTUAL_CONSOLE ; +DRV (xencons_driver)->minor_start =0 ; +DRV (xencons_driver)->name_base =0 ; }else {DRV (xencons_driver)->name ="tty" ;DRV (xencons_driver)->minor_start = xc_num;
include/linux/major.h +2 -0
@@ -166,4 +166,6 @@#define VIOTAPE_MAJOR 230 +#define XEN_VIRTUAL_CONSOLE 232 +#endif
Re: [PATCH] Virtual console driver on /dev/xvc0
Quoted 10 lines · Amos Waterland
The below is the least invasive approach I can find, and works well on my PPC64 blades: I can boot the exact same kernel on bare hardware and as a dom0. I am sure there will be distro concerns (such as
/etc/inittaband/etc/securetty), but I'd like to get the ball rolling with this initial submission.Note that you have to put
xencons=xvc0' in your Linux .config, and runmknod/dev/xvc0c 232 0' in your rootfs.Signed-off-by Amos Waterland <[email protected]>
How did you pick the major? Is there a process for allocating one (I think our bklock-device major is now official)? Could we use a more dynamic (e.g., udev-based) scheme to avoid locking down 1/256th of the 8-bit major space for this?
-- Keir
Re: Re: [PATCH] Virtual console driver on /dev/xvc0
Quoted 11 lines · Keir Fraser
Quoted 9 lines · Amos Waterland
The below is the least invasive approach I can find, and works well on my PPC64 blades: I can boot the exact same kernel on bare hardware and as a dom0. I am sure there will be distro concerns (such as
/etc/inittaband/etc/securetty), but I'd like to get the ball rolling with this initial submission.Note that you have to put
xencons=xvc0' in your Linux .config, and runmknod/dev/xvc0c 232 0' in your rootfs.
Quoted 6 lines
Quoted 1 line
Signed-off-by Amos Waterland <[email protected]>How did you pick the major? Is there a process for allocating one (I think our bklock-device major is now official)? Could we use a more dynamic (e.g., udev-based) scheme to avoid locking down 1/256th of the 8-bit major space for this?
The instructions for getting a major are available at
http://www.lanana.org/docs/device-list/instructions.txt and the official list of majors/minors is at
http://www.lanana.org/docs/device-list/devices-2.6+.txt.
char major 232 is already taken for biometrics. There's no reason that we shouldn't be able to get a minor (or a couple, if it makes more sense to have more than one xvc device in some case) char devices in the low-density serial console region (char major 204)
Jeremy
Re: Re: [PATCH] Virtual console driver on /dev/xvc0
Quoted 10 lines · Jeremy Katz
Quoted 4 lines
How did you pick the major? Is there a process for allocating one (I think our bklock-device major is now official)? Could we use a more dynamic (e.g., udev-based) scheme to avoid locking down 1/256th of the 8-bit major space for this?
The instructions for getting a major are available at
http://www.lanana.org/docs/device-list/instructions.txt and the official list of majors/minors is at
http://www.lanana.org/docs/device-list/devices-2.6+.txt.
Quoted 4 lines
char major 232 is already taken for biometrics. There's no reason that we shouldn't be able to get a minor (or a couple, if it makes more sense to have more than one xvc device in some case) char devices in the low-density serial console region (char major 204)
That page makes it sound like the static allocation of device numbers is obsolete. Is there some preferred dynamic method now?
-- Keir
Re: Re: [PATCH] Virtual console driver on /dev/xvc0
Quoted 11 lines · Keir Fraser
Quoted 10 lines · Jeremy Katz
Quoted 4 lines
How did you pick the major? Is there a process for allocating one (I think our bklock-device major is now official)? Could we use a more dynamic (e.g., udev-based) scheme to avoid locking down 1/256th of the 8-bit major space for this?
The instructions for getting a major are available at
http://www.lanana.org/docs/device-list/instructions.txt and the official list of majors/minors is at
http://www.lanana.org/docs/device-list/devices-2.6+.txt.
Quoted 7 lines
Quoted 4 lines
char major 232 is already taken for biometrics. There's no reason that we shouldn't be able to get a minor (or a couple, if it makes more sense to have more than one xvc device in some case) char devices in the low-density serial console region (char major 204)
That page makes it sound like the static allocation of device numbers is obsolete. Is there some preferred dynamic method now?
Using udev or similar is the way of doing things dynamically. But there are still a number of areas where static major/minor is strongly desirable and consoles are one of those areas.
Jeremy
PATCH 1/1 Virtual console driver on /dev/xvc0 (take two)
In reply to Jeremy KatzUse the low-density serial console major and the next free minor according to the Lanana. Since it would be awkward to say 'xencons=xvc187', use name_base to allow /dev/xvc0 to be major/minor 204/187.
To use, put xencons=xvc0' in your Linux .config, and run mknod /dev/xvc0 c 204 187' in your rootfs. Built and booted up to nfsroot on a JS21 ppc64 blade both on bare hardware and as a dom0.
---
drivers/xen/console/console.c | 29 +++++++++++++++++++++++++++-- include/linux/major.h | 1 + 2 files changed, 28 insertions(+), 2 deletions(-)
drivers/xen/console/console.c +27 -2
@@ -63,13 +63,20 @@* 'xencons=off' [XC_OFF]: Console is disabled. * 'xencons=tty' [XC_TTY]: Console attached to '/dev/tty[0-9]+'. * 'xencons=ttyS' [XC_SERIAL]: Console attached to '/dev/ttyS[0-9]+'. +* 'xencons=xvc' [XC_XVC]: Console attached to '/dev/xvc[0-9]+'. * [XC_DEFAULT]: DOM0 -> XC_SERIAL ; all others -> XC_TTY. * * NB. In mode XC_TTY, we create dummy consoles for tty2-63. This suppresses * warnings from standard distro startup scripts. */ -static enum {XC_OFF ,XC_DEFAULT ,XC_TTY ,XC_SERIAL } xc_mode =XC_DEFAULT ; +static enum {XC_OFF ,XC_DEFAULT ,XC_TTY ,XC_SERIAL ,XC_XVC } + xc_mode =XC_DEFAULT ;static int xc_num =-1 ; + +/* If we are in XC_XVC mode (a virtual console at /dev/xvcX), we need to +* comply with Lanana and use a minor under the low density serial major. +*/ +#define XEN_XVC_MINOR 187#ifdef CONFIG_MAGIC_SYSRQ static unsigned long sysrq_requested;
@@ -85,6 +92,8 @@ static int __init xencons_setup(char *st xc_mode =XC_SERIAL ; else if (!strncmp(str, "tty", 3)) xc_mode =XC_TTY ; + else if (!strncmp(str, "xvc", 3)) + xc_mode =XC_XVC ; else if (!strncmp(str, "off", 3)) xc_mode =XC_OFF ;
@@ -95,6 +104,11 @@ static int __init xencons_setup(char *st xc_num = n;break ;case XC_TTY : + n =simple_strtol (str+3 , &q,10 ); +if (q > (str +3 )) + xc_num = n; +break ; +case XC_XVC : n =simple_strtol (str+3 , &q,10 );if (q > (str +3 )) xc_num = n;
@@ -192,7 +206,7 @@ static int __init xen_console_init(void)if (xc_mode ==XC_DEFAULT ) xc_mode =XC_SERIAL ; kcons_info.write = kcons_write_dom0; -if (xc_mode ==XC_SERIAL ) +if (xc_mode ==XC_SERIAL || xc_mode ==XC_XVC ) kcons_info.flags |=CON_ENABLED ; }else {if (xc_mode ==XC_DEFAULT )
@@ -201,6 +215,12 @@ static int __init xen_console_init(void) }switch (xc_mode) { +case XC_XVC : +strcpy (kcons_info.name,"xvc" ); +if (xc_num ==-1 ) + xc_num =0 ; +break ; +case XC_SERIAL :strcpy (kcons_info.name,"ttyS" );if (xc_num ==-1 )
@@ -597,6 +617,11 @@ static int __init xencons_init(void)DRV (xencons_driver)->name ="ttyS" ;DRV (xencons_driver)->minor_start =64 + xc_num;DRV (xencons_driver)->name_base =0 + xc_num; + }else if (xc_mode ==XC_XVC ) { +DRV (xencons_driver)->name ="xvc" ; +DRV (xencons_driver)->major =LOW_DENS_SERIAL_MAJOR ; +DRV (xencons_driver)->minor_start =XEN_XVC_MINOR ; +DRV (xencons_driver)->name_base = xc_num; }else {DRV (xencons_driver)->name ="tty" ;DRV (xencons_driver)->minor_start = xc_num;
include/linux/major.h +1 -0
@@ -158,6 +158,7 @@#define MSR_MAJOR 202#define CPUID_MAJOR 203 +#define LOW_DENS_SERIAL_MAJOR 204#define OSST_MAJOR 206/* OnStream-SCx0 SCSI tape */
Re: [PATCH] Virtual console driver on /dev/xvc0 (take two)
Quoted 4 lines · Amos Waterland
Use the low-density serial console major and the next free minor according to the Lanana. Since it would be awkward to say 'xencons=xvc187', use
name_baseto allow/dev/xvc0to be major/minor 204/187.
Please go through the process of sending mail to lanana and getting an officially assigned number. Once that's done and it's being used, this should be okay but not before.
Jeremy
Re: [PATCH] Virtual console driver on /dev/xvc0 (take two)
Quoted 9 lines · Jeremy Katz
Quoted 4 lines · Amos Waterland
Use the low-density serial console major and the next free minor according to the Lanana. Since it would be awkward to say 'xencons=xvc187', use
name_baseto allow/dev/xvc0to be major/minor 204/187.Please go through the process of sending mail to lanana and getting an officially assigned number. Once that's done and it's being used, this should be okay but not before.
I can send this to [email protected]. Keir, is this all right with you?
---
The Xen virtual console driver would like to request the following.
204 char Low-density serial ports
187 = /dev/xvc0 Xen virtual console device
Re: [PATCH] Virtual console driver on /dev/xvc0 (take two)
Quoted 5 lines · Amos Waterland
Quoted 3 lines
Please go through the process of sending mail to lanana and getting an officially assigned number. Once that's done and it's being used, this should be okay but not before.
I can send this to [email protected]. Keir, is this all right with you?
Yes, please!
-- Keir
Re: [PATCH] Virtual console driver on /dev/xvc0 (take two)
In reply to Amos WaterlandQuoted 9 lines · Amos Waterland
diff -r
17aa29a18b08drivers/xen/console/console.cdrivers/xen/console/console.c +1
-0@@ -63,13 +63,20 @@* 'xencons=off' [XC_OFF]: Console is disabled. * 'xencons=tty' [XC_TTY]: Console attached to '/dev/tty[0-9] +'. * 'xencons=ttyS' [XC_SERIAL]: Console attached to '/dev/ttyS
Quoted 5 lines
[0-9]+'.
+ * 'xencons=xvc' [XC_XVC]: Console attached to '/dev/xvc[0-9]
+'.
* [XC_DEFAULT]: DOM0 ->XC_SERIAL; all others ->XC_TTY.
Can't we switch the DomU's to XVC as well?
-JX
Re: [PATCH] Virtual console driver on /dev/xvc0 (take two)
Quoted 16 lines · Jimi Xenidis
Quoted 8 lines · Amos Waterland
diff -r
17aa29a18b08drivers/xen/console/console.cdrivers/xen/console/console.c +1
-0@@ -63,13 +63,20 @@* 'xencons=off' [XC_OFF]: Console is disabled. * 'xencons=tty' [XC_TTY]: Console attached to '/dev/tty[0-9] +'. * 'xencons=ttyS' [XC_SERIAL]: Console attached to '/dev/ttyS Quoted 5 lines
[0-9]+'.
+ * 'xencons=xvc' [XC_XVC]: Console attached to '/dev/xvc[0-9]
+'.
* [XC_DEFAULT]: DOM0 ->XC_SERIAL; all others ->XC_TTY.Can't we switch the DomU's to XVC as well?
I would expect that's what we want to do. At which point, the current xenconsole should behave like a serial console (stop taking over /dev/tty*, etc) and we can hopefully have the xenfb stuff to provide a more full-featured console for domUs
Jeremy
Re: [PATCH] Virtual console driver on /dev/xvc0 (take two)
In reply to Jimi XenidisQuoted 8 lines · Jimi Xenidis
Quoted 8 lines
diff -r
17aa29a18b08drivers/xen/console/console.cdrivers/xen/console/console.c Fri Aug 04 13:04:06 2006 -0400 renamed from drivers/xen/console/console.c Thu Jul 27 18:57:20 2006 -0400 +1
-0@@ -63,13 +63,20 @@ * 'xencons=off' [XC_OFF]: Console is disabled. * 'xencons=tty' [XC_TTY]: Console attached to '/dev/tty[0-9] +'. * 'xencons=ttyS' [XC_SERIAL]: Console attached to '/dev/ttyS
Quoted 8 lines
Quoted 5 lines
[0-9]+'.
+ * 'xencons=xvc' [XC_XVC]: Console attached to '/dev/xvc[0-9]
+'.
* [XC_DEFAULT]: DOM0 ->XC_SERIAL; all others ->XC_TTY.Can't we switch the DomU's to XVC as well?
Once the patch is applied and tested out, making xvc the default (or maybe the only choice) probably does make sense.
-- Keir
Re: [PATCH] Virtual console driver on /dev/xvc0 (take two)
In reply to Amos WaterlandQuoted 10 lines · Amos Waterland
Use the low-density serial console major and the next free minor according to the Lanana. Since it would be awkward to say 'xencons=xvc187', use
name_baseto allow/dev/xvc0to be major/minor 204/187.To use, put
xencons=xvc0' in your Linux .config, and runmknod/dev/xvc0c 204 187' in your rootfs. Built and booted up to nfsroot on a JS21 ppc64 blade both on bare hardware and as a dom0.Signed-off-by Amos Waterland <[email protected]>
It'd be polite to email Lanana and request the minor to be allocated for us. Could you do that, please? Apart from that the patch looks fine to me, but I think we should wait for the major/minor to be allocated before we apply it.
-- Keir
Re: [PATCH] Virtual console driver on /dev/xvc0
In reply to Amos WaterlandQuoted 6 lines · Amos Waterland
The below is the least invasive approach I can find, and works well on my PPC64 blades: I can boot the exact same kernel on bare hardware and as a dom0. I am sure there will be distro concerns (such as
/etc/inittaband/etc/securetty), but I'd like to get the ball rolling with this initial submission.
Most modern distros are getty'ing /dev/console, and your logic wires that up correctly. So for recent kernels I do not see why we would want to maintain the older ones.
Kier, perhaps we can make this:
- CONFIG_XEN_XVC=y to make it the default
- CONFIG_XEN_XVC_ONLY=y and depricate the ttySn and ttyn
And any distro that is broken by XVC can keep the backward compat. -JX