From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751723AbbCHBdX (ORCPT ); Sat, 7 Mar 2015 20:33:23 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:52954 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750820AbbCHBdV (ORCPT ); Sat, 7 Mar 2015 20:33:21 -0500 Date: Sun, 8 Mar 2015 01:33:20 +0000 From: Al Viro To: Linus Torvalds Cc: Linux Kernel Mailing List Subject: Re: [RFC] ->poll() bugs Message-ID: <20150308013320.GG29656@ZenIV.linux.org.uk> References: <20150305154921.GZ29656@ZenIV.linux.org.uk> <20150307204405.GC29656@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 07, 2015 at 12:53:14PM -0800, Linus Torvalds wrote: > On Sat, Mar 7, 2015 at 12:44 PM, Al Viro wrote: > > > > Most of the catch consists of ->poll() instances that return -E...; there's > > also an unpleasant mess in net/9p/trans_fd.c and a braino in sunrpc > > unexpectedly caught by the same annotations. > > Hmm. I do wonder if we should just *allow* ->poll() to return an > error, and just turn it into "all bits set"? Doable, but... we do have a bunch of ->poll() call sites (AFAICS, right now it's drivers/staging/comedi/drivers/serial2002.c:142: drivers/vfio/pci/vfio_pci_intrs.c:191: drivers/vhost/vhost.c:95: fs/eventpoll.c:800: fs/proc/inode.c:229: fs/select.c:461: fs/select.c:764: mm/memcontrol.c:4285: net/9p/trans_fd.c:249: net/9p/trans_fd.c:254: virt/kvm/eventfd.c:418: ) and while they could be turned into calls of a wrapper, I really don't like returning negatives as a part of ->poll() calling conventions. I mean, really - "you should return a bitmap of POLL... flags *or* -E...; doesn't matter which error number it is, it'll be lost anyway"... It's OK to have the caller(s) catch such bugs (and report them, IMO), but silently treating it that way as a part of calling conventions... Besides, that doesn't catch the bugs like one in net/9p; sparse annotations do. > But if getting sparse to catch them all isn't *too* painful and the > patch doesn't end up being horribly big, then I guess that's ok. Getting sparse to catch them all is as trivial as * introduce a __bitwise typedef __poll_t => unsigned int * say that ->poll() (in file_operations, as well as in proto_ops, tty_ldisc_ops and several in other subsystems) returns __poll_t * switch the return type of instances from unsigned int to __poll_t * do the same to local variable(s) (if any) used to hold the return value to be. Again, from cc(1) POV it's a no-op - unannotated foo_poll() will be just fine as it is. The only place where I did something more fancy than such type change actually had been buggy - drivers/media/common/siano/smsdvb-debugfs.c:smsdvb_stats_poll() relied upon smsdvb_stats_wait_read() never returning negatives and it needs s/__poll_t rc/& = 0/ for correctness (fixed and folded).