From: Farhan Ali <alifm@xxxxxxxxxxxxx> Use an IRQ to notify userspace that there is a CRW pending in the region, related to path-availability changes on the passthrough subchannel. Signed-off-by: Farhan Ali <alifm@xxxxxxxxxxxxx> Signed-off-by: Eric Farman <farman@xxxxxxxxxxxxx> --- Notes: v0->v1: [EF] - Place the non-refactoring changes from the previous patch here - Clean up checkpatch (whitespace) errors - s/chp_crw/crw/ - Move acquire/release of io_mutex in vfio_ccw_crw_region_read() into patch that introduces that region - Remove duplicate include from vfio_ccw_drv.c - Reorder include in vfio_ccw_private.h drivers/s390/cio/vfio_ccw_drv.c | 27 +++++++++++++++++++++++++++ drivers/s390/cio/vfio_ccw_ops.c | 4 ++++ drivers/s390/cio/vfio_ccw_private.h | 4 ++++ include/uapi/linux/vfio.h | 1 + 4 files changed, 36 insertions(+) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index d1b9020d037b..ab20c32e5319 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -108,6 +108,22 @@ static void vfio_ccw_sch_io_todo(struct work_struct *work) eventfd_signal(private->io_trigger, 1); } +static void vfio_ccw_crw_todo(struct work_struct *work) +{ + struct vfio_ccw_private *private; + struct crw *crw; + + private = container_of(work, struct vfio_ccw_private, crw_work); + crw = &private->crw; + + mutex_lock(&private->io_mutex); + memcpy(&private->crw_region->crw0, crw, sizeof(*crw)); + mutex_unlock(&private->io_mutex); + + if (private->crw_trigger) + eventfd_signal(private->crw_trigger, 1); +} + /* * Css driver callbacks */ @@ -187,6 +203,7 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) goto out_free; INIT_WORK(&private->io_work, vfio_ccw_sch_io_todo); + INIT_WORK(&private->crw_work, vfio_ccw_crw_todo); atomic_set(&private->avail, 1); private->state = VFIO_CCW_STATE_STANDBY; @@ -303,6 +320,11 @@ static int vfio_ccw_chp_event(struct subchannel *sch, case CHP_OFFLINE: /* Path is gone */ cio_cancel_halt_clear(sch, &retry); + private->crw.rsc = CRW_RSC_CPATH; + private->crw.rsid = 0x0 | (link->chpid.cssid << 8) | + link->chpid.id; + private->crw.erc = CRW_ERC_PERRN; + queue_work(vfio_ccw_work_q, &private->crw_work); break; case CHP_VARY_ON: /* Path logically turned on */ @@ -312,6 +334,11 @@ static int vfio_ccw_chp_event(struct subchannel *sch, case CHP_ONLINE: /* Path became available */ sch->lpm |= mask & sch->opm; + private->crw.rsc = CRW_RSC_CPATH; + private->crw.rsid = 0x0 | (link->chpid.cssid << 8) | + link->chpid.id; + private->crw.erc = CRW_ERC_INIT; + queue_work(vfio_ccw_work_q, &private->crw_work); break; } diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index f3033f8fc96d..8b3ed5b45277 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -393,6 +393,7 @@ static int vfio_ccw_mdev_get_irq_info(struct vfio_irq_info *info) { switch (info->index) { case VFIO_CCW_IO_IRQ_INDEX: + case VFIO_CCW_CRW_IRQ_INDEX: info->count = 1; info->flags = VFIO_IRQ_INFO_EVENTFD; break; @@ -420,6 +421,9 @@ static int vfio_ccw_mdev_set_irqs(struct mdev_device *mdev, case VFIO_CCW_IO_IRQ_INDEX: ctx = &private->io_trigger; break; + case VFIO_CCW_CRW_IRQ_INDEX: + ctx = &private->crw_trigger; + break; default: return -EINVAL; } diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h index 8289b6850e59..558c658f3583 100644 --- a/drivers/s390/cio/vfio_ccw_private.h +++ b/drivers/s390/cio/vfio_ccw_private.h @@ -17,6 +17,7 @@ #include <linux/eventfd.h> #include <linux/workqueue.h> #include <linux/vfio_ccw.h> +#include <asm/crw.h> #include <asm/debug.h> #include "css.h" @@ -98,9 +99,12 @@ struct vfio_ccw_private { struct channel_program cp; struct irb irb; union scsw scsw; + struct crw crw; struct eventfd_ctx *io_trigger; + struct eventfd_ctx *crw_trigger; struct work_struct io_work; + struct work_struct crw_work; } __aligned(8); extern int vfio_ccw_mdev_reg(struct subchannel *sch); diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 5024636d7615..1bdf32772545 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -579,6 +579,7 @@ enum { enum { VFIO_CCW_IO_IRQ_INDEX, + VFIO_CCW_CRW_IRQ_INDEX, VFIO_CCW_NUM_IRQS }; -- 2.17.1