Fix seccomp relocatable builds. This is a simple fix to use the
right lib.mk variable TEST_CUSTOM_PROGS to continue to do custom
build to preserve dependency on kselftest_harness.h local header.
This change applies cutom rule to seccomp_bpf seccomp_benchmark
for a simpler logic.
Uses $(OUTPUT) defined in lib.mk to handle build relocation.
The following use-cases work with this change:
In seccomp directory:
make all and make clean
>From top level from main Makefile:
make kselftest-install O=objdir ARCH=arm64 HOSTCC=gcc \
CROSS_COMPILE=aarch64-linux-gnu- TARGETS=seccomp
Signed-off-by: Shuah Khan <skhan(a)linuxfoundation.org>
---
tools/testing/selftests/seccomp/Makefile | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/tools/testing/selftests/seccomp/Makefile b/tools/testing/selftests/seccomp/Makefile
index 1760b3e39730..355bcbc0394a 100644
--- a/tools/testing/selftests/seccomp/Makefile
+++ b/tools/testing/selftests/seccomp/Makefile
@@ -1,17 +1,16 @@
# SPDX-License-Identifier: GPL-2.0
-all:
-
-include ../lib.mk
+CFLAGS += -Wl,-no-as-needed -Wall
+LDFLAGS += -lpthread
.PHONY: all clean
-BINARIES := seccomp_bpf seccomp_benchmark
-CFLAGS += -Wl,-no-as-needed -Wall
+include ../lib.mk
+
+# OUTPUT set by lib.mk
+TEST_CUSTOM_PROGS := $(OUTPUT)/seccomp_bpf $(OUTPUT)/seccomp_benchmark
-seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h
- $(CC) $(CFLAGS) $(LDFLAGS) $< -lpthread -o $@
+$(TEST_CUSTOM_PROGS): ../kselftest_harness.h
-TEST_PROGS += $(BINARIES)
-EXTRA_CLEAN := $(BINARIES)
+all: $(TEST_CUSTOM_PROGS)
-all: $(BINARIES)
+EXTRA_CLEAN := $(TEST_CUSTOM_PROGS)
--
2.20.1
Add RSEQ, restartable sequence, support and related selftest to RISCV.
The Kconfig option HAVE_REGS_AND_STACK_ACCESS_API is also required by
RSEQ because RSEQ will modify the content of pt_regs.sepc through
instruction_pointer_set() during the fixup procedure. In order to select
the config HAVE_REGS_AND_STACK_ACCESS_API, the missing APIs for accessing
pt_regs are also added in this patch set.
The relevant RSEQ tests in kselftest require the Binutils patch "RISC-V:
Fix linker problems with TLS copy relocs" to avoid placing
PREINIT_ARRAY and TLS variable of librseq.so at the same address.
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=3e7bd7f…
A segmental fault will happen if the Binutils misses this patch.
Vincent Chen (3):
riscv: add required functions to enable HAVE_REGS_AND_STACK_ACCESS_API
riscv: Add support for restartable sequence
rseq/selftests: Add support for riscv
arch/riscv/Kconfig | 2 +
arch/riscv/include/asm/ptrace.h | 29 +-
arch/riscv/kernel/entry.S | 4 +
arch/riscv/kernel/ptrace.c | 99 +++++
arch/riscv/kernel/signal.c | 3 +
tools/testing/selftests/rseq/param_test.c | 23 ++
tools/testing/selftests/rseq/rseq-riscv.h | 622 ++++++++++++++++++++++++++++++
tools/testing/selftests/rseq/rseq.h | 2 +
8 files changed, 783 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/rseq/rseq-riscv.h
--
2.7.4
> -----Original Message-----
> From: Shuah Khan
>
> On 2/28/20 10:50 AM, Bird, Tim wrote:
> >
> >
> >> -----Original Message-----
> >> From: Shuah Khan
> >>
> >> Integrating Kselftest into Kernel CI rings depends on Kselftest build
> >> and install framework to support Kernel CI use-cases. I am kicking off
> >> an effort to support Kselftest runs in Kernel CI rings. Running these
> >> tests in Kernel CI rings will help quality of kernel releases, both
> >> stable and mainline.
> >>
> >> What is required for full support?
> >>
> >> 1. Cross-compilation & relocatable build support
> >> 2. Generates objects in objdir/kselftest without cluttering main objdir
> >> 3. Leave source directory clean
> >> 4. Installs correctly in objdir/kselftest/kselftest_install and adds
> >> itself to run_kselftest.sh script generated during install.
> >>
> >> Note that install step is necessary for all files to be installed for
> >> run time support.
> >>
> >> I looked into the current status and identified problems. The work is
> >> minimal to add full support. Out of 80+ tests, 7 fail to cross-build
> >> and 1 fails to install correctly.
> >>
> >> List is below:
> >>
> >> Tests fails to build: bpf, capabilities, kvm, memfd, mqueue, timens, vm
> >> Tests fail to install: android (partial failure)
> >> Leaves source directory dirty: bpf, seccomp
> >>
> >> I have patches ready for the following issues:
> >>
> >> Kselftest objects (test dirs) clutter top level object directory.
> >> seccomp_bpf generates objects in the source directory.
> >>
> >> I created a topic branch to collect all the patches:
> >>
> >> https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/?…
> >>
> >> I am going to start working on build problems. If anybody is
> >> interested in helping me with this effort, don't hesitate to
> >> contact me. I first priority is fixing build and install and
> >> then look into tests that leave the source directory dirty.
> >
> > I'm interested in this. I'd like the same cleanups in order to run
> > kselftest in Fuego, and I can try it with additional toolchains
> > and boards. Unfortunately, in terms of running tests, almost all
> > the boards in my lab are running old kernels. So the tests results
> > aren't useful for upstream work. But I can still test
> > compilation and install issues, for the kselftest tests themselves.
> >
>
> Testing compilation and install issues is very valuable. This is one
> area that hasn't been test coverage compared to running tests. So it
> great if you can help with build/install on linux-next to catch
> problems in new tests. I am finding that older tests have been stable
> and as new tests come in, we tend to miss catching these types of
> problems.
>
> Especially cross-builds and installs on arm64 and others.
OK. I've got 2 different arm64 compilers, with wildly different SDK setups,
so hopefully this will be useful.
> >>
> >> Detailed report can be found here:
> >>
> >> https://drive.google.com/file/d/11nnWOKIzzOrE4EiucZBn423lzSU_eNNv/view?usp=…
> >
> > Is there anything you'd like me to look at specifically? Do you want me to start
> > at the bottom of the list and work up? I could look at 'vm' or 'timens'.
> >
>
> Yes you can start with vm and timens.
I wrote a test for Fuego and ran into a few interesting issues. Also, I have a question
about the best place to start, and your preference for reporting results. Your feedback
on any of this would be appreciated:
Here are some issues and questions I ran into:
1) overwriting of CC in lib.mk
This line in tools/testing/selftests/lib.mk caused me some grief:
CC := $(CROSS_COMPILE)gcc
One of my toolchains pre-defines CC with a bunch of extra flags, so this didn't work for
that tolchain.
I'm still debugging this. I'm not sure why the weird definition of CC works for the rest
of the kernel but not with kselftest. But I may submit some kind of patch to make this
CC assignment conditional (that is, only do the assignment if it's not already defined)
Let me know what you think.
2) ability to get list of targets would be nice
It would be nice if there were a mechanism to get the list of default targets from
kselftest. I added the following for my own tests, so that I don't have to hard-code
my loop over the individual selftests:
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 63430e2..9955e71 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -246,4 +246,7 @@ clean:
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
done;
+show_targets:
+ @echo $(TARGETS)
+
.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean
This is pretty simple. I can submit this as a proper patch, if you're willing to take
something like it, and we can discuss details if you'd rather see this done another way.
3) different ways to invoke kselftest
There are a number of different ways to invoke kselftest. I'm currently using the
'-C' method for both building and installing.
make ARCH=$ARCHITECTURE TARGETS="$target" -C tools/testing/selftests
make ARCH=$ARCHITECTURE TARGETS="$target" -C tools/testing/selftests install
I think, there there are now targets for kselftest in the top-level Makefile.
Do you have a preferred method you'd like me to test? Or would you like
me to run my tests with multiple methods?
And I'm using a KBUILD_OUTPUT environment variable, rather than O=.
Let me know if you'd like me to build a matrix of these different build methods.
4) what tree(s) would you like me to test?
I think you mentioned that you'd like to see the tests against 'linux-next'.
Right now I've been doing tests against the 'torvalds' mainline tree, and
the 'linux-kselftest' tree, master branch. Let me know if there are other
branches or trees you like me to test.
5) where would you like test results?
In the short term, I'm testing the compile and install of the tests
and working on the ones that fail for me (I'm getting 17 or 18
failures, depending on the toolchain I'm using, for some of my boards).
However, I'm still debugging my setup, I hope I can drop that down
to the same one's you are seeing shortly.
Longer-term I plan to set up a CI loop for these tests for Fuego, and publish some
kind of matrix results and reports on my own server (https://birdcloud.org/)
I'm generating HTML tables now that work with Fuego's Jenkins
configuration, but I could send the data elsewhere if desired.
This is still under construction. Would you like me to publish results also to
kcidb, or some other repository? I might be able to publish my
results to Kernelci, but I'll end up with a customized report for kselftest,
that will allow drilling down to see output for individual compile or
install failures. I'm not sure how much of that would be supported in
the KernelCI interface. But I recognize you'd probably not like to
have to go to multiple places to see results.
Also, in terms of periodic results do you want any e-mails
sent to the Linux-kselftest list? I thought I'd hold off for now,
and wait for the compile/install fixes to settle down, so that
future e-mails would only report regressions or issues with new tests.
We can discuss this later, as I don't plan to do this quite
yet (and would only do an e-mail after checking with you anyway).
Thanks for any feedback you can provide.
-- Tim
P.S. Also, please let me know who is working on this on the KernelCI
side (if it's not Kevin), so I can CC them on future discussions.
Hi Linus,
Please pull the following Keselftest update for Linux 5.6-rc5.
This Kselftest update for Linux 5.6-rc5 consists of a cleanup patch
to undo changes to global .gitignore that added selftests/lkdtm
objects and add them to a local selftests/lkdtm/.gitignore.
Summary of Linus's comments on local vs. global gitignore scope:
- Keep local gitignore patterns in local files.
- Put only global gitignore patterns in the top-level gitignore file.
Local scope keeps things much better separated. It also incidentally
means that if a directory gets renamed, the gitignore file continues
to work unless in the case of renaming the actual files themselves that
are named in the gitignore.
Diff is attached.
I took the liberty to include summary of your comments on local vs
global gitignore scope in the commit message.
thanks,
-- Shuah
----------------------------------------------------------------
The following changes since commit ef89d0545132d685f73da6f58b7e7fe002536f91:
selftests/rseq: Fix out-of-tree compilation (2020-02-20 08:57:12 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
tags/linux-kselftest-5.6-rc5
for you to fetch changes up to f3a60268f5cec7dae0e9713f5fc65aecc3734c09:
selftest/lkdtm: Use local .gitignore (2020-03-02 08:39:39 -0700)
----------------------------------------------------------------
linux-kselftest-5.6-rc5
This Kselftest update for Linux 5.6-rc5 consists of a cleanup patch
to undo changes to global .gitignore that added selftests/lkdtm
objects and add them to a local selftests/lkdtm/.gitignore.
Summary of Linus's comments on local vs. global gitignore scope:
- Keep local gitignore patterns in local files.
- Put only global gitignore patterns in the top-level gitignore file.
Local scope keeps things much better separated. It also incidentally
means that if a directory gets renamed, the gitignore file continues
to work unless in the case of renaming the actual files themselves that
are named in the gitignore.
----------------------------------------------------------------
Christophe Leroy (1):
selftest/lkdtm: Use local .gitignore
.gitignore | 4 ----
tools/testing/selftests/lkdtm/.gitignore | 2 ++
2 files changed, 2 insertions(+), 4 deletions(-)
create mode 100644 tools/testing/selftests/lkdtm/.gitignore
----------------------------------------------------------------
Hello,
This patchset implements a new futex operation, called FUTEX_WAIT_MULTIPLE,
which allows a thread to wait on several futexes at the same time, and be
awoken by any of them.
The use case lies in the Wine implementation of the Windows NT interface
WaitMultipleObjects. This Windows API function allows a thread to sleep
waiting on the first of a set of event sources (mutexes, timers, signal,
console input, etc) to signal. Considering this is a primitive
synchronization operation for Windows applications, being able to quickly
signal events on the producer side, and quickly go to sleep on the
consumer side is essential for good performance of those running over Wine.
Since this API exposes a mechanism to wait on multiple objects, and
we might have multiple waiters for each of these events, a M->N
relationship, the current Linux interfaces fell short on performance
evaluation of large M,N scenarios. We experimented, for instance, with
eventfd, which has performance problems discussed below, but we also
experimented with userspace solutions, like making each consumer wait on
a condition variable guarding the entire list of objects, and then
waking up multiple variables on the producer side, but this is
prohibitively expensive since we either need to signal many condition
variables or share that condition variable among multiple waiters, and
then verify for the event being signaled in userspace, which means
dealing with often false positive wakes ups.
The natural interface to implement the behavior we want, also
considering that one of the waitable objects is a mutex itself, would be
the futex interface. Therefore, this patchset proposes a mechanism for
a thread to wait on multiple futexes at once, and wake up on the first
futex that was awaken.
In particular, using futexes in our Wine use case reduced the CPU
utilization by 4% for the game Beat Saber and by 1.5% for the game
Shadow of Tomb Raider, both running over Proton (a Wine based solution
for Windows emulation), when compared to the eventfd interface. This
implementation also doesn't rely of file descriptors, so it doesn't risk
overflowing the resource.
In time, we are also proposing modifications to glibc and libpthread to
make this feature available for Linux native multithreaded applications
using libpthread, which can benefit from the behavior of waiting on any
of a group of futexes.
Technically, the existing FUTEX_WAIT implementation can be easily
reworked by using futex_wait_multiple() with a count of one, and I
have a patch showing how it works. I'm not proposing it, since
futex is such a tricky code, that I'd be more comfortable to have
FUTEX_WAIT_MULTIPLE running upstream for a couple development cycles,
before considering modifying FUTEX_WAIT.
The patch series includes an extensive set of kselftests validating
the behavior of the interface. We also implemented support[1] on
Syzkaller and survived the fuzzy testing.
Finally, if you'd rather pull directly a branch with this set you can
find it here:
https://gitlab.collabora.com/tonyk/linux/commits/futex-dev-v3
The RFC for this patch can be found here:
https://lkml.org/lkml/2019/7/30/1399
=== Performance of eventfd ===
Polling on several eventfd contexts with semaphore semantics would
provide us with the exact semantics we are looking for. However, as
shown below, in a scenario with sufficient producers and consumers, the
eventfd interface itself becomes a bottleneck, in particular because
each thread will compete to acquire a sequence of waitqueue locks for
each eventfd context in the poll list. In addition, in the uncontended
case, where the producer is ready for consumption, eventfd still
requires going into the kernel on the consumer side.
When a write or a read operation in an eventfd file succeeds, it will try
to wake up all threads that are waiting to perform some operation to
the file. The lock (ctx->wqh.lock) that hold the access to the file value
(ctx->count) is the same lock used to control access the waitqueue. When
all those those thread woke, they will compete to get this lock. Along
with that, the poll() also manipulates the waitqueue and need to hold
this same lock. This lock is specially hard to acquire when poll() calls
poll_freewait(), where it tries to free all waitqueues associated with
this poll. While doing that, it will compete with a lot of read and
write operations that have been waken.
In our use case, with a huge number of parallel reads, writes and polls,
this lock is a bottleneck and hurts the performance of applications. Our
implementation of futex, however, decrease the calls of spin lock by more
than 80% in some user applications.
Finally, eventfd operates on file descriptors, which is a limited
resource that has shown its limitation in our use cases. Despite the
Windows interface not waiting on more than 64 objects at once, we still
have multiple waiters at the same time, and we were easily able to
exhaust the FD limits on applications like games.
Thanks,
André
[1] https://github.com/andrealmeid/syzkaller/tree/futex-wait-multiple
Gabriel Krisman Bertazi (4):
futex: Implement mechanism to wait on any of several futexes
selftests: futex: Add FUTEX_WAIT_MULTIPLE timeout test
selftests: futex: Add FUTEX_WAIT_MULTIPLE wouldblock test
selftests: futex: Add FUTEX_WAIT_MULTIPLE wake up test
include/uapi/linux/futex.h | 20 +
kernel/futex.c | 358 +++++++++++++++++-
.../selftests/futex/functional/.gitignore | 1 +
.../selftests/futex/functional/Makefile | 3 +-
.../futex/functional/futex_wait_multiple.c | 173 +++++++++
.../futex/functional/futex_wait_timeout.c | 38 +-
.../futex/functional/futex_wait_wouldblock.c | 28 +-
.../testing/selftests/futex/functional/run.sh | 3 +
.../selftests/futex/include/futextest.h | 22 ++
9 files changed, 639 insertions(+), 7 deletions(-)
create mode 100644 tools/testing/selftests/futex/functional/futex_wait_multiple.c
--
2.25.0