drivers/infiniband/sw/rdmavt/mr.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/sw/rdmavt/mr.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/sw/rdmavt/mr.c- Extension
.c- Size
- 21409 bytes
- Lines
- 923
- Domain
- Driver Families
- Bucket
- drivers/infiniband
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/slab.hlinux/vmalloc.hrdma/ib_umem.hrdma/rdma_vt.hvt.hmr.htrace.h
Detected Declarations
function Copyrightfunction rvt_mr_exitfunction rvt_deinit_mregionfunction __rvt_mregion_completefunction rvt_init_mregionfunction rvt_alloc_lkeyfunction rvt_free_lkeyfunction __rvt_free_mrfunction rvt_qp_mr_cleanfunction rvt_dereg_clean_qpsfunction rvt_check_refsfunction rvt_mr_has_lkeyfunction rvt_ss_has_lkeyfunction rvt_get_dma_mrfunction rvt_set_pagefunction rvt_map_mr_sgfunction rvt_fast_reg_mrfunction rvt_invalidate_rkeyfunction rvt_sge_adjacentfunction rvt_lkey_okfunction rvt_rkey_okexport rvt_fast_reg_mrexport rvt_invalidate_rkeyexport rvt_lkey_okexport rvt_rkey_ok
Annotated Snippet
if (!tmr) {
mr->lkey_published = 1;
/* Insure published written first */
rcu_assign_pointer(dev->dma_mr, mr);
rvt_get_mr(mr);
}
goto success;
}
/* Find the next available LKEY */
r = rkt->next;
n = r;
for (;;) {
if (!rcu_access_pointer(rkt->table[r]))
break;
r = (r + 1) & (rkt->max - 1);
if (r == n)
goto bail;
}
rkt->next = (r + 1) & (rkt->max - 1);
/*
* Make sure lkey is never zero which is reserved to indicate an
* unrestricted LKEY.
*/
rkt->gen++;
/*
* bits are capped to ensure enough bits for generation number
*/
mr->lkey = (r << (32 - dev->dparms.lkey_table_size)) |
((((1 << (24 - dev->dparms.lkey_table_size)) - 1) & rkt->gen)
<< 8);
if (mr->lkey == 0) {
mr->lkey |= 1 << 8;
rkt->gen++;
}
mr->lkey_published = 1;
/* Insure published written first */
rcu_assign_pointer(rkt->table[r], mr);
success:
spin_unlock_irqrestore(&rkt->lock, flags);
out:
return ret;
bail:
rvt_put_mr(mr);
spin_unlock_irqrestore(&rkt->lock, flags);
ret = -ENOMEM;
goto out;
}
/**
* rvt_free_lkey - free an lkey
* @mr: mr to free from tables
*/
static void rvt_free_lkey(struct rvt_mregion *mr)
{
unsigned long flags;
u32 lkey = mr->lkey;
u32 r;
struct rvt_dev_info *dev = ib_to_rvt(mr->pd->device);
struct rvt_lkey_table *rkt = &dev->lkey_table;
int freed = 0;
spin_lock_irqsave(&rkt->lock, flags);
if (!lkey) {
if (mr->lkey_published) {
mr->lkey_published = 0;
/* insure published is written before pointer */
rcu_assign_pointer(dev->dma_mr, NULL);
rvt_put_mr(mr);
}
} else {
if (!mr->lkey_published)
goto out;
r = lkey >> (32 - dev->dparms.lkey_table_size);
mr->lkey_published = 0;
/* insure published is written before pointer */
rcu_assign_pointer(rkt->table[r], NULL);
}
freed++;
out:
spin_unlock_irqrestore(&rkt->lock, flags);
if (freed)
percpu_ref_kill(&mr->refcount);
}
static struct rvt_mr *__rvt_alloc_mr(int count, struct ib_pd *pd)
{
struct rvt_mr *mr;
int rval = -ENOMEM;
int m;
Annotation
- Immediate include surface: `linux/slab.h`, `linux/vmalloc.h`, `rdma/ib_umem.h`, `rdma/rdma_vt.h`, `vt.h`, `mr.h`, `trace.h`.
- Detected declarations: `function Copyright`, `function rvt_mr_exit`, `function rvt_deinit_mregion`, `function __rvt_mregion_complete`, `function rvt_init_mregion`, `function rvt_alloc_lkey`, `function rvt_free_lkey`, `function __rvt_free_mr`, `function rvt_qp_mr_clean`, `function rvt_dereg_clean_qps`.
- Atlas domain: Driver Families / drivers/infiniband.
- Implementation status: integration implementation candidate.
- 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.