From: Jens Axboe <axboe@kernel.dk>
To: Jann Horn <jannh@google.com>, Vlastimil Babka <vbabka@suse.cz>
Cc: Christian Brauner <brauner@kernel.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Linus Torvalds <torvalds@linux-foundation.org>,
linux-mm@kvack.org
Subject: Re: [PATCH] [RFC] mm: add kmem_cache_create_rcu()
Date: Tue, 27 Aug 2024 09:45:43 -0600 [thread overview]
Message-ID: <28677022-1be8-402f-97c4-fc1aba33c77f@kernel.dk> (raw)
In-Reply-To: <CAG48ez0vbcDcv5z7AUSkW2iMDG+ixSbEyS-4i6ipB-XT7fo96g@mail.gmail.com>
On 8/27/24 9:33 AM, Jann Horn wrote:
> On Tue, Aug 27, 2024 at 4:05?PM Vlastimil Babka <vbabka@suse.cz> wrote:
>> On 8/26/24 18:04, Christian Brauner wrote:
>>> diff --git a/include/linux/slab.h b/include/linux/slab.h
>>> index eb2bf4629157..fc3c3cc9f689 100644
>>> --- a/include/linux/slab.h
>>> +++ b/include/linux/slab.h
>>> @@ -242,6 +242,10 @@ struct kmem_cache *kmem_cache_create_usercopy(const char *name,
>>> slab_flags_t flags,
>>> unsigned int useroffset, unsigned int usersize,
>>> void (*ctor)(void *));
>>> +struct kmem_cache *kmem_cache_create_rcu(const char *name, unsigned int size,
>>> + unsigned int offset,
>>> + slab_flags_t flags,
>>> + void (*ctor)(void *));
>>
>> I wonder if there's a way to do this in a more generic way, we'd now have 3
>> variants and neither supports everything (what about both rcu offset and
>> usercopy?).
>
> The "pass all arguments as a struct" pattern might not look too bad
> (or alternatively, "pass all optional arguments as a struct"), as long
> as it's fine for unused arguments to be zero-initialized? Like:
>
> struct kcr_options {
> const char *name;
> unsigned int size;
> ...
> };
>
> struct kmem_cache *kmem_cache_create(struct kcr_options opt);
>
> void blah() {
> kmem_cache_create((struct kcr_options){
> .name = "blah",
> .size = ...,
> ...
> });
> }
>
> I think maybe we can do this now that the kernel is C11?
Yep should work.
I like this approach as a way of unifying the various ways of creating a
slab cache. Particularly as I'd want to use a free ptr myself for an
in-kernel use case that currently creates a cache with
kmem_cache_create_usercopy().
> But I guess if we want to allow leaving out the freeptr_offset
> parameter, we'd have to have a flag to say whether the freeptr_offset
> parameter value should be used... Maybe my proposal is too overly
> fancy...
I think we'll end up going down that route eventually anyway to cover
all cases, so may as well do a prep patch that does that first. At least
that's my opinion...
--
Jens Axboe
next prev parent reply other threads:[~2024-08-27 15:45 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-26 9:23 [PATCH] [POC/RFE]: Avoid silently growing struct file due to SLAB_TYPESAFE_BY_RCU Christian Brauner
2024-08-26 9:25 ` Christian Brauner
2024-08-26 16:04 ` [PATCH] [RFC] mm: add kmem_cache_create_rcu() Christian Brauner
2024-08-27 10:42 ` Mike Rapoport
2024-08-27 13:42 ` Christian Brauner
2024-08-27 14:05 ` Vlastimil Babka
2024-08-27 15:15 ` Christian Brauner
2024-08-27 15:33 ` Jann Horn
2024-08-27 15:44 ` Christian Brauner
2024-08-27 15:45 ` Jens Axboe [this message]
2024-08-27 20:34 ` Vlastimil Babka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=28677022-1be8-402f-97c4-fc1aba33c77f@kernel.dk \
--to=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=jannh@google.com \
--cc=linux-mm@kvack.org \
--cc=paulmck@kernel.org \
--cc=roman.gushchin@linux.dev \
--cc=torvalds@linux-foundation.org \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox