This series wires up getrandom() vDSO implementation on powerpc.
Tested on PPC32.
Performance on powerpc 885 (using kernel selftest):
~# ./vdso_test_getrandom bench-single
vdso: 2500000 times in 7.897495392 seconds
libc: 2500000 times in 56.091632232 seconds
syscall: 2500000 times in 55.704851989 seconds
Performance on powerpc 8321 (using kernel selftest):
~# ./vdso_test_getrandom bench-single
vdso: 2500000 times in 2.017183250 seconds
libc: 2500000 times in 13.088533630 seconds
syscall: 2500000 times in 12.952458068 seconds
Only build tested on PPC64. There is a problem with vdso_test_getrandom
selftest, it doesn't find vDSO symbol __kernel_getrandom. There is the
same problem with vdso_test_gettimeofday so it is not related to
getrandom.
On strange things to be clarified, there is the format of the key passed
to __arch_chacha20_blocks_nostack(). In struct vgetrandom_state it is
declared as a table of u32, but in reality it seems it is a flat storage
that needs to be loaded in reversed byte order, so it should either be
defined as a table of bytes, or as a table of __le32 but not a table of
u32. But this has no impact and can be clarified later and fixed in a
follow-up patch.
Changes in v2:
- Define VM_DROPPABLE for powerpc/32
- Fixes generic vDSO getrandom headers to enable CONFIG_COMPAT build.
- Fixed size of generation counter
- Fixed selftests to work on non x86 architectures
Christophe Leroy (17):
asm-generic/unaligned.h: Extract common header for vDSO
vdso: Clean header inclusion in getrandom
vdso: Add __arch_get_k_vdso_rng_data()
vdso: Add missing c-getrandom-y in Makefile
vdso: Avoid call to memset() by getrandom
vdso: Change getrandom's generation to unsigned long
mm: Define VM_DROPPABLE for powerpc/32
powerpc: Add little endian variants of LWZX_BE and STWX_BE
powerpc/vdso32: Add crtsavres
powerpc/vdso: Refactor CFLAGS for CVDSO build
powerpc/vdso: Wire up getrandom() vDSO implementation
selftests: vdso: Fix powerpc64 vdso_config
selftests: vdso: Don't hard-code location of vDSO sources
selftests: vdso: Make test_vdso_getrandom look for the right vDSO
function
selftests: vdso: Fix build of test_vdso_chacha
selftests: vdso: Make VDSO function call more generic
selftests: vdso: Add support for vdso_test_random for powerpc
arch/powerpc/Kconfig | 1 +
arch/powerpc/include/asm/asm-compat.h | 8 +
arch/powerpc/include/asm/mman.h | 2 +-
arch/powerpc/include/asm/vdso/getrandom.h | 67 ++++
arch/powerpc/include/asm/vdso/vsyscall.h | 6 +
arch/powerpc/include/asm/vdso_datapage.h | 2 +
arch/powerpc/kernel/asm-offsets.c | 1 +
arch/powerpc/kernel/vdso/Makefile | 45 ++-
arch/powerpc/kernel/vdso/getrandom.S | 58 ++++
arch/powerpc/kernel/vdso/gettimeofday.S | 13 -
arch/powerpc/kernel/vdso/vdso32.lds.S | 1 +
arch/powerpc/kernel/vdso/vdso64.lds.S | 1 +
arch/powerpc/kernel/vdso/vgetrandom-chacha.S | 297 ++++++++++++++++++
arch/powerpc/kernel/vdso/vgetrandom.c | 14 +
arch/x86/entry/vdso/vma.c | 3 +
arch/x86/include/asm/pvclock.h | 1 +
arch/x86/include/asm/vdso/vsyscall.h | 10 +-
drivers/char/random.c | 5 +-
fs/proc/task_mmu.c | 4 +-
include/asm-generic/unaligned.h | 11 +-
include/linux/mm.h | 4 +-
include/trace/events/mmflags.h | 4 +-
include/vdso/datapage.h | 2 +-
include/vdso/getrandom.h | 2 +-
include/vdso/helpers.h | 1 +
include/vdso/unaligned.h | 15 +
lib/vdso/Makefile | 1 +
lib/vdso/getrandom.c | 30 +-
tools/arch/powerpc/vdso | 1 +
tools/arch/x86/vdso | 1 +
tools/include/linux/linkage.h | 4 +
tools/testing/selftests/vDSO/Makefile | 12 +-
tools/testing/selftests/vDSO/vdso_call.h | 52 +++
tools/testing/selftests/vDSO/vdso_config.h | 14 +-
.../selftests/vDSO/vdso_test_getrandom.c | 11 +-
35 files changed, 628 insertions(+), 76 deletions(-)
create mode 100644 arch/powerpc/include/asm/vdso/getrandom.h
create mode 100644 arch/powerpc/kernel/vdso/getrandom.S
create mode 100644 arch/powerpc/kernel/vdso/vgetrandom-chacha.S
create mode 100644 arch/powerpc/kernel/vdso/vgetrandom.c
create mode 100644 include/vdso/unaligned.h
create mode 120000 tools/arch/powerpc/vdso
create mode 120000 tools/arch/x86/vdso
create mode 100644 tools/testing/selftests/vDSO/vdso_call.h
--
2.44.0
It was recently observed at [1] that during the folio unmapping stage
of migration, when the PTEs are cleared, a racing thread faulting on that
folio may increase the refcount of the folio, sleep on the folio lock
(the migration path has the lock), and migration ultimately fails
when asserting the actual refcount against the expected. Thereby,
the migration selftest fails on shared-anon mappings.
The above enforces the fact that migration is a best-effort service,
therefore, it is wrong to fail the test for just a single failure;
hence, fail the test after 100 consecutive failures (where 100 is
still a subjective choice). Note that, this has no effect on the
execution time of the test since that is controlled by a timeout.
[1] https://lore.kernel.org/all/20240801081657.1386743-1-dev.jain@arm.com/
Signed-off-by: Dev Jain <dev.jain(a)arm.com>
Suggested-by: David Hildenbrand <david(a)redhat.com>
Reviewed-by: Ryan Roberts <ryan.roberts(a)arm.com>
Tested-by: Ryan Roberts <ryan.roberts(a)arm.com>
---
The above patch was part of the following:
https://lore.kernel.org/all/20240809103129.365029-1-dev.jain@arm.com/
I decided to send it separately since it should be applied
nevertheless.
tools/testing/selftests/mm/migration.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/mm/migration.c b/tools/testing/selftests/mm/migration.c
index 6908569ef406..64bcbb7151cf 100644
--- a/tools/testing/selftests/mm/migration.c
+++ b/tools/testing/selftests/mm/migration.c
@@ -15,10 +15,10 @@
#include <signal.h>
#include <time.h>
-#define TWOMEG (2<<20)
-#define RUNTIME (20)
-
-#define ALIGN(x, a) (((x) + (a - 1)) & (~((a) - 1)))
+#define TWOMEG (2<<20)
+#define RUNTIME (20)
+#define MAX_RETRIES 100
+#define ALIGN(x, a) (((x) + (a - 1)) & (~((a) - 1)))
FIXTURE(migration)
{
@@ -65,6 +65,7 @@ int migrate(uint64_t *ptr, int n1, int n2)
int ret, tmp;
int status = 0;
struct timespec ts1, ts2;
+ int failures = 0;
if (clock_gettime(CLOCK_MONOTONIC, &ts1))
return -1;
@@ -79,13 +80,17 @@ int migrate(uint64_t *ptr, int n1, int n2)
ret = move_pages(0, 1, (void **) &ptr, &n2, &status,
MPOL_MF_MOVE_ALL);
if (ret) {
- if (ret > 0)
+ if (ret > 0) {
+ /* Migration is best effort; try again */
+ if (++failures < MAX_RETRIES)
+ continue;
printf("Didn't migrate %d pages\n", ret);
+ }
else
perror("Couldn't migrate pages");
return -2;
}
-
+ failures = 0;
tmp = n2;
n2 = n1;
n1 = tmp;
--
2.30.2
From: Joshua Hahn <joshua.hahn6(a)gmail.com>
Niced CPU usage is a metric reported in host-level /proc/stat, but is
not reported in cgroup-level statistics in cpu.stat. However, when a
host contains multiple tasks across different workloads, it becomes
difficult to gauage how much of the task is being spent on niced
processes based on /proc/stat alone, since host-level metrics do not
provide this cgroup-level granularity.
Exposing this metric will allow load balancers to correctly probe the
niced CPU metric for each workload, and make more informed decisions
when directing higher priority tasks.
Joshua Hahn (2):
Tracking cgroup-level niced CPU time
Selftests for niced CPU statistics
include/linux/cgroup-defs.h | 1 +
kernel/cgroup/rstat.c | 16 ++++-
tools/testing/selftests/cgroup/test_cpu.c | 72 +++++++++++++++++++++++
3 files changed, 86 insertions(+), 3 deletions(-)
--
2.43.5
v1: https://groups.google.com/g/kunit-dev/c/f4LIMLyofj8
v2: make it more complex and attempt to be thread safe
s/FIXED_STUB/GLOBAL_STUB (David, Lucas)
make it little more thread safe (Rae, David)
wait until stub call finishes before test end (David)
wait until stub call finishes before changing stub (David)
allow stub deactivation (Rae)
prefer kunit log (David)
add simple selftest (Michal)
also introduce ONLY_IF_KUNIT macro (Michal)
Sample output from the tests:
$ tools/testing/kunit/kunit.py run *example*.*global* \
--kunitconfig lib/kunit/.kunitconfig --raw_output
KTAP version 1
1..1
# example: initializing suite
KTAP version 1
# Subtest: example
# module: kunit_example_test
1..1
# example_global_stub_test: initializing
# example_global_stub_test: add_two: redirecting to subtract_one
# example_global_stub_test: add_two: redirecting to subtract_one
# example_global_stub_test: cleaning up
ok 1 example_global_stub_test
# example: exiting suite
ok 1 example
$ tools/testing/kunit/kunit.py run *global*.*global* \
--kunitconfig lib/kunit/.kunitconfig --raw_output
KTAP version 1
1..1
KTAP version 1
# Subtest: kunit_global_stub
# module: kunit_test
1..4
# kunit_global_stub_test_activate: real_void_func: redirecting to replacement_void_func
# kunit_global_stub_test_activate: real_func: redirecting to replacement_func
# kunit_global_stub_test_activate: real_func: redirecting to replacement_func
# kunit_global_stub_test_activate: real_func: redirecting to other_replacement_func
# kunit_global_stub_test_activate: real_func: redirecting to other_replacement_func
# kunit_global_stub_test_activate: real_func: redirecting to super_replacement_func
# kunit_global_stub_test_activate: real_func: redirecting to super_replacement_func
ok 1 kunit_global_stub_test_activate
ok 2 kunit_global_stub_test_deactivate
# kunit_global_stub_test_slow_deactivate: real_func: redirecting to slow_replacement_func
# kunit_global_stub_test_slow_deactivate: real_func: redirecting to slow_replacement_func
# kunit_global_stub_test_slow_deactivate: waiting for slow_replacement_func
# kunit_global_stub_test_slow_deactivate.speed: slow
ok 3 kunit_global_stub_test_slow_deactivate
# kunit_global_stub_test_slow_replace: real_func: redirecting to slow_replacement_func
# kunit_global_stub_test_slow_replace: real_func: redirecting to slow_replacement_func
# kunit_global_stub_test_slow_replace: waiting for slow_replacement_func
# kunit_global_stub_test_slow_replace: real_func: redirecting to other_replacement_func
# kunit_global_stub_test_slow_replace.speed: slow
ok 4 kunit_global_stub_test_slow_replace
# kunit_global_stub: pass:4 fail:0 skip:0 total:4
# Totals: pass:4 fail:0 skip:0 total:4
ok 1 kunit_global_stub
Cc: Rae Moar <rmoar(a)google.com>
Cc: David Gow <davidgow(a)google.com>
Cc: Lucas De Marchi <lucas.demarchi(a)intel.com>
Michal Wajdeczko (6):
kunit: Introduce kunit_is_running()
kunit: Add macro to conditionally expose declarations to tests
kunit: Add macro to conditionally expose expressions to tests
kunit: Allow function redirection outside of the KUnit thread
kunit: Add example with alternate function redirection method
kunit: Add some selftests for global stub redirection macros
include/kunit/static_stub.h | 158 ++++++++++++++++++++
include/kunit/test-bug.h | 12 +-
include/kunit/visibility.h | 16 +++
lib/kunit/kunit-example-test.c | 67 +++++++++
lib/kunit/kunit-test.c | 254 ++++++++++++++++++++++++++++++++-
lib/kunit/static_stub.c | 49 +++++++
6 files changed, 553 insertions(+), 3 deletions(-)
--
2.43.0
This option makes IP_NF_IPTABLES_LEGACY user selectable, giving
users the option to configure iptables without enabling any other
config.
Suggested-by: Florian Westphal <fw(a)strlen.de>
Signed-off-by: Breno Leitao <leitao(a)debian.org>
---
net/ipv4/netfilter/Kconfig | 19 +++++++++++--------
tools/testing/selftests/net/config | 8 ++++++++
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig
index 1b991b889506..a06c1903183f 100644
--- a/net/ipv4/netfilter/Kconfig
+++ b/net/ipv4/netfilter/Kconfig
@@ -12,7 +12,12 @@ config NF_DEFRAG_IPV4
# old sockopt interface and eval loop
config IP_NF_IPTABLES_LEGACY
- tristate
+ tristate "Legacy IP tables support"
+ default n
+ select NETFILTER_XTABLES
+ help
+ iptables is a general, extensible packet identification legacy framework.
+ This is not needed if you are using iptables over nftables (iptables-nft).
config NF_SOCKET_IPV4
tristate "IPv4 socket lookup support"
@@ -177,7 +182,7 @@ config IP_NF_MATCH_TTL
config IP_NF_FILTER
tristate "Packet filtering"
default m if NETFILTER_ADVANCED=n
- select IP_NF_IPTABLES_LEGACY
+ depends on IP_NF_IPTABLES_LEGACY
help
Packet filtering defines a table `filter', which has a series of
rules for simple packet filtering at local input, forwarding and
@@ -217,7 +222,7 @@ config IP_NF_NAT
default m if NETFILTER_ADVANCED=n
select NF_NAT
select NETFILTER_XT_NAT
- select IP_NF_IPTABLES_LEGACY
+ depends on IP_NF_IPTABLES_LEGACY
help
This enables the `nat' table in iptables. This allows masquerading,
port forwarding and other forms of full Network Address Port
@@ -258,7 +263,7 @@ endif # IP_NF_NAT
config IP_NF_MANGLE
tristate "Packet mangling"
default m if NETFILTER_ADVANCED=n
- select IP_NF_IPTABLES_LEGACY
+ depends on IP_NF_IPTABLES_LEGACY
help
This option adds a `mangle' table to iptables: see the man page for
iptables(8). This table is used for various packet alterations
@@ -293,7 +298,7 @@ config IP_NF_TARGET_TTL
# raw + specific targets
config IP_NF_RAW
tristate 'raw table support (required for NOTRACK/TRACE)'
- select IP_NF_IPTABLES_LEGACY
+ depends on IP_NF_IPTABLES_LEGACY
help
This option adds a `raw' table to iptables. This table is the very
first in the netfilter framework and hooks in at the PREROUTING
@@ -305,9 +310,7 @@ config IP_NF_RAW
# security table for MAC policy
config IP_NF_SECURITY
tristate "Security table"
- depends on SECURITY
- depends on NETFILTER_ADVANCED
- select IP_NF_IPTABLES_LEGACY
+ depends on SECURITY && NETFILTER_ADVANCED && IP_NF_IPTABLES_LEGACY
help
This option adds a `security' table to iptables, for use
with Mandatory Access Control (MAC) policy.
diff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config
index 5b9baf708950..90e997cfa12e 100644
--- a/tools/testing/selftests/net/config
+++ b/tools/testing/selftests/net/config
@@ -28,6 +28,7 @@ CONFIG_NET_FOU=y
CONFIG_NET_FOU_IP_TUNNELS=y
CONFIG_NETFILTER=y
CONFIG_NETFILTER_ADVANCED=y
+CONFIG_NETFILTER_XT_TARGET_HL=m
CONFIG_NF_CONNTRACK=m
CONFIG_IPV6_MROUTE=y
CONFIG_IPV6_SIT=y
@@ -35,6 +36,11 @@ CONFIG_IP_DCCP=m
CONFIG_NF_NAT=m
CONFIG_IP6_NF_IPTABLES=m
CONFIG_IP_NF_IPTABLES=m
+CONFIG_IP_NF_IPTABLES_LEGACY=m
+CONFIG_IP_NF_FILTER=m
+CONFIG_IP_NF_TARGET_REJECT=m
+CONFIG_IP_NF_TARGET_MASQUERADE=m
+CONFIG_IP_NF_MANGLE=m
CONFIG_IP6_NF_NAT=m
CONFIG_IP6_NF_RAW=m
CONFIG_IP_NF_NAT=m
@@ -54,6 +60,7 @@ CONFIG_MPTCP=y
CONFIG_NF_TABLES=m
CONFIG_NF_TABLES_IPV6=y
CONFIG_NF_TABLES_IPV4=y
+CONFIG_NF_REJECT_IPV4=y
CONFIG_NFT_NAT=m
CONFIG_NETFILTER_XT_MATCH_LENGTH=m
CONFIG_NET_ACT_CSUM=m
@@ -106,4 +113,5 @@ CONFIG_CRYPTO_ARIA=y
CONFIG_XFRM_INTERFACE=m
CONFIG_XFRM_USER=m
CONFIG_IP_NF_MATCH_RPFILTER=m
+CONFIG_IP_NF_TARGET_MASQUERADE=m
CONFIG_IP6_NF_MATCH_RPFILTER=m
--
2.43.5
[Problem]
Sometimes, we have only x86_64 server for compiling BPF with target ARCH of arm64.
Therefore, the only way to debug bpf is using cross-compile and qemu.
Unfortunately, debugging online on VM is very inconvenient, when test_progs fails.
Such as:
1. We are unable to directly replace old test object
and still need to quit VM and restart, which consumes valuable time.
2. We also want to share other tools or binaries online for execution on the VM,
which is not supported by VM.
[Optimization]
I noitce that CONFIG_9P_FS is enabled in "config.vm",
so virtFS (9p virtio) is available on VM.
To achieve it, I add a new init file on qemu,
which only exists when '-v' option is appended.
root@(none):/# cat /etc/rcS.d/S20-testDebug
#!/bin/sh
set -x
rm -rf /mnt/shared
mkdir -p /mnt/shared
/bin/mount -t 9p -o trans=virtio,version=9p2000.L host0 /mnt/shared
[Usage]
Append the option '-v' to enable it.
For instance:
LDLIBS=-static ./vmtest.sh -v -s -- ./test_progs -t d_path
This will share the directory
between VM's "/mnt/shared" with host's *${OUTPUT_DIR}/${MOUNT_DIR}/shared*.
On host:
$ mv ./test_progs ~/workplace/bpf/arm64/.bpf_selftests/mnt/shared/
On VM(you can directly move it into /root/bpf):
root@(none):/# ls /mnt/shared/
test_progs
Signed-off-by: Lin Yikai <yikai.lin(a)vivo.com>
---
tools/testing/selftests/bpf/vmtest.sh | 75 ++++++++++++++++++++++++++-
1 file changed, 73 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/vmtest.sh b/tools/testing/selftests/bpf/vmtest.sh
index c7461ed496ab..82afadde50da 100755
--- a/tools/testing/selftests/bpf/vmtest.sh
+++ b/tools/testing/selftests/bpf/vmtest.sh
@@ -70,10 +70,15 @@ LOG_FILE_BASE="$(date +"bpf_selftests.%Y-%m-%d_%H-%M-%S")"
LOG_FILE="${LOG_FILE_BASE}.log"
EXIT_STATUS_FILE="${LOG_FILE_BASE}.exit_status"
+DEBUG_CMD_INIT=""
+DEBUG_FILE_INIT="S20-testDebug"
+QEMU_FLAG_VIRTFS=""
+
+
usage()
{
cat <<EOF
-Usage: $0 [-i] [-s] [-d <output_dir>] -- [<command>]
+Usage: $0 [-i] [-s] [-v] [-d <output_dir>] -- [<command>]
<command> is the command you would normally run when you are in
tools/testing/selftests/bpf. e.g:
@@ -101,6 +106,8 @@ Options:
-s) Instead of powering off the VM, start an interactive
shell. If <command> is specified, the shell runs after
the command finishes executing
+ -v) enable virtFS (9p virtio) for sharing directory
+ of "/mnt/shared" on the VM
EOF
}
@@ -275,6 +282,7 @@ EOF
-serial mon:stdio \
"${QEMU_FLAGS[@]}" \
-enable-kvm \
+ ${QEMU_FLAG_VIRTFS} \
-m 4G \
-drive file="${rootfs_img}",format=raw,index=1,media=disk,if=virtio,cache=none \
-kernel "${kernel_bzimage}" \
@@ -354,6 +362,60 @@ catch()
exit ${exit_code}
}
+update_debug_init()
+{
+ #You can do something else just for debuging on qemu.
+ #The init script will be reset every time before vm running on host,
+ #and be executed on qemu before test_progs.
+ local init_script_dir="${OUTPUT_DIR}/${MOUNT_DIR}/etc/rcS.d"
+ local init_script_file="${init_script_dir}/${DEBUG_FILE_INIT}"
+
+ mount_image
+ if [[ "${DEBUG_CMD_INIT}" == "" ]]; then
+ sudo rm -rf ${init_script_file}
+ unmount_image
+ return
+ fi
+
+ if [[ ! -d "${init_script_dir}" ]]; then
+ cat <<EOF
+Could not find ${init_script_dir} in the mounted image.
+This likely indicates a bad or not default rootfs image,
+You need to change debug init manually
+according to the actual situation of the rootfs image.
+EOF
+ unmount_image
+ exit 1
+ fi
+
+ sudo bash -c "cat > ${init_script_file}" <<EOF
+#!/bin/sh
+set -x
+${DEBUG_CMD_INIT}
+EOF
+ sudo chmod 755 "${init_script_file}"
+ unmount_image
+}
+
+#Establish shared dir access by 9p virtfs
+#between "/mnt/shared" on qemu with *${OUTPUT_DIR}/${MOUNT_DIR}/shared* on local host.
+debug_by_virtfs_shared()
+{
+ local qemu_shared_dir="/mnt/shared"
+ local host_shared_dir="${OUTPUT_DIR}/${MOUNT_DIR}/shared"
+
+ #append virtfs shared flag for qemu
+ local flag="-virtfs local,mount_tag=host0,security_model=passthrough,id=host0,path=${host_shared_dir}"
+ mkdir -p "${host_shared_dir}"
+ QEMU_FLAG_VIRTFS="${QEMU_FLAG_VIRTFS} ${flag}"
+
+ #append mount cmd into init
+ DEBUG_CMD_INIT="${DEBUG_CMD_INIT}\
+rm -rf ${qemu_shared_dir}
+mkdir -p ${qemu_shared_dir}
+/bin/mount -t 9p -o trans=virtio,version=9p2000.L host0 ${qemu_shared_dir}"
+}
+
main()
{
local script_dir="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
@@ -365,8 +427,9 @@ main()
local update_image="no"
local exit_command="poweroff -f"
local debug_shell="no"
+ local enable_virtfs_shared="no"
- while getopts ':hskid:j:' opt; do
+ while getopts ':vhskid:j:' opt; do
case ${opt} in
i)
update_image="yes"
@@ -382,6 +445,9 @@ main()
debug_shell="yes"
exit_command="bash"
;;
+ v)
+ enable_virtfs_shared="yes"
+ ;;
h)
usage
exit 0
@@ -449,6 +515,11 @@ main()
create_vm_image
fi
+ if [[ "${enable_virtfs_shared}" == "yes" ]]; then
+ debug_by_virtfs_shared
+ fi
+ update_debug_init
+
update_selftests "${kernel_checkout}" "${make_command}"
update_init_script "${command}" "${exit_command}"
run_vm "${kernel_bzimage}"
--
2.34.1