Skip to content

Commit 9c6e6a8

Browse files
lic121anakryiko
authored andcommitted
libbpf: Unmap rings when umem deleted
xsk_umem__create() does mmap for fill/comp rings, but xsk_umem__delete() doesn't do the unmap. This works fine for regular cases, because xsk_socket__delete() does unmap for the rings. But for the case that xsk_socket__create_shared() fails, umem rings are not unmapped. fill_save/comp_save are checked to determine if rings have already be unmapped by xsk. If fill_save and comp_save are NULL, it means that the rings have already been used by xsk. Then they are supposed to be unmapped by xsk_socket__delete(). Otherwise, xsk_umem__delete() does the unmap. Fixes: 2f6324a ("libbpf: Support shared umems between queues and devices") Signed-off-by: Cheng Li <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]~
1 parent c344b9f commit 9c6e6a8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tools/lib/bpf/xsk.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,12 +1193,23 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname,
11931193

11941194
int xsk_umem__delete(struct xsk_umem *umem)
11951195
{
1196+
struct xdp_mmap_offsets off;
1197+
int err;
1198+
11961199
if (!umem)
11971200
return 0;
11981201

11991202
if (umem->refcount)
12001203
return -EBUSY;
12011204

1205+
err = xsk_get_mmap_offsets(umem->fd, &off);
1206+
if (!err && umem->fill_save && umem->comp_save) {
1207+
munmap(umem->fill_save->ring - off.fr.desc,
1208+
off.fr.desc + umem->config.fill_size * sizeof(__u64));
1209+
munmap(umem->comp_save->ring - off.cr.desc,
1210+
off.cr.desc + umem->config.comp_size * sizeof(__u64));
1211+
}
1212+
12021213
close(umem->fd);
12031214
free(umem);
12041215

0 commit comments

Comments
 (0)