Commit 376f70ac authored by Jiang Liu's avatar Jiang Liu Committed by Bjorn Helgaas

x86/PCI: use RCU list to protect mmconfig list

Use RCU list to protect mmconfig list from dynamic change
when supporting PCI host bridge hotplug.
Reviewed-by: default avatarYinghai Lu <yinghai@kernel.org>
Signed-off-by: default avatarJiang Liu <liuj97@gmail.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
parent 846e4023
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include <linux/bitmap.h> #include <linux/bitmap.h>
#include <linux/dmi.h> #include <linux/dmi.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/mutex.h>
#include <linux/rculist.h>
#include <asm/e820.h> #include <asm/e820.h>
#include <asm/pci_x86.h> #include <asm/pci_x86.h>
#include <asm/acpi.h> #include <asm/acpi.h>
...@@ -25,6 +27,7 @@ ...@@ -25,6 +27,7 @@
/* Indicate if the mmcfg resources have been placed into the resource table. */ /* Indicate if the mmcfg resources have been placed into the resource table. */
static int __initdata pci_mmcfg_resources_inserted; static int __initdata pci_mmcfg_resources_inserted;
static DEFINE_MUTEX(pci_mmcfg_lock);
LIST_HEAD(pci_mmcfg_list); LIST_HEAD(pci_mmcfg_list);
...@@ -45,20 +48,20 @@ static __init void free_all_mmcfg(void) ...@@ -45,20 +48,20 @@ static __init void free_all_mmcfg(void)
pci_mmconfig_remove(cfg); pci_mmconfig_remove(cfg);
} }
static __init void list_add_sorted(struct pci_mmcfg_region *new) static __devinit void list_add_sorted(struct pci_mmcfg_region *new)
{ {
struct pci_mmcfg_region *cfg; struct pci_mmcfg_region *cfg;
/* keep list sorted by segment and starting bus number */ /* keep list sorted by segment and starting bus number */
list_for_each_entry(cfg, &pci_mmcfg_list, list) { list_for_each_entry_rcu(cfg, &pci_mmcfg_list, list) {
if (cfg->segment > new->segment || if (cfg->segment > new->segment ||
(cfg->segment == new->segment && (cfg->segment == new->segment &&
cfg->start_bus >= new->start_bus)) { cfg->start_bus >= new->start_bus)) {
list_add_tail(&new->list, &cfg->list); list_add_tail_rcu(&new->list, &cfg->list);
return; return;
} }
} }
list_add_tail(&new->list, &pci_mmcfg_list); list_add_tail_rcu(&new->list, &pci_mmcfg_list);
} }
static __devinit struct pci_mmcfg_region *pci_mmconfig_alloc(int segment, static __devinit struct pci_mmcfg_region *pci_mmconfig_alloc(int segment,
...@@ -101,8 +104,11 @@ static __init struct pci_mmcfg_region *pci_mmconfig_add(int segment, int start, ...@@ -101,8 +104,11 @@ static __init struct pci_mmcfg_region *pci_mmconfig_add(int segment, int start,
struct pci_mmcfg_region *new; struct pci_mmcfg_region *new;
new = pci_mmconfig_alloc(segment, start, end, addr); new = pci_mmconfig_alloc(segment, start, end, addr);
if (new) if (new) {
mutex_lock(&pci_mmcfg_lock);
list_add_sorted(new); list_add_sorted(new);
mutex_unlock(&pci_mmcfg_lock);
}
return new; return new;
} }
...@@ -111,7 +117,7 @@ struct pci_mmcfg_region *pci_mmconfig_lookup(int segment, int bus) ...@@ -111,7 +117,7 @@ struct pci_mmcfg_region *pci_mmconfig_lookup(int segment, int bus)
{ {
struct pci_mmcfg_region *cfg; struct pci_mmcfg_region *cfg;
list_for_each_entry(cfg, &pci_mmcfg_list, list) list_for_each_entry_rcu(cfg, &pci_mmcfg_list, list)
if (cfg->segment == segment && if (cfg->segment == segment &&
cfg->start_bus <= bus && bus <= cfg->end_bus) cfg->start_bus <= bus && bus <= cfg->end_bus)
return cfg; return cfg;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/rcupdate.h>
#include <asm/e820.h> #include <asm/e820.h>
#include <asm/pci_x86.h> #include <asm/pci_x86.h>
#include <acpi/acpi.h> #include <acpi/acpi.h>
...@@ -60,9 +61,12 @@ err: *value = -1; ...@@ -60,9 +61,12 @@ err: *value = -1;
return -EINVAL; return -EINVAL;
} }
rcu_read_lock();
base = get_base_addr(seg, bus, devfn); base = get_base_addr(seg, bus, devfn);
if (!base) if (!base) {
rcu_read_unlock();
goto err; goto err;
}
raw_spin_lock_irqsave(&pci_config_lock, flags); raw_spin_lock_irqsave(&pci_config_lock, flags);
...@@ -80,6 +84,7 @@ err: *value = -1; ...@@ -80,6 +84,7 @@ err: *value = -1;
break; break;
} }
raw_spin_unlock_irqrestore(&pci_config_lock, flags); raw_spin_unlock_irqrestore(&pci_config_lock, flags);
rcu_read_unlock();
return 0; return 0;
} }
...@@ -93,9 +98,12 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus, ...@@ -93,9 +98,12 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
if ((bus > 255) || (devfn > 255) || (reg > 4095)) if ((bus > 255) || (devfn > 255) || (reg > 4095))
return -EINVAL; return -EINVAL;
rcu_read_lock();
base = get_base_addr(seg, bus, devfn); base = get_base_addr(seg, bus, devfn);
if (!base) if (!base) {
rcu_read_unlock();
return -EINVAL; return -EINVAL;
}
raw_spin_lock_irqsave(&pci_config_lock, flags); raw_spin_lock_irqsave(&pci_config_lock, flags);
...@@ -113,6 +121,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus, ...@@ -113,6 +121,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
break; break;
} }
raw_spin_unlock_irqrestore(&pci_config_lock, flags); raw_spin_unlock_irqrestore(&pci_config_lock, flags);
rcu_read_unlock();
return 0; return 0;
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/acpi.h> #include <linux/acpi.h>
#include <linux/bitmap.h> #include <linux/bitmap.h>
#include <linux/rcupdate.h>
#include <asm/e820.h> #include <asm/e820.h>
#include <asm/pci_x86.h> #include <asm/pci_x86.h>
...@@ -34,9 +35,12 @@ err: *value = -1; ...@@ -34,9 +35,12 @@ err: *value = -1;
return -EINVAL; return -EINVAL;
} }
rcu_read_lock();
addr = pci_dev_base(seg, bus, devfn); addr = pci_dev_base(seg, bus, devfn);
if (!addr) if (!addr) {
rcu_read_unlock();
goto err; goto err;
}
switch (len) { switch (len) {
case 1: case 1:
...@@ -49,6 +53,7 @@ err: *value = -1; ...@@ -49,6 +53,7 @@ err: *value = -1;
*value = mmio_config_readl(addr + reg); *value = mmio_config_readl(addr + reg);
break; break;
} }
rcu_read_unlock();
return 0; return 0;
} }
...@@ -62,9 +67,12 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus, ...@@ -62,9 +67,12 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
if (unlikely((bus > 255) || (devfn > 255) || (reg > 4095))) if (unlikely((bus > 255) || (devfn > 255) || (reg > 4095)))
return -EINVAL; return -EINVAL;
rcu_read_lock();
addr = pci_dev_base(seg, bus, devfn); addr = pci_dev_base(seg, bus, devfn);
if (!addr) if (!addr) {
rcu_read_unlock();
return -EINVAL; return -EINVAL;
}
switch (len) { switch (len) {
case 1: case 1:
...@@ -77,6 +85,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus, ...@@ -77,6 +85,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
mmio_config_writel(addr + reg, value); mmio_config_writel(addr + reg, value);
break; break;
} }
rcu_read_unlock();
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment