Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] fs: uninitialized or stale f_dma_io_tag in init_file() - [Low] fs: missing kernel-doc entry for f_dma_io_tag in struct file --
commit 4c6695df72954d7137a1d0c3d35307639c41ca7f Author: Pavel Begunkov <[email protected]> dma-buf-io: add tags for sharing ctx b/w files This commit adds an importer_tag field to struct dma_buf_io_ctx and an f_dma_io_tag field to struct file so that a dma-buf I/O context can be shared across compatible files belonging to the same subsystem instance. > diff --git a/include/linux/dma-buf-io.h b/include/linux/dma-buf-io.h > index d9f27650a851e..299edf0baaf32 100644 > --- a/include/linux/dma-buf-io.h > +++ b/include/linux/dma-buf-io.h > @@ -48,10 +48,32 @@ struct dma_buf_io_ctx { > enum dma_data_direction dir; > bool is_dead; > > + /* > + * Tags represent an instance of the subsystem the dma-buf I/O > + * context is bound to, the set of underlying devices and subsystem > + * specific map / context structure representations. Remember the > + * registration file's tag (see struct file::f_dma_io_tag) and use > + * it to filter out files that don't share it. > + */ > + unsigned long importer_tag; > + > void *dev_priv; > const struct dma_buf_io_ops *dev_ops; > }; > > +/** > + * dma_buf_io_file_compatible - Check compatibility b/w context and file. > + * @ctx: [in] dma-buf I/O context > + * @file: [in] file > + * > + * Returns true if the context can be used to issue I/O to the given file. > + */ > +static inline bool dma_buf_io_file_compatible(const struct dma_buf_io_ctx > *ctx, > + const struct file *file) > +{ > + return file->f_dma_io_tag == ctx->importer_tag; > +} [Severity: High] Can file->f_dma_io_tag contain uninitialized or stale slab data here and in dma_buf_io_ctx_create() in drivers/dma-buf/dma-buf-io.c? In fs/file_table.c, alloc_empty_file(), alloc_empty_file_noaccount(), and alloc_empty_backing_file() allocate struct file objects from filp_cache and bfilp_cache via kmem_cache_alloc() without __GFP_ZERO. Because those caches use SLAB_TYPESAFE_BY_RCU, init_file() explicitly initializes the fields of struct file on allocation and reuse: fs/file_table.c:init_file() { ... f->f_iocb_flags = 0; f->f_pos = 0; f->f_wb_err = 0; f->f_sb_err = 0; file_ref_init(&f->f_ref, 1); return 0; } Since init_file() does not zero f->f_dma_io_tag, if a tagged file is closed and its slab object is reused for an unrelated file whose open path does not set f_dma_io_tag, wouldn't the new file retain the previous file's f_dma_io_tag and cause dma_buf_io_file_compatible() to report a match? > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 99caef43ff3c4..a9bb63cf6f9d8 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -1293,6 +1293,12 @@ struct file { > freeptr_t f_freeptr; > }; > file_ref_t f_ref; > + > + /* > + * A tag representing the underlying subsystem for dma-buf I/O. > + * See struct dma_buf_io_ctx::importer_tag. > + */ > + unsigned long f_dma_io_tag; [Severity: Low] struct file in include/linux/fs.h has a kernel-doc comment block above its definition. Should an @f_dma_io_tag entry be added there as well so scripts/kernel-doc does not warn about an undescribed struct member during documentation or W=1 builds? -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=1
