drivers/gpu/drm/virtio/virtgpu_submit.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/virtio/virtgpu_submit.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/virtio/virtgpu_submit.c- Extension
.c- Size
- 12288 bytes
- Lines
- 545
- Domain
- Driver Families
- Bucket
- drivers/gpu
- 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.
- 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/dma-fence-unwrap.hlinux/file.hlinux/sync_file.hlinux/uaccess.hdrm/drm_file.hdrm/drm_syncobj.hdrm/virtgpu_drm.hvirtgpu_drv.h
Detected Declarations
struct virtio_gpu_submit_post_depstruct virtio_gpu_submitfunction virtio_gpu_do_fence_waitfunction virtio_gpu_dma_fence_waitfunction dma_fence_unwrap_for_eachfunction virtio_gpu_free_syncobjsfunction virtio_gpu_parse_depsfunction virtio_gpu_reset_syncobjsfunction virtio_gpu_free_post_depsfunction virtio_gpu_parse_post_depsfunction virtio_gpu_process_post_depsfunction virtio_gpu_fence_event_createfunction virtio_gpu_init_submit_buflistfunction virtio_gpu_cleanup_submitfunction virtio_gpu_submitfunction virtio_gpu_complete_submitfunction virtio_gpu_init_submitfunction virtio_gpu_wait_in_fencefunction virtio_gpu_install_out_fence_fdfunction virtio_gpu_lock_buflistfunction virtio_gpu_execbuffer_ioctl
Annotated Snippet
struct virtio_gpu_submit_post_dep {
struct drm_syncobj *syncobj;
struct dma_fence_chain *chain;
u64 point;
};
struct virtio_gpu_submit {
struct virtio_gpu_submit_post_dep *post_deps;
unsigned int num_out_syncobjs;
struct drm_syncobj **in_syncobjs;
unsigned int num_in_syncobjs;
struct virtio_gpu_object_array *buflist;
struct drm_virtgpu_execbuffer *exbuf;
struct virtio_gpu_fence *out_fence;
struct virtio_gpu_fpriv *vfpriv;
struct virtio_gpu_device *vgdev;
struct sync_file *sync_file;
struct drm_file *file;
int out_fence_fd;
u64 fence_ctx;
u32 ring_idx;
void *buf;
};
static int virtio_gpu_do_fence_wait(struct virtio_gpu_submit *submit,
struct dma_fence *in_fence)
{
u64 context = submit->fence_ctx + submit->ring_idx;
if (dma_fence_match_context(in_fence, context))
return 0;
return dma_fence_wait(in_fence, true);
}
static int virtio_gpu_dma_fence_wait(struct virtio_gpu_submit *submit,
struct dma_fence *fence)
{
struct dma_fence_unwrap itr;
struct dma_fence *f;
int err;
dma_fence_unwrap_for_each(f, &itr, fence) {
err = virtio_gpu_do_fence_wait(submit, f);
if (err) {
dma_fence_put(itr.chain);
return err;
}
}
return 0;
}
static void virtio_gpu_free_syncobjs(struct drm_syncobj **syncobjs,
u32 nr_syncobjs)
{
u32 i = nr_syncobjs;
while (i--) {
if (syncobjs[i])
drm_syncobj_put(syncobjs[i]);
}
kvfree(syncobjs);
}
static int
virtio_gpu_parse_deps(struct virtio_gpu_submit *submit)
{
struct drm_virtgpu_execbuffer *exbuf = submit->exbuf;
struct drm_virtgpu_execbuffer_syncobj syncobj_desc;
size_t syncobj_stride = exbuf->syncobj_stride;
u32 num_in_syncobjs = exbuf->num_in_syncobjs;
struct drm_syncobj **syncobjs;
int ret = 0, i;
if (!num_in_syncobjs)
return 0;
/*
* kvmalloc() at first tries to allocate memory using kmalloc() and
* falls back to vmalloc() only on failure. It also uses __GFP_NOWARN
* internally for allocations larger than a page size, preventing
* storm of KMSG warnings.
*/
syncobjs = kvzalloc_objs(*syncobjs, num_in_syncobjs);
if (!syncobjs)
return -ENOMEM;
Annotation
- Immediate include surface: `linux/dma-fence-unwrap.h`, `linux/file.h`, `linux/sync_file.h`, `linux/uaccess.h`, `drm/drm_file.h`, `drm/drm_syncobj.h`, `drm/virtgpu_drm.h`, `virtgpu_drv.h`.
- Detected declarations: `struct virtio_gpu_submit_post_dep`, `struct virtio_gpu_submit`, `function virtio_gpu_do_fence_wait`, `function virtio_gpu_dma_fence_wait`, `function dma_fence_unwrap_for_each`, `function virtio_gpu_free_syncobjs`, `function virtio_gpu_parse_deps`, `function virtio_gpu_reset_syncobjs`, `function virtio_gpu_free_post_deps`, `function virtio_gpu_parse_post_deps`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.