Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4714125iob; Sun, 8 May 2022 23:00:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxr9k7mw7LBJCtLTb0Wuk4e7o7c37KBeZMSEYRVW4OYHEaC2fh8hToB+hlej+w6rf4pd4Ez X-Received: by 2002:a63:455e:0:b0:3c6:270f:cec4 with SMTP id u30-20020a63455e000000b003c6270fcec4mr11828249pgk.417.1652076021965; Sun, 08 May 2022 23:00:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652076021; cv=none; d=google.com; s=arc-20160816; b=psqKudk3dAJAKvlq3jqQGqJysvzKL4si0S/eRo68CTjzd++0NrVWeSctW233o0EQ4V n2l7bTkjvy3GCbcCKr5JbSANiUp7YtoK9goUuvv1KFtkLhMFE8KxLXmrvHFUmFTbqHur S8wMZ3JxqUEKhocCX5WMNbf2st90a1bO+fT1SyY/J7T27e8vyxVrh8Y4ijet7iNUDoOB Fok10pp9Ob2PbYv1lqht/d223eN62aWEEu8IfWFv5Yhua+iam0d+YvzcImIHEnV6hpak 5nw5jR9VAwQ7OsTnL7aA8MmxBUb/a5QTEtThL4PHC44wwBKaw2fxDGgsKHavCuBwI1ei GBIw== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=L0vTBUu7cERNrSt/2j/cpvelXrPJBDUXqkluepqf8b8=; b=fN67Ba4lTVHAiFoU+U+d7idGRPzfUryKMJZsJ2XeR0LVcWO3zd+srMdcKzynx8RV+A xSVYCXnh5aMh+obCECF+K6ykT7cZQl3sj3qNBQ+pzotUCCGkszDP9TXgHPYiZOgi47y+ 6wYEnXICrsGNzhFt5ck9xa61FbHevHkrlVeg+f38YS1yNrQDHNGKo/FEnUEVaMrTy3T0 XgEpz/sL1RGhDGQQFmIwcPKIt+x6pWuQlb6eljKSZH1Y1s59apFncq1IdEPl/WaGV/r/ aNIoCSxkAVMxespcVEhkdWppci1qZNijaZG7Z7v5dWqaio4CORgW5xrB7AyrS1IdMp7j YLfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jSsthn14; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u9-20020a170902e5c900b00158dd22994dsi13750230plf.93.2022.05.08.23.00.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 23:00:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jSsthn14; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 EB44B80739; Sun, 8 May 2022 23:00:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238782AbiEHTGE (ORCPT + 99 others); Sun, 8 May 2022 15:06:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238191AbiEHScE (ORCPT ); Sun, 8 May 2022 14:32:04 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27B962DF7; Sun, 8 May 2022 11:28:14 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d22so11937911plr.9; Sun, 08 May 2022 11:28:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=L0vTBUu7cERNrSt/2j/cpvelXrPJBDUXqkluepqf8b8=; b=jSsthn14SJCrQ++glajXqdmZL710hNBoeiChvIIa2mF54enjFgsN60hFht2Ig41Y/F s15VvMWd/z9OCWjSezTGMmY2w1Xk90IIymsv2zGmFAHbB+0kjZr5M23Ex7pAUV8YLSXx i/QIgEi39FE6nPWsZwuVxbEmWf8HThYWGvVJyIlhUjMgbozOpZOm1P31r5iC73NzWcOn Q+NOAdGnq0tzlWX9SGruGL7rgOkCKccpNd2zGoJsqJvoaOH0rJYyw7zp9aNTNKGhoBX+ HsQT2OVDnX5mnAKsyK1uGvOTvmD2vVaGz7fgfyCQ8ktGlH/gHfMLD0n6ekbJ5Y5YN8YF jv1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=L0vTBUu7cERNrSt/2j/cpvelXrPJBDUXqkluepqf8b8=; b=MzrpBYrViDDEaJA6B03/PItHrkfao5EpWU+4yA+z+/ql5PARR4hvSj41qQq4gxHibG EySzDANWliYeJjarsl4p+SatmvKxsXhoJJqhzS5Rvs5xDgxFPGqZhmH9HnF36CeKNRBA Y2ezdv+p6i2+U7V5glbCgTSs7uRUgXXVOQASJGp/MRkfmR6f2XVGx5JuNDRJ7Eu76bGj M+gLm4D7GgbBoFosngE/uUtxwGkF7YVGfwgwC5DFB4OshIQqNMzXblIgV0941JlQaGa0 08NkU3yVvz9anesvnf+qyR0UUKxwjhs0ZF98lTbKNEeoi4Eb2aO121vzMt+GHxqCGwfy Pz8A== X-Gm-Message-State: AOAM530PFARqatliSGYIQp0w2M3txVSwfd5XqWsKt5VPEmVpBvmdGQka PDwwBqmHArXamfHP06KiSvA= X-Received: by 2002:a17:90a:f3cb:b0:1d9:62d4:25db with SMTP id ha11-20020a17090af3cb00b001d962d425dbmr14412062pjb.222.1652034493427; Sun, 08 May 2022 11:28:13 -0700 (PDT) Received: from gmail.com ([2601:600:8500:5f14:d627:c51e:516e:a105]) by smtp.gmail.com with ESMTPSA id c2-20020aa79522000000b0050dc7628164sm7038349pfp.62.2022.05.08.11.28.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 11:28:12 -0700 (PDT) Date: Sun, 8 May 2022 11:28:07 -0700 From: Andrei Vagin To: Andrew Morton Cc: LKML , linux-fsdevel , stable@kernel.org, Alexander Viro Subject: Re: [PATCH] fs: sendfile handles O_NONBLOCK of out_fd Message-ID: References: <20220415005015.525191-1-avagin@gmail.com> <20220507145224.a9b6555969d6e66586b6514c@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline In-Reply-To: <20220507145224.a9b6555969d6e66586b6514c@linux-foundation.org> 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 On Sat, May 07, 2022 at 02:52:24PM -0700, Andrew Morton wrote: > On Mon, 2 May 2022 00:01:46 -0700 Andrei Vagin wrote: > > > 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. How did b964bf53e540 cause this? do_splice_direct() > accidentally does the right thing even when SPLICE_F_NONBLOCK was not > passed? do_splice_direct() calls pipe_write that handles O_NONBLOCK. Here is a trace log from the reproducer: 1) | __x64_sys_sendfile64() { 1) | do_sendfile() { 1) | __fdget() 1) | rw_verify_area() 1) | __fdget() 1) | rw_verify_area() 1) | do_splice_direct() { 1) | rw_verify_area() 1) | splice_direct_to_actor() { 1) | do_splice_to() { 1) | rw_verify_area() 1) | generic_file_splice_read() 1) + 74.153 us | } 1) | direct_splice_actor() { 1) | iter_file_splice_write() { 1) | __kmalloc() 1) 0.148 us | pipe_lock(); 1) 0.153 us | splice_from_pipe_next.part.0(); 1) 0.162 us | page_cache_pipe_buf_confirm(); ... 16 times 1) 0.159 us | page_cache_pipe_buf_confirm(); 1) | vfs_iter_write() { 1) | do_iter_write() { 1) | rw_verify_area() 1) | do_iter_readv_writev() { 1) | pipe_write() { 1) | mutex_lock() 1) 0.153 us | mutex_unlock(); 1) 1.368 us | } 1) 1.686 us | } 1) 5.798 us | } 1) 6.084 us | } 1) 0.174 us | kfree(); 1) 0.152 us | pipe_unlock(); 1) + 14.461 us | } 1) + 14.783 us | } 1) 0.164 us | page_cache_pipe_buf_release(); ... 16 times 1) 0.161 us | page_cache_pipe_buf_release(); 1) | touch_atime() 1) + 95.854 us | } 1) + 99.784 us | } 1) ! 107.393 us | } 1) ! 107.699 us | } > > I assume that Al will get to this. Meanwhile I can toss it > into linux-next to get some exposure and so it won't be lost. >