Skip to contentSkip to conversation

driver core patches for 2.6.31-rc2

PATCH In review Greg KH 4 participants 15 messages Apr 17, 2009 – Apr 28, 2009

Subsystems (6)
lore
Share & tools
lore

Greg KH

author
#0 lore raw

PATCH 1/1 driver core patches for 2.6.31-rc2

Here are a few driver-core patches for your 2.6.31-rc2 tree.

The biggest patch here is the addition of the early platform driver api. This patch has been in the -mm tree for a few major kernel releases now (around 5 months), and there are a number of drivers pending in some of the arch trees that depend on this api being present. It doesn't affect any x86 code, so the majority of the world will have no problems with this, and it all gets thrown away after init starts up, so it has no affect on memory sizes.

Other than that, it's just a few bugfixes and tweaks.

Please pull from:
master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-core-2.6.git/

All of these patches have been in the linux-next and mm trees for a while.

The patches will be sent as a follow-on to this message to lkml for people to see.

thanks,

greg k-h

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

 Documentation/driver-model/platform.txt |   59 ++++++++
 drivers/base/base.h                     |    2 +-
 drivers/base/core.c                     |    3 +
 drivers/base/platform.c                 |  239 +++++++++++++++++++++++++++++++
 drivers/uio/uio_cif.c                   |    1 +
 fs/proc/base.c                          |    4 +-
 fs/sysfs/file.c                         |   16 ++-
 include/linux/dynamic_debug.h           |    2 +-
 include/linux/init.h                    |    1 +
 include/linux/kernel.h                  |    9 ++
 include/linux/platform_device.h         |   42 ++++++
 init/main.c                             |    7 +-
 lib/kobject_uevent.c                    |    2 +-
 13 files changed, 378 insertions(+), 9 deletions(-)

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

Alex Chiang (1):
sysfs: don't use global workqueue in sysfs_schedule_callback()

Greg Kroah-Hartman (1):
driver core: prevent device_for_each_child from oopsing

Hans J. Koch (1):
UIO: fix specific device driver missing statement for depmod

Jason Baron (1):
Driver core: remove pr_fmt() from dynamic_dev_dbg() printk

KOSAKI Motohiro (2):
sysfs: sysfs poll keep the poll rule of regular file.
proc: mounts_poll() make consistent to mdstat_poll

Kay Sievers (1):
driver core: allow non-root users to listen to uevents

Magnus Damm (1):
Driver Core: early platform driver

Michael Ellerman (1):
dynamic debug: resurrect old pr_debug() semantics as pr_devel()

Ming Lei (1):
driver core: fix driver_match_device

#1 lore raw

PATCH 1/10 sysfs: don't use global workqueue in sysfs_schedule_callback()

From: Alex Chiang <[email protected]>

A sysfs attribute using sysfs_schedule_callback() to commit suicide may end up calling device_unregister(), which will eventually call a driver's ->remove function.

Drivers may call flush_scheduled_work() in their shutdown routines, in which case lockdep will complain with something like the following:

=============================================
[ INFO: possible recursive locking detected ] 2.6.29-rc8-kk #1
---------------------------------------------
events/4/56 is trying to acquire lock:
(events){--..}, at: [<ffffffff80257fc0>] flush_workqueue+0x0/0xa0

but task is already holding lock:
(events){--..}, at: [<ffffffff80257648>] run_workqueue+0x108/0x230

other info that might help us debug this:
3 locks held by events/4/56:

  #0:  (events){--..}, at: [<ffffffff80257648>] run_workqueue+0x108/0x230
  #1:  (&ss->work){--..}, at: [<ffffffff80257648>] run_workqueue+0x108/0x230
  #2:  (pci_remove_rescan_mutex){--..}, at: [<ffffffff803c10d1>] remove_callback+0x21/0x40
  stack backtrace:
  Pid: 56, comm: events/4 Not tainted 2.6.29-rc8-kk #1
  Call Trace:
  [<ffffffff8026dfcd>] validate_chain+0xb7d/0x1260
  [<ffffffff8026eade>] __lock_acquire+0x42e/0xa40
  [<ffffffff8026f148>] lock_acquire+0x58/0x80
  [<ffffffff80257fc0>] ? flush_workqueue+0x0/0xa0
  [<ffffffff8025800d>] flush_workqueue+0x4d/0xa0
  [<ffffffff80257fc0>] ? flush_workqueue+0x0/0xa0
  [<ffffffff80258070>] flush_scheduled_work+0x10/0x20
  [<ffffffffa0144065>] e1000_remove+0x55/0xfe [e1000e]
  [<ffffffff8033ee30>] ? sysfs_schedule_callback_work+0x0/0x50
  [<ffffffff803bfeb2>] pci_device_remove+0x32/0x70
  [<ffffffff80441da9>] __device_release_driver+0x59/0x90
  [<ffffffff80441edb>] device_release_driver+0x2b/0x40
  [<ffffffff804419d6>] bus_remove_device+0xa6/0x120
  [<ffffffff8043e46b>] device_del+0x12b/0x190
  [<ffffffff8043e4f6>] device_unregister+0x26/0x70
  [<ffffffff803ba969>] pci_stop_dev+0x49/0x60
  [<ffffffff803baab0>] pci_remove_bus_device+0x40/0xc0
  [<ffffffff803c10d9>] remove_callback+0x29/0x40
  [<ffffffff8033ee4f>] sysfs_schedule_callback_work+0x1f/0x50
  [<ffffffff8025769a>] run_workqueue+0x15a/0x230
  [<ffffffff80257648>] ? run_workqueue+0x108/0x230
  [<ffffffff8025846f>] worker_thread+0x9f/0x100
  [<ffffffff8025bce0>] ? autoremove_wake_function+0x0/0x40
  [<ffffffff802583d0>] ? worker_thread+0x0/0x100
  [<ffffffff8025b89d>] kthread+0x4d/0x80
  [<ffffffff8020d4ba>] child_rip+0xa/0x20
  [<ffffffff8020cebc>] ? restore_args+0x0/0x30
  [<ffffffff8025b850>] ? kthread+0x0/0x80
  [<ffffffff8020d4b0>] ? child_rip+0x0/0x20

Although we know that the device_unregister path will never acquire a lock that a driver might try to acquire in its ->remove, in general we should never attempt to flush a workqueue from within the same workqueue, and lockdep rightly complains.

So as long as sysfs attributes cannot commit suicide directly and we are stuck with this callback mechanism, put the sysfs callbacks on their own workqueue instead of the global one.

This has the side benefit that if a suicidal sysfs attribute kicks off a long chain of ->remove callbacks, we no longer induce a long delay on the global queue.

This also fixes a missing module_put in the error path introduced by sysfs-only-allow-one-scheduled-removal-callback-per-kobj.patch.

We never destroy the workqueue, but I'm not sure that's a problem.

---
 fs/sysfs/file.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
fs/sysfs/file.c +11 -1
index 289c43a..979e937 100644
@@ -667,6 +667,7 @@ struct sysfs_schedule_callback_struct {
 	struct work_struct	work;
 };
 
+static struct workqueue_struct *sysfs_workqueue;
 static DEFINE_MUTEX(sysfs_workq_mutex);
 static LIST_HEAD(sysfs_workq);
 static void sysfs_schedule_callback_work(struct work_struct *work)
@@ -715,11 +716,20 @@ int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *),
 	mutex_lock(&sysfs_workq_mutex);
 	list_for_each_entry_safe(ss, tmp, &sysfs_workq, workq_list)
 		if (ss->kobj == kobj) {
+			module_put(owner);
 			mutex_unlock(&sysfs_workq_mutex);
 			return -EAGAIN;
 		}
 	mutex_unlock(&sysfs_workq_mutex);
 
+	if (sysfs_workqueue == NULL) {
+		sysfs_workqueue = create_workqueue("sysfsd");
+		if (sysfs_workqueue == NULL) {
+			module_put(owner);
+			return -ENOMEM;
+		}
+	}
+
 	ss = kmalloc(sizeof(*ss), GFP_KERNEL);
 	if (!ss) {
 		module_put(owner);
@@ -735,7 +745,7 @@ int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *),
 	mutex_lock(&sysfs_workq_mutex);
 	list_add_tail(&ss->workq_list, &sysfs_workq);
 	mutex_unlock(&sysfs_workq_mutex);
-	schedule_work(&ss->work);
+	queue_work(sysfs_workqueue, &ss->work);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(sysfs_schedule_callback);
Signature · 1 line
1.6.2
maintainer
#2 lore raw

Re: [PATCH 01/10] sysfs: don't use global workqueue in sysfs_schedule_callback()

Quoted 63 lines · On Fri, 17 Apr 2009 12:04:25 -0700 Greg Kroah-Hartman <[email protected]> wrote:

From: Alex Chiang <[email protected]>

A sysfs attribute using sysfs_schedule_callback() to commit suicide may end up calling device_unregister(), which will eventually call a driver's ->remove function.

Drivers may call flush_scheduled_work() in their shutdown routines, in which case lockdep will complain with something like the following:

=============================================
[ INFO: possible recursive locking detected ] 2.6.29-rc8-kk #1
---------------------------------------------
events/4/56 is trying to acquire lock:
(events){--..}, at: [<ffffffff80257fc0>] flush_workqueue+0x0/0xa0

but task is already holding lock:
(events){--..}, at: [<ffffffff80257648>] run_workqueue+0x108/0x230

other info that might help us debug this:
3 locks held by events/4/56:

  #0:  (events){--..}, at: [<ffffffff80257648>] run_workqueue+0x108/0x230
  #1:  (&ss->work){--..}, at: [<ffffffff80257648>] run_workqueue+0x108/0x230
  #2:  (pci_remove_rescan_mutex){--..}, at: [<ffffffff803c10d1>] remove_callback+0x21/0x40
  stack backtrace:
  Pid: 56, comm: events/4 Not tainted 2.6.29-rc8-kk #1
  Call Trace:
  [<ffffffff8026dfcd>] validate_chain+0xb7d/0x1260
  [<ffffffff8026eade>] __lock_acquire+0x42e/0xa40
  [<ffffffff8026f148>] lock_acquire+0x58/0x80
  [<ffffffff80257fc0>] ? flush_workqueue+0x0/0xa0
  [<ffffffff8025800d>] flush_workqueue+0x4d/0xa0
  [<ffffffff80257fc0>] ? flush_workqueue+0x0/0xa0
  [<ffffffff80258070>] flush_scheduled_work+0x10/0x20
  [<ffffffffa0144065>] e1000_remove+0x55/0xfe [e1000e]
  [<ffffffff8033ee30>] ? sysfs_schedule_callback_work+0x0/0x50
  [<ffffffff803bfeb2>] pci_device_remove+0x32/0x70
  [<ffffffff80441da9>] __device_release_driver+0x59/0x90
  [<ffffffff80441edb>] device_release_driver+0x2b/0x40
  [<ffffffff804419d6>] bus_remove_device+0xa6/0x120
  [<ffffffff8043e46b>] device_del+0x12b/0x190
  [<ffffffff8043e4f6>] device_unregister+0x26/0x70
  [<ffffffff803ba969>] pci_stop_dev+0x49/0x60
  [<ffffffff803baab0>] pci_remove_bus_device+0x40/0xc0
  [<ffffffff803c10d9>] remove_callback+0x29/0x40
  [<ffffffff8033ee4f>] sysfs_schedule_callback_work+0x1f/0x50
  [<ffffffff8025769a>] run_workqueue+0x15a/0x230
  [<ffffffff80257648>] ? run_workqueue+0x108/0x230
  [<ffffffff8025846f>] worker_thread+0x9f/0x100
  [<ffffffff8025bce0>] ? autoremove_wake_function+0x0/0x40
  [<ffffffff802583d0>] ? worker_thread+0x0/0x100
  [<ffffffff8025b89d>] kthread+0x4d/0x80
  [<ffffffff8020d4ba>] child_rip+0xa/0x20
  [<ffffffff8020cebc>] ? restore_args+0x0/0x30
  [<ffffffff8025b850>] ? kthread+0x0/0x80
  [<ffffffff8020d4b0>] ? child_rip+0x0/0x20

Although we know that the device_unregister path will never acquire a lock that a driver might try to acquire in its ->remove, in general we should never attempt to flush a workqueue from within the same workqueue, and lockdep rightly complains.

Quoted 7 lines

So as long as sysfs attributes cannot commit suicide directly and we are stuck with this callback mechanism, put the sysfs callbacks on their own workqueue instead of the global one.

This has the side benefit that if a suicidal sysfs attribute kicks off a long chain of ->remove callbacks, we no longer induce a long delay on the global queue.

I still don't know why I merged

: commit 2355b70fd59cb5be7de2052a9edeee7afb7ff099
: Author: Lai Jiangshan <[email protected]>
: Date: Thu Apr 2 16:58:24 2009 -0700
:
: workqueue: avoid recursion in run_workqueue()

there was nothing wrong with permitting limited recursion into run_workqueue(). It never deadlocked and the three-deep-recursion warning never triggered.

fs/sysfs/file.c int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *), · line 731

Quoted 7 lines
fs/sysfs/file.c +7 -0
+	if (sysfs_workqueue == NULL) {
+		sysfs_workqueue = create_workqueue("sysfsd");
+		if (sysfs_workqueue == NULL) {
+			module_put(owner);
+			return -ENOMEM;
+		}
+	}

This will create a kernel thread per CPU. Surely
create_singlethread_workqueue() will suffice?

#3 lore raw

Re: [PATCH 01/10] sysfs: don't use global workqueue in sysfs_schedule_callback()

* Andrew Morton <[email protected]>:

Quoted 82 lines
Quoted 63 lines · On Fri, 17 Apr 2009 12:04:25 -0700 Greg Kroah-Hartman <[email protected]> wrote:

From: Alex Chiang <[email protected]>

A sysfs attribute using sysfs_schedule_callback() to commit suicide may end up calling device_unregister(), which will eventually call a driver's ->remove function.

Drivers may call flush_scheduled_work() in their shutdown routines, in which case lockdep will complain with something like the following:

=============================================
[ INFO: possible recursive locking detected ] 2.6.29-rc8-kk #1
---------------------------------------------
events/4/56 is trying to acquire lock:
(events){--..}, at: [<ffffffff80257fc0>] flush_workqueue+0x0/0xa0

but task is already holding lock:
(events){--..}, at: [<ffffffff80257648>] run_workqueue+0x108/0x230

other info that might help us debug this:
3 locks held by events/4/56:

  #0:  (events){--..}, at: [<ffffffff80257648>] run_workqueue+0x108/0x230
  #1:  (&ss->work){--..}, at: [<ffffffff80257648>] run_workqueue+0x108/0x230
  #2:  (pci_remove_rescan_mutex){--..}, at: [<ffffffff803c10d1>] remove_callback+0x21/0x40
  stack backtrace:
  Pid: 56, comm: events/4 Not tainted 2.6.29-rc8-kk #1
  Call Trace:
  [<ffffffff8026dfcd>] validate_chain+0xb7d/0x1260
  [<ffffffff8026eade>] __lock_acquire+0x42e/0xa40
  [<ffffffff8026f148>] lock_acquire+0x58/0x80
  [<ffffffff80257fc0>] ? flush_workqueue+0x0/0xa0
  [<ffffffff8025800d>] flush_workqueue+0x4d/0xa0
  [<ffffffff80257fc0>] ? flush_workqueue+0x0/0xa0
  [<ffffffff80258070>] flush_scheduled_work+0x10/0x20
  [<ffffffffa0144065>] e1000_remove+0x55/0xfe [e1000e]
  [<ffffffff8033ee30>] ? sysfs_schedule_callback_work+0x0/0x50
  [<ffffffff803bfeb2>] pci_device_remove+0x32/0x70
  [<ffffffff80441da9>] __device_release_driver+0x59/0x90
  [<ffffffff80441edb>] device_release_driver+0x2b/0x40
  [<ffffffff804419d6>] bus_remove_device+0xa6/0x120
  [<ffffffff8043e46b>] device_del+0x12b/0x190
  [<ffffffff8043e4f6>] device_unregister+0x26/0x70
  [<ffffffff803ba969>] pci_stop_dev+0x49/0x60
  [<ffffffff803baab0>] pci_remove_bus_device+0x40/0xc0
  [<ffffffff803c10d9>] remove_callback+0x29/0x40
  [<ffffffff8033ee4f>] sysfs_schedule_callback_work+0x1f/0x50
  [<ffffffff8025769a>] run_workqueue+0x15a/0x230
  [<ffffffff80257648>] ? run_workqueue+0x108/0x230
  [<ffffffff8025846f>] worker_thread+0x9f/0x100
  [<ffffffff8025bce0>] ? autoremove_wake_function+0x0/0x40
  [<ffffffff802583d0>] ? worker_thread+0x0/0x100
  [<ffffffff8025b89d>] kthread+0x4d/0x80
  [<ffffffff8020d4ba>] child_rip+0xa/0x20
  [<ffffffff8020cebc>] ? restore_args+0x0/0x30
  [<ffffffff8025b850>] ? kthread+0x0/0x80
  [<ffffffff8020d4b0>] ? child_rip+0x0/0x20

Although we know that the device_unregister path will never acquire a lock that a driver might try to acquire in its ->remove, in general we should never attempt to flush a workqueue from within the same workqueue, and lockdep rightly complains.

Quoted 7 lines

So as long as sysfs attributes cannot commit suicide directly and we are stuck with this callback mechanism, put the sysfs callbacks on their own workqueue instead of the global one.

This has the side benefit that if a suicidal sysfs attribute kicks off a long chain of ->remove callbacks, we no longer induce a long delay on the global queue.

I still don't know why I merged

: commit 2355b70fd59cb5be7de2052a9edeee7afb7ff099
: Author: Lai Jiangshan <[email protected]>
: Date: Thu Apr 2 16:58:24 2009 -0700
:
: workqueue: avoid recursion in run_workqueue()

Quoted 3 lines

there was nothing wrong with permitting limited recursion into run_workqueue(). It never deadlocked and the three-deep-recursion warning never triggered.

According to Peter Zjilstra and Lai Jiangshan, there actually is danger of deadlock when flushing a workqueue from the same workqueue:

	http://thread.gmane.org/gmane.linux.kernel.pci/3713/focus=811703

And in any case, I think it's a good idea to avoid the global workqueue, as removing a PCI bridge near the root of the hierarchy may result in a longish series of operations as we unregister drivers, etc.

Quoted 10 lines

fs/sysfs/file.c int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *), · line 731

Quoted 7 lines
fs/sysfs/file.c +7 -0
+	if (sysfs_workqueue == NULL) {
+		sysfs_workqueue = create_workqueue("sysfsd");
+		if (sysfs_workqueue == NULL) {
+			module_put(owner);
+			return -ENOMEM;
+		}
+	}

This will create a kernel thread per CPU. Surely
create_singlethread_workqueue() will suffice?

Oh darn, you are right. We do not need a per-CPU thread. I will queue up a patch to use create_singlethread_workqueue.

Thanks for the review.

/ac

#4 lore raw

PATCH 2/10 driver core: fix driver_match_device

In reply to Greg KH

From: Ming Lei <[email protected]>

This patch fixes a bug introduced in commit
49b420a13ff95b449947181190b08367348e3e1b.

If a instance of bus_type doesn't have .match method, all .probe of drivers in the bus should be called, or else the .probe have not a chance to be called.

---
 drivers/base/base.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/base/base.h +1 -1
index ddc9749..b528145 100644
@@ -115,7 +115,7 @@ extern int driver_probe_device(struct device_driver *drv, struct device *dev);
 static inline int driver_match_device(struct device_driver *drv,
 				      struct device *dev)
 {
-	return drv->bus->match && drv->bus->match(dev, drv);
+	return drv->bus->match ? drv->bus->match(dev, drv) : 1;
 }
 
 extern void sysdev_shutdown(void);
Signature · 1 line
1.6.2
#5 lore raw

PATCH 3/10 driver core: allow non-root users to listen to uevents

In reply to Greg KH

From: Kay Sievers <[email protected]>

Users can read sysfs files, there is no reason they should not be allowed to listen to uevents. This lets xorg and other userspace programs properly get these messages without having to be root.

---
 lib/kobject_uevent.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
lib/kobject_uevent.c +1 -1
index dafeecf..920a3ca 100644
@@ -328,7 +328,7 @@ static int __init kobject_uevent_init(void)
 		       "kobject_uevent: unable to create netlink socket!\n");
 		return -ENODEV;
 	}
-
+	netlink_set_nonroot(NETLINK_KOBJECT_UEVENT, NL_NONROOT_RECV);
 	return 0;
 }
 
Signature · 1 line
1.6.2
#6 lore raw

PATCH 4/10 sysfs: sysfs poll keep the poll rule of regular file.

In reply to Greg KH

From: KOSAKI Motohiro <[email protected]>

Currently, following test programs don't finished.

% ruby -e '
Thread.new { sleep } File.read("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies") '

strace expose the reason.

...
open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies", O_RDONLY|O_LARGEFILE) = 3 ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbf9fa6b8) = -1 ENOTTY (Inappropriate ioctl for device) fstat64(3, {st_mode=S_IFREG|0444, st_size=4096, ...}) = 0
_llseek(3, 0, [0], SEEK_CUR) = 0
select(4, [3], NULL, NULL, NULL) = 1 (in [3])
read(3, "1400000 1300000 1200000 1100000 1"..., 4096) = 62
select(4, [3], NULL, NULL, NULL

Because Ruby (the scripting language) VM assume select system-call against regular file don't block. it because SUSv3 says "Regular files shall always poll TRUE for reading and writing". see
http://www.opengroup.org/onlinepubs/009695399/functions/poll.html it seems valid assumption.

But sysfs_poll() don't keep this rule although sysfs file can read and write always.

This patch restore proper poll behavior to sysfs. /sys/block/md*/md/sync_action polling application and another sysfs updating sensitive application still can use POLLERR and POLLPRI.

---
 fs/sysfs/file.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
fs/sysfs/file.c +2 -2
index 979e937..b1606e0 100644
@@ -446,11 +446,11 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
 	if (buffer->event != atomic_read(&od->event))
 		goto trigger;
 
-	return 0;
+	return DEFAULT_POLLMASK;
 
  trigger:
 	buffer->needs_read_fill = 1;
-	return POLLERR|POLLPRI;
+	return DEFAULT_POLLMASK|POLLERR|POLLPRI;
 }
 
 void sysfs_notify_dirent(struct sysfs_dirent *sd)
Signature · 1 line
1.6.2
#7 lore raw

PATCH 5/10 proc: mounts_poll() make consistent to mdstat_poll

In reply to Greg KH

From: KOSAKI Motohiro <[email protected]>

In recently sysfs_poll discussion, Neil Brown pointed out /proc/mounts also should be fixed.

SUSv3 says "Regular files shall always poll TRUE for reading and writing". see
http://www.opengroup.org/onlinepubs/009695399/functions/poll.html

Then, mounts_poll()'s default should be "POLLIN | POLLRDNORM". it mean always readable.

In addition, event trigger should use "POLLERR | POLLPRI" instead POLLERR. it makes consistent to mdstat_poll() and sysfs_poll(). and, select(2) can handle POLLPRI easily.

---
 fs/proc/base.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
fs/proc/base.c +2 -2
index f715597..aa763ab 100644
@@ -648,14 +648,14 @@ static unsigned mounts_poll(struct file *file, poll_table *wait)
 {
 	struct proc_mounts *p = file->private_data;
 	struct mnt_namespace *ns = p->ns;
-	unsigned res = 0;
+	unsigned res = POLLIN | POLLRDNORM;
 
 	poll_wait(file, &ns->poll, wait);
 
 	spin_lock(&vfsmount_lock);
 	if (p->event != ns->event) {
 		p->event = ns->event;
-		res = POLLERR;
+		res |= POLLERR | POLLPRI;
 	}
 	spin_unlock(&vfsmount_lock);
 
Signature · 1 line
1.6.2
#8 lore raw

PATCH 6/10 Driver Core: early platform driver

In reply to Greg KH

From: Magnus Damm <[email protected]>

V3 of the early platform driver implementation.

Platform drivers are great for embedded platforms because we can separate driver configuration from the actual driver. So base addresses, interrupts and other configuration can be kept with the processor or board code, and the platform driver can be reused by many different platforms.

For early devices we have nothing today. For instance, to configure early timers and early serial ports we cannot use platform devices. This because the setup order during boot. Timers are needed before the platform driver core code is available. The same goes for early printk support. Early in this case means before initcalls.

These early drivers today have their configuration either hard coded or they receive it using some special configuration method. This is working quite well, but if we want to support both regular kernel modules and early devices then we need to have two ways of configuring the same driver. A single way would be better.

The early platform driver patch is basically a set of functions that allow drivers to register themselves and architecture code to locate them and probe. Registration happens through early_param(). The time for the probe is decided by the architecture code.

See Documentation/driver-model/platform.txt for more details.

[[email protected]: coding-style fixes]
Cc Paul Mundt <[email protected]>
Cc Kay Sievers <[email protected]>
Cc David Brownell <[email protected]>
Cc Tejun Heo <[email protected]>
---
 Documentation/driver-model/platform.txt |   59 ++++++++
 drivers/base/platform.c                 |  239 +++++++++++++++++++++++++++++++
 include/linux/init.h                    |    1 +
 include/linux/platform_device.h         |   42 ++++++
 init/main.c                             |    7 +-
 5 files changed, 347 insertions(+), 1 deletions(-)
Documentation/driver-model/platform.txt +59 -0
index 83009fd..2e2c2ea 100644
@@ -169,3 +169,62 @@ three different ways to find such a match:
       be probed later if another device registers.  (Which is OK, since
       this interface is only for use with non-hotpluggable devices.)
 
+
+Early Platform Devices and Drivers
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The early platform interfaces provide platform data to platform device
+drivers early on during the system boot. The code is built on top of the
+early_param() command line parsing and can be executed very early on.
+
+Example: "earlyprintk" class early serial console in 6 steps
+
+1. Registering early platform device data
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The architecture code registers platform device data using the function
+early_platform_add_devices(). In the case of early serial console this
+should be hardware configuration for the serial port. Devices registered
+at this point will later on be matched against early platform drivers.
+
+2. Parsing kernel command line
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The architecture code calls parse_early_param() to parse the kernel
+command line. This will execute all matching early_param() callbacks.
+User specified early platform devices will be registered at this point.
+For the early serial console case the user can specify port on the
+kernel command line as "earlyprintk=serial.0" where "earlyprintk" is
+the class string, "serial" is the name of the platfrom driver and
+0 is the platform device id. If the id is -1 then the dot and the
+id can be omitted.
+
+3. Installing early platform drivers belonging to a certain class
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The architecture code may optionally force registration of all early
+platform drivers belonging to a certain class using the function
+early_platform_driver_register_all(). User specified devices from
+step 2 have priority over these. This step is omitted by the serial
+driver example since the early serial driver code should be disabled
+unless the user has specified port on the kernel command line.
+
+4. Early platform driver registration
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Compiled-in platform drivers making use of early_platform_init() are
+automatically registered during step 2 or 3. The serial driver example
+should use early_platform_init("earlyprintk", &platform_driver).
+
+5. Probing of early platform drivers belonging to a certain class
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The architecture code calls early_platform_driver_probe() to match
+registered early platform devices associated with a certain class with
+registered early platform drivers. Matched devices will get probed().
+This step can be executed at any point during the early boot. As soon
+as possible may be good for the serial port case.
+
+6. Inside the early platform driver probe()
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The driver code needs to take special care during early boot, especially
+when it comes to memory allocation and interrupt registration. The code
+in the probe() function can use is_early_platform_device() to check if
+it is called at early platform device or at the regular platform device
+time. The early serial driver performs register_console() at this point.
+
+For further information, see <linux/platform_device.h>.
drivers/base/platform.c +239 -0

248 lines not on this page · raw message

include/linux/init.h +1 -0
index 68cb026..f121a7a 100644
@@ -247,6 +247,7 @@ struct obs_kernel_param {
 
 /* Relies on boot_command_line being set */
 void __init parse_early_param(void);
+void __init parse_early_options(char *cmdline);
 #endif /* __ASSEMBLY__ */
 
 /**
include/linux/platform_device.h +42 -0

46 lines not on this page · raw message

init/main.c +6 -1
index 3585f07..3bbf93b 100644
@@ -492,6 +492,11 @@ static int __init do_early_param(char *param, char *val)
 	return 0;
 }
 
+void __init parse_early_options(char *cmdline)
+{
+	parse_args("early options", cmdline, NULL, 0, do_early_param);
+}
+
 /* Arch code calls this early on, or if not, just before other parsing. */
 void __init parse_early_param(void)
 {
@@ -503,7 +508,7 @@ void __init parse_early_param(void)
 
 	/* All fall through to do_early_param. */
 	strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
-	parse_args("early options", tmp_cmdline, NULL, 0, do_early_param);
+	parse_early_options(tmp_cmdline);
 	done = 1;
 }
 
Signature · 1 line
1.6.2
#9 lore raw

PATCH 7/10 dynamic debug: resurrect old pr_debug() semantics as pr_devel()

In reply to Greg KH

From: Michael Ellerman <[email protected]>

pr_debug() used to produce zero code unless DEBUG was #defined. This is now no longer the case in practice[1].

There are places where it's useful to have debugging printks, but we don't want them to generate any code in production kernels.

So add a new macro, pr_devel(), for _devel_opment, to provide the old semantics, ie. if the programmer doesn't explicitly enable debugging, no code is produced.

[1]: You can turn CONFIG_DYNAMIC_DEBUG off, but it's enabled in at least
one distro kernel, so it's not really a solution.

---
 include/linux/kernel.h |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
include/linux/kernel.h +9 -0
index d9e75ec..883cd44 100644
@@ -377,6 +377,15 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
 #define pr_cont(fmt, ...) \
 	printk(KERN_CONT fmt, ##__VA_ARGS__)
 
+/* pr_devel() should produce zero code unless DEBUG is defined */
+#ifdef DEBUG
+#define pr_devel(fmt, ...) \
+	printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
+#else
+#define pr_devel(fmt, ...) \
+	({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
+#endif
+
 /* If you are writing a driver, please use dev_dbg instead */
 #if defined(DEBUG)
 #define pr_debug(fmt, ...) \
Signature · 1 line
1.6.2
#10 lore raw

PATCH 8/10 driver core: prevent device_for_each_child from oopsing

In reply to Greg KH

David Vrabel noticed that the wireless usb stack likes to call device_for_each_chile() with an empty bus. This used to work fine, but now oopses. This patch fixes the oops and makes the code behave like it used to.

---
 drivers/base/core.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/base/core.c +3 -0
index e73c92d..d230ff4 100644
@@ -1142,6 +1142,9 @@ int device_for_each_child(struct device *parent, void *data,
 	struct device *child;
 	int error = 0;
 
+	if (!parent->p)
+		return 0;
+
 	klist_iter_init(&parent->p->klist_children, &i);
 	while ((child = next_device(&i)) && !error)
 		error = fn(child, data);
Signature · 1 line
1.6.2
#11 lore raw

PATCH 9/10 Driver core: remove pr_fmt() from dynamic_dev_dbg() printk

In reply to Greg KH

From: Jason Baron <[email protected]>

When pr_fmt() was added to the pr_debug() code, we added it not only to the dynamic_pr_debug() function, but also to the dynamic_dev_dbg() funciton. However, dev_dbg() doesn't make use of pr_fmt(), so neither should dynamic_dev_dbg().

---
 include/linux/dynamic_debug.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/dynamic_debug.h +1 -1
index baabf33..a0d9422 100644
@@ -70,7 +70,7 @@ extern int ddebug_remove_module(char *mod_name);
 		DEBUG_HASH2, __LINE__, _DPRINTK_FLAGS_DEFAULT };	\
 	if (__dynamic_dbg_enabled(descriptor))				\
 			dev_printk(KERN_DEBUG, dev,			\
-					KBUILD_MODNAME ": " pr_fmt(fmt),\
+					KBUILD_MODNAME ": " fmt,	\
 					##__VA_ARGS__);			\
 	} while (0)
 
Signature · 1 line
1.6.2
#12 lore raw

PATCH 10/10 UIO: fix specific device driver missing statement for depmod

In reply to Greg KH

From: Hans J. Koch <[email protected]>

Quoted 4 lines · Andrew Morton
Quoted 1 line · On Fri, 10 Apr 2009 13:32:01 GMT [email protected] wrote:

http://bugzilla.kernel.org/show_bug.cgi?id=13059

drivers/uio/uio_cif.c misses a MODULE_DEVICE_TABLE, this fixes it.

---
 drivers/uio/uio_cif.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/uio/uio_cif.c +1 -0
index c60b8fc..28034c8 100644
@@ -147,5 +147,6 @@ static void __exit hilscher_exit_module(void)
 module_init(hilscher_init_module);
 module_exit(hilscher_exit_module);
 
+MODULE_DEVICE_TABLE(pci, hilscher_pci_ids);
 MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Hans J. Koch, Benedikt Spranger");
Signature · 1 line
1.6.2
#13 lore raw
In reply to Greg KH

2009/4/18 Greg KH <[email protected]>:

Quoted 1 line

Here are a few driver-core patches for your 2.6.31-rc2 tree.

2.6.30-rc2?

Quoted 8 lines

The biggest patch here is the addition of the early platform driver api. This patch has been in the -mm tree for a few major kernel releases now (around 5 months), and there are a number of drivers pending in some of the arch trees that depend on this api being present.  It doesn't affect any x86 code, so the majority of the world will have no problems with this, and it all gets thrown away after init starts up, so it has no affect on memory sizes.

author
#14 lore raw
Quoted 4 lines · KOSAKI Motohiro

2009/4/18 Greg KH <[email protected]>:

Quoted 1 line

Here are a few driver-core patches for your 2.6.31-rc2 tree.

2.6.30-rc2?

Yeah, sorry, I'm numerically challenged at times :)