Skip to content

Commit 425d239

Browse files
tohojoborkmann
authored andcommitted
bpf: Fix release of page_pool in BPF_PROG_RUN in test runner
The live packet mode in BPF_PROG_RUN allocates a page_pool instance for each test run instance and uses it for the packet data. On setup it creates the page_pool, and calls xdp_reg_mem_model() to allow pages to be returned properly from the XDP data path. However, xdp_reg_mem_model() also raises the reference count of the page_pool itself, so the single page_pool_destroy() count on teardown was not enough to actually release the pool. To fix this, add an additional xdp_unreg_mem_model() call on teardown. Fixes: b530e9e ("bpf: Add "live packet" mode for XDP in BPF_PROG_RUN") Reported-by: Freysteinn Alfredsson <[email protected]> Signed-off-by: Toke Høiland-Jørgensen <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Song Liu <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 8de8b71 commit 425d239

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

net/bpf/test_run.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ struct xdp_test_data {
108108
struct page_pool *pp;
109109
struct xdp_frame **frames;
110110
struct sk_buff **skbs;
111+
struct xdp_mem_info mem;
111112
u32 batch_size;
112113
u32 frame_cnt;
113114
};
@@ -147,7 +148,6 @@ static void xdp_test_run_init_page(struct page *page, void *arg)
147148

148149
static int xdp_test_run_setup(struct xdp_test_data *xdp, struct xdp_buff *orig_ctx)
149150
{
150-
struct xdp_mem_info mem = {};
151151
struct page_pool *pp;
152152
int err = -ENOMEM;
153153
struct page_pool_params pp_params = {
@@ -174,7 +174,7 @@ static int xdp_test_run_setup(struct xdp_test_data *xdp, struct xdp_buff *orig_c
174174
}
175175

176176
/* will copy 'mem.id' into pp->xdp_mem_id */
177-
err = xdp_reg_mem_model(&mem, MEM_TYPE_PAGE_POOL, pp);
177+
err = xdp_reg_mem_model(&xdp->mem, MEM_TYPE_PAGE_POOL, pp);
178178
if (err)
179179
goto err_mmodel;
180180

@@ -202,6 +202,7 @@ static int xdp_test_run_setup(struct xdp_test_data *xdp, struct xdp_buff *orig_c
202202

203203
static void xdp_test_run_teardown(struct xdp_test_data *xdp)
204204
{
205+
xdp_unreg_mem_model(&xdp->mem);
205206
page_pool_destroy(xdp->pp);
206207
kfree(xdp->frames);
207208
kfree(xdp->skbs);

0 commit comments

Comments
 (0)