Skip to contentSkip to conversation

PCI: hv: Fix the definiton of vector in hv_compose_msi_msg()

PATCH Superseded Dexuan Cui 4 participants 7 messages Aug 15, 2022 – Aug 19, 2022

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Dexuan Cui

author maintainer
#0 lore raw

PATCH 1/1 PCI: hv: Fix the definiton of vector in hv_compose_msi_msg()

The local variable 'vector' must be u32 rather than u8: see the struct hv_msi_desc3.

'vector_count' should be u16 rather than u8: see struct hv_msi_desc, hv_msi_desc2 and hv_msi_desc3.

Fixes a2bad844a67b ("PCI: hv: Fix interrupt mapping for multi-MSI")
Cc Jeffrey Hugo <[email protected]>
Cc Carl Vanderlip <[email protected]>

---

The patch should be appplied after the earlier patch:
[PATCH] PCI: hv: Only reuse existing IRTE allocation for Multi-MSI
https://lwn.net/ml/linux-kernel/20220804025104.15673-1-decui%40microsoft.com/

 drivers/pci/controller/pci-hyperv.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/pci/controller/pci-hyperv.c +5 -4
index 65d0dab25deb..53580899c859 100644
@@ -1614,7 +1614,7 @@ static void hv_pci_compose_compl(void *context, struct pci_response *resp,
 
 static u32 hv_compose_msi_req_v1(
 	struct pci_create_interrupt *int_pkt, struct cpumask *affinity,
-	u32 slot, u8 vector, u8 vector_count)
+	u32 slot, u8 vector, u16 vector_count)
 {
 	int_pkt->message_type.type = PCI_CREATE_INTERRUPT_MESSAGE;
 	int_pkt->wslot.slot = slot;
@@ -1642,7 +1642,7 @@ static int hv_compose_msi_req_get_cpu(struct cpumask *affinity)
 
 static u32 hv_compose_msi_req_v2(
 	struct pci_create_interrupt2 *int_pkt, struct cpumask *affinity,
-	u32 slot, u8 vector, u8 vector_count)
+	u32 slot, u8 vector, u16 vector_count)
 {
 	int cpu;
 
@@ -1661,7 +1661,7 @@ static u32 hv_compose_msi_req_v2(
 
 static u32 hv_compose_msi_req_v3(
 	struct pci_create_interrupt3 *int_pkt, struct cpumask *affinity,
-	u32 slot, u32 vector, u8 vector_count)
+	u32 slot, u32 vector, u16 vector_count)
 {
 	int cpu;
 
@@ -1702,7 +1702,8 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 	struct tran_int_desc *int_desc;
 	struct msi_desc *msi_desc;
 	bool multi_msi;
-	u8 vector, vector_count;
+	u32 vector; /* Must be u32: see the struct hv_msi_desc3 */
+	u16 vector_count;
 	struct {
 		struct pci_packet pci_pkt;
 		union {
Signature · 1 line
2.25.1
#1 lore raw

s/definiton/definition/ in subject
(only if you have other occasion to repost this)

Quoted 10 lines · Dexuan Cui

The local variable 'vector' must be u32 rather than u8: see the struct hv_msi_desc3.

'vector_count' should be u16 rather than u8: see struct hv_msi_desc, hv_msi_desc2 and hv_msi_desc3.

Fixes a2bad844a67b ("PCI: hv: Fix interrupt mapping for multi-MSI")
Cc Jeffrey Hugo <[email protected]>
Cc Carl Vanderlip <[email protected]>

Looks like Wei has been applying most changes to pci-hyperv.c, so I assume the same will happen here.

Quoted 53 lines

---

The patch should be appplied after the earlier patch:
[PATCH] PCI: hv: Only reuse existing IRTE allocation for Multi-MSI
https://lwn.net/ml/linux-kernel/20220804025104.15673-1-decui%40microsoft.com/

 drivers/pci/controller/pci-hyperv.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/pci/controller/pci-hyperv.c +5 -4
index 65d0dab25deb..53580899c859 100644
@@ -1614,7 +1614,7 @@ static void hv_pci_compose_compl(void *context, struct pci_response *resp,
 
 static u32 hv_compose_msi_req_v1(
 	struct pci_create_interrupt *int_pkt, struct cpumask *affinity,
-	u32 slot, u8 vector, u8 vector_count)
+	u32 slot, u8 vector, u16 vector_count)
 {
 	int_pkt->message_type.type = PCI_CREATE_INTERRUPT_MESSAGE;
 	int_pkt->wslot.slot = slot;
@@ -1642,7 +1642,7 @@ static int hv_compose_msi_req_get_cpu(struct cpumask *affinity)
 
 static u32 hv_compose_msi_req_v2(
 	struct pci_create_interrupt2 *int_pkt, struct cpumask *affinity,
-	u32 slot, u8 vector, u8 vector_count)
+	u32 slot, u8 vector, u16 vector_count)
 {
 	int cpu;
 
@@ -1661,7 +1661,7 @@ static u32 hv_compose_msi_req_v2(
 
 static u32 hv_compose_msi_req_v3(
 	struct pci_create_interrupt3 *int_pkt, struct cpumask *affinity,
-	u32 slot, u32 vector, u8 vector_count)
+	u32 slot, u32 vector, u16 vector_count)
 {
 	int cpu;
 
@@ -1702,7 +1702,8 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 	struct tran_int_desc *int_desc;
 	struct msi_desc *msi_desc;
 	bool multi_msi;
-	u8 vector, vector_count;
+	u32 vector; /* Must be u32: see the struct hv_msi_desc3 */
+	u16 vector_count;
 	struct {
 		struct pci_packet pci_pkt;
 		union {
Signature · 1 line
2.25.1
author maintainer
#2 lore raw
Quoted 6 lines

From: Bjorn Helgaas <[email protected]>
Sent: Monday, August 15, 2022 1:36 PM
To: Dexuan Cui <[email protected]>

s/definiton/definition/ in subject
(only if you have other occasion to repost this)

Thanks, Bjorn! I suppose Wei can help fix this. :-)

Quoted 7 lines · Dexuan Cui
Quoted 6 lines

The local variable 'vector' must be u32 rather than u8: see the struct hv_msi_desc3.

'vector_count' should be u16 rather than u8: see struct hv_msi_desc, hv_msi_desc2 and hv_msi_desc3.

Quoted 7 lines
Quoted 4 lines
Fixes a2bad844a67b ("PCI: hv: Fix interrupt mapping for multi-MSI")
Cc Jeffrey Hugo <[email protected]>
Cc Carl Vanderlip <[email protected]>

Looks like Wei has been applying most changes to pci-hyperv.c, so I assume the same will happen here.

So I interpret this as an ack for Wei to apply the earlier patch
[PATCH] PCI: hv: Only reuse existing IRTE allocation for Multi-MSI
and this patch.

The two small patches are pure Hyper-V specific changes, so IMO it's better for them to go through Wei's Hyper-V tree rather than the PCI tree. (It looks like the PCI folks are too busy right now)

Quoted 4 lines
Quoted 4 lines

---

The patch should be appplied after the earlier patch:
[PATCH] PCI: hv: Only reuse existing IRTE allocation for Multi-MSI

maintainer
#3 lore raw
In reply to Bjorn Helgaas
Quoted 10 lines · Bjorn Helgaas

s/definiton/definition/ in subject
(only if you have other occasion to repost this)

Quoted 6 lines · Dexuan Cui

The local variable 'vector' must be u32 rather than u8: see the struct hv_msi_desc3.

'vector_count' should be u16 rather than u8: see struct hv_msi_desc, hv_msi_desc2 and hv_msi_desc3.

Quoted 7 lines
Quoted 4 lines
Fixes a2bad844a67b ("PCI: hv: Fix interrupt mapping for multi-MSI")
Cc Jeffrey Hugo <[email protected]>
Cc Carl Vanderlip <[email protected]>

Looks like Wei has been applying most changes to pci-hyperv.c, so I assume the same will happen here.

I can take care of this one via hyperv-fixes, but ...

Quoted 7 lines
Quoted 7 lines

---

The patch should be appplied after the earlier patch:
[PATCH] PCI: hv: Only reuse existing IRTE allocation for Multi-MSI
https://lwn.net/ml/linux-kernel/20220804025104.15673-1-decui%40microsoft.com/

... this patch looks to be rejected.

Thanks,
Wei.

author maintainer
#4 lore raw
Quoted 20 lines

From: Wei Liu <[email protected]>
Sent: Friday, August 19, 2022 8:53 AM
To: Bjorn Helgaas <[email protected]>

Quoted 15 lines · Bjorn Helgaas

s/definiton/definition/ in subject
(only if you have other occasion to repost this)

Quoted 10 lines · Dexuan Cui

The local variable 'vector' must be u32 rather than u8: see the struct hv_msi_desc3.

'vector_count' should be u16 rather than u8: see struct hv_msi_desc, hv_msi_desc2 and hv_msi_desc3.

Fixes a2bad844a67b ("PCI: hv: Fix interrupt mapping for multi-MSI")
Cc Jeffrey Hugo <[email protected]>
Cc Carl Vanderlip <[email protected]>
Quoted 4 lines
Quoted 2 lines

Looks like Wei has been applying most changes to pci-hyperv.c, so I assume the same will happen here.

I can take care of this one via hyperv-fixes, but ...

Wei, please ignore this patch. I'll post v2 of this patch with v2 of the other patch.

Quoted 15 lines
Quoted 5 lines
Quoted 5 lines

---

The patch should be appplied after the earlier patch:
[PATCH] PCI: hv: Only reuse existing IRTE allocation for Multi-MSI

https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Flwn.ne
t%2Fml%2Flinux-kernel%2F20220804025104.15673-1-decui%2540microsoft.co m%2F&amp;data=05%7C01%7Cdecui%40microsoft.com%7Cc8ab6638b7d747b cddf008da81fadc12%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C6 37965211688628404%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMD AiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C& amp;sdata=Rb2MfkSFmJ%2B8ze%2FllN0THBhODCtmnZ8oSMB0EOn20u4%3D& amp;reserved=0

Quoted 1 line
Quoted 1 line
Quoted 1 line

... this patch looks to be rejected.

Correct. I'm working on a new version.

Quoted 3 lines

Thanks,
Wei.

#5 lore raw
In reply to Dexuan Cui
Quoted 51 lines · Dexuan Cui

The local variable 'vector' must be u32 rather than u8: see the struct hv_msi_desc3.

'vector_count' should be u16 rather than u8: see struct hv_msi_desc, hv_msi_desc2 and hv_msi_desc3.

Fixes a2bad844a67b ("PCI: hv: Fix interrupt mapping for multi-MSI")
Cc Jeffrey Hugo <[email protected]>
Cc Carl Vanderlip <[email protected]>

---

The patch should be appplied after the earlier patch:
[PATCH] PCI: hv: Only reuse existing IRTE allocation for Multi-MSI
https://lwn.net/ml/linux-kernel/20220804025104.15673-1-decui%40microsoft.com/

  drivers/pci/controller/pci-hyperv.c | 9 +++++----
  1 file changed, 5 insertions(+), 4 deletions(-)
drivers/pci/controller/pci-hyperv.c +3 -3
index 65d0dab25deb..53580899c859 100644
@@ -1614,7 +1614,7 @@ static void hv_pci_compose_compl(void *context, struct pci_response *resp,
 
  static u32 hv_compose_msi_req_v1(
  	struct pci_create_interrupt *int_pkt, struct cpumask *affinity,
-	u32 slot, u8 vector, u8 vector_count)
+	u32 slot, u8 vector, u16 vector_count)
  {
  	int_pkt->message_type.type = PCI_CREATE_INTERRUPT_MESSAGE;
  	int_pkt->wslot.slot = slot;
@@ -1642,7 +1642,7 @@ static int hv_compose_msi_req_get_cpu(struct cpumask *affinity)
 
  static u32 hv_compose_msi_req_v2(
  	struct pci_create_interrupt2 *int_pkt, struct cpumask *affinity,
-	u32 slot, u8 vector, u8 vector_count)
+	u32 slot, u8 vector, u16 vector_count)
  {
  	int cpu;
 
@@ -1661,7 +1661,7 @@ static u32 hv_compose_msi_req_v2(
 
  static u32 hv_compose_msi_req_v3(
  	struct pci_create_interrupt3 *int_pkt, struct cpumask *affinity,
-	u32 slot, u32 vector, u8 vector_count)
+	u32 slot, u32 vector, u16 vector_count)
  {
  	int cpu;
 

drivers/pci/controller/pci-hyperv.c static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) · line 1705

Quoted 5 lines
drivers/pci/controller/pci-hyperv.c +1 -1
@@ -1702,7 +1702,8 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
  	struct tran_int_desc *int_desc;
  	struct msi_desc *msi_desc;
  	bool multi_msi;
-	u8 vector, vector_count;
+	u32 vector; /* Must be u32: see the struct hv_msi_desc3 */

Don't you need to cast this down to a u8 for v1 and v2? Feels like this should be generating a compiler warning...

author maintainer
#6 lore raw
Quoted 5 lines

From: Jeffrey Hugo <[email protected]>
Sent: Tuesday, August 16, 2022 9:01 AM

Review static void hv_compose_msi_msg(struct irq_data

Quoted 2 lines

...

(quoted diff) +0 -0
@@ -1702,7 +1702,8 @@ static void hv_compose_msi_msg(struct irq_data

*data, struct msi_msg *msg)

Quoted 8 lines

Review static void hv_compose_msi_msg(struct irq_data · line 1705

Quoted 5 lines
(quoted diff) +1 -1
  	struct tran_int_desc *int_desc;
  	struct msi_desc *msi_desc;
  	bool multi_msi;
-	u8 vector, vector_count;
+	u32 vector; /* Must be u32: see the struct hv_msi_desc3 */

Don't you need to cast this down to a u8 for v1 and v2? Feels like this should be generating a compiler warning...

My gcc 9.4.0 didn't generate a warning.

hv_compose_msi_req_v3() is for both ARM64 and x86. In the case of ARM64 the 'vector' can be a u32 integer according to the comment around struct hv_msi_desc3.

hv_compose_msi_req_v1 and v2 are for x86 only, and the 'vector' can't be longer than u8. I can post a v2 with the extra changes below:

drivers/pci/controller/pci-hyperv.c +8 -3
index 53580899c859..c7fd76bc8b4c 100644
@@ -1703,7 +1703,7 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
        struct msi_desc *msi_desc;
        bool multi_msi;
        u32 vector; /* Must be u32: see the struct hv_msi_desc3 */
-       u16 vector_count;
+       u16 vector_count; /* see hv_msi_desc, hv_msi_desc2 and hv_msi_desc3 */
        struct {
                struct pci_packet pci_pkt;
                union {
@@ -1788,12 +1788,17 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
        ctxt.pci_pkt.completion_func = hv_pci_compose_compl;
        ctxt.pci_pkt.compl_ctxt = &comp;
 
+       /*
+        * hv_compose_msi_req_v1 and v2 are for x86 only, meaning 'vector'
+        * can't be longer than u8. Cast 'vector' down to u8 explicitly for
+        * better readability.
+        */
        switch (hbus->protocol_version) {
        case PCI_PROTOCOL_VERSION_1_1:
                size = hv_compose_msi_req_v1(&ctxt.int_pkts.v1,
                                        dest,
                                        hpdev->desc.win_slot.slot,
-                                       vector,
+                                       (u8)vector,
                                        vector_count);
                break;
 
@@ -1802,7 +1807,7 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
                size = hv_compose_msi_req_v2(&ctxt.int_pkts.v2,
                                        dest,
                                        hpdev->desc.win_slot.slot,
-                                       vector,
+                                       (u8)vector,
                                        vector_count);
                break;
 

Thanks,
-- Dexuan