drivers/infiniband/core/uverbs_cmd.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/core/uverbs_cmd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/core/uverbs_cmd.c- Extension
.c- Size
- 107397 bytes
- Lines
- 4006
- Domain
- Driver Families
- Bucket
- drivers/infiniband
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/file.hlinux/fs.hlinux/slab.hlinux/sched.hlinux/uaccess.hrdma/uverbs_types.hrdma/uverbs_std_types.hrdma/ib_ucaps.hrdma_core.huverbs.hcore_priv.hrestrack.h
Detected Declarations
struct uverbs_req_iterstruct xrcd_table_entryfunction Copyrightfunction uverbs_requestfunction uverbs_response_lengthfunction uverbs_request_startfunction uverbs_request_nextfunction uverbs_request_finishfunction _ib_uverbs_lookup_comp_filefunction ib_alloc_ucontextfunction ib_init_ucontextfunction ib_uverbs_get_contextfunction copy_query_dev_fieldsfunction ib_uverbs_query_devicefunction ib_uverbs_query_portfunction ib_uverbs_alloc_pdfunction ib_uverbs_dealloc_pdfunction xrcd_table_insertfunction xrcd_table_deletefunction ib_uverbs_open_xrcdfunction ib_uverbs_close_xrcdfunction ib_uverbs_dealloc_xrcdfunction ib_uverbs_reg_mrfunction ib_uverbs_rereg_mrfunction ib_uverbs_dereg_mrfunction ib_uverbs_alloc_mwfunction ib_uverbs_dealloc_mwfunction ib_uverbs_create_comp_channelfunction create_cqfunction ib_uverbs_create_cqfunction ib_uverbs_ex_create_cqfunction ib_uverbs_resize_cqfunction copy_wc_to_userfunction ib_uverbs_poll_cqfunction ib_uverbs_req_notify_cqfunction ib_uverbs_destroy_cqfunction create_qpfunction ib_uverbs_create_qpfunction ib_uverbs_ex_create_qpfunction ib_uverbs_open_qpfunction copy_ah_attr_to_uverbsfunction ib_uverbs_query_qpfunction modify_qp_maskfunction copy_ah_attr_from_uverbsfunction modify_qpfunction ib_uverbs_modify_qpfunction ib_uverbs_ex_modify_qpfunction ib_uverbs_destroy_qp
Annotated Snippet
struct uverbs_req_iter {
const void __user *cur;
const void __user *end;
};
static int uverbs_request_start(struct uverbs_attr_bundle *attrs,
struct uverbs_req_iter *iter,
void *req,
size_t req_len)
{
if (attrs->ucore.inlen < req_len)
return -ENOSPC;
if (copy_from_user(req, attrs->ucore.inbuf, req_len))
return -EFAULT;
iter->cur = attrs->ucore.inbuf + req_len;
iter->end = attrs->ucore.inbuf + attrs->ucore.inlen;
return 0;
}
static int uverbs_request_next(struct uverbs_req_iter *iter, void *val,
size_t len)
{
if (iter->cur + len > iter->end)
return -ENOSPC;
if (copy_from_user(val, iter->cur, len))
return -EFAULT;
iter->cur += len;
return 0;
}
static const void __user *uverbs_request_next_ptr(struct uverbs_req_iter *iter,
size_t len)
{
const void __user *res = iter->cur;
if (len > iter->end - iter->cur)
return (void __force __user *)ERR_PTR(-ENOSPC);
iter->cur += len;
return res;
}
static int uverbs_request_finish(struct uverbs_req_iter *iter)
{
if (!ib_is_buffer_cleared(iter->cur, iter->end - iter->cur))
return -EOPNOTSUPP;
return 0;
}
static struct ib_uverbs_completion_event_file *
_ib_uverbs_lookup_comp_file(s32 fd, struct uverbs_attr_bundle *attrs)
{
struct ib_uobject *uobj = ufd_get_read(UVERBS_OBJECT_COMP_CHANNEL,
fd, attrs);
if (IS_ERR(uobj))
return ERR_CAST(uobj);
uverbs_uobject_get(uobj);
uobj_put_read(uobj);
return container_of(uobj, struct ib_uverbs_completion_event_file,
uobj);
}
#define ib_uverbs_lookup_comp_file(_fd, _ufile) \
_ib_uverbs_lookup_comp_file((_fd)*typecheck(s32, _fd), _ufile)
int ib_alloc_ucontext(struct uverbs_attr_bundle *attrs)
{
struct ib_uverbs_file *ufile = attrs->ufile;
struct ib_ucontext *ucontext;
struct ib_device *ib_dev;
ib_dev = srcu_dereference(ufile->device->ib_dev,
&ufile->device->disassociate_srcu);
if (!ib_dev)
return -EIO;
ucontext = rdma_zalloc_drv_obj(ib_dev, ib_ucontext);
if (!ucontext)
return -ENOMEM;
ucontext->device = ib_dev;
ucontext->ufile = ufile;
xa_init_flags(&ucontext->mmap_xa, XA_FLAGS_ALLOC);
rdma_restrack_new(&ucontext->res, RDMA_RESTRACK_CTX);
Annotation
- Immediate include surface: `linux/file.h`, `linux/fs.h`, `linux/slab.h`, `linux/sched.h`, `linux/uaccess.h`, `rdma/uverbs_types.h`, `rdma/uverbs_std_types.h`, `rdma/ib_ucaps.h`.
- Detected declarations: `struct uverbs_req_iter`, `struct xrcd_table_entry`, `function Copyright`, `function uverbs_request`, `function uverbs_response_length`, `function uverbs_request_start`, `function uverbs_request_next`, `function uverbs_request_finish`, `function _ib_uverbs_lookup_comp_file`, `function ib_alloc_ucontext`.
- Atlas domain: Driver Families / drivers/infiniband.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.