gve: add header split support
Subsystems (3)
PATCH 1/1 gve: add header split support
From: Jeroen de Borst <[email protected]>
- Add device option to recive device's packet buffer size and header buffer size. The driver will use the header-buffer size to determine if header-split is on.
- A dma_pool is introduced for the header buffers. Header buffers are always copied directly into the skb header and payload is always added as a frag.
- Add header-split and strict-header-split ethtool priv flags. These flags control header-split behavior. It can be turned on/off and it can be set to 'strict' which will cause the driver to drop all the packets that don't have a proper header split.
- Add max-rx-buffer-size priv flag to allow user to switch the packet buffer size between max and default(e.g. 4K <-> 2K).
- Add reconfigure rx rings to support the header split and max-rx-buffer-size enable/disable switch.
--- drivers/net/ethernet/google/gve/gve.h | 57 +++- drivers/net/ethernet/google/gve/gve_adminq.c | 77 ++++- drivers/net/ethernet/google/gve/gve_adminq.h | 19 +- drivers/net/ethernet/google/gve/gve_dqo.h | 2 + drivers/net/ethernet/google/gve/gve_ethtool.c | 111 ++++++-- drivers/net/ethernet/google/gve/gve_main.c | 197 ++++++++----- drivers/net/ethernet/google/gve/gve_rx_dqo.c | 264 ++++++++++++++++-- drivers/net/ethernet/google/gve/gve_utils.c | 16 +- drivers/net/ethernet/google/gve/gve_utils.h | 3 + 9 files changed, 621 insertions(+), 125 deletions(-)
drivers/net/ethernet/google/gve/gve.h +56 -1
@@ -48,10 +48,17 @@#define GVE_RX_BUFFER_SIZE_DQO 2048 +#define GVE_MIN_RX_BUFFER_SIZE 2048 +#define GVE_MAX_RX_BUFFER_SIZE 4096 +#define GVE_XDP_ACTIONS 5#define GVE_GQ_TX_MIN_PKT_DESC_BYTES 182 +#define GVE_HEADER_BUFFER_SIZE_MIN 64 +#define GVE_HEADER_BUFFER_SIZE_MAX 256 +#define GVE_HEADER_BUFFER_SIZE_DEFAULT 128 +#define DQO_QPL_DEFAULT_TX_PAGES 512#define DQO_QPL_DEFAULT_RX_PAGES 2048
@@ -145,6 +152,11 @@ struct gve_rx_compl_queue_dqo {u32 mask;/* Mask for indices to the size of the ring */ }; +struct gve_header_buf { +u8 *data; +dma_addr_t addr; +}; +/* Stores state for tracking buffers posted to HW */ struct gve_rx_buf_state_dqo {/* The page posted to HW. */
@@ -158,6 +170,9 @@ struct gve_rx_buf_state_dqo {*/ u32 last_single_ref_offset; +/* Pointer to the header buffer when header-split is active */ +struct gve_header_buf *hdr_buf; +/* Linked list index to next element in the list, or -1 if none */ s16 next; };
@@ -247,19 +262,27 @@ struct gve_rx_ring {/* track number of used buffers */ u16 used_buf_states_cnt; + +/* Array of buffers for header-split */ +struct gve_header_buf *hdr_bufs; } dqo; };u64 rbytes;/* free-running bytes received */ +u64 rheader_bytes;/* free-running header bytes received */ u64 rpackets;/* free-running packets received */ 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 */ +u64 rx_hsplit_pkt;/* free-running packets with headers split */ +u64 rx_hsplit_hbo_pkt;/* free-running packets with header buffer overflow */ 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 by header-split overflow */ +u64 rx_hsplit_err_dropped_pkt;u64 rx_cont_packet_cnt;/* free-running multi-fragment packets received */ u64 rx_frag_flip_cnt;/* free-running count of rx segments where page_flip was used */ u64 rx_frag_copy_cnt;/* free-running count of rx segments copied */
@@ -711,6 +734,7 @@ struct gve_priv {u64 stats_report_len;dma_addr_t stats_report_bus;/* dma address for the stats report */ unsigned long ethtool_flags; +unsigned long ethtool_defaults;/* default flags */ unsigned long stats_report_timer_period;struct timer_list stats_report_timer;
@@ -724,12 +748,20 @@ struct gve_priv {/* Must be a power of two. */ int data_buffer_size_dqo; +int dev_max_rx_buffer_size;/* The max rx buffer size that device support*/ enum gve_queue_format queue_format;/* Interrupt coalescing settings */ u32 tx_coalesce_usecs;u32 rx_coalesce_usecs; + +/* The size of buffers to allocate for the headers. +* A non-zero value enables header-split. +*/ +u16 header_buf_size; +u8 header_split_strict; +struct dma_pool *header_buf_pool; };enum gve_service_task_flags_bit {
@@ -747,9 +779,18 @@ enum gve_state_flags_bit { };enum gve_ethtool_flags_bit { -GVE_PRIV_FLAGS_REPORT_STATS =0 , +GVE_PRIV_FLAGS_REPORT_STATS =0 , +GVE_PRIV_FLAGS_ENABLE_HEADER_SPLIT =1 , +GVE_PRIV_FLAGS_ENABLE_STRICT_HEADER_SPLIT =2 , +GVE_PRIV_FLAGS_ENABLE_MAX_RX_BUFFER_SIZE =3 , }; +#define GVE_PRIV_FLAGS_MASK \ + (BIT(GVE_PRIV_FLAGS_REPORT_STATS) | \ + BIT(GVE_PRIV_FLAGS_ENABLE_HEADER_SPLIT) | \ + BIT(GVE_PRIV_FLAGS_ENABLE_STRICT_HEADER_SPLIT) | \ + BIT(GVE_PRIV_FLAGS_ENABLE_MAX_RX_BUFFER_SIZE)) +static inline bool gve_get_do_reset (struct gve_priv *priv) {return test_bit (GVE_PRIV_FLAGS_DO_RESET , &priv->service_task_flags);
@@ -883,6 +924,16 @@ static inline void gve_clear_report_stats(struct gve_priv *priv)clear_bit (GVE_PRIV_FLAGS_REPORT_STATS , &priv->ethtool_flags); } +static inline bool gve_get_enable_header_split (struct gve_priv *priv) +{ +return test_bit (GVE_PRIV_FLAGS_ENABLE_HEADER_SPLIT , &priv->ethtool_flags); +} + +static inline bool gve_get_enable_max_rx_buffer_size (struct gve_priv *priv) +{ +return test_bit (GVE_PRIV_FLAGS_ENABLE_MAX_RX_BUFFER_SIZE , &priv->ethtool_flags); +} +/* Returns the address of the ntfy_blocks irq doorbell */ static inline __be32 __iomem *gve_irq_doorbell(struct gve_priv *priv,
@@ -1056,6 +1107,10 @@ int gve_rx_poll(struct gve_notify_block *block, int budget);bool gve_rx_work_pending (struct gve_rx_ring *rx);int gve_rx_alloc_rings (struct gve_priv *priv);void gve_rx_free_rings_gqi (struct gve_priv *priv); +int gve_recreate_rx_rings (struct gve_priv *priv); +int gve_reconfigure_rx_rings (struct gve_priv *priv, +bool enable_hdr_split, +int packet_buffer_size);/* Reset */ void gve_schedule_reset (struct gve_priv *priv);int gve_reset (struct gve_priv *priv,bool attempt_teardown);
drivers/net/ethernet/google/gve/gve_adminq.c +71 -6
136 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_adminq.h +17 -2
@@ -125,6 +125,14 @@ struct gve_device_option_jumbo_frames {static_assert (sizeof (struct gve_device_option_jumbo_frames ) ==8 ); +struct gve_device_option_buffer_sizes { +__be32 supported_features_mask; +__be16 packet_buffer_size; +__be16 header_buffer_size; +}; + +static_assert (sizeof (struct gve_device_option_buffer_sizes ) ==8 ); +/* Terminology: * * RDA - Raw DMA Addressing - Buffers associated with SKBs are directly DMA
@@ -140,6 +148,7 @@ enum gve_dev_opt_id {GVE_DEV_OPT_ID_DQO_RDA =0x4 ,GVE_DEV_OPT_ID_DQO_QPL =0x7 ,GVE_DEV_OPT_ID_JUMBO_FRAMES =0x8 , + GVE_DEV_OPT_ID_BUFFER_SIZES = 0xa, }; enum gve_dev_opt_req_feat_mask {
@@ -149,10 +158,12 @@ enum gve_dev_opt_req_feat_mask {GVE_DEV_OPT_REQ_FEAT_MASK_DQO_RDA =0x0 ,GVE_DEV_OPT_REQ_FEAT_MASK_JUMBO_FRAMES =0x0 ,GVE_DEV_OPT_REQ_FEAT_MASK_DQO_QPL =0x0 , + GVE_DEV_OPT_REQ_FEAT_MASK_BUFFER_SIZES = 0x0, };enum gve_sup_feature_mask {GVE_SUP_JUMBO_FRAMES_MASK =1 <<2 , +GVE_SUP_BUFFER_SIZES_MASK =1 <<4 , };#define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
@@ -165,6 +176,7 @@ enum gve_driver_capbility { gve_driver_capability_dqo_qpl =2 ,/* reserved for future use */ gve_driver_capability_dqo_rda =3 , gve_driver_capability_alt_miss_compl =4 , + gve_driver_capability_flexible_buffer_size = 5, };#define GVE_CAP1 (a) BIT((int)a)
@@ -176,7 +188,8 @@ enum gve_driver_capbility { (GVE_CAP1 (gve_driver_capability_gqi_qpl) | \GVE_CAP1 (gve_driver_capability_gqi_rda) | \GVE_CAP1 (gve_driver_capability_dqo_rda) | \ - GVE_CAP1(gve_driver_capability_alt_miss_compl)) +GVE_CAP1 (gve_driver_capability_alt_miss_compl) | \ + GVE_CAP1(gve_driver_capability_flexible_buffer_size))#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
@@ -259,7 +272,9 @@ struct gve_adminq_create_rx_queue {__be16 packet_buffer_size;__be16 rx_buff_ring_size;u8 enable_rsc; -u8 padding[5 ]; +u8 padding1; +__be16 header_buffer_size; +u8 padding2[2 ]; };static_assert (sizeof (struct gve_adminq_create_rx_queue ) ==56 );
drivers/net/ethernet/google/gve/gve_dqo.h +2 -0
@@ -39,10 +39,12 @@ int gve_tx_alloc_rings_dqo(struct gve_priv *priv);void gve_tx_free_rings_dqo (struct gve_priv *priv);int gve_rx_alloc_rings_dqo (struct gve_priv *priv);void gve_rx_free_rings_dqo (struct gve_priv *priv); +void gve_rx_reset_rings_dqo (struct gve_priv *priv);int gve_clean_tx_done_dqo (struct gve_priv *priv,struct gve_tx_ring *tx,struct napi_struct *napi);void gve_rx_post_buffers_dqo (struct gve_rx_ring *rx);void gve_rx_write_doorbell_dqo (const struct gve_priv *priv,int queue_idx); +int gve_rx_handle_hdr_resources_dqo (struct gve_priv *priv,bool enable_hdr_split); static inline void gve_tx_put_doorbell_dqo(const struct gve_priv *priv,
drivers/net/ethernet/google/gve/gve_ethtool.c +88 -23
207 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_main.c +134 -63
270 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_rx_dqo.c +239 -25
395 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_utils.c +11 -5
@@ -48,11 +48,9 @@ void gve_rx_add_to_block(struct gve_priv *priv, int queue_idx) rx->ntfy_id = ntfy_idx; } -struct sk_buff *gve_rx_copy (struct net_device *dev,struct napi_struct *napi, -struct gve_rx_slot_page_info *page_info,u16 len) +struct sk_buff *gve_rx_copy_data (struct net_device *dev,struct napi_struct *napi, +u8 *data,u16 len) { -void *va = page_info->page_address + page_info->page_offset + - page_info->pad;struct sk_buff *skb; skb =napi_alloc_skb (napi, len);
@@ -60,12 +58,20 @@ struct sk_buff *gve_rx_copy(struct net_device *dev, struct napi_struct *napi,return NULL ;__skb_put (skb, len); -skb_copy_to_linear_data_offset (skb,0 , va, len); +skb_copy_to_linear_data_offset (skb,0 , data, len); skb->protocol =eth_type_trans (skb, dev);return skb; } +struct sk_buff *gve_rx_copy (struct net_device *dev,struct napi_struct *napi, +struct gve_rx_slot_page_info *page_info,u16 len) +{ +void *va = page_info->page_address + page_info->page_offset + + page_info->pad; +return gve_rx_copy_data (dev, napi, va, len); +} +void gve_dec_pagecnt_bias (struct gve_rx_slot_page_info *page_info) { page_info->pagecnt_bias--;
drivers/net/ethernet/google/gve/gve_utils.h +3 -0
@@ -17,6 +17,9 @@ void gve_tx_add_to_block(struct gve_priv *priv, int queue_idx);void gve_rx_remove_from_block (struct gve_priv *priv,int queue_idx);void gve_rx_add_to_block (struct gve_priv *priv,int queue_idx); +struct sk_buff *gve_rx_copy_data (struct net_device *dev,struct napi_struct *napi, +u8 *data,u16 len); +struct sk_buff *gve_rx_copy (struct net_device *dev,struct napi_struct *napi,struct gve_rx_slot_page_info *page_info,u16 len);
Signature · 1 line
2.41.0.640.ga95def55d0-goog
Jakub Kicinski
maintainerQuoted 8 lines · On Fri, 11 Aug 2023 15:39:38 -0700 Ziwei Xiao wrote:
- Add header-split and strict-header-split ethtool priv flags. These flags control header-split behavior. It can be turned on/off and it can be set to 'strict' which will cause the driver to drop all the packets that don't have a proper header split.
- Add max-rx-buffer-size priv flag to allow user to switch the packet buffer size between max and default(e.g. 4K <-> 2K).
- Add reconfigure rx rings to support the header split and max-rx-buffer-size enable/disable switch.
Someone on your team needs to participate upstream or you need to get your patches reviewed from someone upstream-savvy before posting.
Anyone participating in netdev reviews would have told you that private flags are unlikely to fly upstream.
One part of an organization participating upstream while another has no upstream understanding and throws code over the wall is a common anti-pattern, and I intend to stop it.
Signature · 1 line
pw-bot: cr
Quoted 10 lines · Jakub Kicinski
Quoted 8 lines · On Fri, 11 Aug 2023 15:39:38 -0700 Ziwei Xiao wrote:
- Add header-split and strict-header-split ethtool priv flags. These flags control header-split behavior. It can be turned on/off and it can be set to 'strict' which will cause the driver to drop all the packets that don't have a proper header split.
- Add max-rx-buffer-size priv flag to allow user to switch the packet buffer size between max and default(e.g. 4K <-> 2K).
- Add reconfigure rx rings to support the header split and max-rx-buffer-size enable/disable switch.
The bulleted list is an indication that maybe this patch is combining too much in a single commit.
Quoted 10 lines
Someone on your team needs to participate upstream or you need to get your patches reviewed from someone upstream-savvy before posting.
Anyone participating in netdev reviews would have told you that private flags are unlikely to fly upstream.
One part of an organization participating upstream while another has no upstream understanding and throws code over the wall is a common anti-pattern, and I intend to stop it.
The one point I want to raise about private flags is that ethtool currently lacks an alternative for header-split.
That probably requires a non-driver patch to add as a new ethtool feature.
I had not given much thought on the two modes of header-split seen here until now: strict or not. We'll have to figure out whether both are really needed, especially if turning into ethtool ABI.