Message ID | 20240903-work-kmem_cache_args-v2-15-76f97e9a4560@kernel.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | slab: add struct kmem_cache_args | expand |
On Tue, Sep 03, 2024 at 04:20:56PM +0200, Christian Brauner wrote: > Port req_cachep to struct kmem_cache_args. > > Signed-off-by: Christian Brauner <brauner@kernel.org> Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org> > --- > io_uring/io_uring.c | 14 ++++++++------ > 1 file changed, 8 insertions(+), 6 deletions(-) > > diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c > index 3942db160f18..d9d721d1424e 100644 > --- a/io_uring/io_uring.c > +++ b/io_uring/io_uring.c > @@ -3638,6 +3638,11 @@ SYSCALL_DEFINE2(io_uring_setup, u32, entries, > > static int __init io_uring_init(void) > { > + struct kmem_cache_args kmem_args = { > + .useroffset = offsetof(struct io_kiocb, cmd.data), > + .usersize = sizeof_field(struct io_kiocb, cmd.data), > + }; > + > #define __BUILD_BUG_VERIFY_OFFSET_SIZE(stype, eoffset, esize, ename) do { \ > BUILD_BUG_ON(offsetof(stype, ename) != eoffset); \ > BUILD_BUG_ON(sizeof_field(stype, ename) != esize); \ > @@ -3722,12 +3727,9 @@ static int __init io_uring_init(void) > * range, and HARDENED_USERCOPY will complain if we haven't > * correctly annotated this range. > */ > - req_cachep = kmem_cache_create_usercopy("io_kiocb", > - sizeof(struct io_kiocb), 0, > - SLAB_HWCACHE_ALIGN | SLAB_PANIC | > - SLAB_ACCOUNT | SLAB_TYPESAFE_BY_RCU, > - offsetof(struct io_kiocb, cmd.data), > - sizeof_field(struct io_kiocb, cmd.data), NULL); > + req_cachep = kmem_cache_create("io_kiocb", sizeof(struct io_kiocb), &kmem_args, > + SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT | > + SLAB_TYPESAFE_BY_RCU); > io_buf_cachep = KMEM_CACHE(io_buffer, > SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT); > > > -- > 2.45.2 >
On 9/3/24 16:20, Christian Brauner wrote: > Port req_cachep to struct kmem_cache_args. Fine but doesn't bring anything on its own, wouldn't Jens want to supply the freeptr_offset at the same time to benefit from it? > Signed-off-by: Christian Brauner <brauner@kernel.org> > --- > io_uring/io_uring.c | 14 ++++++++------ > 1 file changed, 8 insertions(+), 6 deletions(-) > > diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c > index 3942db160f18..d9d721d1424e 100644 > --- a/io_uring/io_uring.c > +++ b/io_uring/io_uring.c > @@ -3638,6 +3638,11 @@ SYSCALL_DEFINE2(io_uring_setup, u32, entries, > > static int __init io_uring_init(void) > { > + struct kmem_cache_args kmem_args = { > + .useroffset = offsetof(struct io_kiocb, cmd.data), > + .usersize = sizeof_field(struct io_kiocb, cmd.data), > + }; > + > #define __BUILD_BUG_VERIFY_OFFSET_SIZE(stype, eoffset, esize, ename) do { \ > BUILD_BUG_ON(offsetof(stype, ename) != eoffset); \ > BUILD_BUG_ON(sizeof_field(stype, ename) != esize); \ > @@ -3722,12 +3727,9 @@ static int __init io_uring_init(void) > * range, and HARDENED_USERCOPY will complain if we haven't > * correctly annotated this range. > */ > - req_cachep = kmem_cache_create_usercopy("io_kiocb", > - sizeof(struct io_kiocb), 0, > - SLAB_HWCACHE_ALIGN | SLAB_PANIC | > - SLAB_ACCOUNT | SLAB_TYPESAFE_BY_RCU, > - offsetof(struct io_kiocb, cmd.data), > - sizeof_field(struct io_kiocb, cmd.data), NULL); > + req_cachep = kmem_cache_create("io_kiocb", sizeof(struct io_kiocb), &kmem_args, > + SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT | > + SLAB_TYPESAFE_BY_RCU); > io_buf_cachep = KMEM_CACHE(io_buffer, > SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT); > >
On Wed, Sep 04, 2024 at 10:20:31AM GMT, Vlastimil Babka wrote: > On 9/3/24 16:20, Christian Brauner wrote: > > Port req_cachep to struct kmem_cache_args. > > Fine but doesn't bring anything on its own, wouldn't Jens want to supply the > freeptr_offset at the same time to benefit from it? I just picked two victims that I knew do rely or want to rely on features that weren't there before. Afterwards, Jens can just select or add a free pointer to struct io_kiocb.
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 3942db160f18..d9d721d1424e 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3638,6 +3638,11 @@ SYSCALL_DEFINE2(io_uring_setup, u32, entries, static int __init io_uring_init(void) { + struct kmem_cache_args kmem_args = { + .useroffset = offsetof(struct io_kiocb, cmd.data), + .usersize = sizeof_field(struct io_kiocb, cmd.data), + }; + #define __BUILD_BUG_VERIFY_OFFSET_SIZE(stype, eoffset, esize, ename) do { \ BUILD_BUG_ON(offsetof(stype, ename) != eoffset); \ BUILD_BUG_ON(sizeof_field(stype, ename) != esize); \ @@ -3722,12 +3727,9 @@ static int __init io_uring_init(void) * range, and HARDENED_USERCOPY will complain if we haven't * correctly annotated this range. */ - req_cachep = kmem_cache_create_usercopy("io_kiocb", - sizeof(struct io_kiocb), 0, - SLAB_HWCACHE_ALIGN | SLAB_PANIC | - SLAB_ACCOUNT | SLAB_TYPESAFE_BY_RCU, - offsetof(struct io_kiocb, cmd.data), - sizeof_field(struct io_kiocb, cmd.data), NULL); + req_cachep = kmem_cache_create("io_kiocb", sizeof(struct io_kiocb), &kmem_args, + SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT | + SLAB_TYPESAFE_BY_RCU); io_buf_cachep = KMEM_CACHE(io_buffer, SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT);
Port req_cachep to struct kmem_cache_args. Signed-off-by: Christian Brauner <brauner@kernel.org> --- io_uring/io_uring.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)