All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Sameeh Jubran <sameeh@daynix.com>, qemu-devel@nongnu.org
Cc: Yan Vugenfirer <yan@daynix.com>
Subject: Re: [Qemu-devel] [RFC 5/6] virtio-net: steering mode: Implement rss support
Date: Mon, 3 Sep 2018 11:48:17 +0800	[thread overview]
Message-ID: <1e0d0354-072f-73b1-ed7e-f88f4ff17659@redhat.com> (raw)
In-Reply-To: <20180830142708.14311-6-sameeh@daynix.com>



On 2018年08月30日 22:27, Sameeh Jubran wrote:
> From: Sameeh Jubran <sjubran@redhat.com>
>
> Signed-off-by: Sameeh Jubran <sjubran@redhat.com>
> ---
>   hw/net/virtio-net.c | 122 ++++++++++++++++++++++++++++++++++++++++++++--------
>   1 file changed, 105 insertions(+), 17 deletions(-)
>
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index e7c4ce6f66..4a52a6a1d0 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -972,41 +972,129 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8_t cmd,
>       return VIRTIO_NET_OK;
>   }
>   
> -static int virtio_net_ctrl_steering_mode(VirtIONet *n, uint8_t cmd,
> +
> +static int virtio_net_ctrl_sm_rss(VirtIONet *n, uint32_t cmd,
>                                   struct iovec *iov, unsigned int iov_cnt,
>                                   struct iovec *iov_in, unsigned int iov_cnt_in,
> -        size_t *size_in)
> +                                size_t *size_in)
> +{
> +    size_t s;
> +    uint32_t supported_hash_function = 0;
> +
> +    switch (cmd) {
> +    case VIRTIO_NET_SM_CTRL_RSS_GET_SUPPORTED_FUNCTIONS:
> +        supported_hash_function |= RSS_HASH_FUNCTION_TOEPLITZ;
> +        if (!size_in) {
> +            return VIRTIO_NET_ERR;
> +        }
> +        s = iov_from_buf(iov_in, iov_cnt_in, 0,
> +        &supported_hash_function,
> +        supported_hash_function);

Indentation looks wrong.

> +        if (s != sizeof(n->supported_modes) ||
> +        !size_in) {
> +            return VIRTIO_NET_ERR;
> +        }
> +        *size_in = s;
> +        break;
> +    case VIRTIO_NET_SM_CTRL_RSS_SET:
> +        if (!n->rss_conf) {
> +            n->rss_conf = g_malloc0(
> +                    sizeof(struct virtio_net_rss_conf));
> +        } else if (iov == NULL || iov_cnt == 0) {
> +            g_free(n->rss_conf->ptrs.hash_key);
> +            g_free(n->rss_conf->ptrs.indirection_table);
> +            g_free(n->rss_conf);
> +            return VIRTIO_NET_OK;
> +        }
> +        s = iov_to_buf(iov, iov_cnt, 0, n->rss_conf,
> +                sizeof(struct virtio_net_rss_conf) -
> +                sizeof(struct virtio_net_rss_conf_ptrs));
> +
> +        if (s != sizeof(struct virtio_net_rss_conf) -
> +                sizeof(struct virtio_net_rss_conf_ptrs)) {
> +            return VIRTIO_NET_ERR;
> +        }
> +        n->rss_conf->ptrs.hash_key = g_malloc0(sizeof(uint8_t) *
> +                n->rss_conf->hash_key_length);

What happens if n->rss_conf != 0 && iov != NULL? Looks like a guest 
trigger-able OOM?

Btw e.g "conf_ptrs" sounds misleading, why not just embed hash key and 
indirection table pointers directly in rss_conf structure itself?

> +        s = iov_to_buf(iov, iov_cnt, 0, n->rss_conf->ptrs.hash_key,
> +                sizeof(uint8_t) * n->rss_conf->hash_key_length);
> +        if (s != sizeof(uint8_t) * n->rss_conf->hash_key_length) {
> +            g_free(n->rss_conf->ptrs.hash_key);
> +            return VIRTIO_NET_ERR;
> +        }
> +        n->rss_conf->ptrs.indirection_table
> +            = g_malloc0(sizeof(uint32_t) *
> +                    n->rss_conf->indirection_table_length);
> +        s = iov_to_buf(iov, iov_cnt, 0,
> +                n->rss_conf->ptrs.indirection_table, sizeof(uint32_t) *
> +                n->rss_conf->indirection_table_length);
> +        if (s != sizeof(uint32_t) *
> +                n->rss_conf->indirection_table_length) {
> +            g_free(n->rss_conf->ptrs.hash_key);
> +            g_free(n->rss_conf->ptrs.indirection_table);
> +            return VIRTIO_NET_ERR;
> +        }
> +        /* do bpf magic */
> +        break;
> +    default:
> +        return VIRTIO_NET_ERR;
> +    }
> +
> +    return VIRTIO_NET_OK;
> +}
> +
> +static int virtio_net_ctrl_steering_mode(VirtIONet *n, uint8_t cmd,
> +                                struct iovec *iov, unsigned int iov_cnt,
> +                                struct iovec *iov_in, unsigned int iov_in_cnt,
> +                                size_t *size_in)
>   {
>       size_t s;
>       struct virtio_net_steering_mode sm;
> +    int status = 0;
> +    size_t size_in_cmd = 0;
>   
>       switch (cmd) {
>       case VIRTIO_NET_CTRL_SM_GET_SUPPORTED_MODES:
>           if (!size_in) {
>               return VIRTIO_NET_ERR;
>           }
> -                  s = iov_from_buf(iov_in, iov_cnt_in, 0,
> -          &n->supported_modes, sizeof(n->supported_modes));
> +        n->supported_modes.steering_modes |= STEERING_MODE_RSS |
> +            STEERING_MODE_AUTO;

We should have a property for RSS instead of hard coding it here.

Thanks

> +        s = iov_from_buf(iov_in, iov_in_cnt, 0,
> +        &n->supported_modes,
> +        sizeof(n->supported_modes));
>           if (s != sizeof(n->supported_modes) ||
> -          !size_in) {
> +        !size_in) {
>               return VIRTIO_NET_ERR;
>           }
> -                  *size_in = s;
> -      break;
> +        *size_in = s;
> +         break;
>       case VIRTIO_NET_CTRL_SM_CONTROL:
> -        s = iov_to_buf(iov, iov_cnt, 0, &sm, sizeof(sm) -
> -                sizeof(union command_data));
> -        if (s != sizeof(sm) - sizeof(union command_data)) {
> +        s = iov_to_buf(iov, iov_cnt, 0, &sm, sizeof(sm));
> +        if (s != sizeof(sm)) {
> +            return VIRTIO_NET_ERR;
> +        }
> +        iov_discard_front(&iov, &iov_cnt, sizeof(sm));
> +        /* TODO handle the case where we change mode, call the old */
> +        /* mode function with null ptrs  should do the trick of */
> +        /* freeing any resources */
> +        switch (sm.steering_mode) {
> +        case STEERING_MODE_AUTO:
> +                    break;
> +        case STEERING_MODE_RSS:
> +            status = virtio_net_ctrl_sm_rss(n, sm.command,
> +                   iov, iov_cnt, iov_in, iov_in_cnt,
> +                   &size_in_cmd);
> +            if (status == VIRTIO_NET_OK && size_in_cmd > 0) {
> +                *size_in += size_in_cmd;
> +            }
> +            break;
> +        default:
>               return VIRTIO_NET_ERR;
>           }
> -        /* switch (cmd)
> -             {
> -                dafault:
> -                return VIRTIO_NET_ERR;
> -         } */
> -      break;
> +        break;
>       default:
> -                return VIRTIO_NET_ERR;
> +        return VIRTIO_NET_ERR;
>       }
>   
>       return VIRTIO_NET_OK;

  reply	other threads:[~2018-09-03  3:48 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-30 14:27 [Qemu-devel] [RFC 0/6] Virtio-net: Support RSS Sameeh Jubran
2018-08-30 14:27 ` [Qemu-devel] [RFC 1/6] Add bpf support to qemu Sameeh Jubran
2018-09-03 11:59   ` Daniel P. Berrangé
2018-09-03 12:18     ` Sameeh Jubran
2018-09-03 12:24     ` Peter Maydell
2018-09-03 12:28       ` Sameeh Jubran
2018-09-03 12:29       ` Daniel P. Berrangé
2018-08-30 14:27 ` [Qemu-devel] [RFC 2/6] tap: Add support for bpf ioctls Sameeh Jubran
2018-08-30 15:21   ` Eric Blake
2018-09-03 11:34     ` Sameeh Jubran
2018-09-03  3:24   ` Jason Wang
2018-09-03 11:33     ` Sameeh Jubran
2018-08-30 14:27 ` [Qemu-devel] [RFC 3/6] vhost-net: Expose vhost_net_get_fd Sameeh Jubran
2018-09-03  3:24   ` Jason Wang
2018-09-03 11:56     ` Sameeh Jubran
2018-08-30 14:27 ` [Qemu-devel] [RFC 4/6] virtio-net: implement steering mode feature Sameeh Jubran
2018-09-03  3:34   ` Jason Wang
2018-09-03 12:51     ` Sameeh Jubran
2018-08-30 14:27 ` [Qemu-devel] [RFC 5/6] virtio-net: steering mode: Implement rss support Sameeh Jubran
2018-09-03  3:48   ` Jason Wang [this message]
2018-09-03 11:45     ` Sameeh Jubran
2018-08-30 14:27 ` [Qemu-devel] [RFC 6/6] virtio-net: rss: Add bpf filter Sameeh Jubran
2018-09-03  4:12   ` Jason Wang
2018-09-03 13:16     ` Sameeh Jubran
2018-09-04  3:03       ` Jason Wang
2018-09-03 11:54   ` Daniel P. Berrangé
2018-09-03 12:35     ` Sameeh Jubran
2018-09-03 12:49       ` Daniel P. Berrangé
2018-09-04  3:07     ` Jason Wang
2018-09-04  8:14       ` Daniel P. Berrangé
2018-09-06  5:26         ` Jason Wang
2018-10-04 13:30           ` Daniel P. Berrangé
2018-09-03 12:11   ` Daniel P. Berrangé
2018-09-04 20:11   ` Eric Blake
2018-09-03  4:15 ` [Qemu-devel] [RFC 0/6] Virtio-net: Support RSS Jason Wang
2018-09-03  9:52   ` Sameeh Jubran

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=1e0d0354-072f-73b1-ed7e-f88f4ff17659@redhat.com \
    --to=jasowang@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sameeh@daynix.com \
    --cc=yan@daynix.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.