Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2137349ybl; Thu, 19 Dec 2019 08:38:22 -0800 (PST) X-Google-Smtp-Source: APXvYqwa77ZmUWT+UC7AJmuAnDrIoPzQ/1ATd2/VR0e5A29Eroq5UeuvZ6Ahow8cHDaHVruvfJcF X-Received: by 2002:a05:6830:1e46:: with SMTP id e6mr6847455otj.245.1576773502049; Thu, 19 Dec 2019 08:38:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576773502; cv=none; d=google.com; s=arc-20160816; b=CB5e0GSyP3pW0PZ6Bp6zobQfJcQxhULpEl5McY2X7id0WwR3TIDFlHDrT89Y/+QQwv ZEooHe2L7yeuB9TYVUzRP5/DaRmdsxhUOm21a4K5g8kT42EZwRkRU2WQ0NQOxR/DvQz9 g0sgNeknX3heSrMTQIq65PSQR2x83Oi/1QePnaRRAB6C8RmUL0g17EBxp7+IHRXcMNx5 TytZ/b/6RASVUKAt6khcvjKHY0lMxP24xVSSU1p0Z3iwaR4l2PiTxnJh3JTW6ss0DkCU cgo/zjkR9PgNim6w0rQrHGlTc2xIYefXlBlN9x/9VA23ysOgWmgbDHBPJd0yY6Z9X2BF aZGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=+0EPaeAm1h5et+pcE0Lw2TnBFxWaf1zou6EIoTCmP30=; b=UazJTMLztyIdnrW9Br/E7wjy2U7F4J7De17JHk0Q6q1Iz3QiZ+mD6nuwEouFaEUUrs O3Xka/mOoIHPXM+SD3OzgCItJmQ0B6yKfqLkHuG/6lQlOJI33Rp9eIbr7kT/IOakdvqA aQokGDGp+ZUCZuJ1FKw4lFBMTDz3FgxUOjgDKkUqA+Z2NnZxjIM6sqIgvI7e2hiwZmvX TeRa7RYYruQXQYV22lsEIjWcEBD6aa+4IZzQOHvJyjLfNwInoZ/8JXGQFZJjI2OPr2at BX2hzgALPsfIXaQZwd7RTsL2Kh0DKmMTolv8g5Ak+uc6/jUdhU4G2AcF7TgdQLnYeDfc e/Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=bZHWn0Ps; 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 i17si3453273otl.149.2019.12.19.08.38.08; Thu, 19 Dec 2019 08:38:22 -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=bZHWn0Ps; 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 S1726949AbfLSQgI (ORCPT + 99 others); Thu, 19 Dec 2019 11:36:08 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:46971 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726760AbfLSQgI (ORCPT ); Thu, 19 Dec 2019 11:36:08 -0500 Received: by mail-lj1-f195.google.com with SMTP id m26so4491788ljc.13 for ; Thu, 19 Dec 2019 08:36:06 -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 :cc; bh=+0EPaeAm1h5et+pcE0Lw2TnBFxWaf1zou6EIoTCmP30=; b=bZHWn0PsXhDbOK/Bql+EUdVYbHBqZFT+2Nbu2NKTbOPDpYJnxQ8/xUws763LXH9j3m XvTn3+qa6G5xDrHkogar6bc8r1mWIiQFLSpH4PfDJaTYQjML3UPjF8ReFuAn4IPFe3wt CsSw4N/hW8UkyP4cDs7xLRa2iwzcttIS4FCkc= 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:cc; bh=+0EPaeAm1h5et+pcE0Lw2TnBFxWaf1zou6EIoTCmP30=; b=fLD6SclczqgTxMqc83/PnM03yC46mYN7SgbMrpuWcceQgBO3izOnPZVWN3a6VBdcPb SEHQSQNh/BGfB7L8LUXFCPa2IGoVPJ6BkCLwB17gWPSC5aUmylJU2Cheb9YWy3k2kIKf sMY6lfHxx5UXEG1gcgz2MI8Wqu3Zoej86OG79zmiFxNByPd78mvZmaBaq7UH1l89W0ag CsFDqBPal7Sqd57osdmt/nGO/Uq+1gOtugH1hdxGWG4ZbOdSjZhMy4QudpqItfAuNGmI kPNKTQDQw67c16Zkg4WcbkUHoREkNRJJcrMIR31joj5po7XFnIVPbe9OeiCd6SlnWwNX 2gtA== X-Gm-Message-State: APjAAAWNvmSqqBaUBz1j6pafXGaF6o3oFouDAApRUxULVrTyTrDRRTDf Bbgghy1X5oGZpW0AfpdGOEXFY1bVZdU= X-Received: by 2002:a2e:844e:: with SMTP id u14mr6753013ljh.183.1576773365064; Thu, 19 Dec 2019 08:36:05 -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 u9sm3103342lji.49.2019.12.19.08.36.03 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Dec 2019 08:36:04 -0800 (PST) Received: by mail-lj1-f174.google.com with SMTP id u17so6934692lja.4 for ; Thu, 19 Dec 2019 08:36:03 -0800 (PST) X-Received: by 2002:a2e:9ad1:: with SMTP id p17mr6832409ljj.26.1576773363095; Thu, 19 Dec 2019 08:36:03 -0800 (PST) MIME-Version: 1.0 References: <157558502272.10278.8718685637610645781.stgit@warthog.procyon.org.uk> <20191206135604.GB2734@twin.jikos.cz> <20191219000013.GB13065@localhost> <20191219001446.GA49812@localhost> <935.1576742190@warthog.procyon.org.uk> In-Reply-To: <935.1576742190@warthog.procyon.org.uk> From: Linus Torvalds Date: Thu, 19 Dec 2019 08:35:46 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 0/2] pipe: Fixes [ver #2] To: David Howells Cc: Josh Triplett , Konstantin Khlebnikov , Akemi Yagi , DJ Delorie , David Sterba , Eric Biggers , Al Viro , linux-fsdevel , Linux Kernel Mailing List , Peter Zijlstra , Ingo Molnar , Vincent Guittot 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 Wed, Dec 18, 2019 at 11:56 PM David Howells wrote: > > I looked at splitting the waitqueue in to two, but it makes poll tricky. No, it's actually trivial for poll. The thing is, poll can happily just add two wait-queues to the poll_table. In my conversion, I just did - poll_wait(filp, &pipe->wait, wait); + if (filp->f_mode & FMODE_READ) + poll_wait(filp, &pipe->rd_wait, wait); + if (filp->f_mode & FMODE_WRITE) + poll_wait(filp, &pipe->wr_wait, wait); which changes the unconditional "add one" to two conditional adds. They _could_ have been unconditional too, but why add unnecessary wakeups? So it only really does it twice on named pipes (if opened for reading and writing). It's _unusual_ to add two wait-queues for a single poll, but it's not wrong. The tty layer has always done it - exactly because it has separate wait queues for reading and writing. Some other drivers do too. Sometimes there's a separate wait queue for errors, sometimes there are multiple wait-queues because there are events from the "subsystem" and there are other events from the "device". I think sound does the latter, for example. And no, I don't particularly like the FMODE_READ/WRITE testing above - it would be better to pass in the polling mask and ask "are we waiting for polling for reading or writing?" instead of asking whether the file descriptor was opened for read or write, but hey, it is what it is. Sadly, "poll()" doesn't really get passed the bitmask of what is being waited on (it's there in the poll_tabvle "_key" field, but I don't want to have the pipe code look into those kinds of details. So the named pipe case could be improved, but it's not like anybody really cares. Nobody uses named pipes any more (and few people ever did). So I didn't worry about it. Linus