linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: Justin Forbes <jmforbes@linuxtx.org>,
	Zwane Mwaikambo <zwane@arm.linux.org.uk>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Randy Dunlap <rdunlap@xenotime.net>,
	Dave Jones <davej@redhat.com>,
	Chuck Wolber <chuckw@quantumlinux.com>,
	Chris Wedgwood <reviews@ml.cw.f00f.org>,
	Michael Krufky <mkrufky@linuxtv.org>,
	Chuck Ebbert <cebbert@redhat.com>,
	Domenico Andreoli <cavokz@gmail.com>, Willy Tarreau <w@1wt.eu>,
	Rodrigo Rubira Branco <rbranco@la.checkpoint.com>,
	Jake Edge <jake@lwn.net>, Eugene Teo <eteo@redhat.com>,
	torvalds@linux-foundation.org, akpm@linux-foundation.org,
	alan@lxorguk.ukuu.org.uk,
	Davide Libenzi <davidel@xmailserver.org>,
	Benjamin LaHaise <bcrl@kvack.org>,
	Trond Myklebust <trond.myklebust@fys.uio.no>,
	Eric Dumazet <dada1@cosmosbay.com>,
	Jeff Moyer <jmoyer@redhat.com>,
	Zach Brown <zach.brown@oracle.com>
Subject: [patch 14/32] eventfd: remove fput() call from possible IRQ context
Date: Fri, 20 Mar 2009 15:26:25 -0700	[thread overview]
Message-ID: <20090320222711.135354566@mini.kroah.org> (raw)
In-Reply-To: <20090320231037.GA2732@kroah.com>

[-- Attachment #1: eventfd-remove-fput-call-from-possible-irq-context.patch --]
[-- Type: text/plain, Size: 4253 bytes --]

2.6.27-stable review patch.  If anyone has any objections, please let us know.

------------------

From: Davide Libenzi <davidel@xmailserver.org>

commit 87c3a86e1c220121d0ced59d1a71e78ed9abc6dd upstream.

Remove a source of fput() call from inside IRQ context.  Myself, like Eric,
wasn't able to reproduce an fput() call from IRQ context, but Jeff said he was
able to, with the attached test program.  Independently from this, the bug is
conceptually there, so we might be better off fixing it.  This patch adds an
optimization similar to the one we already do on ->ki_filp, on ->ki_eventfd.
Playing with ->f_count directly is not pretty in general, but the alternative
here would be to add a brand new delayed fput() infrastructure, that I'm not
sure is worth it.

Signed-off-by: Davide Libenzi <davidel@xmailserver.org>
Cc: Benjamin LaHaise <bcrl@kvack.org>
Cc: Trond Myklebust <trond.myklebust@fys.uio.no>
Cc: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Cc: Zach Brown <zach.brown@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 fs/aio.c |   37 +++++++++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 10 deletions(-)

--- a/fs/aio.c
+++ b/fs/aio.c
@@ -428,7 +428,7 @@ static struct kiocb *__aio_get_req(struc
 	req->private = NULL;
 	req->ki_iovec = NULL;
 	INIT_LIST_HEAD(&req->ki_run_list);
-	req->ki_eventfd = ERR_PTR(-EINVAL);
+	req->ki_eventfd = NULL;
 
 	/* Check if the completion queue has enough free space to
 	 * accept an event from this io.
@@ -470,8 +470,6 @@ static inline void really_put_req(struct
 {
 	assert_spin_locked(&ctx->ctx_lock);
 
-	if (!IS_ERR(req->ki_eventfd))
-		fput(req->ki_eventfd);
 	if (req->ki_dtor)
 		req->ki_dtor(req);
 	if (req->ki_iovec != &req->ki_inline_vec)
@@ -493,8 +491,11 @@ static void aio_fput_routine(struct work
 		list_del(&req->ki_list);
 		spin_unlock_irq(&fput_lock);
 
-		/* Complete the fput */
-		__fput(req->ki_filp);
+		/* Complete the fput(s) */
+		if (req->ki_filp != NULL)
+			__fput(req->ki_filp);
+		if (req->ki_eventfd != NULL)
+			__fput(req->ki_eventfd);
 
 		/* Link the iocb into the context's free list */
 		spin_lock_irq(&ctx->ctx_lock);
@@ -512,12 +513,14 @@ static void aio_fput_routine(struct work
  */
 static int __aio_put_req(struct kioctx *ctx, struct kiocb *req)
 {
+	int schedule_putreq = 0;
+
 	dprintk(KERN_DEBUG "aio_put(%p): f_count=%ld\n",
 		req, atomic_long_read(&req->ki_filp->f_count));
 
 	assert_spin_locked(&ctx->ctx_lock);
 
-	req->ki_users --;
+	req->ki_users--;
 	BUG_ON(req->ki_users < 0);
 	if (likely(req->ki_users))
 		return 0;
@@ -525,10 +528,23 @@ static int __aio_put_req(struct kioctx *
 	req->ki_cancel = NULL;
 	req->ki_retry = NULL;
 
-	/* Must be done under the lock to serialise against cancellation.
-	 * Call this aio_fput as it duplicates fput via the fput_work.
+	/*
+	 * Try to optimize the aio and eventfd file* puts, by avoiding to
+	 * schedule work in case it is not __fput() time. In normal cases,
+	 * we would not be holding the last reference to the file*, so
+	 * this function will be executed w/out any aio kthread wakeup.
 	 */
-	if (unlikely(atomic_long_dec_and_test(&req->ki_filp->f_count))) {
+	if (unlikely(atomic_long_dec_and_test(&req->ki_filp->f_count)))
+		schedule_putreq++;
+	else
+		req->ki_filp = NULL;
+	if (req->ki_eventfd != NULL) {
+		if (unlikely(atomic_long_dec_and_test(&req->ki_eventfd->f_count)))
+			schedule_putreq++;
+		else
+			req->ki_eventfd = NULL;
+	}
+	if (unlikely(schedule_putreq)) {
 		get_ioctx(ctx);
 		spin_lock(&fput_lock);
 		list_add(&req->ki_list, &fput_head);
@@ -992,7 +1008,7 @@ int aio_complete(struct kiocb *iocb, lon
 	 * eventfd. The eventfd_signal() function is safe to be called
 	 * from IRQ context.
 	 */
-	if (!IS_ERR(iocb->ki_eventfd))
+	if (iocb->ki_eventfd != NULL)
 		eventfd_signal(iocb->ki_eventfd, 1);
 
 put_rq:
@@ -1596,6 +1612,7 @@ static int io_submit_one(struct kioctx *
 		req->ki_eventfd = eventfd_fget((int) iocb->aio_resfd);
 		if (IS_ERR(req->ki_eventfd)) {
 			ret = PTR_ERR(req->ki_eventfd);
+			req->ki_eventfd = NULL;
 			goto out_put_req;
 		}
 	}



  parent reply	other threads:[~2009-03-20 23:18 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20090320222611.872315885@mini.kroah.org>
2009-03-20 23:10 ` [patch 00/32] 2.6.27.21-stable review Greg KH
2009-03-20 22:26   ` [patch 01/32] [IA64] Build fix for __early_pfn_to_nid() undefined link error Greg KH
2009-03-20 22:26   ` [patch 02/32] Add -fwrapv to gcc CFLAGS Greg KH
2009-03-20 22:26   ` [patch 03/32] Move cc-option to below arch-specific setup Greg KH
2009-03-20 22:26   ` [patch 04/32] nfsd: nfsd should drop CAP_MKNOD for non-root Greg KH
2009-03-20 22:26   ` [patch 05/32] NFSD: provide encode routine for OP_OPENATTR Greg KH
2009-03-20 22:26   ` [patch 06/32] ALSA: Fix vunmap and free order in snd_free_sgbuf_pages() Greg KH
2009-03-20 22:26   ` [patch 07/32] ALSA: hda - Fix DMA mask for ATI controllers Greg KH
2009-03-20 22:26   ` [patch 08/32] ALSA: mixart, fix lock imbalance Greg KH
2009-03-20 22:26   ` [patch 09/32] ALSA: pcm_oss, fix locking typo Greg KH
2009-03-20 22:26   ` [patch 10/32] ata_piix: add workaround for Samsung DB-P70 Greg KH
2009-03-20 22:26   ` [patch 11/32] dm crypt: fix kcryptd_async_done parameter Greg KH
2009-03-20 22:26   ` [patch 12/32] dm ioctl: validate name length when renaming Greg KH
2009-03-20 22:26   ` [patch 13/32] dm io: respect BIO_MAX_PAGES limit Greg KH
2009-03-20 22:26   ` Greg KH [this message]
2009-03-20 22:26   ` [patch 15/32] S390: __div64_31 broken for CONFIG_MARCH_G5 Greg KH
2009-03-20 22:26   ` [patch 16/32] thinkpad-acpi: fix module autoloading for older models Greg KH
2009-03-20 22:26   ` [patch 17/32] V4L/DVB (10218): cx23885: Fix Oops for mixed install of analog and digital only cards Greg KH
2009-03-20 22:26   ` [patch 18/32] Fix misreporting of #cores as #hyperthreads for Q9550 Greg KH
2009-03-20 22:26   ` [patch 19/32] powerpc: Remove extra semicolon in fsl_soc.c Greg KH
2009-03-20 22:26   ` [patch 20/32] USB: EHCI: expedite unlinks when the root hub is suspended Greg KH
2009-03-20 22:26   ` [patch 21/32] USB: EHCI: Fix isochronous URB leak Greg KH
2009-03-20 22:26   ` [patch 22/32] USB: Add Vendor/Product ID for new CDMA U727 to option driver Greg KH
2009-03-20 22:26   ` [patch 23/32] USB: option.c: add ZTE 622 modem device Greg KH
2009-03-20 22:26   ` [patch 24/32] USB: Add device id for Option GTM380 to option driver Greg KH
2009-03-20 22:26   ` [patch 25/32] USB: Option: let cdc-acm handle Sony Ericsson F3507g / Dell 5530 Greg KH
2009-03-20 22:26   ` [patch 26/32] USB: serial: add FTDI USB/Serial converter devices Greg KH
2009-03-20 22:26   ` [patch 27/32] USB: serial: ftdi: enable UART detection on gnICE JTAG adaptors blacklist interface0 Greg KH
2009-03-20 22:26   ` [patch 28/32] USB: serial: new cp2101 device id Greg KH
2009-03-20 22:26   ` [patch 29/32] USB: storage: Unusual USB device Prolific 2507 variation added Greg KH
2009-03-20 22:26   ` [patch 30/32] USB: unusual_devs: Add support for GI 0431 SD-Card interface Greg KH
2009-03-20 22:26   ` [patch 31/32] USB: Updated unusual-devs entry for USB mass storage on Nokia 6233 Greg KH
2009-03-20 22:26   ` [patch 32/32] USB: usbfs: keep async URBs until the device file is closed Greg KH

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=20090320222711.135354566@mini.kroah.org \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=bcrl@kvack.org \
    --cc=cavokz@gmail.com \
    --cc=cebbert@redhat.com \
    --cc=chuckw@quantumlinux.com \
    --cc=dada1@cosmosbay.com \
    --cc=davej@redhat.com \
    --cc=davidel@xmailserver.org \
    --cc=eteo@redhat.com \
    --cc=jake@lwn.net \
    --cc=jmforbes@linuxtx.org \
    --cc=jmoyer@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkrufky@linuxtv.org \
    --cc=rbranco@la.checkpoint.com \
    --cc=rdunlap@xenotime.net \
    --cc=reviews@ml.cw.f00f.org \
    --cc=stable@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=trond.myklebust@fys.uio.no \
    --cc=tytso@mit.edu \
    --cc=w@1wt.eu \
    --cc=zach.brown@oracle.com \
    --cc=zwane@arm.linux.org.uk \
    /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;
as well as URLs for NNTP newsgroup(s).