From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Akihiko Odaki <akihiko.odaki@daynix.com>
Cc: "Sriram Yagnaraman" <sriram.yagnaraman@est.tech>,
"Jason Wang" <jasowang@redhat.com>,
"Dmitry Fleytman" <dmitry.fleytman@gmail.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Thomas Huth" <thuth@redhat.com>,
"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
"Beraldo Leal" <bleal@redhat.com>,
"Cleber Rosa" <crosa@redhat.com>,
"Laurent Vivier" <lvivier@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
qemu-devel@nongnu.org,
"Tomasz Dzieciol" <t.dzieciol@partner.samsung.com>
Subject: Re: [PATCH v2 01/41] hw/net/net_tx_pkt: Decouple implementation from PCI
Date: Thu, 20 Apr 2023 11:46:09 +0200 [thread overview]
Message-ID: <c28bd26b-1451-4363-f7c8-585067a2d599@linaro.org> (raw)
In-Reply-To: <20230420054657.50367-2-akihiko.odaki@daynix.com>
Hi Akihiko,
On 20/4/23 07:46, Akihiko Odaki wrote:
> This is intended to be followed by another change for the interface.
> It also fixes the leak of memory mapping when the specified memory is
> partially mapped.
>
> Fixes: e263cd49c7 ("Packet abstraction for VMWARE network devices")
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> ---
> hw/net/net_tx_pkt.h | 9 ++++++++
> hw/net/net_tx_pkt.c | 53 ++++++++++++++++++++++++++++-----------------
> 2 files changed, 42 insertions(+), 20 deletions(-)
>
> diff --git a/hw/net/net_tx_pkt.h b/hw/net/net_tx_pkt.h
> index e5ce6f20bc..5eb123ef90 100644
> --- a/hw/net/net_tx_pkt.h
> +++ b/hw/net/net_tx_pkt.h
> @@ -153,6 +153,15 @@ void net_tx_pkt_dump(struct NetTxPkt *pkt);
> */
> void net_tx_pkt_reset(struct NetTxPkt *pkt, PCIDevice *dev);
>
> +/**
> + * Unmap a fragment mapped from a PCI device.
> + *
> + * @context: PCI device owning fragment
Per your description ...
> + * @base: pointer to fragment
> + * @len: length of fragment
> + */
> +void net_tx_pkt_unmap_frag_pci(void *context, void *base, size_t len);
... we can directly use the stricter 'PCIDevice *dev'.
> /**
> * Send packet to qemu. handles sw offloads if vhdr is not supported.
> *
> diff --git a/hw/net/net_tx_pkt.c b/hw/net/net_tx_pkt.c
> index 8dc8568ba2..aca12ff035 100644
> --- a/hw/net/net_tx_pkt.c
> +++ b/hw/net/net_tx_pkt.c
> @@ -384,10 +384,9 @@ void net_tx_pkt_setup_vlan_header_ex(struct NetTxPkt *pkt,
> }
> }
>
> -bool net_tx_pkt_add_raw_fragment(struct NetTxPkt *pkt, hwaddr pa,
> - size_t len)
> +static bool net_tx_pkt_add_raw_fragment_common(struct NetTxPkt *pkt,
> + void *base, size_t len)
> {
> - hwaddr mapped_len = 0;
> struct iovec *ventry;
> assert(pkt);
>
> @@ -395,23 +394,12 @@ bool net_tx_pkt_add_raw_fragment(struct NetTxPkt *pkt, hwaddr pa,
> return false;
> }
>
> - if (!len) {
> - return true;
> - }
> -
> ventry = &pkt->raw[pkt->raw_frags];
> - mapped_len = len;
> + ventry->iov_base = base;
> + ventry->iov_len = len;
> + pkt->raw_frags++;
>
> - ventry->iov_base = pci_dma_map(pkt->pci_dev, pa,
> - &mapped_len, DMA_DIRECTION_TO_DEVICE);
> -
> - if ((ventry->iov_base != NULL) && (len == mapped_len)) {
> - ventry->iov_len = mapped_len;
> - pkt->raw_frags++;
> - return true;
> - } else {
> - return false;
> - }
> + return true;
> }
>
> bool net_tx_pkt_has_fragments(struct NetTxPkt *pkt)
> @@ -465,8 +453,9 @@ void net_tx_pkt_reset(struct NetTxPkt *pkt, PCIDevice *pci_dev)
> assert(pkt->raw);
> for (i = 0; i < pkt->raw_frags; i++) {
> assert(pkt->raw[i].iov_base);
> - pci_dma_unmap(pkt->pci_dev, pkt->raw[i].iov_base,
> - pkt->raw[i].iov_len, DMA_DIRECTION_TO_DEVICE, 0);
> + net_tx_pkt_unmap_frag_pci(pkt->pci_dev,
> + pkt->raw[i].iov_base,
> + pkt->raw[i].iov_len);
> }
> }
> pkt->pci_dev = pci_dev;
> @@ -476,6 +465,30 @@ void net_tx_pkt_reset(struct NetTxPkt *pkt, PCIDevice *pci_dev)
> pkt->l4proto = 0;
> }
>
> +void net_tx_pkt_unmap_frag_pci(void *context, void *base, size_t len)
So net_tx_pkt_unmap_frag_pci(PCIDevice *dev, ...)
> +{
> + pci_dma_unmap(context, base, len, DMA_DIRECTION_TO_DEVICE, 0);
> +}
> +
> +bool net_tx_pkt_add_raw_fragment(struct NetTxPkt *pkt, hwaddr pa,
It seems other hw/net/ models use (dma_addr_t addr, dma_addr_t len).
Similarly does the pci_dma_FOO() API.
> + size_t len)
> +{
> + dma_addr_t mapped_len = len;
See, here you use dma_addr_t.
> + void *base = pci_dma_map(pkt->pci_dev, pa, &mapped_len,
> + DMA_DIRECTION_TO_DEVICE);
> + if (!base) {
> + return false;
> + }
> +
> + if (mapped_len != len ||
> + !net_tx_pkt_add_raw_fragment_common(pkt, base, len)) {
> + net_tx_pkt_unmap_frag_pci(pkt->pci_dev, base, mapped_len);
> + return false;
> + }
> +
> + return true;
> +}
> +
> static void net_tx_pkt_do_sw_csum(struct NetTxPkt *pkt,
> struct iovec *iov, uint32_t iov_len,
> uint16_t csl)
next prev parent reply other threads:[~2023-04-20 9:47 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-20 5:46 [PATCH v2 00/41] igb: Fix for DPDK Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 01/41] hw/net/net_tx_pkt: Decouple implementation from PCI Akihiko Odaki
2023-04-20 9:46 ` Philippe Mathieu-Daudé [this message]
2023-04-20 17:25 ` Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 02/41] hw/net/net_tx_pkt: Decouple interface " Akihiko Odaki
2023-04-20 9:54 ` Philippe Mathieu-Daudé
2023-04-20 17:33 ` Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 03/41] e1000x: Fix BPRC and MPRC Akihiko Odaki
2023-04-20 16:22 ` Sriram Yagnaraman
2023-04-20 5:46 ` [PATCH v2 04/41] igb: Fix Rx packet type encoding Akihiko Odaki
2023-04-20 16:22 ` Sriram Yagnaraman
2023-04-20 5:46 ` [PATCH v2 05/41] igb: Do not require CTRL.VME for tx VLAN tagging Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 06/41] net/net_rx_pkt: Use iovec for net_rx_pkt_set_protocols() Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 07/41] e1000e: Always copy ethernet header Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 08/41] igb: " Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 09/41] Fix references to igb Avocado test Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 10/41] tests/avocado: Remove unused imports Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 11/41] tests/avocado: Remove test_igb_nomsi_kvm Akihiko Odaki
2023-04-20 7:23 ` Thomas Huth
2023-04-20 17:42 ` Alex Bennée
2023-04-20 5:46 ` [PATCH v2 12/41] hw/net/net_tx_pkt: Remove net_rx_pkt_get_l4_info Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 13/41] net/eth: Rename eth_setup_vlan_headers_ex Akihiko Odaki
2023-04-20 9:55 ` Philippe Mathieu-Daudé
2023-04-20 5:46 ` [PATCH v2 14/41] e1000x: Share more Rx filtering logic Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 15/41] e1000x: Take CRC into consideration for size check Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 16/41] e1000x: Rename TcpIpv6 into TcpIpv6Ex Akihiko Odaki
2023-04-20 16:22 ` Sriram Yagnaraman
2023-04-20 17:36 ` Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 17/41] e1000e: Always log status after building rx metadata Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 18/41] igb: " Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 19/41] igb: Remove goto Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 20/41] igb: Read DCMD.VLE of the first Tx descriptor Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 21/41] e1000e: Reset packet state after emptying Tx queue Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 22/41] vmxnet3: " Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 23/41] igb: Add more definitions for Tx descriptor Akihiko Odaki
2023-04-20 16:22 ` Sriram Yagnaraman
2023-04-20 5:46 ` [PATCH v2 24/41] igb: Share common VF constants Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 25/41] igb: Fix igb_mac_reg_init coding style alignment Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 26/41] net/eth: Use void pointers Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 27/41] net/eth: Always add VLAN tag Akihiko Odaki
2023-04-20 16:22 ` Sriram Yagnaraman
2023-04-20 17:38 ` Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 28/41] hw/net/net_rx_pkt: Enforce alignment for eth_header Akihiko Odaki
2023-04-20 16:22 ` Sriram Yagnaraman
2023-04-20 5:46 ` [PATCH v2 29/41] tests/qtest/libqos/igb: Set GPIE.Multiple_MSIX Akihiko Odaki
2023-04-20 16:22 ` Sriram Yagnaraman
2023-04-20 5:46 ` [PATCH v2 30/41] igb: Implement MSI-X single vector mode Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 31/41] igb: Use UDP for RSS hash Akihiko Odaki
2023-04-20 16:22 ` Sriram Yagnaraman
2023-04-20 5:46 ` [PATCH v2 32/41] igb: Implement Rx SCTP CSO Akihiko Odaki
2023-04-20 16:22 ` Sriram Yagnaraman
2023-04-20 17:56 ` Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 33/41] igb: Implement Tx " Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 34/41] igb: Strip the second VLAN tag for extended VLAN Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 35/41] igb: Filter with " Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 36/41] igb: Implement igb-specific oversize check Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 37/41] igb: Implement Rx PTP2 timestamp Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 38/41] igb: Implement Tx timestamp Akihiko Odaki
2023-04-20 16:22 ` Sriram Yagnaraman
2023-04-20 5:46 ` [PATCH v2 39/41] vmxnet3: Do not depend on PC Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 40/41] MAINTAINERS: Add a reviewer for network packet abstractions Akihiko Odaki
2023-04-20 5:46 ` [PATCH v2 41/41] docs/system/devices/igb: Note igb is tested for DPDK Akihiko Odaki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c28bd26b-1451-4363-f7c8-585067a2d599@linaro.org \
--to=philmd@linaro.org \
--cc=akihiko.odaki@daynix.com \
--cc=alex.bennee@linaro.org \
--cc=bleal@redhat.com \
--cc=crosa@redhat.com \
--cc=dmitry.fleytman@gmail.com \
--cc=jasowang@redhat.com \
--cc=lvivier@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sriram.yagnaraman@est.tech \
--cc=t.dzieciol@partner.samsung.com \
--cc=thuth@redhat.com \
--cc=wainersm@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).