Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2060708rdg; Sun, 13 Aug 2023 07:37:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGb/wwd3H2Ucax+NjJ9p/v9eV9I4ZTRqaTQ0PQVhHhS690tEghHty6QOq7uRuidPxPv/Vn2 X-Received: by 2002:aa7:d7da:0:b0:525:63f9:a268 with SMTP id e26-20020aa7d7da000000b0052563f9a268mr646096eds.42.1691937464184; Sun, 13 Aug 2023 07:37:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691937464; cv=none; d=google.com; s=arc-20160816; b=WAmdTKftM8sUf0+V1qatkjPgqShUa02iA26N15M6n5NLGoPNz7i/xyihfyNORbEwR2 zRQ1v9EOQWT6JlGKAelwMSgH85jvW51P7YMYI7XgurMkQvW0ZUoWuKyXy/HRce9/+MZ2 c+kZx/0OnBoKgvGHpOOWC4RpComspxUMr5JB/j91auxesevywSokspX8TRj996/KnNm+ 4RQdZgIpFBPoNCL1//vxz5d6yGQPNaD8P3zJjK+GPST/MKlx5tubC71TXKTVKN1EHkvK GDIt13GqbEmqvxviUM0r10WSFhbKIkSRVqAPGuw6jxKFliCJCd/gD3J7j6FiFGYVv0Y1 Gfyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=QLRHuK7ZwdCAFrJp4UNWv7fPezONTK3CH1++BeufM8Q=; fh=yx3zD7yghnnQSNZMl8IAmBc4fwhKP4q/XMBmPDqKXmM=; b=vJL7gXPWqQG9MRMMv52/CjRYhQJirdLTw3fHwwbg5Cxm7cc1GHeMMvApuOzP3aET7I oC89GUpSHNH+9OhG82EfUip9RM5tgQ5Bq2ORn9v3FzpHXzf4EWSZ0AF7PkpgIPQP17BS Mpag7FefHZeNUFTi80W0X+V1/zOoQnLaM84W03Bj7JmkyrZywH9wg6hyf5hxR/ObFlce 44qbd2o1oPkTQXH7u8yBGpym2EOMio1dm0YRPQHadXwKGkGfPGWxslMv4wx3RKLH3lB3 1fWefH3GpqMIiWxaLZ3OIv9jtZROHXiJ31PIlVeKppDdoDaF7nVOlzMf9cThKKShMLuS EBLw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y21-20020aa7d515000000b0052322c938f4si6508825edq.152.2023.08.13.07.37.19; Sun, 13 Aug 2023 07:37:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231167AbjHMNkF (ORCPT + 99 others); Sun, 13 Aug 2023 09:40:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230325AbjHMNkE (ORCPT ); Sun, 13 Aug 2023 09:40:04 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BE341716; Sun, 13 Aug 2023 06:40:04 -0700 (PDT) X-QQ-mid: bizesmtp90t1691933986tefh5sq6 Received: from linux-lab-host.localdomain ( [116.30.128.116]) by bizesmtp.qq.com (ESMTP) with id ; Sun, 13 Aug 2023 21:39:45 +0800 (CST) X-QQ-SSF: 01200000000000E0X000000A0000000 X-QQ-FEAT: zT6n3Y95oi0Q9hAETwfPAxtGrdKT0h1uUdtny0v5TrbKn15q9s7V0vFt3QvnX rw6l9vZA97AA72YrP8HV22bA1aB5XmPuNYgg9F2Bpaivu82xl4azth3CHHbr2JqvsgoC0gF F24dXZdt4rMZZieT3QFmTJbzZ1H30JG018hOwW2AnxbzawC/e6iy+S+IU91NoCD0Mz/qZjy qlm2SwphK3F8DohC1Y797WBpE8sEtz4SW5Fv36NjNXCD1YTV2c3CJt4j7VEqC+sZ7SHDsH8 qmmxZAhmA+huuUlxFwUqlxK6pQ0xCLfYYkELy2ttiV9zJK0bMTOssVhAaBzLRvneeHTrqJh qJBoTQOBWcQjgbAMXZIj+P7tF+nDMSJJvf4whR44nExggVYZfBjZqJ/wzHjdF2yiFxFkrck X-QQ-GoodBg: 0 X-BIZMAIL-ID: 9377767443625054959 From: Zhangjin Wu To: w@1wt.eu Cc: arnd@arndb.de, david.laight@aculab.com, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, tanyuan@tinylab.org, thomas@t-8ch.de Subject: Re: [PATCH v6 2/2] tools/nolibc: fix up size inflate regression Date: Sun, 13 Aug 2023 21:39:44 +0800 Message-Id: <20230813133944.19604-1-falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230813090037.GE8237@1wt.eu> References: <20230813090037.GE8237@1wt.eu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Willy > On Sat, Aug 12, 2023 at 05:51:53AM +0800, Zhangjin Wu wrote: > > As reported and suggested by Willy, the inline __sysret() helper > > introduces three types of conversions and increases the size: > > > > (1) the "unsigned long" argument to __sysret() forces a sign extension > > from all sys_* functions that used to return 'int' > > > > (2) the comparison with the error range now has to be performed on a > > 'unsigned long' instead of an 'int' > > > > (3) the return value from __sysret() is a 'long' (note, a signed long) > > which then has to be turned back to an 'int' before being returned by the > > caller to satisfy the caller's prototype. > > > > To fix up this, firstly, let's use macro instead of inline function to > > preserves the input type and avoids these useless conversions (1), (3). > > > > Secondly, since all of the sys_* functions have been converted to return > > integer, now, it is able to remove comparison to a 'unsigned long' > > -MAX_ERRNO (2) and restore the simple sign comparison as before. > > > (...) > > +/* Syscall return helper, set errno as -ret when ret < 0 */ > > +#define __sysret(arg) \ > > +({ \ > > + __typeof__(arg) __ret = (arg); \ > > + if (__ret < 0) { \ > > + SET_ERRNO(-__ret); \ > > + __ret = -1L; \ > > + } \ > > + __ret; \ > > +}) > > Except that this now breaks brk(), mmap() and sbrk() by taking any value > with MSB set as an error. Also you've re-introduced the problem you've > faced with const. See my simplification in the other thread by using "?:" > which does avoids any assignment. > Yeah, thanks for your explanation in this reply [1], the 'const' flag only triggers build error on the second 'assign' (__ret == -1L), the first 'assign' is a definition, it is not problematic. so, your "?:" method is a great idea to simply return without the second 'assign'. > Let's just roll brk(), mmap() and sbrk() to their original, working, > definition: > > static __attribute__((unused)) > void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) > { > void *ret = sys_mmap(addr, length, prot, flags, fd, offset); > > if ((unsigned long)ret >= -MAX_ERRNO) { > SET_ERRNO(-(long)ret); > ret = MAP_FAILED; > } > return ret; > } > Agree, only left a suggestion here [2] about whether we can apply the 2nd patch instead of rolling them back, let's discuss it in [2] thread. > And we're done, you can then keep the simplified __sysret() macro for all > other call places. > Now, this issue is near to the end ;-) Thanks! Zhangjin --- [1]: https://lore.kernel.org/lkml/20230813085140.GD8237@1wt.eu/#R [2]: https://lore.kernel.org/lkml/20230813132620.19411-1-falcon@tinylab.org/ > Willy