admin管理员组

文章数量:1356361

I try to use task_cgroup_path in a module kernel.

The mwe is compiling on kernel 4.18.

But In, 5.14 on 6.8, it is not compiling.

Here the code :

#include <linux/module.h>
//#include <linux/printk.h>
//#include <linux/time.h>
#include <linux/cgroup.h>

struct timespec64 ts;

int init_module(void) 
{ 
    char *cpath_buf;
    int cpath_ret;

    cpath_buf = kmalloc(PATH_MAX, GFP_KERNEL);
    ktime_get_real_ts64((struct timespec64 *)&ts);
    cpath_ret = task_cgroup_path(current, cpath_buf, PATH_MAX);
//        pr_info("Hello world (%lld/%ld).\n", ts.tv_sec, ts.tv_nsec);
       
        return 0; 
} 

void cleanup_module(void) 
{ 
        pr_info("Goodbye world 0.\n"); 
} 

MODULE_LICENSE("GPL");

And the issue :

root@kerndev:~/tst_time# make
make -C /lib/modules/6.8.0-55-generic/build M=/root/tst_time  modules 
make[1]: Entering directory '/usr/src/linux-headers-6.8.0-55-generic'
warning: the compiler differs from the one used to build the kernel
  The kernel was built by: x86_64-linux-gnu-gcc-13 (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
  You are using:           gcc-13 (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
  CC [M]  /root/tst_time/m_timespec.o
/root/tst_time/m_timespec.c: In function ‘init_module’:
/root/tst_time/m_timespec.c:15:21: error: implicit declaration of function ‘task_cgroup_path’; did you mean ‘sock_cgroup_ptr’? [-Werror=implicit-function-declaration]
   15 |         cpath_ret = task_cgroup_path(current, cpath_buf, PATH_MAX);
      |                     ^~~~~~~~~~~~~~~~
      |                     sock_cgroup_ptr
cc1: some warnings being treated as errors
make[3]: *** [scripts/Makefile.build:243: /root/tst_time/m_timespec.o] Error 1
make[2]: *** [/usr/src/linux-headers-6.8.0-55-generic/Makefile:1925: /root/tst_time] Error 2
make[1]: *** [Makefile:240: __sub-make] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-6.8.0-55-generic'
make: *** [Makefile:6: all] Error 2
root@kerndev:~/tst_time# uname -a
Linux kerndev 6.8.0-55-generic #57-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 12 23:42:21 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

I try to use task_cgroup_path in a module kernel.

The mwe is compiling on kernel 4.18.

But In, 5.14 on 6.8, it is not compiling.

Here the code :

#include <linux/module.h>
//#include <linux/printk.h>
//#include <linux/time.h>
#include <linux/cgroup.h>

struct timespec64 ts;

int init_module(void) 
{ 
    char *cpath_buf;
    int cpath_ret;

    cpath_buf = kmalloc(PATH_MAX, GFP_KERNEL);
    ktime_get_real_ts64((struct timespec64 *)&ts);
    cpath_ret = task_cgroup_path(current, cpath_buf, PATH_MAX);
//        pr_info("Hello world (%lld/%ld).\n", ts.tv_sec, ts.tv_nsec);
       
        return 0; 
} 

void cleanup_module(void) 
{ 
        pr_info("Goodbye world 0.\n"); 
} 

MODULE_LICENSE("GPL");

And the issue :

root@kerndev:~/tst_time# make
make -C /lib/modules/6.8.0-55-generic/build M=/root/tst_time  modules 
make[1]: Entering directory '/usr/src/linux-headers-6.8.0-55-generic'
warning: the compiler differs from the one used to build the kernel
  The kernel was built by: x86_64-linux-gnu-gcc-13 (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
  You are using:           gcc-13 (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
  CC [M]  /root/tst_time/m_timespec.o
/root/tst_time/m_timespec.c: In function ‘init_module’:
/root/tst_time/m_timespec.c:15:21: error: implicit declaration of function ‘task_cgroup_path’; did you mean ‘sock_cgroup_ptr’? [-Werror=implicit-function-declaration]
   15 |         cpath_ret = task_cgroup_path(current, cpath_buf, PATH_MAX);
      |                     ^~~~~~~~~~~~~~~~
      |                     sock_cgroup_ptr
cc1: some warnings being treated as errors
make[3]: *** [scripts/Makefile.build:243: /root/tst_time/m_timespec.o] Error 1
make[2]: *** [/usr/src/linux-headers-6.8.0-55-generic/Makefile:1925: /root/tst_time] Error 2
make[1]: *** [Makefile:240: __sub-make] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-6.8.0-55-generic'
make: *** [Makefile:6: all] Error 2
root@kerndev:~/tst_time# uname -a
Linux kerndev 6.8.0-55-generic #57-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 12 23:42:21 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Share Improve this question edited Mar 28 at 21:51 Marco Bonelli 69.7k21 gold badges127 silver badges146 bronze badges asked Mar 28 at 16:48 flavflav 2231 silver badge13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

task_cgroup_path() was removed in v6.5 because it had no users (even in 4.18 it had no users). You won't be able to use it as it's simply not there anymore. You may be able to re-implement it yourself, but that's going to take some effort since a lot of the stuff it uses is not exported for modules.

本文标签: compilationlkm dev linux compile issue for taskcgrouppath functionStack Overflow