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 A0DC6C19776 for ; Fri, 28 Feb 2025 12:31:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 465F328001A; Fri, 28 Feb 2025 07:31:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3EF26280001; Fri, 28 Feb 2025 07:31:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26A5B28001A; Fri, 28 Feb 2025 07:31:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0C699280001 for ; Fri, 28 Feb 2025 07:31:27 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 22E984C25B for ; Fri, 28 Feb 2025 12:31:26 +0000 (UTC) X-FDA: 83169288972.15.BFD6CEA Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf07.hostedemail.com (Postfix) with ESMTP id 5D0F14000E for ; Fri, 28 Feb 2025 12:31:24 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf07.hostedemail.com: domain of vincenzo.frascino@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=vincenzo.frascino@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740745884; a=rsa-sha256; cv=none; b=dlCjzq0IBXqz5FIYSOJdXEjjOx04pswiPWIGIOWcb8GWr7FZ8u90S14G5Iw8TaCC/fhZJm wZ6whVt3H9M0iRL5O1NefdD/VzpUfeSWR9v6wdFmmF90d9G87uUVRZSoOrq1XHvf2onPU/ uS0lppHajiDQt5sWS/9rjl01TEWMKQs= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf07.hostedemail.com: domain of vincenzo.frascino@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=vincenzo.frascino@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740745884; 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; bh=H0pGZvxdLpTvE4z1I0vr7X2F0eBGVvBI2nCtRRhCmbI=; b=qO7vYqfS0DMHA9KAsk1Xk4SyMtD2T66NkOCKZ1i1OtfZYTPks8dKkxPwxgUOHKAMZieoo8 tU9xPDJ23H+sDhWxeSJp+dhg2lrYG4iYGliLPynfrACaW4nfnZEIHSRh2zLjMZAhMozjzV nHvHX81TBaHBAZBW/qrXVIAbCkDZdsw= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F14D61688; Fri, 28 Feb 2025 04:31:38 -0800 (PST) Received: from [10.1.196.72] (e119884-lin.cambridge.arm.com [10.1.196.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 55F913F6A8; Fri, 28 Feb 2025 04:31:21 -0800 (PST) Message-ID: <1dbfc2fa-2b40-497f-8588-d04d0d88c5f2@arm.com> Date: Fri, 28 Feb 2025 12:31:19 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 16/16] selftests: vDSO: vdso_standalone_test_x86: Switch to nolibc To: =?UTF-8?Q?Thomas_Wei=C3=9Fschuh?= , Kees Cook , Eric Biederman , Shuah Khan , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andy Lutomirski , Thomas Gleixner , Willy Tarreau , =?UTF-8?Q?Thomas_Wei=C3=9Fschuh?= Cc: "Jason A. Donenfeld" , Christophe Leroy , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, llvm@lists.linux.dev References: <20250226-parse_vdso-nolibc-v2-0-28e14e031ed8@linutronix.de> <20250226-parse_vdso-nolibc-v2-16-28e14e031ed8@linutronix.de> Content-Language: en-US From: Vincenzo Frascino In-Reply-To: <20250226-parse_vdso-nolibc-v2-16-28e14e031ed8@linutronix.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 5D0F14000E X-Stat-Signature: zbhxc5748i88q9fdkntiiuup9d4jh7yk X-HE-Tag: 1740745884-425123 X-HE-Meta: U2FsdGVkX1+V3wwdLqzWsHEQ+tci0CqDyca0egcOVOgggCdDIsyLAxhC5TioQ0To+ehR7pv3uy90CbTRR3iYlWtHEMT9rv6mMhCkD+uowgWThoq0bl6q6uo6jQFORqILRvLoUUhdcE3/Vzwrln/D2fK83eKurE6H1LpdBKozqUYg4Z0oYPmILTAnQFxQ5s0KAe6LSEf2tM4tPRRTRM7h0A8UMYSSrKAuArsUlLHmgFecIz3DCv0cWNROeTUguRURW5E1xzx/wXgu+wQkFl5DKxlwcKruzSMWIkSbV0s6ue5Vq+fnBaY+Z2TpnO3Dcg8yEKgRewPSrYT1g5DyIP+UFeCeFZP/3CL2RFm572Vhciu8W8bMGok55XMGnISXfpkfhiFVT65yvDLROzelcDb/3aRDCl69TH2+Rvw04uWwtsfzyDgsU1UbD8509+9RehmRaxgTseqx+RxOe8i6QBm2BMhJUs1Xrj9FmNuTyoO9lBr/hL5vLpcjZW4KA8Teopsqn2hWgicx4kYyXOeYsml64ouh1aAwmB0owfFWpdwYuc0vQ+V8XS6Ctjy+3R6amiTbJtlI/B8CdqLUK069x4hj0swuy4yo6frUQclkU+1VR1Hi8YxpuYXrFMJM+01JpWB/hY2maL8uqXE6kZjW1D1QsbxW47wgbug2e9hYwCJNFJcViXwa1zFoG5LwZpPbguwRtH7pidNkFENCNx3qc0Pw4BsaOd1/Qz8+xVhRL9MiZz538m+HDGKTf3fLlW43ApVahZLvXG1oZ2ugpZXknNxcnJT/Wq+Pr1idHbhPQczzQAMvP4yPDpqsG5VvF3Bnky027iT2muthJ9m3eQryhUefN4uCwyccO7HmHyNnBoktR/jDfGVZxWXKiglH48h8CIGuDzv5nsQOZ+RVi/ZWNb4f0zs3XcGydinsejNsKFgfW3Gt22AW8awtLLeo1w2zhsqb5faHdt45+Ouz7zCdM8H BqNSppoZ nAjfl49Zl55bGAiRvMJVyX6EToXQ/fTX94eFfUtWN1PSbXghmxIHqgBHIhh0uc04FpXzQ9bdcCq3RIDMQTE6stV4yuH+sTeljzSk+EPokiO+cQUZpKnx16OfkDmCG3NIPdbs4TS0zDHK4I+QjC6eEmlztn7wREFV+6NyqH7RX/o1ocpOG6N6Et/Sgm+PqZjGa9t3styOtKvz2BYS5CLqvr1iTH4RO6UaKj85FgXXIP+6zTSWbIH2h/KFHYpZPs8lkcDHNRcV/VBfzSUlao10WVA2NfgxKz1PvHqT+2hgONZQcS5CcxcXHf/UKKg== 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 26/02/2025 11:44, Thomas Weißschuh wrote: > vdso_standalone_test_x86 provides its own ASM syscall wrappers and > _start() implementation. The in-tree nolibc library already provides > this functionality for multiple architectures. By making use of nolibc, > the standalone testcase can be built from the exact same codebase as the > non-standalone version. > > Signed-off-by: Thomas Weißschuh Reviewed-by: Vincenzo Frascino > --- > tools/testing/selftests/vDSO/Makefile | 8 +- > .../selftests/vDSO/vdso_standalone_test_x86.c | 168 +-------------------- > 2 files changed, 7 insertions(+), 169 deletions(-) > > diff --git a/tools/testing/selftests/vDSO/Makefile b/tools/testing/selftests/vDSO/Makefile > index bc8ca186fb877dc11740c37f1e07e45e84c2ae92..12a0614b9fd4983deffe5d6a7cfa06ba8d92a516 100644 > --- a/tools/testing/selftests/vDSO/Makefile > +++ b/tools/testing/selftests/vDSO/Makefile > @@ -22,13 +22,17 @@ include ../lib.mk > > CFLAGS += $(TOOLS_INCLUDES) > > +CFLAGS_NOLIBC := -nostdlib -nostdinc -ffreestanding -fno-asynchronous-unwind-tables \ > + -fno-stack-protector -include $(top_srcdir)/tools/include/nolibc/nolibc.h \ > + -I$(top_srcdir)/tools/include/nolibc/ $(KHDR_INCLUDES) > + > $(OUTPUT)/vdso_test_gettimeofday: parse_vdso.c vdso_test_gettimeofday.c > $(OUTPUT)/vdso_test_getcpu: parse_vdso.c vdso_test_getcpu.c > $(OUTPUT)/vdso_test_abi: parse_vdso.c vdso_test_abi.c > $(OUTPUT)/vdso_test_clock_getres: vdso_test_clock_getres.c > > -$(OUTPUT)/vdso_standalone_test_x86: vdso_standalone_test_x86.c parse_vdso.c > -$(OUTPUT)/vdso_standalone_test_x86: CFLAGS +=-nostdlib -fno-asynchronous-unwind-tables -fno-stack-protector > +$(OUTPUT)/vdso_standalone_test_x86: vdso_standalone_test_x86.c parse_vdso.c | headers > +$(OUTPUT)/vdso_standalone_test_x86: CFLAGS:=$(CFLAGS_NOLIBC) $(CFLAGS) > > $(OUTPUT)/vdso_test_correctness: vdso_test_correctness.c > $(OUTPUT)/vdso_test_correctness: LDFLAGS += -ldl > diff --git a/tools/testing/selftests/vDSO/vdso_standalone_test_x86.c b/tools/testing/selftests/vDSO/vdso_standalone_test_x86.c > deleted file mode 100644 > index 500608f89c66b5747e3d845ebc54e4c3a35b6ccd..0000000000000000000000000000000000000000 > --- a/tools/testing/selftests/vDSO/vdso_standalone_test_x86.c > +++ /dev/null > @@ -1,167 +0,0 @@ > -// SPDX-License-Identifier: GPL-2.0-only > -/* > - * vdso_test.c: Sample code to test parse_vdso.c on x86 > - * Copyright (c) 2011-2014 Andy Lutomirski > - * > - * You can amuse yourself by compiling with: > - * gcc -std=gnu99 -nostdlib > - * -Os -fno-asynchronous-unwind-tables -flto -lgcc_s > - * vdso_standalone_test_x86.c parse_vdso.c > - * to generate a small binary. On x86_64, you can omit -lgcc_s > - * if you want the binary to be completely standalone. > - */ > - > -#include > -#include > -#include > -#include > -#include > - > -#include "parse_vdso.h" > - > -/* We need some libc functions... */ > -int strcmp(const char *a, const char *b) > -{ > - /* This implementation is buggy: it never returns -1. */ > - while (*a || *b) { > - if (*a != *b) > - return 1; > - if (*a == 0 || *b == 0) > - return 1; > - a++; > - b++; > - } > - > - return 0; > -} > - > -/* > - * The clang build needs this, although gcc does not. > - * Stolen from lib/string.c. > - */ > -void *memcpy(void *dest, const void *src, size_t count) > -{ > - char *tmp = dest; > - const char *s = src; > - > - while (count--) > - *tmp++ = *s++; > - return dest; > -} > - > -/* ...and two syscalls. This is x86-specific. */ > -static inline long x86_syscall3(long nr, long a0, long a1, long a2) > -{ > - long ret; > -#ifdef __x86_64__ > - asm volatile ("syscall" : "=a" (ret) : "a" (nr), > - "D" (a0), "S" (a1), "d" (a2) : > - "cc", "memory", "rcx", > - "r8", "r9", "r10", "r11" ); > -#else > - asm volatile ("int $0x80" : "=a" (ret) : "a" (nr), > - "b" (a0), "c" (a1), "d" (a2) : > - "cc", "memory" ); > -#endif > - return ret; > -} > - > -static inline long linux_write(int fd, const void *data, size_t len) > -{ > - return x86_syscall3(__NR_write, fd, (long)data, (long)len); > -} > - > -static inline void linux_exit(int code) > -{ > - x86_syscall3(__NR_exit, code, 0, 0); > -} > - > -void to_base10(char *lastdig, time_t n) > -{ > - while (n) { > - *lastdig = (n % 10) + '0'; > - n /= 10; > - lastdig--; > - } > -} > - > -unsigned long getauxval(const unsigned long *auxv, unsigned long type) > -{ > - unsigned long ret; > - > - if (!auxv) > - return 0; > - > - while (1) { > - if (!auxv[0] && !auxv[1]) { > - ret = 0; > - break; > - } > - > - if (auxv[0] == type) { > - ret = auxv[1]; > - break; > - } > - > - auxv += 2; > - } > - > - return ret; > -} > - > -void c_main(void **stack) > -{ > - /* Parse the stack */ > - long argc = (long)*stack; > - stack += argc + 2; > - > - /* Now we're pointing at the environment. Skip it. */ > - while(*stack) > - stack++; > - stack++; > - > - /* Now we're pointing at auxv. Initialize the vDSO parser. */ > - vdso_init_from_sysinfo_ehdr(getauxval((unsigned long *)stack, AT_SYSINFO_EHDR)); > - > - /* Find gettimeofday. */ > - typedef long (*gtod_t)(struct timeval *tv, struct timezone *tz); > - gtod_t gtod = (gtod_t)vdso_sym("LINUX_2.6", "__vdso_gettimeofday"); > - > - if (!gtod) > - linux_exit(1); > - > - struct timeval tv; > - long ret = gtod(&tv, 0); > - > - if (ret == 0) { > - char buf[] = "The time is .000000\n"; > - to_base10(buf + 31, tv.tv_sec); > - to_base10(buf + 38, tv.tv_usec); > - linux_write(1, buf, sizeof(buf) - 1); > - } else { > - linux_exit(ret); > - } > - > - linux_exit(0); > -} > - > -/* > - * This is the real entry point. It passes the initial stack into > - * the C entry point. > - */ > -asm ( > - ".text\n" > - ".global _start\n" > - ".type _start,@function\n" > - "_start:\n\t" > -#ifdef __x86_64__ > - "mov %rsp,%rdi\n\t" > - "and $-16,%rsp\n\t" > - "sub $8,%rsp\n\t" > - "jmp c_main" > -#else > - "push %esp\n\t" > - "call c_main\n\t" > - "int $3" > -#endif > - ); > diff --git a/tools/testing/selftests/vDSO/vdso_standalone_test_x86.c b/tools/testing/selftests/vDSO/vdso_standalone_test_x86.c > new file mode 120000 > index 0000000000000000000000000000000000000000..4d3d96f1e440c965474681a6f35375a60b3921be > --- /dev/null > +++ b/tools/testing/selftests/vDSO/vdso_standalone_test_x86.c > @@ -0,0 +1 @@ > +vdso_test_gettimeofday.c > \ No newline at end of file > -- Regards, Vincenzo