drivers/infiniband/core/ucma.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/core/ucma.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/core/ucma.c- Extension
.c- Size
- 50736 bytes
- Lines
- 2008
- Domain
- Driver Families
- Bucket
- drivers/infiniband
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/completion.hlinux/file.hlinux/mutex.hlinux/poll.hlinux/sched.hlinux/idr.hlinux/in.hlinux/in6.hlinux/miscdevice.hlinux/slab.hlinux/sysctl.hlinux/module.hlinux/nsproxy.hlinux/nospec.hrdma/rdma_user_cm.hrdma/ib_marshall.hrdma/rdma_cm.hrdma/rdma_cm_ib.hrdma/ib_addr.hrdma/ib.hrdma/ib_cm.hrdma/rdma_netlink.hcore_priv.h
Detected Declarations
struct ucma_filestruct ucma_contextstruct ucma_multicaststruct ucma_eventfunction ucma_put_ctxfunction ucma_close_idfunction ucma_set_ctx_cm_idfunction ucma_finish_ctxfunction ucma_copy_conn_eventfunction ucma_copy_ud_eventfunction ucma_connect_event_handlerfunction ucma_event_handlerfunction ucma_get_eventfunction ucma_get_qp_typefunction ucma_create_idfunction ucma_cleanup_multicastfunction ucma_cleanup_mc_eventsfunction ucma_cleanup_ctx_eventsfunction ucma_destroy_private_ctxfunction ucma_destroy_idfunction ucma_bind_ipfunction ucma_bindfunction ucma_resolve_ipfunction ucma_resolve_addrfunction ucma_resolve_ib_servicefunction ucma_resolve_routefunction ucma_copy_ib_routefunction ucma_copy_iboe_routefunction ucma_copy_iw_routefunction ucma_query_routefunction ucma_query_device_addrfunction ucma_query_addrfunction ucma_query_pathfunction ucma_query_gidfunction ucma_query_ib_servicefunction ucma_queryfunction ucma_copy_conn_paramfunction ucma_connectfunction ucma_listenfunction ucma_acceptfunction ucma_rejectfunction ucma_disconnectfunction ucma_init_qp_attrfunction ucma_set_option_idfunction ucma_set_ib_pathfunction ucma_set_option_ibfunction ucma_set_option_levelfunction ucma_set_option
Annotated Snippet
static const struct file_operations ucma_fops;
static int ucma_destroy_private_ctx(struct ucma_context *ctx);
static inline struct ucma_context *_ucma_find_context(int id,
struct ucma_file *file)
{
struct ucma_context *ctx;
ctx = xa_load(&ctx_table, id);
if (!ctx)
ctx = ERR_PTR(-ENOENT);
else if (ctx->file != file)
ctx = ERR_PTR(-EINVAL);
return ctx;
}
static struct ucma_context *ucma_get_ctx(struct ucma_file *file, int id)
{
struct ucma_context *ctx;
xa_lock(&ctx_table);
ctx = _ucma_find_context(id, file);
if (!IS_ERR(ctx))
if (!refcount_inc_not_zero(&ctx->ref))
ctx = ERR_PTR(-ENXIO);
xa_unlock(&ctx_table);
return ctx;
}
static void ucma_put_ctx(struct ucma_context *ctx)
{
if (refcount_dec_and_test(&ctx->ref))
complete(&ctx->comp);
}
/*
* Same as ucm_get_ctx but requires that ->cm_id->device is valid, eg that the
* CM_ID is bound.
*/
static struct ucma_context *ucma_get_ctx_dev(struct ucma_file *file, int id)
{
struct ucma_context *ctx = ucma_get_ctx(file, id);
if (IS_ERR(ctx))
return ctx;
if (!ctx->cm_id->device) {
ucma_put_ctx(ctx);
return ERR_PTR(-EINVAL);
}
return ctx;
}
static void ucma_close_id(struct work_struct *work)
{
struct ucma_context *ctx = container_of(work, struct ucma_context, close_work);
/* once all inflight tasks are finished, we close all underlying
* resources. The context is still alive till its explicit destryoing
* by its creator. This puts back the xarray's reference.
*/
ucma_put_ctx(ctx);
wait_for_completion(&ctx->comp);
/* No new events will be generated after destroying the id. */
rdma_destroy_id(ctx->cm_id);
/* Reading the cm_id without holding a positive ref is not allowed */
ctx->cm_id = NULL;
}
static struct ucma_context *ucma_alloc_ctx(struct ucma_file *file)
{
struct ucma_context *ctx;
ctx = kzalloc_obj(*ctx);
if (!ctx)
return NULL;
INIT_WORK(&ctx->close_work, ucma_close_id);
init_completion(&ctx->comp);
INIT_LIST_HEAD(&ctx->mc_list);
/* So list_del() will work if we don't do ucma_finish_ctx() */
INIT_LIST_HEAD(&ctx->list);
ctx->file = file;
mutex_init(&ctx->mutex);
if (xa_alloc(&ctx_table, &ctx->id, NULL, xa_limit_32b, GFP_KERNEL)) {
kfree(ctx);
return NULL;
}
return ctx;
Annotation
- Immediate include surface: `linux/completion.h`, `linux/file.h`, `linux/mutex.h`, `linux/poll.h`, `linux/sched.h`, `linux/idr.h`, `linux/in.h`, `linux/in6.h`.
- Detected declarations: `struct ucma_file`, `struct ucma_context`, `struct ucma_multicast`, `struct ucma_event`, `function ucma_put_ctx`, `function ucma_close_id`, `function ucma_set_ctx_cm_id`, `function ucma_finish_ctx`, `function ucma_copy_conn_event`, `function ucma_copy_ud_event`.
- Atlas domain: Driver Families / drivers/infiniband.
- Implementation status: pattern 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.