Add new feature checks related to crypto to the hwcap test.
The following is a log snippet from my local testing environment
based on for-next/selftests:
~~~
TAP version 13
1..111
# AES present
ok 1 cpuinfo_match_AES
ok 2 sigill_AES
ok 3 # SKIP sigbus_AES
# CRC32 present
ok 4 cpuinfo_match_CRC32
ok 5 sigill_CRC32
ok 6 # SKIP sigbus_CRC32
ok 7 cpuinfo_match_CSSC
# sigill_reported for CSSC
ok 8 # SKIP sigill_CSSC
ok 9 # SKIP sigbus_CSSC
# FP present
ok 10 cpuinfo_match_FP
ok 11 sigill_FP
ok 12 # SKIP sigbus_FP
# JSCVT present
ok 13 cpuinfo_match_JSCVT
ok 14 sigill_JSCVT
ok 15 # SKIP sigbus_JSCVT
# LRCPC present
ok 16 cpuinfo_match_LRCPC
ok 17 sigill_LRCPC
ok 18 # SKIP sigbus_LRCPC
# LRCPC2 present
ok 19 cpuinfo_match_LRCPC2
ok 20 sigill_LRCPC2
ok 21 # SKIP sigbus_LRCPC2
# LSE present
ok 22 cpuinfo_match_LSE
ok 23 sigill_LSE
ok 24 # SKIP sigbus_LSE
# LSE2 present
ok 25 cpuinfo_match_LSE2
ok 26 sigill_LSE2
ok 27 sigbus_LSE2
ok 28 cpuinfo_match_MOPS
ok 29 sigill_MOPS
ok 30 # SKIP sigbus_MOPS
# RNG present
ok 31 cpuinfo_match_RNG
ok 32 sigill_RNG
ok 33 # SKIP sigbus_RNG
# PMULL present
ok 34 cpuinfo_match_PMULL
ok 35 sigill_PMULL
ok 36 # SKIP sigbus_PMULL
ok 37 cpuinfo_match_RPRFM
ok 38 # SKIP sigill_RPRFM
ok 39 # SKIP sigbus_RPRFM
# SHA1 present
ok 40 cpuinfo_match_SHA1
ok 41 sigill_SHA1
ok 42 # SKIP sigbus_SHA1
# SHA2 present
ok 43 cpuinfo_match_SHA2
ok 44 sigill_SHA2
ok 45 # SKIP sigbus_SHA2
# SHA512 present
ok 46 cpuinfo_match_SHA512
ok 47 sigill_SHA512
ok 48 # SKIP sigbus_SHA512
ok 49 cpuinfo_match_SME
ok 50 sigill_SME
ok 51 # SKIP sigbus_SME
ok 52 cpuinfo_match_SME2
ok 53 sigill_SME2
ok 54 # SKIP sigbus_SME2
ok 55 cpuinfo_match_SME 2.1
# sigill_reported for SME 2.1
ok 56 # SKIP sigill_SME 2.1
ok 57 # SKIP sigbus_SME 2.1
ok 58 cpuinfo_match_SME I16I32
# sigill_reported for SME I16I32
ok 59 # SKIP sigill_SME I16I32
ok 60 # SKIP sigbus_SME I16I32
ok 61 cpuinfo_match_SME BI32I32
# sigill_reported for SME BI32I32
ok 62 # SKIP sigill_SME BI32I32
ok 63 # SKIP sigbus_SME BI32I32
ok 64 cpuinfo_match_SME B16B16
# sigill_reported for SME B16B16
ok 65 # SKIP sigill_SME B16B16
ok 66 # SKIP sigbus_SME B16B16
ok 67 cpuinfo_match_SME F16F16
# sigill_reported for SME F16F16
ok 68 # SKIP sigill_SME F16F16
ok 69 # SKIP sigbus_SME F16F16
# SVE present
ok 70 cpuinfo_match_SVE
ok 71 sigill_SVE
ok 72 # SKIP sigbus_SVE
ok 73 cpuinfo_match_SVE 2
# sigill_reported for SVE 2
ok 74 # SKIP sigill_SVE 2
ok 75 # SKIP sigbus_SVE 2
ok 76 cpuinfo_match_SVE 2.1
# sigill_reported for SVE 2.1
ok 77 # SKIP sigill_SVE 2.1
ok 78 # SKIP sigbus_SVE 2.1
ok 79 cpuinfo_match_SVE AES
# sigill_reported for SVE AES
ok 80 # SKIP sigill_SVE AES
ok 81 # SKIP sigbus_SVE AES
ok 82 cpuinfo_match_SVE2 PMULL
# sigill_reported for SVE2 PMULL
ok 83 # SKIP sigill_SVE2 PMULL
ok 84 # SKIP sigbus_SVE2 PMULL
ok 85 cpuinfo_match_SVE2 BITPERM
# sigill_reported for SVE2 BITPERM
ok 86 # SKIP sigill_SVE2 BITPERM
ok 87 # SKIP sigbus_SVE2 BITPERM
ok 88 cpuinfo_match_SVE2 SHA3
# sigill_reported for SVE2 SHA3
ok 89 # SKIP sigill_SVE2 SHA3
ok 90 # SKIP sigbus_SVE2 SHA3
ok 91 cpuinfo_match_SVE2 SM4
# sigill_reported for SVE2 SM4
ok 92 # SKIP sigill_SVE2 SM4
ok 93 # SKIP sigbus_SVE2 SM4
# SVE2 I8MM present
ok 94 cpuinfo_match_SVE2 I8MM
ok 95 sigill_SVE2 I8MM
ok 96 # SKIP sigbus_SVE2 I8MM
# SVE2 F32MM present
ok 97 cpuinfo_match_SVE2 F32MM
ok 98 sigill_SVE2 F32MM
ok 99 # SKIP sigbus_SVE2 F32MM
# SVE2 F64MM present
ok 100 cpuinfo_match_SVE2 F64MM
ok 101 sigill_SVE2 F64MM
ok 102 # SKIP sigbus_SVE2 F64MM
# SVE2 BF16 present
ok 103 cpuinfo_match_SVE2 BF16
ok 104 sigill_SVE2 BF16
ok 105 # SKIP sigbus_SVE2 BF16
ok 106 cpuinfo_match_SVE2 EBF16
ok 107 # SKIP sigill_SVE2 EBF16
ok 108 # SKIP sigbus_SVE2 EBF16
ok 109 cpuinfo_match_HBC
ok 110 sigill_HBC
ok 111 # SKIP sigbus_HBC
# Totals: pass:60 fail:0 xfail:0 xpass:0 skip:51 error:0
~~~
Zeng Heng (4):
kselftest/arm64: add SHA1 and related features to hwcap test
kselftest/arm64: add AES feature check to hwcap test
kselftest/arm64: add pmull feature to hwcap test
kselftest/arm64: add jscvt feature to hwcap test
tools/testing/selftests/arm64/abi/hwcap.c | 77 +++++++++++++++++++++++
1 file changed, 77 insertions(+)
--
2.25.1
Add new feature checks related to crypto to the hwcap test.
The following is a log snippet from my local testing environment
based on for-next/selftests:
~~~
TAP version 13
1..111
# AES present
ok 1 cpuinfo_match_AES
ok 2 sigill_AES
ok 3 # SKIP sigbus_AES
# CRC32 present
ok 4 cpuinfo_match_CRC32
ok 5 sigill_CRC32
ok 6 # SKIP sigbus_CRC32
ok 7 cpuinfo_match_CSSC
# sigill_reported for CSSC
ok 8 # SKIP sigill_CSSC
ok 9 # SKIP sigbus_CSSC
# FP present
ok 10 cpuinfo_match_FP
ok 11 sigill_FP
ok 12 # SKIP sigbus_FP
# JSCVT present
ok 13 cpuinfo_match_JSCVT
ok 14 sigill_JSCVT
ok 15 # SKIP sigbus_JSCVT
# LRCPC present
ok 16 cpuinfo_match_LRCPC
ok 17 sigill_LRCPC
ok 18 # SKIP sigbus_LRCPC
# LRCPC2 present
ok 19 cpuinfo_match_LRCPC2
ok 20 sigill_LRCPC2
ok 21 # SKIP sigbus_LRCPC2
# LSE present
ok 22 cpuinfo_match_LSE
ok 23 sigill_LSE
ok 24 # SKIP sigbus_LSE
# LSE2 present
ok 25 cpuinfo_match_LSE2
ok 26 sigill_LSE2
ok 27 sigbus_LSE2
ok 28 cpuinfo_match_MOPS
ok 29 sigill_MOPS
ok 30 # SKIP sigbus_MOPS
# RNG present
ok 31 cpuinfo_match_RNG
ok 32 sigill_RNG
ok 33 # SKIP sigbus_RNG
# PMULL present
ok 34 cpuinfo_match_PMULL
ok 35 sigill_PMULL
ok 36 # SKIP sigbus_PMULL
ok 37 cpuinfo_match_RPRFM
ok 38 # SKIP sigill_RPRFM
ok 39 # SKIP sigbus_RPRFM
# SHA1 present
ok 40 cpuinfo_match_SHA1
ok 41 sigill_SHA1
ok 42 # SKIP sigbus_SHA1
# SHA2 present
ok 43 cpuinfo_match_SHA2
ok 44 sigill_SHA2
ok 45 # SKIP sigbus_SHA2
# SHA512 present
ok 46 cpuinfo_match_SHA512
ok 47 sigill_SHA512
ok 48 # SKIP sigbus_SHA512
ok 49 cpuinfo_match_SME
ok 50 sigill_SME
ok 51 # SKIP sigbus_SME
ok 52 cpuinfo_match_SME2
ok 53 sigill_SME2
ok 54 # SKIP sigbus_SME2
ok 55 cpuinfo_match_SME 2.1
# sigill_reported for SME 2.1
ok 56 # SKIP sigill_SME 2.1
ok 57 # SKIP sigbus_SME 2.1
ok 58 cpuinfo_match_SME I16I32
# sigill_reported for SME I16I32
ok 59 # SKIP sigill_SME I16I32
ok 60 # SKIP sigbus_SME I16I32
ok 61 cpuinfo_match_SME BI32I32
# sigill_reported for SME BI32I32
ok 62 # SKIP sigill_SME BI32I32
ok 63 # SKIP sigbus_SME BI32I32
ok 64 cpuinfo_match_SME B16B16
# sigill_reported for SME B16B16
ok 65 # SKIP sigill_SME B16B16
ok 66 # SKIP sigbus_SME B16B16
ok 67 cpuinfo_match_SME F16F16
# sigill_reported for SME F16F16
ok 68 # SKIP sigill_SME F16F16
ok 69 # SKIP sigbus_SME F16F16
# SVE present
ok 70 cpuinfo_match_SVE
ok 71 sigill_SVE
ok 72 # SKIP sigbus_SVE
ok 73 cpuinfo_match_SVE 2
# sigill_reported for SVE 2
ok 74 # SKIP sigill_SVE 2
ok 75 # SKIP sigbus_SVE 2
ok 76 cpuinfo_match_SVE 2.1
# sigill_reported for SVE 2.1
ok 77 # SKIP sigill_SVE 2.1
ok 78 # SKIP sigbus_SVE 2.1
ok 79 cpuinfo_match_SVE AES
# sigill_reported for SVE AES
ok 80 # SKIP sigill_SVE AES
ok 81 # SKIP sigbus_SVE AES
ok 82 cpuinfo_match_SVE2 PMULL
# sigill_reported for SVE2 PMULL
ok 83 # SKIP sigill_SVE2 PMULL
ok 84 # SKIP sigbus_SVE2 PMULL
ok 85 cpuinfo_match_SVE2 BITPERM
# sigill_reported for SVE2 BITPERM
ok 86 # SKIP sigill_SVE2 BITPERM
ok 87 # SKIP sigbus_SVE2 BITPERM
ok 88 cpuinfo_match_SVE2 SHA3
# sigill_reported for SVE2 SHA3
ok 89 # SKIP sigill_SVE2 SHA3
ok 90 # SKIP sigbus_SVE2 SHA3
ok 91 cpuinfo_match_SVE2 SM4
# sigill_reported for SVE2 SM4
ok 92 # SKIP sigill_SVE2 SM4
ok 93 # SKIP sigbus_SVE2 SM4
# SVE2 I8MM present
ok 94 cpuinfo_match_SVE2 I8MM
ok 95 sigill_SVE2 I8MM
ok 96 # SKIP sigbus_SVE2 I8MM
# SVE2 F32MM present
ok 97 cpuinfo_match_SVE2 F32MM
ok 98 sigill_SVE2 F32MM
ok 99 # SKIP sigbus_SVE2 F32MM
# SVE2 F64MM present
ok 100 cpuinfo_match_SVE2 F64MM
ok 101 sigill_SVE2 F64MM
ok 102 # SKIP sigbus_SVE2 F64MM
# SVE2 BF16 present
ok 103 cpuinfo_match_SVE2 BF16
ok 104 sigill_SVE2 BF16
ok 105 # SKIP sigbus_SVE2 BF16
ok 106 cpuinfo_match_SVE2 EBF16
ok 107 # SKIP sigill_SVE2 EBF16
ok 108 # SKIP sigbus_SVE2 EBF16
ok 109 cpuinfo_match_HBC
ok 110 sigill_HBC
ok 111 # SKIP sigbus_HBC
# Totals: pass:60 fail:0 xfail:0 xpass:0 skip:51 error:0
~~~
Zeng Heng (4):
kselftest/arm64: add SHA1 and related features to hwcap test
kselftest/arm64: add AES feature check to hwcap test
kselftest/arm64: add pmull feature to hwcap test
kselftest/arm64: add jscvt feature to hwcap test
tools/testing/selftests/arm64/abi/hwcap.c | 77 +++++++++++++++++++++++
1 file changed, 77 insertions(+)
--
2.25.1
Hi,
Can anyone give some hints on how to run a single test on the kselftest
framework? The reason that I want such support is because I have to run
test cases inside emulator, which is very slow.
Per the kselftest documents, I can run kvm selftests with "make
-C tools/testing/selftests TARGETS=kvm run_tests", but it does not provide
a mechanism to run a single test in KVM subsystem. It takes a very long
time to finish the KVM subset testing inside the slow emulator while I'm
only trying to replace/add one testcase.
Currently I modify the code like below, to run only a single test. Not
sure if there is a more generic way to do that. If no such mechanism and
there are more people have similar need, is it possible to add it? I'm more
than happy to contribute with guide.
Thank you
--jyh
diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index c692cc86e7da..25fce1a3ceb8 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -56,7 +56,7 @@ LIBKVM_riscv += lib/riscv/processor.c
LIBKVM_riscv += lib/riscv/ucall.c
# Non-compiled test targets
-TEST_PROGS_x86_64 += x86_64/nx_huge_pages_test.sh
+#TEST_PROGS_x86_64 += x86_64/nx_huge_pages_test.sh
# Compiled test targets
TEST_GEN_PROGS_x86_64 = x86_64/cpuid_test
@@ -135,7 +135,7 @@ TEST_GEN_PROGS_x86_64 += kvm_binary_stats_test
TEST_GEN_PROGS_x86_64 += system_counter_offset_test
# Compiled outputs used by test targets
-TEST_GEN_PROGS_EXTENDED_x86_64 += x86_64/nx_huge_pages_test
+#TEST_GEN_PROGS_EXTENDED_x86_64 += x86_64/nx_huge_pages_test
TEST_GEN_PROGS_aarch64 += aarch64/aarch32_id_regs
TEST_GEN_PROGS_aarch64 += aarch64/arch_timer
@@ -186,6 +186,8 @@ TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(ARCH_DIR))
TEST_GEN_PROGS_EXTENDED += $(TEST_GEN_PROGS_EXTENDED_$(ARCH_DIR))
LIBKVM += $(LIBKVM_$(ARCH_DIR))
+TEST_GEN_PROGS = x86_64/cr4_cpuid_sync_test
+
OVERRIDE_TARGETS = 1
# lib.mak defines $(OUTPUT), prepends $(OUTPUT)/ to $(TEST_GEN_PROGS), and most
As reported and suggested by Willy, the inline __sysret() helper
introduces three types of conversions and increases the size:
(1) the "unsigned long" argument to __sysret() forces a sign extension
from all sys_* functions that used to return 'int'
(2) the comparison with the error range now has to be performed on a
'unsigned long' instead of an 'int'
(3) the return value from __sysret() is a 'long' (note, a signed long)
which then has to be turned back to an 'int' before being returned by the
caller to satisfy the caller's prototype.
To fix up this, firstly, let's use macro instead of inline function to
preserves the input type and avoids these useless conversions (1), (3).
Secondly, comparison to -MAX_ERRNO inflicts on all integer returns where
we could previously keep a simple sign comparison, let's use a new
__is_pointer() macro suggested by David Laight to limit the comparison
to -MAX_ERRNO (2) only for pointer returns and preserve a simple sign
comparison for integer returns as before. The __builtin_choose_expr()
is suggested by David Laight to choose different comparisons based on
the types to share code.
Thirdly, fix up the following warning by an explicit conversion and let
__sysret() be able to accept the (void *) type of argument:
sysroot/powerpc/include/sys.h: In function 'sbrk':
sysroot/powerpc/include/sys.h:104:16: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
104 | return (void *)__sysret(-ENOMEM);
Fourthly, to further workaround the argument type with 'const' flag,
must use __auto_type for gcc >= 11.0 and __typeof__((arg) + 0) suggested
by David Laight for old gcc versions.
Suggested-by: Willy Tarreau <w(a)1wt.eu>
Link: https://lore.kernel.org/lkml/20230806095846.GB10627@1wt.eu/
Link: https://lore.kernel.org/lkml/20230806134348.GA19145@1wt.eu/
Suggested-by: David Laight <David.Laight(a)ACULAB.COM>
Link: https://lore.kernel.org/lkml/f51e54bcf470451ea36f24640f000e61@AcuMS.aculab.…
Link: https://lore.kernel.org/lkml/a1732bbffd1542d3b9dd34c92f45076c@AcuMS.aculab.…
Signed-off-by: Zhangjin Wu <falcon(a)tinylab.org>
---
Hi, Willy, Hi, David
v5 applies suggestions from David Laight, it further drops the fixed
'long' conversion branch by using a __typeof__((arg) + 0) trick and also
merges the pointer type and integer type comparisons with
__bultin_choose_expr() and a new __is_pointer() macro, now, the code is
cleaner than before versions.
David, Thanks a lot!
Like before, tests run for all nolibc supported boards.
Changes from v4 --> v5:
* Use __typeof__((arg) + 0) to lose the 'const' flag for old gcc
versions.
* Import the famous __is_constexpr() macro from kernel side and add a
__is_pointer() macro based on it. (David, to avoid introduce extra
discuss on the prove-in-use __is_constexpr macro, this patch uses the
original version instead of your suggested version, more info here:
https://lore.kernel.org/lkml/20220131204357.1133674-1-keescook@chromium.org/)
* Use __builtin_choose_expr() to merge two comparisons to share the same
errno setting code and the -1L assignment code.
Changes from v3 --> v4:
* fix up a new warning about 'ret < 0' when the input arg type is (void *)
Changes from v2 --> v3:
* define a __GXX_HAS_AUTO_TYPE_WITH_CONST_SUPPORT for gcc >= 11.0 (ABI_VERSION >= 1016)
* split __sysret() to two versions by the macro instead of a mixed unified and unreadable version
* use shorter __ret instead of __sysret_arg
Changes from v1 --> v2:
* fix up argument with 'const' in the type
* support "void *" argument
Best regards,
Zhangjin
---
v4: https://lore.kernel.org/lkml/a4084f7fac7a89f861b5582774bc7a98634d1e76.16913…
v3: https://lore.kernel.org/lkml/8eaab5da2dcbba42e3f3efc2ae686a22c95f84f0.16913…
v2: https://lore.kernel.org/lkml/95fe3e732f455fab653fe1427118d905e4d04257.16913…
v1: https://lore.kernel.org/lkml/20230806131921.52453-1-falcon@tinylab.org/
---
tools/include/nolibc/sys.h | 74 ++++++++++++++++++++++++++++++--------
1 file changed, 59 insertions(+), 15 deletions(-)
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 833d6c5e86dc..6bdd18716e84 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -27,23 +27,67 @@
#include "errno.h"
#include "types.h"
+/*
+ * This returns a constant expression while determining if an argument is
+ * a constant expression, most importantly without evaluating the argument.
+ * Glory to Martin Uecker <Martin.Uecker(a)med.uni-goettingen.de>
+ * (from include/linux/const.h)
+ */
+#define __is_constexpr(x) \
+ (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
+
+/*
+ * "(void *)0 isn't 'constant enough' for is_constexpr() - so
+ * is_constexpr((type)0) can be used to detect pointer types."
+ * (from David Laight <David.Laight(a)ACULAB.COM>)
+ */
+#define __is_pointer(x) (!__is_constexpr((__typeof__(x))0))
-/* Syscall return helper for library routines, set errno as -ret when ret is in
- * range of [-MAX_ERRNO, -1]
+/*
+ * To preserve the input type and workaround the 'error: assignment of
+ * read-only variable' when the input type has 'const' flag.
+ *
+ * For gcc >= 11.0 (__GXX_ABI_VERSION = 1016), use the new __auto_type keyword
+ * instead of __typeof__().
*
- * Note, No official reference states the errno range here aligns with musl
- * (src/internal/syscall_ret.c) and glibc (sysdeps/unix/sysv/linux/sysdep.h)
+ * For old gcc versions, "use typeof((x) + 0) to lose the 'const' flag. The
+ * only downside is that char/short become int." (from David Laight
+ * <David.Laight(a)ACULAB.COM>)
*/
-static __inline__ __attribute__((unused, always_inline))
-long __sysret(unsigned long ret)
-{
- if (ret >= (unsigned long)-MAX_ERRNO) {
- SET_ERRNO(-(long)ret);
- return -1;
- }
- return ret;
-}
+#if __GXX_ABI_VERSION >= 1016
+#define __typeofdecl(arg) __auto_type
+#else
+#define __typeofdecl(arg) __typeof__((arg) + 0)
+#endif
+
+/* Syscall return helper for library routines
+ *
+ * - for pointer returns, set errno as -ret when ret is in [-MAX_ERRNO, -1]
+ * - for integer returns, set errno as -ret when ret < 0
+ *
+ * Note,
+ *
+ * - No official reference states the errno range, here aligns with musl
+ * (src/internal/syscall_ret.c) and glibc (sysdeps/unix/sysv/linux/sysdep.h).
+ *
+ * - To reduce binary size by removing useless type conversions and sign
+ * extensions, the helper is defined as a macro to preserve input type and
+ * provide two comparisons for both pointer and integer types during the
+ * compiling stage.
+ */
+
+#define __sysret(arg) \
+({ \
+ __typeofdecl(arg) __ret = (arg); \
+ if (__builtin_choose_expr(__is_pointer(arg), (unsigned long)-(MAX_ERRNO + 1), (long)__ret) \
+ < __builtin_choose_expr(__is_pointer(arg), (unsigned long)__ret, 0)) { \
+ SET_ERRNO(-(long)__ret); \
+ __ret = (__typeof__(arg))-1L; \
+ } \
+ __ret; \
+})
+
/* Functions in this file only describe syscalls. They're declared static so
* that the compiler usually decides to inline them while still being allowed
@@ -94,7 +138,7 @@ void *sbrk(intptr_t inc)
if (ret && sys_brk(ret + inc) == ret + inc)
return ret + inc;
- return (void *)__sysret(-ENOMEM);
+ return __sysret((void *)-ENOMEM);
}
@@ -682,7 +726,7 @@ void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
static __attribute__((unused))
void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
{
- return (void *)__sysret((unsigned long)sys_mmap(addr, length, prot, flags, fd, offset));
+ return __sysret(sys_mmap(addr, length, prot, flags, fd, offset));
}
static __attribute__((unused))
--
2.25.1
The test allocates dcache inside a cgroup, then destroys the cgroups and
then checks the sanity of numbers on the parent level. The reason it
fails is because dentries are freed with an RCU delay - a debugging
sleep shows that usage drops as expected shortly after.
Insert a 1s sleep after completing the cgroup creation/deletions. This
should be good enough, assuming that machines running those tests are
otherwise not very busy. This commit is directly inspired by Johannes
over at the link below.
Link: https://lore.kernel.org/all/20230801135632.1768830-1-hannes@cmpxchg.org/
Signed-off-by: Lucas Karpinski <lkarpins(a)redhat.com>
---
tools/testing/selftests/cgroup/test_kmem.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/testing/selftests/cgroup/test_kmem.c b/tools/testing/selftests/cgroup/test_kmem.c
index 67cc0182058d..7ac384bbfdd5 100644
--- a/tools/testing/selftests/cgroup/test_kmem.c
+++ b/tools/testing/selftests/cgroup/test_kmem.c
@@ -183,6 +183,9 @@ static int test_kmem_memcg_deletion(const char *root)
if (cg_run_in_subcgroups(parent, alloc_kmem_smp, NULL, 100))
goto cleanup;
+ /* wait for RCU freeing */
+ sleep(1);
+
current = cg_read_long(parent, "memory.current");
slab = cg_read_key_long(parent, "memory.stat", "slab ");
anon = cg_read_key_long(parent, "memory.stat", "anon ");
--
2.41.0
This adds support for receiving KeyUpdate messages (RFC 8446, 4.6.3
[1]). A sender transmits a KeyUpdate message and then changes its TX
key. The receiver should react by updating its RX key before
processing the next message.
This patchset implements key updates by:
1. pausing decryption when a KeyUpdate message is received, to avoid
attempting to use the old key to decrypt a record encrypted with
the new key
2. returning -EKEYEXPIRED to syscalls that cannot receive the
KeyUpdate message, until the rekey has been performed by userspace
3. passing the KeyUpdate message to userspace as a control message
4. allowing updates of the crypto_info via the TLS_TX/TLS_RX
setsockopts
This API has been tested with gnutls to make sure that it allows
userspace libraries to implement key updates [2]. Thanks to Frantisek
Krenzelok <fkrenzel(a)redhat.com> for providing the implementation in
gnutls and testing the kernel patches.
=======================================================================
Discussions around v2 of this patchset focused on how HW offload would
interact with rekey.
RX
- The existing SW path will handle all records between the KeyUpdate
message signaling the change of key and the new key becoming known
to the kernel -- those will be queued encrypted, and decrypted in
SW as they are read by userspace (once the key is provided, ie same
as this patchset)
- Call ->tls_dev_del + ->tls_dev_add immediately during
setsockopt(TLS_RX)
TX
- After setsockopt(TLS_TX), switch to the existing SW path (not the
current device_fallback) until we're able to re-enable HW offload
- tls_device_sendmsg will call into tls_sw_sendmsg under lock_sock
to avoid changing socket ops during the rekey while another
thread might be waiting on the lock
- We only re-enable HW offload (call ->tls_dev_add to install the new
key in HW) once all records sent with the old key have been
ACKed. At this point, all unacked records are SW-encrypted with the
new key, and the old key is unused by both HW and retransmissions.
- If there are no unacked records when userspace does
setsockopt(TLS_TX), we can (try to) install the new key in HW
immediately.
- If yet another key has been provided via setsockopt(TLS_TX), we
don't install intermediate keys, only the latest.
- TCP notifies ktls of ACKs via the icsk_clean_acked callback. In
case of a rekey, tls_icsk_clean_acked will record when all data
sent with the most recent past key has been sent. The next call
to sendmsg will install the new key in HW.
- We close and push the current SW record before reenabling
offload.
If ->tls_dev_add fails to install the new key in HW, we stay in SW
mode. We can add a counter to keep track of this.
In addition:
Because we can't change socket ops during a rekey, we'll also have to
modify do_tls_setsockopt_conf to check ctx->tx_conf and only call
either tls_set_device_offload or tls_set_sw_offload. RX already uses
the same ops for both TLS_HW and TLS_SW, so we could switch between HW
and SW mode on rekey.
An alternative would be to have a common sendmsg which locks
the socket and then calls the correct implementation. We'll need that
anyway for the offload under rekey case, so that would only add a test
to the SW path's ops (compared to the current code). That should allow
us to simplify build_protos a bit, but might have a performance
impact - we'll need to check it if we want to go that route.
=======================================================================
Note: in a future series, I'll clean up tls_set_sw_offload and
eliminate the per-cipher copy-paste using tls_cipher_size_desc.
[1] https://www.rfc-editor.org/rfc/rfc8446#section-4.6.3
[2] https://gitlab.com/gnutls/gnutls/-/merge_requests/1625
Sabrina Dubroca (6):
tls: remove tls_context argument from tls_set_sw_offload
tls: block decryption when a rekey is pending
tls: implement rekey for TLS1.3
docs: tls: document TLS1.3 key updates
selftests: tls: add key_generation argument to tls_crypto_info_init
selftests: tls: add rekey tests
Documentation/networking/tls.rst | 21 ++
include/net/tls.h | 3 +
net/tls/tls.h | 3 +-
net/tls/tls_device.c | 2 +-
net/tls/tls_main.c | 47 ++-
net/tls/tls_sw.c | 184 +++++++++---
tools/testing/selftests/net/tls.c | 466 +++++++++++++++++++++++++++++-
7 files changed, 661 insertions(+), 65 deletions(-)
--
2.40.1
From: Rong Tao <rongtao(a)cestc.cn>
commit 686a8bb72349("selftests/mm: split uffd tests into uffd-stress and
uffd-unit-tests") split uffd tests into uffd-stress and uffd-unit-tests,
obviously we need to modify the help information synchronously.
Also modify code indentation.
Signed-off-by: Rong Tao <rongtao(a)cestc.cn>
---
tools/testing/selftests/mm/uffd-stress.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c
index 995ff13e74c7..e40b6d7d2c0e 100644
--- a/tools/testing/selftests/mm/uffd-stress.c
+++ b/tools/testing/selftests/mm/uffd-stress.c
@@ -53,21 +53,21 @@ pthread_attr_t attr;
do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
const char *examples =
- "# Run anonymous memory test on 100MiB region with 99999 bounces:\n"
- "./userfaultfd anon 100 99999\n\n"
- "# Run share memory test on 1GiB region with 99 bounces:\n"
- "./userfaultfd shmem 1000 99\n\n"
- "# Run hugetlb memory test on 256MiB region with 50 bounces:\n"
- "./userfaultfd hugetlb 256 50\n\n"
- "# Run the same hugetlb test but using private file:\n"
- "./userfaultfd hugetlb-private 256 50\n\n"
- "# 10MiB-~6GiB 999 bounces anonymous test, "
- "continue forever unless an error triggers\n"
- "while ./userfaultfd anon $[RANDOM % 6000 + 10] 999; do true; done\n\n";
+ "# Run anonymous memory test on 100MiB region with 99999 bounces:\n"
+ "./uffd-stress anon 100 99999\n\n"
+ "# Run share memory test on 1GiB region with 99 bounces:\n"
+ "./uffd-stress shmem 1000 99\n\n"
+ "# Run hugetlb memory test on 256MiB region with 50 bounces:\n"
+ "./uffd-stress hugetlb 256 50\n\n"
+ "# Run the same hugetlb test but using private file:\n"
+ "./uffd-stress hugetlb-private 256 50\n\n"
+ "# 10MiB-~6GiB 999 bounces anonymous test, "
+ "continue forever unless an error triggers\n"
+ "while ./uffd-stress anon $[RANDOM % 6000 + 10] 999; do true; done\n\n";
static void usage(void)
{
- fprintf(stderr, "\nUsage: ./userfaultfd <test type> <MiB> <bounces>\n\n");
+ fprintf(stderr, "\nUsage: ./uffd-stress <test type> <MiB> <bounces>\n\n");
fprintf(stderr, "Supported <test type>: anon, hugetlb, "
"hugetlb-private, shmem, shmem-private\n\n");
fprintf(stderr, "Examples:\n\n");
--
2.39.3