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 v4 1/9] bgmac: simplify tx ring index handling
Date: Mon, 13 Apr 2015 17:01:02 +0200 [thread overview]
Message-ID: <552BDA2E.3060909@openwrt.org> (raw)
In-Reply-To: <CACna6rxeBNuSq8OJTBH1Yr75o79q9CDqc2JTW4=kEk+HQt5JRg@mail.gmail.com>
On 2015-04-13 16:21, Rafał Miłecki wrote:
>> @@ -158,13 +157,7 @@ static netdev_tx_t bgmac_dma_tx_add(struct bgmac *bgmac,
>> skb_checksum_help(skb);
>>
>> nr_frags = skb_shinfo(skb)->nr_frags;
>> -
>> - if (ring->start <= ring->end)
>> - free_slots = ring->start - ring->end + BGMAC_TX_RING_SLOTS;
>> - else
>> - free_slots = ring->start - ring->end;
>> -
>> - if (free_slots <= nr_frags + 1) {
>> + if (ring->end - ring->start + nr_frags + 1 >= BGMAC_TX_RING_SLOTS) {
>> bgmac_err(bgmac, "TX ring is full, queue should be stopped!\n");
>> netif_stop_queue(net_dev);
>> return NETDEV_TX_BUSY;
>
> How is this going to work with ring->end lower than ring->start? Let's
> say you have 2 empty slots at the end of ring and 2 empty slots at the
> beginning. In total 4 free slots. Doing ring->end - ring->start will
> give you some big negative number (depending on the ring size), won't
> it?
It won't, because the resulting data type is limited to 32 bit. I'm
pretty sure there are other places in the kernel that rely on the same
behavior.
>> @@ -284,10 +276,8 @@ static void bgmac_dma_tx_free(struct bgmac *bgmac, struct bgmac_dma_ring *ring)
>> slot->skb = NULL;
>> }
>>
>> -next:
>> slot->dma_addr = 0;
>> - if (++ring->start >= BGMAC_TX_RING_SLOTS)
>> - ring->start = 0;
>> + ring->start++;
>> freed = true;
>> }
>>
>
> Do I understand correctly you're using u32 overflow here? Is this
> OK/allowed in kernel to knowingly use overflows?
I think so.
>> diff --git a/drivers/net/ethernet/broadcom/bgmac.h b/drivers/net/ethernet/broadcom/bgmac.h
>> index 3ad965f..5a198d5 100644
>> --- a/drivers/net/ethernet/broadcom/bgmac.h
>> +++ b/drivers/net/ethernet/broadcom/bgmac.h
>> @@ -414,10 +414,10 @@ enum bgmac_dma_ring_type {
>> * empty.
>> */
>> struct bgmac_dma_ring {
>> - u16 num_slots;
>> - u16 start;
>> - u16 end;
>> + u32 start;
>> + u32 end;
>>
>> + u16 num_slots;
>> u16 mmio_base;
>> struct bgmac_dma_desc *cpu_base;
>> dma_addr_t dma_base;
>
> Any reason for u32 instead of u16?
To avoid writes touching other fields close to it.
- Felix
next prev parent reply other threads:[~2015-04-13 15:01 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-13 13:52 [PATCH v4 1/9] bgmac: simplify tx ring index handling Felix Fietkau
2015-04-13 13:52 ` [PATCH v4 2/9] bgmac: leave interrupts disabled as long as there is work to do Felix Fietkau
2015-04-13 14:34 ` Rafał Miłecki
2015-04-13 15:03 ` Felix Fietkau
2015-04-13 15:06 ` Rafał Miłecki
2015-04-13 15:44 ` Felix Fietkau
2015-04-13 16:35 ` Rafał Miłecki
2015-04-13 13:52 ` [PATCH v4 3/9] bgmac: set received skb headroom to NET_SKB_PAD Felix Fietkau
2015-04-13 13:52 ` [PATCH v4 4/9] bgmac: simplify rx DMA error handling Felix Fietkau
2015-04-13 14:53 ` Rafał Miłecki
2015-04-13 15:05 ` Felix Fietkau
2015-04-13 13:52 ` [PATCH v4 5/9] bgmac: add check for oversized packets Felix Fietkau
2015-04-13 13:52 ` [PATCH v4 6/9] bgmac: increase rx ring size from 511 to 512 Felix Fietkau
2015-04-13 13:52 ` [PATCH v4 7/9] bgmac: simplify dma init/cleanup Felix Fietkau
2015-04-13 13:52 ` [PATCH v4 8/9] bgmac: fix DMA rx corruption Felix Fietkau
2015-04-13 13:52 ` [PATCH v4 9/9] bgmac: drop ring->num_slots Felix Fietkau
2015-04-13 14:21 ` [PATCH v4 1/9] bgmac: simplify tx ring index handling Rafał Miłecki
2015-04-13 15:01 ` Felix Fietkau [this message]
2015-04-13 18:05 ` 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=552BDA2E.3060909@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.