bpf: BPF-driven proactive memcg reclaim
Subsystems (5)
v5 cover bpf: BPF-driven proactive memcg reclaim
From: Hui Zhu <[email protected]>
BPF programs can observe memory pressure on a cgroup (e.g. refault stats via bpf_mem_cgroup_page_state()), but cannot act on it:
triggering reclaim on a chosen cgroup requires writing to memory.reclaim, which BPF cannot do. This series adds bpf_proactive_reclaim(), a sleepable kfunc performing one proactive reclaim pass on a target memcg, so when and how hard to reclaim is BPF policy rather than hard-coded thresholds.
The use case we are looking at is protecting high-priority workloads:
a BPF program monitors the state of a high-priority cgroup and, when it degrades (e.g. PSI rises or refaults increase, as in the selftest), asynchronously reclaims memory from low-priority cgroups via bpf_wq and bpf_proactive_reclaim(), giving the pressured cgroup more free pages.
Another use case: several vendor-maintained kernels carry private implementations that trigger asynchronous reclaim when a memcg enters a certain state. These exist for historical and partly psychological reasons, but the underlying demand is real. We expect BPF-driven proactive reclaim, combined with the BPF hooks for the memory controller currently under discussion and development, to serve these needs in mainline, reducing kernel fragmentation and improving kernel maintainability.
Hui Zhu (2):
mm/bpf: Add bpf_proactive_reclaim kfunc
selftests/bpf: Add memcg async reclaim test
mm/bpf_memcontrol.c | 46 ++ .../bpf/prog_tests/memcg_async_reclaim.c | 480 ++++++++++++++++++ .../selftests/bpf/progs/memcg_async_reclaim.c | 181 +++++++ 3 files changed, 707 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/memcg_async_reclaim.c create mode 100644 tools/testing/selftests/bpf/progs/memcg_async_reclaim.c
Signature · 1 line
2.53.0
PATCH v5 1/2 mm/bpf: Add bpf_proactive_reclaim kfunc
From: Hui Zhu <[email protected]>
Add bpf_proactive_reclaim(), a sleepable kfunc which performs one proactive reclaim pass on a given memory cgroup, similar to a write to memory.reclaim but without retrying until the target is reached.
The kfunc refuses to reclaim if the calling task is already in a reclaim context, as a nested reclaim would corrupt the outer reclaim state.
--- mm/bpf_memcontrol.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
mm/bpf_memcontrol.c +46 -0
@@ -6,6 +6,7 @@*/ #include <linux/memcontrol.h> +#include <linux/swap.h> #include <linux/bpf.h> __bpf_kfunc_start_defs ();
@@ -159,6 +160,49 @@ __bpf_kfunc void bpf_mem_cgroup_flush_stats(struct mem_cgroup *memcg)mem_cgroup_flush_stats (memcg); } +/* +* Reclaim must not recurse: try_to_free_mem_cgroup_pages() overwrites +* current->reclaim_state, so a nested call would corrupt the outer +* reclaim state. Reclaim windows are marked with PF_MEMALLOC; +* reclaim_state is also checked because it is installed slightly +* before PF_MEMALLOC. +*/ +static bool bpf_in_reclaim_context (void ) +{ +return (current->flags &PF_MEMALLOC ) || current->reclaim_state; +} + +/** +* bpf_proactive_reclaim - proactively reclaim memory from a memory +* cgroup +* @memcg: the target memory cgroup to reclaim from +* @size: the amount of memory to reclaim, in bytes +* +* Trigger one proactive reclaim pass on @memcg, similar to a write to +* memory.reclaim, but without retrying until @size is reached. +* Must not be called with a filesystem lock held: the reclaim path +* may deadlock on it via filesystem shrinkers. +* +* Return: The amount of memory reclaimed, in bytes, or 0 if @size is +* smaller than a page or the task is already in a reclaim context. +*/ +__bpf_kfunc unsigned long bpf_proactive_reclaim (struct mem_cgroup *memcg, +unsigned long size) +{ +unsigned long nr_reclaimed; + +if (size <PAGE_SIZE ||unlikely (bpf_in_reclaim_context ())) +return 0 ; + + nr_reclaimed =try_to_free_mem_cgroup_pages (memcg, size /PAGE_SIZE , +GFP_KERNEL , +MEMCG_RECLAIM_MAY_SWAP | +MEMCG_RECLAIM_PROACTIVE , +NULL ); + +return nr_reclaimed *PAGE_SIZE ; +} +__bpf_kfunc_end_defs ();BTF_KFUNCS_START (bpf_memcontrol_kfuncs)
@@ -172,6 +216,8 @@ BTF_ID_FLAGS(func, bpf_mem_cgroup_usage) BTF_ID_FLAGS(func, bpf_mem_cgroup_page_state) BTF_ID_FLAGS(func, bpf_mem_cgroup_flush_stats, KF_SLEEPABLE) +BTF_ID_FLAGS(func, bpf_proactive_reclaim, KF_SLEEPABLE) +BTF_KFUNCS_END (bpf_memcontrol_kfuncs) static const struct btf_kfunc_id_set bpf_memcontrol_kfunc_set = {
Signature · 1 line
2.53.0
PATCH v5 2/2 selftests/bpf: Add memcg async reclaim test
In reply to Hui ZhuFrom: Hui Zhu <[email protected]>
Add the memcg_async_reclaim selftest, which verifies that BPF-driven async proactive reclaim mitigates refault-induced slowdown under memory pressure: a BPF program monitors the refault stats of a memory-pressured cgroup and, once they grow, asynchronously reclaims another cgroup via bpf_wq and bpf_proactive_reclaim(), letting the pressured workload finish faster.
--- .../bpf/prog_tests/memcg_async_reclaim.c | 480 ++++++++++++++++++ .../selftests/bpf/progs/memcg_async_reclaim.c | 181 +++++++ 2 files changed, 661 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/memcg_async_reclaim.c create mode 100644 tools/testing/selftests/bpf/progs/memcg_async_reclaim.c
tools/testing/selftests/bpf/prog_tests/memcg_async_reclaim.c new file +480 -0
@@ -0,0 +1,480 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Memory controller eBPF async reclaim test +*/ + +#include <test_progs.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <sys/vfs.h> +#include <sys/wait.h> +#include <fcntl.h> +#include <signal.h> +#include <time.h> +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <limits.h> +#include <linux/magic.h> + +#include "cgroup_helpers.h" + +struct bpf_args { +u64 high_cgroup_id; +u64 low_cgroup_id; +u64 event_delta_threshold; +u64 check_ns; +}; + +#include "memcg_async_reclaim.skel.h" + +#define FILE_SIZE (32 * 1024 * 1024ul) +#define BUFFER_SIZE (4096) +#define CG_LIMIT (32 * 1024 * 1024ul) +#define READ_TIMES 50 + +#define CG_DIR "/memcg_async_reclaim" +#define CG_HIGH_DIR CG_DIR "/high" +#define CG_LOW_DIR CG_DIR "/low" + +#define CHECK_PERIOD_NS (2 * 1000 * 1000ull) +#define EVENT_DELTA_THRESHOLD 1 + +/* +* The workload files must sit on a regular filesystem: with swap +* disabled for the cgroup, tmpfs/ramfs pages are unevictable and would +* OOM the cgroup instead of exercising reclaim; they are also charged +* as anonymous memory, so they never raise the WORKINGSET_REFAULT_FILE +* events the BPF program monitors. Fall back to the current directory +* when /tmp is backed by such a filesystem. +*/ +static const char *workload_files_dir (void ) +{ +struct statfs st; + +if (!statfs ("/tmp" , &st) && + (st.f_type ==TMPFS_MAGIC || st.f_type ==RAMFS_MAGIC )) +return "." ; +return "/tmp" ; +} + +/* +* The workload children run after test_progs hijacked stdio, so +* anything they print is lost with their private copy of the hijacked +* buffer. The exit status is the only diagnostics channel that reaches +* the parent, so each failing step gets its own code. +*/ +enum child_exit_code { +CHILD_EXIT_OK =0 , +CHILD_EXIT_JOIN_CGROUP , +CHILD_EXIT_WRITE_FILE , +CHILD_EXIT_READ_FILE , +CHILD_EXIT_TIME_FILE , +}; + +static const char *child_exit_str (int code) +{ +switch (code) { +case CHILD_EXIT_OK : +return "success" ; +case CHILD_EXIT_JOIN_CGROUP : +return "join cgroup" ; +case CHILD_EXIT_WRITE_FILE : +return "write data file" ; +case CHILD_EXIT_READ_FILE : +return "read data file" ; +case CHILD_EXIT_TIME_FILE : +return "write time file" ; +default : +return "unknown" ; + } +} + +static int setup_high_low_cgroups (u64 *high_cgroup_id,u64 *low_cgroup_id) +{ +int ret; +char limit_buf[20 ]; + + ret =setup_cgroup_environment (); +if (!ASSERT_OK (ret,"setup_cgroup_environment" )) + goto cleanup; + + ret =create_and_get_cgroup (CG_DIR ); +if (!ASSERT_GE (ret,0 ,"create_and_get_cgroup " CG_DIR )) + goto cleanup; +close (ret); + + ret =enable_controllers (CG_DIR ,"memory" ); +if (!ASSERT_OK (ret,"enable_controllers" )) + goto cleanup; + +snprintf (limit_buf,sizeof (limit_buf),"%lu" ,CG_LIMIT ); + ret =write_cgroup_file (CG_DIR ,"memory.max" , limit_buf); +if (!ASSERT_OK (ret,"write_cgroup_file memory.max" )) + goto cleanup; + +/* +* Keep the workloads from swapping out. With CONFIG_SWAP=n the +* memory.swap.max file does not exist, and no swap can happen +* anyway, so skip the write. +*/ +if (!access ("/proc/swaps" ,F_OK )) { + ret =write_cgroup_file (CG_DIR ,"memory.swap.max" ,"0" ); +if (!ASSERT_OK (ret,"write_cgroup_file memory.swap.max" )) + goto cleanup; + } + + ret =create_and_get_cgroup (CG_HIGH_DIR ); +if (!ASSERT_GE (ret,0 ,"create_and_get_cgroup " CG_HIGH_DIR )) + goto cleanup; +close (ret); + + *high_cgroup_id =get_cgroup_id (CG_HIGH_DIR ); +if (!ASSERT_GT (*high_cgroup_id,0 ,"get_cgroup_id" )) + goto cleanup; + + ret =create_and_get_cgroup (CG_LOW_DIR ); +if (!ASSERT_GE (ret,0 ,"create_and_get_cgroup " CG_LOW_DIR )) + goto cleanup; +close (ret); + + *low_cgroup_id =get_cgroup_id (CG_LOW_DIR ); +if (!ASSERT_GT (*low_cgroup_id,0 ,"get_cgroup_id" )) + goto cleanup; + +return 0 ; + +cleanup: +cleanup_cgroup_environment (); +return -1 ; +} + +static int write_file (const char *filename) +{ +int ret =-1 ; +size_t written =0 ; +char *buffer; +FILE *fp; + + fp =fopen (filename,"wb" ); +if (!fp) + goto out; + + buffer =malloc (BUFFER_SIZE ); +if (!buffer) + goto cleanup_fp; + +memset (buffer,'A' ,BUFFER_SIZE ); + +while (written <FILE_SIZE ) { +size_t to_write =FILE_SIZE - written <BUFFER_SIZE ? +FILE_SIZE - written :BUFFER_SIZE ; + +if (fwrite (buffer,1 , to_write, fp) != to_write) + goto cleanup; + written += to_write; + } + + ret =0 ; +cleanup: +free (buffer); +cleanup_fp: +fclose (fp); +out: +return ret; +} + +static int read_file (const char *filename,int iterations) +{ +int ret =-1 ; +long page_size =sysconf (_SC_PAGESIZE); +char *map; +size_t i; +int fd; +struct stat sb; + + fd =open (filename,O_RDONLY ); +if (fd ==-1 ) + goto out; + +if (fstat (fd, &sb) ==-1 ) + goto cleanup_fd; + +if (sb.st_size !=FILE_SIZE ) { +fprintf (stderr,"File size mismatch: expected %lu, got %lu\n" , + (unsigned long )FILE_SIZE , (unsigned long )sb.st_size); + goto cleanup_fd; + } + + map =mmap (NULL ,FILE_SIZE ,PROT_READ ,MAP_PRIVATE , fd,0 ); +if (map ==MAP_FAILED ) + goto cleanup_fd; + +for (int iter =0 ; iter < iterations; iter++) { +for (i =0 ; i <FILE_SIZE ; i += page_size) { +/* access a byte to trigger page fault */ +volatile char v = map[i]; + (void )v; + } + } + +if (munmap (map,FILE_SIZE ) ==-1 ) + goto cleanup_fd; + + ret =0 ; + +cleanup_fd: +close (fd); +out: +return ret; +} + +static int real_test_child_work (const char *cgroup_path,char *data_filename, +char *time_filename,int read_times) +{ +struct timespec start, end; +double elapsed; +FILE *fp; + +if (join_parent_cgroup (cgroup_path)) +return CHILD_EXIT_JOIN_CGROUP ; + +clock_gettime (CLOCK_MONOTONIC , &start); + +if (write_file (data_filename)) +return CHILD_EXIT_WRITE_FILE ; + +if (read_file (data_filename, read_times)) +return CHILD_EXIT_READ_FILE ; + +clock_gettime (CLOCK_MONOTONIC , &end); + +if (!time_filename) +return CHILD_EXIT_OK ; + + elapsed = (end.tv_sec - start.tv_sec) + + (end.tv_nsec - start.tv_nsec) /1000000000.0 ; +printf ("%.6f\n" , elapsed); + + fp =fopen (time_filename,"w" ); +if (!fp) +return CHILD_EXIT_TIME_FILE ; +fprintf (fp,"%.6f" , elapsed); +fclose (fp); + +return CHILD_EXIT_OK ; +} + +static int get_time (char *time_filename,double *time) +{ +int ret =-1 ; +FILE *fp; +char buf[64 ]; + + fp =fopen (time_filename,"r" ); +if (!ASSERT_OK_PTR (fp,"fopen" )) + goto out; + +if (!ASSERT_OK_PTR (fgets (buf,sizeof (buf), fp),"fgets" )) + goto cleanup; + +if (sscanf (buf,"%lf" , time) !=1 ) { +PRINT_FAIL ("sscanf %s" , buf); + goto cleanup; + } + + ret =0 ; +cleanup: +fclose (fp); +out: +return ret; +} + +static int +run_high_low_workload (double *high_elapsed,double *low_elapsed,int read_times) +{ +char high_data_file[PATH_MAX ]; +char low_data_file[PATH_MAX ]; +char high_time_file[PATH_MAX ]; +char low_time_file[PATH_MAX ]; +const char *dir =workload_files_dir (); +pid_t high_pid =-1 , low_pid =-1 ; +pid_t wait_ret; +int fd, status; +int ret =-1 ; + +snprintf (high_data_file,sizeof (high_data_file), +"%s/memcg_async_high_data_XXXXXX" , dir); +snprintf (low_data_file,sizeof (low_data_file), +"%s/memcg_async_low_data_XXXXXX" , dir); +snprintf (high_time_file,sizeof (high_time_file), +"%s/memcg_async_high_time_XXXXXX" , dir); +snprintf (low_time_file,sizeof (low_time_file), +"%s/memcg_async_low_time_XXXXXX" , dir); + + fd =mkstemp (high_data_file); +if (!ASSERT_GE (fd,0 ,"mkstemp" )) + goto cleanup; +close (fd); + + fd =mkstemp (low_data_file); +if (!ASSERT_GE (fd,0 ,"mkstemp" )) + goto cleanup; +close (fd); + + fd =mkstemp (high_time_file); +if (!ASSERT_GE (fd,0 ,"mkstemp" )) + goto cleanup; +close (fd); + + fd =mkstemp (low_time_file); +if (!ASSERT_GE (fd,0 ,"mkstemp" )) + goto cleanup; +close (fd); + + low_pid =fork (); +if (!ASSERT_GE (low_pid,0 ,"fork low" )) + goto cleanup; +if (low_pid ==0 ) +_exit (real_test_child_work (CG_LOW_DIR , low_data_file, + low_time_file, read_times)); + + high_pid =fork (); +if (!ASSERT_GE (high_pid,0 ,"fork high" )) + goto cleanup; +if (high_pid ==0 ) +_exit (real_test_child_work (CG_HIGH_DIR , high_data_file, + high_time_file, read_times)); + + wait_ret =waitpid (low_pid, &status,0 ); +if (!ASSERT_GT (wait_ret,0 ,"low waitpid" )) + goto cleanup; +/* +* The child has been reaped and its PID can already be reused, +* so mark it to keep cleanup from signaling an unrelated process. +*/ + low_pid =-1 ; +if (!ASSERT_TRUE (WIFEXITED (status),"low exited" )) + goto cleanup; +if (WEXITSTATUS (status) !=CHILD_EXIT_OK ) { +PRINT_FAIL ("low child failed at: %s (exit status %d)" , +child_exit_str (WEXITSTATUS (status)), +WEXITSTATUS (status)); + goto cleanup; + } + + wait_ret =waitpid (high_pid, &status,0 ); +if (!ASSERT_GT (wait_ret,0 ,"high waitpid" )) + goto cleanup; +/* Same as above: the reaped PID must not be signaled again. */ + high_pid =-1 ; +if (!ASSERT_TRUE (WIFEXITED (status),"high exited" )) + goto cleanup; +if (WEXITSTATUS (status) !=CHILD_EXIT_OK ) { +PRINT_FAIL ("high child failed at: %s (exit status %d)" , +child_exit_str (WEXITSTATUS (status)), +WEXITSTATUS (status)); + goto cleanup; + } + +if (get_time (high_time_file, high_elapsed)) + goto cleanup; +if (get_time (low_time_file, low_elapsed)) + goto cleanup; + + ret =0 ; + +cleanup: +/* On failure, make sure no child process is left behind */ +if (ret) { +if (high_pid >0 ) { +kill (high_pid,SIGKILL ); + (void )waitpid (high_pid,NULL ,0 ); + } +if (low_pid >0 ) { +kill (low_pid,SIGKILL ); + (void )waitpid (low_pid,NULL ,0 ); + } + } +unlink (low_time_file); +unlink (high_time_file); +unlink (low_data_file); +unlink (high_data_file); +return ret; +} + +static int +setup_bpf (u64 high_cgroup_id,u64 low_cgroup_id, +struct memcg_async_reclaim **skel_ptr) +{ +struct memcg_async_reclaim *skel; +struct bpf_args args = { + .high_cgroup_id = high_cgroup_id, + .low_cgroup_id = low_cgroup_id, + .event_delta_threshold =EVENT_DELTA_THRESHOLD , + .check_ns =CHECK_PERIOD_NS , + }; +LIBBPF_OPTS (bpf_test_run_opts, run_opts, + .ctx_in = &args, + .ctx_size_in = sizeof(args)); +int prog_init_fd, err; + + skel =memcg_async_reclaim__open_and_load (); +if (!ASSERT_OK_PTR (skel,"memcg_async_reclaim__open_and_load" )) +return -1 ; + + prog_init_fd =bpf_program__fd (skel->progs.wq_prog_init); + + err =bpf_prog_test_run_opts (prog_init_fd, &run_opts); +if (!ASSERT_OK (err,"bpf_prog_test_run_opts" )) + goto error_out; +if (!ASSERT_EQ (run_opts.retval,0 ,"prog_init retval" )) + goto error_out; + + *skel_ptr = skel; +return 0 ; + +error_out: +memcg_async_reclaim__destroy (skel); +return -1 ; +} + +void test_memcg_async_reclaim (void ) +{ +u64 high_cgroup_id, low_cgroup_id; +int err; +double high_time =0.0 , low_time =0.0 ; +struct memcg_async_reclaim *skel =NULL ; + + err =setup_high_low_cgroups (&high_cgroup_id, &low_cgroup_id); +if (!ASSERT_OK (err,"setup_high_low_cgroups reclaim" )) +return ; + + err =setup_bpf (high_cgroup_id, low_cgroup_id, &skel); +if (!ASSERT_OK (err,"setup_bpf" )) + goto out; + + err =run_high_low_workload (&high_time, &low_time,READ_TIMES ); +if (!ASSERT_OK (err,"run_high_low_workload reclaim" )) + goto out; + +/* +* The timing comparison below alone cannot distinguish a working +* reclaim from a no-op one, so require that the BPF program +* actually reclaimed memory from the low cgroup. +*/ +if (!ASSERT_GT (skel->bss->reclaim_calls,0 ,"reclaim_calls" )) + goto out; +if (!ASSERT_GT (skel->bss->reclaimed_bytes,0 ,"reclaimed_bytes" )) + goto out; + +if (high_time >= low_time) +PRINT_FAIL ("high cgroup not improved: high=%f low=%f" , + high_time, low_time); + +out: +if (skel) +memcg_async_reclaim__destroy (skel); +cleanup_cgroup_environment (); +}
tools/testing/selftests/bpf/progs/memcg_async_reclaim.c new file +181 -0
181 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH bpf-next v5 2/2] selftests/bpf: Add memcg async reclaim test
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Medium] Insecure temporary file creation (Time-of-Check to Time-of-Use symlink attack)
Pre-existing issues:
- [High] Missing negative bounds check for enum in BPF memory controller kfuncs --
commit d790568f8e67742a221eaf1bb57e732d1d035f32
Author: Hui Zhu <[email protected]>
selftests/bpf: Add memcg async reclaim test
This commit adds the memcg_async_reclaim selftest to verify that BPF-driven async proactive reclaim mitigates refault-induced slowdown under memory pressure.
[Severity: High]
This is a pre-existing issue, but there is a missing negative bounds check for enum arguments in the BPF memory controller kfuncs.
In mm/bpf_memcontrol.c:bpf_mem_cgroup_memory_events():
if (unlikely(event >= MEMCG_NR_MEMORY_EVENTS))
return (unsigned long)-1;
And similarly in mm/memcontrol.c:memcg_vm_event_item_valid():
if (idx >= NR_VM_EVENT_ITEMS)
return false;
Because enum types in C are signed integers, these signed comparisons allow negative values to bypass the bounds check. A BPF program calling these kfuncs with a negative integer value can bypass the check, leading directly to an out-of-bounds kernel memory read. Since the BPF verifier permits this (the enum parameter is not constrained by __const), could this allow information disclosure for users with CAP_BPF?
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/memcg_async_reclaim.c new file +0
-0
[ ... ]
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/memcg_async_reclaim.c new file +10
-0+static int write_file (const char *filename) +{ +int ret =-1 ; +size_t written =0 ; +char *buffer; +FILE *fp; + + fp =fopen (filename,"wb" ); +if (!fp) + goto out;
[ ... ]
Quoted 16 lines
tools/testing/selftests/bpf/prog_tests/memcg_async_reclaim.c new file +16
-0+static int +run_high_low_workload (double *high_elapsed,double *low_elapsed,int read_times) +{ +char high_data_file[PATH_MAX ]; +char low_data_file[PATH_MAX ]; +char high_time_file[PATH_MAX ]; +char low_time_file[PATH_MAX ]; +const char *dir =workload_files_dir (); +pid_t high_pid =-1 , low_pid =-1 ; +pid_t wait_ret; +int fd, status; +int ret =-1 ; + +snprintf (high_data_file,sizeof (high_data_file), +"%s/memcg_async_high_data_XXXXXX" , dir); + snprintf(low_data_file, sizeof(low_data_file),
tools/testing/selftests/bpf/prog_tests/memcg_async_reclaim.c line 319
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/memcg_async_reclaim.c new file +10
-0+ "%s/memcg_async_low_data_XXXXXX", dir); +snprintf (high_time_file,sizeof (high_time_file), +"%s/memcg_async_high_time_XXXXXX" , dir); +snprintf (low_time_file,sizeof (low_time_file), +"%s/memcg_async_low_time_XXXXXX" , dir); + + fd =mkstemp (high_data_file); +if (!ASSERT_GE (fd,0 ,"mkstemp" )) + goto cleanup; +close (fd);
[Severity: Medium]
Is there a potential Time-of-Check to Time-of-Use (TOCTOU) symlink vulnerability here?
The test uses mkstemp() to securely create temporary files, but immediately closes the file descriptor. Later, the child process opens the file by name in write_file() using fopen(filename, "wb").
If the test is run in a shared temporary directory (like /tmp), could a local attacker replace the temporary file with a symlink to another file on the system during the window between close() and fopen()? Since the test process typically runs as root, this would follow the symlink and overwrite the target file.
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH bpf-next v5 1/2] mm/bpf: Add bpf_proactive_reclaim kfunc
In reply to Hui ZhuThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] BPF kfunc `bpf_proactive_reclaim` can cause kernel deadlocks by triggering memory reclaim with…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] BPF kfunc bpf_proactive_reclaim can cause kernel deadlocks by triggering memory reclaim with GFP_KERNEL from sleepable contexts where filesystem or IO locks may be held.
- [Medium] Integer overflow in calculating the returned reclaimed bytes on 32-bit architectures.
--
commit ef066c78e33635cc7e9aa0fc78438725da7dc30b
Author: Hui Zhu <[email protected]>
mm/bpf: Add bpf_proactive_reclaim kfunc
This commit adds a sleepable kfunc bpf_proactive_reclaim() which performs one proactive reclaim pass on a given memory cgroup. It refuses to reclaim if the calling task is already in a reclaim context to avoid corrupting the outer reclaim state.
Quoted 4 lines
mm/bpf_memcontrol.c +0
-0
[ ... ]
Quoted 3 lines
mm/bpf_memcontrol.c +0
-0@@ -159,6 +160,49 @@ __bpf_kfunc void bpf_mem_cgroup_flush_stats(struct mem_cgroup *memcg)mem_cgroup_flush_stats (memcg); }
[ ... ]
mm/bpf_memcontrol.c __bpf_kfunc void bpf_mem_cgroup_flush_stats(struct mem_cgroup *memcg) · line 198
Quoted 10 lines
mm/bpf_memcontrol.c +10
-0+__bpf_kfunc unsigned long bpf_proactive_reclaim (struct mem_cgroup *memcg, +unsigned long size) +{ +unsigned long nr_reclaimed; + +if (size <PAGE_SIZE ||unlikely (bpf_in_reclaim_context ())) +return 0 ; + + nr_reclaimed = try_to_free_mem_cgroup_pages(memcg, size / PAGE_SIZE, + GFP_KERNEL,
[Severity: High]
Can this cause a kernel deadlock when called from sleepable contexts where filesystem or IO locks may be held?
Since GFP_KERNEL includes __GFP_FS and __GFP_IO, the direct reclaim path is allowed to invoke filesystem shrinkers. If a shrinker attempts to acquire a lock already held by the task (e.g., if a sleepable BPF program attached to an LSM hook like inode_rmdir or security_file_open calls bpf_proactive_reclaim), a self-deadlock could occur.
Would it be safer to wrap the reclaim call in memalloc_nofs_save() and memalloc_nofs_restore() to guarantee safety, as the verifier cannot statically enforce that no filesystem locks are held?
mm/bpf_memcontrol.c __bpf_kfunc void bpf_mem_cgroup_flush_stats(struct mem_cgroup *memcg) · line 203
Quoted 5 lines
mm/bpf_memcontrol.c +5
-0+MEMCG_RECLAIM_MAY_SWAP | +MEMCG_RECLAIM_PROACTIVE , + NULL); + +return nr_reclaimed *PAGE_SIZE ;
[Severity: Medium]
Does this calculation overflow the 32-bit boundary before returning to the caller?
On 32-bit architectures, unsigned long is 32 bits, making ULONG_MAX approximately 4GB. If a user requests a reclaim pass with size close to ULONG_MAX, the target pages will be close to 1,048,575.
try_to_free_mem_cgroup_pages() reclaims in batches and can easily overshoot the target.
If nr_reclaimed exceeds 1,048,575 pages, multiplying it by PAGE_SIZE (4096) will wrap around the 32-bit limit, yielding a severely truncated result.
Quoted 1 line
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH bpf-next v5 1/2] mm/bpf: Add bpf_proactive_reclaim kfunc
In reply to Hui ZhuThis isn't a bug, but could the changelog say why this kfunc is needed - the intended consumer, and why a single non-retrying pass is preferred over what a write to memory.reclaim does - rather than…
Quoted 11 lines
mm/bpf: Add
bpf_proactive_reclaimkfuncAdd
bpf_proactive_reclaim(), a sleepable kfunc which performs one proactive reclaim pass on a given memory cgroup, similar to a write to memory.reclaim but without retrying until the target is reached.The kfunc refuses to reclaim if the calling task is already in a reclaim context, as a nested reclaim would corrupt the outer reclaim state.
Signed-off-by Hui Zhu <[email protected]>
This isn't a bug, but could the changelog say why this kfunc is needed - the intended consumer, and why a single non-retrying pass is preferred over what a write to memory.reclaim does - rather than restating what the function does?
Quoted 4 lines
mm/bpf_memcontrol.c +0
-0
[ ... ]
Quoted 51 lines
mm/bpf_memcontrol.c +43
-0@@ -159,6 +160,49 @@ __bpf_kfunc void bpf_mem_cgroup_flush_stats(struct mem_cgroup *memcg)mem_cgroup_flush_stats (memcg); } +/* +* Reclaim must not recurse: try_to_free_mem_cgroup_pages() overwrites +* current->reclaim_state, so a nested call would corrupt the outer +* reclaim state. Reclaim windows are marked with PF_MEMALLOC; +* reclaim_state is also checked because it is installed slightly +* before PF_MEMALLOC. +*/ +static bool bpf_in_reclaim_context (void ) +{ +return (current->flags &PF_MEMALLOC ) || current->reclaim_state; +} + +/** +* bpf_proactive_reclaim - proactively reclaim memory from a memory +* cgroup +* @memcg: the target memory cgroup to reclaim from +* @size: the amount of memory to reclaim, in bytes +* +* Trigger one proactive reclaim pass on @memcg, similar to a write to +* memory.reclaim, but without retrying until @size is reached. +* Must not be called with a filesystem lock held: the reclaim path +* may deadlock on it via filesystem shrinkers. +* +* Return: The amount of memory reclaimed, in bytes, or 0 if @size is +* smaller than a page or the task is already in a reclaim context. +*/ +__bpf_kfunc unsigned long bpf_proactive_reclaim (struct mem_cgroup *memcg, +unsigned long size) +{ +unsigned long nr_reclaimed; + +if (size <PAGE_SIZE ||unlikely (bpf_in_reclaim_context ())) +return 0 ; + + nr_reclaimed =try_to_free_mem_cgroup_pages (memcg, size /PAGE_SIZE , +GFP_KERNEL , +MEMCG_RECLAIM_MAY_SWAP | +MEMCG_RECLAIM_PROACTIVE , +NULL ); + +return nr_reclaimed *PAGE_SIZE ; +} +__bpf_kfunc_end_defs ();BTF_KFUNCS_START (bpf_memcontrol_kfuncs)
mm/bpf_memcontrol.c BTF_ID_FLAGS(func, bpf_mem_cgroup_usage) · line 220
Quoted 5 lines
mm/bpf_memcontrol.c +2
-0@@ -172,6 +216,8 @@ BTF_ID_FLAGS(func, bpf_mem_cgroup_usage) BTF_ID_FLAGS(func, bpf_mem_cgroup_page_state) BTF_ID_FLAGS(func, bpf_mem_cgroup_flush_stats, KF_SLEEPABLE) +BTF_ID_FLAGS (func, bpf_proactive_reclaim,KF_SLEEPABLE ) +
This isn't a bug, but would it be worth extending tools/testing/selftests/bpf/progs/cgroup_iter_memcg.c (or adding a small test) to exercise bpf_proactive_reclaim? The sibling kfuncs registered in the same set (bpf_get_mem_cgroup, bpf_mem_cgroup_flush_stats, bpf_mem_cgroup_page_state, bpf_mem_cgroup_vm_events) are all exercised by that test, and a test would pin down the byte units and the 'returns 0' cases.
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/33064477499
[email protected]
AI reviewRe: [PATCH bpf-next v5 2/2] selftests/bpf: Add memcg async reclaim test
In reply to Hui ZhuThe three PRINT_FAIL() calls in run_high_low_workload() omit the trailing newline, so the failure messages run into whatever is logged next. PRINT_FAIL() in test_progs.h does not append a newline:
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/memcg_async_reclaim.c new file +0
-0
[ ... ]
Quoted 20 lines
tools/testing/selftests/bpf/prog_tests/memcg_async_reclaim.c new file +20
-0+ wait_ret =waitpid (low_pid, &status,0 ); +if (!ASSERT_GT (wait_ret,0 ,"low waitpid" )) + goto cleanup; +/* +* The child has been reaped and its PID can already be reused, +* so mark it to keep cleanup from signaling an unrelated process. +*/ + low_pid =-1 ; +if (!ASSERT_TRUE (WIFEXITED (status),"low exited" )) + goto cleanup; +if (WEXITSTATUS (status) !=CHILD_EXIT_OK ) { +PRINT_FAIL ("low child failed at: %s (exit status %d)" , +child_exit_str (WEXITSTATUS (status)), +WEXITSTATUS (status)); + goto cleanup; + } + + wait_ret =waitpid (high_pid, &status,0 ); +if (!ASSERT_GT (wait_ret,0 ,"high waitpid" )) + goto cleanup;
tools/testing/selftests/bpf/prog_tests/memcg_async_reclaim.c line 379
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/memcg_async_reclaim.c new file +10
-0+/* Same as above: the reaped PID must not be signaled again. */ + high_pid =-1 ; +if (!ASSERT_TRUE (WIFEXITED (status),"high exited" )) + goto cleanup; +if (WEXITSTATUS (status) !=CHILD_EXIT_OK ) { +PRINT_FAIL ("high child failed at: %s (exit status %d)" , +child_exit_str (WEXITSTATUS (status)), +WEXITSTATUS (status)); + goto cleanup; + }
The three PRINT_FAIL() calls in run_high_low_workload() omit the trailing newline, so the failure messages run into whatever is logged next. PRINT_FAIL() in test_progs.h does not append a newline:
#define PRINT_FAIL(format...) \
({ \
test__fail(); \
fprintf(stdout, "%s:FAIL:%d ", __func__, __LINE__); \
fprintf(stdout, ##format); \
})Since test_progs hijacks stdout into an open_memstream() buffer that is dumped verbatim, the missing newline concatenates these lines with the following log output. The dominant convention in prog_tests/ is to terminate the format string (33 of the ~44 PRINT_FAIL() call sites end in "\n").
Should these three PRINT_FAIL() calls (the two shown above and the one after the high_time/low_time comparison) end with "\n"?
Quoted 5 lines
tools/testing/selftests/bpf/progs/memcg_async_reclaim.c new file +0
-0
[ ... ]
Quoted 11 lines
tools/testing/selftests/bpf/progs/memcg_async_reclaim.c new file +11
-0+static int reclaim_cgroup (u64 cgroup_id) +{ +struct cgroup_memcg cm; +int i; + +if (get_cgroup_memcg_from_id (cgroup_id, &cm)) +return 0 ; + + reclaim_calls++; +for (i =0 ; i <RECLAIM_MAX_ITER ; i++) { +u64 nr =bpf_proactive_reclaim (cm.memcg,RECLAIM_SIZE );
tools/testing/selftests/bpf/progs/memcg_async_reclaim.c line 106
Quoted 10 lines
tools/testing/selftests/bpf/progs/memcg_async_reclaim.c new file +10
-0+ +if (!nr) +break ; + reclaimed_bytes += nr; + } + +put_cgroup_memcg (&cm); + +return 0 ; +}
This isn't a bug, but reclaim_cgroup() is declared to return int but returns 0 on every path, including the lookup-failure path, and its only caller discards the value:
reclaim_work_fn() {
...
if (should_reclaim_cgroup(...)) {
reclaim_cgroup(wq_low_cgroup_id);
bpf_wq_start(&elem->work, 0);
}
...
}The failure to obtain the memcg is therefore indistinguishable from success. The file already uses void where a helper has no result (put_cgroup_memcg), so would it make sense to make reclaim_cgroup() void, or to return -1 on the lookup failure and react to it?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/33064477499
Shakeel Butt
maintainerRe: [PATCH bpf-next v5 1/2] mm/bpf: Add bpf_proactive_reclaim kfunc
In reply to Hui ZhuQuoted 54 lines · Hui Zhu
From: Hui Zhu <[email protected]>
Add
bpf_proactive_reclaim(), a sleepable kfunc which performs one proactive reclaim pass on a given memory cgroup, similar to a write to memory.reclaim but without retrying until the target is reached.The kfunc refuses to reclaim if the calling task is already in a reclaim context, as a nested reclaim would corrupt the outer reclaim state.
Signed-off-by Hui Zhu <[email protected]>--- mm/bpf_memcontrol.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)mm/bpf_memcontrol.c +24
-0@@ -6,6 +6,7 @@*/ #include <linux/memcontrol.h> +#include <linux/swap.h> #include <linux/bpf.h> __bpf_kfunc_start_defs ();@@ -159,6 +160,49 @@ __bpf_kfunc void bpf_mem_cgroup_flush_stats(struct mem_cgroup *memcg)mem_cgroup_flush_stats (memcg); } +/* +* Reclaim must not recurse: try_to_free_mem_cgroup_pages() overwrites +* current->reclaim_state, so a nested call would corrupt the outer +* reclaim state. Reclaim windows are marked with PF_MEMALLOC; +* reclaim_state is also checked because it is installed slightly +* before PF_MEMALLOC. +*/ +static bool bpf_in_reclaim_context (void ) +{ +return (current->flags &PF_MEMALLOC ) || current->reclaim_state; +} + +/** +* bpf_proactive_reclaim - proactively reclaim memory from a memory +* cgroup +* @memcg: the target memory cgroup to reclaim from +* @size: the amount of memory to reclaim, in bytes +* +* Trigger one proactive reclaim pass on @memcg, similar to a write to +* memory.reclaim, but without retrying until @size is reached. +* Must not be called with a filesystem lock held: the reclaim path +* may deadlock on it via filesystem shrinkers. +*
mm/bpf_memcontrol.c __bpf_kfunc void bpf_mem_cgroup_flush_stats(struct mem_cgroup *memcg) · line 195
Quoted 10 lines
mm/bpf_memcontrol.c +10
-0+* Return: The amount of memory reclaimed, in bytes, or 0 if @size is +* smaller than a page or the task is already in a reclaim context. +*/ +__bpf_kfunc unsigned long bpf_proactive_reclaim (struct mem_cgroup *memcg, +unsigned long size) +{ +unsigned long nr_reclaimed; + +if (size <PAGE_SIZE ||unlikely (bpf_in_reclaim_context ())) +return 0 ;
I have been thinking about this more and more and after looking at the reasoning behind your check current->reclaim_state and also Sashiko's comment on NOIO/NOFS contexts, I am more convinced that this kfunc can not be a simple sleepable function. We need more than that. We need clean process context as well similar to the userspace poking memory.reclaim. Something like kthread or workqueue.
Kumar & Andrii, is there a way to restrict a kfunc to only be called from special BPF threads/workqueues? Is there some similar concept in BPF world?
Quoted 25 lines
mm/bpf_memcontrol.c +12
-0+ + nr_reclaimed =try_to_free_mem_cgroup_pages (memcg, size /PAGE_SIZE , +GFP_KERNEL , +MEMCG_RECLAIM_MAY_SWAP | +MEMCG_RECLAIM_PROACTIVE , +NULL ); + +return nr_reclaimed *PAGE_SIZE ; +} +__bpf_kfunc_end_defs ();BTF_KFUNCS_START (bpf_memcontrol_kfuncs)@@ -172,6 +216,8 @@ BTF_ID_FLAGS(func, bpf_mem_cgroup_usage) BTF_ID_FLAGS(func, bpf_mem_cgroup_page_state) BTF_ID_FLAGS(func, bpf_mem_cgroup_flush_stats, KF_SLEEPABLE) +BTF_ID_FLAGS(func, bpf_proactive_reclaim, KF_SLEEPABLE) +BTF_KFUNCS_END (bpf_memcontrol_kfuncs) static const struct btf_kfunc_id_set bpf_memcontrol_kfunc_set = {Signature · 1 line
2.53.0
Kumar Kartikeya Dwivedi
maintainerRe: [PATCH bpf-next v5 1/2] mm/bpf: Add bpf_proactive_reclaim kfunc
Quoted 72 lines · Shakeel Butt
Quoted 54 lines · Hui Zhu
From: Hui Zhu <[email protected]>
Add
bpf_proactive_reclaim(), a sleepable kfunc which performs one proactive reclaim pass on a given memory cgroup, similar to a write to memory.reclaim but without retrying until the target is reached.The kfunc refuses to reclaim if the calling task is already in a reclaim context, as a nested reclaim would corrupt the outer reclaim state.
Signed-off-by Hui Zhu <[email protected]>--- mm/bpf_memcontrol.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)mm/bpf_memcontrol.c +24
-0@@ -6,6 +6,7 @@*/ #include <linux/memcontrol.h> +#include <linux/swap.h> #include <linux/bpf.h> __bpf_kfunc_start_defs ();@@ -159,6 +160,49 @@ __bpf_kfunc void bpf_mem_cgroup_flush_stats(struct mem_cgroup *memcg)mem_cgroup_flush_stats (memcg); } +/* +* Reclaim must not recurse: try_to_free_mem_cgroup_pages() overwrites +* current->reclaim_state, so a nested call would corrupt the outer +* reclaim state. Reclaim windows are marked with PF_MEMALLOC; +* reclaim_state is also checked because it is installed slightly +* before PF_MEMALLOC. +*/ +static bool bpf_in_reclaim_context (void ) +{ +return (current->flags &PF_MEMALLOC ) || current->reclaim_state; +} + +/** +* bpf_proactive_reclaim - proactively reclaim memory from a memory +* cgroup +* @memcg: the target memory cgroup to reclaim from +* @size: the amount of memory to reclaim, in bytes +* +* Trigger one proactive reclaim pass on @memcg, similar to a write to +* memory.reclaim, but without retrying until @size is reached. +* Must not be called with a filesystem lock held: the reclaim path +* may deadlock on it via filesystem shrinkers. +* mm/bpf_memcontrol.c __bpf_kfunc void bpf_mem_cgroup_flush_stats(struct mem_cgroup *memcg) · line 195
Quoted 10 lines
mm/bpf_memcontrol.c +10
-0+* Return: The amount of memory reclaimed, in bytes, or 0 if @size is +* smaller than a page or the task is already in a reclaim context. +*/ +__bpf_kfunc unsigned long bpf_proactive_reclaim (struct mem_cgroup *memcg, +unsigned long size) +{ +unsigned long nr_reclaimed; + +if (size <PAGE_SIZE ||unlikely (bpf_in_reclaim_context ())) +return 0 ;I have been thinking about this more and more and after looking at the reasoning behind your check
current->reclaim_stateand also Sashiko's comment on NOIO/NOFS contexts, I am more convinced that this kfunc can not be a simple sleepable function. We need more than that. We need clean process context as well similar to the userspace poking memory.reclaim. Something like kthread or workqueue.
Quoted 3 lines
Kumar & Andrii, is there a way to restrict a kfunc to only be called from special BPF threads/workqueues? Is there some similar concept in BPF world?
Yeah, I think the concern is valid. E.g. inode_rmdir() is sleepable but will be problematic here, I think. My first instinct was if bpf_in_reclaim_context() + nofs/noio save-restore might provide enough protection to let it be callable from generic sleepable contexts, but I guess that will disable invocation of filesystem shrinkers unconditionally.
So my suggestion would be to fix the context to BPF_PROG_TYPE_SYSCALL. There, we should be able to init and schedule timers which poll specific state and arms wq execution etc. It then remains invocable from sleepable async contexts (wq, task_work) or the syscall program, all of which should be ok. Once BPF kthread lands we can let it be callable from those threads as well, but that is for later.
Quoted 1 line
[...]
Re: [PATCH bpf-next v5 1/2] mm/bpf: Add bpf_proactive_reclaim kfunc
Quoted 82 lines · Shakeel Butt
Quoted 71 lines · Hui Zhu
Quoted 54 lines
From: Hui Zhu <[email protected]>
Add
bpf_proactive_reclaim(), a sleepable kfunc which performs one proactive reclaim pass on a given memory cgroup, similar to a write to memory.reclaim but without retrying until the target is reached.The kfunc refuses to reclaim if the calling task is already in a reclaim context, as a nested reclaim would corrupt the outer reclaim state.
Signed-off-by Hui Zhu <[email protected]>--- mm/bpf_memcontrol.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)mm/bpf_memcontrol.c +24
-0@@ -6,6 +6,7 @@*/ #include <linux/memcontrol.h> +#include <linux/swap.h> #include <linux/bpf.h> __bpf_kfunc_start_defs ();@@ -159,6 +160,49 @@ __bpf_kfunc void bpf_mem_cgroup_flush_stats(struct mem_cgroup *memcg)mem_cgroup_flush_stats (memcg); } +/* +* Reclaim must not recurse: try_to_free_mem_cgroup_pages() overwrites +* current->reclaim_state, so a nested call would corrupt the outer +* reclaim state. Reclaim windows are marked with PF_MEMALLOC; +* reclaim_state is also checked because it is installed slightly +* before PF_MEMALLOC. +*/ +static bool bpf_in_reclaim_context (void ) +{ +return (current->flags &PF_MEMALLOC ) || current->reclaim_state; +} + +/** +* bpf_proactive_reclaim - proactively reclaim memory from a memory +* cgroup +* @memcg: the target memory cgroup to reclaim from +* @size: the amount of memory to reclaim, in bytes +* +* Trigger one proactive reclaim pass on @memcg, similar to a write to +* memory.reclaim, but without retrying until @size is reached. +* Must not be called with a filesystem lock held: the reclaim path +* may deadlock on it via filesystem shrinkers. +* mm/bpf_memcontrol.c __bpf_kfunc void bpf_mem_cgroup_flush_stats(struct mem_cgroup *memcg) · line 195
Quoted 10 lines
mm/bpf_memcontrol.c +10
-0+* Return: The amount of memory reclaimed, in bytes, or 0 if @size is +* smaller than a page or the task is already in a reclaim context. +*/ +__bpf_kfunc unsigned long bpf_proactive_reclaim (struct mem_cgroup *memcg, +unsigned long size) +{ +unsigned long nr_reclaimed; + +if (size <PAGE_SIZE ||unlikely (bpf_in_reclaim_context ())) +return 0 ;I have been thinking about this more and more and after looking at the reasoning behind your check
current->reclaim_stateand also Sashiko's comment on NOIO/NOFS contexts, I am more convinced that this kfunc can not be a simple sleepable function. We need more than that. We need clean process context as well similar to the userspace poking memory.reclaim. Something like kthread or workqueue.Quoted 3 lines
Kumar & Andrii, is there a way to restrict a kfunc to only be called from special BPF threads/workqueues? Is there some similar concept in BPF world?
Yeah, I think the concern is valid. E.g.
inode_rmdir()is sleepable but will be problematic here, I think. My first instinct was ifbpf_in_reclaim_context()+ nofs/noio save-restore might provide enough protection to let it be callable from generic sleepable contexts, but I guess that will disable invocation of filesystem shrinkers unconditionally.
Quoted 6 lines
So my suggestion would be to fix the context to
BPF_PROG_TYPE_SYSCALL. There, we should be able to init and schedule timers which poll specific state and arms wq execution etc. It then remains invocable from sleepable async contexts (wq,task_work) or the syscall program, all of which should be ok. Once BPF kthread lands we can let it be callable from those threads as well, but that is for later.
Hi Kumar and Shakeel,
The patch has been modified according to your comments.
Please help me review it.
Best,
Hui
Quoted 1 line
Quoted 1 line
[...]