[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAF=yD-L22CzLshK0K53TDTK7bhhHfpnrncznTZHCa4YtPo3gGw@mail.gmail.com>
Date: Wed, 7 Feb 2018 11:00:17 -0500
From: Willem de Bruijn <willemdebruijn.kernel@...il.com>
To: Björn Töpel <bjorn.topel@...il.com>
Cc: "Karlsson, Magnus" <magnus.karlsson@...el.com>,
Alexander Duyck <alexander.h.duyck@...el.com>,
Alexander Duyck <alexander.duyck@...il.com>,
John Fastabend <john.fastabend@...il.com>,
Alexei Starovoitov <ast@...com>,
Jesper Dangaard Brouer <brouer@...hat.com>,
Daniel Borkmann <daniel@...earbox.net>,
Network Development <netdev@...r.kernel.org>,
Björn Töpel <bjorn.topel@...el.com>,
michael.lundkvist@...csson.com,
"Brandeburg, Jesse" <jesse.brandeburg@...el.com>,
"Singhai, Anjali" <anjali.singhai@...el.com>,
"Shaw, Jeffrey B" <jeffrey.b.shaw@...el.com>,
"Yigit, Ferruh" <ferruh.yigit@...el.com>,
"Zhang, Qi Z" <qi.z.zhang@...el.com>
Subject: Re: [RFC PATCH 02/24] xsk: add user memory registration sockopt
On Wed, Jan 31, 2018 at 8:53 AM, Björn Töpel <bjorn.topel@...il.com> wrote:
> From: Björn Töpel <bjorn.topel@...el.com>
>
> The XDP_MEM_REG socket option allows a process to register a window of
> user space memory to the kernel. This memory will later be used as
> frame data buffer.
>
> Signed-off-by: Björn Töpel <bjorn.topel@...el.com>
> ---
> +static struct xsk_umem *xsk_mem_reg(u64 addr, u64 size, u32 frame_size,
> + u32 data_headroom)
> +{
> + unsigned long lock_limit, locked, npages;
> + int ret = 0;
> + struct xsk_umem *umem;
> +
> + if (!can_do_mlock())
> + return ERR_PTR(-EPERM);
> +
> + umem = xsk_umem_create(addr, size, frame_size, data_headroom);
> + if (IS_ERR(umem))
> + return umem;
> +
> + npages = PAGE_ALIGN(umem->nframes * umem->frame_size) >> PAGE_SHIFT;
> +
> + down_write(¤t->mm->mmap_sem);
> +
> + locked = npages + current->mm->pinned_vm;
> + lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
> +
> + if (locked > lock_limit && !capable(CAP_IPC_LOCK)) {
> + ret = -ENOMEM;
> + goto out;
> + }
> +
> + if (npages == 0 || npages > UINT_MAX) {
> + ret = -EINVAL;
> + goto out;
> + }
> + umem->npgs = npages;
> +
> + ret = xsk_umem_pin_pages(umem);
> +
> +out:
> + if (ret < 0) {
> + put_pid(umem->pid);
> + kfree(umem);
> + } else {
> + current->mm->pinned_vm = locked;
> + }
> +
> + up_write(¤t->mm->mmap_sem);
This limits per process. You may want to limit per user. See also
mm_account_pinned_pages.
Powered by blists - more mailing lists