lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ZBHbOrk3P3TXSkK8@kernel.org>
Date:   Wed, 15 Mar 2023 16:50:34 +0200
From:   Mike Rapoport <rppt@...nel.org>
To:     Vlastimil Babka <vbabka@...e.cz>
Cc:     Mike Rapoport <mike.rapoport@...il.com>,
        Christoph Lameter <cl@...ux.com>,
        David Rientjes <rientjes@...gle.com>,
        Joonsoo Kim <iamjoonsoo.kim@....com>,
        Pekka Enberg <penberg@...nel.org>,
        Hyeonggon Yoo <42.hyeyoo@...il.com>,
        Roman Gushchin <roman.gushchin@...ux.dev>,
        Andrew Morton <akpm@...ux-foundation.org>, linux-mm@...ck.org,
        rcu@...r.kernel.org, linux-fsdevel@...r.kernel.org,
        linux-kernel@...r.kernel.org, patches@...ts.linux.dev,
        netdev@...r.kernel.org, linux-doc@...r.kernel.org,
        Jonathan Corbet <corbet@....net>,
        "Paul E. McKenney" <paulmck@...nel.org>,
        Frederic Weisbecker <frederic@...nel.org>,
        Neeraj Upadhyay <quic_neeraju@...cinc.com>,
        Josh Triplett <josh@...htriplett.org>,
        Steven Rostedt <rostedt@...dmis.org>,
        Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
        Lai Jiangshan <jiangshanlai@...il.com>,
        Joel Fernandes <joel@...lfernandes.org>
Subject: Re: [PATCH 7/7] mm/slab: document kfree() as allowed for
 kmem_cache_alloc() objects

On Wed, Mar 15, 2023 at 02:38:47PM +0100, Vlastimil Babka wrote:
> On 3/12/23 10:59, Mike Rapoport wrote:
> > On Fri, Mar 10, 2023 at 11:32:09AM +0100, Vlastimil Babka wrote:
> >> This will make it easier to free objects in situations when they can
> >> come from either kmalloc() or kmem_cache_alloc(), and also allow
> >> kfree_rcu() for freeing objects from kmem_cache_alloc().
> >> 
> >> For the SLAB and SLUB allocators this was always possible so with SLOB
> >> gone, we can document it as supported.
> >> 
> >> Signed-off-by: Vlastimil Babka <vbabka@...e.cz>
> >> Cc: Mike Rapoport <rppt@...nel.org>
> >> Cc: Jonathan Corbet <corbet@....net>
> >> Cc: "Paul E. McKenney" <paulmck@...nel.org>
> >> Cc: Frederic Weisbecker <frederic@...nel.org>
> >> Cc: Neeraj Upadhyay <quic_neeraju@...cinc.com>
> >> Cc: Josh Triplett <josh@...htriplett.org>
> >> Cc: Steven Rostedt <rostedt@...dmis.org>
> >> Cc: Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
> >> Cc: Lai Jiangshan <jiangshanlai@...il.com>
> >> Cc: Joel Fernandes <joel@...lfernandes.org>
> >> ---
> >>  Documentation/core-api/memory-allocation.rst | 15 +++++++++++----
> >>  include/linux/rcupdate.h                     |  6 ++++--
> >>  mm/slab_common.c                             |  5 +----
> >>  3 files changed, 16 insertions(+), 10 deletions(-)
> >> 
> >> diff --git a/Documentation/core-api/memory-allocation.rst b/Documentation/core-api/memory-allocation.rst
> >> index 5954ddf6ee13..f9e8d352ed67 100644
> >> --- a/Documentation/core-api/memory-allocation.rst
> >> +++ b/Documentation/core-api/memory-allocation.rst
> >> @@ -170,7 +170,14 @@ should be used if a part of the cache might be copied to the userspace.
> >>  After the cache is created kmem_cache_alloc() and its convenience
> >>  wrappers can allocate memory from that cache.
> >>  
> >> -When the allocated memory is no longer needed it must be freed. You can
> >> -use kvfree() for the memory allocated with `kmalloc`, `vmalloc` and
> >> -`kvmalloc`. The slab caches should be freed with kmem_cache_free(). And
> >> -don't forget to destroy the cache with kmem_cache_destroy().
> >> +When the allocated memory is no longer needed it must be freed. Objects
> > 
> > I'd add a line break before Objects                               ^
> > 
> >> +allocated by `kmalloc` can be freed by `kfree` or `kvfree`.
> >> +Objects allocated by `kmem_cache_alloc` can be freed with `kmem_cache_free`
> >> +or also by `kfree` or `kvfree`, which can be more convenient as it does
> > 
> > Maybe replace 'or also by' with a coma:
> > 
> > Objects allocated by `kmem_cache_alloc` can be freed with `kmem_cache_free`,
> > `kfree` or `kvfree`, which can be more convenient as it does
> 
> But then I need to clarify what the "which" applies to?

Yeah, I kinda missed that...

> > 
> >> +not require the kmem_cache pointed.
> > 
> >                              ^ pointer.
> > 
> >> +The rules for _bulk and _rcu flavors of freeing functions are analogical.
> > 
> > Maybe 
> > 
> > The same rules apply to _bulk and _rcu flavors of freeing functions.
> 
> So like this incremental diff?
 
> diff --git a/Documentation/core-api/memory-allocation.rst b/Documentation/core-api/memory-allocation.rst
> index f9e8d352ed67..1c58d883b273 100644
> --- a/Documentation/core-api/memory-allocation.rst
> +++ b/Documentation/core-api/memory-allocation.rst
> @@ -170,12 +170,14 @@ should be used if a part of the cache might be copied to the userspace.
>  After the cache is created kmem_cache_alloc() and its convenience
>  wrappers can allocate memory from that cache.
>  
> -When the allocated memory is no longer needed it must be freed. Objects
> -allocated by `kmalloc` can be freed by `kfree` or `kvfree`.
> -Objects allocated by `kmem_cache_alloc` can be freed with `kmem_cache_free`
> -or also by `kfree` or `kvfree`, which can be more convenient as it does
> -not require the kmem_cache pointed.
> -The rules for _bulk and _rcu flavors of freeing functions are analogical.
> +When the allocated memory is no longer needed it must be freed.
> +
> +Objects allocated by `kmalloc` can be freed by `kfree` or `kvfree`. Objects
> +allocated by `kmem_cache_alloc` can be freed with `kmem_cache_free`, `kfree`
> +or `kvfree`, where the latter two might be more convenient thanks to not
> +needing the kmem_cache pointer.

... but this way it's more explicit that kfree and kvfree don't need
kmem_cache pointer.

> +
> +The same rules apply to _bulk and _rcu flavors of freeing functions.
>  
>  Memory allocated by `vmalloc` can be freed with `vfree` or `kvfree`.
>  Memory allocated by `kvmalloc` can be freed with `kvfree`.
> 

-- 
Sincerely yours,
Mike.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ