Skip to contentSkip to conversation

pci-hyperv: use kmalloc to allocate hypercall params buffer

PATCH RESEND In review Long Li 4 participants 5 messages Nov 8, 2016 PCI

lore
Share & tools
lore

Long Li

author
#0 lore raw

PATCH RESEND 1/1 pci-hyperv: use kmalloc to allocate hypercall params buffer

From: Long Li <[email protected]>

hv_do_hypercall assumes that we pass a segment from a physically continuous buffer. Buffer allocated on the stack may not work if CONFIG_VMAP_STACK=y is set. Use kmalloc to allocate this buffer.

---
 drivers/pci/host/pci-hyperv.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/pci/host/pci-hyperv.c +13 -11
index 763ff87..97e6daf 100644
@@ -378,6 +378,7 @@ struct hv_pcibus_device {
 	struct msi_domain_info msi_info;
 	struct msi_controller msi_chip;
 	struct irq_domain *irq_domain;
+	struct retarget_msi_interrupt retarget_msi_interrupt_params;
 };
 
 /*
@@ -774,7 +775,7 @@ void hv_irq_unmask(struct irq_data *data)
 {
 	struct msi_desc *msi_desc = irq_data_get_msi_desc(data);
 	struct irq_cfg *cfg = irqd_cfg(data);
-	struct retarget_msi_interrupt params;
+	struct retarget_msi_interrupt *params;
 	struct hv_pcibus_device *hbus;
 	struct cpumask *dest;
 	struct pci_bus *pbus;
@@ -785,23 +786,24 @@ void hv_irq_unmask(struct irq_data *data)
 	pdev = msi_desc_to_pci_dev(msi_desc);
 	pbus = pdev->bus;
 	hbus = container_of(pbus->sysdata, struct hv_pcibus_device, sysdata);
-
-	memset(&params, 0, sizeof(params));
-	params.partition_id = HV_PARTITION_ID_SELF;
-	params.source = 1; /* MSI(-X) */
-	params.address = msi_desc->msg.address_lo;
-	params.data = msi_desc->msg.data;
-	params.device_id = (hbus->hdev->dev_instance.b[5] << 24) |
+	params = &hbus->retarget_msi_interrupt_params;
+
+	memset(params, 0, sizeof(*params));
+	params->partition_id = HV_PARTITION_ID_SELF;
+	params->source = 1; /* MSI(-X) */
+	params->address = msi_desc->msg.address_lo;
+	params->data = msi_desc->msg.data;
+	params->device_id = (hbus->hdev->dev_instance.b[5] << 24) |
 			   (hbus->hdev->dev_instance.b[4] << 16) |
 			   (hbus->hdev->dev_instance.b[7] << 8) |
 			   (hbus->hdev->dev_instance.b[6] & 0xf8) |
 			   PCI_FUNC(pdev->devfn);
-	params.vector = cfg->vector;
+	params->vector = cfg->vector;
 
 	for_each_cpu_and(cpu, dest, cpu_online_mask)
-		params.vp_mask |= (1ULL << vmbus_cpu_number_to_vp_number(cpu));
+		params->vp_mask |= (1ULL << vmbus_cpu_number_to_vp_number(cpu));
 
-	hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, &params, NULL);
+	hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, params, NULL);
 
 	pci_msi_unmask_irq(data);
 }
Signature · 1 line
2.7.4
#1 lore raw
Quoted 3 lines · Long Li

From: Long Li <[email protected]>

hv_do_hypercall assumes that we pass a segment from a physically continuous buffer. Buffer allocated on the stack may not work if CONFIG_VMAP_STACK=y is set. Use kmalloc to allocate this buffer.

Please wrap your changelog at 72 columns.

Quoted 12 lines
---
 drivers/pci/host/pci-hyperv.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/pci/host/pci-hyperv.c +0 -0
index 763ff87..97e6daf 100644

drivers/pci/host/pci-hyperv.c struct hv_pcibus_device { · line 381

Quoted 4 lines
drivers/pci/host/pci-hyperv.c +1 -0
@@ -378,6 +378,7 @@ struct hv_pcibus_device {
 	struct msi_domain_info msi_info;
 	struct msi_controller msi_chip;
 	struct irq_domain *irq_domain;
+	struct retarget_msi_interrupt retarget_msi_interrupt_params;

Can you handle potentially unaligned accesses like this? Is there some lock preventing you from using this structure more than once at the same time?

Quoted 34 lines
drivers/pci/host/pci-hyperv.c +9 -8
 };
 
 /*
@@ -774,7 +775,7 @@ void hv_irq_unmask(struct irq_data *data)
 {
 	struct msi_desc *msi_desc = irq_data_get_msi_desc(data);
 	struct irq_cfg *cfg = irqd_cfg(data);
-	struct retarget_msi_interrupt params;
+	struct retarget_msi_interrupt *params;
 	struct hv_pcibus_device *hbus;
 	struct cpumask *dest;
 	struct pci_bus *pbus;
@@ -785,23 +786,24 @@ void hv_irq_unmask(struct irq_data *data)
 	pdev = msi_desc_to_pci_dev(msi_desc);
 	pbus = pdev->bus;
 	hbus = container_of(pbus->sysdata, struct hv_pcibus_device, sysdata);
-
-	memset(&params, 0, sizeof(params));
-	params.partition_id = HV_PARTITION_ID_SELF;
-	params.source = 1; /* MSI(-X) */
-	params.address = msi_desc->msg.address_lo;
-	params.data = msi_desc->msg.data;
-	params.device_id = (hbus->hdev->dev_instance.b[5] << 24) |
+	params = &hbus->retarget_msi_interrupt_params;
+
+	memset(params, 0, sizeof(*params));
+	params->partition_id = HV_PARTITION_ID_SELF;
+	params->source = 1; /* MSI(-X) */
+	params->address = msi_desc->msg.address_lo;
+	params->data = msi_desc->msg.data;
+	params->device_id = (hbus->hdev->dev_instance.b[5] << 24) |
 			   (hbus->hdev->dev_instance.b[4] << 16) |
 			   (hbus->hdev->dev_instance.b[7] << 8) |
 			   (hbus->hdev->dev_instance.b[6] & 0xf8) |

drivers/pci/host/pci-hyperv.c void hv_irq_unmask(struct irq_data *data) · line 806

Quoted 10 lines
drivers/pci/host/pci-hyperv.c +3 -3
 			   PCI_FUNC(pdev->devfn);
-	params.vector = cfg->vector;
+	params->vector = cfg->vector;
 
 	for_each_cpu_and(cpu, dest, cpu_online_mask)
-		params.vp_mask |= (1ULL << vmbus_cpu_number_to_vp_number(cpu));
+		params->vp_mask |= (1ULL << vmbus_cpu_number_to_vp_number(cpu));
 
-	hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, &params, NULL);
+	hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, params, NULL);

As you only use this in one spot, why not just allocate it here and then free it? Why add it to the pcibus device structure?

thanks,

greg k-h

#2 lore raw
Quoted 83 lines

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Monday, November 7, 2016 11:00 PM
To: Long Li <[email protected]>
Cc: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Bjorn Helgaas <[email protected]>; [email protected]; [email protected]; linux- [email protected]
Subject: Re: [Resend] [PATCH] pci-hyperv: use kmalloc to allocate hypercall params buffer

Quoted 3 lines · Long Li

From: Long Li <[email protected]>

hv_do_hypercall assumes that we pass a segment from a physically

continuous buffer. Buffer allocated on the stack may not work if CONFIG_VMAP_STACK=y is set. Use kmalloc to allocate this buffer.

Please wrap your changelog at 72 columns.

Quoted 12 lines
---
 drivers/pci/host/pci-hyperv.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
(quoted diff) +0 -0

b/drivers/pci/host/pci-hyperv.c index 763ff87..97e6daf 100644

drivers/pci/host/pci-hyperv.c struct hv_pcibus_device { · line 381

Quoted 4 lines
drivers/pci/host/pci-hyperv.c +1 -0
@@ -378,6 +378,7 @@ struct hv_pcibus_device {
 	struct msi_domain_info msi_info;
 	struct msi_controller msi_chip;
 	struct irq_domain *irq_domain;
+	struct retarget_msi_interrupt retarget_msi_interrupt_params;

Can you handle potentially unaligned accesses like this? Is there some lock preventing you from using this structure more than once at the same time?

Quoted 30 lines
drivers/pci/host/pci-hyperv.c +8 -8
 };
 
 /*
@@ -774,7 +775,7 @@ void hv_irq_unmask(struct irq_data *data)  {
 	struct msi_desc *msi_desc = irq_data_get_msi_desc(data);
 	struct irq_cfg *cfg = irqd_cfg(data);
-	struct retarget_msi_interrupt params;
+	struct retarget_msi_interrupt *params;
 	struct hv_pcibus_device *hbus;
 	struct cpumask *dest;
 	struct pci_bus *pbus;
@@ -785,23 +786,24 @@ void hv_irq_unmask(struct irq_data *data)
 	pdev = msi_desc_to_pci_dev(msi_desc);
 	pbus = pdev->bus;
 	hbus = container_of(pbus->sysdata, struct hv_pcibus_device,
 sysdata);
-
-	memset(&params, 0, sizeof(params));
-	params.partition_id = HV_PARTITION_ID_SELF;
-	params.source = 1; /* MSI(-X) */
-	params.address = msi_desc->msg.address_lo;
-	params.data = msi_desc->msg.data;
-	params.device_id = (hbus->hdev->dev_instance.b[5] << 24) |
+	params = &hbus->retarget_msi_interrupt_params;
+
+	memset(params, 0, sizeof(*params));
+	params->partition_id = HV_PARTITION_ID_SELF;
+	params->source = 1; /* MSI(-X) */
+	params->address = msi_desc->msg.address_lo;
+	params->data = msi_desc->msg.data;

drivers/pci/host/pci-hyperv.c void hv_irq_unmask(struct irq_data *data) · line 803

Quoted 10 lines
drivers/pci/host/pci-hyperv.c +2 -2
+	params->device_id = (hbus->hdev->dev_instance.b[5] << 24) |
 			   (hbus->hdev->dev_instance.b[4] << 16) |
 			   (hbus->hdev->dev_instance.b[7] << 8) |
 			   (hbus->hdev->dev_instance.b[6] & 0xf8) |
 			   PCI_FUNC(pdev->devfn);
-	params.vector = cfg->vector;
+	params->vector = cfg->vector;
 
 	for_each_cpu_and(cpu, dest, cpu_online_mask)
-		params.vp_mask |= (1ULL <<

vmbus_cpu_number_to_vp_number(cpu));

Quoted 8 lines

drivers/pci/host/pci-hyperv.c void hv_irq_unmask(struct irq_data *data) · line 805

Quoted 1 line
drivers/pci/host/pci-hyperv.c +1 -0
+		params->vp_mask |= (1ULL <<

vmbus_cpu_number_to_vp_number(cpu));

drivers/pci/host/pci-hyperv.c void hv_irq_unmask(struct irq_data *data) · line 806

Quoted 3 lines
drivers/pci/host/pci-hyperv.c +1 -1
-	hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, &params, NULL);
+	hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, params, NULL);

As you only use this in one spot, why not just allocate it here and then free it? Why add it to the pcibus device structure?

Thanks Greg. I will send a V2.

Quoted 4 lines

thanks,

greg k-h

#3 lore raw
Quoted 11 lines

-----Original Message-----
From: Long Li
Sent: Tuesday, November 8, 2016 8:57 AM
To: Greg KH <[email protected]>
Cc: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Bjorn Helgaas <[email protected]>; [email protected]; [email protected]; linux- [email protected]
Subject: RE: [Resend] [PATCH] pci-hyperv: use kmalloc to allocate hyperca=

ll

Quoted 13 lines

params buffer
=20
=20
=20

Quoted 9 lines

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Monday, November 7, 2016 11:00 PM
To: Long Li <[email protected]>
Cc: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Bjorn Helgaas <[email protected]>; [email protected]; [email protected]; linux- [email protected]
Subject: Re: [Resend] [PATCH] pci-hyperv: use kmalloc to allocate hyper=

call

Quoted 10 lines
Quoted 10 lines

params buffer

Quoted 3 lines · Long Li

From: Long Li <[email protected]>

hv_do_hypercall assumes that we pass a segment from a physically

continuous buffer. Buffer allocated on the stack may not work if CONFIG_VMAP_STACK=3Dy is set. Use kmalloc to allocate this buffer.

Please wrap your changelog at 72 columns.

Long, this should not be part of the commit message. Please include changes=
in
each version below the line (----)

Regards,

K. Y=20

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
---
 drivers/pci/host/pci-hyperv.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
Quoted 11 lines
Quoted 11 lines

drivers/pci/host/pci-hyperv.c struct hv_pcibus_device { · line 381

Quoted 9 lines
(quoted diff) +0 -0

b/drivers/pci/host/pci-hyperv.c index 763ff87..97e6daf 100644

drivers/pci/host/pci-hyperv.c +1 -0
@@ -378,6 +378,7 @@ struct hv_pcibus_device {
 	struct msi_domain_info msi_info;
 	struct msi_controller msi_chip;
 	struct irq_domain *irq_domain;
+	struct retarget_msi_interrupt retarget_msi_interrupt_params;

Can you handle potentially unaligned accesses like this? Is there some=

lock

Quoted 1 line
Quoted 1 line

preventing you from using this structure more than once at the same tim=

e?

Quoted 42 lines
Quoted 42 lines
Quoted 31 lines
drivers/pci/host/pci-hyperv.c +8 -8
 };
 
 /*
@@ -774,7 +775,7 @@ void hv_irq_unmask(struct irq_data *data)  {
 	struct msi_desc *msi_desc =3D irq_data_get_msi_desc(data);
 	struct irq_cfg *cfg =3D irqd_cfg(data);
-	struct retarget_msi_interrupt params;
+	struct retarget_msi_interrupt *params;
 	struct hv_pcibus_device *hbus;
 	struct cpumask *dest;
 	struct pci_bus *pbus;
@@ -785,23 +786,24 @@ void hv_irq_unmask(struct irq_data *data)
 	pdev =3D msi_desc_to_pci_dev(msi_desc);
 	pbus =3D pdev->bus;
 	hbus =3D container_of(pbus->sysdata, struct hv_pcibus_device,
 sysdata);
-
-	memset(&params, 0, sizeof(params));
-	params.partition_id =3D HV_PARTITION_ID_SELF;
-	params.source =3D 1; /* MSI(-X) */
-	params.address =3D msi_desc->msg.address_lo;
-	params.data =3D msi_desc->msg.data;
-	params.device_id =3D (hbus->hdev->dev_instance.b[5] << 24) |
+	params =3D &hbus->retarget_msi_interrupt_params;
+
+	memset(params, 0, sizeof(*params));
+	params->partition_id =3D HV_PARTITION_ID_SELF;
+	params->source =3D 1; /* MSI(-X) */
+	params->address =3D msi_desc->msg.address_lo;
+	params->data =3D msi_desc->msg.data;

drivers/pci/host/pci-hyperv.c void hv_irq_unmask(struct irq_data *data) · line 803

Quoted 10 lines
drivers/pci/host/pci-hyperv.c +2 -2
+	params->device_id =3D (hbus->hdev->dev_instance.b[5] << 24) |
 			   (hbus->hdev->dev_instance.b[4] << 16) |
 			   (hbus->hdev->dev_instance.b[7] << 8) |
 			   (hbus->hdev->dev_instance.b[6] & 0xf8) |
 			   PCI_FUNC(pdev->devfn);
-	params.vector =3D cfg->vector;
+	params->vector =3D cfg->vector;
 
 	for_each_cpu_and(cpu, dest, cpu_online_mask)
-		params.vp_mask |=3D (1ULL <<

vmbus_cpu_number_to_vp_number(cpu));

Quoted 7 lines
Quoted 7 lines

drivers/pci/host/pci-hyperv.c void hv_irq_unmask(struct irq_data *data) · line 805

Quoted 1 line
drivers/pci/host/pci-hyperv.c +1 -0
+		params->vp_mask |=3D (1ULL <<

vmbus_cpu_number_to_vp_number(cpu));

drivers/pci/host/pci-hyperv.c void hv_irq_unmask(struct irq_data *data) · line 806

Quoted 3 lines
drivers/pci/host/pci-hyperv.c +1 -1
-	hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, &params, NULL);
+	hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, params, NULL);

As you only use this in one spot, why not just allocate it here and the=

n free

Quoted 8 lines
Quoted 1 line

it? Why add it to the pcibus device structure?

=20
Thanks Greg. I will send a V2.
=20

Quoted 4 lines

thanks,

greg k-h

#4 lore raw
In reply to Long Li
Quoted 11 lines

-----Original Message-----
From: devel [mailto:[email protected]] On Behalf Of Long Li
Sent: Tuesday, November 8, 2016 8:57 AM
To: Greg KH <[email protected]>
Cc: [email protected]; Haiyang Zhang <[email protected]>; [email protected]; Bjorn Helgaas <[email protected]>; [email protected]
Subject: RE: [Resend] [PATCH] pci-hyperv: use kmalloc to allocate hyperca=

ll

Quoted 44 lines

params buffer
=20
This sender failed our fraud detection checks and may not be who they appear to be. Learn about spoofing at http://aka.ms/LearnAboutSpoofing
=20

Quoted 39 lines

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Monday, November 7, 2016 11:00 PM
To: Long Li <[email protected]>
Cc: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Bjorn Helgaas <[email protected]>; [email protected]; [email protected]; linux- [email protected]
Subject: Re: [Resend] [PATCH] pci-hyperv: use kmalloc to allocate hypercall params buffer

Quoted 3 lines · Long Li

From: Long Li <[email protected]>

hv_do_hypercall assumes that we pass a segment from a physically

continuous buffer. Buffer allocated on the stack may not work if CONFIG_VMAP_STACK=3Dy is set. Use kmalloc to allocate this buffer.

Please wrap your changelog at 72 columns.

Quoted 12 lines
---
 drivers/pci/host/pci-hyperv.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
(quoted diff) +0 -0

b/drivers/pci/host/pci-hyperv.c index 763ff87..97e6daf 100644

drivers/pci/host/pci-hyperv.c struct hv_pcibus_device { · line 381

Quoted 4 lines
drivers/pci/host/pci-hyperv.c +1 -0
@@ -378,6 +378,7 @@ struct hv_pcibus_device {
    struct msi_domain_info msi_info;
    struct msi_controller msi_chip;
    struct irq_domain *irq_domain;
+   struct retarget_msi_interrupt retarget_msi_interrupt_params;

Can you handle potentially unaligned accesses like this? Is there some lock preventing you from using this structure more than once at th=

e

Quoted 46 lines

same time?

Quoted 45 lines
Quoted 31 lines
drivers/pci/host/pci-hyperv.c +8 -8
 };
 
 /*
@@ -774,7 +775,7 @@ void hv_irq_unmask(struct irq_data *data)  {
    struct msi_desc *msi_desc =3D irq_data_get_msi_desc(data);
    struct irq_cfg *cfg =3D irqd_cfg(data);
-   struct retarget_msi_interrupt params;
+   struct retarget_msi_interrupt *params;
    struct hv_pcibus_device *hbus;
    struct cpumask *dest;
    struct pci_bus *pbus;
@@ -785,23 +786,24 @@ void hv_irq_unmask(struct irq_data *data)
    pdev =3D msi_desc_to_pci_dev(msi_desc);
    pbus =3D pdev->bus;
    hbus =3D container_of(pbus->sysdata, struct hv_pcibus_device,
 sysdata);
-
-   memset(&params, 0, sizeof(params));
-   params.partition_id =3D HV_PARTITION_ID_SELF;
-   params.source =3D 1; /* MSI(-X) */
-   params.address =3D msi_desc->msg.address_lo;
-   params.data =3D msi_desc->msg.data;
-   params.device_id =3D (hbus->hdev->dev_instance.b[5] << 24) |
+   params =3D &hbus->retarget_msi_interrupt_params;
+
+   memset(params, 0, sizeof(*params));
+   params->partition_id =3D HV_PARTITION_ID_SELF;
+   params->source =3D 1; /* MSI(-X) */
+   params->address =3D msi_desc->msg.address_lo;
+   params->data =3D msi_desc->msg.data;

drivers/pci/host/pci-hyperv.c void hv_irq_unmask(struct irq_data *data) · line 803

Quoted 10 lines
drivers/pci/host/pci-hyperv.c +2 -2
+   params->device_id =3D (hbus->hdev->dev_instance.b[5] << 24) |
                       (hbus->hdev->dev_instance.b[4] << 16) |
                       (hbus->hdev->dev_instance.b[7] << 8) |
                       (hbus->hdev->dev_instance.b[6] & 0xf8) |
                       PCI_FUNC(pdev->devfn);
-   params.vector =3D cfg->vector;
+   params->vector =3D cfg->vector;
 
    for_each_cpu_and(cpu, dest, cpu_online_mask)
-           params.vp_mask |=3D (1ULL <<

vmbus_cpu_number_to_vp_number(cpu));

drivers/pci/host/pci-hyperv.c void hv_irq_unmask(struct irq_data *data) · line 805

Quoted 1 line
drivers/pci/host/pci-hyperv.c +1 -0
+           params->vp_mask |=3D (1ULL <<

vmbus_cpu_number_to_vp_number(cpu));

Quoted 1 line
Quoted 7 lines
Quoted 5 lines

drivers/pci/host/pci-hyperv.c void hv_irq_unmask(struct irq_data *data) · line 806

Quoted 2 lines
drivers/pci/host/pci-hyperv.c +1 -1
-   hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, &params, NULL);
+   hv_do_hypercall(HVCALL_RETARGET_INTERRUPT, params, NULL);

As you only use this in one spot, why not just allocate it here and then free it? Why add it to the pcibus device structure?

=20
Thanks Greg. I will send a V2.

Sorry forgot to address the reason why we don't just allocate the buffer he= re. This function cannot fail. So it's better to pre-allocate the buffer.

Quoted 14 lines

=20

Quoted 4 lines

thanks,

greg k-h

_______________________________________________
devel mailing list
[email protected]
https://na01.safelinks.protection.outlook.com/?url=3Dhttp%3A%2F%2Fdriverd
ev.linuxdriverproject.org%2Fmailman%2Flistinfo%2Fdriverdev- devel&data=3D02%7C01%7Clongli%40microsoft.com%7C6e28f5459da345cdb5e 408d407f836f0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636142 210041216500&sdata=3DvvVxGQUet7KMuRgs9%2BRbR8JE70rKF1AJo%2Fu3zx% 2FQNwY%3D&reserved=3D0