From nobody Mon Feb 9 19:47:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1640260659; cv=none; d=zohomail.com; s=zohoarc; b=Yra8yuui+po5UP6KGsRxE3Tjf7LaZGIyX6oy1hPMNkJg8HJbYFbNeUkXKRGXAaRrcbxYwmbDl15O1UbLYACag0xrMJ0RmcR11HgWPt6pBaYgYTv4lHIZ2ga7Ze12OPr2Yg6X67BA55jW2zc9q3ary08gHH+jB+EKuaVjBRohcjM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640260659; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=JlHtEDNchl3mn6IN4VTMeHX5PZJU77q/cfu6ijIqzmY=; b=EG3MfQUvjYEtDTCGPqxqnE/0MkrZcm2cV/OpIGUjbcPuv3//SIE7JyfriC2JT0VrYITV3R4Y6pEW6XqPJJ6F3hS0XNLxC7yYcqojJlhDlhHgOCESjqSlKFOf9WLW9yc8Eb0ouZYD8g3uYhPYW5T2t+jStqWcibm68HIslgt1ZKY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1640260659453394.72103003999064; Thu, 23 Dec 2021 03:57:39 -0800 (PST) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-379-NXhptVnuMbGDm7CV4msyZw-1; Thu, 23 Dec 2021 06:57:37 -0500 Received: by mail-wm1-f71.google.com with SMTP id o18-20020a05600c511200b00345c1603997so549460wms.1 for ; Thu, 23 Dec 2021 03:57:37 -0800 (PST) Return-Path: Return-Path: Received: from x1w.. (33.red-193-152-124.dynamicip.rima-tde.net. [193.152.124.33]) by smtp.gmail.com with ESMTPSA id s8sm5491683wra.9.2021.12.23.03.57.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Dec 2021 03:57:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1640260658; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JlHtEDNchl3mn6IN4VTMeHX5PZJU77q/cfu6ijIqzmY=; b=hJQmQWIbMWu3N663X0PbGStwVaN3HU8ZAAJWyhhtks+XQf2AMV1++xLZ+rE1pLUM8pbReR /rkQhJIpPQCsTYOzgfBbOObbLtUAzKNDGoSqUorTgXYn/3xNWS9Pul2FqtKn7kcrIjt5Z1 GSvbLFX9gByUjUabFDI/Uw9YrJECTq4= X-MC-Unique: NXhptVnuMbGDm7CV4msyZw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JlHtEDNchl3mn6IN4VTMeHX5PZJU77q/cfu6ijIqzmY=; b=lD3CVBZZA7Gw949FupqWPp7YztcMCjC2Rw+ga2OAaVJ1hzu674Lk9vKJyI2X3yoxb0 QS4SwMrzW77R92VjK0RxKi4y4cUWn4N7xGV2BLkDrRPGjNU8F5bPbmdJzIZuiMzVwTN/ w57m6wtYL9ncvDcByO80hBA4SnRKjqHFcn4pGsLm3EYWRf5n96nryy6e1gQCQ0H4cqm4 ObMdDXBNCWoEXCANf3KisfGnVeObqWtj/J+3Pn3Vl3mdiaPyQERM6yrkG3H6r07RmhdR hECvM0X1mLRSDXGw2hl0UWqJORetIjPO9y9v747nC18QST54n1YVqzxPjetNUBpChXN/ 4zDA== X-Gm-Message-State: AOAM531DJgrhdxqAJDRSHeZmXm3KR7i+UU/Fwp3jpsjbJS54W3fPW52Z ydAQ8ind9IaQ3k18yTjHqGJ2i7MClkDUN/PrtqYsoIsupTtTk9Camhl5QJvXdsRfYjoaVemK8/z gvNL3SvlyQ/N2IA== X-Received: by 2002:a05:6000:1ac9:: with SMTP id i9mr1470548wry.531.1640260656013; Thu, 23 Dec 2021 03:57:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJz2odW8+cHbNw40desh9u11A2zmSKk2WtuGp/wX3MfWh5yu32srGB6BOu1wbMWVJtpX+ZACyQ== X-Received: by 2002:a05:6000:1ac9:: with SMTP id i9mr1470497wry.531.1640260655713; Thu, 23 Dec 2021 03:57:35 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Joel Stanley , Richard Henderson , qemu-block@nongnu.org, Jason Wang , Keith Busch , "Michael S. Tsirkin" , Fam Zheng , Alistair Francis , David Hildenbrand , Eduardo Habkost , Havard Skinnemoen , Sven Schnelle , Tyrone Ting , Gerd Hoffmann , Peter Maydell , Beniamino Galvani , Daniel Henrique Barboza , Dmitry Fleytman , John Snow , Bin Meng , Greg Kurz , Eric Auger , Mark Cave-Ayland , "Edgar E. Iglesias" , Andrew Jeffery , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Andrew Baumann , Hannes Reinecke , Paolo Bonzini , Peter Xu , qemu-arm@nongnu.org, Klaus Jensen , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-ppc@nongnu.org, Jan Kiszka , David Gibson , Li Qiang , "Edgar E . Iglesias" , Stefan Hajnoczi Subject: [PATCH v2 06/23] dma: Let dma_memory_map() take MemTxAttrs argument Date: Thu, 23 Dec 2021 12:55:37 +0100 Message-Id: <20211223115554.3155328-7-philmd@redhat.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211223115554.3155328-1-philmd@redhat.com> References: <20211223115554.3155328-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1640260660032100001 Let devices specify transaction attributes when calling dma_memory_map(). Patch created mechanically using spatch with this script: @@ expression E1, E2, E3, E4; @@ - dma_memory_map(E1, E2, E3, E4) + dma_memory_map(E1, E2, E3, E4, MEMTXATTRS_UNSPECIFIED) Reviewed-by: Richard Henderson Reviewed-by: Li Qiang Reviewed-by: Edgar E. Iglesias Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Stefan Hajnoczi Message-Id: <20210702092439.989969-7-philmd@redhat.com> --- include/hw/pci/pci.h | 3 ++- include/sysemu/dma.h | 5 +++-- hw/display/virtio-gpu.c | 10 ++++++---- hw/hyperv/vmbus.c | 8 +++++--- hw/ide/ahci.c | 8 +++++--- hw/usb/libhw.c | 3 ++- hw/virtio/virtio.c | 6 ++++-- softmmu/dma-helpers.c | 3 ++- 8 files changed, 29 insertions(+), 17 deletions(-) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 4383f1c95e0..1acefc2a4c3 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -875,7 +875,8 @@ static inline void *pci_dma_map(PCIDevice *dev, dma_add= r_t addr, { void *buf; =20 - buf =3D dma_memory_map(pci_get_address_space(dev), addr, plen, dir); + buf =3D dma_memory_map(pci_get_address_space(dev), addr, plen, dir, + MEMTXATTRS_UNSPECIFIED); return buf; } =20 diff --git a/include/sysemu/dma.h b/include/sysemu/dma.h index 522682bf386..97ff6f29f8c 100644 --- a/include/sysemu/dma.h +++ b/include/sysemu/dma.h @@ -202,16 +202,17 @@ MemTxResult dma_memory_set(AddressSpace *as, dma_addr= _t addr, * @addr: address within that address space * @len: pointer to length of buffer; updated on return * @dir: indicates the transfer direction + * @attrs: memory attributes */ static inline void *dma_memory_map(AddressSpace *as, dma_addr_t addr, dma_addr_t *len, - DMADirection dir) + DMADirection dir, MemTxAttrs attrs) { hwaddr xlen =3D *len; void *p; =20 p =3D address_space_map(as, addr, &xlen, dir =3D=3D DMA_DIRECTION_FROM= _DEVICE, - MEMTXATTRS_UNSPECIFIED); + attrs); *len =3D xlen; return p; } diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index d78b9700c7d..c6dc818988c 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -814,8 +814,9 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g, =20 do { len =3D l; - map =3D dma_memory_map(VIRTIO_DEVICE(g)->dma_as, - a, &len, DMA_DIRECTION_TO_DEVICE); + map =3D dma_memory_map(VIRTIO_DEVICE(g)->dma_as, a, &len, + DMA_DIRECTION_TO_DEVICE, + MEMTXATTRS_UNSPECIFIED); if (!map) { qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to map MMIO mem= ory for" " element %d\n", __func__, e); @@ -1252,8 +1253,9 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque,= size_t size, for (i =3D 0; i < res->iov_cnt; i++) { hwaddr len =3D res->iov[i].iov_len; res->iov[i].iov_base =3D - dma_memory_map(VIRTIO_DEVICE(g)->dma_as, - res->addrs[i], &len, DMA_DIRECTION_TO_DEVIC= E); + dma_memory_map(VIRTIO_DEVICE(g)->dma_as, res->addrs[i], &l= en, + DMA_DIRECTION_TO_DEVICE, + MEMTXATTRS_UNSPECIFIED); =20 if (!res->iov[i].iov_base || len !=3D res->iov[i].iov_len) { /* Clean up the half-a-mapping we just created... */ diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c index dbce3b35fba..8aad29f1bb2 100644 --- a/hw/hyperv/vmbus.c +++ b/hw/hyperv/vmbus.c @@ -373,7 +373,8 @@ static ssize_t gpadl_iter_io(GpadlIter *iter, void *buf= , uint32_t len) =20 maddr =3D (iter->gpadl->gfns[idx] << TARGET_PAGE_BITS) | off_i= n_page; =20 - iter->map =3D dma_memory_map(iter->as, maddr, &mlen, iter->dir= ); + iter->map =3D dma_memory_map(iter->as, maddr, &mlen, iter->dir, + MEMTXATTRS_UNSPECIFIED); if (mlen !=3D pgleft) { dma_memory_unmap(iter->as, iter->map, mlen, iter->dir, 0); iter->map =3D NULL; @@ -490,7 +491,8 @@ int vmbus_map_sgl(VMBusChanReq *req, DMADirection dir, = struct iovec *iov, goto err; } =20 - iov[ret_cnt].iov_base =3D dma_memory_map(sgl->as, a, &l, dir); + iov[ret_cnt].iov_base =3D dma_memory_map(sgl->as, a, &l, dir, + MEMTXATTRS_UNSPECIFIED); if (!l) { ret =3D -EFAULT; goto err; @@ -566,7 +568,7 @@ static vmbus_ring_buffer *ringbuf_map_hdr(VMBusRingBufC= ommon *ringbuf) dma_addr_t mlen =3D sizeof(*rb); =20 rb =3D dma_memory_map(ringbuf->as, ringbuf->rb_addr, &mlen, - DMA_DIRECTION_FROM_DEVICE); + DMA_DIRECTION_FROM_DEVICE, MEMTXATTRS_UNSPECIFIED); if (mlen !=3D sizeof(*rb)) { dma_memory_unmap(ringbuf->as, rb, mlen, DMA_DIRECTION_FROM_DEVICE, 0); diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index a94c6e26fb0..8e77ddb660f 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -249,7 +249,8 @@ static void map_page(AddressSpace *as, uint8_t **ptr, u= int64_t addr, dma_memory_unmap(as, *ptr, len, DMA_DIRECTION_FROM_DEVICE, len); } =20 - *ptr =3D dma_memory_map(as, addr, &len, DMA_DIRECTION_FROM_DEVICE); + *ptr =3D dma_memory_map(as, addr, &len, DMA_DIRECTION_FROM_DEVICE, + MEMTXATTRS_UNSPECIFIED); if (len < wanted && *ptr) { dma_memory_unmap(as, *ptr, len, DMA_DIRECTION_FROM_DEVICE, len); *ptr =3D NULL; @@ -939,7 +940,8 @@ static int ahci_populate_sglist(AHCIDevice *ad, QEMUSGL= ist *sglist, =20 /* map PRDT */ if (!(prdt =3D dma_memory_map(ad->hba->as, prdt_addr, &prdt_len, - DMA_DIRECTION_TO_DEVICE))){ + DMA_DIRECTION_TO_DEVICE, + MEMTXATTRS_UNSPECIFIED))){ trace_ahci_populate_sglist_no_map(ad->hba, ad->port_no); return -1; } @@ -1301,7 +1303,7 @@ static int handle_cmd(AHCIState *s, int port, uint8_t= slot) tbl_addr =3D le64_to_cpu(cmd->tbl_addr); cmd_len =3D 0x80; cmd_fis =3D dma_memory_map(s->as, tbl_addr, &cmd_len, - DMA_DIRECTION_TO_DEVICE); + DMA_DIRECTION_TO_DEVICE, MEMTXATTRS_UNSPECIFI= ED); if (!cmd_fis) { trace_handle_cmd_badfis(s, port); return -1; diff --git a/hw/usb/libhw.c b/hw/usb/libhw.c index 9c33a1640f7..f350eae443d 100644 --- a/hw/usb/libhw.c +++ b/hw/usb/libhw.c @@ -36,7 +36,8 @@ int usb_packet_map(USBPacket *p, QEMUSGList *sgl) =20 while (len) { dma_addr_t xlen =3D len; - mem =3D dma_memory_map(sgl->as, base, &xlen, dir); + mem =3D dma_memory_map(sgl->as, base, &xlen, dir, + MEMTXATTRS_UNSPECIFIED); if (!mem) { goto err; } diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index ea7c079fb04..e11a8a0dbab 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1306,7 +1306,8 @@ static bool virtqueue_map_desc(VirtIODevice *vdev, un= signed int *p_num_sg, iov[num_sg].iov_base =3D dma_memory_map(vdev->dma_as, pa, &len, is_write ? DMA_DIRECTION_FROM_DEVICE : - DMA_DIRECTION_TO_DEVICE); + DMA_DIRECTION_TO_DEVICE, + MEMTXATTRS_UNSPECIFIED); if (!iov[num_sg].iov_base) { virtio_error(vdev, "virtio: bogus descriptor or out of resourc= es"); goto out; @@ -1355,7 +1356,8 @@ static void virtqueue_map_iovec(VirtIODevice *vdev, s= truct iovec *sg, sg[i].iov_base =3D dma_memory_map(vdev->dma_as, addr[i], &len, is_write ? DMA_DIRECTION_FROM_DEVICE : - DMA_DIRECTION_TO_DEVICE); + DMA_DIRECTION_TO_DEVICE, + MEMTXATTRS_UNSPECIFIED); if (!sg[i].iov_base) { error_report("virtio: error trying to map MMIO memory"); exit(1); diff --git a/softmmu/dma-helpers.c b/softmmu/dma-helpers.c index 5bf76fff6bd..3c06a2feddd 100644 --- a/softmmu/dma-helpers.c +++ b/softmmu/dma-helpers.c @@ -143,7 +143,8 @@ static void dma_blk_cb(void *opaque, int ret) while (dbs->sg_cur_index < dbs->sg->nsg) { cur_addr =3D dbs->sg->sg[dbs->sg_cur_index].base + dbs->sg_cur_byt= e; cur_len =3D dbs->sg->sg[dbs->sg_cur_index].len - dbs->sg_cur_byte; - mem =3D dma_memory_map(dbs->sg->as, cur_addr, &cur_len, dbs->dir); + mem =3D dma_memory_map(dbs->sg->as, cur_addr, &cur_len, dbs->dir, + MEMTXATTRS_UNSPECIFIED); /* * Make reads deterministic in icount mode. Windows sometimes issu= es * disk read requests with overlapping SGs. It leads --=20 2.33.1