This patchset contains everything needed to integrate KASAN and KUnit.
KUnit will be able to:
(1) Fail tests when an unexpected KASAN error occurs
(2) Pass tests when an expected KASAN error occurs
Convert KASAN tests to KUnit with the exception of copy_user_test
because KUnit is unable to test those.
Add documentation on how to run the KASAN tests with KUnit and what to
expect when running these tests.
Depends on "[PATCH v3 kunit-next 0/2] kunit: extend kunit resources
API" patchset [1]
Changes from v5:
- Split out the panic_on_warn changes to a separate patch.
- Fix documentation to fewer to the new Kconfig names.
- Fix some changes which were in the wrong patch.
- Rebase on top of kselftest/kunit (currently identical to 5.7-rc1)
Changes from v4:
- KASAN no longer will panic on errors if both panic_on_warn and
kasan_multishot are enabled.
- As a result, the KASAN tests will no-longer disable panic_on_warn.
- This also means panic_on_warn no-longer needs to be exported.
- The use of temporary "kasan_data" variables has been cleaned up
somewhat.
- A potential refcount/resource leak should multiple KASAN errors
appear during an assertion was fixed.
- Some wording changes to the KASAN test Kconfig entries.
Changes from v3:
- KUNIT_SET_KASAN_DATA and KUNIT_DO_EXPECT_KASAN_FAIL have been
combined and included in KUNIT_DO_EXPECT_KASAN_FAIL() instead.
- Reordered logic in kasan_update_kunit_status() in report.c to be
easier to read.
- Added comment to not use the name "kasan_data" for any kunit tests
outside of KUNIT_EXPECT_KASAN_FAIL().
Changes since v2:
- Due to Alan's changes in [1], KUnit can be built as a module.
- The name of the tests that could not be run with KUnit has been
changed to be more generic: test_kasan_module.
- Documentation on how to run the new KASAN tests and what to expect
when running them has been added.
- Some variables and functions are now static.
- Now save/restore panic_on_warn in a similar way to kasan_multi_shot
and renamed the init/exit functions to be more generic to accommodate.
- Due to [2] in kasan_strings, kasan_memchr, and
kasan_memcmp will fail if CONFIG_AMD_MEM_ENCRYPT is enabled so return
early and print message explaining this circumstance.
- Changed preprocessor checks to C checks where applicable.
Changes since v1:
- Make use of Alan Maguire's suggestion to use his patch that allows
static resources for integration instead of adding a new attribute to
the kunit struct
- All KUNIT_EXPECT_KASAN_FAIL statements are local to each test
- The definition of KUNIT_EXPECT_KASAN_FAIL is local to the
test_kasan.c file since it seems this is the only place this will
be used.
- Integration relies on KUnit being builtin
- copy_user_test has been separated into its own file since KUnit
is unable to test these. This can be run as a module just as before,
using CONFIG_TEST_KASAN_USER
- The addition to the current task has been separated into its own
patch as this is a significant enough change to be on its own.
[1] https://lore.kernel.org/linux-kselftest/1585313122-26441-1-git-send-email-a…
[2] https://bugzilla.kernel.org/show_bug.cgi?id=206337
David Gow (1):
mm: kasan: Do not panic if both panic_on_warn and kasan_multishot set
Patricia Alfonso (4):
Add KUnit Struct to Current Task
KUnit: KASAN Integration
KASAN: Port KASAN Tests to KUnit
KASAN: Testing Documentation
Documentation/dev-tools/kasan.rst | 70 +++
include/kunit/test.h | 5 +
include/linux/kasan.h | 6 +
include/linux/sched.h | 4 +
lib/Kconfig.kasan | 18 +-
lib/Makefile | 3 +-
lib/kunit/test.c | 13 +-
lib/test_kasan.c | 682 +++++++++++++-----------------
lib/test_kasan_module.c | 76 ++++
mm/kasan/report.c | 37 +-
10 files changed, 513 insertions(+), 401 deletions(-)
create mode 100644 lib/test_kasan_module.c
--
2.26.1.301.g55bc3eb7cb9-goog
This patch fixes an encoding bug in emit_stx for BPF_B when the source
register is BPF_REG_FP.
The current implementation for BPF_STX BPF_B in emit_stx saves one REX
byte when the operands can be encoded using Mod-R/M alone. The lower 8
bits of registers %rax, %rbx, %rcx, and %rdx can be accessed without using
a REX prefix via %al, %bl, %cl, and %dl, respectively. Other registers,
(e.g., %rsi, %rdi, %rbp, %rsp) require a REX prefix to use their 8-bit
equivalents (%sil, %dil, %bpl, %spl).
The current code checks if the source for BPF_STX BPF_B is BPF_REG_1
or BPF_REG_2 (which map to %rdi and %rsi), in which case it emits the
required REX prefix. However, it misses the case when the source is
BPF_REG_FP (mapped to %rbp).
The result is that BPF_STX BPF_B with BPF_REG_FP as the source operand
will read from register %ch instead of the correct %bpl. This patch fixes
the problem by fixing and refactoring the check on which registers need
the extra REX byte. Since no BPF registers map to %rsp, there is no need
to handle %spl.
Fixes: 622582786c9e0 ("net: filter: x86: internal BPF JIT")
Signed-off-by: Xi Wang <xi.wang(a)gmail.com>
Signed-off-by: Luke Nelson <luke.r.nels(a)gmail.com>
---
arch/x86/net/bpf_jit_comp.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 5ea7c2cf7ab4..42b6709e6dc7 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -158,6 +158,19 @@ static bool is_ereg(u32 reg)
BIT(BPF_REG_AX));
}
+/*
+ * is_ereg_8l() == true if BPF register 'reg' is mapped to access x86-64
+ * lower 8-bit registers dil,sil,bpl,spl,r8b..r15b, which need extra byte
+ * of encoding. al,cl,dl,bl have simpler encoding.
+ */
+static bool is_ereg_8l(u32 reg)
+{
+ return is_ereg(reg) ||
+ (1 << reg) & (BIT(BPF_REG_1) |
+ BIT(BPF_REG_2) |
+ BIT(BPF_REG_FP));
+}
+
static bool is_axreg(u32 reg)
{
return reg == BPF_REG_0;
@@ -598,9 +611,8 @@ static void emit_stx(u8 **pprog, u32 size, u32 dst_reg, u32 src_reg, int off)
switch (size) {
case BPF_B:
/* Emit 'mov byte ptr [rax + off], al' */
- if (is_ereg(dst_reg) || is_ereg(src_reg) ||
- /* We have to add extra byte for x86 SIL, DIL regs */
- src_reg == BPF_REG_1 || src_reg == BPF_REG_2)
+ if (is_ereg(dst_reg) || is_ereg_8l(src_reg))
+ /* Add extra byte for eregs or SIL,DIL,BPL in src_reg */
EMIT2(add_2mod(0x40, dst_reg, src_reg), 0x88);
else
EMIT1(0x88);
--
2.17.1
From: Heikki Krogerus <heikki.krogerus(a)linux.intel.com>
Previously, kobjects were released before the associated kobj_types;
this can cause a kobject deallocation to fail when the kobject has
children; an example of this is in software_node_unregister_nodes(); it
calls release on the parent before children meaning that children can be
released after the parent, which may be needed for removal.
So, take a reference to the parent before we delete a node to ensure
that the parent is not released before the children.
Reported-by: Naresh Kamboju <naresh.kamboju(a)linaro.org>
Fixes: 7589238a8cf3 ("Revert "software node: Simplify software_node_release() function"")
Link: https://lore.kernel.org/linux-kselftest/CAFd5g44s5NQvT8TG_x4rwbqoa7zWzkV0TX…
Co-developed-by: Brendan Higgins <brendanhiggins(a)google.com>
Signed-off-by: Brendan Higgins <brendanhiggins(a)google.com>
---
This patch is based on the diff written by Heikki linked above.
Heikki, can you either reply with a Signed-off-by? Otherwise, I can
resend with me as the author and I will list you as the Co-developed-by.
Sorry for all the CCs: I just want to make sure everyone who was a party
to the original bug sees this.
---
lib/kobject.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/kobject.c b/lib/kobject.c
index 83198cb37d8d..5921e2470b46 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -663,6 +663,7 @@ EXPORT_SYMBOL(kobject_get_unless_zero);
*/
static void kobject_cleanup(struct kobject *kobj)
{
+ struct kobject *parent = kobj->parent;
struct kobj_type *t = get_ktype(kobj);
const char *name = kobj->name;
@@ -680,6 +681,9 @@ static void kobject_cleanup(struct kobject *kobj)
kobject_uevent(kobj, KOBJ_REMOVE);
}
+ /* make sure the parent is not released before the (last) child */
+ kobject_get(parent);
+
/* remove from sysfs if the caller did not do it */
if (kobj->state_in_sysfs) {
pr_debug("kobject: '%s' (%p): auto cleanup kobject_del\n",
@@ -693,6 +697,8 @@ static void kobject_cleanup(struct kobject *kobj)
t->release(kobj);
}
+ kobject_put(parent);
+
/* free name if we allocated it */
if (name) {
pr_debug("kobject: '%s': free name\n", name);
base-commit: 8632e9b5645bbc2331d21d892b0d6961c1a08429
--
2.26.0.110.g2183baf09c-goog
From: Colin Ian King <colin.king(a)canonical.com>
There a are several spelling mistakes in various messages. Fix these.
There are three spelling mistakes in various messages. Fix these.
Signed-off-by: Colin Ian King <colin.king(a)canonical.com>
---
tools/testing/selftests/vm/khugepaged.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/vm/khugepaged.c b/tools/testing/selftests/vm/khugepaged.c
index 490055290d7f..399a67d54e52 100644
--- a/tools/testing/selftests/vm/khugepaged.c
+++ b/tools/testing/selftests/vm/khugepaged.c
@@ -537,7 +537,7 @@ static void collapse_max_ptes_none(void)
p = alloc_mapping();
fill_memory(p, 0, (hpage_pmd_nr - max_ptes_none - 1) * page_size);
- if (wait_for_scan("Do not collapse with max_ptes_none exeeded", p))
+ if (wait_for_scan("Do not collapse with max_ptes_none exceeded", p))
fail("Timeout");
else if (check_huge(p))
fail("Fail");
@@ -576,7 +576,7 @@ static void collapse_swapin_single_pte(void)
goto out;
}
- if (wait_for_scan("Collapse with swaping in single PTE entry", p))
+ if (wait_for_scan("Collapse with swapping in single PTE entry", p))
fail("Timeout");
else if (check_huge(p))
success("OK");
@@ -607,7 +607,7 @@ static void collapse_max_ptes_swap(void)
goto out;
}
- if (wait_for_scan("Do not collapse with max_ptes_swap exeeded", p))
+ if (wait_for_scan("Do not collapse with max_ptes_swap exceeded", p))
fail("Timeout");
else if (check_huge(p))
fail("Fail");
@@ -654,14 +654,14 @@ static void collapse_single_pte_entry_compound(void)
fail("Fail");
madvise(p, hpage_pmd_size, MADV_NOHUGEPAGE);
- printf("Split huge page leaving single PTE mapping compount page...");
+ printf("Split huge page leaving single PTE mapping compound page...");
madvise(p + page_size, hpage_pmd_size - page_size, MADV_DONTNEED);
if (!check_huge(p))
success("OK");
else
fail("Fail");
- if (wait_for_scan("Collapse PTE table with single PTE mapping compount page", p))
+ if (wait_for_scan("Collapse PTE table with single PTE mapping compound page", p))
fail("Timeout");
else if (check_huge(p))
success("OK");
@@ -685,7 +685,7 @@ static void collapse_full_of_compound(void)
else
fail("Fail");
- printf("Split huge page leaving single PTE page table full of compount pages...");
+ printf("Split huge page leaving single PTE page table full of compound pages...");
madvise(p, page_size, MADV_NOHUGEPAGE);
madvise(p, hpage_pmd_size, MADV_NOHUGEPAGE);
if (!check_huge(p))
@@ -908,7 +908,7 @@ static void collapse_max_ptes_shared()
else
fail("Fail");
- if (wait_for_scan("Do not collapse with max_ptes_shared exeeded", p))
+ if (wait_for_scan("Do not collapse with max_ptes_shared exceeded", p))
fail("Timeout");
else if (!check_huge(p))
success("OK");
--
2.25.1
This series adds basic self tests for HMM and are intended for Jason
Gunthorpe's rdma tree since I believe he is planning to make some HMM
related changes that this can help test.
Changes v8 -> v9:
Rebased to linux-5.7.0-rc1.
Moved include/uapi/linux/test_hmm.h to lib/test_hmm_uapi.h
Added calls to release_mem_region() to free device private addresses
Applied Jason's suggested changes for v8.
Added a check for no VMA read access before migrating to device private
memory.
Changes v7 -> v8:
Rebased to Jason's rdma/hmm tree, plus Jason's 6 patch series
"Small hmm_range_fault() cleanups".
Applied a number of changes from Jason's comments.
Changes v6 -> v7:
Rebased to linux-5.6.0-rc6
Reverted back to just using mmu_interval_notifier_insert() and making
this series only introduce HMM self tests.
Changes v5 -> v6:
Rebased to linux-5.5.0-rc6
Refactored mmu interval notifier patches
Converted nouveau to use the new mmu interval notifier API
Changes v4 -> v5:
Added mmu interval notifier insert/remove/update callable from the
invalidate() callback
Updated HMM tests to use the new core interval notifier API
Changes v1 -> v4:
https://lore.kernel.org/linux-mm/20191104222141.5173-1-rcampbell@nvidia.com
Ralph Campbell (3):
mm/hmm/test: add selftest driver for HMM
mm/hmm/test: add selftests for HMM
MAINTAINERS: add HMM selftests
MAINTAINERS | 3 +
lib/Kconfig.debug | 13 +
lib/Makefile | 1 +
lib/test_hmm.c | 1175 ++++++++++++++++++++
lib/test_hmm_uapi.h | 59 +
tools/testing/selftests/vm/.gitignore | 1 +
tools/testing/selftests/vm/Makefile | 3 +
tools/testing/selftests/vm/config | 2 +
tools/testing/selftests/vm/hmm-tests.c | 1359 ++++++++++++++++++++++++
tools/testing/selftests/vm/run_vmtests | 16 +
tools/testing/selftests/vm/test_hmm.sh | 97 ++
11 files changed, 2729 insertions(+)
create mode 100644 lib/test_hmm.c
create mode 100644 lib/test_hmm_uapi.h
create mode 100644 tools/testing/selftests/vm/hmm-tests.c
create mode 100755 tools/testing/selftests/vm/test_hmm.sh
--
2.25.2
Hello Brendan Higgins,
The patch 5f3e06208920: "kunit: test: add support for test abort"
from Sep 23, 2019, leads to the following static checker warning:
lib/kunit/try-catch.c:93 kunit_try_catch_run()
misplaced newline? ' # %s: Unknown error: %d
lib/kunit/try-catch.c
58 void kunit_try_catch_run(struct kunit_try_catch *try_catch, void *context)
59 {
60 DECLARE_COMPLETION_ONSTACK(try_completion);
61 struct kunit *test = try_catch->test;
62 struct task_struct *task_struct;
63 int exit_code, time_remaining;
64
65 try_catch->context = context;
66 try_catch->try_completion = &try_completion;
67 try_catch->try_result = 0;
68 task_struct = kthread_run(kunit_generic_run_threadfn_adapter,
69 try_catch,
70 "kunit_try_catch_thread");
71 if (IS_ERR(task_struct)) {
72 try_catch->catch(try_catch->context);
73 return;
74 }
75
76 time_remaining = wait_for_completion_timeout(&try_completion,
77 kunit_test_timeout());
78 if (time_remaining == 0) {
79 kunit_err(test, "try timed out\n");
^^
The kunit_log() macro adds its own newline. Most of the callers add
a newline. It should be the callers add a newline because that's how
everything else works in the kernel.
The dev_printk() stuff will sometimes add a newline, but never a
duplicate newline. In other words, it's slightly complicated. But
basically the caller should add a newline.
80 try_catch->try_result = -ETIMEDOUT;
81 }
82
83 exit_code = try_catch->try_result;
84
85 if (!exit_code)
86 return;
87
88 if (exit_code == -EFAULT)
89 try_catch->try_result = 0;
90 else if (exit_code == -EINTR)
91 kunit_err(test, "wake_up_process() was never called\n");
^^
92 else if (exit_code)
93 kunit_err(test, "Unknown error: %d\n", exit_code);
^^
94
95 try_catch->catch(try_catch->context);
96 }
regards,
dan carpenter
> It should set config->test_fs instead of config->test_driver as NULL
> after kfree_const(config->test_fs) to avoid potential double free.
I suggest to improve this change description.
* How do you think about a wording variant like the following?
Reset the member “test_fs” of the test configuration after a call
of the function “kfree_const” to a null pointer so that a double
memory release will not be performed.
* Would you like to add the tag “Fixes”?
Regards,
Markus
From: "Steven Rostedt (VMware)" <rostedt(a)goodmis.org>
[ Upstream commit b43e78f65b1d35fd3e13c7b23f9b64ea83c9ad3a ]
As the ftrace selftests can run for a long period of time, disable the
timeout that the general selftests have. If a selftest hangs, then it
probably means the machine will hang too.
Link: https://lore.kernel.org/r/alpine.LSU.2.21.1911131604170.18679@pobox.suse.cz
Suggested-by: Miroslav Benes <mbenes(a)suse.cz>
Tested-by: Miroslav Benes <mbenes(a)suse.cz>
Reviewed-by: Miroslav Benes <mbenes(a)suse.cz>
Signed-off-by: Steven Rostedt (VMware) <rostedt(a)goodmis.org>
Signed-off-by: Sasha Levin <sashal(a)kernel.org>
---
tools/testing/selftests/ftrace/settings | 1 +
1 file changed, 1 insertion(+)
create mode 100644 tools/testing/selftests/ftrace/settings
diff --git a/tools/testing/selftests/ftrace/settings b/tools/testing/selftests/ftrace/settings
new file mode 100644
index 0000000000000..e7b9417537fbc
--- /dev/null
+++ b/tools/testing/selftests/ftrace/settings
@@ -0,0 +1 @@
+timeout=0
--
2.20.1
From: "Steven Rostedt (VMware)" <rostedt(a)goodmis.org>
[ Upstream commit b43e78f65b1d35fd3e13c7b23f9b64ea83c9ad3a ]
As the ftrace selftests can run for a long period of time, disable the
timeout that the general selftests have. If a selftest hangs, then it
probably means the machine will hang too.
Link: https://lore.kernel.org/r/alpine.LSU.2.21.1911131604170.18679@pobox.suse.cz
Suggested-by: Miroslav Benes <mbenes(a)suse.cz>
Tested-by: Miroslav Benes <mbenes(a)suse.cz>
Reviewed-by: Miroslav Benes <mbenes(a)suse.cz>
Signed-off-by: Steven Rostedt (VMware) <rostedt(a)goodmis.org>
Signed-off-by: Sasha Levin <sashal(a)kernel.org>
---
tools/testing/selftests/ftrace/settings | 1 +
1 file changed, 1 insertion(+)
create mode 100644 tools/testing/selftests/ftrace/settings
diff --git a/tools/testing/selftests/ftrace/settings b/tools/testing/selftests/ftrace/settings
new file mode 100644
index 0000000000000..e7b9417537fbc
--- /dev/null
+++ b/tools/testing/selftests/ftrace/settings
@@ -0,0 +1 @@
+timeout=0
--
2.20.1
Hi,
My name is felix. I have a quick and easy business offer that
will benefit us both immensely. The amount involved is over 9.4
Milli0n in US d0llars.
I await your immediate reply so that I can give full details.
Rgds
Felix
This introduces a test case to check memory slots with overlapped
regions on the guest address cannot be added. The cases checked
are described in the block comment upon test_overlap_memory_regions()
(see the patch 01).
I didn't see the need to calcute the addresses on compile/run-time, so I
just left them hard-coded (remember: aligned 1M to work on s390x).
It works on x86_64, aarch64, and s390x.
The patch is based on queue branch.
Ah, I did some cosmetic changes on test_add_max_memory_regions() too. If
it is not OK to be in a single patch...let me know.
Wainer dos Santos Moschetta (1):
selftests: kvm: Add overlapped memory regions test
.../selftests/kvm/set_memory_region_test.c | 75 ++++++++++++++++++-
1 file changed, 74 insertions(+), 1 deletion(-)
--
2.17.2
Hi,
This new patch series brings some improvements while simplifying the
code, fixes some bugs and adds more tests:
Use a bitfield of layers to properly manage superset and subset of
access rights, whatever their order in the stack of layers [1].
Allow to open pipes and similar special files through /proc/self/fd, as
well as internal filesystems such as nsfs through /proc/self/ns, because
disconnected path cannot be evaluated. Such special filesystems could
be handled with a future evolution.
For the sake of simplicity, forbid reparenting when linking or renaming
to protect against possible privilege escalation. This could happen by
changing the hierarchy of a file or directory in relation to an enforced
access policy (from the set of layers). This will be relaxed in the
future with more complex code.
Rename the unlink and rmdir access rights to a more generic ones:
remove_dir and remove_file. Indeed it makes sense to also use them for
the action of renaming a file or a directory, which may lead to the
removal of the source file or directory. Replace the link_to,
rename_from and rename_to access rights with remove_file, remove_dir and
make_* .
Add multiple tests to check semantic, and improve test coverage for
security/landlock to 94.1% of lines (best possible with deterministic
user space tests).
Add current limitations to documentation: file renaming and linking,
OverlayFS and special filesystems (e.g. nsfs).
The previously identified memory accounting limitation can already be
solved with the (kernel) Memory Resource Controller from cgroup.
The SLOC count is 1267 for security/landlock/ and 1643 for
tools/testing/selftest/landlock/ .
The compiled documentation is available here:
https://landlock.io/linux-doc/landlock-v16/security/landlock/index.html
This series can be applied on top of v5.7-rc1. This can be tested with
CONFIG_SECURITY_LANDLOCK and CONFIG_SAMPLE_LANDLOCK. This patch series
can be found in a Git repository here:
https://github.com/landlock-lsm/linux/commits/landlock-v16
I would really appreciate constructive comments on this patch series.
# Landlock LSM
The goal of Landlock is to enable to restrict ambient rights (e.g.
global filesystem access) for a set of processes. Because Landlock is a
stackable LSM [2], it makes possible to create safe security sandboxes
as new security layers in addition to the existing system-wide
access-controls. This kind of sandbox is expected to help mitigate the
security impact of bugs or unexpected/malicious behaviors in user-space
applications. Landlock empowers any process, including unprivileged
ones, to securely restrict themselves.
Landlock is inspired by seccomp-bpf but instead of filtering syscalls
and their raw arguments, a Landlock rule can restrict the use of kernel
objects like file hierarchies, according to the kernel semantic.
Landlock also takes inspiration from other OS sandbox mechanisms: XNU
Sandbox, FreeBSD Capsicum or OpenBSD Pledge/Unveil.
Previous version:
https://lore.kernel.org/lkml/20200326202731.693608-1-mic@digikod.net/
[1] https://lore.kernel.org/lkml/e07fe473-1801-01cc-12ae-b3167f95250e@digikod.n…
[2] https://lore.kernel.org/lkml/50db058a-7dde-441b-a7f9-f6837fe8b69f@schaufler…
Regards,
Mickaël Salaün (10):
landlock: Add object management
landlock: Add ruleset and domain management
landlock: Set up the security framework and manage credentials
landlock: Add ptrace restrictions
fs,landlock: Support filesystem access-control
landlock: Add syscall implementation
arch: Wire up landlock() syscall
selftests/landlock: Add initial tests
samples/landlock: Add a sandbox manager example
landlock: Add user and kernel documentation
Documentation/security/index.rst | 1 +
Documentation/security/landlock/index.rst | 18 +
Documentation/security/landlock/kernel.rst | 69 +
Documentation/security/landlock/user.rst | 268 +++
MAINTAINERS | 12 +
arch/alpha/kernel/syscalls/syscall.tbl | 1 +
arch/arm/tools/syscall.tbl | 1 +
arch/arm64/include/asm/unistd.h | 2 +-
arch/arm64/include/asm/unistd32.h | 2 +
arch/ia64/kernel/syscalls/syscall.tbl | 1 +
arch/m68k/kernel/syscalls/syscall.tbl | 1 +
arch/microblaze/kernel/syscalls/syscall.tbl | 1 +
arch/mips/kernel/syscalls/syscall_n32.tbl | 1 +
arch/mips/kernel/syscalls/syscall_n64.tbl | 1 +
arch/mips/kernel/syscalls/syscall_o32.tbl | 1 +
arch/parisc/kernel/syscalls/syscall.tbl | 1 +
arch/powerpc/kernel/syscalls/syscall.tbl | 1 +
arch/s390/kernel/syscalls/syscall.tbl | 1 +
arch/sh/kernel/syscalls/syscall.tbl | 1 +
arch/sparc/kernel/syscalls/syscall.tbl | 1 +
arch/x86/entry/syscalls/syscall_32.tbl | 1 +
arch/x86/entry/syscalls/syscall_64.tbl | 1 +
arch/xtensa/kernel/syscalls/syscall.tbl | 1 +
fs/super.c | 2 +
include/linux/fs.h | 5 +
include/linux/landlock.h | 22 +
include/linux/syscalls.h | 3 +
include/uapi/asm-generic/unistd.h | 4 +-
include/uapi/linux/landlock.h | 296 +++
kernel/sys_ni.c | 3 +
samples/Kconfig | 7 +
samples/Makefile | 1 +
samples/landlock/.gitignore | 1 +
samples/landlock/Makefile | 15 +
samples/landlock/sandboxer.c | 228 +++
security/Kconfig | 11 +-
security/Makefile | 2 +
security/landlock/Kconfig | 18 +
security/landlock/Makefile | 4 +
security/landlock/common.h | 20 +
security/landlock/cred.c | 46 +
security/landlock/cred.h | 58 +
security/landlock/fs.c | 601 ++++++
security/landlock/fs.h | 42 +
security/landlock/object.c | 66 +
security/landlock/object.h | 91 +
security/landlock/ptrace.c | 120 ++
security/landlock/ptrace.h | 14 +
security/landlock/ruleset.c | 344 ++++
security/landlock/ruleset.h | 161 ++
security/landlock/setup.c | 39 +
security/landlock/setup.h | 18 +
security/landlock/syscall.c | 501 +++++
tools/testing/selftests/Makefile | 1 +
tools/testing/selftests/landlock/.gitignore | 4 +
tools/testing/selftests/landlock/Makefile | 29 +
tools/testing/selftests/landlock/common.h | 42 +
tools/testing/selftests/landlock/config | 5 +
tools/testing/selftests/landlock/test_base.c | 156 ++
tools/testing/selftests/landlock/test_fs.c | 1696 +++++++++++++++++
.../testing/selftests/landlock/test_ptrace.c | 291 +++
tools/testing/selftests/landlock/true.c | 5 +
62 files changed, 5353 insertions(+), 7 deletions(-)
create mode 100644 Documentation/security/landlock/index.rst
create mode 100644 Documentation/security/landlock/kernel.rst
create mode 100644 Documentation/security/landlock/user.rst
create mode 100644 include/linux/landlock.h
create mode 100644 include/uapi/linux/landlock.h
create mode 100644 samples/landlock/.gitignore
create mode 100644 samples/landlock/Makefile
create mode 100644 samples/landlock/sandboxer.c
create mode 100644 security/landlock/Kconfig
create mode 100644 security/landlock/Makefile
create mode 100644 security/landlock/common.h
create mode 100644 security/landlock/cred.c
create mode 100644 security/landlock/cred.h
create mode 100644 security/landlock/fs.c
create mode 100644 security/landlock/fs.h
create mode 100644 security/landlock/object.c
create mode 100644 security/landlock/object.h
create mode 100644 security/landlock/ptrace.c
create mode 100644 security/landlock/ptrace.h
create mode 100644 security/landlock/ruleset.c
create mode 100644 security/landlock/ruleset.h
create mode 100644 security/landlock/setup.c
create mode 100644 security/landlock/setup.h
create mode 100644 security/landlock/syscall.c
create mode 100644 tools/testing/selftests/landlock/.gitignore
create mode 100644 tools/testing/selftests/landlock/Makefile
create mode 100644 tools/testing/selftests/landlock/common.h
create mode 100644 tools/testing/selftests/landlock/config
create mode 100644 tools/testing/selftests/landlock/test_base.c
create mode 100644 tools/testing/selftests/landlock/test_fs.c
create mode 100644 tools/testing/selftests/landlock/test_ptrace.c
create mode 100644 tools/testing/selftests/landlock/true.c
--
2.26.1
This patchset contains everything needed to integrate KASAN and KUnit.
KUnit will be able to:
(1) Fail tests when an unexpected KASAN error occurs
(2) Pass tests when an expected KASAN error occurs
Convert KASAN tests to KUnit with the exception of copy_user_test
because KUnit is unable to test those.
Add documentation on how to run the KASAN tests with KUnit and what to
expect when running these tests.
Depends on "[PATCH v3 kunit-next 0/2] kunit: extend kunit resources
API" patchset [1]
Changes from v4:
- KASAN no longer will panic on errors if both panic_on_warn and
kasan_multishot are enabled.
- As a result, the KASAN tests will no-longer disable panic_on_warn.
- This also means panic_on_warn no-longer needs to be exported.
- The use of temporary "kasan_data" variables has been cleaned up
somewhat.
- A potential refcount/resource leak should multiple KASAN errors
appear during an assertion was fixed.
- Some wording changes to the KASAN test Kconfig entries.
Changes from v3:
- KUNIT_SET_KASAN_DATA and KUNIT_DO_EXPECT_KASAN_FAIL have been
combined and included in KUNIT_DO_EXPECT_KASAN_FAIL() instead.
- Reordered logic in kasan_update_kunit_status() in report.c to be
easier to read.
- Added comment to not use the name "kasan_data" for any kunit tests
outside of KUNIT_EXPECT_KASAN_FAIL().
Changes since v2:
- Due to Alan's changes in [1], KUnit can be built as a module.
- The name of the tests that could not be run with KUnit has been
changed to be more generic: test_kasan_module.
- Documentation on how to run the new KASAN tests and what to expect
when running them has been added.
- Some variables and functions are now static.
- Now save/restore panic_on_warn in a similar way to kasan_multi_shot
and renamed the init/exit functions to be more generic to accommodate.
- Due to [2] in kasan_strings, kasan_memchr, and
kasan_memcmp will fail if CONFIG_AMD_MEM_ENCRYPT is enabled so return
early and print message explaining this circumstance.
- Changed preprocessor checks to C checks where applicable.
Changes since v1:
- Make use of Alan Maguire's suggestion to use his patch that allows
static resources for integration instead of adding a new attribute to
the kunit struct
- All KUNIT_EXPECT_KASAN_FAIL statements are local to each test
- The definition of KUNIT_EXPECT_KASAN_FAIL is local to the
test_kasan.c file since it seems this is the only place this will
be used.
- Integration relies on KUnit being builtin
- copy_user_test has been separated into its own file since KUnit
is unable to test these. This can be run as a module just as before,
using CONFIG_TEST_KASAN_USER
- The addition to the current task has been separated into its own
patch as this is a significant enough change to be on its own.
[1] https://lore.kernel.org/linux-kselftest/1585313122-26441-1-git-send-email-a…
[2] https://bugzilla.kernel.org/show_bug.cgi?id=206337
Patricia Alfonso (4):
Add KUnit Struct to Current Task
KUnit: KASAN Integration
KASAN: Port KASAN Tests to KUnit
KASAN: Testing Documentation
Documentation/dev-tools/kasan.rst | 70 ++++
include/kunit/test.h | 5 +
include/linux/kasan.h | 6 +
include/linux/sched.h | 4 +
lib/Kconfig.kasan | 18 +-
lib/Makefile | 3 +-
lib/kunit/test.c | 13 +-
lib/test_kasan.c | 668 +++++++++++++-----------------
lib/test_kasan_module.c | 76 ++++
mm/kasan/report.c | 34 +-
10 files changed, 504 insertions(+), 393 deletions(-)
create mode 100644 lib/test_kasan_module.c
--
2.26.0.110.g2183baf09c-goog
This series adds basic self tests for HMM and are intended for Jason
Gunthorpe's rdma tree which has a number of HMM patches applied.
Changes v7 -> v8:
Rebased to Jason's rdma/hmm tree, plus Jason's 6 patch series
"Small hmm_range_fault() cleanups".
Applied a number of changes from Jason's comments.
Changes v6 -> v7:
Rebased to linux-5.6.0-rc6
Reverted back to just using mmu_interval_notifier_insert() and making
this series only introduce HMM self tests.
Changes v5 -> v6:
Rebased to linux-5.5.0-rc6
Refactored mmu interval notifier patches
Converted nouveau to use the new mmu interval notifier API
Changes v4 -> v5:
Added mmu interval notifier insert/remove/update callable from the
invalidate() callback
Updated HMM tests to use the new core interval notifier API
Changes v1 -> v4:
https://lore.kernel.org/linux-mm/20191104222141.5173-1-rcampbell@nvidia.com
Ralph Campbell (3):
mm/hmm/test: add selftest driver for HMM
mm/hmm/test: add selftests for HMM
MAINTAINERS: add HMM selftests
MAINTAINERS | 3 +
include/uapi/linux/test_hmm.h | 59 ++
lib/Kconfig.debug | 12 +
lib/Makefile | 1 +
lib/test_hmm.c | 1177 +++++++++++++++++++++
tools/testing/selftests/vm/.gitignore | 1 +
tools/testing/selftests/vm/Makefile | 3 +
tools/testing/selftests/vm/config | 2 +
tools/testing/selftests/vm/hmm-tests.c | 1353 ++++++++++++++++++++++++
tools/testing/selftests/vm/run_vmtests | 16 +
tools/testing/selftests/vm/test_hmm.sh | 97 ++
11 files changed, 2724 insertions(+)
create mode 100644 include/uapi/linux/test_hmm.h
create mode 100644 lib/test_hmm.c
create mode 100644 tools/testing/selftests/vm/hmm-tests.c
create mode 100755 tools/testing/selftests/vm/test_hmm.sh
--
2.20.1
When kunit tests are run on native (i.e. non-UML) environments, the results
of test execution are often intermixed with dmesg output. This patch
series attempts to solve this by providing a debugfs representation
of the results of the last test run, available as
/sys/kernel/debug/kunit/<testsuite>/results
Changes since v7:
- renamed KUNIT_INDENT[2] to KUNIT_SUBTEST_INDENT, KUNIT_SUBSUBTEST_INDENT
and added more description to their definitions to clarify why they
are defined as they are (Shuah)
- defined KUNIT_SUBSUBTEST_INDENT directly as 8 spaces to avoid
checkpatch error (Shuah)
Changes since v6:
- fixed regexp parsing in kunit_parser.py to ensure test results are read
successfully with 4-space indentation (Brendan, patch 3)
Changes since v5:
- replaced undefined behaviour use of snprintf(buf, ..., buf) in
kunit_log() with a function to append string to existing log
(Frank, patch 1)
- added clarification on log size limitations to documentation
(Frank, patch 4)
Changes since v4:
- added suite-level log expectations to kunit log test (Brendan, patch 2)
- added log expectations (of it being NULL) for case where
CONFIG_KUNIT_DEBUGFS=n to kunit log test (patch 2)
- added patch 3 which replaces subtest tab indentation with 4 space
indentation as per TAP 14 spec (Frank, patch 3)
Changes since v3:
- added CONFIG_KUNIT_DEBUGFS to support conditional compilation of debugfs
representation, including string logging (Frank, patch 1)
- removed unneeded NULL check for test_case in
kunit_suite_for_each_test_case() (Frank, patch 1)
- added kunit log test to verify logging multiple strings works
(Frank, patch 2)
- rephrased description of results file (Frank, patch 3)
Changes since v2:
- updated kunit_status2str() to kunit_status_to_string() and made it
static inline in include/kunit/test.h (Brendan)
- added log string to struct kunit_suite and kunit_case, with log
pointer in struct kunit pointing at the case log. This allows us
to collect kunit_[err|info|warning]() messages at the same time
as we printk() them. This solves for the most part the sharing
of log messages between test execution and debugfs since we
just print the suite log (which contains the test suite preamble)
and the individual test logs. The only exception is the suite-level
status, which we cannot store in the suite log as it would mean
we'd print the suite and its status prior to the suite's results.
(Brendan, patch 1)
- dropped debugfs-based kunit run patch for now so as not to cause
problems with tests currently under development (Brendan)
- fixed doc issues with code block (Brendan, patch 3)
Changes since v1:
- trimmed unneeded include files in lib/kunit/debugfs.c (Greg)
- renamed global debugfs functions to be prefixed with kunit_ (Greg)
- removed error checking for debugfs operations (Greg)
Alan Maguire (4):
kunit: add debugfs /sys/kernel/debug/kunit/<suite>/results display
kunit: add log test
kunit: subtests should be indented 4 spaces according to TAP
kunit: update documentation to describe debugfs representation
Documentation/dev-tools/kunit/usage.rst | 14 +++
include/kunit/test.h | 63 ++++++++++++--
lib/kunit/Kconfig | 8 ++
lib/kunit/Makefile | 4 +
lib/kunit/assert.c | 79 ++++++++---------
lib/kunit/debugfs.c | 116 +++++++++++++++++++++++++
lib/kunit/debugfs.h | 30 +++++++
lib/kunit/kunit-test.c | 44 +++++++++-
lib/kunit/test.c | 148 +++++++++++++++++++++++++-------
tools/testing/kunit/kunit_parser.py | 10 +--
10 files changed, 430 insertions(+), 86 deletions(-)
create mode 100644 lib/kunit/debugfs.c
create mode 100644 lib/kunit/debugfs.h
--
1.8.3.1
Hi!
Shuah please consider applying to the kselftest tree.
This set is an attempt to make running tests for different
sets of data easier. The direct motivation is the tls
test which we'd like to run for TLS 1.2 and TLS 1.3,
but currently there is no easy way to invoke the same
tests with different parameters.
Tested all users of kselftest_harness.h.
v2:
- don't run tests by fixture
- don't pass params as an explicit argument
v3:
- go back to the orginal implementation with an extra
parameter, and running by fixture (Kees);
- add LIST_APPEND helper (Kees);
- add a dot between fixture and param name (Kees);
- rename the params to variants (Tim);
v4:
- whitespace fixes.
v5 (Kees):
- move a comment;
- remove a temporary variable;
- reword the commit message on patch 4.
v1: https://lore.kernel.org/netdev/20200313031752.2332565-1-kuba@kernel.org/
v2: https://lore.kernel.org/netdev/20200314005501.2446494-1-kuba@kernel.org/
v3: https://lore.kernel.org/netdev/20200316225647.3129354-1-kuba@kernel.org/
v4: https://lore.kernel.org/netdev/20200317010419.3268916-1-kuba@kernel.org/
Jakub Kicinski (5):
kselftest: factor out list manipulation to a helper
kselftest: create fixture objects
kselftest: run tests by fixture
kselftest: add fixture variants
selftests: tls: run all tests for TLS 1.2 and TLS 1.3
Documentation/dev-tools/kselftest.rst | 3 +-
tools/testing/selftests/kselftest_harness.h | 234 +++++++++++++++-----
tools/testing/selftests/net/tls.c | 93 ++------
3 files changed, 202 insertions(+), 128 deletions(-)
--
2.25.1
> Traced event can trigger 'snapshot' operation(i.e. calls snapshot_trigger()
I suggest to improve the change description.
* Adjustment:
… operation (i. e. …
* Will the tag “Fixes” become relevant?
Regards,
Markus
Fix warnings at 'make htmldocs', and formatting issues in the resulting
documentation.
- test.h: Fix annotation in kernel-doc parameter description.
- Documentation/*.rst: Fixing formatting issues, and a duplicate label
issue due to usage of sphinx.ext.autosectionlabel and identical labels
within one document (sphinx warning)
NB: checkpatch.pl will complain about flow control statements (i.e. usage
of "return") within the macro kunit_test_suites(suites_list...).
v2: Several documentation fixes
v3: Do not touch API documentation index
v4: Replace macro argument in test.h by named variadic argument
Signed-off-by: Lothar Rubusch <l.rubusch(a)gmail.com>
---
Documentation/dev-tools/kunit/start.rst | 13 ++++++++-----
Documentation/dev-tools/kunit/usage.rst | 4 ++--
include/kunit/test.h | 12 ++++++------
3 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/Documentation/dev-tools/kunit/start.rst b/Documentation/dev-tools/kunit/start.rst
index e1c5ce80ce12..bb112cf70624 100644
--- a/Documentation/dev-tools/kunit/start.rst
+++ b/Documentation/dev-tools/kunit/start.rst
@@ -32,15 +32,17 @@ test targets as well. The ``.kunitconfig`` should also contain any other config
options required by the tests.
A good starting point for a ``.kunitconfig`` is the KUnit defconfig:
+
.. code-block:: bash
cd $PATH_TO_LINUX_REPO
cp arch/um/configs/kunit_defconfig .kunitconfig
You can then add any other Kconfig options you wish, e.g.:
+
.. code-block:: none
- CONFIG_LIST_KUNIT_TEST=y
+ CONFIG_LIST_KUNIT_TEST=y
:doc:`kunit_tool <kunit-tool>` will ensure that all config options set in
``.kunitconfig`` are set in the kernel ``.config`` before running the tests.
@@ -54,8 +56,8 @@ using.
other tools (such as make menuconfig) to adjust other config options.
-Running the tests
------------------
+Running the tests (KUnit Wrapper)
+---------------------------------
To make sure that everything is set up correctly, simply invoke the Python
wrapper from your kernel repo:
@@ -105,8 +107,9 @@ have config options ending in ``_KUNIT_TEST``.
KUnit and KUnit tests can be compiled as modules: in this case the tests in a
module will be run when the module is loaded.
-Running the tests
------------------
+
+Running the tests (w/o KUnit Wrapper)
+-------------------------------------
Build and run your kernel as usual. Test output will be written to the kernel
log in `TAP <https://testanything.org/>`_ format.
diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst
index 473a2361ec37..3c3fe8b5fecc 100644
--- a/Documentation/dev-tools/kunit/usage.rst
+++ b/Documentation/dev-tools/kunit/usage.rst
@@ -595,7 +595,7 @@ able to run one test case per invocation.
KUnit debugfs representation
============================
When kunit test suites are initialized, they create an associated directory
-in /sys/kernel/debug/kunit/<test-suite>. The directory contains one file
+in ``/sys/kernel/debug/kunit/<test-suite>``. The directory contains one file
- results: "cat results" displays results of each test case and the results
of the entire suite for the last test run.
@@ -604,4 +604,4 @@ The debugfs representation is primarily of use when kunit test suites are
run in a native environment, either as modules or builtin. Having a way
to display results like this is valuable as otherwise results can be
intermixed with other events in dmesg output. The maximum size of each
-results file is KUNIT_LOG_SIZE bytes (defined in include/kunit/test.h).
+results file is KUNIT_LOG_SIZE bytes (defined in ``include/kunit/test.h``).
diff --git a/include/kunit/test.h b/include/kunit/test.h
index 9b0c46a6ca1f..47e61e1d5337 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -175,7 +175,7 @@ struct kunit_suite {
void (*exit)(struct kunit *test);
struct kunit_case *test_cases;
- /* private - internal use only */
+ /* private: internal use only */
struct dentry *debugfs;
char *log;
};
@@ -232,12 +232,12 @@ void __kunit_test_suites_exit(struct kunit_suite **suites);
* kunit_test_suites() - used to register one or more &struct kunit_suite
* with KUnit.
*
- * @suites: a statically allocated list of &struct kunit_suite.
+ * @suites_list...: a statically allocated list of &struct kunit_suite.
*
- * Registers @suites with the test framework. See &struct kunit_suite for
+ * Registers @suites_list with the test framework. See &struct kunit_suite for
* more information.
*
- * When builtin, KUnit tests are all run as late_initcalls; this means
+ * When builtin, KUnit tests are all run as late_initcalls; this means
* that they cannot test anything where tests must run at a different init
* phase. One significant restriction resulting from this is that KUnit
* cannot reliably test anything that is initialize in the late_init phase;
@@ -253,8 +253,8 @@ void __kunit_test_suites_exit(struct kunit_suite **suites);
* tests from the same place, and at the very least to do so after
* everything else is definitely initialized.
*/
-#define kunit_test_suites(...) \
- static struct kunit_suite *suites[] = { __VA_ARGS__, NULL}; \
+#define kunit_test_suites(suites_list...) \
+ static struct kunit_suite *suites[] = {suites_list, NULL}; \
static int kunit_test_suites_init(void) \
{ \
return __kunit_test_suites_init(suites); \
--
2.20.1
Add test which adds a tree of software_nodes, checks that the nodes
exist, and then removes the tree. This exercises a bug reported by
Naresh Kamboju <naresh.kamboju(a)linaro.org>, and pretty much just takes a
test case from the test_printf Kselftest module and refocusses it on
adding and then removing a tree of software_nodes.
Signed-off-by: Brendan Higgins <brendanhiggins(a)google.com>
---
I am not sure if this should be rolled into the property entry test, or
should be moved somewhere else; nevertheless, testing the software node
API seems like a good idea and this seems like a good place to start.
---
drivers/base/test/Kconfig | 14 ++++++++
drivers/base/test/Makefile | 2 ++
drivers/base/test/software-node-test.c | 46 ++++++++++++++++++++++++++
3 files changed, 62 insertions(+)
create mode 100644 drivers/base/test/software-node-test.c
diff --git a/drivers/base/test/Kconfig b/drivers/base/test/Kconfig
index 305c7751184a..b42f385fe233 100644
--- a/drivers/base/test/Kconfig
+++ b/drivers/base/test/Kconfig
@@ -11,3 +11,17 @@ config TEST_ASYNC_DRIVER_PROBE
config KUNIT_DRIVER_PE_TEST
bool "KUnit Tests for property entry API"
depends on KUNIT=y
+config KUNIT_DRIVER_SOFTWARE_NODE_TEST
+ bool "KUnit Tests for software node API"
+ depends on KUNIT=y
+ help
+ This builds the software node API tests.
+
+ KUnit tests run during boot and output the results to the debug log
+ in TAP format (http://testanything.org/). Only useful for kernel devs
+ and are not for inclusion into a production build.
+
+ For more information on KUnit and unit tests in general please refer
+ to the KUnit documentation in Documentation/dev-tools/kunit/.
+
+ If unsure, say N.
diff --git a/drivers/base/test/Makefile b/drivers/base/test/Makefile
index 3ca56367c84b..63325e8a5288 100644
--- a/drivers/base/test/Makefile
+++ b/drivers/base/test/Makefile
@@ -2,3 +2,5 @@
obj-$(CONFIG_TEST_ASYNC_DRIVER_PROBE) += test_async_driver_probe.o
obj-$(CONFIG_KUNIT_DRIVER_PE_TEST) += property-entry-test.o
+
+obj-$(CONFIG_KUNIT_DRIVER_SOFTWARE_NODE_TEST) += software-node-test.o
diff --git a/drivers/base/test/software-node-test.c b/drivers/base/test/software-node-test.c
new file mode 100644
index 000000000000..0609cbd9aa0a
--- /dev/null
+++ b/drivers/base/test/software-node-test.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0
+// Unit tests for software node API
+//
+// Copyright 2020 Google LLC.
+
+#include <kunit/test.h>
+#include <linux/property.h>
+#include <linux/types.h>
+
+static void software_node_test_register_nodes(struct kunit *test)
+{
+ const struct software_node softnodes[] = {
+ { .name = "first", },
+ { .name = "second", .parent = &softnodes[0], },
+ { .name = "third", .parent = &softnodes[1], },
+ {}
+ };
+ const char * const full_name = "first/second/third";
+ char *buf;
+
+ buf = kunit_kzalloc(test, strlen(full_name), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
+
+ KUNIT_ASSERT_EQ(test, software_node_register_nodes(softnodes), 0);
+
+ /* Check that all the nodes exist. */
+ KUNIT_ASSERT_EQ(test,
+ (size_t)sprintf(buf, "%pfw",
+ software_node_fwnode(&softnodes[2])),
+ strlen(full_name));
+ KUNIT_EXPECT_STREQ(test, buf, full_name);
+
+ software_node_unregister_nodes(softnodes);
+}
+
+static struct kunit_case software_node_test_cases[] = {
+ KUNIT_CASE(software_node_test_register_nodes),
+ {}
+};
+
+static struct kunit_suite software_node_test_suite = {
+ .name = "software-node",
+ .test_cases = software_node_test_cases,
+};
+
+kunit_test_suite(software_node_test_suite);
base-commit: 8632e9b5645bbc2331d21d892b0d6961c1a08429
--
2.26.0.110.g2183baf09c-goog
From: Tim Bird <tim.bird(a)sony.com>
Add ksft-compile-test.sh. This is a program used to test
cross-compilation and installation of selftest tests.
See the test usage for help
This program currently tests 3 scenarios out of a larger matrix
of possibly interesting scenarios. For each scenario, it conducts
multiple tests for correctness. This version tests:
1) does the test compile
2) is the kernel source directory clean after the compile
3) does the test install operation succeed
4) does the test run script reference the test
Signed-off-by: Tim Bird <tim.bird(a)sony.com>
---
MAINTAINERS | 6 +
tools/testing/selftests/ksft-compile-test.sh | 567 +++++++++++++++++++++++++++
2 files changed, 573 insertions(+)
create mode 100755 tools/testing/selftests/ksft-compile-test.sh
diff --git a/MAINTAINERS b/MAINTAINERS
index cc1d18c..a6289c7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9127,6 +9127,12 @@ S: Maintained
F: tools/testing/selftests/
F: Documentation/dev-tools/kselftest*
+KERNEL SELFTEST SELFTEST
+M: Tim Bird <tim.bird(a)sony.com>
+L: linux-kselftest(a)vger.kernel.org
+S: Maintained
+F: tools/testing/selftests/ksft-compile-test.sh
+
KERNEL UNIT TESTING FRAMEWORK (KUnit)
M: Brendan Higgins <brendanhiggins(a)google.com>
L: linux-kselftest(a)vger.kernel.org
diff --git a/tools/testing/selftests/ksft-compile-test.sh b/tools/testing/selftests/ksft-compile-test.sh
new file mode 100755
index 0000000..e36e858
--- /dev/null
+++ b/tools/testing/selftests/ksft-compile-test.sh
@@ -0,0 +1,567 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only OR MIT
+#
+# ksft-compile-test.sh - test compiling Linux kernel selftests under lots of
+# different configurations. This is used to check that cross-compilation
+# and install works properly for a newly submitted test target, and
+# also that changes to existing test Makefiles don't regress with regard to
+# this functionality.
+#
+# Copyright 2020 Sony Corporation
+#
+# Here are the things that Shuah Kahn asked for on 3/6/2020
+# 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.
+#
+# Would be nice to make sure other features also work:
+# 5. can use absolute, relative, or current directory for output directory
+# 6. can use ~ in output directory path
+#
+# matrix of build combinations:
+# dimensions:
+# cwd: top-level, build-dir, tools/testing/selftests/<target>
+# change-dir: <none>, -C tools/testing/selftests (selftests)
+# make-target: <none>, kselftest-install, install
+# output-dir: <none>, KBUILD_OUTPUT-rel, KBUILD_OUTPUT-abs, O-rel, O-abs
+#
+# NOTE: you should not put your output directory inside your source directory
+# Parts of the kbuild system don't like this.
+#
+# The test matrix is not full:
+# <cwd>,<change-dir>,<make target>,<output-dir>
+# top, none, kselftest-install, none
+# top, none, kselftest-install, KBO-rel
+# 2 top, none, kselftest-install, KBO-abs
+# top, none, kselftest-install, O-rel
+# 1 top, none, kselftest-install, O-abs
+# top, selftests, none , none
+# top, selftests, none , KBO-rel
+# 3 top, selftests, none , KBO-abs
+# top, selftests, none , O-rel
+# 4 top, selftests, none , O-abs
+# build-dir, none, kselftest-install, none
+# build-dir, none, kselftest-install, KBO-rel
+# build-dir, none, kselftest-install, KBO-abs
+# build-dir, none, kselftest-install, O-rel
+# build-dir, none, kselftest-install, O-abs
+# build-dir, selftests, none, none
+# build-dir, selftests, none, KBO-rel
+# build-dir, selftests, none, KBO-abs
+# build-dir, selftests, none, kselftest-install, O-rel
+# build-dir, selftests, none, O-abs
+# 5 target, none, none, none
+# 6 target, none, install, none
+# target, none, none, KBO-rel
+# target, none, install, KBO-rel
+# target, none, none, KBO-abs
+# target, none, install, KBO-abs
+# target, none, none, O-rel
+# target, none, install, O-rel
+# target, none, none, O-abs
+# target, none, install, O-abs
+#
+# 1 = Shuah preferred test (top-level, kselftest-install, with O=)
+# 3 = Fuego (Tim's) default build style
+#
+# To do for this test:
+#
+
+usage() {
+ cat <<HERE
+Usage: ksft-compile-test.sh [-h|--help] [TARGETS="<targets>"] [<options>]
+
+compile_test.sh will test building selftest programs in the indicated
+target areas. The script tests various output-directory configurations.
+
+OPTIONS
+ -h, --help Show this usage help.
+ TARGETS="<targets>" Indicate the set of targets to test. <targets> is a
+ space-separated list of testing areas from
+ tools/testing/selftests/Makefile
+ O=<dir> Indicate a directory to use for output. Normally, the
+ program creates a temporary directory for testing, and
+ removes it when done. This sets -p, to avoid removing
+ the directory at the end of the test. Using O= with an
+ existing directory can save time (the kernel does not
+ need to be rebuilt). The directory must already exist.
+ -c <config-file> Specify a configuration file for the kernel.
+ If not specified, an appropriate defconfig will be used.
+ -p, --preserve Preserve files when this test completes.
+ If not specified, test will remove working files when
+ it completes.
+ -l <log-file> Specify the file to use for log output. All test output
+ goes to STDOUT (and STDERR) A subset of output
+ is placed in the logfile. If not specified, the
+ filename 'compile-test-log-<timestamp>.txt' is used.
+ -s, --summary Show summary of results at end of test.
+ -e <extra-data-file> Put contents of <extra-data-file> in the header of
+ the logfile (and in test output). This allows a CI
+ system to add additional information about the build
+ system, toolchain, etc. used for the test.
+ -C <kernel-src-dir> Use the indicated directory (instead of current
+ working directory) as the kernel source dir.
+
+ENVIRONMENT
+ Set ARCH and CROSS_COMPILE to values appropriate for your environment
+ (the same as for a Linux kernel image build)
+
+ You can use a TARGETS environment variable, instead of the TARGETS=
+ command line option.
+
+OUTPUT
+ Program output is in TAP13 format. The exit code indicates if the test was
+ 100% successful (SKIPS are counted as failures).
+HERE
+ exit 1
+}
+
+INDENT=3
+DEBUG=1
+
+dprint() {
+ if [ $DEBUG = 1 ] ; then
+ echo "$1"
+ fi
+}
+
+# parse command line options
+CONFIG_FILE=use_defconfig
+PRESERVE_FILES=0
+LOGFILE="$(pwd)/compile-test-log-$(date -Iseconds).txt"
+SHOW_SUMMARY=0
+SRC_TOP="$(realpath $(pwd))"
+
+while [ -n "$1" ] ; do
+ case $1 in
+ -h|--help)
+ usage
+ ;;
+ TARGETS=*)
+ TARGETS="${1#TARGETS=}"
+ export TARGETS
+ shift
+ ;;
+ O=*)
+ OUTPUT_DIR="${1#O=}"
+ shift
+ export OUTPUT_DIR
+ PRESERVE_FILES=1
+ if [ ! -d "$OUTPUT_DIR" ] ; then
+ echo "Error: output directory $OUTPUT_DIR does not exist"
+ echo "Use '-h' to get program usage"
+ exit 1
+ fi
+ ;;
+ -c)
+ CONFIG_FILE="$2"
+ shift 2
+ if [ ! -f ${CONFIG_FILE} ] ; then
+ echo "Error: Can't read specified config file $CONFIG_FILE"
+ echo "Use '-h' to get program usage"
+ exit 1
+ fi
+ ;;
+ -p|--preserve)
+ PRESERVE_FILES=1
+ shift
+ ;;
+ -l)
+ LOGFILE=="$2"
+ shift 2
+ if [ -z "$LOGFILE" ] ; then
+ echo "Error: No log-file specified with -l"
+ echo "Use '-h' to get program usage"
+ exit 1
+ fi
+ echo "Using logfile $LOGFILE"
+ ;;
+ -s|--summary)
+ SHOW_SUMMARY=1
+ shift
+ ;;
+ -e)
+ EXTRA_DATA_FILE="$2"
+ shift 2
+ if [ -z "$EXTRA_DATA_FILE" ] ; then
+ echo "Error: No <extra-data-file> specified with -e"
+ echo "Use '-h' to get program usage"
+ exit 1
+ fi
+ if [ ! -f "$EXTRA_DATA_FILE" ] ; then
+ echo "Error: Extra data file '$EXTRA_DATA_FILE' does not exist"
+ echo "Use '-h' to get program usage"
+ exit 1
+ fi
+ echo "Using extra data file $EXTRA_DATA_FILE"
+ ;;
+ -C)
+ SRC_TOP="$(realpath $2)"
+ shift 2
+ if [ ! -d $SRC_TOP ] ; then
+ echo "Error: Kernel source dir '$SRC_TOP' does not exist"
+ echo "Use '-h' to get program usage"
+ exit 1
+ fi
+ if [ ! -f "$SRC_TOP/MAINTAINERS" ] ; then
+ echo "Error: $SRC_TOP doesn't seem to be a kernel source tree."
+ echo "Missing MAINTAINERS file."
+ exit 1
+ fi
+ echo "Using kernel source tree: $SRC_TOP"
+ cd $SRC_TOP
+ ;;
+ *)
+ echo "Error: Unknown option '$1'"
+ echo "Use '-h' to get program usage"
+ exit 1
+ ;;
+ esac
+done
+
+# for debugging option parsing
+dprint "TARGETS=$TARGETS"
+dprint "CONFIG_FILE=$CONFIG_FILE"
+dprint "LOGFILE=$LOGFILE"
+dprint "PRESERVE_FILES=$PRESERVE_FILES"
+dprint "OUTPUT_DIR=$OUTPUT_DIR"
+dprint "SRC_TOP=$SRC_TOP"
+
+#### logging routines
+# log_msg - put a single-line message in the logfile (and STDOUT)
+log_msg() {
+ echo "$1" | tee -a $LOGFILE
+}
+
+# log_result - put TAP-syntax prefix and description to logfile
+# $1 = result to log
+# $2 = result description (usually "$test_id", but may include SKIP)
+# Uses global TEST_NUM
+log_result() {
+ if [ $1 = 0 ] ; then
+ log_msg "ok $TEST_NUM $2"
+ else
+ log_msg "not ok $TEST_NUM $2"
+ fi
+}
+
+# log_cmd - put output of command into logfile
+# $1 - command to execute
+log_cmd() {
+ RETCODE=/tmp/$$-${RANDOM}
+ touch $RETCODE
+ bash -c "{ $1; echo \$? >$RETCODE ; } 2>&1 | tee -a $LOGFILE"
+ RESULT=$(cat $RETCODE)
+ rm -f $RETCODE
+ return $RESULT
+}
+
+# log_cmd_indented - put output of command into logfile, indented by INDENT
+# $1 - command to execute
+# Uses global INDENT
+log_cmd_indented() {
+ RETCODE=/tmp/$$-${RANDOM}
+ TMPOUT=/tmp/$$-${RANDOM}
+ touch $RETCODE
+ bash -c "{ $1; echo \$? >$RETCODE ; } 2>&1 | tee -a $TMPOUT"
+ RESULT=$(cat $RETCODE)
+
+ # could use sed here instead of pr, if needed
+ cat $TMPOUT | pr -to $INDENT >>$LOGFILE
+
+ rm -f $RETCODE $TMPOUT
+ return $RESULT
+}
+
+# do some sanity checks before we get started
+test_pre_check() {
+ # are we in the top directory of a kernel source tree?
+ if [ ! -f "MAINTAINERS" ] ; then
+ echo "Error: We're not in a kernel source tree (no MAINTAINERS file)"
+ echo "Use '-h' to get program usage"
+ exit 1
+ fi
+
+ if [ -z $ARCH ] ; then
+ ARCH_ARGS=""
+ else
+ ARCH_ARGS="ARCH=$ARCH"
+ fi
+ export ARCH_ARGS
+
+ if [ -z "$CROSS_COMPILE" -a -n "$ARCH_ARGS" ] ; then
+ echo "Warning: no CROSS_COMPILE prefix defined, but ARCH $ARCH specified"
+ echo "Usually, if you specify an ARCH you need to specify CROSS_COMPILE"
+ echo "Use '-h' to get program usage"
+ fi
+}
+
+# prepare for tests
+# on completion, following should be set:
+# INDENT, TARGET_LIST, NUM_MAKE_JOBS, KBUILD_DIR_REL, KBUILD_DIR_ABS
+# Uses: ARCH
+test_setup() {
+ echo "In test setup"
+
+ # read target list from test variable, if defined
+ if [ -n "${TARGETS}" ] ; then
+ TARGET_LIST="${TARGETS}"
+ else
+ # use hardcoded kselftest target list for now
+ TARGET_LIST="android arm64 bpf breakpoints capabilities cgroup \
+ clone3 cpufreq cpu-hotplug drivers/dma-buf efivarfs exec \
+ filesystems filesystems/binderfs filesystems/epoll firmware \
+ ftrace futex gpio intel_pstate ipc ir kcmp kexec kvm lib \
+ livepatch lkdtm membarrier memfd memory-hotplug mount mqueue \
+ net net/mptcp netfilter networking/timestamping nsfs pidfd \
+ powerpc proc pstore ptrace openat2 rseq rtc seccomp sigaltstack \
+ size sparc64 splice static_keys sync sysctl timens timers tmpfs \
+ tpm2 user vm x86 zram"
+ # FIXTHIS - query kernel for kselftest full target list
+ #TARGET_LIST=$(make --no-print-directory -s \
+ # -C tools/testing/selftests show_targets)
+ fi
+
+ # get number of parallel jobs to start in make
+ proc_count=$(cat /proc/cpuinfo | grep processor | wc -l)
+ NUM_MAKE_JOBS=$(( proc_count / 2 ))
+ if [ $NUM_MAKE_JOBS -lt 1 ] ; then
+ NUM_MAKE_JOBS=1
+ fi
+
+ if [ -z "$OUTPUT_DIR" ] ; then
+ # make output dir
+ tmp1=$(mktemp -d ../ksft-XXXXXX)
+ export KBUILD_DIR_REL="$tmp1"
+ export KBUILD_DIR_ABS=$(realpath $tmp1)
+ else
+ export KBUILD_DIR_REL=$(realpath --relative-to=$(pwd) $OUTPUT_DIR)
+ export KBUILD_DIR_ABS=$(realpath $OUTPUT_DIR)
+ fi
+ mkdir -p $KBUILD_DIR_ABS
+
+ # for setup, use KBUILD_OUTPUT environment var for output dir
+ KBUILD_OUTPUT=$KBUILD_DIR_ABS
+
+ if [ $CONFIG_FILE = "use_defconfig" ] ; then
+ make $ARCH_ARGS defconfig
+ else
+ cp $CONFIG_FILE $KBUILD_OUTPUT/.config
+ fi
+ make $ARCH_ARGS oldconfig
+
+ # this should only be needed once
+ make $ARCH_ARGS -j $NUM_MAKE_JOBS headers_install
+
+ make $ARCH_ARGS -j $NUM_MAKE_JOBS vmlinux
+}
+
+#
+# $1 = KBUILD_DIR
+# $2 = target
+check_output_dir() {
+ install_result=0
+ log_msg "# Contents of kselftest_install directory:"
+ if [ -d $1/kselftest/kselftest_install ] ; then
+ pushd $1/kselftest/kselftest_install >/dev/null
+
+ log_cmd_indented "ls -lR"
+ log_msg "# File types:"
+ log_cmd_indented "find . -type f | xargs file -n | \
+ sed \"s/BuildID.*, //\""
+
+ # check that run scripts has the target
+ if ! grep "^cd $2" run_kselftest.sh 2>&1 >/dev/null ; then
+ log_mesg "# Missing target $2 in run_kselftest.sh"
+ install_result=1
+ fi
+
+ popd >/dev/null
+ else
+ log_msg "# Missing $KBUILD_OUTPUT/kselftest/kselftest_install directory"
+ install_result=1
+ fi
+ return $install_result
+}
+
+# do_test - perform one test combination
+# $1 = method (string for use in test_id)
+# $2 = target
+# $3 = compile args
+# $4 = install args (if any)
+# $5 = clean args
+#
+# Uses: ARCH_ARGS, KBUILD_DIR and LOGFILE (indirectly), and SRC_TOP
+# Uses and sets: TEST_NUM
+#
+do_test() {
+ method=$1
+ target=$2
+ COMPILE_ARGS=$3
+ INSTALL_ARGS=$4
+ CLEAN_ARGS=$4
+
+ TARGET_DIR=$SRC_TOP/tools/testing/selftests/$target
+
+ SRC_LS_FILE1="$(mktemp)"
+ SRC_LS_FILE2="$(mktemp)"
+ ls -lR $TARGET_DIR >$SRC_LS_FILE1
+
+ test_id="$target compile $method"
+ TEST_NUM=$(( TEST_NUM + 1 ))
+ log_msg "# $TEST_NUM $test_id"
+
+ # do the compile
+ log_cmd_indented "make $ARCH_ARGS TARGETS=\"$target\" $COMPILE_ARGS"
+ compile_result=$?
+
+ log_result $compile_result "$test_id"
+
+ # check that nothing changed in the src directory
+ test_id="$target src tree clean after compile $method"
+ TEST_NUM=$(( TEST_NUM + 1 ))
+ log_msg "# $TEST_NUM $test_id"
+
+ ls -lR $TARGET_DIR >$SRC_LS_FILE2
+ log_cmd_indented "diff -u $SRC_LS_FILE1 $SRC_LS_FILE2"
+ src_clean_result=$?
+
+ if [ $src_clean_result != 0 ] ; then
+ log_msg "# File or directory changes found in $TARGET_DIR"
+ fi
+
+ log_result $src_clean_result "$test_id"
+ rm $SRC_LS_FILE1
+ rm $SRC_LS_FILE2
+
+ test_id="$target install $method"
+ TEST_NUM=$(( TEST_NUM + 1 ))
+ log_msg "# $TEST_NUM $test_id"
+
+ if [ -n "INSTALL_ARGS" ] ; then
+ # skip the install test if it didn't compile
+ if [ $compile_result != 0 ] ; then
+ install_result=$compile_result
+ reason="compile failed"
+ log_result $install_result "$test_id # SKIP - $reason"
+
+ else
+ # now do install
+ log_cmd_indented "make $ARCH_ARGS TARGETS=\"$target\" $INSTALL_ARGS"
+ install_result=$?
+ log_result $install_result "$test_id"
+ fi
+ else
+ install_result=$compile_result
+ log_result $install_result "$test_id"
+ fi
+
+ test_id="$target check install output $method"
+ TEST_NUM=$(( TEST_NUM + 1 ))
+ log_msg "# $TEST_NUM $test_id"
+
+ # check results
+ if [ $install_result = 0 ] ; then
+ check_output_dir $KBUILD_DIR $target
+ install_output_result=$?
+ log_result $install_output_result "$test_id"
+ else
+ log_result $install_result "$test_id # SKIP - install failed"
+ fi
+
+ # clean up after test
+ make $ARCH_ARGS TARGETS=\"$target\" $CLEAN_ARGS
+
+ # clear out install directory for next test
+ rm -rf $KBUILD_DIR/kselftest/kselftest_install
+ mkdir -p $KBUILD_DIR/kselftest/kselftest_install
+}
+
+test_run() {
+ export KBUILD_DIR=$KBUILD_DIR_ABS
+ NUM_SCENARIOS=3
+ TESTS_PER_SCENARIO=4
+
+ # output the header
+ log_msg "ARCH=$ARCH"
+ log_msg "CROSS_COMPILE=$CROSS_COMPILE"
+ if [ -f "$EXTRA_DATA_FILE" ] ; then
+ log_msg "=== Test Details ==="
+ log_cmd "cat $EXTRA_DATA_FILE"
+ log_msg "==="
+ fi
+ log_msg "TAP VERSION 13"
+
+ target_count=$(echo $TARGET_LIST | wc -w)
+ export test_count=$(( target_count * $NUM_SCENARIOS * $TESTS_PER_SCENARIO ))
+ log_msg "1..$test_count"
+
+ # disable 'stop-on-error'
+ set +e
+
+ export TEST_NUM=0
+ for target in $TARGET_LIST ; do
+ echo "########## Doing tests for target $target ##########"
+
+ # clean out directory to force a re-build
+ make $ARCH_ARGS TARGETS=\"$target\" -C tools/testing/selftests clean
+
+ ### MATRIX SCENARIO: KBUILD_OUTPUT,-C
+ export KBUILD_OUTPUT="$KBUILD_DIR"
+ method="KBUILD_OUTPUT,-C"
+ COMPILE_ARGS="-C tools/testing/selftests"
+ INSTALL_ARGS="$COMPILE_ARGS install"
+ CLEAN_ARGS="$COMPILE_ARGS clean"
+ do_test "$method" $target "$COMPILE_ARGS" "$INSTALL_ARGS" "$CLEAN_ARGS"
+
+ ### MATRIX SCENARIO: O,-C
+ unset KBUILD_OUTPUT
+ O_TMP="$KBUILD_DIR"
+ method="O,-C"
+ COMPILE_ARGS="-C tools/testing/selftests O=$O_TMP"
+ INSTALL_ARGS="$COMPILE_ARGS install"
+ CLEAN_ARGS="$COMPILE_ARGS clean"
+ do_test "$method" $target "$COMPILE_ARGS" "$INSTALL_ARGS" "$CLEAN_ARGS"
+
+ ### MATRIX SCENARIO: O,top
+ method="O,top"
+ COMPILE_ARGS="O=$O_TMP kselftest-install"
+ INSTALL_ARGS=""
+ CLEAN_ARGS="O=$O_TMP kselftest-clean"
+ do_test "$method" $target "$COMPILE_ARGS" "$INSTALL_ARGS" "$CLEAN_ARGS"
+
+ done
+ set -e
+}
+
+test_cleanup() {
+ echo "In test cleanup"
+ if [ -z "$OUTPUT_DIR" ] ; then
+ if [ "$PRESERVE_FILES" = 0 ] ; then
+ rm -rf $KBUILD_DIR_ABS
+ else
+ echo "Build data was left in directory $KBUILD_DIR_ABS"
+ fi
+ else
+ echo "Not removing files in user-specified output dir $OUTPUT_DIR"
+ fi
+}
+
+# this is main()
+test_pre_check
+test_setup
+dprint "TARGET_LIST=$TARGET_LIST"
+test_run
+test_cleanup
+
+echo "Done. Log file is in $LOGFILE"
+
+if [ "$SHOW_SUMMARY" = 1 ] ; then
+ ok_count=$(grep ^ok $LOGFILE | wc -l)
+ fail_count=$(grep "^not ok" $LOGFILE | grep -v SKIP | wc -l)
+ skip_count=$(grep "^not ok" $LOGFILE | grep SKIP | wc -l)
+ total=$(( ok_count + fail_count + skip_count ))
+ echo "OK: $ok_count, FAIL: $fail_count, SKIP: $skip_count, TOTAL: $total"
+fi
--
2.1.4
This series introduces a new KVM selftest (mem_slot_test) that goal
is to verify memory slots can be added up to the maximum allowed. An
extra slot is attempted which should occur on error.
The patch 01 is needed so that the VM fd can be accessed from the
test code (for the ioctl call attempting to add an extra slot).
I ran the test successfully on x86_64, aarch64, and s390x. This
is why it is enabled to build on those arches.
- Changelog -
v4 -> v5:
- Initialize the guest_addr and mem_reg_size variables on definition
[krish.sadhukhan]
v3 -> v4:
- Discarded mem_reg_flags variable. Simply using 0 instead [drjones]
- Discarded kvm_region pointer. Instead passing a compound literal in
the ioctl [drjones]
- All variables are declared on the declaration block [drjones]
v2 -> v3:
- Keep alphabetical order of .gitignore and Makefile [drjones]
- Use memory region flags equals to zero [drjones]
- Changed mmap() assert from 'mem != NULL' to 'mem != MAP_FAILED' [drjones]
- kvm_region is declared along side other variables and malloc()'ed
later [drjones]
- Combined two asserts into a single 'ret == -1 && errno == EINVAL'
[drjones]
v1 -> v2:
- Rebased to queue
- vm_get_fd() returns int instead of unsigned int (patch 01) [drjones]
- Removed MEM_REG_FLAGS and GUEST_VM_MODE defines [drjones]
- Replaced DEBUG() with pr_info() [drjones]
- Calculate number of guest pages with vm_calc_num_guest_pages()
[drjones]
- Using memory region of 1 MB sized (matches mininum needed
for s390x)
- Removed the increment of guest_addr after the loop [drjones]
- Added assert for the errno when adding a slot beyond-the-limit [drjones]
- Prefer KVM_MEM_READONLY flag but on s390x it switch to KVM_MEM_LOG_DIRTY_PAGES,
so ensure the coverage of both flags. Also somewhat tests the KVM_CAP_READONLY_MEM capability check [drjones]
- Moved the test logic to test_add_max_slots(), this allows to more easily add new cases in the "suite".
v1: https://lore.kernel.org/kvm/20200330204310.21736-1-wainersm@redhat.com
Wainer dos Santos Moschetta (2):
selftests: kvm: Add vm_get_fd() in kvm_util
selftests: kvm: Add mem_slot_test test
tools/testing/selftests/kvm/.gitignore | 1 +
tools/testing/selftests/kvm/Makefile | 3 +
.../testing/selftests/kvm/include/kvm_util.h | 1 +
tools/testing/selftests/kvm/lib/kvm_util.c | 5 ++
tools/testing/selftests/kvm/mem_slot_test.c | 69 +++++++++++++++++++
5 files changed, 79 insertions(+)
create mode 100644 tools/testing/selftests/kvm/mem_slot_test.c
--
2.17.2
After successfully running the IPC msgque test once, subsequent runs
result in a test failure:
$ sudo ./run_kselftest.sh
TAP version 13
1..1
# selftests: ipc: msgque
# Failed to get stats for IPC queue with id 0
# Failed to dump queue: -22
# Bail out!
# # Pass 0 Fail 0 Xfail 0 Xpass 0 Skip 0 Error 0
not ok 1 selftests: ipc: msgque # exit=1
The dump_queue() function loops through the possible message queue index
values using calls to msgctl(kern_id, MSG_STAT, ...) where kern_id
represents the index value. The first time the test is ran, the initial
index value of 0 is valid and the test is able to complete. The index
value of 0 is not valid in subsequent test runs and the loop attempts to
try index values of 1, 2, 3, and so on until a valid index value is
found that corresponds to the message queue created earlier in the test.
The msgctl() syscall returns -1 and sets errno to EINVAL when invalid
index values are used. The test failure is caused by incorrectly
comparing errno to -EINVAL when cycling through possible index values.
Fix invalid test failures on subsequent runs of the msgque test by
correctly comparing errno values to a non-negated EINVAL.
Fixes: 3a665531a3b7 ("selftests: IPC message queue copy feature test")
Signed-off-by: Tyler Hicks <tyhicks(a)linux.microsoft.com>
---
tools/testing/selftests/ipc/msgque.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/ipc/msgque.c b/tools/testing/selftests/ipc/msgque.c
index 4c156aeab6b8..5ec4d9e18806 100644
--- a/tools/testing/selftests/ipc/msgque.c
+++ b/tools/testing/selftests/ipc/msgque.c
@@ -137,7 +137,7 @@ int dump_queue(struct msgque_data *msgque)
for (kern_id = 0; kern_id < 256; kern_id++) {
ret = msgctl(kern_id, MSG_STAT, &ds);
if (ret < 0) {
- if (errno == -EINVAL)
+ if (errno == EINVAL)
continue;
printf("Failed to get stats for IPC queue with id %d\n",
kern_id);
--
2.17.1