Linux cgroups development
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Sean Christopherson <seanjc@google.com>
Cc: linux-fsdevel@vger.kernel.org,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, David Woodhouse <dwmw2@infradead.org>,
	Paul Durrant <paul@xen.org>, Oded Gabbay <ogabbay@kernel.org>,
	Wu Hao <hao.wu@intel.com>, Tom Rix <trix@redhat.com>,
	Moritz Fischer <mdf@kernel.org>, Xu Yilun <yilun.xu@intel.com>,
	Zhenyu Wang <zhenyuw@linux.intel.com>,
	Zhi Wang <zhi.a.wang@intel.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
	David Airlie <airlied@gma>
Subject: Re: [PATCH 2/2] eventfd: simplify eventfd_signal_mask()
Date: Thu, 13 Jul 2023 16:52:34 +0200	[thread overview]
Message-ID: <20230713-mahnen-drosseln-fa717117e827@brauner> (raw)
In-Reply-To: <ZLAK+FA3qgbHW0YK@google.com>

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.

  reply	other threads:[~2023-07-13 14:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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
     [not found]   ` <20230713-vfs-eventfd-signal-v1-2-7fda6c5d212b-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2023-07-13 14:33     ` Sean Christopherson
2023-07-13 14:52       ` Christian Brauner [this message]
2023-07-13 17:10 ` [PATCH 0/2] eventfd: simplify signal helpers Alex Williamson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230713-mahnen-drosseln-fa717117e827@brauner \
    --to=brauner@kernel.org \
    --cc=airlied@gma \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dwmw2@infradead.org \
    --cc=hao.wu@intel.com \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mdf@kernel.org \
    --cc=mingo@redhat.com \
    --cc=ogabbay@kernel.org \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=trix@redhat.com \
    --cc=tvrtko.ursulin@linux.intel.com \
    --cc=vkuznets@redhat.com \
    --cc=x86@kernel.org \
    --cc=yilun.xu@intel.com \
    --cc=zhenyuw@linux.intel.com \
    --cc=zhi.a.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox