Skip to contentSkip to conversation

GVE Raw Addressing

PATCH Superseded David Awogbemila 2 participants 14 messages Nov 3, 2020 – Nov 9, 2020

Subsystems (3)

v5 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v5 cover GVE Raw Addressing

Changes from v4:
Patch 2: Removed "#include <linux/device-mapper.h>" gve_rx.c - it was added
by accident.
Removed unused rx_no_refill_dropped_pkt field in gve_priv struct.

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 |  70 +++-
 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     | 374 ++++++++++++++-----
 drivers/net/ethernet/google/gve/gve_tx.c     | 207 ++++++++--
 7 files changed, 581 insertions(+), 155 deletions(-)
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
#1 lore raw

PATCH v5 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 | 52 ++++++++++++++++++++
 drivers/net/ethernet/google/gve/gve_adminq.h | 15 ++++--
 drivers/net/ethernet/google/gve/gve_main.c   |  9 ++++
 4 files changed, 73 insertions(+), 4 deletions(-)
drivers/net/ethernet/google/gve/gve.h +1 -0
index f5c80229ea96..80cdae06ee39 100644
@@ -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 +52 -0

69 lines not on this page · raw message

drivers/net/ethernet/google/gve/gve_adminq.h +11 -4
index 281de8326bc5..af5f586167bd 100644
@@ -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 0x0
 
 struct 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
index 48a433154ce0..70685c10db0e 100644
@@ -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.29.1.341.ge80a0c044ae-goog
#2 lore raw

Re: [PATCH 1/4] gve: Add support for raw addressing device option

Quoted 138 lines · David Awogbemila

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 | 52
++++++++++++++++++++
 drivers/net/ethernet/google/gve/gve_adminq.h | 15 ++++--
 drivers/net/ethernet/google/gve/gve_main.c   |  9 ++++
 4 files changed, 73 insertions(+), 4 deletions(-)
drivers/net/ethernet/google/gve/gve.h +1 -0
index f5c80229ea96..80cdae06ee39 100644
@@ -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 */

drivers/net/ethernet/google/gve/gve.h +0 -0
 	struct gve_queue_config tx_cfg;
 	struct gve_queue_config rx_cfg;
drivers/net/ethernet/google/gve/gve_adminq.c +3 -0
index 24ae6a28a806..0b7a2653fe33 100644
@@ -460,11 +460,14 @@ int gve_adminq_destroy_rx_queues(struct
 gve_priv *priv, u32 num_queues)
 int gve_adminq_describe_device(struct gve_priv *priv)
 {
 	struct gve_device_descriptor *descriptor;
+	struct gve_device_option *dev_opt;
 	union gve_adminq_command cmd;
 	dma_addr_t descriptor_bus;
+	u16 num_options;
 	int err = 0;
 	u8 *mac;
 	u16 mtu;
+	int i;
 
 	memset(&cmd, 0, sizeof(cmd));
drivers/net/ethernet/google/gve/gve_adminq.c +9 -0
 	descriptor = dma_alloc_coherent(&priv->pdev->dev, PAGE_SIZE,
@@ -518,6 +521,55 @@ 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);
+		void *option_end;
+
+		option_end = (void *)dev_opt + sizeof(*dev_opt) +

option_length;

drivers/net/ethernet/google/gve/gve_adminq.c +1 -0
+		if (option_end > (void *)descriptor +

be16_to_cpu(descriptor->total_length)) {

drivers/net/ethernet/google/gve/gve_adminq.c +2 -0
+			dev_err(&priv->dev->dev,
+				"options exceed device_descriptor's

total length.\n");

drivers/net/ethernet/google/gve/gve_adminq.c +10 -0
+			err = -EINVAL;
+			goto free_device_descriptor;
+		}
+
+		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 ||

drivers/net/ethernet/google/gve/gve_adminq.c +2 -0
+			    dev_opt->feat_mask !=
+			    cpu_to_be32(GVE_DEV_OPT_FEAT_MASK_RAW_ADDRE

SSING)) {

drivers/net/ethernet/google/gve/gve_adminq.c +2 -0
+				dev_warn(&priv->pdev->dev,
+					 "Raw addressing option

error:\n"

drivers/net/ethernet/google/gve/gve_adminq.c +1 -0
+					 "	Expected: length=%d,

feature_mask=%x.\n"

drivers/net/ethernet/google/gve/gve_adminq.c +1 -0
+					 "	Actual: length=%d,

feature_mask=%x.\n",

drivers/net/ethernet/google/gve/gve_adminq.c +1 -0
+					 GVE_DEV_OPT_LEN_RAW_ADDRESSING

,

drivers/net/ethernet/google/gve/gve_adminq.c +1 -0
+					 cpu_to_be32(GVE_DEV_OPT_FEAT_M

ASK_RAW_ADDRESSING),

drivers/net/ethernet/google/gve/gve_adminq.c +1 -0
+					 option_length, dev_opt-
Quoted 1 line

feat_mask);

drivers/net/ethernet/google/gve/gve_adminq.c +4 -0
+				priv->raw_addressing = false;
+			} else {
+				dev_info(&priv->pdev->dev,
+					 "Raw addressing device option

enabled.\n");

drivers/net/ethernet/google/gve/gve_adminq.c +5 -0
+				priv->raw_addressing = true;
+			}
+			break;
+		default:
+			/* If we don't recognize the option just

continue

drivers/net/ethernet/google/gve/gve_adminq.c +4 -0
+			 * without doing anything.
+			 */
+			dev_dbg(&priv->pdev->dev,
+				"Unrecognized device option 0x%hx not

enabled.\n",

drivers/net/ethernet/google/gve/gve_adminq.c +4 -0
+				option_id);
+			break;
+		}
+		dev_opt = (void *)dev_opt + sizeof(*dev_opt) +
Quoted 1 line

option_length;

This was already calculated above, "option_end"

Suggestion: you can make an iterator macro to return the next opt

next_opt = GET_NEXT_OPT(descriptor, curr_opt);

you can make it check boundaries and return null on last iteration or when total length is exceeded, and just use it in a more readable iterator loop.

#3 lore raw

Re: [PATCH 1/4] gve: Add support for raw addressing device option

Quoted 145 lines · Saeed Mahameed
Quoted 138 lines · David Awogbemila

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 | 52
++++++++++++++++++++
 drivers/net/ethernet/google/gve/gve_adminq.h | 15 ++++--
 drivers/net/ethernet/google/gve/gve_main.c   |  9 ++++
 4 files changed, 73 insertions(+), 4 deletions(-)
drivers/net/ethernet/google/gve/gve.h +1 -0
index f5c80229ea96..80cdae06ee39 100644
@@ -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 +3 -0
index 24ae6a28a806..0b7a2653fe33 100644
@@ -460,11 +460,14 @@ int gve_adminq_destroy_rx_queues(struct
 gve_priv *priv, u32 num_queues)
 int gve_adminq_describe_device(struct gve_priv *priv)
 {
      struct gve_device_descriptor *descriptor;
+     struct gve_device_option *dev_opt;
      union gve_adminq_command cmd;
      dma_addr_t descriptor_bus;
+     u16 num_options;
      int err = 0;
      u8 *mac;
      u16 mtu;
+     int i;
 
      memset(&cmd, 0, sizeof(cmd));
      descriptor = dma_alloc_coherent(&priv->pdev->dev, PAGE_SIZE,
drivers/net/ethernet/google/gve/gve_adminq.c +9 -0
@@ -518,6 +521,55 @@ 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);
+             void *option_end;
+
+             option_end = (void *)dev_opt + sizeof(*dev_opt) +

option_length;
+ if (option_end > (void *)descriptor +
be16_to_cpu(descriptor->total_length)) {

drivers/net/ethernet/google/gve/gve_adminq.c +2 -0
+                     dev_err(&priv->dev->dev,
+                             "options exceed device_descriptor's

total length.\n");

drivers/net/ethernet/google/gve/gve_adminq.c +10 -0
+                     err = -EINVAL;
+                     goto free_device_descriptor;
+             }
+
+             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 ||

drivers/net/ethernet/google/gve/gve_adminq.c +2 -0
+                         dev_opt->feat_mask !=
+                         cpu_to_be32(GVE_DEV_OPT_FEAT_MASK_RAW_ADDRE

SSING)) {

drivers/net/ethernet/google/gve/gve_adminq.c +2 -0
+                             dev_warn(&priv->pdev->dev,
+                                      "Raw addressing option

error:\n"
+ " Expected: length=%d,
feature_mask=%x.\n"
+ " Actual: length=%d,
feature_mask=%x.\n",
+ GVE_DEV_OPT_LEN_RAW_ADDRESSING
,
+ cpu_to_be32(GVE_DEV_OPT_FEAT_M
ASK_RAW_ADDRESSING),
+ option_length, dev_opt-

Quoted 1 line

feat_mask);

drivers/net/ethernet/google/gve/gve_adminq.c +4 -0
+                             priv->raw_addressing = false;
+                     } else {
+                             dev_info(&priv->pdev->dev,
+                                      "Raw addressing device option

enabled.\n");

drivers/net/ethernet/google/gve/gve_adminq.c +5 -0
+                             priv->raw_addressing = true;
+                     }
+                     break;
+             default:
+                     /* If we don't recognize the option just

continue

drivers/net/ethernet/google/gve/gve_adminq.c +4 -0
+                      * without doing anything.
+                      */
+                     dev_dbg(&priv->pdev->dev,
+                             "Unrecognized device option 0x%hx not

enabled.\n",

drivers/net/ethernet/google/gve/gve_adminq.c +4 -0
+                             option_id);
+                     break;
+             }
+             dev_opt = (void *)dev_opt + sizeof(*dev_opt) +
Quoted 1 line

option_length;

This was already calculated above, "option_end"

Quoted 8 lines

Suggestion: you can make an iterator macro to return the next opt

next_opt = GET_NEXT_OPT(descriptor, curr_opt);

you can make it check boundaries and return null on last iteration or when total length is exceeded, and just use it in a more readable iterator loop.

Thanks for the suggestion. I will adopt a macro but it'll only return NULL if the options exceed the boundary - that way we can distinguish between an error (boundary exceeded) and the last option.

#4 lore raw

Re: [PATCH 1/4] gve: Add support for raw addressing device option

Actually, I think I'll adopt a helper static inline function - it may be tidier than a macro.

Quoted 158 lines · David Awogbemila
Quoted 145 lines · Saeed Mahameed
Quoted 138 lines · David Awogbemila

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 | 52
++++++++++++++++++++
 drivers/net/ethernet/google/gve/gve_adminq.h | 15 ++++--
 drivers/net/ethernet/google/gve/gve_main.c   |  9 ++++
 4 files changed, 73 insertions(+), 4 deletions(-)
drivers/net/ethernet/google/gve/gve.h +1 -0
index f5c80229ea96..80cdae06ee39 100644
@@ -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 +3 -0
index 24ae6a28a806..0b7a2653fe33 100644
@@ -460,11 +460,14 @@ int gve_adminq_destroy_rx_queues(struct
 gve_priv *priv, u32 num_queues)
 int gve_adminq_describe_device(struct gve_priv *priv)
 {
      struct gve_device_descriptor *descriptor;
+     struct gve_device_option *dev_opt;
      union gve_adminq_command cmd;
      dma_addr_t descriptor_bus;
+     u16 num_options;
      int err = 0;
      u8 *mac;
      u16 mtu;
+     int i;
 
      memset(&cmd, 0, sizeof(cmd));
      descriptor = dma_alloc_coherent(&priv->pdev->dev, PAGE_SIZE,
drivers/net/ethernet/google/gve/gve_adminq.c +9 -0
@@ -518,6 +521,55 @@ 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);
+             void *option_end;
+
+             option_end = (void *)dev_opt + sizeof(*dev_opt) +

option_length;
+ if (option_end > (void *)descriptor +
be16_to_cpu(descriptor->total_length)) {

drivers/net/ethernet/google/gve/gve_adminq.c +2 -0
+                     dev_err(&priv->dev->dev,
+                             "options exceed device_descriptor's

total length.\n");

drivers/net/ethernet/google/gve/gve_adminq.c +10 -0
+                     err = -EINVAL;
+                     goto free_device_descriptor;
+             }
+
+             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 ||

drivers/net/ethernet/google/gve/gve_adminq.c +2 -0
+                         dev_opt->feat_mask !=
+                         cpu_to_be32(GVE_DEV_OPT_FEAT_MASK_RAW_ADDRE

SSING)) {

drivers/net/ethernet/google/gve/gve_adminq.c +2 -0
+                             dev_warn(&priv->pdev->dev,
+                                      "Raw addressing option

error:\n"
+ " Expected: length=%d,
feature_mask=%x.\n"
+ " Actual: length=%d,
feature_mask=%x.\n",
+ GVE_DEV_OPT_LEN_RAW_ADDRESSING
,
+ cpu_to_be32(GVE_DEV_OPT_FEAT_M
ASK_RAW_ADDRESSING),
+ option_length, dev_opt-

Quoted 1 line

feat_mask);

drivers/net/ethernet/google/gve/gve_adminq.c +4 -0
+                             priv->raw_addressing = false;
+                     } else {
+                             dev_info(&priv->pdev->dev,
+                                      "Raw addressing device option

enabled.\n");

drivers/net/ethernet/google/gve/gve_adminq.c +5 -0
+                             priv->raw_addressing = true;
+                     }
+                     break;
+             default:
+                     /* If we don't recognize the option just

continue

drivers/net/ethernet/google/gve/gve_adminq.c +4 -0
+                      * without doing anything.
+                      */
+                     dev_dbg(&priv->pdev->dev,
+                             "Unrecognized device option 0x%hx not

enabled.\n",

drivers/net/ethernet/google/gve/gve_adminq.c +4 -0
+                             option_id);
+                     break;
+             }
+             dev_opt = (void *)dev_opt + sizeof(*dev_opt) +
Quoted 1 line

option_length;

This was already calculated above, "option_end"

Quoted 8 lines

Suggestion: you can make an iterator macro to return the next opt

next_opt = GET_NEXT_OPT(descriptor, curr_opt);

you can make it check boundaries and return null on last iteration or when total length is exceeded, and just use it in a more readable iterator loop.

Thanks for the suggestion. I will adopt a macro but it'll only return NULL if the options exceed the boundary - that way we can distinguish between an error (boundary exceeded) and the last option.

#5 lore raw

PATCH v5 2/4 gve: Add support for raw addressing to the rx path

In reply to David Awogbemila

From: 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        |   9 +-
 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     | 220 +++++++++++++++----
 5 files changed, 203 insertions(+), 53 deletions(-)
drivers/net/ethernet/google/gve/gve.h +7 -2
index 80cdae06ee39..5c48f9e2d04c 100644
@@ -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,6 +83,7 @@ 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 */
@@ -194,7 +196,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 +446,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
index 0b7a2653fe33..3a7a12b3d144 100644
@@ -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
index 54779871d52e..0aad314aefaf 100644
@@ -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
index 70685c10db0e..225e17dd1ae5 100644
@@ -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 +180 -40

373 lines not on this page · raw message

Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
#6 lore raw

Re: [PATCH 2/4] gve: Add support for raw addressing to the rx path

Quoted 21 lines · David Awogbemila

From: 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        |   9 +-
 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     | 220 +++++++++++++++
----
 5 files changed, 203 insertions(+), 53 deletions(-)

...

drivers/net/ethernet/google/gve/gve.h static inline u32 gve_num_tx_qpls(struct gve_priv *priv) · line 452

Quoted 7 lines

static inline u32 gve_num_rx_qpls(struct gve_priv *priv) {

drivers/net/ethernet/google/gve/gve.h +4 -1
-	return priv->rx_cfg.num_queues;
+	if (priv->raw_addressing)
+		return 0;
+	else
+		return priv->rx_cfg.num_queues;

else statement is redundant.

Quoted 22 lines

static int gve_prefill_rx_pages(struct gve_rx_ring *rx) {

drivers/net/ethernet/google/gve/gve_rx.c +1 -0
 	struct gve_priv *priv = rx->gve;
 	u32 slots;
+	int err;
 	int i;
 
 	/* Allocate one page per Rx queue slot. Each page is split into

two

drivers/net/ethernet/google/gve/gve_rx.c +2 -4
@@ -71,12 +96,31 @@ static int gve_prefill_rx_pages(struct
 gve_rx_ring *rx)
 	if (!rx->data.page_info)
 		return -ENOMEM;
 
-	rx->data.qpl = gve_assign_rx_qpl(priv);
-
+	if (!rx->data.raw_addressing)
+		rx->data.qpl = gve_assign_rx_qpl(priv);
 	for (i = 0; i < slots; i++) {
-		struct page *page = rx->data.qpl->pages[i];
-		dma_addr_t addr = i * PAGE_SIZE;

drivers/net/ethernet/google/gve/gve_rx.c static int gve_prefill_rx_pages(struct · line 112

Quoted 10 lines
drivers/net/ethernet/google/gve/gve_rx.c +8 -0
+		struct page *page;
+		dma_addr_t addr;
+
+		if (rx->data.raw_addressing) {
+			err = gve_alloc_page(priv, &priv->pdev->dev,
 &page,
+					     &addr, DMA_FROM_DEVICE);
+			if (err) {
+				int j;
 

the code is skewed right, 5 level indentation is a lot.
you can just goto alloc_err; and handle the rewind on the exit path of the function .

BTW you could split this loop to two independent flows if you utilize gve_rx_alloc_buffer()

if (!raw_Addressing) {
        page = rx->data.qpl->pages[i];
	addr = i * PAGE_SIZE;
	gve_setup_rx_buffer(...);
        continue;
}

/* raw addressing mode */
err = gve_rx_alloc_buffer(...);
if (err)

      goto alloc_err;
#7 lore raw

Re: [PATCH 2/4] gve: Add support for raw addressing to the rx path

Quoted 34 lines · Saeed Mahameed
Quoted 21 lines · David Awogbemila

From: 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        |   9 +-
 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     | 220 +++++++++++++++
----
 5 files changed, 203 insertions(+), 53 deletions(-)

...

drivers/net/ethernet/google/gve/gve.h static inline u32 gve_num_tx_qpls(struct gve_priv *priv) · line 452

Quoted 7 lines

static inline u32 gve_num_rx_qpls(struct gve_priv *priv) {

drivers/net/ethernet/google/gve/gve.h +4 -1
-     return priv->rx_cfg.num_queues;
+     if (priv->raw_addressing)
+             return 0;
+     else
+             return priv->rx_cfg.num_queues;
Quoted 1 line

else statement is redundant.

Thanks, I'll take the else statement away.

Quoted 49 lines
Quoted 24 lines

static int gve_prefill_rx_pages(struct gve_rx_ring *rx)

 {
      struct gve_priv *priv = rx->gve;
      u32 slots;
+     int err;
      int i;

      /* Allocate one page per Rx queue slot. Each page is split into

two

drivers/net/ethernet/google/gve/gve_rx.c +2 -4
@@ -71,12 +96,31 @@ static int gve_prefill_rx_pages(struct
 gve_rx_ring *rx)
      if (!rx->data.page_info)
              return -ENOMEM;
 
-     rx->data.qpl = gve_assign_rx_qpl(priv);
-
+     if (!rx->data.raw_addressing)
+             rx->data.qpl = gve_assign_rx_qpl(priv);
      for (i = 0; i < slots; i++) {
-             struct page *page = rx->data.qpl->pages[i];
-             dma_addr_t addr = i * PAGE_SIZE;

drivers/net/ethernet/google/gve/gve_rx.c static int gve_prefill_rx_pages(struct · line 112

Quoted 10 lines
drivers/net/ethernet/google/gve/gve_rx.c +8 -0
+             struct page *page;
+             dma_addr_t addr;
+
+             if (rx->data.raw_addressing) {
+                     err = gve_alloc_page(priv, &priv->pdev->dev,
 &page,
+                                          &addr, DMA_FROM_DEVICE);
+                     if (err) {
+                             int j;
 

the code is skewed right, 5 level indentation is a lot.
you can just goto alloc_err; and handle the rewind on the exit path of the function .

BTW you could split this loop to two independent flows if you utilize gve_rx_alloc_buffer()

if (!raw_Addressing) {
        page = rx->data.qpl->pages[i];
        addr = i * PAGE_SIZE;
        gve_setup_rx_buffer(...);
        continue;
}
Quoted 5 lines

/* raw addressing mode */
err = gve_rx_alloc_buffer(...);
if (err)

      goto alloc_err;

Thanks, I'll eliminate the skew andI'll take the suggestion to separate the independent flows.

#8 lore raw

PATCH v5 3/4 gve: Rx Buffer Recycling

In reply to David Awogbemila

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.

---
 drivers/net/ethernet/google/gve/gve.h    |  10 +-
 drivers/net/ethernet/google/gve/gve_rx.c | 194 +++++++++++++++--------
 2 files changed, 129 insertions(+), 75 deletions(-)
drivers/net/ethernet/google/gve/gve.h +1 -9
index 5c48f9e2d04c..d1a2a526a250 100644
@@ -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
@@ -503,15 +504,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 +128 -66

255 lines not on this page · raw message

Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
#9 lore raw

Re: [PATCH 3/4] gve: Rx Buffer Recycling

Quoted 28 lines · David Awogbemila

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.

---
 drivers/net/ethernet/google/gve/gve.h    |  10 +-
 drivers/net/ethernet/google/gve/gve_rx.c | 194 +++++++++++++++----

----

drivers/net/ethernet/google/gve/gve_rx.c +13 -0
+	if (len <= priv->rx_copybreak) {
+		/* Just copy small packets */
+		skb = gve_rx_copy(dev, napi, page_info, len);
+		u64_stats_update_begin(&rx->statss);
+		rx->rx_copied_pkt++;
+		rx->rx_copybreak_pkt++;
+		u64_stats_update_end(&rx->statss);
+	} else {
+		bool can_flip = gve_rx_can_flip_buffers(dev);
+		int recycle = 0;
+
+		if (can_flip) {
+			recycle = gve_rx_can_recycle_buffer(page_info-
Quoted 1 line

page);

Review

Quoted 2 lines
(quoted diff) +2 -0
+			if (recycle < 0) {
+				gve_schedule_reset(priv);

How would a reset solve anything if your driver is handling pages with "bad" refcount, i don't agree here that reset is the best course of action, all you can do here is warn and leak the page ... this is a critical driver bug and not something that user should expect.

Quoted 16 lines
drivers/net/ethernet/google/gve/gve_rx.c +3 -0
+	
+		} else {
+			/* It is possible that the networking stack has

already

(quoted diff) +1 -0
+			 * finished processing all outstanding packets

in the buffer

(quoted diff) +2 -0
+			 * and it can be reused.
+			 * Flipping is unnecessary here - if the

networking stack still

(quoted diff) +1 -0
+			 * owns half the page it is impossible to tell

which half. Either

(quoted diff) +1 -0
+			 * the whole page is free or it needs to be

replaced.

(quoted diff) +2 -0
+			 */
+			int recycle =

gve_rx_can_recycle_buffer(page_info->page);

drivers/net/ethernet/google/gve/gve_rx.c static bool gve_rx(struct gve_rx_ring *rx, struct gve_rx_desc *rx_desc, · line 468

Quoted 4 lines
drivers/net/ethernet/google/gve/gve_rx.c +4 -0
+
+			if (recycle < 0) {
+				gve_schedule_reset(priv);
+				return false;

Same.

#10 lore raw

Re: [PATCH 3/4] gve: Rx Buffer Recycling

Quoted 30 lines · Saeed Mahameed
Quoted 28 lines · David Awogbemila

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.

---
 drivers/net/ethernet/google/gve/gve.h    |  10 +-
 drivers/net/ethernet/google/gve/gve_rx.c | 194 +++++++++++++++----

----

drivers/net/ethernet/google/gve/gve_rx.c +13 -0
+     if (len <= priv->rx_copybreak) {
+             /* Just copy small packets */
+             skb = gve_rx_copy(dev, napi, page_info, len);
+             u64_stats_update_begin(&rx->statss);
+             rx->rx_copied_pkt++;
+             rx->rx_copybreak_pkt++;
+             u64_stats_update_end(&rx->statss);
+     } else {
+             bool can_flip = gve_rx_can_flip_buffers(dev);
+             int recycle = 0;
+
+             if (can_flip) {
+                     recycle = gve_rx_can_recycle_buffer(page_info-
Quoted 1 line

page);

Quoted 9 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+                     if (recycle < 0) {
+                             gve_schedule_reset(priv);

How would a reset solve anything if your driver is handling pages with "bad" refcount, i don't agree here that reset is the best course of action, all you can do here is warn and leak the page ... this is a critical driver bug and not something that user should expect.

Thanks for pointing this out. For the raw addressing case it would be fine to warn and leak the page, but for the qpl (non raw addressing) case, the driver pre-allocates a set of pages which it registers with the NIC so we'd want to avoid leaking pages - a reset will help here because we'd allocate a new set of pages and register them with the NIC.
I will handle both cases separately:
- in raw addressing mode, just warn and leak the page
- in qpl mode, schedule a reset.

Quoted 24 lines
Quoted 16 lines
drivers/net/ethernet/google/gve/gve_rx.c +3 -0
+
+             } else {
+                     /* It is possible that the networking stack has

already
+ * finished processing all outstanding packets
in the buffer

(quoted diff) +2 -0
+                      * 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.

(quoted diff) +2 -0
+                      */
+                     int recycle =

gve_rx_can_recycle_buffer(page_info->page);

drivers/net/ethernet/google/gve/gve_rx.c static bool gve_rx(struct gve_rx_ring *rx, struct gve_rx_desc *rx_desc, · line 468

Quoted 4 lines
drivers/net/ethernet/google/gve/gve_rx.c +4 -0
+
+                     if (recycle < 0) {
+                             gve_schedule_reset(priv);
+                             return false;

Same.

#11 lore raw

PATCH v5 4/4 gve: Add support for raw addressing in the tx path

In reply to David Awogbemila

From: 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     | 207 +++++++++++++++----
 4 files changed, 194 insertions(+), 43 deletions(-)
drivers/net/ethernet/google/gve/gve.h +16 -2
index d1a2a526a250..37a449fb032e 100644
@@ -110,12 +110,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 */
@@ -138,13 +146,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 */
@@ -440,7 +451,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
index 3a7a12b3d144..1b3715e21ae4 100644
@@ -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
index 0aad314aefaf..a7da364e81c8 100644
@@ -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 +170 -37

309 lines not on this page · raw message

Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
#12 lore raw

Re: [PATCH 4/4] gve: Add support for raw addressing in the tx path

Quoted 22 lines · David Awogbemila

From: 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     | 207 +++++++++++++++
----
 4 files changed, 194 insertions(+), 43 deletions(-)

static inline u32 gve_num_tx_qpls(struct gve_priv *priv) {

drivers/net/ethernet/google/gve/gve.h static inline u32 gve_rx_idx_to_ntfy(struct gve_priv *priv, u32 queue_idx) · line 457

Quoted 5 lines
drivers/net/ethernet/google/gve/gve.h +4 -1
-	return priv->tx_cfg.num_queues;
+	if (priv->raw_addressing)
+		return 0;
+	else
+		return priv->tx_cfg.num_queues;

redundant else statement.

Quoted 19 lines

-static void gve_dma_sync_for_device(struct device *dev, dma_addr_t *page_buses,

drivers/net/ethernet/google/gve/gve_tx.c +2 -3
+static void gve_dma_sync_for_device(struct gve_priv *priv,
+				    dma_addr_t *page_buses,
 				    u64 iov_offset, u64 iov_len)
 {
 	u64 last_page = (iov_offset + iov_len - 1) / PAGE_SIZE;
 	u64 first_page = iov_offset / PAGE_SIZE;
-	dma_addr_t dma;
 	u64 page;
 
 	for (page = first_page; page <= last_page; page++) {
-		dma = page_buses[page];
-		dma_sync_single_for_device(dev, dma, PAGE_SIZE,

DMA_TO_DEVICE);

drivers/net/ethernet/google/gve/gve_tx.c +3 -0
+		dma_addr_t dma = page_buses[page];
+
+		dma_sync_single_for_device(&priv->pdev->dev, dma,
Quoted 1 line

PAGE_SIZE, DMA_TO_DEVICE);

Why did you change the function params to pass priv here ? I don't see any valid reason.

...

Quoted 6 lines
drivers/net/ethernet/google/gve/gve_tx.c +1 -1
-	gve_dma_sync_for_device(dev, tx->tx_fifo.qpl->page_buses,
+	gve_dma_sync_for_device(priv, tx->tx_fifo.qpl->page_buses,
 				info->iov[hdr_nfrags - 1].iov_offset,
 				info->iov[hdr_nfrags - 1].iov_len);

...

Quoted 87 lines
(quoted diff) +0 -1
-		gve_dma_sync_for_device(dev, tx->tx_fifo.qpl-
Quoted 1 line

page_buses,

(quoted diff) +1 -0
+		gve_dma_sync_for_device(priv, tx->tx_fifo.qpl-
Quoted 1 line

page_buses,

drivers/net/ethernet/google/gve/gve_tx.c +20 -0
 					info->iov[i].iov_offset,
 					info->iov[i].iov_len);
 		copy_offset += info->iov[i].iov_len;
@@ -472,6 +499,98 @@ static int gve_tx_add_skb(struct gve_tx_ring
 *tx, struct sk_buff *skb,
 	return 1 + payload_nfrags;
 }
 
+static int gve_tx_add_skb_no_copy(struct gve_priv *priv, struct
 gve_tx_ring *tx,
+				  struct sk_buff *skb)
+{
+	const struct skb_shared_info *shinfo = skb_shinfo(skb);
+	int hlen, payload_nfrags, l4_hdr_offset, seg_idx_bias;
+	union gve_tx_desc *pkt_desc, *seg_desc;
+	struct gve_tx_buffer_state *info;
+	bool is_gso = skb_is_gso(skb);
+	u32 idx = tx->req & tx->mask;
+	struct gve_tx_dma_buf *buf;
+	int last_mapped = 0;
+	u64 addr;
+	u32 len;
+	int i;
+
+	info = &tx->info[idx];
+	pkt_desc = &tx->desc[idx];
+
+	l4_hdr_offset = skb_checksum_start_offset(skb);
+	/* If the skb is gso, then we want only up to the tcp header in

the first segment

(quoted diff) +1 -0
+	 * to efficiently replicate on each segment otherwise we want

the linear portion

(quoted diff) +1 -0
+	 * of the skb (which will contain the checksum because skb-
Quoted 1 line

csum_start and

(quoted diff) +1 -0
+	 * skb->csum_offset are given relative to skb->head) in the

first segment.

drivers/net/ethernet/google/gve/gve_tx.c +19 -0
+	 */
+	hlen = is_gso ? l4_hdr_offset + tcp_hdrlen(skb) :
+			skb_headlen(skb);
+	len = skb_headlen(skb);
+
+	info->skb =  skb;
+
+	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);
+	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

drivers/net/ethernet/google/gve/gve_tx.c +4 -0
+		 * be in its own descriptor.
+		 */
+		payload_nfrags++;
+		gve_tx_fill_pkt_desc(pkt_desc, skb, is_gso,

l4_hdr_offset,

drivers/net/ethernet/google/gve/gve_tx.c +10 -0
+				     1 + payload_nfrags, hlen, addr);
+
+		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,

drivers/net/ethernet/google/gve/gve_tx.c +10 -0
+				     1 + payload_nfrags, hlen, addr);
+	}
+	idx = (tx->req + seg_idx_bias) & tx->mask;
+
+	for (i = 0; i < payload_nfrags - (seg_idx_bias - 1); i++) {
+		const skb_frag_t *frag = &shinfo->frags[i];
+
+		seg_desc = &tx->desc[idx];
+		len = skb_frag_size(frag);
+		addr = skb_frag_dma_map(tx->dev, frag, 0, len,

DMA_TO_DEVICE);

Review

Quoted 2 lines
(quoted diff) +2 -0
+		if (unlikely(dma_mapping_error(tx->dev, addr))) {
+			priv->dma_mapping_error++;

don't you need to protect this from parallel access ?

Quoted 25 lines
drivers/net/ethernet/google/gve/gve_tx.c +16 -0
+			goto unmap_drop;
+		}
+		buf = &tx->info[idx].buf;
+		tx->info[idx].skb = NULL;
+		dma_unmap_len_set(buf, len, len);
+		dma_unmap_addr_set(buf, dma, addr);
+
+		gve_tx_fill_seg_desc(seg_desc, skb, is_gso, len, addr);
+		idx = (idx + 1) & tx->mask;
+	}
+
+	return 1 + payload_nfrags;
+
+unmap_drop:
+	i--;
+	for (last_mapped = i + seg_idx_bias; last_mapped >= 0;

last_mapped--) {

drivers/net/ethernet/google/gve/gve_tx.c +8 -0
+		idx = (tx->req + last_mapped) & tx->mask;
+		gve_tx_unmap_buf(tx->dev, &tx->info[idx]);
+	}
+drop:
+	tx->dropped_pkt++;
+	return 0;
+}
+

...

#13 lore raw

Re: [PATCH 4/4] gve: Add support for raw addressing in the tx path

Quoted 30 lines · Saeed Mahameed
Quoted 22 lines · David Awogbemila

From: 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     | 207 +++++++++++++++
----
 4 files changed, 194 insertions(+), 43 deletions(-)

static inline u32 gve_num_tx_qpls(struct gve_priv *priv) {

drivers/net/ethernet/google/gve/gve.h static inline u32 gve_rx_idx_to_ntfy(struct gve_priv *priv, u32 queue_idx) · line 457

Quoted 5 lines
drivers/net/ethernet/google/gve/gve.h +4 -1
-     return priv->tx_cfg.num_queues;
+     if (priv->raw_addressing)
+             return 0;
+     else
+             return priv->tx_cfg.num_queues;
Quoted 1 line

redundant else statement.

Ok, I'll remove the else.

Quoted 13 lines
Quoted 13 lines

-static void gve_dma_sync_for_device(struct device *dev, dma_addr_t *page_buses,

drivers/net/ethernet/google/gve/gve_tx.c +2 -1
+static void gve_dma_sync_for_device(struct gve_priv *priv,
+                                 dma_addr_t *page_buses,
                                  u64 iov_offset, u64 iov_len)
 {
      u64 last_page = (iov_offset + iov_len - 1) / PAGE_SIZE;
      u64 first_page = iov_offset / PAGE_SIZE;
-     dma_addr_t dma;
      u64 page;
Quoted 11 lines
Quoted 8 lines
      for (page = first_page; page <= last_page; page++) {
(quoted diff) +0 -2
-             dma = page_buses[page];
-             dma_sync_single_for_device(dev, dma, PAGE_SIZE,

DMA_TO_DEVICE);

drivers/net/ethernet/google/gve/gve_tx.c +3 -0
+             dma_addr_t dma = page_buses[page];
+
+             dma_sync_single_for_device(&priv->pdev->dev, dma,

PAGE_SIZE, DMA_TO_DEVICE);

Why did you change the function params to pass priv here ? I don't see any valid reason.

Good point, I will revert this.

Quoted 94 lines

...

Quoted 6 lines
drivers/net/ethernet/google/gve/gve_tx.c +1 -1
-     gve_dma_sync_for_device(dev, tx->tx_fifo.qpl->page_buses,
+     gve_dma_sync_for_device(priv, tx->tx_fifo.qpl->page_buses,
                              info->iov[hdr_nfrags - 1].iov_offset,
                              info->iov[hdr_nfrags - 1].iov_len);

...

Quoted 83 lines

- gve_dma_sync_for_device(dev, tx->tx_fifo.qpl-

Quoted 1 line

page_buses,

+ gve_dma_sync_for_device(priv, tx->tx_fifo.qpl-

Quoted 1 line

page_buses,

                                      info->iov[i].iov_offset,
                                      info->iov[i].iov_len);
              copy_offset += info->iov[i].iov_len;
drivers/net/ethernet/google/gve/gve_tx.c +20 -0
@@ -472,6 +499,98 @@ static int gve_tx_add_skb(struct gve_tx_ring
 *tx, struct sk_buff *skb,
      return 1 + payload_nfrags;
 }
 
+static int gve_tx_add_skb_no_copy(struct gve_priv *priv, struct
 gve_tx_ring *tx,
+                               struct sk_buff *skb)
+{
+     const struct skb_shared_info *shinfo = skb_shinfo(skb);
+     int hlen, payload_nfrags, l4_hdr_offset, seg_idx_bias;
+     union gve_tx_desc *pkt_desc, *seg_desc;
+     struct gve_tx_buffer_state *info;
+     bool is_gso = skb_is_gso(skb);
+     u32 idx = tx->req & tx->mask;
+     struct gve_tx_dma_buf *buf;
+     int last_mapped = 0;
+     u64 addr;
+     u32 len;
+     int i;
+
+     info = &tx->info[idx];
+     pkt_desc = &tx->desc[idx];
+
+     l4_hdr_offset = skb_checksum_start_offset(skb);
+     /* If the skb is gso, then we want only up to the tcp header in

the first segment
+ * to efficiently replicate on each segment otherwise we want
the linear portion
+ * of the skb (which will contain the checksum because skb-

Quoted 1 line

csum_start and

+ * skb->csum_offset are given relative to skb->head) in the
first segment.

drivers/net/ethernet/google/gve/gve_tx.c +19 -0
+      */
+     hlen = is_gso ? l4_hdr_offset + tcp_hdrlen(skb) :
+                     skb_headlen(skb);
+     len = skb_headlen(skb);
+
+     info->skb =  skb;
+
+     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);
+     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

drivers/net/ethernet/google/gve/gve_tx.c +4 -0
+              * be in its own descriptor.
+              */
+             payload_nfrags++;
+             gve_tx_fill_pkt_desc(pkt_desc, skb, is_gso,

l4_hdr_offset,

drivers/net/ethernet/google/gve/gve_tx.c +10 -0
+                                  1 + payload_nfrags, hlen, addr);
+
+             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,

drivers/net/ethernet/google/gve/gve_tx.c +7 -0
+                                  1 + payload_nfrags, hlen, addr);
+     }
+     idx = (tx->req + seg_idx_bias) & tx->mask;
+
+     for (i = 0; i < payload_nfrags - (seg_idx_bias - 1); i++) {
+             const skb_frag_t *frag = &shinfo->frags[i];
+
Quoted 8 lines

Review

Quoted 6 lines
drivers/net/ethernet/google/gve/gve_tx.c +3 -0
+             seg_desc = &tx->desc[idx];
+             len = skb_frag_size(frag);
+             addr = skb_frag_dma_map(tx->dev, frag, 0, len,

DMA_TO_DEVICE);

(quoted diff) +2 -0
+             if (unlikely(dma_mapping_error(tx->dev, addr))) {
+                     priv->dma_mapping_error++;

don't you need to protect this from parallel access ?

I think you're right. I'll protect it with rtnl_lock/unlock/end.

Quoted 28 lines
Quoted 25 lines
drivers/net/ethernet/google/gve/gve_tx.c +16 -0
+                     goto unmap_drop;
+             }
+             buf = &tx->info[idx].buf;
+             tx->info[idx].skb = NULL;
+             dma_unmap_len_set(buf, len, len);
+             dma_unmap_addr_set(buf, dma, addr);
+
+             gve_tx_fill_seg_desc(seg_desc, skb, is_gso, len, addr);
+             idx = (idx + 1) & tx->mask;
+     }
+
+     return 1 + payload_nfrags;
+
+unmap_drop:
+     i--;
+     for (last_mapped = i + seg_idx_bias; last_mapped >= 0;

last_mapped--) {

drivers/net/ethernet/google/gve/gve_tx.c +8 -0
+             idx = (tx->req + last_mapped) & tx->mask;
+             gve_tx_unmap_buf(tx->dev, &tx->info[idx]);
+     }
+drop:
+     tx->dropped_pkt++;
+     return 0;
+}
+

...