netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: Alex Williamson <alex.williamson@hp.com>
Cc: markmc@redhat.com, netdev@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH v2 3/4] virtio_net: Add a MAC filter table
Date: Fri, 30 Jan 2009 16:16:26 +1030	[thread overview]
Message-ID: <200901301616.26914.rusty@rustcorp.com.au> (raw)
In-Reply-To: <20090129230518.2672.20841.stgit@debian.lart>

On Friday 30 January 2009 09:35:18 Alex Williamson wrote:
>  	struct virtnet_info *vi = netdev_priv(dev);
>  	u8 promisc, allmulti;
> +	struct scatterlist sg[4];
> +	struct virtio_net_ctrl_hdr ctrl;
> +	virtio_net_ctrl_ack status;
> +	u8 *uc_buf = NULL, *mc_buf = NULL;
> +	unsigned int tmp;
>  
>  	if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_RX))
>  		return;

It's kind of annoying that we have our virtnet_send_command helper and
yet we can't use it here.

Hmm, maybe we can kill two birds in one stone?  I was a bit nervous about the virtnet_send_command data arg because the pointer must not be vmalloc'ed memory.  If we make the arg to virtnet_send_command an sg[] in place of data & len, we force the caller to do the sg_set_buf (which means they *should* be aware of the limitation on what can be put in an sg), and we can make a copy (ideally we could chain it, but it's not possible to chain a const sg[], so let's BUG_ON if it's too big to fit on the stack).

Then this code can use it.

> -	promisc = ((dev->flags & IFF_PROMISC) != 0 || dev->uc_count > 0);
> -	allmulti = ((dev->flags & IFF_ALLMULTI) != 0 || dev->mc_count > 0);
> +	promisc = ((dev->flags & IFF_PROMISC) != 0);
> +	allmulti = ((dev->flags & IFF_ALLMULTI) != 0);
> +
> +	if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_MAC)) {
> +		promisc |= (dev->uc_count > 0);
> +		allmulti |= (dev->mc_count > 0);
> +	}
>  
>  	if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX,
>  				  VIRTIO_NET_CTRL_RX_PROMISC,
> @@ -682,6 +692,79 @@ static void virtnet_set_rx_mode(struct net_device *dev)
>  				  &allmulti, sizeof(allmulti)))
>  		printk(KERN_WARNING "%s: Failed to %sable allmulti mode.\n",
>  		       dev->name, allmulti ? "en" : "dis");
> +
> +	if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_MAC))
> +		return;

I think we can now fold this feature into VIRTIO_NET_F_CTRL_RX and assert that you must support mac filtering.  Because it's now trivial to support in the host (use promisc!), and it simplifies the implementation.

> +	if (dev->uc_count) {
...
> +		sg_set_buf(&sg[1], uc_buf, dev->uc_count * ETH_ALEN);
...
> +	if (dev->mc_count) {
...
> +		sg_set_buf(&sg[2], mc_buf, dev->mc_count * ETH_ALEN);

We made the decision a while ago not to rely on scatter gather boundaries to define the API.  So you'll actually need a structure to contain the counts unfortunately (technically you only need one count, since the other can be intuited, but that seems silly, and this way you could theoretically add more fields without problems with future feature bits).

It also means you can do a single kmalloc, and skip the if here, if you wanted.

Cheers,
Rusty.

  reply	other threads:[~2009-01-30  5:46 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-29 23:05 [PATCH v2 0/4] virtio_net: Add MAC and VLAN filtering Alex Williamson
2009-01-29 23:05 ` [PATCH v2 1/4] virtio_net: Add a virtqueue for outbound control commands Alex Williamson
2009-01-30  5:08   ` Rusty Russell
2009-01-29 23:05 ` [PATCH v2 2/4] virtio_net: Add a set_rx_mode interface Alex Williamson
2009-01-30  5:30   ` Rusty Russell
2009-01-29 23:05 ` [PATCH v2 3/4] virtio_net: Add a MAC filter table Alex Williamson
2009-01-30  5:46   ` Rusty Russell [this message]
2009-01-29 23:05 ` [PATCH v2 4/4] virtio_net: Add support for VLAN filtering in the hypervisor Alex Williamson
2009-01-30  6:01   ` Rusty Russell
2009-01-30  1:49 ` [PATCH v2 0/4] virtio_net: Add MAC and VLAN filtering David Miller
2009-01-30  7:05   ` Rusty Russell
2009-01-30  7:12     ` David Miller
2009-01-30  5:03 ` Rusty Russell
2009-02-01 20:05   ` [PATCH v3 " Alex Williamson
2009-02-01 20:05     ` [PATCH v3 1/4] virtio_net: Add a virtqueue for outbound control commands Alex Williamson
2009-02-02  9:40       ` Rusty Russell
2009-02-02 14:10         ` Anthony Liguori
2009-02-01 20:05     ` [PATCH v3 2/4] virtio_net: Add a set_rx_mode interface Alex Williamson
2009-02-02  9:52       ` Rusty Russell
2009-02-02 21:34         ` Alex Williamson
2009-02-03  2:54           ` Rusty Russell
2009-02-01 20:05     ` [PATCH v3 3/4] virtio_net: Add a MAC filter table Alex Williamson
2009-02-02  9:57       ` Rusty Russell
2009-02-01 20:05     ` [PATCH v3 4/4] virtio_net: Add support for VLAN filtering in the hypervisor Alex Williamson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200901301616.26914.rusty@rustcorp.com.au \
    --to=rusty@rustcorp.com.au \
    --cc=alex.williamson@hp.com \
    --cc=kvm@vger.kernel.org \
    --cc=markmc@redhat.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).