Skip to contentSkip to conversation

virtio pmem: coverity fixes

PATCH In review Pankaj Gupta 5 participants 16 messages Jul 12, 2019 – Jul 15, 2019

lore
Share & tools
lore
#0 lore raw

cover virtio pmem: coverity fixes

This patch series two fixes for coverity and a
transactional info removal patch.

Pankaj Gupta (3):
virtio pmem: fix wrong mem region condition
virtio pmem: remove memdev null check
virtio pmem: remove transational device info

 hw/virtio/virtio-pmem-pci.c | 4 +---
 hw/virtio/virtio-pmem.c     | 4 ++--
 2 files changed, 3 insertions(+), 5 deletions(-)
Signature · 1 line
2.14.5
#1 lore raw

PATCH 1/3 virtio pmem: fix wrong mem region condition

Coverity reported memory region returns zero
for non-null value. This is because of wrong
arguments to '?:' , fixing this.

---
 hw/virtio/virtio-pmem-pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-pmem-pci.c +1 -1
index 8b2d0dbccc..0da6627469 100644
@@ -57,7 +57,7 @@ static uint64_t virtio_pmem_pci_get_plugged_size(const MemoryDeviceState *md,
     MemoryRegion *mr = vpc->get_memory_region(pmem, errp);
 
     /* the plugged size corresponds to the region size */
-    return mr ? 0 : memory_region_size(mr);
+    return mr ? memory_region_size(mr) : 0;
 }
 
 static void virtio_pmem_pci_fill_device_info(const MemoryDeviceState *md,
Signature · 1 line
2.14.5
Reviewed-by on v1 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] virtio pmem: fix wrong mem region condition

Quoted 8 lines · Pankaj Gupta

Coverity reported memory region returns zero
for non-null value. This is because of wrong
arguments to '?:' , fixing this.

---
 hw/virtio/virtio-pmem-pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
hw/virtio/virtio-pmem-pci.c +1 -1
index 8b2d0dbccc..0da6627469 100644
@@ -57,7 +57,7 @@ static uint64_t virtio_pmem_pci_get_plugged_size(const MemoryDeviceState *md,
     MemoryRegion *mr = vpc->get_memory_region(pmem, errp);
 
     /* the plugged size corresponds to the region size */
-    return mr ? 0 : memory_region_size(mr);
+    return mr ? memory_region_size(mr) : 0;
 }
 
 static void virtio_pmem_pci_fill_device_info(const MemoryDeviceState *md,
Signature · 1 line
2.14.5
Reviewed-by on v1 1/3
#3 lore raw

Re: [Qemu-devel] [PATCH 1/3] virtio pmem: fix wrong mem region condition

In reply to Pankaj Gupta
Quoted 8 lines · On Fri, 12 Jul 2019 13:05:52 +0530 Pankaj Gupta <[email protected]> wrote:

Coverity reported memory region returns zero
for non-null value. This is because of wrong
arguments to '?:' , fixing this.

---
 hw/virtio/virtio-pmem-pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by Tested-by on v1 1/3
#4 lore raw

Re: [Qemu-devel] [PATCH 1/3] virtio pmem: fix wrong mem region condition

In reply to Pankaj Gupta
Quoted 4 lines · Pankaj Gupta

Coverity reported memory region returns zero
for non-null value. This is because of wrong
arguments to '?:' , fixing this.

Please amend:

Fixes Coverity (CID 1403009)
Quoted 1 line
Quoted 18 lines
---
 hw/virtio/virtio-pmem-pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-pmem-pci.c +1 -1
index 8b2d0dbccc..0da6627469 100644
@@ -57,7 +57,7 @@ static uint64_t virtio_pmem_pci_get_plugged_size(const MemoryDeviceState *md,
     MemoryRegion *mr = vpc->get_memory_region(pmem, errp);
 
     /* the plugged size corresponds to the region size */
-    return mr ? 0 : memory_region_size(mr);
+    return mr ? memory_region_size(mr) : 0;
 }
 
 static void virtio_pmem_pci_fill_device_info(const MemoryDeviceState *md,
Reviewed-by on v1 1/3
#5 lore raw

Re: [Qemu-devel] [PATCH 1/3] virtio pmem: fix wrong mem region condition

In reply to Pankaj Gupta
Quoted 15 lines · Pankaj Gupta

Coverity reported memory region returns zero
for non-null value. This is because of wrong
arguments to '?:' , fixing this.

---
 hw/virtio/virtio-pmem-pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-pmem-pci.c +0 -0
index 8b2d0dbccc..0da6627469 100644

hw/virtio/virtio-pmem-pci.c static uint64_t virtio_pmem_pci_get_plugged_size(const MemoryDeviceState *md, · line 63

Quoted 8 lines
hw/virtio/virtio-pmem-pci.c +1 -1
@@ -57,7 +57,7 @@ static uint64_t virtio_pmem_pci_get_plugged_size(const MemoryDeviceState *md,
     MemoryRegion *mr = vpc->get_memory_region(pmem, errp);
 
     /* the plugged size corresponds to the region size */
-    return mr ? 0 : memory_region_size(mr);
+    return mr ? memory_region_size(mr) : 0;
 }
 
 static void virtio_pmem_pci_fill_device_info(const MemoryDeviceState *md,
Signature · 3 lines
Thanks,

David / dhildenb
#6 lore raw

PATCH 2/3 virtio pmem: remove memdev null check

In reply to Pankaj Gupta

Coverity reports that when we're assigning vi->size we handle the "pmem->memdev is NULL" case; but we then pass it into object_get_canonical_path(), which unconditionally dereferences it and will crash if it is NULL. If this pointer can be NULL then we need to do something else here.

We are removing 'pmem->memdev' null check here as memdev will never be null in this function.

---
 hw/virtio/virtio-pmem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/virtio/virtio-pmem.c +2 -2
index adbfb603ab..17c196d107 100644
@@ -134,8 +134,8 @@ static void virtio_pmem_fill_device_info(const VirtIOPMEM *pmem,
                                          VirtioPMEMDeviceInfo *vi)
 {
     vi->memaddr = pmem->start;
-    vi->size = pmem->memdev ? memory_region_size(&pmem->memdev->mr) : 0;
-    vi->memdev = object_get_canonical_path(OBJECT(pmem->memdev));
+    vi->size    = memory_region_size(&pmem->memdev->mr);
+    vi->memdev  = object_get_canonical_path(OBJECT(pmem->memdev));
 }
 
 static MemoryRegion *virtio_pmem_get_memory_region(VirtIOPMEM *pmem,
Signature · 1 line
2.14.5
Reviewed-by on v1 2/3
#7 lore raw

Re: [Qemu-devel] [PATCH 2/3] virtio pmem: remove memdev null check

Quoted 8 lines · On Fri, 12 Jul 2019 13:05:53 +0530 Pankaj Gupta <[email protected]> wrote:

Coverity reports that when we're assigning vi->size we handle the "pmem->memdev is NULL" case; but we then pass it into object_get_canonical_path(), which unconditionally dereferences it and will crash if it is NULL. If this pointer can be NULL then we need to do something else here.

We are removing 'pmem->memdev' null check here as memdev will never be null in this function.

Indeed, we'll fail to realize the device if it is NULL.

Quoted 5 lines
---
 hw/virtio/virtio-pmem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
#8 lore raw

PATCH 3/3 virtio pmem: remove transational device info

In reply to Pankaj Gupta

Remove transactional & non transactional device info for virtio pmem.

---
 hw/virtio/virtio-pmem-pci.c | 2 --
 1 file changed, 2 deletions(-)
hw/virtio/virtio-pmem-pci.c +0 -2
index 0da6627469..fe2af00fa1 100644
@@ -113,8 +113,6 @@ static void virtio_pmem_pci_instance_init(Object *obj)
 static const VirtioPCIDeviceTypeInfo virtio_pmem_pci_info = {
     .base_name             = TYPE_VIRTIO_PMEM_PCI,
     .generic_name          = "virtio-pmem-pci",
-    .transitional_name     = "virtio-pmem-pci-transitional",
-    .non_transitional_name = "virtio-pmem-pci-non-transitional",
     .instance_size = sizeof(VirtIOPMEMPCI),
     .instance_init = virtio_pmem_pci_instance_init,
     .class_init    = virtio_pmem_pci_class_init,
Signature · 1 line
2.14.5
Reviewed-by on v1 3/3
#9 lore raw

Re: [Qemu-devel] [PATCH 3/3] virtio pmem: remove transational device info

Quoted 2 lines · On Fri, 12 Jul 2019 13:05:54 +0530 Pankaj Gupta <[email protected]> wrote:

Remove transactional & non transactional device info for virtio pmem.

s/device info/names/ ?

Quoted 5 lines
---
 hw/virtio/virtio-pmem-pci.c | 2 --
 1 file changed, 2 deletions(-)
#10 lore raw

Re: [Qemu-devel] [PATCH 3/3] virtio pmem: remove transational device info

Quoted 9 lines
Quoted 2 lines · On Fri, 12 Jul 2019 13:05:54 +0530 Pankaj Gupta <[email protected]> wrote:

Remove transactional & non transactional device info for virtio pmem.

s/device info/names/ ?

yes.

Quoted 9 lines
Quoted 6 lines
---
 hw/virtio/virtio-pmem-pci.c | 2 --
 1 file changed, 2 deletions(-)
#11 lore raw

Re: [Qemu-devel] [PATCH 3/3] virtio pmem: remove transational device info

In reply to Pankaj Gupta
Quoted 2 lines · Pankaj Gupta

Remove transactional & non transactional device info for virtio pmem.

Can you explain and add *why* ?

Quoted 20 lines
---
 hw/virtio/virtio-pmem-pci.c | 2 --
 1 file changed, 2 deletions(-)
hw/virtio/virtio-pmem-pci.c +0 -2
index 0da6627469..fe2af00fa1 100644
@@ -113,8 +113,6 @@ static void virtio_pmem_pci_instance_init(Object *obj)
 static const VirtioPCIDeviceTypeInfo virtio_pmem_pci_info = {
     .base_name             = TYPE_VIRTIO_PMEM_PCI,
     .generic_name          = "virtio-pmem-pci",
-    .transitional_name     = "virtio-pmem-pci-transitional",
-    .non_transitional_name = "virtio-pmem-pci-non-transitional",
     .instance_size = sizeof(VirtIOPMEMPCI),
     .instance_init = virtio_pmem_pci_instance_init,
     .class_init    = virtio_pmem_pci_class_init,
Signature · 3 lines
Thanks,

David / dhildenb
#12 lore raw

Re: [Qemu-devel] [PATCH 3/3] virtio pmem: remove transational device info

Quoted 7 lines · Pankaj Gupta
Quoted 2 lines

Remove transactional & non transactional device info for virtio pmem.

Can you explain and add *why* ?

As per upstream suggestion by Cornelia & MST, transactional devices are for legacy purpose. So, does not make sense for virtio-pmem.

Thanks,
Pankaj

Quoted 29 lines
Quoted 13 lines
---
 hw/virtio/virtio-pmem-pci.c | 2 --
 1 file changed, 2 deletions(-)
hw/virtio/virtio-pmem-pci.c +0 -0
index 0da6627469..fe2af00fa1 100644

hw/virtio/virtio-pmem-pci.c static void virtio_pmem_pci_instance_init(Object *obj) · line 118

Quoted 8 lines
hw/virtio/virtio-pmem-pci.c +0 -2
@@ -113,8 +113,6 @@ static void virtio_pmem_pci_instance_init(Object *obj)
 static const VirtioPCIDeviceTypeInfo virtio_pmem_pci_info = {
     .base_name             = TYPE_VIRTIO_PMEM_PCI,
     .generic_name          = "virtio-pmem-pci",
-    .transitional_name     = "virtio-pmem-pci-transitional",
-    .non_transitional_name = "virtio-pmem-pci-non-transitional",
     .instance_size = sizeof(VirtIOPMEMPCI),
     .instance_init = virtio_pmem_pci_instance_init,
     .class_init    = virtio_pmem_pci_class_init,

--

Thanks,

David / dhildenb

Reviewed-by
#13 lore raw

Re: [Qemu-devel] [PATCH 3/3] virtio pmem: remove transational device info

Quoted 10 lines · Pankaj Gupta
Quoted 7 lines · Pankaj Gupta
Quoted 2 lines

Remove transactional & non transactional device info for virtio pmem.

Can you explain and add *why* ?

As per upstream suggestion by Cornelia & MST, transactional devices are for legacy purpose. So, does not make sense for virtio-pmem.

With something like that added to the description

Quoted 33 lines

Thanks,
Pankaj

Quoted 29 lines
Quoted 13 lines
---
 hw/virtio/virtio-pmem-pci.c | 2 --
 1 file changed, 2 deletions(-)
hw/virtio/virtio-pmem-pci.c +0 -0
index 0da6627469..fe2af00fa1 100644

hw/virtio/virtio-pmem-pci.c static void virtio_pmem_pci_instance_init(Object *obj) · line 118

Quoted 8 lines
hw/virtio/virtio-pmem-pci.c +0 -2
@@ -113,8 +113,6 @@ static void virtio_pmem_pci_instance_init(Object *obj)
 static const VirtioPCIDeviceTypeInfo virtio_pmem_pci_info = {
     .base_name             = TYPE_VIRTIO_PMEM_PCI,
     .generic_name          = "virtio-pmem-pci",
-    .transitional_name     = "virtio-pmem-pci-transitional",
-    .non_transitional_name = "virtio-pmem-pci-non-transitional",
     .instance_size = sizeof(VirtIOPMEMPCI),
     .instance_init = virtio_pmem_pci_instance_init,
     .class_init    = virtio_pmem_pci_class_init,

--

Thanks,

David / dhildenb

Signature · 3 lines
Thanks,

David / dhildenb
#14 lore raw
In reply to Pankaj Gupta
Quoted 12 lines · On Fri, 12 Jul 2019 13:05:51 +0530 Pankaj Gupta <[email protected]> wrote:

This patch series two fixes for coverity and a
transactional info removal patch.

Pankaj Gupta (3):
virtio pmem: fix wrong mem region condition
virtio pmem: remove memdev null check
virtio pmem: remove transational device info

 hw/virtio/virtio-pmem-pci.c | 4 +---
 hw/virtio/virtio-pmem.c     | 4 ++--
 2 files changed, 3 insertions(+), 5 deletions(-)

I think all of this is 4.1 material.

#15 lore raw
Quoted 13 lines
Quoted 8 lines · On Fri, 12 Jul 2019 13:05:51 +0530 Pankaj Gupta <[email protected]> wrote:

This patch series two fixes for coverity and a
transactional info removal patch.

Pankaj Gupta (3):
virtio pmem: fix wrong mem region condition
virtio pmem: remove memdev null check
virtio pmem: remove transational device info

Quoted 6 lines
Quoted 4 lines
 hw/virtio/virtio-pmem-pci.c | 4 +---
 hw/virtio/virtio-pmem.c     | 4 ++--
 2 files changed, 3 insertions(+), 5 deletions(-)

I think all of this is 4.1 material.

Yes, forgot to add in the subject.

Thank you for the review.

Best regards,
Pankaj

Quoted 2 lines