From: Felix Fietkau <nbd@openwrt.org>
To: "Rafał Miłecki" <zajec5@gmail.com>
Cc: Network Development <netdev@vger.kernel.org>,
Hauke Mehrtens <hauke@hauke-m.de>
Subject: Re: [PATCH v6 4/9] bgmac: simplify/optimize rx DMA error handling
Date: Tue, 14 Apr 2015 11:13:49 +0200 [thread overview]
Message-ID: <552CDA4D.6080702@openwrt.org> (raw)
In-Reply-To: <CACna6ry7yD4jb2ph1EOvOrmdWiqOU8+yFQKvH0OCS=haH4dUqA@mail.gmail.com>
On 2015-04-14 07:55, Rafał Miłecki wrote:
> On 14 April 2015 at 01:42, Felix Fietkau <nbd@openwrt.org> wrote:
>> @@ -382,6 +382,19 @@ static void bgmac_dma_rx_setup_desc(struct bgmac *bgmac,
>> dma_desc->ctl1 = cpu_to_le32(ctl1);
>> }
>>
>> +static void bgmac_dma_rx_poison_buf(struct device *dma_dev,
>> + struct bgmac_slot_info *slot)
>> +{
>> + struct bgmac_rx_header *rx = slot->buf + BGMAC_RX_BUF_OFFSET;
>> +
>> + dma_sync_single_for_cpu(dma_dev, slot->dma_addr, BGMAC_RX_BUF_SIZE,
>> + DMA_FROM_DEVICE);
>> + rx->len = cpu_to_le16(0xdead);
>> + rx->flags = cpu_to_le16(0xdead);
>> + dma_sync_single_for_device(dma_dev, slot->dma_addr, BGMAC_RX_BUF_SIZE,
>> + DMA_FROM_DEVICE);
>> +}
>
> flags should be 0xbeef
Right.
>> @@ -404,51 +417,32 @@ static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring,
>> void *buf = slot->buf;
>> u16 len, flags;
>>
>> - /* Unmap buffer to make it accessible to the CPU */
>> - dma_sync_single_for_cpu(dma_dev, slot->dma_addr,
>> - BGMAC_RX_BUF_SIZE, DMA_FROM_DEVICE);
>> + do {
>> + /* Prepare new skb as replacement */
>> + if (bgmac_dma_rx_skb_for_slot(bgmac, slot)) {
>> + bgmac_dma_rx_poison_buf(dma_dev, slot);
>> + break;
>> + }
>
> So you just replaced slot->dma_addr with a mapping of new skb data.
>
>
>>
>> - /* Get info from the header */
>> - len = le16_to_cpu(rx->len);
>> - flags = le16_to_cpu(rx->flags);
>> + /* Unmap buffer to make it accessible to the CPU */
>> + dma_unmap_single(dma_dev, slot->dma_addr,
>> + BGMAC_RX_BUF_SIZE, DMA_FROM_DEVICE);
>
> Now you unmap the new sbk data instead of the old one you want to access.
> That's why the old code included old_dma_addr.
Stupid mistake, I should be more careful with late night coding ;)
>> @@ -528,14 +524,14 @@ static void bgmac_dma_rx_ring_free(struct bgmac *bgmac,
>>
>> for (i = 0; i < ring->num_slots; i++) {
>> slot = &ring->slots[i];
>> - if (!slot->buf)
>> + if (!slot->dma_addr)
>> continue;
>
> I think it breaks error path of bgmac_dma_alloc. It may happen that
> during DMA alloc we alloc skb and then we fail to map it. In such case
> buf should be freed. Please trace how bgmac_dma_free is used in
> bgmac_dma_alloc.
I don't think so: bgmac_dma_rx_skb_for_slot handles both buffer
allocation and dma mapping. If dma mapping fails, the buffer is freed
before any part of the slot is overwritten.
>> - if (slot->dma_addr)
>> - dma_unmap_single(dma_dev, slot->dma_addr,
>> - BGMAC_RX_BUF_SIZE,
>> - DMA_FROM_DEVICE);
>> + dma_unmap_single(dma_dev, slot->dma_addr,
>> + BGMAC_RX_BUF_SIZE,
>> + DMA_FROM_DEVICE);
>> put_page(virt_to_head_page(slot->buf));
>> + slot->dma_addr = 0;
>> }
>> }
- Felix
next prev parent reply other threads:[~2015-04-14 9:13 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-13 23:42 [PATCH v6 1/9] bgmac: simplify tx ring index handling Felix Fietkau
2015-04-13 23:42 ` [PATCH v6 2/9] bgmac: leave interrupts disabled as long as there is work to do Felix Fietkau
2015-04-14 5:40 ` Rafał Miłecki
2015-04-13 23:42 ` [PATCH v6 3/9] bgmac: set received skb headroom to NET_SKB_PAD Felix Fietkau
2015-04-13 23:42 ` [PATCH v6 4/9] bgmac: simplify/optimize rx DMA error handling Felix Fietkau
2015-04-14 5:55 ` Rafał Miłecki
2015-04-14 9:13 ` Felix Fietkau [this message]
2015-04-14 9:19 ` Rafał Miłecki
2015-04-14 9:26 ` Felix Fietkau
2015-04-14 9:32 ` Rafał Miłecki
2015-04-14 9:37 ` Rafał Miłecki
2015-04-13 23:42 ` [PATCH v6 5/9] bgmac: add check for oversized packets Felix Fietkau
2015-04-14 5:56 ` Rafał Miłecki
2015-04-13 23:42 ` [PATCH v6 6/9] bgmac: increase rx ring size from 511 to 512 Felix Fietkau
2015-04-14 5:57 ` Rafał Miłecki
2015-04-13 23:42 ` [PATCH v6 7/9] bgmac: simplify dma init/cleanup Felix Fietkau
2015-04-14 7:24 ` Rafał Miłecki
2015-04-13 23:42 ` [PATCH v6 8/9] bgmac: fix DMA rx corruption Felix Fietkau
2015-04-13 23:42 ` [PATCH v6 9/9] bgmac: drop ring->num_slots Felix Fietkau
2015-04-14 6:38 ` Rafał Miłecki
2015-04-14 5:38 ` [PATCH v6 1/9] bgmac: simplify tx ring index handling Rafał Miłecki
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=552CDA4D.6080702@openwrt.org \
--to=nbd@openwrt.org \
--cc=hauke@hauke-m.de \
--cc=netdev@vger.kernel.org \
--cc=zajec5@gmail.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).