Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1667546rwb; Fri, 28 Jul 2023 12:59:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlEcRD/kRvbdKk12ky6keq9ShIRBbXlhmnVoPLscu03LnBBgugygJMbFw85B9KnD7ikuGCev X-Received: by 2002:a17:90a:3e84:b0:267:f7eb:f12e with SMTP id k4-20020a17090a3e8400b00267f7ebf12emr2365453pjc.39.1690574380376; Fri, 28 Jul 2023 12:59:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690574380; cv=none; d=google.com; s=arc-20160816; b=v5KXpKETTEKbPjNNHj48iM+YMjUoNuNcH3YAhM9NbL7sHgMjW3zSEaYkFEFsmyqLWd 2+pijo0gn6iae/jza1/OK6Ac0Q6ogD1x3Vr8NTs0CosGC3Q9d4YBM59XZzEz2U1TIy0z SyHVQ2OU/a7CQHtrSOx1IcVzED8xrRP1Wht0cM+8SjtGErZuRdwGKpSKbrvDFAHxPISJ qWzwh2t3THXo+rbhcmbTcjG36oIQQ0CMva1H5i5sxrzR8To8v9GxuGi+KIgU6isEN574 LhRAZdTqksCFKLErZvYzEpQEjLoExCxc6JjIjNJuttjN4KCTDjb+3iSzrdibm9nQ15cY OQnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=jre1/L5voDbFXUoxYm2vKudms4VXInSUmkVea3yzFUw=; fh=b6nw+B+9mF8GeMIwxXIg4qqZuncuOzEMy122AmBiQTY=; b=jCUE8Ff/418EIzNaB4ZpWR/860Zo91fS9uz1dfewavNq3joC7D30x5nZCn+npM/0tE 58VJ2LfhI+BxyXeXhZfKjBlRzNUt++1/gZuisKUTlVpHpkRxJ+UhvltAmxBvGo5luy13 kdhH9rQs3o/ZB0JcMs2srCjspmcBfDDjqTuZqeZfuaC4UQr5JvYIE2kEeHuuDSY580GB G6+7kpuiXZKEY6OtDGcNCfKMZC5G3usLjfijqaeSAdzJc2bEIqkqYxY5N5+gQfQu+Kd1 c4qZ3ruE1m6iWqyEAIccVTH7Rb4XF4BakG7b2bltEZjRIlX73owaGvCoWcVUtduV7Lqe 0Zvg== 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 u7-20020a17090a410700b0025be6419478si3497187pjf.92.2023.07.28.12.59.04; Fri, 28 Jul 2023 12:59:40 -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 S232112AbjG1TR1 (ORCPT + 99 others); Fri, 28 Jul 2023 15:17:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229520AbjG1TR0 (ORCPT ); Fri, 28 Jul 2023 15:17:26 -0400 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5672B19BA; Fri, 28 Jul 2023 12:17:25 -0700 (PDT) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 36SJHILA032228; Fri, 28 Jul 2023 21:17:18 +0200 Date: Fri, 28 Jul 2023 21:17:18 +0200 From: Willy Tarreau To: Zhangjin Wu Cc: tanyuan@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH 1/2] tools/nolibc: add pipe() support Message-ID: <20230728191717.GA32165@1wt.eu> References: <20230728155031.35125-1-falcon@tinylab.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230728155031.35125-1-falcon@tinylab.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Zhangjin, hi Yuan, On Fri, Jul 28, 2023 at 11:50:31PM +0800, Zhangjin Wu wrote: > Hi, Yuan > > > pipe is crucial for shell. > > > > As the syscall manpage[1] shows, pipe() is just one of the exceptions how > may require two return registers in some platforms, e.g.: > arch/mips/kernel/syscall.c > > * For historic reasons the pipe(2) syscall on MIPS has an unusual calling > * convention. It returns results in registers $v0 / $v1 which means there > * is no need for it to do verify the validity of a userspace pointer > * argument. Historically that used to be expensive in Linux. These days > * the performance advantage is negligible. > */ (...) Ah indeed! I vaguely remembered that I had left that one aside for some time but did not remember why. Now I remember that I couldn't handle the MIPS implementation by then while it used to be my primary target. > Since we are able to use pipe2() for pipe() (introduced from early Linux > 2.6.27, glibc 2.9) and use getpid+getppid for getxpid, getuid+geteuid > for getxuid and getgid+getegit for getxgid. > > So, it is possible provide such pipe() as a wraper of pipe2() and Indeed. > getxpid, getxuid and getxgid as wrappers of their corresponding syscall > pairs, I doubt anyone needs these ones, I didn't know them and do not even have their man page. Let's keep the focus on what developers really use. > then, no need to provide a second return value for all of the > existing architectures, for example: > > #ifndef pipe > int pipe(int pipefd[2]) > { > pipe2(pipefd, 0); > } > #endif > > And for mips: > > // may be in tools/include/nolibc/types.h ? > struct fd_pair { > long fd[2]; > }; > > // tools/include/nolibc/arch-mips.h > struct fd_pair pipe(void) > { > struct fd_pair fds; > int pipefds[2]; > > pipe2(pipefds, 0); > > fds.fd[0] = pipefds[0]; > fds.fd[1] = pipefds[1]; > > return fds; > } This one does not have the correct prototype for the function exposed to the user, pipe really is "int pipe(int pipefd[2])". Maybe you were thinking about sys_pipe() instead ? But since MIPS also has pipe2() now, there's no reason to make an exception. > To use such method, the test case should be changed too, perhaps an > easier method is even only provide pipe2() for all and let users define > their own pipe() if really required, we also need to change the test > case. No, we need to provide users with what they need to compile standard code. If we rely on pipe2() to deliver pipe(), that's fine. We can even do it per-arch if there are constraints but it seems to me that pipe2() is OK. Thanks, Willy