Re: [PATCH v5 4/5] powerpc/vdso: Wire up getrandom() vDSO implementation on VDSO32

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 05, 2024 at 07:03:34PM +0200, Jason A. Donenfeld wrote:
> On Thu, Sep 05, 2024 at 06:55:27PM +0200, Christophe Leroy wrote:
> > 
> > 
> > Le 05/09/2024 à 18:13, Jason A. Donenfeld a écrit :
> > >> +/*
> > >> + * The macro sets two stack frames, one for the caller and one for the callee
> > >> + * because there are no requirement for the caller to set a stack frame when
> > >> + * calling VDSO so it may have omitted to set one, especially on PPC64
> > >> + */
> > >> +
> > >> +.macro cvdso_call funct
> > >> +  .cfi_startproc
> > >> +	PPC_STLU	r1, -PPC_MIN_STKFRM(r1)
> > >> +  .cfi_adjust_cfa_offset PPC_MIN_STKFRM
> > >> +	mflr		r0
> > >> +	PPC_STLU	r1, -PPC_MIN_STKFRM(r1)
> > >> +  .cfi_adjust_cfa_offset PPC_MIN_STKFRM
> > >> +	PPC_STL		r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1)
> > >> +  .cfi_rel_offset lr, PPC_MIN_STKFRM + PPC_LR_STKOFF
> > >> +	get_datapage	r8
> > >> +	addi		r8, r8, VDSO_RNG_DATA_OFFSET
> > >> +	bl		CFUNC(DOTSYM(\funct))
> > >> +	PPC_LL		r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1)
> > >> +	cmpwi		r3, 0
> > >> +	mtlr		r0
> > >> +	addi		r1, r1, 2 * PPC_MIN_STKFRM
> > >> +  .cfi_restore lr
> > >> +  .cfi_def_cfa_offset 0
> > >> +	crclr		so
> > >> +	bgelr+
> > >> +	crset		so
> > >> +	neg		r3, r3
> > >> +	blr
> > >> +  .cfi_endproc
> > >> +.endm
> > > 
> > > You wrote in an earlier email that this worked with time namespaces, but
> > > in my testing that doesn't seem to be the case.
> > 
> > Did I write that ? I can't remember and neither can I remember testing 
> > it with time namespaces.
> 
> It's possible I confused you with someone else? Hum. Anyway...
> 
> > >  From my test harness [1]:
> > > 
> > > Normal single thread
> > >     vdso: 25000000 times in 12.494133131 seconds
> > >     libc: 25000000 times in 69.594625188 seconds
> > > syscall: 25000000 times in 67.349243972 seconds
> > > Time namespace single thread
> > >     vdso: 25000000 times in 71.673057436 seconds
> > >     libc: 25000000 times in 71.712774121 seconds
> > > syscall: 25000000 times in 66.902318080 seconds
> > > 
> > > I'm seeing this on ppc, ppc64, and ppc64le.
> > 
> > What is the command to use to test with time namespace ?
> 
> Look at the C in the commit I linked.

The below also seems to work well for testing on x86. I'll clean that up
and send a patch to the list.

diff --git a/tools/testing/selftests/vDSO/vdso_test_getrandom.c b/tools/testing/selftests/vDSO/vdso_test_getrandom.c
index 8866b65a4605..4df80f769aa7 100644
--- a/tools/testing/selftests/vDSO/vdso_test_getrandom.c
+++ b/tools/testing/selftests/vDSO/vdso_test_getrandom.c
@@ -16,8 +16,11 @@
 #include <sys/mman.h>
 #include <sys/random.h>
 #include <sys/syscall.h>
+#include <sys/ptrace.h>
+#include <sys/wait.h>
 #include <sys/types.h>
 #include <linux/random.h>
+#include <linux/ptrace.h>

 #include "../kselftest.h"
 #include "parse_vdso.h"
@@ -239,9 +242,10 @@ static void fill(void)
 static void kselftest(void)
 {
 	uint8_t weird_size[1263];
+	pid_t child;

 	ksft_print_header();
-	ksft_set_plan(1);
+	ksft_set_plan(2);

 	for (size_t i = 0; i < 1000; ++i) {
 		ssize_t ret = vgetrandom(weird_size, sizeof(weird_size), 0);
@@ -250,6 +254,39 @@ static void kselftest(void)
 	}

 	ksft_test_result_pass("getrandom: PASS\n");
+
+	assert(unshare(CLONE_NEWTIME) == 0);
+	child = fork();
+	assert(child >= 0);
+
+	if (!child) {
+		vgetrandom_init();
+		child = getpid();
+		assert(ptrace(PTRACE_TRACEME, 0, NULL, NULL) == 0);
+		assert(kill(child, SIGSTOP) == 0);
+		assert(vgetrandom(weird_size, sizeof(weird_size), 0) == sizeof(weird_size));
+		_exit(0);
+	}
+	for (;;) {
+		struct ptrace_syscall_info info = { 0 };
+		int status, ret;
+		assert(waitpid(child, &status, 0) >= 0);
+		if (WIFEXITED(status))
+			break;
+		assert(WIFSTOPPED(status));
+		if (WSTOPSIG(status) == SIGSTOP)
+			assert(ptrace(PTRACE_SETOPTIONS, child, 0, PTRACE_O_TRACESYSGOOD) == 0);
+		else if (WSTOPSIG(status) == SIGTRAP | 0x80) {
+			assert(ptrace(PTRACE_GET_SYSCALL_INFO, child, sizeof(info), &info) > 0);
+			if (info.entry.nr == __NR_getrandom &&
+			    ((void *)info.entry.args[0] == &weird_size && info.entry.args[1] == sizeof(weird_size)))
+				exit(KSFT_FAIL);
+		}
+		assert(ptrace(PTRACE_SYSCALL, child, 0, 0) == 0);
+	}
+
+	ksft_test_result_pass("getrandom timens: PASS\n");
+
 	exit(KSFT_PASS);
 }





[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux