virtio-ccw: fix + notifiers
The following changes since commit baf8673ca802cb3ea2cdbe94813441d23bde223b:
Merge remote-tracking branch 'stefanha/block' into staging (2013-06-24 14:33:17 -0500)
are available in the git repository at:
git://github.com/cohuck/qemu virtio-ccw-upstr
for you to fetch changes up to 320ce8503baf081725f74514d73d7bd65071a45e:
virtio-ccw: Wire up guest and host notifies. (2013-06-25 17:11:12 +0200)
----------------------------------------------------------------
Christian Borntraeger (1):
s390/virtio-ccw: Fix virtio reset
Cornelia Huck (2):
virtio-ccw: Wire up ioeventfd.
virtio-ccw: Wire up guest and host notifies.
hw/s390x/css.c | 2 +- hw/s390x/css.h | 1 + hw/s390x/virtio-ccw.c | 207 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw.h | 8 ++ target-s390x/cpu.h | 16 ++++ target-s390x/kvm.c | 19 +++++ 6 files changed, 252 insertions(+), 1 deletion(-)
Signature · 1 line
1.7.9.5
[Qemu-devel] [PULL 1/3] s390/virtio-ccw: Fix virtio reset
From: Christian Borntraeger <[email protected]>
On virtio reset we must reset the indicator to avoid stale interrupts, e.g. after a reset.
--- hw/s390x/virtio-ccw.c | 2 ++ 1 file changed, 2 insertions(+)
hw/s390x/virtio-ccw.c +2 -0
@@ -803,6 +803,8 @@ static void virtio_ccw_reset(DeviceState *d)virtio_reset (dev->vdev);css_reset_sch (dev->sch); + dev->indicators =0 ; + dev->indicators2 =0 ; }/**************** Virtio-ccw Bus Device Descriptions *******************/
Signature · 1 line
1.7.9.5
[Qemu-devel] [PULL 2/3] virtio-ccw: Wire up ioeventfd.
In reply to Cornelia HuckOn hosts that support ioeventfd, make use of it for host-to-guest notifications via diagnose 500.
--- hw/s390x/css.c | 2 +- hw/s390x/css.h | 1 + hw/s390x/virtio-ccw.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw.h | 7 +++ target-s390x/cpu.h | 16 +++++++ target-s390x/kvm.c | 19 ++++++++ 6 files changed, 161 insertions(+), 1 deletion(-)
hw/s390x/css.c +1 -1
@@ -68,7 +68,7 @@ int css_create_css_image(uint8_t cssid, bool default_image)return 0 ; } -static uint16_t css_build_subchannel_id (SubchDev *sch) +uint16_t css_build_subchannel_id (SubchDev *sch) {if (channel_subsys->max_cssid >0 ) {return (sch->cssid <<8 ) | (1 <<3 ) | (sch->ssid <<1 ) |1 ;
hw/s390x/css.h +1 -0
@@ -90,6 +90,7 @@ bool css_devno_used(uint8_t cssid, uint8_t ssid, uint16_t devno);void css_subch_assign (uint8_t cssid,uint8_t ssid,uint16_t schid,uint16_t devno,SubchDev *sch);void css_sch_build_virtual_schib (SubchDev *sch,uint8_t chpid,uint8_t type); +uint16_t css_build_subchannel_id (SubchDev *sch);void css_reset (void );void css_reset_sch (SubchDev *sch);void css_queue_crw (uint8_t rsc,uint8_t erc,int chain,uint16_t rsid);
hw/s390x/virtio-ccw.c +117 -0
199 lines not on this page · raw message
hw/s390x/virtio-ccw.h +7 -0
@@ -69,6 +69,11 @@ typedef struct VirtIOCCWDeviceClass {/* Change here if we want to support more feature bits. */ #define VIRTIO_CCW_FEATURE_SIZE 1 +/* Performance improves when virtqueue kick processing is decoupled from the +* vcpu thread using ioeventfd for some devices. */ +#define VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT 1 +#define VIRTIO_CCW_FLAG_USE_IOEVENTFD (1 << VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT) +struct VirtioCcwDevice {DeviceState parent_obj;SubchDev *sch;
@@ -76,6 +81,8 @@ struct VirtioCcwDevice {char *bus_id;uint32_t host_features[VIRTIO_CCW_FEATURE_SIZE ];VirtioBusState bus; +bool ioeventfd_started; +uint32_t flags;/* Guest provided values: */ hwaddr indicators;hwaddr indicators2;
target-s390x/cpu.h +16 -0
@@ -1081,6 +1081,7 @@ void kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id,void kvm_s390_crw_mchk (S390CPU *cpu);void kvm_s390_enable_css_support (S390CPU *cpu);int kvm_s390_get_registers_partial (CPUState *cpu); +int kvm_s390_assign_subch_ioeventfd (int fd,uint32_t sch,int vq,bool assign);#else static inline void kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id,
@@ -1099,6 +1100,11 @@ static inline int kvm_s390_get_registers_partial(CPUState *cpu) {return -ENOSYS ; } +static inline int kvm_s390_assign_subch_ioeventfd (int fd,uint32_t sch,int vq, +bool assign) +{ +return -ENOSYS ; +}#endif static inline void s390_io_interrupt(S390CPU *cpu,
@@ -1125,4 +1131,14 @@ static inline void s390_crw_mchk(S390CPU *cpu) } } +static inline int s390_assign_subch_ioeventfd (int fd,uint32_t sch_id,int vq, +bool assign) +{ +if (kvm_enabled ()) { +return kvm_s390_assign_subch_ioeventfd (fd, sch_id, vq, assign); + }else { +return -ENOSYS ; + } +} +#endif
target-s390x/kvm.c +19 -0
@@ -932,3 +932,22 @@ void kvm_s390_enable_css_support(S390CPU *cpu)void kvm_arch_init_irq_routing (KVMState *s) { } + +int kvm_s390_assign_subch_ioeventfd (int fd,uint32_t sch,int vq,bool assign) +{ +struct kvm_ioeventfd kick = { + .flags =KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY | +KVM_IOEVENTFD_FLAG_DATAMATCH , + .fd = fd, + .datamatch = vq, + .addr = sch, + .len =8 , + }; +if (!kvm_check_extension (kvm_state,KVM_CAP_IOEVENTFD )) { +return -ENOSYS ; + } +if (!assign) { + kick.flags |=KVM_IOEVENTFD_FLAG_DEASSIGN ; + } +return kvm_vm_ioctl (kvm_state,KVM_IOEVENTFD , &kick); +}
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PULL 2/3] virtio-ccw: Wire up ioeventfd.
Am 25.06.2013 18:25, schrieb Cornelia Huck:
Quoted 4 lines
On hosts that support ioeventfd, make use of it for host-to-guest notifications via diagnose 500.
Signed-off-by Cornelia Huck <[email protected]>
Quoted 8 lines
--- hw/s390x/css.c | 2 +- hw/s390x/css.h | 1 + hw/s390x/virtio-ccw.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw.h | 7 +++ target-s390x/cpu.h | 16 +++++++ target-s390x/kvm.c | 19 ++++++++ 6 files changed, 161 insertions(+), 1 deletion(-)
This patch was recently committed to git master and breaks builds:
It uses event_notifier_get_fd which is only available for POSIX hosts. W32/W64 uses event_notifier_get_handle.
Output from broken build:
LINK s390x-softmmu/qemu-system-s390xw.exehw/s390x/virtio-ccw.o: In function `virtio_ccw_set_guest2host_notifier':hw/s390x/virtio-ccw.c:92: undefined reference to event_notifier_get_fd' hw/s390x/virtio-ccw.c:82: undefined reference to event_notifier_get_fd'
Regards
Stefan Weil
Re: [Qemu-devel] [PULL 2/3] virtio-ccw: Wire up ioeventfd.
Il 27/06/2013 20:28, Stefan Weil ha scritto:
Quoted 19 lines
Am 25.06.2013 18:25, schrieb Cornelia Huck:
Quoted 4 lines
On hosts that support ioeventfd, make use of it for host-to-guest notifications via diagnose 500.
Signed-off-by Cornelia Huck <[email protected]>Quoted 8 lines
--- hw/s390x/css.c | 2 +- hw/s390x/css.h | 1 + hw/s390x/virtio-ccw.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw.h | 7 +++ target-s390x/cpu.h | 16 +++++++ target-s390x/kvm.c | 19 ++++++++ 6 files changed, 161 insertions(+), 1 deletion(-)This patch was recently committed to git master and breaks builds:
It uses
event_notifier_get_fdwhich is only available for POSIX hosts. W32/W64 usesevent_notifier_get_handle.
Quoted 6 lines
Output from broken build:
LINK s390x-softmmu/qemu-system-s390xw.exe
hw/s390x/virtio-ccw.o: In function `virtio_ccw_set_guest2host_notifier':hw/s390x/virtio-ccw.c:92: undefined reference toevent_notifier_get_fd' hw/s390x/virtio-ccw.c:82: undefined reference toevent_notifier_get_fd'
The solution is simply to pass the EventNotifier to s390_assign_subch_ioeventfd (as we do for the MemoryListener eventfd_{add,del} callbacks, for example).
Paolo
PATCH 1/1 virtio-ccw: fix build breakage on windows
event_notifier_get_fd() is not available on windows hosts. Fix this by moving the calls to event_notifier_get_fd() to the kvm code.
--- hw/s390x/virtio-ccw.c | 6 ++---- target-s390x/cpu.h | 11 +++++++---- target-s390x/kvm.c | 5 +++-- 3 files changed, 12 insertions(+), 10 deletions(-)
hw/s390x/virtio-ccw.c +2 -4
@@ -79,8 +79,7 @@ static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice *dev, int n,return r; }virtio_queue_set_host_notifier_fd_handler (vq, true, set_handler); - r =s390_assign_subch_ioeventfd (event_notifier_get_fd (notifier), sch_id, - n, assign); + r =s390_assign_subch_ioeventfd (notifier, sch_id, n, assign);if (r <0 ) {error_report ("%s: unable to assign ioeventfd: %d" , __func__, r);virtio_queue_set_host_notifier_fd_handler (vq, false, false);
@@ -89,8 +88,7 @@ static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice *dev, int n, } }else {virtio_queue_set_host_notifier_fd_handler (vq, false, false); -s390_assign_subch_ioeventfd (event_notifier_get_fd (notifier), sch_id, - n, assign); +s390_assign_subch_ioeventfd (notifier, sch_id, n, assign);event_notifier_cleanup (notifier); }return r;
target-s390x/cpu.h +7 -4
@@ -1081,7 +1081,8 @@ void kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id,void kvm_s390_crw_mchk (S390CPU *cpu);void kvm_s390_enable_css_support (S390CPU *cpu);int kvm_s390_get_registers_partial (CPUState *cpu); -int kvm_s390_assign_subch_ioeventfd (int fd,uint32_t sch,int vq,bool assign); +int kvm_s390_assign_subch_ioeventfd (EventNotifier *notifier,uint32_t sch, +int vq,bool assign);#else static inline void kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id,
@@ -1100,7 +1101,8 @@ static inline int kvm_s390_get_registers_partial(CPUState *cpu) {return -ENOSYS ; } -static inline int kvm_s390_assign_subch_ioeventfd (int fd,uint32_t sch,int vq, +static inline int kvm_s390_assign_subch_ioeventfd (EventNotifier *notifier, +uint32_t sch,int vq,bool assign) {return -ENOSYS ;
@@ -1131,11 +1133,12 @@ static inline void s390_crw_mchk(S390CPU *cpu) } } -static inline int s390_assign_subch_ioeventfd (int fd,uint32_t sch_id,int vq, +static inline int s390_assign_subch_ioeventfd (EventNotifier *notifier, +uint32_t sch_id,int vq,bool assign) {if (kvm_enabled ()) { -return kvm_s390_assign_subch_ioeventfd (fd, sch_id, vq, assign); +return kvm_s390_assign_subch_ioeventfd (notifier, sch_id, vq, assign); }else {return -ENOSYS ; }
target-s390x/kvm.c +3 -2
@@ -933,12 +933,13 @@ void kvm_arch_init_irq_routing(KVMState *s) { } -int kvm_s390_assign_subch_ioeventfd (int fd,uint32_t sch,int vq,bool assign) +int kvm_s390_assign_subch_ioeventfd (EventNotifier *notifier,uint32_t sch, +int vq,bool assign) {struct kvm_ioeventfd kick = { .flags =KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY |KVM_IOEVENTFD_FLAG_DATAMATCH , - .fd = fd, + .fd =event_notifier_get_fd (notifier), .datamatch = vq, .addr = sch, .len =8 ,
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH] virtio-ccw: fix build breakage on windows
Il 28/06/2013 09:47, Cornelia Huck ha scritto:
Quoted 85 lines
event_notifier_get_fd()is not available on windows hosts. Fix this by moving the calls toevent_notifier_get_fd()to the kvm code.Reported-by Stefan Weil <[email protected]>Signed-off-by Cornelia Huck <[email protected]>--- hw/s390x/virtio-ccw.c | 6 ++---- target-s390x/cpu.h | 11 +++++++---- target-s390x/kvm.c | 5 +++-- 3 files changed, 12 insertions(+), 10 deletions(-)hw/s390x/virtio-ccw.c +2
-4@@ -79,8 +79,7 @@ static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice *dev, int n,return r; }virtio_queue_set_host_notifier_fd_handler (vq, true, set_handler); - r =s390_assign_subch_ioeventfd (event_notifier_get_fd (notifier), sch_id, - n, assign); + r =s390_assign_subch_ioeventfd (notifier, sch_id, n, assign);if (r <0 ) {error_report ("%s: unable to assign ioeventfd: %d" , __func__, r);virtio_queue_set_host_notifier_fd_handler (vq, false, false);@@ -89,8 +88,7 @@ static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice *dev, int n, } }else {virtio_queue_set_host_notifier_fd_handler (vq, false, false); -s390_assign_subch_ioeventfd (event_notifier_get_fd (notifier), sch_id, - n, assign); +s390_assign_subch_ioeventfd (notifier, sch_id, n, assign);event_notifier_cleanup (notifier); }return r;target-s390x/cpu.h +7
-4@@ -1081,7 +1081,8 @@ void kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id,void kvm_s390_crw_mchk (S390CPU *cpu);void kvm_s390_enable_css_support (S390CPU *cpu);int kvm_s390_get_registers_partial (CPUState *cpu); -int kvm_s390_assign_subch_ioeventfd (int fd,uint32_t sch,int vq,bool assign); +int kvm_s390_assign_subch_ioeventfd (EventNotifier *notifier,uint32_t sch, +int vq,bool assign);#else static inline void kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id,@@ -1100,7 +1101,8 @@ static inline int kvm_s390_get_registers_partial(CPUState *cpu) {return -ENOSYS ; } -static inline int kvm_s390_assign_subch_ioeventfd (int fd,uint32_t sch,int vq, +static inline int kvm_s390_assign_subch_ioeventfd (EventNotifier *notifier, +uint32_t sch,int vq,bool assign) {return -ENOSYS ;@@ -1131,11 +1133,12 @@ static inline void s390_crw_mchk(S390CPU *cpu) } } -static inline int s390_assign_subch_ioeventfd (int fd,uint32_t sch_id,int vq, +static inline int s390_assign_subch_ioeventfd (EventNotifier *notifier, +uint32_t sch_id,int vq,bool assign) {if (kvm_enabled ()) { -return kvm_s390_assign_subch_ioeventfd (fd, sch_id, vq, assign); +return kvm_s390_assign_subch_ioeventfd (notifier, sch_id, vq, assign); }else {return -ENOSYS ; }target-s390x/kvm.c +1
-1@@ -933,12 +933,13 @@ void kvm_arch_init_irq_routing(KVMState *s) { } -int kvm_s390_assign_subch_ioeventfd (int fd,uint32_t sch,int vq,bool assign) +int kvm_s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch,
target-s390x/kvm.c void kvm_arch_init_irq_routing(KVMState *s) · line 945
Quoted 10 lines
target-s390x/kvm.c +2
-1+ int vq, bool assign) {struct kvm_ioeventfd kick = { .flags =KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY |KVM_IOEVENTFD_FLAG_DATAMATCH , - .fd = fd, + .fd =event_notifier_get_fd (notifier), .datamatch = vq, .addr = sch, .len =8 ,
[Qemu-devel] [PULL 3/3] virtio-ccw: Wire up guest and host notifies.
In reply to Cornelia HuckGuest and host notifiers are needed by vhost. We use ioeventfds for the guest notifiers, but need to fall back on qemu injecting interrupts for the host notifiers.
--- hw/s390x/virtio-ccw.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw.h | 1 + 2 files changed, 89 insertions(+)
hw/s390x/virtio-ccw.c +88 -0
@@ -101,6 +101,7 @@ static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)int n, r;if (!(dev->flags &VIRTIO_CCW_FLAG_USE_IOEVENTFD ) || + dev->ioeventfd_disabled || dev->ioeventfd_started) {return ; }
@@ -911,6 +912,90 @@ static void virtio_ccw_vmstate_change(DeviceState *d, bool running) } } +static bool virtio_ccw_query_guest_notifiers (DeviceState *d) +{ +VirtioCcwDevice *dev =VIRTIO_CCW_DEVICE (d); + +return !!(dev->sch->curr_status.pmcw.flags &PMCW_FLAGS_MASK_ENA ); +} + +static int virtio_ccw_set_host_notifier (DeviceState *d,int n,bool assign) +{ +VirtioCcwDevice *dev =VIRTIO_CCW_DEVICE (d); + +/* Stop using the generic ioeventfd, we are doing eventfd handling +* ourselves below */ + dev->ioeventfd_disabled = assign; +if (assign) { +virtio_ccw_stop_ioeventfd (dev); + } +return virtio_ccw_set_guest2host_notifier (dev, n, assign, false); +} + +static int virtio_ccw_set_guest_notifier (VirtioCcwDevice *dev,int n, +bool assign,bool with_irqfd) +{ +VirtQueue *vq =virtio_get_queue (dev->vdev, n); +EventNotifier *notifier =virtio_queue_get_guest_notifier (vq); +VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (dev->vdev); + +if (assign) { +int r =event_notifier_init (notifier,0 ); + +if (r <0 ) { +return r; + } +virtio_queue_set_guest_notifier_fd_handler (vq, true, with_irqfd); +/* We do not support irqfd for classic I/O interrupts, because the +* classic interrupts are intermixed with the subchannel status, that +* is queried with test subchannel. We want to use vhost, though. +* Lets make sure to have vhost running and wire up the irq fd to +* land in qemu (and only the irq fd) in this code. +*/ +if (k->guest_notifier_mask) { + k->guest_notifier_mask (dev->vdev, n, false); + } +/* get lost events and re-inject */ +if (k->guest_notifier_pending && + k->guest_notifier_pending (dev->vdev, n)) { +event_notifier_set (notifier); + } + }else { +if (k->guest_notifier_mask) { + k->guest_notifier_mask (dev->vdev, n, true); + } +virtio_queue_set_guest_notifier_fd_handler (vq, false, with_irqfd); +event_notifier_cleanup (notifier); + } +return 0 ; +} + +static int virtio_ccw_set_guest_notifiers (DeviceState *d,int nvqs, +bool assigned) +{ +VirtioCcwDevice *dev =VIRTIO_CCW_DEVICE (d); +VirtIODevice *vdev = dev->vdev; +int r, n; + +for (n =0 ; n < nvqs; n++) { +if (!virtio_queue_get_num (vdev, n)) { +break ; + } +/* false -> true, as soon as irqfd works */ + r =virtio_ccw_set_guest_notifier (dev, n, assigned, false); +if (r <0 ) { + goto assign_error; + } + } +return 0 ; + +assign_error: +while (--n >=0 ) { +virtio_ccw_set_guest_notifier (dev, n, !assigned, false); + } +return r; +} +/**************** Virtio-ccw Bus Device Descriptions *******************/ static Property virtio_ccw_net_properties[] = {
@@ -1224,6 +1309,9 @@ static void virtio_ccw_bus_class_init(ObjectClass *klass, void *data) k->notify = virtio_ccw_notify; k->get_features = virtio_ccw_get_features; k->vmstate_change = virtio_ccw_vmstate_change; + k->query_guest_notifiers = virtio_ccw_query_guest_notifiers; + k->set_host_notifier = virtio_ccw_set_host_notifier; + k->set_guest_notifiers = virtio_ccw_set_guest_notifiers; }static const TypeInfo virtio_ccw_bus_info = {
hw/s390x/virtio-ccw.h +1 -0
@@ -82,6 +82,7 @@ struct VirtioCcwDevice {uint32_t host_features[VIRTIO_CCW_FEATURE_SIZE ];VirtioBusState bus;bool ioeventfd_started; +bool ioeventfd_disabled;uint32_t flags;/* Guest provided values: */ hwaddr indicators;
Signature · 1 line
1.7.9.5