skb frags are either page_pool pages tracked via pp_ref_count
(released by napi_pp_put_page()), or regular pages tracked via
_refcount (released by put_netmem()).
skb->pp_recycle was unbalanced and caused the underflow that
hit BUG().
Fix by taking the page_pool reference only when the destination has
pp_recycle set and the fragment's page is actually page_pool owned,
matching skb_pp_frag_ref(); fall back to a plain reference otherwise.
See the kernel splat, before. Observed under normal traffic when a page_pool
frag is shared into two extra skbs
[ 52.644633] ------------[ cut here ]------------
[ 52.644649] WARNING: ./include/net/page_pool/helpers.h:297 at page_pool_put_netmem.constprop.0+0x1f/0x40, CPU#0: swapper/0/0
[ 52.644665] CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted 7.3.0-rc2-00485-gcda8dccdef8d #19 PREEMPT(full)
[ 52.644669] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
[ 52.644672] RIP: 0010:page_pool_put_netmem.constprop.0+0x1f/0x40
[ 52.644676] Code: 90 90 90 90 90 90 90 90 90 90 90 48 89 f0 48 83 e0 fe 48 8b 48 28 48 ff c9 74 20 48 83 c9 ff f0 48 0f c1 48 28 48 ff c9 79 07 <0f> 0b c3 cc cc cc cc 75 13 48 c7 40 28 01 00 00 00 0f b6 ca 83 ca
[ 52.644679] RSP: 0018:ffffc90000003c98 EFLAGS: 00010296
[ 52.644683] RAX: ffffea00041cc200 RBX: ffff888105335100 RCX: ffffffffffffffff
[ 52.644686] RDX: 0000000000000001 RSI: ffffea00041cc200 RDI: ffff8881013fa000
[ 52.644688] RBP: 000000000000000c R08: 000000000000005e R09: 0000000000000a00
[ 52.644690] R10: ffff888106834fc0 R11: 0000000000000020 R12: 0000000000000000
[ 52.644692] R13: ffff8881013fb000 R14: ffffea00041cc200 R15: ffff88810097d9c0
[ 52.644698] FS: 0000000000000000(0000) GS:ffff8881f887c000(0000) knlGS:0000000000000000
[ 52.644701] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 52.644703] CR2: 00007fd8753ec180 CR3: 0000000106f2e004 CR4: 0000000000170eb0
[ 52.644706] Call Trace:
[ 52.644710]
[ 52.644712] page_to_skb+0x1f3/0x210
[ 52.644719] receive_buf+0x712/0xca0
[ 52.644724] ? detach_buf_split_in_order+0x5d/0x110
[ 52.644730] virtnet_poll+0x1da/0x460
[ 52.644736] __napi_poll.constprop.0+0x2a/0x120
[ 52.644745] net_rx_action+0x11a/0x230
[ 52.644748] ? raise_softirq_irqoff+0x5/0x20
[ 52.644754] ? __napi_schedule+0x31/0x50
[ 52.644759] ? vring_interrupt+0x77/0x90
[ 52.644765] handle_softirqs+0x11e/0x270
[ 52.644769] __irq_exit_rcu+0x53/0xf0
[ 52.644773] common_interrupt+0x95/0xc0
[ 52.644782]
[ 52.644784]
[ 52.644786] asm_common_interrupt+0x22/0x40
[ 52.644790] RIP: 0010:default_idle+0xb/0x20
[ 52.644794] Code: 00 4d 29 c8 4c 01 c7 4c 29 c2 e9 6e ff ff ff 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 eb 07 0f 00 2d 1d c6 01 00 fb f4 c3 cc cc cc cc 66 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 90
[ 52.644797] RSP: 0018:ffffffff82a03e08 EFLAGS: 00000212
[ 52.644800] RAX: 0000000000000000 RBX: ffffffff82a0b480 RCX: 00000000ffff0e38
[ 52.644802] RDX: 0000000000000000 RSI: ffffffff82211089 RDI: 00000000000ec84c
[ 52.644804] RBP: 0000000000000000 R08: 0000000000000002 R09: 0000000000000000
[ 52.644806] R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
[ 52.644808] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000013ab0
[ 52.644814] default_idle_call+0x3c/0x70
[ 52.644818] do_idle+0xdc/0x200
[ 52.644823] cpu_startup_entry+0x29/0x30
[ 52.644828] rest_init+0xe8/0xf0
[ 52.644833] ? __pfx_kernel_init+0x10/0x10
[ 52.644836] start_kernel+0x5fd/0x600
[ 52.644846] x86_64_start_reservations+0x20/0x20
[ 52.644850] x86_64_start_kernel+0xc9/0xd0
[ 52.644854] common_startup_64+0x129/0x148
[ 52.644860]
[ 52.644862] ---[ end trace 0000000000000000 ]---
Fixes: 5f2b6a909574 ("xfrm: iptfs: add skb-fragment sharing code")
Fixes: b96ba312e21c ("xfrm: iptfs: share page fragments of inner packets")
Signed-off-by: Antony Antony
---
v2->v3: check page is pp before pp_ref_count bump. create helper func
- Link to v2: https://patchwork.kernel.org/project/netdevbpf/patch/xfrm-iptfs-pp_ref_count-underflow-v1-1-5fb363833d41@secunet.com/
v1->v2: rebase to latest ipsec
- Link to v1: https://lore.kernel.org/all/xfrm-iptfs-pp_ref_count-underflow-v1-1-47b319c6d2f6@secunet.com/
---
net/xfrm/xfrm_iptfs.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c
index 6920940a35b4..229f84ac6a31 100644
--- a/net/xfrm/xfrm_iptfs.c
+++ b/net/xfrm/xfrm_iptfs.c
@@ -14,6 +14,7 @@
#include
#include
#include
+#include
#include
#include
@@ -449,6 +450,20 @@ static bool iptfs_skb_can_add_frags(const struct sk_buff *skb,
return true;
}
+static void iptfs_frag_ref(skb_frag_t *frag, bool recycle)
+{
+ struct page *head;
+
+ if (recycle && !skb_frag_is_net_iov(frag)) {
+ head = compound_head(skb_frag_page(frag));
+ if (page_pool_page_is_pp(head)) {
+ page_pool_ref_page(head);
+ return;
+ }
+ }
+ __skb_frag_ref(frag);
+}
+
/**
* iptfs_skb_add_frags() - add a range of fragment references into an skb
* @skb: skb to add references into
@@ -486,7 +501,7 @@ static int iptfs_skb_add_frags(struct sk_buff *skb,
tofrag->len -= offset;
offset = 0;
}
- __skb_frag_ref(tofrag);
+ iptfs_frag_ref(tofrag, skb->pp_recycle);
shinfo->nr_frags++;
shinfo->flags |= SKBFL_SHARED_FRAG;
@@ -2171,7 +2186,8 @@ static void iptfs_consume_frags(struct sk_buff *to, struct sk_buff *from)
new_truesize = SKB_TRUESIZE(skb_end_offset(from));
} else {
iptfs_skb_head_to_frag(from, &toi->frags[toi->nr_frags]);
- skb_frag_ref(to, toi->nr_frags++);
+ iptfs_frag_ref(&toi->frags[toi->nr_frags], to->pp_recycle);
+ toi->nr_frags++;
new_truesize = SKB_DATA_ALIGN(sizeof(struct sk_buff));
}
---
base-commit: 868f63c8bfafa9b827168c9126f85264c39c02ec
change-id: xfrm-iptfs-pp_ref_count-underflow-063ee0302600
Best regards,
--
Antony Antony