Instead of a get/set for config values, just request the address of the config region, and handle that by simply reading directly from that region. Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx> --- tools/kvm/include/kvm/virtio.h | 3 +-- tools/kvm/virtio/9p.c | 12 ++---------- tools/kvm/virtio/balloon.c | 12 ++---------- tools/kvm/virtio/blk.c | 12 ++---------- tools/kvm/virtio/console.c | 12 ++---------- tools/kvm/virtio/mmio.c | 6 +++--- tools/kvm/virtio/net.c | 12 ++---------- tools/kvm/virtio/pci.c | 4 ++-- tools/kvm/virtio/rng.c | 8 +------- tools/kvm/virtio/scsi.c | 12 ++---------- 10 files changed, 19 insertions(+), 74 deletions(-) diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h index 71b6bad..5dc2544 100644 --- a/tools/kvm/include/kvm/virtio.h +++ b/tools/kvm/include/kvm/virtio.h @@ -78,8 +78,7 @@ struct virtio_device { }; struct virtio_ops { - void (*set_config)(struct kvm *kvm, void *dev, u8 data, u32 offset); - u8 (*get_config)(struct kvm *kvm, void *dev, u32 offset); + u8 *(*get_config)(struct kvm *kvm, void *dev); u32 (*get_host_features)(struct kvm *kvm, void *dev); void (*set_guest_features)(struct kvm *kvm, void *dev, u32 features); int (*init_vq)(struct kvm *kvm, void *dev, u32 vq, u32 pfn); diff --git a/tools/kvm/virtio/9p.c b/tools/kvm/virtio/9p.c index d668106..c3f5280 100644 --- a/tools/kvm/virtio/9p.c +++ b/tools/kvm/virtio/9p.c @@ -1250,18 +1250,11 @@ static void virtio_p9_do_io(struct kvm *kvm, void *param) } } -static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset) +static u8 *get_config(struct kvm *kvm, void *dev) { struct p9_dev *p9dev = dev; - ((u8 *)(p9dev->config))[offset] = data; -} - -static u8 get_config(struct kvm *kvm, void *dev, u32 offset) -{ - struct p9_dev *p9dev = dev; - - return ((u8 *)(p9dev->config))[offset]; + return ((u8 *)(p9dev->config)); } static u32 get_host_features(struct kvm *kvm, void *dev) @@ -1323,7 +1316,6 @@ static int get_size_vq(struct kvm *kvm, void *dev, u32 vq) } struct virtio_ops p9_dev_virtio_ops = (struct virtio_ops) { - .set_config = set_config, .get_config = get_config, .get_host_features = get_host_features, .set_guest_features = set_guest_features, diff --git a/tools/kvm/virtio/balloon.c b/tools/kvm/virtio/balloon.c index a838ff4..ea64fd4 100644 --- a/tools/kvm/virtio/balloon.c +++ b/tools/kvm/virtio/balloon.c @@ -175,18 +175,11 @@ static void handle_mem(int fd, u32 type, u32 len, u8 *msg) bdev.vdev.ops->signal_config(kvm, &bdev.vdev); } -static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset) +static u8 *get_config(struct kvm *kvm, void *dev) { struct bln_dev *bdev = dev; - ((u8 *)(&bdev->config))[offset] = data; -} - -static u8 get_config(struct kvm *kvm, void *dev, u32 offset) -{ - struct bln_dev *bdev = dev; - - return ((u8 *)(&bdev->config))[offset]; + return ((u8 *)(&bdev->config)); } static u32 get_host_features(struct kvm *kvm, void *dev) @@ -241,7 +234,6 @@ static int get_size_vq(struct kvm *kvm, void *dev, u32 vq) } struct virtio_ops bln_dev_virtio_ops = (struct virtio_ops) { - .set_config = set_config, .get_config = get_config, .get_host_features = get_host_features, .set_guest_features = set_guest_features, diff --git a/tools/kvm/virtio/blk.c b/tools/kvm/virtio/blk.c index d988365..98f17a2 100644 --- a/tools/kvm/virtio/blk.c +++ b/tools/kvm/virtio/blk.c @@ -134,18 +134,11 @@ static void virtio_blk_do_io(struct kvm *kvm, struct virt_queue *vq, struct blk_ } } -static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset) +static u8 *get_config(struct kvm *kvm, void *dev) { struct blk_dev *bdev = dev; - ((u8 *)(&bdev->blk_config))[offset] = data; -} - -static u8 get_config(struct kvm *kvm, void *dev, u32 offset) -{ - struct blk_dev *bdev = dev; - - return ((u8 *)(&bdev->blk_config))[offset]; + return ((u8 *)(&bdev->blk_config)); } static u32 get_host_features(struct kvm *kvm, void *dev) @@ -230,7 +223,6 @@ static int set_size_vq(struct kvm *kvm, void *dev, u32 vq, int size) } static struct virtio_ops blk_dev_virtio_ops = (struct virtio_ops) { - .set_config = set_config, .get_config = get_config, .get_host_features = get_host_features, .set_guest_features = set_guest_features, diff --git a/tools/kvm/virtio/console.c b/tools/kvm/virtio/console.c index 4bb1365..e925a54 100644 --- a/tools/kvm/virtio/console.c +++ b/tools/kvm/virtio/console.c @@ -105,18 +105,11 @@ static void virtio_console_handle_callback(struct kvm *kvm, void *param) } -static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset) +static u8 *get_config(struct kvm *kvm, void *dev) { struct con_dev *cdev = dev; - ((u8 *)(&cdev->config))[offset] = data; -} - -static u8 get_config(struct kvm *kvm, void *dev, u32 offset) -{ - struct con_dev *cdev = dev; - - return ((u8 *)(&cdev->config))[offset]; + return ((u8 *)(&cdev->config)); } static u32 get_host_features(struct kvm *kvm, void *dev) @@ -174,7 +167,6 @@ static int get_size_vq(struct kvm *kvm, void *dev, u32 vq) } static struct virtio_ops con_dev_virtio_ops = (struct virtio_ops) { - .set_config = set_config, .get_config = get_config, .get_host_features = get_host_features, .set_guest_features = set_guest_features, diff --git a/tools/kvm/virtio/mmio.c b/tools/kvm/virtio/mmio.c index 1cf0815..5971922 100644 --- a/tools/kvm/virtio/mmio.c +++ b/tools/kvm/virtio/mmio.c @@ -94,11 +94,11 @@ static void virtio_mmio_device_specific(u64 addr, u8 *data, u32 len, for (i = 0; i < len; i++) { if (is_write) - vdev->ops->set_config(vmmio->kvm, vmmio->dev, - *(u8 *)data + i, addr + i); + vdev->ops->get_config(vmmio->kvm, vmmio->dev)[addr + i] = + *(u8 *)data + i; else data[i] = vdev->ops->get_config(vmmio->kvm, - vmmio->dev, addr + i); + vmmio->dev)[addr + i]; } } diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c index 8f3735b..25bc3a4 100644 --- a/tools/kvm/virtio/net.c +++ b/tools/kvm/virtio/net.c @@ -290,18 +290,11 @@ static struct net_dev_operations uip_ops = { .tx = uip_ops_tx, }; -static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset) +static u8 *get_config(struct kvm *kvm, void *dev) { struct net_dev *ndev = dev; - ((u8 *)(&ndev->config))[offset] = data; -} - -static u8 get_config(struct kvm *kvm, void *dev, u32 offset) -{ - struct net_dev *ndev = dev; - - return ((u8 *)(&ndev->config))[offset]; + return ((u8 *)(&ndev->config)); } static u32 get_host_features(struct kvm *kvm, void *dev) @@ -448,7 +441,6 @@ static int set_size_vq(struct kvm *kvm, void *dev, u32 vq, int size) } static struct virtio_ops net_dev_virtio_ops = (struct virtio_ops) { - .set_config = set_config, .get_config = get_config, .get_host_features = get_host_features, .set_guest_features = set_guest_features, diff --git a/tools/kvm/virtio/pci.c b/tools/kvm/virtio/pci.c index 4dc7916..81f95ae 100644 --- a/tools/kvm/virtio/pci.c +++ b/tools/kvm/virtio/pci.c @@ -86,7 +86,7 @@ static bool virtio_pci__specific_io_in(struct kvm *kvm, struct virtio_device *vd } else if (type == VIRTIO_PCI_O_CONFIG) { u8 cfg; - cfg = vdev->ops->get_config(kvm, vpci->dev, config_offset); + cfg = vdev->ops->get_config(kvm, vpci->dev)[config_offset]; ioport__write8(data, cfg); return true; } @@ -164,7 +164,7 @@ static bool virtio_pci__specific_io_out(struct kvm *kvm, struct virtio_device *v return true; } else if (type == VIRTIO_PCI_O_CONFIG) { - vdev->ops->set_config(kvm, vpci->dev, *(u8 *)data, config_offset); + vdev->ops->get_config(kvm, vpci->dev)[config_offset] = *(u8 *)data; return true; } diff --git a/tools/kvm/virtio/rng.c b/tools/kvm/virtio/rng.c index 5aa632d..2b1ab39 100644 --- a/tools/kvm/virtio/rng.c +++ b/tools/kvm/virtio/rng.c @@ -41,12 +41,7 @@ struct rng_dev { static LIST_HEAD(rdevs); static int compat_id = -1; -static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset) -{ - /* Unused */ -} - -static u8 get_config(struct kvm *kvm, void *dev, u32 offset) +static u8 *get_config(struct kvm *kvm, void *dev) { /* Unused */ return 0; @@ -138,7 +133,6 @@ static int get_size_vq(struct kvm *kvm, void *dev, u32 vq) } static struct virtio_ops rng_dev_virtio_ops = (struct virtio_ops) { - .set_config = set_config, .get_config = get_config, .get_host_features = get_host_features, .set_guest_features = set_guest_features, diff --git a/tools/kvm/virtio/scsi.c b/tools/kvm/virtio/scsi.c index 8276fb0..c445f08 100644 --- a/tools/kvm/virtio/scsi.c +++ b/tools/kvm/virtio/scsi.c @@ -29,18 +29,11 @@ struct scsi_dev { struct kvm *kvm; }; -static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset) +static u8 *get_config(struct kvm *kvm, void *dev) { struct scsi_dev *sdev = dev; - ((u8 *)(&sdev->config))[offset] = data; -} - -static u8 get_config(struct kvm *kvm, void *dev, u32 offset) -{ - struct scsi_dev *sdev = dev; - - return ((u8 *)(&sdev->config))[offset]; + return ((u8 *)(&sdev->config)); } static u32 get_host_features(struct kvm *kvm, void *dev) @@ -174,7 +167,6 @@ static int set_size_vq(struct kvm *kvm, void *dev, u32 vq, int size) } static struct virtio_ops scsi_dev_virtio_ops = (struct virtio_ops) { - .set_config = set_config, .get_config = get_config, .get_host_features = get_host_features, .set_guest_features = set_guest_features, -- 1.7.12 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html