gve: Alloc before freeing when changing config
Subsystems (3)
cover gve: Alloc before freeing when changing config
Functions allocating resources did so directly into priv thus far. The assumption doing that was that priv was not already holding references to live resources.
When ring configuration is changed in any way from userspace, thus far we relied on calling the ndo_stop and ndo_open callbacks in succession. This meant that we teardown existing resources and rob the OS of networking before we have successfully allocated resources for the new config.
Correcting this requires us to perform allocations without editing priv. That is what the "gve: Switch to config-aware..." patch does: it modifies all the allocation paths so that they take a new configuration as input and return references to newly allocated resources without modifying priv or interfering with live resources in any way.
Having corrected the allocation paths so, the ndo open and close callbacks are refactored to make available distinct functions for allocating queue resources and starting or stopping them. This is then put to use in the set_channels and set_features hooks in the last two patches.
These changes have been tested by verifying the integrity of a stream of integers while the driver is continuously reconfigured with ethtool.
Shailend Chand (6):
gve: Define config structs for queue allocation
gve: Refactor napi add and remove functions
gve: Switch to config-aware queue allocation
gve: Refactor gve_open and gve_close
gve: Alloc before freeing when adjusting queues
gve: Alloc before freeing when changing features
drivers/net/ethernet/google/gve/gve.h | 144 +++- drivers/net/ethernet/google/gve/gve_dqo.h | 18 +- drivers/net/ethernet/google/gve/gve_main.c | 854 ++++++++++++------- drivers/net/ethernet/google/gve/gve_rx.c | 116 ++- drivers/net/ethernet/google/gve/gve_rx_dqo.c | 91 +- drivers/net/ethernet/google/gve/gve_tx.c | 128 ++- drivers/net/ethernet/google/gve/gve_tx_dqo.c | 108 ++- drivers/net/ethernet/google/gve/gve_utils.c | 31 + drivers/net/ethernet/google/gve/gve_utils.h | 5 + 9 files changed, 999 insertions(+), 496 deletions(-)
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
PATCH 1/6 gve: Define config structs for queue allocation
Queue allocation functions currently can only allocate into priv and free memory in priv. These new structs would be passed into the queue functions in a subsequent change to make them capable of returning newly allocated resources and not just writing them into priv. They also make it possible to allocate resources for queues with a different config than that of the currently active queues.
--- drivers/net/ethernet/google/gve/gve.h | 49 +++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
drivers/net/ethernet/google/gve/gve.h +49 -0
@@ -622,6 +622,55 @@ struct gve_ptype_lut {struct gve_ptype ptypes[GVE_NUM_PTYPES ]; }; +/* Parameters for allocating queue page lists */ +struct gve_qpls_alloc_cfg { +struct gve_qpl_config *qpl_cfg; +struct gve_queue_config *tx_cfg; +struct gve_queue_config *rx_cfg; + +u16 num_xdp_queues; +bool raw_addressing; +bool is_gqi; + +/* Allocated resources are returned here */ +struct gve_queue_page_list *qpls; +}; + +/* Parameters for allocating resources for tx queues */ +struct gve_tx_alloc_rings_cfg { +struct gve_queue_config *qcfg; + +/* qpls and qpl_cfg must already be allocated */ +struct gve_queue_page_list *qpls; +struct gve_qpl_config *qpl_cfg; + +u16 ring_size; +u16 start_idx; +u16 num_rings; +bool raw_addressing; + +/* Allocated resources are returned here */ +struct gve_tx_ring *tx; +}; + +/* Parameters for allocating resources for rx queues */ +struct gve_rx_alloc_rings_cfg { +/* tx config is also needed to determine QPL ids */ +struct gve_queue_config *qcfg; +struct gve_queue_config *qcfg_tx; + +/* qpls and qpl_cfg must already be allocated */ +struct gve_queue_page_list *qpls; +struct gve_qpl_config *qpl_cfg; + +u16 ring_size; +bool raw_addressing; +bool enable_header_split; + +/* Allocated resources are returned here */ +struct gve_rx_ring *rx; +}; +/* GVE_QUEUE_FORMAT_UNSPECIFIED must be zero since 0 is the default value * when the entire configure_device_resources command is zeroed out and the * queue_format is not specified.
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
Re: [PATCH net-next 1/6] gve: Define config structs for queue allocation
Quoted 10 lines · Shailend Chand
Queue allocation functions currently can only allocate into priv and free memory in priv. These new structs would be passed into the queue functions in a subsequent change to make them capable of returning newly allocated resources and not just writing them into priv. They also make it possible to allocate resources for queues with a different config than that of the currently active queues.
Signed-off-by Shailend Chand <[email protected]>Reviewed-by Willem de Bruijn <[email protected]>Reviewed-by Jeroen de Borst <[email protected]>
PATCH 2/6 gve: Refactor napi add and remove functions
In reply to Shailend ChandThis change makes the napi poll functions non-static and moves the gve_(add|remove)_napi functions to gve_utils.c, to make possible future "start queue" hooks in the datapath files.
--- drivers/net/ethernet/google/gve/gve.h | 3 +++ drivers/net/ethernet/google/gve/gve_dqo.h | 2 ++ drivers/net/ethernet/google/gve/gve_main.c | 20 +++----------------- drivers/net/ethernet/google/gve/gve_utils.c | 15 +++++++++++++++ drivers/net/ethernet/google/gve/gve_utils.h | 3 +++ 5 files changed, 26 insertions(+), 17 deletions(-)
drivers/net/ethernet/google/gve/gve.h +3 -0
@@ -1085,6 +1085,9 @@ static inline u32 gve_xdp_tx_start_queue_id(struct gve_priv *priv)return gve_xdp_tx_queue_id (priv,0 ); } +/* gqi napi handler defined in gve_main.c */ +int gve_napi_poll (struct napi_struct *napi,int budget); +/* 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_dqo.h +2 -0
@@ -93,4 +93,6 @@ gve_set_itr_coalesce_usecs_dqo(struct gve_priv *priv,gve_write_irq_doorbell_dqo (priv, block, gve_setup_itr_interval_dqo(usecs)); } + +int gve_napi_poll_dqo (struct napi_struct *napi,int budget);#endif /* _GVE_DQO_H_ */
drivers/net/ethernet/google/gve/gve_main.c +3 -17
@@ -22,6 +22,7 @@#include "gve_dqo.h" #include "gve_adminq.h" #include "gve_register.h" +#include "gve_utils.h" #define GVE_DEFAULT_RX_COPYBREAK (256)
@@ -252,7 +253,7 @@ static irqreturn_t gve_intr_dqo(int irq, void *arg)return IRQ_HANDLED ; } -static int gve_napi_poll (struct napi_struct *napi,int budget) +int gve_napi_poll (struct napi_struct *napi,int budget) {struct gve_notify_block *block;__be32 __iomem *irq_doorbell;
@@ -302,7 +303,7 @@ static int gve_napi_poll(struct napi_struct *napi, int budget)return work_done; } -static int gve_napi_poll_dqo (struct napi_struct *napi,int budget) +int gve_napi_poll_dqo (struct napi_struct *napi,int budget) {struct gve_notify_block *block = container_of(napi, struct gve_notify_block, napi);
@@ -581,21 +582,6 @@ static void gve_teardown_device_resources(struct gve_priv *priv)gve_clear_device_resources_ok (priv); } -static void gve_add_napi (struct gve_priv *priv,int ntfy_idx, -int (*gve_poll)(struct napi_struct *,int )) -{ -struct gve_notify_block *block = &priv->ntfy_blocks[ntfy_idx]; - -netif_napi_add (priv->dev, &block->napi, gve_poll); -} - -static void gve_remove_napi (struct gve_priv *priv,int ntfy_idx) -{ -struct gve_notify_block *block = &priv->ntfy_blocks[ntfy_idx]; - -netif_napi_del (&block->napi); -} -static int gve_register_xdp_qpls (struct gve_priv *priv) {int start_id;
drivers/net/ethernet/google/gve/gve_utils.c +15 -0
@@ -81,3 +81,18 @@ void gve_dec_pagecnt_bias(struct gve_rx_slot_page_info *page_info)page_ref_add (page_info->page,INT_MAX - pagecount); } } + +void gve_add_napi (struct gve_priv *priv,int ntfy_idx, +int (*gve_poll)(struct napi_struct *,int )) +{ +struct gve_notify_block *block = &priv->ntfy_blocks[ntfy_idx]; + +netif_napi_add (priv->dev, &block->napi, gve_poll); +} + +void gve_remove_napi (struct gve_priv *priv,int ntfy_idx) +{ +struct gve_notify_block *block = &priv->ntfy_blocks[ntfy_idx]; + +netif_napi_del (&block->napi); +}
drivers/net/ethernet/google/gve/gve_utils.h +3 -0
@@ -23,5 +23,8 @@ struct sk_buff *gve_rx_copy(struct net_device *dev, struct napi_struct *napi,/* Decrement pagecnt_bias. Set it back to INT_MAX if it reached zero. */ void gve_dec_pagecnt_bias (struct gve_rx_slot_page_info *page_info); +void gve_add_napi (struct gve_priv *priv,int ntfy_idx, +int (*gve_poll)(struct napi_struct *,int )); +void gve_remove_napi (struct gve_priv *priv,int ntfy_idx);#endif /* _GVE_UTILS_H */
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
Re: [PATCH net-next 2/6] gve: Refactor napi add and remove functions
Quoted 7 lines · Shailend Chand
This change makes the napi poll functions non-static and moves the gve_(add|remove)_napi functions to
gve_utils.c, to make possible future "start queue" hooks in the datapath files.Signed-off-by Shailend Chand <[email protected]>Reviewed-by Willem de Bruijn <[email protected]>Reviewed-by Jeroen de Borst <[email protected]>
PATCH 3/6 gve: Switch to config-aware queue allocation
In reply to Shailend ChandThe new config-aware functions will help achieve the goal of being able to allocate resources for new queues while there already are active queues serving traffic.
These new functions work off of arbitrary queue allocation configs rather than just the currently active config in priv, and they return the newly allocated resources instead of writing them into priv.
--- drivers/net/ethernet/google/gve/gve.h | 92 +-- drivers/net/ethernet/google/gve/gve_dqo.h | 16 +- drivers/net/ethernet/google/gve/gve_main.c | 601 +++++++++++-------- drivers/net/ethernet/google/gve/gve_rx.c | 116 ++-- drivers/net/ethernet/google/gve/gve_rx_dqo.c | 91 ++- drivers/net/ethernet/google/gve/gve_tx.c | 128 ++-- drivers/net/ethernet/google/gve/gve_tx_dqo.c | 108 +++- drivers/net/ethernet/google/gve/gve_utils.c | 16 + drivers/net/ethernet/google/gve/gve_utils.h | 2 + 9 files changed, 745 insertions(+), 425 deletions(-)
drivers/net/ethernet/google/gve/gve.h +50 -42
@@ -966,14 +966,14 @@ static inline bool gve_is_qpl(struct gve_priv *priv) priv->queue_format ==GVE_DQO_QPL_FORMAT ; } -/* Returns the number of tx queue page lists -*/ -static inline u32 gve_num_tx_qpls (struct gve_priv *priv) +/* Returns the number of tx queue page lists */ +static inline u32 gve_num_tx_qpls (const struct gve_queue_config *tx_cfg, +int num_xdp_queues, +bool is_qpl) { -if (!gve_is_qpl (priv)) +if (!is_qpl)return 0 ; - -return priv->tx_cfg.num_queues + priv->num_xdp_queues; +return tx_cfg->num_queues + num_xdp_queues; }/* Returns the number of XDP tx queue page lists
@@ -986,14 +986,13 @@ static inline u32 gve_num_xdp_qpls(struct gve_priv *priv)return priv->num_xdp_queues; } -/* Returns the number of rx queue page lists -*/ -static inline u32 gve_num_rx_qpls (struct gve_priv *priv) +/* Returns the number of rx queue page lists */ +static inline u32 gve_num_rx_qpls (const struct gve_queue_config *rx_cfg, +bool is_qpl) { -if (!gve_is_qpl (priv)) +if (!is_qpl)return 0 ; - -return priv->rx_cfg.num_queues; +return rx_cfg->num_queues; }static inline u32 gve_tx_qpl_id (struct gve_priv *priv,int tx_qid)
@@ -1006,59 +1005,59 @@ static inline u32 gve_rx_qpl_id(struct gve_priv *priv, int rx_qid)return priv->tx_cfg.max_queues + rx_qid; } +/* Returns the index into priv->qpls where a certain rx queue's QPL resides */ +static inline u32 gve_get_rx_qpl_id (const struct gve_queue_config *tx_cfg,int rx_qid) +{ +return tx_cfg->max_queues + rx_qid; +} +static inline u32 gve_tx_start_qpl_id (struct gve_priv *priv) {return gve_tx_qpl_id (priv,0 ); } -static inline u32 gve_rx_start_qpl_id (struct gve_priv *priv) +/* Returns the index into priv->qpls where the first rx queue's QPL resides */ +static inline u32 gve_rx_start_qpl_id (const struct gve_queue_config *tx_cfg) { -return gve_rx_qpl_id (priv,0 ); +return gve_get_rx_qpl_id (tx_cfg,0 ); } -/* Returns a pointer to the next available tx qpl in the list of qpls -*/ +/* Returns a pointer to the next available tx qpl in the list of qpls */ static inline -struct gve_queue_page_list *gve_assign_tx_qpl (struct gve_priv *priv,int tx_qid) +struct gve_queue_page_list *gve_assign_tx_qpl (struct gve_tx_alloc_rings_cfg *cfg, +int tx_qid) { -int id =gve_tx_qpl_id (priv, tx_qid); -/* QPL already in use */ -if (test_bit (id, priv->qpl_cfg.qpl_id_map)) +if (test_bit (tx_qid, cfg->qpl_cfg->qpl_id_map))return NULL ; - -set_bit (id, priv->qpl_cfg.qpl_id_map); -return &priv->qpls[id]; +set_bit (tx_qid, cfg->qpl_cfg->qpl_id_map); +return &cfg->qpls[tx_qid]; } -/* Returns a pointer to the next available rx qpl in the list of qpls -*/ +/* Returns a pointer to the next available rx qpl in the list of qpls */ static inline -struct gve_queue_page_list *gve_assign_rx_qpl (struct gve_priv *priv,int rx_qid) +struct gve_queue_page_list *gve_assign_rx_qpl (struct gve_rx_alloc_rings_cfg *cfg, +int rx_qid) { -int id =gve_rx_qpl_id (priv, rx_qid); - +int id =gve_get_rx_qpl_id (cfg->qcfg_tx, rx_qid);/* QPL already in use */ -if (test_bit (id, priv->qpl_cfg.qpl_id_map)) +if (test_bit (id, cfg->qpl_cfg->qpl_id_map))return NULL ; - -set_bit (id, priv->qpl_cfg.qpl_id_map); -return &priv->qpls[id]; +set_bit (id, cfg->qpl_cfg->qpl_id_map); +return &cfg->qpls[id]; } -/* Unassigns the qpl with the given id -*/ -static inline void gve_unassign_qpl (struct gve_priv *priv,int id) +/* Unassigns the qpl with the given id */ +static inline void gve_unassign_qpl (struct gve_qpl_config *qpl_cfg,int id) { -clear_bit (id, priv->qpl_cfg.qpl_id_map); +clear_bit (id, qpl_cfg->qpl_id_map); } -/* Returns the correct dma direction for tx and rx qpls -*/ +/* Returns the correct dma direction for tx and rx qpls */ static inline enum dma_data_direction gve_qpl_dma_dir (struct gve_priv *priv,int id) { -if (id <gve_rx_start_qpl_id (priv)) +if (id <gve_rx_start_qpl_id (&priv->tx_cfg))return DMA_TO_DEVICE ;else return DMA_FROM_DEVICE ;
@@ -1103,8 +1102,12 @@ int gve_xdp_xmit_one(struct gve_priv *priv, struct gve_tx_ring *tx,void gve_xdp_tx_flush (struct gve_priv *priv,u32 xdp_qid);bool gve_tx_poll (struct gve_notify_block *block,int budget);bool gve_xdp_poll (struct gve_notify_block *block,int budget); -int gve_tx_alloc_rings (struct gve_priv *priv,int start_id,int num_rings); -void gve_tx_free_rings_gqi (struct gve_priv *priv,int start_id,int num_rings); +int gve_tx_alloc_rings_gqi (struct gve_priv *priv, +struct gve_tx_alloc_rings_cfg *cfg); +void gve_tx_free_rings_gqi (struct gve_priv *priv, +struct gve_tx_alloc_rings_cfg *cfg); +void gve_tx_start_ring_gqi (struct gve_priv *priv,int idx); +void gve_tx_stop_ring_gqi (struct gve_priv *priv,int idx);u32 gve_tx_load_event_counter (struct gve_priv *priv,struct gve_tx_ring *tx);bool gve_tx_clean_pending (struct gve_priv *priv,struct gve_tx_ring *tx);
@@ -1113,7 +1116,12 @@ void gve_rx_write_doorbell(struct gve_priv *priv, struct gve_rx_ring *rx);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_rx_alloc_rings_gqi (struct gve_priv *priv, +struct gve_rx_alloc_rings_cfg *cfg); +void gve_rx_free_rings_gqi (struct gve_priv *priv, +struct gve_rx_alloc_rings_cfg *cfg); +void gve_rx_start_ring_gqi (struct gve_priv *priv,int idx); +void gve_rx_stop_ring_gqi (struct gve_priv *priv,int idx);/* 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_dqo.h +12 -4
@@ -38,10 +38,18 @@ netdev_features_t gve_features_check_dqo(struct sk_buff *skb, netdev_features_t features);bool gve_tx_poll_dqo (struct gve_notify_block *block,bool do_clean);int gve_rx_poll_dqo (struct gve_notify_block *block,int budget); -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); +int gve_tx_alloc_rings_dqo (struct gve_priv *priv, +struct gve_tx_alloc_rings_cfg *cfg); +void gve_tx_free_rings_dqo (struct gve_priv *priv, +struct gve_tx_alloc_rings_cfg *cfg); +void gve_tx_start_ring_dqo (struct gve_priv *priv,int idx); +void gve_tx_stop_ring_dqo (struct gve_priv *priv,int idx); +int gve_rx_alloc_rings_dqo (struct gve_priv *priv, +struct gve_rx_alloc_rings_cfg *cfg); +void gve_rx_free_rings_dqo (struct gve_priv *priv, +struct gve_rx_alloc_rings_cfg *cfg); +void gve_rx_start_ring_dqo (struct gve_priv *priv,int idx); +void gve_rx_stop_ring_dqo (struct gve_priv *priv,int idx);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);
drivers/net/ethernet/google/gve/gve_main.c +352 -249
875 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_rx.c +78 -38
230 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_rx_dqo.c +65 -26
170 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_tx.c +89 -39
207 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_tx_dqo.c +81 -27
179 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_utils.c +16 -0
@@ -8,6 +8,14 @@#include "gve_adminq.h" #include "gve_utils.h" +bool gve_tx_was_added_to_block (struct gve_priv *priv,int queue_idx) +{ +struct gve_notify_block *block = + &priv->ntfy_blocks[gve_tx_idx_to_ntfy (priv, queue_idx)]; + +return block->tx !=NULL ; +} +void gve_tx_remove_from_block (struct gve_priv *priv,int queue_idx) { struct gve_notify_block *block =
@@ -30,6 +38,14 @@ void gve_tx_add_to_block(struct gve_priv *priv, int queue_idx) queue_idx); } +bool gve_rx_was_added_to_block (struct gve_priv *priv,int queue_idx) +{ +struct gve_notify_block *block = + &priv->ntfy_blocks[gve_rx_idx_to_ntfy (priv, queue_idx)]; + +return block->rx !=NULL ; +} +void gve_rx_remove_from_block (struct gve_priv *priv,int queue_idx) { struct gve_notify_block *block =
drivers/net/ethernet/google/gve/gve_utils.h +2 -0
@@ -11,9 +11,11 @@#include "gve.h" +bool gve_tx_was_added_to_block (struct gve_priv *priv,int queue_idx);void gve_tx_remove_from_block (struct gve_priv *priv,int queue_idx);void gve_tx_add_to_block (struct gve_priv *priv,int queue_idx); +bool gve_rx_was_added_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);
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
Re: [PATCH net-next 3/6] gve: Switch to config-aware queue allocation
Quoted 11 lines · Shailend Chand
The new config-aware functions will help achieve the goal of being able to allocate resources for new queues while there already are active queues serving traffic.
These new functions work off of arbitrary queue allocation configs rather than just the currently active config in priv, and they return the newly allocated resources instead of writing them into priv.
Signed-off-by Shailend Chand <[email protected]>Reviewed-by Willem de Bruijn <[email protected]>Reviewed-by Jeroen de Borst <[email protected]>
PATCH 4/6 gve: Refactor gve_open and gve_close
In reply to Shailend Chandgve_open is rewritten to be composed of two funcs: gve_queues_mem_alloc and gve_queues_start. The former only allocates queue resources without doing anything to install the queues, which is taken up by the latter. Similarly gve_close is split into gve_queues_stop and gve_queues_mem_free.
Separating the acts of queue resource allocation and making the queue become live help with subsequent changes that aim to not take down the datapath when applying new configurations.
--- drivers/net/ethernet/google/gve/gve_main.c | 159 +++++++++++++++------ 1 file changed, 119 insertions(+), 40 deletions(-)
drivers/net/ethernet/google/gve/gve_main.c +119 -40
@@ -1350,45 +1350,99 @@ static void gve_rx_stop_rings(struct gve_priv *priv, int num_rings) } } -static int gve_open (struct net_device *dev) +static void gve_queues_mem_free (struct gve_priv *priv, +struct gve_qpls_alloc_cfg *qpls_alloc_cfg, +struct gve_tx_alloc_rings_cfg *tx_alloc_cfg, +struct gve_rx_alloc_rings_cfg *rx_alloc_cfg) +{ +gve_free_rings (priv, tx_alloc_cfg, rx_alloc_cfg); +gve_free_qpls (priv, qpls_alloc_cfg); +} + +static int gve_queues_mem_alloc (struct gve_priv *priv, +struct gve_qpls_alloc_cfg *qpls_alloc_cfg, +struct gve_tx_alloc_rings_cfg *tx_alloc_cfg, +struct gve_rx_alloc_rings_cfg *rx_alloc_cfg) +{ +int err; + + err =gve_alloc_qpls (priv, qpls_alloc_cfg); +if (err) { +netif_err (priv, drv, priv->dev,"Failed to alloc QPLs\n" ); +return err; + } + tx_alloc_cfg->qpls = qpls_alloc_cfg->qpls; + rx_alloc_cfg->qpls = qpls_alloc_cfg->qpls; + err =gve_alloc_rings (priv, tx_alloc_cfg, rx_alloc_cfg); +if (err) { +netif_err (priv, drv, priv->dev,"Failed to alloc rings\n" ); + goto free_qpls; + } + +return 0 ; + +free_qpls: +gve_free_qpls (priv, qpls_alloc_cfg); +return err; +} + +static void gve_queues_mem_remove (struct gve_priv *priv) {struct gve_tx_alloc_rings_cfg tx_alloc_cfg = {0 };struct gve_rx_alloc_rings_cfg rx_alloc_cfg = {0 };struct gve_qpls_alloc_cfg qpls_alloc_cfg = {0 }; -struct gve_priv *priv =netdev_priv (dev); + +gve_get_curr_alloc_cfgs (priv, &qpls_alloc_cfg, + &tx_alloc_cfg, &rx_alloc_cfg); +gve_queues_mem_free (priv, &qpls_alloc_cfg, + &tx_alloc_cfg, &rx_alloc_cfg); + priv->qpls =NULL ; + priv->tx =NULL ; + priv->rx =NULL ; +} + +/* The passed-in queue memory is stored into priv and the queues are made live. +* No memory is allocated. Passed-in memory is freed on errors. +*/ +static int gve_queues_start (struct gve_priv *priv, +struct gve_qpls_alloc_cfg *qpls_alloc_cfg, +struct gve_tx_alloc_rings_cfg *tx_alloc_cfg, +struct gve_rx_alloc_rings_cfg *rx_alloc_cfg) +{ +struct net_device *dev = priv->dev;int err; +/* Record new resources into priv */ + priv->qpls = qpls_alloc_cfg->qpls; + priv->tx = tx_alloc_cfg->tx; + priv->rx = rx_alloc_cfg->rx; + +/* Record new configs into priv */ + priv->qpl_cfg = *qpls_alloc_cfg->qpl_cfg; + priv->tx_cfg = *tx_alloc_cfg->qcfg; + priv->rx_cfg = *rx_alloc_cfg->qcfg; + priv->tx_desc_cnt = tx_alloc_cfg->ring_size; + priv->rx_desc_cnt = rx_alloc_cfg->ring_size; +if (priv->xdp_prog) priv->num_xdp_queues = priv->rx_cfg.num_queues;else priv->num_xdp_queues =0 ; -gve_get_curr_alloc_cfgs (priv, &qpls_alloc_cfg, - &tx_alloc_cfg, &rx_alloc_cfg); - err =gve_alloc_qpls (priv, &qpls_alloc_cfg); -if (err) -return err; - priv->qpls = qpls_alloc_cfg.qpls; - tx_alloc_cfg.qpls = priv->qpls; - rx_alloc_cfg.qpls = priv->qpls; - err =gve_alloc_rings (priv, &tx_alloc_cfg, &rx_alloc_cfg); -if (err) - goto free_qpls; - -gve_tx_start_rings (priv,0 , tx_alloc_cfg.num_rings); -gve_rx_start_rings (priv, rx_alloc_cfg.qcfg->num_queues); +gve_tx_start_rings (priv,0 , tx_alloc_cfg->num_rings); +gve_rx_start_rings (priv, rx_alloc_cfg->qcfg->num_queues);gve_init_sync_stats (priv); err =netif_set_real_num_tx_queues (dev, priv->tx_cfg.num_queues);if (err) - goto free_rings; + goto stop_and_free_rings; err =netif_set_real_num_rx_queues (dev, priv->rx_cfg.num_queues);if (err) - goto free_rings; + goto stop_and_free_rings; err =gve_reg_xdp_info (priv, dev);if (err) - goto free_rings; + goto stop_and_free_rings; err =gve_register_qpls (priv);if (err)
@@ -1416,29 +1470,22 @@ static int gve_open(struct net_device *dev) priv->interface_up_cnt++;return 0 ; -free_rings: -gve_tx_stop_rings (priv,0 , tx_alloc_cfg.num_rings); -gve_rx_stop_rings (priv, rx_alloc_cfg.qcfg->num_queues); -gve_free_rings (priv, &tx_alloc_cfg, &rx_alloc_cfg); -free_qpls: -gve_free_qpls (priv, &qpls_alloc_cfg); -return err; - reset: -/* This must have been called from a reset due to the rtnl lock -* so just return at this point. -*/ if (gve_get_reset_in_progress (priv)) -return err; -/* Otherwise reset before returning */ + goto stop_and_free_rings;gve_reset_and_teardown (priv, true);/* if this fails there is nothing we can do so just ignore the return */ gve_reset_recovery (priv, false);/* return the original error */ return err; +stop_and_free_rings: +gve_tx_stop_rings (priv,0 ,gve_num_tx_queues (priv)); +gve_rx_stop_rings (priv, priv->rx_cfg.num_queues); +gve_queues_mem_remove (priv); +return err; } -static int gve_close (struct net_device *dev) +static int gve_open (struct net_device *dev) {struct gve_tx_alloc_rings_cfg tx_alloc_cfg = {0 };struct gve_rx_alloc_rings_cfg rx_alloc_cfg = {0 };
@@ -1446,7 +1493,30 @@ static int gve_close(struct net_device *dev)struct gve_priv *priv =netdev_priv (dev);int err; -netif_carrier_off (dev); +gve_get_curr_alloc_cfgs (priv, &qpls_alloc_cfg, + &tx_alloc_cfg, &rx_alloc_cfg); + + err =gve_queues_mem_alloc (priv, &qpls_alloc_cfg, + &tx_alloc_cfg, &rx_alloc_cfg); +if (err) +return err; + +/* No need to free on error: ownership of resources is lost after +* calling gve_queues_start. +*/ + err =gve_queues_start (priv, &qpls_alloc_cfg, + &tx_alloc_cfg, &rx_alloc_cfg); +if (err) +return err; + +return 0 ; +} + +static int gve_queues_stop (struct gve_priv *priv) +{ +int err; + +netif_carrier_off (priv->dev);if (gve_get_device_rings_ok (priv)) {gve_turndown (priv);gve_drain_page_cache (priv);
@@ -1462,12 +1532,8 @@ static int gve_close(struct net_device *dev)gve_unreg_xdp_info (priv); -gve_get_curr_alloc_cfgs (priv, &qpls_alloc_cfg, - &tx_alloc_cfg, &rx_alloc_cfg); -gve_tx_stop_rings (priv,0 , tx_alloc_cfg.num_rings); -gve_rx_stop_rings (priv, rx_alloc_cfg.qcfg->num_queues); -gve_free_rings (priv, &tx_alloc_cfg, &rx_alloc_cfg); -gve_free_qpls (priv, &qpls_alloc_cfg); +gve_tx_stop_rings (priv,0 ,gve_num_tx_queues (priv)); +gve_rx_stop_rings (priv, priv->rx_cfg.num_queues); priv->interface_down_cnt++;return 0 ;
@@ -1483,6 +1549,19 @@ static int gve_close(struct net_device *dev)return gve_reset_recovery (priv, false); } +static int gve_close (struct net_device *dev) +{ +struct gve_priv *priv =netdev_priv (dev); +int err; + + err =gve_queues_stop (priv); +if (err) +return err; + +gve_queues_mem_remove (priv); +return 0 ; +} +static int gve_remove_xdp_queues (struct gve_priv *priv) {int qpl_start_id;
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
PATCH 5/6 gve: Alloc before freeing when adjusting queues
In reply to Shailend ChandPreviously, existing queues were being freed before the resources for the new queues were being allocated. This would take down the interface if someone were to attempt to change queue counts under a resource crunch.
--- drivers/net/ethernet/google/gve/gve_main.c | 89 ++++++++++++++++------ 1 file changed, 67 insertions(+), 22 deletions(-)
drivers/net/ethernet/google/gve/gve_main.c +67 -22
@@ -1869,42 +1869,87 @@ static int gve_xdp(struct net_device *dev, struct netdev_bpf *xdp) } } +static int gve_adjust_config (struct gve_priv *priv, +struct gve_qpls_alloc_cfg *qpls_alloc_cfg, +struct gve_tx_alloc_rings_cfg *tx_alloc_cfg, +struct gve_rx_alloc_rings_cfg *rx_alloc_cfg) +{ +int err; + +/* Allocate resources for the new confiugration */ + err =gve_queues_mem_alloc (priv, qpls_alloc_cfg, + tx_alloc_cfg, rx_alloc_cfg); +if (err) { +netif_err (priv, drv, priv->dev, +"Adjust config failed to alloc new queues" ); +return err; + } + +/* Teardown the device and free existing resources */ + err =gve_close (priv->dev); +if (err) { +netif_err (priv, drv, priv->dev, +"Adjust config failed to close old queues" ); +gve_queues_mem_free (priv, qpls_alloc_cfg, + tx_alloc_cfg, rx_alloc_cfg); +return err; + } + +/* Bring the device back up again with the new resources. */ + err =gve_queues_start (priv, qpls_alloc_cfg, + tx_alloc_cfg, rx_alloc_cfg); +if (err) { +netif_err (priv, drv, priv->dev, +"Adjust config failed to start new queues, !!! DISABLING ALL QUEUES !!!\n" ); +/* No need to free on error: ownership of resources is lost after +* calling gve_queues_start. +*/ +gve_turndown (priv); +return err; + } + +return 0 ; +} +int gve_adjust_queues (struct gve_priv *priv,struct gve_queue_config new_rx_config,struct gve_queue_config new_tx_config) { +struct gve_tx_alloc_rings_cfg tx_alloc_cfg = {0 }; +struct gve_rx_alloc_rings_cfg rx_alloc_cfg = {0 }; +struct gve_qpls_alloc_cfg qpls_alloc_cfg = {0 }; +struct gve_qpl_config new_qpl_cfg;int err; -if (netif_carrier_ok (priv->dev)) { -/* To make this process as simple as possible we teardown the -* device, set the new configuration, and then bring the device -* up again. -*/ - err =gve_close (priv->dev); -/* we have already tried to reset in close, -* just fail at this point -*/ -if (err) -return err; - priv->tx_cfg = new_tx_config; - priv->rx_cfg = new_rx_config; +gve_get_curr_alloc_cfgs (priv, &qpls_alloc_cfg, + &tx_alloc_cfg, &rx_alloc_cfg); - err =gve_open (priv->dev); -if (err) - goto err; +/* qpl_cfg is not read-only, it contains a map that gets updated as +* rings are allocated, which is why we cannot use the yet unreleased +* one in priv. +*/ + qpls_alloc_cfg.qpl_cfg = &new_qpl_cfg; + tx_alloc_cfg.qpl_cfg = &new_qpl_cfg; + rx_alloc_cfg.qpl_cfg = &new_qpl_cfg; + +/* Relay the new config from ethtool */ + qpls_alloc_cfg.tx_cfg = &new_tx_config; + tx_alloc_cfg.qcfg = &new_tx_config; + rx_alloc_cfg.qcfg_tx = &new_tx_config; + qpls_alloc_cfg.rx_cfg = &new_rx_config; + rx_alloc_cfg.qcfg = &new_rx_config; + tx_alloc_cfg.num_rings = new_tx_config.num_queues; -return 0 ; +if (netif_carrier_ok (priv->dev)) { + err =gve_adjust_config (priv, &qpls_alloc_cfg, + &tx_alloc_cfg, &rx_alloc_cfg); +return err; }/* Set the config for the next up. */ priv->tx_cfg = new_tx_config; priv->rx_cfg = new_rx_config;return 0 ; -err: -netif_err (priv, drv, priv->dev, -"Adjust queues failed! !!! DISABLING ALL QUEUES !!!\n" ); -gve_turndown (priv); -return err; }static void gve_turndown (struct gve_priv *priv)
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
PATCH 6/6 gve: Alloc before freeing when changing features
In reply to Shailend ChandPreviously, existing queues were being freed before the resources for the new queues were being allocated. This would take down the interface if someone were to attempt to change feature flags under a resource crunch.
--- drivers/net/ethernet/google/gve/gve_main.c | 41 +++++++++++----------- 1 file changed, 21 insertions(+), 20 deletions(-)
drivers/net/ethernet/google/gve/gve_main.c +21 -20
@@ -2069,36 +2069,37 @@ static int gve_set_features(struct net_device *netdev, netdev_features_t features) {const netdev_features_t orig_features = netdev->features; +struct gve_tx_alloc_rings_cfg tx_alloc_cfg = {0 }; +struct gve_rx_alloc_rings_cfg rx_alloc_cfg = {0 }; +struct gve_qpls_alloc_cfg qpls_alloc_cfg = {0 };struct gve_priv *priv =netdev_priv (netdev); +struct gve_qpl_config new_qpl_cfg;int err; +gve_get_curr_alloc_cfgs (priv, &qpls_alloc_cfg, + &tx_alloc_cfg, &rx_alloc_cfg); +/* qpl_cfg is not read-only, it contains a map that gets updated as +* rings are allocated, which is why we cannot use the yet unreleased +* one in priv. +*/ + qpls_alloc_cfg.qpl_cfg = &new_qpl_cfg; + tx_alloc_cfg.qpl_cfg = &new_qpl_cfg; + rx_alloc_cfg.qpl_cfg = &new_qpl_cfg; +if ((netdev->features &NETIF_F_LRO ) != (features &NETIF_F_LRO )) { netdev->features ^=NETIF_F_LRO ;if (netif_carrier_ok (netdev)) { -/* To make this process as simple as possible we -* teardown the device, set the new configuration, -* and then bring the device up again. -*/ - err =gve_close (netdev); -/* We have already tried to reset in close, just fail -* at this point. -*/ -if (err) - goto err; - - err =gve_open (netdev); -if (err) - goto err; + err =gve_adjust_config (priv, &qpls_alloc_cfg, + &tx_alloc_cfg, &rx_alloc_cfg); +if (err) { +/* Revert the change on error. */ + netdev->features = orig_features; +return err; + } } }return 0 ; -err: -/* Reverts the change on error. */ - netdev->features = orig_features; -netif_err (priv, drv, netdev, -"Set features failed! !!! DISABLING ALL QUEUES !!!\n" ); -return err; }static const struct net_device_ops gve_netdev_ops = {
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Mon, 22 Jan 2024 18:26:26 +0000 you wrote:
Functions allocating resources did so directly into priv thus far. The assumption doing that was that priv was not already holding references to live resources.
When ring configuration is changed in any way from userspace, thus far we relied on calling the
ndo_stopandndo_opencallbacks in succession. This meant that we teardown existing resources and rob the OS of networking before we have successfully allocated resources for the new config.[...]
Here is the summary with links:
- [net-next,1/6] gve: Define config structs for queue allocation
https://git.kernel.org/netdev/net-next/c/7cea48b9a4b2 - [net-next,2/6] gve: Refactor napi add and remove functions https://git.kernel.org/netdev/net-next/c/1dfc2e46117e - [net-next,3/6] gve: Switch to config-aware queue allocation https://git.kernel.org/netdev/net-next/c/f13697cc7a19 - [net-next,4/6] gve: Refactor gve_open and gve_close https://git.kernel.org/netdev/net-next/c/92a6d7a4010c - [net-next,5/6] gve: Alloc before freeing when adjusting queues https://git.kernel.org/netdev/net-next/c/5f08cd3d6423 - [net-next,6/6] gve: Alloc before freeing when changing features https://git.kernel.org/netdev/net-next/c/f3753771e7cc
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html