mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@SteelEye.com>
To: Greg KH <greg@kroah.com>
Cc: Andrew Morton <akpm@osdl.org>, Linus Torvalds <torvalds@osdl.org>,
	linux-kernel@vger.kernel.org, Jens Axboe <axboe@suse.de>,
	"Brown, Len" <len.brown@intel.com>,
	"David S. Miller" <davem@davemloft.net>,
	linux-acpi@vger.kernel.org,
	linux-usb-devel@lists.sourceforge.net, "Yu,
	Luming" <luming.yu@intel.com>, Ben Castricum <lk@bencastricum.nl>,
	sanjoy@mrao.cam.ac.uk, Helge Hafting <helgehaf@aitel.hist.no>,
	"Carlo E. Prelz" <fluido@fluido.as>,
	Gerrit Bruchh?user <gbruchhaeuser@gmx.de>,
	Nicolas.Mailhot@LaPoste.net, Jaroslav Kysela <perex@suse.cz>,
	Takashi Iwai <tiwai@suse.de>,
	Patrizio Bassi <patrizio.bassi@gmail.com>,
	Bj?rn Nilsson <bni.swe@gmail.com>,
	Andrey Borzenkov <arvidjaar@mail.ru>,
	"P. Christeas" <p_christ@hol.gr>, ghrt <ghrt@dial.kappa.ro>,
	jinhong hu <jinhong.hu@gmail.com>,
	Andrew Vasquez <andrew.vasquez@qlogic.com>,
	linux-scsi@vger.kernel.org, Benjamin LaHaise <bcrl@kvack.org>
Subject: Re: Linux 2.6.16-rc3
Date: Wed, 15 Feb 2006 20:56:00 -0500	[thread overview]
Message-ID: <1140054960.3037.5.camel@mulgrave.il.steeleye.com> (raw)
In-Reply-To: <1139934883.14115.4.camel@mulgrave.il.steeleye.com>

On Tue, 2006-02-14 at 10:34 -0600, James Bottomley wrote:
> Well, I can't solve the problem that it requires memory allocation from
> IRQ context to operate.  Based on that, it's an unsafe interface.  I'm
> going to put it inside SCSI for 2.6.16, since it's better than what we
> have now, but I don't think we can export it globally.

OK, this is what I'm proposing as the device model fix.  What it does is
thread context checking APIs throughout the device subsystem.  SCSI can
then use it simply via device_put_process_context().  Since we have to
supply the kref_work; I'd plan to do that as an additional element in
struct scsi_device.

This, by itself, won't solve the SCSI target problem, but I plan to fix
that via a device model addition which would have target alloc waiting
around for any deleted targets to disappear.

Since this is planned for post 2.6.16, we have plenty of time to argue
about it.

James

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 6b355bd..4ae42de 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -338,10 +338,10 @@ struct device * get_device(struct device
  *	put_device - decrement reference count.
  *	@dev:	device in question.
  */
-void put_device(struct device * dev)
+void put_device_process_context(struct device * dev, struct kref_work *work)
 {
 	if (dev)
-		kobject_put(&dev->kobj);
+	  kobject_put_process_context(&dev->kobj, work);
 }
 
 
@@ -445,7 +445,7 @@ EXPORT_SYMBOL_GPL(device_register);
 EXPORT_SYMBOL_GPL(device_del);
 EXPORT_SYMBOL_GPL(device_unregister);
 EXPORT_SYMBOL_GPL(get_device);
-EXPORT_SYMBOL_GPL(put_device);
+EXPORT_SYMBOL_GPL(put_device_process_context);
 
 EXPORT_SYMBOL_GPL(device_create_file);
 EXPORT_SYMBOL_GPL(device_remove_file);
diff --git a/include/linux/device.h b/include/linux/device.h
index 58df18d..ac9d457 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -396,7 +396,13 @@ extern int (*platform_notify_remove)(str
  *
  */
 extern struct device * get_device(struct device * dev);
-extern void put_device(struct device * dev);
+extern void put_device_process_context(struct device * dev,
+				       struct kref_work *work);
+static inline void put_device(struct device *dev)
+{
+	put_device_process_context(dev, NULL);
+}
+						  
 
 
 /* drivers/base/power.c */
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 2a8d8da..d079fea 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -76,7 +76,12 @@ extern int kobject_register(struct kobje
 extern void kobject_unregister(struct kobject *);
 
 extern struct kobject * kobject_get(struct kobject *);
-extern void kobject_put(struct kobject *);
+extern void kobject_put_process_context(struct kobject *, struct kref_work *);
+
+static inline void kobject_put(struct kobject *kobj)
+{
+	kobject_put_process_context(kobj, NULL);
+}
 
 extern char * kobject_get_path(struct kobject *, gfp_t);
 
diff --git a/include/linux/kref.h b/include/linux/kref.h
index 6fee353..16b15db 100644
--- a/include/linux/kref.h
+++ b/include/linux/kref.h
@@ -18,15 +18,29 @@
 #ifdef __KERNEL__
 
 #include <linux/types.h>
+#include <linux/workqueue.h>
 #include <asm/atomic.h>
 
 struct kref {
 	atomic_t refcount;
 };
 
+struct kref_work {
+	struct work_struct work;
+	struct kref *kref;
+	void (*release)(struct kref *kref);
+};
+
 void kref_init(struct kref *kref);
 void kref_get(struct kref *kref);
-int kref_put(struct kref *kref, void (*release) (struct kref *kref));
+int kref_put_process_context(struct kref *kref,
+			     void (*release) (struct kref *kref),
+			     struct kref_work *work);
+static inline int kref_put(struct kref *kref,
+			   void (*release) (struct kref *kref))
+{
+	return kref_put_process_context(kref, release, NULL);
+}
 
 #endif /* __KERNEL__ */
 #endif /* _KREF_H_ */
diff --git a/lib/kobject.c b/lib/kobject.c
index efe67fa..6b80c54 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -372,10 +372,10 @@ static void kobject_release(struct kref 
  *
  *	Decrement the refcount, and if 0, call kobject_cleanup().
  */
-void kobject_put(struct kobject * kobj)
+void kobject_put_process_context(struct kobject * kobj, struct kref_work *work)
 {
 	if (kobj)
-		kref_put(&kobj->kref, kobject_release);
+		kref_put_process_context(&kobj->kref, kobject_release, work);
 }
 
 
@@ -537,7 +537,7 @@ EXPORT_SYMBOL(kobject_init);
 EXPORT_SYMBOL(kobject_register);
 EXPORT_SYMBOL(kobject_unregister);
 EXPORT_SYMBOL(kobject_get);
-EXPORT_SYMBOL(kobject_put);
+EXPORT_SYMBOL(kobject_put_process_context);
 EXPORT_SYMBOL(kobject_add);
 EXPORT_SYMBOL(kobject_del);
 
diff --git a/lib/kref.c b/lib/kref.c
index 0d07cc3..66231cf 100644
--- a/lib/kref.c
+++ b/lib/kref.c
@@ -13,6 +13,7 @@
 
 #include <linux/kref.h>
 #include <linux/module.h>
+#include <linux/hardirq.h>
 
 /**
  * kref_init - initialize object.
@@ -33,27 +34,47 @@ void kref_get(struct kref *kref)
 	atomic_inc(&kref->refcount);
 }
 
+static void kref_release_process_context(void *data)
+{
+	struct kref_work *work = data;
+
+	work->release(work->kref);
+}
+
 /**
- * kref_put - decrement refcount for object.
+ * kref_put_user - decrement refcount for object and put in user context
  * @kref: object.
  * @release: pointer to the function that will clean up the object when the
  *	     last reference to the object is released.
  *	     This pointer is required, and it is not acceptable to pass kfree
  *	     in as this function.
+ * @work:    pointer to a kref_work used to take the release through user
+ *	     context (may be null)
  *
- * Decrement the refcount, and if 0, call release().
+ * Decrement the refcount, and if 0, call release().  If work is not null
+ * execute release via schedule_work if not in process context.
  * Return 1 if the object was removed, otherwise return 0.  Beware, if this
  * function returns 0, you still can not count on the kref from remaining in
  * memory.  Only use the return value if you want to see if the kref is now
  * gone, not present.
  */
-int kref_put(struct kref *kref, void (*release)(struct kref *kref))
+int kref_put_process_context(struct kref *kref,
+			     void (*release)(struct kref *kref),
+			     struct kref_work *work)
 {
 	WARN_ON(release == NULL);
 	WARN_ON(release == (void (*)(struct kref *))kfree);
 
 	if (atomic_dec_and_test(&kref->refcount)) {
-		release(kref);
+		if (!work || !in_interrupt())
+			release(kref);
+		else {
+			INIT_WORK(&work->work, kref_release_process_context,
+				  work);
+			schedule_work(&work->work);
+		}
+			
+			
 		return 1;
 	}
 	return 0;
@@ -61,4 +82,4 @@ int kref_put(struct kref *kref, void (*r
 
 EXPORT_SYMBOL(kref_init);
 EXPORT_SYMBOL(kref_get);
-EXPORT_SYMBOL(kref_put);
+EXPORT_SYMBOL(kref_put_process_context);



  parent reply	other threads:[~2006-02-16 16:15 UTC|newest]

Thread overview: 121+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-13  1:19 Linus Torvalds
2006-02-13  3:05 ` Andrew Morton
2006-02-13  3:22   ` Trond Myklebust
2006-02-13 15:09     ` Benjamin LaHaise
2006-02-13  3:28   ` Sanjoy Mahajan
2006-02-13  3:36   ` Jeff Garzik
2006-02-13  4:40   ` James Bottomley
2006-02-13  5:20   ` S3 sleep regression bisected (was Re: Linux 2.6.16-rc3) Sanjoy Mahajan
2006-02-13  7:04   ` Linux 2.6.16-rc3 Arjan van de Ven
2006-02-13  8:11   ` Jens Axboe
2006-02-13  9:22   ` Patrizio Bassi
2006-02-13 10:07   ` Linux 2.6.16-rc3 - x86_64 specific outstanding bugs Andi Kleen
2006-02-13 12:02   ` Linux 2.6.16-rc3 Takashi Iwai
2006-02-13 12:37     ` Patrizio Bassi
2006-02-13 13:13       ` Takashi Iwai
2006-02-13 13:31         ` Patrizio Bassi
2006-02-13 14:15           ` Takashi Iwai
2006-02-13 14:34             ` Patrizio Bassi
2006-02-13 14:39               ` Takashi Iwai
2006-02-13 13:09     ` Rafael J. Wysocki
2006-02-13 13:51       ` Takashi Iwai
2006-02-13 19:33         ` Rafael J. Wysocki
2006-02-13 16:36     ` Thierry Vignaud
2006-02-15  6:51       ` Andrew Morton
2006-02-15 13:40         ` Thierry Vignaud
2006-02-15 20:00           ` Andrew Morton
2006-02-13 16:36     ` Thierry Vignaud
2006-02-13 16:10   ` Adrian Bunk
2006-02-13 19:31     ` Daniel Drake
2006-02-13 20:30   ` Paul Fulghum
2006-02-13 20:38   ` Greg KH
2006-02-14 16:34     ` James Bottomley
2006-02-15 16:07       ` [linux-usb-devel] " Alan Stern
2006-02-15 16:27         ` Greg KH
2006-02-15 16:35           ` Arjan van de Ven
2006-02-15 17:06             ` Greg KH
2006-02-15 21:52               ` Alan Stern
2006-02-15 21:59                 ` Greg KH
2006-02-15 22:25                   ` Alan Stern
2006-02-15 22:37                     ` Greg KH
2006-02-15 22:51                       ` Alan Stern
2006-02-15 19:58         ` James Bottomley
2006-02-15 22:24           ` Alan Stern
2006-02-16  1:56       ` James Bottomley [this message]
2006-02-16 17:12         ` Russell King
2006-02-16 17:34           ` Stefan Richter
2006-02-16 17:57           ` James Bottomley
2006-02-16 18:09             ` Russell King
2006-02-16 18:14               ` James Bottomley
2006-02-16 18:18                 ` Russell King
2006-02-16 19:09                   ` James Bottomley
2006-02-16 20:01                     ` Jens Axboe
2006-02-18  0:42                       ` James Bottomley
2006-02-18  1:00                         ` Greg KH
2006-02-18  2:12                         ` Roland Dreier
2006-02-18 10:03                         ` [linux-usb-devel] " Sergey Vlasov
2006-02-19 14:30                           ` James Bottomley
2006-02-23 18:43                             ` James Bottomley
2006-02-18 20:16                         ` Alan Stern
2006-02-19 13:51                           ` James Bottomley
2006-02-14 15:19   ` [PATCH] x86: fix oprofile kernel callgraph regression Gerald Britton
2006-02-14 15:58     ` Hugh Dickins
2006-02-18 21:06   ` Linux 2.6.16-rc3 Helge Hafting
2006-02-22 16:49   ` Ben Castricum
2006-02-13  8:46 ` Jan Dittmer
2006-02-13  9:07   ` Yoichi Yuasa
2006-02-13 15:47   ` Linus Torvalds
2006-02-13 22:11     ` Jan Dittmer
     [not found] ` <3aa654a40602130231p1c476e99paa986fa198951839@mail.gmail.com>
2006-02-13 10:39   ` Andrew Morton
2006-02-13 10:54     ` Con Kolivas
2006-02-13 17:27       ` Andi Kleen
     [not found]     ` <3aa654a40602130251t174a5e4bg28a52a147cc9b2cf@mail.gmail.com>
2006-02-13 10:56       ` Andrew Morton
2006-02-14  2:44         ` Andrew Morton
2006-02-14  2:54           ` Dave Jones
2006-02-14  3:21             ` Andrew Morton
2006-02-13 17:09 ` 2.6.16-rc3: more regressions Adrian Bunk
2006-02-13 17:24   ` Dave Jones
2006-02-13 17:30   ` Dmitry Torokhov
2006-02-13 17:35   ` Linus Torvalds
2006-02-13 17:46     ` Dave Jones
2006-02-13 18:04       ` Linus Torvalds
2006-02-13 18:16         ` Linus Torvalds
2006-02-13 18:27           ` Dave Jones
2006-02-13 18:33             ` Linus Torvalds
2006-02-13 18:42               ` Adrian Bunk
2006-02-13 18:34           ` Adrian Bunk
2006-02-13 18:42             ` Dave Jones
2006-02-13 18:47               ` Adrian Bunk
2006-02-13 18:51               ` Alex Deucher
2006-02-13 18:50             ` Linus Torvalds
2006-02-13 19:09               ` Adrian Bunk
2006-02-13 19:17                 ` Linus Torvalds
2006-02-13 19:21                   ` Linus Torvalds
2006-02-13 23:27                   ` Jesse Allen
2006-02-13 23:35                     ` Felix Kühling
2006-02-15 16:22                       ` Jesse Allen
2006-02-16 22:00                         ` Dave Airlie
2006-02-14 23:55             ` Gerhard Mack
2006-02-14  0:08         ` Dave Airlie
2006-02-14  0:29           ` Dave Jones
2006-02-14  0:33             ` Dave Airlie
2006-02-13 18:33   ` Mark Fasheh
2006-02-13  6:59 Linux 2.6.16-rc3 Brown, Len
2006-02-13  7:07 Brown, Len
2006-02-13  7:13 ` David S. Miller
2006-02-13  7:43 ` Sanjoy Mahajan
2006-02-13  8:02 Brown, Len
2006-02-13  8:12 ` Andrew Morton
2006-02-13  8:42   ` Sanjoy Mahajan
2006-02-13  8:57   ` Arjan van de Ven
2006-02-14  3:08     ` Michal Jaegermann
2006-02-14  3:28       ` Andrew Morton
2006-02-14  4:48         ` Dave Jones
2006-02-14  5:29         ` Arjan van de Ven
2006-02-14  6:22         ` Michal Jaegermann
2006-02-16 23:04         ` Pavel Machek
2006-02-14  3:30       ` Lee Revell
2006-02-14  6:55         ` Michal Jaegermann
2006-02-14  5:31       ` Arjan van de Ven
2006-02-14 21:17 ` Sanjoy Mahajan
2006-02-14  6:23 Brown, Len

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=1140054960.3037.5.camel@mulgrave.il.steeleye.com \
    --to=james.bottomley@steeleye.com \
    --cc=Nicolas.Mailhot@LaPoste.net \
    --cc=akpm@osdl.org \
    --cc=andrew.vasquez@qlogic.com \
    --cc=arvidjaar@mail.ru \
    --cc=axboe@suse.de \
    --cc=bcrl@kvack.org \
    --cc=bni.swe@gmail.com \
    --cc=davem@davemloft.net \
    --cc=fluido@fluido.as \
    --cc=gbruchhaeuser@gmx.de \
    --cc=ghrt@dial.kappa.ro \
    --cc=greg@kroah.com \
    --cc=helgehaf@aitel.hist.no \
    --cc=jinhong.hu@gmail.com \
    --cc=len.brown@intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    --cc=lk@bencastricum.nl \
    --cc=luming.yu@intel.com \
    --cc=p_christ@hol.gr \
    --cc=patrizio.bassi@gmail.com \
    --cc=perex@suse.cz \
    --cc=sanjoy@mrao.cam.ac.uk \
    --cc=tiwai@suse.de \
    --cc=torvalds@osdl.org \
    /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

all inboxes | Powered by JetHome®