GVE Raw Addressing.
Subsystems (3)
v3 cover GVE Raw Addressing.
Changes from v2:
Patch 1: Get end of struct more simply: descriptor + 1, no need to cast void pointers. Patch 2: Separate page recycling to its own commit (patch 3 in v3). Patch 4 (patch 3 in v2): Fix alignment of gve_dma_sync_for_device params.
Catherine Sullivan (3):
gve: Add support for raw addressing device option
gve: Add support for raw addressing to the rx path
gve: Add support for raw addressing in the tx path
David Awogbemila (1):
gve: Rx Buffer Recycling
drivers/net/ethernet/google/gve/gve.h | 40 ++- drivers/net/ethernet/google/gve/gve_adminq.c | 64 +++- drivers/net/ethernet/google/gve/gve_adminq.h | 15 +- drivers/net/ethernet/google/gve/gve_desc.h | 18 +- drivers/net/ethernet/google/gve/gve_main.c | 12 +- drivers/net/ethernet/google/gve/gve_rx.c | 350 ++++++++++++++----- drivers/net/ethernet/google/gve/gve_tx.c | 205 +++++++++-- 7 files changed, 554 insertions(+), 150 deletions(-)
Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
PATCH v3 1/4 gve: Add support for raw addressing device option
From: Catherine Sullivan <[email protected]>
Add support to describe device for parsing device options. As the first device option, add raw addressing.
"Raw Addressing" mode (as opposed to the current "qpl" mode) is an operational mode which allows the driver avoid bounce buffer copies which it currently performs using pre-allocated qpls (queue_page_lists) when sending and receiving packets.
For egress packets, the provided skb data addresses will be dma_map'ed and passed to the device, allowing the NIC can perform DMA directly - the driver will not have to copy the buffer content into pre-allocated buffers/qpls (as in qpl mode).
For ingress packets, copies are also eliminated as buffers are handed to the networking stack and then recycled or re-allocated as necessary, avoiding the use of skb_copy_to_linear_data().
This patch only introduces the option to the driver. Subsequent patches will add the ingress and egress functionality.
--- drivers/net/ethernet/google/gve/gve.h | 1 + drivers/net/ethernet/google/gve/gve_adminq.c | 46 ++++++++++++++++++++ drivers/net/ethernet/google/gve/gve_adminq.h | 15 +++++-- drivers/net/ethernet/google/gve/gve_main.c | 9 ++++ 4 files changed, 67 insertions(+), 4 deletions(-)
drivers/net/ethernet/google/gve/gve.h +1 -0
@@ -199,6 +199,7 @@ struct gve_priv {u64 num_registered_pages;/* num pages registered with NIC */ u32 rx_copybreak;/* copy packets smaller than this */ u16 default_num_queues;/* default num queues to set up */ +bool raw_addressing;/* true if this dev supports raw addressing */ struct gve_queue_config tx_cfg;struct gve_queue_config rx_cfg;
drivers/net/ethernet/google/gve/gve_adminq.c +46 -0
63 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_adminq.h +11 -4
@@ -79,12 +79,17 @@ struct gve_device_descriptor {static_assert (sizeof (struct gve_device_descriptor ) ==40 ); -struct device_option { -__be32 option_id; -__be32 option_length; +struct gve_device_option { +__be16 option_id; +__be16 option_length; +__be32 feat_mask; }; -static_assert (sizeof (struct device_option ) ==8 ); +static_assert (sizeof (struct gve_device_option ) ==8 ); + +#define GVE_DEV_OPT_ID_RAW_ADDRESSING 0x1 +#define GVE_DEV_OPT_LEN_RAW_ADDRESSING 0x0 +#define GVE_DEV_OPT_FEAT_MASK_RAW_ADDRESSING 0x0struct gve_adminq_configure_device_resources {__be64 counter_array;
@@ -111,6 +116,8 @@ struct gve_adminq_unregister_page_list {static_assert (sizeof (struct gve_adminq_unregister_page_list ) ==4 ); +#define GVE_RAW_ADDRESSING_QPL_ID 0xFFFFFFFF +struct gve_adminq_create_tx_queue {__be32 queue_id;__be32 reserved;
drivers/net/ethernet/google/gve/gve_main.c +9 -0
@@ -678,6 +678,10 @@ static int gve_alloc_qpls(struct gve_priv *priv)int i, j;int err; +/* Raw addressing means no QPLs */ +if (priv->raw_addressing) +return 0 ; + priv->qpls =kvzalloc (num_qpls *sizeof (*priv->qpls),GFP_KERNEL );if (!priv->qpls)return -ENOMEM ;
@@ -718,6 +722,10 @@ static void gve_free_qpls(struct gve_priv *priv)int num_qpls =gve_num_tx_qpls (priv) +gve_num_rx_qpls (priv);int i; +/* Raw addressing means no QPLs */ +if (priv->raw_addressing) +return ; +kvfree (priv->qpl_cfg.qpl_id_map);for (i =0 ; i < num_qpls; i++)
@@ -1078,6 +1086,7 @@ static int gve_init_priv(struct gve_priv *priv, bool skip_describe_device)if (skip_describe_device) goto setup_device; + priv->raw_addressing = false;/* Get the initial information we need from the device */ err =gve_adminq_describe_device (priv);if (err) {
Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
Jakub Kicinski
maintainerRe: [PATCH net-next v3 1/4] gve: Add support for raw addressing device option
drivers/net/ethernet/google/gve/gve_adminq.c int gve_adminq_describe_device(struct gve_priv *priv) · line 532
Quoted 13 lines · On Wed, 23 Sep 2020 18:01:01 -0700 David Awogbemila wrote:
drivers/net/ethernet/google/gve/gve_adminq.c +9
-0@@ -518,6 +521,49 @@ int gve_adminq_describe_device(struct gve_priv *priv) priv->rx_desc_cnt = priv->rx_pages_per_qpl; } priv->default_num_queues =be16_to_cpu (descriptor->default_num_queues); + dev_opt = (void *)(descriptor +1 ); + + num_options =be16_to_cpu (descriptor->num_device_options); +for (i =0 ; i < num_options; i++) { +u16 option_length =be16_to_cpu (dev_opt->option_length); +u16 option_id =be16_to_cpu (dev_opt->option_id); + +if ((void *)dev_opt +sizeof (*dev_opt) + option_length > (void *)descriptor + +be16_to_cpu (descriptor->total_length)) {
Can you calculate an void *end pointer before the loop and avoid this very long condition?
Quoted 4 lines
drivers/net/ethernet/google/gve/gve_adminq.c +4
-0+dev_err (&priv->dev->dev, +"options exceed device_descriptor's total length.\n" ); + err = -EINVAL ; + goto free_device_descriptor;
drivers/net/ethernet/google/gve/gve_adminq.c int gve_adminq_describe_device(struct gve_priv *priv) · line 546
Quoted 10 lines
drivers/net/ethernet/google/gve/gve_adminq.c +10
-0+ } + +switch (option_id) { +case GVE_DEV_OPT_ID_RAW_ADDRESSING : +/* If the length or feature mask doesn't match, +* continue without enabling the feature. +*/ +if (option_length !=GVE_DEV_OPT_LEN_RAW_ADDRESSING || +be32_to_cpu (dev_opt->feat_mask) != +GVE_DEV_OPT_FEAT_MASK_RAW_ADDRESSING ) {
Apply the byteswap to the constant so it's done at compilation time.
drivers/net/ethernet/google/gve/gve_adminq.c int gve_adminq_describe_device(struct gve_priv *priv) · line 548
Quoted 2 lines
drivers/net/ethernet/google/gve/gve_adminq.c +2
-0+dev_info (&priv->pdev->dev, +"Raw addressing device option not enabled, length or features mask did not match expected.\n" );
dev_warn(), also do yourself a favor and print what the values were.
drivers/net/ethernet/google/gve/gve_adminq.c int gve_adminq_describe_device(struct gve_priv *priv) · line 553
Quoted 5 lines
drivers/net/ethernet/google/gve/gve_adminq.c +5
-0+ priv->raw_addressing = false; + }else { +dev_info (&priv->pdev->dev, +"Raw addressing device option enabled.\n" ); + priv->raw_addressing = true;
Does this really need to be printed on every boot?
drivers/net/ethernet/google/gve/gve_adminq.c int gve_adminq_describe_device(struct gve_priv *priv) · line 561
Quoted 8 lines
drivers/net/ethernet/google/gve/gve_adminq.c +8
-0+ } +break ; +default : +/* If we don't recognize the option just continue +* without doing anything. +*/ + dev_info(&priv->pdev->dev, + "Unrecognized device option 0x%hx not enabled.\n",
dev_dbg()
drivers/net/ethernet/google/gve/gve_adminq.c int gve_adminq_describe_device(struct gve_priv *priv) · line 562
Quoted 1 line
drivers/net/ethernet/google/gve/gve_adminq.c +1
-0+ option_id);
alignment is off
Quoted 4 lines
drivers/net/ethernet/google/gve/gve_adminq.c +4
-0+break ; + } + dev_opt = (void *)dev_opt +sizeof (*dev_opt) + option_length; + }
PATCH v3 2/4 gve: Add support for raw addressing to the rx path
In reply to David AwogbemilaFrom: Catherine Sullivan <[email protected]>
Add support to use raw dma addresses in the rx path. Due to this new support we can alloc a new buffer instead of making a copy.
RX buffers are handed to the networking stack and are re-allocated as needed, avoiding the need to use skb_copy_to_linear_data() as in "qpl" mode.
--- drivers/net/ethernet/google/gve/gve.h | 11 +- drivers/net/ethernet/google/gve/gve_adminq.c | 14 +- drivers/net/ethernet/google/gve/gve_desc.h | 10 +- drivers/net/ethernet/google/gve/gve_main.c | 3 +- drivers/net/ethernet/google/gve/gve_rx.c | 185 +++++++++++++++---- 5 files changed, 177 insertions(+), 46 deletions(-)
drivers/net/ethernet/google/gve/gve.h +9 -2
@@ -68,6 +68,7 @@ struct gve_rx_data_queue {dma_addr_t data_bus;/* dma mapping of the slots */ struct gve_rx_slot_page_info *page_info;/* page info of the buffers */ struct gve_queue_page_list *qpl;/* qpl assigned to this queue */ +bool raw_addressing;/* use raw_addressing? */ };struct gve_priv ;
@@ -82,11 +83,14 @@ struct gve_rx_ring {u32 cnt;/* free-running total number of completed packets */ u32 fill_cnt;/* free-running total number of descs and buffs posted */ u32 mask;/* masks the cnt and fill_cnt to the size of the ring */ +u32 db_threshold;/* threshold for posting new buffs and descs */ u64 rx_copybreak_pkt;/* free-running count of copybreak packets */ u64 rx_copied_pkt;/* free-running total number of copied packets */ u64 rx_skb_alloc_fail;/* free-running count of skb alloc fails */ u64 rx_buf_alloc_fail;/* free-running count of buffer alloc fails */ u64 rx_desc_err_dropped_pkt;/* free-running count of packets dropped by descriptor error */ +/* free-running count of packets dropped because of lack of buffer refill */ +u64 rx_no_refill_dropped_pkt;u32 q_num;/* queue index */ u32 ntfy_id;/* notification block index */ struct gve_queue_resources *q_resources;/* head and tail pointer idx */
@@ -194,7 +198,7 @@ struct gve_priv {u16 tx_desc_cnt;/* num desc per ring */ u16 rx_desc_cnt;/* num desc per ring */ u16 tx_pages_per_qpl;/* tx buffer length */ -u16 rx_pages_per_qpl;/* rx buffer length */ +u16 rx_data_slot_cnt;/* rx buffer length */ u64 max_registered_pages;u64 num_registered_pages;/* num pages registered with NIC */ u32 rx_copybreak;/* copy packets smaller than this */
@@ -444,7 +448,10 @@ static inline u32 gve_num_tx_qpls(struct gve_priv *priv)*/ static inline u32 gve_num_rx_qpls (struct gve_priv *priv) { -return priv->rx_cfg.num_queues; +if (priv->raw_addressing) +return 0 ; +else +return priv->rx_cfg.num_queues; }/* Returns a pointer to the next available tx qpl in the list of qpls
drivers/net/ethernet/google/gve/gve_adminq.c +8 -6
@@ -357,8 +357,10 @@ static int gve_adminq_create_rx_queue(struct gve_priv *priv, u32 queue_index) {struct gve_rx_ring *rx = &priv->rx[queue_index];union gve_adminq_command cmd; +u32 qpl_id;int err; + qpl_id = priv->raw_addressing ?GVE_RAW_ADDRESSING_QPL_ID : rx->data.qpl->id;memset (&cmd,0 ,sizeof (cmd)); cmd.opcode =cpu_to_be32 (GVE_ADMINQ_CREATE_RX_QUEUE ); cmd.create_rx_queue = (struct gve_adminq_create_rx_queue ) {
@@ -369,7 +371,7 @@ static int gve_adminq_create_rx_queue(struct gve_priv *priv, u32 queue_index) .queue_resources_addr = cpu_to_be64(rx->q_resources_bus), .rx_desc_ring_addr = cpu_to_be64(rx->desc.bus), .rx_data_ring_addr = cpu_to_be64(rx->data.data_bus), - .queue_page_list_id = cpu_to_be32(rx->data.qpl->id), + .queue_page_list_id = cpu_to_be32(qpl_id), }; err =gve_adminq_issue_cmd (priv, &cmd);
@@ -514,11 +516,11 @@ int gve_adminq_describe_device(struct gve_priv *priv) mac = descriptor->mac;dev_info (&priv->pdev->dev,"MAC addr: %pM\n" , mac); priv->tx_pages_per_qpl =be16_to_cpu (descriptor->tx_pages_per_qpl); - priv->rx_pages_per_qpl =be16_to_cpu (descriptor->rx_pages_per_qpl); -if (priv->rx_pages_per_qpl < priv->rx_desc_cnt) { -dev_err (&priv->pdev->dev,"rx_pages_per_qpl cannot be smaller than rx_desc_cnt, setting rx_desc_cnt down to %d.\n" , - priv->rx_pages_per_qpl); - priv->rx_desc_cnt = priv->rx_pages_per_qpl; + priv->rx_data_slot_cnt =be16_to_cpu (descriptor->rx_pages_per_qpl); +if (priv->rx_data_slot_cnt < priv->rx_desc_cnt) { +dev_err (&priv->pdev->dev,"rx_data_slot_cnt cannot be smaller than rx_desc_cnt, setting rx_desc_cnt down to %d.\n" , + priv->rx_data_slot_cnt); + priv->rx_desc_cnt = priv->rx_data_slot_cnt; } priv->default_num_queues =be16_to_cpu (descriptor->default_num_queues); dev_opt = (void *)(descriptor +1 );
drivers/net/ethernet/google/gve/gve_desc.h +6 -4
@@ -72,12 +72,14 @@ struct gve_rx_desc { } __packed;static_assert (sizeof (struct gve_rx_desc ) ==64 ); -/* As with the Tx ring format, the qpl_offset entries below are offsets into an -* ordered list of registered pages. +/* If the device supports raw dma addressing then the addr in data slot is +* the dma address of the buffer. +* If the device only supports registered segments than the addr is a byte +* offset into the registered segment (an ordered list of pages) where the +* buffer is. */ struct gve_rx_data_slot { -/* byte offset into the rx registered segment of this slot */ -__be64 qpl_offset; +__be64 addr; };/* GVE Recive Packet Descriptor Seq No */
drivers/net/ethernet/google/gve/gve_main.c +2 -1
@@ -596,6 +596,7 @@ int gve_alloc_page(struct gve_priv *priv, struct device *dev,if (dma_mapping_error (dev, *dma)) { priv->dma_mapping_error++;put_page (*page); + *page =NULL ;return -ENOMEM ; }return 0 ;
@@ -694,7 +695,7 @@ static int gve_alloc_qpls(struct gve_priv *priv) }for (; i < num_qpls; i++) { err =gve_alloc_queue_page_list (priv, i, - priv->rx_pages_per_qpl); + priv->rx_data_slot_cnt);if (err) goto free_qpls; }
drivers/net/ethernet/google/gve/gve_rx.c +152 -33
340 lines not on this page · raw message
Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
PATCH v3 3/4 gve: Rx Buffer Recycling
In reply to David AwogbemilaThis patch lets the driver reuse buffers that have been freed by the networking stack.
In the raw addressing case, this allows the driver avoid allocating new buffers.
In the qpl case, the driver can avoid copies.
--- drivers/net/ethernet/google/gve/gve.h | 10 +- drivers/net/ethernet/google/gve/gve_rx.c | 197 +++++++++++++++-------- 2 files changed, 133 insertions(+), 74 deletions(-)
drivers/net/ethernet/google/gve/gve.h +1 -9
@@ -50,6 +50,7 @@ struct gve_rx_slot_page_info {struct page *page;void *page_address;u32 page_offset;/* offset to write to in page */ +bool can_flip; };/* A list of pages registered with the device during setup and used by a queue
@@ -505,15 +506,6 @@ static inline enum dma_data_direction gve_qpl_dma_dir(struct gve_priv *priv,return DMA_FROM_DEVICE ; } -/* Returns true if the max mtu allows page recycling */ -static inline bool gve_can_recycle_pages (struct net_device *dev) -{ -/* We can't recycle the pages if we can't fit a packet into half a -* page. -*/ -return dev->max_mtu <=PAGE_SIZE /2 ; -} -/* buffers */ int gve_alloc_page(struct gve_priv *priv, struct device *dev, struct page **page, dma_addr_t *dma,
drivers/net/ethernet/google/gve/gve_rx.c +132 -65
257 lines not on this page · raw message
Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
Jakub Kicinski
maintainerRe: [PATCH net-next v3 3/4] gve: Rx Buffer Recycling
Quoted 73 lines · On Wed, 23 Sep 2020 18:01:03 -0700 David Awogbemila wrote:
This patch lets the driver reuse buffers that have been freed by the networking stack.
In the raw addressing case, this allows the driver avoid allocating new buffers.
In the qpl case, the driver can avoid copies.Signed-off-by David Awogbemila <[email protected]>--- drivers/net/ethernet/google/gve/gve.h | 10 +- drivers/net/ethernet/google/gve/gve_rx.c | 197 +++++++++++++++-------- 2 files changed, 133 insertions(+), 74 deletions(-)drivers/net/ethernet/google/gve/gve.h +1
-9@@ -50,6 +50,7 @@ struct gve_rx_slot_page_info {struct page *page;void *page_address;u32 page_offset;/* offset to write to in page */ +bool can_flip; };/* A list of pages registered with the device during setup and used by a queue @@ -505,15 +506,6 @@ static inline enum dma_data_direction gve_qpl_dma_dir(struct gve_priv *priv,return DMA_FROM_DEVICE ; } -/* Returns true if the max mtu allows page recycling */ -static inline bool gve_can_recycle_pages (struct net_device *dev) -{ -/* We can't recycle the pages if we can't fit a packet into half a -* page. -*/ -return dev->max_mtu <=PAGE_SIZE /2 ; -} -/* buffers */ int gve_alloc_page(struct gve_priv *priv, struct device *dev, struct page **page, dma_addr_t *dma,drivers/net/ethernet/google/gve/gve_rx.c +2
-6@@ -263,8 +263,7 @@ static enum pkt_hash_types gve_rss_type(__be16 pkt_flags)return PKT_HASH_TYPE_L2 ; } -static struct sk_buff *gve_rx_copy (struct gve_rx_ring *rx, -struct net_device *dev, +static struct sk_buff *gve_rx_copy (struct net_device *dev,struct napi_struct *napi,struct gve_rx_slot_page_info *page_info,u16 len)@@ -282,10 +281,6 @@ static struct sk_buff *gve_rx_copy(struct gve_rx_ring *rx, skb->protocol =eth_type_trans (skb, dev); -u64_stats_update_begin (&rx->statss); - rx->rx_copied_pkt++; -u64_stats_update_end (&rx->statss); -return skb; }@@ -331,22 +326,91 @@ static void gve_rx_flip_buff(struct gve_rx_slot_page_info *page_info, {u64 addr =be64_to_cpu (data_ring->addr); +/* "flip" to other packet buffer on this page */ page_info->page_offset ^=PAGE_SIZE /2 ; addr ^=PAGE_SIZE /2 ;
drivers/net/ethernet/google/gve/gve_rx.c static void gve_rx_flip_buff(struct gve_rx_slot_page_info *page_info, · line 341
Quoted 10 lines
drivers/net/ethernet/google/gve/gve_rx.c +7
-0data_ring->addr =cpu_to_be64 (addr); } +static bool gve_rx_can_flip_buffers (struct net_device *netdev) +{ +#if PAGE_SIZE ==4096 +/* We can't flip a buffer if we can't fit a packet +* into half a page. +*/ +if (netdev->max_mtu +GVE_RX_PAD +ETH_HLEN >PAGE_SIZE /2 )
double space
drivers/net/ethernet/google/gve/gve_rx.c static void gve_rx_flip_buff(struct gve_rx_slot_page_info *page_info, · line 343
Quoted 2 lines
drivers/net/ethernet/google/gve/gve_rx.c +2
-0+return false; +return true;
Flip the condition and just return it.
return netdev->max_mtu + GVE_RX_PAD + ETH_HLEN <= PAGE_SIZE / 2
Also you should probably look at mtu not max_mtu. More likely to be in cache.
Quoted 7 lines
drivers/net/ethernet/google/gve/gve_rx.c +7
-0+#else +/* PAGE_SIZE != 4096 - don't try to reuse */ +return false; +#endif +} + +static int gve_rx_can_recycle_buffer (struct page *page)
drivers/net/ethernet/google/gve/gve_rx.c static void gve_rx_flip_buff(struct gve_rx_slot_page_info *page_info, · line 360
Quoted 10 lines
drivers/net/ethernet/google/gve/gve_rx.c +10
-0+{ +int pagecount =page_count (page); + +/* This page is not being used by any SKBs - reuse */ +if (pagecount ==1 ) { +return 1 ; +/* This page is still being used by an SKB - we can't reuse */ + }else if (pagecount >=2 ) { +return 0 ; + }
parenthesis not necessary around single line statements.
drivers/net/ethernet/google/gve/gve_rx.c static void gve_rx_flip_buff(struct gve_rx_slot_page_info *page_info, · line 371
Quoted 12 lines
drivers/net/ethernet/google/gve/gve_rx.c +5
-1+WARN (pagecount <1 ,"Pagecount should never be < 1" ); +return -1 ; +} +static struct sk_buff *gve_rx_raw_addressing (struct device *dev,struct net_device *netdev,struct gve_rx_slot_page_info *page_info,u16 len,struct napi_struct *napi, -struct gve_rx_data_slot *data_slot) +struct gve_rx_data_slot *data_slot,bool can_flip) {struct sk_buff *skb =gve_rx_add_frags (napi, page_info, len);
IMHO it looks weird when a function is called on variable init and then error checking is done after an empty line.
Quoted 10 lines
drivers/net/ethernet/google/gve/gve_rx.c +7
-0if (!skb)return NULL ; +/* Optimistically stop the kernel from freeing the page by increasing +* the page bias. We will check the refcount in refill to determine if +* we need to alloc a new page. +*/ +get_page (page_info->page); + page_info->can_flip = can_flip; +
drivers/net/ethernet/google/gve/gve_rx.c static void gve_rx_flip_buff(struct gve_rx_slot_page_info *page_info, · line 392
Quoted 10 lines
drivers/net/ethernet/google/gve/gve_rx.c +10
-0+return skb; +} + +static struct sk_buff * +gve_rx_qpl (struct device *dev,struct net_device *netdev, +struct gve_rx_ring *rx,struct gve_rx_slot_page_info *page_info, +u16 len,struct napi_struct *napi, +struct gve_rx_data_slot *data_slot,bool recycle) +{ +struct sk_buff *skb;
empty line here
drivers/net/ethernet/google/gve/gve_rx.c static void gve_rx_flip_buff(struct gve_rx_slot_page_info *page_info, · line 394
Quoted 2 lines
drivers/net/ethernet/google/gve/gve_rx.c +2
-0+/* if raw_addressing mode is not enabled gvnic can only receive into +* registered segmens. If the buffer can't be recycled, our only
segments?
Quoted 60 lines
drivers/net/ethernet/google/gve/gve_rx.c +45
-7+* choice is to copy the data out of it so that we can return it to the +* device. +*/ +if (recycle) { + skb =gve_rx_add_frags (napi, page_info, len); +/* No point in recycling if we didn't get the skb */ +if (skb) { +/* Make sure the networking stack can't free the page */ +get_page (page_info->page); +gve_rx_flip_buff (page_info, data_slot); + } + }else { + skb =gve_rx_copy (netdev, napi, page_info, len); +if (skb) { +u64_stats_update_begin (&rx->statss); + rx->rx_copied_pkt++; +u64_stats_update_end (&rx->statss); + } + }return skb; }@@ -490,14 +525,46 @@ static bool gve_rx_refill_buffers(struct gve_priv *priv, struct gve_rx_ring *rx)while ((fill_cnt & rx->mask) != (rx->cnt & rx->mask)) {u32 idx = fill_cnt & rx->mask; -struct gve_rx_slot_page_info *page_info = &rx->data.page_info[idx]; -struct gve_rx_data_slot *data_slot = &rx->data.data_ring[idx]; -struct device *dev = &priv->pdev->dev; +struct gve_rx_slot_page_info *page_info = + &rx->data.page_info[idx]; -gve_rx_free_buffer (dev, page_info, data_slot); - page_info->page =NULL ; -if (gve_rx_alloc_buffer (priv, dev, page_info, data_slot, rx)) -break ; +if (page_info->can_flip) { +/* The other half of the page is free because it was +* free when we processed the descriptor. Flip to it. +*/ +struct gve_rx_data_slot *data_slot = + &rx->data.data_ring[idx]; + +gve_rx_flip_buff (page_info, data_slot); + page_info->can_flip = false; + }else { +/* It is possible that the networking stack has already +* finished processing all outstanding packets in the buffer +* and it can be reused. +* Flipping is unnecessary here - if the networking stack still +* owns half the page it is impossible to tell which half. Either +* the whole page is free or it needs to be replaced. +*/ +int recycle =gve_rx_can_recycle_buffer (page_info->page); + +if (recycle <0 ) { +gve_schedule_reset (priv); +return false; + } +if (!recycle) {
drivers/net/ethernet/google/gve/gve_rx.c static bool gve_rx_refill_buffers(struct gve_priv *priv, struct gve_rx_ring *rx) · line 564
Quoted 10 lines
drivers/net/ethernet/google/gve/gve_rx.c +10
-0+/* We can't reuse the buffer - alloc a new one*/ +struct gve_rx_data_slot *data_slot = + &rx->data.data_ring[idx]; +struct device *dev = &priv->pdev->dev; + +gve_rx_free_buffer (dev, page_info, data_slot); + page_info->page =NULL ; +if (gve_rx_alloc_buffer (priv, dev, page_info, + data_slot, rx)) { +break ;
What if the queue runs completely dry during memory shortage? You need some form of delayed work to periodically refill the free buffers, right?
drivers/net/ethernet/google/gve/gve_rx.c static bool gve_rx_refill_buffers(struct gve_priv *priv, struct gve_rx_ring *rx) · line 565
Quoted 1 line
drivers/net/ethernet/google/gve/gve_rx.c +1
-0+ }
parens unnecessary
Quoted 5 lines
drivers/net/ethernet/google/gve/gve_rx.c +2
-0+ } + } fill_cnt++; } rx->fill_cnt = fill_cnt;
Re: [PATCH net-next v3 3/4] gve: Rx Buffer Recycling
Quoted 78 lines · Jakub Kicinski
Quoted 76 lines · On Wed, 23 Sep 2020 18:01:03 -0700 David Awogbemila wrote:
This patch lets the driver reuse buffers that have been freed by the networking stack.
In the raw addressing case, this allows the driver avoid allocating new buffers.
In the qpl case, the driver can avoid copies.Signed-off-by David Awogbemila <[email protected]>--- drivers/net/ethernet/google/gve/gve.h | 10 +- drivers/net/ethernet/google/gve/gve_rx.c | 197 +++++++++++++++-------- 2 files changed, 133 insertions(+), 74 deletions(-)drivers/net/ethernet/google/gve/gve.h +1
-9@@ -50,6 +50,7 @@ struct gve_rx_slot_page_info {struct page *page;void *page_address;u32 page_offset;/* offset to write to in page */ +bool can_flip; };/* A list of pages registered with the device during setup and used by a queue @@ -505,15 +506,6 @@ static inline enum dma_data_direction gve_qpl_dma_dir(struct gve_priv *priv,return DMA_FROM_DEVICE ; } -/* Returns true if the max mtu allows page recycling */ -static inline bool gve_can_recycle_pages (struct net_device *dev) -{ -/* We can't recycle the pages if we can't fit a packet into half a -* page. -*/ -return dev->max_mtu <=PAGE_SIZE /2 ; -} -/* buffers */ int gve_alloc_page(struct gve_priv *priv, struct device *dev, struct page **page, dma_addr_t *dma,drivers/net/ethernet/google/gve/gve_rx.c +2
-6@@ -263,8 +263,7 @@ static enum pkt_hash_types gve_rss_type(__be16 pkt_flags)return PKT_HASH_TYPE_L2 ; } -static struct sk_buff *gve_rx_copy (struct gve_rx_ring *rx, -struct net_device *dev, +static struct sk_buff *gve_rx_copy (struct net_device *dev,struct napi_struct *napi,struct gve_rx_slot_page_info *page_info,u16 len)@@ -282,10 +281,6 @@ static struct sk_buff *gve_rx_copy(struct gve_rx_ring *rx, skb->protocol =eth_type_trans (skb, dev); -u64_stats_update_begin (&rx->statss); - rx->rx_copied_pkt++; -u64_stats_update_end (&rx->statss); -return skb; }@@ -331,22 +326,91 @@ static void gve_rx_flip_buff(struct gve_rx_slot_page_info *page_info, {u64 addr =be64_to_cpu (data_ring->addr); +/* "flip" to other packet buffer on this page */ page_info->page_offset ^=PAGE_SIZE /2 ; addr ^=PAGE_SIZE /2 ; data_ring->addr =cpu_to_be64 (addr); }
Quoted 9 lines
drivers/net/ethernet/google/gve/gve_rx.c static void gve_rx_flip_buff(struct gve_rx_slot_page_info *page_info, · line 341
Quoted 7 lines
drivers/net/ethernet/google/gve/gve_rx.c +7
-0+static bool gve_rx_can_flip_buffers (struct net_device *netdev) +{ +#if PAGE_SIZE ==4096 +/* We can't flip a buffer if we can't fit a packet +* into half a page. +*/ +if (netdev->max_mtu +GVE_RX_PAD +ETH_HLEN >PAGE_SIZE /2 )double space
I'll adjust this.
Quoted 9 lines
drivers/net/ethernet/google/gve/gve_rx.c static void gve_rx_flip_buff(struct gve_rx_slot_page_info *page_info, · line 343
Quoted 2 lines
drivers/net/ethernet/google/gve/gve_rx.c +2
-0+return false; +return true;Flip the condition and just return it.
return
netdev->max_mtu+GVE_RX_PAD+ETH_HLEN<=PAGE_SIZE/ 2Also you should probably look at mtu not
max_mtu. More likely to be in cache.
Ok, I'll adjust this to use mtu instead.
Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/google/gve/gve_rx.c +11
-0+#else +/* PAGE_SIZE != 4096 - don't try to reuse */ +return false; +#endif +} + +static int gve_rx_can_recycle_buffer (struct page *page) +{ +int pagecount =page_count (page); + +/* This page is not being used by any SKBs - reuse */
Quoted 8 lines
drivers/net/ethernet/google/gve/gve_rx.c static void gve_rx_flip_buff(struct gve_rx_slot_page_info *page_info, · line 360
Quoted 6 lines
drivers/net/ethernet/google/gve/gve_rx.c +6
-0+if (pagecount ==1 ) { +return 1 ; +/* This page is still being used by an SKB - we can't reuse */ + }else if (pagecount >=2 ) { +return 0 ; + }parenthesis not necessary around single line statements.
I'll adjust this.
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/google/gve/gve_rx.c +4
-0+WARN (pagecount <1 ,"Pagecount should never be < 1" ); +return -1 ; +} +static struct sk_buff * gve_rx_raw_addressing(struct device *dev, struct net_device *netdev, struct gve_rx_slot_page_info *page_info, u16 len,
Quoted 8 lines
drivers/net/ethernet/google/gve/gve_rx.c static void gve_rx_flip_buff(struct gve_rx_slot_page_info *page_info, · line 371
Quoted 5 lines
drivers/net/ethernet/google/gve/gve_rx.c +1
-1struct napi_struct *napi, - struct gve_rx_data_slot *data_slot) + struct gve_rx_data_slot *data_slot, bool can_flip) { struct sk_buff *skb = gve_rx_add_frags(napi, page_info, len);IMHO it looks weird when a function is called on variable init and then error checking is done after an empty line.
Ok, I'll declare skb and then initialize it separately.
Quoted 14 lines
Quoted 14 lines
drivers/net/ethernet/google/gve/gve_rx.c +11
-0if (!skb)return NULL ; +/* Optimistically stop the kernel from freeing the page by increasing +* the page bias. We will check the refcount in refill to determine if +* we need to alloc a new page. +*/ +get_page (page_info->page); + page_info->can_flip = can_flip; + +return skb; +} + +static struct sk_buff *
Quoted 8 lines
drivers/net/ethernet/google/gve/gve_rx.c static void gve_rx_flip_buff(struct gve_rx_slot_page_info *page_info, · line 392
Quoted 6 lines
drivers/net/ethernet/google/gve/gve_rx.c +6
-0+gve_rx_qpl(struct device *dev, struct net_device *netdev, + struct gve_rx_ring *rx, struct gve_rx_slot_page_info *page_info, + u16 len, struct napi_struct *napi, + struct gve_rx_data_slot *data_slot, bool recycle) +{ + struct sk_buff *skb;empty line here
I'll adjust this.
Quoted 4 lines
drivers/net/ethernet/google/gve/gve_rx.c static void gve_rx_flip_buff(struct gve_rx_slot_page_info *page_info, · line 394
Quoted 2 lines
drivers/net/ethernet/google/gve/gve_rx.c +2
-0+/* if raw_addressing mode is not enabled gvnic can only receive into +* registered segmens. If the buffer can't be recycled, our only segments?
I'll correct this.
Quoted 66 lines
Quoted 66 lines
drivers/net/ethernet/google/gve/gve_rx.c +51
-7+* choice is to copy the data out of it so that we can return it to the +* device. +*/ +if (recycle) { + skb =gve_rx_add_frags (napi, page_info, len); +/* No point in recycling if we didn't get the skb */ +if (skb) { +/* Make sure the networking stack can't free the page */ +get_page (page_info->page); +gve_rx_flip_buff (page_info, data_slot); + } + }else { + skb =gve_rx_copy (netdev, napi, page_info, len); +if (skb) { +u64_stats_update_begin (&rx->statss); + rx->rx_copied_pkt++; +u64_stats_update_end (&rx->statss); + } + }return skb; }@@ -490,14 +525,46 @@ static bool gve_rx_refill_buffers(struct gve_priv *priv, struct gve_rx_ring *rx)while ((fill_cnt & rx->mask) != (rx->cnt & rx->mask)) {u32 idx = fill_cnt & rx->mask; -struct gve_rx_slot_page_info *page_info = &rx->data.page_info[idx]; -struct gve_rx_data_slot *data_slot = &rx->data.data_ring[idx]; -struct device *dev = &priv->pdev->dev; +struct gve_rx_slot_page_info *page_info = + &rx->data.page_info[idx]; -gve_rx_free_buffer (dev, page_info, data_slot); - page_info->page =NULL ; -if (gve_rx_alloc_buffer (priv, dev, page_info, data_slot, rx)) -break ; +if (page_info->can_flip) { +/* The other half of the page is free because it was +* free when we processed the descriptor. Flip to it. +*/ +struct gve_rx_data_slot *data_slot = + &rx->data.data_ring[idx]; + +gve_rx_flip_buff (page_info, data_slot); + page_info->can_flip = false; + }else { +/* It is possible that the networking stack has already +* finished processing all outstanding packets in the buffer +* and it can be reused. +* Flipping is unnecessary here - if the networking stack still +* owns half the page it is impossible to tell which half. Either +* the whole page is free or it needs to be replaced. +*/ +int recycle =gve_rx_can_recycle_buffer (page_info->page); + +if (recycle <0 ) { +gve_schedule_reset (priv); +return false; + } +if (!recycle) { +/* We can't reuse the buffer - alloc a new one*/ +struct gve_rx_data_slot *data_slot = + &rx->data.data_ring[idx]; +struct device *dev = &priv->pdev->dev; + +gve_rx_free_buffer (dev, page_info, data_slot);
Quoted 8 lines
drivers/net/ethernet/google/gve/gve_rx.c static bool gve_rx_refill_buffers(struct gve_priv *priv, struct gve_rx_ring *rx) · line 564
Quoted 4 lines
drivers/net/ethernet/google/gve/gve_rx.c +4
-0+ page_info->page =NULL ; +if (gve_rx_alloc_buffer (priv, dev, page_info, + data_slot, rx)) { +break ;What if the queue runs completely dry during memory shortage? You need some form of delayed work to periodically refill the free buffers, right?
Thanks, this looks like it will require modifications that will need to be well tested.
Just for my own curiosity, how common of an occurrence are such memory shortages?
Quoted 4 lines
drivers/net/ethernet/google/gve/gve_rx.c static bool gve_rx_refill_buffers(struct gve_priv *priv, struct gve_rx_ring *rx) · line 565
Quoted 2 lines
drivers/net/ethernet/google/gve/gve_rx.c +1
-0+ }parens unnecessary
I'll adjust this.
Jakub Kicinski
maintainerRe: [PATCH net-next v3 3/4] gve: Rx Buffer Recycling
Quoted 8 lines · On Wed, 30 Sep 2020 09:10:02 -0700 David Awogbemila wrote:
Quoted 3 lines
What if the queue runs completely dry during memory shortage? You need some form of delayed work to periodically refill the free buffers, right?
Thanks, this looks like it will require modifications that will need to be well tested.
Just for my own curiosity, how common of an occurrence are such memory shortages?
Depends on the workload. For some apps they are very common.
PATCH v3 4/4 gve: Add support for raw addressing in the tx path
In reply to David AwogbemilaFrom: Catherine Sullivan <[email protected]>
During TX, skbs' data addresses are dma_map'ed and passed to the NIC. This means that the device can perform DMA directly from these addresses and the driver does not have to copy the buffer content into pre-allocated buffers/qpls (as in qpl mode).
--- drivers/net/ethernet/google/gve/gve.h | 18 +- drivers/net/ethernet/google/gve/gve_adminq.c | 4 +- drivers/net/ethernet/google/gve/gve_desc.h | 8 +- drivers/net/ethernet/google/gve/gve_tx.c | 205 +++++++++++++++---- 4 files changed, 193 insertions(+), 42 deletions(-)
drivers/net/ethernet/google/gve/gve.h +16 -2
@@ -112,12 +112,20 @@ struct gve_tx_iovec {u32 iov_padding;/* padding associated with this segment */ }; +struct gve_tx_dma_buf { +DEFINE_DMA_UNMAP_ADDR (dma); +DEFINE_DMA_UNMAP_LEN (len); +}; +/* Tracks the memory in the fifo occupied by the skb. Mapped 1:1 to a desc * ring entry but only used for a pkt_desc not a seg_desc */ struct gve_tx_buffer_state {struct sk_buff *skb;/* skb for this pkt */ -struct gve_tx_iovec iov[GVE_TX_MAX_IOVEC ];/* segments of this pkt */ +union { +struct gve_tx_iovec iov[GVE_TX_MAX_IOVEC ];/* segments of this pkt */ +struct gve_tx_dma_buf buf; + }; };/* A TX buffer - each queue has one */
@@ -140,13 +148,16 @@ struct gve_tx_ring {__be32 last_nic_done____cacheline_aligned ;/* NIC tail pointer */ u64 pkt_done;/* free-running - total packets completed */ u64 bytes_done;/* free-running - total bytes completed */ +u32 dropped_pkt;/* free-running - total packets dropped */ /* Cacheline 2 -- Read-mostly fields */ union gve_tx_desc *desc____cacheline_aligned ;struct gve_tx_buffer_state *info;/* Maps 1:1 to a desc */ struct netdev_queue *netdev_txq;struct gve_queue_resources *q_resources;/* head and tail pointer idx */ +struct device *dev;u32 mask;/* masks req and done down to queue size */ +bool raw_addressing;/* use raw_addressing? */ /* Slow-path fields */ u32 q_num____cacheline_aligned ;/* queue idx */
@@ -442,7 +453,10 @@ static inline u32 gve_rx_idx_to_ntfy(struct gve_priv *priv, u32 queue_idx)*/ static inline u32 gve_num_tx_qpls (struct gve_priv *priv) { -return priv->tx_cfg.num_queues; +if (priv->raw_addressing) +return 0 ; +else +return priv->tx_cfg.num_queues; }/* Returns the number of rx queue page lists
drivers/net/ethernet/google/gve/gve_adminq.c +3 -1
@@ -318,8 +318,10 @@ static int gve_adminq_create_tx_queue(struct gve_priv *priv, u32 queue_index) {struct gve_tx_ring *tx = &priv->tx[queue_index];union gve_adminq_command cmd; +u32 qpl_id;int err; + qpl_id = priv->raw_addressing ?GVE_RAW_ADDRESSING_QPL_ID : tx->tx_fifo.qpl->id;memset (&cmd,0 ,sizeof (cmd)); cmd.opcode =cpu_to_be32 (GVE_ADMINQ_CREATE_TX_QUEUE ); cmd.create_tx_queue = (struct gve_adminq_create_tx_queue ) {
@@ -328,7 +330,7 @@ static int gve_adminq_create_tx_queue(struct gve_priv *priv, u32 queue_index) .queue_resources_addr = cpu_to_be64(tx->q_resources_bus), .tx_ring_addr = cpu_to_be64(tx->bus), - .queue_page_list_id = cpu_to_be32(tx->tx_fifo.qpl->id), + .queue_page_list_id = cpu_to_be32(qpl_id), .ntfy_id = cpu_to_be32(tx->ntfy_id), };
drivers/net/ethernet/google/gve/gve_desc.h +5 -3
@@ -16,9 +16,11 @@* Base addresses encoded in seg_addr are not assumed to be physical * addresses. The ring format assumes these come from some linear address * space. This could be physical memory, kernel virtual memory, user virtual -* memory. gVNIC uses lists of registered pages. Each queue is assumed -* to be associated with a single such linear address space to ensure a -* consistent meaning for seg_addrs posted to its rings. +* memory. +* If raw dma addressing is not supported then gVNIC uses lists of registered +* pages. Each queue is assumed to be associated with a single such linear +* address space to ensure a consistent meaning for seg_addrs posted to its +* rings. */ struct gve_tx_pkt_desc {
drivers/net/ethernet/google/gve/gve_tx.c +169 -36
301 lines not on this page · raw message
Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
Re: [PATCH net-next v3 4/4] gve: Add support for raw addressing in the tx path
drivers/net/ethernet/google/gve/gve_tx.c static int gve_tx_add_skb(struct gve_tx_ring *tx, struct sk_buff *skb, · line 530
Quoted 1 line · On Wed, 23 Sep 2020 18:01:04 -0700 David Awogbemila wrote:
drivers/net/ethernet/google/gve/gve_tx.c +1
-0+ info->skb = skb;
double space
Quoted 7 lines
drivers/net/ethernet/google/gve/gve_tx.c +7
-0+ addr =dma_map_single (tx->dev, skb->data, len,DMA_TO_DEVICE ); +if (unlikely (dma_mapping_error (tx->dev, addr))) { + priv->dma_mapping_error++; + goto drop; + } + buf = &info->buf; +dma_unmap_len_set (buf, len, len);
drivers/net/ethernet/google/gve/gve_tx.c static int gve_tx_add_skb(struct gve_tx_ring *tx, struct sk_buff *skb, · line 548
Quoted 10 lines
drivers/net/ethernet/google/gve/gve_tx.c +10
-0+dma_unmap_addr_set (buf, dma, addr); + + payload_nfrags = shinfo->nr_frags; +if (hlen < len) { +/* For gso the rest of the linear portion of the skb needs to +* be in its own descriptor. +*/ + payload_nfrags++; +gve_tx_fill_pkt_desc (pkt_desc, skb, is_gso, l4_hdr_offset, +1 + payload_nfrags, hlen, addr);
This..
drivers/net/ethernet/google/gve/gve_tx.c static int gve_tx_add_skb(struct gve_tx_ring *tx, struct sk_buff *skb, · line 558
Quoted 9 lines
drivers/net/ethernet/google/gve/gve_tx.c +9
-0+ len -= hlen; + addr += hlen; + seg_desc = &tx->desc[(tx->req +1 ) & tx->mask]; + seg_idx_bias =2 ; +gve_tx_fill_seg_desc (seg_desc, skb, is_gso, len, addr); + }else { + seg_idx_bias =1 ; +gve_tx_fill_pkt_desc (pkt_desc, skb, is_gso, l4_hdr_offset, +1 + payload_nfrags, hlen, addr);
and this look identical. You can probably move it before the if.
Otherwise this one is:
Re: [PATCH net-next v3 4/4] gve: Add support for raw addressing in the tx path
Quoted 5 lines · Jakub Kicinski
Quoted 1 line · On Wed, 23 Sep 2020 18:01:04 -0700 David Awogbemila wrote:
+
info->skb= skb;double space
Ok, I'll fix this.
Quoted 31 lines
Quoted 8 lines
drivers/net/ethernet/google/gve/gve_tx.c +7
-0+ addr =dma_map_single (tx->dev, skb->data, len,DMA_TO_DEVICE ); +if (unlikely (dma_mapping_error (tx->dev, addr))) { + priv->dma_mapping_error++; + goto drop; + } + buf = &info->buf; +dma_unmap_len_set (buf, len, len);drivers/net/ethernet/google/gve/gve_tx.c static int gve_tx_add_skb(struct gve_tx_ring *tx, struct sk_buff *skb, · line 548
Quoted 10 lines
drivers/net/ethernet/google/gve/gve_tx.c +10
-0+dma_unmap_addr_set (buf, dma, addr); + + payload_nfrags = shinfo->nr_frags; +if (hlen < len) { +/* For gso the rest of the linear portion of the skb needs to +* be in its own descriptor. +*/ + payload_nfrags++; +gve_tx_fill_pkt_desc (pkt_desc, skb, is_gso, l4_hdr_offset, +1 + payload_nfrags, hlen, addr);This..
drivers/net/ethernet/google/gve/gve_tx.c static int gve_tx_add_skb(struct gve_tx_ring *tx, struct sk_buff *skb, · line 558
Quoted 9 lines
drivers/net/ethernet/google/gve/gve_tx.c +9
-0+ len -= hlen; + addr += hlen; + seg_desc = &tx->desc[(tx->req +1 ) & tx->mask]; + seg_idx_bias =2 ; +gve_tx_fill_seg_desc (seg_desc, skb, is_gso, len, addr); + }else { + seg_idx_bias =1 ; +gve_tx_fill_pkt_desc (pkt_desc, skb, is_gso, l4_hdr_offset, +1 + payload_nfrags, hlen, addr);
Quoted 1 line
and this look identical. You can probably move it before the if.
Thanks, I need to make sure I understand: you're referring to the call to gve_tx_fill_pkt_desc? if so, the calls look the same but payload_nfrags is different in the if and else cases, perhaps I could move it after the else? but I'm not sure if that helps.
Quoted 4 lines
Otherwise this one is:
Reviewed-by Jakub Kicinski <[email protected]>
Jakub Kicinski
maintainerRe: [PATCH net-next v3 4/4] gve: Add support for raw addressing in the tx path
Quoted 10 lines · On Wed, 30 Sep 2020 09:09:57 -0700 David Awogbemila wrote:
Quoted 10 lines
Quoted 9 lines
drivers/net/ethernet/google/gve/gve_tx.c +9
-0+ len -= hlen; + addr += hlen; + seg_desc = &tx->desc[(tx->req +1 ) & tx->mask]; + seg_idx_bias =2 ; +gve_tx_fill_seg_desc (seg_desc, skb, is_gso, len, addr); + }else { + seg_idx_bias =1 ; +gve_tx_fill_pkt_desc (pkt_desc, skb, is_gso, l4_hdr_offset, +1 + payload_nfrags, hlen, addr);
Quoted 6 lines
Quoted 1 line
and this look identical. You can probably move it before the if.
Thanks, I need to make sure I understand: you're referring to the call to
gve_tx_fill_pkt_desc? if so, the calls look the same butpayload_nfragsis different in the if and else cases, perhaps I could move it after the else? but I'm not sure if that helps.
Fair, you can leave it as is.
kernel test robot
build botRe: [PATCH net-next v3 4/4] gve: Add support for raw addressing in the tx path
In reply to David AwogbemilaI love your patch! Perhaps something to improve:
Hi David,
I love your patch! Perhaps something to improve:
[auto build test WARNING on net-next/master]
url: https://github.com/0day-ci/linux/commits/David-Awogbemila/GVE-Raw-Addressing/20200924-091514 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 68d4fd30c83b1b208e08c954cd45e6474b148c87 config: riscv-randconfig-r003-20200930 (attached as .config) compiler: riscv32-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/a1e5a942c313ca3513dcf760370e780af10f694d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review David-Awogbemila/GVE-Raw-Addressing/20200924-091514 git checkout a1e5a942c313ca3513dcf760370e780af10f694d
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=riscv
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
drivers/net/ethernet/google/gve/gve_tx.c: In function 'gve_tx_add_skb_no_copy':
>> drivers/net/ethernet/google/gve/gve_tx.c:511:25: warning: variable 'buf' set but not used [-Wunused-but-set-variable]
511 | struct gve_tx_dma_buf *buf;
| ^~~vim +/buf +511 drivers/net/ethernet/google/gve/gve_tx.c
501
502 static int gve_tx_add_skb_no_copy(struct gve_priv *priv, struct gve_tx_ring *tx,
503 struct sk_buff *skb)
504 {
505 const struct skb_shared_info *shinfo = skb_shinfo(skb);
506 int hlen, payload_nfrags, l4_hdr_offset, seg_idx_bias;
507 union gve_tx_desc *pkt_desc, *seg_desc;
508 struct gve_tx_buffer_state *info;
509 bool is_gso = skb_is_gso(skb);
510 u32 idx = tx->req & tx->mask;
> 511 struct gve_tx_dma_buf *buf;
512 int last_mapped = 0;
513 u64 addr;
514 u32 len;
515 int i;
516
517 info = &tx->info[idx];
518 pkt_desc = &tx->desc[idx];
519
520 l4_hdr_offset = skb_checksum_start_offset(skb);
521 /* If the skb is gso, then we want only up to the tcp header in the first segment
522 * to efficiently replicate on each segment otherwise we want the linear portion
523 * of the skb (which will contain the checksum because skb->csum_start and
524 * skb->csum_offset are given relative to skb->head) in the first segment.
525 */
526 hlen = is_gso ? l4_hdr_offset + tcp_hdrlen(skb) :
527 skb_headlen(skb);
528 len = skb_headlen(skb);
529
530 info->skb = skb;
531
532 addr = dma_map_single(tx->dev, skb->data, len, DMA_TO_DEVICE);
533 if (unlikely(dma_mapping_error(tx->dev, addr))) {
534 priv->dma_mapping_error++;
535 goto drop;
536 }
537 buf = &info->buf;
538 dma_unmap_len_set(buf, len, len);
539 dma_unmap_addr_set(buf, dma, addr);
540
541 payload_nfrags = shinfo->nr_frags;
542 if (hlen < len) {
543 /* For gso the rest of the linear portion of the skb needs to
544 * be in its own descriptor.
545 */
546 payload_nfrags++;
547 gve_tx_fill_pkt_desc(pkt_desc, skb, is_gso, l4_hdr_offset,
548 1 + payload_nfrags, hlen, addr);
549
550 len -= hlen;
551 addr += hlen;
552 seg_desc = &tx->desc[(tx->req + 1) & tx->mask];
553 seg_idx_bias = 2;
554 gve_tx_fill_seg_desc(seg_desc, skb, is_gso, len, addr);
555 } else {
556 seg_idx_bias = 1;
557 gve_tx_fill_pkt_desc(pkt_desc, skb, is_gso, l4_hdr_offset,
558 1 + payload_nfrags, hlen, addr);
559 }
560 idx = (tx->req + seg_idx_bias) & tx->mask;
561
562 for (i = 0; i < payload_nfrags - (seg_idx_bias - 1); i++) {
563 const skb_frag_t *frag = &shinfo->frags[i];
564
565 seg_desc = &tx->desc[idx];
566 len = skb_frag_size(frag);
567 addr = skb_frag_dma_map(tx->dev, frag, 0, len, DMA_TO_DEVICE);
568 if (unlikely(dma_mapping_error(tx->dev, addr))) {
569 priv->dma_mapping_error++;
570 goto unmap_drop;
571 }
572 buf = &tx->info[idx].buf;
573 tx->info[idx].skb = NULL;
574 dma_unmap_len_set(buf, len, len);
575 dma_unmap_addr_set(buf, dma, addr);
576
577 gve_tx_fill_seg_desc(seg_desc, skb, is_gso, len, addr);
578 idx = (idx + 1) & tx->mask;
579 }
580
581 return 1 + payload_nfrags;
582
583 unmap_drop:
584 i--;
585 for (last_mapped = i + seg_idx_bias; last_mapped >= 0; last_mapped--) {
586 idx = (tx->req + last_mapped) & tx->mask;
587 gve_tx_unmap_buf(tx->dev, &tx->info[idx]);
588 }
589 drop:
590 tx->dropped_pkt++;
591 return 0;
592 }
593
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org