drivers/xen/gntdev-dmabuf.c
Source file repositories/reference/linux-study-clean/drivers/xen/gntdev-dmabuf.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/xen/gntdev-dmabuf.c- Extension
.c- Size
- 20443 bytes
- Lines
- 838
- Domain
- Driver Families
- Bucket
- drivers/xen
- 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/kernel.hlinux/errno.hlinux/dma-buf.hlinux/dma-direct.hlinux/slab.hlinux/types.hlinux/uaccess.hlinux/module.hxen/xen.hxen/grant_table.hgntdev-common.hgntdev-dmabuf.h
Detected Declarations
struct gntdev_dmabufstruct gntdev_dmabuf_wait_objstruct gntdev_dmabuf_attachmentstruct gntdev_dmabuf_privstruct gntdev_dmabuf_export_argsfunction dmabuf_exp_wait_obj_newfunction dmabuf_exp_wait_obj_freefunction dmabuf_exp_wait_obj_waitfunction dmabuf_exp_wait_obj_signalfunction list_for_each_entryfunction dmabuf_exp_wait_obj_get_dmabuffunction dmabuf_exp_wait_releasedfunction dmabuf_pages_to_sgtfunction dmabuf_exp_ops_attachfunction dmabuf_exp_ops_detachfunction dmabuf_exp_ops_map_dma_buffunction dmabuf_exp_ops_unmap_dma_buffunction dmabuf_exp_remove_mapfunction dmabuf_exp_ops_releasefunction dmabuf_exp_from_pagesfunction dmabuf_exp_alloc_backing_storagefunction dmabuf_exp_from_refsfunction dmabuf_imp_grant_foreign_accessfunction dmabuf_imp_end_foreign_accessfunction dmabuf_imp_free_storagefunction dmabuf_imp_to_refsfunction dmabuf_imp_find_unlinkfunction dmabuf_imp_releasefunction dmabuf_imp_release_allfunction gntdev_ioctl_dmabuf_exp_from_refsfunction gntdev_ioctl_dmabuf_exp_wait_releasedfunction gntdev_ioctl_dmabuf_imp_to_refsfunction gntdev_ioctl_dmabuf_imp_releasefunction gntdev_dmabuf_fini
Annotated Snippet
struct gntdev_dmabuf {
struct gntdev_dmabuf_priv *priv;
struct dma_buf *dmabuf;
struct list_head next;
int fd;
union {
struct {
/* Exported buffers are reference counted. */
struct kref refcount;
struct gntdev_priv *priv;
struct gntdev_grant_map *map;
} exp;
struct {
/* Granted references of the imported buffer. */
grant_ref_t *refs;
/* Scatter-gather table of the imported buffer. */
struct sg_table *sgt;
/* dma-buf attachment of the imported buffer. */
struct dma_buf_attachment *attach;
} imp;
} u;
/* Number of pages this buffer has. */
int nr_pages;
/* Pages of this buffer (only for dma-buf export). */
struct page **pages;
};
struct gntdev_dmabuf_wait_obj {
struct list_head next;
struct gntdev_dmabuf *gntdev_dmabuf;
struct completion completion;
};
struct gntdev_dmabuf_attachment {
struct sg_table *sgt;
enum dma_data_direction dir;
};
struct gntdev_dmabuf_priv {
/* List of exported DMA buffers. */
struct list_head exp_list;
/* List of wait objects. */
struct list_head exp_wait_list;
/* List of imported DMA buffers. */
struct list_head imp_list;
/* This is the lock which protects dma_buf_xxx lists. */
struct mutex lock;
/*
* We reference this file while exporting dma-bufs, so
* the grant device context is not destroyed while there are
* external users alive.
*/
struct file *filp;
};
/* DMA buffer export support. */
/* Implementation of wait for exported DMA buffer to be released. */
static void dmabuf_exp_release(struct kref *kref);
static struct gntdev_dmabuf_wait_obj *
dmabuf_exp_wait_obj_new(struct gntdev_dmabuf_priv *priv,
struct gntdev_dmabuf *gntdev_dmabuf)
{
struct gntdev_dmabuf_wait_obj *obj;
obj = kzalloc_obj(*obj);
if (!obj)
return ERR_PTR(-ENOMEM);
init_completion(&obj->completion);
obj->gntdev_dmabuf = gntdev_dmabuf;
mutex_lock(&priv->lock);
list_add(&obj->next, &priv->exp_wait_list);
/* Put our reference and wait for gntdev_dmabuf's release to fire. */
kref_put(&gntdev_dmabuf->u.exp.refcount, dmabuf_exp_release);
mutex_unlock(&priv->lock);
return obj;
}
static void dmabuf_exp_wait_obj_free(struct gntdev_dmabuf_priv *priv,
struct gntdev_dmabuf_wait_obj *obj)
{
mutex_lock(&priv->lock);
list_del(&obj->next);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/dma-buf.h`, `linux/dma-direct.h`, `linux/slab.h`, `linux/types.h`, `linux/uaccess.h`, `linux/module.h`.
- Detected declarations: `struct gntdev_dmabuf`, `struct gntdev_dmabuf_wait_obj`, `struct gntdev_dmabuf_attachment`, `struct gntdev_dmabuf_priv`, `struct gntdev_dmabuf_export_args`, `function dmabuf_exp_wait_obj_new`, `function dmabuf_exp_wait_obj_free`, `function dmabuf_exp_wait_obj_wait`, `function dmabuf_exp_wait_obj_signal`, `function list_for_each_entry`.
- Atlas domain: Driver Families / drivers/xen.
- 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.