gve: leave refcount headroom in the RX page bias
Subsystems (5)
PATCH v3 1/1 gve: leave refcount headroom in the RX page bias
gve's GQI and DQO-QPL RX paths set every RX page's refcount to INT_MAX and hand references to the stack by decrementing page_info->pagecnt_bias, to avoid an atomic op per packet. This leaves the page no headroom: while a fresh page's buffer sits in an skb its refcount is already INT_MAX, so a single get_page() from the stack wraps it negative.
splice() of received TCP data into a pipe takes such a reference, and the onward splice into a socket then fails: skb_splice_from_iter() sees page_count() < 1, sendpage_ok() fails and the send returns -EIO (since commit 2e910b95329c ("net: Add a function to splice pages into an skbuff for MSG_SPLICE_PAGES")). tee() of the pipe fails with -EFAULT via try_get_page(). On GQI the reuse check gve_rx_can_recycle_buffer() also sees page_count() < pagecnt_bias, WARNs and calls gve_schedule_reset(), so a task that merely pins a fresh RX page (e.g. holds spliced data in an undrained tee() pipe) can reset the NIC.
Use USHRT_MAX in a u16, as igb, igc, ixgbe, i40e and hns3 do: the bias only has to make the per-packet atomic rare, so a small value leaves page_count() ample headroom below INT_MAX for the stack's references. Refill by adding a fixed batch and setting the bias to it, which keeps the rule references = page_count() - bias intact.
Reproduced on gVNIC in GQI-QPL mode (GCE n2-standard-8, 6.12) and in DQO-RDA mode (GCE c3-standard-8, 6.12, where DQO-RDA still uses the bias) with the help of relay.py -- a small splice(2) TCP proxy -- relaying a download while the RX ring is refilled with fresh pages:
ethtool -G eth0 rx 512 && ethtool -G eth0 rx 1024 # fresh RX pages
./relay.py $HOST 8080 & # splice()s both ways
for i in $(seq 200); do curl -so /dev/null \
--connect-to $HOST:80:127.0.0.1:8080 http://$HOST/file; doneMost downloads failed with EIO before the fix (tee() with EFAULT) and all completed after it. relay.py is at the Link below.
This bug was found and fixed with the help of an AI coding assistant (Claude Code) over an interactive session; it read the driver and splice/pipe code and ran the tests above.
---
v3:
- Refill when the bias reaches 0 again, as in v1. DQO-QPL is not supposed to support XDP at all, and it will be blocked explicitly in a separate patch, so the v2 refill-at-1 change is not needed.
- Added Reviewed-by and Tested-by from Harshitha Ramamurthy.
v2: https://lore.kernel.org/netdev/[email protected]/
- Refill when the bias reaches 1 instead of 0 so the driver keeps a reference of its own across every handoff. At bias 0 a consumer that returns its reference synchronously, such as an AF_XDP socket in copy mode on an XDP_REDIRECT from DQO-QPL, freed a page still registered in the QPL.
- Commit message: explain the refill point, drop the build notes.
- Re-tested on 6.12.113 (c3-standard-8, DQO-RDA, which still uses the bias on 6.12): no EIO/EFAULT from splice/tee and no NIC reset after applying the patch. DQO-QPL is untested; I have no access to that hardware.
v1: https://lore.kernel.org/netdev/[email protected]/
Built allmodconfig W=1, no new warnings.
drivers/net/ethernet/google/gve/gve.h | 2 +- .../net/ethernet/google/gve/gve_buffer_mgmt_dqo.c | 4 ++-- drivers/net/ethernet/google/gve/gve_rx.c | 8 ++++---- drivers/net/ethernet/google/gve/gve_utils.c | 12 +++--------- drivers/net/ethernet/google/gve/gve_utils.h | 8 +++++++- 5 files changed, 17 insertions(+), 17 deletions(-)
drivers/net/ethernet/google/gve/gve.h +1 -1
@@ -119,7 +119,7 @@ struct gve_rx_slot_page_info {void *page_address;u32 page_offset;/* offset to write to in page */ unsigned int buf_size; -int pagecnt_bias;/* expected pagecnt if only the driver has a ref */ +u16 pagecnt_bias;/* expected pagecnt if only the driver has a ref */ u16 pad;/* adjustment for rx padding */ u8 can_flip;/* tracks if the networking stack is using the page */ };
drivers/net/ethernet/google/gve/gve_buffer_mgmt_dqo.c +2 -2
@@ -149,8 +149,8 @@ int gve_alloc_qpl_page_dqo(struct gve_rx_ring *rx, buf_state->last_single_ref_offset =0 ;/* The page already has 1 ref. */ -page_ref_add (buf_state->page_info.page,INT_MAX -1 ); - buf_state->page_info.pagecnt_bias =INT_MAX ; +page_ref_add (buf_state->page_info.page,GVE_PAGECNT_BIAS -1 ); + buf_state->page_info.pagecnt_bias =GVE_PAGECNT_BIAS ;return 0 ; }
drivers/net/ethernet/google/gve/gve_rx.c +4 -4
@@ -152,8 +152,8 @@ static void gve_setup_rx_buffer(struct gve_rx_ring *rx, page_info->buf_size = rx->packet_buffer_size; *slot_addr =cpu_to_be64 (addr);/* The page already has 1 ref */ -page_ref_add (page,INT_MAX -1 ); - page_info->pagecnt_bias =INT_MAX ; +page_ref_add (page,GVE_PAGECNT_BIAS -1 ); + page_info->pagecnt_bias =GVE_PAGECNT_BIAS ; } static int gve_rx_alloc_buffer(struct gve_priv *priv, struct device *dev,
@@ -230,8 +230,8 @@ static int gve_rx_prefill_pages(struct gve_rx_ring *rx, rx->qpl_copy_pool[j].buf_size = rx->packet_buffer_size;/* The page already has 1 ref. */ -page_ref_add (page,INT_MAX -1 ); - rx->qpl_copy_pool[j].pagecnt_bias =INT_MAX ; +page_ref_add (page,GVE_PAGECNT_BIAS -1 ); + rx->qpl_copy_pool[j].pagecnt_bias =GVE_PAGECNT_BIAS ; } }
drivers/net/ethernet/google/gve/gve_utils.c +3 -9
@@ -93,15 +93,9 @@ void gve_dec_pagecnt_bias(struct gve_rx_slot_page_info *page_info) { page_info->pagecnt_bias--;if (page_info->pagecnt_bias ==0 ) { -int pagecount =page_count (page_info->page); - -/* If we have run out of bias - set it back up to INT_MAX -* minus the existing refs. -*/ - page_info->pagecnt_bias =INT_MAX - pagecount; - -/* Set pagecount back up to max. */ -page_ref_add (page_info->page,INT_MAX - pagecount); +/* Out of bias: take another batch of references. */ + page_info->pagecnt_bias =GVE_PAGECNT_BIAS ; +page_ref_add (page_info->page,GVE_PAGECNT_BIAS ); } }
drivers/net/ethernet/google/gve/gve_utils.h +7 -1
@@ -25,7 +25,13 @@ struct sk_buff *gve_rx_copy_data(struct net_device *dev, struct napi_struct *napstruct sk_buff *gve_rx_copy (struct net_device *dev,struct napi_struct *napi,struct gve_rx_slot_page_info *page_info,u16 len); -/* Decrement pagecnt_bias. Set it back to INT_MAX if it reached zero. */ +/* Up-front references gve holds on an RX page, so handing a buffer to the +* stack is a pagecnt_bias decrement, not a get_page(). Keep it in a u16 so +* the 32-bit page refcount keeps the headroom every page needs below INT_MAX. +*/ +#define GVE_PAGECNT_BIAS USHRT_MAX + +/* Decrement pagecnt_bias. Top it up by GVE_PAGECNT_BIAS 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,
base-commit: 21f57ec673a1917547c808cfa81890485fffa03b
Signature · 1 line
2.47.3
Quoted 5 lines · Amaan Cheval
gve's GQI and DQO-QPL RX paths set every RX page's refcount to
INT_MAXand hand references to the stack by decrementingpage_info->pagecnt_bias, to avoid an atomic op per packet. This leaves the page no headroom: while a fresh page's buffer sits in an skb its refcount is alreadyINT_MAX, so a singleget_page()from the stack wraps it negative.
Hi Amaan,
by headroom you mean here the space for additional refcount bumps? A bit confusing as my head tends to correlate 'headroom' with packet layout ;)
one minor comment below.
Quoted 152 lines
splice()of received TCP data into a pipe takes such a reference, and the onward splice into a socket then fails:skb_splice_from_iter()seespage_count()< 1,sendpage_ok()fails and the send returns-EIO(since commit2e910b95329c("net: Add a function to splice pages into an skbuff forMSG_SPLICE_PAGES")).tee()of the pipe fails with-EFAULTviatry_get_page(). On GQI the reuse checkgve_rx_can_recycle_buffer()also seespage_count()<pagecnt_bias, WARNs and callsgve_schedule_reset(), so a task that merely pins a fresh RX page (e.g. holds spliced data in an undrainedtee()pipe) can reset the NIC.Use
USHRT_MAXin a u16, as igb, igc, ixgbe, i40e and hns3 do: the bias only has to make the per-packet atomic rare, so a small value leavespage_count()ample headroom belowINT_MAXfor the stack's references. Refill by adding a fixed batch and setting the bias to it, which keeps the rulereferences = page_count() - biasintact.Reproduced on gVNIC in GQI-QPL mode (GCE n2-standard-8, 6.12) and in DQO-RDA mode (GCE c3-standard-8, 6.12, where DQO-RDA still uses the bias) with the help of
relay.py-- a small splice(2) TCP proxy -- relaying a download while the RX ring is refilled with fresh pages:ethtool -G eth0 rx 512 && ethtool -G eth0 rx 1024 # fresh RX pages ./relay.py $HOST 8080 & # splice()s both ways for i in $(seq 200); do curl -so /dev/null \ --connect-to $HOST:80:127.0.0.1:8080 http://$HOST/file; doneMost downloads failed with EIO before the fix (
tee()with EFAULT) and all completed after it.relay.pyis at the Link below.This bug was found and fixed with the help of an AI coding assistant (Claude Code) over an interactive session; it read the driver and splice/pipe code and ran the tests above.
Fixes 9b8dd5e5ea48 ("gve: DQO: Add RX path")Fixes 58401b2a46e7 ("gve: Add rx buffer pagecnt bias")Fixes 82fd151d38d9 ("gve: Reduce alloc and copy costs in the GQ rx path")Reviewed-by Harshitha Ramamurthy <[email protected]>Tested-by Harshitha Ramamurthy <[email protected]>Signed-off-by Amaan Cheval <[email protected]>---
v3:
- Refill when the bias reaches 0 again, as in v1. DQO-QPL is not supposed to support XDP at all, and it will be blocked explicitly in a separate patch, so the v2 refill-at-1 change is not needed.
- Added Reviewed-by and Tested-by from Harshitha Ramamurthy.
v2: https://lore.kernel.org/netdev/[email protected]/
- Refill when the bias reaches 1 instead of 0 so the driver keeps a reference of its own across every handoff. At bias 0 a consumer that returns its reference synchronously, such as anAF_XDPsocket in copy mode on anXDP_REDIRECTfrom DQO-QPL, freed a page still registered in the QPL.
- Commit message: explain the refill point, drop the build notes.
- Re-tested on 6.12.113 (c3-standard-8, DQO-RDA, which still uses the bias on 6.12): no EIO/EFAULT from splice/tee and no NIC reset after applying the patch. DQO-QPL is untested; I have no access to that hardware.
v1: https://lore.kernel.org/netdev/[email protected]/Built allmodconfig W=1, no new warnings.
drivers/net/ethernet/google/gve/gve.h | 2 +- .../net/ethernet/google/gve/gve_buffer_mgmt_dqo.c | 4 ++-- drivers/net/ethernet/google/gve/gve_rx.c | 8 ++++---- drivers/net/ethernet/google/gve/gve_utils.c | 12 +++--------- drivers/net/ethernet/google/gve/gve_utils.h | 8 +++++++- 5 files changed, 17 insertions(+), 17 deletions(-)drivers/net/ethernet/google/gve/gve.h +1
-1@@ -119,7 +119,7 @@ struct gve_rx_slot_page_info {void *page_address;u32 page_offset;/* offset to write to in page */ unsigned int buf_size; -int pagecnt_bias;/* expected pagecnt if only the driver has a ref */ +u16 pagecnt_bias;/* expected pagecnt if only the driver has a ref */ u16 pad;/* adjustment for rx padding */ u8 can_flip;/* tracks if the networking stack is using the page */ };drivers/net/ethernet/google/gve/gve_buffer_mgmt_dqo.c +2
-2@@ -149,8 +149,8 @@ int gve_alloc_qpl_page_dqo(struct gve_rx_ring *rx, buf_state->last_single_ref_offset =0 ;/* The page already has 1 ref. */ -page_ref_add (buf_state->page_info.page,INT_MAX -1 ); - buf_state->page_info.pagecnt_bias =INT_MAX ; +page_ref_add (buf_state->page_info.page,GVE_PAGECNT_BIAS -1 ); + buf_state->page_info.pagecnt_bias =GVE_PAGECNT_BIAS ;return 0 ; }drivers/net/ethernet/google/gve/gve_rx.c +4
-4@@ -152,8 +152,8 @@ static void gve_setup_rx_buffer(struct gve_rx_ring *rx, page_info->buf_size = rx->packet_buffer_size; *slot_addr =cpu_to_be64 (addr);/* The page already has 1 ref */ -page_ref_add (page,INT_MAX -1 ); - page_info->pagecnt_bias =INT_MAX ; +page_ref_add (page,GVE_PAGECNT_BIAS -1 ); + page_info->pagecnt_bias =GVE_PAGECNT_BIAS ; } static int gve_rx_alloc_buffer(struct gve_priv *priv, struct device *dev,@@ -230,8 +230,8 @@ static int gve_rx_prefill_pages(struct gve_rx_ring *rx, rx->qpl_copy_pool[j].buf_size = rx->packet_buffer_size;/* The page already has 1 ref. */ -page_ref_add (page,INT_MAX -1 ); - rx->qpl_copy_pool[j].pagecnt_bias =INT_MAX ; +page_ref_add (page,GVE_PAGECNT_BIAS -1 ); + rx->qpl_copy_pool[j].pagecnt_bias =GVE_PAGECNT_BIAS ; } }drivers/net/ethernet/google/gve/gve_utils.c +3
-9@@ -93,15 +93,9 @@ void gve_dec_pagecnt_bias(struct gve_rx_slot_page_info *page_info) { page_info->pagecnt_bias--;if (page_info->pagecnt_bias ==0 ) { -int pagecount =page_count (page_info->page); - -/* If we have run out of bias - set it back up to INT_MAX -* minus the existing refs. -*/ - page_info->pagecnt_bias =INT_MAX - pagecount; - -/* Set pagecount back up to max. */ -page_ref_add (page_info->page,INT_MAX - pagecount); +/* Out of bias: take another batch of references. */ + page_info->pagecnt_bias =GVE_PAGECNT_BIAS ; +page_ref_add (page_info->page,GVE_PAGECNT_BIAS ); } }drivers/net/ethernet/google/gve/gve_utils.h +0
-0
drivers/net/ethernet/google/gve/gve_utils.h struct sk_buff *gve_rx_copy_data(struct net_device *dev, struct napi_struct *nap · line 32
Quoted 9 lines
drivers/net/ethernet/google/gve/gve_utils.h +5
-1@@ -25,7 +25,13 @@ struct sk_buff *gve_rx_copy_data(struct net_device *dev, struct napi_struct *napstruct sk_buff *gve_rx_copy (struct net_device *dev,struct napi_struct *napi,struct gve_rx_slot_page_info *page_info,u16 len); -/* Decrement pagecnt_bias. Set it back to INT_MAX if it reached zero. */ +/* Up-front references gve holds on an RX page, so handing a buffer to the +* stack is a pagecnt_bias decrement, not a get_page(). Keep it in a u16 so +* the 32-bit page refcount keeps the headroom every page needs below INT_MAX. +*/ +#define GVE_PAGECNT_BIAS USHRT_MAX
IMHO code would be more readable with plain USHRT_MAX usage then you know immediately what value is being used. Other drivers do so at least.
Quoted 11 lines
drivers/net/ethernet/google/gve/gve_utils.h +2
-0+ +/* Decrement pagecnt_bias. Top it up by GVE_PAGECNT_BIAS 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,base-commit:
21f57ec673a1917547c808cfa81890485fffa03bSignature · 1 line
2.47.3
Quoted 8 lines · Maciej Fijalkowski
Quoted 5 lines · Amaan Cheval
gve's GQI and DQO-QPL RX paths set every RX page's refcount to
INT_MAXand hand references to the stack by decrementingpage_info->pagecnt_bias, to avoid an atomic op per packet. This leaves the page no headroom: while a fresh page's buffer sits in an skb its refcount is alreadyINT_MAX, so a singleget_page()from the stack wraps it negative.
Quoted 4 lines
Hi Amaan,
by headroom you mean here the space for additional refcount bumps? A bit confusing as my head tends to correlate 'headroom' with packet layout ;)
Yes, that's what I meant.
However, my head is inclined to agree with your head, thanks for the catch! I'll reword it as "fix RX page refcount overflow from the pagecnt bias" in v4.
Quoted 168 lines
one minor comment below.
Quoted 152 lines
splice()of received TCP data into a pipe takes such a reference, and the onward splice into a socket then fails:skb_splice_from_iter()seespage_count()< 1,sendpage_ok()fails and the send returns-EIO(since commit2e910b95329c("net: Add a function to splice pages into an skbuff forMSG_SPLICE_PAGES")).tee()of the pipe fails with-EFAULTviatry_get_page(). On GQI the reuse checkgve_rx_can_recycle_buffer()also seespage_count()<pagecnt_bias, WARNs and callsgve_schedule_reset(), so a task that merely pins a fresh RX page (e.g. holds spliced data in an undrainedtee()pipe) can reset the NIC.Use
USHRT_MAXin a u16, as igb, igc, ixgbe, i40e and hns3 do: the bias only has to make the per-packet atomic rare, so a small value leavespage_count()ample headroom belowINT_MAXfor the stack's references. Refill by adding a fixed batch and setting the bias to it, which keeps the rulereferences = page_count() - biasintact.Reproduced on gVNIC in GQI-QPL mode (GCE n2-standard-8, 6.12) and in DQO-RDA mode (GCE c3-standard-8, 6.12, where DQO-RDA still uses the bias) with the help of
relay.py-- a small splice(2) TCP proxy -- relaying a download while the RX ring is refilled with fresh pages:ethtool -G eth0 rx 512 && ethtool -G eth0 rx 1024 # fresh RX pages ./relay.py $HOST 8080 & # splice()s both ways for i in $(seq 200); do curl -so /dev/null \ --connect-to $HOST:80:127.0.0.1:8080 http://$HOST/file; doneMost downloads failed with EIO before the fix (
tee()with EFAULT) and all completed after it.relay.pyis at the Link below.This bug was found and fixed with the help of an AI coding assistant (Claude Code) over an interactive session; it read the driver and splice/pipe code and ran the tests above.
Fixes 9b8dd5e5ea48 ("gve: DQO: Add RX path")Fixes 58401b2a46e7 ("gve: Add rx buffer pagecnt bias")Fixes 82fd151d38d9 ("gve: Reduce alloc and copy costs in the GQ rx path")Reviewed-by Harshitha Ramamurthy <[email protected]>Tested-by Harshitha Ramamurthy <[email protected]>Signed-off-by Amaan Cheval <[email protected]>---
v3:
- Refill when the bias reaches 0 again, as in v1. DQO-QPL is not supposed to support XDP at all, and it will be blocked explicitly in a separate patch, so the v2 refill-at-1 change is not needed.
- Added Reviewed-by and Tested-by from Harshitha Ramamurthy.
v2: https://lore.kernel.org/netdev/[email protected]/
- Refill when the bias reaches 1 instead of 0 so the driver keeps a reference of its own across every handoff. At bias 0 a consumer that returns its reference synchronously, such as anAF_XDPsocket in copy mode on anXDP_REDIRECTfrom DQO-QPL, freed a page still registered in the QPL.
- Commit message: explain the refill point, drop the build notes.
- Re-tested on 6.12.113 (c3-standard-8, DQO-RDA, which still uses the bias on 6.12): no EIO/EFAULT from splice/tee and no NIC reset after applying the patch. DQO-QPL is untested; I have no access to that hardware.
v1: https://lore.kernel.org/netdev/[email protected]/Built allmodconfig W=1, no new warnings.
drivers/net/ethernet/google/gve/gve.h | 2 +- .../net/ethernet/google/gve/gve_buffer_mgmt_dqo.c | 4 ++-- drivers/net/ethernet/google/gve/gve_rx.c | 8 ++++---- drivers/net/ethernet/google/gve/gve_utils.c | 12 +++--------- drivers/net/ethernet/google/gve/gve_utils.h | 8 +++++++- 5 files changed, 17 insertions(+), 17 deletions(-)drivers/net/ethernet/google/gve/gve.h +1
-1@@ -119,7 +119,7 @@ struct gve_rx_slot_page_info {void *page_address;u32 page_offset;/* offset to write to in page */ unsigned int buf_size; -int pagecnt_bias;/* expected pagecnt if only the driver has a ref */ +u16 pagecnt_bias;/* expected pagecnt if only the driver has a ref */ u16 pad;/* adjustment for rx padding */ u8 can_flip;/* tracks if the networking stack is using the page */ };drivers/net/ethernet/google/gve/gve_buffer_mgmt_dqo.c +2
-2@@ -149,8 +149,8 @@ int gve_alloc_qpl_page_dqo(struct gve_rx_ring *rx, buf_state->last_single_ref_offset =0 ;/* The page already has 1 ref. */ -page_ref_add (buf_state->page_info.page,INT_MAX -1 ); - buf_state->page_info.pagecnt_bias =INT_MAX ; +page_ref_add (buf_state->page_info.page,GVE_PAGECNT_BIAS -1 ); + buf_state->page_info.pagecnt_bias =GVE_PAGECNT_BIAS ;return 0 ; }drivers/net/ethernet/google/gve/gve_rx.c +4
-4@@ -152,8 +152,8 @@ static void gve_setup_rx_buffer(struct gve_rx_ring *rx, page_info->buf_size = rx->packet_buffer_size; *slot_addr =cpu_to_be64 (addr);/* The page already has 1 ref */ -page_ref_add (page,INT_MAX -1 ); - page_info->pagecnt_bias =INT_MAX ; +page_ref_add (page,GVE_PAGECNT_BIAS -1 ); + page_info->pagecnt_bias =GVE_PAGECNT_BIAS ; } static int gve_rx_alloc_buffer(struct gve_priv *priv, struct device *dev,@@ -230,8 +230,8 @@ static int gve_rx_prefill_pages(struct gve_rx_ring *rx, rx->qpl_copy_pool[j].buf_size = rx->packet_buffer_size;/* The page already has 1 ref. */ -page_ref_add (page,INT_MAX -1 ); - rx->qpl_copy_pool[j].pagecnt_bias =INT_MAX ; +page_ref_add (page,GVE_PAGECNT_BIAS -1 ); + rx->qpl_copy_pool[j].pagecnt_bias =GVE_PAGECNT_BIAS ; } }drivers/net/ethernet/google/gve/gve_utils.c +3
-9@@ -93,15 +93,9 @@ void gve_dec_pagecnt_bias(struct gve_rx_slot_page_info *page_info) { page_info->pagecnt_bias--;if (page_info->pagecnt_bias ==0 ) { -int pagecount =page_count (page_info->page); - -/* If we have run out of bias - set it back up to INT_MAX -* minus the existing refs. -*/ - page_info->pagecnt_bias =INT_MAX - pagecount; - -/* Set pagecount back up to max. */ -page_ref_add (page_info->page,INT_MAX - pagecount); +/* Out of bias: take another batch of references. */ + page_info->pagecnt_bias =GVE_PAGECNT_BIAS ; +page_ref_add (page_info->page,GVE_PAGECNT_BIAS ); } }drivers/net/ethernet/google/gve/gve_utils.h +0
-0drivers/net/ethernet/google/gve/gve_utils.h struct sk_buff *gve_rx_copy_data(struct net_device *dev, struct napi_struct *nap · line 32
Quoted 9 lines
drivers/net/ethernet/google/gve/gve_utils.h +5
-1@@ -25,7 +25,13 @@ struct sk_buff *gve_rx_copy_data(struct net_device *dev, struct napi_struct *napstruct sk_buff *gve_rx_copy (struct net_device *dev,struct napi_struct *napi,struct gve_rx_slot_page_info *page_info,u16 len); -/* Decrement pagecnt_bias. Set it back to INT_MAX if it reached zero. */ +/* Up-front references gve holds on an RX page, so handing a buffer to the +* stack is a pagecnt_bias decrement, not a get_page(). Keep it in a u16 so +* the 32-bit page refcount keeps the headroom every page needs below INT_MAX. +*/ +#define GVE_PAGECNT_BIAS USHRT_MAXIMHO code would be more readable with plain
USHRT_MAXusage then you know immediately what value is being used. Other drivers do so at least.
Quoted 1 line
Reviewed-by Maciej Fijalkowski <[email protected]>
Makes sense, I'll use USHRT_MAX directly in v4.
Thanks for the review and tag!
Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/google/gve/gve_utils.h +2
-0+ +/* Decrement pagecnt_bias. Top it up by GVE_PAGECNT_BIAS 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,base-commit:
21f57ec673a1917547c808cfa81890485fffa03b--
2.47.3
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 1 · High: 0 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Critical] This patch refills the bias only after gve_dec_pagecnt_bias() reaches 0, and it lowers the per-page bias from…
--
gve: leave refcount headroom in the RX page bias
This patch lowers the gve RX page refcount bias from INT_MAX to USHRT_MAX and stores it in a u16. This leaves page_count() room for references the stack takes with get_page(), such as splice() and tee(). When the bias reaches 0, it is refilled with a fixed batch of GVE_PAGECNT_BIAS.
Quoted 12 lines
drivers/net/ethernet/google/gve/gve_utils.c +0
-4@@ -93,15 +93,9 @@ void gve_dec_pagecnt_bias(struct gve_rx_slot_page_info *page_info) { page_info->pagecnt_bias--;if (page_info->pagecnt_bias ==0 ) { -int pagecount =page_count (page_info->page); - -/* If we have run out of bias - set it back up to INT_MAX -* minus the existing refs.
drivers/net/ethernet/google/gve/gve_utils.c void gve_dec_pagecnt_bias(struct gve_rx_slot_page_info *page_info) · line 100
Quoted 10 lines
drivers/net/ethernet/google/gve/gve_utils.c +3
-5-*/ - page_info->pagecnt_bias =INT_MAX - pagecount; - -/* Set pagecount back up to max. */ -page_ref_add (page_info->page,INT_MAX - pagecount); +/* Out of bias: take another batch of references. */ + page_info->pagecnt_bias =GVE_PAGECNT_BIAS ; +page_ref_add (page_info->page,GVE_PAGECNT_BIAS ); } }
[Severity: Critical]
Can this free a DQO-QPL RX page that is still registered with the device?
Because the refill happens only at 0, the 1 -> 0 transition hands the driver's last reference to the consumer. With INT_MAX a page needed about 2^31 handoffs to get there. With GVE_PAGECNT_BIAS it happens every 65534 handoffs.
On DQO-QPL, gve_xdp_done_dqo() redirects the buffer before it touches the bias:
case XDP_REDIRECT: err = xdp_do_redirect(priv->dev, xdp, xprog); if (unlikely(err)) goto err; gve_reuse_buffer(rx, buf_state);
gve_reg_xdp_info() registers QPL rings as MEM_TYPE_PAGE_SHARED. If the redirect target is an AF_XDP socket in copy mode, the page is released synchronously:
xdp_do_redirect()
xsk_rcv()
xdp_return_buff()
__xdp_return()
page_frag_free()
put_page_testzero()
free_frozen_pages()Suppose the page is at pagecnt_bias == 1 and page_count == 1. That is the normal recyclable state once all earlier consumers have released their references. The QPL page then goes back to the buddy allocator while it is still DMA mapped, registered in the QPL and owned by the buf_state.
After that, gve_reuse_buffer()->gve_dec_pagecnt_bias() calls page_ref_add(page, GVE_PAGECNT_BIAS) on the freed page. gve_try_recycle_buf() then sees page_count - bias == 0 and posts the page back to the NIC. Could the device then DMA packet data into memory that has already been handed to another user?
The v3 notes say XDP on DQO-QPL "will be blocked explicitly in a separate patch". In this tree, gve_xdp(), gve_verify_xdp_configuration() and gve_set_xdp() do not check queue_format.
gve_set_netdev_xdp_features() sets xdp_features = 0 for DQO-QPL, but nothing on the attach path enforces it. xp_assign_dev() also falls back to copy mode when NETDEV_XDP_ACT_XSK is missing.
That note is below the --- line, so it will not be in the applied commit. The patch is also tagged for stable without naming the prerequisite.
The commit message also says:
Use USHRT_MAX in a u16, as igb, igc, ixgbe, i40e and hns3 do
Those drivers refill at bias == 1, so they always keep a reference. For example, igb_can_reuse_rx_page() does:
if (unlikely(pagecnt_bias == 1)) {
page_ref_add(page, USHRT_MAX - 1);
rx_buffer->pagecnt_bias = USHRT_MAX;
}Would it be safer to refill at 1 here, as v2 did, so the driver never gives up its last reference on a QPL page?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261103090651.35399-1-amaan.cheval%40gmail.com
Quoted 108 lines · On Thu, Nov 5, 2026 at 2:39 AM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 1 · High: 0 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Critical] This patch refills the bias only after
gve_dec_pagecnt_bias()reaches 0, and it lowers the per-page bias from…--
gve: leave refcount headroom in the RX page bias
This patch lowers the gve RX page refcount bias from
INT_MAXtoUSHRT_MAXand stores it in a u16. This leavespage_count()room for references the stack takes withget_page(), such assplice()andtee(). When the bias reaches 0, it is refilled with a fixed batch ofGVE_PAGECNT_BIAS.Quoted 12 lines
drivers/net/ethernet/google/gve/gve_utils.c +0
-4@@ -93,15 +93,9 @@ void gve_dec_pagecnt_bias(struct gve_rx_slot_page_info *page_info) { page_info->pagecnt_bias--;if (page_info->pagecnt_bias ==0 ) { -int pagecount =page_count (page_info->page); - -/* If we have run out of bias - set it back up to INT_MAX -* minus the existing refs. drivers/net/ethernet/google/gve/gve_utils.c void gve_dec_pagecnt_bias(struct gve_rx_slot_page_info *page_info) · line 100
Quoted 10 lines
drivers/net/ethernet/google/gve/gve_utils.c +3
-5-*/ - page_info->pagecnt_bias =INT_MAX - pagecount; - -/* Set pagecount back up to max. */ -page_ref_add (page_info->page,INT_MAX - pagecount); +/* Out of bias: take another batch of references. */ + page_info->pagecnt_bias =GVE_PAGECNT_BIAS ; +page_ref_add (page_info->page,GVE_PAGECNT_BIAS ); } }[Severity: Critical]
Can this free a DQO-QPL RX page that is still registered with the device?
Because the refill happens only at 0, the 1 -> 0 transition hands the driver's last reference to the consumer. With
INT_MAXa page needed about 2^31 handoffs to get there. WithGVE_PAGECNT_BIASit happens every 65534 handoffs.On DQO-QPL,
gve_xdp_done_dqo()redirects the buffer before it touches the bias:case XDP_REDIRECT: err = xdp_do_redirect(priv->dev, xdp, xprog); if (unlikely(err)) goto err; gve_reuse_buffer(rx, buf_state);
gve_reg_xdp_info()registers QPL rings asMEM_TYPE_PAGE_SHARED. If the redirect target is anAF_XDPsocket in copy mode, the page is released synchronously:
xdp_do_redirect()
xsk_rcv()xdp_return_buff() __xdp_return() page_frag_free() put_page_testzero() free_frozen_pages()Suppose the page is at
pagecnt_bias== 1 andpage_count== 1. That is the normal recyclable state once all earlier consumers have released their references. The QPL page then goes back to the buddy allocator while it is still DMA mapped, registered in the QPL and owned by thebuf_state.After that, gve_reuse_buffer()->gve_dec_pagecnt_bias() calls
page_ref_add(page, GVE_PAGECNT_BIAS)on the freed page.gve_try_recycle_buf()then seespage_count- bias == 0 and posts the page back to the NIC. Could the device then DMA packet data into memory that has already been handed to another user?The v3 notes say XDP on DQO-QPL "will be blocked explicitly in a separate patch". In this tree,
gve_xdp(),gve_verify_xdp_configuration()andgve_set_xdp()do not checkqueue_format.
gve_set_netdev_xdp_features()setsxdp_features= 0 for DQO-QPL, but nothing on the attach path enforces it.xp_assign_dev()also falls back to copy mode whenNETDEV_XDP_ACT_XSKis missing.That note is below the --- line, so it will not be in the applied commit. The patch is also tagged for stable without naming the prerequisite.
The commit message also says:
Use
USHRT_MAXin a u16, as igb, igc, ixgbe, i40e and hns3 doThose drivers refill at bias == 1, so they always keep a reference. For example,
igb_can_reuse_rx_page()does:
Quoted 7 lines
if (unlikely(pagecnt_bias == 1)) { page_ref_add(page, USHRT_MAX - 1); rx_buffer->pagecnt_bias = USHRT_MAX; }Would it be safer to refill at 1 here, as v2 did, so the driver never gives up its last reference on a QPL page?
The scenario is real, but it is reachable only because XDP can be attached on DQO-QPL at all, which the driver does not support:
commit d8a8ca14c937 ("gve: add XDP_TX and XDP_REDIRECT support for DQ RDA") dropped the queue_format check that used to refuse it, and the core only checks that ndo_bpf exists. Harshitha indicated on v2 that the right fix is to block XDP on DQO-QPL rather than to change the refill point.
Harshitha, I know you mentioned Google would send that patch:
https://lore.kernel.org/netdev/CAEAWyHfCM_ZesnChP71AQvxjM4MASwukesgzuWCYECts7jiNhA@mail.gmail.com/
Since this fix depends on it, I'd like to post v4 as a two-patch series with the DQO-QPL block as 1/2, so that the fix and its prerequisite reach stable together. If you already have one in flight, or would rather send your own, please let me know and I'll drop 1/2 and rebase on yours instead.
pw-bot: cr
Quoted 3 lines
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261103090651.35399-1-amaan.cheval%40gmail.com