Skip to content

Introduce eBPF support for HID devices #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a96c585
adding ci files
Mar 4, 2022
8423e72
bpf: add new is_sys_admin_prog_type() helper
bentiss Mar 4, 2022
9299986
bpf: introduce hid program type
bentiss Mar 4, 2022
f8b13cf
HID: hook up with bpf
bentiss Mar 4, 2022
c12fb24
libbpf: add HID program type and API
bentiss Mar 4, 2022
ebf189e
selftests/bpf: add tests for the HID-bpf initial implementation
bentiss Mar 4, 2022
dbe504f
samples/bpf: add new hid_mouse example
bentiss Mar 4, 2022
bc36cc7
bpf/hid: add a new attach type to change the report descriptor
bentiss Mar 4, 2022
a915794
HID: allow to change the report descriptor from an eBPF program
bentiss Mar 4, 2022
30a2b9b
libbpf: add new attach type BPF_HID_RDESC_FIXUP
bentiss Mar 4, 2022
5ee3873
selftests/bpf: add report descriptor fixup tests
bentiss Mar 4, 2022
46ea70a
samples/bpf: add a report descriptor fixup
bentiss Mar 4, 2022
086795e
bpf/hid: add hid_{get|set}_data helpers
bentiss Mar 4, 2022
0a28ac2
HID: bpf: implement hid_bpf_get|set_data
bentiss Mar 4, 2022
d9c6db1
selftests/bpf: add tests for hid_{get|set}_data helpers
bentiss Mar 4, 2022
4d65d91
bpf/hid: add new BPF type to trigger commands from userspace
bentiss Mar 4, 2022
6ee83ca
libbpf: add new attach type BPF_HID_USER_EVENT
bentiss Mar 4, 2022
e77649a
selftests/bpf: add test for user call of HID bpf programs
bentiss Mar 4, 2022
923394f
selftests/bpf: hid: rely on uhid event to know if a test device is ready
bentiss Mar 4, 2022
d30f59a
bpf/hid: add bpf_hid_raw_request helper function
bentiss Mar 4, 2022
b081f3a
HID: add implementation of bpf_hid_raw_request
bentiss Mar 4, 2022
89764cf
selftests/bpf: add tests for bpf_hid_hw_request
bentiss Mar 4, 2022
a5df405
bpf/verifier: prevent non GPL programs to be loaded against HID
bentiss Mar 4, 2022
2ab3411
HID: bpf: compute only the required buffer size for the device
bentiss Mar 4, 2022
9ed43dc
HID: bpf: only call hid_bpf_raw_event() if a ctx is available
bentiss Mar 4, 2022
8507978
bpf/hid: Add a flag to add the program at the beginning of the list
bentiss Mar 4, 2022
01f6c21
libbpf: add handling for BPF_F_INSERT_HEAD in HID programs
bentiss Mar 4, 2022
d8a4a34
selftests/bpf: Add a test for BPF_F_INSERT_HEAD
bentiss Mar 4, 2022
4c27914
samples/bpf: fix bpf_program__attach_hid() api change
bentiss Mar 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/actions/vmtest/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 'vmtest'
description: 'Build + run vmtest'
runs:
using: "composite"
steps:
# 1. Setup environment
- name: Setup build environment
uses: libbpf/ci/setup-build-env@master
# 2. Build
- name: Build kernel image
shell: bash
run: ${GITHUB_ACTION_PATH}/build.sh
- name: Build selftests
shell: bash
run: ${GITHUB_ACTION_PATH}/build_selftests.sh
env:
VMLINUX_BTF: ${{ github.workspace }}/vmlinux
# 3. Test
- name: Prepare rootfs
uses: libbpf/ci/prepare-rootfs@master
with:
project-name: 'libbpf'
arch: 'x86_64'
kernel-root: '.'
- name: Run selftests
uses: libbpf/ci/run-qemu@master
with:
arch: 'x86_64'
img: '/tmp/root.img'
vmlinuz: '${{ github.workspace }}/vmlinuz'
14 changes: 14 additions & 0 deletions .github/actions/vmtest/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -euo pipefail

THISDIR="$(cd $(dirname $0) && pwd)"

source "${THISDIR}"/helpers.sh

travis_fold start build_kernel "Building kernel"

cp "${GITHUB_ACTION_PATH}"/latest.config .config
make -j $((4*$(nproc))) olddefconfig all > /dev/null

travis_fold end build_kernel
42 changes: 42 additions & 0 deletions .github/actions/vmtest/build_selftests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

set -euo pipefail

THISDIR="$(cd $(dirname $0) && pwd)"

source "${THISDIR}"/helpers.sh

travis_fold start prepare_selftests "Building selftests"

LLVM_VER=15
LIBBPF_PATH="${REPO_ROOT}"

PREPARE_SELFTESTS_SCRIPT=${THISDIR}/prepare_selftests-${KERNEL}.sh
if [ -f "${PREPARE_SELFTESTS_SCRIPT}" ]; then
(cd "${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf" && ${PREPARE_SELFTESTS_SCRIPT})
fi

if [[ "${KERNEL}" = 'LATEST' ]]; then
VMLINUX_H=
else
VMLINUX_H=${THISDIR}/vmlinux.h
fi

cd ${REPO_ROOT}/${REPO_PATH}
make \
CLANG=clang-${LLVM_VER} \
LLC=llc-${LLVM_VER} \
LLVM_STRIP=llvm-strip-${LLVM_VER} \
VMLINUX_BTF="${VMLINUX_BTF}" \
VMLINUX_H="${VMLINUX_H}" \
-C "${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf" \
-j $((4*$(nproc))) > /dev/null
cd -
mkdir "${LIBBPF_PATH}"/selftests
cp -R "${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf" \
"${LIBBPF_PATH}"/selftests
cd "${LIBBPF_PATH}"
rm selftests/bpf/.gitignore
git add selftests

travis_fold end prepare_selftests
44 changes: 44 additions & 0 deletions .github/actions/vmtest/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# $1 - start or end
# $2 - fold identifier, no spaces
# $3 - fold section description
travis_fold() {
local YELLOW='\033[1;33m'
local NOCOLOR='\033[0m'
if [ -z ${GITHUB_WORKFLOW+x} ]; then
echo travis_fold:$1:$2
if [ ! -z "${3:-}" ]; then
echo -e "${YELLOW}$3${NOCOLOR}"
fi
echo
else
if [ $1 = "start" ]; then
line="::group::$2"
if [ ! -z "${3:-}" ]; then
line="$line - ${YELLOW}$3${NOCOLOR}"
fi
else
line="::endgroup::"
fi
echo -e "$line"
fi
}

__print() {
local TITLE=""
if [[ -n $2 ]]; then
TITLE=" title=$2"
fi
echo "::$1${TITLE}::$3"
}

# $1 - title
# $2 - message
print_error() {
__print error $1 $2
}

# $1 - title
# $2 - message
print_notice() {
__print notice $1 $2
}
Loading