Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net

No conflicts.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski
2022-02-03 17:36:16 -08:00
405 changed files with 4031 additions and 2044 deletions

View File

@@ -6,6 +6,7 @@
# Author: Felix Guo <felixguoxiuping@gmail.com>
# Author: Brendan Higgins <brendanhiggins@google.com>
import importlib.abc
import importlib.util
import logging
import subprocess

View File

@@ -74,7 +74,7 @@ static inline unsigned long page_to_phys(struct page *page)
__UNIQUE_ID(min1_), __UNIQUE_ID(min2_), \
x, y)
#define preemptible() (1)
#define pagefault_disabled() (0)
static inline void *kmap(struct page *page)
{
@@ -127,6 +127,7 @@ kmalloc_array(unsigned int n, unsigned int size, unsigned int flags)
#define kmemleak_free(a)
#define PageSlab(p) (0)
#define flush_dcache_page(p)
#define MAX_ERRNO 4095

View File

@@ -261,7 +261,7 @@ static void ptrace_sve_fpsimd(pid_t child, const struct vec_type *type)
}
ksft_test_result((sve->flags & SVE_PT_REGS_MASK) == SVE_PT_REGS_FPSIMD,
"Set FPSIMD registers via %s\n", type->name);
"Got FPSIMD registers via %s\n", type->name);
if ((sve->flags & SVE_PT_REGS_MASK) != SVE_PT_REGS_FPSIMD)
goto out;
@@ -557,7 +557,14 @@ static int do_parent(pid_t child)
}
/* prctl() flags */
ptrace_set_get_inherit(child, &vec_types[i]);
if (getauxval(vec_types[i].hwcap_type) & vec_types[i].hwcap) {
ptrace_set_get_inherit(child, &vec_types[i]);
} else {
ksft_test_result_skip("%s SVE_PT_VL_INHERIT set\n",
vec_types[i].name);
ksft_test_result_skip("%s SVE_PT_VL_INHERIT cleared\n",
vec_types[i].name);
}
/* Step through every possible VQ */
for (vq = SVE_VQ_MIN; vq <= SVE_VQ_MAX; vq++) {

View File

@@ -28,7 +28,6 @@
// 5. We can read keycode from same /dev/lirc device
#include <linux/bpf.h>
#include <linux/lirc.h>
#include <linux/input.h>
#include <errno.h>
#include <stdio.h>

View File

@@ -194,5 +194,5 @@ prerequisite
# Run requested functions
clear_dumps $OUTFILE
do_test >> $OUTFILE.txt
do_test | tee -a $OUTFILE.txt
dmesg_dumps $OUTFILE

View File

@@ -5,7 +5,7 @@ CFLAGS += -D_GNU_SOURCE
TEST_PROGS := binfmt_script non-regular
TEST_GEN_PROGS := execveat load_address_4096 load_address_2097152 load_address_16777216
TEST_GEN_FILES := execveat.symlink execveat.denatured script subdir pipe
TEST_GEN_FILES := execveat.symlink execveat.denatured script subdir
# Makefile is a run-time dependency, since it's accessed by the execveat test
TEST_FILES := Makefile

View File

@@ -11,7 +11,7 @@ all:
@for DIR in $(SUBDIRS); do \
BUILD_TARGET=$(OUTPUT)/$$DIR; \
mkdir $$BUILD_TARGET -p; \
make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
if [ -e $$DIR/$(TEST_PROGS) ]; then \
rsync -a $$DIR/$(TEST_PROGS) $$BUILD_TARGET/; \
fi \
@@ -32,6 +32,6 @@ override define CLEAN
@for DIR in $(SUBDIRS); do \
BUILD_TARGET=$(OUTPUT)/$$DIR; \
mkdir $$BUILD_TARGET -p; \
make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
done
endef

View File

@@ -877,7 +877,8 @@ static void __timeout_handler(int sig, siginfo_t *info, void *ucontext)
}
t->timed_out = true;
kill(t->pid, SIGKILL);
// signal process group
kill(-(t->pid), SIGKILL);
}
void __wait_for_test(struct __test_metadata *t)
@@ -987,6 +988,7 @@ void __run_test(struct __fixture_metadata *f,
ksft_print_msg("ERROR SPAWNING TEST CHILD\n");
t->passed = 0;
} else if (t->pid == 0) {
setpgrp();
t->fn(t, variant);
if (t->skip)
_exit(255);

View File

@@ -85,6 +85,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/xen_vmcall_test
TEST_GEN_PROGS_x86_64 += x86_64/vmx_pi_mmio_test
TEST_GEN_PROGS_x86_64 += x86_64/sev_migrate_tests
TEST_GEN_PROGS_x86_64 += x86_64/amx_test
TEST_GEN_PROGS_x86_64 += access_tracking_perf_test
TEST_GEN_PROGS_x86_64 += demand_paging_test
TEST_GEN_PROGS_x86_64 += dirty_log_test
TEST_GEN_PROGS_x86_64 += dirty_log_perf_test

View File

@@ -345,7 +345,6 @@ struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus,
* guest_code - The vCPU's entry point
*/
void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code);
void vm_xsave_req_perm(void);
bool vm_is_unrestricted_guest(struct kvm_vm *vm);

View File

@@ -458,6 +458,7 @@ uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2,
struct kvm_cpuid2 *kvm_get_supported_hv_cpuid(void);
void vcpu_set_hv_cpuid(struct kvm_vm *vm, uint32_t vcpuid);
struct kvm_cpuid2 *vcpu_get_supported_hv_cpuid(struct kvm_vm *vm, uint32_t vcpuid);
void vm_xsave_req_perm(int bit);
enum x86_page_size {
X86_PAGE_SIZE_4K = 0,

View File

@@ -393,13 +393,6 @@ struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus,
struct kvm_vm *vm;
int i;
#ifdef __x86_64__
/*
* Permission needs to be requested before KVM_SET_CPUID2.
*/
vm_xsave_req_perm();
#endif
/* Force slot0 memory size not small than DEFAULT_GUEST_PHY_PAGES */
if (slot0_mem_pages < DEFAULT_GUEST_PHY_PAGES)
slot0_mem_pages = DEFAULT_GUEST_PHY_PAGES;

View File

@@ -665,16 +665,31 @@ static bool is_xfd_supported(void)
return !!(eax & CPUID_XFD_BIT);
}
void vm_xsave_req_perm(void)
void vm_xsave_req_perm(int bit)
{
unsigned long bitmask;
int kvm_fd;
u64 bitmask;
long rc;
struct kvm_device_attr attr = {
.group = 0,
.attr = KVM_X86_XCOMP_GUEST_SUPP,
.addr = (unsigned long) &bitmask
};
kvm_fd = open_kvm_dev_path_or_exit();
rc = ioctl(kvm_fd, KVM_GET_DEVICE_ATTR, &attr);
close(kvm_fd);
if (rc == -1 && (errno == ENXIO || errno == EINVAL))
exit(KSFT_SKIP);
TEST_ASSERT(rc == 0, "KVM_GET_DEVICE_ATTR(0, KVM_X86_XCOMP_GUEST_SUPP) error: %ld", rc);
if (!(bitmask & (1ULL << bit)))
exit(KSFT_SKIP);
if (!is_xfd_supported())
return;
exit(KSFT_SKIP);
rc = syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_GUEST_PERM, bit);
rc = syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_GUEST_PERM,
XSTATE_XTILE_DATA_BIT);
/*
* The older kernel version(<5.15) can't support
* ARCH_REQ_XCOMP_GUEST_PERM and directly return.
@@ -684,7 +699,7 @@ void vm_xsave_req_perm(void)
rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_GUEST_PERM, &bitmask);
TEST_ASSERT(rc == 0, "prctl(ARCH_GET_XCOMP_GUEST_PERM) error: %ld", rc);
TEST_ASSERT(bitmask & XFEATURE_XTILE_MASK,
TEST_ASSERT(bitmask & (1ULL << bit),
"prctl(ARCH_REQ_XCOMP_GUEST_PERM) failure bitmask=0x%lx",
bitmask);
}

View File

@@ -329,6 +329,8 @@ int main(int argc, char *argv[])
u32 amx_offset;
int stage, ret;
vm_xsave_req_perm(XSTATE_XTILE_DATA_BIT);
/* Create VM */
vm = vm_create_default(VCPU_ID, 0, guest_code);

View File

@@ -105,7 +105,6 @@ static void guest_code(void *arg)
if (cpu_has_svm()) {
run_guest(svm->vmcb, svm->vmcb_gpa);
svm->vmcb->save.rip += 3;
run_guest(svm->vmcb, svm->vmcb_gpa);
} else {
vmlaunch();

View File

@@ -207,15 +207,21 @@ TEST(check_file_mmap)
errno = 0;
fd = open(".", O_TMPFILE | O_RDWR, 0600);
ASSERT_NE(-1, fd) {
TH_LOG("Can't create temporary file: %s",
strerror(errno));
if (fd < 0) {
ASSERT_EQ(errno, EOPNOTSUPP) {
TH_LOG("Can't create temporary file: %s",
strerror(errno));
}
SKIP(goto out_free, "O_TMPFILE not supported by filesystem.");
}
errno = 0;
retval = fallocate(fd, 0, 0, FILE_SIZE);
ASSERT_EQ(0, retval) {
TH_LOG("Error allocating space for the temporary file: %s",
strerror(errno));
if (retval) {
ASSERT_EQ(errno, EOPNOTSUPP) {
TH_LOG("Error allocating space for the temporary file: %s",
strerror(errno));
}
SKIP(goto out_close, "fallocate not supported by filesystem.");
}
/*
@@ -271,7 +277,9 @@ TEST(check_file_mmap)
}
munmap(addr, FILE_SIZE);
out_close:
close(fd);
out_free:
free(vec);
}

View File

@@ -27,7 +27,7 @@ TYPES="net_port port_net net6_port port_proto net6_port_mac net6_port_mac_proto
net6_port_net6_port net_port_mac_proto_net"
# Reported bugs, also described by TYPE_ variables below
BUGS="flush_remove_add"
BUGS="flush_remove_add reload"
# List of possible paths to pktgen script from kernel tree for performance tests
PKTGEN_SCRIPT_PATHS="
@@ -354,6 +354,23 @@ TYPE_flush_remove_add="
display Add two elements, flush, re-add
"
TYPE_reload="
display net,mac with reload
type_spec ipv4_addr . ether_addr
chain_spec ip daddr . ether saddr
dst addr4
src mac
start 1
count 1
src_delta 2000
tools sendip nc bash
proto udp
race_repeat 0
perf_duration 0
"
# Set template for all tests, types and rules are filled in depending on test
set_template='
flush ruleset
@@ -1473,6 +1490,59 @@ test_bug_flush_remove_add() {
nft flush ruleset
}
# - add ranged element, check that packets match it
# - reload the set, check packets still match
test_bug_reload() {
setup veth send_"${proto}" set || return ${KSELFTEST_SKIP}
rstart=${start}
range_size=1
for i in $(seq "${start}" $((start + count))); do
end=$((start + range_size))
# Avoid negative or zero-sized port ranges
if [ $((end / 65534)) -gt $((start / 65534)) ]; then
start=${end}
end=$((end + 1))
fi
srcstart=$((start + src_delta))
srcend=$((end + src_delta))
add "$(format)" || return 1
range_size=$((range_size + 1))
start=$((end + range_size))
done
# check kernel does allocate pcpu sctrach map
# for reload with no elemet add/delete
( echo flush set inet filter test ;
nft list set inet filter test ) | nft -f -
start=${rstart}
range_size=1
for i in $(seq "${start}" $((start + count))); do
end=$((start + range_size))
# Avoid negative or zero-sized port ranges
if [ $((end / 65534)) -gt $((start / 65534)) ]; then
start=${end}
end=$((end + 1))
fi
srcstart=$((start + src_delta))
srcend=$((end + src_delta))
for j in $(seq ${start} $((range_size / 2 + 1)) ${end}); do
send_match "${j}" $((j + src_delta)) || return 1
done
range_size=$((range_size + 1))
start=$((end + range_size))
done
nft flush ruleset
}
test_reported_issues() {
eval test_bug_"${subtest}"
}

View File

@@ -899,6 +899,144 @@ EOF
ip netns exec "$ns0" nft delete table $family nat
}
test_stateless_nat_ip()
{
local lret=0
ip netns exec "$ns0" sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null
ip netns exec "$ns0" sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null
ip netns exec "$ns2" ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
if [ $? -ne 0 ] ; then
echo "ERROR: cannot ping $ns1 from $ns2 before loading stateless rules"
return 1
fi
ip netns exec "$ns0" nft -f /dev/stdin <<EOF
table ip stateless {
map xlate_in {
typeof meta iifname . ip saddr . ip daddr : ip daddr
elements = {
"veth1" . 10.0.2.99 . 10.0.1.99 : 10.0.2.2,
}
}
map xlate_out {
typeof meta iifname . ip saddr . ip daddr : ip daddr
elements = {
"veth0" . 10.0.1.99 . 10.0.2.2 : 10.0.2.99
}
}
chain prerouting {
type filter hook prerouting priority -400; policy accept;
ip saddr set meta iifname . ip saddr . ip daddr map @xlate_in
ip daddr set meta iifname . ip saddr . ip daddr map @xlate_out
}
}
EOF
if [ $? -ne 0 ]; then
echo "SKIP: Could not add ip statless rules"
return $ksft_skip
fi
reset_counters
ip netns exec "$ns2" ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
if [ $? -ne 0 ] ; then
echo "ERROR: cannot ping $ns1 from $ns2 with stateless rules"
lret=1
fi
# ns1 should have seen packets from .2.2, due to stateless rewrite.
expect="packets 1 bytes 84"
cnt=$(ip netns exec "$ns1" nft list counter inet filter ns0insl | grep -q "$expect")
if [ $? -ne 0 ]; then
bad_counter "$ns1" ns0insl "$expect" "test_stateless 1"
lret=1
fi
for dir in "in" "out" ; do
cnt=$(ip netns exec "$ns2" nft list counter inet filter ns1${dir} | grep -q "$expect")
if [ $? -ne 0 ]; then
bad_counter "$ns2" ns1$dir "$expect" "test_stateless 2"
lret=1
fi
done
# ns1 should not have seen packets from ns2, due to masquerade
expect="packets 0 bytes 0"
for dir in "in" "out" ; do
cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect")
if [ $? -ne 0 ]; then
bad_counter "$ns1" ns0$dir "$expect" "test_stateless 3"
lret=1
fi
cnt=$(ip netns exec "$ns0" nft list counter inet filter ns1${dir} | grep -q "$expect")
if [ $? -ne 0 ]; then
bad_counter "$ns0" ns1$dir "$expect" "test_stateless 4"
lret=1
fi
done
reset_counters
socat -h > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Could not run stateless nat frag test without socat tool"
if [ $lret -eq 0 ]; then
return $ksft_skip
fi
ip netns exec "$ns0" nft delete table ip stateless
return $lret
fi
local tmpfile=$(mktemp)
dd if=/dev/urandom of=$tmpfile bs=4096 count=1 2>/dev/null
local outfile=$(mktemp)
ip netns exec "$ns1" timeout 3 socat -u UDP4-RECV:4233 OPEN:$outfile < /dev/null &
sc_r=$!
sleep 1
# re-do with large ping -> ip fragmentation
ip netns exec "$ns2" timeout 3 socat - UDP4-SENDTO:"10.0.1.99:4233" < "$tmpfile" > /dev/null
if [ $? -ne 0 ] ; then
echo "ERROR: failed to test udp $ns1 to $ns2 with stateless ip nat" 1>&2
lret=1
fi
wait
cmp "$tmpfile" "$outfile"
if [ $? -ne 0 ]; then
ls -l "$tmpfile" "$outfile"
echo "ERROR: in and output file mismatch when checking udp with stateless nat" 1>&2
lret=1
fi
rm -f "$tmpfile" "$outfile"
# ns1 should have seen packets from 2.2, due to stateless rewrite.
expect="packets 3 bytes 4164"
cnt=$(ip netns exec "$ns1" nft list counter inet filter ns0insl | grep -q "$expect")
if [ $? -ne 0 ]; then
bad_counter "$ns1" ns0insl "$expect" "test_stateless 5"
lret=1
fi
ip netns exec "$ns0" nft delete table ip stateless
if [ $? -ne 0 ]; then
echo "ERROR: Could not delete table ip stateless" 1>&2
lret=1
fi
test $lret -eq 0 && echo "PASS: IP statless for $ns2"
return $lret
}
# ip netns exec "$ns0" ping -c 1 -q 10.0.$i.99
for i in 0 1 2; do
ip netns exec ns$i-$sfx nft -f /dev/stdin <<EOF
@@ -965,6 +1103,19 @@ table inet filter {
EOF
done
# special case for stateless nat check, counter needs to
# be done before (input) ip defragmentation
ip netns exec ns1-$sfx nft -f /dev/stdin <<EOF
table inet filter {
counter ns0insl {}
chain pre {
type filter hook prerouting priority -400; policy accept;
ip saddr 10.0.2.2 counter name "ns0insl"
}
}
EOF
sleep 3
# test basic connectivity
for i in 1 2; do
@@ -1019,6 +1170,7 @@ $test_inet_nat && test_redirect inet
$test_inet_nat && test_redirect6 inet
test_port_shadowing
test_stateless_nat_ip
if [ $ret -ne 0 ];then
echo -n "FAIL: "

View File

@@ -9,7 +9,7 @@ ns="ns-$sfx"
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
zones=20000
zones=2000
have_ct_tool=0
ret=0
@@ -75,10 +75,10 @@ EOF
while [ $i -lt $max_zones ]; do
local start=$(date +%s%3N)
i=$((i + 10000))
i=$((i + 1000))
j=$((j + 1))
# nft rule in output places each packet in a different zone.
dd if=/dev/zero of=/dev/stdout bs=8k count=10000 2>/dev/null | ip netns exec "$ns" socat STDIN UDP:127.0.0.1:12345,sourceport=12345
dd if=/dev/zero of=/dev/stdout bs=8k count=1000 2>/dev/null | ip netns exec "$ns" socat STDIN UDP:127.0.0.1:12345,sourceport=12345
if [ $? -ne 0 ] ;then
ret=1
break
@@ -86,7 +86,7 @@ EOF
stop=$(date +%s%3N)
local duration=$((stop-start))
echo "PASS: added 10000 entries in $duration ms (now $i total, loop $j)"
echo "PASS: added 1000 entries in $duration ms (now $i total, loop $j)"
done
if [ $have_ct_tool -eq 1 ]; then
@@ -128,11 +128,11 @@ test_conntrack_tool() {
break
fi
if [ $((i%10000)) -eq 0 ];then
if [ $((i%1000)) -eq 0 ];then
stop=$(date +%s%3N)
local duration=$((stop-start))
echo "PASS: added 10000 entries in $duration ms (now $i total)"
echo "PASS: added 1000 entries in $duration ms (now $i total)"
start=$stop
fi
done

View File

@@ -5,4 +5,4 @@ TEST_GEN_PROGS := openat2_test resolve_test rename_attack_test
include ../lib.mk
$(TEST_GEN_PROGS): helpers.c
$(TEST_GEN_PROGS): helpers.c helpers.h

View File

@@ -9,6 +9,7 @@
#define _GNU_SOURCE
#include <stdint.h>
#include <stdbool.h>
#include <errno.h>
#include <linux/types.h>
#include "../kselftest.h"
@@ -62,11 +63,12 @@ bool needs_openat2(const struct open_how *how);
(similar to chroot(2)). */
#endif /* RESOLVE_IN_ROOT */
#define E_func(func, ...) \
do { \
if (func(__VA_ARGS__) < 0) \
ksft_exit_fail_msg("%s:%d %s failed\n", \
__FILE__, __LINE__, #func);\
#define E_func(func, ...) \
do { \
errno = 0; \
if (func(__VA_ARGS__) < 0) \
ksft_exit_fail_msg("%s:%d %s failed - errno:%d\n", \
__FILE__, __LINE__, #func, errno); \
} while (0)
#define E_asprintf(...) E_func(asprintf, __VA_ARGS__)

View File

@@ -259,6 +259,16 @@ void test_openat2_flags(void)
unlink(path);
fd = sys_openat2(AT_FDCWD, path, &test->how);
if (fd < 0 && fd == -EOPNOTSUPP) {
/*
* Skip the testcase if it failed because not supported
* by FS. (e.g. a valid O_TMPFILE combination on NFS)
*/
ksft_test_result_skip("openat2 with %s fails with %d (%s)\n",
test->name, fd, strerror(-fd));
goto next;
}
if (test->err >= 0)
failed = (fd < 0);
else
@@ -303,7 +313,7 @@ skip:
else
resultfn("openat2 with %s fails with %d (%s)\n",
test->name, test->err, strerror(-test->err));
next:
free(fdpath);
fflush(stdout);
}

View File

@@ -1 +1 @@
timeout=90
timeout=180

View File

@@ -33,110 +33,114 @@ typedef long (*vdso_clock_gettime_t)(clockid_t clk_id, struct timespec *ts);
typedef long (*vdso_clock_getres_t)(clockid_t clk_id, struct timespec *ts);
typedef time_t (*vdso_time_t)(time_t *t);
static int vdso_test_gettimeofday(void)
#define VDSO_TEST_PASS_MSG() "\n%s(): PASS\n", __func__
#define VDSO_TEST_FAIL_MSG(x) "\n%s(): %s FAIL\n", __func__, x
#define VDSO_TEST_SKIP_MSG(x) "\n%s(): SKIP: Could not find %s\n", __func__, x
static void vdso_test_gettimeofday(void)
{
/* Find gettimeofday. */
vdso_gettimeofday_t vdso_gettimeofday =
(vdso_gettimeofday_t)vdso_sym(version, name[0]);
if (!vdso_gettimeofday) {
printf("Could not find %s\n", name[0]);
return KSFT_SKIP;
ksft_test_result_skip(VDSO_TEST_SKIP_MSG(name[0]));
return;
}
struct timeval tv;
long ret = vdso_gettimeofday(&tv, 0);
if (ret == 0) {
printf("The time is %lld.%06lld\n",
(long long)tv.tv_sec, (long long)tv.tv_usec);
ksft_print_msg("The time is %lld.%06lld\n",
(long long)tv.tv_sec, (long long)tv.tv_usec);
ksft_test_result_pass(VDSO_TEST_PASS_MSG());
} else {
printf("%s failed\n", name[0]);
return KSFT_FAIL;
ksft_test_result_fail(VDSO_TEST_FAIL_MSG(name[0]));
}
return KSFT_PASS;
}
static int vdso_test_clock_gettime(clockid_t clk_id)
static void vdso_test_clock_gettime(clockid_t clk_id)
{
/* Find clock_gettime. */
vdso_clock_gettime_t vdso_clock_gettime =
(vdso_clock_gettime_t)vdso_sym(version, name[1]);
if (!vdso_clock_gettime) {
printf("Could not find %s\n", name[1]);
return KSFT_SKIP;
ksft_test_result_skip(VDSO_TEST_SKIP_MSG(name[1]));
return;
}
struct timespec ts;
long ret = vdso_clock_gettime(clk_id, &ts);
if (ret == 0) {
printf("The time is %lld.%06lld\n",
(long long)ts.tv_sec, (long long)ts.tv_nsec);
ksft_print_msg("The time is %lld.%06lld\n",
(long long)ts.tv_sec, (long long)ts.tv_nsec);
ksft_test_result_pass(VDSO_TEST_PASS_MSG());
} else {
printf("%s failed\n", name[1]);
return KSFT_FAIL;
ksft_test_result_fail(VDSO_TEST_FAIL_MSG(name[1]));
}
return KSFT_PASS;
}
static int vdso_test_time(void)
static void vdso_test_time(void)
{
/* Find time. */
vdso_time_t vdso_time =
(vdso_time_t)vdso_sym(version, name[2]);
if (!vdso_time) {
printf("Could not find %s\n", name[2]);
return KSFT_SKIP;
ksft_test_result_skip(VDSO_TEST_SKIP_MSG(name[2]));
return;
}
long ret = vdso_time(NULL);
if (ret > 0) {
printf("The time in hours since January 1, 1970 is %lld\n",
ksft_print_msg("The time in hours since January 1, 1970 is %lld\n",
(long long)(ret / 3600));
ksft_test_result_pass(VDSO_TEST_PASS_MSG());
} else {
printf("%s failed\n", name[2]);
return KSFT_FAIL;
ksft_test_result_fail(VDSO_TEST_FAIL_MSG(name[2]));
}
return KSFT_PASS;
}
static int vdso_test_clock_getres(clockid_t clk_id)
static void vdso_test_clock_getres(clockid_t clk_id)
{
int clock_getres_fail = 0;
/* Find clock_getres. */
vdso_clock_getres_t vdso_clock_getres =
(vdso_clock_getres_t)vdso_sym(version, name[3]);
if (!vdso_clock_getres) {
printf("Could not find %s\n", name[3]);
return KSFT_SKIP;
ksft_test_result_skip(VDSO_TEST_SKIP_MSG(name[3]));
return;
}
struct timespec ts, sys_ts;
long ret = vdso_clock_getres(clk_id, &ts);
if (ret == 0) {
printf("The resolution is %lld %lld\n",
(long long)ts.tv_sec, (long long)ts.tv_nsec);
ksft_print_msg("The vdso resolution is %lld %lld\n",
(long long)ts.tv_sec, (long long)ts.tv_nsec);
} else {
printf("%s failed\n", name[3]);
return KSFT_FAIL;
clock_getres_fail++;
}
ret = syscall(SYS_clock_getres, clk_id, &sys_ts);
if ((sys_ts.tv_sec != ts.tv_sec) || (sys_ts.tv_nsec != ts.tv_nsec)) {
printf("%s failed\n", name[3]);
return KSFT_FAIL;
}
ksft_print_msg("The syscall resolution is %lld %lld\n",
(long long)sys_ts.tv_sec, (long long)sys_ts.tv_nsec);
return KSFT_PASS;
if ((sys_ts.tv_sec != ts.tv_sec) || (sys_ts.tv_nsec != ts.tv_nsec))
clock_getres_fail++;
if (clock_getres_fail > 0) {
ksft_test_result_fail(VDSO_TEST_FAIL_MSG(name[3]));
} else {
ksft_test_result_pass(VDSO_TEST_PASS_MSG());
}
}
const char *vdso_clock_name[12] = {
@@ -158,36 +162,23 @@ const char *vdso_clock_name[12] = {
* This function calls vdso_test_clock_gettime and vdso_test_clock_getres
* with different values for clock_id.
*/
static inline int vdso_test_clock(clockid_t clock_id)
static inline void vdso_test_clock(clockid_t clock_id)
{
int ret0, ret1;
ksft_print_msg("\nclock_id: %s\n", vdso_clock_name[clock_id]);
ret0 = vdso_test_clock_gettime(clock_id);
/* A skipped test is considered passed */
if (ret0 == KSFT_SKIP)
ret0 = KSFT_PASS;
vdso_test_clock_gettime(clock_id);
ret1 = vdso_test_clock_getres(clock_id);
/* A skipped test is considered passed */
if (ret1 == KSFT_SKIP)
ret1 = KSFT_PASS;
ret0 += ret1;
printf("clock_id: %s", vdso_clock_name[clock_id]);
if (ret0 > 0)
printf(" [FAIL]\n");
else
printf(" [PASS]\n");
return ret0;
vdso_test_clock_getres(clock_id);
}
#define VDSO_TEST_PLAN 16
int main(int argc, char **argv)
{
unsigned long sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);
int ret;
ksft_print_header();
ksft_set_plan(VDSO_TEST_PLAN);
if (!sysinfo_ehdr) {
printf("AT_SYSINFO_EHDR is not present!\n");
@@ -201,44 +192,42 @@ int main(int argc, char **argv)
vdso_init_from_sysinfo_ehdr(getauxval(AT_SYSINFO_EHDR));
ret = vdso_test_gettimeofday();
vdso_test_gettimeofday();
#if _POSIX_TIMERS > 0
#ifdef CLOCK_REALTIME
ret += vdso_test_clock(CLOCK_REALTIME);
vdso_test_clock(CLOCK_REALTIME);
#endif
#ifdef CLOCK_BOOTTIME
ret += vdso_test_clock(CLOCK_BOOTTIME);
vdso_test_clock(CLOCK_BOOTTIME);
#endif
#ifdef CLOCK_TAI
ret += vdso_test_clock(CLOCK_TAI);
vdso_test_clock(CLOCK_TAI);
#endif
#ifdef CLOCK_REALTIME_COARSE
ret += vdso_test_clock(CLOCK_REALTIME_COARSE);
vdso_test_clock(CLOCK_REALTIME_COARSE);
#endif
#ifdef CLOCK_MONOTONIC
ret += vdso_test_clock(CLOCK_MONOTONIC);
vdso_test_clock(CLOCK_MONOTONIC);
#endif
#ifdef CLOCK_MONOTONIC_RAW
ret += vdso_test_clock(CLOCK_MONOTONIC_RAW);
vdso_test_clock(CLOCK_MONOTONIC_RAW);
#endif
#ifdef CLOCK_MONOTONIC_COARSE
ret += vdso_test_clock(CLOCK_MONOTONIC_COARSE);
vdso_test_clock(CLOCK_MONOTONIC_COARSE);
#endif
#endif
ret += vdso_test_time();
vdso_test_time();
if (ret > 0)
return KSFT_FAIL;
return KSFT_PASS;
ksft_print_cnts();
return ksft_get_fail_cnt() == 0 ? KSFT_PASS : KSFT_FAIL;
}

View File

@@ -2,9 +2,6 @@
# SPDX-License-Identifier: GPL-2.0
TCID="zram.sh"
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
. ./zram_lib.sh
run_zram () {
@@ -18,14 +15,4 @@ echo ""
check_prereqs
# check zram module exists
MODULE_PATH=/lib/modules/`uname -r`/kernel/drivers/block/zram/zram.ko
if [ -f $MODULE_PATH ]; then
run_zram
elif [ -b /dev/zram0 ]; then
run_zram
else
echo "$TCID : No zram.ko module or /dev/zram0 device file not found"
echo "$TCID : CONFIG_ZRAM is not set"
exit $ksft_skip
fi
run_zram

View File

@@ -33,9 +33,7 @@ zram_algs="lzo"
zram_fill_fs()
{
local mem_free0=$(free -m | awk 'NR==2 {print $4}')
for i in $(seq 0 $(($dev_num - 1))); do
for i in $(seq $dev_start $dev_end); do
echo "fill zram$i..."
local b=0
while [ true ]; do
@@ -45,29 +43,17 @@ zram_fill_fs()
b=$(($b + 1))
done
echo "zram$i can be filled with '$b' KB"
local mem_used_total=`awk '{print $3}' "/sys/block/zram$i/mm_stat"`
local v=$((100 * 1024 * $b / $mem_used_total))
if [ "$v" -lt 100 ]; then
echo "FAIL compression ratio: 0.$v:1"
ERR_CODE=-1
return
fi
echo "zram compression ratio: $(echo "scale=2; $v / 100 " | bc):1: OK"
done
local mem_free1=$(free -m | awk 'NR==2 {print $4}')
local used_mem=$(($mem_free0 - $mem_free1))
local total_size=0
for sm in $zram_sizes; do
local s=$(echo $sm | sed 's/M//')
total_size=$(($total_size + $s))
done
echo "zram used ${used_mem}M, zram disk sizes ${total_size}M"
local v=$((100 * $total_size / $used_mem))
if [ "$v" -lt 100 ]; then
echo "FAIL compression ratio: 0.$v:1"
ERR_CODE=-1
zram_cleanup
return
fi
echo "zram compression ratio: $(echo "scale=2; $v / 100 " | bc):1: OK"
}
check_prereqs
@@ -81,7 +67,6 @@ zram_mount
zram_fill_fs
zram_cleanup
zram_unload
if [ $ERR_CODE -ne 0 ]; then
echo "$TCID : [FAIL]"

View File

@@ -36,7 +36,6 @@ zram_set_memlimit
zram_makeswap
zram_swapoff
zram_cleanup
zram_unload
if [ $ERR_CODE -ne 0 ]; then
echo "$TCID : [FAIL]"

View File

@@ -5,12 +5,17 @@
# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
# Modified: Naresh Kamboju <naresh.kamboju@linaro.org>
MODULE=0
dev_makeswap=-1
dev_mounted=-1
dev_start=0
dev_end=-1
module_load=-1
sys_control=-1
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
kernel_version=`uname -r | cut -d'.' -f1,2`
kernel_major=${kernel_version%.*}
kernel_minor=${kernel_version#*.}
trap INT
@@ -25,68 +30,104 @@ check_prereqs()
fi
}
kernel_gte()
{
major=${1%.*}
minor=${1#*.}
if [ $kernel_major -gt $major ]; then
return 0
elif [[ $kernel_major -eq $major && $kernel_minor -ge $minor ]]; then
return 0
fi
return 1
}
zram_cleanup()
{
echo "zram cleanup"
local i=
for i in $(seq 0 $dev_makeswap); do
for i in $(seq $dev_start $dev_makeswap); do
swapoff /dev/zram$i
done
for i in $(seq 0 $dev_mounted); do
for i in $(seq $dev_start $dev_mounted); do
umount /dev/zram$i
done
for i in $(seq 0 $(($dev_num - 1))); do
for i in $(seq $dev_start $dev_end); do
echo 1 > /sys/block/zram${i}/reset
rm -rf zram$i
done
}
if [ $sys_control -eq 1 ]; then
for i in $(seq $dev_start $dev_end); do
echo $i > /sys/class/zram-control/hot_remove
done
fi
zram_unload()
{
if [ $MODULE -ne 0 ] ; then
echo "zram rmmod zram"
if [ $module_load -eq 1 ]; then
rmmod zram > /dev/null 2>&1
fi
}
zram_load()
{
# check zram module exists
MODULE_PATH=/lib/modules/`uname -r`/kernel/drivers/block/zram/zram.ko
if [ -f $MODULE_PATH ]; then
MODULE=1
echo "create '$dev_num' zram device(s)"
modprobe zram num_devices=$dev_num
if [ $? -ne 0 ]; then
echo "failed to insert zram module"
exit 1
fi
echo "create '$dev_num' zram device(s)"
dev_num_created=$(ls /dev/zram* | wc -w)
# zram module loaded, new kernel
if [ -d "/sys/class/zram-control" ]; then
echo "zram modules already loaded, kernel supports" \
"zram-control interface"
dev_start=$(ls /dev/zram* | wc -w)
dev_end=$(($dev_start + $dev_num - 1))
sys_control=1
if [ "$dev_num_created" -ne "$dev_num" ]; then
echo "unexpected num of devices: $dev_num_created"
ERR_CODE=-1
else
echo "zram load module successful"
fi
elif [ -b /dev/zram0 ]; then
echo "/dev/zram0 device file found: OK"
else
echo "ERROR: No zram.ko module or no /dev/zram0 device found"
echo "$TCID : CONFIG_ZRAM is not set"
exit 1
for i in $(seq $dev_start $dev_end); do
cat /sys/class/zram-control/hot_add > /dev/null
done
echo "all zram devices (/dev/zram$dev_start~$dev_end" \
"successfully created"
return 0
fi
# detect old kernel or built-in
modprobe zram num_devices=$dev_num
if [ ! -d "/sys/class/zram-control" ]; then
if grep -q '^zram' /proc/modules; then
rmmod zram > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "zram module is being used on old kernel" \
"without zram-control interface"
exit $ksft_skip
fi
else
echo "test needs CONFIG_ZRAM=m on old kernel without" \
"zram-control interface"
exit $ksft_skip
fi
modprobe zram num_devices=$dev_num
fi
module_load=1
dev_end=$(($dev_num - 1))
echo "all zram devices (/dev/zram0~$dev_end) successfully created"
}
zram_max_streams()
{
echo "set max_comp_streams to zram device(s)"
local i=0
kernel_gte 4.7
if [ $? -eq 0 ]; then
echo "The device attribute max_comp_streams was"\
"deprecated in 4.7"
return 0
fi
local i=$dev_start
for max_s in $zram_max_streams; do
local sys_path="/sys/block/zram${i}/max_comp_streams"
echo $max_s > $sys_path || \
@@ -98,7 +139,7 @@ zram_max_streams()
echo "FAIL can't set max_streams '$max_s', get $max_stream"
i=$(($i + 1))
echo "$sys_path = '$max_streams' ($i/$dev_num)"
echo "$sys_path = '$max_streams'"
done
echo "zram max streams: OK"
@@ -108,15 +149,16 @@ zram_compress_alg()
{
echo "test that we can set compression algorithm"
local algs=$(cat /sys/block/zram0/comp_algorithm)
local i=$dev_start
local algs=$(cat /sys/block/zram${i}/comp_algorithm)
echo "supported algs: $algs"
local i=0
for alg in $zram_algs; do
local sys_path="/sys/block/zram${i}/comp_algorithm"
echo "$alg" > $sys_path || \
echo "FAIL can't set '$alg' to $sys_path"
i=$(($i + 1))
echo "$sys_path = '$alg' ($i/$dev_num)"
echo "$sys_path = '$alg'"
done
echo "zram set compression algorithm: OK"
@@ -125,14 +167,14 @@ zram_compress_alg()
zram_set_disksizes()
{
echo "set disk size to zram device(s)"
local i=0
local i=$dev_start
for ds in $zram_sizes; do
local sys_path="/sys/block/zram${i}/disksize"
echo "$ds" > $sys_path || \
echo "FAIL can't set '$ds' to $sys_path"
i=$(($i + 1))
echo "$sys_path = '$ds' ($i/$dev_num)"
echo "$sys_path = '$ds'"
done
echo "zram set disksizes: OK"
@@ -142,14 +184,14 @@ zram_set_memlimit()
{
echo "set memory limit to zram device(s)"
local i=0
local i=$dev_start
for ds in $zram_mem_limits; do
local sys_path="/sys/block/zram${i}/mem_limit"
echo "$ds" > $sys_path || \
echo "FAIL can't set '$ds' to $sys_path"
i=$(($i + 1))
echo "$sys_path = '$ds' ($i/$dev_num)"
echo "$sys_path = '$ds'"
done
echo "zram set memory limit: OK"
@@ -158,8 +200,8 @@ zram_set_memlimit()
zram_makeswap()
{
echo "make swap with zram device(s)"
local i=0
for i in $(seq 0 $(($dev_num - 1))); do
local i=$dev_start
for i in $(seq $dev_start $dev_end); do
mkswap /dev/zram$i > err.log 2>&1
if [ $? -ne 0 ]; then
cat err.log
@@ -182,7 +224,7 @@ zram_makeswap()
zram_swapoff()
{
local i=
for i in $(seq 0 $dev_makeswap); do
for i in $(seq $dev_start $dev_end); do
swapoff /dev/zram$i > err.log 2>&1
if [ $? -ne 0 ]; then
cat err.log
@@ -196,7 +238,7 @@ zram_swapoff()
zram_makefs()
{
local i=0
local i=$dev_start
for fs in $zram_filesystems; do
# if requested fs not supported default it to ext2
which mkfs.$fs > /dev/null 2>&1 || fs=ext2
@@ -215,7 +257,7 @@ zram_makefs()
zram_mount()
{
local i=0
for i in $(seq 0 $(($dev_num - 1))); do
for i in $(seq $dev_start $dev_end); do
echo "mount /dev/zram$i"
mkdir zram$i
mount /dev/zram$i zram$i > /dev/null || \