diff mbox series

[v4,net-next,1/3] net: introduce page_pool pointer in softnet_data percpu struct

Message ID 2a267c8f331996de0e26568472c45fe78eb67e1d.1702375338.git.lorenzo@kernel.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series add multi-buff support for xdp running in generic mode | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5201 this patch: 5201
netdev/cc_maintainers warning 4 maintainers not CCed: ast@kernel.org ilias.apalodimas@linaro.org daniel@iogearbox.net john.fastabend@gmail.com
netdev/build_clang success Errors and warnings before: 1360 this patch: 1360
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 5530 this patch: 5530
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 103 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Lorenzo Bianconi Dec. 12, 2023, 10:06 a.m. UTC
Allocate percpu page_pools in softnet_data.
Moreover add cpuid filed in page_pool struct in order to recycle the
page in the page_pool "hot" cache if napi_pp_put_page() is running on
the same cpu.
This is a preliminary patch to add xdp multi-buff support for xdp running
in generic mode.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 include/linux/netdevice.h       |  1 +
 include/net/page_pool/helpers.h |  5 +++++
 include/net/page_pool/types.h   |  2 +-
 net/core/dev.c                  | 28 +++++++++++++++++++++++++++-
 net/core/skbuff.c               |  5 +++--
 5 files changed, 37 insertions(+), 4 deletions(-)

Comments

kernel test robot Dec. 12, 2023, 9:46 p.m. UTC | #1
Hi Lorenzo,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Lorenzo-Bianconi/net-introduce-page_pool-pointer-in-softnet_data-percpu-struct/20231212-181103
base:   net-next/main
patch link:    https://lore.kernel.org/r/2a267c8f331996de0e26568472c45fe78eb67e1d.1702375338.git.lorenzo%40kernel.org
patch subject: [PATCH v4 net-next 1/3] net: introduce page_pool pointer in softnet_data percpu struct
config: um-allnoconfig (https://download.01.org/0day-ci/archive/20231213/202312130546.Kst7VY7F-lkp@intel.com/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231213/202312130546.Kst7VY7F-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202312130546.Kst7VY7F-lkp@intel.com/

All errors (new ones prefixed by >>):

   /usr/bin/ld: init/main.o: warning: relocation in read-only section `.ref.text'
   /usr/bin/ld: warning: .tmp_vmlinux.kallsyms1 has a LOAD segment with RWX permissions
   /usr/bin/ld: net/core/dev.o: in function `net_dev_init':
>> net/core/dev.c:11734: undefined reference to `page_pool_create'
   /usr/bin/ld: warning: creating DT_TEXTREL in a PIE
   clang: error: linker command failed with exit code 1 (use -v to see invocation)


vim +11734 net/core/dev.c

 11667	
 11668	/*
 11669	 *	Initialize the DEV module. At boot time this walks the device list and
 11670	 *	unhooks any devices that fail to initialise (normally hardware not
 11671	 *	present) and leaves us with a valid list of present and active devices.
 11672	 *
 11673	 */
 11674	
 11675	#define SD_PAGE_POOL_RING_SIZE	256
 11676	/*
 11677	 *       This is called single threaded during boot, so no need
 11678	 *       to take the rtnl semaphore.
 11679	 */
 11680	static int __init net_dev_init(void)
 11681	{
 11682		struct softnet_data *sd;
 11683		int i, rc = -ENOMEM;
 11684	
 11685		BUG_ON(!dev_boot_phase);
 11686	
 11687		net_dev_struct_check();
 11688	
 11689		if (dev_proc_init())
 11690			goto out;
 11691	
 11692		if (netdev_kobject_init())
 11693			goto out;
 11694	
 11695		INIT_LIST_HEAD(&ptype_all);
 11696		for (i = 0; i < PTYPE_HASH_SIZE; i++)
 11697			INIT_LIST_HEAD(&ptype_base[i]);
 11698	
 11699		if (register_pernet_subsys(&netdev_net_ops))
 11700			goto out;
 11701	
 11702		/*
 11703		 *	Initialise the packet receive queues.
 11704		 */
 11705	
 11706		for_each_possible_cpu(i) {
 11707			struct work_struct *flush = per_cpu_ptr(&flush_works, i);
 11708			struct page_pool_params page_pool_params = {
 11709				.pool_size = SD_PAGE_POOL_RING_SIZE,
 11710				.nid = NUMA_NO_NODE,
 11711			};
 11712	
 11713			INIT_WORK(flush, flush_backlog);
 11714	
 11715			sd = &per_cpu(softnet_data, i);
 11716			skb_queue_head_init(&sd->input_pkt_queue);
 11717			skb_queue_head_init(&sd->process_queue);
 11718	#ifdef CONFIG_XFRM_OFFLOAD
 11719			skb_queue_head_init(&sd->xfrm_backlog);
 11720	#endif
 11721			INIT_LIST_HEAD(&sd->poll_list);
 11722			sd->output_queue_tailp = &sd->output_queue;
 11723	#ifdef CONFIG_RPS
 11724			INIT_CSD(&sd->csd, rps_trigger_softirq, sd);
 11725			sd->cpu = i;
 11726	#endif
 11727			INIT_CSD(&sd->defer_csd, trigger_rx_softirq, sd);
 11728			spin_lock_init(&sd->defer_lock);
 11729	
 11730			init_gro_hash(&sd->backlog);
 11731			sd->backlog.poll = process_backlog;
 11732			sd->backlog.weight = weight_p;
 11733	
 11734			sd->page_pool = page_pool_create(&page_pool_params);
 11735			if (IS_ERR(sd->page_pool)) {
 11736				sd->page_pool = NULL;
 11737				goto out;
 11738			}
 11739			page_pool_set_cpuid(sd->page_pool, i);
 11740		}
 11741	
 11742		dev_boot_phase = 0;
 11743	
 11744		/* The loopback device is special if any other network devices
 11745		 * is present in a network namespace the loopback device must
 11746		 * be present. Since we now dynamically allocate and free the
 11747		 * loopback device ensure this invariant is maintained by
 11748		 * keeping the loopback device as the first device on the
 11749		 * list of network devices.  Ensuring the loopback devices
 11750		 * is the first device that appears and the last network device
 11751		 * that disappears.
 11752		 */
 11753		if (register_pernet_device(&loopback_net_ops))
 11754			goto out;
 11755	
 11756		if (register_pernet_device(&default_device_ops))
 11757			goto out;
 11758	
 11759		open_softirq(NET_TX_SOFTIRQ, net_tx_action);
 11760		open_softirq(NET_RX_SOFTIRQ, net_rx_action);
 11761	
 11762		rc = cpuhp_setup_state_nocalls(CPUHP_NET_DEV_DEAD, "net/dev:dead",
 11763					       NULL, dev_cpu_dead);
 11764		WARN_ON(rc < 0);
 11765		rc = 0;
 11766	out:
 11767		if (rc < 0) {
 11768			for_each_possible_cpu(i) {
 11769				sd = &per_cpu(softnet_data, i);
 11770				if (!sd->page_pool)
 11771					continue;
 11772	
 11773				page_pool_destroy(sd->page_pool);
 11774				sd->page_pool = NULL;
 11775			}
 11776		}
 11777	
 11778		return rc;
 11779	}
 11780
kernel test robot Dec. 12, 2023, 9:56 p.m. UTC | #2
Hi Lorenzo,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Lorenzo-Bianconi/net-introduce-page_pool-pointer-in-softnet_data-percpu-struct/20231212-181103
base:   net-next/main
patch link:    https://lore.kernel.org/r/2a267c8f331996de0e26568472c45fe78eb67e1d.1702375338.git.lorenzo%40kernel.org
patch subject: [PATCH v4 net-next 1/3] net: introduce page_pool pointer in softnet_data percpu struct
config: arc-defconfig (https://download.01.org/0day-ci/archive/20231213/202312130531.EIYsEYp0-lkp@intel.com/config)
compiler: arc-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231213/202312130531.EIYsEYp0-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202312130531.EIYsEYp0-lkp@intel.com/

All errors (new ones prefixed by >>):

   arc-elf-ld: net/core/dev.o: in function `net_dev_init':
>> dev.c:(.init.text+0x180): undefined reference to `page_pool_create'
>> arc-elf-ld: dev.c:(.init.text+0x180): undefined reference to `page_pool_create'
diff mbox series

Patch

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 1b935ee341b4..30b6a3f601fe 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -3319,6 +3319,7 @@  struct softnet_data {
 	int			defer_count;
 	int			defer_ipi_scheduled;
 	struct sk_buff		*defer_list;
+	struct page_pool	*page_pool;
 	call_single_data_t	defer_csd;
 };
 
diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h
index 7dc65774cde5..b0da1fdb62dc 100644
--- a/include/net/page_pool/helpers.h
+++ b/include/net/page_pool/helpers.h
@@ -393,4 +393,9 @@  static inline void page_pool_nid_changed(struct page_pool *pool, int new_nid)
 		page_pool_update_nid(pool, new_nid);
 }
 
+static inline void page_pool_set_cpuid(struct page_pool *pool, int cpuid)
+{
+	pool->cpuid = cpuid;
+}
+
 #endif /* _NET_PAGE_POOL_HELPERS_H */
diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h
index ac286ea8ce2d..75396f107b20 100644
--- a/include/net/page_pool/types.h
+++ b/include/net/page_pool/types.h
@@ -127,7 +127,7 @@  struct page_pool_stats {
 
 struct page_pool {
 	struct page_pool_params_fast p;
-
+	int cpuid;
 	bool has_init_callback;
 
 	long frag_users;
diff --git a/net/core/dev.c b/net/core/dev.c
index 0432b04cf9b0..4c3d82fcf5b5 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -153,6 +153,8 @@ 
 #include <linux/prandom.h>
 #include <linux/once_lite.h>
 #include <net/netdev_rx_queue.h>
+#include <net/page_pool/types.h>
+#include <net/page_pool/helpers.h>
 
 #include "dev.h"
 #include "net-sysfs.h"
@@ -11670,12 +11672,14 @@  static void __init net_dev_struct_check(void)
  *
  */
 
+#define SD_PAGE_POOL_RING_SIZE	256
 /*
  *       This is called single threaded during boot, so no need
  *       to take the rtnl semaphore.
  */
 static int __init net_dev_init(void)
 {
+	struct softnet_data *sd;
 	int i, rc = -ENOMEM;
 
 	BUG_ON(!dev_boot_phase);
@@ -11701,10 +11705,14 @@  static int __init net_dev_init(void)
 
 	for_each_possible_cpu(i) {
 		struct work_struct *flush = per_cpu_ptr(&flush_works, i);
-		struct softnet_data *sd = &per_cpu(softnet_data, i);
+		struct page_pool_params page_pool_params = {
+			.pool_size = SD_PAGE_POOL_RING_SIZE,
+			.nid = NUMA_NO_NODE,
+		};
 
 		INIT_WORK(flush, flush_backlog);
 
+		sd = &per_cpu(softnet_data, i);
 		skb_queue_head_init(&sd->input_pkt_queue);
 		skb_queue_head_init(&sd->process_queue);
 #ifdef CONFIG_XFRM_OFFLOAD
@@ -11722,6 +11730,13 @@  static int __init net_dev_init(void)
 		init_gro_hash(&sd->backlog);
 		sd->backlog.poll = process_backlog;
 		sd->backlog.weight = weight_p;
+
+		sd->page_pool = page_pool_create(&page_pool_params);
+		if (IS_ERR(sd->page_pool)) {
+			sd->page_pool = NULL;
+			goto out;
+		}
+		page_pool_set_cpuid(sd->page_pool, i);
 	}
 
 	dev_boot_phase = 0;
@@ -11749,6 +11764,17 @@  static int __init net_dev_init(void)
 	WARN_ON(rc < 0);
 	rc = 0;
 out:
+	if (rc < 0) {
+		for_each_possible_cpu(i) {
+			sd = &per_cpu(softnet_data, i);
+			if (!sd->page_pool)
+				continue;
+
+			page_pool_destroy(sd->page_pool);
+			sd->page_pool = NULL;
+		}
+	}
+
 	return rc;
 }
 
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index b157efea5dea..4bc0a7f98241 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -918,9 +918,10 @@  bool napi_pp_put_page(struct page *page, bool napi_safe)
 	 */
 	if (napi_safe || in_softirq()) {
 		const struct napi_struct *napi = READ_ONCE(pp->p.napi);
+		unsigned int cpuid = smp_processor_id();
 
-		allow_direct = napi &&
-			READ_ONCE(napi->list_owner) == smp_processor_id();
+		allow_direct = napi && READ_ONCE(napi->list_owner) == cpuid;
+		allow_direct |= (pp->cpuid == cpuid);
 	}
 
 	/* Driver set this to memory recycling info. Reset it on recycle.