* [PATCH] virtio-console: skip NUL terminator in port name
@ 2026-11-30 13:07 Manos Pitsidianakis
2026-11-30 13:31 ` Tommaso Califano
2026-11-30 17:24 ` Philippe Mathieu-Daudé
0 siblings, 2 replies; 9+ messages in thread
From: Manos Pitsidianakis @ 2026-11-30 13:07 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Laurent Vivier, Amit Shah, Michael S. Tsirkin,
Manos Pitsidianakis
VIRTIO spec says:
VIRTIO_CONSOLE_PORT_NAME (7)
Sent by the device to give a tag to the port. This control command is immediately followed by the UTF-8 name of the port for identification within the guest (without a NUL terminator).
- Section 5.3.6.2 Multiport Device Operation
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
---
hw/char/virtio-serial-bus.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 7fe90571249f1cbdb9a9d095f041d4e048ea506e..cfc48fc1d4ab625b60a59ed840f2f0eb0bd47629 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -473,12 +473,11 @@ static void handle_control_message(VirtIOSerial *vser,
virtio_stw_p(vdev, &cpkt.event, VIRTIO_CONSOLE_PORT_NAME);
virtio_stw_p(vdev, &cpkt.value, 1);
- buffer_len = sizeof(cpkt) + strlen(port->name) + 1;
+ buffer_len = sizeof(cpkt) + strlen(port->name);
buffer = g_malloc(buffer_len);
memcpy(buffer, &cpkt, sizeof(cpkt));
memcpy(buffer + sizeof(cpkt), port->name, strlen(port->name));
- buffer[buffer_len - 1] = 0;
send_control_msg(vser, buffer, buffer_len);
g_free(buffer);
---
base-commit: 9cda597a1a3903d090e8e55e23f5b8a859da88ab
change-id: 20261130-fix-virtio-console-port-name-32be73542009
Best regards,
--
Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH] virtio-console: skip NUL terminator in port name
2026-11-30 13:07 [PATCH] virtio-console: skip NUL terminator in port name Manos Pitsidianakis
@ 2026-11-30 13:31 ` Tommaso Califano
2026-11-30 13:40 ` Manos Pitsidianakis
2026-11-30 17:24 ` Philippe Mathieu-Daudé
1 sibling, 1 reply; 9+ messages in thread
From: Tommaso Califano @ 2026-11-30 13:31 UTC (permalink / raw)
To: Manos Pitsidianakis, qemu-devel
Cc: qemu-stable, Laurent Vivier, Amit Shah, Michael S. Tsirkin,
qemu-devel-bounces+tcalifano=redhat.com
Hi,
The subject is not compliant with QEMU commit style: it should be
'hw/char/virtio-serial-bus' instead of 'virtio-console'.
> VIRTIO spec says:
>
> VIRTIO_CONSOLE_PORT_NAME (7)
>
> Sent by the device to give a tag to the port. This control command is immediately followed by the UTF-8 name of the port for identification within the guest (without a NUL terminator).
Please wrap the paragraph, lines should not be longer than 76
characters.
>
> - Section 5.3.6.2 Multiport Device Operation
>
Fixes Tag?
> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> ---
> hw/char/virtio-serial-bus.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
> index 7fe90571249f1cbdb9a9d095f041d4e048ea506e..cfc48fc1d4ab625b60a59ed840f2f0eb0bd47629 100644
> --- a/hw/char/virtio-serial-bus.c
> +++ b/hw/char/virtio-serial-bus.c
> @@ -473,12 +473,11 @@ static void handle_control_message(VirtIOSerial *vser,
> virtio_stw_p(vdev, &cpkt.event, VIRTIO_CONSOLE_PORT_NAME);
> virtio_stw_p(vdev, &cpkt.value, 1);
>
> - buffer_len = sizeof(cpkt) + strlen(port->name) + 1;
> + buffer_len = sizeof(cpkt) + strlen(port->name);
> buffer = g_malloc(buffer_len);
>
> memcpy(buffer, &cpkt, sizeof(cpkt));
> memcpy(buffer + sizeof(cpkt), port->name, strlen(port->name));
> - buffer[buffer_len - 1] = 0;
>
> send_control_msg(vser, buffer, buffer_len);
> g_free(buffer);
>
> ---
> base-commit: 9cda597a1a3903d090e8e55e23f5b8a859da88ab
> change-id: 20261130-fix-virtio-console-port-name-32be73542009
>
> Best regards,
Best regards,
Tommaso
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] virtio-console: skip NUL terminator in port name
2026-11-30 13:31 ` Tommaso Califano
@ 2026-11-30 13:40 ` Manos Pitsidianakis
2026-11-30 13:45 ` Peter Maydell
0 siblings, 1 reply; 9+ messages in thread
From: Manos Pitsidianakis @ 2026-11-30 13:40 UTC (permalink / raw)
To: Tommaso Califano
Cc: qemu-devel, qemu-stable, Laurent Vivier, Amit Shah,
Michael S. Tsirkin, qemu-devel-bounces+tcalifano=redhat.com
On Mon, Nov 30, 2026 at 3:31 PM Tommaso Califano <tcalifano@redhat.com> wrote:
>
> Hi,
>
> The subject is not compliant with QEMU commit style: it should be
> 'hw/char/virtio-serial-bus' instead of 'virtio-console'.
There is no such rule.
The documentation recommends "subsystem: single line summary of
change" and when using `hw/char/virtio-serial-bus` etc you **cannot
fit anything meaningful in the title** so I trimmed it to
virtio-console.
>
> > VIRTIO spec says:
> >
> > VIRTIO_CONSOLE_PORT_NAME (7)
> >
> > Sent by the device to give a tag to the port. This control command is immediately followed by the UTF-8 name of the port for identification within the guest (without a NUL terminator).
>
> Please wrap the paragraph, lines should not be longer than 76
> characters.
checkpatch did not complain, so I see no reason to send a v2 just for
this. Thanks though!
>
> >
> > - Section 5.3.6.2 Multiport Device Operation
> >
>
> Fixes Tag?
This code is so old (over 10 years) I think there is no point.
>
> > Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> > ---
> > hw/char/virtio-serial-bus.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
> > index 7fe90571249f1cbdb9a9d095f041d4e048ea506e..cfc48fc1d4ab625b60a59ed840f2f0eb0bd47629 100644
> > --- a/hw/char/virtio-serial-bus.c
> > +++ b/hw/char/virtio-serial-bus.c
> > @@ -473,12 +473,11 @@ static void handle_control_message(VirtIOSerial *vser,
> > virtio_stw_p(vdev, &cpkt.event, VIRTIO_CONSOLE_PORT_NAME);
> > virtio_stw_p(vdev, &cpkt.value, 1);
> >
> > - buffer_len = sizeof(cpkt) + strlen(port->name) + 1;
> > + buffer_len = sizeof(cpkt) + strlen(port->name);
> > buffer = g_malloc(buffer_len);
> >
> > memcpy(buffer, &cpkt, sizeof(cpkt));
> > memcpy(buffer + sizeof(cpkt), port->name, strlen(port->name));
> > - buffer[buffer_len - 1] = 0;
> >
> > send_control_msg(vser, buffer, buffer_len);
> > g_free(buffer);
> >
> > ---
> > base-commit: 9cda597a1a3903d090e8e55e23f5b8a859da88ab
> > change-id: 20261130-fix-virtio-console-port-name-32be73542009
> >
> > Best regards,
>
> Best regards,
> Tommaso
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] virtio-console: skip NUL terminator in port name
2026-11-30 13:40 ` Manos Pitsidianakis
@ 2026-11-30 13:45 ` Peter Maydell
2026-11-30 18:07 ` Michael S. Tsirkin
0 siblings, 1 reply; 9+ messages in thread
From: Peter Maydell @ 2026-11-30 13:45 UTC (permalink / raw)
To: Manos Pitsidianakis
Cc: Tommaso Califano, qemu-devel, qemu-stable, Laurent Vivier,
Amit Shah, Michael S. Tsirkin,
qemu-devel-bounces+tcalifano=redhat.com
On Mon, 30 Nov 2026 at 13:41, Manos Pitsidianakis
<manos.pitsidianakis@linaro.org> wrote:
>
> On Mon, Nov 30, 2026 at 3:31 PM Tommaso Califano <tcalifano@redhat.com> wrote:
> > > VIRTIO spec says:
> > >
> > > VIRTIO_CONSOLE_PORT_NAME (7)
> > >
> > > Sent by the device to give a tag to the port. This control command is immediately followed by the UTF-8 name of the port for identification within the guest (without a NUL terminator).
> >
> > Please wrap the paragraph, lines should not be longer than 76
> > characters.
>
> checkpatch did not complain, so I see no reason to send a v2 just for
> this. Thanks though!
Checkpatch doesn't complain about lots of things that are standard
QEMU style requirements. Commit messages definitely should be wrapped
(except for special cases like "this is a URL" or "this is verbatim
output" where wrapping would mangle things).
It's the kind of thing that can be fixed up by the applier, of course.
thanks
-- PMM
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] virtio-console: skip NUL terminator in port name
2026-11-30 13:45 ` Peter Maydell
@ 2026-11-30 18:07 ` Michael S. Tsirkin
0 siblings, 0 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2026-11-30 18:07 UTC (permalink / raw)
To: Peter Maydell
Cc: Manos Pitsidianakis, Tommaso Califano, qemu-devel, qemu-stable,
Laurent Vivier, Amit Shah,
qemu-devel-bounces+tcalifano=redhat.com
On Mon, Nov 30, 2026 at 01:45:19PM +0000, Peter Maydell wrote:
> On Mon, 30 Nov 2026 at 13:41, Manos Pitsidianakis
> <manos.pitsidianakis@linaro.org> wrote:
> >
> > On Mon, Nov 30, 2026 at 3:31 PM Tommaso Califano <tcalifano@redhat.com> wrote:
>
> > > > VIRTIO spec says:
> > > >
> > > > VIRTIO_CONSOLE_PORT_NAME (7)
> > > >
> > > > Sent by the device to give a tag to the port. This control command is immediately followed by the UTF-8 name of the port for identification within the guest (without a NUL terminator).
> > >
> > > Please wrap the paragraph, lines should not be longer than 76
> > > characters.
> >
> > checkpatch did not complain, so I see no reason to send a v2 just for
> > this. Thanks though!
>
> Checkpatch doesn't complain about lots of things that are standard
> QEMU style requirements. Commit messages definitely should be wrapped
> (except for special cases like "this is a URL" or "this is verbatim
> output" where wrapping would mangle things).
>
> It's the kind of thing that can be fixed up by the applier, of course.
>
> thanks
> -- PMM
Not me, I have too much stuff to do as it is.
--
MST
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] virtio-console: skip NUL terminator in port name
2026-11-30 13:07 [PATCH] virtio-console: skip NUL terminator in port name Manos Pitsidianakis
2026-11-30 13:31 ` Tommaso Califano
@ 2026-11-30 17:24 ` Philippe Mathieu-Daudé
2026-12-01 5:35 ` Manos Pitsidianakis
1 sibling, 1 reply; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-30 17:24 UTC (permalink / raw)
To: Manos Pitsidianakis, qemu-devel
Cc: qemu-stable, Laurent Vivier, Amit Shah, Michael S. Tsirkin
On 30/11/26 14:07, Manos Pitsidianakis wrote:
> VIRTIO spec says:
>
> VIRTIO_CONSOLE_PORT_NAME (7)
>
> Sent by the device to give a tag to the port. This control command is immediately followed by the UTF-8 name of the port for identification within the guest (without a NUL terminator).
>
> - Section 5.3.6.2 Multiport Device Operation
>
I adapted style as:
hw/virtio/virtio-console: skip NUL terminator in port name
VIRTIO spec says:
VIRTIO_CONSOLE_PORT_NAME (7)
Sent by the device to give a tag to the port. This control
command is immediately followed by the UTF-8 name of the
port for identification within the guest (without a NUL
terminator).
- Section 5.3.6.2 Multiport Device Operation
but then I wondered about guest drivers already running and
being migrated, would that confuse them? We could confirm
extending tests/qtest/virtio-serial-test.c coverage.
Fixes: 160600fd137a ("virtio-serial-bus: Add a port 'name' property for
port discovery in guests")
> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> ---
> hw/char/virtio-serial-bus.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
> index 7fe90571249f1cbdb9a9d095f041d4e048ea506e..cfc48fc1d4ab625b60a59ed840f2f0eb0bd47629 100644
> --- a/hw/char/virtio-serial-bus.c
> +++ b/hw/char/virtio-serial-bus.c
> @@ -473,12 +473,11 @@ static void handle_control_message(VirtIOSerial *vser,
Local var to have one single strlen call?
size_t name_len = strlen(port->name);
...
buffer_len = sizeof(cpkt) + name_len;
> virtio_stw_p(vdev, &cpkt.event, VIRTIO_CONSOLE_PORT_NAME);
> virtio_stw_p(vdev, &cpkt.value, 1);
>
> - buffer_len = sizeof(cpkt) + strlen(port->name) + 1;
> + buffer_len = sizeof(cpkt) + strlen(port->name);
> buffer = g_malloc(buffer_len);
>
> memcpy(buffer, &cpkt, sizeof(cpkt));
> memcpy(buffer + sizeof(cpkt), port->name, strlen(port->name));
> - buffer[buffer_len - 1] = 0;
We rather strpadcpy() which makes intent explicit:
strpadcpy(buffer + sizeof(cpkt), name_len, port->name, '\0');
>
> send_control_msg(vser, buffer, buffer_len);
> g_free(buffer);
>
> ---
> base-commit: 9cda597a1a3903d090e8e55e23f5b8a859da88ab
> change-id: 20261130-fix-virtio-console-port-name-32be73542009
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] virtio-console: skip NUL terminator in port name
2026-11-30 17:24 ` Philippe Mathieu-Daudé
@ 2026-12-01 5:35 ` Manos Pitsidianakis
2026-12-01 10:52 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 9+ messages in thread
From: Manos Pitsidianakis @ 2026-12-01 5:35 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, qemu-stable, Laurent Vivier, Amit Shah,
Michael S. Tsirkin
On Mon, Nov 30, 2026 at 7:24 PM Philippe Mathieu-Daudé
<philmd@oss.qualcomm.com> wrote:
>
> On 30/11/26 14:07, Manos Pitsidianakis wrote:
> > VIRTIO spec says:
> >
> > VIRTIO_CONSOLE_PORT_NAME (7)
> >
> > Sent by the device to give a tag to the port. This control command is immediately followed by the UTF-8 name of the port for identification within the guest (without a NUL terminator).
> >
> > - Section 5.3.6.2 Multiport Device Operation
> >
>
> I adapted style as:
>
> hw/virtio/virtio-console: skip NUL terminator in port name
>
> VIRTIO spec says:
>
> VIRTIO_CONSOLE_PORT_NAME (7)
>
> Sent by the device to give a tag to the port. This control
> command is immediately followed by the UTF-8 name of the
> port for identification within the guest (without a NUL
> terminator).
>
> - Section 5.3.6.2 Multiport Device Operation
>
> but then I wondered about guest drivers already running and
> being migrated, would that confuse them? We could confirm
> extending tests/qtest/virtio-serial-test.c coverage.
>
> Fixes: 160600fd137a ("virtio-serial-bus: Add a port 'name' property for
> port discovery in guests")
>
> > Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> > ---
> > hw/char/virtio-serial-bus.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
> > index 7fe90571249f1cbdb9a9d095f041d4e048ea506e..cfc48fc1d4ab625b60a59ed840f2f0eb0bd47629 100644
> > --- a/hw/char/virtio-serial-bus.c
> > +++ b/hw/char/virtio-serial-bus.c
> > @@ -473,12 +473,11 @@ static void handle_control_message(VirtIOSerial *vser,
>
> Local var to have one single strlen call?
>
> size_t name_len = strlen(port->name);
>
> ...
> buffer_len = sizeof(cpkt) + name_len;
>
> > virtio_stw_p(vdev, &cpkt.event, VIRTIO_CONSOLE_PORT_NAME);
> > virtio_stw_p(vdev, &cpkt.value, 1);
> >
> > - buffer_len = sizeof(cpkt) + strlen(port->name) + 1;
> > + buffer_len = sizeof(cpkt) + strlen(port->name);
> > buffer = g_malloc(buffer_len);
> >
> > memcpy(buffer, &cpkt, sizeof(cpkt));
> > memcpy(buffer + sizeof(cpkt), port->name, strlen(port->name));
> > - buffer[buffer_len - 1] = 0;
>
> We rather strpadcpy() which makes intent explicit:
>
> strpadcpy(buffer + sizeof(cpkt), name_len, port->name, '\0');
>
> >
> > send_control_msg(vser, buffer, buffer_len);
> > g_free(buffer);
> >
> > ---
> > base-commit: 9cda597a1a3903d090e8e55e23f5b8a859da88ab
> > change-id: 20261130-fix-virtio-console-port-name-32be73542009
>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Thanks Phil!
I purposefully kept the patch diff as small as possible because I just
wanted to fix the bug and avoid any bikeshedding on refactoring. It's
probably better to shape up the code in a different patch.
>
--
Manos Pitsidianakis
Emulation and Virtualization Engineer at Linaro Ltd
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] virtio-console: skip NUL terminator in port name
2026-12-01 5:35 ` Manos Pitsidianakis
@ 2026-12-01 10:52 ` Philippe Mathieu-Daudé
2026-12-01 11:02 ` Manos Pitsidianakis
0 siblings, 1 reply; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-12-01 10:52 UTC (permalink / raw)
To: Manos Pitsidianakis
Cc: qemu-devel, qemu-stable, Laurent Vivier, Amit Shah,
Michael S. Tsirkin
On 1/12/26 06:35, Manos Pitsidianakis wrote:
> On Mon, Nov 30, 2026 at 7:24 PM Philippe Mathieu-Daudé
> <philmd@oss.qualcomm.com> wrote:
>>
>> On 30/11/26 14:07, Manos Pitsidianakis wrote:
>>> VIRTIO spec says:
>>>
>>> VIRTIO_CONSOLE_PORT_NAME (7)
>>>
>>> Sent by the device to give a tag to the port. This control command is immediately followed by the UTF-8 name of the port for identification within the guest (without a NUL terminator).
>>>
>>> - Section 5.3.6.2 Multiport Device Operation
>>>
>>
>> I adapted style as:
>>
>> hw/virtio/virtio-console: skip NUL terminator in port name
>>
>> VIRTIO spec says:
>>
>> VIRTIO_CONSOLE_PORT_NAME (7)
>>
>> Sent by the device to give a tag to the port. This control
>> command is immediately followed by the UTF-8 name of the
>> port for identification within the guest (without a NUL
>> terminator).
>>
>> - Section 5.3.6.2 Multiport Device Operation
>>
>> but then I wondered about guest drivers already running and
>> being migrated, would that confuse them?
What about the migration question?
>> We could confirm
>> extending tests/qtest/virtio-serial-test.c coverage.
>>
>> Fixes: 160600fd137a ("virtio-serial-bus: Add a port 'name' property for
>> port discovery in guests")
>>
>>> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>>> ---
>>> hw/char/virtio-serial-bus.c | 3 +--
>>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>>
>>> diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
>>> index 7fe90571249f1cbdb9a9d095f041d4e048ea506e..cfc48fc1d4ab625b60a59ed840f2f0eb0bd47629 100644
>>> --- a/hw/char/virtio-serial-bus.c
>>> +++ b/hw/char/virtio-serial-bus.c
>>> @@ -473,12 +473,11 @@ static void handle_control_message(VirtIOSerial *vser,
>>
>> Local var to have one single strlen call?
>>
>> size_t name_len = strlen(port->name);
>>
>> ...
>> buffer_len = sizeof(cpkt) + name_len;
>>
>>> virtio_stw_p(vdev, &cpkt.event, VIRTIO_CONSOLE_PORT_NAME);
>>> virtio_stw_p(vdev, &cpkt.value, 1);
>>>
>>> - buffer_len = sizeof(cpkt) + strlen(port->name) + 1;
>>> + buffer_len = sizeof(cpkt) + strlen(port->name);
>>> buffer = g_malloc(buffer_len);
>>>
>>> memcpy(buffer, &cpkt, sizeof(cpkt));
>>> memcpy(buffer + sizeof(cpkt), port->name, strlen(port->name));
>>> - buffer[buffer_len - 1] = 0;
>>
>> We rather strpadcpy() which makes intent explicit:
>>
>> strpadcpy(buffer + sizeof(cpkt), name_len, port->name, '\0');
>>
>>>
>>> send_control_msg(vser, buffer, buffer_len);
>>> g_free(buffer);
>>>
>>> ---
>>> base-commit: 9cda597a1a3903d090e8e55e23f5b8a859da88ab
>>> change-id: 20261130-fix-virtio-console-port-name-32be73542009
>>
>> Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
>
> Thanks Phil!
>
> I purposefully kept the patch diff as small as possible because I just
> wanted to fix the bug and avoid any bikeshedding on refactoring. It's
> probably better to shape up the code in a different patch.
OK.
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] virtio-console: skip NUL terminator in port name
2026-12-01 10:52 ` Philippe Mathieu-Daudé
@ 2026-12-01 11:02 ` Manos Pitsidianakis
0 siblings, 0 replies; 9+ messages in thread
From: Manos Pitsidianakis @ 2026-12-01 11:02 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, qemu-stable, Laurent Vivier, Amit Shah,
Michael S. Tsirkin
On Tue, Dec 1, 2026 at 12:52 PM Philippe Mathieu-Daudé
<philmd@oss.qualcomm.com> wrote:
>
> On 1/12/26 06:35, Manos Pitsidianakis wrote:
> > On Mon, Nov 30, 2026 at 7:24 PM Philippe Mathieu-Daudé
> > <philmd@oss.qualcomm.com> wrote:
> >>
> >> On 30/11/26 14:07, Manos Pitsidianakis wrote:
> >>> VIRTIO spec says:
> >>>
> >>> VIRTIO_CONSOLE_PORT_NAME (7)
> >>>
> >>> Sent by the device to give a tag to the port. This control command is immediately followed by the UTF-8 name of the port for identification within the guest (without a NUL terminator).
> >>>
> >>> - Section 5.3.6.2 Multiport Device Operation
> >>>
> >>
> >> I adapted style as:
> >>
> >> hw/virtio/virtio-console: skip NUL terminator in port name
> >>
> >> VIRTIO spec says:
> >>
> >> VIRTIO_CONSOLE_PORT_NAME (7)
> >>
> >> Sent by the device to give a tag to the port. This control
> >> command is immediately followed by the UTF-8 name of the
> >> port for identification within the guest (without a NUL
> >> terminator).
> >>
> >> - Section 5.3.6.2 Multiport Device Operation
> >>
> >> but then I wondered about guest drivers already running and
> >> being migrated, would that confuse them?
>
> What about the migration question?
Oh yeah sorry. This event is only sent once, for the sake of the guest
associating an identifier to a port. It cannot be used or requested
again so there won't be any possibility for mismatch. Because the VM
cannot get the name of an existing port after a migration and "see"
the nul byte missing. But even if it could, Linux kernel already
ignores it anyway.
>
> >> We could confirm
> >> extending tests/qtest/virtio-serial-test.c coverage.
> >>
> >> Fixes: 160600fd137a ("virtio-serial-bus: Add a port 'name' property for
> >> port discovery in guests")
> >>
> >>> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> >>> ---
> >>> hw/char/virtio-serial-bus.c | 3 +--
> >>> 1 file changed, 1 insertion(+), 2 deletions(-)
> >>>
> >>> diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
> >>> index 7fe90571249f1cbdb9a9d095f041d4e048ea506e..cfc48fc1d4ab625b60a59ed840f2f0eb0bd47629 100644
> >>> --- a/hw/char/virtio-serial-bus.c
> >>> +++ b/hw/char/virtio-serial-bus.c
> >>> @@ -473,12 +473,11 @@ static void handle_control_message(VirtIOSerial *vser,
> >>
> >> Local var to have one single strlen call?
> >>
> >> size_t name_len = strlen(port->name);
> >>
> >> ...
> >> buffer_len = sizeof(cpkt) + name_len;
> >>
> >>> virtio_stw_p(vdev, &cpkt.event, VIRTIO_CONSOLE_PORT_NAME);
> >>> virtio_stw_p(vdev, &cpkt.value, 1);
> >>>
> >>> - buffer_len = sizeof(cpkt) + strlen(port->name) + 1;
> >>> + buffer_len = sizeof(cpkt) + strlen(port->name);
> >>> buffer = g_malloc(buffer_len);
> >>>
> >>> memcpy(buffer, &cpkt, sizeof(cpkt));
> >>> memcpy(buffer + sizeof(cpkt), port->name, strlen(port->name));
> >>> - buffer[buffer_len - 1] = 0;
> >>
> >> We rather strpadcpy() which makes intent explicit:
> >>
> >> strpadcpy(buffer + sizeof(cpkt), name_len, port->name, '\0');
> >>
> >>>
> >>> send_control_msg(vser, buffer, buffer_len);
> >>> g_free(buffer);
> >>>
> >>> ---
> >>> base-commit: 9cda597a1a3903d090e8e55e23f5b8a859da88ab
> >>> change-id: 20261130-fix-virtio-console-port-name-32be73542009
> >>
> >> Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
> >
> > Thanks Phil!
> >
> > I purposefully kept the patch diff as small as possible because I just
> > wanted to fix the bug and avoid any bikeshedding on refactoring. It's
> > probably better to shape up the code in a different patch.
>
> OK.
--
Manos Pitsidianakis
Emulation and Virtualization Engineer at Linaro Ltd
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-12-01 11:05 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 13:07 [PATCH] virtio-console: skip NUL terminator in port name Manos Pitsidianakis
2026-11-30 13:31 ` Tommaso Califano
2026-11-30 13:40 ` Manos Pitsidianakis
2026-11-30 13:45 ` Peter Maydell
2026-11-30 18:07 ` Michael S. Tsirkin
2026-11-30 17:24 ` Philippe Mathieu-Daudé
2026-12-01 5:35 ` Manos Pitsidianakis
2026-12-01 10:52 ` Philippe Mathieu-Daudé
2026-12-01 11:02 ` Manos Pitsidianakis
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.