Re: [PATCH RFC 3/5] tun: vringfd receive support.

From: Anthony Liguori
Date: Sat Apr 05 2008 - 13:27:20 EST


Rusty Russell wrote:
This patch modifies tun to allow a vringfd to specify the receive
buffer. Because we can't copy to userspace in bh context, we queue
like normal then use the "pull" hook to actually do the copy.

More thought needs to be put into the possible races with ring
registration and a simultaneous close, for example (see FIXME).

We use struct virtio_net_hdr prepended to packets in the ring to allow
userspace to receive GSO packets in future (at the moment, the tun
driver doesn't tell the stack it can handle them, so these cases are
never taken).

Signed-off-by: Rusty Russell <rusty@xxxxxxxxxxxxxxx>

<snip>

+
+#ifdef CONFIG_VRINGFD

I think the rest of the code needs these for it to actually work without VRINGFD.

+static void unset_recv(void *_tun)
+{
+ struct tun_struct *tun = _tun;
+
+ tun->inring = NULL;
+}
+
+/* Returns number of used buffers, or negative errno. */
+static int pull_recv_skbs(void *_tun)
+{
+ struct tun_struct *tun = _tun;
+ int err = 0, num_copied = 0;
+ struct sk_buff *skb;
+
+ while ((skb = skb_dequeue(&tun->readq)) != NULL) {
+ struct iovec iov[1+MAX_SKB_FRAGS];
+ struct virtio_net_hdr gso = { 0 }; /* no info leak */
+ unsigned int iovnum = ARRAY_SIZE(iov);
+ unsigned long len;
+ int id;
+
+ id = vring_get_buffer(tun->inring, iov, &iovnum, &len,
+ NULL, NULL, NULL);
+ if (id <= 0) {
+ err = id;
+ break;
+ }

Ah, I see now why you're passing something from the stack.

Regards,

Anthony Liguori
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/