Patchwork bgmac: fix unaligned accesses to network headers

login
register
mail settings
Submitter Hauke Mehrtens
Date Feb. 16, 2013, 2:32 p.m.
Message ID <1361025154-11612-1-git-send-email-hauke@hauke-m.de>
Download mbox | patch
Permalink /patch/220961/
State Changes Requested
Delegated to: David Miller
Headers show

Comments

Hauke Mehrtens - Feb. 16, 2013, 2:32 p.m.
Without this patch I get many unaligned access warnings per packet,
this patches fixes them all. This should improve performance ony some
systems like mips.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
 drivers/net/ethernet/broadcom/bgmac.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
stephen hemminger - Feb. 16, 2013, 6:36 p.m.
On Sat, 16 Feb 2013 15:32:34 +0100
Hauke Mehrtens <hauke@hauke-m.de> wrote:

> Without this patch I get many unaligned access warnings per packet,
> this patches fixes them all. This should improve performance ony some
> systems like mips.
> 
> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
> ---
>  drivers/net/ethernet/broadcom/bgmac.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c
> index d341090..f9b1bc8 100644
> --- a/drivers/net/ethernet/broadcom/bgmac.c
> +++ b/drivers/net/ethernet/broadcom/bgmac.c
> @@ -301,8 +301,9 @@ static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring,
>  			bgmac_err(bgmac, "Found poisoned packet at slot %d, DMA issue!\n",
>  				  ring->start);
>  		} else {
> -			new_skb = netdev_alloc_skb(bgmac->net_dev, len);
> +			new_skb = netdev_alloc_skb(bgmac->net_dev, len + 2);
>  			if (new_skb) {
> +				skb_reserve(new_skb, 2);
>  				skb_put(new_skb, len);
>  				skb_copy_from_linear_data_offset(skb, BGMAC_RX_FRAME_OFFSET,
>  								 new_skb->data,

NAK. Use netdev_alloc_skb_ip_align instead. 
It is less error prone, and handles case of architectures where unaligned is faster.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Hauke Mehrtens - Feb. 16, 2013, 7:01 p.m.
On 02/16/2013 07:36 PM, Stephen Hemminger wrote:
> On Sat, 16 Feb 2013 15:32:34 +0100
> Hauke Mehrtens <hauke@hauke-m.de> wrote:
> 
>> Without this patch I get many unaligned access warnings per packet,
>> this patches fixes them all. This should improve performance ony some
>> systems like mips.
>>
>> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
>> ---
>>  drivers/net/ethernet/broadcom/bgmac.c |    3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c
>> index d341090..f9b1bc8 100644
>> --- a/drivers/net/ethernet/broadcom/bgmac.c
>> +++ b/drivers/net/ethernet/broadcom/bgmac.c
>> @@ -301,8 +301,9 @@ static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring,
>>  			bgmac_err(bgmac, "Found poisoned packet at slot %d, DMA issue!\n",
>>  				  ring->start);
>>  		} else {
>> -			new_skb = netdev_alloc_skb(bgmac->net_dev, len);
>> +			new_skb = netdev_alloc_skb(bgmac->net_dev, len + 2);
>>  			if (new_skb) {
>> +				skb_reserve(new_skb, 2);
>>  				skb_put(new_skb, len);
>>  				skb_copy_from_linear_data_offset(skb, BGMAC_RX_FRAME_OFFSET,
>>  								 new_skb->data,
> 
> NAK. Use netdev_alloc_skb_ip_align instead. 
> It is less error prone, and handles case of architectures where unaligned is faster.

Thanks for the hint, I will send a better version of this patch.

Hauke
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Rafał Miłecki - Feb. 18, 2013, 4:14 p.m.
2013/2/16 Hauke Mehrtens <hauke@hauke-m.de>:
> Without this patch I get many unaligned access warnings per packet,
> this patches fixes them all. This should improve performance ony some
> systems like mips.
>
> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
> ---
>  drivers/net/ethernet/broadcom/bgmac.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c
> index d341090..f9b1bc8 100644
> --- a/drivers/net/ethernet/broadcom/bgmac.c
> +++ b/drivers/net/ethernet/broadcom/bgmac.c
> @@ -301,8 +301,9 @@ static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring,
>                         bgmac_err(bgmac, "Found poisoned packet at slot %d, DMA issue!\n",
>                                   ring->start);
>                 } else {
> -                       new_skb = netdev_alloc_skb(bgmac->net_dev, len);
> +                       new_skb = netdev_alloc_skb(bgmac->net_dev, len + 2);
>                         if (new_skb) {
> +                               skb_reserve(new_skb, 2);

I never understood that code in b44, glad you hit that warnings! ;)

The version with netdev_alloc_skb_ip_align looks much better (no more
magic numbers), b44 should be converted too.

Thanks for your patch!

Patch

diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c
index d341090..f9b1bc8 100644
--- a/drivers/net/ethernet/broadcom/bgmac.c
+++ b/drivers/net/ethernet/broadcom/bgmac.c
@@ -301,8 +301,9 @@  static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring,
 			bgmac_err(bgmac, "Found poisoned packet at slot %d, DMA issue!\n",
 				  ring->start);
 		} else {
-			new_skb = netdev_alloc_skb(bgmac->net_dev, len);
+			new_skb = netdev_alloc_skb(bgmac->net_dev, len + 2);
 			if (new_skb) {
+				skb_reserve(new_skb, 2);
 				skb_put(new_skb, len);
 				skb_copy_from_linear_data_offset(skb, BGMAC_RX_FRAME_OFFSET,
 								 new_skb->data,