virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen: Enable Xen console by default in domU
@ 2008-04-04 14:59 Markus Armbruster
  0 siblings, 0 replies; 4+ messages in thread
From: Markus Armbruster @ 2008-04-04 14:59 UTC (permalink / raw)
  To: linux-kernel; +Cc: mingo, virtualization

Without console= arguments on the kernel command line, the first
console to register becomes enabled and the preferred console (the one
behind /dev/console).  This is tty (assuming CONFIG_VT_CONSOLE is
enabled, which it commonly is).

This is okay as long tty is a useful console.  But unless we have the
PV framebuffer, and it is enabled for this domain, tty0 in domU is
merely a dummy.  In that case, we want the preferred console to be the
Xen console hvc0, and we want it without having to fiddle with the
kernel command line.

Even with PV framebuffer enabled, we still want to enable the Xen
console as well.

Problem: when tty registers, we can't yet know whether the PVFB is
enabled.  By the time we can know (xenstore is up), the console setup
game is over.

Enable the Xen console hvc by default, and make it the preferred
console.  Change the preferred to tty when PVFB probes successfully.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
This patch supersedes the "xen: Make hvc0 the preferred console in
domU" patch.  It does not depend on the PVFB patch; it works with and
without it.

Aside: xenfb_make_preferred_console() may not be the best way to solve
the problem.  I simply followed the precedence in
arch/parisc/kernel/pdc_cons.c's pdc_console_restart().  Maybe a
function console_force_prefer() in printk.c to move make a console the
preferred console would make more sense.

 arch/x86/xen/enlighten.c    |    6 ++++++
 drivers/video/xen-fbfront.c |   22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index de4e6f0..4a5106e 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -25,6 +25,7 @@
 #include <linux/mm.h>
 #include <linux/page-flags.h>
 #include <linux/highmem.h>
+#include <linux/console.h>
 
 #include <xen/interface/xen.h>
 #include <xen/interface/physdev.h>
@@ -1215,6 +1216,11 @@ asmlinkage void __init xen_start_kernel(void)
 		? __pa(xen_start_info->mod_start) : 0;
 	boot_params.hdr.ramdisk_size = xen_start_info->mod_len;
 
+	if (!is_initial_xendomain()) {
+		add_preferred_console("tty", 0, NULL);
+		add_preferred_console("hvc", 0, NULL);
+	}
+
 	/* Start the world */
 	start_kernel();
 }
diff --git a/drivers/video/xen-fbfront.c b/drivers/video/xen-fbfront.c
index 619a6f8..9b428b5 100644
--- a/drivers/video/xen-fbfront.c
+++ b/drivers/video/xen-fbfront.c
@@ -18,6 +18,7 @@
  * frame buffer.
  */
 
+#include <linux/console.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/fb.h>
@@ -48,6 +49,7 @@ struct xenfb_info {
 
 static u32 xenfb_mem_len = XENFB_WIDTH * XENFB_HEIGHT * XENFB_DEPTH / 8;
 
+static void xenfb_make_preferred_console(void);
 static int xenfb_remove(struct xenbus_device *);
 static void xenfb_init_shared_page(struct xenfb_info *);
 static int xenfb_connect_backend(struct xenbus_device *, struct xenfb_info *);
@@ -348,6 +350,7 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
 	if (ret < 0)
 		goto error;
 
+	xenfb_make_preferred_console();
 	return 0;
 
  error_nomem:
@@ -358,6 +361,25 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
 	return ret;
 }
 
+static __devinit void
+xenfb_make_preferred_console(void)
+{
+	struct console *c;
+
+	acquire_console_sem();
+	for (c = console_drivers; c; c = c->next) {
+		if (!strcmp(c->name, "tty") && c->index == 0)
+			break;
+	}
+	release_console_sem();
+	if (c) {
+		unregister_console(c);
+		c->flags |= CON_CONSDEV;
+		c->flags &= ~CON_PRINTBUFFER; /* don't print again */
+		register_console(c);
+	}
+}
+
 static int xenfb_resume(struct xenbus_device *dev)
 {
 	struct xenfb_info *info = dev->dev.driver_data;
-- 
1.5.3.3

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

* [PATCH] xen: Enable Xen console by default in domU
       [not found] <87hcehshyc.fsf@pike.pond.sub.org>
@ 2008-04-10 15:46 ` Markus Armbruster
  2008-04-11  8:52   ` Mark McLoughlin
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Armbruster @ 2008-04-10 15:46 UTC (permalink / raw)
  To: linux-kernel
  Cc: Jeremy Fitzhardinge, xen-devel, linux-fbdev-devel, virtualization,
	mingo, adaplas

Without console= arguments on the kernel command line, the first
console to register becomes enabled and the preferred console (the one
behind /dev/console).  This is tty (assuming CONFIG_VT_CONSOLE is
enabled, which it commonly is).

This is okay as long tty is a useful console.  But unless we have the
PV framebuffer, and it is enabled for this domain, tty0 in domU is
merely a dummy.  In that case, we want the preferred console to be the
Xen console hvc0, and we want it without having to fiddle with the
kernel command line.

Even with PV framebuffer enabled, we still want to enable the Xen
console as well.

Problem: when tty registers, we can't yet know whether the PVFB is
enabled.  By the time we can know (xenstore is up), the console setup
game is over.

Enable the Xen console hvc by default, and make it the preferred
console.  Change the preferred console to tty when PVFB probes
successfully, unless we've been given console kernel parameters.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
The previous version of this patch had the PVFB change the preferred
console *always*.  That's wrong, because it blithely overwrites any
preferred console the user might have set up with console kernel
parameters.  Unfortunately, I couldn't see how to fix that cleanly
without messing with printk.c.  If you can think of a better way, let
me know.

 arch/x86/xen/enlighten.c    |    6 ++++++
 drivers/video/xen-fbfront.c |   25 +++++++++++++++++++++++++
 include/linux/console.h     |    2 ++
 kernel/printk.c             |    2 ++
 4 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index 27ee26a..87d235c 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -25,6 +25,7 @@
 #include <linux/mm.h>
 #include <linux/page-flags.h>
 #include <linux/highmem.h>
+#include <linux/console.h>
 
 #include <xen/interface/xen.h>
 #include <xen/interface/physdev.h>
@@ -1228,6 +1229,11 @@ asmlinkage void __init xen_start_kernel(void)
 		? __pa(xen_start_info->mod_start) : 0;
 	boot_params.hdr.ramdisk_size = xen_start_info->mod_len;
 
+	if (!is_initial_xendomain()) {
+		add_preferred_console("tty", 0, NULL);
+		add_preferred_console("hvc", 0, NULL);
+	}
+
 	/* Start the world */
 	start_kernel();
 }
diff --git a/drivers/video/xen-fbfront.c b/drivers/video/xen-fbfront.c
index 619a6f8..4e10876 100644
--- a/drivers/video/xen-fbfront.c
+++ b/drivers/video/xen-fbfront.c
@@ -18,6 +18,7 @@
  * frame buffer.
  */
 
+#include <linux/console.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/fb.h>
@@ -48,6 +49,7 @@ struct xenfb_info {
 
 static u32 xenfb_mem_len = XENFB_WIDTH * XENFB_HEIGHT * XENFB_DEPTH / 8;
 
+static void xenfb_make_preferred_console(void);
 static int xenfb_remove(struct xenbus_device *);
 static void xenfb_init_shared_page(struct xenfb_info *);
 static int xenfb_connect_backend(struct xenbus_device *, struct xenfb_info *);
@@ -348,6 +350,7 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
 	if (ret < 0)
 		goto error;
 
+	xenfb_make_preferred_console();
 	return 0;
 
  error_nomem:
@@ -358,6 +361,28 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
 	return ret;
 }
 
+static __devinit void
+xenfb_make_preferred_console(void)
+{
+	struct console *c;
+
+	if (console_set_on_cmdline)
+		return;
+
+	acquire_console_sem();
+	for (c = console_drivers; c; c = c->next) {
+		if (!strcmp(c->name, "tty") && c->index == 0)
+			break;
+	}
+	release_console_sem();
+	if (c) {
+		unregister_console(c);
+		c->flags |= CON_CONSDEV;
+		c->flags &= ~CON_PRINTBUFFER; /* don't print again */
+		register_console(c);
+	}
+}
+
 static int xenfb_resume(struct xenbus_device *dev)
 {
 	struct xenfb_info *info = dev->dev.driver_data;
diff --git a/include/linux/console.h b/include/linux/console.h
index a5f88a6..7f51fa8 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -107,6 +107,8 @@ struct console {
 	struct	 console *next;
 };
 
+extern int console_set_on_cmdline;
+
 extern int add_preferred_console(char *name, int idx, char *options);
 extern int update_console_cmdline(char *name, int idx, char *name_new, int idx_new, char *options);
 extern void register_console(struct console *);
diff --git a/kernel/printk.c b/kernel/printk.c
index c46a20a..c07bfc1 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -118,6 +118,7 @@ struct console_cmdline
 static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
 static int selected_console = -1;
 static int preferred_console = -1;
+int console_set_on_cmdline;
 
 /* Flag: console code may call schedule() */
 static int console_may_schedule;
@@ -829,6 +830,7 @@ static int __init console_setup(char *str)
 	*s = 0;
 
 	add_preferred_console(buf, idx, options);
+	console_set_on_cmdline = 1;
 	return 1;
 }
 __setup("console=", console_setup);
-- 
1.5.3.3

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

* Re: [PATCH] xen: Enable Xen console by default in domU
  2008-04-10 15:46 ` [PATCH] xen: Enable Xen console by default in domU Markus Armbruster
@ 2008-04-11  8:52   ` Mark McLoughlin
  2008-04-11  8:59     ` Mark McLoughlin
  0 siblings, 1 reply; 4+ messages in thread
From: Mark McLoughlin @ 2008-04-11  8:52 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: linux-kernel, virtualization, xen-devel, linux-fbdev-devel,
	adaplas, Jeremy Fitzhardinge, mingo

On Thu, 2008-04-10 at 17:46 +0200, Markus Armbruster wrote:
...
> Problem: when tty registers, we can't yet know whether the PVFB is
> enabled.  By the time we can know (xenstore is up), the console setup
> game is over.
> 
> Enable the Xen console hvc by default, and make it the preferred
> console.  Change the preferred console to tty when PVFB probes
> successfully, unless we've been given console kernel parameters.
...
> The previous version of this patch had the PVFB change the preferred
> console *always*.  That's wrong, because it blithely overwrites any
> preferred console the user might have set up with console kernel
> parameters.  Unfortunately, I couldn't see how to fix that cleanly
> without messing with printk.c.  If you can think of a better way, let
> me know.
...
> --- a/drivers/video/xen-fbfront.c
> +++ b/drivers/video/xen-fbfront.c

> @@ -358,6 +361,28 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
>  	return ret;
>  }
>  
> +static __devinit void
> +xenfb_make_preferred_console(void)
> +{
> +	struct console *c;
> +
> +	if (console_set_on_cmdline)
> +		return;
> +
> +	acquire_console_sem();
> +	for (c = console_drivers; c; c = c->next) {
> +		if (!strcmp(c->name, "tty") && c->index == 0)
> +			break;
> +	}

How about adding a new console flag so that e.g. you could do:

        if (!strcmp(c->name, "tty") && c->index == 0 &&
            !(c->flags & CON_SET_ON_CMDLINE))
                break;

> +	release_console_sem();
> +	if (c) {
> +		unregister_console(c);
> +		c->flags |= CON_CONSDEV;
> +		c->flags &= ~CON_PRINTBUFFER; /* don't print again */
> +		register_console(c);
> +	}
> +}
> +
...
> --- a/include/linux/console.h
> +++ b/include/linux/console.h
> @@ -107,6 +107,8 @@ struct console {
>  	struct	 console *next;
>  };
>  
> +extern int console_set_on_cmdline;
> +
>  extern int add_preferred_console(char *name, int idx, char *options);
>  extern int update_console_cmdline(char *name, int idx, char *name_new, int idx_new, char *options);
>  extern void register_console(struct console *);
> diff --git a/kernel/printk.c b/kernel/printk.c
> index c46a20a..c07bfc1 100644
> --- a/kernel/printk.c
> +++ b/kernel/printk.c
> @@ -118,6 +118,7 @@ struct console_cmdline
>  static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
>  static int selected_console = -1;
>  static int preferred_console = -1;
> +int console_set_on_cmdline;
>  
>  /* Flag: console code may call schedule() */
>  static int console_may_schedule;
> @@ -829,6 +830,7 @@ static int __init console_setup(char *str)
>  	*s = 0;
>  
>  	add_preferred_console(buf, idx, options);
> +	console_set_on_cmdline = 1;
>  	return 1;
>  }
>  __setup("console=", console_setup);

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

* Re: [PATCH] xen: Enable Xen console by default in domU
  2008-04-11  8:52   ` Mark McLoughlin
@ 2008-04-11  8:59     ` Mark McLoughlin
  0 siblings, 0 replies; 4+ messages in thread
From: Mark McLoughlin @ 2008-04-11  8:59 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Jeremy Fitzhardinge, xen-devel, linux-fbdev-devel, linux-kernel,
	virtualization, mingo, adaplas

On Fri, 2008-04-11 at 09:52 +0100, Mark McLoughlin wrote:
> On Thu, 2008-04-10 at 17:46 +0200, Markus Armbruster wrote:
> > diff --git a/kernel/printk.c b/kernel/printk.c
> > index c46a20a..c07bfc1 100644
> > --- a/kernel/printk.c
> > +++ b/kernel/printk.c
> > @@ -118,6 +118,7 @@ struct console_cmdline
> >  static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
> >  static int selected_console = -1;
> >  static int preferred_console = -1;
> > +int console_set_on_cmdline;

You'd also need to export this symbol for the unusual case where fbfront
is a module ...

Cheers,
Mark.

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

end of thread, other threads:[~2008-04-11  8:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <87hcehshyc.fsf@pike.pond.sub.org>
2008-04-10 15:46 ` [PATCH] xen: Enable Xen console by default in domU Markus Armbruster
2008-04-11  8:52   ` Mark McLoughlin
2008-04-11  8:59     ` Mark McLoughlin
2008-04-04 14:59 Markus Armbruster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).