dm: virtio: remove hv_caps from virtio_ops

currently, each virtio device has their own virtio_ops implementation.
Take virtio-blk for example:

static struct virtio_ops virtio_blk_ops = {
        "virtio_blk",
        1,
        sizeof(struct virtio_blk_config),
        virtio_blk_reset,
        virtio_blk_notify,
        virtio_blk_cfgread,
        virtio_blk_cfgwrite,
        NULL,
        NULL,
        VIRTIO_BLK_S_HOSTCAPS,
};

If start DM with two virtio-blk, this global variable will be
assigined to two virtio-blk instances. Changing hv_caps for one
instance will affect others. But different instances may need
different capabilities.

To support this requirement, we suggest to move hv_caps to
virtio_base structure, and each instance can return their own
capabilities.

Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
Conghui Chen 2018-07-27 09:50:55 +00:00 committed by lijinxia
parent a2b299179d
commit f4fcf5d6eb
11 changed files with 12 additions and 18 deletions

View File

@ -381,7 +381,7 @@ vq_getchain(struct virtio_vq_info *vq, uint16_t *pidx,
if ((vdir->flags & VRING_DESC_F_INDIRECT) == 0) { if ((vdir->flags & VRING_DESC_F_INDIRECT) == 0) {
_vq_record(i, vdir, ctx, iov, n_iov, flags); _vq_record(i, vdir, ctx, iov, n_iov, flags);
i++; i++;
} else if ((base->vops->hv_caps & } else if ((base->device_caps &
VIRTIO_RING_F_INDIRECT_DESC) == 0) { VIRTIO_RING_F_INDIRECT_DESC) == 0) {
fprintf(stderr, fprintf(stderr,
"%s: descriptor has forbidden INDIRECT flag, " "%s: descriptor has forbidden INDIRECT flag, "
@ -696,7 +696,7 @@ bad:
switch (offset) { switch (offset) {
case VIRTIO_CR_HOSTCAP: case VIRTIO_CR_HOSTCAP:
value = vops->hv_caps; value = base->device_caps;
break; break;
case VIRTIO_CR_GUESTCAP: case VIRTIO_CR_GUESTCAP:
value = base->negotiated_caps; value = base->negotiated_caps;
@ -813,7 +813,7 @@ bad:
switch (offset) { switch (offset) {
case VIRTIO_CR_GUESTCAP: case VIRTIO_CR_GUESTCAP:
base->negotiated_caps = value & vops->hv_caps; base->negotiated_caps = value & base->device_caps;
if (vops->apply_features) if (vops->apply_features)
(*vops->apply_features)(DEV_STRUCT(base), (*vops->apply_features)(DEV_STRUCT(base),
base->negotiated_caps); base->negotiated_caps);
@ -1020,7 +1020,7 @@ virtio_set_modern_bar(struct virtio_base *base, bool use_notify_pio)
vops = base->vops; vops = base->vops;
if (!vops || (vops->hv_caps & VIRTIO_F_VERSION_1) == 0) if (!vops || (base->device_caps & VIRTIO_F_VERSION_1) == 0)
return -1; return -1;
if (use_notify_pio) if (use_notify_pio)
@ -1111,9 +1111,9 @@ virtio_common_cfg_read(struct pci_vdev *dev, uint64_t offset, int size)
break; break;
case VIRTIO_COMMON_DF: case VIRTIO_COMMON_DF:
if (base->device_feature_select == 0) if (base->device_feature_select == 0)
value = vops->hv_caps & 0xffffffff; value = base->device_caps & 0xffffffff;
else if (base->device_feature_select == 1) else if (base->device_feature_select == 1)
value = (vops->hv_caps >> 32) & 0xffffffff; value = (base->device_caps >> 32) & 0xffffffff;
else /* present 0, see 4.1.4.3.1 */ else /* present 0, see 4.1.4.3.1 */
value = 0; value = 0;
break; break;
@ -1240,7 +1240,7 @@ virtio_common_cfg_write(struct pci_vdev *dev, uint64_t offset, int size,
value &= 0xffffffff; value &= 0xffffffff;
base->negotiated_caps = base->negotiated_caps =
(value << (base->driver_feature_select * 32)) (value << (base->driver_feature_select * 32))
& vops->hv_caps; & base->device_caps;
if (vops->apply_features) if (vops->apply_features)
(*vops->apply_features)(DEV_STRUCT(base), (*vops->apply_features)(DEV_STRUCT(base),
base->negotiated_caps); base->negotiated_caps);

View File

@ -88,7 +88,6 @@ static struct virtio_ops virtio_audio_ops_k = {
NULL, /* write virtio config */ NULL, /* write virtio config */
NULL, /* apply negotiated features */ NULL, /* apply negotiated features */
virtio_audio_k_set_status,/* called on guest set status */ virtio_audio_k_set_status,/* called on guest set status */
0, /* our capabilities */
}; };
static int static int

View File

@ -143,7 +143,6 @@ static struct virtio_ops virtio_blk_ops = {
virtio_blk_cfgwrite, /* write PCI config */ virtio_blk_cfgwrite, /* write PCI config */
NULL, /* apply negotiated features */ NULL, /* apply negotiated features */
NULL, /* called on guest set status */ NULL, /* called on guest set status */
VIRTIO_BLK_S_HOSTCAPS, /* our capabilities */
}; };
static void static void
@ -339,6 +338,7 @@ virtio_blk_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
/* init virtio struct and virtqueues */ /* init virtio struct and virtqueues */
virtio_linkup(&blk->base, &virtio_blk_ops, blk, dev, &blk->vq); virtio_linkup(&blk->base, &virtio_blk_ops, blk, dev, &blk->vq);
blk->base.mtx = &blk->mtx; blk->base.mtx = &blk->mtx;
blk->base.device_caps = VIRTIO_BLK_S_HOSTCAPS;
blk->vq.qsize = VIRTIO_BLK_RINGSZ; blk->vq.qsize = VIRTIO_BLK_RINGSZ;
/* blk->vq.vq_notify = we have no per-queue notify */ /* blk->vq.vq_notify = we have no per-queue notify */

View File

@ -164,7 +164,6 @@ static struct virtio_ops virtio_console_ops = {
virtio_console_cfgwrite, /* write virtio config */ virtio_console_cfgwrite, /* write virtio config */
virtio_console_neg_features, /* apply negotiated features */ virtio_console_neg_features, /* apply negotiated features */
NULL, /* called on guest set status */ NULL, /* called on guest set status */
VIRTIO_CONSOLE_S_HOSTCAPS, /* our capabilities */
}; };
static const char *virtio_console_be_table[VIRTIO_CONSOLE_BE_MAX] = { static const char *virtio_console_be_table[VIRTIO_CONSOLE_BE_MAX] = {
@ -837,6 +836,7 @@ virtio_console_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
virtio_linkup(&console->base, &virtio_console_ops, console, dev, virtio_linkup(&console->base, &virtio_console_ops, console, dev,
console->queues); console->queues);
console->base.mtx = &console->mtx; console->base.mtx = &console->mtx;
console->base.device_caps = VIRTIO_CONSOLE_S_HOSTCAPS;
for (i = 0; i < VIRTIO_CONSOLE_MAXQ; i++) { for (i = 0; i < VIRTIO_CONSOLE_MAXQ; i++) {
console->queues[i].qsize = VIRTIO_CONSOLE_RINGSZ; console->queues[i].qsize = VIRTIO_CONSOLE_RINGSZ;

View File

@ -151,7 +151,6 @@ static struct virtio_ops virtio_heci_ops = {
virtio_heci_cfgwrite, /* write virtio config */ virtio_heci_cfgwrite, /* write virtio config */
NULL, /* apply negotiated features */ NULL, /* apply negotiated features */
NULL, /* called on guest set status */ NULL, /* called on guest set status */
0, /* our capabilities */
}; };
static void static void

View File

@ -84,7 +84,6 @@ static struct virtio_ops virtio_hyper_dmabuf_ops_k = {
NULL, /* write virtio config */ NULL, /* write virtio config */
NULL, /* apply negotiated features */ NULL, /* apply negotiated features */
virtio_hyper_dmabuf_set_status, /* called on guest set status */ virtio_hyper_dmabuf_set_status, /* called on guest set status */
0, /* our capabilities */
}; };
static int static int

View File

@ -143,7 +143,6 @@ static struct virtio_ops virtio_input_ops = {
virtio_input_cfgwrite, /* write virtio config */ virtio_input_cfgwrite, /* write virtio config */
virtio_input_neg_features, /* apply negotiated features */ virtio_input_neg_features, /* apply negotiated features */
virtio_input_set_status, /* called on guest set status */ virtio_input_set_status, /* called on guest set status */
VIRTIO_INPUT_S_HOSTCAPS, /* our capabilities */
}; };
static void static void
@ -606,6 +605,7 @@ virtio_input_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
virtio_linkup(&vi->base, &virtio_input_ops, vi, dev, vi->queues); virtio_linkup(&vi->base, &virtio_input_ops, vi, dev, vi->queues);
vi->base.mtx = &vi->mtx; vi->base.mtx = &vi->mtx;
vi->base.device_caps = VIRTIO_INPUT_S_HOSTCAPS;
vi->queues[VIRTIO_INPUT_EVENT_QUEUE].qsize = VIRTIO_INPUT_RINGSZ; vi->queues[VIRTIO_INPUT_EVENT_QUEUE].qsize = VIRTIO_INPUT_RINGSZ;
vi->queues[VIRTIO_INPUT_EVENT_QUEUE].notify = vi->queues[VIRTIO_INPUT_EVENT_QUEUE].notify =

View File

@ -168,7 +168,6 @@ static struct virtio_ops virtio_net_ops = {
virtio_net_cfgwrite, /* write PCI config */ virtio_net_cfgwrite, /* write PCI config */
virtio_net_neg_features, /* apply negotiated features */ virtio_net_neg_features, /* apply negotiated features */
NULL, /* called on guest set status */ NULL, /* called on guest set status */
VIRTIO_NET_S_HOSTCAPS, /* our capabilities */
}; };
static struct ether_addr * static struct ether_addr *
@ -914,6 +913,7 @@ virtio_net_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
virtio_linkup(&net->base, &virtio_net_ops, net, dev, net->queues); virtio_linkup(&net->base, &virtio_net_ops, net, dev, net->queues);
net->base.mtx = &net->mtx; net->base.mtx = &net->mtx;
net->base.device_caps = VIRTIO_NET_S_HOSTCAPS;
net->queues[VIRTIO_NET_RXQ].qsize = VIRTIO_NET_RINGSZ; net->queues[VIRTIO_NET_RXQ].qsize = VIRTIO_NET_RINGSZ;
net->queues[VIRTIO_NET_RXQ].notify = virtio_net_ping_rxq; net->queues[VIRTIO_NET_RXQ].notify = virtio_net_ping_rxq;

View File

@ -97,7 +97,6 @@ static struct virtio_ops virtio_rnd_ops = {
NULL, /* write virtio config */ NULL, /* write virtio config */
NULL, /* apply negotiated features */ NULL, /* apply negotiated features */
NULL, /* called on guest set status */ NULL, /* called on guest set status */
0, /* our capabilities */
}; };
/* VBS-K virtio_ops */ /* VBS-K virtio_ops */
@ -113,7 +112,6 @@ static struct virtio_ops virtio_rnd_ops_k = {
NULL, /* write virtio config */ NULL, /* write virtio config */
NULL, /* apply negotiated features */ NULL, /* apply negotiated features */
virtio_rnd_k_set_status,/* called on guest set status */ virtio_rnd_k_set_status,/* called on guest set status */
0, /* our capabilities */
}; };
/* VBS-K interface function implementations */ /* VBS-K interface function implementations */

View File

@ -600,7 +600,6 @@ static struct virtio_ops virtio_rpmb_ops = {
NULL, /* write virtio config */ NULL, /* write virtio config */
NULL, /* apply negotiated features */ NULL, /* apply negotiated features */
NULL, /* called on guest set status */ NULL, /* called on guest set status */
0, /* our capabilities */
}; };
static int static int

View File

@ -507,6 +507,7 @@ struct virtio_base {
pthread_mutex_t *mtx; /**< POSIX mutex, if any */ pthread_mutex_t *mtx; /**< POSIX mutex, if any */
struct pci_vdev *dev; /**< PCI device instance */ struct pci_vdev *dev; /**< PCI device instance */
uint64_t negotiated_caps; /**< negotiated capabilities */ uint64_t negotiated_caps; /**< negotiated capabilities */
uint64_t device_caps; /**< device capabilities */
struct virtio_vq_info *queues; /**< one per nvq */ struct virtio_vq_info *queues; /**< one per nvq */
int curq; /**< current queue */ int curq; /**< current queue */
uint8_t status; /**< value from last status write */ uint8_t status; /**< value from last status write */
@ -552,7 +553,6 @@ struct virtio_ops {
/**< to apply negotiated features */ /**< to apply negotiated features */
void (*set_status)(void *, uint64_t); void (*set_status)(void *, uint64_t);
/**< called to set device status */ /**< called to set device status */
uint64_t hv_caps; /**< hypervisor-provided capabilities */
}; };
#define VQ_ALLOC 0x01 /* set once we have a pfn */ #define VQ_ALLOC 0x01 /* set once we have a pfn */