drivers/vhost/iotlb.c
Source file repositories/reference/linux-study-clean/drivers/vhost/iotlb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vhost/iotlb.c- Extension
.c- Size
- 5384 bytes
- Lines
- 218
- Domain
- Driver Families
- Bucket
- drivers/vhost
- 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.
- 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/vhost_iotlb.hlinux/module.h
Detected Declarations
function vhost_iotlb_map_freefunction vhost_iotlb_add_range_ctxfunction vhost_iotlb_add_rangefunction vhost_iotlb_del_rangefunction vhost_iotlb_initfunction vhost_iotlb_resetfunction vhost_iotlb_freefunction vhost_iotlb_itree_firstfunction vhost_iotlb_itree_nextexport vhost_iotlb_map_freeexport vhost_iotlb_add_range_ctxexport vhost_iotlb_add_rangeexport vhost_iotlb_del_rangeexport vhost_iotlb_initexport vhost_iotlb_allocexport vhost_iotlb_resetexport vhost_iotlb_freeexport vhost_iotlb_itree_firstexport vhost_iotlb_itree_next
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/* Copyright (C) 2020 Red Hat, Inc.
* Author: Jason Wang <jasowang@redhat.com>
*
* IOTLB implementation for vhost.
*/
#include <linux/slab.h>
#include <linux/vhost_iotlb.h>
#include <linux/module.h>
#define MOD_VERSION "0.1"
#define MOD_DESC "VHOST IOTLB"
#define MOD_AUTHOR "Jason Wang <jasowang@redhat.com>"
#define MOD_LICENSE "GPL v2"
#define START(map) ((map)->start)
#define LAST(map) ((map)->last)
INTERVAL_TREE_DEFINE(struct vhost_iotlb_map,
rb, __u64, __subtree_last,
START, LAST, static inline, vhost_iotlb_itree);
/**
* vhost_iotlb_map_free - remove a map node and free it
* @iotlb: the IOTLB
* @map: the map that want to be remove and freed
*/
void vhost_iotlb_map_free(struct vhost_iotlb *iotlb,
struct vhost_iotlb_map *map)
{
vhost_iotlb_itree_remove(map, &iotlb->root);
list_del(&map->link);
kfree(map);
iotlb->nmaps--;
}
EXPORT_SYMBOL_GPL(vhost_iotlb_map_free);
/**
* vhost_iotlb_add_range_ctx - add a new range to vhost IOTLB
* @iotlb: the IOTLB
* @start: start of the IOVA range
* @last: last of IOVA range
* @addr: the address that is mapped to @start
* @perm: access permission of this range
* @opaque: the opaque pointer for the new mapping
*
* Returns an error last is smaller than start or memory allocation
* fails
*/
int vhost_iotlb_add_range_ctx(struct vhost_iotlb *iotlb,
u64 start, u64 last,
u64 addr, unsigned int perm,
void *opaque)
{
struct vhost_iotlb_map *map;
if (last < start)
return -EFAULT;
/* If the range being mapped is [0, ULONG_MAX], split it into two entries
* otherwise its size would overflow u64.
*/
if (start == 0 && last == ULONG_MAX) {
u64 mid = last / 2;
int err = vhost_iotlb_add_range_ctx(iotlb, start, mid, addr,
perm, opaque);
if (err)
return err;
addr += mid + 1;
start = mid + 1;
}
if (iotlb->limit &&
iotlb->nmaps == iotlb->limit &&
iotlb->flags & VHOST_IOTLB_FLAG_RETIRE) {
map = list_first_entry(&iotlb->list, typeof(*map), link);
vhost_iotlb_map_free(iotlb, map);
}
map = kmalloc_obj(*map, GFP_ATOMIC);
if (!map)
return -ENOMEM;
map->start = start;
map->size = last - start + 1;
map->last = last;
map->addr = addr;
map->perm = perm;
Annotation
- Immediate include surface: `linux/slab.h`, `linux/vhost_iotlb.h`, `linux/module.h`.
- Detected declarations: `function vhost_iotlb_map_free`, `function vhost_iotlb_add_range_ctx`, `function vhost_iotlb_add_range`, `function vhost_iotlb_del_range`, `function vhost_iotlb_init`, `function vhost_iotlb_reset`, `function vhost_iotlb_free`, `function vhost_iotlb_itree_first`, `function vhost_iotlb_itree_next`, `export vhost_iotlb_map_free`.
- Atlas domain: Driver Families / drivers/vhost.
- Implementation status: integration implementation candidate.
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.