Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp33493160rwd; Sat, 8 Jul 2023 13:18:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlEnkWOlUZAVx6mIkRk8ZK9bM38wE0V0V/eAlTx6ciNl05Bo9MC2wj+CcxRr/T+iuoLze3vh X-Received: by 2002:a2e:96c6:0:b0:2b6:eb8c:af06 with SMTP id d6-20020a2e96c6000000b002b6eb8caf06mr6354808ljj.8.1688847488041; Sat, 08 Jul 2023 13:18:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688847488; cv=none; d=google.com; s=arc-20160816; b=wEN8WSNEHuskNUdgZqOacu5bdz4vstTf0KLVR0WG9rvbOmSG3lO/OU4FdrC950MnEb BcPnmQl9s3YusNWvrGt7fUjL240FpbSzp5i4OSd0U/VxqLqghaPmaM5+Z9aYGhquyOAC rj4EX4JZJGVpcMBLeZXEXunzKVJuyxZ1x953piNc8JaR+m3pXpQaMLFLwAlCUd0EztUR a35Ig44H8FY0iSWGqcO8nQFarfrnSobO6ZjEKtH8YqnmE/oS0tqspE9ePVdwD70La1Xg s60WyBuFHM8nGHaAUYoLSytyKZPwU0+f2Omj7XApBOmQh0GoI2Aw5ZbVG/58EfAYyH6c gGqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=p4Vp3Erq+15doC8TaKuLyM/3Ed9sN2YSA27huRqWK3E=; fh=oG/VNmW4AJWGtL4MWiEK/gPzCFKJNdDT1OLkdPA0RO0=; b=WDxavwp04/tldnZMXMkl3hElGdXB2AW34d6R3mLAm8ela1qGoMo8bL/88rUbQiadKr WA/g3xuhqdI5qp7bmrb8SLf/dQwZIeGgGaXCRWq3dIHCbYB2YvOTfO36097jMAoskIKC 4J/2bHNYfPx19RQy4kie2fdQdYkN3htosrp0RzFi9tuXZkw0IgV/Nk6NT1MsuiCsLqx3 78eNrWkYbltVF0Zuk89s/KqseIdfeLn6zH3tDzRD5wOoT73fMbyHDcYEWzdRPUXlGdGk VRtZYIUMLomOB/iUoi3x9htu6Z4BcGrP+0yhlBfJ5JftJHYlCF0Y3BOzJmny7ZISipeN 3NHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=DdN9gbE0; 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 sb22-20020a170906edd600b0099392706398si3697907ejb.231.2023.07.08.13.17.44; Sat, 08 Jul 2023 13:18:08 -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=@linux-foundation.org header.s=google header.b=DdN9gbE0; 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 S229905AbjGHUHU (ORCPT + 99 others); Sat, 8 Jul 2023 16:07:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjGHUHS (ORCPT ); Sat, 8 Jul 2023 16:07:18 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 608D8E40 for ; Sat, 8 Jul 2023 13:07:16 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2b6afc1ceffso50396351fa.0 for ; Sat, 08 Jul 2023 13:07:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1688846834; x=1691438834; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=p4Vp3Erq+15doC8TaKuLyM/3Ed9sN2YSA27huRqWK3E=; b=DdN9gbE0dmOUglBUKd1NpEKQ0KoynKPwGIP7Yxe9xRmzSTcBuG0SJzw6xM7cDxvm0i zOX2zG8qWnoPnU8iB1Aki0/PCf9bu/DfRAKYBE+KySAT4i/KHbyHnuwYRNqCnP/nPFTo dGf/1tiT1jhYkXEhytI38Q6/8RDzWLQLJyRiE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688846834; x=1691438834; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p4Vp3Erq+15doC8TaKuLyM/3Ed9sN2YSA27huRqWK3E=; b=enIvlKrDTadjJevs410lxk4qb3Gxs07XzGfT6CbZOGxPXEgrX/OAUfjK0Af15QYDos nAx7ANgt443+GGZUvf++fpEqf20DLpWqTduoXQtnLLMevm3Z9A+WkmzFBiZvULG8yxUf tyhlAgq3RmXtVwEu2mhiSgCpU0lfcGCTUOgqOo1w9T4zLx3cnd5FNLeSvHDtPHD3cnJ7 yCfORWJ8H+733z1aU9oa66RRL24Pj3jrlrO/QSaIdzycl3mv3S3GFkwa/H+Dq5nnNHGb sD3A9djp68gQoWVOonJlSAj0t+E2pqY0W3U2VNGcmz9PoSUyariwV4HPKAE2bpkbwdx8 s8MQ== X-Gm-Message-State: ABy/qLZ/JT3xYYkSbr46NRRdzGSlKg9yvY3hjm1lQgdH4MZw6SrBYH4P TNKu2X2dImcdEO/m6WdiQI1UEOdZo2plYR0uT4u0Dmg0 X-Received: by 2002:a19:5e06:0:b0:4f9:5a61:194f with SMTP id s6-20020a195e06000000b004f95a61194fmr6110334lfb.11.1688846834478; Sat, 08 Jul 2023 13:07:14 -0700 (PDT) Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com. [209.85.221.53]) by smtp.gmail.com with ESMTPSA id h22-20020a170906399600b0099329b3ab67sm3883601eje.71.2023.07.08.13.07.13 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 08 Jul 2023 13:07:13 -0700 (PDT) Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-31441bc0092so3027495f8f.1 for ; Sat, 08 Jul 2023 13:07:13 -0700 (PDT) X-Received: by 2002:a5d:4b8e:0:b0:313:eb4d:6a0e with SMTP id b14-20020a5d4b8e000000b00313eb4d6a0emr6250669wrt.9.1688846832870; Sat, 08 Jul 2023 13:07:12 -0700 (PDT) MIME-Version: 1.0 References: <20230626-vorverlegen-setzen-c7f96e10df34@brauner> <4sdy3yn462gdvubecjp4u7wj7hl5aah4kgsxslxlyqfnv67i72@euauz57cr3ex> <20230626-fazit-campen-d54e428aa4d6@brauner> <20230707-konsens-ruckartig-211a4fb24e27@brauner> In-Reply-To: From: Linus Torvalds Date: Sat, 8 Jul 2023 13:06:56 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Pending splice(file -> FIFO) excludes all other FIFO operations forever (was: ... always blocks read(FIFO), regardless of O_NONBLOCK on read side?) To: =?UTF-8?Q?Ahelenia_Ziemia=C5=84ska?= Cc: Christian Brauner , Jens Axboe , David Howells , Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 Fri, 7 Jul 2023 at 17:30, Ahelenia Ziemia=C5=84ska wrote: > > Same reproducer, backtrace attached: > $ scripts/faddr2line vmlinux splice_from_pipe_next+0x6e > splice_from_pipe_next+0x6e/0x180: > pipe_buf_confirm at include/linux/pipe_fs_i.h:233 Bah. I should have looked more closely at your case. This is a buffer without an 'ops' pointer. So it looks like was already released. And the reason is that the pipe was readable because there were no writers, and I had put the if (!pipe->writers) return 0; check in splice_from_pipe_next() in the wrong place. It needs to be *before* the eat_empty_buffer() call. Duh. Anyway, while I think that fixes your NULL pointer thing, having looked at my original patch I realized that keeping the pointer to the pipe buffer in copy_splice_read() across the dropping of the pipe lock is completely broken. I thought (because I didn't remember the code) that pipe resizing will just copy the pipe buffer pointers around. That would have made it ok to remember a pipe buffer pointer. But it is not so. It will actually create new pipe buffers and copy the buffer contents around. So while fixing your NULL pointer check should be trivial, I think that first patch is actually fundamentally broken wrt pipe resizing, and I see no really sane way to fix it. We could add a new lock just for that, but I don't think it's worth it. > You are, but, well, that's also the case when the pipe is full. > As it stands, the pipe is /empty/ and yet /no-one can write to it/. > This is the crux of the issue at hand. No, I think you are mis-representing things. The pipe isn't empty. It's full of things that just aren't finalized yet. > Or, rather: splice() from a non-seekable (non-mmap()pable?) Please stop with the non-seekable nonsense. Any time I see a patch like this: > + if (!(in->f_mode & FMODE_LSEEK)) > + return -EINVAL; I will just go "that person is not competent". This has absolutely nothing to do with seekability. But it is possible that we need to just bite the bullet and say "copy_splice_read() needs to use a non-blocking kiocb for the IO". Of course, that then doesn't work, because while doing this is trivial: --- a/fs/splice.c +++ b/fs/splice.c @@ -364,6 +364,7 @@ ssize_t copy_splice_read(struct file *in, loff_t *ppo= s, iov_iter_bvec(&to, ITER_DEST, bv, npages, len); init_sync_kiocb(&kiocb, in); kiocb.ki_pos =3D *ppos; + kiocb.ki_flags |=3D IOCB_NOWAIT; ret =3D call_read_iter(in, &kiocb, &to); if (ret > 0) { I suspectr you'll find that it makes no difference, because the tty layer doesn't actually honor the IOCB_NOWAIT flag for various historical reasons. In fact, the kiocb isn't even passed down to the low-level routine, which only gets the 'struct file *', and instead it looks at tty_io_nonblock(), which just does that legacy file->f_flags & O_NONBLOCK test. I guess combined with something like if (!(in->f_mode & FMODE_NOWAIT)) return -EINVAL; it might all work. Linus