New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tools/slabratetop: call to undeclared function 'slab_address' #4438
Comments
commit 40f3bf0("mm: Convert struct page to struct slab in functions used by other subsystems") introduce 'slab_address()' and 'struct slab' in slab_def.h(CONFIG_SLAB) and slub_def.h(CONFIG_SLUB). When referencing a header file <linux/slub_def.h> in a module or BPF code, 'slab_address()' and 'struct slab' are not recognized, resulting in incomplete and undefined errors(see bcc slabratetop.py error [0]). Moving the function definitions of reference data structures such as struct slab and slab_address() such as nearest_obj(), obj_to_index(), and objs_per_slab() to the internal header file slab.h solves this fatal problem. [0] iovisor/bcc#4438 Signed-off-by: Rong Tao <rongtao@cestc.cn>
Sadly, kernel maintainer tends to not merge the above commit mm: Functions used internally should not be put into slub_def.h, that is to say, slabratetop.py could not include <sl*b_def.h> anymore since kernel commit 40f3bf0cb04c(“mm: Convert struct page to struct slab in functions used by other subsystems”). may we should solve the kmem_cache structure with BTF way. |
As a temporary workaround, something like below will work,
The above is based on latest bpf-next code base and need to be guarded with proper kernel versions or by some btf struct change around 40f3bf0cb04c("mm: Convert struct page to struct slab in functions used by other subsystems"). Need to double check the structure definition for earlier versions as well. Currently, there is an effort (#4405) to move bcc source to be more libbpf-processible. Hopefully with that it can make it easier to access the structure easier. |
@yonghong-song Thanks, Song. This patch solved my problem as a temporary solution. I have followed the submission of 4405, thanks again. |
@Rtoax Although this is a temporary workaround, could you still add the above temporary solution to slabratetop tool? This way, we can at least make slabratetop work for the >= 5.16 kernels. |
…lab' kernel commit 40f3bf0cb04c("mm: Convert struct page to struct slab in functions used by other subsystems") introduce slab_address() function, commit 6e48a966dfd1 ("mm/kasan: Convert to struct folio and struct slab") linux/kasan.h adds a dependency on the slab struct, This leads to the following problems: $ sudo ./slabratetop.py In file included from /virtual/main.c:13: include/linux/slub_def.h:162:26: warning: call to undeclared function 'slab_address'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] void *object = x - (x - slab_address(slab)) % cache->size; ^ include/linux/slub_def.h:162:46: error: invalid operands to binary expression ('void *' and 'unsigned int') void *object = x - (x - slab_address(slab)) % cache->size; ~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~ include/linux/slub_def.h:164:8: error: incomplete definition of type 'struct slab' (slab->objects - 1) * cache->size; ~~~~^ include/linux/kasan.h:13:8: note: forward declaration of 'struct slab' struct slab; ^ ... At first, I wanted to fix this with a kernel patch [1], however, bcc as a downstream project of the kernel, this issue should be solved inside the bcc project. This is agreed by kernel maintainer and bcc maintainer @yonghong-song. This solution is provided by @yonghong-song [0]. [0] iovisor#4438 [1] https://lore.kernel.org/all/tencent_ABA832E296819D1053D6C625ADCAF76BC706@qq.com/ Signed-off-by: Rong Tao <rongtao@cestc.cn> Signed-off-by: Yonghong Song <yhs@fb.com>
@yonghong-song Hi, Song, I just submit a PR #4447 |
…lab' kernel commit 40f3bf0cb04c("mm: Convert struct page to struct slab in functions used by other subsystems") introduce slab_address() function, commit 6e48a966dfd1 ("mm/kasan: Convert to struct folio and struct slab") linux/kasan.h adds a dependency on the slab struct, This leads to the following problems: $ sudo ./slabratetop.py In file included from /virtual/main.c:13: include/linux/slub_def.h:162:26: warning: call to undeclared function 'slab_address'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] void *object = x - (x - slab_address(slab)) % cache->size; ^ include/linux/slub_def.h:162:46: error: invalid operands to binary expression ('void *' and 'unsigned int') void *object = x - (x - slab_address(slab)) % cache->size; ~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~ include/linux/slub_def.h:164:8: error: incomplete definition of type 'struct slab' (slab->objects - 1) * cache->size; ~~~~^ include/linux/kasan.h:13:8: note: forward declaration of 'struct slab' struct slab; ^ ... At first, I wanted to fix this with a kernel patch [1], however, bcc as a downstream project of the kernel, this issue should be solved inside the bcc project. This is agreed by kernel maintainer and bcc maintainer @yonghong-song. This solution is provided by @yonghong-song [0]. [0] iovisor#4438 [1] https://lore.kernel.org/all/tencent_ABA832E296819D1053D6C625ADCAF76BC706@qq.com/ Signed-off-by: Rong Tao <rongtao@cestc.cn> Signed-off-by: Yonghong Song <yhs@fb.com>
…lab' kernel commit 40f3bf0cb04c("mm: Convert struct page to struct slab in functions used by other subsystems") introduce slab_address() function, commit 6e48a966dfd1 ("mm/kasan: Convert to struct folio and struct slab") linux/kasan.h adds a dependency on the slab struct, This leads to the following problems: $ sudo ./slabratetop.py In file included from /virtual/main.c:13: include/linux/slub_def.h:162:26: warning: call to undeclared function 'slab_address'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] void *object = x - (x - slab_address(slab)) % cache->size; ^ include/linux/slub_def.h:162:46: error: invalid operands to binary expression ('void *' and 'unsigned int') void *object = x - (x - slab_address(slab)) % cache->size; ~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~ include/linux/slub_def.h:164:8: error: incomplete definition of type 'struct slab' (slab->objects - 1) * cache->size; ~~~~^ include/linux/kasan.h:13:8: note: forward declaration of 'struct slab' struct slab; ^ ... At first, I wanted to fix this with a kernel patch [1], however, bcc as a downstream project of the kernel, this issue should be solved inside the bcc project. This is agreed by kernel maintainer and bcc maintainer @yonghong-song. This solution is provided by @yonghong-song [0]. [0] iovisor#4438 [1] https://lore.kernel.org/all/tencent_ABA832E296819D1053D6C625ADCAF76BC706@qq.com/ Signed-off-by: Rong Tao <rongtao@cestc.cn> Signed-off-by: Yonghong Song <yhs@fb.com>
…lab' kernel commit 40f3bf0cb04c("mm: Convert struct page to struct slab in functions used by other subsystems") introduce slab_address() function, commit 6e48a966dfd1 ("mm/kasan: Convert to struct folio and struct slab") linux/kasan.h adds a dependency on the slab struct, This leads to the following problems: $ sudo ./slabratetop.py In file included from /virtual/main.c:13: include/linux/slub_def.h:162:26: warning: call to undeclared function 'slab_address'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] void *object = x - (x - slab_address(slab)) % cache->size; ^ include/linux/slub_def.h:162:46: error: invalid operands to binary expression ('void *' and 'unsigned int') void *object = x - (x - slab_address(slab)) % cache->size; ~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~ include/linux/slub_def.h:164:8: error: incomplete definition of type 'struct slab' (slab->objects - 1) * cache->size; ~~~~^ include/linux/kasan.h:13:8: note: forward declaration of 'struct slab' struct slab; ^ ... At first, I wanted to fix this with a kernel patch [1], however, bcc as a downstream project of the kernel, this issue should be solved inside the bcc project. This is agreed by kernel maintainer and bcc maintainer @yonghong-song. This solution is provided by @yonghong-song [0]. [0] iovisor#4438 [1] https://lore.kernel.org/all/tencent_ABA832E296819D1053D6C625ADCAF76BC706@qq.com/ Signed-off-by: Rong Tao <rongtao@cestc.cn> Signed-off-by: Yonghong Song <yhs@fb.com>
…lab' kernel commit 40f3bf0cb04c("mm: Convert struct page to struct slab in functions used by other subsystems") introduce slab_address() function, commit 6e48a966dfd1 ("mm/kasan: Convert to struct folio and struct slab") linux/kasan.h adds a dependency on the slab struct, This leads to the following problems: $ sudo ./slabratetop.py In file included from /virtual/main.c:13: include/linux/slub_def.h:162:26: warning: call to undeclared function 'slab_address'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] void *object = x - (x - slab_address(slab)) % cache->size; ^ include/linux/slub_def.h:162:46: error: invalid operands to binary expression ('void *' and 'unsigned int') void *object = x - (x - slab_address(slab)) % cache->size; ~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~ include/linux/slub_def.h:164:8: error: incomplete definition of type 'struct slab' (slab->objects - 1) * cache->size; ~~~~^ include/linux/kasan.h:13:8: note: forward declaration of 'struct slab' struct slab; ^ ... At first, I wanted to fix this with a kernel patch [1], however, bcc as a downstream project of the kernel, this issue should be solved inside the bcc project. This is agreed by kernel maintainer and bcc maintainer @yonghong-song. This solution is provided by @yonghong-song [0]. [0] #4438 [1] https://lore.kernel.org/all/tencent_ABA832E296819D1053D6C625ADCAF76BC706@qq.com/ Signed-off-by: Rong Tao <rongtao@cestc.cn> Signed-off-by: Yonghong Song <yhs@fb.com>
…lab' kernel commit 40f3bf0cb04c("mm: Convert struct page to struct slab in functions used by other subsystems") introduce slab_address() function, commit 6e48a966dfd1 ("mm/kasan: Convert to struct folio and struct slab") linux/kasan.h adds a dependency on the slab struct, This leads to the following problems: $ sudo ./slabratetop.py In file included from /virtual/main.c:13: include/linux/slub_def.h:162:26: warning: call to undeclared function 'slab_address'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] void *object = x - (x - slab_address(slab)) % cache->size; ^ include/linux/slub_def.h:162:46: error: invalid operands to binary expression ('void *' and 'unsigned int') void *object = x - (x - slab_address(slab)) % cache->size; ~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~ include/linux/slub_def.h:164:8: error: incomplete definition of type 'struct slab' (slab->objects - 1) * cache->size; ~~~~^ include/linux/kasan.h:13:8: note: forward declaration of 'struct slab' struct slab; ^ ... At first, I wanted to fix this with a kernel patch [1], however, bcc as a downstream project of the kernel, this issue should be solved inside the bcc project. This is agreed by kernel maintainer and bcc maintainer @yonghong-song. This solution is provided by @yonghong-song [0]. [0] iovisor#4438 [1] https://lore.kernel.org/all/tencent_ABA832E296819D1053D6C625ADCAF76BC706@qq.com/ Signed-off-by: Rong Tao <rongtao@cestc.cn> Signed-off-by: Yonghong Song <yhs@fb.com>
…lab' kernel commit 40f3bf0cb04c("mm: Convert struct page to struct slab in functions used by other subsystems") introduce slab_address() function, commit 6e48a966dfd1 ("mm/kasan: Convert to struct folio and struct slab") linux/kasan.h adds a dependency on the slab struct, This leads to the following problems: $ sudo ./slabratetop.py In file included from /virtual/main.c:13: include/linux/slub_def.h:162:26: warning: call to undeclared function 'slab_address'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] void *object = x - (x - slab_address(slab)) % cache->size; ^ include/linux/slub_def.h:162:46: error: invalid operands to binary expression ('void *' and 'unsigned int') void *object = x - (x - slab_address(slab)) % cache->size; ~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~ include/linux/slub_def.h:164:8: error: incomplete definition of type 'struct slab' (slab->objects - 1) * cache->size; ~~~~^ include/linux/kasan.h:13:8: note: forward declaration of 'struct slab' struct slab; ^ ... At first, I wanted to fix this with a kernel patch [1], however, bcc as a downstream project of the kernel, this issue should be solved inside the bcc project. This is agreed by kernel maintainer and bcc maintainer @yonghong-song. This solution is provided by @yonghong-song [0]. [0] iovisor#4438 [1] https://lore.kernel.org/all/tencent_ABA832E296819D1053D6C625ADCAF76BC706@qq.com/ Signed-off-by: Rong Tao <rongtao@cestc.cn> Signed-off-by: Yonghong Song <yhs@fb.com>
When my system uses SLUB And the kernel version >=5.16, there are the following problems:
see commit 40f3bf0cb04c("mm: Convert struct page to struct slab in functions used by other subsystems")
This issue should be modified in the kernel, I'm trying to fix this, kernel submit mm: Functions used internally should not be put into slub_def.h totally solve this fatal error, hope it'll be merged to kernel souce code tree.
The text was updated successfully, but these errors were encountered: