Skip to content

Commit 41af159

Browse files
author
Alexei Starovoitov
committed
Merge branch 'bpf-next/master' into for-next
Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents cdfa60a + cd7312a commit 41af159

File tree

15 files changed

+119
-26
lines changed

15 files changed

+119
-26
lines changed

kernel/bpf/bpf_iter.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ static DEFINE_MUTEX(link_mutex);
3838
/* incremented on every opened seq_file */
3939
static atomic64_t session_id;
4040

41-
static int prepare_seq_file(struct file *file, struct bpf_iter_link *link,
42-
const struct bpf_iter_seq_info *seq_info);
41+
static int prepare_seq_file(struct file *file, struct bpf_iter_link *link);
4342

4443
static void bpf_iter_inc_seq_num(struct seq_file *seq)
4544
{
@@ -257,7 +256,7 @@ static int iter_open(struct inode *inode, struct file *file)
257256
{
258257
struct bpf_iter_link *link = inode->i_private;
259258

260-
return prepare_seq_file(file, link, __get_seq_info(link));
259+
return prepare_seq_file(file, link);
261260
}
262261

263262
static int iter_release(struct inode *inode, struct file *file)
@@ -586,9 +585,9 @@ static void init_seq_meta(struct bpf_iter_priv_data *priv_data,
586585
priv_data->done_stop = false;
587586
}
588587

589-
static int prepare_seq_file(struct file *file, struct bpf_iter_link *link,
590-
const struct bpf_iter_seq_info *seq_info)
588+
static int prepare_seq_file(struct file *file, struct bpf_iter_link *link)
591589
{
590+
const struct bpf_iter_seq_info *seq_info = __get_seq_info(link);
592591
struct bpf_iter_priv_data *priv_data;
593592
struct bpf_iter_target_info *tinfo;
594593
struct bpf_prog *prog;
@@ -653,7 +652,7 @@ int bpf_iter_new_fd(struct bpf_link *link)
653652
}
654653

655654
iter_link = container_of(link, struct bpf_iter_link, link);
656-
err = prepare_seq_file(file, iter_link, __get_seq_info(iter_link));
655+
err = prepare_seq_file(file, iter_link);
657656
if (err)
658657
goto free_file;
659658

kernel/trace/bpf_trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ __bpf_kfunc_start_defs();
12701270
* Return: a bpf_key pointer with a valid key pointer if the key is found, a
12711271
* NULL pointer otherwise.
12721272
*/
1273-
__bpf_kfunc struct bpf_key *bpf_lookup_user_key(u32 serial, u64 flags)
1273+
__bpf_kfunc struct bpf_key *bpf_lookup_user_key(s32 serial, u64 flags)
12741274
{
12751275
key_ref_t key_ref;
12761276
struct bpf_key *bkey;

tools/bpf/bpftool/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,9 @@ int main(int argc, char **argv)
534534
usage();
535535

536536
if (version_requested)
537-
return do_version(argc, argv);
538-
539-
ret = cmd_select(commands, argc, argv, do_help);
537+
ret = do_version(argc, argv);
538+
else
539+
ret = cmd_select(commands, argc, argv, do_help);
540540

541541
if (json_output)
542542
jsonw_destroy(&json_wtr);

tools/testing/selftests/bpf/bpf_kfuncs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ extern int bpf_get_file_xattr(struct file *file, const char *name,
6969
struct bpf_dynptr *value_ptr) __ksym;
7070
extern int bpf_get_fsverity_digest(struct file *file, struct bpf_dynptr *digest_ptr) __ksym;
7171

72-
extern struct bpf_key *bpf_lookup_user_key(__u32 serial, __u64 flags) __ksym;
72+
extern struct bpf_key *bpf_lookup_user_key(__s32 serial, __u64 flags) __ksym;
7373
extern struct bpf_key *bpf_lookup_system_key(__u64 id) __ksym;
7474
extern void bpf_key_put(struct bpf_key *key) __ksym;
7575
extern int bpf_verify_pkcs7_signature(struct bpf_dynptr *data_ptr,

tools/testing/selftests/bpf/prog_tests/fd_array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ static void check_fd_array_cnt__referenced_btfs(void)
312312

313313
/* btf should still exist when original file descriptor is closed */
314314
err = get_btf_id_by_fd(extra_fds[0], &btf_id);
315-
if (!ASSERT_GE(err, 0, "get_btf_id_by_fd"))
315+
if (!ASSERT_EQ(err, 0, "get_btf_id_by_fd"))
316316
goto cleanup;
317317

318318
Close(extra_fds[0]);

tools/testing/selftests/bpf/prog_tests/log_buf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include "test_log_buf.skel.h"
88
#include "bpf_util.h"
99

10+
#if !defined(__clang__)
11+
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
12+
#endif
13+
1014
static size_t libbpf_log_pos;
1115
static char libbpf_log_buf[1024 * 1024];
1216
static bool libbpf_log_error;

tools/testing/selftests/bpf/prog_tests/tailcalls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ static void test_tailcall_hierarchy_count(const char *which, bool test_fentry,
11951195
bool test_fexit,
11961196
bool test_fentry_entry)
11971197
{
1198-
int err, map_fd, prog_fd, main_data_fd, fentry_data_fd, fexit_data_fd, i, val;
1198+
int err, map_fd, prog_fd, main_data_fd, fentry_data_fd = 0, fexit_data_fd = 0, i, val;
11991199
struct bpf_object *obj = NULL, *fentry_obj = NULL, *fexit_obj = NULL;
12001200
struct bpf_link *fentry_link = NULL, *fexit_link = NULL;
12011201
struct bpf_program *prog, *fentry_prog;

tools/testing/selftests/bpf/progs/rcu_read_lock.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ struct {
1616
__type(value, long);
1717
} map_a SEC(".maps");
1818

19-
__u32 user_data, key_serial, target_pid;
19+
__u32 user_data, target_pid;
20+
__s32 key_serial;
2021
__u64 flags, task_storage_val, cgroup_id;
2122

22-
struct bpf_key *bpf_lookup_user_key(__u32 serial, __u64 flags) __ksym;
23+
struct bpf_key *bpf_lookup_user_key(__s32 serial, __u64 flags) __ksym;
2324
void bpf_key_put(struct bpf_key *key) __ksym;
2425
void bpf_rcu_read_lock(void) __ksym;
2526
void bpf_rcu_read_unlock(void) __ksym;

tools/testing/selftests/bpf/progs/test_lookup_key.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
char _license[] SEC("license") = "GPL";
1515

1616
__u32 monitored_pid;
17-
__u32 key_serial;
17+
__s32 key_serial;
1818
__u32 key_id;
1919
__u64 flags;
2020

21-
extern struct bpf_key *bpf_lookup_user_key(__u32 serial, __u64 flags) __ksym;
21+
extern struct bpf_key *bpf_lookup_user_key(__s32 serial, __u64 flags) __ksym;
2222
extern struct bpf_key *bpf_lookup_system_key(__u64 id) __ksym;
2323
extern void bpf_key_put(struct bpf_key *key) __ksym;
2424

tools/testing/selftests/bpf/progs/test_sig_in_xattr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ char digest[MAGIC_SIZE + SIZEOF_STRUCT_FSVERITY_DIGEST + SHA256_DIGEST_SIZE];
4040
__u32 monitored_pid;
4141
char sig[MAX_SIG_SIZE];
4242
__u32 sig_size;
43-
__u32 user_keyring_serial;
43+
__s32 user_keyring_serial;
4444

4545
SEC("lsm.s/file_open")
4646
int BPF_PROG(test_file_open, struct file *f)

tools/testing/selftests/bpf/progs/test_verify_pkcs7_sig.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#define MAX_SIG_SIZE 1024
1818

1919
__u32 monitored_pid;
20-
__u32 user_keyring_serial;
20+
__s32 user_keyring_serial;
2121
__u64 system_keyring_id;
2222

2323
struct data {

tools/testing/selftests/bpf/progs/verifier_ref_tracking.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct bpf_key {} __attribute__((preserve_access_index));
2727

2828
extern void bpf_key_put(struct bpf_key *key) __ksym;
2929
extern struct bpf_key *bpf_lookup_system_key(__u64 id) __ksym;
30-
extern struct bpf_key *bpf_lookup_user_key(__u32 serial, __u64 flags) __ksym;
30+
extern struct bpf_key *bpf_lookup_user_key(__s32 serial, __u64 flags) __ksym;
3131

3232
/* BTF FUNC records are not generated for kfuncs referenced
3333
* from inline assembly. These records are necessary for

tools/testing/selftests/bpf/test_loader.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,9 +1103,9 @@ void run_subtest(struct test_loader *tester,
11031103
}
11041104
}
11051105

1106-
do_prog_test_run(bpf_program__fd(tprog), &retval,
1107-
bpf_program__type(tprog) == BPF_PROG_TYPE_SYSCALL ? true : false);
1108-
if (retval != subspec->retval && subspec->retval != POINTER_VALUE) {
1106+
err = do_prog_test_run(bpf_program__fd(tprog), &retval,
1107+
bpf_program__type(tprog) == BPF_PROG_TYPE_SYSCALL ? true : false);
1108+
if (!err && retval != subspec->retval && subspec->retval != POINTER_VALUE) {
11091109
PRINT_FAIL("Unexpected retval: %d != %d\n", retval, subspec->retval);
11101110
goto tobj_cleanup;
11111111
}

tools/testing/selftests/bpf/unpriv_helpers.c

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,76 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22

3+
#include <errno.h>
4+
#include <limits.h>
35
#include <stdbool.h>
46
#include <stdlib.h>
57
#include <stdio.h>
68
#include <string.h>
9+
#include <sys/utsname.h>
710
#include <unistd.h>
811
#include <fcntl.h>
12+
#include <zlib.h>
913

1014
#include "unpriv_helpers.h"
1115

12-
static bool get_mitigations_off(void)
16+
static gzFile open_config(void)
17+
{
18+
struct utsname uts;
19+
char buf[PATH_MAX];
20+
gzFile config;
21+
22+
if (uname(&uts)) {
23+
perror("uname");
24+
goto config_gz;
25+
}
26+
27+
snprintf(buf, sizeof(buf), "/boot/config-%s", uts.release);
28+
config = gzopen(buf, "rb");
29+
if (config)
30+
return config;
31+
fprintf(stderr, "gzopen %s: %s\n", buf, strerror(errno));
32+
33+
config_gz:
34+
config = gzopen("/proc/config.gz", "rb");
35+
if (!config)
36+
perror("gzopen /proc/config.gz");
37+
return config;
38+
}
39+
40+
static int config_contains(const char *pat)
41+
{
42+
const char *msg;
43+
char buf[1024];
44+
gzFile config;
45+
int n, err;
46+
47+
config = open_config();
48+
if (!config)
49+
return -1;
50+
51+
for (;;) {
52+
if (!gzgets(config, buf, sizeof(buf))) {
53+
msg = gzerror(config, &err);
54+
if (err == Z_ERRNO)
55+
perror("gzgets /proc/config.gz");
56+
else if (err != Z_OK)
57+
fprintf(stderr, "gzgets /proc/config.gz: %s", msg);
58+
gzclose(config);
59+
return -1;
60+
}
61+
n = strlen(buf);
62+
if (buf[n - 1] == '\n')
63+
buf[n - 1] = 0;
64+
if (strcmp(buf, pat) == 0) {
65+
gzclose(config);
66+
return 1;
67+
}
68+
}
69+
gzclose(config);
70+
return 0;
71+
}
72+
73+
static bool cmdline_contains(const char *pat)
1374
{
1475
char cmdline[4096], *c;
1576
int fd, ret = false;
@@ -27,7 +88,7 @@ static bool get_mitigations_off(void)
2788

2889
cmdline[sizeof(cmdline) - 1] = '\0';
2990
for (c = strtok(cmdline, " \n"); c; c = strtok(NULL, " \n")) {
30-
if (strncmp(c, "mitigations=off", strlen(c)))
91+
if (strncmp(c, pat, strlen(c)))
3192
continue;
3293
ret = true;
3394
break;
@@ -37,8 +98,21 @@ static bool get_mitigations_off(void)
3798
return ret;
3899
}
39100

101+
static int get_mitigations_off(void)
102+
{
103+
int enabled_in_config;
104+
105+
if (cmdline_contains("mitigations=off"))
106+
return 1;
107+
enabled_in_config = config_contains("CONFIG_CPU_MITIGATIONS=y");
108+
if (enabled_in_config < 0)
109+
return -1;
110+
return !enabled_in_config;
111+
}
112+
40113
bool get_unpriv_disabled(void)
41114
{
115+
int mitigations_off;
42116
bool disabled;
43117
char buf[2];
44118
FILE *fd;
@@ -52,5 +126,19 @@ bool get_unpriv_disabled(void)
52126
disabled = true;
53127
}
54128

55-
return disabled ? true : get_mitigations_off();
129+
if (disabled)
130+
return true;
131+
132+
/*
133+
* Some unpriv tests rely on spectre mitigations being on.
134+
* If mitigations are off or status can't be determined
135+
* assume that unpriv tests are disabled.
136+
*/
137+
mitigations_off = get_mitigations_off();
138+
if (mitigations_off < 0) {
139+
fprintf(stderr,
140+
"Can't determine if mitigations are enabled, disabling unpriv tests.");
141+
return true;
142+
}
143+
return mitigations_off;
56144
}

tools/testing/selftests/bpf/veristat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
364364
fprintf(stderr, "invalid top N specifier: %s\n", arg);
365365
argp_usage(state);
366366
}
367+
break;
367368
case 'C':
368369
env.comparison_mode = true;
369370
break;

0 commit comments

Comments
 (0)