diff mbox

check the return value of ndo_select_queue()

Message ID 4AF7E221.2040901@gmail.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Changli Gao Nov. 9, 2009, 9:34 a.m. UTC
check the return value of ndo_select_queue()

Check the return value of ndo_select_queue(). If the value isn't smaller
than the real_num_tx_queues, print a warning message, and reset it to zero.

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
----
net/core/dev.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)



--
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

Comments

Eric Dumazet Nov. 9, 2009, 9:50 a.m. UTC | #1
Changli Gao a écrit :
> check the return value of ndo_select_queue()
> 
> Check the return value of ndo_select_queue(). If the value isn't smaller
> than the real_num_tx_queues, print a warning message, and reset it to zero.
> 
> Signed-off-by: Changli Gao <xiaosuo@gmail.com>
> ----
> net/core/dev.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/net/core/dev.c b/net/core/dev.c
> index b8f74cf..0a6bf2e 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -1794,10 +1794,17 @@ static struct netdev_queue *dev_pick_tx(struct net_device *dev,
>  	const struct net_device_ops *ops = dev->netdev_ops;
>  	u16 queue_index = 0;
>  
> -	if (ops->ndo_select_queue)
> +	if (ops->ndo_select_queue) {
>  		queue_index = ops->ndo_select_queue(dev, skb);
> -	else if (dev->real_num_tx_queues > 1)
> +		if (queue_index >= dev->real_num_tx_queues) {
> +			WARN(1, "%s selects TX queue %d, "
> +			     "but real number of TX queues is %d\n",
> +			     dev->name, queue_index, dev->real_num_tx_queues);
> +			queue_index = 0;
> +		}
> +	} else if (dev->real_num_tx_queues > 1) {
>  		queue_index = skb_tx_hash(dev, skb);
> +	}
>  
>  	skb_set_queue_mapping(skb, queue_index);
>  	return netdev_get_tx_queue(dev, queue_index);

Yes, but this is a _very_ unlikely condition (a bug IMHO), so you could use :

if (unlikely(queue_index >= dev->real_num_tx_queues)) {
	...
}

(This unlikely() clause is implied in WARN... macros)

--
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
Eric Dumazet Nov. 9, 2009, 10:02 a.m. UTC | #2
Eric Dumazet a écrit :
> 
> Yes, but this is a _very_ unlikely condition (a bug IMHO), so you could use :
> 
> if (unlikely(queue_index >= dev->real_num_tx_queues)) {
> 	...
> }
> 
> (This unlikely() clause is implied in WARN... macros)
> 

Also, you want to trigger this message only once, or ratelimit it at least

--
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
Changli Gao Nov. 9, 2009, 11:29 a.m. UTC | #3
2009/11/9 Eric Dumazet <eric.dumazet@gmail.com>:
> Eric Dumazet a écrit :
>>
>> Yes, but this is a _very_ unlikely condition (a bug IMHO), so you could use :
>>
>> if (unlikely(queue_index >= dev->real_num_tx_queues)) {
>>       ...
>> }
>>
>> (This unlikely() clause is implied in WARN... macros)
>>
>
> Also, you want to trigger this message only once, or ratelimit it at least
>
>

How about this version:

        u16 queue_index;
        u16 (*ndo_select_queue)(struct net_device*, struct sk_buff*);
        unsigned int real_num_tx_queues = dev->real_num_tx_queues;

        if (real_num_tx_queues == 1) {
                queue_index = 0;
        } else if ((ndo_select_queue = dev->netdev_ops->ndo_select_queue)) {
                queue_index = ndo_select_queue(dev, skb);
                if (unlikely(queue_index >= real_num_tx_queues)) {
                        if (net_ratelimit())
                                WARN(1, "%s selects TX queue %d, "
                                     "but real number of TX queues is %d\n",
                                     dev->name, queue_index,
                                     real_num_tx_queues);
                        queue_index = 0;
                }
        } else {
                queue_index = skb_tx_hash(dev, skb);
        }

        skb_set_queue_mapping(skb, queue_index);
        return netdev_get_tx_queue(dev, queue_index);
diff mbox

Patch

diff --git a/net/core/dev.c b/net/core/dev.c
index b8f74cf..0a6bf2e 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1794,10 +1794,17 @@  static struct netdev_queue *dev_pick_tx(struct net_device *dev,
 	const struct net_device_ops *ops = dev->netdev_ops;
 	u16 queue_index = 0;
 
-	if (ops->ndo_select_queue)
+	if (ops->ndo_select_queue) {
 		queue_index = ops->ndo_select_queue(dev, skb);
-	else if (dev->real_num_tx_queues > 1)
+		if (queue_index >= dev->real_num_tx_queues) {
+			WARN(1, "%s selects TX queue %d, "
+			     "but real number of TX queues is %d\n",
+			     dev->name, queue_index, dev->real_num_tx_queues);
+			queue_index = 0;
+		}
+	} else if (dev->real_num_tx_queues > 1) {
 		queue_index = skb_tx_hash(dev, skb);
+	}
 
 	skb_set_queue_mapping(skb, queue_index);
 	return netdev_get_tx_queue(dev, queue_index);