Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5361157ybl; Sun, 22 Dec 2019 04:38:36 -0800 (PST) X-Google-Smtp-Source: APXvYqxDn0yy+8n8NcE3ZxUiiZlhsXpkwVz/ZJT8IdkEC0pepfEI2fInKMcUvFcItx0x+l+hLg6J X-Received: by 2002:a9d:21f5:: with SMTP id s108mr6507104otb.152.1577018316406; Sun, 22 Dec 2019 04:38:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577018316; cv=none; d=google.com; s=arc-20160816; b=ovjFqbyZ91Y/QsMcfHOHnI9hKq5p1OX/TWU9MJPPo3aPqqqIlnnMPkpwroD/vo0Sa7 Nc2FS/uo95wS+VtFsd5XmMCoQdrM77/4flwnxuqeOUmrAiy7DeSpY8+r3N3v1F9j7bAm iU9WwGb6+swMQJ6s/XKQN3dcpw5XVBkFkThxDj71j5PiLjZEoEauoNXzsx/YDCZU9VTB A5UZq6QlDB8L/fT4gGtWhinjHjicUwlELqmt3GdEqOsER72jyJwWi8hud45clOkFmfIy D7Qw6xUKyGBCEIOLkvTvrz1PDJum6KeHXDSssEgGyLWV2ctKivaH0/DIo8kn0Eyk2XdX yTKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=NK/+oH5PS+9JogKOeHE773KhmgeeUExyinl8Dzq73ME=; b=eNi04mTlvGdZAP4UtTzRjW/bbvw3DxvNmQrfYyLXb+tO9xV8DZq4PZLOkLEAr5fcUf LJQLcEPwgy0ZS6XZja7J9xKdxs6xEREDzueXNuqPFsBme+wR7JMlHGBd/lgNWuoPOjZ1 1d8FWvcMHoa3k+czMF1rG5QaS5lJgnHgB9iwkKHXwAoLuduzvEjQyr5FuGK0Yg07fUxm a3nG81hFKPyGyx/gyiwEt0olDpibQFEVY2jBpGzwGdV/5EknOeJus4H+Y+PPvUweZGZv 70j60sh6N66WXAdtkXYdp4PkJOTWqXtF15Z8uSAHhrXnEOSIPletAH5Psopqm8J2ESdo yXAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JEARhVaw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k7si6705767otb.90.2019.12.22.04.38.12; Sun, 22 Dec 2019 04:38:36 -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=@redhat.com header.s=mimecast20190719 header.b=JEARhVaw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726633AbfLVMfI (ORCPT + 99 others); Sun, 22 Dec 2019 07:35:08 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:30897 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726189AbfLVMfI (ORCPT ); Sun, 22 Dec 2019 07:35:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577018107; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=NK/+oH5PS+9JogKOeHE773KhmgeeUExyinl8Dzq73ME=; b=JEARhVawUeg3A1rV+xCvT4sj0fJoNH2kW8x0roqyUhgEJ03HG6uDC79JVYPi/wOG7Hr03w Pl9cevHtXXvgWKKAqasZrlaJGR+KHGQ1JVoHVcb+15xEHZ6t/dmCP/zptR1VjDvoilAP45 lUd+8e1QNOiGMIopK+nZyqLNDQaJvt0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-110-hfmQO_ZBMzm7W1Z2L0kHSA-1; Sun, 22 Dec 2019 07:35:00 -0500 X-MC-Unique: hfmQO_ZBMzm7W1Z2L0kHSA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B6B88100550E; Sun, 22 Dec 2019 12:34:59 +0000 (UTC) Received: from dustball.brq.redhat.com (unknown [10.43.17.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B46663F8A; Sun, 22 Dec 2019 12:34:57 +0000 (UTC) From: Jan Stancek To: torvalds@linux-foundation.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, dhowells@redhat.com, viro@zeniv.linux.org.uk, rasibley@redhat.com, jstancek@redhat.com Subject: [PATCH] pipe: fix empty pipe check in pipe_write() Date: Sun, 22 Dec 2019 13:33:24 +0100 Message-Id: <65b22cd4e8bb142c5b7b86bc33fb08de6f318089.1577017472.git.jstancek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org LTP pipeio_1 test is hanging with v5.5-rc2-385-gb8e382a185eb, with read side observing empty pipe and sleeping and write side running out of space and then sleeping as well. In this scenario there are 5 writers and 1 reader. Problem is that after pipe_write() reacquires pipe lock, it re-checks for empty pipe with potentially stale 'head' and doesn't wake up read side anymore. pipe->tail can advance beyond 'head', because there are multiple writers. Use pipe->head for empty pipe check after reacquiring lock to observe current state. Testing: With patch, LTP pipeio_1 ran successfully in loop for 1 hour. Without patch it hanged within a minute. Fixes: 1b6b26ae7053 ("pipe: fix and clarify pipe write wakeup logic") Reported-by: Rachel Sibley Signed-off-by: Jan Stancek --- fs/pipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/pipe.c b/fs/pipe.c index 04d004ee2e8c..57502c3c0fba 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -581,7 +581,7 @@ static inline bool pipe_writable(const struct pipe_inode_info *pipe) } wait_event_interruptible(pipe->wait, pipe_writable(pipe)); __pipe_lock(pipe); - was_empty = pipe_empty(head, pipe->tail); + was_empty = pipe_empty(pipe->head, pipe->tail); } out: __pipe_unlock(pipe); -- 1.8.3.1