drivers/nvme/host/ioctl.c
Source file repositories/reference/linux-study-clean/drivers/nvme/host/ioctl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nvme/host/ioctl.c- Extension
.c- Size
- 23445 bytes
- Lines
- 875
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: implementation source
- Status
- source implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/blk-integrity.hlinux/ptrace.hlinux/nvme_ioctl.hlinux/io_uring/cmd.hnvme.h
Detected Declarations
struct nvme_uring_datastruct nvme_uring_cmd_pdustruct nvme_user_io32function nvme_cmd_allowedfunction nvme_map_user_requestfunction nvme_submit_user_cmdfunction nvme_submit_iofunction nvme_validate_passthru_nsidfunction nvme_user_cmdfunction nvme_user_cmd64function nvme_uring_task_cbfunction nvme_uring_cmd_end_iofunction requestfunction nvme_uring_cmd_iofunction is_ctrl_ioctlfunction nvme_ctrl_ioctlfunction nvme_ns_ioctlfunction nvme_ioctlfunction nvme_ns_chr_ioctlfunction nvme_uring_cmd_checksfunction nvme_ns_uring_cmdfunction nvme_ns_chr_uring_cmdfunction nvme_ns_chr_uring_cmd_iopollfunction nvme_ns_head_ctrl_ioctlfunction nvme_ns_head_ioctlfunction nvme_ns_head_chr_ioctlfunction nvme_ns_head_chr_uring_cmdfunction nvme_dev_uring_cmdfunction nvme_dev_user_cmdfunction nvme_dev_ioctl
Annotated Snippet
struct nvme_uring_data {
__u64 metadata;
__u64 addr;
__u32 data_len;
__u32 metadata_len;
__u32 timeout_ms;
};
/*
* This overlays struct io_uring_cmd pdu.
* Expect build errors if this grows larger than that.
*/
struct nvme_uring_cmd_pdu {
struct request *req;
struct bio *bio;
u64 result;
int status;
};
static inline struct nvme_uring_cmd_pdu *nvme_uring_cmd_pdu(
struct io_uring_cmd *ioucmd)
{
return io_uring_cmd_to_pdu(ioucmd, struct nvme_uring_cmd_pdu);
}
static void nvme_uring_task_cb(struct io_tw_req tw_req, io_tw_token_t tw)
{
struct io_uring_cmd *ioucmd = io_uring_cmd_from_tw(tw_req);
struct nvme_uring_cmd_pdu *pdu = nvme_uring_cmd_pdu(ioucmd);
if (pdu->bio)
blk_rq_unmap_user(pdu->bio);
io_uring_cmd_done32(ioucmd, pdu->status, pdu->result,
IO_URING_CMD_TASK_WORK_ISSUE_FLAGS);
}
static enum rq_end_io_ret nvme_uring_cmd_end_io(struct request *req,
blk_status_t err,
const struct io_comp_batch *iob)
{
struct io_uring_cmd *ioucmd = req->end_io_data;
struct nvme_uring_cmd_pdu *pdu = nvme_uring_cmd_pdu(ioucmd);
if (nvme_req(req)->flags & NVME_REQ_CANCELLED) {
pdu->status = -EINTR;
} else {
pdu->status = nvme_req(req)->status;
if (!pdu->status)
pdu->status = blk_status_to_errno(err);
}
pdu->result = le64_to_cpu(nvme_req(req)->result.u64);
/*
* For IOPOLL, check if this completion is happening in the context
* of the same io_ring that owns the request (local context). If so,
* we can complete inline without task_work overhead. Otherwise, we
* must punt to task_work to ensure completion happens in the correct
* ring's context.
*/
if (blk_rq_is_poll(req) && iob &&
iob->poll_ctx == io_uring_cmd_ctx_handle(ioucmd)) {
if (pdu->bio)
blk_rq_unmap_user(pdu->bio);
io_uring_cmd_done32(ioucmd, pdu->status, pdu->result, 0);
} else {
io_uring_cmd_do_in_task_lazy(ioucmd, nvme_uring_task_cb);
}
return RQ_END_IO_FREE;
}
static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
struct io_uring_cmd *ioucmd, unsigned int issue_flags, bool vec)
{
struct nvme_uring_cmd_pdu *pdu = nvme_uring_cmd_pdu(ioucmd);
const struct nvme_uring_cmd *cmd = io_uring_sqe128_cmd(ioucmd->sqe,
struct nvme_uring_cmd);
struct request_queue *q = ns ? ns->queue : ctrl->admin_q;
struct nvme_uring_data d;
struct nvme_command c;
struct iov_iter iter;
struct iov_iter *map_iter = NULL;
struct request *req;
blk_opf_t rq_flags = 0;
blk_mq_req_flags_t blk_flags = 0;
int ret;
c.common.opcode = READ_ONCE(cmd->opcode);
c.common.flags = READ_ONCE(cmd->flags);
if (c.common.flags)
return -EINVAL;
Annotation
- Immediate include surface: `linux/blk-integrity.h`, `linux/ptrace.h`, `linux/nvme_ioctl.h`, `linux/io_uring/cmd.h`, `nvme.h`.
- Detected declarations: `struct nvme_uring_data`, `struct nvme_uring_cmd_pdu`, `struct nvme_user_io32`, `function nvme_cmd_allowed`, `function nvme_map_user_request`, `function nvme_submit_user_cmd`, `function nvme_submit_io`, `function nvme_validate_passthru_nsid`, `function nvme_user_cmd`, `function nvme_user_cmd64`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: source 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.