From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A66BCD6E74 for ; Thu, 5 Sep 2024 17:16:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9B116B008C; Thu, 5 Sep 2024 13:16:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A54DF6B0093; Thu, 5 Sep 2024 13:16:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C4F66B0095; Thu, 5 Sep 2024 13:16:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6ADBE6B008C for ; Thu, 5 Sep 2024 13:16:31 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 21F1B40721 for ; Thu, 5 Sep 2024 17:16:31 +0000 (UTC) X-FDA: 82531338582.22.17A3D8A Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf21.hostedemail.com (Postfix) with ESMTP id E45761C0018 for ; Thu, 5 Sep 2024 17:16:28 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=zx2c4.com header.s=20210105 header.b=hCjAgG29; spf=pass (imf21.hostedemail.com: domain of "SRS0=ehJl=QD=zx2c4.com=Jason@kernel.org" designates 147.75.193.91 as permitted sender) smtp.mailfrom="SRS0=ehJl=QD=zx2c4.com=Jason@kernel.org"; dmarc=pass (policy=quarantine) header.from=zx2c4.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725556512; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=U/i7kxMFedYKvorYnbQF73cn+5NdhIM30ISsp20UbHg=; b=751Sm0FPdBi3e0+IGCf/8rxkNUNT1PPF7+tEUQ0NzPE/amRuW/hECsz043xDxxWYQaGVSr yDYZQcke0+IWai1RHUpxKFmNNxQpCbHKJ+PHSUcl9nCljzc8lYx4iTkEQ/kebgs7SLxRLa DMYsFwCUgQOd5cZaBIYd/0YPaVky05I= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=zx2c4.com header.s=20210105 header.b=hCjAgG29; spf=pass (imf21.hostedemail.com: domain of "SRS0=ehJl=QD=zx2c4.com=Jason@kernel.org" designates 147.75.193.91 as permitted sender) smtp.mailfrom="SRS0=ehJl=QD=zx2c4.com=Jason@kernel.org"; dmarc=pass (policy=quarantine) header.from=zx2c4.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725556512; a=rsa-sha256; cv=none; b=rj9JcKNZS8Hd7T/eS40OYXNsx8vvrvgKCEeWbK6HNlf6vBTrWg0VREK6C/KUYxWNmVafzh mlM3dVWhwuO6d1bO9D9y1m9FP4zVc81yBhZU4s+5UJabIQtgmzpx2Kom4bKR1rZJ/YCpDv 0YTyFA9AIgjlGaRQ/Mm3hFYjUFGMg9M= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id EFB4BA44E2F; Thu, 5 Sep 2024 17:16:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0216CC4CEC3; Thu, 5 Sep 2024 17:16:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1725556584; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U/i7kxMFedYKvorYnbQF73cn+5NdhIM30ISsp20UbHg=; b=hCjAgG292GvjSYLd7cIJbV9+sE37uAJnudlmH79DWrvxKhI1aT+MkTsEmZIqTXhYJC3AjG GKu0T3GOiKFo6Gd/ZQwz0mjJ7G8jNN7vZoXVVqlMX+NTR4p/v66KLBzSg7LZ0ZRymTcpi5 z8NptxebJrjClHLK2svu5ZYfVCDOfJ0= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id c27291d3 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 5 Sep 2024 17:16:24 +0000 (UTC) Date: Thu, 5 Sep 2024 19:16:20 +0200 From: "Jason A. Donenfeld" To: Christophe Leroy Cc: Andrew Morton , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Shuah Khan , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kselftest@vger.kernel.org, llvm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, Adhemerval Zanella , Xi Ruoyao Subject: Re: [PATCH v5 4/5] powerpc/vdso: Wire up getrandom() vDSO implementation on VDSO32 Message-ID: References: <1f49c2ce009f8b007ab0676fb41187b2d54f28b2.1725304404.git.christophe.leroy@csgroup.eu> <85c02620-e8b2-4c97-9905-685a9a4e556d@csgroup.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Stat-Signature: cnwwd9bbmmaf16f6j8sx5gzapbc9kft4 X-Rspam-User: X-Rspamd-Queue-Id: E45761C0018 X-Rspamd-Server: rspam02 X-HE-Tag: 1725556588-339521 X-HE-Meta: U2FsdGVkX19oAC5eAF0+b2KlazwBmARsp8/eTgl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Gj0BebXY0F5c5gj8WV8wSmWHmeKPKUPh2PJM4n+Freh9MSrnifJXlY0MdEA2veZS/3XwGj7HnzjJOTlTGgB1kGsH7AsIr8HIXDiLCDV08AR8/LcaXgVAyUAZGZP9SF2nWJgwGCVrBUWR+UcztYuDXfCS8tYkl8ud5tZKfPivSahwZqzfadNlESQa6vrzi+hjm2dcdY4IfX6rjz1u7LODNIGFr1+XBHzTCoznufefeD/84PV6NIFELZNV6pT1dW+k/+GmhUsG9hMrQgdXTc+9b28ENjlbqcQ4VFEK021ZIgaE1CmQU7laNXU3sbcqJXk/PQcLYPK5QkMU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 #include #include +#include +#include #include #include +#include #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); }