All of lore.kernel.org
 help / color / mirror / Atom feed
From: Raphael Norwitz <raphael.norwitz@nutanix.com>
To: Daniil Tatianin <d-tatianin@yandex-team.ru>
Cc: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"yc-core@yandex-team.ru" <yc-core@yandex-team.ru>,
	"mst@redhat.com" <mst@redhat.com>,
	"stefanha@redhat.com" <stefanha@redhat.com>,
	Raphael Norwitz <raphael.norwitz@nutanix.com>,
	"kwolf@redhat.com" <kwolf@redhat.com>,
	"qemu-block@nongnu.org" <qemu-block@nongnu.org>,
	"jasowang@redhat.com" <jasowang@redhat.com>
Subject: Re: [PATCH v2 1/8] virtio: introduce VirtIOConfigSizeParams & virtio_get_config_size
Date: Fri, 2 Sep 2022 17:52:07 +0000	[thread overview]
Message-ID: <20220902175112.GA5363@raphael-debian-dev> (raw)
In-Reply-To: <20220826143248.580939-2-d-tatianin@yandex-team.ru>

I feel like it would be easier to review if the first 4 patches were
squashed together, but that’s not a big deal.

For this one:

Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>

On Fri, Aug 26, 2022 at 05:32:41PM +0300, Daniil Tatianin wrote:
> This is the first step towards moving all device config size calculation
> logic into the virtio core code. In particular, this adds a struct that
> contains all the necessary information for common virtio code to be able
> to calculate the final config size for a device. This is expected to be
> used with the new virtio_get_config_size helper, which calculates the
> final length based on the provided host features.
> 
> This builds on top of already existing code like VirtIOFeature and
> virtio_feature_get_config_size(), but adds additional fields, as well as
> sanity checking so that device-specifc code doesn't have to duplicate it.
> 
> An example usage would be:
> 
>     static const VirtIOFeature dev_features[] = {
>         {.flags = 1ULL << FEATURE_1_BIT,
>          .end = endof(struct virtio_dev_config, feature_1)},
>         {.flags = 1ULL << FEATURE_2_BIT,
>          .end = endof(struct virtio_dev_config, feature_2)},
>         {}
>     };
> 
>     static const VirtIOConfigSizeParams dev_cfg_size_params = {
>         .min_size = DEV_BASE_CONFIG_SIZE,
>         .max_size = sizeof(struct virtio_dev_config),
>         .feature_sizes = dev_features
>     };
> 
>     // code inside my_dev_device_realize()
>     size_t config_size = virtio_get_config_size(&dev_cfg_size_params,
>                                                 host_features);
>     virtio_init(vdev, VIRTIO_ID_MYDEV, config_size);
> 
> Currently every device is expected to write its own boilerplate from the
> example above in device_realize(), however, the next step of this
> transition is moving VirtIOConfigSizeParams into VirtioDeviceClass,
> so that it can be done automatically by the virtio initialization code.
> 
> Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
> ---
>  hw/virtio/virtio.c         | 17 +++++++++++++++++
>  include/hw/virtio/virtio.h |  9 +++++++++
>  2 files changed, 26 insertions(+)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 5d607aeaa0..8518382025 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -3014,6 +3014,23 @@ size_t virtio_feature_get_config_size(const VirtIOFeature *feature_sizes,
>      return config_size;
>  }
>  
> +size_t virtio_get_config_size(const VirtIOConfigSizeParams *params,
> +                              uint64_t host_features)
> +{
> +    size_t config_size = params->min_size;
> +    const VirtIOFeature *feature_sizes = params->feature_sizes;
> +    size_t i;
> +
> +    for (i = 0; feature_sizes[i].flags != 0; i++) {
> +        if (host_features & feature_sizes[i].flags) {
> +            config_size = MAX(feature_sizes[i].end, config_size);
> +        }
> +    }
> +
> +    assert(config_size <= params->max_size);
> +    return config_size;
> +}
> +
>  int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
>  {
>      int i, ret;
> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> index db1c0ddf6b..1991c58d9b 100644
> --- a/include/hw/virtio/virtio.h
> +++ b/include/hw/virtio/virtio.h
> @@ -44,6 +44,15 @@ typedef struct VirtIOFeature {
>      size_t end;
>  } VirtIOFeature;
>  
> +typedef struct VirtIOConfigSizeParams {
> +    size_t min_size;
> +    size_t max_size;
> +    const VirtIOFeature *feature_sizes;
> +} VirtIOConfigSizeParams;
> +
> +size_t virtio_get_config_size(const VirtIOConfigSizeParams *params,
> +                              uint64_t host_features);
> +
>  size_t virtio_feature_get_config_size(const VirtIOFeature *features,
>                                        uint64_t host_features);
>  
> -- 
> 2.25.1
> 

  reply	other threads:[~2022-09-02 18:07 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-26 14:32 [PATCH v2 0/8] vhost-user-blk: dynamically resize config space based on features Daniil Tatianin
2022-08-26 14:32 ` [PATCH v2 1/8] virtio: introduce VirtIOConfigSizeParams & virtio_get_config_size Daniil Tatianin
2022-09-02 17:52   ` Raphael Norwitz [this message]
2022-09-02 22:12     ` Daniil Tatianin
2022-09-04 22:40       ` Raphael Norwitz
2022-08-26 14:32 ` [PATCH v2 2/8] virtio-blk: utilize " Daniil Tatianin
2022-09-02 17:52   ` Raphael Norwitz
2022-08-26 14:32 ` [PATCH v2 3/8] virtio-net: " Daniil Tatianin
2022-09-02 17:54   ` Raphael Norwitz
2022-09-02 22:24     ` Daniil Tatianin
2022-08-26 14:32 ` [PATCH v2 4/8] virtio: remove the virtio_feature_get_config_size helper Daniil Tatianin
2022-09-02 17:55   ` Raphael Norwitz
2022-08-26 14:32 ` [PATCH v2 5/8] virtio-blk: move config size params to virtio-blk-common Daniil Tatianin
2022-09-02 17:57   ` Raphael Norwitz
2022-09-02 22:15     ` Daniil Tatianin
2022-08-26 14:32 ` [PATCH v2 6/8] vhost-user-blk: make it possible to disable write-zeroes/discard Daniil Tatianin
2022-09-02 17:57   ` Raphael Norwitz
2022-08-26 14:32 ` [PATCH v2 7/8] vhost-user-blk: make 'config_wce' part of 'host_features' Daniil Tatianin
2022-09-02 17:58   ` Raphael Norwitz
2022-08-26 14:32 ` [PATCH v2 8/8] vhost-user-blk: dynamically resize config space based on features Daniil Tatianin
2022-09-02 17:59   ` Raphael Norwitz
     [not found] ` <292621662027678@mail.yandex-team.ru>
2022-09-02  3:40   ` [PATCH v2 0/8] " Raphael Norwitz

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=20220902175112.GA5363@raphael-debian-dev \
    --to=raphael.norwitz@nutanix.com \
    --cc=d-tatianin@yandex-team.ru \
    --cc=jasowang@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=yc-core@yandex-team.ru \
    /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.