From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751924AbaGGTIi (ORCPT ); Mon, 7 Jul 2014 15:08:38 -0400 Received: from mga09.intel.com ([134.134.136.24]:12392 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751085AbaGGTIh (ORCPT ); Mon, 7 Jul 2014 15:08:37 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,619,1400050800"; d="scan'208";a="539867954" Message-ID: <53BAF01C.8010700@intel.com> Date: Mon, 07 Jul 2014 12:08:12 -0700 From: Dave Hansen User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Naoya Horiguchi , Andrew Morton CC: Konstantin Khlebnikov , Wu Fengguang , Arnaldo Carvalho de Melo , Borislav Petkov , "Kirill A. Shutemov" , Johannes Weiner , Rusty Russell , David Miller , Andres Freund , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , Dave Chinner , Michael Kerrisk , Linux API , Naoya Horiguchi Subject: Re: [PATCH v3 3/3] man2/fincore.2: document general description about fincore(2) References: <1404756006-23794-1-git-send-email-n-horiguchi@ah.jp.nec.com> <1404756006-23794-4-git-send-email-n-horiguchi@ah.jp.nec.com> In-Reply-To: <1404756006-23794-4-git-send-email-n-horiguchi@ah.jp.nec.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/07/2014 11:00 AM, Naoya Horiguchi wrote: > +.SH RETURN VALUE > +On success, > +.BR fincore () > +returns 0. > +On error, \-1 is returned, and > +.I errno > +is set appropriately. Is this accurate? From reading the syscall itself, it looked like it did this: > + * Return value is the number of pages whose data is stored in fc->buffer. > + */ > +static long do_fincore(struct fincore_control *fc, int nr_pages) and: > +SYSCALL_DEFINE6(fincore, int, fd, loff_t, start, long, nr_pages, ... > + while (fc.nr_pages > 0) { > + memset(fc.buffer, 0, fc.buffer_size); > + ret = do_fincore(&fc, min(step, fc.nr_pages)); > + /* Reached the end of the file */ > + if (ret == 0) > + break; > + if (ret < 0) > + break; ... > + } ... > + return ret; > +} Which seems that for a given loop of do_fincore(), you might end up returning the result of that *single* iteration of do_fincore() instead of the aggregate of the entire syscall. So, it can return <0 on failure, 0 on success, or also an essentially random >0 number on success too. Why not just use the return value for something useful instead of hacking in the extras->nr_entries stuff? Oh, and what if that > + if (extra) > + __put_user(nr, &extra->nr_entries); fails? It seems like we might silently forget to tell userspace how many entries we filled. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dave Hansen Subject: Re: [PATCH v3 3/3] man2/fincore.2: document general description about fincore(2) Date: Mon, 07 Jul 2014 12:08:12 -0700 Message-ID: <53BAF01C.8010700@intel.com> References: <1404756006-23794-1-git-send-email-n-horiguchi@ah.jp.nec.com> <1404756006-23794-4-git-send-email-n-horiguchi@ah.jp.nec.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1404756006-23794-4-git-send-email-n-horiguchi-PaJj6Psr51x8UrSeD/g0lQ@public.gmane.org> Sender: linux-api-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Naoya Horiguchi , Andrew Morton Cc: Konstantin Khlebnikov , Wu Fengguang , Arnaldo Carvalho de Melo , Borislav Petkov , "Kirill A. Shutemov" , Johannes Weiner , Rusty Russell , David Miller , Andres Freund , linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, Christoph Hellwig , Dave Chinner , Michael Kerrisk , Linux API , Naoya Horiguchi List-Id: linux-api@vger.kernel.org On 07/07/2014 11:00 AM, Naoya Horiguchi wrote: > +.SH RETURN VALUE > +On success, > +.BR fincore () > +returns 0. > +On error, \-1 is returned, and > +.I errno > +is set appropriately. Is this accurate? From reading the syscall itself, it looked like it did this: > + * Return value is the number of pages whose data is stored in fc->buffer. > + */ > +static long do_fincore(struct fincore_control *fc, int nr_pages) and: > +SYSCALL_DEFINE6(fincore, int, fd, loff_t, start, long, nr_pages, ... > + while (fc.nr_pages > 0) { > + memset(fc.buffer, 0, fc.buffer_size); > + ret = do_fincore(&fc, min(step, fc.nr_pages)); > + /* Reached the end of the file */ > + if (ret == 0) > + break; > + if (ret < 0) > + break; ... > + } ... > + return ret; > +} Which seems that for a given loop of do_fincore(), you might end up returning the result of that *single* iteration of do_fincore() instead of the aggregate of the entire syscall. So, it can return <0 on failure, 0 on success, or also an essentially random >0 number on success too. Why not just use the return value for something useful instead of hacking in the extras->nr_entries stuff? Oh, and what if that > + if (extra) > + __put_user(nr, &extra->nr_entries); fails? It seems like we might silently forget to tell userspace how many entries we filled. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pd0-f180.google.com (mail-pd0-f180.google.com [209.85.192.180]) by kanga.kvack.org (Postfix) with ESMTP id 6B47F900003 for ; Mon, 7 Jul 2014 15:08:38 -0400 (EDT) Received: by mail-pd0-f180.google.com with SMTP id fp1so5827394pdb.11 for ; Mon, 07 Jul 2014 12:08:38 -0700 (PDT) Received: from mga02.intel.com (mga02.intel.com. [134.134.136.20]) by mx.google.com with ESMTP id ex14si41735020pac.42.2014.07.07.12.08.36 for ; Mon, 07 Jul 2014 12:08:37 -0700 (PDT) Message-ID: <53BAF01C.8010700@intel.com> Date: Mon, 07 Jul 2014 12:08:12 -0700 From: Dave Hansen MIME-Version: 1.0 Subject: Re: [PATCH v3 3/3] man2/fincore.2: document general description about fincore(2) References: <1404756006-23794-1-git-send-email-n-horiguchi@ah.jp.nec.com> <1404756006-23794-4-git-send-email-n-horiguchi@ah.jp.nec.com> In-Reply-To: <1404756006-23794-4-git-send-email-n-horiguchi@ah.jp.nec.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Naoya Horiguchi , Andrew Morton Cc: Konstantin Khlebnikov , Wu Fengguang , Arnaldo Carvalho de Melo , Borislav Petkov , "Kirill A. Shutemov" , Johannes Weiner , Rusty Russell , David Miller , Andres Freund , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , Dave Chinner , Michael Kerrisk , Linux API , Naoya Horiguchi On 07/07/2014 11:00 AM, Naoya Horiguchi wrote: > +.SH RETURN VALUE > +On success, > +.BR fincore () > +returns 0. > +On error, \-1 is returned, and > +.I errno > +is set appropriately. Is this accurate? From reading the syscall itself, it looked like it did this: > + * Return value is the number of pages whose data is stored in fc->buffer. > + */ > +static long do_fincore(struct fincore_control *fc, int nr_pages) and: > +SYSCALL_DEFINE6(fincore, int, fd, loff_t, start, long, nr_pages, ... > + while (fc.nr_pages > 0) { > + memset(fc.buffer, 0, fc.buffer_size); > + ret = do_fincore(&fc, min(step, fc.nr_pages)); > + /* Reached the end of the file */ > + if (ret == 0) > + break; > + if (ret < 0) > + break; ... > + } ... > + return ret; > +} Which seems that for a given loop of do_fincore(), you might end up returning the result of that *single* iteration of do_fincore() instead of the aggregate of the entire syscall. So, it can return <0 on failure, 0 on success, or also an essentially random >0 number on success too. Why not just use the return value for something useful instead of hacking in the extras->nr_entries stuff? Oh, and what if that > + if (extra) > + __put_user(nr, &extra->nr_entries); fails? It seems like we might silently forget to tell userspace how many entries we filled. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org