io_uring/query.c
Source file repositories/reference/linux-study-clean/io_uring/query.c
File Facts
- System
- Linux kernel
- Corpus path
io_uring/query.c- Extension
.c- Size
- 3650 bytes
- Lines
- 153
- Domain
- Kernel Services
- Bucket
- io_uring
- Inferred role
- Kernel Services: implementation source
- Status
- source 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/io_uring/query.hquery.hio_uring.hzcrx.h
Detected Declarations
function io_query_opsfunction io_query_zcrxfunction io_query_zcrx_notiffunction io_query_scqfunction io_handle_query_entryfunction io_query
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include "linux/io_uring/query.h"
#include "query.h"
#include "io_uring.h"
#include "zcrx.h"
union io_query_data {
struct io_uring_query_opcode opcodes;
struct io_uring_query_zcrx zcrx;
struct io_uring_query_zcrx_notif zcrx_notif;
struct io_uring_query_scq scq;
};
#define IO_MAX_QUERY_SIZE sizeof(union io_query_data)
#define IO_MAX_QUERY_ENTRIES 1000
static ssize_t io_query_ops(union io_query_data *data)
{
struct io_uring_query_opcode *e = &data->opcodes;
e->nr_request_opcodes = IORING_OP_LAST;
e->nr_register_opcodes = IORING_REGISTER_LAST;
e->feature_flags = IORING_FEAT_FLAGS;
e->ring_setup_flags = IORING_SETUP_FLAGS;
e->enter_flags = IORING_ENTER_FLAGS;
e->sqe_flags = SQE_VALID_FLAGS;
e->nr_query_opcodes = __IO_URING_QUERY_MAX;
e->__pad = 0;
return sizeof(*e);
}
static ssize_t io_query_zcrx(union io_query_data *data)
{
struct io_uring_query_zcrx *e = &data->zcrx;
e->register_flags = ZCRX_SUPPORTED_REG_FLAGS;
e->area_flags = IORING_ZCRX_AREA_DMABUF;
e->nr_ctrl_opcodes = __ZCRX_CTRL_LAST;
e->rq_hdr_size = sizeof(struct io_uring);
e->rq_hdr_alignment = L1_CACHE_BYTES;
e->features = ZCRX_FEATURES;
e->__resv2 = 0;
return sizeof(*e);
}
static ssize_t io_query_zcrx_notif(union io_query_data *data)
{
struct io_uring_query_zcrx_notif *e = &data->zcrx_notif;
e->notif_flags = ZCRX_NOTIF_TYPE_MASK;
e->notif_stats_size = sizeof(struct zcrx_notif_stats);
e->notif_stats_off_alignment = __alignof__(struct zcrx_notif_stats);
e->__resv1 = 0;
memset(&e->__resv2, 0, sizeof(e->__resv2));
return sizeof(*e);
}
static ssize_t io_query_scq(union io_query_data *data)
{
struct io_uring_query_scq *e = &data->scq;
e->hdr_size = sizeof(struct io_rings);
e->hdr_alignment = SMP_CACHE_BYTES;
return sizeof(*e);
}
static int io_handle_query_entry(union io_query_data *data, void __user *uhdr,
u64 *next_entry)
{
struct io_uring_query_hdr hdr;
size_t usize, res_size = 0;
ssize_t ret = -EINVAL;
void __user *udata;
if (copy_from_user(&hdr, uhdr, sizeof(hdr)))
return -EFAULT;
usize = hdr.size;
hdr.size = min(hdr.size, IO_MAX_QUERY_SIZE);
udata = u64_to_user_ptr(hdr.query_data);
if (hdr.query_op >= __IO_URING_QUERY_MAX) {
ret = -EOPNOTSUPP;
goto out;
}
if (!mem_is_zero(hdr.__resv, sizeof(hdr.__resv)) || hdr.result || !hdr.size)
goto out;
if (copy_from_user(data, udata, hdr.size))
return -EFAULT;
Annotation
- Immediate include surface: `linux/io_uring/query.h`, `query.h`, `io_uring.h`, `zcrx.h`.
- Detected declarations: `function io_query_ops`, `function io_query_zcrx`, `function io_query_zcrx_notif`, `function io_query_scq`, `function io_handle_query_entry`, `function io_query`.
- Atlas domain: Kernel Services / io_uring.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.