Skip to content

Commit e70af8d

Browse files
dcuiliuw
authored andcommitted
PCI: hv: Fix the definition 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: a2bad84 ("PCI: hv: Fix interrupt mapping for multi-MSI") Signed-off-by: Dexuan Cui <decui@microsoft.com> Cc: Jeffrey Hugo <quic_jhugo@quicinc.com> Cc: Carl Vanderlip <quic_carlv@quicinc.com> Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com> Link: https://lore.kernel.org/r/20221027205256.17678-1-decui@microsoft.com Signed-off-by: Wei Liu <wei.liu@kernel.org>
1 parent 9539c7f commit e70af8d

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

drivers/pci/controller/pci-hyperv.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ static void hv_pci_compose_compl(void *context, struct pci_response *resp,
16141614

16151615
static u32 hv_compose_msi_req_v1(
16161616
struct pci_create_interrupt *int_pkt, const struct cpumask *affinity,
1617-
u32 slot, u8 vector, u8 vector_count)
1617+
u32 slot, u8 vector, u16 vector_count)
16181618
{
16191619
int_pkt->message_type.type = PCI_CREATE_INTERRUPT_MESSAGE;
16201620
int_pkt->wslot.slot = slot;
@@ -1642,7 +1642,7 @@ static int hv_compose_msi_req_get_cpu(const struct cpumask *affinity)
16421642

16431643
static u32 hv_compose_msi_req_v2(
16441644
struct pci_create_interrupt2 *int_pkt, const struct cpumask *affinity,
1645-
u32 slot, u8 vector, u8 vector_count)
1645+
u32 slot, u8 vector, u16 vector_count)
16461646
{
16471647
int cpu;
16481648

@@ -1661,7 +1661,7 @@ static u32 hv_compose_msi_req_v2(
16611661

16621662
static u32 hv_compose_msi_req_v3(
16631663
struct pci_create_interrupt3 *int_pkt, const struct cpumask *affinity,
1664-
u32 slot, u32 vector, u8 vector_count)
1664+
u32 slot, u32 vector, u16 vector_count)
16651665
{
16661666
int cpu;
16671667

@@ -1701,7 +1701,12 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
17011701
struct compose_comp_ctxt comp;
17021702
struct tran_int_desc *int_desc;
17031703
struct msi_desc *msi_desc;
1704-
u8 vector, vector_count;
1704+
/*
1705+
* vector_count should be u16: see hv_msi_desc, hv_msi_desc2
1706+
* and hv_msi_desc3. vector must be u32: see hv_msi_desc3.
1707+
*/
1708+
u16 vector_count;
1709+
u32 vector;
17051710
struct {
17061711
struct pci_packet pci_pkt;
17071712
union {
@@ -1767,6 +1772,11 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
17671772
vector_count = 1;
17681773
}
17691774

1775+
/*
1776+
* hv_compose_msi_req_v1 and v2 are for x86 only, meaning 'vector'
1777+
* can't exceed u8. Cast 'vector' down to u8 for v1/v2 explicitly
1778+
* for better readability.
1779+
*/
17701780
memset(&ctxt, 0, sizeof(ctxt));
17711781
init_completion(&comp.comp_pkt.host_event);
17721782
ctxt.pci_pkt.completion_func = hv_pci_compose_compl;
@@ -1777,7 +1787,7 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
17771787
size = hv_compose_msi_req_v1(&ctxt.int_pkts.v1,
17781788
dest,
17791789
hpdev->desc.win_slot.slot,
1780-
vector,
1790+
(u8)vector,
17811791
vector_count);
17821792
break;
17831793

@@ -1786,7 +1796,7 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
17861796
size = hv_compose_msi_req_v2(&ctxt.int_pkts.v2,
17871797
dest,
17881798
hpdev->desc.win_slot.slot,
1789-
vector,
1799+
(u8)vector,
17901800
vector_count);
17911801
break;
17921802

0 commit comments

Comments
 (0)