netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] xsk: support use vaddr as ring
@ 2023-02-09  9:24 Xuan Zhuo
  2023-02-09 11:06 ` kernel test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Xuan Zhuo @ 2023-02-09  9:24 UTC (permalink / raw)
  To: netdev
  Cc: Björn Töpel, Magnus Karlsson, Maciej Fijalkowski,
	Jonathan Lemon, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, bpf

When we try to start AF_XDP on some machines with long running time, due
to the machine's memory fragmentation problem, there is no sufficient
continuous physical memory that will cause the start failure.

After AF_XDP fails to apply for continuous physical memory, this patch
tries to use vmalloc() to allocate memory to solve this problem.

Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
 net/xdp/xsk.c       |  8 +++++---
 net/xdp/xsk_queue.c | 20 ++++++++++++++------
 net/xdp/xsk_queue.h |  1 +
 3 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 9f0561b67c12..33db57548ee3 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -1296,7 +1296,6 @@ static int xsk_mmap(struct file *file, struct socket *sock,
 	struct xdp_sock *xs = xdp_sk(sock->sk);
 	struct xsk_queue *q = NULL;
 	unsigned long pfn;
-	struct page *qpg;
 
 	if (READ_ONCE(xs->state) != XSK_READY)
 		return -EBUSY;
@@ -1319,10 +1318,13 @@ static int xsk_mmap(struct file *file, struct socket *sock,
 
 	/* Matches the smp_wmb() in xsk_init_queue */
 	smp_rmb();
-	qpg = virt_to_head_page(q->ring);
-	if (size > page_size(qpg))
+
+	if (PAGE_ALIGN(q->ring_size) < size)
 		return -EINVAL;
 
+	if (is_vmalloc_addr(q->ring))
+		return remap_vmalloc_range(vma, q->ring, 0);
+
 	pfn = virt_to_phys(q->ring) >> PAGE_SHIFT;
 	return remap_pfn_range(vma, vma->vm_start, pfn,
 			       size, vma->vm_page_prot);
diff --git a/net/xdp/xsk_queue.c b/net/xdp/xsk_queue.c
index 6cf9586e5027..6582d394b7e2 100644
--- a/net/xdp/xsk_queue.c
+++ b/net/xdp/xsk_queue.c
@@ -37,14 +37,18 @@ struct xsk_queue *xskq_create(u32 nentries, bool umem_queue)
 		    __GFP_COMP  | __GFP_NORETRY;
 	size = xskq_get_ring_size(q, umem_queue);
 
+	q->ring_size = size;
 	q->ring = (struct xdp_ring *)__get_free_pages(gfp_flags,
 						      get_order(size));
-	if (!q->ring) {
-		kfree(q);
-		return NULL;
-	}
+	if (q->ring)
+		return q;
+
+	q->ring = vmalloc_user(size);
+	if (q->ring)
+		return q;
 
-	return q;
+	kfree(q);
+	return NULL;
 }
 
 void xskq_destroy(struct xsk_queue *q)
@@ -52,6 +56,10 @@ void xskq_destroy(struct xsk_queue *q)
 	if (!q)
 		return;
 
-	page_frag_free(q->ring);
+	if (is_vmalloc_addr(q->ring))
+		vfree(q->ring);
+	else
+		page_frag_free(q->ring);
+
 	kfree(q);
 }
diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h
index c6fb6b763658..35922b8b92a8 100644
--- a/net/xdp/xsk_queue.h
+++ b/net/xdp/xsk_queue.h
@@ -45,6 +45,7 @@ struct xsk_queue {
 	struct xdp_ring *ring;
 	u64 invalid_descs;
 	u64 queue_empty_descs;
+	size_t ring_size;
 };
 
 /* The structure of the shared state of the rings are a simple
-- 
2.32.0.3.g01195cf9f


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] xsk: support use vaddr as ring
  2023-02-09  9:24 [PATCH net-next] xsk: support use vaddr as ring Xuan Zhuo
@ 2023-02-09 11:06 ` kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2023-02-09 11:06 UTC (permalink / raw)
  To: Xuan Zhuo, netdev
  Cc: oe-kbuild-all, Björn Töpel, Magnus Karlsson,
	Maciej Fijalkowski, Jonathan Lemon, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, bpf

Hi Xuan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Xuan-Zhuo/xsk-support-use-vaddr-as-ring/20230209-172553
patch link:    https://lore.kernel.org/r/20230209092436.87795-1-xuanzhuo%40linux.alibaba.com
patch subject: [PATCH net-next] xsk: support use vaddr as ring
config: mips-allyesconfig (https://download.01.org/0day-ci/archive/20230209/202302091850.0HBmsDAq-lkp@intel.com/config)
compiler: mips-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/4a7734a008a4c9739f0abcc596455e4b76b601ec
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Xuan-Zhuo/xsk-support-use-vaddr-as-ring/20230209-172553
        git checkout 4a7734a008a4c9739f0abcc596455e4b76b601ec
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=mips olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=mips SHELL=/bin/bash net/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202302091850.0HBmsDAq-lkp@intel.com

All warnings (new ones prefixed by >>):

   net/xdp/xsk_queue.c: In function 'xskq_create':
   net/xdp/xsk_queue.c:46:19: error: implicit declaration of function 'vmalloc_user' [-Werror=implicit-function-declaration]
      46 |         q->ring = vmalloc_user(size);
         |                   ^~~~~~~~~~~~
>> net/xdp/xsk_queue.c:46:17: warning: assignment to 'struct xdp_ring *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
      46 |         q->ring = vmalloc_user(size);
         |                 ^
   net/xdp/xsk_queue.c: In function 'xskq_destroy':
   net/xdp/xsk_queue.c:60:17: error: implicit declaration of function 'vfree'; did you mean 'kvfree'? [-Werror=implicit-function-declaration]
      60 |                 vfree(q->ring);
         |                 ^~~~~
         |                 kvfree
   cc1: some warnings being treated as errors


vim +46 net/xdp/xsk_queue.c

    22	
    23	struct xsk_queue *xskq_create(u32 nentries, bool umem_queue)
    24	{
    25		struct xsk_queue *q;
    26		gfp_t gfp_flags;
    27		size_t size;
    28	
    29		q = kzalloc(sizeof(*q), GFP_KERNEL);
    30		if (!q)
    31			return NULL;
    32	
    33		q->nentries = nentries;
    34		q->ring_mask = nentries - 1;
    35	
    36		gfp_flags = GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN |
    37			    __GFP_COMP  | __GFP_NORETRY;
    38		size = xskq_get_ring_size(q, umem_queue);
    39	
    40		q->ring_size = size;
    41		q->ring = (struct xdp_ring *)__get_free_pages(gfp_flags,
    42							      get_order(size));
    43		if (q->ring)
    44			return q;
    45	
  > 46		q->ring = vmalloc_user(size);
    47		if (q->ring)
    48			return q;
    49	
    50		kfree(q);
    51		return NULL;
    52	}
    53	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-09 11:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-09  9:24 [PATCH net-next] xsk: support use vaddr as ring Xuan Zhuo
2023-02-09 11:06 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).