From nobody Fri Dec 19 15:59:31 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C98B1EFF8F for ; Mon, 19 May 2025 18:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747680923; cv=none; b=ss6h5/IrFHFQWPiSXfcyqRdN23APLrAwCOtbncejX8mdmjMjpi3r8noMXiuK45/kjg9zBfyzZ4JFH1OEnfXaLxvRnXifL6wE5KN0ULrsGQQrVVDLHflyVFVE5ygy7YDfaY6IlcUPcfo9nrafygzZxRIMKB//HfEOtijUqDxmqSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747680923; c=relaxed/simple; bh=8ktdrLUAiBXw/pB6xl3QteVK8vmsyuV4GRrjhK4M1uk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=nO1bXvriZbmyy2hCHfDEJ2DLGMbeR/PjFTm4lvMSAaq0yLZVCuhWPmrrtirL6mSiJjADmP+ZkAok4ZCuU7V5KBjX+FmWg2E7qXEzW408xht17pRdP+ZbQfCyesh3A8+w16m9B3lXGTAmW1sgBw7W8K/xD8S6K603v8DOTL/VDCA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=zgrg4IZJ; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zgrg4IZJ" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-30e9b2e7a34so2087659a91.0 for ; Mon, 19 May 2025 11:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1747680920; x=1748285720; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=ID0K77cu4OHC+wFfljvoyA4ejd82lVYZb+u9j8jbS6w=; b=zgrg4IZJlF83sIQo4ec3zWuR7bxitiitKVCJa+rxAUWQX+Z/DYUbLQ3iFma1V1CVyu qIPykXj0uRU67lF8qjf7wT2lNILDX6z/AAx0N/QuLOSGbK36R9vcyRmu4Suhm4rlhBEr jd5Zm02KspkaWwQL5elLbh/coh/bCsNFLYYj286iBNMZ4k3cXoWgXQH+JzTCbA0yaxVq cnqLad8Ul5pN0fW2+2ooRQt9XyH52IVL3tesZzWwcSfBvEy0tt41btbZV5QhGE3Rfu3L KBTjgF1yk/g/jIp1DQQocoav9iDn+MEN+Ug8w3dD/+FnhBCMnczKbshd7TUXGwuxWzF6 Me9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747680920; x=1748285720; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ID0K77cu4OHC+wFfljvoyA4ejd82lVYZb+u9j8jbS6w=; b=nCKt1415XpYz0OfdKQV2AEkuVlHiY/p1dAC25NMPx+euW1fV6AwGHU0+DBEsiUIHPE xkKzkwR5Ggf5EvO2+ZE4wCMriW3BQkE6iEow9wlOkQxSMxINVFcI5e7lBF+86mUFgFaP BJHKfnrlUWClf3FnFzN7JovSutLlR+7/xkK8O6yy9Q4x3RO44ebPpGXlD6mdKj1eo8+l xqx9iOHTJvFDVWxoc3AZqaODkMQfM5+pDjDoc2HXYoAWToOEMNY4taqIfxhKwYx3l7N0 YFMkTD9en8S/52Atw+DzAG+lHeN0vX1dvwF5MsTL4Vfs0qjyXUjJ1eobSwNTMCCmdW/6 LDDg== X-Forwarded-Encrypted: i=1; AJvYcCVSuqjaGsMVaVnz1IeCs9egALF/FkmFa6Bek4hksu3rINfEJ0VkBtg/7/aul27MhpPaHwq7VRc3QGYGULc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy86SHCK/gnxs8UMF7HmoCGeLt/+mZkuNf9lzDUfQNIvCbUySS0 TFp7uZhAdAq/XoFW4SOy/QAbio/0OiM2UNeNsqniZ87BqBokDKUuZ9hhJ2IAoula02o6NYQC9HB RVlR3zA== X-Google-Smtp-Source: AGHT+IEaLF1s48wE5AIuvexHP+HKA2rzrNNO6wCebHCQJZafvZj5yhtA+uxhZqD9qAgjgxLgy4Xu2cmiqA0= X-Received: from pjtu3.prod.google.com ([2002:a17:90a:c883:b0:2ff:6e58:8a0a]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:d604:b0:30a:9316:75a2 with SMTP id 98e67ed59e1d1-30e7d52adcfmr23209313a91.10.1747680920311; Mon, 19 May 2025 11:55:20 -0700 (PDT) Reply-To: Sean Christopherson Date: Mon, 19 May 2025 11:55:03 -0700 In-Reply-To: <20250519185514.2678456-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250519185514.2678456-1-seanjc@google.com> X-Mailer: git-send-email 2.49.0.1101.gccaa498523-goog Message-ID: <20250519185514.2678456-2-seanjc@google.com> Subject: [PATCH v2 01/12] KVM: Use a local struct to do the initial vfs_poll() on an irqfd From: Sean Christopherson To: Paolo Bonzini , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Marc Zyngier , Oliver Upton , Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, K Prateek Nayak , David Matlack , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use a function-local struct for the poll_table passed to vfs_poll(), as nothing in the vfs_poll() callchain grabs a long-term reference to the structure, i.e. its lifetime doesn't need to be tied to the irqfd. Using a local structure will also allow propagating failures out of the polling callback without further polluting kvm_kernel_irqfd. Opportunstically rename irqfd_ptable_queue_proc() to kvm_irqfd_register() to capture what it actually does. Signed-off-by: Sean Christopherson --- include/linux/kvm_irqfd.h | 1 - virt/kvm/eventfd.c | 26 +++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/include/linux/kvm_irqfd.h b/include/linux/kvm_irqfd.h index 8ad43692e3bb..44fd2a20b09e 100644 --- a/include/linux/kvm_irqfd.h +++ b/include/linux/kvm_irqfd.h @@ -55,7 +55,6 @@ struct kvm_kernel_irqfd { /* Used for setup/shutdown */ struct eventfd_ctx *eventfd; struct list_head list; - poll_table pt; struct work_struct shutdown; struct irq_bypass_consumer consumer; struct irq_bypass_producer *producer; diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c index 11e5d1e3f12e..39e42b19d9f7 100644 --- a/virt/kvm/eventfd.c +++ b/virt/kvm/eventfd.c @@ -245,12 +245,17 @@ irqfd_wakeup(wait_queue_entry_t *wait, unsigned mode,= int sync, void *key) return ret; } =20 -static void -irqfd_ptable_queue_proc(struct file *file, wait_queue_head_t *wqh, - poll_table *pt) +struct kvm_irqfd_pt { + struct kvm_kernel_irqfd *irqfd; + poll_table pt; +}; + +static void kvm_irqfd_register(struct file *file, wait_queue_head_t *wqh, + poll_table *pt) { - struct kvm_kernel_irqfd *irqfd =3D - container_of(pt, struct kvm_kernel_irqfd, pt); + struct kvm_irqfd_pt *p =3D container_of(pt, struct kvm_irqfd_pt, pt); + struct kvm_kernel_irqfd *irqfd =3D p->irqfd; + add_wait_queue_priority(wqh, &irqfd->wait); } =20 @@ -305,6 +310,7 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *arg= s) { struct kvm_kernel_irqfd *irqfd, *tmp; struct eventfd_ctx *eventfd =3D NULL, *resamplefd =3D NULL; + struct kvm_irqfd_pt irqfd_pt; int ret; __poll_t events; int idx; @@ -394,7 +400,6 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *arg= s) * a callback whenever someone signals the underlying eventfd */ init_waitqueue_func_entry(&irqfd->wait, irqfd_wakeup); - init_poll_funcptr(&irqfd->pt, irqfd_ptable_queue_proc); =20 spin_lock_irq(&kvm->irqfds.lock); =20 @@ -416,11 +421,14 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *a= rgs) spin_unlock_irq(&kvm->irqfds.lock); =20 /* - * Check if there was an event already pending on the eventfd - * before we registered, and trigger it as if we didn't miss it. + * Register the irqfd with the eventfd by polling on the eventfd. If + * there was en event pending on the eventfd prior to registering, + * manually trigger IRQ injection. */ - events =3D vfs_poll(fd_file(f), &irqfd->pt); + irqfd_pt.irqfd =3D irqfd; + init_poll_funcptr(&irqfd_pt.pt, kvm_irqfd_register); =20 + events =3D vfs_poll(fd_file(f), &irqfd_pt.pt); if (events & EPOLLIN) schedule_work(&irqfd->inject); =20 --=20 2.49.0.1101.gccaa498523-goog