mbox series

[0/8] hw/dma: Introduce dma_size_t type definition

Message ID 20211231114901.976937-1-philmd@redhat.com
Headers show
Series hw/dma: Introduce dma_size_t type definition | expand

Message

Philippe Mathieu-Daudé Dec. 31, 2021, 11:48 a.m. UTC
Hi,

This series aims to clarify a bit the DMA API, in particular the
'size' argument which is not clear enough (as we use multiple types
for it). The clarification is trivial: add a dma_size_t typedef,
similar to the dma_addr_t one. This helps avoiding build failures
on 32-bit host [*] (and likely overflows calculation too IMO).

Some units using the DMA API are first removed from user-mode
emulation to avoid build failure (they shouldn't be there in
the first place).

Then some variables are renamed for clarity (no functional change).

Finally the dma_size_t typedef is added, and the previous patch
which failed on 32-bit host applied on top (not failing anymore).

Regards,

Phil.

[*] https://www.mail-archive.com/qemu-devel@nongnu.org/msg858825.html

Philippe Mathieu-Daudé (8):
  hw/nvram: Restrict stub to sysemu and tools
  hw/pci: Restrict pci-bus stub to sysemu
  hw/pci: Document pci_dma_map()
  hw/dma: Remove CONFIG_USER_ONLY check
  hw/rdma/rdma_utils: Rename rdma_pci_dma_map 'len' argument
  hw/scsi: Rename SCSIRequest::resid as 'residual'
  hw/dma: Introduce dma_size_t type definition
  hw/dma: Let dma_buf_read() / dma_buf_write() propagate MemTxResult

 hw/rdma/rdma_utils.h      |  4 +-
 include/hw/pci/pci.h      | 22 +++++++---
 include/hw/scsi/scsi.h    |  4 +-
 include/sysemu/dma.h      | 59 ++++++++++++++-------------
 hw/ide/ahci.c             | 10 ++---
 hw/nvme/ctrl.c            |  6 +--
 hw/nvram/fw_cfg.c         |  2 +-
 hw/rdma/rdma_utils.c      | 16 ++++----
 hw/rdma/vmw/pvrdma_main.c |  2 +-
 hw/scsi/lsi53c895a.c      |  4 +-
 hw/scsi/megasas.c         | 85 +++++++++++++++++++++++++++------------
 hw/scsi/scsi-bus.c        | 12 +++---
 hw/scsi/scsi-disk.c       |  4 +-
 hw/usb/libhw.c            |  4 +-
 softmmu/dma-helpers.c     | 38 ++++++++---------
 hw/nvram/meson.build      |  6 ++-
 hw/rdma/trace-events      |  2 +-
 stubs/meson.build         |  4 +-
 18 files changed, 164 insertions(+), 120 deletions(-)

Comments

Philippe Mathieu-Daudé Dec. 31, 2021, 11:51 a.m. UTC | #1
On 12/31/21 12:49, Philippe Mathieu-Daudé wrote:
> Since the previous commit, dma_buf_rw() returns a MemTxResult
> type. Do not discard it, return it to the caller.
> 
> Since both dma_buf_read/dma_buf_write functions were previously
> returning the QEMUSGList size not consumed, add an extra argument
> where the unconsummed size can be stored.
> 
> Update the few callers.
> 
> Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  include/hw/scsi/scsi.h |  2 +-
>  include/sysemu/dma.h   |  6 +++--
>  hw/ide/ahci.c          |  8 +++---
>  hw/nvme/ctrl.c         |  4 +--
>  hw/scsi/megasas.c      | 59 ++++++++++++++++++++++++++++++------------
>  hw/scsi/scsi-bus.c     |  6 +++--
>  softmmu/dma-helpers.c  | 18 +++++--------
>  7 files changed, 63 insertions(+), 40 deletions(-)
> 
> diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h
> index b27d133b113..1ffb367f94f 100644
> --- a/include/hw/scsi/scsi.h
> +++ b/include/hw/scsi/scsi.h
> @@ -30,7 +30,7 @@ struct SCSIRequest {
>      int16_t           status;
>      int16_t           host_status;
>      void              *hba_private;
> -    size_t            residual;
> +    uint64_t          residual;

Oops I forgot to mention this change since the previous version.

>      SCSICommand       cmd;
>      NotifierList      cancel_notifiers;
>  
> diff --git a/include/sysemu/dma.h b/include/sysemu/dma.h
> index 45a2567848c..77a346d5ed1 100644
> --- a/include/sysemu/dma.h
> +++ b/include/sysemu/dma.h
> @@ -303,8 +303,10 @@ BlockAIOCB *dma_blk_read(BlockBackend *blk,
>  BlockAIOCB *dma_blk_write(BlockBackend *blk,
>                            QEMUSGList *sg, uint64_t offset, uint32_t align,
>                            BlockCompletionFunc *cb, void *opaque);
> -uint64_t dma_buf_read(void *ptr, int32_t len, QEMUSGList *sg, MemTxAttrs attrs);
> -uint64_t dma_buf_write(void *ptr, int32_t len, QEMUSGList *sg, MemTxAttrs attrs);
> +MemTxResult dma_buf_read(void *ptr, dma_size_t len, dma_size_t *residual,
> +                         QEMUSGList *sg, MemTxAttrs attrs);
> +MemTxResult dma_buf_write(void *ptr, dma_size_t len, dma_size_t *residual,
> +                          QEMUSGList *sg, MemTxAttrs attrs);
>