netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch net 0/4] net: hns: bug fixes & optimization for HNS driver
@ 2018-08-23  3:10 Huazhong Tan
  2018-08-23  3:10 ` [Patch net 1/4] net: hns: fix length and page_offset overflow when CONFIG_ARM64_64K_PAGES Huazhong Tan
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Huazhong Tan @ 2018-08-23  3:10 UTC (permalink / raw)
  To: davem; +Cc: netdev, linuxarm, salil.mehta, yisen.zhuang, lipeng321,
	tanhuazhong

This patchset presents some bug fixes found out when CONFIG_ARM64_64K_PAGES
enable and an optimization for HNS driver.

Huazhong Tan (4):
  net: hns: fix length and page_offset overflow when
    CONFIG_ARM64_64K_PAGES
  net: hns: modify variable type in hns_nic_reuse_page
  net: hns: fix skb->truesize underestimation
  net: hns: use eth_get_headlen interface instead of hns_nic_get_headlen

 drivers/net/ethernet/hisilicon/hns/hnae.h     |   6 +-
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 108 +-------------------------
 2 files changed, 7 insertions(+), 107 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Patch net 1/4] net: hns: fix length and page_offset overflow when CONFIG_ARM64_64K_PAGES
  2018-08-23  3:10 [Patch net 0/4] net: hns: bug fixes & optimization for HNS driver Huazhong Tan
@ 2018-08-23  3:10 ` Huazhong Tan
  2018-08-23  3:10 ` [Patch net 2/4] net: hns: modify variable type in hns_nic_reuse_page Huazhong Tan
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Huazhong Tan @ 2018-08-23  3:10 UTC (permalink / raw)
  To: davem; +Cc: netdev, linuxarm, salil.mehta, yisen.zhuang, lipeng321,
	tanhuazhong

When enable the config item "CONFIG_ARM64_64K_PAGES", the size of PAGE_SIZE
is 65536(64K). But the  type of length and page_offset are u16, they will
overflow. So change them to u32.

Fixes: 6fe6611ff275 ("net: add Hisilicon Network Subsystem hnae framework support")
Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hnae.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.h b/drivers/net/ethernet/hisilicon/hns/hnae.h
index fa5b30f..cad52bd 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.h
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.h
@@ -220,10 +220,10 @@ struct hnae_desc_cb {
 
 	/* priv data for the desc, e.g. skb when use with ip stack*/
 	void *priv;
-	u16 page_offset;
-	u16 reuse_flag;
+	u32 page_offset;
+	u32 length;     /* length of the buffer */
 
-	u16 length;     /* length of the buffer */
+	u16 reuse_flag;
 
        /* desc type, used by the ring user to mark the type of the priv data */
 	u16 type;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Patch net 2/4] net: hns: modify variable type in hns_nic_reuse_page
  2018-08-23  3:10 [Patch net 0/4] net: hns: bug fixes & optimization for HNS driver Huazhong Tan
  2018-08-23  3:10 ` [Patch net 1/4] net: hns: fix length and page_offset overflow when CONFIG_ARM64_64K_PAGES Huazhong Tan
@ 2018-08-23  3:10 ` Huazhong Tan
  2018-08-23  3:10 ` [Patch net 3/4] net: hns: fix skb->truesize underestimation Huazhong Tan
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Huazhong Tan @ 2018-08-23  3:10 UTC (permalink / raw)
  To: davem; +Cc: netdev, linuxarm, salil.mehta, yisen.zhuang, lipeng321,
	tanhuazhong

'truesize' is supposed to be u32, not int, so fix it.

Signed-off-by: Huazhong tan <tanhuazhong@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index 9f2b552..c8c0b03 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -512,7 +512,8 @@ static void hns_nic_reuse_page(struct sk_buff *skb, int i,
 			       struct hnae_desc_cb *desc_cb)
 {
 	struct hnae_desc *desc;
-	int truesize, size;
+	u32 truesize;
+	int size;
 	int last_offset;
 	bool twobufs;
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Patch net 3/4] net: hns: fix skb->truesize underestimation
  2018-08-23  3:10 [Patch net 0/4] net: hns: bug fixes & optimization for HNS driver Huazhong Tan
  2018-08-23  3:10 ` [Patch net 1/4] net: hns: fix length and page_offset overflow when CONFIG_ARM64_64K_PAGES Huazhong Tan
  2018-08-23  3:10 ` [Patch net 2/4] net: hns: modify variable type in hns_nic_reuse_page Huazhong Tan
@ 2018-08-23  3:10 ` Huazhong Tan
  2018-08-23  3:10 ` [Patch net 4/4] net: hns: use eth_get_headlen interface instead of hns_nic_get_headlen Huazhong Tan
  2018-08-23  4:48 ` [Patch net 0/4] net: hns: bug fixes & optimization for HNS driver David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: Huazhong Tan @ 2018-08-23  3:10 UTC (permalink / raw)
  To: davem; +Cc: netdev, linuxarm, salil.mehta, yisen.zhuang, lipeng321,
	tanhuazhong

skb->truesize is not meant to be tracking amount of used bytes in a skb,
but amount of reserved/consumed bytes in memory.

For instance, if we use a single byte in last page fragment, we have to
account the full size of the fragment.

So skb_add_rx_frag needs to calculate the length of the entire buffer into
turesize.

Fixes: 9cbe9fd5214e ("net: hns: optimize XGE capability by reducing cpu usage")
Signed-off-by: Huazhong tan <tanhuazhong@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index c8c0b03..71bd3bf 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -531,7 +531,7 @@ static void hns_nic_reuse_page(struct sk_buff *skb, int i,
 	}
 
 	skb_add_rx_frag(skb, i, desc_cb->priv, desc_cb->page_offset + pull_len,
-			size - pull_len, truesize - pull_len);
+			size - pull_len, truesize);
 
 	 /* avoid re-using remote pages,flag default unreuse */
 	if (unlikely(page_to_nid(desc_cb->priv) != numa_node_id()))
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Patch net 4/4] net: hns: use eth_get_headlen interface instead of hns_nic_get_headlen
  2018-08-23  3:10 [Patch net 0/4] net: hns: bug fixes & optimization for HNS driver Huazhong Tan
                   ` (2 preceding siblings ...)
  2018-08-23  3:10 ` [Patch net 3/4] net: hns: fix skb->truesize underestimation Huazhong Tan
@ 2018-08-23  3:10 ` Huazhong Tan
  2018-08-23  4:48 ` [Patch net 0/4] net: hns: bug fixes & optimization for HNS driver David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: Huazhong Tan @ 2018-08-23  3:10 UTC (permalink / raw)
  To: davem; +Cc: netdev, linuxarm, salil.mehta, yisen.zhuang, lipeng321,
	tanhuazhong

Update hns to drop the hns_nic_get_headlen function in favour of
eth_get_headlen, and hence also removes now redundant hns_nic_get_headlen.

Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 103 +-------------------------
 1 file changed, 1 insertion(+), 102 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index 71bd3bf..02a0ba2 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -406,107 +406,6 @@ netdev_tx_t hns_nic_net_xmit_hw(struct net_device *ndev,
 	return NETDEV_TX_BUSY;
 }
 
-/**
- * hns_nic_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
- * @data: pointer to the start of the headers
- * @max: total length of section to find headers in
- *
- * This function is meant to determine the length of headers that will
- * be recognized by hardware for LRO, GRO, and RSC offloads.  The main
- * motivation of doing this is to only perform one pull for IPv4 TCP
- * packets so that we can do basic things like calculating the gso_size
- * based on the average data per packet.
- **/
-static unsigned int hns_nic_get_headlen(unsigned char *data, u32 flag,
-					unsigned int max_size)
-{
-	unsigned char *network;
-	u8 hlen;
-
-	/* this should never happen, but better safe than sorry */
-	if (max_size < ETH_HLEN)
-		return max_size;
-
-	/* initialize network frame pointer */
-	network = data;
-
-	/* set first protocol and move network header forward */
-	network += ETH_HLEN;
-
-	/* handle any vlan tag if present */
-	if (hnae_get_field(flag, HNS_RXD_VLAN_M, HNS_RXD_VLAN_S)
-		== HNS_RX_FLAG_VLAN_PRESENT) {
-		if ((typeof(max_size))(network - data) > (max_size - VLAN_HLEN))
-			return max_size;
-
-		network += VLAN_HLEN;
-	}
-
-	/* handle L3 protocols */
-	if (hnae_get_field(flag, HNS_RXD_L3ID_M, HNS_RXD_L3ID_S)
-		== HNS_RX_FLAG_L3ID_IPV4) {
-		if ((typeof(max_size))(network - data) >
-		    (max_size - sizeof(struct iphdr)))
-			return max_size;
-
-		/* access ihl as a u8 to avoid unaligned access on ia64 */
-		hlen = (network[0] & 0x0F) << 2;
-
-		/* verify hlen meets minimum size requirements */
-		if (hlen < sizeof(struct iphdr))
-			return network - data;
-
-		/* record next protocol if header is present */
-	} else if (hnae_get_field(flag, HNS_RXD_L3ID_M, HNS_RXD_L3ID_S)
-		== HNS_RX_FLAG_L3ID_IPV6) {
-		if ((typeof(max_size))(network - data) >
-		    (max_size - sizeof(struct ipv6hdr)))
-			return max_size;
-
-		/* record next protocol */
-		hlen = sizeof(struct ipv6hdr);
-	} else {
-		return network - data;
-	}
-
-	/* relocate pointer to start of L4 header */
-	network += hlen;
-
-	/* finally sort out TCP/UDP */
-	if (hnae_get_field(flag, HNS_RXD_L4ID_M, HNS_RXD_L4ID_S)
-		== HNS_RX_FLAG_L4ID_TCP) {
-		if ((typeof(max_size))(network - data) >
-		    (max_size - sizeof(struct tcphdr)))
-			return max_size;
-
-		/* access doff as a u8 to avoid unaligned access on ia64 */
-		hlen = (network[12] & 0xF0) >> 2;
-
-		/* verify hlen meets minimum size requirements */
-		if (hlen < sizeof(struct tcphdr))
-			return network - data;
-
-		network += hlen;
-	} else if (hnae_get_field(flag, HNS_RXD_L4ID_M, HNS_RXD_L4ID_S)
-		== HNS_RX_FLAG_L4ID_UDP) {
-		if ((typeof(max_size))(network - data) >
-		    (max_size - sizeof(struct udphdr)))
-			return max_size;
-
-		network += sizeof(struct udphdr);
-	}
-
-	/* If everything has gone correctly network should be the
-	 * data section of the packet and will be the end of the header.
-	 * If not then it probably represents the end of the last recognized
-	 * header.
-	 */
-	if ((typeof(max_size))(network - data) < max_size)
-		return network - data;
-	else
-		return max_size;
-}
-
 static void hns_nic_reuse_page(struct sk_buff *skb, int i,
 			       struct hnae_ring *ring, int pull_len,
 			       struct hnae_desc_cb *desc_cb)
@@ -696,7 +595,7 @@ static int hns_nic_poll_rx_skb(struct hns_nic_ring_data *ring_data,
 	} else {
 		ring->stats.seg_pkt_cnt++;
 
-		pull_len = hns_nic_get_headlen(va, bnum_flag, HNS_RX_HEAD_SIZE);
+		pull_len = eth_get_headlen(va, HNS_RX_HEAD_SIZE);
 		memcpy(__skb_put(skb, pull_len), va,
 		       ALIGN(pull_len, sizeof(long)));
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Patch net 0/4] net: hns: bug fixes & optimization for HNS driver
  2018-08-23  3:10 [Patch net 0/4] net: hns: bug fixes & optimization for HNS driver Huazhong Tan
                   ` (3 preceding siblings ...)
  2018-08-23  3:10 ` [Patch net 4/4] net: hns: use eth_get_headlen interface instead of hns_nic_get_headlen Huazhong Tan
@ 2018-08-23  4:48 ` David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2018-08-23  4:48 UTC (permalink / raw)
  To: tanhuazhong; +Cc: netdev, linuxarm, salil.mehta, yisen.zhuang, lipeng321

From: Huazhong Tan <tanhuazhong@huawei.com>
Date: Thu, 23 Aug 2018 11:10:09 +0800

> This patchset presents some bug fixes found out when
> CONFIG_ARM64_64K_PAGES enable and an optimization for HNS driver.

Series applied, thank you.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-08-23  8:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-23  3:10 [Patch net 0/4] net: hns: bug fixes & optimization for HNS driver Huazhong Tan
2018-08-23  3:10 ` [Patch net 1/4] net: hns: fix length and page_offset overflow when CONFIG_ARM64_64K_PAGES Huazhong Tan
2018-08-23  3:10 ` [Patch net 2/4] net: hns: modify variable type in hns_nic_reuse_page Huazhong Tan
2018-08-23  3:10 ` [Patch net 3/4] net: hns: fix skb->truesize underestimation Huazhong Tan
2018-08-23  3:10 ` [Patch net 4/4] net: hns: use eth_get_headlen interface instead of hns_nic_get_headlen Huazhong Tan
2018-08-23  4:48 ` [Patch net 0/4] net: hns: bug fixes & optimization for HNS driver David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).