qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

vfio-ccw: Refactor ccw irq handler

Make it easier to add new ones in the future.

Signed-off-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Message-Id: <20200505125757.98209-5-farman@linux.ibm.com>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>

authored by

Eric Farman and committed by
Cornelia Huck
690e29b9 46ea3841

+42 -16
+42 -16
hw/vfio/ccw.c
··· 324 324 css_inject_io_interrupt(sch); 325 325 } 326 326 327 - static void vfio_ccw_register_io_notifier(VFIOCCWDevice *vcdev, Error **errp) 327 + static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev, 328 + unsigned int irq, 329 + Error **errp) 328 330 { 329 331 VFIODevice *vdev = &vcdev->vdev; 330 332 struct vfio_irq_info *irq_info; 331 333 size_t argsz; 332 334 int fd; 335 + EventNotifier *notifier; 336 + IOHandler *fd_read; 333 337 334 - if (vdev->num_irqs < VFIO_CCW_IO_IRQ_INDEX + 1) { 335 - error_setg(errp, "vfio: unexpected number of io irqs %u", 338 + switch (irq) { 339 + case VFIO_CCW_IO_IRQ_INDEX: 340 + notifier = &vcdev->io_notifier; 341 + fd_read = vfio_ccw_io_notifier_handler; 342 + break; 343 + default: 344 + error_setg(errp, "vfio: Unsupported device irq(%d)", irq); 345 + return; 346 + } 347 + 348 + if (vdev->num_irqs < irq + 1) { 349 + error_setg(errp, "vfio: unexpected number of irqs %u", 336 350 vdev->num_irqs); 337 351 return; 338 352 } 339 353 340 354 argsz = sizeof(*irq_info); 341 355 irq_info = g_malloc0(argsz); 342 - irq_info->index = VFIO_CCW_IO_IRQ_INDEX; 356 + irq_info->index = irq; 343 357 irq_info->argsz = argsz; 344 358 if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO, 345 359 irq_info) < 0 || irq_info->count < 1) { ··· 347 361 goto out_free_info; 348 362 } 349 363 350 - if (event_notifier_init(&vcdev->io_notifier, 0)) { 364 + if (event_notifier_init(notifier, 0)) { 351 365 error_setg_errno(errp, errno, 352 - "vfio: Unable to init event notifier for IO"); 366 + "vfio: Unable to init event notifier for irq (%d)", 367 + irq); 353 368 goto out_free_info; 354 369 } 355 370 356 - fd = event_notifier_get_fd(&vcdev->io_notifier); 357 - qemu_set_fd_handler(fd, vfio_ccw_io_notifier_handler, NULL, vcdev); 371 + fd = event_notifier_get_fd(notifier); 372 + qemu_set_fd_handler(fd, fd_read, NULL, vcdev); 358 373 359 - if (vfio_set_irq_signaling(vdev, VFIO_CCW_IO_IRQ_INDEX, 0, 374 + if (vfio_set_irq_signaling(vdev, irq, 0, 360 375 VFIO_IRQ_SET_ACTION_TRIGGER, fd, errp)) { 361 376 qemu_set_fd_handler(fd, NULL, NULL, vcdev); 362 - event_notifier_cleanup(&vcdev->io_notifier); 377 + event_notifier_cleanup(notifier); 363 378 } 364 379 365 380 out_free_info: 366 381 g_free(irq_info); 367 382 } 368 383 369 - static void vfio_ccw_unregister_io_notifier(VFIOCCWDevice *vcdev) 384 + static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev, 385 + unsigned int irq) 370 386 { 371 387 Error *err = NULL; 388 + EventNotifier *notifier; 372 389 373 - if (vfio_set_irq_signaling(&vcdev->vdev, VFIO_CCW_IO_IRQ_INDEX, 0, 390 + switch (irq) { 391 + case VFIO_CCW_IO_IRQ_INDEX: 392 + notifier = &vcdev->io_notifier; 393 + break; 394 + default: 395 + error_report("vfio: Unsupported device irq(%d)", irq); 396 + return; 397 + } 398 + 399 + if (vfio_set_irq_signaling(&vcdev->vdev, irq, 0, 374 400 VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) { 375 401 error_reportf_err(err, VFIO_MSG_PREFIX, vcdev->vdev.name); 376 402 } 377 403 378 - qemu_set_fd_handler(event_notifier_get_fd(&vcdev->io_notifier), 404 + qemu_set_fd_handler(event_notifier_get_fd(notifier), 379 405 NULL, NULL, vcdev); 380 - event_notifier_cleanup(&vcdev->io_notifier); 406 + event_notifier_cleanup(notifier); 381 407 } 382 408 383 409 static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp) ··· 565 591 goto out_region_err; 566 592 } 567 593 568 - vfio_ccw_register_io_notifier(vcdev, &err); 594 + vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX, &err); 569 595 if (err) { 570 596 goto out_notifier_err; 571 597 } ··· 594 620 S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev); 595 621 VFIOGroup *group = vcdev->vdev.group; 596 622 597 - vfio_ccw_unregister_io_notifier(vcdev); 623 + vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX); 598 624 vfio_ccw_put_region(vcdev); 599 625 vfio_ccw_put_device(vcdev); 600 626 vfio_put_group(group);