From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) by sourceware.org (Postfix) with ESMTPS id 3444E3858C53 for ; Sat, 24 Feb 2024 02:06:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3444E3858C53 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3444E3858C53 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c31 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708740419; cv=none; b=waU51z8ludkhq/c+6Ttr9YV+gB7r4jo+b9TgpmQQgwIWNdWpjdlv5zlx6xXYEecDshj8ycs5GjIY0Zyn8lCdRH1X61eOMaCUHyFzPKqNojAuH7s04CNT2XoCT28PY/IL4RK7jQQ1Osm4HFgVdx+mr4vMIlMz8j0unHBYt1bszeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708740419; c=relaxed/simple; bh=A7dGujkQR+sKE0g1irPkcO8iPSLV8t0Z5sNdb2YbfpU=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=u3ktq4hI3wxCNzBMhEAEzv/hmMvXsgmfPKW/i3Gq5bMc5S06uTwxPgejGaSxX9IzfYHKhWwwkugDYOOQzOQ5Yj+IgvHZgir08dop28WvrIQlWvCo6u0Jhx+ptXgSaJG2JPqE/x5dgESDrt91ac0dWwyFkkq1ixoStbMcvjngddM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-59927972125so909818eaf.3 for ; Fri, 23 Feb 2024 18:06:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708740415; x=1709345215; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=x8acuzfPUIlnS6QtP1i8Pt6E9NaXLc5PuTmFqOn2hdQ=; b=kUkIGse3kMBCU55hvY9eK/pXjmdwPYFjCu0d60D2PcpKhzExnd5TRItDlcLQYrqNLR rkNDCPL79DrF9xYPIOmKfMIlDnMzaV+twY5r7cighbuuIY8mAp24P5+o/5s3hAnELJdI k+dL1LH1uzHEIGtEqaQvu/A54sAfZtpGSfpgOXvtrUEo65w5sxNjPn64rx+ZcIhzYZou EFksCevgLJrnhA6JYW/akkW7cG9QELhYDeX9biYZS2vl/nyo/NMyoOTmQfXJ2G5sd1bc PnB0OGz2+LlmgyUBViyo0C4Figc3ZmzVp+fCs5TC2bj1HYUT4zpjZizkdOl6MtD9uvS2 PyzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708740415; x=1709345215; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=x8acuzfPUIlnS6QtP1i8Pt6E9NaXLc5PuTmFqOn2hdQ=; b=YwU1l/NaR9lkaoM3Nwqw5pxJVVfP+RG7MvnSyMPqEPK3R+Yg8AzlTGKfYOoLYahS/p XLLQTnD3XEoQGc6pFnm6b/SalK2NI776PqikidulJn4ZWVupIcBwxHGDmIQRMmurnoTo LGNPkoVpPtYQt+b8mTJDpZAQiqwIcW0yMOJC25OihXdWiAijmRzDTiyhFeX1H6gqlBlA 62Y1W2coeKpapQX/3reQ6gaKyoug9FJEgHU1FzaHXEYQA2JENkkjI8W9y8proXfWF947 Czu0nWmbVAhB3EdnvK8e6qQ42xOiRpm1pOaC5yH3mrfXBxVkKYjlY3VfTX+hzwB8rKe3 oIVg== X-Gm-Message-State: AOJu0YzXzDph7oRQjTvMPXLKB4VPBP7Hv6bmmbcjgfU2QD9NP9mw4GYn aviu5duR+YQX1c0O1sUOTz/JGVi7gjiixIGtK5lp62j0CoNWkdvOes4EZ8wKf1g= X-Google-Smtp-Source: AGHT+IFRmo8Bdm60jxzh1SQxh3QXOQVp13mr//3O56RpPvi8jlfZ3hxYOd6YZcMPqBYwl8ua5k65kw== X-Received: by 2002:a05:6358:541a:b0:178:e2b3:98da with SMTP id u26-20020a056358541a00b00178e2b398damr1903198rwe.28.1708740415347; Fri, 23 Feb 2024 18:06:55 -0800 (PST) Received: from [172.20.1.19] (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id h12-20020a056a00230c00b006e13ce6f4dcsm137072pfh.87.2024.02.23.18.06.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Feb 2024 18:06:54 -0800 (PST) Message-ID: <8017cc86-01a5-41ad-a1f0-269f477a3ee7@linaro.org> Date: Fri, 23 Feb 2024 16:06:51 -1000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v12 2/7] linux: Introduce INTERNAL_VSYSCALL Content-Language: en-US To: Gabriel Ravier , 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> <3ca8157c-9e99-43fb-90b4-16767d559fbd@gmail.com> From: Richard Henderson In-Reply-To: <3ca8157c-9e99-43fb-90b4-16767d559fbd@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 13:29, Gabriel Ravier wrote: > 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. Or a switch? switch (vdsop != NULL) { case 1: sc_ret = INTERNAL_VSYSCALL_CALL(...); if (!error_p (sc_ret) || errno (sc_ret) != ENOSYS) break; /* FALLTHRU */ default: sc_ret = INTERVAL_SYSCALL_CALL(...); break; } I haven't actually looked at the generated code, but I'd think it would be identical to the gotos. r~