Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758642AbXEOVWb (ORCPT ); Tue, 15 May 2007 17:22:31 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755221AbXEOVWJ (ORCPT ); Tue, 15 May 2007 17:22:09 -0400 Received: from extu-mxob-1.symantec.com ([216.10.194.28]:35112 "EHLO extu-mxob-1.symantec.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754129AbXEOVWD (ORCPT ); Tue, 15 May 2007 17:22:03 -0400 Date: Tue, 15 May 2007 19:44:58 +0100 (BST) From: Hugh Dickins X-X-Sender: hugh@blonde.wat.veritas.com To: Christoph Lameter cc: Andrew Morton , Badari Pulavarty , netdev@vger.kernel.org, lkml Subject: Re: select(0, ..) is valid ? In-Reply-To: Message-ID: References: <1179250159.2836.117.camel@dyn9047017100.beaverton.ibm.com> <20070515104453.f901e91f.akpm@linux-foundation.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-OriginalArrivalTime: 15 May 2007 21:22:01.0123 (UTC) FILETIME=[139A6730:01C79737] X-Brightmail-Verdict: VlJEQwAAAAIAAAABAAAAAAAAAAEAAAAAAAAABWluYm94AGxpbnV4LWtlcm5lbEB2Z2VyLmtlcm5lbC5vcmcAbmV0ZGV2QHZnZXIua2VybmVsLm9yZwBha3BtQGxpbnV4LWZvdW5kYXRpb24ub3JnAHBiYWRhcmlAdXMuaWJtLmNvbQBjbGFtZXRlckBzZ2kuY29tAA== X-Brightmail-Tracker: AAAAAA== Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2165 Lines: 58 On Tue, 15 May 2007, Christoph Lameter wrote: > On Tue, 15 May 2007, Andrew Morton wrote: > > > I _think_ we can just do > > > > --- a/fs/compat.c~a > > +++ a/fs/compat.c > > @@ -1566,9 +1566,13 @@ int compat_core_sys_select(int n, compat > > */ > > ret = -ENOMEM; > > size = FDS_BYTES(n); > > - bits = kmalloc(6 * size, GFP_KERNEL); > > - if (!bits) > > - goto out_nofds; > > + if (likely(size)) { > > + bits = kmalloc(6 * size, GFP_KERNEL); > > + if (!bits) > > + goto out_nofds; > > + } else { > > + bits = NULL; > > + } It's interesting that compat_core_sys_select() shows this kmalloc(0) failure but core_sys_select() does not. That's because core_sys_select() avoids kmalloc by using a buffer on the stack for small allocations (and 0 sure is small). Shouldn't compat_core_sys_select() do just the same? Or is SLUB going to be so efficient that doing so is a waste of time? > > fds.in = (unsigned long *) bits; > > fds.out = (unsigned long *) (bits + size); > > fds.ex = (unsigned long *) (bits + 2*size); > > _ > > > > I mean, if that oopses then I'd be very interested in finding out why. > > > > But I'm starting to suspect that it would be better to permit kmalloc(0) in > > slub. It depends on how many more of these things need fixing. > > > > otoh, a kmalloc(0) could be a sign of some buggy/inefficient/weird code, so > > there's some value in forcing us to go look at all the callsites. > > Hmmm... We could have kmalloc(0) return a pointer to the zero page? That > would catch any writers? I don't think using the zero page that way would be at all safe: there's probably configurations/architectures in which it is write protected, but I don't believe that's a given at all. But the principle is good: ERR_PTR(-MAX_ERRNO) should work, that area up the top should always give a fault. Hmm, but perhaps there are architectures on which it does not? Hugh - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/