Skip to contentSkip to conversation

vfio: memory leak fix and code cleanup

PATCH In review Zhenzhong Duan 5 participants 12 messages Oct 9, 2023

lore
Share & tools
lore
#0 lore raw

cover vfio: memory leak fix and code cleanup

Hi,

This trivial patchset fixes a incremental memory leak in rare case, and some cleanup on ap/ccw.

This patchset is based on vfio-next.

Thanks
Zhenzhong

Zhenzhong Duan (3):
vfio/pci: Fix a potential memory leak in vfio_listener_region_add vfio/ap: Remove pointless apdev variable
vfio/ccw: Remove redundant definition of TYPE_VFIO_CCW

 hw/vfio/ap.c                | 9 +++------
 hw/vfio/common.c            | 2 +-
 include/hw/s390x/vfio-ccw.h | 2 --
 3 files changed, 4 insertions(+), 9 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/3 vfio/pci: Fix a potential memory leak in vfio_listener_region_add

When there is an failure in vfio_listener_region_add() and the section belongs to a ram device, there is an inaccurate error report which should never be related to vfio_dma_map failure. The memory holding err is also incrementally leaked in each failure.

Fix it by reporting the real error and free it.

Fixes 567b5b309ab ("vfio/pci: Relax DMA map errors for MMIO regions")
---
 hw/vfio/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/common.c +1 -1
index 9e61de03ee..5ff5acf1d8 100644
@@ -763,7 +763,7 @@ static void vfio_listener_region_add(MemoryListener *listener,
 
 fail:
     if (memory_region_is_ram_device(section->mr)) {
-        error_report("failed to vfio_dma_map. pci p2p may not work");
+        error_reportf_err(err, "PCI p2p may not work: ");
         return;
     }
     /*
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/3 vfio/ap: Remove pointless apdev variable

In reply to Zhenzhong Duan

No need to double-cast, call VFIO_AP_DEVICE() on DeviceState.

No functional changes.

---
 hw/vfio/ap.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
hw/vfio/ap.c +3 -6
index 22e564f4f7..e083a19eac 100644
@@ -156,8 +156,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
 {
     int ret;
     Error *err = NULL;
-    APDevice *apdev = AP_DEVICE(dev);
-    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
+    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(dev);
     VFIODevice *vbasedev = &vapdev->vdev;
 
     vbasedev->name = g_path_get_basename(vbasedev->sysfsdev);
@@ -195,8 +194,7 @@ error:
 
 static void vfio_ap_unrealize(DeviceState *dev)
 {
-    APDevice *apdev = AP_DEVICE(dev);
-    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
+    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(dev);
 
     vfio_ap_unregister_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX);
     vfio_detach_device(&vapdev->vdev);
@@ -211,8 +209,7 @@ static Property vfio_ap_properties[] = {
 static void vfio_ap_reset(DeviceState *dev)
 {
     int ret;
-    APDevice *apdev = AP_DEVICE(dev);
-    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
+    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(dev);
 
     ret = ioctl(vapdev->vdev.fd, VFIO_DEVICE_RESET);
     if (ret) {
Signature · 1 line
2.34.1
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] vfio/ap: Remove pointless apdev variable

In reply to Zhenzhong Duan
Quoted 43 lines · Zhenzhong Duan

No need to double-cast, call VFIO_AP_DEVICE() on DeviceState.

No functional changes.

---
  hw/vfio/ap.c | 9 +++------
  1 file changed, 3 insertions(+), 6 deletions(-)
hw/vfio/ap.c +3 -6
index 22e564f4f7..e083a19eac 100644
@@ -156,8 +156,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
  {
      int ret;
      Error *err = NULL;
-    APDevice *apdev = AP_DEVICE(dev);
-    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
+    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(dev);
      VFIODevice *vbasedev = &vapdev->vdev;
 
      vbasedev->name = g_path_get_basename(vbasedev->sysfsdev);
@@ -195,8 +194,7 @@ error:
 
  static void vfio_ap_unrealize(DeviceState *dev)
  {
-    APDevice *apdev = AP_DEVICE(dev);
-    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
+    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(dev);
 
      vfio_ap_unregister_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX);
      vfio_detach_device(&vapdev->vdev);
@@ -211,8 +209,7 @@ static Property vfio_ap_properties[] = {
  static void vfio_ap_reset(DeviceState *dev)
  {
      int ret;
-    APDevice *apdev = AP_DEVICE(dev);
-    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
+    VFIOAPDevice *vapdev = VFIO_AP_DEVICE(dev);
 
      ret = ioctl(vapdev->vdev.fd, VFIO_DEVICE_RESET);
      if (ret) {
#5 lore raw

PATCH 3/3 vfio/ccw: Remove redundant definition of TYPE_VFIO_CCW

In reply to Zhenzhong Duan

No functional changes.

---
 include/hw/s390x/vfio-ccw.h | 2 --
 1 file changed, 2 deletions(-)
include/hw/s390x/vfio-ccw.h +0 -2
index 63a909eb7e..4209d27657 100644
@@ -22,6 +22,4 @@
 #define TYPE_VFIO_CCW "vfio-ccw"
 OBJECT_DECLARE_SIMPLE_TYPE(VFIOCCWDevice, VFIO_CCW)
 
-#define TYPE_VFIO_CCW "vfio-ccw"
-
 #endif
Signature · 1 line
2.34.1
Reviewed-by on v1 3/3
#7 lore raw

Re: [PATCH 3/3] vfio/ccw: Remove redundant definition of TYPE_VFIO_CCW

In reply to Zhenzhong Duan
Quoted 3 lines · Zhenzhong Duan

No functional changes.

I see Cedric has already queued this, but FWIW:

Quoted 16 lines

---
 include/hw/s390x/vfio-ccw.h | 2 --

 1 file changed, 2 deletions(-)
include/hw/s390x/vfio- renamed from include/hw/s390x/vfio-ccw.h +0 -0

ccw.h
index 63a909eb7e..4209d27657 100644

include/hw/s390x/vfio-ccw.h +0 -0
@@ -22,6 +22,4 @@
  #define TYPE_VFIO_CCW "vfio-ccw"
  OBJECT_DECLARE_SIMPLE_TYPE(VFIOCCWDevice, VFIO_CCW)

include/hw/s390x/vfio-ccw.h +0 -2
-#define TYPE_VFIO_CCW "vfio-ccw"
-

 #endif

#8 lore raw

Re: [PATCH 3/3] vfio/ccw: Remove redundant definition of TYPE_VFIO_CCW

Quoted 8 lines · Eric Farman
Quoted 3 lines · Zhenzhong Duan

No functional changes.

I see Cedric has already queued this, but FWIW:

I will take the new tags when I rebase.

Thanks,

C.

Quoted 18 lines
Quoted 17 lines
---
  include/hw/s390x/vfio-ccw.h | 2 --
  1 file changed, 2 deletions(-)
include/hw/s390x/vfio- renamed from include/hw/s390x/vfio-ccw.h +0 -0

ccw.h
index 63a909eb7e..4209d27657 100644

include/hw/s390x/vfio-ccw.h +0 -2
@@ -22,6 +22,4 @@
  #define TYPE_VFIO_CCW "vfio-ccw"
  OBJECT_DECLARE_SIMPLE_TYPE(VFIOCCWDevice, VFIO_CCW)
 
-#define TYPE_VFIO_CCW "vfio-ccw"
-
  #endif
#9 lore raw
In reply to Zhenzhong Duan
Quoted 6 lines · Zhenzhong Duan

Hi,

This trivial patchset fixes a incremental memory leak in rare case, and some cleanup on ap/ccw.

This patchset is based on vfio-next.

Will this apply on the future v5 of Eric ?

Thanks,

C.

Quoted 14 lines

Thanks
Zhenzhong

Zhenzhong Duan (3):
vfio/pci: Fix a potential memory leak in vfio_listener_region_add vfio/ap: Remove pointless apdev variable
vfio/ccw: Remove redundant definition of TYPE_VFIO_CCW

  hw/vfio/ap.c                | 9 +++------
  hw/vfio/common.c            | 2 +-
  include/hw/s390x/vfio-ccw.h | 2 --
  3 files changed, 4 insertions(+), 9 deletions(-)
#10 lore raw
Quoted 8 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Monday, October 9, 2023 2:32 PM
Subject: Re: [PATCH 0/3] vfio: memory leak fix and code cleanup

On 10/9/23 04:20, Zhenzhong Duan wrote:

Quoted 8 lines
Quoted 6 lines

Hi,

This trivial patchset fixes a incremental memory leak in rare case, and some cleanup on ap/ccw.

This patchset is based on vfio-next.

Will this apply on the future v5 of Eric ?

I think so, though this patchset is applied on v4 of Eric. Let me know if you want a new version without basing on the prerequisite patchset, it’s easy to rebase.

Thanks
Zhenzhong

#11 lore raw
In reply to Zhenzhong Duan
Quoted 6 lines · Zhenzhong Duan

Hi,

This trivial patchset fixes a incremental memory leak in rare case, and some cleanup on ap/ccw.

This patchset is based on vfio-next.

Applied on vfio-next.

Thanks,

C.