diff mbox series

[v2,02/24] netmem: Add utility functions

Message ID 20230105214631.3939268-3-willy@infradead.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series Split netmem from struct page | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_maps on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_progs on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-17 fail Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 fail Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32 on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-22 fail Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 fail Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_progs_no_alu32_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-29 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for test_progs_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-31 success Logs for test_progs_parallel on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-32 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-33 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-34 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-35 success Logs for test_verifier on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-36 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-37 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-38 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_progs_no_alu32_parallel on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ${{ matrix.test }} on ${{ matrix.arch }} with ${{ matrix.toolchain }}
bpf/vmtest-bpf-next-VM_Test-2 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-5 fail Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-8 success Logs for llvm-toolchain
bpf/vmtest-bpf-next-VM_Test-9 success Logs for set-matrix
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Series has a cover letter
netdev/patch_count fail Series longer than 15 patches (and no cover letter)
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5340 this patch: 5340
netdev/cc_maintainers warning 4 maintainers not CCed: edumazet@google.com davem@davemloft.net pabeni@redhat.com kuba@kernel.org
netdev/build_clang success Errors and warnings before: 1086 this patch: 1086
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
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: 5554 this patch: 5554
netdev/checkpatch fail CHECK: Macro argument 'nmem' may be better as '(nmem)' to avoid precedence issues ERROR: spaces required around that ':' (ctx:VxW) WARNING: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Matthew Wilcox (Oracle) Jan. 5, 2023, 9:46 p.m. UTC
netmem_page() is defined this way to preserve constness.  page_netmem()
doesn't call compound_head() because netmem users always use the head
page; it does include a debugging assert to check that it's true.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/net/page_pool.h | 59 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

Comments

kernel test robot Jan. 6, 2023, 2:24 a.m. UTC | #1
Hi Matthew,

I love your patch! Perhaps something to improve:

[auto build test WARNING on bpf-next/master]
[also build test WARNING on bpf/master net/master net-next/master linus/master v6.2-rc2 next-20230105]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Matthew-Wilcox-Oracle/netmem-Create-new-type/20230106-054852
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
patch link:    https://lore.kernel.org/r/20230105214631.3939268-3-willy%40infradead.org
patch subject: [PATCH v2 02/24] netmem: Add utility functions
config: arm-randconfig-r014-20230105
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 8d9828ef5aa9688500657d36cd2aefbe12bbd162)
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
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # https://github.com/intel-lab-lkp/linux/commit/167a5c35da10f97c077af525e9f537fab4438b94
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Matthew-Wilcox-Oracle/netmem-Create-new-type/20230106-054852
        git checkout 167a5c35da10f97c077af525e9f537fab4438b94
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash kernel/ net/core/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   kernel/fork.c:162:13: warning: no previous prototype for function 'arch_release_task_struct' [-Wmissing-prototypes]
   void __weak arch_release_task_struct(struct task_struct *tsk)
               ^
   kernel/fork.c:162:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   void __weak arch_release_task_struct(struct task_struct *tsk)
   ^
   static 
   kernel/fork.c:862:20: warning: no previous prototype for function 'arch_task_cache_init' [-Wmissing-prototypes]
   void __init __weak arch_task_cache_init(void) { }
                      ^
   kernel/fork.c:862:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   void __init __weak arch_task_cache_init(void) { }
   ^
   static 
   kernel/fork.c:957:12: warning: no previous prototype for function 'arch_dup_task_struct' [-Wmissing-prototypes]
   int __weak arch_dup_task_struct(struct task_struct *dst,
              ^
   kernel/fork.c:957:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int __weak arch_dup_task_struct(struct task_struct *dst,
   ^
   static 
   In file included from kernel/fork.c:1087:
   In file included from include/linux/init_task.h:18:
   In file included from include/net/net_namespace.h:43:
   In file included from include/linux/skbuff.h:41:
>> include/net/page_pool.h:111:21: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_pfn(netmem_page(nmem));
                              ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:116:21: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_nid(netmem_page(nmem));
                              ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:126:22: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_virt(netmem_page(nmem));
                               ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:131:22: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_address(netmem_page(nmem));
                               ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:136:24: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_ref_count(netmem_page(nmem));
                                 ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   8 warnings generated.
--
   In file included from kernel/exit.c:55:
   In file included from include/linux/init_task.h:18:
   In file included from include/net/net_namespace.h:43:
   In file included from include/linux/skbuff.h:41:
>> include/net/page_pool.h:111:21: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_pfn(netmem_page(nmem));
                              ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:116:21: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_nid(netmem_page(nmem));
                              ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:126:22: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_virt(netmem_page(nmem));
                               ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:131:22: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_address(netmem_page(nmem));
                               ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:136:24: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_ref_count(netmem_page(nmem));
                                 ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   5 warnings generated.
--
   In file included from kernel/kallsyms.c:25:
   In file included from include/linux/filter.h:12:
   In file included from include/linux/skbuff.h:41:
>> include/net/page_pool.h:111:21: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_pfn(netmem_page(nmem));
                              ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:116:21: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_nid(netmem_page(nmem));
                              ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:126:22: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_virt(netmem_page(nmem));
                               ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:131:22: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_address(netmem_page(nmem));
                               ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:136:24: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_ref_count(netmem_page(nmem));
                                 ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   kernel/kallsyms.c:663:12: warning: no previous prototype for function 'arch_get_kallsym' [-Wmissing-prototypes]
   int __weak arch_get_kallsym(unsigned int symnum, unsigned long *value,
              ^
   kernel/kallsyms.c:663:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int __weak arch_get_kallsym(unsigned int symnum, unsigned long *value,
   ^
   static 
   6 warnings generated.
--
   In file included from net/core/flow_dissector.c:3:
   In file included from include/linux/skbuff.h:41:
>> include/net/page_pool.h:111:21: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_pfn(netmem_page(nmem));
                              ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:116:21: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_nid(netmem_page(nmem));
                              ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:126:22: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_virt(netmem_page(nmem));
                               ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:131:22: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_address(netmem_page(nmem));
                               ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:136:24: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_ref_count(netmem_page(nmem));
                                 ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   In file included from net/core/flow_dissector.c:21:
   In file included from include/linux/if_pppox.h:17:
   include/uapi/linux/if_pppox.h:71:4: warning: field sa_addr within 'struct sockaddr_pppox' is less aligned than 'union (unnamed union at include/uapi/linux/if_pppox.h:68:2)' and is usually due to 'struct sockaddr_pppox' being packed, which can lead to unaligned accesses [-Wunaligned-access]
           } sa_addr;
             ^
   6 warnings generated.
--
   In file included from net/core/dev.c:89:
   In file included from include/linux/if_ether.h:19:
   In file included from include/linux/skbuff.h:41:
>> include/net/page_pool.h:111:21: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_pfn(netmem_page(nmem));
                              ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:116:21: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_nid(netmem_page(nmem));
                              ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:126:22: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_virt(netmem_page(nmem));
                               ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:131:22: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_address(netmem_page(nmem));
                               ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:136:24: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_ref_count(netmem_page(nmem));
                                 ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   net/core/dev.c:5098:1: warning: unused function 'sch_handle_ingress' [-Wunused-function]
   sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret,
   ^
   net/core/dev.c:5251:19: warning: unused function 'nf_ingress' [-Wunused-function]
   static inline int nf_ingress(struct sk_buff *skb, struct packet_type **pt_prev,
                     ^
   7 warnings generated.
--
   In file included from kernel/sched/core.c:44:
   In file included from include/linux/init_task.h:18:
   In file included from include/net/net_namespace.h:43:
   In file included from include/linux/skbuff.h:41:
>> include/net/page_pool.h:111:21: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_pfn(netmem_page(nmem));
                              ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:116:21: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_nid(netmem_page(nmem));
                              ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:126:22: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_virt(netmem_page(nmem));
                               ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:131:22: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_address(netmem_page(nmem));
                               ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:136:24: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_ref_count(netmem_page(nmem));
                                 ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   kernel/sched/core.c:6664:35: warning: no previous prototype for function 'schedule_user' [-Wmissing-prototypes]
   asmlinkage __visible void __sched schedule_user(void)
                                     ^
   kernel/sched/core.c:6664:22: note: declare 'static' if the function is not intended to be used outside of this translation unit
   asmlinkage __visible void __sched schedule_user(void)
                        ^
                        static 
   kernel/sched/core.c:3579:20: warning: unused function 'rq_has_pinned_tasks' [-Wunused-function]
   static inline bool rq_has_pinned_tasks(struct rq *rq)
                      ^
   kernel/sched/core.c:5673:20: warning: unused function 'sched_tick_start' [-Wunused-function]
   static inline void sched_tick_start(int cpu) { }
                      ^
   kernel/sched/core.c:5674:20: warning: unused function 'sched_tick_stop' [-Wunused-function]
   static inline void sched_tick_stop(int cpu) { }
                      ^
   kernel/sched/core.c:6367:20: warning: unused function 'sched_core_cpu_starting' [-Wunused-function]
   static inline void sched_core_cpu_starting(unsigned int cpu) {}
                      ^
   kernel/sched/core.c:6368:20: warning: unused function 'sched_core_cpu_deactivate' [-Wunused-function]
   static inline void sched_core_cpu_deactivate(unsigned int cpu) {}
                      ^
   kernel/sched/core.c:6369:20: warning: unused function 'sched_core_cpu_dying' [-Wunused-function]
   static inline void sched_core_cpu_dying(unsigned int cpu) {}
                      ^
   12 warnings generated.
--
   In file included from kernel/bpf/core.c:21:
   In file included from include/linux/filter.h:12:
   In file included from include/linux/skbuff.h:41:
>> include/net/page_pool.h:111:21: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_pfn(netmem_page(nmem));
                              ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:116:21: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_nid(netmem_page(nmem));
                              ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:126:22: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_virt(netmem_page(nmem));
                               ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:131:22: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_address(netmem_page(nmem));
                               ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   include/net/page_pool.h:136:24: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_ref_count(netmem_page(nmem));
                                 ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
   kernel/bpf/core.c:1630:12: warning: no previous prototype for function 'bpf_probe_read_kernel' [-Wmissing-prototypes]
   u64 __weak bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
              ^
   kernel/bpf/core.c:1630:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   u64 __weak bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
   ^
   static 
   kernel/bpf/core.c:2069:6: warning: no previous prototype for function 'bpf_patch_call_args' [-Wmissing-prototypes]
   void bpf_patch_call_args(struct bpf_insn *insn, u32 stack_depth)
        ^
   kernel/bpf/core.c:2069:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   void bpf_patch_call_args(struct bpf_insn *insn, u32 stack_depth)
   ^
   static 
   7 warnings generated.


vim +111 include/net/page_pool.h

   108	
   109	static inline unsigned long netmem_pfn(const struct netmem *nmem)
   110	{
 > 111		return page_to_pfn(netmem_page(nmem));
   112	}
   113
Jesper Dangaard Brouer Jan. 6, 2023, 1:35 p.m. UTC | #2
On 05/01/2023 22.46, Matthew Wilcox (Oracle) wrote:
> netmem_page() is defined this way to preserve constness.  page_netmem()
> doesn't call compound_head() because netmem users always use the head
> page; it does include a debugging assert to check that it's true.
> 
> Signed-off-by: Matthew Wilcox (Oracle)<willy@infradead.org>
> ---
>   include/net/page_pool.h | 59 +++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 59 insertions(+)

Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
Matthew Wilcox (Oracle) Jan. 6, 2023, 8:35 p.m. UTC | #3
On Fri, Jan 06, 2023 at 10:24:30AM +0800, kernel test robot wrote:
> >> include/net/page_pool.h:111:21: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
>            return page_to_pfn(netmem_page(nmem));
>                               ^
>    include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
>            const struct netmem:    (const struct page *)nmem,              \
>                  ^

OK, figured out what this error means.

#define netmem_page(nmem) (_Generic((*nmem),                            \
        const struct netmem:    (const struct page *)nmem,              \
        struct netmem:          (struct page *)nmem))

Because I defined this with _Generic((*nmem),...) instead of
_Generic((nmem),...) (like page_folio() is defined), clang always
selects the second case and not the const case.  Apparently lvalue
coversions remove the const (backed up by
https://en.cppreference.com/w/c/language/conversion) but I had no idea
that _Generic applied lvalue conversion to the controlling-expression
(it does!  https://en.cppreference.com/w/c/language/generic)

So, yay for clang's extra warning.  I'll fix this up (as below) and send
a v3 next week including the various R-b that I've received.

-#define netmem_page(nmem) (_Generic((*nmem),                           \
-       const struct netmem:    (const struct page *)nmem,              \
-       struct netmem:          (struct page *)nmem))
+#define netmem_page(nmem) (_Generic((nmem),                            \
+       const struct netmem *:  (const struct page *)nmem,              \
+       struct netmem *:        (struct page *)nmem))
diff mbox series

Patch

diff --git a/include/net/page_pool.h b/include/net/page_pool.h
index cbea4df54918..84b4ea8af015 100644
--- a/include/net/page_pool.h
+++ b/include/net/page_pool.h
@@ -96,6 +96,65 @@  NETMEM_MATCH(_refcount, _refcount);
 #undef NETMEM_MATCH
 static_assert(sizeof(struct netmem) <= sizeof(struct page));
 
+#define netmem_page(nmem) (_Generic((*nmem),				\
+	const struct netmem:	(const struct page *)nmem,		\
+	struct netmem:		(struct page *)nmem))
+
+static inline struct netmem *page_netmem(struct page *page)
+{
+	VM_BUG_ON_PAGE(PageTail(page), page);
+	return (struct netmem *)page;
+}
+
+static inline unsigned long netmem_pfn(const struct netmem *nmem)
+{
+	return page_to_pfn(netmem_page(nmem));
+}
+
+static inline unsigned long netmem_nid(const struct netmem *nmem)
+{
+	return page_to_nid(netmem_page(nmem));
+}
+
+static inline struct netmem *virt_to_netmem(const void *x)
+{
+	return page_netmem(virt_to_head_page(x));
+}
+
+static inline void *netmem_to_virt(const struct netmem *nmem)
+{
+	return page_to_virt(netmem_page(nmem));
+}
+
+static inline void *netmem_address(const struct netmem *nmem)
+{
+	return page_address(netmem_page(nmem));
+}
+
+static inline int netmem_ref_count(const struct netmem *nmem)
+{
+	return page_ref_count(netmem_page(nmem));
+}
+
+static inline void netmem_get(struct netmem *nmem)
+{
+	struct folio *folio = (struct folio *)nmem;
+
+	folio_get(folio);
+}
+
+static inline void netmem_put(struct netmem *nmem)
+{
+	struct folio *folio = (struct folio *)nmem;
+
+	folio_put(folio);
+}
+
+static inline bool netmem_is_pfmemalloc(const struct netmem *nmem)
+{
+	return nmem->pp_magic & BIT(1);
+}
+
 /*
  * Fast allocation side cache array/stack
  *