* [PATCH 0/2] eventfd: simplify signal helpers
@ 2023-07-13 10:05 Christian Brauner
2023-07-13 10:05 ` [PATCH 1/2] eventfd: simplify eventfd_signal() Christian Brauner
` (2 more replies)
0 siblings, 3 replies; 17+ messages in thread
From: Christian Brauner @ 2023-07-13 10:05 UTC (permalink / raw)
To: linux-fsdevel
Cc: Vitaly Kuznetsov, Sean Christopherson, Paolo Bonzini,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
David Woodhouse, Paul Durrant, Oded Gabbay, Wu Hao, Tom Rix,
Moritz Fischer, Xu Yilun, Zhenyu Wang, Zhi Wang, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Daniel Vetter, Leon Romanovsky, Jason Gunthorpe, Frederic Barrat,
Andrew Donnellan, Arnd Bergmann, Greg Kroah-Hartman, Eric Farman,
Matthew Rosato, Halil Pasic, Vineeth Vijayan,
Peter Oberparleiter, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, Sven Schnelle,
Tony Krowiak, Jason Herne, Harald Freudenberger,
Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Diana Craciun,
Alex Williamson, Eric Auger, Fei Li, Benjamin LaHaise,
Christian Brauner, Johannes Weiner, Michal Hocko, Roman Gushchin,
Shakeel Butt, Muchun Song, Kirti Wankhede, kvm, linux-kernel,
dri-devel, linux-fpga, intel-gvt-dev, intel-gfx, linux-rdma,
linuxppc-dev, linux-s390, linux-usb, virtualization, netdev,
linux-aio, cgroups, linux-mm, Jens Axboe, Pavel Begunkov,
io-uring
Hey everyone,
This simplifies the eventfd_signal() and eventfd_signal_mask() helpers
by removing the count argument which is effectively unused.
---
---
base-commit: 6be357f00aad4189130147fdc6f568cf776a4909
change-id: 20230713-vfs-eventfd-signal-0b0d167ad6ec
^ permalink raw reply [flat|nested] 17+ messages in thread* [PATCH 1/2] eventfd: simplify eventfd_signal() 2023-07-13 10:05 [PATCH 0/2] eventfd: simplify signal helpers Christian Brauner @ 2023-07-13 10:05 ` Christian Brauner 2023-07-13 13:29 ` Anthony Krowiak 2023-07-13 13:34 ` Oded Gabbay 2023-07-13 10:05 ` [PATCH 2/2] eventfd: simplify eventfd_signal_mask() Christian Brauner 2023-07-13 17:10 ` [PATCH 0/2] eventfd: simplify signal helpers Alex Williamson 2 siblings, 2 replies; 17+ messages in thread From: Christian Brauner @ 2023-07-13 10:05 UTC (permalink / raw) To: linux-fsdevel Cc: Vitaly Kuznetsov, Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, David Woodhouse, Paul Durrant, Oded Gabbay, Wu Hao, Tom Rix, Moritz Fischer, Xu Yilun, Zhenyu Wang, Zhi Wang, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Daniel Vetter, Leon Romanovsky, Jason Gunthorpe, Frederic Barrat, Andrew Donnellan, Arnd Bergmann, Greg Kroah-Hartman, Eric Farman, Matthew Rosato, Halil Pasic, Vineeth Vijayan, Peter Oberparleiter, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Tony Krowiak, Jason Herne, Harald Freudenberger, Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Diana Craciun, Alex Williamson, Eric Auger, Fei Li, Benjamin LaHaise, Christian Brauner, Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt, Muchun Song, Kirti Wankhede, kvm, linux-kernel, dri-devel, linux-fpga, intel-gvt-dev, intel-gfx, linux-rdma, linuxppc-dev, linux-s390, linux-usb, virtualization, netdev, linux-aio, cgroups, linux-mm, Jens Axboe, Pavel Begunkov, io-uring Ever since the evenfd type was introduced back in 2007 in commit e1ad7468c77d ("signal/timer/event: eventfd core") the eventfd_signal() function only ever passed 1 as a value for @n. There's no point in keeping that additional argument. Signed-off-by: Christian Brauner <brauner@kernel.org> --- arch/x86/kvm/hyperv.c | 2 +- arch/x86/kvm/xen.c | 2 +- drivers/accel/habanalabs/common/device.c | 2 +- drivers/fpga/dfl.c | 2 +- drivers/gpu/drm/i915/gvt/interrupt.c | 2 +- drivers/infiniband/hw/mlx5/devx.c | 2 +- drivers/misc/ocxl/file.c | 2 +- drivers/s390/cio/vfio_ccw_chp.c | 2 +- drivers/s390/cio/vfio_ccw_drv.c | 4 ++-- drivers/s390/cio/vfio_ccw_ops.c | 6 +++--- drivers/s390/crypto/vfio_ap_ops.c | 2 +- drivers/usb/gadget/function/f_fs.c | 4 ++-- drivers/vdpa/vdpa_user/vduse_dev.c | 6 +++--- drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c | 2 +- drivers/vfio/pci/vfio_pci_core.c | 6 +++--- drivers/vfio/pci/vfio_pci_intrs.c | 12 ++++++------ drivers/vfio/platform/vfio_platform_irq.c | 4 ++-- drivers/vhost/vdpa.c | 4 ++-- drivers/vhost/vhost.c | 10 +++++----- drivers/vhost/vhost.h | 2 +- drivers/virt/acrn/ioeventfd.c | 2 +- fs/aio.c | 2 +- fs/eventfd.c | 9 +++------ include/linux/eventfd.h | 4 ++-- mm/memcontrol.c | 10 +++++----- mm/vmpressure.c | 2 +- samples/vfio-mdev/mtty.c | 4 ++-- virt/kvm/eventfd.c | 4 ++-- 28 files changed, 56 insertions(+), 59 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index b28fd020066f..2f4bd74b482c 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -2387,7 +2387,7 @@ static u16 kvm_hvcall_signal_event(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *h if (!eventfd) return HV_STATUS_INVALID_PORT_ID; - eventfd_signal(eventfd, 1); + eventfd_signal(eventfd); return HV_STATUS_SUCCESS; } diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 40edf4d1974c..a7b62bafd57b 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -2043,7 +2043,7 @@ static bool kvm_xen_hcall_evtchn_send(struct kvm_vcpu *vcpu, u64 param, u64 *r) if (ret < 0 && ret != -ENOTCONN) return false; } else { - eventfd_signal(evtchnfd->deliver.eventfd.ctx, 1); + eventfd_signal(evtchnfd->deliver.eventfd.ctx); } *r = 0; diff --git a/drivers/accel/habanalabs/common/device.c b/drivers/accel/habanalabs/common/device.c index b97339d1f7c6..30357b371d61 100644 --- a/drivers/accel/habanalabs/common/device.c +++ b/drivers/accel/habanalabs/common/device.c @@ -1963,7 +1963,7 @@ static void hl_notifier_event_send(struct hl_notifier_event *notifier_event, u64 notifier_event->events_mask |= event_mask; if (notifier_event->eventfd) - eventfd_signal(notifier_event->eventfd, 1); + eventfd_signal(notifier_event->eventfd); mutex_unlock(¬ifier_event->lock); } diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c index dd7a783d53b5..e73f88050f08 100644 --- a/drivers/fpga/dfl.c +++ b/drivers/fpga/dfl.c @@ -1872,7 +1872,7 @@ static irqreturn_t dfl_irq_handler(int irq, void *arg) { struct eventfd_ctx *trigger = arg; - eventfd_signal(trigger, 1); + eventfd_signal(trigger); return IRQ_HANDLED; } diff --git a/drivers/gpu/drm/i915/gvt/interrupt.c b/drivers/gpu/drm/i915/gvt/interrupt.c index 68eca023bbc6..3d9e09c2add4 100644 --- a/drivers/gpu/drm/i915/gvt/interrupt.c +++ b/drivers/gpu/drm/i915/gvt/interrupt.c @@ -435,7 +435,7 @@ static int inject_virtual_interrupt(struct intel_vgpu *vgpu) */ if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status)) return -ESRCH; - if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger, 1) != 1) + if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger) != 1) return -EFAULT; return 0; } diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c index db5fb196c728..ad50487790ff 100644 --- a/drivers/infiniband/hw/mlx5/devx.c +++ b/drivers/infiniband/hw/mlx5/devx.c @@ -2498,7 +2498,7 @@ static void dispatch_event_fd(struct list_head *fd_list, list_for_each_entry_rcu(item, fd_list, xa_list) { if (item->eventfd) - eventfd_signal(item->eventfd, 1); + eventfd_signal(item->eventfd); else deliver_event(item, data); } diff --git a/drivers/misc/ocxl/file.c b/drivers/misc/ocxl/file.c index 6e63f060e4cc..51766db296ab 100644 --- a/drivers/misc/ocxl/file.c +++ b/drivers/misc/ocxl/file.c @@ -185,7 +185,7 @@ static irqreturn_t irq_handler(void *private) { struct eventfd_ctx *ev_ctx = private; - eventfd_signal(ev_ctx, 1); + eventfd_signal(ev_ctx); return IRQ_HANDLED; } diff --git a/drivers/s390/cio/vfio_ccw_chp.c b/drivers/s390/cio/vfio_ccw_chp.c index d3f3a611f95b..38c176cf6295 100644 --- a/drivers/s390/cio/vfio_ccw_chp.c +++ b/drivers/s390/cio/vfio_ccw_chp.c @@ -115,7 +115,7 @@ static ssize_t vfio_ccw_crw_region_read(struct vfio_ccw_private *private, /* Notify the guest if more CRWs are on our queue */ if (!list_empty(&private->crw) && private->crw_trigger) - eventfd_signal(private->crw_trigger, 1); + eventfd_signal(private->crw_trigger); return ret; } diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index 43601816ea4e..bfb35cfce1ef 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -112,7 +112,7 @@ void vfio_ccw_sch_io_todo(struct work_struct *work) private->state = VFIO_CCW_STATE_IDLE; if (private->io_trigger) - eventfd_signal(private->io_trigger, 1); + eventfd_signal(private->io_trigger); } void vfio_ccw_crw_todo(struct work_struct *work) @@ -122,7 +122,7 @@ void vfio_ccw_crw_todo(struct work_struct *work) private = container_of(work, struct vfio_ccw_private, crw_work); if (!list_empty(&private->crw) && private->crw_trigger) - eventfd_signal(private->crw_trigger, 1); + eventfd_signal(private->crw_trigger); } /* diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index 5b53b94f13c7..3df231f6feda 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -421,7 +421,7 @@ static int vfio_ccw_mdev_set_irqs(struct vfio_ccw_private *private, case VFIO_IRQ_SET_DATA_NONE: { if (*ctx) - eventfd_signal(*ctx, 1); + eventfd_signal(*ctx); return 0; } case VFIO_IRQ_SET_DATA_BOOL: @@ -432,7 +432,7 @@ static int vfio_ccw_mdev_set_irqs(struct vfio_ccw_private *private, return -EFAULT; if (trigger && *ctx) - eventfd_signal(*ctx, 1); + eventfd_signal(*ctx); return 0; } case VFIO_IRQ_SET_DATA_EVENTFD: @@ -612,7 +612,7 @@ static void vfio_ccw_mdev_request(struct vfio_device *vdev, unsigned int count) "Relaying device request to user (#%u)\n", count); - eventfd_signal(private->req_trigger, 1); + eventfd_signal(private->req_trigger); } else if (count == 0) { dev_notice(dev, "No device request channel registered, blocked until released by user\n"); diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index b441745b0418..feb88526ac9d 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -1749,7 +1749,7 @@ static void vfio_ap_mdev_request(struct vfio_device *vdev, unsigned int count) "Relaying device request to user (#%u)\n", count); - eventfd_signal(matrix_mdev->req_trigger, 1); + eventfd_signal(matrix_mdev->req_trigger); } else if (count == 0) { dev_notice(dev, "No device request registered, blocked until released by user\n"); diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index f41a385a5c42..ceb1aad0c5df 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -831,7 +831,7 @@ static void ffs_user_copy_worker(struct work_struct *work) io_data->kiocb->ki_complete(io_data->kiocb, ret); if (io_data->ffs->ffs_eventfd && !kiocb_has_eventfd) - eventfd_signal(io_data->ffs->ffs_eventfd, 1); + eventfd_signal(io_data->ffs->ffs_eventfd); if (io_data->read) kfree(io_data->to_free); @@ -2739,7 +2739,7 @@ static void __ffs_event_add(struct ffs_data *ffs, ffs->ev.types[ffs->ev.count++] = type; wake_up_locked(&ffs->ev.waitq); if (ffs->ffs_eventfd) - eventfd_signal(ffs->ffs_eventfd, 1); + eventfd_signal(ffs->ffs_eventfd); } static void ffs_event_add(struct ffs_data *ffs, diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index dc38ed21319d..99b901a9e638 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -494,7 +494,7 @@ static void vduse_vq_kick(struct vduse_virtqueue *vq) goto unlock; if (vq->kickfd) - eventfd_signal(vq->kickfd, 1); + eventfd_signal(vq->kickfd); else vq->kicked = true; unlock: @@ -912,7 +912,7 @@ static int vduse_kickfd_setup(struct vduse_dev *dev, eventfd_ctx_put(vq->kickfd); vq->kickfd = ctx; if (vq->ready && vq->kicked && vq->kickfd) { - eventfd_signal(vq->kickfd, 1); + eventfd_signal(vq->kickfd); vq->kicked = false; } spin_unlock(&vq->kick_lock); @@ -961,7 +961,7 @@ static bool vduse_vq_signal_irqfd(struct vduse_virtqueue *vq) spin_lock_irq(&vq->irq_lock); if (vq->ready && vq->cb.trigger) { - eventfd_signal(vq->cb.trigger, 1); + eventfd_signal(vq->cb.trigger); signal = true; } spin_unlock_irq(&vq->irq_lock); diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c b/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c index c51229fccbd6..d62fbfff20b8 100644 --- a/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c @@ -54,7 +54,7 @@ static irqreturn_t vfio_fsl_mc_irq_handler(int irq_num, void *arg) { struct vfio_fsl_mc_irq *mc_irq = (struct vfio_fsl_mc_irq *)arg; - eventfd_signal(mc_irq->trigger, 1); + eventfd_signal(mc_irq->trigger); return IRQ_HANDLED; } diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 20d7b69ea6ff..01c8e31db23b 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -441,7 +441,7 @@ static int vfio_pci_core_runtime_resume(struct device *dev) */ down_write(&vdev->memory_lock); if (vdev->pm_wake_eventfd_ctx) { - eventfd_signal(vdev->pm_wake_eventfd_ctx, 1); + eventfd_signal(vdev->pm_wake_eventfd_ctx); __vfio_pci_runtime_pm_exit(vdev); } up_write(&vdev->memory_lock); @@ -1861,7 +1861,7 @@ void vfio_pci_core_request(struct vfio_device *core_vdev, unsigned int count) pci_notice_ratelimited(pdev, "Relaying device request to user (#%u)\n", count); - eventfd_signal(vdev->req_trigger, 1); + eventfd_signal(vdev->req_trigger); } else if (count == 0) { pci_warn(pdev, "No device request channel registered, blocked until released by user\n"); @@ -2280,7 +2280,7 @@ pci_ers_result_t vfio_pci_core_aer_err_detected(struct pci_dev *pdev, mutex_lock(&vdev->igate); if (vdev->err_trigger) - eventfd_signal(vdev->err_trigger, 1); + eventfd_signal(vdev->err_trigger); mutex_unlock(&vdev->igate); diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index cbb4bcbfbf83..237beac83809 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -94,7 +94,7 @@ static void vfio_send_intx_eventfd(void *opaque, void *unused) ctx = vfio_irq_ctx_get(vdev, 0); if (WARN_ON_ONCE(!ctx)) return; - eventfd_signal(ctx->trigger, 1); + eventfd_signal(ctx->trigger); } } @@ -342,7 +342,7 @@ static irqreturn_t vfio_msihandler(int irq, void *arg) { struct eventfd_ctx *trigger = arg; - eventfd_signal(trigger, 1); + eventfd_signal(trigger); return IRQ_HANDLED; } @@ -689,11 +689,11 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev, if (!ctx) continue; if (flags & VFIO_IRQ_SET_DATA_NONE) { - eventfd_signal(ctx->trigger, 1); + eventfd_signal(ctx->trigger); } else if (flags & VFIO_IRQ_SET_DATA_BOOL) { uint8_t *bools = data; if (bools[i - start]) - eventfd_signal(ctx->trigger, 1); + eventfd_signal(ctx->trigger); } } return 0; @@ -707,7 +707,7 @@ static int vfio_pci_set_ctx_trigger_single(struct eventfd_ctx **ctx, if (flags & VFIO_IRQ_SET_DATA_NONE) { if (*ctx) { if (count) { - eventfd_signal(*ctx, 1); + eventfd_signal(*ctx); } else { eventfd_ctx_put(*ctx); *ctx = NULL; @@ -722,7 +722,7 @@ static int vfio_pci_set_ctx_trigger_single(struct eventfd_ctx **ctx, trigger = *(uint8_t *)data; if (trigger && *ctx) - eventfd_signal(*ctx, 1); + eventfd_signal(*ctx); return 0; } else if (flags & VFIO_IRQ_SET_DATA_EVENTFD) { diff --git a/drivers/vfio/platform/vfio_platform_irq.c b/drivers/vfio/platform/vfio_platform_irq.c index 665197caed89..61a1bfb68ac7 100644 --- a/drivers/vfio/platform/vfio_platform_irq.c +++ b/drivers/vfio/platform/vfio_platform_irq.c @@ -155,7 +155,7 @@ static irqreturn_t vfio_automasked_irq_handler(int irq, void *dev_id) spin_unlock_irqrestore(&irq_ctx->lock, flags); if (ret == IRQ_HANDLED) - eventfd_signal(irq_ctx->trigger, 1); + eventfd_signal(irq_ctx->trigger); return ret; } @@ -164,7 +164,7 @@ static irqreturn_t vfio_irq_handler(int irq, void *dev_id) { struct vfio_platform_irq *irq_ctx = dev_id; - eventfd_signal(irq_ctx->trigger, 1); + eventfd_signal(irq_ctx->trigger); return IRQ_HANDLED; } diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index b43e8680eee8..722894a0f124 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -161,7 +161,7 @@ static irqreturn_t vhost_vdpa_virtqueue_cb(void *private) struct eventfd_ctx *call_ctx = vq->call_ctx.ctx; if (call_ctx) - eventfd_signal(call_ctx, 1); + eventfd_signal(call_ctx); return IRQ_HANDLED; } @@ -172,7 +172,7 @@ static irqreturn_t vhost_vdpa_config_cb(void *private) struct eventfd_ctx *config_ctx = v->config_ctx; if (config_ctx) - eventfd_signal(config_ctx, 1); + eventfd_signal(config_ctx); return IRQ_HANDLED; } diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index c71d573f1c94..bee50f153c8e 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2250,7 +2250,7 @@ int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log, len -= l; if (!len) { if (vq->log_ctx) - eventfd_signal(vq->log_ctx, 1); + eventfd_signal(vq->log_ctx); return 0; } } @@ -2273,7 +2273,7 @@ static int vhost_update_used_flags(struct vhost_virtqueue *vq) log_used(vq, (used - (void __user *)vq->used), sizeof vq->used->flags); if (vq->log_ctx) - eventfd_signal(vq->log_ctx, 1); + eventfd_signal(vq->log_ctx); } return 0; } @@ -2291,7 +2291,7 @@ static int vhost_update_avail_event(struct vhost_virtqueue *vq) log_used(vq, (used - (void __user *)vq->used), sizeof *vhost_avail_event(vq)); if (vq->log_ctx) - eventfd_signal(vq->log_ctx, 1); + eventfd_signal(vq->log_ctx); } return 0; } @@ -2717,7 +2717,7 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads, log_used(vq, offsetof(struct vring_used, idx), sizeof vq->used->idx); if (vq->log_ctx) - eventfd_signal(vq->log_ctx, 1); + eventfd_signal(vq->log_ctx); } return r; } @@ -2765,7 +2765,7 @@ void vhost_signal(struct vhost_dev *dev, struct vhost_virtqueue *vq) { /* Signal the Guest tell them we used something up. */ if (vq->call_ctx.ctx && vhost_notify(dev, vq)) - eventfd_signal(vq->call_ctx.ctx, 1); + eventfd_signal(vq->call_ctx.ctx); } EXPORT_SYMBOL_GPL(vhost_signal); diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index f60d5f7bef94..9e942fcda5c3 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -249,7 +249,7 @@ void vhost_iotlb_map_free(struct vhost_iotlb *iotlb, #define vq_err(vq, fmt, ...) do { \ pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \ if ((vq)->error_ctx) \ - eventfd_signal((vq)->error_ctx, 1);\ + eventfd_signal((vq)->error_ctx);\ } while (0) enum { diff --git a/drivers/virt/acrn/ioeventfd.c b/drivers/virt/acrn/ioeventfd.c index ac4037e9f947..4e845c6ca0b5 100644 --- a/drivers/virt/acrn/ioeventfd.c +++ b/drivers/virt/acrn/ioeventfd.c @@ -223,7 +223,7 @@ static int acrn_ioeventfd_handler(struct acrn_ioreq_client *client, mutex_lock(&client->vm->ioeventfds_lock); p = hsm_ioeventfd_match(client->vm, addr, val, size, req->type); if (p) - eventfd_signal(p->eventfd, 1); + eventfd_signal(p->eventfd); mutex_unlock(&client->vm->ioeventfds_lock); return 0; diff --git a/fs/aio.c b/fs/aio.c index 77e33619de40..96cf97b19077 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1166,7 +1166,7 @@ static void aio_complete(struct aio_kiocb *iocb) * from IRQ context. */ if (iocb->ki_eventfd) - eventfd_signal(iocb->ki_eventfd, 1); + eventfd_signal(iocb->ki_eventfd); /* * We have to order our ring_info tail store above and test diff --git a/fs/eventfd.c b/fs/eventfd.c index 33a918f9566c..dc9e01053235 100644 --- a/fs/eventfd.c +++ b/fs/eventfd.c @@ -74,20 +74,17 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask) /** * eventfd_signal - Adds @n to the eventfd counter. * @ctx: [in] Pointer to the eventfd context. - * @n: [in] Value of the counter to be added to the eventfd internal counter. - * The value cannot be negative. * * This function is supposed to be called by the kernel in paths that do not * allow sleeping. In this function we allow the counter to reach the ULLONG_MAX * value, and we signal this as overflow condition by returning a EPOLLERR * to poll(2). * - * Returns the amount by which the counter was incremented. This will be less - * than @n if the counter has overflowed. + * Returns the amount by which the counter was incremented. */ -__u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n) +__u64 eventfd_signal(struct eventfd_ctx *ctx) { - return eventfd_signal_mask(ctx, n, 0); + return eventfd_signal_mask(ctx, 1, 0); } EXPORT_SYMBOL_GPL(eventfd_signal); diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h index b9d83652c097..562089431551 100644 --- a/include/linux/eventfd.h +++ b/include/linux/eventfd.h @@ -35,7 +35,7 @@ void eventfd_ctx_put(struct eventfd_ctx *ctx); struct file *eventfd_fget(int fd); struct eventfd_ctx *eventfd_ctx_fdget(int fd); struct eventfd_ctx *eventfd_ctx_fileget(struct file *file); -__u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n); +__u64 eventfd_signal(struct eventfd_ctx *ctx); __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask); int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t *wait, __u64 *cnt); @@ -58,7 +58,7 @@ static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd) return ERR_PTR(-ENOSYS); } -static inline int eventfd_signal(struct eventfd_ctx *ctx, __u64 n) +static inline int eventfd_signal(struct eventfd_ctx *ctx) { return -ENOSYS; } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index e8ca4bdcb03c..891550f575a1 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4228,7 +4228,7 @@ static void __mem_cgroup_threshold(struct mem_cgroup *memcg, bool swap) * only one element of the array here. */ for (; i >= 0 && unlikely(t->entries[i].threshold > usage); i--) - eventfd_signal(t->entries[i].eventfd, 1); + eventfd_signal(t->entries[i].eventfd); /* i = current_threshold + 1 */ i++; @@ -4240,7 +4240,7 @@ static void __mem_cgroup_threshold(struct mem_cgroup *memcg, bool swap) * only one element of the array here. */ for (; i < t->size && unlikely(t->entries[i].threshold <= usage); i++) - eventfd_signal(t->entries[i].eventfd, 1); + eventfd_signal(t->entries[i].eventfd); /* Update current_threshold */ t->current_threshold = i - 1; @@ -4280,7 +4280,7 @@ static int mem_cgroup_oom_notify_cb(struct mem_cgroup *memcg) spin_lock(&memcg_oom_lock); list_for_each_entry(ev, &memcg->oom_notify, list) - eventfd_signal(ev->eventfd, 1); + eventfd_signal(ev->eventfd); spin_unlock(&memcg_oom_lock); return 0; @@ -4499,7 +4499,7 @@ static int mem_cgroup_oom_register_event(struct mem_cgroup *memcg, /* already in OOM ? */ if (memcg->under_oom) - eventfd_signal(eventfd, 1); + eventfd_signal(eventfd); spin_unlock(&memcg_oom_lock); return 0; @@ -4791,7 +4791,7 @@ static void memcg_event_remove(struct work_struct *work) event->unregister_event(memcg, event->eventfd); /* Notify userspace the event is going away. */ - eventfd_signal(event->eventfd, 1); + eventfd_signal(event->eventfd); eventfd_ctx_put(event->eventfd); kfree(event); diff --git a/mm/vmpressure.c b/mm/vmpressure.c index b52644771cc4..ba4cdef37e42 100644 --- a/mm/vmpressure.c +++ b/mm/vmpressure.c @@ -169,7 +169,7 @@ static bool vmpressure_event(struct vmpressure *vmpr, continue; if (level < ev->level) continue; - eventfd_signal(ev->efd, 1); + eventfd_signal(ev->efd); ret = true; } mutex_unlock(&vmpr->events_lock); diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index a60801fb8660..5edcf8d738de 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c @@ -1028,9 +1028,9 @@ static int mtty_trigger_interrupt(struct mdev_state *mdev_state) } if (mdev_state->irq_index == VFIO_PCI_MSI_IRQ_INDEX) - ret = eventfd_signal(mdev_state->msi_evtfd, 1); + ret = eventfd_signal(mdev_state->msi_evtfd); else - ret = eventfd_signal(mdev_state->intx_evtfd, 1); + ret = eventfd_signal(mdev_state->intx_evtfd); #if defined(DEBUG_INTR) pr_info("Intx triggered\n"); diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c index 89912a17f5d5..c0e230f4c3e9 100644 --- a/virt/kvm/eventfd.c +++ b/virt/kvm/eventfd.c @@ -61,7 +61,7 @@ static void irqfd_resampler_notify(struct kvm_kernel_irqfd_resampler *resampler) list_for_each_entry_srcu(irqfd, &resampler->list, resampler_link, srcu_read_lock_held(&resampler->kvm->irq_srcu)) - eventfd_signal(irqfd->resamplefd, 1); + eventfd_signal(irqfd->resamplefd); } /* @@ -786,7 +786,7 @@ ioeventfd_write(struct kvm_vcpu *vcpu, struct kvm_io_device *this, gpa_t addr, if (!ioeventfd_in_range(p, addr, len, val)) return -EOPNOTSUPP; - eventfd_signal(p->eventfd, 1); + eventfd_signal(p->eventfd); return 0; } -- 2.34.1 ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 1/2] eventfd: simplify eventfd_signal() 2023-07-13 10:05 ` [PATCH 1/2] eventfd: simplify eventfd_signal() Christian Brauner @ 2023-07-13 13:29 ` Anthony Krowiak 2023-07-13 13:34 ` Oded Gabbay 1 sibling, 0 replies; 17+ messages in thread From: Anthony Krowiak @ 2023-07-13 13:29 UTC (permalink / raw) To: Christian Brauner, linux-fsdevel Cc: Vitaly Kuznetsov, Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, David Woodhouse, Paul Durrant, Oded Gabbay, Wu Hao, Tom Rix, Moritz Fischer, Xu Yilun, Zhenyu Wang, Zhi Wang, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Daniel Vetter, Leon Romanovsky, Jason Gunthorpe, Frederic Barrat, Andrew Donnellan, Arnd Bergmann, Greg Kroah-Hartman, Eric Farman, Matthew Rosato, Halil Pasic, Vineeth Vijayan, Peter Oberparleiter, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Jason Herne, Harald Freudenberger, Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Diana Craciun, Alex Williamson, Eric Auger, Fei Li, Benjamin LaHaise, Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt, Muchun Song, Kirti Wankhede, kvm, linux-kernel, dri-devel, linux-fpga, intel-gvt-dev, intel-gfx, linux-rdma, linuxppc-dev, linux-s390, linux-usb, virtualization, netdev, linux-aio, cgroups, linux-mm, Jens Axboe, Pavel Begunkov, io-uring For vfio_ap_ops.c: Reviewed-by: Tony Krowiak <akrowiak@stny.rr.com> On 7/13/23 6:05 AM, Christian Brauner wrote: > Ever since the evenfd type was introduced back in 2007 in commit > e1ad7468c77d ("signal/timer/event: eventfd core") the eventfd_signal() > function only ever passed 1 as a value for @n. There's no point in > keeping that additional argument. > > Signed-off-by: Christian Brauner <brauner@kernel.org> > --- > arch/x86/kvm/hyperv.c | 2 +- > arch/x86/kvm/xen.c | 2 +- > drivers/accel/habanalabs/common/device.c | 2 +- > drivers/fpga/dfl.c | 2 +- > drivers/gpu/drm/i915/gvt/interrupt.c | 2 +- > drivers/infiniband/hw/mlx5/devx.c | 2 +- > drivers/misc/ocxl/file.c | 2 +- > drivers/s390/cio/vfio_ccw_chp.c | 2 +- > drivers/s390/cio/vfio_ccw_drv.c | 4 ++-- > drivers/s390/cio/vfio_ccw_ops.c | 6 +++--- > drivers/s390/crypto/vfio_ap_ops.c | 2 +- > drivers/usb/gadget/function/f_fs.c | 4 ++-- > drivers/vdpa/vdpa_user/vduse_dev.c | 6 +++--- > drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c | 2 +- > drivers/vfio/pci/vfio_pci_core.c | 6 +++--- > drivers/vfio/pci/vfio_pci_intrs.c | 12 ++++++------ > drivers/vfio/platform/vfio_platform_irq.c | 4 ++-- > drivers/vhost/vdpa.c | 4 ++-- > drivers/vhost/vhost.c | 10 +++++----- > drivers/vhost/vhost.h | 2 +- > drivers/virt/acrn/ioeventfd.c | 2 +- > fs/aio.c | 2 +- > fs/eventfd.c | 9 +++------ > include/linux/eventfd.h | 4 ++-- > mm/memcontrol.c | 10 +++++----- > mm/vmpressure.c | 2 +- > samples/vfio-mdev/mtty.c | 4 ++-- > virt/kvm/eventfd.c | 4 ++-- > 28 files changed, 56 insertions(+), 59 deletions(-) > > diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c > index b28fd020066f..2f4bd74b482c 100644 > --- a/arch/x86/kvm/hyperv.c > +++ b/arch/x86/kvm/hyperv.c > @@ -2387,7 +2387,7 @@ static u16 kvm_hvcall_signal_event(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *h > if (!eventfd) > return HV_STATUS_INVALID_PORT_ID; > > - eventfd_signal(eventfd, 1); > + eventfd_signal(eventfd); > return HV_STATUS_SUCCESS; > } > > diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c > index 40edf4d1974c..a7b62bafd57b 100644 > --- a/arch/x86/kvm/xen.c > +++ b/arch/x86/kvm/xen.c > @@ -2043,7 +2043,7 @@ static bool kvm_xen_hcall_evtchn_send(struct kvm_vcpu *vcpu, u64 param, u64 *r) > if (ret < 0 && ret != -ENOTCONN) > return false; > } else { > - eventfd_signal(evtchnfd->deliver.eventfd.ctx, 1); > + eventfd_signal(evtchnfd->deliver.eventfd.ctx); > } > > *r = 0; > diff --git a/drivers/accel/habanalabs/common/device.c b/drivers/accel/habanalabs/common/device.c > index b97339d1f7c6..30357b371d61 100644 > --- a/drivers/accel/habanalabs/common/device.c > +++ b/drivers/accel/habanalabs/common/device.c > @@ -1963,7 +1963,7 @@ static void hl_notifier_event_send(struct hl_notifier_event *notifier_event, u64 > notifier_event->events_mask |= event_mask; > > if (notifier_event->eventfd) > - eventfd_signal(notifier_event->eventfd, 1); > + eventfd_signal(notifier_event->eventfd); > > mutex_unlock(¬ifier_event->lock); > } > diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c > index dd7a783d53b5..e73f88050f08 100644 > --- a/drivers/fpga/dfl.c > +++ b/drivers/fpga/dfl.c > @@ -1872,7 +1872,7 @@ static irqreturn_t dfl_irq_handler(int irq, void *arg) > { > struct eventfd_ctx *trigger = arg; > > - eventfd_signal(trigger, 1); > + eventfd_signal(trigger); > return IRQ_HANDLED; > } > > diff --git a/drivers/gpu/drm/i915/gvt/interrupt.c b/drivers/gpu/drm/i915/gvt/interrupt.c > index 68eca023bbc6..3d9e09c2add4 100644 > --- a/drivers/gpu/drm/i915/gvt/interrupt.c > +++ b/drivers/gpu/drm/i915/gvt/interrupt.c > @@ -435,7 +435,7 @@ static int inject_virtual_interrupt(struct intel_vgpu *vgpu) > */ > if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status)) > return -ESRCH; > - if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger, 1) != 1) > + if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger) != 1) > return -EFAULT; > return 0; > } > diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c > index db5fb196c728..ad50487790ff 100644 > --- a/drivers/infiniband/hw/mlx5/devx.c > +++ b/drivers/infiniband/hw/mlx5/devx.c > @@ -2498,7 +2498,7 @@ static void dispatch_event_fd(struct list_head *fd_list, > > list_for_each_entry_rcu(item, fd_list, xa_list) { > if (item->eventfd) > - eventfd_signal(item->eventfd, 1); > + eventfd_signal(item->eventfd); > else > deliver_event(item, data); > } > diff --git a/drivers/misc/ocxl/file.c b/drivers/misc/ocxl/file.c > index 6e63f060e4cc..51766db296ab 100644 > --- a/drivers/misc/ocxl/file.c > +++ b/drivers/misc/ocxl/file.c > @@ -185,7 +185,7 @@ static irqreturn_t irq_handler(void *private) > { > struct eventfd_ctx *ev_ctx = private; > > - eventfd_signal(ev_ctx, 1); > + eventfd_signal(ev_ctx); > return IRQ_HANDLED; > } > > diff --git a/drivers/s390/cio/vfio_ccw_chp.c b/drivers/s390/cio/vfio_ccw_chp.c > index d3f3a611f95b..38c176cf6295 100644 > --- a/drivers/s390/cio/vfio_ccw_chp.c > +++ b/drivers/s390/cio/vfio_ccw_chp.c > @@ -115,7 +115,7 @@ static ssize_t vfio_ccw_crw_region_read(struct vfio_ccw_private *private, > > /* Notify the guest if more CRWs are on our queue */ > if (!list_empty(&private->crw) && private->crw_trigger) > - eventfd_signal(private->crw_trigger, 1); > + eventfd_signal(private->crw_trigger); > > return ret; > } > diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c > index 43601816ea4e..bfb35cfce1ef 100644 > --- a/drivers/s390/cio/vfio_ccw_drv.c > +++ b/drivers/s390/cio/vfio_ccw_drv.c > @@ -112,7 +112,7 @@ void vfio_ccw_sch_io_todo(struct work_struct *work) > private->state = VFIO_CCW_STATE_IDLE; > > if (private->io_trigger) > - eventfd_signal(private->io_trigger, 1); > + eventfd_signal(private->io_trigger); > } > > void vfio_ccw_crw_todo(struct work_struct *work) > @@ -122,7 +122,7 @@ void vfio_ccw_crw_todo(struct work_struct *work) > private = container_of(work, struct vfio_ccw_private, crw_work); > > if (!list_empty(&private->crw) && private->crw_trigger) > - eventfd_signal(private->crw_trigger, 1); > + eventfd_signal(private->crw_trigger); > } > > /* > diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c > index 5b53b94f13c7..3df231f6feda 100644 > --- a/drivers/s390/cio/vfio_ccw_ops.c > +++ b/drivers/s390/cio/vfio_ccw_ops.c > @@ -421,7 +421,7 @@ static int vfio_ccw_mdev_set_irqs(struct vfio_ccw_private *private, > case VFIO_IRQ_SET_DATA_NONE: > { > if (*ctx) > - eventfd_signal(*ctx, 1); > + eventfd_signal(*ctx); > return 0; > } > case VFIO_IRQ_SET_DATA_BOOL: > @@ -432,7 +432,7 @@ static int vfio_ccw_mdev_set_irqs(struct vfio_ccw_private *private, > return -EFAULT; > > if (trigger && *ctx) > - eventfd_signal(*ctx, 1); > + eventfd_signal(*ctx); > return 0; > } > case VFIO_IRQ_SET_DATA_EVENTFD: > @@ -612,7 +612,7 @@ static void vfio_ccw_mdev_request(struct vfio_device *vdev, unsigned int count) > "Relaying device request to user (#%u)\n", > count); > > - eventfd_signal(private->req_trigger, 1); > + eventfd_signal(private->req_trigger); > } else if (count == 0) { > dev_notice(dev, > "No device request channel registered, blocked until released by user\n"); > diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c > index b441745b0418..feb88526ac9d 100644 > --- a/drivers/s390/crypto/vfio_ap_ops.c > +++ b/drivers/s390/crypto/vfio_ap_ops.c > @@ -1749,7 +1749,7 @@ static void vfio_ap_mdev_request(struct vfio_device *vdev, unsigned int count) > "Relaying device request to user (#%u)\n", > count); > > - eventfd_signal(matrix_mdev->req_trigger, 1); > + eventfd_signal(matrix_mdev->req_trigger); > } else if (count == 0) { > dev_notice(dev, > "No device request registered, blocked until released by user\n"); > diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c > index f41a385a5c42..ceb1aad0c5df 100644 > --- a/drivers/usb/gadget/function/f_fs.c > +++ b/drivers/usb/gadget/function/f_fs.c > @@ -831,7 +831,7 @@ static void ffs_user_copy_worker(struct work_struct *work) > io_data->kiocb->ki_complete(io_data->kiocb, ret); > > if (io_data->ffs->ffs_eventfd && !kiocb_has_eventfd) > - eventfd_signal(io_data->ffs->ffs_eventfd, 1); > + eventfd_signal(io_data->ffs->ffs_eventfd); > > if (io_data->read) > kfree(io_data->to_free); > @@ -2739,7 +2739,7 @@ static void __ffs_event_add(struct ffs_data *ffs, > ffs->ev.types[ffs->ev.count++] = type; > wake_up_locked(&ffs->ev.waitq); > if (ffs->ffs_eventfd) > - eventfd_signal(ffs->ffs_eventfd, 1); > + eventfd_signal(ffs->ffs_eventfd); > } > > static void ffs_event_add(struct ffs_data *ffs, > diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c > index dc38ed21319d..99b901a9e638 100644 > --- a/drivers/vdpa/vdpa_user/vduse_dev.c > +++ b/drivers/vdpa/vdpa_user/vduse_dev.c > @@ -494,7 +494,7 @@ static void vduse_vq_kick(struct vduse_virtqueue *vq) > goto unlock; > > if (vq->kickfd) > - eventfd_signal(vq->kickfd, 1); > + eventfd_signal(vq->kickfd); > else > vq->kicked = true; > unlock: > @@ -912,7 +912,7 @@ static int vduse_kickfd_setup(struct vduse_dev *dev, > eventfd_ctx_put(vq->kickfd); > vq->kickfd = ctx; > if (vq->ready && vq->kicked && vq->kickfd) { > - eventfd_signal(vq->kickfd, 1); > + eventfd_signal(vq->kickfd); > vq->kicked = false; > } > spin_unlock(&vq->kick_lock); > @@ -961,7 +961,7 @@ static bool vduse_vq_signal_irqfd(struct vduse_virtqueue *vq) > > spin_lock_irq(&vq->irq_lock); > if (vq->ready && vq->cb.trigger) { > - eventfd_signal(vq->cb.trigger, 1); > + eventfd_signal(vq->cb.trigger); > signal = true; > } > spin_unlock_irq(&vq->irq_lock); > diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c b/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c > index c51229fccbd6..d62fbfff20b8 100644 > --- a/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c > +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c > @@ -54,7 +54,7 @@ static irqreturn_t vfio_fsl_mc_irq_handler(int irq_num, void *arg) > { > struct vfio_fsl_mc_irq *mc_irq = (struct vfio_fsl_mc_irq *)arg; > > - eventfd_signal(mc_irq->trigger, 1); > + eventfd_signal(mc_irq->trigger); > return IRQ_HANDLED; > } > > diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c > index 20d7b69ea6ff..01c8e31db23b 100644 > --- a/drivers/vfio/pci/vfio_pci_core.c > +++ b/drivers/vfio/pci/vfio_pci_core.c > @@ -441,7 +441,7 @@ static int vfio_pci_core_runtime_resume(struct device *dev) > */ > down_write(&vdev->memory_lock); > if (vdev->pm_wake_eventfd_ctx) { > - eventfd_signal(vdev->pm_wake_eventfd_ctx, 1); > + eventfd_signal(vdev->pm_wake_eventfd_ctx); > __vfio_pci_runtime_pm_exit(vdev); > } > up_write(&vdev->memory_lock); > @@ -1861,7 +1861,7 @@ void vfio_pci_core_request(struct vfio_device *core_vdev, unsigned int count) > pci_notice_ratelimited(pdev, > "Relaying device request to user (#%u)\n", > count); > - eventfd_signal(vdev->req_trigger, 1); > + eventfd_signal(vdev->req_trigger); > } else if (count == 0) { > pci_warn(pdev, > "No device request channel registered, blocked until released by user\n"); > @@ -2280,7 +2280,7 @@ pci_ers_result_t vfio_pci_core_aer_err_detected(struct pci_dev *pdev, > mutex_lock(&vdev->igate); > > if (vdev->err_trigger) > - eventfd_signal(vdev->err_trigger, 1); > + eventfd_signal(vdev->err_trigger); > > mutex_unlock(&vdev->igate); > > diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c > index cbb4bcbfbf83..237beac83809 100644 > --- a/drivers/vfio/pci/vfio_pci_intrs.c > +++ b/drivers/vfio/pci/vfio_pci_intrs.c > @@ -94,7 +94,7 @@ static void vfio_send_intx_eventfd(void *opaque, void *unused) > ctx = vfio_irq_ctx_get(vdev, 0); > if (WARN_ON_ONCE(!ctx)) > return; > - eventfd_signal(ctx->trigger, 1); > + eventfd_signal(ctx->trigger); > } > } > > @@ -342,7 +342,7 @@ static irqreturn_t vfio_msihandler(int irq, void *arg) > { > struct eventfd_ctx *trigger = arg; > > - eventfd_signal(trigger, 1); > + eventfd_signal(trigger); > return IRQ_HANDLED; > } > > @@ -689,11 +689,11 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev, > if (!ctx) > continue; > if (flags & VFIO_IRQ_SET_DATA_NONE) { > - eventfd_signal(ctx->trigger, 1); > + eventfd_signal(ctx->trigger); > } else if (flags & VFIO_IRQ_SET_DATA_BOOL) { > uint8_t *bools = data; > if (bools[i - start]) > - eventfd_signal(ctx->trigger, 1); > + eventfd_signal(ctx->trigger); > } > } > return 0; > @@ -707,7 +707,7 @@ static int vfio_pci_set_ctx_trigger_single(struct eventfd_ctx **ctx, > if (flags & VFIO_IRQ_SET_DATA_NONE) { > if (*ctx) { > if (count) { > - eventfd_signal(*ctx, 1); > + eventfd_signal(*ctx); > } else { > eventfd_ctx_put(*ctx); > *ctx = NULL; > @@ -722,7 +722,7 @@ static int vfio_pci_set_ctx_trigger_single(struct eventfd_ctx **ctx, > > trigger = *(uint8_t *)data; > if (trigger && *ctx) > - eventfd_signal(*ctx, 1); > + eventfd_signal(*ctx); > > return 0; > } else if (flags & VFIO_IRQ_SET_DATA_EVENTFD) { > diff --git a/drivers/vfio/platform/vfio_platform_irq.c b/drivers/vfio/platform/vfio_platform_irq.c > index 665197caed89..61a1bfb68ac7 100644 > --- a/drivers/vfio/platform/vfio_platform_irq.c > +++ b/drivers/vfio/platform/vfio_platform_irq.c > @@ -155,7 +155,7 @@ static irqreturn_t vfio_automasked_irq_handler(int irq, void *dev_id) > spin_unlock_irqrestore(&irq_ctx->lock, flags); > > if (ret == IRQ_HANDLED) > - eventfd_signal(irq_ctx->trigger, 1); > + eventfd_signal(irq_ctx->trigger); > > return ret; > } > @@ -164,7 +164,7 @@ static irqreturn_t vfio_irq_handler(int irq, void *dev_id) > { > struct vfio_platform_irq *irq_ctx = dev_id; > > - eventfd_signal(irq_ctx->trigger, 1); > + eventfd_signal(irq_ctx->trigger); > > return IRQ_HANDLED; > } > diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c > index b43e8680eee8..722894a0f124 100644 > --- a/drivers/vhost/vdpa.c > +++ b/drivers/vhost/vdpa.c > @@ -161,7 +161,7 @@ static irqreturn_t vhost_vdpa_virtqueue_cb(void *private) > struct eventfd_ctx *call_ctx = vq->call_ctx.ctx; > > if (call_ctx) > - eventfd_signal(call_ctx, 1); > + eventfd_signal(call_ctx); > > return IRQ_HANDLED; > } > @@ -172,7 +172,7 @@ static irqreturn_t vhost_vdpa_config_cb(void *private) > struct eventfd_ctx *config_ctx = v->config_ctx; > > if (config_ctx) > - eventfd_signal(config_ctx, 1); > + eventfd_signal(config_ctx); > > return IRQ_HANDLED; > } > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > index c71d573f1c94..bee50f153c8e 100644 > --- a/drivers/vhost/vhost.c > +++ b/drivers/vhost/vhost.c > @@ -2250,7 +2250,7 @@ int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log, > len -= l; > if (!len) { > if (vq->log_ctx) > - eventfd_signal(vq->log_ctx, 1); > + eventfd_signal(vq->log_ctx); > return 0; > } > } > @@ -2273,7 +2273,7 @@ static int vhost_update_used_flags(struct vhost_virtqueue *vq) > log_used(vq, (used - (void __user *)vq->used), > sizeof vq->used->flags); > if (vq->log_ctx) > - eventfd_signal(vq->log_ctx, 1); > + eventfd_signal(vq->log_ctx); > } > return 0; > } > @@ -2291,7 +2291,7 @@ static int vhost_update_avail_event(struct vhost_virtqueue *vq) > log_used(vq, (used - (void __user *)vq->used), > sizeof *vhost_avail_event(vq)); > if (vq->log_ctx) > - eventfd_signal(vq->log_ctx, 1); > + eventfd_signal(vq->log_ctx); > } > return 0; > } > @@ -2717,7 +2717,7 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads, > log_used(vq, offsetof(struct vring_used, idx), > sizeof vq->used->idx); > if (vq->log_ctx) > - eventfd_signal(vq->log_ctx, 1); > + eventfd_signal(vq->log_ctx); > } > return r; > } > @@ -2765,7 +2765,7 @@ void vhost_signal(struct vhost_dev *dev, struct vhost_virtqueue *vq) > { > /* Signal the Guest tell them we used something up. */ > if (vq->call_ctx.ctx && vhost_notify(dev, vq)) > - eventfd_signal(vq->call_ctx.ctx, 1); > + eventfd_signal(vq->call_ctx.ctx); > } > EXPORT_SYMBOL_GPL(vhost_signal); > > diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h > index f60d5f7bef94..9e942fcda5c3 100644 > --- a/drivers/vhost/vhost.h > +++ b/drivers/vhost/vhost.h > @@ -249,7 +249,7 @@ void vhost_iotlb_map_free(struct vhost_iotlb *iotlb, > #define vq_err(vq, fmt, ...) do { \ > pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \ > if ((vq)->error_ctx) \ > - eventfd_signal((vq)->error_ctx, 1);\ > + eventfd_signal((vq)->error_ctx);\ > } while (0) > > enum { > diff --git a/drivers/virt/acrn/ioeventfd.c b/drivers/virt/acrn/ioeventfd.c > index ac4037e9f947..4e845c6ca0b5 100644 > --- a/drivers/virt/acrn/ioeventfd.c > +++ b/drivers/virt/acrn/ioeventfd.c > @@ -223,7 +223,7 @@ static int acrn_ioeventfd_handler(struct acrn_ioreq_client *client, > mutex_lock(&client->vm->ioeventfds_lock); > p = hsm_ioeventfd_match(client->vm, addr, val, size, req->type); > if (p) > - eventfd_signal(p->eventfd, 1); > + eventfd_signal(p->eventfd); > mutex_unlock(&client->vm->ioeventfds_lock); > > return 0; > diff --git a/fs/aio.c b/fs/aio.c > index 77e33619de40..96cf97b19077 100644 > --- a/fs/aio.c > +++ b/fs/aio.c > @@ -1166,7 +1166,7 @@ static void aio_complete(struct aio_kiocb *iocb) > * from IRQ context. > */ > if (iocb->ki_eventfd) > - eventfd_signal(iocb->ki_eventfd, 1); > + eventfd_signal(iocb->ki_eventfd); > > /* > * We have to order our ring_info tail store above and test > diff --git a/fs/eventfd.c b/fs/eventfd.c > index 33a918f9566c..dc9e01053235 100644 > --- a/fs/eventfd.c > +++ b/fs/eventfd.c > @@ -74,20 +74,17 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask) > /** > * eventfd_signal - Adds @n to the eventfd counter. > * @ctx: [in] Pointer to the eventfd context. > - * @n: [in] Value of the counter to be added to the eventfd internal counter. > - * The value cannot be negative. > * > * This function is supposed to be called by the kernel in paths that do not > * allow sleeping. In this function we allow the counter to reach the ULLONG_MAX > * value, and we signal this as overflow condition by returning a EPOLLERR > * to poll(2). > * > - * Returns the amount by which the counter was incremented. This will be less > - * than @n if the counter has overflowed. > + * Returns the amount by which the counter was incremented. > */ > -__u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n) > +__u64 eventfd_signal(struct eventfd_ctx *ctx) > { > - return eventfd_signal_mask(ctx, n, 0); > + return eventfd_signal_mask(ctx, 1, 0); > } > EXPORT_SYMBOL_GPL(eventfd_signal); > > diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h > index b9d83652c097..562089431551 100644 > --- a/include/linux/eventfd.h > +++ b/include/linux/eventfd.h > @@ -35,7 +35,7 @@ void eventfd_ctx_put(struct eventfd_ctx *ctx); > struct file *eventfd_fget(int fd); > struct eventfd_ctx *eventfd_ctx_fdget(int fd); > struct eventfd_ctx *eventfd_ctx_fileget(struct file *file); > -__u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n); > +__u64 eventfd_signal(struct eventfd_ctx *ctx); > __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask); > int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t *wait, > __u64 *cnt); > @@ -58,7 +58,7 @@ static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd) > return ERR_PTR(-ENOSYS); > } > > -static inline int eventfd_signal(struct eventfd_ctx *ctx, __u64 n) > +static inline int eventfd_signal(struct eventfd_ctx *ctx) > { > return -ENOSYS; > } > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index e8ca4bdcb03c..891550f575a1 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -4228,7 +4228,7 @@ static void __mem_cgroup_threshold(struct mem_cgroup *memcg, bool swap) > * only one element of the array here. > */ > for (; i >= 0 && unlikely(t->entries[i].threshold > usage); i--) > - eventfd_signal(t->entries[i].eventfd, 1); > + eventfd_signal(t->entries[i].eventfd); > > /* i = current_threshold + 1 */ > i++; > @@ -4240,7 +4240,7 @@ static void __mem_cgroup_threshold(struct mem_cgroup *memcg, bool swap) > * only one element of the array here. > */ > for (; i < t->size && unlikely(t->entries[i].threshold <= usage); i++) > - eventfd_signal(t->entries[i].eventfd, 1); > + eventfd_signal(t->entries[i].eventfd); > > /* Update current_threshold */ > t->current_threshold = i - 1; > @@ -4280,7 +4280,7 @@ static int mem_cgroup_oom_notify_cb(struct mem_cgroup *memcg) > spin_lock(&memcg_oom_lock); > > list_for_each_entry(ev, &memcg->oom_notify, list) > - eventfd_signal(ev->eventfd, 1); > + eventfd_signal(ev->eventfd); > > spin_unlock(&memcg_oom_lock); > return 0; > @@ -4499,7 +4499,7 @@ static int mem_cgroup_oom_register_event(struct mem_cgroup *memcg, > > /* already in OOM ? */ > if (memcg->under_oom) > - eventfd_signal(eventfd, 1); > + eventfd_signal(eventfd); > spin_unlock(&memcg_oom_lock); > > return 0; > @@ -4791,7 +4791,7 @@ static void memcg_event_remove(struct work_struct *work) > event->unregister_event(memcg, event->eventfd); > > /* Notify userspace the event is going away. */ > - eventfd_signal(event->eventfd, 1); > + eventfd_signal(event->eventfd); > > eventfd_ctx_put(event->eventfd); > kfree(event); > diff --git a/mm/vmpressure.c b/mm/vmpressure.c > index b52644771cc4..ba4cdef37e42 100644 > --- a/mm/vmpressure.c > +++ b/mm/vmpressure.c > @@ -169,7 +169,7 @@ static bool vmpressure_event(struct vmpressure *vmpr, > continue; > if (level < ev->level) > continue; > - eventfd_signal(ev->efd, 1); > + eventfd_signal(ev->efd); > ret = true; > } > mutex_unlock(&vmpr->events_lock); > diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c > index a60801fb8660..5edcf8d738de 100644 > --- a/samples/vfio-mdev/mtty.c > +++ b/samples/vfio-mdev/mtty.c > @@ -1028,9 +1028,9 @@ static int mtty_trigger_interrupt(struct mdev_state *mdev_state) > } > > if (mdev_state->irq_index == VFIO_PCI_MSI_IRQ_INDEX) > - ret = eventfd_signal(mdev_state->msi_evtfd, 1); > + ret = eventfd_signal(mdev_state->msi_evtfd); > else > - ret = eventfd_signal(mdev_state->intx_evtfd, 1); > + ret = eventfd_signal(mdev_state->intx_evtfd); > > #if defined(DEBUG_INTR) > pr_info("Intx triggered\n"); > diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c > index 89912a17f5d5..c0e230f4c3e9 100644 > --- a/virt/kvm/eventfd.c > +++ b/virt/kvm/eventfd.c > @@ -61,7 +61,7 @@ static void irqfd_resampler_notify(struct kvm_kernel_irqfd_resampler *resampler) > > list_for_each_entry_srcu(irqfd, &resampler->list, resampler_link, > srcu_read_lock_held(&resampler->kvm->irq_srcu)) > - eventfd_signal(irqfd->resamplefd, 1); > + eventfd_signal(irqfd->resamplefd); > } > > /* > @@ -786,7 +786,7 @@ ioeventfd_write(struct kvm_vcpu *vcpu, struct kvm_io_device *this, gpa_t addr, > if (!ioeventfd_in_range(p, addr, len, val)) > return -EOPNOTSUPP; > > - eventfd_signal(p->eventfd, 1); > + eventfd_signal(p->eventfd); > return 0; > } > > ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 1/2] eventfd: simplify eventfd_signal() 2023-07-13 10:05 ` [PATCH 1/2] eventfd: simplify eventfd_signal() Christian Brauner 2023-07-13 13:29 ` Anthony Krowiak @ 2023-07-13 13:34 ` Oded Gabbay 1 sibling, 0 replies; 17+ messages in thread From: Oded Gabbay @ 2023-07-13 13:34 UTC (permalink / raw) To: Christian Brauner Cc: linux-fsdevel, Vitaly Kuznetsov, Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, David Woodhouse, Paul Durrant, Wu Hao, Tom Rix, Moritz Fischer, Xu Yilun, Zhenyu Wang, Zhi Wang, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Daniel Vetter, Leon Romanovsky, Jason Gunthorpe, Frederic Barrat, Andrew Donnellan, Arnd Bergmann, Greg Kroah-Hartman, Eric Farman, Matthew Rosato, Halil Pasic, Vineeth Vijayan, Peter Oberparleiter, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Tony Krowiak, Jason Herne, Harald Freudenberger, Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Diana Craciun, Alex Williamson, Eric Auger, Fei Li, Benjamin LaHaise, Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt, Muchun Song, Kirti Wankhede, kvm, linux-kernel, dri-devel, linux-fpga, intel-gvt-dev, intel-gfx, linux-rdma, linuxppc-dev, linux-s390, linux-usb, virtualization, netdev, linux-aio, cgroups, linux-mm, Jens Axboe, Pavel Begunkov, io-uring On Thu, Jul 13, 2023 at 1:06 PM Christian Brauner <brauner@kernel.org> wrote: > > Ever since the evenfd type was introduced back in 2007 in commit > e1ad7468c77d ("signal/timer/event: eventfd core") the eventfd_signal() > function only ever passed 1 as a value for @n. There's no point in > keeping that additional argument. > > Signed-off-by: Christian Brauner <brauner@kernel.org> > --- > arch/x86/kvm/hyperv.c | 2 +- > arch/x86/kvm/xen.c | 2 +- > drivers/accel/habanalabs/common/device.c | 2 +- > drivers/fpga/dfl.c | 2 +- > drivers/gpu/drm/i915/gvt/interrupt.c | 2 +- > drivers/infiniband/hw/mlx5/devx.c | 2 +- > drivers/misc/ocxl/file.c | 2 +- > drivers/s390/cio/vfio_ccw_chp.c | 2 +- > drivers/s390/cio/vfio_ccw_drv.c | 4 ++-- > drivers/s390/cio/vfio_ccw_ops.c | 6 +++--- > drivers/s390/crypto/vfio_ap_ops.c | 2 +- > drivers/usb/gadget/function/f_fs.c | 4 ++-- > drivers/vdpa/vdpa_user/vduse_dev.c | 6 +++--- > drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c | 2 +- > drivers/vfio/pci/vfio_pci_core.c | 6 +++--- > drivers/vfio/pci/vfio_pci_intrs.c | 12 ++++++------ > drivers/vfio/platform/vfio_platform_irq.c | 4 ++-- > drivers/vhost/vdpa.c | 4 ++-- > drivers/vhost/vhost.c | 10 +++++----- > drivers/vhost/vhost.h | 2 +- > drivers/virt/acrn/ioeventfd.c | 2 +- > fs/aio.c | 2 +- > fs/eventfd.c | 9 +++------ > include/linux/eventfd.h | 4 ++-- > mm/memcontrol.c | 10 +++++----- > mm/vmpressure.c | 2 +- > samples/vfio-mdev/mtty.c | 4 ++-- > virt/kvm/eventfd.c | 4 ++-- > 28 files changed, 56 insertions(+), 59 deletions(-) > > diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c > index b28fd020066f..2f4bd74b482c 100644 > --- a/arch/x86/kvm/hyperv.c > +++ b/arch/x86/kvm/hyperv.c > @@ -2387,7 +2387,7 @@ static u16 kvm_hvcall_signal_event(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *h > if (!eventfd) > return HV_STATUS_INVALID_PORT_ID; > > - eventfd_signal(eventfd, 1); > + eventfd_signal(eventfd); > return HV_STATUS_SUCCESS; > } > > diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c > index 40edf4d1974c..a7b62bafd57b 100644 > --- a/arch/x86/kvm/xen.c > +++ b/arch/x86/kvm/xen.c > @@ -2043,7 +2043,7 @@ static bool kvm_xen_hcall_evtchn_send(struct kvm_vcpu *vcpu, u64 param, u64 *r) > if (ret < 0 && ret != -ENOTCONN) > return false; > } else { > - eventfd_signal(evtchnfd->deliver.eventfd.ctx, 1); > + eventfd_signal(evtchnfd->deliver.eventfd.ctx); > } > > *r = 0; > diff --git a/drivers/accel/habanalabs/common/device.c b/drivers/accel/habanalabs/common/device.c > index b97339d1f7c6..30357b371d61 100644 > --- a/drivers/accel/habanalabs/common/device.c > +++ b/drivers/accel/habanalabs/common/device.c > @@ -1963,7 +1963,7 @@ static void hl_notifier_event_send(struct hl_notifier_event *notifier_event, u64 > notifier_event->events_mask |= event_mask; > > if (notifier_event->eventfd) > - eventfd_signal(notifier_event->eventfd, 1); > + eventfd_signal(notifier_event->eventfd); > > mutex_unlock(¬ifier_event->lock); > } > diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c > index dd7a783d53b5..e73f88050f08 100644 > --- a/drivers/fpga/dfl.c > +++ b/drivers/fpga/dfl.c > @@ -1872,7 +1872,7 @@ static irqreturn_t dfl_irq_handler(int irq, void *arg) > { > struct eventfd_ctx *trigger = arg; > > - eventfd_signal(trigger, 1); > + eventfd_signal(trigger); > return IRQ_HANDLED; > } > > diff --git a/drivers/gpu/drm/i915/gvt/interrupt.c b/drivers/gpu/drm/i915/gvt/interrupt.c > index 68eca023bbc6..3d9e09c2add4 100644 > --- a/drivers/gpu/drm/i915/gvt/interrupt.c > +++ b/drivers/gpu/drm/i915/gvt/interrupt.c > @@ -435,7 +435,7 @@ static int inject_virtual_interrupt(struct intel_vgpu *vgpu) > */ > if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status)) > return -ESRCH; > - if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger, 1) != 1) > + if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger) != 1) > return -EFAULT; > return 0; > } > diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c > index db5fb196c728..ad50487790ff 100644 > --- a/drivers/infiniband/hw/mlx5/devx.c > +++ b/drivers/infiniband/hw/mlx5/devx.c > @@ -2498,7 +2498,7 @@ static void dispatch_event_fd(struct list_head *fd_list, > > list_for_each_entry_rcu(item, fd_list, xa_list) { > if (item->eventfd) > - eventfd_signal(item->eventfd, 1); > + eventfd_signal(item->eventfd); > else > deliver_event(item, data); > } > diff --git a/drivers/misc/ocxl/file.c b/drivers/misc/ocxl/file.c > index 6e63f060e4cc..51766db296ab 100644 > --- a/drivers/misc/ocxl/file.c > +++ b/drivers/misc/ocxl/file.c > @@ -185,7 +185,7 @@ static irqreturn_t irq_handler(void *private) > { > struct eventfd_ctx *ev_ctx = private; > > - eventfd_signal(ev_ctx, 1); > + eventfd_signal(ev_ctx); > return IRQ_HANDLED; > } > > diff --git a/drivers/s390/cio/vfio_ccw_chp.c b/drivers/s390/cio/vfio_ccw_chp.c > index d3f3a611f95b..38c176cf6295 100644 > --- a/drivers/s390/cio/vfio_ccw_chp.c > +++ b/drivers/s390/cio/vfio_ccw_chp.c > @@ -115,7 +115,7 @@ static ssize_t vfio_ccw_crw_region_read(struct vfio_ccw_private *private, > > /* Notify the guest if more CRWs are on our queue */ > if (!list_empty(&private->crw) && private->crw_trigger) > - eventfd_signal(private->crw_trigger, 1); > + eventfd_signal(private->crw_trigger); > > return ret; > } > diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c > index 43601816ea4e..bfb35cfce1ef 100644 > --- a/drivers/s390/cio/vfio_ccw_drv.c > +++ b/drivers/s390/cio/vfio_ccw_drv.c > @@ -112,7 +112,7 @@ void vfio_ccw_sch_io_todo(struct work_struct *work) > private->state = VFIO_CCW_STATE_IDLE; > > if (private->io_trigger) > - eventfd_signal(private->io_trigger, 1); > + eventfd_signal(private->io_trigger); > } > > void vfio_ccw_crw_todo(struct work_struct *work) > @@ -122,7 +122,7 @@ void vfio_ccw_crw_todo(struct work_struct *work) > private = container_of(work, struct vfio_ccw_private, crw_work); > > if (!list_empty(&private->crw) && private->crw_trigger) > - eventfd_signal(private->crw_trigger, 1); > + eventfd_signal(private->crw_trigger); > } > > /* > diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c > index 5b53b94f13c7..3df231f6feda 100644 > --- a/drivers/s390/cio/vfio_ccw_ops.c > +++ b/drivers/s390/cio/vfio_ccw_ops.c > @@ -421,7 +421,7 @@ static int vfio_ccw_mdev_set_irqs(struct vfio_ccw_private *private, > case VFIO_IRQ_SET_DATA_NONE: > { > if (*ctx) > - eventfd_signal(*ctx, 1); > + eventfd_signal(*ctx); > return 0; > } > case VFIO_IRQ_SET_DATA_BOOL: > @@ -432,7 +432,7 @@ static int vfio_ccw_mdev_set_irqs(struct vfio_ccw_private *private, > return -EFAULT; > > if (trigger && *ctx) > - eventfd_signal(*ctx, 1); > + eventfd_signal(*ctx); > return 0; > } > case VFIO_IRQ_SET_DATA_EVENTFD: > @@ -612,7 +612,7 @@ static void vfio_ccw_mdev_request(struct vfio_device *vdev, unsigned int count) > "Relaying device request to user (#%u)\n", > count); > > - eventfd_signal(private->req_trigger, 1); > + eventfd_signal(private->req_trigger); > } else if (count == 0) { > dev_notice(dev, > "No device request channel registered, blocked until released by user\n"); > diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c > index b441745b0418..feb88526ac9d 100644 > --- a/drivers/s390/crypto/vfio_ap_ops.c > +++ b/drivers/s390/crypto/vfio_ap_ops.c > @@ -1749,7 +1749,7 @@ static void vfio_ap_mdev_request(struct vfio_device *vdev, unsigned int count) > "Relaying device request to user (#%u)\n", > count); > > - eventfd_signal(matrix_mdev->req_trigger, 1); > + eventfd_signal(matrix_mdev->req_trigger); > } else if (count == 0) { > dev_notice(dev, > "No device request registered, blocked until released by user\n"); > diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c > index f41a385a5c42..ceb1aad0c5df 100644 > --- a/drivers/usb/gadget/function/f_fs.c > +++ b/drivers/usb/gadget/function/f_fs.c > @@ -831,7 +831,7 @@ static void ffs_user_copy_worker(struct work_struct *work) > io_data->kiocb->ki_complete(io_data->kiocb, ret); > > if (io_data->ffs->ffs_eventfd && !kiocb_has_eventfd) > - eventfd_signal(io_data->ffs->ffs_eventfd, 1); > + eventfd_signal(io_data->ffs->ffs_eventfd); > > if (io_data->read) > kfree(io_data->to_free); > @@ -2739,7 +2739,7 @@ static void __ffs_event_add(struct ffs_data *ffs, > ffs->ev.types[ffs->ev.count++] = type; > wake_up_locked(&ffs->ev.waitq); > if (ffs->ffs_eventfd) > - eventfd_signal(ffs->ffs_eventfd, 1); > + eventfd_signal(ffs->ffs_eventfd); > } > > static void ffs_event_add(struct ffs_data *ffs, > diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c > index dc38ed21319d..99b901a9e638 100644 > --- a/drivers/vdpa/vdpa_user/vduse_dev.c > +++ b/drivers/vdpa/vdpa_user/vduse_dev.c > @@ -494,7 +494,7 @@ static void vduse_vq_kick(struct vduse_virtqueue *vq) > goto unlock; > > if (vq->kickfd) > - eventfd_signal(vq->kickfd, 1); > + eventfd_signal(vq->kickfd); > else > vq->kicked = true; > unlock: > @@ -912,7 +912,7 @@ static int vduse_kickfd_setup(struct vduse_dev *dev, > eventfd_ctx_put(vq->kickfd); > vq->kickfd = ctx; > if (vq->ready && vq->kicked && vq->kickfd) { > - eventfd_signal(vq->kickfd, 1); > + eventfd_signal(vq->kickfd); > vq->kicked = false; > } > spin_unlock(&vq->kick_lock); > @@ -961,7 +961,7 @@ static bool vduse_vq_signal_irqfd(struct vduse_virtqueue *vq) > > spin_lock_irq(&vq->irq_lock); > if (vq->ready && vq->cb.trigger) { > - eventfd_signal(vq->cb.trigger, 1); > + eventfd_signal(vq->cb.trigger); > signal = true; > } > spin_unlock_irq(&vq->irq_lock); > diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c b/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c > index c51229fccbd6..d62fbfff20b8 100644 > --- a/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c > +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c > @@ -54,7 +54,7 @@ static irqreturn_t vfio_fsl_mc_irq_handler(int irq_num, void *arg) > { > struct vfio_fsl_mc_irq *mc_irq = (struct vfio_fsl_mc_irq *)arg; > > - eventfd_signal(mc_irq->trigger, 1); > + eventfd_signal(mc_irq->trigger); > return IRQ_HANDLED; > } > > diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c > index 20d7b69ea6ff..01c8e31db23b 100644 > --- a/drivers/vfio/pci/vfio_pci_core.c > +++ b/drivers/vfio/pci/vfio_pci_core.c > @@ -441,7 +441,7 @@ static int vfio_pci_core_runtime_resume(struct device *dev) > */ > down_write(&vdev->memory_lock); > if (vdev->pm_wake_eventfd_ctx) { > - eventfd_signal(vdev->pm_wake_eventfd_ctx, 1); > + eventfd_signal(vdev->pm_wake_eventfd_ctx); > __vfio_pci_runtime_pm_exit(vdev); > } > up_write(&vdev->memory_lock); > @@ -1861,7 +1861,7 @@ void vfio_pci_core_request(struct vfio_device *core_vdev, unsigned int count) > pci_notice_ratelimited(pdev, > "Relaying device request to user (#%u)\n", > count); > - eventfd_signal(vdev->req_trigger, 1); > + eventfd_signal(vdev->req_trigger); > } else if (count == 0) { > pci_warn(pdev, > "No device request channel registered, blocked until released by user\n"); > @@ -2280,7 +2280,7 @@ pci_ers_result_t vfio_pci_core_aer_err_detected(struct pci_dev *pdev, > mutex_lock(&vdev->igate); > > if (vdev->err_trigger) > - eventfd_signal(vdev->err_trigger, 1); > + eventfd_signal(vdev->err_trigger); > > mutex_unlock(&vdev->igate); > > diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c > index cbb4bcbfbf83..237beac83809 100644 > --- a/drivers/vfio/pci/vfio_pci_intrs.c > +++ b/drivers/vfio/pci/vfio_pci_intrs.c > @@ -94,7 +94,7 @@ static void vfio_send_intx_eventfd(void *opaque, void *unused) > ctx = vfio_irq_ctx_get(vdev, 0); > if (WARN_ON_ONCE(!ctx)) > return; > - eventfd_signal(ctx->trigger, 1); > + eventfd_signal(ctx->trigger); > } > } > > @@ -342,7 +342,7 @@ static irqreturn_t vfio_msihandler(int irq, void *arg) > { > struct eventfd_ctx *trigger = arg; > > - eventfd_signal(trigger, 1); > + eventfd_signal(trigger); > return IRQ_HANDLED; > } > > @@ -689,11 +689,11 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev, > if (!ctx) > continue; > if (flags & VFIO_IRQ_SET_DATA_NONE) { > - eventfd_signal(ctx->trigger, 1); > + eventfd_signal(ctx->trigger); > } else if (flags & VFIO_IRQ_SET_DATA_BOOL) { > uint8_t *bools = data; > if (bools[i - start]) > - eventfd_signal(ctx->trigger, 1); > + eventfd_signal(ctx->trigger); > } > } > return 0; > @@ -707,7 +707,7 @@ static int vfio_pci_set_ctx_trigger_single(struct eventfd_ctx **ctx, > if (flags & VFIO_IRQ_SET_DATA_NONE) { > if (*ctx) { > if (count) { > - eventfd_signal(*ctx, 1); > + eventfd_signal(*ctx); > } else { > eventfd_ctx_put(*ctx); > *ctx = NULL; > @@ -722,7 +722,7 @@ static int vfio_pci_set_ctx_trigger_single(struct eventfd_ctx **ctx, > > trigger = *(uint8_t *)data; > if (trigger && *ctx) > - eventfd_signal(*ctx, 1); > + eventfd_signal(*ctx); > > return 0; > } else if (flags & VFIO_IRQ_SET_DATA_EVENTFD) { > diff --git a/drivers/vfio/platform/vfio_platform_irq.c b/drivers/vfio/platform/vfio_platform_irq.c > index 665197caed89..61a1bfb68ac7 100644 > --- a/drivers/vfio/platform/vfio_platform_irq.c > +++ b/drivers/vfio/platform/vfio_platform_irq.c > @@ -155,7 +155,7 @@ static irqreturn_t vfio_automasked_irq_handler(int irq, void *dev_id) > spin_unlock_irqrestore(&irq_ctx->lock, flags); > > if (ret == IRQ_HANDLED) > - eventfd_signal(irq_ctx->trigger, 1); > + eventfd_signal(irq_ctx->trigger); > > return ret; > } > @@ -164,7 +164,7 @@ static irqreturn_t vfio_irq_handler(int irq, void *dev_id) > { > struct vfio_platform_irq *irq_ctx = dev_id; > > - eventfd_signal(irq_ctx->trigger, 1); > + eventfd_signal(irq_ctx->trigger); > > return IRQ_HANDLED; > } > diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c > index b43e8680eee8..722894a0f124 100644 > --- a/drivers/vhost/vdpa.c > +++ b/drivers/vhost/vdpa.c > @@ -161,7 +161,7 @@ static irqreturn_t vhost_vdpa_virtqueue_cb(void *private) > struct eventfd_ctx *call_ctx = vq->call_ctx.ctx; > > if (call_ctx) > - eventfd_signal(call_ctx, 1); > + eventfd_signal(call_ctx); > > return IRQ_HANDLED; > } > @@ -172,7 +172,7 @@ static irqreturn_t vhost_vdpa_config_cb(void *private) > struct eventfd_ctx *config_ctx = v->config_ctx; > > if (config_ctx) > - eventfd_signal(config_ctx, 1); > + eventfd_signal(config_ctx); > > return IRQ_HANDLED; > } > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > index c71d573f1c94..bee50f153c8e 100644 > --- a/drivers/vhost/vhost.c > +++ b/drivers/vhost/vhost.c > @@ -2250,7 +2250,7 @@ int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log, > len -= l; > if (!len) { > if (vq->log_ctx) > - eventfd_signal(vq->log_ctx, 1); > + eventfd_signal(vq->log_ctx); > return 0; > } > } > @@ -2273,7 +2273,7 @@ static int vhost_update_used_flags(struct vhost_virtqueue *vq) > log_used(vq, (used - (void __user *)vq->used), > sizeof vq->used->flags); > if (vq->log_ctx) > - eventfd_signal(vq->log_ctx, 1); > + eventfd_signal(vq->log_ctx); > } > return 0; > } > @@ -2291,7 +2291,7 @@ static int vhost_update_avail_event(struct vhost_virtqueue *vq) > log_used(vq, (used - (void __user *)vq->used), > sizeof *vhost_avail_event(vq)); > if (vq->log_ctx) > - eventfd_signal(vq->log_ctx, 1); > + eventfd_signal(vq->log_ctx); > } > return 0; > } > @@ -2717,7 +2717,7 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads, > log_used(vq, offsetof(struct vring_used, idx), > sizeof vq->used->idx); > if (vq->log_ctx) > - eventfd_signal(vq->log_ctx, 1); > + eventfd_signal(vq->log_ctx); > } > return r; > } > @@ -2765,7 +2765,7 @@ void vhost_signal(struct vhost_dev *dev, struct vhost_virtqueue *vq) > { > /* Signal the Guest tell them we used something up. */ > if (vq->call_ctx.ctx && vhost_notify(dev, vq)) > - eventfd_signal(vq->call_ctx.ctx, 1); > + eventfd_signal(vq->call_ctx.ctx); > } > EXPORT_SYMBOL_GPL(vhost_signal); > > diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h > index f60d5f7bef94..9e942fcda5c3 100644 > --- a/drivers/vhost/vhost.h > +++ b/drivers/vhost/vhost.h > @@ -249,7 +249,7 @@ void vhost_iotlb_map_free(struct vhost_iotlb *iotlb, > #define vq_err(vq, fmt, ...) do { \ > pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \ > if ((vq)->error_ctx) \ > - eventfd_signal((vq)->error_ctx, 1);\ > + eventfd_signal((vq)->error_ctx);\ > } while (0) > > enum { > diff --git a/drivers/virt/acrn/ioeventfd.c b/drivers/virt/acrn/ioeventfd.c > index ac4037e9f947..4e845c6ca0b5 100644 > --- a/drivers/virt/acrn/ioeventfd.c > +++ b/drivers/virt/acrn/ioeventfd.c > @@ -223,7 +223,7 @@ static int acrn_ioeventfd_handler(struct acrn_ioreq_client *client, > mutex_lock(&client->vm->ioeventfds_lock); > p = hsm_ioeventfd_match(client->vm, addr, val, size, req->type); > if (p) > - eventfd_signal(p->eventfd, 1); > + eventfd_signal(p->eventfd); > mutex_unlock(&client->vm->ioeventfds_lock); > > return 0; > diff --git a/fs/aio.c b/fs/aio.c > index 77e33619de40..96cf97b19077 100644 > --- a/fs/aio.c > +++ b/fs/aio.c > @@ -1166,7 +1166,7 @@ static void aio_complete(struct aio_kiocb *iocb) > * from IRQ context. > */ > if (iocb->ki_eventfd) > - eventfd_signal(iocb->ki_eventfd, 1); > + eventfd_signal(iocb->ki_eventfd); > > /* > * We have to order our ring_info tail store above and test > diff --git a/fs/eventfd.c b/fs/eventfd.c > index 33a918f9566c..dc9e01053235 100644 > --- a/fs/eventfd.c > +++ b/fs/eventfd.c > @@ -74,20 +74,17 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask) > /** > * eventfd_signal - Adds @n to the eventfd counter. > * @ctx: [in] Pointer to the eventfd context. > - * @n: [in] Value of the counter to be added to the eventfd internal counter. > - * The value cannot be negative. > * > * This function is supposed to be called by the kernel in paths that do not > * allow sleeping. In this function we allow the counter to reach the ULLONG_MAX > * value, and we signal this as overflow condition by returning a EPOLLERR > * to poll(2). > * > - * Returns the amount by which the counter was incremented. This will be less > - * than @n if the counter has overflowed. > + * Returns the amount by which the counter was incremented. > */ > -__u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n) > +__u64 eventfd_signal(struct eventfd_ctx *ctx) > { > - return eventfd_signal_mask(ctx, n, 0); > + return eventfd_signal_mask(ctx, 1, 0); > } > EXPORT_SYMBOL_GPL(eventfd_signal); > > diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h > index b9d83652c097..562089431551 100644 > --- a/include/linux/eventfd.h > +++ b/include/linux/eventfd.h > @@ -35,7 +35,7 @@ void eventfd_ctx_put(struct eventfd_ctx *ctx); > struct file *eventfd_fget(int fd); > struct eventfd_ctx *eventfd_ctx_fdget(int fd); > struct eventfd_ctx *eventfd_ctx_fileget(struct file *file); > -__u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n); > +__u64 eventfd_signal(struct eventfd_ctx *ctx); > __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask); > int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t *wait, > __u64 *cnt); > @@ -58,7 +58,7 @@ static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd) > return ERR_PTR(-ENOSYS); > } > > -static inline int eventfd_signal(struct eventfd_ctx *ctx, __u64 n) > +static inline int eventfd_signal(struct eventfd_ctx *ctx) > { > return -ENOSYS; > } > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index e8ca4bdcb03c..891550f575a1 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -4228,7 +4228,7 @@ static void __mem_cgroup_threshold(struct mem_cgroup *memcg, bool swap) > * only one element of the array here. > */ > for (; i >= 0 && unlikely(t->entries[i].threshold > usage); i--) > - eventfd_signal(t->entries[i].eventfd, 1); > + eventfd_signal(t->entries[i].eventfd); > > /* i = current_threshold + 1 */ > i++; > @@ -4240,7 +4240,7 @@ static void __mem_cgroup_threshold(struct mem_cgroup *memcg, bool swap) > * only one element of the array here. > */ > for (; i < t->size && unlikely(t->entries[i].threshold <= usage); i++) > - eventfd_signal(t->entries[i].eventfd, 1); > + eventfd_signal(t->entries[i].eventfd); > > /* Update current_threshold */ > t->current_threshold = i - 1; > @@ -4280,7 +4280,7 @@ static int mem_cgroup_oom_notify_cb(struct mem_cgroup *memcg) > spin_lock(&memcg_oom_lock); > > list_for_each_entry(ev, &memcg->oom_notify, list) > - eventfd_signal(ev->eventfd, 1); > + eventfd_signal(ev->eventfd); > > spin_unlock(&memcg_oom_lock); > return 0; > @@ -4499,7 +4499,7 @@ static int mem_cgroup_oom_register_event(struct mem_cgroup *memcg, > > /* already in OOM ? */ > if (memcg->under_oom) > - eventfd_signal(eventfd, 1); > + eventfd_signal(eventfd); > spin_unlock(&memcg_oom_lock); > > return 0; > @@ -4791,7 +4791,7 @@ static void memcg_event_remove(struct work_struct *work) > event->unregister_event(memcg, event->eventfd); > > /* Notify userspace the event is going away. */ > - eventfd_signal(event->eventfd, 1); > + eventfd_signal(event->eventfd); > > eventfd_ctx_put(event->eventfd); > kfree(event); > diff --git a/mm/vmpressure.c b/mm/vmpressure.c > index b52644771cc4..ba4cdef37e42 100644 > --- a/mm/vmpressure.c > +++ b/mm/vmpressure.c > @@ -169,7 +169,7 @@ static bool vmpressure_event(struct vmpressure *vmpr, > continue; > if (level < ev->level) > continue; > - eventfd_signal(ev->efd, 1); > + eventfd_signal(ev->efd); > ret = true; > } > mutex_unlock(&vmpr->events_lock); > diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c > index a60801fb8660..5edcf8d738de 100644 > --- a/samples/vfio-mdev/mtty.c > +++ b/samples/vfio-mdev/mtty.c > @@ -1028,9 +1028,9 @@ static int mtty_trigger_interrupt(struct mdev_state *mdev_state) > } > > if (mdev_state->irq_index == VFIO_PCI_MSI_IRQ_INDEX) > - ret = eventfd_signal(mdev_state->msi_evtfd, 1); > + ret = eventfd_signal(mdev_state->msi_evtfd); > else > - ret = eventfd_signal(mdev_state->intx_evtfd, 1); > + ret = eventfd_signal(mdev_state->intx_evtfd); > > #if defined(DEBUG_INTR) > pr_info("Intx triggered\n"); > diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c > index 89912a17f5d5..c0e230f4c3e9 100644 > --- a/virt/kvm/eventfd.c > +++ b/virt/kvm/eventfd.c > @@ -61,7 +61,7 @@ static void irqfd_resampler_notify(struct kvm_kernel_irqfd_resampler *resampler) > > list_for_each_entry_srcu(irqfd, &resampler->list, resampler_link, > srcu_read_lock_held(&resampler->kvm->irq_srcu)) > - eventfd_signal(irqfd->resamplefd, 1); > + eventfd_signal(irqfd->resamplefd); > } > > /* > @@ -786,7 +786,7 @@ ioeventfd_write(struct kvm_vcpu *vcpu, struct kvm_io_device *this, gpa_t addr, > if (!ioeventfd_in_range(p, addr, len, val)) > return -EOPNOTSUPP; > > - eventfd_signal(p->eventfd, 1); > + eventfd_signal(p->eventfd); > return 0; > } > > > -- > 2.34.1 > For habanalabs (device.c): Reviewed-by: Oded Gabbay <ogabbay@kernel.org> ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 2/2] eventfd: simplify eventfd_signal_mask() 2023-07-13 10:05 [PATCH 0/2] eventfd: simplify signal helpers Christian Brauner 2023-07-13 10:05 ` [PATCH 1/2] eventfd: simplify eventfd_signal() Christian Brauner @ 2023-07-13 10:05 ` Christian Brauner 2023-07-13 11:59 ` Petr Machata 2023-07-13 14:33 ` Sean Christopherson 2023-07-13 17:10 ` [PATCH 0/2] eventfd: simplify signal helpers Alex Williamson 2 siblings, 2 replies; 17+ messages in thread From: Christian Brauner @ 2023-07-13 10:05 UTC (permalink / raw) To: linux-fsdevel Cc: Vitaly Kuznetsov, Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, David Woodhouse, Paul Durrant, Oded Gabbay, Wu Hao, Tom Rix, Moritz Fischer, Xu Yilun, Zhenyu Wang, Zhi Wang, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Daniel Vetter, Leon Romanovsky, Jason Gunthorpe, Frederic Barrat, Andrew Donnellan, Arnd Bergmann, Greg Kroah-Hartman, Eric Farman, Matthew Rosato, Halil Pasic, Vineeth Vijayan, Peter Oberparleiter, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Tony Krowiak, Jason Herne, Harald Freudenberger, Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Diana Craciun, Alex Williamson, Eric Auger, Fei Li, Benjamin LaHaise, Christian Brauner, Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt, Muchun Song, Kirti Wankhede, kvm, linux-kernel, dri-devel, linux-fpga, intel-gvt-dev, intel-gfx, linux-rdma, linuxppc-dev, linux-s390, linux-usb, virtualization, netdev, linux-aio, cgroups, linux-mm, Jens Axboe, Pavel Begunkov, io-uring The eventfd_signal_mask() helper was introduced for io_uring and similar to eventfd_signal() it always passed 1 for @n. So don't bother with that argument at all. Signed-off-by: Christian Brauner <brauner@kernel.org> --- drivers/gpu/drm/i915/gvt/interrupt.c | 2 +- fs/eventfd.c | 9 +++++---- include/linux/eventfd.h | 9 ++++----- io_uring/io_uring.c | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/interrupt.c b/drivers/gpu/drm/i915/gvt/interrupt.c index 3d9e09c2add4..31aff6f733d4 100644 --- a/drivers/gpu/drm/i915/gvt/interrupt.c +++ b/drivers/gpu/drm/i915/gvt/interrupt.c @@ -435,7 +435,7 @@ static int inject_virtual_interrupt(struct intel_vgpu *vgpu) */ if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status)) return -ESRCH; - if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger) != 1) + if (vgpu->msi_trigger && !eventfd_signal(vgpu->msi_trigger)) return -EFAULT; return 0; } diff --git a/fs/eventfd.c b/fs/eventfd.c index dc9e01053235..077be5da72bd 100644 --- a/fs/eventfd.c +++ b/fs/eventfd.c @@ -43,9 +43,10 @@ struct eventfd_ctx { int id; }; -__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask) +bool eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask) { unsigned long flags; + __u64 n = 1; /* * Deadlock or stack overflow issues can happen if we recurse here @@ -68,7 +69,7 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask) current->in_eventfd = 0; spin_unlock_irqrestore(&ctx->wqh.lock, flags); - return n; + return n == 1; } /** @@ -82,9 +83,9 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask) * * Returns the amount by which the counter was incremented. */ -__u64 eventfd_signal(struct eventfd_ctx *ctx) +bool eventfd_signal(struct eventfd_ctx *ctx) { - return eventfd_signal_mask(ctx, 1, 0); + return eventfd_signal_mask(ctx, 0); } EXPORT_SYMBOL_GPL(eventfd_signal); diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h index 562089431551..0155ee25f7c8 100644 --- a/include/linux/eventfd.h +++ b/include/linux/eventfd.h @@ -35,8 +35,8 @@ void eventfd_ctx_put(struct eventfd_ctx *ctx); struct file *eventfd_fget(int fd); struct eventfd_ctx *eventfd_ctx_fdget(int fd); struct eventfd_ctx *eventfd_ctx_fileget(struct file *file); -__u64 eventfd_signal(struct eventfd_ctx *ctx); -__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask); +bool eventfd_signal(struct eventfd_ctx *ctx); +bool eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask); int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t *wait, __u64 *cnt); void eventfd_ctx_do_read(struct eventfd_ctx *ctx, __u64 *cnt); @@ -58,13 +58,12 @@ static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd) return ERR_PTR(-ENOSYS); } -static inline int eventfd_signal(struct eventfd_ctx *ctx) +static inline bool eventfd_signal(struct eventfd_ctx *ctx) { return -ENOSYS; } -static inline int eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, - unsigned mask) +static inline bool eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned mask) { return -ENOSYS; } diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index e8096d502a7c..a9359ef73935 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -537,7 +537,7 @@ static void io_eventfd_ops(struct rcu_head *rcu) int ops = atomic_xchg(&ev_fd->ops, 0); if (ops & BIT(IO_EVENTFD_OP_SIGNAL_BIT)) - eventfd_signal_mask(ev_fd->cq_ev_fd, 1, EPOLL_URING_WAKE); + eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE); /* IO_EVENTFD_OP_FREE_BIT may not be set here depending on callback * ordering in a race but if references are 0 we know we have to free @@ -573,7 +573,7 @@ static void io_eventfd_signal(struct io_ring_ctx *ctx) goto out; if (likely(eventfd_signal_allowed())) { - eventfd_signal_mask(ev_fd->cq_ev_fd, 1, EPOLL_URING_WAKE); + eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE); } else { atomic_inc(&ev_fd->refs); if (!atomic_fetch_or(BIT(IO_EVENTFD_OP_SIGNAL_BIT), &ev_fd->ops)) -- 2.34.1 ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/2] eventfd: simplify eventfd_signal_mask() 2023-07-13 10:05 ` [PATCH 2/2] eventfd: simplify eventfd_signal_mask() Christian Brauner @ 2023-07-13 11:59 ` Petr Machata 2023-07-13 14:00 ` Christian Brauner 2023-07-13 14:33 ` Sean Christopherson 1 sibling, 1 reply; 17+ messages in thread From: Petr Machata @ 2023-07-13 11:59 UTC (permalink / raw) To: Christian Brauner; +Cc: linux-fsdevel, linux-kernel Christian Brauner <brauner@kernel.org> writes: > @@ -82,9 +83,9 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask) > * > * Returns the amount by which the counter was incremented. This should be reworded to reflect the fact that the function now returns a bool. > */ > -__u64 eventfd_signal(struct eventfd_ctx *ctx) > +bool eventfd_signal(struct eventfd_ctx *ctx) > { > - return eventfd_signal_mask(ctx, 1, 0); > + return eventfd_signal_mask(ctx, 0); > } > EXPORT_SYMBOL_GPL(eventfd_signal); > ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/2] eventfd: simplify eventfd_signal_mask() 2023-07-13 11:59 ` Petr Machata @ 2023-07-13 14:00 ` Christian Brauner 0 siblings, 0 replies; 17+ messages in thread From: Christian Brauner @ 2023-07-13 14:00 UTC (permalink / raw) To: Petr Machata; +Cc: linux-fsdevel, linux-kernel On Thu, Jul 13, 2023 at 01:59:01PM +0200, Petr Machata wrote: > > Christian Brauner <brauner@kernel.org> writes: > > > @@ -82,9 +83,9 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask) > > * > > * Returns the amount by which the counter was incremented. > > This should be reworded to reflect the fact that the function now > returns a bool. Thanks, I'll update that in-tree to avoid respamming everyone. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/2] eventfd: simplify eventfd_signal_mask() 2023-07-13 10:05 ` [PATCH 2/2] eventfd: simplify eventfd_signal_mask() Christian Brauner 2023-07-13 11:59 ` Petr Machata @ 2023-07-13 14:33 ` Sean Christopherson 2023-07-13 14:52 ` Christian Brauner 1 sibling, 1 reply; 17+ messages in thread From: Sean Christopherson @ 2023-07-13 14:33 UTC (permalink / raw) To: Christian Brauner Cc: linux-fsdevel, Vitaly Kuznetsov, Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, David Woodhouse, Paul Durrant, Oded Gabbay, Wu Hao, Tom Rix, Moritz Fischer, Xu Yilun, Zhenyu Wang, Zhi Wang, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Daniel Vetter, Leon Romanovsky, Jason Gunthorpe, Frederic Barrat, Andrew Donnellan, Arnd Bergmann, Greg Kroah-Hartman, Eric Farman, Matthew Rosato, Halil Pasic, Vineeth Vijayan, Peter Oberparleiter, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Tony Krowiak, Jason Herne, Harald Freudenberger, Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Diana Craciun, Alex Williamson, Eric Auger, Fei Li, Benjamin LaHaise, Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt, Muchun Song, Kirti Wankhede, kvm, linux-kernel, dri-devel, linux-fpga, intel-gvt-dev, intel-gfx, linux-rdma, linuxppc-dev, linux-s390, linux-usb, virtualization, netdev, linux-aio, cgroups, linux-mm, Jens Axboe, Pavel Begunkov, io-uring On Thu, Jul 13, 2023, Christian Brauner wrote: > diff --git a/fs/eventfd.c b/fs/eventfd.c > index dc9e01053235..077be5da72bd 100644 > --- a/fs/eventfd.c > +++ b/fs/eventfd.c > @@ -43,9 +43,10 @@ struct eventfd_ctx { > int id; > }; > > -__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask) > +bool eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask) > { > unsigned long flags; > + __u64 n = 1; > > /* > * Deadlock or stack overflow issues can happen if we recurse here > @@ -68,7 +69,7 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask) > current->in_eventfd = 0; > spin_unlock_irqrestore(&ctx->wqh.lock, flags); > > - return n; > + return n == 1; > } ... > @@ -58,13 +58,12 @@ static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd) > return ERR_PTR(-ENOSYS); > } > > -static inline int eventfd_signal(struct eventfd_ctx *ctx) > +static inline bool eventfd_signal(struct eventfd_ctx *ctx) > { > return -ENOSYS; > } > > -static inline int eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, > - unsigned mask) > +static inline bool eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned mask) > { > return -ENOSYS; This will morph to "true" for what should be an error case. One option would be to have eventfd_signal_mask() return 0/-errno instead of the count, but looking at all the callers, nothing ever actually consumes the result. KVMGT morphs failure into -EFAULT if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger, 1) != 1) return -EFAULT; but the only caller of that user ignores the return value. if (vgpu_vreg(vgpu, i915_mmio_reg_offset(GEN8_MASTER_IRQ)) & ~GEN8_MASTER_IRQ_CONTROL) inject_virtual_interrupt(vgpu); The sample driver in samples/vfio-mdev/mtty.c uses a similar pattern: prints an error but otherwise ignores the result. So why not return nothing? That will simplify eventfd_signal_mask() a wee bit more, and eliminate that bizarre return value confusion for the ugly stubs, e.g. void eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned mask) { unsigned long flags; /* * Deadlock or stack overflow issues can happen if we recurse here * through waitqueue wakeup handlers. If the caller users potentially * nested waitqueues with custom wakeup handlers, then it should * check eventfd_signal_allowed() before calling this function. If * it returns false, the eventfd_signal() call should be deferred to a * safe context. */ if (WARN_ON_ONCE(current->in_eventfd)) return; spin_lock_irqsave(&ctx->wqh.lock, flags); current->in_eventfd = 1; if (ctx->count < ULLONG_MAX) ctx->count++; if (waitqueue_active(&ctx->wqh)) wake_up_locked_poll(&ctx->wqh, EPOLLIN | mask); current->in_eventfd = 0; spin_unlock_irqrestore(&ctx->wqh.lock, flags); } You could even go further and unify the real and stub versions of eventfd_signal(). ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/2] eventfd: simplify eventfd_signal_mask() 2023-07-13 14:33 ` Sean Christopherson @ 2023-07-13 14:52 ` Christian Brauner 0 siblings, 0 replies; 17+ messages in thread From: Christian Brauner @ 2023-07-13 14:52 UTC (permalink / raw) To: Sean Christopherson Cc: linux-fsdevel, Vitaly Kuznetsov, Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, David Woodhouse, Paul Durrant, Oded Gabbay, Wu Hao, Tom Rix, Moritz Fischer, Xu Yilun, Zhenyu Wang, Zhi Wang, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Daniel Vetter, Leon Romanovsky, Jason Gunthorpe, Frederic Barrat, Andrew Donnellan, Arnd Bergmann, Greg Kroah-Hartman, Eric Farman, Matthew Rosato, Halil Pasic, Vineeth Vijayan, Peter Oberparleiter, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, Sven Schnelle, Tony Krowiak, Jason Herne, Harald Freudenberger, Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Diana Craciun, Alex Williamson, Eric Auger, Fei Li, Benjamin LaHaise, Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt, Muchun Song, Kirti Wankhede, kvm, linux-kernel, dri-devel, linux-fpga, intel-gvt-dev, intel-gfx, linux-rdma, linuxppc-dev, linux-s390, linux-usb, virtualization, netdev, linux-aio, cgroups, linux-mm, Jens Axboe, Pavel Begunkov, io-uring On Thu, Jul 13, 2023 at 07:33:05AM -0700, Sean Christopherson wrote: > On Thu, Jul 13, 2023, Christian Brauner wrote: > > diff --git a/fs/eventfd.c b/fs/eventfd.c > > index dc9e01053235..077be5da72bd 100644 > > --- a/fs/eventfd.c > > +++ b/fs/eventfd.c > > @@ -43,9 +43,10 @@ struct eventfd_ctx { > > int id; > > }; > > > > -__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask) > > +bool eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask) > > { > > unsigned long flags; > > + __u64 n = 1; > > > > /* > > * Deadlock or stack overflow issues can happen if we recurse here > > @@ -68,7 +69,7 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask) > > current->in_eventfd = 0; > > spin_unlock_irqrestore(&ctx->wqh.lock, flags); > > > > - return n; > > + return n == 1; > > } > > ... > > > @@ -58,13 +58,12 @@ static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd) > > return ERR_PTR(-ENOSYS); > > } > > > > -static inline int eventfd_signal(struct eventfd_ctx *ctx) > > +static inline bool eventfd_signal(struct eventfd_ctx *ctx) > > { > > return -ENOSYS; > > } > > > > -static inline int eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, > > - unsigned mask) > > +static inline bool eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned mask) > > { > > return -ENOSYS; > > This will morph to "true" for what should be an error case. One option would be Ewww, that means it did return -ENOSYS before any of this. > to have eventfd_signal_mask() return 0/-errno instead of the count, but looking > at all the callers, nothing ever actually consumes the result. > > KVMGT morphs failure into -EFAULT > > if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger, 1) != 1) > return -EFAULT; > > but the only caller of that user ignores the return value. > > if (vgpu_vreg(vgpu, i915_mmio_reg_offset(GEN8_MASTER_IRQ)) > & ~GEN8_MASTER_IRQ_CONTROL) > inject_virtual_interrupt(vgpu); > > The sample driver in samples/vfio-mdev/mtty.c uses a similar pattern: prints an > error but otherwise ignores the result. > > So why not return nothing? That will simplify eventfd_signal_mask() a wee bit > more, and eliminate that bizarre return value confusion for the ugly stubs, e.g. Yeah, it used to return an int in the non-eventfd and a __u64 in the eventfd case. > > void eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned mask) > { > unsigned long flags; > > /* > * Deadlock or stack overflow issues can happen if we recurse here > * through waitqueue wakeup handlers. If the caller users potentially > * nested waitqueues with custom wakeup handlers, then it should > * check eventfd_signal_allowed() before calling this function. If > * it returns false, the eventfd_signal() call should be deferred to a > * safe context. > */ > if (WARN_ON_ONCE(current->in_eventfd)) > return; > > spin_lock_irqsave(&ctx->wqh.lock, flags); > current->in_eventfd = 1; > if (ctx->count < ULLONG_MAX) > ctx->count++; > if (waitqueue_active(&ctx->wqh)) > wake_up_locked_poll(&ctx->wqh, EPOLLIN | mask); > current->in_eventfd = 0; > spin_unlock_irqrestore(&ctx->wqh.lock, flags); > } > > You could even go further and unify the real and stub versions of eventfd_signal(). The reason I didn't make eventfd_signal_mask() return void was that it was called from eventfd_signal() which did, I didn't realize the caller didn't actually consume the return value. If we can let both return void it gets simpler. Thanks for that. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 0/2] eventfd: simplify signal helpers 2023-07-13 10:05 [PATCH 0/2] eventfd: simplify signal helpers Christian Brauner 2023-07-13 10:05 ` [PATCH 1/2] eventfd: simplify eventfd_signal() Christian Brauner 2023-07-13 10:05 ` [PATCH 2/2] eventfd: simplify eventfd_signal_mask() Christian Brauner @ 2023-07-13 17:10 ` Alex Williamson 2 siblings, 0 replies; 17+ messages in thread From: Alex Williamson @ 2023-07-13 17:10 UTC (permalink / raw) To: Christian Brauner Cc: linux-fsdevel, linux-aio, linux-usb, Matthew Rosato, Paul Durrant, Tom Rix, Jason Wang, dri-devel, Michal Hocko, linux-mm, Kirti Wankhede, Paolo Bonzini, Jens Axboe, Vineeth Vijayan, Diana Craciun, Alexander Gordeev, Xuan Zhuo, Shakeel Butt, Vasily Gorbik, Leon Romanovsky, Harald Freudenberger, Fei Li, x86, Roman Gushchin, Halil Pasic, Jason Gunthorpe, Ingo Molnar, intel-gfx, Christian Borntraeger, linux-fpga, Zhi Wang, Wu Hao, Jason Herne, Eric Farman, Dave Hansen, Andrew Donnellan, Arnd Bergmann, linux-s390, Heiko Carstens, Johannes Weiner, linuxppc-dev, Eric Auger, Borislav Petkov, kvm, Rodrigo Vivi, cgroups, Thomas Gleixner, virtualization, intel-gvt-dev, io-uring, netdev, Tony Krowiak, Tvrtko Ursulin, Pavel Begunkov, Sean Christopherson, Oded Gabbay, Muchun Song, Peter Oberparleiter, linux-kernel, linux-rdma, Benjamin LaHaise, Michael S. Tsirkin, Sven Schnelle, Greg Kroah-Hartman, Frederic Barrat, Moritz Fischer, Vitaly Kuznetsov, David Woodhouse, Xu Yilun, jaz On Thu, 13 Jul 2023 12:05:36 +0200 Christian Brauner <brauner@kernel.org> wrote: > Hey everyone, > > This simplifies the eventfd_signal() and eventfd_signal_mask() helpers > by removing the count argument which is effectively unused. We have a patch under review which does in fact make use of the signaling value: https://lore.kernel.org/all/20230630155936.3015595-1-jaz@semihalf.com/ Thanks, Alex ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v6] vfio/pci: Propagate ACPI notifications to user-space via eventfd
@ 2023-06-30 15:59 Grzegorz Jaszczyk
2023-07-14 7:05 ` [PATCH 0/2] eventfd: simplify signal helpers Christian Brauner
0 siblings, 1 reply; 17+ messages in thread
From: Grzegorz Jaszczyk @ 2023-06-30 15:59 UTC (permalink / raw)
To: linux-kernel, alex.williamson
Cc: dmy, tn, dbehr, dbehr, upstream, dtor, jgg, kevin.tian, cohuck,
abhsahu, yishaih, yi.l.liu, kvm, libvir-list, pmorel,
borntraeger, mjrosato, Grzegorz Jaszczyk
To allow pass-through devices receiving ACPI notifications, permit to
register ACPI notify handler (via VFIO_DEVICE_SET_IRQS) for a given
device. The handler role is to receive and propagate such ACPI
notifications to the user-space through the user provided eventfd. This
allows VMM to receive and propagate them further to the VM, where the
actual driver for pass-through device resides and can react to device
specific notifications accordingly.
The eventfd usage ensures VMM and device isolation: it allows to use a
dedicated channel associated with the device for such events, such that
the VMM has direct access.
Since the eventfd counter is used as ACPI notification value
placeholder, the eventfd signaling needs to be serialized in order to
not end up with notification values being coalesced. Therefore ACPI
notification values are buffered and signalized one by one, when the
previous notification value has been consumed.
Signed-off-by: Grzegorz Jaszczyk <jaz@semihalf.com>
---
Changelog v5..v6
- Get rid of #if IS_ENABLED(CONFIG_ACPI) from vfio_pci_intrs.c
- There is no need to keep vfio_acpi_notification struct definition in
header, make it private and move to cpi_notify.c
- Add lockdep_asserts in acpi_notification_dequeue
- notification_list_lock was not initialized which triggers some
warning with CONFIG_DEBUG_MUTEXES enabled (it was not logical error
since mentioned mutex was zeroed thanks to kzalloc it is just
DEBUG_MUTEXES performs extra checks and sets lock->magic).
- Change notification_lock from mutex to semaphore (notification_sem).
The logic was working fine with the mutex but enabling lockdep support
made me realize that the mutex has to be released by the same task
which acquires it and it is checked with lockdep enabled. Semaphore
does not have such a restriction.
- In order to correctly handle some sequences such as:
* user configures a notification eventfd
* a notification fires
* the user closes the eventfd without reading it, and then tries
to swap in a different eventfd ctx
separate the entire eventfd context together with notification_sem
from the main vfio_acpi_notification struct. Thanks to that entire,
separate eventfd ctx could be swapped leaving the previous eventfd ctx
untouched. The new eventfd has its separate notification_sem
initialized and will not depend on previous eventfd ctx. Additionally
when the last handle to old eventfd will be released and EPOLLHUP
triggered, old eventfd ctx will be cleaned-up.
- Together with the above add support for required EPOLLHUP handling.
- Add missing fput invocations.
- Move some common code into vfio_acpi_eventfd_init and use it during
registration and eventfd swapping.
- v5: https://patchwork.kernel.org/project/kvm/patch/20230609133950.2197552-1-jaz@semihalf.com/
Changelog v4..v5
Address Alex Williamson's feedback:
- s/vfio_acpi_notify.{c,o}/acpi_notify.{c,o}
- Do not put acpi_notify to its own module but fold it into main
vfio.ko. Additionally select it from VFIO_PCI_CORE instead of VFIO_PCI.
- Cleanup acpi notify under igate mutex (in vfio_pci_core_close_device).
- Add extra check for ACPI companion in vfio_pci_get_irq_count and
extend vfio_pci_ioctl_get_irq_info.
- Drop acpi.h include - linux/vfio_acpi_notify.h includes it already.
- Send device check notification value for DATA_NONE and non-zero count
and for DATA_BOOL and non-zero count (as for loopback testing).
- Drop some redundant !acpi_notify->acpi_notify_trigger checks.
- Move some common code to new helper functions:
1) acpi_notification_dequeue
2) vfio_acpi_notify_cleanup and rename previous
vfio_acpi_notify_cleanup into vfio_remove_acpi_notify which uses it
- Add rate limited logging for dropped notifications.
- Move vdev->acpi_notification pointer cleanup to the
vfio_acpi_notify_cleanup function this also fixes two bigger issues
caught by Alex.
- Allow the eventfd to be swapped.
- s/GFP_KERNEL/GFP_KERNEL_ACCOUNT.
- s/VFIO_PCI_ACPI_NTFY_IRQ_INDEX/VFIO_PCI_ACPI_IRQ_INDEX.
- Add header protection for multiple includes.
- v4: https://patchwork.kernel.org/project/kvm/patch/20230522165811.123417-1-jaz@semihalf.com/
Changelog v3..v4
Address Alex Williamson feedback:
- Instead of introducing new ioctl used for eventfd registration, take
advantage of VFIO_DEVICE_SET_IRQS which already supports virtual IRQs
for things like error notification and device release requests.
- Introduced mechanism preventing creation of large queues.
Other:
- Move the implementation into the newly introduced VFIO_ACPI_NOTIFY
helper module. It is actually not bound to VFIO_PCI but VFIO_PCI
enables it whenever ACPI support is enabled. This change is introduced
since ACPI notifications are not limited to PCI devices, making it PCI
independent will allow to re-use it also for other VFIO_* like
supports: e.g. VFIO_PLATFORM in the future if needed. Moving it out of
drivers/vfio/pci/ was also suggested offline.
- s/notify_val_next/node
- v3: https://patchwork.kernel.org/project/kvm/patch/20230502132700.654528-1-jaszczyk@google.com/
Changelog v2..v3:
- Fix compilation warnings when building with "W=1"
Changelog v1..v2:
- The v2 implementation is actually completely different then v1:
instead of using acpi netlink events for propagating ACPI
notifications to the user space take advantage of eventfd, which can
provide better VMM and device isolation: it allows to use a dedicated
channel associated with the device for such events, such that the VMM
has direct access.
- Using eventfd counter as notification value placeholder was suggested
in v1 and requires additional serialization logic introduced in v2.
- Since the vfio-pci supports non-ACPI platforms address !CONFIG_ACPI
case.
- v1 discussion: https://patchwork.kernel.org/project/kvm/patch/20230307220553.631069-1-jaz@semihalf.com/
---
drivers/vfio/Kconfig | 5 +
drivers/vfio/Makefile | 1 +
drivers/vfio/acpi_notify.c | 324 ++++++++++++++++++++++++++++++
drivers/vfio/pci/Kconfig | 1 +
drivers/vfio/pci/vfio_pci_core.c | 13 ++
drivers/vfio/pci/vfio_pci_intrs.c | 80 ++++++++
include/linux/vfio_acpi_notify.h | 36 ++++
include/linux/vfio_pci_core.h | 1 +
include/uapi/linux/vfio.h | 1 +
9 files changed, 462 insertions(+)
create mode 100644 drivers/vfio/acpi_notify.c
create mode 100644 include/linux/vfio_acpi_notify.h
diff --git a/drivers/vfio/Kconfig b/drivers/vfio/Kconfig
index 89e06c981e43..cd9df43a4eb4 100644
--- a/drivers/vfio/Kconfig
+++ b/drivers/vfio/Kconfig
@@ -12,6 +12,11 @@ menuconfig VFIO
If you don't know what to do here, say N.
if VFIO
+config VFIO_ACPI_NOTIFY
+ bool
+ depends on ACPI
+ default n
+
config VFIO_CONTAINER
bool "Support for the VFIO container /dev/vfio/vfio"
select VFIO_IOMMU_TYPE1 if MMU && (X86 || S390 || ARM || ARM64)
diff --git a/drivers/vfio/Makefile b/drivers/vfio/Makefile
index 70e7dcb302ef..003c2b041785 100644
--- a/drivers/vfio/Makefile
+++ b/drivers/vfio/Makefile
@@ -7,6 +7,7 @@ vfio-y += vfio_main.o \
vfio-$(CONFIG_IOMMUFD) += iommufd.o
vfio-$(CONFIG_VFIO_CONTAINER) += container.o
vfio-$(CONFIG_VFIO_VIRQFD) += virqfd.o
+vfio-$(CONFIG_VFIO_ACPI_NOTIFY) += acpi_notify.o
obj-$(CONFIG_VFIO_IOMMU_TYPE1) += vfio_iommu_type1.o
obj-$(CONFIG_VFIO_IOMMU_SPAPR_TCE) += vfio_iommu_spapr_tce.o
diff --git a/drivers/vfio/acpi_notify.c b/drivers/vfio/acpi_notify.c
new file mode 100644
index 000000000000..b78c33077dfa
--- /dev/null
+++ b/drivers/vfio/acpi_notify.c
@@ -0,0 +1,324 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * VFIO ACPI notification propagation
+ *
+ * Author: Grzegorz Jaszczyk <jaz@semihalf.com>
+ */
+#include <linux/file.h>
+#include <linux/semaphore.h>
+#include <linux/vfio_acpi_notify.h>
+
+#define NOTIFICATION_QUEUE_SIZE 20
+
+struct acpi_eventfd_ctx {
+ struct eventfd_ctx *acpi_notify_trigger;
+ struct file *acpi_notify_trigger_file;
+ struct semaphore notification_sem;
+ struct work_struct acpi_notification_work;
+ wait_queue_entry_t wait;
+ poll_table pt;
+ struct vfio_acpi_notification *acpi_notify;
+};
+
+struct vfio_acpi_notification {
+ struct acpi_eventfd_ctx *acpi_eventfd;
+ struct list_head notification_list;
+ struct mutex notification_list_lock;
+ int notification_queue_count;
+};
+
+struct notification_queue {
+ int notification_val;
+ struct list_head node;
+};
+
+static int vfio_eventfd_wakeup(wait_queue_entry_t *wait, unsigned int mode,
+ int sync, void *key)
+{
+ struct acpi_eventfd_ctx *acpi_eventfdctx =
+ container_of(wait, struct acpi_eventfd_ctx, wait);
+ __poll_t flags = key_to_poll(key);
+
+ /*
+ * eventfd_read signalize EPOLLOUT at the end of its function - this
+ * means previous eventfd with its notification value was consumed so
+ * the next notification can be signalized now if pending - schedule
+ * proper work.
+ */
+ if (flags & EPOLLOUT) {
+ up(&acpi_eventfdctx->notification_sem);
+
+ schedule_work(&acpi_eventfdctx->acpi_notification_work);
+ }
+
+ /*
+ * Even if the eventfd is closed lets still queue notifications so they
+ * can be replicated when new eventfd is registered (see "Allow eventfd
+ * to be swapped").
+ *
+ * Below will be reached only in case user closes eventfd and then
+ * trigger eventfd swap (or vice-versa).
+ */
+ if (flags & EPOLLHUP) {
+ /*
+ * eventfd_release after signalling EPOLLHUP calls eventfd_ctx_put
+ * so no need to do it here.
+ */
+
+ kfree(acpi_eventfdctx);
+ }
+
+ return 0;
+}
+
+static void vfio_ptable_queue_proc(struct file *file,
+ wait_queue_head_t *wqh, poll_table *pt)
+{
+ struct acpi_eventfd_ctx *acpi_eventfdctx =
+ container_of(pt, struct acpi_eventfd_ctx, pt);
+
+ add_wait_queue(wqh, &acpi_eventfdctx->wait);
+}
+
+static struct notification_queue *
+acpi_notification_dequeue(struct vfio_acpi_notification *acpi_notify)
+{
+ struct notification_queue *oldest_entry;
+
+ lockdep_assert_held(&acpi_notify->notification_list_lock);
+
+ oldest_entry = list_first_entry(&acpi_notify->notification_list,
+ struct notification_queue,
+ node);
+ list_del(&oldest_entry->node);
+ acpi_notify->notification_queue_count--;
+
+ return oldest_entry;
+}
+
+static void acpi_notification_work_fn(struct work_struct *work)
+{
+ struct acpi_eventfd_ctx *acpi_eventfdctx;
+ struct vfio_acpi_notification *acpi_notify;
+ struct notification_queue *entry;
+
+ acpi_eventfdctx = container_of(work, struct acpi_eventfd_ctx,
+ acpi_notification_work);
+
+ acpi_notify = acpi_eventfdctx->acpi_notify;
+
+ mutex_lock(&acpi_notify->notification_list_lock);
+ if (list_empty(&acpi_notify->notification_list))
+ goto out;
+
+ /*
+ * If the previous eventfd was not yet consumed by user-space lets hold
+ * on and exit. The notification function will be rescheduled when
+ * signaling eventfd will be possible (when the EPOLLOUT will be
+ * signalized and unlocks notify_events or when eventfd will be swapped).
+ */
+ if (down_trylock(&acpi_eventfdctx->notification_sem))
+ goto out;
+
+ entry = acpi_notification_dequeue(acpi_notify);
+
+ mutex_unlock(&acpi_notify->notification_list_lock);
+
+ eventfd_signal(acpi_eventfdctx->acpi_notify_trigger, entry->notification_val);
+
+ kfree(entry);
+
+ return;
+out:
+ mutex_unlock(&acpi_notify->notification_list_lock);
+}
+
+static void
+vfio_acpi_notify_cleanup(struct vfio_acpi_notification **acpi_notify_ptr,
+ struct acpi_device *adev)
+{
+ struct vfio_acpi_notification *acpi_notify = *acpi_notify_ptr;
+ struct acpi_eventfd_ctx *acpi_eventfd = acpi_notify->acpi_eventfd;
+ struct notification_queue *entry, *entry_tmp;
+ u64 cnt;
+
+ eventfd_ctx_remove_wait_queue(acpi_eventfd->acpi_notify_trigger,
+ &acpi_eventfd->wait, &cnt);
+
+ flush_work(&acpi_eventfd->acpi_notification_work);
+
+ mutex_lock(&acpi_notify->notification_list_lock);
+ list_for_each_entry_safe(entry, entry_tmp,
+ &acpi_notify->notification_list,
+ node) {
+ list_del(&entry->node);
+ kfree(entry);
+ }
+ mutex_unlock(&acpi_notify->notification_list_lock);
+
+ eventfd_ctx_put(acpi_eventfd->acpi_notify_trigger);
+
+ /*
+ * fput releases references to eventfd file but it will not trigger the
+ * vfio_eventfd_wakeup with EPOLLHUP since eventfd_ctx_remove_wait_queue
+ * was already called and removed wq entry (wait) from the eventfd
+ * wq head.
+ */
+ fput(acpi_eventfd->acpi_notify_trigger_file);
+
+ kfree(acpi_notify->acpi_eventfd);
+ kfree(acpi_notify);
+
+ *acpi_notify_ptr = NULL;
+}
+
+static void vfio_acpi_notify_handler(acpi_handle handle, u32 event, void *data)
+{
+ struct vfio_acpi_notification *acpi_notify = (struct vfio_acpi_notification *)data;
+ struct notification_queue *entry;
+
+ entry = kmalloc(sizeof(*entry), GFP_KERNEL);
+ if (!entry)
+ return;
+
+ entry->notification_val = event;
+ INIT_LIST_HEAD(&entry->node);
+
+ mutex_lock(&acpi_notify->notification_list_lock);
+ if (acpi_notify->notification_queue_count > NOTIFICATION_QUEUE_SIZE) {
+ struct notification_queue *oldest_entry =
+ acpi_notification_dequeue(acpi_notify);
+
+ if (printk_ratelimit())
+ acpi_handle_warn(handle,
+ "dropping notification value %d\n",
+ oldest_entry->notification_val);
+
+ kfree(oldest_entry);
+ }
+ list_add_tail(&entry->node, &acpi_notify->notification_list);
+ acpi_notify->notification_queue_count++;
+ mutex_unlock(&acpi_notify->notification_list_lock);
+
+ schedule_work(&acpi_notify->acpi_eventfd->acpi_notification_work);
+}
+
+void vfio_acpi_notify(struct acpi_device *adev, u32 event, void *data)
+{
+ acpi_handle handle = adev->handle;
+
+ vfio_acpi_notify_handler(handle, event, data);
+}
+EXPORT_SYMBOL_GPL(vfio_acpi_notify);
+
+void vfio_remove_acpi_notify(struct vfio_acpi_notification **acpi_notify_ptr,
+ struct acpi_device *adev)
+{
+ struct vfio_acpi_notification *acpi_notify = *acpi_notify_ptr;
+
+ if (!acpi_notify)
+ return;
+
+ acpi_remove_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY,
+ vfio_acpi_notify_handler);
+
+ vfio_acpi_notify_cleanup(acpi_notify_ptr, adev);
+}
+EXPORT_SYMBOL_GPL(vfio_remove_acpi_notify);
+
+static void vfio_acpi_eventfd_init(struct vfio_acpi_notification *acpi_notify,
+ struct eventfd_ctx *efdctx, int32_t fd)
+{
+ struct acpi_eventfd_ctx *acpi_eventfd;
+
+ acpi_eventfd = kzalloc(sizeof(struct acpi_eventfd_ctx), GFP_KERNEL_ACCOUNT);
+
+ INIT_WORK(&acpi_eventfd->acpi_notification_work, acpi_notification_work_fn);
+ acpi_eventfd->acpi_notify_trigger = efdctx;
+
+ sema_init(&acpi_eventfd->notification_sem, 1);
+
+ /*
+ * Install custom wake-up handler to be notified whenever underlying
+ * eventfd is consumed by the user-space.
+ */
+ init_waitqueue_func_entry(&acpi_eventfd->wait, vfio_eventfd_wakeup);
+ init_poll_funcptr(&acpi_eventfd->pt, vfio_ptable_queue_proc);
+
+ acpi_eventfd->acpi_notify_trigger_file = eventfd_fget(fd);
+ vfs_poll(acpi_eventfd->acpi_notify_trigger_file, &acpi_eventfd->pt);
+
+ acpi_eventfd->acpi_notify = acpi_notify;
+ acpi_notify->acpi_eventfd = acpi_eventfd;
+}
+
+int vfio_register_acpi_notify_handler(struct vfio_acpi_notification **acpi_notify_ptr,
+ struct acpi_device *adev, int32_t fd)
+{
+ struct vfio_acpi_notification *acpi_notify = *acpi_notify_ptr;
+ struct eventfd_ctx *efdctx;
+ acpi_status status;
+
+ if (fd < -1)
+ return -EINVAL;
+ else if (fd == -1) {
+ vfio_remove_acpi_notify(acpi_notify_ptr, adev);
+ return 0;
+ }
+
+ efdctx = eventfd_ctx_fdget(fd);
+ if (IS_ERR(efdctx))
+ return PTR_ERR(efdctx);
+
+ /* Allow eventfd to be swapped */
+ if (acpi_notify) {
+ struct file *trigger_file_before_swap =
+ acpi_notify->acpi_eventfd->acpi_notify_trigger_file;
+
+ /*
+ * Lets allocate new acpi_eventfd_ctx, the previous is
+ * alive until eventfd is closed.
+ */
+ vfio_acpi_eventfd_init(acpi_notify, efdctx, fd);
+
+ /*
+ * The ACPI notifications could arrive and be queued during
+ * eventfd swap, retrigger the worker after notification
+ * replication unlocking.
+ */
+ schedule_work(&acpi_notify->acpi_eventfd->acpi_notification_work);
+
+ /*
+ * If the last reference to acpi_notify_trigger_file was
+ * released, the EPOLLHUP will be handled (but not immediately
+ * since fput is async).
+ */
+ fput(trigger_file_before_swap);
+
+ return 0;
+ }
+
+ acpi_notify = kzalloc(sizeof(*acpi_notify), GFP_KERNEL_ACCOUNT);
+ if (!acpi_notify)
+ return -ENOMEM;
+
+ *acpi_notify_ptr = acpi_notify;
+ mutex_init(&acpi_notify->notification_list_lock);
+ INIT_LIST_HEAD(&acpi_notify->notification_list);
+
+ vfio_acpi_eventfd_init(acpi_notify, efdctx, fd);
+
+ status = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY,
+ vfio_acpi_notify_handler, (void *)acpi_notify);
+ if (ACPI_FAILURE(status)) {
+ dev_err(&adev->dev, "Failed to install notify handler: %s",
+ acpi_format_exception(status));
+
+ vfio_acpi_notify_cleanup(acpi_notify_ptr, adev);
+
+ return -ENODEV;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(vfio_register_acpi_notify_handler);
diff --git a/drivers/vfio/pci/Kconfig b/drivers/vfio/pci/Kconfig
index f9d0c908e738..f03ca773dfd9 100644
--- a/drivers/vfio/pci/Kconfig
+++ b/drivers/vfio/pci/Kconfig
@@ -4,6 +4,7 @@ config VFIO_PCI_CORE
tristate
select VFIO_VIRQFD
select IRQ_BYPASS_MANAGER
+ select VFIO_ACPI_NOTIFY if ACPI
config VFIO_PCI_MMAP
def_bool y if !S390
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index a5ab416cf476..1cc4a9c05403 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -27,6 +27,7 @@
#include <linux/vgaarb.h>
#include <linux/nospec.h>
#include <linux/sched/mm.h>
+#include <linux/vfio_acpi_notify.h>
#if IS_ENABLED(CONFIG_EEH)
#include <asm/eeh.h>
#endif
@@ -683,6 +684,7 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev)
{
struct vfio_pci_core_device *vdev =
container_of(core_vdev, struct vfio_pci_core_device, vdev);
+ struct acpi_device *adev = ACPI_COMPANION(&vdev->pdev->dev);
if (vdev->sriov_pf_core_dev) {
mutex_lock(&vdev->sriov_pf_core_dev->vf_token->lock);
@@ -704,6 +706,8 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev)
eventfd_ctx_put(vdev->req_trigger);
vdev->req_trigger = NULL;
}
+ if (adev)
+ vfio_remove_acpi_notify(&vdev->acpi_notification, adev);
mutex_unlock(&vdev->igate);
}
EXPORT_SYMBOL_GPL(vfio_pci_core_close_device);
@@ -725,6 +729,8 @@ EXPORT_SYMBOL_GPL(vfio_pci_core_finish_enable);
static int vfio_pci_get_irq_count(struct vfio_pci_core_device *vdev, int irq_type)
{
+ struct acpi_device *adev = ACPI_COMPANION(&vdev->pdev->dev);
+
if (irq_type == VFIO_PCI_INTX_IRQ_INDEX) {
u8 pin;
@@ -761,6 +767,8 @@ static int vfio_pci_get_irq_count(struct vfio_pci_core_device *vdev, int irq_typ
return 1;
} else if (irq_type == VFIO_PCI_REQ_IRQ_INDEX) {
return 1;
+ } else if (adev && irq_type == VFIO_PCI_ACPI_IRQ_INDEX) {
+ return 1;
}
return 0;
@@ -1084,6 +1092,7 @@ static int vfio_pci_ioctl_get_irq_info(struct vfio_pci_core_device *vdev,
struct vfio_irq_info __user *arg)
{
unsigned long minsz = offsetofend(struct vfio_irq_info, count);
+ struct acpi_device *adev = ACPI_COMPANION(&vdev->pdev->dev);
struct vfio_irq_info info;
if (copy_from_user(&info, arg, minsz))
@@ -1096,6 +1105,10 @@ static int vfio_pci_ioctl_get_irq_info(struct vfio_pci_core_device *vdev,
case VFIO_PCI_INTX_IRQ_INDEX ... VFIO_PCI_MSIX_IRQ_INDEX:
case VFIO_PCI_REQ_IRQ_INDEX:
break;
+ case VFIO_PCI_ACPI_IRQ_INDEX:
+ if (adev)
+ break;
+ return -EINVAL;
case VFIO_PCI_ERR_IRQ_INDEX:
if (pci_is_pcie(vdev->pdev))
break;
diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
index bffb0741518b..27d0c4cdc3c9 100644
--- a/drivers/vfio/pci/vfio_pci_intrs.c
+++ b/drivers/vfio/pci/vfio_pci_intrs.c
@@ -19,6 +19,7 @@
#include <linux/vfio.h>
#include <linux/wait.h>
#include <linux/slab.h>
+#include <linux/vfio_acpi_notify.h>
#include "vfio_pci_priv.h"
@@ -667,6 +668,71 @@ static int vfio_pci_set_req_trigger(struct vfio_pci_core_device *vdev,
count, flags, data);
}
+static int
+vfio_pci_set_acpi_ntfy_trigger(struct vfio_pci_core_device *vdev,
+ unsigned int index, unsigned int start,
+ unsigned int count, uint32_t flags, void *data)
+{
+ struct acpi_device *adev = ACPI_COMPANION(&vdev->pdev->dev);
+
+ if (index != VFIO_PCI_ACPI_IRQ_INDEX || start != 0 || count > 1)
+ return -EINVAL;
+
+ if (!adev)
+ return -ENODEV;
+
+ if (!vdev->acpi_notification)
+ return -EINVAL;
+
+ /*
+ * Disable notifications: flags = (DATA_NONE|ACTION_TRIGGER), count = 0
+ * Enable loopback testing: (DATA_BOOL|ACTION_TRIGGER) or
+ * (DATA_NONE|ACTION_TRIGGER), count != 0
+ */
+ if (flags & VFIO_IRQ_SET_DATA_NONE) {
+ if (count)
+ vfio_acpi_notify(adev, ACPI_NOTIFY_DEVICE_CHECK,
+ vdev->acpi_notification);
+ else
+ vfio_remove_acpi_notify(&vdev->acpi_notification, adev);
+
+ return 0;
+ } else if (flags & VFIO_IRQ_SET_DATA_BOOL) {
+ uint8_t trigger;
+
+ if (!count)
+ return -EINVAL;
+
+ trigger = *(uint8_t *)data;
+ if (trigger)
+ vfio_acpi_notify(adev, ACPI_NOTIFY_DEVICE_CHECK,
+ vdev->acpi_notification);
+
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
+static int
+vfio_pci_set_acpi_ntfy_eventfd_trigger(struct vfio_pci_core_device *vdev,
+ unsigned int index, unsigned int start,
+ unsigned int count, uint32_t flags, void *data)
+{
+ struct acpi_device *adev = ACPI_COMPANION(&vdev->pdev->dev);
+ int32_t fd;
+
+ if (index != VFIO_PCI_ACPI_IRQ_INDEX || start != 0 || count != 1)
+ return -EINVAL;
+
+ if (!adev)
+ return -ENODEV;
+
+ fd = *(int32_t *)data;
+
+ return vfio_register_acpi_notify_handler(&vdev->acpi_notification, adev, fd);
+}
+
int vfio_pci_set_irqs_ioctl(struct vfio_pci_core_device *vdev, uint32_t flags,
unsigned index, unsigned start, unsigned count,
void *data)
@@ -716,6 +782,20 @@ int vfio_pci_set_irqs_ioctl(struct vfio_pci_core_device *vdev, uint32_t flags,
break;
}
break;
+ case VFIO_PCI_ACPI_IRQ_INDEX:
+ switch (flags & VFIO_IRQ_SET_ACTION_TYPE_MASK) {
+ case VFIO_IRQ_SET_ACTION_TRIGGER:
+ switch (flags & VFIO_IRQ_SET_DATA_TYPE_MASK) {
+ case VFIO_IRQ_SET_DATA_BOOL:
+ case VFIO_IRQ_SET_DATA_NONE:
+ func = vfio_pci_set_acpi_ntfy_trigger;
+ break;
+ case VFIO_IRQ_SET_DATA_EVENTFD:
+ func = vfio_pci_set_acpi_ntfy_eventfd_trigger;
+ break;
+ }
+ }
+ break;
}
if (!func)
diff --git a/include/linux/vfio_acpi_notify.h b/include/linux/vfio_acpi_notify.h
new file mode 100644
index 000000000000..e29e4274d192
--- /dev/null
+++ b/include/linux/vfio_acpi_notify.h
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * VFIO ACPI notification replication
+ *
+ * Author: Grzegorz Jaszczyk <jaz@semihalf.com>
+ */
+#include <linux/acpi.h>
+#include <linux/eventfd.h>
+#include <linux/poll.h>
+
+#ifndef VFIO_ACPI_NOTIFY_H
+#define VFIO_ACPI_NOTIFY_H
+
+struct vfio_acpi_notification;
+
+#if IS_ENABLED(CONFIG_ACPI)
+void vfio_acpi_notify(struct acpi_device *adev, u32 event, void *data);
+int vfio_register_acpi_notify_handler(struct vfio_acpi_notification **acpi_notify,
+ struct acpi_device *adev, int32_t fd);
+void vfio_remove_acpi_notify(struct vfio_acpi_notification **acpi_notify,
+ struct acpi_device *adev);
+#else
+static inline void vfio_acpi_notify(struct acpi_device *adev, u32 event, void *data) {}
+static inline int
+vfio_register_acpi_notify_handler(struct vfio_acpi_notification **acpi_notify,
+ struct acpi_device *adev, int32_t fd)
+{
+ return -ENODEV;
+}
+
+static inline void
+vfio_remove_acpi_notify(struct vfio_acpi_notification **acpi_notify,
+ struct acpi_device *adev) {}
+#endif /* CONFIG_ACPI */
+
+#endif /* VFIO_ACPI_NOTIFY_H */
diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h
index 367fd79226a3..a4491b3d8064 100644
--- a/include/linux/vfio_pci_core.h
+++ b/include/linux/vfio_pci_core.h
@@ -96,6 +96,7 @@ struct vfio_pci_core_device {
struct mutex vma_lock;
struct list_head vma_list;
struct rw_semaphore memory_lock;
+ struct vfio_acpi_notification *acpi_notification;
};
/* Will be exported for vfio pci drivers usage */
diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
index b71276bd7f91..ee8ba6354662 100644
--- a/include/uapi/linux/vfio.h
+++ b/include/uapi/linux/vfio.h
@@ -625,6 +625,7 @@ enum {
VFIO_PCI_MSIX_IRQ_INDEX,
VFIO_PCI_ERR_IRQ_INDEX,
VFIO_PCI_REQ_IRQ_INDEX,
+ VFIO_PCI_ACPI_IRQ_INDEX,
VFIO_PCI_NUM_IRQS
};
--
2.41.0.255.g8b1d071c50-goog
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: [PATCH 0/2] eventfd: simplify signal helpers 2023-06-30 15:59 [PATCH v6] vfio/pci: Propagate ACPI notifications to user-space via eventfd Grzegorz Jaszczyk @ 2023-07-14 7:05 ` Christian Brauner 2023-07-14 15:24 ` Jason Gunthorpe 2023-07-17 8:29 ` Grzegorz Jaszczyk 0 siblings, 2 replies; 17+ messages in thread From: Christian Brauner @ 2023-07-14 7:05 UTC (permalink / raw) To: Alex Williamson Cc: linux-fsdevel, linux-aio, linux-usb, Matthew Rosato, Paul Durrant, Tom Rix, Jason Wang, dri-devel, Michal Hocko, linux-mm, Kirti Wankhede, Paolo Bonzini, Jens Axboe, Vineeth Vijayan, Diana Craciun, Alexander Gordeev, Xuan Zhuo, Shakeel Butt, Vasily Gorbik, Leon Romanovsky, Harald Freudenberger, Fei Li, x86, Roman Gushchin, Halil Pasic, Jason Gunthorpe, Ingo Molnar, intel-gfx, Christian Borntraeger, linux-fpga, Zhi Wang, Wu Hao, Jason Herne, Eric Farman, Dave Hansen, Andrew Donnellan, Arnd Bergmann, linux-s390, Heiko Carstens, Johannes Weiner, linuxppc-dev, Eric Auger, Borislav Petkov, kvm, Rodrigo Vivi, cgroups, Thomas Gleixner, virtualization, intel-gvt-dev, io-uring, netdev, Tony Krowiak, Tvrtko Ursulin, Pavel Begunkov, Sean Christopherson, Oded Gabbay, Muchun Song, Peter Oberparleiter, linux-kernel, linux-rdma, Benjamin LaHaise, Michael S. Tsirkin, Sven Schnelle, Greg Kroah-Hartman, Frederic Barrat, Moritz Fischer, Vitaly Kuznetsov, David Woodhouse, Xu Yilun, jaz On Thu, Jul 13, 2023 at 11:10:54AM -0600, Alex Williamson wrote: > On Thu, 13 Jul 2023 12:05:36 +0200 > Christian Brauner <brauner@kernel.org> wrote: > > > Hey everyone, > > > > This simplifies the eventfd_signal() and eventfd_signal_mask() helpers > > by removing the count argument which is effectively unused. > > We have a patch under review which does in fact make use of the > signaling value: > > https://lore.kernel.org/all/20230630155936.3015595-1-jaz@semihalf.com/ Huh, thanks for the link. Quoting from https://patchwork.kernel.org/project/kvm/patch/20230307220553.631069-1-jaz@semihalf.com/#25266856 > Reading an eventfd returns an 8-byte value, we generally only use it > as a counter, but it's been discussed previously and IIRC, it's possible > to use that value as a notification value. So the goal is to pipe a specific value through eventfd? But it is explicitly a counter. The whole thing is written around a counter and each write and signal adds to the counter. The consequences are pretty well described in the cover letter of v6 https://lore.kernel.org/all/20230630155936.3015595-1-jaz@semihalf.com/ > Since the eventfd counter is used as ACPI notification value > placeholder, the eventfd signaling needs to be serialized in order to > not end up with notification values being coalesced. Therefore ACPI > notification values are buffered and signalized one by one, when the > previous notification value has been consumed. But isn't this a good indication that you really don't want an eventfd but something that's explicitly designed to associate specific data with a notification? Using eventfd in that manner requires serialization, buffering, and enforces ordering. I have no skin in the game aside from having to drop this conversion which I'm fine to do if there are actually users for this btu really, that looks a lot like abusing an api that really wasn't designed for this. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 0/2] eventfd: simplify signal helpers 2023-07-14 7:05 ` [PATCH 0/2] eventfd: simplify signal helpers Christian Brauner @ 2023-07-14 15:24 ` Jason Gunthorpe 2023-07-17 8:29 ` Grzegorz Jaszczyk 1 sibling, 0 replies; 17+ messages in thread From: Jason Gunthorpe @ 2023-07-14 15:24 UTC (permalink / raw) To: Christian Brauner Cc: Alex Williamson, linux-fsdevel, linux-aio, linux-usb, Matthew Rosato, Paul Durrant, Tom Rix, Jason Wang, dri-devel, Michal Hocko, linux-mm, Kirti Wankhede, Paolo Bonzini, Jens Axboe, Vineeth Vijayan, Diana Craciun, Alexander Gordeev, Xuan Zhuo, Shakeel Butt, Vasily Gorbik, Leon Romanovsky, Harald Freudenberger, Fei Li, x86, Roman Gushchin, Halil Pasic, Ingo Molnar, intel-gfx, Christian Borntraeger, linux-fpga, Zhi Wang, Wu Hao, Jason Herne, Eric Farman, Dave Hansen, Andrew Donnellan, Arnd Bergmann, linux-s390, Heiko Carstens, Johannes Weiner, linuxppc-dev, Eric Auger, Borislav Petkov, kvm, Rodrigo Vivi, cgroups, Thomas Gleixner, virtualization, intel-gvt-dev, io-uring, netdev, Tony Krowiak, Tvrtko Ursulin, Pavel Begunkov, Sean Christopherson, Oded Gabbay, Muchun Song, Peter Oberparleiter, linux-kernel, linux-rdma, Benjamin LaHaise, Michael S. Tsirkin, Sven Schnelle, Greg Kroah-Hartman, Frederic Barrat, Moritz Fischer, Vitaly Kuznetsov, David Woodhouse, Xu Yilun, jaz On Fri, Jul 14, 2023 at 09:05:21AM +0200, Christian Brauner wrote: > I have no skin in the game aside from having to drop this conversion > which I'm fine to do if there are actually users for this btu really, > that looks a lot like abusing an api that really wasn't designed for > this. Yeah, I think so too. The ACPI thing should use its own FD if it wants to feed actual data.. Jason ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 0/2] eventfd: simplify signal helpers 2023-07-14 7:05 ` [PATCH 0/2] eventfd: simplify signal helpers Christian Brauner 2023-07-14 15:24 ` Jason Gunthorpe @ 2023-07-17 8:29 ` Grzegorz Jaszczyk 2023-07-17 19:08 ` Alex Williamson 1 sibling, 1 reply; 17+ messages in thread From: Grzegorz Jaszczyk @ 2023-07-17 8:29 UTC (permalink / raw) To: Christian Brauner, Alex Williamson Cc: linux-fsdevel, linux-aio, linux-usb, Matthew Rosato, Paul Durrant, Tom Rix, Jason Wang, dri-devel, Michal Hocko, linux-mm, Kirti Wankhede, Paolo Bonzini, Jens Axboe, Vineeth Vijayan, Diana Craciun, Alexander Gordeev, Xuan Zhuo, Shakeel Butt, Vasily Gorbik, Leon Romanovsky, Harald Freudenberger, Fei Li, x86, Roman Gushchin, Halil Pasic, Jason Gunthorpe, Ingo Molnar, intel-gfx, Christian Borntraeger, linux-fpga, Zhi Wang, Wu Hao, Jason Herne, Eric Farman, Dave Hansen, Andrew Donnellan, Arnd Bergmann, linux-s390, Heiko Carstens, Johannes Weiner, linuxppc-dev, Eric Auger, Borislav Petkov, kvm, Rodrigo Vivi, cgroups, Thomas Gleixner, virtualization, intel-gvt-dev, io-uring, netdev, Tony Krowiak, Tvrtko Ursulin, Pavel Begunkov, Sean Christopherson, Oded Gabbay, Muchun Song, Peter Oberparleiter, linux-kernel, linux-rdma, Benjamin LaHaise, Michael S. Tsirkin, Sven Schnelle, Greg Kroah-Hartman, Frederic Barrat, Moritz Fischer, Vitaly Kuznetsov, David Woodhouse, Xu Yilun, Dominik Behr, Marcin Wojtas pt., 14 lip 2023 o 09:05 Christian Brauner <brauner@kernel.org> napisał(a): > > On Thu, Jul 13, 2023 at 11:10:54AM -0600, Alex Williamson wrote: > > On Thu, 13 Jul 2023 12:05:36 +0200 > > Christian Brauner <brauner@kernel.org> wrote: > > > > > Hey everyone, > > > > > > This simplifies the eventfd_signal() and eventfd_signal_mask() helpers > > > by removing the count argument which is effectively unused. > > > > We have a patch under review which does in fact make use of the > > signaling value: > > > > https://lore.kernel.org/all/20230630155936.3015595-1-jaz@semihalf.com/ > > Huh, thanks for the link. > > Quoting from > https://patchwork.kernel.org/project/kvm/patch/20230307220553.631069-1-jaz@semihalf.com/#25266856 > > > Reading an eventfd returns an 8-byte value, we generally only use it > > as a counter, but it's been discussed previously and IIRC, it's possible > > to use that value as a notification value. > > So the goal is to pipe a specific value through eventfd? But it is > explicitly a counter. The whole thing is written around a counter and > each write and signal adds to the counter. > > The consequences are pretty well described in the cover letter of > v6 https://lore.kernel.org/all/20230630155936.3015595-1-jaz@semihalf.com/ > > > Since the eventfd counter is used as ACPI notification value > > placeholder, the eventfd signaling needs to be serialized in order to > > not end up with notification values being coalesced. Therefore ACPI > > notification values are buffered and signalized one by one, when the > > previous notification value has been consumed. > > But isn't this a good indication that you really don't want an eventfd > but something that's explicitly designed to associate specific data with > a notification? Using eventfd in that manner requires serialization, > buffering, and enforces ordering. > > I have no skin in the game aside from having to drop this conversion > which I'm fine to do if there are actually users for this btu really, > that looks a lot like abusing an api that really wasn't designed for > this. https://patchwork.kernel.org/project/kvm/patch/20230307220553.631069-1-jaz@semihalf.com/ was posted at the beginig of March and one of the main things we've discussed was the mechanism for propagating acpi notification value. We've endup with eventfd as the best mechanism and have actually been using it from v2. I really do not want to waste this effort, I think we are quite advanced with v6 now. Additionally we didn't actually modify any part of eventfd support that was in place, we only used it in a specific (and discussed beforehand) way. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 0/2] eventfd: simplify signal helpers 2023-07-17 8:29 ` Grzegorz Jaszczyk @ 2023-07-17 19:08 ` Alex Williamson 2023-07-17 22:12 ` Jason Gunthorpe 0 siblings, 1 reply; 17+ messages in thread From: Alex Williamson @ 2023-07-17 19:08 UTC (permalink / raw) To: Grzegorz Jaszczyk Cc: Christian Brauner, linux-fsdevel, linux-aio, linux-usb, Matthew Rosato, Paul Durrant, Tom Rix, Jason Wang, dri-devel, Michal Hocko, linux-mm, Kirti Wankhede, Paolo Bonzini, Jens Axboe, Vineeth Vijayan, Diana Craciun, Alexander Gordeev, Xuan Zhuo, Shakeel Butt, Vasily Gorbik, Leon Romanovsky, Harald Freudenberger, Fei Li, x86, Roman Gushchin, Halil Pasic, Jason Gunthorpe, Ingo Molnar, intel-gfx, Christian Borntraeger, linux-fpga, Zhi Wang, Wu Hao, Jason Herne, Eric Farman, Dave Hansen, Andrew Donnellan, Arnd Bergmann, linux-s390, Heiko Carstens, Johannes Weiner, linuxppc-dev, Eric Auger, Borislav Petkov, kvm, Rodrigo Vivi, cgroups, Thomas Gleixner, virtualization, intel-gvt-dev, io-uring, netdev, Tony Krowiak, Tvrtko Ursulin, Pavel Begunkov, Sean Christopherson, Oded Gabbay, Muchun Song, Peter Oberparleiter, linux-kernel, linux-rdma, Benjamin LaHaise, Michael S. Tsirkin, Sven Schnelle, Greg Kroah-Hartman, Frederic Barrat, Moritz Fischer, Vitaly Kuznetsov, David Woodhouse, Xu Yilun, Dominik Behr, Marcin Wojtas On Mon, 17 Jul 2023 10:29:34 +0200 Grzegorz Jaszczyk <jaz@semihalf.com> wrote: > pt., 14 lip 2023 o 09:05 Christian Brauner <brauner@kernel.org> napisał(a): > > > > On Thu, Jul 13, 2023 at 11:10:54AM -0600, Alex Williamson wrote: > > > On Thu, 13 Jul 2023 12:05:36 +0200 > > > Christian Brauner <brauner@kernel.org> wrote: > > > > > > > Hey everyone, > > > > > > > > This simplifies the eventfd_signal() and eventfd_signal_mask() helpers > > > > by removing the count argument which is effectively unused. > > > > > > We have a patch under review which does in fact make use of the > > > signaling value: > > > > > > https://lore.kernel.org/all/20230630155936.3015595-1-jaz@semihalf.com/ > > > > Huh, thanks for the link. > > > > Quoting from > > https://patchwork.kernel.org/project/kvm/patch/20230307220553.631069-1-jaz@semihalf.com/#25266856 > > > > > Reading an eventfd returns an 8-byte value, we generally only use it > > > as a counter, but it's been discussed previously and IIRC, it's possible > > > to use that value as a notification value. > > > > So the goal is to pipe a specific value through eventfd? But it is > > explicitly a counter. The whole thing is written around a counter and > > each write and signal adds to the counter. > > > > The consequences are pretty well described in the cover letter of > > v6 https://lore.kernel.org/all/20230630155936.3015595-1-jaz@semihalf.com/ > > > > > Since the eventfd counter is used as ACPI notification value > > > placeholder, the eventfd signaling needs to be serialized in order to > > > not end up with notification values being coalesced. Therefore ACPI > > > notification values are buffered and signalized one by one, when the > > > previous notification value has been consumed. > > > > But isn't this a good indication that you really don't want an eventfd > > but something that's explicitly designed to associate specific data with > > a notification? Using eventfd in that manner requires serialization, > > buffering, and enforces ordering. What would that mechanism be? We've been iterating on getting the serialization and buffering correct, but I don't know of another means that combines the notification with a value, so we'd likely end up with an eventfd only for notification and a separate ring buffer for notification values. As this series demonstrates, the current in-kernel users only increment the counter and most userspace likely discards the counter value, which makes the counter largely a waste. While perhaps unconventional, there's no requirement that the counter may only be incremented by one, nor any restriction that I see in how userspace must interpret the counter value. As I understand the ACPI notification proposal that Grzegorz links below, a notification with an interpreted value allows for a more direct userspace implementation when dealing with a series of discrete notification with value events. Thanks, Alex > > I have no skin in the game aside from having to drop this conversion > > which I'm fine to do if there are actually users for this btu really, > > that looks a lot like abusing an api that really wasn't designed for > > this. > > https://patchwork.kernel.org/project/kvm/patch/20230307220553.631069-1-jaz@semihalf.com/ > was posted at the beginig of March and one of the main things we've > discussed was the mechanism for propagating acpi notification value. > We've endup with eventfd as the best mechanism and have actually been > using it from v2. I really do not want to waste this effort, I think > we are quite advanced with v6 now. Additionally we didn't actually > modify any part of eventfd support that was in place, we only used it > in a specific (and discussed beforehand) way. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 0/2] eventfd: simplify signal helpers 2023-07-17 19:08 ` Alex Williamson @ 2023-07-17 22:12 ` Jason Gunthorpe 2023-07-17 22:52 ` Alex Williamson 0 siblings, 1 reply; 17+ messages in thread From: Jason Gunthorpe @ 2023-07-17 22:12 UTC (permalink / raw) To: Alex Williamson Cc: Grzegorz Jaszczyk, Christian Brauner, linux-fsdevel, linux-aio, linux-usb, Matthew Rosato, Paul Durrant, Tom Rix, Jason Wang, dri-devel, Michal Hocko, linux-mm, Kirti Wankhede, Paolo Bonzini, Jens Axboe, Vineeth Vijayan, Diana Craciun, Alexander Gordeev, Xuan Zhuo, Shakeel Butt, Vasily Gorbik, Leon Romanovsky, Harald Freudenberger, Fei Li, x86, Roman Gushchin, Halil Pasic, Ingo Molnar, intel-gfx, Christian Borntraeger, linux-fpga, Zhi Wang, Wu Hao, Jason Herne, Eric Farman, Dave Hansen, Andrew Donnellan, Arnd Bergmann, linux-s390, Heiko Carstens, Johannes Weiner, linuxppc-dev, Eric Auger, Borislav Petkov, kvm, Rodrigo Vivi, cgroups, Thomas Gleixner, virtualization, intel-gvt-dev, io-uring, netdev, Tony Krowiak, Tvrtko Ursulin, Pavel Begunkov, Sean Christopherson, Oded Gabbay, Muchun Song, Peter Oberparleiter, linux-kernel, linux-rdma, Benjamin LaHaise, Michael S. Tsirkin, Sven Schnelle, Greg Kroah-Hartman, Frederic Barrat, Moritz Fischer, Vitaly Kuznetsov, David Woodhouse, Xu Yilun, Dominik Behr, Marcin Wojtas On Mon, Jul 17, 2023 at 01:08:31PM -0600, Alex Williamson wrote: > What would that mechanism be? We've been iterating on getting the > serialization and buffering correct, but I don't know of another means > that combines the notification with a value, so we'd likely end up with > an eventfd only for notification and a separate ring buffer for > notification values. All FDs do this. You just have to make a FD with custom file_operations that does what this wants. The uAPI shouldn't be able to tell if the FD is backing it with an eventfd or otherwise. Have the kernel return the FD instead of accepting it. Follow the basic design of eg mlx5vf_save_fops Jason ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 0/2] eventfd: simplify signal helpers 2023-07-17 22:12 ` Jason Gunthorpe @ 2023-07-17 22:52 ` Alex Williamson 2023-07-18 15:56 ` Jason Gunthorpe 0 siblings, 1 reply; 17+ messages in thread From: Alex Williamson @ 2023-07-17 22:52 UTC (permalink / raw) To: Jason Gunthorpe Cc: Grzegorz Jaszczyk, Christian Brauner, linux-fsdevel, linux-aio, linux-usb, Matthew Rosato, Paul Durrant, Tom Rix, Jason Wang, dri-devel, Michal Hocko, linux-mm, Kirti Wankhede, Paolo Bonzini, Jens Axboe, Vineeth Vijayan, Diana Craciun, Alexander Gordeev, Xuan Zhuo, Shakeel Butt, Vasily Gorbik, Leon Romanovsky, Harald Freudenberger, Fei Li, x86, Roman Gushchin, Halil Pasic, Ingo Molnar, intel-gfx, Christian Borntraeger, linux-fpga, Zhi Wang, Wu Hao, Jason Herne, Eric Farman, Dave Hansen, Andrew Donnellan, Arnd Bergmann, linux-s390, Heiko Carstens, Johannes Weiner, linuxppc-dev, Eric Auger, Borislav Petkov, kvm, Rodrigo Vivi, cgroups, Thomas Gleixner, virtualization, intel-gvt-dev, io-uring, netdev, Tony Krowiak, Tvrtko Ursulin, Pavel Begunkov, Sean Christopherson, Oded Gabbay, Muchun Song, Peter Oberparleiter, linux-kernel, linux-rdma, Benjamin LaHaise, Michael S. Tsirkin, Sven Schnelle, Greg Kroah-Hartman, Frederic Barrat, Moritz Fischer, Vitaly Kuznetsov, David Woodhouse, Xu Yilun, Dominik Behr, Marcin Wojtas On Mon, 17 Jul 2023 19:12:16 -0300 Jason Gunthorpe <jgg@ziepe.ca> wrote: > On Mon, Jul 17, 2023 at 01:08:31PM -0600, Alex Williamson wrote: > > > What would that mechanism be? We've been iterating on getting the > > serialization and buffering correct, but I don't know of another means > > that combines the notification with a value, so we'd likely end up with > > an eventfd only for notification and a separate ring buffer for > > notification values. > > All FDs do this. You just have to make a FD with custom > file_operations that does what this wants. The uAPI shouldn't be able > to tell if the FD is backing it with an eventfd or otherwise. Have the > kernel return the FD instead of accepting it. Follow the basic design > of eg mlx5vf_save_fops Sure, userspace could poll on any fd and read a value from it, but at that point we're essentially duplicating a lot of what eventfd provides for a minor(?) semantic difference over how the counter value is interpreted. Using an actual eventfd allows the ACPI notification to work as just another interrupt index within the existing vfio IRQ uAPI. Thanks, Alex ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 0/2] eventfd: simplify signal helpers 2023-07-17 22:52 ` Alex Williamson @ 2023-07-18 15:56 ` Jason Gunthorpe 0 siblings, 0 replies; 17+ messages in thread From: Jason Gunthorpe @ 2023-07-18 15:56 UTC (permalink / raw) To: Alex Williamson Cc: Grzegorz Jaszczyk, Christian Brauner, linux-fsdevel, linux-aio, linux-usb, Matthew Rosato, Paul Durrant, Tom Rix, Jason Wang, dri-devel, Michal Hocko, linux-mm, Kirti Wankhede, Paolo Bonzini, Jens Axboe, Vineeth Vijayan, Diana Craciun, Alexander Gordeev, Xuan Zhuo, Shakeel Butt, Vasily Gorbik, Leon Romanovsky, Harald Freudenberger, Fei Li, x86, Roman Gushchin, Halil Pasic, Ingo Molnar, intel-gfx, Christian Borntraeger, linux-fpga, Zhi Wang, Wu Hao, Jason Herne, Eric Farman, Dave Hansen, Andrew Donnellan, Arnd Bergmann, linux-s390, Heiko Carstens, Johannes Weiner, linuxppc-dev, Eric Auger, Borislav Petkov, kvm, Rodrigo Vivi, cgroups, Thomas Gleixner, virtualization, intel-gvt-dev, io-uring, netdev, Tony Krowiak, Tvrtko Ursulin, Pavel Begunkov, Sean Christopherson, Oded Gabbay, Muchun Song, Peter Oberparleiter, linux-kernel, linux-rdma, Benjamin LaHaise, Michael S. Tsirkin, Sven Schnelle, Greg Kroah-Hartman, Frederic Barrat, Moritz Fischer, Vitaly Kuznetsov, David Woodhouse, Xu Yilun, Dominik Behr, Marcin Wojtas On Mon, Jul 17, 2023 at 04:52:03PM -0600, Alex Williamson wrote: > On Mon, 17 Jul 2023 19:12:16 -0300 > Jason Gunthorpe <jgg@ziepe.ca> wrote: > > > On Mon, Jul 17, 2023 at 01:08:31PM -0600, Alex Williamson wrote: > > > > > What would that mechanism be? We've been iterating on getting the > > > serialization and buffering correct, but I don't know of another means > > > that combines the notification with a value, so we'd likely end up with > > > an eventfd only for notification and a separate ring buffer for > > > notification values. > > > > All FDs do this. You just have to make a FD with custom > > file_operations that does what this wants. The uAPI shouldn't be able > > to tell if the FD is backing it with an eventfd or otherwise. Have the > > kernel return the FD instead of accepting it. Follow the basic design > > of eg mlx5vf_save_fops > > Sure, userspace could poll on any fd and read a value from it, but at > that point we're essentially duplicating a lot of what eventfd provides > for a minor(?) semantic difference over how the counter value is > interpreted. Using an actual eventfd allows the ACPI notification to > work as just another interrupt index within the existing vfio IRQ > uAPI. Yes, duplicated, sort of, whatever the "ack" is to allow pushing a new value can be revised to run as part of the read. But I don't really view it as a minor difference. eventfd is a counter. It should not be abused otherwise, even if it can be made to work. It really isn't an IRQ if it is pushing an async message w/data. Jason ^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2023-07-18 15:56 UTC | newest] Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-07-13 10:05 [PATCH 0/2] eventfd: simplify signal helpers Christian Brauner 2023-07-13 10:05 ` [PATCH 1/2] eventfd: simplify eventfd_signal() Christian Brauner 2023-07-13 13:29 ` Anthony Krowiak 2023-07-13 13:34 ` Oded Gabbay 2023-07-13 10:05 ` [PATCH 2/2] eventfd: simplify eventfd_signal_mask() Christian Brauner 2023-07-13 11:59 ` Petr Machata 2023-07-13 14:00 ` Christian Brauner 2023-07-13 14:33 ` Sean Christopherson 2023-07-13 14:52 ` Christian Brauner 2023-07-13 17:10 ` [PATCH 0/2] eventfd: simplify signal helpers Alex Williamson -- strict thread matches above, loose matches on Subject: below -- 2023-06-30 15:59 [PATCH v6] vfio/pci: Propagate ACPI notifications to user-space via eventfd Grzegorz Jaszczyk 2023-07-14 7:05 ` [PATCH 0/2] eventfd: simplify signal helpers Christian Brauner 2023-07-14 15:24 ` Jason Gunthorpe 2023-07-17 8:29 ` Grzegorz Jaszczyk 2023-07-17 19:08 ` Alex Williamson 2023-07-17 22:12 ` Jason Gunthorpe 2023-07-17 22:52 ` Alex Williamson 2023-07-18 15:56 ` Jason Gunthorpe
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®