Skip to content

Commit e12f065

Browse files
author
Jiri Kosina
committed
Merge branch 'for-6.7/selftests' into for-linus
- HID selftests fixes and improvements (Benjamin Tissoires)
2 parents eacaa65 + 9193963 commit e12f065

File tree

3 files changed

+81
-9
lines changed

3 files changed

+81
-9
lines changed

tools/testing/selftests/hid/Makefile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ CXX ?= $(CROSS_COMPILE)g++
2121

2222
HOSTPKG_CONFIG := pkg-config
2323

24-
CFLAGS += -g -O0 -rdynamic -Wall -Werror -I$(KHDR_INCLUDES) -I$(OUTPUT)
24+
CFLAGS += -g -O0 -rdynamic -Wall -Werror -I$(OUTPUT)
25+
CFLAGS += -I$(OUTPUT)/tools/include
26+
2527
LDLIBS += -lelf -lz -lrt -lpthread
2628

2729
# Silence some warnings when compiled with clang
@@ -65,7 +67,6 @@ BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool
6567
SCRATCH_DIR := $(OUTPUT)/tools
6668
BUILD_DIR := $(SCRATCH_DIR)/build
6769
INCLUDE_DIR := $(SCRATCH_DIR)/include
68-
KHDR_INCLUDES := $(SCRATCH_DIR)/uapi/include
6970
BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a
7071
ifneq ($(CROSS_COMPILE),)
7172
HOST_BUILD_DIR := $(BUILD_DIR)/host
@@ -151,9 +152,6 @@ else
151152
$(Q)cp "$(VMLINUX_H)" $@
152153
endif
153154

154-
$(KHDR_INCLUDES)/linux/hid.h: $(top_srcdir)/include/uapi/linux/hid.h
155-
$(MAKE) -C $(top_srcdir) INSTALL_HDR_PATH=$(SCRATCH_DIR)/uapi headers_install
156-
157155
$(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids \
158156
$(TOOLSDIR)/bpf/resolve_btfids/main.c \
159157
$(TOOLSDIR)/lib/rbtree.c \
@@ -231,7 +229,7 @@ $(BPF_SKELS): %.skel.h: %.bpf.o $(BPFTOOL) | $(OUTPUT)
231229
$(Q)$(BPFTOOL) gen object $(<:.o=.linked1.o) $<
232230
$(Q)$(BPFTOOL) gen skeleton $(<:.o=.linked1.o) name $(notdir $(<:.bpf.o=)) > $@
233231

234-
$(OUTPUT)/%.o: %.c $(BPF_SKELS) $(KHDR_INCLUDES)/linux/hid.h
232+
$(OUTPUT)/%.o: %.c $(BPF_SKELS)
235233
$(call msg,CC,,$@)
236234
$(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
237235

tools/testing/selftests/hid/progs/hid.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
// SPDX-License-Identifier: GPL-2.0
22
/* Copyright (c) 2022 Red hat */
3-
#include "vmlinux.h"
4-
#include <bpf/bpf_helpers.h>
5-
#include <bpf/bpf_tracing.h>
63
#include "hid_bpf_helpers.h"
74

85
char _license[] SEC("license") = "GPL";

tools/testing/selftests/hid/progs/hid_bpf_helpers.h

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,83 @@
55
#ifndef __HID_BPF_HELPERS_H
66
#define __HID_BPF_HELPERS_H
77

8+
/* "undefine" structs and enums in vmlinux.h, because we "override" them below */
9+
#define hid_bpf_ctx hid_bpf_ctx___not_used
10+
#define hid_report_type hid_report_type___not_used
11+
#define hid_class_request hid_class_request___not_used
12+
#define hid_bpf_attach_flags hid_bpf_attach_flags___not_used
13+
#define HID_INPUT_REPORT HID_INPUT_REPORT___not_used
14+
#define HID_OUTPUT_REPORT HID_OUTPUT_REPORT___not_used
15+
#define HID_FEATURE_REPORT HID_FEATURE_REPORT___not_used
16+
#define HID_REPORT_TYPES HID_REPORT_TYPES___not_used
17+
#define HID_REQ_GET_REPORT HID_REQ_GET_REPORT___not_used
18+
#define HID_REQ_GET_IDLE HID_REQ_GET_IDLE___not_used
19+
#define HID_REQ_GET_PROTOCOL HID_REQ_GET_PROTOCOL___not_used
20+
#define HID_REQ_SET_REPORT HID_REQ_SET_REPORT___not_used
21+
#define HID_REQ_SET_IDLE HID_REQ_SET_IDLE___not_used
22+
#define HID_REQ_SET_PROTOCOL HID_REQ_SET_PROTOCOL___not_used
23+
#define HID_BPF_FLAG_NONE HID_BPF_FLAG_NONE___not_used
24+
#define HID_BPF_FLAG_INSERT_HEAD HID_BPF_FLAG_INSERT_HEAD___not_used
25+
#define HID_BPF_FLAG_MAX HID_BPF_FLAG_MAX___not_used
26+
27+
#include "vmlinux.h"
28+
29+
#undef hid_bpf_ctx
30+
#undef hid_report_type
31+
#undef hid_class_request
32+
#undef hid_bpf_attach_flags
33+
#undef HID_INPUT_REPORT
34+
#undef HID_OUTPUT_REPORT
35+
#undef HID_FEATURE_REPORT
36+
#undef HID_REPORT_TYPES
37+
#undef HID_REQ_GET_REPORT
38+
#undef HID_REQ_GET_IDLE
39+
#undef HID_REQ_GET_PROTOCOL
40+
#undef HID_REQ_SET_REPORT
41+
#undef HID_REQ_SET_IDLE
42+
#undef HID_REQ_SET_PROTOCOL
43+
#undef HID_BPF_FLAG_NONE
44+
#undef HID_BPF_FLAG_INSERT_HEAD
45+
#undef HID_BPF_FLAG_MAX
46+
47+
#include <bpf/bpf_helpers.h>
48+
#include <bpf/bpf_tracing.h>
49+
#include <linux/const.h>
50+
51+
enum hid_report_type {
52+
HID_INPUT_REPORT = 0,
53+
HID_OUTPUT_REPORT = 1,
54+
HID_FEATURE_REPORT = 2,
55+
56+
HID_REPORT_TYPES,
57+
};
58+
59+
struct hid_bpf_ctx {
60+
__u32 index;
61+
const struct hid_device *hid;
62+
__u32 allocated_size;
63+
enum hid_report_type report_type;
64+
union {
65+
__s32 retval;
66+
__s32 size;
67+
};
68+
} __attribute__((preserve_access_index));
69+
70+
enum hid_class_request {
71+
HID_REQ_GET_REPORT = 0x01,
72+
HID_REQ_GET_IDLE = 0x02,
73+
HID_REQ_GET_PROTOCOL = 0x03,
74+
HID_REQ_SET_REPORT = 0x09,
75+
HID_REQ_SET_IDLE = 0x0A,
76+
HID_REQ_SET_PROTOCOL = 0x0B,
77+
};
78+
79+
enum hid_bpf_attach_flags {
80+
HID_BPF_FLAG_NONE = 0,
81+
HID_BPF_FLAG_INSERT_HEAD = _BITUL(0),
82+
HID_BPF_FLAG_MAX,
83+
};
84+
885
/* following are kfuncs exported by HID for HID-BPF */
986
extern __u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx,
1087
unsigned int offset,

0 commit comments

Comments
 (0)