Skip to content

Commit 14ef39f

Browse files
dcuiLorenzo Pieralisi
authored andcommitted
PCI: hv: Change pci_protocol_version to per-hbus
A VM can have multiple Hyper-V hbus. It's incorrect to set the global variable 'pci_protocol_version' when *every* hbus is initialized in hv_pci_protocol_negotiation(). This is not an issue in practice since every hbus should have the same value of hbus->protocol_version, but we should make the variable per-hbus, so in case we have busses with different protocol versions, the driver can still work correctly. Signed-off-by: Dexuan Cui <[email protected]> Signed-off-by: Lorenzo Pieralisi <[email protected]> Reviewed-by: Michael Kelley <[email protected]>
1 parent ac82fc8 commit 14ef39f

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

drivers/pci/controller/pci-hyperv.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ static enum pci_protocol_version_t pci_protocol_versions[] = {
7676
PCI_PROTOCOL_VERSION_1_1,
7777
};
7878

79-
/*
80-
* Protocol version negotiated by hv_pci_protocol_negotiation().
81-
*/
82-
static enum pci_protocol_version_t pci_protocol_version;
83-
8479
#define PCI_CONFIG_MMIO_LENGTH 0x2000
8580
#define CFG_PAGE_OFFSET 0x1000
8681
#define CFG_PAGE_SIZE (PCI_CONFIG_MMIO_LENGTH - CFG_PAGE_OFFSET)
@@ -462,6 +457,8 @@ enum hv_pcibus_state {
462457

463458
struct hv_pcibus_device {
464459
struct pci_sysdata sysdata;
460+
/* Protocol version negotiated with the host */
461+
enum pci_protocol_version_t protocol_version;
465462
enum hv_pcibus_state state;
466463
refcount_t remove_lock;
467464
struct hv_device *hdev;
@@ -1225,7 +1222,7 @@ static void hv_irq_unmask(struct irq_data *data)
12251222
* negative effect (yet?).
12261223
*/
12271224

1228-
if (pci_protocol_version >= PCI_PROTOCOL_VERSION_1_2) {
1225+
if (hbus->protocol_version >= PCI_PROTOCOL_VERSION_1_2) {
12291226
/*
12301227
* PCI_PROTOCOL_VERSION_1_2 supports the VP_SET version of the
12311228
* HVCALL_RETARGET_INTERRUPT hypercall, which also coincides
@@ -1395,7 +1392,7 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
13951392
ctxt.pci_pkt.completion_func = hv_pci_compose_compl;
13961393
ctxt.pci_pkt.compl_ctxt = &comp;
13971394

1398-
switch (pci_protocol_version) {
1395+
switch (hbus->protocol_version) {
13991396
case PCI_PROTOCOL_VERSION_1_1:
14001397
size = hv_compose_msi_req_v1(&ctxt.int_pkts.v1,
14011398
dest,
@@ -2415,6 +2412,7 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev,
24152412
enum pci_protocol_version_t version[],
24162413
int num_version)
24172414
{
2415+
struct hv_pcibus_device *hbus = hv_get_drvdata(hdev);
24182416
struct pci_version_request *version_req;
24192417
struct hv_pci_compl comp_pkt;
24202418
struct pci_packet *pkt;
@@ -2454,10 +2452,10 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev,
24542452
}
24552453

24562454
if (comp_pkt.completion_status >= 0) {
2457-
pci_protocol_version = version[i];
2455+
hbus->protocol_version = version[i];
24582456
dev_info(&hdev->device,
24592457
"PCI VMBus probing: Using version %#x\n",
2460-
pci_protocol_version);
2458+
hbus->protocol_version);
24612459
goto exit;
24622460
}
24632461

@@ -2741,7 +2739,7 @@ static int hv_send_resources_allocated(struct hv_device *hdev)
27412739
u32 wslot;
27422740
int ret;
27432741

2744-
size_res = (pci_protocol_version < PCI_PROTOCOL_VERSION_1_2)
2742+
size_res = (hbus->protocol_version < PCI_PROTOCOL_VERSION_1_2)
27452743
? sizeof(*res_assigned) : sizeof(*res_assigned2);
27462744

27472745
pkt = kmalloc(sizeof(*pkt) + size_res, GFP_KERNEL);
@@ -2760,7 +2758,7 @@ static int hv_send_resources_allocated(struct hv_device *hdev)
27602758
pkt->completion_func = hv_pci_generic_compl;
27612759
pkt->compl_ctxt = &comp_pkt;
27622760

2763-
if (pci_protocol_version < PCI_PROTOCOL_VERSION_1_2) {
2761+
if (hbus->protocol_version < PCI_PROTOCOL_VERSION_1_2) {
27642762
res_assigned =
27652763
(struct pci_resources_assigned *)&pkt->message;
27662764
res_assigned->message_type.type =
@@ -3200,7 +3198,7 @@ static int hv_pci_resume(struct hv_device *hdev)
32003198
return ret;
32013199

32023200
/* Only use the version that was in use before hibernation. */
3203-
version[0] = pci_protocol_version;
3201+
version[0] = hbus->protocol_version;
32043202
ret = hv_pci_protocol_negotiation(hdev, version, 1);
32053203
if (ret)
32063204
goto out;

0 commit comments

Comments
 (0)