Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp176963iob; Mon, 2 May 2022 16:21:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmsLbkAxR4lTKqj/4LhNvlJx5orazlspA4YCi/ERYHCrHi8kiClaFL1p172a0H80/Le00V X-Received: by 2002:a17:902:b906:b0:14f:76a0:ad48 with SMTP id bf6-20020a170902b90600b0014f76a0ad48mr14096744plb.79.1651533683706; Mon, 02 May 2022 16:21:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651533683; cv=none; d=google.com; s=arc-20160816; b=bcq7HFYIPJ5WkCKCJ5jbWu8qu/4K574Nv9OcVocRnlnN6i/HvHhHFf/OcgAfOCXcNO gkJErkPI1y6xsyHsfPiOHaQmXt+GNDuO4dOYjll0KCycNNGcoAevY9NM53aHQwrIi/Ui QjKZAqRwhjBKiP30H7jBR6jN9GteL/nmrLLXkgD1humwP3LXuJL7Qd6+XZSX9uAR2DSQ PY4/+YYDbH9eoolh1USmEJASSOeAtNDuntf4LQqIL7VC9s8cXSOLr2CcNy+pS5UT+uCb hSz69aQFjh5GQTfc9B/oFxFDZkAMV9MrowflLO0I42pCMLVUzTx7WYCNOBqNIoA0XqiV NDOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=t7MLSEk1Zg4N4Mn5YyAWZbEoas0CNhuGYCu9wwnw6i0=; b=Ls0mO9utpJIc5ctHm0vKnvCCMZrJsXa2BeLEnBPT+hHN9iraAz2pHQ/y2g9BG3Hykt 2KoZDU7TV9Qs+zIuIH+vs93d0lEdpG/ebqc+p525qhPCRHGVIrfZF69IoRsKMJ/O8lg8 S8QUvYQtzAtrQO+UdGDwcuJk8KLX1vAipVgIYRxoUT5HBaKkrhtcSIvr90Oq7I54hf27 +ifm/CreYuuIcdXXNKaU0O73kZzljo2cT91a2Ai2ZMalWYlwWVo/A/J1j0jNSZLheYFb Rv9UeBsfLbVaQuX30APMeZXlvSXFXnwLzTGeLMAEVd5tcj8tfBPSemGnqt/h8/xWuxZv wROQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ahirv5dz; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id ob16-20020a17090b391000b001dc6391a6aasi707224pjb.79.2022.05.02.16.21.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 16:21:23 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ahirv5dz; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DCBE827B14; Mon, 2 May 2022 16:20:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358188AbiEBHF3 (ORCPT + 99 others); Mon, 2 May 2022 03:05:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238801AbiEBHF1 (ORCPT ); Mon, 2 May 2022 03:05:27 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2D9C6460; Mon, 2 May 2022 00:01:58 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id gj17-20020a17090b109100b001d8b390f77bso15408208pjb.1; Mon, 02 May 2022 00:01:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=t7MLSEk1Zg4N4Mn5YyAWZbEoas0CNhuGYCu9wwnw6i0=; b=ahirv5dzvVouAXT8RwoOabSoKNJRRFLUSaFEEDTZHdRUVq8VW4Lg+/2s7OcTUPj+LF e/Gub+1gSkUehxRdDEmTx8QS4LhPhfbBlFWTAYI3NNvlq4OpoH6wDUAwjxQ0TzoUQVWQ zuawSMlfn12c9eNHRqiLgln342w45ahqetAY825Q4YzsyV/5IN0P1dZSgByv04NeM6cv 1nj7oIwFez4xYH5gp8kvEvBPQxkacKDdCBPvha7MRShPSEtAphDqOZuWNx8tfp0J5+ZV k9njEY5PmaM/hWLDv4jjUwTmP98fgYJPWVSeU+wGwxGxns5rqc45RsuW7hqGpuindlCE YCcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=t7MLSEk1Zg4N4Mn5YyAWZbEoas0CNhuGYCu9wwnw6i0=; b=kWQCx5yRvEI/Oyc+zvtGgn0pqhVUPi1wVtwhD30zr0xHSUEH0C8MHi1y5dWBcl1igP zoPeJgKiue7Kyd7dT6wHYD0Qhdo8M09ksu5KDQ6koPMW9B3hLXnrBf5QE2J8oEfy5rZ6 zYJHE+VHtYHFYzTImdY01uPi3F1eZCGerj78sxr7nom3RTRJp1kZ0Vn+XM4u6tHedtIt 1GE5q0BObwtZlGzvFishOIetdCSzNV51Eq6D90VDVJIvoNtP+c8BfqN23bUt1HbCCBER 9+56WaMUXNGVZ2ZiGhE6hR6CGXI77MErDZkYXdRE90YeurN0mZlRnzifJXSbTiZosylH trog== X-Gm-Message-State: AOAM532cG43wWpHctFpnAjABDzbZC7k01/MJRCPQSID0bO7n8fBAOA6X XLPTlkXRdzyM8wf8jTxzzJCsG6jqz/qlkczrKnlt9nvcM58VnQ== X-Received: by 2002:a17:90b:380b:b0:1dc:6d24:76ff with SMTP id mq11-20020a17090b380b00b001dc6d2476ffmr393653pjb.42.1651474917714; Mon, 02 May 2022 00:01:57 -0700 (PDT) MIME-Version: 1.0 References: <20220415005015.525191-1-avagin@gmail.com> In-Reply-To: <20220415005015.525191-1-avagin@gmail.com> From: Andrei Vagin Date: Mon, 2 May 2022 00:01:46 -0700 Message-ID: Subject: Re: [PATCH] fs: sendfile handles O_NONBLOCK of out_fd To: LKML , Andrew Morton Cc: linux-fsdevel , stable@kernel.org, Alexander Viro Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Andrew, could you take a look at this patch? Here is a small reproducer for the problem: #define _GNU_SOURCE /* See feature_test_macros(7) */ #include #include #include #include #include #include #include #define FILE_SIZE (1UL << 30) int main(int argc, char **argv) { int p[2], fd; if (pipe2(p, O_NONBLOCK)) return 1; fd = open(argv[1], O_RDWR | O_TMPFILE, 0666); if (fd < 0) return 1; ftruncate(fd, FILE_SIZE); if (sendfile(p[1], fd, 0, FILE_SIZE) == -1) { fprintf(stderr, "FAIL\n"); } if (sendfile(p[1], fd, 0, FILE_SIZE) != -1 || errno != EAGAIN) { fprintf(stderr, "FAIL\n"); } return 0; } It worked before b964bf53e540, it is stuck after b964bf53e540, and it works again with this fix. Thanks, Andrei On Thu, Apr 14, 2022 at 5:50 PM Andrei Vagin wrote: > > sendfile has to return EAGAIN if out_fd is nonblocking and the write > into it would block. > > Cc: Al Viro > Cc: stable@kernel.org > Fixes: b964bf53e540 ("teach sendfile(2) to handle send-to-pipe directly") > Signed-off-by: Andrei Vagin > --- > fs/read_write.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/fs/read_write.c b/fs/read_write.c > index e643aec2b0ef..ee59419cbf0f 100644 > --- a/fs/read_write.c > +++ b/fs/read_write.c > @@ -1247,6 +1247,9 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, > count, fl); > file_end_write(out.file); > } else { > + if (out.file->f_flags & O_NONBLOCK) > + fl |= SPLICE_F_NONBLOCK; > + > retval = splice_file_to_pipe(in.file, opipe, &pos, count, fl); > } > > -- > 2.35.1 >