Re: [RFC PATCH v1 09/25] hw/xen: Add evtchn operations to allow redirection to internal emulation

2023-03-07 Thread Paul Durrant

On 02/03/2023 15:34, David Woodhouse wrote:

From: David Woodhouse 

The existing implementation calling into the real libxenevtchn moves to
a new file hw/xen/xen-operations.c, and is called via a function table
which in a subsequent commit will also be able to invoke the emulated
event channel support.

Signed-off-by: David Woodhouse 
Signed-off-by: Paul Durrant 
---
  hw/9pfs/xen-9p-backend.c|  24 +++---
  hw/i386/xen/xen-hvm.c   |  27 ---
  hw/xen/meson.build  |   1 +
  hw/xen/xen-bus.c|  22 +++---
  hw/xen/xen-legacy-backend.c |   8 +-
  hw/xen/xen-operations.c |  71 +
  hw/xen/xen_pvdev.c  |  12 +--
  include/hw/xen/xen-bus.h|   1 +
  include/hw/xen/xen-legacy-backend.h |   1 +
  include/hw/xen/xen_backend_ops.h| 118 
  include/hw/xen/xen_common.h |  12 ---
  include/hw/xen/xen_pvdev.h  |   1 +
  softmmu/globals.c   |   1 +
  13 files changed, 242 insertions(+), 57 deletions(-)
  create mode 100644 hw/xen/xen-operations.c
  create mode 100644 include/hw/xen/xen_backend_ops.h



Reviewed-by: Paul Durrant 




[RFC PATCH v1 09/25] hw/xen: Add evtchn operations to allow redirection to internal emulation

2023-03-02 Thread David Woodhouse
From: David Woodhouse 

The existing implementation calling into the real libxenevtchn moves to
a new file hw/xen/xen-operations.c, and is called via a function table
which in a subsequent commit will also be able to invoke the emulated
event channel support.

Signed-off-by: David Woodhouse 
Signed-off-by: Paul Durrant 
---
 hw/9pfs/xen-9p-backend.c|  24 +++---
 hw/i386/xen/xen-hvm.c   |  27 ---
 hw/xen/meson.build  |   1 +
 hw/xen/xen-bus.c|  22 +++---
 hw/xen/xen-legacy-backend.c |   8 +-
 hw/xen/xen-operations.c |  71 +
 hw/xen/xen_pvdev.c  |  12 +--
 include/hw/xen/xen-bus.h|   1 +
 include/hw/xen/xen-legacy-backend.h |   1 +
 include/hw/xen/xen_backend_ops.h| 118 
 include/hw/xen/xen_common.h |  12 ---
 include/hw/xen/xen_pvdev.h  |   1 +
 softmmu/globals.c   |   1 +
 13 files changed, 242 insertions(+), 57 deletions(-)
 create mode 100644 hw/xen/xen-operations.c
 create mode 100644 include/hw/xen/xen_backend_ops.h

diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c
index 65c4979c3c..864bdaf952 100644
--- a/hw/9pfs/xen-9p-backend.c
+++ b/hw/9pfs/xen-9p-backend.c
@@ -241,7 +241,7 @@ static void xen_9pfs_push_and_notify(V9fsPDU *pdu)
 xen_wmb();
 
 ring->inprogress = false;
-xenevtchn_notify(ring->evtchndev, ring->local_port);
+qemu_xen_evtchn_notify(ring->evtchndev, ring->local_port);
 
 qemu_bh_schedule(ring->bh);
 }
@@ -324,8 +324,8 @@ static void xen_9pfs_evtchn_event(void *opaque)
 Xen9pfsRing *ring = opaque;
 evtchn_port_t port;
 
-port = xenevtchn_pending(ring->evtchndev);
-xenevtchn_unmask(ring->evtchndev, port);
+port = qemu_xen_evtchn_pending(ring->evtchndev);
+qemu_xen_evtchn_unmask(ring->evtchndev, port);
 
 qemu_bh_schedule(ring->bh);
 }
@@ -337,10 +337,10 @@ static void xen_9pfs_disconnect(struct XenLegacyDevice 
*xendev)
 
 for (i = 0; i < xen_9pdev->num_rings; i++) {
 if (xen_9pdev->rings[i].evtchndev != NULL) {
-qemu_set_fd_handler(xenevtchn_fd(xen_9pdev->rings[i].evtchndev),
-NULL, NULL, NULL);
-xenevtchn_unbind(xen_9pdev->rings[i].evtchndev,
- xen_9pdev->rings[i].local_port);
+
qemu_set_fd_handler(qemu_xen_evtchn_fd(xen_9pdev->rings[i].evtchndev),
+NULL, NULL, NULL);
+qemu_xen_evtchn_unbind(xen_9pdev->rings[i].evtchndev,
+   xen_9pdev->rings[i].local_port);
 xen_9pdev->rings[i].evtchndev = NULL;
 }
 }
@@ -447,12 +447,12 @@ static int xen_9pfs_connect(struct XenLegacyDevice 
*xendev)
 xen_9pdev->rings[i].inprogress = false;
 
 
-xen_9pdev->rings[i].evtchndev = xenevtchn_open(NULL, 0);
+xen_9pdev->rings[i].evtchndev = qemu_xen_evtchn_open();
 if (xen_9pdev->rings[i].evtchndev == NULL) {
 goto out;
 }
-qemu_set_cloexec(xenevtchn_fd(xen_9pdev->rings[i].evtchndev));
-xen_9pdev->rings[i].local_port = xenevtchn_bind_interdomain
+qemu_set_cloexec(qemu_xen_evtchn_fd(xen_9pdev->rings[i].evtchndev));
+xen_9pdev->rings[i].local_port = qemu_xen_evtchn_bind_interdomain
 (xen_9pdev->rings[i].evtchndev,
  xendev->dom,
  xen_9pdev->rings[i].evtchn);
@@ -463,8 +463,8 @@ static int xen_9pfs_connect(struct XenLegacyDevice *xendev)
 goto out;
 }
 xen_pv_printf(xendev, 2, "bind evtchn port %d\n", xendev->local_port);
-qemu_set_fd_handler(xenevtchn_fd(xen_9pdev->rings[i].evtchndev),
-xen_9pfs_evtchn_event, NULL, &xen_9pdev->rings[i]);
+qemu_set_fd_handler(qemu_xen_evtchn_fd(xen_9pdev->rings[i].evtchndev),
+xen_9pfs_evtchn_event, NULL, &xen_9pdev->rings[i]);
 }
 
 xen_9pdev->security_model = xenstore_read_be_str(xendev, "security_model");
diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c
index e5a1dd19f4..cb1d24f592 100644
--- a/hw/i386/xen/xen-hvm.c
+++ b/hw/i386/xen/xen-hvm.c
@@ -761,7 +761,7 @@ static ioreq_t *cpu_get_ioreq(XenIOState *state)
 int i;
 evtchn_port_t port;
 
-port = xenevtchn_pending(state->xce_handle);
+port = qemu_xen_evtchn_pending(state->xce_handle);
 if (port == state->bufioreq_local_port) {
 timer_mod(state->buffered_io_timer,
 BUFFER_IO_MAX_DELAY + qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
@@ -780,7 +780,7 @@ static ioreq_t *cpu_get_ioreq(XenIOState *state)
 }
 
 /* unmask the wanted port again */
-xenevtchn_unmask(state->xce_handle, port);
+qemu_xen_evtchn_unmask(state->xce_handle, port);
 
 /* get the io packet from shared memory */
 st