From owner-svn-src-all@freebsd.org Sun Jan 7 19:07:54 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1D37AE7B849; Sun, 7 Jan 2018 19:07:54 +0000 (UTC) (envelope-from freebsd@pdx.rh.CN85.dnsmgr.net) Received: from pdx.rh.CN85.dnsmgr.net (br1.CN84in.dnsmgr.net [69.59.192.140]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EC8B773EAC; Sun, 7 Jan 2018 19:07:53 +0000 (UTC) (envelope-from freebsd@pdx.rh.CN85.dnsmgr.net) Received: from pdx.rh.CN85.dnsmgr.net (localhost [127.0.0.1]) by pdx.rh.CN85.dnsmgr.net (8.13.3/8.13.3) with ESMTP id w07J7pRd018032; Sun, 7 Jan 2018 11:07:51 -0800 (PST) (envelope-from freebsd@pdx.rh.CN85.dnsmgr.net) Received: (from freebsd@localhost) by pdx.rh.CN85.dnsmgr.net (8.13.3/8.13.3/Submit) id w07J7pUF018031; Sun, 7 Jan 2018 11:07:51 -0800 (PST) (envelope-from freebsd) From: "Rodney W. Grimes" Message-Id: <201801071907.w07J7pUF018031@pdx.rh.CN85.dnsmgr.net> Subject: Re: svn commit: r327676 - head/sys/compat/linuxkpi/common/include/linux In-Reply-To: To: Kristof Provost Date: Sun, 7 Jan 2018 11:07:51 -0800 (PST) CC: rgrimes@freebsd.org, src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Reply-To: rgrimes@freebsd.org X-Mailer: ELM [version 2.4ME+ PL121h (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Jan 2018 19:07:54 -0000 > On 7 Jan 2018, at 19:37, Rodney W. Grimes wrote: > >> On 7 Jan 2018, at 19:02, Rodney W. Grimes wrote: > >>>> Author: kp > >>>> Date: Sun Jan 7 13:39:12 2018 > >>>> New Revision: 327676 > >>>> URL: https://svnweb.freebsd.org/changeset/base/327676 > >>>> > >>>> Log: > >>>> linuxkpi: Implement kcalloc() based on mallocarray() > >>>> > >>>> This means we now get integer overflow protection, which Linux > >>>> code > >>>> might expect as it is also provided by kcalloc() in Linux. > >>>> > >>>> Modified: > >>>> head/sys/compat/linuxkpi/common/include/linux/slab.h > >>>> > >>>> Modified: head/sys/compat/linuxkpi/common/include/linux/slab.h > >>>> ============================================================================== > >>>> --- head/sys/compat/linuxkpi/common/include/linux/slab.h Sun Jan 7 > >>>> 13:35:15 2018 (r327675) > >>>> +++ head/sys/compat/linuxkpi/common/include/linux/slab.h Sun Jan 7 > >>>> 13:39:12 2018 (r327676) > >>>> @@ -46,7 +46,6 @@ MALLOC_DECLARE(M_KMALLOC); > >>>> #define kzalloc(size, flags) kmalloc(size, (flags) | __GFP_ZERO) > >>>> #define kzalloc_node(size, flags, node) kmalloc(size, (flags) | > >>>> __GFP_ZERO) > >>>> #define kfree_const(ptr) kfree(ptr) > >>>> -#define kcalloc(n, size, flags) kmalloc((n) * (size), > >>>> (flags) | __GFP_ZERO) > >>> > >>> Would not: > >>> #define kcalloc(n, size, flags) mallocarray(mallocarray((n), > >>> (size), M_KMALLOC, linux_check_m_flags((flags | __GFP_ZERO)) > >>> work just fine, saving a call and stack use of about framesize + 32 > >>> bytes? > >>> > >>> > >> It would also work, but it?d have to be split up into multiple lines > >> then. > > > > But it would retain the direct macro form, your change changes it > > from a #define which is evaluated at pre proc time to a function > > call that is evaluated at compile time. The resulting code from > > a -O0 well be different because of this. > > > Indeed. It?s not something I?d worry about as anyone who cares about > it being fast (as opposed to easier to debug for example) would build it > as -O2/-O3. > > >> I thought it?d be more readable as a function. > > > > If that is the only reason I would rather see it retain the > > same form as all the other allocs. > > > How does this look? > > diff --git a/sys/compat/linuxkpi/common/include/linux/slab.h > b/sys/compat/linuxkpi/common/include/linux/slab.h > index 1f8ec82db98..5551211c281 100644 > --- a/sys/compat/linuxkpi/common/include/linux/slab.h > +++ b/sys/compat/linuxkpi/common/include/linux/slab.h > @@ -46,6 +46,9 @@ MALLOC_DECLARE(M_KMALLOC); > #define kzalloc(size, flags) kmalloc(size, (flags) | __GFP_ZERO) > #define kzalloc_node(size, flags, node) kmalloc(size, (flags) | > __GFP_ZERO) > #define kfree_const(ptr) kfree(ptr) > +#define kcalloc(n, size, flags) mallocarray((n), (size), \ > + M_KMALLOC, \ > + linux_check_m_flags((flags | __GFP_ZERO))) > #define vzalloc(size) __vmalloc(size, GFP_KERNEL | __GFP_NOWARN | > __GFP_ZERO, 0) > #define vfree(arg) kfree(arg) > #define kvfree(arg) kfree(arg) > @@ -99,13 +102,6 @@ kmalloc(size_t size, gfp_t flags) > return (malloc(size, M_KMALLOC, linux_check_m_flags(flags))); > } > > -static inline void * > -kcalloc(size_t n, size_t size, gfp_t flags) > -{ > - flags |= __GFP_ZERO; > - return (mallocarray(n, size, M_KMALLOC, linux_check_m_flags(flags))); > -} > - > static inline void * > __vmalloc(size_t size, gfp_t flags, int other) > { > > Regards, > Kristof Should probably revert and go through review, I would at least wait for comments from others. -- Rod Grimes rgrimes@freebsd.org