提交 49404210 编写于 作者: B Bjorn Helgaas

Merge branch 'pci/host-hv' into next

* pci/host-hv:
  PCI: hv: Convert hv_pci_dev.refs from atomic_t to refcount_t
  PCI: hv: Allocate interrupt descriptors with GFP_ATOMIC
  PCI: hv: Specify CPU_AFFINITY_ALL for MSI affinity when >= 32 CPUs
  PCI: hv: Lock PCI bus on device eject
  PCI: hv: Properly handle PCI bus remove
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include <asm/apic.h> #include <asm/apic.h>
#include <linux/msi.h> #include <linux/msi.h>
#include <linux/hyperv.h> #include <linux/hyperv.h>
#include <linux/refcount.h>
#include <asm/mshyperv.h> #include <asm/mshyperv.h>
/* /*
...@@ -72,6 +73,7 @@ enum { ...@@ -72,6 +73,7 @@ enum {
PCI_PROTOCOL_VERSION_CURRENT = PCI_PROTOCOL_VERSION_1_1 PCI_PROTOCOL_VERSION_CURRENT = PCI_PROTOCOL_VERSION_1_1
}; };
#define CPU_AFFINITY_ALL -1ULL
#define PCI_CONFIG_MMIO_LENGTH 0x2000 #define PCI_CONFIG_MMIO_LENGTH 0x2000
#define CFG_PAGE_OFFSET 0x1000 #define CFG_PAGE_OFFSET 0x1000
#define CFG_PAGE_SIZE (PCI_CONFIG_MMIO_LENGTH - CFG_PAGE_OFFSET) #define CFG_PAGE_SIZE (PCI_CONFIG_MMIO_LENGTH - CFG_PAGE_OFFSET)
...@@ -350,6 +352,7 @@ enum hv_pcibus_state { ...@@ -350,6 +352,7 @@ enum hv_pcibus_state {
hv_pcibus_init = 0, hv_pcibus_init = 0,
hv_pcibus_probed, hv_pcibus_probed,
hv_pcibus_installed, hv_pcibus_installed,
hv_pcibus_removed,
hv_pcibus_maximum hv_pcibus_maximum
}; };
...@@ -421,7 +424,7 @@ enum hv_pcidev_ref_reason { ...@@ -421,7 +424,7 @@ enum hv_pcidev_ref_reason {
struct hv_pci_dev { struct hv_pci_dev {
/* List protected by pci_rescan_remove_lock */ /* List protected by pci_rescan_remove_lock */
struct list_head list_entry; struct list_head list_entry;
atomic_t refs; refcount_t refs;
enum hv_pcichild_state state; enum hv_pcichild_state state;
struct pci_function_description desc; struct pci_function_description desc;
bool reported_missing; bool reported_missing;
...@@ -876,7 +879,7 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) ...@@ -876,7 +879,7 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
hv_int_desc_free(hpdev, int_desc); hv_int_desc_free(hpdev, int_desc);
} }
int_desc = kzalloc(sizeof(*int_desc), GFP_KERNEL); int_desc = kzalloc(sizeof(*int_desc), GFP_ATOMIC);
if (!int_desc) if (!int_desc)
goto drop_reference; goto drop_reference;
...@@ -897,9 +900,13 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) ...@@ -897,9 +900,13 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
* processors because Hyper-V only supports 64 in a guest. * processors because Hyper-V only supports 64 in a guest.
*/ */
affinity = irq_data_get_affinity_mask(data); affinity = irq_data_get_affinity_mask(data);
for_each_cpu_and(cpu, affinity, cpu_online_mask) { if (cpumask_weight(affinity) >= 32) {
int_pkt->int_desc.cpu_mask |= int_pkt->int_desc.cpu_mask = CPU_AFFINITY_ALL;
(1ULL << vmbus_cpu_number_to_vp_number(cpu)); } else {
for_each_cpu_and(cpu, affinity, cpu_online_mask) {
int_pkt->int_desc.cpu_mask |=
(1ULL << vmbus_cpu_number_to_vp_number(cpu));
}
} }
ret = vmbus_sendpacket(hpdev->hbus->hdev->channel, int_pkt, ret = vmbus_sendpacket(hpdev->hbus->hdev->channel, int_pkt,
...@@ -1208,9 +1215,11 @@ static int create_root_hv_pci_bus(struct hv_pcibus_device *hbus) ...@@ -1208,9 +1215,11 @@ static int create_root_hv_pci_bus(struct hv_pcibus_device *hbus)
hbus->pci_bus->msi = &hbus->msi_chip; hbus->pci_bus->msi = &hbus->msi_chip;
hbus->pci_bus->msi->dev = &hbus->hdev->device; hbus->pci_bus->msi->dev = &hbus->hdev->device;
pci_lock_rescan_remove();
pci_scan_child_bus(hbus->pci_bus); pci_scan_child_bus(hbus->pci_bus);
pci_bus_assign_resources(hbus->pci_bus); pci_bus_assign_resources(hbus->pci_bus);
pci_bus_add_devices(hbus->pci_bus); pci_bus_add_devices(hbus->pci_bus);
pci_unlock_rescan_remove();
hbus->state = hv_pcibus_installed; hbus->state = hv_pcibus_installed;
return 0; return 0;
} }
...@@ -1254,13 +1263,13 @@ static void q_resource_requirements(void *context, struct pci_response *resp, ...@@ -1254,13 +1263,13 @@ static void q_resource_requirements(void *context, struct pci_response *resp,
static void get_pcichild(struct hv_pci_dev *hpdev, static void get_pcichild(struct hv_pci_dev *hpdev,
enum hv_pcidev_ref_reason reason) enum hv_pcidev_ref_reason reason)
{ {
atomic_inc(&hpdev->refs); refcount_inc(&hpdev->refs);
} }
static void put_pcichild(struct hv_pci_dev *hpdev, static void put_pcichild(struct hv_pci_dev *hpdev,
enum hv_pcidev_ref_reason reason) enum hv_pcidev_ref_reason reason)
{ {
if (atomic_dec_and_test(&hpdev->refs)) if (refcount_dec_and_test(&hpdev->refs))
kfree(hpdev); kfree(hpdev);
} }
...@@ -1314,7 +1323,7 @@ static struct hv_pci_dev *new_pcichild_device(struct hv_pcibus_device *hbus, ...@@ -1314,7 +1323,7 @@ static struct hv_pci_dev *new_pcichild_device(struct hv_pcibus_device *hbus,
wait_for_completion(&comp_pkt.host_event); wait_for_completion(&comp_pkt.host_event);
hpdev->desc = *desc; hpdev->desc = *desc;
get_pcichild(hpdev, hv_pcidev_ref_initial); refcount_set(&hpdev->refs, 1);
get_pcichild(hpdev, hv_pcidev_ref_childlist); get_pcichild(hpdev, hv_pcidev_ref_childlist);
spin_lock_irqsave(&hbus->device_list_lock, flags); spin_lock_irqsave(&hbus->device_list_lock, flags);
...@@ -1504,13 +1513,24 @@ static void pci_devices_present_work(struct work_struct *work) ...@@ -1504,13 +1513,24 @@ static void pci_devices_present_work(struct work_struct *work)
put_pcichild(hpdev, hv_pcidev_ref_initial); put_pcichild(hpdev, hv_pcidev_ref_initial);
} }
/* Tell the core to rescan bus because there may have been changes. */ switch(hbus->state) {
if (hbus->state == hv_pcibus_installed) { case hv_pcibus_installed:
/*
* Tell the core to rescan bus
* because there may have been changes.
*/
pci_lock_rescan_remove(); pci_lock_rescan_remove();
pci_scan_child_bus(hbus->pci_bus); pci_scan_child_bus(hbus->pci_bus);
pci_unlock_rescan_remove(); pci_unlock_rescan_remove();
} else { break;
case hv_pcibus_init:
case hv_pcibus_probed:
survey_child_resources(hbus); survey_child_resources(hbus);
break;
default:
break;
} }
up(&hbus->enum_sem); up(&hbus->enum_sem);
...@@ -1600,8 +1620,10 @@ static void hv_eject_device_work(struct work_struct *work) ...@@ -1600,8 +1620,10 @@ static void hv_eject_device_work(struct work_struct *work)
pdev = pci_get_domain_bus_and_slot(hpdev->hbus->sysdata.domain, 0, pdev = pci_get_domain_bus_and_slot(hpdev->hbus->sysdata.domain, 0,
wslot); wslot);
if (pdev) { if (pdev) {
pci_lock_rescan_remove();
pci_stop_and_remove_bus_device(pdev); pci_stop_and_remove_bus_device(pdev);
pci_dev_put(pdev); pci_dev_put(pdev);
pci_unlock_rescan_remove();
} }
spin_lock_irqsave(&hpdev->hbus->device_list_lock, flags); spin_lock_irqsave(&hpdev->hbus->device_list_lock, flags);
...@@ -2185,6 +2207,7 @@ static int hv_pci_probe(struct hv_device *hdev, ...@@ -2185,6 +2207,7 @@ static int hv_pci_probe(struct hv_device *hdev,
hbus = kzalloc(sizeof(*hbus), GFP_KERNEL); hbus = kzalloc(sizeof(*hbus), GFP_KERNEL);
if (!hbus) if (!hbus)
return -ENOMEM; return -ENOMEM;
hbus->state = hv_pcibus_init;
/* /*
* The PCI bus "domain" is what is called "segment" in ACPI and * The PCI bus "domain" is what is called "segment" in ACPI and
...@@ -2348,6 +2371,7 @@ static int hv_pci_remove(struct hv_device *hdev) ...@@ -2348,6 +2371,7 @@ static int hv_pci_remove(struct hv_device *hdev)
pci_stop_root_bus(hbus->pci_bus); pci_stop_root_bus(hbus->pci_bus);
pci_remove_root_bus(hbus->pci_bus); pci_remove_root_bus(hbus->pci_bus);
pci_unlock_rescan_remove(); pci_unlock_rescan_remove();
hbus->state = hv_pcibus_removed;
} }
hv_pci_bus_exit(hdev); hv_pci_bus_exit(hdev);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部