qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PULL 0/3]  Misc QGA patches 2023-10-11
@ 2023-10-11 14:20 Konstantin Kostiuk
  2023-10-11 14:20 ` [PULL 1/3] qga: Remove platform GUID definitions Konstantin Kostiuk
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Konstantin Kostiuk @ 2023-10-11 14:20 UTC (permalink / raw)
  To: qemu-devel, Peter Maydell

The following changes since commit cea3ea670fe265421131aad90c36fbb87bc4d206:

  Merge tag 'pull-vfio-20231009' of https://github.com/legoater/qemu into staging (2023-10-09 10:11:35 -0400)

are available in the Git repository at:

  https://github.com/kostyanf14/qemu.git tags/qga-pull-2023-10-11

for you to fetch changes up to f897ef0d47d332d4c4498aed1140c6856fe56d79:

  qapi: qga: Clarify when out-data and err-data are populated (2023-10-11 14:30:54 +0300)

----------------------------------------------------------------
qga-pull-2023-10-11

----------------------------------------------------------------
Akihiko Odaki (1):
      qga: Remove platform GUID definitions

Daniel Xu (2):
      qga: Fix memory leak when output stream is unused
      qapi: qga: Clarify when out-data and err-data are populated

 qga/commands-win32.c | 7 -------
 qga/commands.c       | 4 ++--
 qga/qapi-schema.json | 8 +++++---
 3 files changed, 7 insertions(+), 12 deletions(-)

--
2.42.0



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

* [PULL 1/3] qga: Remove platform GUID definitions
  2023-10-11 14:20 [PULL 0/3] Misc QGA patches 2023-10-11 Konstantin Kostiuk
@ 2023-10-11 14:20 ` Konstantin Kostiuk
  2023-10-11 14:20 ` [PULL 2/3] qga: Fix memory leak when output stream is unused Konstantin Kostiuk
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Konstantin Kostiuk @ 2023-10-11 14:20 UTC (permalink / raw)
  To: qemu-devel, Peter Maydell

From: Akihiko Odaki <akihiko.odaki@daynix.com>

GUID_DEVINTERFACE_DISK and GUID_DEVINTERFACE_STORAGEPORT are already
defined by MinGW-w64. They are not only unnecessary, but can lead to
duplicate definition errors at link time with some unknown condition.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>
Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
---
 qga/commands-win32.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 6beae659b7..697c65507c 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -501,13 +501,6 @@ static GuestDiskBusType find_bus_type(STORAGE_BUS_TYPE bus)
     return win2qemu[(int)bus];
 }
 
-DEFINE_GUID(GUID_DEVINTERFACE_DISK,
-        0x53f56307L, 0xb6bf, 0x11d0, 0x94, 0xf2,
-        0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
-DEFINE_GUID(GUID_DEVINTERFACE_STORAGEPORT,
-        0x2accfe60L, 0xc130, 0x11d2, 0xb0, 0x82,
-        0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
-
 static void get_pci_address_for_device(GuestPCIAddress *pci,
                                        HDEVINFO dev_info)
 {
-- 
2.42.0



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

* [PULL 2/3] qga: Fix memory leak when output stream is unused
  2023-10-11 14:20 [PULL 0/3] Misc QGA patches 2023-10-11 Konstantin Kostiuk
  2023-10-11 14:20 ` [PULL 1/3] qga: Remove platform GUID definitions Konstantin Kostiuk
@ 2023-10-11 14:20 ` Konstantin Kostiuk
  2023-10-11 14:20 ` [PULL 3/3] qapi: qga: Clarify when out-data and err-data are populated Konstantin Kostiuk
  2023-10-12 18:51 ` [PULL 0/3] Misc QGA patches 2023-10-11 Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Konstantin Kostiuk @ 2023-10-11 14:20 UTC (permalink / raw)
  To: qemu-devel, Peter Maydell

From: Daniel Xu <dxu@dxuuu.xyz>

If capture-output is requested but one of the channels goes unused (eg.
we attempt to capture stderr but the command never writes to stderr), we
can leak memory.

guest_exec_output_watch() is (from what I understand) unconditionally
called for both streams if output capture is requested. The first call
will always pass the `p->size == p->length` check b/c both values are
0. Then GUEST_EXEC_IO_SIZE bytes will be allocated for the stream.

But when we reap the exited process there's a `gei->err.length > 0`
check to actually free the buffer. Which does not get run if the command
doesn't write to the stream.

Fix by making free() unconditional.

Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>
Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
---
 qga/commands.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/qga/commands.c b/qga/commands.c
index 09c683e263..ce172edd2d 100644
--- a/qga/commands.c
+++ b/qga/commands.c
@@ -206,15 +206,15 @@ GuestExecStatus *qmp_guest_exec_status(int64_t pid, Error **errp)
 #endif
         if (gei->out.length > 0) {
             ges->out_data = g_base64_encode(gei->out.data, gei->out.length);
-            g_free(gei->out.data);
             ges->has_out_truncated = gei->out.truncated;
         }
+        g_free(gei->out.data);
 
         if (gei->err.length > 0) {
             ges->err_data = g_base64_encode(gei->err.data, gei->err.length);
-            g_free(gei->err.data);
             ges->has_err_truncated = gei->err.truncated;
         }
+        g_free(gei->err.data);
 
         QTAILQ_REMOVE(&guest_exec_state.processes, gei, next);
         g_free(gei);
-- 
2.42.0



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

* [PULL 3/3] qapi: qga: Clarify when out-data and err-data are populated
  2023-10-11 14:20 [PULL 0/3] Misc QGA patches 2023-10-11 Konstantin Kostiuk
  2023-10-11 14:20 ` [PULL 1/3] qga: Remove platform GUID definitions Konstantin Kostiuk
  2023-10-11 14:20 ` [PULL 2/3] qga: Fix memory leak when output stream is unused Konstantin Kostiuk
@ 2023-10-11 14:20 ` Konstantin Kostiuk
  2023-10-12 18:51 ` [PULL 0/3] Misc QGA patches 2023-10-11 Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Konstantin Kostiuk @ 2023-10-11 14:20 UTC (permalink / raw)
  To: qemu-devel, Peter Maydell

From: Daniel Xu <dxu@dxuuu.xyz>

If output is being captured for a guest-exec invocation, the out-data
and err-data fields of guest-exec-status are only populated after the
process is reaped. This is somewhat counter intuitive and too late to
change. Thus, it would be good to document the behavior.

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>
Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
---
 qga/qapi-schema.json | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index b720dd4379..876e2a8ea8 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -1220,11 +1220,13 @@
 # @signal: signal number (linux) or unhandled exception code (windows)
 #     if the process was abnormally terminated.
 #
-# @out-data: base64-encoded stdout of the process
+# @out-data: base64-encoded stdout of the process. This field will only
+#     be populated after the process exits.
 #
-# @err-data: base64-encoded stderr of the process Note: @out-data and
+# @err-data: base64-encoded stderr of the process. Note: @out-data and
 #     @err-data are present only if 'capture-output' was specified for
-#     'guest-exec'
+#     'guest-exec'. This field will only be populated after the process
+#     exits.
 #
 # @out-truncated: true if stdout was not fully captured due to size
 #     limitation.
-- 
2.42.0



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

* Re: [PULL 0/3]  Misc QGA patches 2023-10-11
  2023-10-11 14:20 [PULL 0/3] Misc QGA patches 2023-10-11 Konstantin Kostiuk
                   ` (2 preceding siblings ...)
  2023-10-11 14:20 ` [PULL 3/3] qapi: qga: Clarify when out-data and err-data are populated Konstantin Kostiuk
@ 2023-10-12 18:51 ` Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2023-10-12 18:51 UTC (permalink / raw)
  To: Konstantin Kostiuk; +Cc: qemu-devel, Peter Maydell

[-- Attachment #1: Type: text/plain, Size: 115 bytes --]

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/8.2 for any user-visible changes.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2023-10-13 15:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-11 14:20 [PULL 0/3] Misc QGA patches 2023-10-11 Konstantin Kostiuk
2023-10-11 14:20 ` [PULL 1/3] qga: Remove platform GUID definitions Konstantin Kostiuk
2023-10-11 14:20 ` [PULL 2/3] qga: Fix memory leak when output stream is unused Konstantin Kostiuk
2023-10-11 14:20 ` [PULL 3/3] qapi: qga: Clarify when out-data and err-data are populated Konstantin Kostiuk
2023-10-12 18:51 ` [PULL 0/3] Misc QGA patches 2023-10-11 Stefan Hajnoczi

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