From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: (qmail 24732 invoked from network); 16 Apr 2020 18:53:06 -0000 Received-SPF: pass (mother.openwall.net: domain of lists.openwall.com designates 195.42.179.200 as permitted sender) receiver=inbox.vuxu.org; client-ip=195.42.179.200 envelope-from= Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with UTF8ESMTPZ; 16 Apr 2020 18:53:06 -0000 Received: (qmail 30344 invoked by uid 550); 16 Apr 2020 18:53:04 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 30301 invoked from network); 16 Apr 2020 18:53:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=to:cc:references:from:autocrypt:subject:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=KENJEd6gB1Uz5TpoFGVaD9PihxC5EPvSKkhTaP/j9Dk=; b=oIXZJlnI1FAX+Z3w3ilJCzfiUwdh8yIcl62gROt1IO0cro/Nnj5gkxHs69F8fs4S5Z aLE+dzt1/jRAJ1oqIBNChJk1Vp9U6/c/kVE+yZnALjv0nwGmQM5Rlool/Hp9cXD1DA/o ZbJaTlNg18BKd2kNffUpLfSnwRI84wFG7RUwPxL/qEHMK/F8eixuM/piHPsDR9mI+nGE +3GEtIqfKrt+ArL3CV/SsKMY2Ve2+4QlqboMOwb/5a5aUO3sKsYcjQ11xjtl4zXy4Q8j RHBuuqAD1na4K5lSX5034JFHyQuIrM/Xi4mpkGoSV+flSDFa0BCq9GQidBPr8ANEfVYi w+yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:autocrypt:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=KENJEd6gB1Uz5TpoFGVaD9PihxC5EPvSKkhTaP/j9Dk=; b=qid+en1TFUwsOZQ0Cgv0Amjtu5WKu/HV9NwoF3DPP/3zJblppinf200N6Efn6EO9ML TZXjp/IchLcYuQ816CSVsFcmNBJuvhIAzxunilcVaCsGmTgW2udcEBAb1h9UEfGGShtl v9QMblR8cgHDqk4IV2RX3AGVCaySZBtnBi1ZHG95pWx4LQZg4qGsCIJL0a+HRreAftIz 4rosRPTYKNNmcdRs4pL5KGNBoQS9LKR6/mg1ptrjJ3X6i9OyEz8FYnKimSNDpm1kXVVv mmrQ2SYb5od5NJ2GSjvINd7/HCnWdbRLq7Tw5p4zfK2oO2ZaP6w79bcrEiYz9ErdTWIN zVww== X-Gm-Message-State: AGi0PubN83jJay7yt+zG9movWhFcvPIv1qZWdMc0PL8bvsGR4Te9bLHK mo/DDzVM37DTa3ncBA3qud/XmQ== X-Google-Smtp-Source: APiQypJd70ncLZFRitUidGH9S0UwjQ2vABpTQ59TKib83h0+1J2zdCDf7jnhjGR97dKc43WyJfhrxw== X-Received: by 2002:a37:ac18:: with SMTP id e24mr25525197qkm.234.1587063171257; Thu, 16 Apr 2020 11:52:51 -0700 (PDT) To: Rich Felker Cc: Nicholas Piggin , libc-alpha@sourceware.org, musl@lists.openwall.com, linuxppc-dev@lists.ozlabs.org, libc-dev@lists.llvm.org References: <1586931450.ub4c8cq8dj.astroid@bobo.none> <20200415225539.GL11469@brightrain.aerifal.cx> <20200416153756.GU11469@brightrain.aerifal.cx> <4b2a7a56-dd2b-1863-50e5-2f4cdbeef47c@linaro.org> <20200416175932.GZ11469@brightrain.aerifal.cx> <4f824a37-e660-8912-25aa-fde88d4b79f3@linaro.org> <20200416183151.GA11469@brightrain.aerifal.cx> From: Adhemerval Zanella Autocrypt: addr=adhemerval.zanella@linaro.org; prefer-encrypt=mutual; keydata= xsFNBFcVGkoBEADiQU2x/cBBmAVf5C2d1xgz6zCnlCefbqaflUBw4hB/bEME40QsrVzWZ5Nq 8kxkEczZzAOKkkvv4pRVLlLn/zDtFXhlcvQRJ3yFMGqzBjofucOrmdYkOGo0uCaoJKPT186L NWp53SACXguFJpnw4ODI64ziInzXQs/rUJqrFoVIlrPDmNv/LUv1OVPKz20ETjgfpg8MNwG6 iMizMefCl+RbtXbIEZ3TE/IaDT/jcOirjv96lBKrc/pAL0h/O71Kwbbp43fimW80GhjiaN2y WGByepnkAVP7FyNarhdDpJhoDmUk9yfwNuIuESaCQtfd3vgKKuo6grcKZ8bHy7IXX1XJj2X/ BgRVhVgMHAnDPFIkXtP+SiarkUaLjGzCz7XkUn4XAGDskBNfbizFqYUQCaL2FdbW3DeZqNIa nSzKAZK7Dm9+0VVSRZXP89w71Y7JUV56xL/PlOE+YKKFdEw+gQjQi0e+DZILAtFjJLoCrkEX w4LluMhYX/X8XP6/C3xW0yOZhvHYyn72sV4yJ1uyc/qz3OY32CRy+bwPzAMAkhdwcORA3JPb kPTlimhQqVgvca8m+MQ/JFZ6D+K7QPyvEv7bQ7M+IzFmTkOCwCJ3xqOD6GjX3aphk8Sr0dq3 4Awlf5xFDAG8dn8Uuutb7naGBd/fEv6t8dfkNyzj6yvc4jpVxwARAQABzUlBZGhlbWVydmFs IFphbmVsbGEgTmV0dG8gKExpbmFybyBWUE4gS2V5KSA8YWRoZW1lcnZhbC56YW5lbGxhQGxp bmFyby5vcmc+wsF3BBMBCAAhBQJXFRpKAhsDBQsJCAcDBRUKCQgLBRYCAwEAAh4BAheAAAoJ EKqx7BSnlIjv0e8P/1YOYoNkvJ+AJcNUaM5a2SA9oAKjSJ/M/EN4Id5Ow41ZJS4lUA0apSXW NjQg3VeVc2RiHab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X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200416183151.GA11469@brightrain.aerifal.cx> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit Subject: Re: [musl] Powerpc Linux 'scv' system call ABI proposal take 2 On 16/04/2020 15:31, Rich Felker wrote: > On Thu, Apr 16, 2020 at 03:18:42PM -0300, Adhemerval Zanella wrote: >> >> >> On 16/04/2020 14:59, Rich Felker wrote: >>> On Thu, Apr 16, 2020 at 02:50:18PM -0300, Adhemerval Zanella wrote: >>>> >>>> >>>> On 16/04/2020 12:37, Rich Felker wrote: >>>>> On Thu, Apr 16, 2020 at 11:16:04AM -0300, Adhemerval Zanella wrote: >>>>>>> My preference would be that it work just like the i386 AT_SYSINFO >>>>>>> where you just replace "int $128" with "call *%%gs:16" and the kernel >>>>>>> provides a stub in the vdso that performs either scv or the old >>>>>>> mechanism with the same calling convention. Then if the kernel doesn't >>>>>>> provide it (because the kernel is too old) libc would have to provide >>>>>>> its own stub that uses the legacy method and matches the calling >>>>>>> convention of the one the kernel is expected to provide. >>>>>> >>>>>> What about pthread cancellation and the requirement of checking the >>>>>> cancellable syscall anchors in asynchronous cancellation? My plan is >>>>>> still to use musl strategy on glibc (BZ#12683) and for i686 it >>>>>> requires to always use old int$128 for program that uses cancellation >>>>>> (static case) or just threads (dynamic mode, which should be more >>>>>> common on glibc). >>>>>> >>>>>> Using the i686 strategy of a vDSO bridge symbol would require to always >>>>>> fallback to 'sc' to still use the same cancellation strategy (and >>>>>> thus defeating this optimization in such cases). >>>>> >>>>> Yes, I assumed it would be the same, ignoring the new syscall >>>>> mechanism for cancellable syscalls. While there are some exceptions, >>>>> cancellable syscalls are generally not hot paths but things that are >>>>> expected to block and to have significant amounts of work to do in >>>>> kernelspace, so saving a few tens of cycles is rather pointless. >>>>> >>>>> It's possible to do a branch/multiple versions of the syscall asm for >>>>> cancellation but would require extending the cancellation handler to >>>>> support checking against multiple independent address ranges or using >>>>> some alternate markup of them. >>>> >>>> The main issue is at least for glibc dynamic linking is way more common >>>> than static linking and once the program become multithread the fallback >>>> will be always used. >>> >>> I'm not relying on static linking optimizing out the cancellable >>> version. I'm talking about how cancellable syscalls are pretty much >>> all "heavy" operations to begin with where a few tens of cycles are in >>> the realm of "measurement noise" relative to the dominating time >>> costs. >> >> Yes I am aware, but at same time I am not sure how it plays on real world. >> For instance, some workloads might issue kernel query syscalls, such as >> recv, where buffer copying might not be dominant factor. So I see that if >> the idea is optimizing syscall mechanism, we should try to leverage it >> as whole in libc. > > Have you timed a minimal recv? I'm not assuming buffer copying is the > dominant factor. I'm assuming the overhead of all the kernel layers > involved is dominant. Not really, but reading the advantages of using 'scv' over 'sc' also does not outline the real expect gain. Taking in consideration this should be a micro-optimization (focused on entry syscall patch), I think we should use where it possible. > >>>> And besides the cancellation performance issue, a new bridge vDSO mechanism >>>> will still require to setup some extra bridge for the case of the older >>>> kernel. In the scheme you suggested: >>>> >>>> __asm__("indirect call" ... with common clobbers); >>>> >>>> The indirect call will be either the vDSO bridge or an libc provided that >>>> fallback to 'sc' for !PPC_FEATURE2_SCV. I am not this is really a gain >>>> against: >>>> >>>> if (hwcap & PPC_FEATURE2_SCV) { >>>> __asm__(... with some clobbers); >>>> } else { >>>> __asm__(... with different clobbers); >>>> } >>> >>> If the indirect call can be made roughly as efficiently as the sc >>> sequence now (which already have some cost due to handling the nasty >>> error return convention, making the indirect call likely just as small >>> or smaller), it's O(1) additional code size (and thus icache usage) >>> rather than O(n) where n is number of syscall points. >>> >>> Of course it would work just as well (for avoiding O(n) growth) to >>> have a direct call to out-of-line branch like you suggested. >> >> Yes, but does it really matter to optimize this specific usage case >> for size? glibc, for instance, tries to leverage the syscall mechanism >> by adding some complex pre-processor asm directives. It optimizes >> the syscall code size in most cases. For instance, kill in static case >> generates on x86_64: >> >> 0000000000000000 <__kill>: >> 0: b8 3e 00 00 00 mov $0x3e,%eax >> 5: 0f 05 syscall >> 7: 48 3d 01 f0 ff ff cmp $0xfffffffffffff001,%rax >> d: 0f 83 00 00 00 00 jae 13 <__kill+0x13> >> 13: c3 retq >> >> While on musl: >> >> 0000000000000000 : >> 0: 48 83 ec 08 sub $0x8,%rsp >> 4: 48 63 ff movslq %edi,%rdi >> 7: 48 63 f6 movslq %esi,%rsi >> a: b8 3e 00 00 00 mov $0x3e,%eax >> f: 0f 05 syscall >> 11: 48 89 c7 mov %rax,%rdi >> 14: e8 00 00 00 00 callq 19 >> 19: 5a pop %rdx >> 1a: c3 retq > > Wow that's some extraordinarily bad codegen going on by gcc... The > sign-extension is semantically needed and I don't see a good way > around it (glibc's asm is kinda a hack taking advantage of kernel not > looking at high bits, I think), but the gratuitous stack adjustment > and refusal to generate a tail call isn't. I'll see if we can track > down what's going on and get it fixed. Wrt glibc, it is most likely and it has bitten us on x32 port recently (where some types were being passed correctly). In any case, my long term plan to also get rid of this nasty assembly pre-processor on syscall passing. > >> But I hardly think it pays off the required code complexity. Some >> for providing a O(1) bridge: this will require additional complexity >> to write it and setup correctly. > > In some sense I agree, but inline instructions are a lot more > expensive on ppc (being 32-bit each), and it might take out-of-lining > anyway to get rid of stack frame setups if that ends up being a > problem. Indeed, I didn't started to prototype what would be required to make this change on glibc. Maybe an out-of-line helper might make sense. > >>>> Specially if 'hwcap & PPC_FEATURE2_SCV' could be optimized with a >>>> TCB member (as we do on glibc) and if we could make the asm clever >>>> enough to not require different clobbers (although not sure if >>>> it would be possible). >>> >>> The easy way not to require different clobbers is just using the union >>> of the clobbers, no? Does the proposed new method clobber any >>> call-saved registers that would make it painful (requiring new call >>> frames to save them in)? >> >> As far I can tell, it should be ok. > > Note that because lr is clobbered we need at least once normally > call-clobbered register that's not syscall clobbered to save lr in. > Otherwise stack frame setup is required to spill it. (And I'm not even > sure if gcc does things right to avoid it by using a register -- we > should check that I guess...) If I recall correctly Florian has found some issue in lr clobbering.