Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2402102rdh; Wed, 27 Sep 2023 01:08:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaKYChhBomHkREf8hS+xPt6jFTIrcW1IFTV22bXIMCdAY1XiiE4jH7jWw26dYahLzpZ9ex X-Received: by 2002:a05:6870:a54c:b0:1d6:7f77:c922 with SMTP id p12-20020a056870a54c00b001d67f77c922mr1566662oal.28.1695802127969; Wed, 27 Sep 2023 01:08:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695802127; cv=none; d=google.com; s=arc-20160816; b=Yz14lHMMZDugKF1Umgmd/z8YlAgJ+HkQhkh+MVle5ZJeAQvVCWNrfhQ9cYUp/EuPyl 071CAyIt0H+LFgW79hmtlgiO+AHk3EJuy+9CF1N1vn1o3lRMHGznqodwyudegLE4z5iP c1nNutDbrewQ/l/JmzzzSqiAm7E+U1OsjjNZVJ0T7okVbqdNcoaKqmtndSVSLgpZ9gtv Rusr9LjqgATfMvagpGS+QXwNTRUY4qMcWV/jECP7+hfbn+lagU8SlIpwwBWhNcyoXkwy SDua692zOJy0TPKI2DguBKSgYbcrOFas65zyY1A2CmE9zDztc0c1tviJpAnUjvzw+XXd WpTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=wsYv3xWuvEVECDbNso3cjCx2CaNlaoPlk+DFKVSGqhU=; fh=iBDRI8sKFl04fKrrlMIPh3nQtqtzk1yIxI9uUQT9SPE=; b=an03jMguUQ2Bj1+G3mB9Kir27RzrvND07h3Yju+/V5tg9Bz3YtEQI/NPGrPrK4B5xJ jk4sjtFjoKIis1JqCJNeDC+tMvGLyquZ5I85rxm4n9LQv1t9JlxthNazco3WSlJd+SQw Xh3RiRpY4OhYL4exEUVbE/odKeU9Sz+9BvY9ddKkdujenARxsj+Ho/5mwRgD1yag6NnA pglG31sKVqSEotOAcl4wt6XJO+63eHUSb4lvAGTbOPdLrRBOi3YqNVRi2SWacQv/qbOH xywrHLXCLYGGogQoV0j23sfV/8FbHaGQhTOHINEeQAsZqw/XywwnXTRVu6h1CHv78IIg GV/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=LMQfIFhV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id j191-20020a6380c8000000b0056513361b4fsi14650494pgd.741.2023.09.27.01.08.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 01:08:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=LMQfIFhV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 800B48315C81; Tue, 26 Sep 2023 17:14:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231755AbjI0AOm (ORCPT + 99 others); Tue, 26 Sep 2023 20:14:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231985AbjI0AMk (ORCPT ); Tue, 26 Sep 2023 20:12:40 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58C181F2A8 for ; Tue, 26 Sep 2023 16:30:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1695771029; bh=MbrBGLxP+0Stq0F10v63Xe15gOAo5JV50TCT1Ux7SP8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LMQfIFhVOG1WEgplNfBuehwT9eOc4eMw0UaR/IhOIewXYTTeJgZi0HeV/Kkx/0lU4 xUcL1blLHdBHij5VNNzhUAMrT2fU+EB66Xn8faua+DaVX+d5Gm54EJsQkewvSfDuRV MD58sa5IYyzwONRABNLDX/hWmaAB/aKl1OydQ6uc= Date: Wed, 27 Sep 2023 01:30:28 +0200 From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Rodrigo Campos Cc: Willy Tarreau , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] tools/nolibc: Add workarounds for centos-7 Message-ID: References: <20230926133647.467179-1-rodrigo@sdfg.com.ar> <20230926133647.467179-2-rodrigo@sdfg.com.ar> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230926133647.467179-2-rodrigo@sdfg.com.ar> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 26 Sep 2023 17:14:43 -0700 (PDT) Hi Rodrigo, thanks for your patch! Some comments below. On 2023-09-26 15:36:47+0200, Rodrigo Campos wrote: > Centos-7 doesn't include statx on its linux/stat.h file. So, let's just > define it if the include doesn't define STATX_BASIC_STATS. Could you mention which version of the kernel headers you compiled this with and with which version you tested it? Also which is the exact revision you use to extract nolibc? Does nolibc actually support statx()/stat() on centos-7 with these changes? I'm asking because I tried to reproduce it and for me CentOS 7 with kernel-headers 3.10.0-1160.99.1.el7 doesn't define __NR_statx. Without this symbol the statx() and stat() functions should just always return -ENOSYS. It seems a bit wasteful to introduce 200 new lines of code for a "feature" that will not do anything. FYI the hard requirement for the statx syscall is fairly new, it was added in commit af93807eaef6 ("tools/nolibc: remove the old sys_stat support"). As you are vendoring nolibc, if you don't need stat/statx support in for your usecase you could drop the support for it in your vendored copy. Or we try to reintroduce compatibility for stat() without the statx() syscall. But given the really limited applicability, personally I'm against that. Some more notes below. > This makes nolibc work on centos-7 just fine, before this patch it > failed with: > > nolibc/sys.h:987:78: warning: ‘struct statx’ declared inside parameter list [enabled by default] > int sys_statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf) > > Please note that while on types.h we can still include linux/stat.h > and it won't cause any issues, it seems simpler if we just always > include "statx.h" instead of that file and be safe. That is why I > changed types.h too. All of nolibc will end up included into the same namespace by design. It seems weird that it would make a difference from where this file is included. > Signed-off-by: Rodrigo Campos > --- > tools/include/nolibc/statx.h | 218 +++++++++++++++++++++++++++++++++++ > tools/include/nolibc/sys.h | 2 +- > tools/include/nolibc/types.h | 2 +- > 3 files changed, 220 insertions(+), 2 deletions(-) > create mode 100644 tools/include/nolibc/statx.h > > diff --git tools/include/nolibc/statx.h tools/include/nolibc/statx.h > new file mode 100644 > index 000000000000..d05528754154 > --- /dev/null > +++ tools/include/nolibc/statx.h > @@ -0,0 +1,218 @@ Below you mention that this was copied from tools/include/uapi/linux/stat.h, but... > +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ The original code was "GPL-2.0 WITH Linux-syscall-note". > +/* > + * Compatibility header to allow using statx() on old distros. > + * Copyright (C) 2023 Rodrigo Campos Catelin Assuming copyright for copied code is not great. > + */ > + > +#ifndef _NOLIBC_STATX_H > +#define _NOLIBC_STATX_H > + > +/* We should always include this file instead of linux/stat.h, so nolibc works > + * in old distros too. > + * > + * The problem is centos-7, that doesn't have statx() defined in linux/stat.h. > + * We can't include sys/stat.h because it creates conflicts, so let's just > + * define it here. > + * No other distros seem affected by this, so we can remove this file when it > + * hits EOL (06/2024). > + */ > +#include /* for statx() */ > + > +#ifndef STATX_BASIC_STATS > + > +/* This is just a c&p from tools/include/uapi/linux/stat.h as it is in > + * Linux 6.6-rc3. > + * We don't need it all, but it's easier to just copy it all in case in the > + * future we start using more of it, as we won't have CI running on centos-7. > + */ > +#include > + > +#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) > + > +#define S_IFMT 00170000 > +#define S_IFSOCK 0140000 > +#define S_IFLNK 0120000 > +#define S_IFREG 0100000 > +#define S_IFBLK 0060000 > +#define S_IFDIR 0040000 > +#define S_IFCHR 0020000 > +#define S_IFIFO 0010000 > +#define S_ISUID 0004000 > +#define S_ISGID 0002000 > +#define S_ISVTX 0001000 > + > +#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) > +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) > +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) > +#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) > +#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) > +#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) > +#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) > + > +#define S_IRWXU 00700 > +#define S_IRUSR 00400 > +#define S_IWUSR 00200 > +#define S_IXUSR 00100 > + > +#define S_IRWXG 00070 > +#define S_IRGRP 00040 > +#define S_IWGRP 00020 > +#define S_IXGRP 00010 > + > +#define S_IRWXO 00007 > +#define S_IROTH 00004 > +#define S_IWOTH 00002 > +#define S_IXOTH 00001 We already have all of these in types.h. > + > +#endif > [..] > diff --git tools/include/nolibc/sys.h tools/include/nolibc/sys.h > index fdb6bd6c0e2f..d3e45793682a 100644 > --- tools/include/nolibc/sys.h > +++ tools/include/nolibc/sys.h > @@ -20,9 +20,9 @@ > #include > #include > #include /* for O_* and AT_* */ > -#include /* for statx() */ So this means that compatibility with user applications that also include on their own is broken? That would not be good. > #include > > +#include "statx.h" /* for statx() */ > #include "arch.h" > #include "errno.h" > #include "types.h" > [..]