Skip to contentSkip to conversation

pci_dma_rw: return correct value instead of 0

PATCH In review Emanuele Giuseppe Esposito 4 participants 8 messages Jul 29, 2020 – Aug 17, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci_dma_rw: return correct value instead of 0

pci_dma_rw currently always returns 0, regardless of the result of dma_memory_rw. Adjusted to return the correct value.

---
 include/hw/pci/pci.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/hw/pci/pci.h +1 -2
index c1bf7d5356..41c4ab5932 100644
@@ -787,8 +787,7 @@ static inline AddressSpace *pci_get_address_space(PCIDevice *dev)
 static inline int pci_dma_rw(PCIDevice *dev, dma_addr_t addr,
                              void *buf, dma_addr_t len, DMADirection dir)
 {
-    dma_memory_rw(pci_get_address_space(dev), addr, buf, len, dir);
-    return 0;
+    return dma_memory_rw(pci_get_address_space(dev), addr, buf, len, dir);
 }
 
 static inline int pci_dma_read(PCIDevice *dev, dma_addr_t addr,
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Emanuele Giuseppe Esposito

pci_dma_rw currently always returns 0, regardless of the result of dma_memory_rw. Adjusted to return the correct value.

---
 include/hw/pci/pci.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/hw/pci/pci.h +0 -0
index c1bf7d5356..41c4ab5932 100644

include/hw/pci/pci.h static inline AddressSpace *pci_get_address_space(PCIDevice *dev) · line 791

Quoted 7 lines
include/hw/pci/pci.h +1 -2
@@ -787,8 +787,7 @@ static inline AddressSpace *pci_get_address_space(PCIDevice *dev)
 static inline int pci_dma_rw(PCIDevice *dev, dma_addr_t addr,
                              void *buf, dma_addr_t len, DMADirection dir)
 {
-    dma_memory_rw(pci_get_address_space(dev), addr, buf, len, dir);
-    return 0;
+    return dma_memory_rw(pci_get_address_space(dev), addr, buf, len, dir);
 }

I think it's a left over from when we used "void cpu_physical_memory_rw()".

I agree that it is better to return the dma_memory_rw() return value, but at first look, no one seems to check the return value of pci_dma_rw(), pci_dma_read(), andpci_dma_write().

Should we make them void?

Anyway, for this patch:

Thanks,
Stefano

#2 lore raw
Quoted 25 lines · Stefano Garzarella
Quoted 14 lines · Emanuele Giuseppe Esposito

pci_dma_rw currently always returns 0, regardless of the result of dma_memory_rw. Adjusted to return the correct value.

---
  include/hw/pci/pci.h | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
include/hw/pci/pci.h +0 -0
index c1bf7d5356..41c4ab5932 100644

include/hw/pci/pci.h static inline AddressSpace *pci_get_address_space(PCIDevice *dev) · line 791

Quoted 7 lines
include/hw/pci/pci.h +1 -2
@@ -787,8 +787,7 @@ static inline AddressSpace *pci_get_address_space(PCIDevice *dev)
  static inline int pci_dma_rw(PCIDevice *dev, dma_addr_t addr,
                               void *buf, dma_addr_t len, DMADirection dir)
  {
-    dma_memory_rw(pci_get_address_space(dev), addr, buf, len, dir);
-    return 0;
+    return dma_memory_rw(pci_get_address_space(dev), addr, buf, len, dir);
  }

I think it's a left over from when we used "void cpu_physical_memory_rw()".

Quoted 5 lines

I agree that it is better to return the dma_memory_rw() return value, but at first look, no one seems to check the return value of pci_dma_rw(), pci_dma_read(), andpci_dma_write().

Should we make them void?

I noticed that nobody checks the return of those functions, but I think checking for possible error is always useful. I am using the edu device and clearly doing something wrong since with this fix I discovered that the pci_dma_read call returns nonzero.

Keeping the function as it is or void would make it harder to spot such errors in future.

Thank you,
Emanuele

Quoted 9 lines

Anyway, for this patch:

Thanks,
Stefano

#3 lore raw
Quoted 34 lines · Emanuele Giuseppe Esposito
Quoted 25 lines · Stefano Garzarella
Quoted 14 lines · Emanuele Giuseppe Esposito

pci_dma_rw currently always returns 0, regardless of the result of dma_memory_rw. Adjusted to return the correct value.

---
  include/hw/pci/pci.h | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
include/hw/pci/pci.h +0 -0
index c1bf7d5356..41c4ab5932 100644

include/hw/pci/pci.h static inline AddressSpace *pci_get_address_space(PCIDevice *dev) · line 791

Quoted 7 lines
include/hw/pci/pci.h +1 -2
@@ -787,8 +787,7 @@ static inline AddressSpace *pci_get_address_space(PCIDevice *dev)
  static inline int pci_dma_rw(PCIDevice *dev, dma_addr_t addr,
                               void *buf, dma_addr_t len, DMADirection dir)
  {
-    dma_memory_rw(pci_get_address_space(dev), addr, buf, len, dir);
-    return 0;
+    return dma_memory_rw(pci_get_address_space(dev), addr, buf, len, dir);
  }

I think it's a left over from when we used "void cpu_physical_memory_rw()".

Quoted 5 lines

I agree that it is better to return the dma_memory_rw() return value, but at first look, no one seems to check the return value of pci_dma_rw(), pci_dma_read(), andpci_dma_write().

Should we make them void?

Quoted 7 lines

I noticed that nobody checks the return of those functions, but I think checking for possible error is always useful. I am using the edu device and clearly doing something wrong since with this fix I discovered that the pci_dma_read call returns nonzero.

Keeping the function as it is or void would make it harder to spot such errors in future.

I agree, I was just worried that no one checks the return value.

Thanks,
Stefano

#4 lore raw
In reply to Stefano Garzarella
Quoted 5 lines · Stefano Garzarella

I agree that it is better to return the dma_memory_rw() return value, but at first look, no one seems to check the return value of pci_dma_rw(), pci_dma_read(), andpci_dma_write().

Should we make them void?

In general code (eg device models) that issues memory transactions need to have a mechanism for finding out whether the transaction succeeds. Traditionally QEMU didn't have the concept of a transaction failing, but we have added it, starting with the APIs at the bottom level (the address_space_* ones). We haven't always plumbed the error-handling (or the memory-transaction input, for that matter) through to some of these other APIs. I think for consistency we should do that, and ideally we should make all these APIs look the same as the base-level address_space* ones, which would mean returning a MemTxError rather than a bool.

We should also figure out why the dma_* functions exist at all:
they include some calls to dma_barrier(), but not all devices do DMA with the dma_* functions, so we have an inconsistency that should be sorted out...

thanks
-- PMM

#5 lore raw
Quoted 7 lines · Peter Maydell
Quoted 5 lines · Stefano Garzarella

I agree that it is better to return the dma_memory_rw() return value, but at first look, no one seems to check the return value of pci_dma_rw(), pci_dma_read(), andpci_dma_write().

Should we make them void?

Quoted 11 lines

In general code (eg device models) that issues memory transactions need to have a mechanism for finding out whether the transaction succeeds. Traditionally QEMU didn't have the concept of a transaction failing, but we have added it, starting with the APIs at the bottom level (the address_space_* ones). We haven't always plumbed the error-handling (or the memory-transaction input, for that matter) through to some of these other APIs. I think for consistency we should do that, and ideally we should make all these APIs look the same as the base-level address_space* ones, which would mean returning a MemTxError rather than a bool.

Yeah, that makes a lot of sense to me.

Quoted 6 lines

We should also figure out why the dma_* functions exist at all:
they include some calls to dma_barrier(), but not all devices do DMA with the dma_* functions, so we have an inconsistency that should be sorted out...

I've never looked in detail, but I agree we should have more consistency.

Thanks for the details!
Stefano

#6 lore raw
In reply to Emanuele Giuseppe Esposito
Quoted 6 lines · Emanuele Giuseppe Esposito

pci_dma_rw currently always returns 0, regardless of the result of dma_memory_rw. Adjusted to return the correct value.

We also have the equivalent patch from Klaus Jensen back in 2019 which got reviewed at the time but seems to have gotten lost along the way:
https://patchwork.kernel.org/patch/11184911/

thanks
-- PMM

#7 lore raw
Quoted 7 lines · Peter Maydell
Quoted 5 lines · Emanuele Giuseppe Esposito

pci_dma_rw currently always returns 0, regardless of the result of dma_memory_rw. Adjusted to return the correct value.

Quoted 9 lines
Quoted 1 line

We also have the equivalent patch from Klaus Jensen back in 2019 which got reviewed at the time but seems to have gotten lost along the way:
https://patchwork.kernel.org/patch/11184911/

thanks
-- PMM

Yes, I posted this a while back because I need that return value in the emulated nvme device - so please don't make it void ;)

My patch was part of a series that has not gone in yet, but I can resend seperately - or you can just apply the patch from Emanuele. It's no biggie to me as long as the fix is there!

Klaus