aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing
diff options
context:
space:
mode:
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/cxl/cxl_core_exports.c2
-rw-r--r--tools/testing/cxl/test/cxl.c4
-rw-r--r--tools/testing/cxl/test/mem.c2
-rw-r--r--tools/testing/cxl/test/mock.c28
-rw-r--r--tools/testing/nvdimm/test/ndtest.c2
-rw-r--r--tools/testing/selftests/Makefile1
-rw-r--r--tools/testing/selftests/alsa/.gitignore2
-rw-r--r--tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py2
-rw-r--r--tools/testing/selftests/filesystems/binderfs/binderfs_test.c1
-rw-r--r--tools/testing/selftests/kvm/riscv/get-reg-list.c16
-rw-r--r--tools/testing/selftests/module/Makefile12
-rw-r--r--tools/testing/selftests/module/config3
-rwxr-xr-xtools/testing/selftests/module/find_symbol.sh81
-rw-r--r--tools/testing/selftests/mount_setattr/mount_setattr_test.c2
-rw-r--r--tools/testing/selftests/net/Makefile3
-rw-r--r--tools/testing/selftests/net/netlink-dumps.c129
-rw-r--r--tools/testing/selftests/net/rds/Makefile5
-rwxr-xr-xtools/testing/selftests/net/rtnetlink.sh95
-rw-r--r--tools/testing/selftests/pcie_bwctrl/Makefile2
-rwxr-xr-xtools/testing/selftests/pcie_bwctrl/set_pcie_cooling_state.sh122
-rwxr-xr-xtools/testing/selftests/pcie_bwctrl/set_pcie_speed.sh67
-rw-r--r--tools/testing/selftests/riscv/Makefile2
-rw-r--r--tools/testing/selftests/riscv/abi/.gitignore1
-rw-r--r--tools/testing/selftests/riscv/abi/Makefile10
-rw-r--r--tools/testing/selftests/riscv/abi/pointer_masking.c332
-rw-r--r--tools/testing/shared/linux.c14
26 files changed, 907 insertions, 33 deletions
diff --git a/tools/testing/cxl/cxl_core_exports.c b/tools/testing/cxl/cxl_core_exports.c
index 077e6883921d..f088792a8925 100644
--- a/tools/testing/cxl/cxl_core_exports.c
+++ b/tools/testing/cxl/cxl_core_exports.c
@@ -4,4 +4,4 @@
#include "cxl.h"
/* Exporting of cxl_core symbols that are only used by cxl_test */
-EXPORT_SYMBOL_NS_GPL(cxl_num_decoders_committed, CXL);
+EXPORT_SYMBOL_NS_GPL(cxl_num_decoders_committed, "CXL");
diff --git a/tools/testing/cxl/test/cxl.c b/tools/testing/cxl/test/cxl.c
index 050725afa45d..d0337c11f9ee 100644
--- a/tools/testing/cxl/test/cxl.c
+++ b/tools/testing/cxl/test/cxl.c
@@ -1531,5 +1531,5 @@ MODULE_PARM_DESC(interleave_arithmetic, "Modulo:0, XOR:1");
module_init(cxl_test_init);
module_exit(cxl_test_exit);
MODULE_LICENSE("GPL v2");
-MODULE_IMPORT_NS(ACPI);
-MODULE_IMPORT_NS(CXL);
+MODULE_IMPORT_NS("ACPI");
+MODULE_IMPORT_NS("CXL");
diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c
index 71916e0e1546..347c1e7b37bd 100644
--- a/tools/testing/cxl/test/mem.c
+++ b/tools/testing/cxl/test/mem.c
@@ -1679,4 +1679,4 @@ static struct platform_driver cxl_mock_mem_driver = {
module_platform_driver(cxl_mock_mem_driver);
MODULE_LICENSE("GPL v2");
-MODULE_IMPORT_NS(CXL);
+MODULE_IMPORT_NS("CXL");
diff --git a/tools/testing/cxl/test/mock.c b/tools/testing/cxl/test/mock.c
index f4ce96cc11d4..450c7566c33f 100644
--- a/tools/testing/cxl/test/mock.c
+++ b/tools/testing/cxl/test/mock.c
@@ -76,7 +76,7 @@ int __wrap_acpi_table_parse_cedt(enum acpi_cedt_type id,
return rc;
}
-EXPORT_SYMBOL_NS_GPL(__wrap_acpi_table_parse_cedt, ACPI);
+EXPORT_SYMBOL_NS_GPL(__wrap_acpi_table_parse_cedt, "ACPI");
acpi_status __wrap_acpi_evaluate_integer(acpi_handle handle,
acpi_string pathname,
@@ -147,7 +147,7 @@ struct cxl_hdm *__wrap_devm_cxl_setup_hdm(struct cxl_port *port,
return cxlhdm;
}
-EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_setup_hdm, CXL);
+EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_setup_hdm, "CXL");
int __wrap_devm_cxl_add_passthrough_decoder(struct cxl_port *port)
{
@@ -162,7 +162,7 @@ int __wrap_devm_cxl_add_passthrough_decoder(struct cxl_port *port)
return rc;
}
-EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_add_passthrough_decoder, CXL);
+EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_add_passthrough_decoder, "CXL");
int __wrap_devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm,
struct cxl_endpoint_dvsec_info *info)
@@ -179,7 +179,7 @@ int __wrap_devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm,
return rc;
}
-EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_enumerate_decoders, CXL);
+EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_enumerate_decoders, "CXL");
int __wrap_devm_cxl_port_enumerate_dports(struct cxl_port *port)
{
@@ -194,7 +194,7 @@ int __wrap_devm_cxl_port_enumerate_dports(struct cxl_port *port)
return rc;
}
-EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_port_enumerate_dports, CXL);
+EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_port_enumerate_dports, "CXL");
int __wrap_cxl_await_media_ready(struct cxl_dev_state *cxlds)
{
@@ -209,7 +209,7 @@ int __wrap_cxl_await_media_ready(struct cxl_dev_state *cxlds)
return rc;
}
-EXPORT_SYMBOL_NS_GPL(__wrap_cxl_await_media_ready, CXL);
+EXPORT_SYMBOL_NS_GPL(__wrap_cxl_await_media_ready, "CXL");
int __wrap_cxl_hdm_decode_init(struct cxl_dev_state *cxlds,
struct cxl_hdm *cxlhdm,
@@ -226,7 +226,7 @@ int __wrap_cxl_hdm_decode_init(struct cxl_dev_state *cxlds,
return rc;
}
-EXPORT_SYMBOL_NS_GPL(__wrap_cxl_hdm_decode_init, CXL);
+EXPORT_SYMBOL_NS_GPL(__wrap_cxl_hdm_decode_init, "CXL");
int __wrap_cxl_dvsec_rr_decode(struct device *dev, struct cxl_port *port,
struct cxl_endpoint_dvsec_info *info)
@@ -242,7 +242,7 @@ int __wrap_cxl_dvsec_rr_decode(struct device *dev, struct cxl_port *port,
return rc;
}
-EXPORT_SYMBOL_NS_GPL(__wrap_cxl_dvsec_rr_decode, CXL);
+EXPORT_SYMBOL_NS_GPL(__wrap_cxl_dvsec_rr_decode, "CXL");
struct cxl_dport *__wrap_devm_cxl_add_rch_dport(struct cxl_port *port,
struct device *dport_dev,
@@ -266,7 +266,7 @@ struct cxl_dport *__wrap_devm_cxl_add_rch_dport(struct cxl_port *port,
return dport;
}
-EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_add_rch_dport, CXL);
+EXPORT_SYMBOL_NS_GPL(__wrap_devm_cxl_add_rch_dport, "CXL");
resource_size_t __wrap_cxl_rcd_component_reg_phys(struct device *dev,
struct cxl_dport *dport)
@@ -283,7 +283,7 @@ resource_size_t __wrap_cxl_rcd_component_reg_phys(struct device *dev,
return component_reg_phys;
}
-EXPORT_SYMBOL_NS_GPL(__wrap_cxl_rcd_component_reg_phys, CXL);
+EXPORT_SYMBOL_NS_GPL(__wrap_cxl_rcd_component_reg_phys, "CXL");
void __wrap_cxl_endpoint_parse_cdat(struct cxl_port *port)
{
@@ -297,7 +297,7 @@ void __wrap_cxl_endpoint_parse_cdat(struct cxl_port *port)
cxl_endpoint_parse_cdat(port);
put_cxl_mock_ops(index);
}
-EXPORT_SYMBOL_NS_GPL(__wrap_cxl_endpoint_parse_cdat, CXL);
+EXPORT_SYMBOL_NS_GPL(__wrap_cxl_endpoint_parse_cdat, "CXL");
void __wrap_cxl_dport_init_ras_reporting(struct cxl_dport *dport, struct device *host)
{
@@ -309,8 +309,8 @@ void __wrap_cxl_dport_init_ras_reporting(struct cxl_dport *dport, struct device
put_cxl_mock_ops(index);
}
-EXPORT_SYMBOL_NS_GPL(__wrap_cxl_dport_init_ras_reporting, CXL);
+EXPORT_SYMBOL_NS_GPL(__wrap_cxl_dport_init_ras_reporting, "CXL");
MODULE_LICENSE("GPL v2");
-MODULE_IMPORT_NS(ACPI);
-MODULE_IMPORT_NS(CXL);
+MODULE_IMPORT_NS("ACPI");
+MODULE_IMPORT_NS("CXL");
diff --git a/tools/testing/nvdimm/test/ndtest.c b/tools/testing/nvdimm/test/ndtest.c
index 892e990c034a..68a064ce598c 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -883,7 +883,7 @@ static const struct platform_device_id ndtest_id[] = {
static struct platform_driver ndtest_driver = {
.probe = ndtest_probe,
- .remove_new = ndtest_remove,
+ .remove = ndtest_remove,
.driver = {
.name = KBUILD_MODNAME,
},
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 3f06b6233ae4..2401e973c359 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -72,6 +72,7 @@ TARGETS += net/packetdrill
TARGETS += net/rds
TARGETS += net/tcp_ao
TARGETS += nsfs
+TARGETS += pcie_bwctrl
TARGETS += perf_events
TARGETS += pidfd
TARGETS += pid_namespace
diff --git a/tools/testing/selftests/alsa/.gitignore b/tools/testing/selftests/alsa/.gitignore
index 12dc3fcd3456..3dd8e1176b89 100644
--- a/tools/testing/selftests/alsa/.gitignore
+++ b/tools/testing/selftests/alsa/.gitignore
@@ -1,3 +1,5 @@
+global-timer
mixer-test
pcm-test
test-pcmtest-driver
+utimer-test
diff --git a/tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py b/tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py
index db84000fc75b..79fde603cbbc 100644
--- a/tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py
+++ b/tools/testing/selftests/drivers/net/hw/lib/py/linkconfig.py
@@ -218,5 +218,5 @@ class LinkConfig:
json_data = process[0]
"""Check if the field exist in the json data"""
if field not in json_data:
- raise KsftSkipEx(f"Field {field} does not exist in the output of interface {json_data["ifname"]}")
+ raise KsftSkipEx(f'Field {field} does not exist in the output of interface {json_data["ifname"]}')
return json_data[field]
diff --git a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
index 319567f0fae1..81db85a5cc16 100644
--- a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
+++ b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
@@ -57,7 +57,6 @@ static int __do_binderfs_test(struct __test_metadata *_metadata)
{
int fd, ret, saved_errno, result = 1;
size_t len;
- ssize_t wret;
struct binderfs_device device = { 0 };
struct binder_version version = { 0 };
char binderfs_mntpt[] = P_tmpdir "/binderfs_XXXXXX",
diff --git a/tools/testing/selftests/kvm/riscv/get-reg-list.c b/tools/testing/selftests/kvm/riscv/get-reg-list.c
index 8e34f7fa44e9..4bc1051848e5 100644
--- a/tools/testing/selftests/kvm/riscv/get-reg-list.c
+++ b/tools/testing/selftests/kvm/riscv/get-reg-list.c
@@ -41,10 +41,14 @@ bool filter_reg(__u64 reg)
case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_I:
case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_M:
case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_V:
+ case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_SMNPM:
case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_SMSTATEEN:
case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_SSAIA:
case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_SSCOFPMF:
+ case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_SSNPM:
case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_SSTC:
+ case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_SVADE:
+ case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_SVADU:
case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_SVINVAL:
case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_SVNAPOT:
case KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | KVM_RISCV_ISA_EXT_SVPBMT:
@@ -414,10 +418,14 @@ static const char *isa_ext_single_id_to_str(__u64 reg_off)
KVM_ISA_EXT_ARR(I),
KVM_ISA_EXT_ARR(M),
KVM_ISA_EXT_ARR(V),
+ KVM_ISA_EXT_ARR(SMNPM),
KVM_ISA_EXT_ARR(SMSTATEEN),
KVM_ISA_EXT_ARR(SSAIA),
KVM_ISA_EXT_ARR(SSCOFPMF),
+ KVM_ISA_EXT_ARR(SSNPM),
KVM_ISA_EXT_ARR(SSTC),
+ KVM_ISA_EXT_ARR(SVADE),
+ KVM_ISA_EXT_ARR(SVADU),
KVM_ISA_EXT_ARR(SVINVAL),
KVM_ISA_EXT_ARR(SVNAPOT),
KVM_ISA_EXT_ARR(SVPBMT),
@@ -946,9 +954,13 @@ KVM_ISA_EXT_SUBLIST_CONFIG(aia, AIA);
KVM_ISA_EXT_SUBLIST_CONFIG(fp_f, FP_F);
KVM_ISA_EXT_SUBLIST_CONFIG(fp_d, FP_D);
KVM_ISA_EXT_SIMPLE_CONFIG(h, H);
+KVM_ISA_EXT_SIMPLE_CONFIG(smnpm, SMNPM);
KVM_ISA_EXT_SUBLIST_CONFIG(smstateen, SMSTATEEN);
KVM_ISA_EXT_SIMPLE_CONFIG(sscofpmf, SSCOFPMF);
+KVM_ISA_EXT_SIMPLE_CONFIG(ssnpm, SSNPM);
KVM_ISA_EXT_SIMPLE_CONFIG(sstc, SSTC);
+KVM_ISA_EXT_SIMPLE_CONFIG(svade, SVADE);
+KVM_ISA_EXT_SIMPLE_CONFIG(svadu, SVADU);
KVM_ISA_EXT_SIMPLE_CONFIG(svinval, SVINVAL);
KVM_ISA_EXT_SIMPLE_CONFIG(svnapot, SVNAPOT);
KVM_ISA_EXT_SIMPLE_CONFIG(svpbmt, SVPBMT);
@@ -1009,9 +1021,13 @@ struct vcpu_reg_list *vcpu_configs[] = {
&config_fp_f,
&config_fp_d,
&config_h,
+ &config_smnpm,
&config_smstateen,
&config_sscofpmf,
+ &config_ssnpm,
&config_sstc,
+ &config_svade,
+ &config_svadu,
&config_svinval,
&config_svnapot,
&config_svpbmt,
diff --git a/tools/testing/selftests/module/Makefile b/tools/testing/selftests/module/Makefile
new file mode 100644
index 000000000000..6132d7ddb08b
--- /dev/null
+++ b/tools/testing/selftests/module/Makefile
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# Makefile for module loading selftests
+
+# No binaries, but make sure arg-less "make" doesn't trigger "run_tests"
+all:
+
+TEST_PROGS := find_symbol.sh
+
+include ../lib.mk
+
+# Nothing to clean up.
+clean:
diff --git a/tools/testing/selftests/module/config b/tools/testing/selftests/module/config
new file mode 100644
index 000000000000..b0c206b1ad47
--- /dev/null
+++ b/tools/testing/selftests/module/config
@@ -0,0 +1,3 @@
+CONFIG_TEST_RUNTIME=y
+CONFIG_TEST_RUNTIME_MODULE=y
+CONFIG_TEST_KALLSYMS=m
diff --git a/tools/testing/selftests/module/find_symbol.sh b/tools/testing/selftests/module/find_symbol.sh
new file mode 100755
index 000000000000..2c56805c9b6e
--- /dev/null
+++ b/tools/testing/selftests/module/find_symbol.sh
@@ -0,0 +1,81 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later OR copyleft-next-0.3.1
+# Copyright (C) 2023 Luis Chamberlain <mcgrof@kernel.org>
+#
+# This is a stress test script for kallsyms through find_symbol()
+
+set -e
+
+# Kselftest framework requirement - SKIP code is 4.
+ksft_skip=4
+
+test_reqs()
+{
+ if ! which modprobe 2> /dev/null > /dev/null; then
+ echo "$0: You need modprobe installed" >&2
+ exit $ksft_skip
+ fi
+
+ if ! which kmod 2> /dev/null > /dev/null; then
+ echo "$0: You need kmod installed" >&2
+ exit $ksft_skip
+ fi
+
+ if ! which perf 2> /dev/null > /dev/null; then
+ echo "$0: You need perf installed" >&2
+ exit $ksft_skip
+ fi
+
+ uid=$(id -u)
+ if [ $uid -ne 0 ]; then
+ echo $msg must be run as root >&2
+ exit $ksft_skip
+ fi
+}
+
+load_mod()
+{
+ local STATS="-e duration_time"
+ STATS="$STATS -e user_time"
+ STATS="$STATS -e system_time"
+ STATS="$STATS -e page-faults"
+ local MOD=$1
+
+ local ARCH="$(uname -m)"
+ case "${ARCH}" in
+ x86_64)
+ perf stat $STATS $MODPROBE $MOD
+ ;;
+ *)
+ time $MODPROBE $MOD
+ exit 1
+ ;;
+ esac
+}
+
+remove_all()
+{
+ $MODPROBE -r test_kallsyms_b
+ for i in a b c d; do
+ $MODPROBE -r test_kallsyms_$i
+ done
+}
+test_reqs
+
+MODPROBE=$(</proc/sys/kernel/modprobe)
+
+remove_all
+load_mod test_kallsyms_b
+remove_all
+
+# Now pollute the namespace
+$MODPROBE test_kallsyms_c
+load_mod test_kallsyms_b
+
+# Now pollute the namespace with twice the number of symbols than the last time
+remove_all
+$MODPROBE test_kallsyms_c
+$MODPROBE test_kallsyms_d
+load_mod test_kallsyms_b
+
+exit 0
diff --git a/tools/testing/selftests/mount_setattr/mount_setattr_test.c b/tools/testing/selftests/mount_setattr/mount_setattr_test.c
index 68801e1a9ec2..70f65eb320a7 100644
--- a/tools/testing/selftests/mount_setattr/mount_setattr_test.c
+++ b/tools/testing/selftests/mount_setattr/mount_setattr_test.c
@@ -1026,7 +1026,7 @@ FIXTURE_SETUP(mount_setattr_idmapped)
"size=100000,mode=700"), 0);
ASSERT_EQ(mount("testing", "/mnt", "tmpfs", MS_NOATIME | MS_NODEV,
- "size=100000,mode=700"), 0);
+ "size=2m,mode=700"), 0);
ASSERT_EQ(mkdir("/mnt/A", 0777), 0);
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 3d487b03c4a0..cb2fc601de66 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -78,7 +78,6 @@ TEST_PROGS += test_vxlan_vnifiltering.sh
TEST_GEN_FILES += io_uring_zerocopy_tx
TEST_PROGS += io_uring_zerocopy_tx.sh
TEST_GEN_FILES += bind_bhash
-TEST_GEN_PROGS += netlink-dumps
TEST_GEN_PROGS += sk_bind_sendto_listen
TEST_GEN_PROGS += sk_connect_zero_addr
TEST_GEN_PROGS += sk_so_peek_off
@@ -101,7 +100,7 @@ TEST_PROGS += ipv6_route_update_soft_lockup.sh
TEST_PROGS += busy_poll_test.sh
# YNL files, must be before "include ..lib.mk"
-YNL_GEN_FILES := busy_poller
+YNL_GEN_FILES := busy_poller netlink-dumps
TEST_GEN_FILES += $(YNL_GEN_FILES)
TEST_FILES := settings
diff --git a/tools/testing/selftests/net/netlink-dumps.c b/tools/testing/selftests/net/netlink-dumps.c
index 84e29b7dffb6..07423f256f96 100644
--- a/tools/testing/selftests/net/netlink-dumps.c
+++ b/tools/testing/selftests/net/netlink-dumps.c
@@ -12,11 +12,140 @@
#include <unistd.h>
#include <linux/genetlink.h>
+#include <linux/neighbour.h>
+#include <linux/netdevice.h>
#include <linux/netlink.h>
#include <linux/mqueue.h>
+#include <linux/rtnetlink.h>
#include "../kselftest_harness.h"
+#include <ynl.h>
+
+struct ext_ack {
+ int err;
+
+ __u32 attr_offs;
+ __u32 miss_type;
+ __u32 miss_nest;
+ const char *str;
+};
+
+/* 0: no done, 1: done found, 2: extack found, -1: error */
+static int nl_get_extack(char *buf, size_t n, struct ext_ack *ea)
+{
+ const struct nlmsghdr *nlh;
+ const struct nlattr *attr;
+ ssize_t rem;
+
+ for (rem = n; rem > 0; NLMSG_NEXT(nlh, rem)) {
+ nlh = (struct nlmsghdr *)&buf[n - rem];
+ if (!NLMSG_OK(nlh, rem))
+ return -1;
+
+ if (nlh->nlmsg_type != NLMSG_DONE)
+ continue;
+
+ ea->err = -*(int *)NLMSG_DATA(nlh);
+
+ if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS))
+ return 1;
+
+ ynl_attr_for_each(attr, nlh, sizeof(int)) {
+ switch (ynl_attr_type(attr)) {
+ case NLMSGERR_ATTR_OFFS:
+ ea->attr_offs = ynl_attr_get_u32(attr);
+ break;
+ case NLMSGERR_ATTR_MISS_TYPE:
+ ea->miss_type = ynl_attr_get_u32(attr);
+ break;
+ case NLMSGERR_ATTR_MISS_NEST:
+ ea->miss_nest = ynl_attr_get_u32(attr);
+ break;
+ case NLMSGERR_ATTR_MSG:
+ ea->str = ynl_attr_get_str(attr);
+ break;
+ }
+ }
+
+ return 2;
+ }
+
+ return 0;
+}
+
+static const struct {
+ struct nlmsghdr nlhdr;
+ struct ndmsg ndm;
+ struct nlattr ahdr;
+ __u32 val;
+} dump_neigh_bad = {
+ .nlhdr = {
+ .nlmsg_len = sizeof(dump_neigh_bad),
+ .nlmsg_type = RTM_GETNEIGH,
+ .nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP,
+ .nlmsg_seq = 1,
+ },
+ .ndm = {
+ .ndm_family = 123,
+ },
+ .ahdr = {
+ .nla_len = 4 + 4,
+ .nla_type = NDA_FLAGS_EXT,
+ },
+ .val = -1, // should fail MASK validation
+};
+
+TEST(dump_extack)
+{
+ int netlink_sock;
+ char buf[8192];
+ int one = 1;
+ int i, cnt;
+ ssize_t n;
+
+ netlink_sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+ ASSERT_GE(netlink_sock, 0);
+
+ n = setsockopt(netlink_sock, SOL_NETLINK, NETLINK_CAP_ACK,
+ &one, sizeof(one));
+ ASSERT_EQ(n, 0);
+ n = setsockopt(netlink_sock, SOL_NETLINK, NETLINK_EXT_ACK,
+ &one, sizeof(one));
+ ASSERT_EQ(n, 0);
+ n = setsockopt(netlink_sock, SOL_NETLINK, NETLINK_GET_STRICT_CHK,
+ &one, sizeof(one));
+ ASSERT_EQ(n, 0);
+
+ /* Dump so many times we fill up the buffer */
+ cnt = 64;
+ for (i = 0; i < cnt; i++) {
+ n = send(netlink_sock, &dump_neigh_bad,
+ sizeof(dump_neigh_bad), 0);
+ ASSERT_EQ(n, sizeof(dump_neigh_bad));
+ }
+
+ /* Read out the ENOBUFS */
+ n = recv(netlink_sock, buf, sizeof(buf), MSG_DONTWAIT);
+ EXPECT_EQ(n, -1);
+ EXPECT_EQ(errno, ENOBUFS);
+
+ for (i = 0; i < cnt; i++) {
+ struct ext_ack ea = {};
+
+ n = recv(netlink_sock, buf, sizeof(buf), MSG_DONTWAIT);
+ if (n < 0) {
+ ASSERT_GE(i, 10);
+ break;
+ }
+ ASSERT_GE(n, (ssize_t)sizeof(struct nlmsghdr));
+
+ EXPECT_EQ(nl_get_extack(buf, n, &ea), 2);
+ EXPECT_EQ(ea.attr_offs,
+ sizeof(struct nlmsghdr) + sizeof(struct ndmsg));
+ }
+}
+
static const struct {
struct nlmsghdr nlhdr;
struct genlmsghdr genlhdr;
diff --git a/tools/testing/selftests/net/rds/Makefile b/tools/testing/selftests/net/rds/Makefile
index 1803c39dbacb..612a7219990e 100644
--- a/tools/testing/selftests/net/rds/Makefile
+++ b/tools/testing/selftests/net/rds/Makefile
@@ -3,10 +3,9 @@
all:
@echo mk_build_dir="$(shell pwd)" > include.sh
-TEST_PROGS := run.sh \
- test.py
+TEST_PROGS := run.sh
-TEST_FILES := include.sh
+TEST_FILES := include.sh test.py
EXTRA_CLEAN := /tmp/rds_logs include.sh
diff --git a/tools/testing/selftests/net/rtnetlink.sh b/tools/testing/selftests/net/rtnetlink.sh
index 7f05b5f9b76f..2e8243a65b50 100755
--- a/tools/testing/selftests/net/rtnetlink.sh
+++ b/tools/testing/selftests/net/rtnetlink.sh
@@ -29,6 +29,7 @@ ALL_TESTS="
kci_test_bridge_parent_id
kci_test_address_proto
kci_test_enslave_bonding
+ kci_test_mngtmpaddr
"
devdummy="test-dummy0"
@@ -44,6 +45,7 @@ check_err()
if [ $ret -eq 0 ]; then
ret=$1
fi
+ [ -n "$2" ] && echo "$2"
}
# same but inverted -- used when command must fail for test to pass
@@ -1239,6 +1241,99 @@ kci_test_enslave_bonding()
ip netns del "$testns"
}
+# Called to validate the addresses on $IFNAME:
+#
+# 1. Every `temporary` address must have a matching `mngtmpaddr`
+# 2. Every `mngtmpaddr` address must have some un`deprecated` `temporary`
+#
+# If the mngtmpaddr or tempaddr checking failed, return 0 and stop slowwait
+validate_mngtmpaddr()
+{
+ local dev=$1
+ local prefix=""
+ local addr_list=$(ip -j -n $testns addr show dev ${dev})
+ local temp_addrs=$(echo ${addr_list} | \
+ jq -r '.[].addr_info[] | select(.temporary == true) | .local')
+ local mng_prefixes=$(echo ${addr_list} | \
+ jq -r '.[].addr_info[] | select(.mngtmpaddr == true) | .local' | \
+ cut -d: -f1-4 | tr '\n' ' ')
+ local undep_prefixes=$(echo ${addr_list} | \
+ jq -r '.[].addr_info[] | select(.temporary == true and .deprecated != true) | .local' | \
+ cut -d: -f1-4 | tr '\n' ' ')
+
+ # 1. All temporary addresses (temp and dep) must have a matching mngtmpaddr
+ for address in ${temp_addrs}; do
+ prefix=$(echo ${address} | cut -d: -f1-4)
+ if [[ ! " ${mng_prefixes} " =~ " $prefix " ]]; then
+ check_err 1 "FAIL: Temporary $address with no matching mngtmpaddr!";
+ return 0
+ fi
+ done
+
+ # 2. All mngtmpaddr addresses must have a temporary address (not dep)
+ for prefix in ${mng_prefixes}; do
+ if [[ ! " ${undep_prefixes} " =~ " $prefix " ]]; then
+ check_err 1 "FAIL: No undeprecated temporary in $prefix!";
+ return 0
+ fi
+ done
+
+ return 1
+}
+
+kci_test_mngtmpaddr()
+{
+ local ret=0
+
+ setup_ns testns
+ if [ $? -ne 0 ]; then
+ end_test "SKIP mngtmpaddr tests: cannot add net namespace $testns"
+ return $ksft_skip
+ fi
+
+ # 1. Create a dummy Ethernet interface
+ run_cmd ip -n $testns link add ${devdummy} type dummy
+ run_cmd ip -n $testns link set ${devdummy} up
+ run_cmd ip netns exec $testns sysctl -w net.ipv6.conf.${devdummy}.use_tempaddr=1
+ run_cmd ip netns exec $testns sysctl -w net.ipv6.conf.${devdummy}.temp_prefered_lft=10
+ run_cmd ip netns exec $testns sysctl -w net.ipv6.conf.${devdummy}.temp_valid_lft=25
+ run_cmd ip netns exec $testns sysctl -w net.ipv6.conf.${devdummy}.max_desync_factor=1
+
+ # 2. Create several mngtmpaddr addresses on that interface.
+ # with temp_*_lft configured to be pretty short (10 and 35 seconds
+ # for prefer/valid respectively)
+ for i in $(seq 1 9); do
+ run_cmd ip -n $testns addr add 2001:db8:7e57:${i}::1/64 mngtmpaddr dev ${devdummy}
+ done
+
+ # 3. Confirm that a preferred temporary address exists for each mngtmpaddr
+ # address at all times, polling once per second for 30 seconds.
+ slowwait 30 validate_mngtmpaddr ${devdummy}
+
+ # 4. Delete each mngtmpaddr address, one at a time (alternating between
+ # deleting and merely un-mngtmpaddr-ing), and confirm that the other
+ # mngtmpaddr addresses still have preferred temporaries.
+ for i in $(seq 1 9); do
+ (( $i % 4 == 0 )) && mng_flag="mngtmpaddr" || mng_flag=""
+ if (( $i % 2 == 0 )); then
+ run_cmd ip -n $testns addr del 2001:db8:7e57:${i}::1/64 $mng_flag dev ${devdummy}
+ else
+ run_cmd ip -n $testns addr change 2001:db8:7e57:${i}::1/64 dev ${devdummy}
+ fi
+ # the temp addr should be deleted
+ validate_mngtmpaddr ${devdummy}
+ done
+
+ if [ $ret -ne 0 ]; then
+ end_test "FAIL: mngtmpaddr add/remove incorrect"
+ else
+ end_test "PASS: mngtmpaddr add/remove correctly"
+ fi
+
+ ip netns del "$testns"
+ return $ret
+}
+
kci_test_rtnl()
{
local current_test
diff --git a/tools/testing/selftests/pcie_bwctrl/Makefile b/tools/testing/selftests/pcie_bwctrl/Makefile
new file mode 100644
index 000000000000..3e84e26341d1
--- /dev/null
+++ b/tools/testing/selftests/pcie_bwctrl/Makefile
@@ -0,0 +1,2 @@
+TEST_PROGS = set_pcie_cooling_state.sh
+include ../lib.mk
diff --git a/tools/testing/selftests/pcie_bwctrl/set_pcie_cooling_state.sh b/tools/testing/selftests/pcie_bwctrl/set_pcie_cooling_state.sh
new file mode 100755
index 000000000000..9df606552af3
--- /dev/null
+++ b/tools/testing/selftests/pcie_bwctrl/set_pcie_cooling_state.sh
@@ -0,0 +1,122 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+SYSFS=
+# Kselftest framework requirement - SKIP code is 4.
+ksft_skip=4
+retval=0
+skipmsg="skip all tests:"
+
+PCIEPORTTYPE="PCIe_Port_Link_Speed"
+
+prerequisite()
+{
+ local ports
+
+ if [ $UID != 0 ]; then
+ echo $skipmsg must be run as root >&2
+ exit $ksft_skip
+ fi
+
+ SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
+
+ if [ ! -d "$SYSFS" ]; then
+ echo $skipmsg sysfs is not mounted >&2
+ exit $ksft_skip
+ fi
+
+ if ! ls $SYSFS/class/thermal/cooling_device* > /dev/null 2>&1; then
+ echo $skipmsg thermal cooling devices missing >&2
+ exit $ksft_skip
+ fi
+
+ ports=`grep -e "^$PCIEPORTTYPE" $SYSFS/class/thermal/cooling_device*/type | wc -l`
+ if [ $ports -eq 0 ]; then
+ echo $skipmsg pcie cooling devices missing >&2
+ exit $ksft_skip
+ fi
+}
+
+testport=
+find_pcie_port()
+{
+ local patt="$1"
+ local pcieports
+ local max
+ local cur
+ local delta
+ local bestdelta=-1
+
+ pcieports=`grep -l -F -e "$patt" /sys/class/thermal/cooling_device*/type`
+ if [ -z "$pcieports" ]; then
+ return
+ fi
+ pcieports=${pcieports//\/type/}
+ # Find the port with the highest PCIe Link Speed
+ for port in $pcieports; do
+ max=`cat $port/max_state`
+ cur=`cat $port/cur_state`
+ delta=$((max-cur))
+ if [ $delta -gt $bestdelta ]; then
+ testport="$port"
+ bestdelta=$delta
+ fi
+ done
+}
+
+sysfspcidev=
+find_sysfs_pci_dev()
+{
+ local typefile="$1/type"
+ local pcidir
+
+ pcidir="$SYSFS/bus/pci/devices/`sed -e "s|^${PCIEPORTTYPE}_||g" $typefile`"
+
+ if [ -r "$pcidir/current_link_speed" ]; then
+ sysfspcidev="$pcidir/current_link_speed"
+ fi
+}
+
+usage()
+{
+ echo "Usage $0 [ -d dev ]"
+ echo -e "\t-d: PCIe port BDF string (e.g., 0000:00:04.0)"
+}
+
+pattern="$PCIEPORTTYPE"
+parse_arguments()
+{
+ while getopts d:h opt; do
+ case $opt in
+ h)
+ usage "$0"
+ exit 0
+ ;;
+ d)
+ pattern="$PCIEPORTTYPE_$OPTARG"
+ ;;
+ *)
+ usage "$0"
+ exit 0
+ ;;
+ esac
+ done
+}
+
+parse_arguments "$@"
+prerequisite
+find_pcie_port "$pattern"
+if [ -z "$testport" ]; then
+ echo $skipmsg "pcie cooling device not found from sysfs" >&2
+ exit $ksft_skip
+fi
+find_sysfs_pci_dev "$testport"
+if [ -z "$sysfspcidev" ]; then
+ echo $skipmsg "PCIe port device not found from sysfs" >&2
+ exit $ksft_skip
+fi
+
+./set_pcie_speed.sh "$testport" "$sysfspcidev"
+retval=$?
+
+exit $retval
diff --git a/tools/testing/selftests/pcie_bwctrl/set_pcie_speed.sh b/tools/testing/selftests/pcie_bwctrl/set_pcie_speed.sh
new file mode 100755
index 000000000000..584596949312
--- /dev/null
+++ b/tools/testing/selftests/pcie_bwctrl/set_pcie_speed.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+set -e
+
+TESTNAME=set_pcie_speed
+
+declare -a PCIELINKSPEED=(
+ "2.5 GT/s PCIe"
+ "5.0 GT/s PCIe"
+ "8.0 GT/s PCIe"
+ "16.0 GT/s PCIe"
+ "32.0 GT/s PCIe"
+ "64.0 GT/s PCIe"
+)
+
+# Kselftest framework requirement - SKIP code is 4.
+ksft_skip=4
+retval=0
+
+coolingdev="$1"
+statefile="$coolingdev/cur_state"
+maxfile="$coolingdev/max_state"
+linkspeedfile="$2"
+
+oldstate=`cat $statefile`
+maxstate=`cat $maxfile`
+
+set_state()
+{
+ local state=$1
+ local linkspeed
+ local expected_linkspeed
+
+ echo $state > $statefile
+
+ sleep 1
+
+ linkspeed="`cat $linkspeedfile`"
+ expected_linkspeed=$((maxstate-state))
+ expected_str="${PCIELINKSPEED[$expected_linkspeed]}"
+ if [ ! "${expected_str}" = "${linkspeed}" ]; then
+ echo "$TESTNAME failed: expected: ${expected_str}; got ${linkspeed}"
+ retval=1
+ fi
+}
+
+cleanup_skip ()
+{
+ set_state $oldstate
+ exit $ksft_skip
+}
+
+trap cleanup_skip EXIT
+
+echo "$TESTNAME: testing states $maxstate .. $oldstate with $coolingdev"
+for i in $(seq $maxstate -1 $oldstate); do
+ set_state "$i"
+done
+
+trap EXIT
+if [ $retval -eq 0 ]; then
+ echo "$TESTNAME [PASS]"
+else
+ echo "$TESTNAME [FAIL]"
+fi
+exit $retval
diff --git a/tools/testing/selftests/riscv/Makefile b/tools/testing/selftests/riscv/Makefile
index 7ce03d832b64..099b8c1f46f8 100644
--- a/tools/testing/selftests/riscv/Makefile
+++ b/tools/testing/selftests/riscv/Makefile
@@ -5,7 +5,7 @@
ARCH ?= $(shell uname -m 2>/dev/null || echo not)
ifneq (,$(filter $(ARCH),riscv))
-RISCV_SUBTARGETS ?= hwprobe vector mm sigreturn
+RISCV_SUBTARGETS ?= abi hwprobe mm sigreturn vector
else
RISCV_SUBTARGETS :=
endif
diff --git a/tools/testing/selftests/riscv/abi/.gitignore b/tools/testing/selftests/riscv/abi/.gitignore
new file mode 100644
index 000000000000..b38358f91c4d
--- /dev/null
+++ b/tools/testing/selftests/riscv/abi/.gitignore
@@ -0,0 +1 @@
+pointer_masking
diff --git a/tools/testing/selftests/riscv/abi/Makefile b/tools/testing/selftests/riscv/abi/Makefile
new file mode 100644
index 000000000000..ed82ff9c664e
--- /dev/null
+++ b/tools/testing/selftests/riscv/abi/Makefile
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0
+
+CFLAGS += -I$(top_srcdir)/tools/include
+
+TEST_GEN_PROGS := pointer_masking
+
+include ../../lib.mk
+
+$(OUTPUT)/pointer_masking: pointer_masking.c
+ $(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^
diff --git a/tools/testing/selftests/riscv/abi/pointer_masking.c b/tools/testing/selftests/riscv/abi/pointer_masking.c
new file mode 100644
index 000000000000..dee41b7ee3e3
--- /dev/null
+++ b/tools/testing/selftests/riscv/abi/pointer_masking.c
@@ -0,0 +1,332 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <errno.h>
+#include <fcntl.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <sys/prctl.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include "../../kselftest.h"
+
+#ifndef PR_PMLEN_SHIFT
+#define PR_PMLEN_SHIFT 24
+#endif
+#ifndef PR_PMLEN_MASK
+#define PR_PMLEN_MASK (0x7fUL << PR_PMLEN_SHIFT)
+#endif
+
+static int dev_zero;
+
+static int pipefd[2];
+
+static sigjmp_buf jmpbuf;
+
+static void sigsegv_handler(int sig)
+{
+ siglongjmp(jmpbuf, 1);
+}
+
+static int min_pmlen;
+static int max_pmlen;
+
+static inline bool valid_pmlen(int pmlen)
+{
+ return pmlen == 0 || pmlen == 7 || pmlen == 16;
+}
+
+static void test_pmlen(void)
+{
+ ksft_print_msg("Testing available PMLEN values\n");
+
+ for (int request = 0; request <= 16; request++) {
+ int pmlen, ret;
+
+ ret = prctl(PR_SET_TAGGED_ADDR_CTRL, request << PR_PMLEN_SHIFT, 0, 0, 0);
+ if (ret)
+ goto pr_set_error;
+
+ ret = prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0);
+ ksft_test_result(ret >= 0, "PMLEN=%d PR_GET_TAGGED_ADDR_CTRL\n", request);
+ if (ret < 0)
+ goto pr_get_error;
+
+ pmlen = (ret & PR_PMLEN_MASK) >> PR_PMLEN_SHIFT;
+ ksft_test_result(pmlen >= request, "PMLEN=%d constraint\n", request);
+ ksft_test_result(valid_pmlen(pmlen), "PMLEN=%d validity\n", request);
+
+ if (min_pmlen == 0)
+ min_pmlen = pmlen;
+ if (max_pmlen < pmlen)
+ max_pmlen = pmlen;
+
+ continue;
+
+pr_set_error:
+ ksft_test_result_skip("PMLEN=%d PR_GET_TAGGED_ADDR_CTRL\n", request);
+pr_get_error:
+ ksft_test_result_skip("PMLEN=%d constraint\n", request);
+ ksft_test_result_skip("PMLEN=%d validity\n", request);
+ }
+
+ if (max_pmlen == 0)
+ ksft_exit_fail_msg("Failed to enable pointer masking\n");
+}
+
+static int set_tagged_addr_ctrl(int pmlen, bool tagged_addr_abi)
+{
+ int arg, ret;
+
+ arg = pmlen << PR_PMLEN_SHIFT | tagged_addr_abi;
+ ret = prctl(PR_SET_TAGGED_ADDR_CTRL, arg, 0, 0, 0);
+ if (!ret) {
+ ret = prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0);
+ if (ret == arg)
+ return 0;
+ }
+
+ return ret < 0 ? -errno : -ENODATA;
+}
+
+static void test_dereference_pmlen(int pmlen)
+{
+ static volatile int i;
+ volatile int *p;
+ int ret;
+
+ ret = set_tagged_addr_ctrl(pmlen, false);
+ if (ret)
+ return ksft_test_result_error("PMLEN=%d setup (%d)\n", pmlen, ret);
+
+ i = pmlen;
+
+ if (pmlen) {
+ p = (volatile int *)((uintptr_t)&i | 1UL << (__riscv_xlen - pmlen));
+
+ /* These dereferences should succeed. */
+ if (sigsetjmp(jmpbuf, 1))
+ return ksft_test_result_fail("PMLEN=%d valid tag\n", pmlen);
+ if (*p != pmlen)
+ return ksft_test_result_fail("PMLEN=%d bad value\n", pmlen);
+ ++*p;
+ }
+
+ p = (volatile int *)((uintptr_t)&i | 1UL << (__riscv_xlen - pmlen - 1));
+
+ /* These dereferences should raise SIGSEGV. */
+ if (sigsetjmp(jmpbuf, 1))
+ return ksft_test_result_pass("PMLEN=%d dereference\n", pmlen);
+ ++*p;
+ ksft_test_result_fail("PMLEN=%d invalid tag\n", pmlen);
+}
+
+static void test_dereference(void)
+{
+ ksft_print_msg("Testing userspace pointer dereference\n");
+
+ signal(SIGSEGV, sigsegv_handler);
+
+ test_dereference_pmlen(0);
+ test_dereference_pmlen(min_pmlen);
+ test_dereference_pmlen(max_pmlen);
+
+ signal(SIGSEGV, SIG_DFL);
+}
+
+static void execve_child_sigsegv_handler(int sig)
+{
+ exit(42);
+}
+
+static int execve_child(void)
+{
+ static volatile int i;
+ volatile int *p = (volatile int *)((uintptr_t)&i | 1UL << (__riscv_xlen - 7));
+
+ signal(SIGSEGV, execve_child_sigsegv_handler);
+
+ /* This dereference should raise SIGSEGV. */
+ return *p;
+}
+
+static void test_fork_exec(void)
+{
+ int ret, status;
+
+ ksft_print_msg("Testing fork/exec behavior\n");
+
+ ret = set_tagged_addr_ctrl(min_pmlen, false);
+ if (ret)
+ return ksft_test_result_error("setup (%d)\n", ret);
+
+ if (fork()) {
+ wait(&status);
+ ksft_test_result(WIFEXITED(status) && WEXITSTATUS(status) == 42,
+ "dereference after fork\n");
+ } else {
+ static volatile int i = 42;
+ volatile int *p;
+
+ p = (volatile int *)((uintptr_t)&i | 1UL << (__riscv_xlen - min_pmlen));
+
+ /* This dereference should succeed. */
+ exit(*p);
+ }
+
+ if (fork()) {
+ wait(&status);
+ ksft_test_result(WIFEXITED(status) && WEXITSTATUS(status) == 42,
+ "dereference after fork+exec\n");
+ } else {
+ /* Will call execve_child(). */
+ execve("/proc/self/exe", (char *const []) { "", NULL }, NULL);
+ }
+}
+
+static void test_tagged_addr_abi_sysctl(void)
+{
+ char value;
+ int fd;
+
+ ksft_print_msg("Testing tagged address ABI sysctl\n");
+
+ fd = open("/proc/sys/abi/tagged_addr_disabled", O_WRONLY);
+ if (fd < 0) {
+ ksft_test_result_skip("failed to open sysctl file\n");
+ ksft_test_result_skip("failed to open sysctl file\n");
+ return;
+ }
+
+ value = '1';
+ pwrite(fd, &value, 1, 0);
+ ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == -EINVAL,
+ "sysctl disabled\n");
+
+ value = '0';
+ pwrite(fd, &value, 1, 0);
+ ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == 0,
+ "sysctl enabled\n");
+
+ set_tagged_addr_ctrl(0, false);
+
+ close(fd);
+}
+
+static void test_tagged_addr_abi_pmlen(int pmlen)
+{
+ int i, *p, ret;
+
+ i = ~pmlen;
+
+ if (pmlen) {
+ p = (int *)((uintptr_t)&i | 1UL << (__riscv_xlen - pmlen));
+
+ ret = set_tagged_addr_ctrl(pmlen, false);
+ if (ret)
+ return ksft_test_result_error("PMLEN=%d ABI disabled setup (%d)\n",
+ pmlen, ret);
+
+ ret = write(pipefd[1], p, sizeof(*p));
+ if (ret >= 0 || errno != EFAULT)
+ return ksft_test_result_fail("PMLEN=%d ABI disabled write\n", pmlen);
+
+ ret = read(dev_zero, p, sizeof(*p));
+ if (ret >= 0 || errno != EFAULT)
+ return ksft_test_result_fail("PMLEN=%d ABI disabled read\n", pmlen);
+
+ if (i != ~pmlen)
+ return ksft_test_result_fail("PMLEN=%d ABI disabled value\n", pmlen);
+
+ ret = set_tagged_addr_ctrl(pmlen, true);
+ if (ret)
+ return ksft_test_result_error("PMLEN=%d ABI enabled setup (%d)\n",
+ pmlen, ret);
+
+ ret = write(pipefd[1], p, sizeof(*p));
+ if (ret != sizeof(*p))
+ return ksft_test_result_fail("PMLEN=%d ABI enabled write\n", pmlen);
+
+ ret = read(dev_zero, p, sizeof(*p));
+ if (ret != sizeof(*p))
+ return ksft_test_result_fail("PMLEN=%d ABI enabled read\n", pmlen);
+
+ if (i)
+ return ksft_test_result_fail("PMLEN=%d ABI enabled value\n", pmlen);
+
+ i = ~pmlen;
+ } else {
+ /* The tagged address ABI cannot be enabled when PMLEN == 0. */
+ ret = set_tagged_addr_ctrl(pmlen, true);
+ if (ret != -EINVAL)
+ return ksft_test_result_error("PMLEN=%d ABI setup (%d)\n",
+ pmlen, ret);
+ }
+
+ p = (int *)((uintptr_t)&i | 1UL << (__riscv_xlen - pmlen - 1));
+
+ ret = write(pipefd[1], p, sizeof(*p));
+ if (ret >= 0 || errno != EFAULT)
+ return ksft_test_result_fail("PMLEN=%d invalid tag write (%d)\n", pmlen, errno);
+
+ ret = read(dev_zero, p, sizeof(*p));
+ if (ret >= 0 || errno != EFAULT)
+ return ksft_test_result_fail("PMLEN=%d invalid tag read\n", pmlen);
+
+ if (i != ~pmlen)
+ return ksft_test_result_fail("PMLEN=%d invalid tag value\n", pmlen);
+
+ ksft_test_result_pass("PMLEN=%d tagged address ABI\n", pmlen);
+}
+
+static void test_tagged_addr_abi(void)
+{
+ ksft_print_msg("Testing tagged address ABI\n");
+
+ test_tagged_addr_abi_pmlen(0);
+ test_tagged_addr_abi_pmlen(min_pmlen);
+ test_tagged_addr_abi_pmlen(max_pmlen);
+}
+
+static struct test_info {
+ unsigned int nr_tests;
+ void (*test_fn)(void);
+} tests[] = {
+ { .nr_tests = 17 * 3, test_pmlen },
+ { .nr_tests = 3, test_dereference },
+ { .nr_tests = 2, test_fork_exec },
+ { .nr_tests = 2, test_tagged_addr_abi_sysctl },
+ { .nr_tests = 3, test_tagged_addr_abi },
+};
+
+int main(int argc, char **argv)
+{
+ unsigned int plan = 0;
+ int ret;
+
+ /* Check if this is the child process after execve(). */
+ if (!argv[0][0])
+ return execve_child();
+
+ dev_zero = open("/dev/zero", O_RDWR);
+ if (dev_zero < 0)
+ return 1;
+
+ /* Write to a pipe so the kernel must dereference the buffer pointer. */
+ ret = pipe(pipefd);
+ if (ret)
+ return 1;
+
+ ksft_print_header();
+
+ for (int i = 0; i < ARRAY_SIZE(tests); i++)
+ plan += tests[i].nr_tests;
+
+ ksft_set_plan(plan);
+
+ for (int i = 0; i < ARRAY_SIZE(tests); i++)
+ tests[i].test_fn();
+
+ ksft_finished();
+}
diff --git a/tools/testing/shared/linux.c b/tools/testing/shared/linux.c
index 17263696b5d8..66dbb362385f 100644
--- a/tools/testing/shared/linux.c
+++ b/tools/testing/shared/linux.c
@@ -96,10 +96,13 @@ void *kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru,
p = node;
} else {
pthread_mutex_unlock(&cachep->lock);
- if (cachep->align)
- posix_memalign(&p, cachep->align, cachep->size);
- else
+ if (cachep->align) {
+ if (posix_memalign(&p, cachep->align, cachep->size) < 0)
+ return NULL;
+ } else {
p = malloc(cachep->size);
+ }
+
if (cachep->ctor)
cachep->ctor(p);
else if (gfp & __GFP_ZERO)
@@ -195,8 +198,9 @@ int kmem_cache_alloc_bulk(struct kmem_cache *cachep, gfp_t gfp, size_t size,
}
if (cachep->align) {
- posix_memalign(&p[i], cachep->align,
- cachep->size);
+ if (posix_memalign(&p[i], cachep->align,
+ cachep->size) < 0)
+ break;
} else {
p[i] = malloc(cachep->size);
if (!p[i])