From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 840353858413 for ; Fri, 23 Feb 2024 23:13:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 840353858413 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 840353858413 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708729991; cv=none; b=h4kvCc2ya4xxF2TSQfA8JCUvwr+CVxIu2wgOhWygOO5AVoMEZUqBRACVV7w1bzGx69VzptMUoAHShQRQmx01cwEX0Je9i7tFNH11VVKtt64r4PXge4HbufgmIhIhgRbawzJwO99OuHmoV0zfZf8HftGdp9zT/itZcufB8wQPMGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708729991; c=relaxed/simple; bh=mGXIp9PYfdYvS3x4nbIRAy1Rik4vlYqguarFDhbMmQ0=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=NIbuTHhi7txyt/P5hKNq+i3f7S4GIH8JnJBsP/gWiEF96A6RQqlc4BWwmGu5iA2Inkrf/4Fyq8gOfxlp/WQvafQDAgf0d0/M1KBbqNGCMtWd+CNeOFLGNjbUb27lq8DGQ/sIzrWK3KL43/B92sQYMA8oRcvw+2HH04qvsSvRHFk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-512ea6ce06aso1186866e87.2 for ; Fri, 23 Feb 2024 15:13:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708729988; x=1709334788; darn=sourceware.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=STK+8akM4lXjzlvasPkZ9+CELidzULhQpSJdNC7MYuA=; b=PPhymQIMv0TK1eg+ngNqL8GuK26LJ197uk7H0IoO19eJ5g5G5k68F6KZPZqEcayzmO B1NW6kriBm9U47O5vAfQ+xm9ID5C0kTuawu/8Co/lPXly7WoJX/w6gr/uz9GfNeiCNMv fOXN5a/5Mv7LDVTQZmQtoi3OfpxQGO2JWvj2bU5ZYIX4J1lTYQWkDFthPpSEyKb3HEvY jXzE8lyIdPXN2yX6IeH5WW8o6XuiUYz0WVgfWrq1KzF2TTEJNzYG0EvBZG8ImMrXPD8T vzIjiThtN8yohZqL6cxAYhXZSJ6tlpsghW/qTEbsT0BoytzyPpAVolfQ/5+ycccpC86K XaCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708729988; x=1709334788; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=STK+8akM4lXjzlvasPkZ9+CELidzULhQpSJdNC7MYuA=; b=X0sdz2iIp7MzyXYmxGqo1OBrtTJoMMpiCw4Ws2ZFb4FU312dN0yWqEmAH99D5wLtVM PVi2HbMxjCdb1iOyp565tbYERHeDqsoKC3AzEWi9MaQJdlfhjWQ3qBg+gsGmweIBsE5l GCGqWi4WSkKuZRpdg7ucK6fzCBKCxLOpD1tTGPnGrVPJt/j2t8DatixptDlaKR8Bh51V Dd9yKDQceNfwV0ZKgWCK4zp18QX0tRQjGnQcMjUMwUwTXf5moINrY8us6U9JDtmqoirq tRHqeLcLnHkeIlIK2YTU0ArcptYy/nlVb7EboHV4RHooTT3GCe2gPmwG5OGFy9KEfKUn zyZQ== X-Gm-Message-State: AOJu0YxkFaKNFvTmNcZMSuyF43D0UK2Ecg6riNJ3M8xN5XoXz2/0xwVF hxurFOlgaR4J3+OUrgsI8Teq7yv6wIBw8d+jU1WBM3Wj0D0w4MQm3q11KjYTnB3X0ezMIhbo3rX I3XbUsFMpZKVlsi8yXiPsXBnLLhOUwsUawfbZ9A== X-Google-Smtp-Source: AGHT+IFk1BhIOeVUWfP8W10ua3iedAV/CCy/1AVSHa4xexaWeMw+PLHXmAsm8RY8laBwBZQ4jmX1LPXRPqK+E9yzODE= X-Received: by 2002:a05:6512:3b85:b0:512:eeac:2463 with SMTP id g5-20020a0565123b8500b00512eeac2463mr428853lfv.14.1708729987845; Fri, 23 Feb 2024 15:13:07 -0800 (PST) MIME-Version: 1.0 References: <20240214143159.2951158-1-evan@rivosinc.com> <20240214143159.2951158-3-evan@rivosinc.com> <877cj47t0f.fsf@oldenburg.str.redhat.com> In-Reply-To: <877cj47t0f.fsf@oldenburg.str.redhat.com> From: Evan Green Date: Fri, 23 Feb 2024 15:12:31 -0800 Message-ID: Subject: Re: [PATCH v12 2/7] linux: Introduce INTERNAL_VSYSCALL To: Florian Weimer Cc: libc-alpha@sourceware.org, vineetg@rivosinc.com, slewis@rivosinc.com, palmer@rivosinc.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, Feb 15, 2024 at 11:44=E2=80=AFPM Florian Weimer wrote: > > * Evan Green: > > > Add an INTERNAL_VSYSCALL() macro that makes a vDSO call, falling back t= o > > a regular syscall, but without setting errno. Instead, the return value > > is plumbed straight out of the macro. > > > > Signed-off-by: Evan Green > > --- > > > > (no changes since v10) > > > > Changes in v10: > > - Introduced INTERNAL_VSYSCALL patch > > > > sysdeps/unix/sysv/linux/sysdep-vdso.h | 19 +++++++++++++++++++ > > 1 file changed, 19 insertions(+) > > > > diff --git a/sysdeps/unix/sysv/linux/sysdep-vdso.h b/sysdeps/unix/sysv/= linux/sysdep-vdso.h > > index 189319ad98..f7d4b29b25 100644 > > --- a/sysdeps/unix/sysv/linux/sysdep-vdso.h > > +++ b/sysdeps/unix/sysv/linux/sysdep-vdso.h > > @@ -53,4 +53,23 @@ > > sc_ret; = \ > > }) > > > > +#define INTERNAL_VSYSCALL(name, nr, args...) = \ > > + ({ = \ > > + __label__ out; = \ > > + long int sc_ret; = \ > > + = \ > > + __typeof (GLRO(dl_vdso_##name)) vdsop =3D GLRO(dl_vdso_##name); = \ > > + if (vdsop !=3D NULL) = \ > > + { = \ > > + sc_ret =3D INTERNAL_VSYSCALL_CALL (vdsop, nr, ##args); = \ > > + if ((!INTERNAL_SYSCALL_ERROR_P (sc_ret)) || = \ > > + (INTERNAL_SYSCALL_ERRNO (sc_ret) !=3D ENOSYS)) = \ > > + goto out; = \ > > + } = \ > > + = \ > > + sc_ret =3D INTERNAL_SYSCALL_CALL (name, ##args); = \ > > + out: = \ > > + sc_ret; = \ > > + }) > > + > > #endif /* SYSDEP_VDSO_LINUX_H */ > > I wonder if this is clearer without the label and with a conditional > expression instead? It's kinda awkward without the label because the regular syscall is made either if vdsop is NULL or returns ENOSYS (which is two checks on the return value, so doesn't lend itself to inlining in the if statement). The best I could come up with without the label is to duplicate the syscall_call: #define INTERNAL_VSYSCALL(name, nr, args...) \ ({ \ long int sc_ret; \ \ __typeof (GLRO(dl_vdso_##name)) vdsop =3D GLRO(dl_vdso_##name); = \ if (vdsop !=3D NULL) \ { \ sc_ret =3D INTERNAL_VSYSCALL_CALL (vdsop, nr, ##args); \ if ((INTERNAL_SYSCALL_ERROR_P (sc_ret)) && \ (INTERNAL_SYSCALL_ERRNO (sc_ret) =3D=3D ENOSYS)) \ sc_ret =3D INTERNAL_SYSCALL_CALL (name, ##args); \ } \ else \ { \ sc_ret =3D INTERNAL_SYSCALL_CALL (name, ##args); \ } \ sc_ret; \ }) I think I prefer the version with the label, but I'm not attuned to the glibc style, so let me know if you like this and I'll send out a new version. -Evan