Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1175057ybl; Fri, 6 Dec 2019 12:32:07 -0800 (PST) X-Google-Smtp-Source: APXvYqyIwMSvFA+ipVAdieqpnrx/PXx7wJPiBpTBe1pHrRB/NKmyjdoQTiKw05LUw38Sl1NLXS7V X-Received: by 2002:aca:d4c1:: with SMTP id l184mr14252391oig.172.1575664326900; Fri, 06 Dec 2019 12:32:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575664326; cv=none; d=google.com; s=arc-20160816; b=aUHSy71Ss6MsnlGiXSJnSTbuhAjjJXgc6PW4kKbtfGZz9S0jlH+LGU7MnV0RGjum9s DYoyiy8d7YBFfbODq8QkRFkZ2mWTtPWXQaMLQ+sdn6pHgOL+fI5SjEneoNvaduvByV6F qEkFpHQ3MBqHGD752woVoIYf7JO5xm6P92iz4OS6xIiXA7f5o65BG6CaOQDfECg2w4ma kgmx9gi7V8dWPK1BgKRVJKl4n+ei8+GkWMgI5RW0vBPEUzgxmBlHA/cw++6w3prJnxR5 3tj77lOMvfaBcdvkM+2J1I7TBnwIisdg1/vP/jAyfRuC8FK8SleOAcep/hJ+bdmEbzw8 fPHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=D7AuzC7KPUuG+16rwarCAF7khGQqEuNHk2heBfehumM=; b=UGuNK8gIEeC3lgtrx35KeYupr6v5aTF7eDzuNk/6bax7EuQmSAAH+2y17qx3Al6iZs 5fTDDp2S5aCGCqtYI5H+l7N4st4lpsF+N91Qqatj55S+gxGca3yUEyO7PFx0p+ca2wVb fVcGk7cAid7PTv+YRh5qO7xAfB9vgRyzl1KyX05E6cAhJ0mr6YSjodNixD8nn5DwiD0P aAxG5EnsBt7lLDcH2o6GHzMISaVTOnN/ERs5uVRPtmsxasRk/UuNNLuGtmDGm8oClu4Q SauoduwaOMWJ6oB1v7ksAbE331wuWOy5/JdN7bXKraBOIhbRhn4ocVezdvyiftQi5APg j6/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=g8Wqm1Um; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s82si7630585oif.96.2019.12.06.12.31.41; Fri, 06 Dec 2019 12:32:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=g8Wqm1Um; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726388AbfLFU21 (ORCPT + 99 others); Fri, 6 Dec 2019 15:28:27 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:33971 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726353AbfLFU20 (ORCPT ); Fri, 6 Dec 2019 15:28:26 -0500 Received: by mail-lj1-f193.google.com with SMTP id m6so9047614ljc.1 for ; Fri, 06 Dec 2019 12:28:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=D7AuzC7KPUuG+16rwarCAF7khGQqEuNHk2heBfehumM=; b=g8Wqm1UmJpiH9XsG7+mZgytZn6KAUz++mHOwaddVEx2NVcxiPW1xU5oMTujibpzGt1 vA9Ahc4HGx1rvG4yaU+qIwSsmJrUqOaUYXaZB3Qxd428SSA5oPrNmN3i/iWippFABM3e SQvl5CWEZqP7WerH4SEuBDeTCnoSRwNi7YXJU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=D7AuzC7KPUuG+16rwarCAF7khGQqEuNHk2heBfehumM=; b=HYLGhWL4JEjkAgt4kR3JMV9GDMKIWxLGdrCDG3TTvpYla2IxAvu7+KP6bOGgWtF3L9 7UR3kRapFODZF04/AxpccS4Znf2a0/U8WUhHQRsi51HHJ/fqMnImjxxK89w9tL/B4TS7 NTpWrYhXqtkWPhOD8reBGRlSn2r4SQGpXiYQHnOGe5rO9It37AOgiyPITfVTwumtI+2e 58G8eKzgvtq8RPqEjTYNVlekiu09l0x5HE1qeUD5AkVnBwCmGhkryCxJedKTvlfXun44 N5YDJutLgtrWODdqHfvXclz9qsld2V65W2Mx1Lq/5VnfViuHs2IEe1t9qa9HiOyLBF+N tk1g== X-Gm-Message-State: APjAAAUXKs37IIvWsNMgQAGkpw4wMNSYjyxMaaxWlccQ317ownWRo5os 53j+NHzRbFuJtbuA2QN4rADSHHO8o74= X-Received: by 2002:a2e:8606:: with SMTP id a6mr9670828lji.119.1575664104320; Fri, 06 Dec 2019 12:28:24 -0800 (PST) Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com. [209.85.208.174]) by smtp.gmail.com with ESMTPSA id b17sm6990427lfp.15.2019.12.06.12.28.22 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Dec 2019 12:28:23 -0800 (PST) Received: by mail-lj1-f174.google.com with SMTP id c19so8954050lji.11 for ; Fri, 06 Dec 2019 12:28:22 -0800 (PST) X-Received: by 2002:a2e:99d0:: with SMTP id l16mr9946818ljj.1.1575664102180; Fri, 06 Dec 2019 12:28:22 -0800 (PST) MIME-Version: 1.0 References: <157558502272.10278.8718685637610645781.stgit@warthog.procyon.org.uk> <20191206135604.GB2734@twin.jikos.cz> In-Reply-To: <20191206135604.GB2734@twin.jikos.cz> From: Linus Torvalds Date: Fri, 6 Dec 2019 12:28:06 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 0/2] pipe: Fixes [ver #2] To: David Sterba , David Howells , Linus Torvalds , Eric Biggers , Al Viro , linux-fsdevel , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 6, 2019 at 5:56 AM David Sterba wrote: > > For reference, I've retested current master (b0d4beaa5a4b7d), that > incldes the 2 pipe fixes, the test still hangs. I think I found it. TOTALLY UNTESTED patch appended. It's whitespace-damaged and may be completely wrong. And might not fix it. The first hunk is purely syntactic sugar - use the normal head/tail order. The second/third hunk is what I think fixes the problem: iter_file_splice_write() had the same buggy "let's cache head/tail/mask" pattern as pipe_write() had. You can't cache them over a 'pipe_wait()' that drops the pipe lock, and there's one in splice_from_pipe_next(). Linus --- snip snip -- diff --git a/fs/splice.c b/fs/splice.c index f2400ce7d528..fa1f3773c8cd 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -495,7 +495,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des unsigned int mask = pipe->ring_size - 1; int ret; - while (!pipe_empty(tail, head)) { + while (!pipe_empty(head, tail)) { struct pipe_buffer *buf = &pipe->bufs[tail & mask]; sd->len = buf->len; @@ -711,9 +711,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out, splice_from_pipe_begin(&sd); while (sd.total_len) { struct iov_iter from; - unsigned int head = pipe->head; - unsigned int tail = pipe->tail; - unsigned int mask = pipe->ring_size - 1; + unsigned int head, tail, mask; size_t left; int n; @@ -732,6 +730,10 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out, } } + head = pipe->head; + tail = pipe->tail; + mask = pipe->ring_size - 1; + /* build the vector */ left = sd.total_len; for (n = 0; !pipe_empty(head, tail) && left && n < nbufs; tail++, n++) {