virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v2] virtio_console: Introduce an ID allocator for virtual console numbers
       [not found] <20221114173811.1977367-1-clg@kaod.org>
@ 2022-11-22 11:12 ` Thomas Huth
  2022-11-22 17:03 ` Amit Shah
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Huth @ 2022-11-22 11:12 UTC (permalink / raw)
  To: Cédric Le Goater, Amit Shah
  Cc: Greg Kroah-Hartman, Michael S. Tsirkin, linux-kernel,
	Arnd Bergmann, virtualization

On 14/11/2022 18.38, Cédric Le Goater wrote:
> When a virtio console port is initialized, it is registered as an hvc
> console using a virtual console number. If a KVM guest is started with
> multiple virtio console devices, the same vtermno (or virtual console
> number) can be used to allocate different hvc consoles, which leads to
> various communication problems later on.
> 
> This is also reported in debugfs :
> 
>    # grep vtermno /sys/kernel/debug/virtio-ports/*
>    /sys/kernel/debug/virtio-ports/vport1p1:console_vtermno: 1
>    /sys/kernel/debug/virtio-ports/vport2p1:console_vtermno: 1
>    /sys/kernel/debug/virtio-ports/vport3p1:console_vtermno: 2
>    /sys/kernel/debug/virtio-ports/vport4p1:console_vtermno: 3
> 
> Replace the next_vtermno global with an ID allocator and start the
> allocation at 1 as it is today. Also recycle IDs when a console port
> is removed.

Sounds like a good idea!

> @@ -1244,8 +1236,11 @@ static int init_port_console(struct port *port)
>   	 * pointers.  The final argument is the output buffer size: we
>   	 * can do any size, so we put PAGE_SIZE here.
>   	 */
> -	port->cons.vtermno = pdrvdata.next_vtermno;
> +	ret = ida_alloc_range(&vtermno_ida, 1, ~0, GFP_KERNEL);

Just cosmetics: I think you could use ida_alloc_min() instead.

> +	if (ret < 0)
> +		return ret;
>   
> +	port->cons.vtermno = ret;
>   	port->cons.hvc = hvc_alloc(port->cons.vtermno, 0, &hv_ops, PAGE_SIZE);
>   	if (IS_ERR(port->cons.hvc)) {
>   		ret = PTR_ERR(port->cons.hvc);

What if this if (IS_ERR()) error happens? The code seems to return early in 
this case - shouldn't the ID be freed again in this case?

  Thomas

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH v2] virtio_console: Introduce an ID allocator for virtual console numbers
       [not found] <20221114173811.1977367-1-clg@kaod.org>
  2022-11-22 11:12 ` [PATCH v2] virtio_console: Introduce an ID allocator for virtual console numbers Thomas Huth
@ 2022-11-22 17:03 ` Amit Shah
       [not found]   ` <62cfdcff-9323-5007-67e2-54178e43b21e@kaod.org>
  1 sibling, 1 reply; 3+ messages in thread
From: Amit Shah @ 2022-11-22 17:03 UTC (permalink / raw)
  To: Cédric Le Goater, Amit Shah
  Cc: Greg Kroah-Hartman, linux-kernel, Arnd Bergmann, virtualization

On Mon, 2022-11-14 at 18:38 +0100, Cédric Le Goater wrote:
> When a virtio console port is initialized, it is registered as an hvc
> console using a virtual console number. If a KVM guest is started with
> multiple virtio console devices, the same vtermno (or virtual console
> number) can be used to allocate different hvc consoles, which leads to
> various communication problems later on.
> 
> This is also reported in debugfs :
> 
>   # grep vtermno /sys/kernel/debug/virtio-ports/*
>   /sys/kernel/debug/virtio-ports/vport1p1:console_vtermno: 1
>   /sys/kernel/debug/virtio-ports/vport2p1:console_vtermno: 1
>   /sys/kernel/debug/virtio-ports/vport3p1:console_vtermno: 2
>   /sys/kernel/debug/virtio-ports/vport4p1:console_vtermno: 3
> 
> Replace the next_vtermno global with an ID allocator and start the
> allocation at 1 as it is today. Also recycle IDs when a console port
> is removed.

When the original virtio_console module was written, it didn't have
support for multiple ports to be used this way.  So the oddity you're
seeing is left there deliberately: VMMs should not be instantiating
console ports this way.

I don't know if we should take in this change, but can you walk through
all combinations of new/old guest and new/old hypervisor and ensure
nothing's going to break -- and confirm with the spec this is still OK
to do?  It may not be a goal to still ensure launches of a new guest on
a very old (say) Centos5 guest still works -- but that was the point of
maintaining backward compat...


		Amit
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH v2] virtio_console: Introduce an ID allocator for virtual console numbers
       [not found]   ` <62cfdcff-9323-5007-67e2-54178e43b21e@kaod.org>
@ 2022-11-23 10:36     ` Amit Shah
  0 siblings, 0 replies; 3+ messages in thread
From: Amit Shah @ 2022-11-23 10:36 UTC (permalink / raw)
  To: Cédric Le Goater, Amit Shah
  Cc: Thomas Huth, Arnd Bergmann, Michael S. Tsirkin,
	Greg Kroah-Hartman, linux-kernel, virtualization

On Wed, 2022-11-23 at 11:17 +0100, Cédric Le Goater wrote:
> Hello Amit,
> 
> On 11/22/22 18:03, Amit Shah wrote:
> > On Mon, 2022-11-14 at 18:38 +0100, Cédric Le Goater wrote:
> > > When a virtio console port is initialized, it is registered as an hvc
> > > console using a virtual console number. If a KVM guest is started with
> > > multiple virtio console devices, the same vtermno (or virtual console
> > > number) can be used to allocate different hvc consoles, which leads to
> > > various communication problems later on.
> > > 
> > > This is also reported in debugfs :
> > > 
> > >    # grep vtermno /sys/kernel/debug/virtio-ports/*
> > >    /sys/kernel/debug/virtio-ports/vport1p1:console_vtermno: 1
> > >    /sys/kernel/debug/virtio-ports/vport2p1:console_vtermno: 1
> > >    /sys/kernel/debug/virtio-ports/vport3p1:console_vtermno: 2
> > >    /sys/kernel/debug/virtio-ports/vport4p1:console_vtermno: 3
> > > 
> > > Replace the next_vtermno global with an ID allocator and start the
> > > allocation at 1 as it is today. Also recycle IDs when a console port
> > > is removed.
> > 
> > When the original virtio_console module was written, it didn't have
> > support for multiple ports to be used this way.  So the oddity you're
> > seeing is left there deliberately: VMMs should not be instantiating
> > console ports this way.
> > 
> > I don't know if we should take in this change, but can you walk through
> > all combinations of new/old guest and new/old hypervisor and ensure
> > nothing's going to break -- and confirm with the spec this is still OK
> > to do?  It may not be a goal to still ensure launches of a new guest on
> > a very old (say) Centos5 guest still works -- but that was the point of
> > maintaining backward compat...
> 
> 'next_vtermno' was introduced by d8a02bd58ab6 ("virtio: console:
> remove global var") to differentiate the underlying kernel hvc console
> associated with each virtio console port. Some drivers, like XEN,
> simply use a magic/cookie number for instance.
> 
> This number is not related to the virtio specs. It is not exposed to
> QEMU nor the guest (a part from debugfs). It's an internal identifier
> related to the implementation in the kernel. I don't understand how
> this could break compatibility. The change even keeps the allocated
> range the same in case some assumption is made on vtermno 0. Am I
> missing something ?

No, you're right about this being kernel-internal -- just that it's
used with hvc instead of qemu like I mentioned.

I think this is the right change; just want to confirm hvc didn't get
confused.

> 
> In the virtio console driver case, we could also generate a unique
> number from the tuple { virtio device index, virtio console port }.
> The ID allocator approach is simpler.

I think the bug is that we don't increment the vtermno today in all
places that we should; but this patch solves it too - I don't mind
adding the extra ida bits.
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

end of thread, other threads:[~2022-11-23 10:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20221114173811.1977367-1-clg@kaod.org>
2022-11-22 11:12 ` [PATCH v2] virtio_console: Introduce an ID allocator for virtual console numbers Thomas Huth
2022-11-22 17:03 ` Amit Shah
     [not found]   ` <62cfdcff-9323-5007-67e2-54178e43b21e@kaod.org>
2022-11-23 10:36     ` Amit Shah

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).