Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #123 from sched-ext/structops_follow_ups
Browse files Browse the repository at this point in the history
scx: Fix a couple follow ups to recent struct_ops changes
  • Loading branch information
Byte-Lab authored Jan 20, 2024
2 parents b1a0f3e + a141212 commit 30b6fa8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
31 changes: 18 additions & 13 deletions kernel/sched/ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -3761,26 +3761,31 @@ static bool promote_dispatch_2nd_arg(int off, int size,
if (member_idx >= btf_type_vlen(t))
return false;

/* Get the member name of this program. For example, the
* member name of the dispatch program is "dispatch".
/*
* Get the member name of this struct_ops program, which corresponds to
* a field in struct sched_ext_ops. For example, the member name of the
* dispatch struct_ops program (callback) is "dispatch".
*/
member = &btf_type_member(t)[member_idx];
mname = btf_name_by_offset(btf_vmlinux, member->name_off);

/* Chkeck if it is the 2nd argument of the function pointer at
* "dispatch" in struct sched_ext_ops. The arguments of
* struct_ops operators are placed in the context one after
* another. And, they are 64-bits. So, the 2nd argument is at
* offset sizeof(__u64).
/*
* Check if it is the second argument of the function pointer at
* "dispatch" in struct sched_ext_ops. The arguments of struct_ops
* operators are sequential and 64-bit, so the second argument is at
* offset sizeof(__u64).
*/
if (strcmp(mname, "dispatch") == 0 &&
off == sizeof(__u64)) {
/* The value is a pointer to a type (struct
* task_struct) given by a BTF ID (PTR_TO_BTF_ID). It
* is tursted (PTR_TRUSTED), however, can be a NULL
* (PTR_MAYBE_NULL). The BPF program should check the
* pointer to make sure it is not null before using
* it, or the verifier will reject the program.
/*
* The value is a pointer to a type (struct task_struct) given
* by a BTF ID (PTR_TO_BTF_ID). It is trusted (PTR_TRUSTED),
* however, can be a NULL (PTR_MAYBE_NULL). The BPF program
* should check the pointer to make sure it is not NULL before
* using it, or the verifier will reject the program.
*
* Longer term, this is something that should be addressed by
* BTF, and be fully contained within the verifier.
*/
info->reg_type = PTR_MAYBE_NULL | PTR_TO_BTF_ID |
PTR_TRUSTED;
Expand Down
7 changes: 4 additions & 3 deletions tools/testing/selftests/scx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,17 @@ testcase-targets := $(addsuffix .o,$(addprefix $(SCXOBJ_DIR)/,$(auto-test-target
$(SCXOBJ_DIR)/runner.o: runner.c | $(SCXOBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@

$(SCXOBJ_DIR)/maybe_null.o: $(INCLUDE_DIR)/maybe_null_fail.bpf.skel.h

# Create all of the test targets object files, whose testcase objects will be
# registered into the runner in ELF constructors.
#
# Note that we must do double expansion here in order to support conditionally
# compiling BPF object files only if one is present, as the wildcard Make
# function doesn't support using implicit rules otherwise.
.SECONDEXPANSION:
$(testcase-targets): $(SCXOBJ_DIR)/%.o: %.c $(SCXOBJ_DIR)/runner.o $$(if $$(wildcard $$*.bpf.c), $(INCLUDE_DIR)/%.bpf.skel.h) | $(SCXOBJ_DIR)
$(testcase-targets): $(SCXOBJ_DIR)/%.o: %.c $(SCXOBJ_DIR)/runner.o \
$$(if $$(wildcard $$*.bpf.c), $(INCLUDE_DIR)/%.bpf.skel.h) \
$$(if $$(wildcard $$*_fail.bpf.c), $(INCLUDE_DIR)/%_fail.bpf.skel.h) \
| $(SCXOBJ_DIR)
$(eval test=$(patsubst %.o,%.c,$(notdir $@)))
$(CC) $(CFLAGS) -c $< -o $@ $(SCXOBJ_DIR)/runner.o

Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/scx/maybe_null.bpf.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2023 Meta Platforms, Inc. and affiliates.
* Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
*/

#include <scx/common.bpf.h>
Expand Down
4 changes: 1 addition & 3 deletions tools/testing/selftests/scx/maybe_null.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2023 Meta Platforms, Inc. and affiliates.
* Copyright (c) 2023 David Vernet <[email protected]>
* Copyright (c) 2023 Tejun Heo <[email protected]>
* Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
*/
#include <bpf/bpf.h>
#include <scx/common.h>
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/scx/maybe_null_fail.bpf.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2023 Meta Platforms, Inc. and affiliates.
* Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
*/

#include <scx/common.bpf.h>
Expand Down

0 comments on commit 30b6fa8

Please sign in to comment.