Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp32401489rwd; Fri, 7 Jul 2023 13:20:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlGNzJSsHKFZEROqtM/ISFuSmmRDX6sXpShN93ymeim9UTuKsnQEKuvzdPXa+q+e2l0RDNcR X-Received: by 2002:a17:907:90d5:b0:993:a37a:cb4c with SMTP id gk21-20020a17090790d500b00993a37acb4cmr4080432ejb.9.1688761200341; Fri, 07 Jul 2023 13:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688761200; cv=none; d=google.com; s=arc-20160816; b=i68W4hS2mTC88CgNl4etrsklZEdxDGt8PSiLZTsHN/T2OfAZbAnxpduUMWnlBP1kBu PtdhFSvcFZ59FQwHc48cwCdZQv8GVldEKRv5NM9OwtOTZZQNtNNFEr4P7FKyxY14MXBj ibbxXXNINkV4EI+0P0hNBbEznolaRdvM+E170CNaBbu7T3JByP4VRB9Mm81kA1+ANSGk QtzwiAfkSsw8QWa9abXxMmLGDMAKO9Pet5R0JsvAZafXLygCaKauHSmGhPJVqSBgiLb5 0ik0jHWjJQxr6I8jJp3bbSZPp3XoAdIn5WfUHzdU8+91QY2aXu17fN8PkQugFnDuNl3j wNZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=mgLH4x6SYCM3FO+eSHQqZ04OTA4A5LMIJOwD5iZGGk8=; fh=NmtsskQdu/O6roQi3gn349NqmySV54p2Yq9ndx6MhuI=; b=dVDDndhSAtsfdV4FE98nE2qh2+QyeYf/vgRCTOHOyUmgH0wqgjSVh3fRr0wMEYP5xH v0C03aOT9NRAny1XCmH6oKolbG3x4LIGduPDM/d1CSgF7cfh0to/s4zcdmrBODHqm4QC Vad9+VEzp6IFQxD4lYgV8UjtIaGxETtmiNJ/b5JZYRTDrjLhnYfSnbhrPhxX0YoNcvVc uAytHUXXf0fenuMRWzP6hOT6+rUWd6rr7RcoNA3YRatWk+7Jb9e/MOkEBHE35On6cgYq iZcoVkMxoD4KpAHYMingKrK9w36GveU8FlqAwy6rnvPO9wSgU/A7Iui8pdmIJWlUuFq/ AWvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20221208.gappssmtp.com header.s=20221208 header.b=cAhHHR31; 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 pw11-20020a17090720ab00b0099316735a60si1792461ejb.1042.2023.07.07.13.19.36; Fri, 07 Jul 2023 13:20:00 -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; dkim=pass header.i=@kernel-dk.20221208.gappssmtp.com header.s=20221208 header.b=cAhHHR31; 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 S231976AbjGGT5Q (ORCPT + 99 others); Fri, 7 Jul 2023 15:57:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229625AbjGGT5O (ORCPT ); Fri, 7 Jul 2023 15:57:14 -0400 Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 778EC1FEF for ; Fri, 7 Jul 2023 12:57:08 -0700 (PDT) Received: by mail-il1-x12a.google.com with SMTP id e9e14a558f8ab-345d2b936c2so2581515ab.0 for ; Fri, 07 Jul 2023 12:57:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1688759828; x=1691351828; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=mgLH4x6SYCM3FO+eSHQqZ04OTA4A5LMIJOwD5iZGGk8=; b=cAhHHR31cXZokqKFqFUU6LpiBxlJylyjK9v28qKYzx6+AzyKuhMfsw097GTDBDySuU nZSPnwCOpTx84jS/jzqemPck6uTOrYjRiLH6PqGIzbuplG74B9PvL0gZ/lbJsGkc/Qmg v95XSITioq9vER0belBMjKUyd4+6OgLDn7GXUQ3DB7eoPEUG/idT2dwk11+P0T+b+C+v 18W52rDVmcdWknEXzsdEwN4jrFXy5hwPt6WJvR2Ig2GFBRgYDG7aX+adZeDVFVA6Xf6l i0gyB/47Uxd5hTQMemH1ImSN3E4JKvptKPOnagts19kEX2M4xqy1ui41tfEXLp/RfSN4 JkUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688759828; x=1691351828; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mgLH4x6SYCM3FO+eSHQqZ04OTA4A5LMIJOwD5iZGGk8=; b=goqcJeJA/uP9LVNxi16t9GVvLraUXD/T3TUb6pw3w0PCgZzYHQo7r28yc7YOzpP+2N 6JreJv2EeSIHiDMPufRhP5xcm/9sTpiwPPM4yBxga/WqIftHt1ldU0yYlxLj+bdlqz2G aZrFVv/wNA6hjR+Qf5OZvYWm4h/Vi1g3uWMFDl1h2f+ocjg3M9DNTT6Jdl120RVNbEe2 18Za4KXyJFmjfKaxmMIAyIImXa4B41RajPOvZ2RU+6dYqRNiLyA8XxYgakBERUfxpqFm O4mta/GV2mTAypchcB88BcIZ1ACElO7lS0BEO+Chfl/qf9fO65uNmr8eCzc8gwEArXwH bqYA== X-Gm-Message-State: ABy/qLaAf01c+Tu+rVxY5zNH47ec1T4aKyk/JLRAOPZIKGVVxNusT4K8 PR+ALmGnQS/D5Su7FA9JY2uNyA== X-Received: by 2002:a05:6602:3993:b0:780:c6bb:ad8d with SMTP id bw19-20020a056602399300b00780c6bbad8dmr8772671iob.0.1688759827735; Fri, 07 Jul 2023 12:57:07 -0700 (PDT) Received: from [192.168.1.94] ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id u16-20020a02c950000000b0042b85d6e125sm900567jao.24.2023.07.07.12.57.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 07 Jul 2023 12:57:07 -0700 (PDT) Message-ID: <42294e31-9cc8-3c5a-c28f-cfa3854fbe69@kernel.dk> Date: Fri, 7 Jul 2023 13:57:06 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: Pending splice(file -> FIFO) excludes all other FIFO operations forever (was: ... always blocks read(FIFO), regardless of O_NONBLOCK on read side?) Content-Language: en-US To: Linus Torvalds , Christian Brauner Cc: =?UTF-8?Q?Ahelenia_Ziemia=c5=84ska?= , David Howells , Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org References: <20230626-vorverlegen-setzen-c7f96e10df34@brauner> <4sdy3yn462gdvubecjp4u7wj7hl5aah4kgsxslxlyqfnv67i72@euauz57cr3ex> <20230626-fazit-campen-d54e428aa4d6@brauner> <20230707-konsens-ruckartig-211a4fb24e27@brauner> From: Jens Axboe In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 On 7/7/23 1:10?PM, Linus Torvalds wrote: > On Fri, 7 Jul 2023 at 10:21, Christian Brauner wrote: >> >> Forgot to say, fwiw, I've been running this through the LTP splice, >> pipe, and ipc tests without issues. A hanging reader can be signaled >> away cleanly with this. > > So that patch still has a couple of "wait for this" cases remaining. > > In particular, when we do a read, and we do have pipe buffers, both > the read() system call and a number of internal splice functions will > go "Ahh, I have data", and then do pipe_buf_confirm() and read it. > > Which then results in pipe_buf_confirm() blocking. It now blocks > interruptibly, which is much nicer, but several of these users *could* > just do a non-blocking confirmation instead, and wait for pipe > readability. > > HOWEVER, that's slightly less trivial than you'd expect, because the > "wait for readability" needs to be done without the pipe lock held - > so you can't actually check the pipe buffer state at that point (since > you need the pipe lock to look up the buffer). > > That's true even of "trivial" cases like actual user-space "read() > with O_NONBLOCK and poll()" situations. > > Now, the solution to all this is *fairly* straightforward: > > (a) don't use "!pipe_empty()" for a readability check. > > We already have "pipe_readable()", but it's hidden in fs/pipe.c, > so all the splice() code ended up writing the "does this pipe have > data" using "!pipe_empty()" instead. > > (b) make "pipe_buf_confirm()" take a "non-blocking" boolean argument, > and if it is non-blocking but hits one of those blocked pages, set > "pipe->not_ready", and return -EAGAIN. > > This is ok, because "pipe_buf_confirm()" is always under the pipe > lock, and we'll just clear "pipe->not_ready" under the pipe lock after > finalizing all those pages (and before waking up readers) > > (c) make "pipe_wait_readable()" and "poll()" know about this all, so > that we wait properly for a pipe that was not ready to become ready > > This all makes *most* users deal properly with these blocking events. > In particular, things like splice_to_socket() can now do the whole > proper "wait without holding the pipe lock" sequence, even when the > pipe is not empty, just in this blocked state. > > This *may* also make all the cases Jens had with io_uring and splicing > JustWork(tm). Exactly! I was reading this thread with excitement just now, would be nice to get rid of that kludge. > NOTE! NOTE! NOTE! Once more, this "feels right to me", and I'd argue > that the basic approach is fairly straightfoward. The patch is also > not horrendous. It all makes a fair amount of sense. BUT! I haven't > tested this, and like the previous patch, I really would want people > to think about this a lot. > > Comments? Jens? I'll take a closer look at this, but won't be until Monday most likely. But the approach seems sane, and going in a more idiomatic direction than before. So seems promising. -- Jens Axboe