io_uring/rsrc.c
Source file repositories/reference/linux-study-clean/io_uring/rsrc.c
File Facts
- System
- Linux kernel
- Corpus path
io_uring/rsrc.c- Extension
.c- Size
- 39671 bytes
- Lines
- 1709
- Domain
- Kernel Services
- Bucket
- io_uring
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/errno.hlinux/fs.hlinux/file.hlinux/mm.hlinux/slab.hlinux/nospec.hlinux/hugetlb.hlinux/compat.hlinux/io_uring.hlinux/io_uring/cmd.huapi/linux/io_uring.hfiletable.hio_uring.hopenclose.hrsrc.hmemmap.hregister.h
Detected Declarations
struct io_rsrc_updatefunction hpage_acct_reffunction hpage_acct_unreffunction __io_account_memfunction io_unaccount_memfunction io_account_memfunction io_validate_user_buf_rangefunction io_release_ubuffunction io_free_imufunction io_buffer_unaccount_pagesfunction io_buffer_unmapfunction io_rsrc_cache_initfunction io_rsrc_cache_freefunction io_clear_table_tagsfunction io_rsrc_data_freefunction io_rsrc_data_allocfunction __io_sqe_files_updatefunction __io_sqe_buffers_updatefunction __io_register_rsrc_updatefunction io_register_files_updatefunction io_register_rsrc_updatefunction io_register_rsrcfunction io_files_update_prepfunction io_files_update_with_index_allocfunction io_files_updatefunction io_free_rsrc_nodefunction io_sqe_files_unregisterfunction io_sqe_files_registerfunction io_sqe_buffers_unregisterfunction hpage_acct_reffunction io_buffer_account_pinfunction io_coalesce_bufferfunction io_check_coalesce_bufferfunction io_sqe_buffers_registerfunction io_buffer_register_bvecfunction io_buffer_unregister_bvecfunction validate_fixed_rangefunction io_import_kbuffunction io_import_fixedfunction io_import_reg_buffunction io_buffer_acct_cloned_hpagesfunction lock_two_ringsfunction io_clone_buffersfunction io_register_clone_buffersfunction io_vec_freefunction io_vec_reallocfunction io_vec_fill_bvecfunction io_estimate_bvec_size
Annotated Snippet
struct io_rsrc_update {
struct file *file;
u64 arg;
u32 nr_args;
u32 offset;
};
static struct io_rsrc_node *io_sqe_buffer_register(struct io_ring_ctx *ctx,
struct iovec *iov);
static int hpage_acct_ref(struct io_ring_ctx *ctx, struct page *hpage,
bool *acct_new)
{
unsigned long key = (unsigned long) hpage;
unsigned long count;
void *entry;
int ret;
lockdep_assert_held(&ctx->uring_lock);
entry = xa_load(&ctx->hpage_acct, key);
if (entry) {
*acct_new = false;
count = xa_to_value(entry) + 1;
} else {
ret = xa_reserve(&ctx->hpage_acct, key, GFP_KERNEL_ACCOUNT);
if (ret)
return ret;
*acct_new = true;
count = 1;
}
xa_store(&ctx->hpage_acct, key, xa_mk_value(count), GFP_KERNEL_ACCOUNT);
return 0;
}
static bool hpage_acct_unref(struct io_ring_ctx *ctx, struct page *hpage)
{
unsigned long key = (unsigned long) hpage;
unsigned long count;
void *entry;
lockdep_assert_held(&ctx->uring_lock);
entry = xa_load(&ctx->hpage_acct, key);
if (WARN_ON_ONCE(!entry))
return false;
count = xa_to_value(entry);
if (count == 1) {
xa_erase(&ctx->hpage_acct, key);
return true;
}
xa_store(&ctx->hpage_acct, key, xa_mk_value(count - 1), GFP_KERNEL_ACCOUNT);
return false;
}
/* only define max */
#define IORING_MAX_FIXED_FILES (1U << 20)
#define IORING_MAX_REG_BUFFERS (1U << 14)
#define IO_CACHED_BVECS_SEGS 32
int __io_account_mem(struct user_struct *user, unsigned long nr_pages)
{
unsigned long page_limit, cur_pages, new_pages;
if (!nr_pages)
return 0;
/* Don't allow more pages than we can safely lock */
page_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
cur_pages = atomic_long_read(&user->locked_vm);
do {
new_pages = cur_pages + nr_pages;
if (new_pages > page_limit)
return -ENOMEM;
} while (!atomic_long_try_cmpxchg(&user->locked_vm,
&cur_pages, new_pages));
return 0;
}
void io_unaccount_mem(struct user_struct *user, struct mm_struct *mm_account,
unsigned long nr_pages)
{
if (user)
__io_unaccount_mem(user, nr_pages);
if (mm_account)
atomic64_sub(nr_pages, &mm_account->pinned_vm);
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/fs.h`, `linux/file.h`, `linux/mm.h`, `linux/slab.h`, `linux/nospec.h`, `linux/hugetlb.h`.
- Detected declarations: `struct io_rsrc_update`, `function hpage_acct_ref`, `function hpage_acct_unref`, `function __io_account_mem`, `function io_unaccount_mem`, `function io_account_mem`, `function io_validate_user_buf_range`, `function io_release_ubuf`, `function io_free_imu`, `function io_buffer_unaccount_pages`.
- Atlas domain: Kernel Services / io_uring.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.