From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id E6F873858407 for ; Fri, 23 Feb 2024 23:29:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E6F873858407 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E6F873858407 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::331 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708730983; cv=none; b=mll+wDjgnU1e20C8mpFe71hj9hR2E9+h6mgk3BVArowXCELhcAYl8t6CB8r6IUWwkylKOajVrg/R4bIWNEIXGYU2YuxyFLP8nXmEVWJhkNmgfGXht/Tl44yjJdZayOv3Y89JRQiEVvtP+x8+LIi46k0wStBhdCjqIPCG5OF1oRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708730983; c=relaxed/simple; bh=4yOgXOVJkufW9KDkYhuW8UFQieyuD0MK2o24Nmd/YXM=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=slm/wJZgWF2oPgIj2e2k0xR7f1YK+HiSw7uME6ajoS1gebnUK3be2XcXk2HnhNUVjBRH8/la3iEGvPwrrex8iRq+UgKXWbCKjK7x5Du8K7/rQC/qAy9mHhZjip2NM3+FaLUSvtQF3hVe7BF4dS8qvzDvIqeuQ0QaXxLqwUk37ao= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-412985ba594so3236835e9.3 for ; Fri, 23 Feb 2024 15:29:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708730979; x=1709335779; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=I8qmzh8HzSw4gBw/okuilIDIv4LIhZfsuyTcDhT7k8Q=; b=Ie+PdtiDjtOeEpA7XWWkzHSTFmo8zWiCcWI0/lGsh7qFEWX2Du6JJ+rWNvcPTA/2vK iJDk2URquUg3s2QHjzi2vouyyzW0xRpNfKc3GUaZixU+8MRJla/B1QsJdTgDldDQOFj9 /kTheWo3iDh3aypfF5ymB827MoaAMYg/e8Yf+pQPWFfs2ffI6ANIp0YRV4mOh52pLrnA PenYvTABaFMMtM0q/PHtP5ot+/BVPEHIredcSxSPoJeKCBxi8PZM4SDlGVLkO3/wNqqP EKcZCNb/KxxDPmF4A30zI+5Ni/AXazzpfcGBMZ0WTDoKkNGUc4mc6t+wlVxE7CEMd2hN Rgjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708730979; x=1709335779; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=I8qmzh8HzSw4gBw/okuilIDIv4LIhZfsuyTcDhT7k8Q=; b=uG4egNTz/uez95SJrth7V0feQU085M1+CPvaIC1gEq2/xDp8HSowRFo9mDiLsxhS9S 8/orDq/bUk6gEPMkV2fUkxuAzD7zC8zjXi7yji3R/EXu/cYniFaPnlryoq/eme90UGgp lTgCL0Kru/5IwndOMVlE6AeqMpFqDDk6fXlyU+hn+HPowKijjHf/M8vfLfM8eHXQRrJh o6+OlEfjb9pAplACPWdhPEupMfsKellJGg7oSDfWelfhPmGGJhlpiwcauCZNwEsIdBUl oNosL2NjEQ1yHUrnIpa18OtCk/kggr6NatM36kHdOaVWfbdAKiHbqSXFfTjAEMgRns3w 6tLw== X-Gm-Message-State: AOJu0YxjyTO/mYGn3vNbj9nse3php0IWlcKUz4TNcEEMk52Sy3MC2uvP uksu8J7rb6/bnGLFH5mRS2NvWrpdc1WTwj//VDyMDABSmIL13R6Q X-Google-Smtp-Source: AGHT+IFhYNfviqYNy5ofU/Rnr0DJE4vuyg+4NtoK2fclMI36G2S8cKGj8FLwmlM6LcfCXwoIMw/NsA== X-Received: by 2002:a05:600c:3b90:b0:412:aec:2cfa with SMTP id n16-20020a05600c3b9000b004120aec2cfamr861516wms.1.1708730979326; Fri, 23 Feb 2024 15:29:39 -0800 (PST) Received: from [10.96.0.26] ([146.70.48.12]) by smtp.gmail.com with ESMTPSA id m30-20020a05600c3b1e00b004129013aa45sm4146825wms.7.2024.02.23.15.29.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Feb 2024 15:29:38 -0800 (PST) Message-ID: <3ca8157c-9e99-43fb-90b4-16767d559fbd@gmail.com> Date: Fri, 23 Feb 2024 23:29:37 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v12 2/7] linux: Introduce INTERNAL_VSYSCALL To: Evan Green , Florian Weimer Cc: libc-alpha@sourceware.org, vineetg@rivosinc.com, slewis@rivosinc.com, palmer@rivosinc.com References: <20240214143159.2951158-1-evan@rivosinc.com> <20240214143159.2951158-3-evan@rivosinc.com> <877cj47t0f.fsf@oldenburg.str.redhat.com> Content-Language: en-US From: Gabriel Ravier In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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 2/23/24 23:12, Evan Green wrote: > On Thu, Feb 15, 2024 at 11:44 PM Florian Weimer wrote: >> * Evan Green: >> >>> Add an INTERNAL_VSYSCALL() macro that makes a vDSO call, falling back to >>> 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 = GLRO(dl_vdso_##name); \ >>> + if (vdsop != NULL) \ >>> + { \ >>> + sc_ret = INTERNAL_VSYSCALL_CALL (vdsop, nr, ##args); \ >>> + if ((!INTERNAL_SYSCALL_ERROR_P (sc_ret)) || \ >>> + (INTERNAL_SYSCALL_ERRNO (sc_ret) != ENOSYS)) \ >>> + goto out; \ >>> + } \ >>> + \ >>> + sc_ret = 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 = GLRO(dl_vdso_##name); \ > if (vdsop != NULL) \ > { \ > sc_ret = INTERNAL_VSYSCALL_CALL (vdsop, nr, ##args); \ > if ((INTERNAL_SYSCALL_ERROR_P (sc_ret)) && \ > (INTERNAL_SYSCALL_ERRNO (sc_ret) == ENOSYS)) \ > sc_ret = INTERNAL_SYSCALL_CALL (name, ##args); \ > } \ > else \ > { \ > sc_ret = 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 Is GCC able to de-duplicate the duplicated syscall call ? The label version already seems readable enough in any case and if GCC is not able to de-duplicate the syscall it seems preferable from a performance/code size standpoint as well.