kernel/bpf/dmabuf_iter.c

Source file repositories/reference/linux-study-clean/kernel/bpf/dmabuf_iter.c

File Facts

System
Linux kernel
Corpus path
kernel/bpf/dmabuf_iter.c
Extension
.c
Size
4404 bytes
Lines
193
Domain
Core OS
Bucket
Scheduler, Processes, Timers, Sync, And Syscalls
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

struct dmabuf_iter_priv {
	/*
	 * If this pointer is non-NULL, the buffer's refcount is elevated to
	 * prevent destruction between stop/start. If reading is not resumed and
	 * start is never called again, then dmabuf_iter_seq_fini drops the
	 * reference when the iterator is released.
	 */
	struct dma_buf *dmabuf;
};

static void *dmabuf_iter_seq_start(struct seq_file *seq, loff_t *pos)
{
	struct dmabuf_iter_priv *p = seq->private;

	if (*pos) {
		struct dma_buf *dmabuf = p->dmabuf;

		if (!dmabuf)
			return NULL;

		/*
		 * Always resume from where we stopped, regardless of the value
		 * of pos.
		 */
		p->dmabuf = NULL;
		return dmabuf;
	}

	return dma_buf_iter_begin();
}

static void *dmabuf_iter_seq_next(struct seq_file *seq, void *v, loff_t *pos)
{
	struct dma_buf *dmabuf = v;

	++*pos;

	return dma_buf_iter_next(dmabuf);
}

struct bpf_iter__dmabuf {
	__bpf_md_ptr(struct bpf_iter_meta *, meta);
	__bpf_md_ptr(struct dma_buf *, dmabuf);
};

static int __dmabuf_seq_show(struct seq_file *seq, void *v, bool in_stop)
{
	struct bpf_iter_meta meta = {
		.seq = seq,
	};
	struct bpf_iter__dmabuf ctx = {
		.meta = &meta,
		.dmabuf = v,
	};
	struct bpf_prog *prog = bpf_iter_get_info(&meta, in_stop);

	if (prog)
		return bpf_iter_run_prog(prog, &ctx);

	return 0;
}

static int dmabuf_iter_seq_show(struct seq_file *seq, void *v)
{
	return __dmabuf_seq_show(seq, v, false);
}

static void dmabuf_iter_seq_stop(struct seq_file *seq, void *v)
{
	struct dma_buf *dmabuf = v;

	if (dmabuf) {
		struct dmabuf_iter_priv *p = seq->private;

		p->dmabuf = dmabuf;
	}
}

static const struct seq_operations dmabuf_iter_seq_ops = {
	.start	= dmabuf_iter_seq_start,
	.next	= dmabuf_iter_seq_next,
	.stop	= dmabuf_iter_seq_stop,
	.show	= dmabuf_iter_seq_show,
};

static void bpf_iter_dmabuf_show_fdinfo(const struct bpf_iter_aux_info *aux,
					struct seq_file *seq)
{
	seq_puts(seq, "dmabuf iter\n");
}

Annotation

Implementation Notes