Skip to content

mm: Add ptep_try_set() for lockless empty-slot installs#12163

Open
kernel-patches-daemon-bpf[bot] wants to merge 1 commit into
bpf_basefrom
series/1099523=>bpf
Open

mm: Add ptep_try_set() for lockless empty-slot installs#12163
kernel-patches-daemon-bpf[bot] wants to merge 1 commit into
bpf_basefrom
series/1099523=>bpf

Conversation

@kernel-patches-daemon-bpf
Copy link
Copy Markdown

Pull request for series with
subject: mm: Add ptep_try_set() for lockless empty-slot installs
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1099523

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 49b1831
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1099523
version: 1

Pull request is NOT updated. Failed to apply https://patchwork.kernel.org/project/netdevbpf/list/?series=1099523
error message:

Cmd('git') failed due to: exit code(128)
  cmdline: git am --3way
  stdout: 'Applying: mm: Add ptep_try_set() for lockless empty-slot installs
Applying: bpf: Recover arena kernel faults with scratch page
Using index info to reconstruct a base tree...
M	arch/arm64/mm/fault.c
M	arch/x86/mm/fault.c
M	include/linux/bpf.h
M	kernel/bpf/arena.c
M	kernel/bpf/core.c
Falling back to patching base and 3-way merge...
Auto-merging arch/arm64/mm/fault.c
Auto-merging arch/x86/mm/fault.c
Auto-merging include/linux/bpf.h
Auto-merging kernel/bpf/arena.c
Auto-merging kernel/bpf/core.c
Applying: bpf: Add sleepable variant of bpf_arena_alloc_pages for kernel callers
Applying: bpf: Add bpf_struct_ops_for_each_prog()
Applying: bpf/arena: Add bpf_arena_map_kern_vm_start() and bpf_prog_arena()
Applying: sched_ext: Require an arena for cid-form schedulers
Using index info to reconstruct a base tree...
M	kernel/sched/ext.c
M	kernel/sched/ext_internal.h
Falling back to patching base and 3-way merge...
Auto-merging kernel/sched/ext.c
CONFLICT (content): Merge conflict in kernel/sched/ext.c
Auto-merging kernel/sched/ext_internal.h
CONFLICT (content): Merge conflict in kernel/sched/ext_internal.h
Patch failed at 0006 sched_ext: Require an arena for cid-form schedulers'
  stderr: 'error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"'

conflict:

diff --cc kernel/sched/ext.c
index 38d90baf78cf,56f94ac32ba0..000000000000
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@@ -6492,6 -6735,24 +6494,27 @@@ static struct scx_sched_pnode *alloc_pn
  }
  
  /*
++<<<<<<< HEAD
++=======
+  * scx_enable() is offloaded to a dedicated system-wide RT kthread to avoid
+  * starvation. During the READY -> ENABLED task switching loop, the calling
+  * thread's sched_class gets switched from fair to ext. As fair has higher
+  * priority than ext, the calling thread can be indefinitely starved under
+  * fair-class saturation, leading to a system hang.
+  */
+ struct scx_enable_cmd {
+ 	struct kthread_work	work;
+ 	union {
+ 		struct sched_ext_ops		*ops;
+ 		struct sched_ext_ops_cid	*ops_cid;
+ 	};
+ 	bool			is_cid_type;
+ 	struct bpf_map		*arena_map;	/* arena ref to transfer to sch */
+ 	int			ret;
+ };
+ 
+ /*
++>>>>>>> sched_ext: Require an arena for cid-form schedulers
   * Allocate and initialize a new scx_sched. @cgrp's reference is always
   * consumed whether the function succeeds or fails.
   */
@@@ -6639,10 -6916,22 +6662,19 @@@ static struct scx_sched *scx_alloc_and_
  		return ERR_PTR(ret);
  	}
  #endif	/* CONFIG_EXT_SUB_SCHED */
+ 
+ 	/*
+ 	 * Consume the arena_map ref bpf_scx_reg_cid() took. Defer to here so
+ 	 * earlier failure paths leave cmd->arena_map set and bpf_scx_reg_cid
+ 	 * drops the ref. After this point, sch owns the ref and any cleanup
+ 	 * runs through scx_sched_free_rcu_work() which puts it.
+ 	 */
+ 	sch->arena_map = cmd->arena_map;
+ 	cmd->arena_map = NULL;
  	return sch;
  
 -#ifdef CONFIG_EXT_SUB_SCHED
  err_free_lb_resched:
 -	RCU_INIT_POINTER(ops->priv, NULL);
  	free_cpumask_var(sch->bypass_lb_resched_cpumask);
 -#endif
  err_free_lb_cpumask:
  	free_cpumask_var(sch->bypass_lb_donee_cpumask);
  err_stop_helper:
@@@ -7504,7 -7905,58 +7536,62 @@@ static int bpf_scx_check_member(const s
  
  static int bpf_scx_reg(void *kdata, struct bpf_link *link)
  {
++<<<<<<< HEAD
 +	return scx_enable(kdata, link);
++=======
+ 	struct scx_enable_cmd cmd = { .ops = kdata };
+ 
+ 	return scx_enable(&cmd, link);
+ }
+ 
+ struct scx_arena_scan {
+ 	struct bpf_map	*arena;
+ 	int		err;
+ };
+ 
+ /*
+  * The verifier enforces one arena per BPF program, so each struct_ops
+  * member prog contributes at most one arena via bpf_prog_arena().
+  * Require all non-NULL contributions to match.
+  */
+ static int scx_arena_scan_prog(struct bpf_prog *prog, void *data)
+ {
+ 	struct scx_arena_scan *s = data;
+ 	struct bpf_map *arena = bpf_prog_arena(prog);
+ 
+ 	if (!arena)
+ 		return 0;
+ 	if (s->arena && s->arena != arena) {
+ 		s->err = -EINVAL;
+ 		return 1;
+ 	}
+ 	s->arena = arena;
+ 	return 0;
+ }
+ 
+ static int bpf_scx_reg_cid(void *kdata, struct bpf_link *link)
+ {
+ 	struct scx_enable_cmd cmd = { .ops_cid = kdata, .is_cid_type = true };
+ 	struct scx_arena_scan scan = {};
+ 	int ret;
+ 
+ 	bpf_struct_ops_for_each_prog(kdata, scx_arena_scan_prog, &scan);
+ 	if (scan.err) {
+ 		pr_err("sched_ext: cid-form scheduler uses multiple arena maps\n");
+ 		return scan.err;
+ 	}
+ 	if (!scan.arena) {
+ 		pr_err("sched_ext: cid-form scheduler must use a BPF arena map\n");
+ 		return -EINVAL;
+ 	}
+ 
+ 	bpf_map_inc(scan.arena);
+ 	cmd.arena_map = scan.arena;
+ 	ret = scx_enable(&cmd, link);
+ 	if (cmd.arena_map)		/* not consumed by scx_alloc_and_add_sched() */
+ 		bpf_map_put(cmd.arena_map);
+ 	return ret;
++>>>>>>> sched_ext: Require an arena for cid-form schedulers
  }
  
  static void bpf_scx_unreg(void *kdata, struct bpf_link *link)
diff --cc kernel/sched/ext_internal.h
index a075732d4430,d40cfd29ddaa..000000000000
--- a/kernel/sched/ext_internal.h
+++ b/kernel/sched/ext_internal.h
@@@ -1009,7 -1099,26 +1009,30 @@@ struct scx_sched_pnode 
  };
  
  struct scx_sched {
++<<<<<<< HEAD
 +	struct sched_ext_ops	ops;
++=======
+ 	/*
+ 	 * cpu-form and cid-form ops share field offsets up to .priv (verified
+ 	 * by BUILD_BUG_ON in scx_init()). The anonymous union lets the kernel
+ 	 * access either view of the same storage without function-pointer
+ 	 * casts: use .ops for cpu-form and shared fields, .ops_cid for the
+ 	 * cid-renamed callbacks (set_cmask, select_cid, cid_online, ...).
+ 	 */
+ 	union {
+ 		struct sched_ext_ops		ops;
+ 		struct sched_ext_ops_cid	ops_cid;
+ 	};
+ 	bool			is_cid_type;	/* true if registered via bpf_sched_ext_ops_cid */
+ 
+ 	/*
+ 	 * Arena map auto-discovered from member progs at struct_ops attach.
+ 	 * cid-form schedulers must use exactly one arena across all member
+ 	 * progs. NULL on cpu-form.
+ 	 */
+ 	struct bpf_map		*arena_map;
+ 
++>>>>>>> sched_ext: Require an arena for cid-form schedulers
  	DECLARE_BITMAP(has_op, SCX_OPI_END);
  
  	/*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants