Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c021eac4 authored by Shirley Ma's avatar Shirley Ma Committed by Rusty Russell
Browse files

virtio: Add ability to detach unused buffers from vrings



There's currently no way for a virtio driver to ask for unused
buffers, so it has to keep a list itself to reclaim them at shutdown.
This is redundant, since virtio_ring stores that information.  So
add a new hook to do this.

Signed-off-by: default avatarShirley Ma <xma@us.ibm.com>
Signed-off-by: default avatarAmit Shah <amit.shah@redhat.com>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 69740c8b
Loading
Loading
Loading
Loading
+25 −0
Original line number Original line Diff line number Diff line
@@ -351,6 +351,30 @@ static bool vring_enable_cb(struct virtqueue *_vq)
	return true;
	return true;
}
}


static void *vring_detach_unused_buf(struct virtqueue *_vq)
{
	struct vring_virtqueue *vq = to_vvq(_vq);
	unsigned int i;
	void *buf;

	START_USE(vq);

	for (i = 0; i < vq->vring.num; i++) {
		if (!vq->data[i])
			continue;
		/* detach_buf clears data, so grab it now. */
		buf = vq->data[i];
		detach_buf(vq, i);
		END_USE(vq);
		return buf;
	}
	/* That should have freed everything. */
	BUG_ON(vq->num_free != vq->vring.num);

	END_USE(vq);
	return NULL;
}

irqreturn_t vring_interrupt(int irq, void *_vq)
irqreturn_t vring_interrupt(int irq, void *_vq)
{
{
	struct vring_virtqueue *vq = to_vvq(_vq);
	struct vring_virtqueue *vq = to_vvq(_vq);
@@ -377,6 +401,7 @@ static struct virtqueue_ops vring_vq_ops = {
	.kick = vring_kick,
	.kick = vring_kick,
	.disable_cb = vring_disable_cb,
	.disable_cb = vring_disable_cb,
	.enable_cb = vring_enable_cb,
	.enable_cb = vring_enable_cb,
	.detach_unused_buf = vring_detach_unused_buf,
};
};


struct virtqueue *vring_new_virtqueue(unsigned int num,
struct virtqueue *vring_new_virtqueue(unsigned int num,
+4 −0
Original line number Original line Diff line number Diff line
@@ -51,6 +51,9 @@ struct virtqueue {
 *	This re-enables callbacks; it returns "false" if there are pending
 *	This re-enables callbacks; it returns "false" if there are pending
 *	buffers in the queue, to detect a possible race between the driver
 *	buffers in the queue, to detect a possible race between the driver
 *	checking for more work, and enabling callbacks.
 *	checking for more work, and enabling callbacks.
 * @detach_unused_buf: detach first unused buffer
 * 	vq: the struct virtqueue we're talking about.
 * 	Returns NULL or the "data" token handed to add_buf
 *
 *
 * Locking rules are straightforward: the driver is responsible for
 * Locking rules are straightforward: the driver is responsible for
 * locking.  No two operations may be invoked simultaneously, with the exception
 * locking.  No two operations may be invoked simultaneously, with the exception
@@ -71,6 +74,7 @@ struct virtqueue_ops {


	void (*disable_cb)(struct virtqueue *vq);
	void (*disable_cb)(struct virtqueue *vq);
	bool (*enable_cb)(struct virtqueue *vq);
	bool (*enable_cb)(struct virtqueue *vq);
	void *(*detach_unused_buf)(struct virtqueue *vq);
};
};


/**
/**