From: Alexander Duyck Date: Wed, 2 Mar 2016 21:16:01 +0000 (-0500) Subject: e1000: Do not overestimate descriptor counts in Tx pre-check X-Git-Tag: v4.1.12-105.0.20170622_2100~134 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=64f524b65fefe160983ab4618f08253b6fd07380;p=users%2Fjedix%2Flinux-maple.git e1000: Do not overestimate descriptor counts in Tx pre-check The current code path is capable of grossly overestimating the number of descriptors needed to transmit a new frame. This specifically occurs if the skb contains a number of 4K pages. The issue is that the logic for determining the descriptors needed is ((S) >> (X)) + 1. When X is 12 it means that we were indicating that we required 2 descriptors for each 4K page when we only needed one. This change corrects this by instead adding (1 << (X)) - 1 to the S value instead of adding 1 after the fact. This way we get an accurate descriptor needed count as we are essentially doing a DIV_ROUNDUP(). Reported-by: Ivan Suzdal Signed-off-by: Alexander Duyck Tested-by: Aaron Brown Signed-off-by: Jeff Kirsher Orabug: 26243014 (cherry picked from commit 847a1d6796c767f8b697ead60997b847a84b897b) Signed-off-by: Jack Vogel Reviewed-by: Ethan Zhao --- diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c index e93acdfd5c06..7e568f8b7ee6 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_main.c +++ b/drivers/net/ethernet/intel/e1000/e1000_main.c @@ -3111,7 +3111,7 @@ static int e1000_maybe_stop_tx(struct net_device *netdev, return __e1000_maybe_stop_tx(netdev, size); } -#define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1) +#define TXD_USE_COUNT(S, X) (((S) + ((1 << (X)) - 1)) >> (X)) static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev) {