[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAEf4BzYm=3Awdz2H32JC6bB4anCY40=+_LWF6E57CbR8a9TFxg@mail.gmail.com>
Date: Mon, 7 Mar 2022 22:03:09 -0800
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: lic121 <lic121@...natelecom.cn>
Cc: bpf <bpf@...r.kernel.org>,
Björn Töpel <bjorn@...nel.org>,
Magnus Karlsson <magnus.karlsson@...el.com>,
Jonathan Lemon <jonathan.lemon@...il.com>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Jesper Dangaard Brouer <hawk@...nel.org>,
Networking <netdev@...r.kernel.org>,
open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH bpf] libbpf: unmap rings when umem deleted
On Tue, Mar 1, 2022 at 5:26 AM lic121 <lic121@...natelecom.cn> wrote:
>
> 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: 2f6324a3937f ("libbpf: Support shared umems between queues and devices")
> Signed-off-by: lic121 <lic121@...natelecom.cn>
> ---
Applied to bpf-next as well. Changed the name to Cheng Li while
applying. Thanks.
> tools/lib/bpf/xsk.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
> index edafe56..32a2f57 100644
> --- a/tools/lib/bpf/xsk.c
> +++ b/tools/lib/bpf/xsk.c
> @@ -1193,12 +1193,23 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname,
>
> int xsk_umem__delete(struct xsk_umem *umem)
> {
> + struct xdp_mmap_offsets off;
> + int err;
> +
> if (!umem)
> return 0;
>
> if (umem->refcount)
> return -EBUSY;
>
> + err = xsk_get_mmap_offsets(umem->fd, &off);
> + if (!err && umem->fill_save && umem->comp_save) {
> + munmap(umem->fill_save->ring - off.fr.desc,
> + off.fr.desc + umem->config.fill_size * sizeof(__u64));
> + munmap(umem->comp_save->ring - off.cr.desc,
> + off.cr.desc + umem->config.comp_size * sizeof(__u64));
> + }
> +
> close(umem->fd);
> free(umem);
>
> --
> 1.8.3.1
>
Powered by blists - more mailing lists