aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAjit Khaparde <ajitk@serverengines.com>2009-06-25 22:51:07 -0400
committerDavid S. Miller <davem@davemloft.net>2009-06-28 20:34:25 -0400
commitbd46cb6cf11867130a41ea9546dd65688b71f3c2 (patch)
treebfd797129c817d3989f471914ef4979d008ef0d8
parentff780cd8f2fa928b193554f593b36d1243554212 (diff)
be2net: Fix to avoid a crash seen on PPC with LRO and Jumbo frames.
While testing the driver on PPC, we ran into a crash with LRO, Jumbo frames. With CONFIG_PPC_64K_PAGES configured (a default in PPC), MAX_SKB_FRAGS drops to 3 and we were crossing the array limits on skb_shinfo(skb)->frags[]. Now we coalesce the frags from the same physical page into one slot in skb_shinfo(skb)->frags[] and go to the next index when the frag is from different physical page. This patch is against the net-2.6 tree. Signed-off-by: Ajit Khaparde <ajitk@serverengines.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/benet/be.h2
-rw-r--r--drivers/net/benet/be_ethtool.c4
-rw-r--r--drivers/net/benet/be_main.c45
3 files changed, 35 insertions, 16 deletions
diff --git a/drivers/net/benet/be.h b/drivers/net/benet/be.h
index f703758f0a6e..5b4bf3d2cdc2 100644
--- a/drivers/net/benet/be.h
+++ b/drivers/net/benet/be.h
@@ -73,7 +73,7 @@ static inline char *nic_name(struct pci_dev *pdev)
73#define RX_FRAGS_REFILL_WM (RX_Q_LEN - MAX_RX_POST) 73#define RX_FRAGS_REFILL_WM (RX_Q_LEN - MAX_RX_POST)
74 74
75#define BE_MAX_LRO_DESCRIPTORS 16 75#define BE_MAX_LRO_DESCRIPTORS 16
76#define BE_MAX_FRAGS_PER_FRAME 16 76#define BE_MAX_FRAGS_PER_FRAME (min((u32) 16, (u32) MAX_SKB_FRAGS))
77 77
78struct be_dma_mem { 78struct be_dma_mem {
79 void *va; 79 void *va;
diff --git a/drivers/net/benet/be_ethtool.c b/drivers/net/benet/be_ethtool.c
index 9592f22e4c8c..cccc5419ad72 100644
--- a/drivers/net/benet/be_ethtool.c
+++ b/drivers/net/benet/be_ethtool.c
@@ -162,8 +162,8 @@ be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
162 return -EINVAL; 162 return -EINVAL;
163 163
164 adapter->max_rx_coal = coalesce->rx_max_coalesced_frames; 164 adapter->max_rx_coal = coalesce->rx_max_coalesced_frames;
165 if (adapter->max_rx_coal > MAX_SKB_FRAGS) 165 if (adapter->max_rx_coal > BE_MAX_FRAGS_PER_FRAME)
166 adapter->max_rx_coal = MAX_SKB_FRAGS - 1; 166 adapter->max_rx_coal = BE_MAX_FRAGS_PER_FRAME;
167 167
168 /* if AIC is being turned on now, start with an EQD of 0 */ 168 /* if AIC is being turned on now, start with an EQD of 0 */
169 if (rx_eq->enable_aic == 0 && 169 if (rx_eq->enable_aic == 0 &&
diff --git a/drivers/net/benet/be_main.c b/drivers/net/benet/be_main.c
index 66c10c87f517..308eb09ca56b 100644
--- a/drivers/net/benet/be_main.c
+++ b/drivers/net/benet/be_main.c
@@ -666,7 +666,7 @@ static void skb_fill_rx_data(struct be_adapter *adapter,
666{ 666{
667 struct be_queue_info *rxq = &adapter->rx_obj.q; 667 struct be_queue_info *rxq = &adapter->rx_obj.q;
668 struct be_rx_page_info *page_info; 668 struct be_rx_page_info *page_info;
669 u16 rxq_idx, i, num_rcvd; 669 u16 rxq_idx, i, num_rcvd, j;
670 u32 pktsize, hdr_len, curr_frag_len; 670 u32 pktsize, hdr_len, curr_frag_len;
671 u8 *start; 671 u8 *start;
672 672
@@ -709,22 +709,33 @@ static void skb_fill_rx_data(struct be_adapter *adapter,
709 709
710 /* More frags present for this completion */ 710 /* More frags present for this completion */
711 pktsize -= curr_frag_len; /* account for above copied frag */ 711 pktsize -= curr_frag_len; /* account for above copied frag */
712 for (i = 1; i < num_rcvd; i++) { 712 for (i = 1, j = 0; i < num_rcvd; i++) {
713 index_inc(&rxq_idx, rxq->len); 713 index_inc(&rxq_idx, rxq->len);
714 page_info = get_rx_page_info(adapter, rxq_idx); 714 page_info = get_rx_page_info(adapter, rxq_idx);
715 715
716 curr_frag_len = min(pktsize, rx_frag_size); 716 curr_frag_len = min(pktsize, rx_frag_size);
717 717
718 skb_shinfo(skb)->frags[i].page = page_info->page; 718 /* Coalesce all frags from the same physical page in one slot */
719 skb_shinfo(skb)->frags[i].page_offset = page_info->page_offset; 719 if (page_info->page_offset == 0) {
720 skb_shinfo(skb)->frags[i].size = curr_frag_len; 720 /* Fresh page */
721 j++;
722 skb_shinfo(skb)->frags[j].page = page_info->page;
723 skb_shinfo(skb)->frags[j].page_offset =
724 page_info->page_offset;
725 skb_shinfo(skb)->frags[j].size = 0;
726 skb_shinfo(skb)->nr_frags++;
727 } else {
728 put_page(page_info->page);
729 }
730
731 skb_shinfo(skb)->frags[j].size += curr_frag_len;
721 skb->len += curr_frag_len; 732 skb->len += curr_frag_len;
722 skb->data_len += curr_frag_len; 733 skb->data_len += curr_frag_len;
723 skb_shinfo(skb)->nr_frags++;
724 pktsize -= curr_frag_len; 734 pktsize -= curr_frag_len;
725 735
726 memset(page_info, 0, sizeof(*page_info)); 736 memset(page_info, 0, sizeof(*page_info));
727 } 737 }
738 BUG_ON(j > MAX_SKB_FRAGS);
728 739
729done: 740done:
730 be_rx_stats_update(adapter, pktsize, num_rcvd); 741 be_rx_stats_update(adapter, pktsize, num_rcvd);
@@ -786,7 +797,7 @@ static void be_rx_compl_process_lro(struct be_adapter *adapter,
786 struct skb_frag_struct rx_frags[BE_MAX_FRAGS_PER_FRAME]; 797 struct skb_frag_struct rx_frags[BE_MAX_FRAGS_PER_FRAME];
787 struct be_queue_info *rxq = &adapter->rx_obj.q; 798 struct be_queue_info *rxq = &adapter->rx_obj.q;
788 u32 num_rcvd, pkt_size, remaining, vlanf, curr_frag_len; 799 u32 num_rcvd, pkt_size, remaining, vlanf, curr_frag_len;
789 u16 i, rxq_idx = 0, vid; 800 u16 i, rxq_idx = 0, vid, j;
790 801
791 num_rcvd = AMAP_GET_BITS(struct amap_eth_rx_compl, numfrags, rxcp); 802 num_rcvd = AMAP_GET_BITS(struct amap_eth_rx_compl, numfrags, rxcp);
792 pkt_size = AMAP_GET_BITS(struct amap_eth_rx_compl, pktsize, rxcp); 803 pkt_size = AMAP_GET_BITS(struct amap_eth_rx_compl, pktsize, rxcp);
@@ -794,20 +805,28 @@ static void be_rx_compl_process_lro(struct be_adapter *adapter,
794 rxq_idx = AMAP_GET_BITS(struct amap_eth_rx_compl, fragndx, rxcp); 805 rxq_idx = AMAP_GET_BITS(struct amap_eth_rx_compl, fragndx, rxcp);
795 806
796 remaining = pkt_size; 807 remaining = pkt_size;
797 for (i = 0; i < num_rcvd; i++) { 808 for (i = 0, j = -1; i < num_rcvd; i++) {
798 page_info = get_rx_page_info(adapter, rxq_idx); 809 page_info = get_rx_page_info(adapter, rxq_idx);
799 810
800 curr_frag_len = min(remaining, rx_frag_size); 811 curr_frag_len = min(remaining, rx_frag_size);
801 812
802 rx_frags[i].page = page_info->page; 813 /* Coalesce all frags from the same physical page in one slot */
803 rx_frags[i].page_offset = page_info->page_offset; 814 if (i == 0 || page_info->page_offset == 0) {
804 rx_frags[i].size = curr_frag_len; 815 /* First frag or Fresh page */
805 remaining -= curr_frag_len; 816 j++;
817 rx_frags[j].page = page_info->page;
818 rx_frags[j].page_offset = page_info->page_offset;
819 rx_frags[j].size = 0;
820 } else {
821 put_page(page_info->page);
822 }
823 rx_frags[j].size += curr_frag_len;
806 824
825 remaining -= curr_frag_len;
807 index_inc(&rxq_idx, rxq->len); 826 index_inc(&rxq_idx, rxq->len);
808
809 memset(page_info, 0, sizeof(*page_info)); 827 memset(page_info, 0, sizeof(*page_info));
810 } 828 }
829 BUG_ON(j > MAX_SKB_FRAGS);
811 830
812 if (likely(!vlanf)) { 831 if (likely(!vlanf)) {
813 lro_receive_frags(&adapter->rx_obj.lro_mgr, rx_frags, pkt_size, 832 lro_receive_frags(&adapter->rx_obj.lro_mgr, rx_frags, pkt_size,