All of lore.kernel.org
 help / color / mirror / Atom feed
From: Franco Fichtner <franco@lastsummer.de>
To: Neil Horman <nhorman@tuxdriver.com>
Cc: netdev@vger.kernel.org, e1000-devel@lists.sourceforge.net,
	davem@davemloft.net, jeffrey.t.kirsher@intel.com,
	jesse.brandeburg@intel.com, bruce.w.allan@intel.com,
	peter.p.waskiewicz.jr@intel.com, john.ronciak@intel.com
Subject: Re: [PATCH 1/3] e1000: increase skb size to prevent dma over skb boundary
Date: Mon, 07 Dec 2009 16:24:02 +0100	[thread overview]
Message-ID: <4B1D1E12.8010200@lastsummer.de> (raw)
In-Reply-To: <20091207144736.GB8073@hmsreliant.think-freely.org>

Hi Neil,

Neil Horman wrote:
> Update e1000 driver to not allow dma beyond the end of the allocated skb
>     
> Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
>
>
> e1000_main.c |   34 +++++++++++++++++++++++++++++++++-
> 1 file changed, 33 insertions(+), 1 deletion(-)
>
>
> diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
> index 7e855f9..7600deb 100644
> --- a/drivers/net/e1000/e1000_main.c
> +++ b/drivers/net/e1000/e1000_main.c
> @@ -1667,6 +1667,19 @@ int e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
>  	return err;
>  }
>  
> +static inline u32 normalize_rx_len(u32 len)
> +{
> +        u32 match, last_match;
> +
>   
Skip newline and get rid of last_match. Also, there is a whitespace error...
> +
> +        for (match = 0x100; match <= 0x4000; match *= 2) {
> +                if (len <= match)
> +                        return match;
> +        }
> +
>   
> +        return 0;
> +}
>   
You should return (match >> 1), which is the largest size possible. (Which
is exactly what you need here).
> +
>  /**
>   * e1000_setup_rctl - configure the receive control registers
>   * @adapter: Board private structure
> @@ -1675,6 +1688,7 @@ static void e1000_setup_rctl(struct e1000_adapter *adapter)
>  {
>  	struct e1000_hw *hw = &adapter->hw;
>  	u32 rctl;
> +	u32 normed_rx_len;
>  
>  	rctl = er32(RCTL);
>  
> @@ -1697,7 +1711,25 @@ static void e1000_setup_rctl(struct e1000_adapter *adapter)
>  	/* Setup buffer sizes */
>  	rctl &= ~E1000_RCTL_SZ_4096;
>  	rctl |= E1000_RCTL_BSEX;
> -	switch (adapter->rx_buffer_len) {
> +
> +	/*
> +	 * We need to normalize the rx_buffer_len here
> +	 * since the hardware only knows about 7 discrete
> +	 * frame lengths here.  To accomodate that we need
> +	 * to set the rx length in the hardware to the next highest
> +	 * size over the rx_buffer_len, then increase rx_buffer_len
> +	 * to match it, so that we can get a full mtu sized frame 
> +	 */
> +	normed_rx_len = normalize_rx_len(adapter->rx_buffer_len);
> +	
> +	if (!normed_rx_len) {
> +		printk(KERN_ERR "No valid rx len found, assume 2048\n");
> +		normed_rx_len = 0x800;
> +	}
> +
> +	adapter->rx_buffer_len = normed_rx_len;
>   
If you modify rx_buffer_len anyway, then get rid of normed_rx_len and
do a quick

    adapter->rx_buffer_len = normalize_rx_len(adapter->rx_buffer_len);

instead. With the modification above, it never fails, so no need to check
for !normed_rx_len.

But I don't really know the context of this change. Is it okay to shorten
rx_buffer_len here? Why was it not set appropriately as the driver
expects?

Oh, BTW, the default case in the switch statement is stupid and should
be removed.

> +
> +	switch (normed_rx_len) {
>  		case E1000_RXBUFFER_256:
>  			rctl |= E1000_RCTL_SZ_256;
>  			rctl &= ~E1000_RCTL_BSEX;
> --
> 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
>   

Franco

  parent reply	other threads:[~2009-12-07 15:24 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-07 14:46 [PATCH 0/3] increase skb size to prevent dma over skb boundary Neil Horman
2009-12-07 14:47 ` [PATCH 1/3] e1000: " Neil Horman
2009-12-07 15:13   ` Ben Dooks
2009-12-07 15:19   ` Michał Mirosław
2009-12-07 15:24   ` Franco Fichtner [this message]
2009-12-07 15:59     ` [PATCH 1/3] e1000: increase skb size to prevent dma over skb boundary (v2) Neil Horman
2009-12-07 20:52       ` Jeff Kirsher
2009-12-07 14:48 ` [PATCH 2/3] e1000e: increase skb size to prevent dma over skb boundary Neil Horman
2009-12-07 16:02   ` [PATCH 2/3] e1000e: increase skb size to prevent dma over skb boundary (v2) Neil Horman
2009-12-07 20:53     ` Jeff Kirsher
2009-12-07 14:49 ` [PATCH 3/3] ixgb: increase skb size to prevent dma over skb boundary Neil Horman
2009-12-07 20:54   ` Jeff Kirsher
2009-12-07 20:57     ` Neil Horman
2009-12-08  9:27       ` David Miller
2009-12-08 23:37 ` [PATCH 0/3] " Tantilov, Emil S
2009-12-09  2:46   ` Neil Horman
2009-12-09 15:23   ` Neil Horman
2009-12-10 18:20     ` Tantilov, Emil S
2009-12-10 21:00       ` Neil Horman
2009-12-23  6:47       ` Brandon Philips
2009-12-23 19:43         ` Brandeburg, Jesse
2009-12-25  1:31           ` Neil Horman

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=4B1D1E12.8010200@lastsummer.de \
    --to=franco@lastsummer.de \
    --cc=bruce.w.allan@intel.com \
    --cc=davem@davemloft.net \
    --cc=e1000-devel@lists.sourceforge.net \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=john.ronciak@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=peter.p.waskiewicz.jr@intel.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.