Skip to contentSkip to conversation

Patch "selftests: vDSO: skip getrandom test if architecture is unsupported" has been added to the 6.11-stable tree

PATCH Superseded Jason A. Donenfeld 4 participants 31 messages Oct 1, 2024 – Oct 8, 2024 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

This is not stable material and I didn't mark it as such. Do not backport.

maintainer
#2 lore raw
Quoted 1 line · Jason A. Donenfeld

This is not stable material and I didn't mark it as such. Do not backport.

The way selftest work is they just skip if a feature isn't supported. As such this test should run gracefully on stable releases.

I would say backport unless and skip if the feature isn't supported.

Does this build on stables?

thanks,
-- Shuah

#3 lore raw
Quoted 7 lines · Shuah Khan
Quoted 1 line · Jason A. Donenfeld

This is not stable material and I didn't mark it as such. Do not backport.

The way selftest work is they just skip if a feature isn't supported. As such this test should run gracefully on stable releases.

I would say backport unless and skip if the feature isn't supported.

Nonsense. 6.11 never returns ENOSYS from vDSO. This doesn't make sense.

maintainer
#4 lore raw
Quoted 10 lines · Jason A. Donenfeld
Quoted 7 lines · Shuah Khan
Quoted 1 line · Jason A. Donenfeld

This is not stable material and I didn't mark it as such. Do not backport.

The way selftest work is they just skip if a feature isn't supported. As such this test should run gracefully on stable releases.

I would say backport unless and skip if the feature isn't supported.

Nonsense. 6.11 never returns ENOSYS from vDSO. This doesn't make sense.

Not sure what you mean by Nonsense. ENOSYS can be used to skip??

thanks,
-- Shuah

#5 lore raw
Quoted 5 lines · Shuah Khan
Quoted 4 lines · Jason A. Donenfeld
Quoted 3 lines · Shuah Khan
Quoted 1 line · Jason A. Donenfeld

This is not stable material and I didn't mark it as such. Do not backport.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

The way selftest work is they just skip if a feature isn't supported. As such this test should run gracefully on stable releases.

I would say backport unless and skip if the feature isn't supported.

Nonsense. 6.11 never returns ENOSYS from vDSO. This doesn't make sense.

Not sure what you mean by Nonsense. ENOSYS can be used to skip??

The branch that this patch adds will never be reached in 6.11 because the kernel does not have the corresponding code.

maintainer
#6 lore raw
Quoted 9 lines · Jason A. Donenfeld
Quoted 8 lines · Shuah Khan
Quoted 7 lines · Jason A. Donenfeld
Quoted 6 lines · Shuah Khan
Quoted 1 line · Jason A. Donenfeld

This is not stable material and I didn't mark it as such. Do not backport.

The way selftest work is they just skip if a feature isn't supported. As such this test should run gracefully on stable releases.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I would say backport unless and skip if the feature isn't supported.

Nonsense. 6.11 never returns ENOSYS from vDSO. This doesn't make sense.

Not sure what you mean by Nonsense. ENOSYS can be used to skip??

The branch that this patch adds will never be reached in 6.11 because the kernel does not have the corresponding code.

What should/would happen if this test is run on a kernel that doesn't support the feature?

thanks,
-- Shuah

#7 lore raw
Quoted 14 lines · Shuah Khan
Quoted 13 lines · Jason A. Donenfeld
Quoted 12 lines · Shuah Khan
Quoted 10 lines · Jason A. Donenfeld
Quoted 7 lines · Shuah Khan
Quoted 1 line · Jason A. Donenfeld

This is not stable material and I didn't mark it as such. Do not backport.

The way selftest work is they just skip if a feature isn't supported. As such this test should run gracefully on stable releases.

I would say backport unless and skip if the feature isn't supported.

Nonsense. 6.11 never returns ENOSYS from vDSO. This doesn't make sense.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Not sure what you mean by Nonsense. ENOSYS can be used to skip??

The branch that this patch adds will never be reached in 6.11 because the kernel does not have the corresponding code.

What should/would happen if this test is run on a kernel that doesn't support the feature?

The build system doesn't compile it for kernels without the feature.

#8 lore raw
Quoted 17 lines · Jason A. Donenfeld
Quoted 16 lines · Shuah Khan
Quoted 15 lines · Jason A. Donenfeld
Quoted 13 lines · Shuah Khan
Quoted 10 lines · Jason A. Donenfeld
Quoted 7 lines · Shuah Khan
Quoted 1 line · Jason A. Donenfeld

This is not stable material and I didn't mark it as such. Do not backport.

The way selftest work is they just skip if a feature isn't supported. As such this test should run gracefully on stable releases.

I would say backport unless and skip if the feature isn't supported.

Nonsense. 6.11 never returns ENOSYS from vDSO. This doesn't make sense.

Not sure what you mean by Nonsense. ENOSYS can be used to skip??

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

The branch that this patch adds will never be reached in 6.11 because the kernel does not have the corresponding code.

What should/would happen if this test is run on a kernel that doesn't support the feature?

The build system doesn't compile it for kernels without the feature.

That's not how the kselftests should be working. They can run on any kernel image (build is separate from running on many test systems), and so they should just fail with whatever the "feature not present" error is if the feature isn't present in the system-that-is-being-tested.

thanks,

greg k-h

#9 lore raw
Quoted 21 lines · Greg KH
Quoted 20 lines · Jason A. Donenfeld
Quoted 19 lines · Shuah Khan
Quoted 17 lines · Jason A. Donenfeld
Quoted 5 lines · Shuah Khan
Quoted 4 lines · Jason A. Donenfeld
Quoted 3 lines · Shuah Khan
Quoted 1 line · Jason A. Donenfeld

This is not stable material and I didn't mark it as such. Do not backport.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

The way selftest work is they just skip if a feature isn't supported. As such this test should run gracefully on stable releases.

I would say backport unless and skip if the feature isn't supported.

Nonsense. 6.11 never returns ENOSYS from vDSO. This doesn't make sense.

Not sure what you mean by Nonsense. ENOSYS can be used to skip??

The branch that this patch adds will never be reached in 6.11 because the kernel does not have the corresponding code.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

What should/would happen if this test is run on a kernel that doesn't support the feature?

The build system doesn't compile it for kernels without the feature.

That's not how the kselftests should be working.

If you'd like to get involved in the development of these, by all means send patches. As you can see, for 6.12, these were intensely improved in all manner of ways:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/log/tools/testing/selftests/vDSO

Just look at that flurry of activity. Things are getting better! And things were in pretty bad shape before. If you think there's an interesting subset of that for backporting, by all means go for it, but do it thoughtfully and don't pick patches willy-nilly.

Quoted 4 lines

They can run on any
kernel image (build is separate from running on many test systems), and so they should just fail with whatever the "feature not present" error is if the feature isn't present in the system-that-is-being-tested.

So, it's actually not that clear what the best thing is. Firstly, for vdso_test_chacha.c, it can't even compile without the symlink and a resolving tools/arch/$(SRCARCH)/vdso/vgetrandom-chacha.S symlink, which is on a per-arch basis. You might say that in this case, it's best to condition the Makefile on ifneq ($(wildcard tools/arch/$(SRCARCH)/vdso/ vgetrandom-chacha.S),) instead of on $(ARCH), but there's this ugly wrinkle where some of the code that's being compiled is 64-bit only, and x86_64 and x86 share a $(SRCARCH) path. (That Makefile makes use of $(CONFIG_X86_32), which is pretty gross and might not work; I'm not yet sure how to fix that.) Christophe experimented with having the compiler decide, and then there being a runtime result, but it added a lot of complexity that didn't seem necessary. There's more experimentation to be done here.

Meanwhile, part of vdso_test_getrandom.c's purpose is to test whether __kernel_getrandom() or __vdso_getrandom() is actually being properly exported from the vDSO. This is also interesting on powerpc, where it's implemented on both 32-bit and 64-bit, so there's the compat case to worry about. That in turn means that this test has in it:

	vgrnd.fn = (__typeof__(vgrnd.fn))vdso_sym(version, name);
	if (!vgrnd.fn) {
		printf("%s is missing!\n", name);
		exit(KSFT_FAIL);
	}

And not exit(KSFT_SKIP), since that would hide the failure to export the symbol. Now, you could say that since development on the fundamental part is mostly concluded, we could move to a KSFT_SKIP, in order to simplify the build choice and such. I'm not sure where I stand on that. At the very least, there's still RISC-V coming down the pipeline for this feature, so it probably would change after that comes out.

Anyway, that is all to say that this stuff has been thoroughly considered, not haphazardly glued together or something. Maybe that consideration has reached wrong conclusions -- that's an entirely possible of an outcome -- but it wouldn't be for lack of caring. If you'd like to contribute to it, I'd certainly welcome a hand. But please don't do the arm-chair coding thing.

Meanwhile, this ENOSYS thing has nothing to do with what either of you assumed it does. This is to handle obscure/exotic arm64 hardware, which might not exist in the Linux world, that doesn't have NEON support. But since arm64 support for this function didn't even come to Linux 6.11, there's no point in discussing it as a backport.

Jason

maintainer
#10 lore raw
Quoted 34 lines · Jason A. Donenfeld
Quoted 21 lines · Greg KH
Quoted 20 lines · Jason A. Donenfeld
Quoted 19 lines · Shuah Khan
Quoted 17 lines · Jason A. Donenfeld
Quoted 5 lines · Shuah Khan
Quoted 4 lines · Jason A. Donenfeld
Quoted 3 lines · Shuah Khan
Quoted 1 line · Jason A. Donenfeld

This is not stable material and I didn't mark it as such. Do not backport.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

The way selftest work is they just skip if a feature isn't supported. As such this test should run gracefully on stable releases.

I would say backport unless and skip if the feature isn't supported.

Nonsense. 6.11 never returns ENOSYS from vDSO. This doesn't make sense.

Not sure what you mean by Nonsense. ENOSYS can be used to skip??

The branch that this patch adds will never be reached in 6.11 because the kernel does not have the corresponding code.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

What should/would happen if this test is run on a kernel that doesn't support the feature?

The build system doesn't compile it for kernels without the feature.

That's not how the kselftests should be working.

If you'd like to get involved in the development of these, by all means send patches. As you can see, for 6.12, these were intensely improved in all manner of ways:

Quoted 7 lines

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/log/tools/testing/selftests/vDSO

Just look at that flurry of activity. Things are getting better! And things were in pretty bad shape before. If you think there's an interesting subset of that for backporting, by all means go for it, but do it thoughtfully and don't pick patches willy-nilly.

This is not different from other kernel APIs and enhancements and correspo0nding updates to the existing selftests.

The
vdso_test_getrandom test a user-space program exists in 6.11.

Use should be able to run vdso_test_getrandom compiled on 6.12 repo on a 6.11 kernel.

Quoted 5 lines
Quoted 4 lines

They can run on any
kernel image (build is separate from running on many test systems), and so they should just fail with whatever the "feature not present" error is if the feature isn't present in the system-that-is-being-tested.

vdso_test_getrandom test a user-space program exists in 6.11. Users should be able to run vdso_test_getrandom compiled on 6.12 repo on a 6.11 kernel. This is what several CIs do.

Quoted 20 lines

So, it's actually not that clear what the best thing is. Firstly, for vdso_test_chacha.c, it can't even compile without the symlink and a resolving tools/arch/$(SRCARCH)/vdso/vgetrandom-chacha.S symlink, which is on a per-arch basis. You might say that in this case, it's best to condition the Makefile on ifneq ($(wildcard tools/arch/$(SRCARCH)/vdso/ vgetrandom-chacha.S),) instead of on $(ARCH), but there's this ugly wrinkle where some of the code that's being compiled is 64-bit only, and x86_64 and x86 share a $(SRCARCH) path. (That Makefile makes use of $(CONFIG_X86_32), which is pretty gross and might not work; I'm not yet sure how to fix that.) Christophe experimented with having the compiler decide, and then there being a runtime result, but it added a lot of complexity that didn't seem necessary. There's more experimentation to be done here.

Meanwhile, part of vdso_test_getrandom.c's purpose is to test whether __kernel_getrandom() or __vdso_getrandom() is actually being properly exported from the vDSO. This is also interesting on powerpc, where it's implemented on both 32-bit and 64-bit, so there's the compat case to worry about. That in turn means that this test has in it:

Quoted 6 lines
	vgrnd.fn = (__typeof__(vgrnd.fn))vdso_sym(version, name);
	if (!vgrnd.fn) {
		printf("%s is missing!\n", name);
		exit(KSFT_FAIL);
	}

x86 selftest handles 32 vs 64-bit related scenarios now. You can take a look at the Makefile. You can also split the test specific to 32 vs 64 and compile it for native and cross-compile cases.

Quoted 4 lines

And not exit(KSFT_SKIP), since that would hide the failure to export the symbol. Now, you could say that since development on the fundamental part is mostly concluded, we could move to a KSFT_SKIP, in order to simplify the build choice and such. I'm not sure where I stand on that.

If I am understanding this correctly, KSFT_FAIL is used during development and as of today, KSFT_SKIP is the correct exit code??

Quoted 3 lines

At the very least, there's still RISC-V coming down the pipeline for this feature, so it probably would change after that comes out.

This can be handled as part RISC-V.

Quoted 7 lines

Anyway, that is all to say that this stuff has been thoroughly considered, not haphazardly glued together or something. Maybe that consideration has reached wrong conclusions -- that's an entirely possible of an outcome -- but it wouldn't be for lack of caring. If you'd like to contribute to it, I'd certainly welcome a hand. But please don't do the arm-chair coding thing.

Probably. We don't know what we don't know. selftest use-cases are the ones we are discussing here.

You can check the kselftest use-cases and contribution guidelines in kselftest.rst

Quoted 5 lines

Meanwhile, this ENOSYS thing has nothing to do with what either of you assumed it does. This is to handle obscure/exotic arm64 hardware, which might not exist in the Linux world, that doesn't have NEON support. But since arm64 support for this function didn't even come to Linux 6.11, there's no point in discussing it as a backport.

#define ENOSYS 78 /* Function not implemented */

user-space understands ENOSYS as feature/function not implemented.

If ENOSYS is the right choice for this obscure/exotic arm64 hardware?

The user-space vdso_test_getrandom test has to run on all architectures if can be compiled (unless Makefile restricts the compile) and older releases and handle not finding the feature and fail gracefully.

thanks,
-- Shuah

#11 lore raw
Quoted 11 lines · Shuah Khan

This is not different from other kernel APIs and enhancements and correspo0nding updates to the existing selftests.

The
vdso_test_getrandom test a user-space program exists in 6.11.

Use should be able to run vdso_test_getrandom compiled on 6.12 repo on a 6.11 kernel.
vdso_test_getrandom test a user-space program exists in 6.11. Users should be able to run vdso_test_getrandom compiled on 6.12 repo on a 6.11 kernel. This is what several CIs do.

The x86 test from 6.12 works just fine on 6.11.

I really don't follow you at all or what you're getting at. I think if you actually look at the code, you'll be mostly okay with it. And if there's something that looks awry to you, send a patch or describe to me clearly what looks wrong and I'll send a patch.

#12 lore raw

cover getrandom & chacha cleanups

Hi Shuah,

I've now read your email several times trying to figure out what you meant and what your objections are. This series is my best attempt at trying to satisfy that. But my understanding still has a lot of question marks, so I may have missed your point here. Nonetheless, maybe this moves things forward a bit.

Jason

Cc Shuah Khan <[email protected]>
Cc Greg KH <[email protected]>

Jason A. Donenfeld (3):
selftests: vDSO: condition chacha build on chacha implementation
selftests: vDSO: unconditionally build getrandom test
selftests: vDSO: improve getrandom and chacha error messages

 tools/testing/selftests/vDSO/Makefile         |  4 +-
 .../testing/selftests/vDSO/vdso_test_chacha.c | 27 ++++---
 .../selftests/vDSO/vdso_test_getrandom.c      | 75 ++++++++-----------
 3 files changed, 52 insertions(+), 54 deletions(-)
Signature · 1 line
2.46.0
#13 lore raw

PATCH 1/3 selftests: vDSO: condition chacha build on chacha implementation

The chacha test can build anywhere that the vgetrandom-chacha.S file is available, so condition it on the existence of that file, rather than a specific arch.

There is one wrinkle, which is that x86 and x86_64 are the same ARCH, but the code is only functional for x86_64. So filter out the test for CONFIG_X86_32 in the same block that the other 32-bit special case lives.

We have to define top_srcdir ourselves, because even though lib.mk defines it later, that has to be included after TEST_GEN_PROGS is populated. Fortunately the definition is fairly trivial.

---
 tools/testing/selftests/vDSO/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/vDSO/Makefile +4 -0
index af9cedbf5357..2c38c9c6d056 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 include ../../../scripts/Makefile.arch
+top_srcdir = $(realpath ../../../..)
 
 TEST_GEN_PROGS := vdso_test_gettimeofday
 TEST_GEN_PROGS += vdso_test_getcpu
@@ -11,6 +12,8 @@ endif
 TEST_GEN_PROGS += vdso_test_correctness
 ifeq ($(ARCH)$(CONFIG_X86_32),$(filter $(ARCH)$(CONFIG_X86_32),x86 x86_64 loongarch arm64 powerpc s390))
 TEST_GEN_PROGS += vdso_test_getrandom
+endif
+ifneq ($(wildcard $(top_srcdir)/tools/arch/$(SRCARCH)/vdso/vgetrandom-chacha.S),)
 TEST_GEN_PROGS += vdso_test_chacha
 endif
 
@@ -18,6 +21,7 @@ CFLAGS := -std=gnu99 -O2
 
 ifeq ($(CONFIG_X86_32),y)
 LDLIBS += -lgcc_s
+TEST_GEN_PROGS := $(filter-out vdso_test_chacha,$(TEST_GEN_PROGS))
 endif
 
 include ../lib.mk
Signature · 1 line
2.46.0
#14 lore raw

PATCH 2/3 selftests: vDSO: unconditionally build getrandom test

In reply to Jason A. Donenfeld

Rather than building on supported archs, build on all archs, and then use the presence of the symbol in the vDSO to either skip the test or move forward with it.

Note that this means that this test no longer checks whether the symbol was correctly added to the kernel. But hopefully this will be clear enough to developers and we'll cross our fingers that symbols aren't removed by accident and not caught after this change.

---
 tools/testing/selftests/vDSO/Makefile              | 2 --
 tools/testing/selftests/vDSO/vdso_test_getrandom.c | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)
tools/testing/selftests/vDSO/Makefile +0 -2
index 2c38c9c6d056..96b4f2a766e2 100644
@@ -10,9 +10,7 @@ ifeq ($(ARCH),$(filter $(ARCH),x86 x86_64))
 TEST_GEN_PROGS += vdso_standalone_test_x86
 endif
 TEST_GEN_PROGS += vdso_test_correctness
-ifeq ($(ARCH)$(CONFIG_X86_32),$(filter $(ARCH)$(CONFIG_X86_32),x86 x86_64 loongarch arm64 powerpc s390))
 TEST_GEN_PROGS += vdso_test_getrandom
-endif
 ifneq ($(wildcard $(top_srcdir)/tools/arch/$(SRCARCH)/vdso/vgetrandom-chacha.S),)
 TEST_GEN_PROGS += vdso_test_chacha
 endif
tools/testing/selftests/vDSO/vdso_test_getrandom.c +1 -1
index 72a1d9b43a84..5489a2f07434 100644
@@ -119,7 +119,7 @@ static void vgetrandom_init(void)
 	vgrnd.fn = (__typeof__(vgrnd.fn))vdso_sym(version, name);
 	if (!vgrnd.fn) {
 		printf("%s is missing!\n", name);
-		exit(KSFT_FAIL);
+		exit(KSFT_SKIP);
 	}
 	ret = VDSO_CALL(vgrnd.fn, 5, NULL, 0, 0, &vgrnd.params, ~0UL);
 	if (ret == -ENOSYS) {
Signature · 1 line
2.46.0
#15 lore raw

PATCH 3/3 selftests: vDSO: improve getrandom and chacha error messages

In reply to Jason A. Donenfeld

Improve the error and skip condition messages to let the developer know precisely where a test has failed. Also make better use of the ksft api for this.

---
 .../testing/selftests/vDSO/vdso_test_chacha.c | 27 ++++---
 .../selftests/vDSO/vdso_test_getrandom.c      | 75 ++++++++-----------
 2 files changed, 49 insertions(+), 53 deletions(-)
tools/testing/selftests/vDSO/vdso_test_chacha.c +16 -11
index b1ea532c5996..60c5ea5cb925 100644
@@ -90,10 +90,8 @@ int main(int argc, char *argv[])
 	ksft_set_plan(1);
 
 	for (unsigned int trial = 0; trial < TRIALS; ++trial) {
-		if (getrandom(key, sizeof(key), 0) != sizeof(key)) {
-			printf("getrandom() failed!\n");
-			return KSFT_SKIP;
-		}
+		if (getrandom(key, sizeof(key), 0) != sizeof(key))
+			ksft_exit_skip("getrandom() failed unexpectedly\n");
 		memset(counter1, 0, sizeof(counter1));
 		reference_chacha20_blocks(output1, key, counter1, BLOCKS);
 		for (unsigned int split = 0; split < BLOCKS; ++split) {
@@ -102,8 +100,10 @@ int main(int argc, char *argv[])
 			if (split)
 				__arch_chacha20_blocks_nostack(output2, key, counter2, split);
 			__arch_chacha20_blocks_nostack(output2 + split * BLOCK_SIZE, key, counter2, BLOCKS - split);
-			if (memcmp(output1, output2, sizeof(output1)) || memcmp(counter1, counter2, sizeof(counter1)))
-				return KSFT_FAIL;
+			if (memcmp(output1, output2, sizeof(output1)))
+				ksft_exit_fail_msg("Main loop outputs do not match on trial %u, split %u\n", trial, split);
+			if (memcmp(counter1, counter2, sizeof(counter1)))
+				ksft_exit_fail_msg("Main loop counters do not match on trial %u, split %u\n", trial, split);
 		}
 	}
 	memset(counter1, 0, sizeof(counter1));
@@ -113,14 +113,19 @@ int main(int argc, char *argv[])
 
 	reference_chacha20_blocks(output1, key, counter1, BLOCKS);
 	__arch_chacha20_blocks_nostack(output2, key, counter2, BLOCKS);
-	if (memcmp(output1, output2, sizeof(output1)) || memcmp(counter1, counter2, sizeof(counter1)))
-		return KSFT_FAIL;
+	if (memcmp(output1, output2, sizeof(output1)))
+		ksft_exit_fail_msg("Block limit outputs do not match after first round\n");
+	if (memcmp(counter1, counter2, sizeof(counter1)))
+		ksft_exit_fail_msg("Block limit counters do not match after first round\n");
 
 	reference_chacha20_blocks(output1, key, counter1, BLOCKS);
 	__arch_chacha20_blocks_nostack(output2, key, counter2, BLOCKS);
-	if (memcmp(output1, output2, sizeof(output1)) || memcmp(counter1, counter2, sizeof(counter1)))
-		return KSFT_FAIL;
+	if (memcmp(output1, output2, sizeof(output1)))
+		ksft_exit_fail_msg("Block limit outputs do not match after second round\n");
+	if (memcmp(counter1, counter2, sizeof(counter1)))
+		ksft_exit_fail_msg("Block limit counters do not match after second round\n");
 
 	ksft_test_result_pass("chacha: PASS\n");
-	return KSFT_PASS;
+	ksft_exit_pass();
+	return 0;
 }
tools/testing/selftests/vDSO/vdso_test_getrandom.c +33 -42

165 lines not on this page · raw message

Signature · 1 line
2.46.0
#16 lore raw

Re: [PATCH kselftest 3/3] selftests: vDSO: improve getrandom and chacha error messages

kernel test robot noticed the following build warnings:

Hi Jason,

kernel test robot noticed the following build warnings:

[auto build test WARNING on shuah-kselftest/next]
[also build test WARNING on shuah-kselftest/fixes linus/master v6.12-rc1 next-20241004] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jason-A-Donenfeld/selftests-vDSO-condition-chacha-build-on-chacha-implementation/20241003-111508
base:   https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git next
patch link:    https://lore.kernel.org/r/20241003031307.2236454-4-Jason%40zx2c4.com
patch subject: [PATCH kselftest 3/3] selftests: vDSO: improve getrandom and chacha error messages

:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241005/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

All warnings (new ones prefixed by >>):

>> vdso_test_getrandom.c:274:3: warning: add explicit braces to avoid dangling else [-Wdangling-else]
     274 |                 else if (WSTOPSIG(status) == (SIGTRAP | 0x80)) {
         |                 ^

1 warning generated.

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#17 lore raw

Re: [PATCH kselftest 3/3] selftests: vDSO: improve getrandom and chacha error messages

I'll send a v2.

#18 lore raw

PATCH v2 1/4 selftests: vDSO: condition chacha build on chacha implementation

The chacha test can build anywhere that the vgetrandom-chacha.S file is available, so condition it on the existence of that file, rather than a specific arch.

There is one wrinkle, which is that x86 and x86_64 are the same ARCH, but the code is only functional for x86_64. So filter out the test for CONFIG_X86_32 in the same block that the other 32-bit special case lives.

We have to define top_srcdir ourselves, because even though lib.mk defines it later, that has to be included after TEST_GEN_PROGS is populated. Fortunately the definition is fairly trivial.

---
 tools/testing/selftests/vDSO/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/vDSO/Makefile +4 -0
index af9cedbf5357..2c38c9c6d056 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 include ../../../scripts/Makefile.arch
+top_srcdir = $(realpath ../../../..)
 
 TEST_GEN_PROGS := vdso_test_gettimeofday
 TEST_GEN_PROGS += vdso_test_getcpu
@@ -11,6 +12,8 @@ endif
 TEST_GEN_PROGS += vdso_test_correctness
 ifeq ($(ARCH)$(CONFIG_X86_32),$(filter $(ARCH)$(CONFIG_X86_32),x86 x86_64 loongarch arm64 powerpc s390))
 TEST_GEN_PROGS += vdso_test_getrandom
+endif
+ifneq ($(wildcard $(top_srcdir)/tools/arch/$(SRCARCH)/vdso/vgetrandom-chacha.S),)
 TEST_GEN_PROGS += vdso_test_chacha
 endif
 
@@ -18,6 +21,7 @@ CFLAGS := -std=gnu99 -O2
 
 ifeq ($(CONFIG_X86_32),y)
 LDLIBS += -lgcc_s
+TEST_GEN_PROGS := $(filter-out vdso_test_chacha,$(TEST_GEN_PROGS))
 endif
 
 include ../lib.mk
Signature · 1 line
2.46.0
#19 lore raw

PATCH v2 2/4 selftests: vDSO: unconditionally build getrandom test

Rather than building on supported archs, build on all archs, and then use the presence of the symbol in the vDSO to either skip the test or move forward with it.

Note that this means that this test no longer checks whether the symbol was correctly added to the kernel. But hopefully this will be clear enough to developers and we'll cross our fingers that symbols aren't removed by accident and not caught after this change.

---
 tools/testing/selftests/vDSO/Makefile              | 2 --
 tools/testing/selftests/vDSO/vdso_test_getrandom.c | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)
tools/testing/selftests/vDSO/Makefile +0 -2
index 2c38c9c6d056..96b4f2a766e2 100644
@@ -10,9 +10,7 @@ ifeq ($(ARCH),$(filter $(ARCH),x86 x86_64))
 TEST_GEN_PROGS += vdso_standalone_test_x86
 endif
 TEST_GEN_PROGS += vdso_test_correctness
-ifeq ($(ARCH)$(CONFIG_X86_32),$(filter $(ARCH)$(CONFIG_X86_32),x86 x86_64 loongarch arm64 powerpc s390))
 TEST_GEN_PROGS += vdso_test_getrandom
-endif
 ifneq ($(wildcard $(top_srcdir)/tools/arch/$(SRCARCH)/vdso/vgetrandom-chacha.S),)
 TEST_GEN_PROGS += vdso_test_chacha
 endif
tools/testing/selftests/vDSO/vdso_test_getrandom.c +1 -1
index 72a1d9b43a84..5489a2f07434 100644
@@ -119,7 +119,7 @@ static void vgetrandom_init(void)
 	vgrnd.fn = (__typeof__(vgrnd.fn))vdso_sym(version, name);
 	if (!vgrnd.fn) {
 		printf("%s is missing!\n", name);
-		exit(KSFT_FAIL);
+		exit(KSFT_SKIP);
 	}
 	ret = VDSO_CALL(vgrnd.fn, 5, NULL, 0, 0, &vgrnd.params, ~0UL);
 	if (ret == -ENOSYS) {
Signature · 1 line
2.46.0
#20 lore raw

PATCH v2 3/4 selftests: vDSO: improve getrandom and chacha error messages

In reply to Jason A. Donenfeld

Improve the error and skip condition messages to let the developer know precisely where a test has failed. Also make better use of the ksft api for this.

---
 .../testing/selftests/vDSO/vdso_test_chacha.c | 27 ++++---
 .../selftests/vDSO/vdso_test_getrandom.c      | 75 ++++++++-----------
 2 files changed, 49 insertions(+), 53 deletions(-)
tools/testing/selftests/vDSO/vdso_test_chacha.c +16 -11
index b1ea532c5996..60c5ea5cb925 100644
@@ -90,10 +90,8 @@ int main(int argc, char *argv[])
 	ksft_set_plan(1);
 
 	for (unsigned int trial = 0; trial < TRIALS; ++trial) {
-		if (getrandom(key, sizeof(key), 0) != sizeof(key)) {
-			printf("getrandom() failed!\n");
-			return KSFT_SKIP;
-		}
+		if (getrandom(key, sizeof(key), 0) != sizeof(key))
+			ksft_exit_skip("getrandom() failed unexpectedly\n");
 		memset(counter1, 0, sizeof(counter1));
 		reference_chacha20_blocks(output1, key, counter1, BLOCKS);
 		for (unsigned int split = 0; split < BLOCKS; ++split) {
@@ -102,8 +100,10 @@ int main(int argc, char *argv[])
 			if (split)
 				__arch_chacha20_blocks_nostack(output2, key, counter2, split);
 			__arch_chacha20_blocks_nostack(output2 + split * BLOCK_SIZE, key, counter2, BLOCKS - split);
-			if (memcmp(output1, output2, sizeof(output1)) || memcmp(counter1, counter2, sizeof(counter1)))
-				return KSFT_FAIL;
+			if (memcmp(output1, output2, sizeof(output1)))
+				ksft_exit_fail_msg("Main loop outputs do not match on trial %u, split %u\n", trial, split);
+			if (memcmp(counter1, counter2, sizeof(counter1)))
+				ksft_exit_fail_msg("Main loop counters do not match on trial %u, split %u\n", trial, split);
 		}
 	}
 	memset(counter1, 0, sizeof(counter1));
@@ -113,14 +113,19 @@ int main(int argc, char *argv[])
 
 	reference_chacha20_blocks(output1, key, counter1, BLOCKS);
 	__arch_chacha20_blocks_nostack(output2, key, counter2, BLOCKS);
-	if (memcmp(output1, output2, sizeof(output1)) || memcmp(counter1, counter2, sizeof(counter1)))
-		return KSFT_FAIL;
+	if (memcmp(output1, output2, sizeof(output1)))
+		ksft_exit_fail_msg("Block limit outputs do not match after first round\n");
+	if (memcmp(counter1, counter2, sizeof(counter1)))
+		ksft_exit_fail_msg("Block limit counters do not match after first round\n");
 
 	reference_chacha20_blocks(output1, key, counter1, BLOCKS);
 	__arch_chacha20_blocks_nostack(output2, key, counter2, BLOCKS);
-	if (memcmp(output1, output2, sizeof(output1)) || memcmp(counter1, counter2, sizeof(counter1)))
-		return KSFT_FAIL;
+	if (memcmp(output1, output2, sizeof(output1)))
+		ksft_exit_fail_msg("Block limit outputs do not match after second round\n");
+	if (memcmp(counter1, counter2, sizeof(counter1)))
+		ksft_exit_fail_msg("Block limit counters do not match after second round\n");
 
 	ksft_test_result_pass("chacha: PASS\n");
-	return KSFT_PASS;
+	ksft_exit_pass();
+	return 0;
 }
tools/testing/selftests/vDSO/vdso_test_getrandom.c +33 -42

165 lines not on this page · raw message

Signature · 1 line
2.46.0
#21 lore raw

PATCH v2 4/4 selftests: vDSO: unconditionally build chacha test

In reply to Jason A. Donenfeld

Rather than using symlinks to find the vgetrandom-chacha.S file for each arch, store this in a file that uses the compiler to determine architecture, and then make use of weak symbols to skip the test on architectures that don't provide the code.

---
 tools/arch/arm64/vdso                            |  1 -
 tools/arch/loongarch/vdso                        |  1 -
 tools/arch/powerpc/vdso                          |  1 -
 tools/arch/s390/vdso                             |  1 -
 tools/arch/x86/vdso                              |  1 -
 tools/testing/selftests/vDSO/Makefile            |  6 +-----
 tools/testing/selftests/vDSO/vdso_test_chacha.c  |  6 ++++++
 .../selftests/vDSO/vgetrandom-chacha-finder.S    | 16 ++++++++++++++++
 8 files changed, 23 insertions(+), 10 deletions(-)
 delete mode 120000 tools/arch/arm64/vdso
 delete mode 120000 tools/arch/loongarch/vdso
 delete mode 120000 tools/arch/powerpc/vdso
 delete mode 120000 tools/arch/s390/vdso
 delete mode 120000 tools/arch/x86/vdso
 create mode 100644 tools/testing/selftests/vDSO/vgetrandom-chacha-finder.S
tools/arch/arm64/vdso deleted +0 -1
deleted file mode 120000
index 233c7a26f6e5..000000000000
@@ -1 +0,0 @@
-../../../arch/arm64/kernel/vdso
\ No newline at end of file
tools/arch/loongarch/vdso deleted +0 -1
deleted file mode 120000
index ebda43a82db7..000000000000
@@ -1 +0,0 @@
-../../../arch/loongarch/vdso
\ No newline at end of file
tools/arch/powerpc/vdso deleted +0 -1
deleted file mode 120000
index 4e676d1d1cb4..000000000000
@@ -1 +0,0 @@
-../../../arch/powerpc/kernel/vdso
\ No newline at end of file
tools/arch/s390/vdso deleted +0 -1
deleted file mode 120000
index 6cf4c1cebdcd..000000000000
@@ -1 +0,0 @@
-../../../arch/s390/kernel/vdso64
\ No newline at end of file
tools/arch/x86/vdso deleted +0 -1
deleted file mode 120000
index 7eb962fd3454..000000000000
@@ -1 +0,0 @@
-../../../arch/x86/entry/vdso/
\ No newline at end of file
tools/testing/selftests/vDSO/Makefile +1 -5
index 96b4f2a766e2..e453c178d97f 100644
@@ -1,6 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 include ../../../scripts/Makefile.arch
-top_srcdir = $(realpath ../../../..)
 
 TEST_GEN_PROGS := vdso_test_gettimeofday
 TEST_GEN_PROGS += vdso_test_getcpu
@@ -11,15 +10,12 @@ TEST_GEN_PROGS += vdso_standalone_test_x86
 endif
 TEST_GEN_PROGS += vdso_test_correctness
 TEST_GEN_PROGS += vdso_test_getrandom
-ifneq ($(wildcard $(top_srcdir)/tools/arch/$(SRCARCH)/vdso/vgetrandom-chacha.S),)
 TEST_GEN_PROGS += vdso_test_chacha
-endif
 
 CFLAGS := -std=gnu99 -O2
 
 ifeq ($(CONFIG_X86_32),y)
 LDLIBS += -lgcc_s
-TEST_GEN_PROGS := $(filter-out vdso_test_chacha,$(TEST_GEN_PROGS))
 endif
 
 include ../lib.mk
@@ -39,7 +35,7 @@ $(OUTPUT)/vdso_test_getrandom: CFLAGS += -isystem $(top_srcdir)/tools/include \
                                          $(KHDR_INCLUDES) \
                                          -isystem $(top_srcdir)/include/uapi
 
-$(OUTPUT)/vdso_test_chacha: $(top_srcdir)/tools/arch/$(SRCARCH)/vdso/vgetrandom-chacha.S
+$(OUTPUT)/vdso_test_chacha: vgetrandom-chacha-finder.S
 $(OUTPUT)/vdso_test_chacha: CFLAGS += -idirafter $(top_srcdir)/tools/include \
                                       -idirafter $(top_srcdir)/tools/include/generated \
                                       -idirafter $(top_srcdir)/arch/$(SRCARCH)/include \
tools/testing/selftests/vDSO/vdso_test_chacha.c +6 -0
index 60c5ea5cb925..e68f1cd4ebcf 100644
@@ -78,6 +78,12 @@ typedef uint32_t u32;
 typedef uint64_t u64;
 #include <vdso/getrandom.h>
 
+__attribute__((weak))
+void __arch_chacha20_blocks_nostack(u8 *dst_bytes, const u32 *key, u32 *counter, size_t nblocks)
+{
+	ksft_exit_skip("Not implemented on architecture\n");
+}
+
 int main(int argc, char *argv[])
 {
 	enum { TRIALS = 1000, BLOCKS = 128, BLOCK_SIZE = 64 };
tools/testing/selftests/vDSO/vgetrandom-chacha-finder.S new file +16 -0
new file mode 100644
index 000000000000..1ca240ddaab7
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2024 Jason A. Donenfeld <[email protected]>. All Rights Reserved.
+ */
+
+#if defined(__aarch64__)
+#include "../../../../arch/arm64/kernel/vdso/vgetrandom-chacha.S"
+#elif defined(__loongarch__)
+#include "../../../../arch/loongarch/vdso/vgetrandom-chacha.S"
+#elif defined(__powerpc__) || defined(__powerpc64__)
+#include "../../../../arch/powerpc/kernel/vdso/vgetrandom-chacha.S"
+#elif defined(__s390x__)
+#include "../../../../arch/s390/kernel/vdso64/vgetrandom-chacha.S"
+#elif defined(__x86_64__)
+#include "../../../../arch/x86/entry/vdso/vgetrandom-chacha.S"
+#endif
Signature · 1 line
2.46.0
maintainer
#22 lore raw

Re: [PATCH kselftest v2 4/4] selftests: vDSO: unconditionally build chacha test

Quoted 16 lines · Jason A. Donenfeld

Rather than using symlinks to find the vgetrandom-chacha.S file for each arch, store this in a file that uses the compiler to determine architecture, and then make use of weak symbols to skip the test on architectures that don't provide the code.

---
  tools/arch/arm64/vdso                            |  1 -
  tools/arch/loongarch/vdso                        |  1 -
  tools/arch/powerpc/vdso                          |  1 -
  tools/arch/s390/vdso                             |  1 -
  tools/arch/x86/vdso                              |  1 -
  tools/testing/selftests/vDSO/Makefile            |  6 +-----
  tools/testing/selftests/vDSO/vdso_test_chacha.c  |  6 ++++++
  .../selftests/vDSO/vgetrandom-chacha-finder.S    | 16 ++++++++++++++++
  8 files changed, 23 insertions(+), 10 deletions(-)
Quoted 6 lines

delete mode 120000 tools/arch/arm64/vdso
delete mode 120000 tools/arch/loongarch/vdso
delete mode 120000 tools/arch/powerpc/vdso
delete mode 120000 tools/arch/s390/vdso
delete mode 120000 tools/arch/x86/vdso
create mode 100644 tools/testing/selftests/vDSO/vgetrandom-chacha-finder.S

Jason,

I am seeing a few checkpatch warnings on this patch. They are worth looking at.

WARNING: Prefer __weak over __attribute__((weak)) #176: FILE: tools/testing/selftests/vDSO/vdso_test_chacha.c:81:
+__attribute__((weak))

WARNING: Improper SPDX comment style for 'tools/testing/selftests/vDSO/vgetrandom-chacha-finder.S', please use '/*' instead #191: FILE: tools/testing/selftests/vDSO/vgetrandom-chacha-finder.S:1:
+// SPDX-License-Identifier: GPL-2.0

WARNING: Missing or malformed SPDX-License-Identifier tag in line 1 #191: FILE: tools/testing/selftests/vDSO/vgetrandom-chacha-finder.S:1:
+// SPDX-License-Identifier: GPL-2.0

thanks,
-- Shuah

#23 lore raw

PATCH v3 1/3 selftests: vDSO: unconditionally build chacha test

Rather than using symlinks to find the vgetrandom-chacha.S file for each arch, store this in a file that uses the compiler to determine architecture, and then make use of weak symbols to skip the test on architectures that don't provide the code.

---
 tools/arch/arm64/vdso                          |  1 -
 tools/arch/loongarch/vdso                      |  1 -
 tools/arch/powerpc/vdso                        |  1 -
 tools/arch/s390/vdso                           |  1 -
 tools/arch/x86/vdso                            |  1 -
 tools/testing/selftests/vDSO/Makefile          |  6 +++---
 .../testing/selftests/vDSO/vdso_test_chacha.c  |  9 +++++----
 .../testing/selftests/vDSO/vgetrandom-chacha.S | 18 ++++++++++++++++++
 8 files changed, 26 insertions(+), 12 deletions(-)
 delete mode 120000 tools/arch/arm64/vdso
 delete mode 120000 tools/arch/loongarch/vdso
 delete mode 120000 tools/arch/powerpc/vdso
 delete mode 120000 tools/arch/s390/vdso
 delete mode 120000 tools/arch/x86/vdso
 create mode 100644 tools/testing/selftests/vDSO/vgetrandom-chacha.S
tools/arch/arm64/vdso deleted +0 -1
deleted file mode 120000
index 233c7a26f6e5..000000000000
@@ -1 +0,0 @@
-../../../arch/arm64/kernel/vdso
\ No newline at end of file
tools/arch/loongarch/vdso deleted +0 -1
deleted file mode 120000
index ebda43a82db7..000000000000
@@ -1 +0,0 @@
-../../../arch/loongarch/vdso
\ No newline at end of file
tools/arch/powerpc/vdso deleted +0 -1
deleted file mode 120000
index 4e676d1d1cb4..000000000000
@@ -1 +0,0 @@
-../../../arch/powerpc/kernel/vdso
\ No newline at end of file
tools/arch/s390/vdso deleted +0 -1
deleted file mode 120000
index 6cf4c1cebdcd..000000000000
@@ -1 +0,0 @@
-../../../arch/s390/kernel/vdso64
\ No newline at end of file
tools/arch/x86/vdso deleted +0 -1
deleted file mode 120000
index 7eb962fd3454..000000000000
@@ -1 +0,0 @@
-../../../arch/x86/entry/vdso/
\ No newline at end of file
tools/testing/selftests/vDSO/Makefile +3 -3
index af9cedbf5357..45641386c662 100644
@@ -11,8 +11,8 @@ endif
 TEST_GEN_PROGS += vdso_test_correctness
 ifeq ($(ARCH)$(CONFIG_X86_32),$(filter $(ARCH)$(CONFIG_X86_32),x86 x86_64 loongarch arm64 powerpc s390))
 TEST_GEN_PROGS += vdso_test_getrandom
-TEST_GEN_PROGS += vdso_test_chacha
 endif
+TEST_GEN_PROGS += vdso_test_chacha
 
 CFLAGS := -std=gnu99 -O2
 
@@ -37,9 +37,9 @@ $(OUTPUT)/vdso_test_getrandom: CFLAGS += -isystem $(top_srcdir)/tools/include \
                                          $(KHDR_INCLUDES) \
                                          -isystem $(top_srcdir)/include/uapi
 
-$(OUTPUT)/vdso_test_chacha: $(top_srcdir)/tools/arch/$(SRCARCH)/vdso/vgetrandom-chacha.S
+$(OUTPUT)/vdso_test_chacha: vgetrandom-chacha.S
 $(OUTPUT)/vdso_test_chacha: CFLAGS += -idirafter $(top_srcdir)/tools/include \
                                       -idirafter $(top_srcdir)/tools/include/generated \
                                       -idirafter $(top_srcdir)/arch/$(SRCARCH)/include \
                                       -idirafter $(top_srcdir)/include \
-                                      -D__ASSEMBLY__ -Wa,--noexecstack
+                                      -Wa,--noexecstack
tools/testing/selftests/vDSO/vdso_test_chacha.c +5 -4
index b1ea532c5996..c66eb9df89bd 100644
@@ -3,6 +3,7 @@
  * Copyright (C) 2022-2024 Jason A. Donenfeld <[email protected]>. All Rights Reserved.
  */
 
+#include <linux/compiler.h>
 #include <tools/le_byteshift.h>
 #include <sys/random.h>
 #include <sys/auxv.h>
@@ -73,10 +74,10 @@ static void reference_chacha20_blocks(uint8_t *dst_bytes, const uint32_t *key, u
 	counter[1] = s[13];
 }
 
-typedef uint8_t u8;
-typedef uint32_t u32;
-typedef uint64_t u64;
-#include <vdso/getrandom.h>
+void __weak __arch_chacha20_blocks_nostack(uint8_t *dst_bytes, const uint32_t *key, uint32_t *counter, size_t nblocks)
+{
+	ksft_exit_skip("Not implemented on architecture\n");
+}
 
 int main(int argc, char *argv[])
 {
tools/testing/selftests/vDSO/vgetrandom-chacha.S new file +18 -0
new file mode 100644
index 000000000000..d6e09af7c0a9
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2024 Jason A. Donenfeld <[email protected]>. All Rights Reserved.
+ */
+
+#define __ASSEMBLY__
+
+#if defined(__aarch64__)
+#include "../../../../arch/arm64/kernel/vdso/vgetrandom-chacha.S"
+#elif defined(__loongarch__)
+#include "../../../../arch/loongarch/vdso/vgetrandom-chacha.S"
+#elif defined(__powerpc__) || defined(__powerpc64__)
+#include "../../../../arch/powerpc/kernel/vdso/vgetrandom-chacha.S"
+#elif defined(__s390x__)
+#include "../../../../arch/s390/kernel/vdso64/vgetrandom-chacha.S"
+#elif defined(__x86_64__)
+#include "../../../../arch/x86/entry/vdso/vgetrandom-chacha.S"
+#endif
Signature · 1 line
2.46.0
#24 lore raw

PATCH v3 2/3 selftests: vDSO: unconditionally build getrandom test

Rather than building on supported archs, build on all archs, and then use the presence of the symbol in the vDSO to either skip the test or move forward with it.

Note that this means that this test no longer checks whether the symbol was correctly added to the kernel. But hopefully this will be clear enough to developers and we'll cross our fingers that symbols aren't removed by accident and not caught after this change.

---
 tools/testing/selftests/vDSO/Makefile              | 2 --
 tools/testing/selftests/vDSO/vdso_test_getrandom.c | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)
tools/testing/selftests/vDSO/Makefile +0 -2
index 45641386c662..1cf14a8da438 100644
@@ -9,9 +9,7 @@ ifeq ($(ARCH),$(filter $(ARCH),x86 x86_64))
 TEST_GEN_PROGS += vdso_standalone_test_x86
 endif
 TEST_GEN_PROGS += vdso_test_correctness
-ifeq ($(ARCH)$(CONFIG_X86_32),$(filter $(ARCH)$(CONFIG_X86_32),x86 x86_64 loongarch arm64 powerpc s390))
 TEST_GEN_PROGS += vdso_test_getrandom
-endif
 TEST_GEN_PROGS += vdso_test_chacha
 
 CFLAGS := -std=gnu99 -O2
tools/testing/selftests/vDSO/vdso_test_getrandom.c +1 -1
index 72a1d9b43a84..5489a2f07434 100644
@@ -119,7 +119,7 @@ static void vgetrandom_init(void)
 	vgrnd.fn = (__typeof__(vgrnd.fn))vdso_sym(version, name);
 	if (!vgrnd.fn) {
 		printf("%s is missing!\n", name);
-		exit(KSFT_FAIL);
+		exit(KSFT_SKIP);
 	}
 	ret = VDSO_CALL(vgrnd.fn, 5, NULL, 0, 0, &vgrnd.params, ~0UL);
 	if (ret == -ENOSYS) {
Signature · 1 line
2.46.0
#25 lore raw

PATCH v3 3/3 selftests: vDSO: improve getrandom and chacha error messages

In reply to Jason A. Donenfeld

Improve the error and skip condition messages to let the developer know precisely where a test has failed. Also make better use of the ksft api for this.

---
 .../testing/selftests/vDSO/vdso_test_chacha.c | 27 ++++---
 .../selftests/vDSO/vdso_test_getrandom.c      | 75 ++++++++-----------
 2 files changed, 49 insertions(+), 53 deletions(-)
tools/testing/selftests/vDSO/vdso_test_chacha.c +16 -11
index c66eb9df89bd..8757f738b0b1 100644
@@ -91,10 +91,8 @@ int main(int argc, char *argv[])
 	ksft_set_plan(1);
 
 	for (unsigned int trial = 0; trial < TRIALS; ++trial) {
-		if (getrandom(key, sizeof(key), 0) != sizeof(key)) {
-			printf("getrandom() failed!\n");
-			return KSFT_SKIP;
-		}
+		if (getrandom(key, sizeof(key), 0) != sizeof(key))
+			ksft_exit_skip("getrandom() failed unexpectedly\n");
 		memset(counter1, 0, sizeof(counter1));
 		reference_chacha20_blocks(output1, key, counter1, BLOCKS);
 		for (unsigned int split = 0; split < BLOCKS; ++split) {
@@ -103,8 +101,10 @@ int main(int argc, char *argv[])
 			if (split)
 				__arch_chacha20_blocks_nostack(output2, key, counter2, split);
 			__arch_chacha20_blocks_nostack(output2 + split * BLOCK_SIZE, key, counter2, BLOCKS - split);
-			if (memcmp(output1, output2, sizeof(output1)) || memcmp(counter1, counter2, sizeof(counter1)))
-				return KSFT_FAIL;
+			if (memcmp(output1, output2, sizeof(output1)))
+				ksft_exit_fail_msg("Main loop outputs do not match on trial %u, split %u\n", trial, split);
+			if (memcmp(counter1, counter2, sizeof(counter1)))
+				ksft_exit_fail_msg("Main loop counters do not match on trial %u, split %u\n", trial, split);
 		}
 	}
 	memset(counter1, 0, sizeof(counter1));
@@ -114,14 +114,19 @@ int main(int argc, char *argv[])
 
 	reference_chacha20_blocks(output1, key, counter1, BLOCKS);
 	__arch_chacha20_blocks_nostack(output2, key, counter2, BLOCKS);
-	if (memcmp(output1, output2, sizeof(output1)) || memcmp(counter1, counter2, sizeof(counter1)))
-		return KSFT_FAIL;
+	if (memcmp(output1, output2, sizeof(output1)))
+		ksft_exit_fail_msg("Block limit outputs do not match after first round\n");
+	if (memcmp(counter1, counter2, sizeof(counter1)))
+		ksft_exit_fail_msg("Block limit counters do not match after first round\n");
 
 	reference_chacha20_blocks(output1, key, counter1, BLOCKS);
 	__arch_chacha20_blocks_nostack(output2, key, counter2, BLOCKS);
-	if (memcmp(output1, output2, sizeof(output1)) || memcmp(counter1, counter2, sizeof(counter1)))
-		return KSFT_FAIL;
+	if (memcmp(output1, output2, sizeof(output1)))
+		ksft_exit_fail_msg("Block limit outputs do not match after second round\n");
+	if (memcmp(counter1, counter2, sizeof(counter1)))
+		ksft_exit_fail_msg("Block limit counters do not match after second round\n");
 
 	ksft_test_result_pass("chacha: PASS\n");
-	return KSFT_PASS;
+	ksft_exit_pass();
+	return 0;
 }
tools/testing/selftests/vDSO/vdso_test_getrandom.c +33 -42

165 lines not on this page · raw message

Signature · 1 line
2.46.0
maintainer
#26 lore raw

Re: [PATCH kselftest v3 1/3] selftests: vDSO: unconditionally build chacha test

In reply to Jason A. Donenfeld
Quoted 7 lines · Jason A. Donenfeld

Rather than using symlinks to find the vgetrandom-chacha.S file for each arch, store this in a file that uses the compiler to determine architecture, and then make use of weak symbols to skip the test on architectures that don't provide the code.

---

Thank you.

Applied all three patches to linux-kselftest fixes and will include them in my next pull request for rc3.

thanks,
-- Shuah

#27 lore raw

[PATCH kselftest 4/3] selftests: vDSO: unconditionally build chacha test

In reply to Jason A. Donenfeld

Rather than using symlinks to find the vgetrandom-chacha.S file for each arch, store this in a file that uses the compiler to determine architecture, and then make use of weak symbols to skip the test on architectures that don't provide the code.

---
 tools/arch/arm64/vdso                            |  1 -
 tools/arch/loongarch/vdso                        |  1 -
 tools/arch/powerpc/vdso                          |  1 -
 tools/arch/s390/vdso                             |  1 -
 tools/arch/x86/vdso                              |  1 -
 tools/testing/selftests/vDSO/Makefile            |  6 +-----
 tools/testing/selftests/vDSO/vdso_test_chacha.c  |  6 ++++++
 .../selftests/vDSO/vgetrandom-chacha-finder.S    | 16 ++++++++++++++++
 8 files changed, 23 insertions(+), 10 deletions(-)
 delete mode 120000 tools/arch/arm64/vdso
 delete mode 120000 tools/arch/loongarch/vdso
 delete mode 120000 tools/arch/powerpc/vdso
 delete mode 120000 tools/arch/s390/vdso
 delete mode 120000 tools/arch/x86/vdso
 create mode 100644 tools/testing/selftests/vDSO/vgetrandom-chacha-finder.S
tools/arch/arm64/vdso deleted +0 -1
deleted file mode 120000
index 233c7a26f6e5..000000000000
@@ -1 +0,0 @@
-../../../arch/arm64/kernel/vdso
\ No newline at end of file
tools/arch/loongarch/vdso deleted +0 -1
deleted file mode 120000
index ebda43a82db7..000000000000
@@ -1 +0,0 @@
-../../../arch/loongarch/vdso
\ No newline at end of file
tools/arch/powerpc/vdso deleted +0 -1
deleted file mode 120000
index 4e676d1d1cb4..000000000000
@@ -1 +0,0 @@
-../../../arch/powerpc/kernel/vdso
\ No newline at end of file
tools/arch/s390/vdso deleted +0 -1
deleted file mode 120000
index 6cf4c1cebdcd..000000000000
@@ -1 +0,0 @@
-../../../arch/s390/kernel/vdso64
\ No newline at end of file
tools/arch/x86/vdso deleted +0 -1
deleted file mode 120000
index 7eb962fd3454..000000000000
@@ -1 +0,0 @@
-../../../arch/x86/entry/vdso/
\ No newline at end of file
tools/testing/selftests/vDSO/Makefile +1 -5
index 96b4f2a766e2..e453c178d97f 100644
@@ -1,6 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 include ../../../scripts/Makefile.arch
-top_srcdir = $(realpath ../../../..)
 
 TEST_GEN_PROGS := vdso_test_gettimeofday
 TEST_GEN_PROGS += vdso_test_getcpu
@@ -11,15 +10,12 @@ TEST_GEN_PROGS += vdso_standalone_test_x86
 endif
 TEST_GEN_PROGS += vdso_test_correctness
 TEST_GEN_PROGS += vdso_test_getrandom
-ifneq ($(wildcard $(top_srcdir)/tools/arch/$(SRCARCH)/vdso/vgetrandom-chacha.S),)
 TEST_GEN_PROGS += vdso_test_chacha
-endif
 
 CFLAGS := -std=gnu99 -O2
 
 ifeq ($(CONFIG_X86_32),y)
 LDLIBS += -lgcc_s
-TEST_GEN_PROGS := $(filter-out vdso_test_chacha,$(TEST_GEN_PROGS))
 endif
 
 include ../lib.mk
@@ -39,7 +35,7 @@ $(OUTPUT)/vdso_test_getrandom: CFLAGS += -isystem $(top_srcdir)/tools/include \
                                          $(KHDR_INCLUDES) \
                                          -isystem $(top_srcdir)/include/uapi
 
-$(OUTPUT)/vdso_test_chacha: $(top_srcdir)/tools/arch/$(SRCARCH)/vdso/vgetrandom-chacha.S
+$(OUTPUT)/vdso_test_chacha: vgetrandom-chacha-finder.S
 $(OUTPUT)/vdso_test_chacha: CFLAGS += -idirafter $(top_srcdir)/tools/include \
                                       -idirafter $(top_srcdir)/tools/include/generated \
                                       -idirafter $(top_srcdir)/arch/$(SRCARCH)/include \
tools/testing/selftests/vDSO/vdso_test_chacha.c +6 -0
index 60c5ea5cb925..e68f1cd4ebcf 100644
@@ -78,6 +78,12 @@ typedef uint32_t u32;
 typedef uint64_t u64;
 #include <vdso/getrandom.h>
 
+__attribute__((weak))
+void __arch_chacha20_blocks_nostack(u8 *dst_bytes, const u32 *key, u32 *counter, size_t nblocks)
+{
+	ksft_exit_skip("Not implemented on architecture\n");
+}
+
 int main(int argc, char *argv[])
 {
 	enum { TRIALS = 1000, BLOCKS = 128, BLOCK_SIZE = 64 };
tools/testing/selftests/vDSO/vgetrandom-chacha-finder.S new file +16 -0
new file mode 100644
index 000000000000..1ca240ddaab7
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2024 Jason A. Donenfeld <[email protected]>. All Rights Reserved.
+ */
+
+#if defined(__aarch64__)
+#include "../../../../arch/arm64/kernel/vdso/vgetrandom-chacha.S"
+#elif defined(__loongarch__)
+#include "../../../../arch/loongarch/vdso/vgetrandom-chacha.S"
+#elif defined(__powerpc__) || defined(__powerpc64__)
+#include "../../../../arch/powerpc/kernel/vdso/vgetrandom-chacha.S"
+#elif defined(__s390x__)
+#include "../../../../arch/s390/kernel/vdso64/vgetrandom-chacha.S"
+#elif defined(__x86_64__)
+#include "../../../../arch/x86/entry/vdso/vgetrandom-chacha.S"
+#endif
Signature · 1 line
2.46.0
maintainer
#28 lore raw

Re: [PATCH kselftest 0/3] getrandom & chacha cleanups

In reply to Jason A. Donenfeld
Quoted 18 lines · Jason A. Donenfeld

Hi Shuah,

I've now read your email several times trying to figure out what you meant and what your objections are. This series is my best attempt at trying to satisfy that. But my understanding still has a lot of question marks, so I may have missed your point here. Nonetheless, maybe this moves things forward a bit.

Jason

Cc Shuah Khan <[email protected]>
Cc Greg KH <[email protected]>

Jason A. Donenfeld (3):
selftests: vDSO: condition chacha build on chacha implementation
selftests: vDSO: unconditionally build getrandom test
selftests: vDSO: improve getrandom and chacha error messages

Quoted 5 lines
  tools/testing/selftests/vDSO/Makefile         |  4 +-
  .../testing/selftests/vDSO/vdso_test_chacha.c | 27 ++++---
  .../selftests/vDSO/vdso_test_getrandom.c      | 75 ++++++++-----------
  3 files changed, 52 insertions(+), 54 deletions(-)

Thank you Jason for fixing the problem. The patches look good to me. I will run some tests and apply all 4 patches for next rc.

I did review the 4th patch as well.
https://patchwork.kernel.org/project/linux-kselftest/patch/[email protected]/

than

maintainer
#29 lore raw
In reply to Jason A. Donenfeld
Quoted 7 lines · Jason A. Donenfeld
Quoted 6 lines · Shuah Khan

This is not different from other kernel APIs and enhancements and correspo0nding updates to the existing selftests.

The
vdso_test_getrandom test a user-space program exists in 6.11.

Quoted 7 lines
Quoted 5 lines

Use should be able to run vdso_test_getrandom compiled on 6.12 repo on a 6.11 kernel.
vdso_test_getrandom test a user-space program exists in 6.11. Users should be able to run vdso_test_getrandom compiled on 6.12 repo on a 6.11 kernel. This is what several CIs do.

The x86 test from 6.12 works just fine on 6.11.

Yes x86 test is a good example to look at that handles 32-bit and 640-bit issues you brought up in your email.

That is reason why I asked you to refer to x86 Makefile to solve the architecture differences related to this test you mentioned in your email.

Quoted 5 lines

I really don't follow you at all or what you're getting at. I think if you actually look at the code, you'll be mostly okay with it. And if there's something that looks awry to you, send a patch or describe to me clearly what looks wrong and I'll send a patch.

To be very clear about the selftest guidelines (covered in kselftest.rst document)

1. Ideally selftests should compile on all architectures. Exception to this are few architecture specific features which can be selectively compiled either with ifdef statements in the code or Makefile arch checks.

The goal is to keep these to a minimum so we can a wide range of tests in CIs and other test systems.

2. Selftest from mainline should run on stable releases handling missing features and missing config options with skip so we don't have to deal false failures.

The goal is to minimize false negatives and false positives.

3. Reported results are clear to the users and testers.

Thank you for the patches. I will review your patches and give you feedback.

thanks,
-- Shuah

#30 lore raw
Quoted 4 lines · Shuah Khan
Quoted 1 line

The x86 test from 6.12 works just fine on 6.11.

Yes x86 test is a good example to look at that handles 32-bit and 640-bit issues you brought up in your email.

The x86 test is only for 64-bit. It doesn't get compiled on 32-bit. That changes in the series I attached.

Quoted 5 lines

1. Ideally selftests should compile on all architectures. Exception to this are few architecture specific features which can be selectively compiled either with ifdef statements in the code or Makefile arch checks.

The thing is, this *is* a test with an architecture-specific feature:
it's not available on all archs, especially not 32-bit ones. There's the workaround (in the attached series) that I think might help things. But for the chacha one, it just won't compile on systems that lack the implementation.

Quoted 3 lines

2. Selftest from mainline should run on stable releases handling missing features and missing config options with skip so we don't have to deal false failures.

Noted. I would like to point out, though, that this is the "opposite" stability guarantee that Linux usually offers of old binaries working on new systems. You want new binaries working on old systems.

Quoted 1 line

3. Reported results are clear to the users and testers.

Patch 3/3 fixes this up.

Quoted 2 lines

Thank you for the patches. I will review your patches and give you feedback.

Great, okay. I think the series matches your expectations.

I have additional ideas too for the chacha test, if you think it's necessary to go further, but maybe things are good enough now.

Jason