From cf587ffca489455f8fa2dbc57e1cbbf77bf5d27f Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 12 Aug 2003 20:45:56 -0700 Subject: [PATCH] PCI: add PCI_DEVICE() macro to make pci_device_id tables easier to read. --- include/linux/pci.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include/linux') diff --git a/include/linux/pci.h b/include/linux/pci.h index a4c7a4c7965e..90619534463e 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -524,6 +524,18 @@ struct pci_driver { #define to_pci_driver(drv) container_of(drv,struct pci_driver, driver) +/** + * PCI_DEVICE - macro used to describe a specific pci device + * @vend: the 16 bit PCI Vendor ID + * @dev: the 16 bit PCI Device ID + * + * This macro is used to create a struct pci_device_id that matches a + * specific device. The subvendor and subdevice fields will be set to + * PCI_ANY_ID. + */ +#define PCI_DEVICE(vend,dev) \ + .vendor = (vend), .device = (dev), \ + .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID /* these external functions are only available when PCI support is enabled */ #ifdef CONFIG_PCI -- cgit v1.2.3 From 7c8114e7088a4db8eea6383626a4232c7031fb80 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 18 Aug 2003 01:22:01 -0700 Subject: [PATCH] PCI: add PCI_DEVICE_CLASS() macro to match PCI_DEVICE() macro. --- include/linux/pci.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include/linux') diff --git a/include/linux/pci.h b/include/linux/pci.h index 90619534463e..55e296dd57e3 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -537,6 +537,20 @@ struct pci_driver { .vendor = (vend), .device = (dev), \ .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID +/** + * PCI_DEVICE_CLASS - macro used to describe a specific pci device class + * @dev_class: the class, subclass, prog-if triple for this device + * @dev_class_mask: the class mask for this device + * + * This macro is used to create a struct pci_device_id that matches a + * specific PCI class. The vendor, device, subvendor, and subdevice + * fields will be set to PCI_ANY_ID. + */ +#define PCI_DEVICE_CLASS(dev_class,dev_class_mask) \ + .class = (dev_class), .class_mask = (dev_class_mask), \ + .vendor = PCI_ANY_ID, .device = PCI_ANY_ID, \ + .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID + /* these external functions are only available when PCI support is enabled */ #ifdef CONFIG_PCI -- cgit v1.2.3 From 75d01c2efed5f5fcb8d0e65619cb5829decd193d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 20 Aug 2003 02:48:01 -0700 Subject: [PATCH] PCI: add PCI_NAME_SIZE instead of using DEVICE_NAME_SIZE based on a patch from OGAWA Hirofumi --- drivers/pci/names.c | 6 +++--- include/linux/pci.h | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'include/linux') diff --git a/drivers/pci/names.c b/drivers/pci/names.c index 121ad4b52319..eb707bf79dda 100644 --- a/drivers/pci/names.c +++ b/drivers/pci/names.c @@ -80,14 +80,14 @@ void __devinit pci_name_device(struct pci_dev *dev) } /* Ok, found the vendor, but unknown device */ - sprintf(name, "PCI device %04x:%04x (%." DEVICE_NAME_HALF "s)", + sprintf(name, "PCI device %04x:%04x (%." PCI_NAME_HALF "s)", dev->vendor, dev->device, vendor_p->name); return; /* Full match */ match_device: { - char *n = name + sprintf(name, "%." DEVICE_NAME_HALF - "s %." DEVICE_NAME_HALF "s", + char *n = name + sprintf(name, "%." PCI_NAME_HALF + "s %." PCI_NAME_HALF "s", vendor_p->name, device_p->name); int nr = device_p->seen + 1; device_p->seen = nr; diff --git a/include/linux/pci.h b/include/linux/pci.h index 55e296dd57e3..287f8ebc4bf2 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -420,7 +420,9 @@ struct pci_dev { unsigned int transparent:1; /* Transparent PCI bridge */ unsigned int multifunction:1;/* Part of multi-function device */ #ifdef CONFIG_PCI_NAMES - char pretty_name[DEVICE_NAME_SIZE]; /* pretty name for users to see */ +#define PCI_NAME_SIZE 50 +#define PCI_NAME_HALF __stringify(20) /* less than half to handle slop */ + char pretty_name[PCI_NAME_SIZE]; /* pretty name for users to see */ #endif }; -- cgit v1.2.3 From 7d33101cd55d08cdc51ba5abe9290984cd4198d6 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Wed, 20 Aug 2003 10:29:16 -0700 Subject: [PATCH] fix /proc mm_struct refcounting bug From: Suparna Bhattacharya The /proc code's bare atomic_inc(&mm->count) is racy against __exit_mm()'s mmput() on another CPU: it calls mmput() outside task_lock(tsk), and task_lock() isn't appropriate locking anyway. So what happens is: CPU0 CPU1 mmput() ->atomic_dec_and_lock(mm->mm_users) atomic_inc(mm->mm_users) ->list_del(mm->mmlist) mmput() ->atomic_dec_and_lock(mm->mm_users) ->list_del(mm->mmlist) And the double list_del() of course goes splat. So we use mmlist_lock to synchronise these steps. The patch implements a new mmgrab() routine which increments mm_users only if the mm isn't already going away. Changes get_task_mm() and proc_pid_stat() to call mmgrab() instead of a direct atomic_inc(&mm->mm_users). Hugh, there's some cruft in swapoff which looks like it should be using mmgrab()... --- fs/proc/array.c | 2 +- include/linux/sched.h | 4 +++- kernel/fork.c | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) (limited to 'include/linux') diff --git a/fs/proc/array.c b/fs/proc/array.c index 643ccd392f23..a7a3bdaac4ec 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -300,7 +300,7 @@ int proc_pid_stat(struct task_struct *task, char * buffer) task_lock(task); mm = task->mm; if(mm) - atomic_inc(&mm->mm_users); + mm = mmgrab(mm); if (task->tty) { tty_pgrp = task->tty->pgrp; tty_nr = task->tty->device; diff --git a/include/linux/sched.h b/include/linux/sched.h index 61ec12b5b77a..054168543a45 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -638,6 +638,8 @@ static inline void mmdrop(struct mm_struct * mm) /* mmput gets rid of the mappings and all user-space */ extern void mmput(struct mm_struct *); +/* Grab a reference to the mm if its not already going away */ +extern struct mm_struct *mmgrab(struct mm_struct *); /* Remove the current tasks stale references to the old mm_struct */ extern void mm_release(struct task_struct *, struct mm_struct *); @@ -745,7 +747,7 @@ static inline struct mm_struct * get_task_mm(struct task_struct * task) task_lock(task); mm = task->mm; if (mm) - atomic_inc(&mm->mm_users); + mm = mmgrab(mm); task_unlock(task); return mm; diff --git a/kernel/fork.c b/kernel/fork.c index b65c19fe2dce..690b8d77a04b 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -398,6 +398,23 @@ void mmput(struct mm_struct *mm) } } +/* + * Checks if the use count of an mm is non-zero and if so + * returns a reference to it after bumping up the use count. + * If the use count is zero, it means this mm is going away, + * so return NULL. + */ +struct mm_struct *mmgrab(struct mm_struct *mm) +{ + spin_lock(&mmlist_lock); + if (!atomic_read(&mm->mm_users)) + mm = NULL; + else + atomic_inc(&mm->mm_users); + spin_unlock(&mmlist_lock); + return mm; +} + /* Please note the differences between mmput and mm_release. * mmput is called whenever we stop holding onto a mm_struct, * error success whatever. -- cgit v1.2.3 From c8480a1881f8a0422603ee56a95e079709d678a6 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 20 Aug 2003 20:07:11 -0700 Subject: PCI: added the pci_pretty_name() macro to pci.h as 2 arches already had it. --- arch/alpha/kernel/sys_marvel.c | 7 ------- arch/x86_64/kernel/pci-gart.c | 6 ------ include/linux/pci.h | 7 +++++++ 3 files changed, 7 insertions(+), 13 deletions(-) (limited to 'include/linux') diff --git a/arch/alpha/kernel/sys_marvel.c b/arch/alpha/kernel/sys_marvel.c index c5b58f01a790..561122beae58 100644 --- a/arch/alpha/kernel/sys_marvel.c +++ b/arch/alpha/kernel/sys_marvel.c @@ -33,13 +33,6 @@ # error NR_IRQS < MARVEL_NR_IRQS !!! #endif -/* ??? Should probably be generic. */ -#ifdef CONFIG_PCI_NAMES -#define pci_pretty_name(x) ((x)->pretty_name) -#else -#define pci_pretty_name(x) "" -#endif - /* * Interrupt handling. diff --git a/arch/x86_64/kernel/pci-gart.c b/arch/x86_64/kernel/pci-gart.c index 6e97e0daa765..6842d5823465 100644 --- a/arch/x86_64/kernel/pci-gart.c +++ b/arch/x86_64/kernel/pci-gart.c @@ -31,12 +31,6 @@ #include #include -#ifdef CONFIG_PCI_NAMES -#define pci_pretty_name(dev) ((dev)->pretty_name) -#else -#define pci_pretty_name(dev) "" -#endif - dma_addr_t bad_dma_address; unsigned long iommu_bus_base; /* GART remapping area (physical) */ diff --git a/include/linux/pci.h b/include/linux/pci.h index 287f8ebc4bf2..3c4fc6c62773 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -842,6 +842,13 @@ static inline char *pci_name(struct pci_dev *pdev) return pdev->dev.bus_id; } +/* Some archs want to see the pretty pci name, so use this macro */ +#ifdef CONFIG_PCI_NAMES +#define pci_pretty_name(dev) ((dev)->pretty_name) +#else +#define pci_pretty_name(dev) "" +#endif + /* * The world is not perfect and supplies us with broken PCI devices. * For at least a part of these bugs we need a work-around, so both -- cgit v1.2.3