KVM: Implement support for the RH bit
PATCH v2 1/1 KVM: Implement support for the RH bit
The RH bit exists in the message address register (lower 32 bits of the address).
The bit indicates whether the message should go to the processor which was indicated in the destination ID bits, or whether it should go to the processor running at the lowest priority.
--- virt/kvm/irq_comm.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)
virt/kvm/irq_comm.c +16 -1
@@ -134,7 +134,22 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, irq.level =1 ; irq.shorthand =0 ; -/* TODO Deal with RH bit of MSI message address */ +/* +* If the RH bit is set, we'll deliver to the processor running +* at the lowest priority. +*/ +if (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI ) { + irq.delivery_mode =MSI_DATA_DELIVERY_LOWPRI ; + }else { +/* +* If the RH bit is not set, we'll deliver to the specific +* processor mentioned in destination ID, and ignore the DM +* bit. +*/ + irq.dest_mode =MSI_ADDR_DEST_MODE_PHYSICAL ; + irq.delivery_mode =MSI_DATA_DELIVERY_FIXED ; + } +return kvm_irq_delivery_to_apic (kvm,NULL , &irq); }
Signature · 1 line
1.7.6.1
Quoted 32 lines · Sasha Levin
The RH bit exists in the message address register (lower 32 bits of the address).
The bit indicates whether the message should go to the processor which was indicated in the destination ID bits, or whether it should go to the processor running at the lowest priority.
Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- virt/kvm/irq_comm.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)virt/kvm/irq_comm.c +9
-1@@ -134,7 +134,22 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, irq.level =1 ; irq.shorthand =0 ; -/* TODO Deal with RH bit of MSI message address */ +/* +* If the RH bit is set, we'll deliver to the processor running +* at the lowest priority. +*/ +if (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI ) { + irq.delivery_mode =MSI_DATA_DELIVERY_LOWPRI ; + }else { +/* +* If the RH bit is not set, we'll deliver to the specific
virt/kvm/irq_comm.c int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, · line 155
Quoted 10 lines
virt/kvm/irq_comm.c +7
-0+* processor mentioned in destination ID, and ignore the DM +* bit. +*/ + irq.dest_mode =MSI_ADDR_DEST_MODE_PHYSICAL ; + irq.delivery_mode =MSI_DATA_DELIVERY_FIXED ; + } +return kvm_irq_delivery_to_apic (kvm,NULL , &irq); }
Do you happen have a kvm unit test for this? Or how did you validate the change? It doesn't look incorrect to me, I'd just like to check it QEMU as well which apparently already has the logic above but also some contradictory comment.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Sasha Levin
The RH bit exists in the message address register (lower 32 bits of the address).
The bit indicates whether the message should go to the processor which was indicated in the destination ID bits, or whether it should go to the processor running at the lowest priority.
Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- virt/kvm/irq_comm.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)virt/kvm/irq_comm.c +16
-1@@ -134,7 +134,22 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, irq.level =1 ; irq.shorthand =0 ; -/* TODO Deal with RH bit of MSI message address */ +/* +* If the RH bit is set, we'll deliver to the processor running +* at the lowest priority. +*/ +if (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI ) { + irq.delivery_mode =MSI_DATA_DELIVERY_LOWPRI ; + }else { +/* +* If the RH bit is not set, we'll deliver to the specific +* processor mentioned in destination ID, and ignore the DM +* bit. +*/ + irq.dest_mode =MSI_ADDR_DEST_MODE_PHYSICAL ; + irq.delivery_mode =MSI_DATA_DELIVERY_FIXED ; + } +
Quoted 8 lines
virt/kvm/irq_comm.c int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, · line 155
Quoted 3 lines
virt/kvm/irq_comm.c +0
-0return kvm_irq_delivery_to_apic (kvm,NULL , &irq); }Do you happen have a kvm unit test for this? Or how did you validate the change? It doesn't look incorrect to me, I'd just like to check it QEMU as well which apparently already has the logic above but also some contradictory comment.
Err, no, QEMU does not have this logic, it also ignores RH.
But the above bits make "irq.delivery_mode = e->msi.data & 0x700" pointless. And that strongly suggests something is still wrong.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 50 lines · Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Sasha Levin
The RH bit exists in the message address register (lower 32 bits of the address).
The bit indicates whether the message should go to the processor which was indicated in the destination ID bits, or whether it should go to the processor running at the lowest priority.
Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- virt/kvm/irq_comm.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)virt/kvm/irq_comm.c +16
-1@@ -134,7 +134,22 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, irq.level =1 ; irq.shorthand =0 ; -/* TODO Deal with RH bit of MSI message address */ +/* +* If the RH bit is set, we'll deliver to the processor running +* at the lowest priority. +*/ +if (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI ) { + irq.delivery_mode =MSI_DATA_DELIVERY_LOWPRI ; + }else { +/* +* If the RH bit is not set, we'll deliver to the specific +* processor mentioned in destination ID, and ignore the DM +* bit. +*/ + irq.dest_mode =MSI_ADDR_DEST_MODE_PHYSICAL ; + irq.delivery_mode =MSI_DATA_DELIVERY_FIXED ; + } +Quoted 8 lines
virt/kvm/irq_comm.c int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, · line 155
Quoted 3 lines
virt/kvm/irq_comm.c +0
-0return kvm_irq_delivery_to_apic (kvm,NULL , &irq); }Do you happen have a kvm unit test for this? Or how did you validate the change? It doesn't look incorrect to me, I'd just like to check it QEMU as well which apparently already has the logic above but also some contradictory comment.
Quoted 4 lines
Err, no, QEMU does not have this logic, it also ignores RH.
But the above bits make "irq.delivery_mode =
e->msi.data&0x700" pointless. And that strongly suggests something is still wrong.
I tend to believe that this is what the spec tries to tell us:
virt/kvm/irq_comm.c +2 -1
@@ -128,7 +128,8 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, MSI_ADDR_DEST_ID_MASK) >> MSI_ADDR_DEST_ID_SHIFT; irq.vector = (e->msi.data &MSI_DATA_VECTOR_MASK ) >>MSI_DATA_VECTOR_SHIFT ; - irq.dest_mode = (1 <<MSI_ADDR_DEST_MODE_SHIFT ) & e->msi.address_lo; + irq.dest_mode = ((e->msi.address_lo &MSI_ADDR_DEST_MODE_LOGICAL ) && + (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI )); irq.trig_mode = (1 <<MSI_DATA_TRIGGER_SHIFT ) & e->msi.data; irq.delivery_mode = e->msi.data &0x700 ; irq.level =1 ;
ie. the DM flag is only relevant if RH is set, and RH==0 is equivalent to RH==1 && DH==0.
BTW, irq_comm.c is surely the wrong place for all this IA32-specific interpretation of MSI address and data. And we have yet another guest-triggerable printk in kvm_irq_delivery_to_apic (messages to physical ID 0xff).
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 73 lines · Jan Kiszka
Quoted 50 lines · Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Sasha Levin
The RH bit exists in the message address register (lower 32 bits of the address).
The bit indicates whether the message should go to the processor which was indicated in the destination ID bits, or whether it should go to the processor running at the lowest priority.
Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- virt/kvm/irq_comm.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)virt/kvm/irq_comm.c +16
-1@@ -134,7 +134,22 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, irq.level =1 ; irq.shorthand =0 ; -/* TODO Deal with RH bit of MSI message address */ +/* +* If the RH bit is set, we'll deliver to the processor running +* at the lowest priority. +*/ +if (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI ) { + irq.delivery_mode =MSI_DATA_DELIVERY_LOWPRI ; + }else { +/* +* If the RH bit is not set, we'll deliver to the specific +* processor mentioned in destination ID, and ignore the DM +* bit. +*/ + irq.dest_mode =MSI_ADDR_DEST_MODE_PHYSICAL ; + irq.delivery_mode =MSI_DATA_DELIVERY_FIXED ; + } +Quoted 8 lines
virt/kvm/irq_comm.c int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, · line 155
Quoted 3 lines
virt/kvm/irq_comm.c +0
-0return kvm_irq_delivery_to_apic (kvm,NULL , &irq); }Do you happen have a kvm unit test for this? Or how did you validate the change? It doesn't look incorrect to me, I'd just like to check it QEMU as well which apparently already has the logic above but also some contradictory comment.
Quoted 4 lines
Err, no, QEMU does not have this logic, it also ignores RH.
But the above bits make "irq.delivery_mode =
e->msi.data&0x700" pointless. And that strongly suggests something is still wrong.I tend to believe that this is what the spec tries to tell us:
virt/kvm/irq_comm.c +2
-1@@ -128,7 +128,8 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, MSI_ADDR_DEST_ID_MASK) >> MSI_ADDR_DEST_ID_SHIFT; irq.vector = (e->msi.data &MSI_DATA_VECTOR_MASK ) >>MSI_DATA_VECTOR_SHIFT ; - irq.dest_mode = (1 <<MSI_ADDR_DEST_MODE_SHIFT ) & e->msi.address_lo; + irq.dest_mode = ((e->msi.address_lo &MSI_ADDR_DEST_MODE_LOGICAL ) && + (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI )); irq.trig_mode = (1 <<MSI_DATA_TRIGGER_SHIFT ) & e->msi.data; irq.delivery_mode = e->msi.data &0x700 ; irq.level =1 ;
Quoted 2 lines
ie. the DM flag is only relevant if RH is set, and RH==0 is equivalent to RH==1 && DH==0.
Thing is, the spec specifically states that RH==1 should deliver to lowest priority - even though it doesn't state whats the relationship between delivery mode and RH bit.
Maybe we should set irq.delivery_mode only if RH==1?
Quoted 8 lines
BTW,
irq_comm.cis surely the wrong place for all this IA32-specific interpretation of MSI address and data. And we have yet another guest-triggerable printk inkvm_irq_delivery_to_apic(messages to physical ID0xff).Jan
Signature · 1 line
Sasha.
Quoted 74 lines · Sasha Levin
Quoted 73 lines · Jan Kiszka
Quoted 50 lines · Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Sasha Levin
The RH bit exists in the message address register (lower 32 bits of the address).
The bit indicates whether the message should go to the processor which was indicated in the destination ID bits, or whether it should go to the processor running at the lowest priority.
Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- virt/kvm/irq_comm.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)virt/kvm/irq_comm.c +16
-1@@ -134,7 +134,22 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, irq.level =1 ; irq.shorthand =0 ; -/* TODO Deal with RH bit of MSI message address */ +/* +* If the RH bit is set, we'll deliver to the processor running +* at the lowest priority. +*/ +if (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI ) { + irq.delivery_mode =MSI_DATA_DELIVERY_LOWPRI ; + }else { +/* +* If the RH bit is not set, we'll deliver to the specific +* processor mentioned in destination ID, and ignore the DM +* bit. +*/ + irq.dest_mode =MSI_ADDR_DEST_MODE_PHYSICAL ; + irq.delivery_mode =MSI_DATA_DELIVERY_FIXED ; + } +Quoted 8 lines
virt/kvm/irq_comm.c int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, · line 155
Quoted 3 lines
virt/kvm/irq_comm.c +0
-0return kvm_irq_delivery_to_apic (kvm,NULL , &irq); }Do you happen have a kvm unit test for this? Or how did you validate the change? It doesn't look incorrect to me, I'd just like to check it QEMU as well which apparently already has the logic above but also some contradictory comment.
Quoted 4 lines
Err, no, QEMU does not have this logic, it also ignores RH.
But the above bits make "irq.delivery_mode =
e->msi.data&0x700" pointless. And that strongly suggests something is still wrong.I tend to believe that this is what the spec tries to tell us:
virt/kvm/irq_comm.c +2
-1@@ -128,7 +128,8 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, MSI_ADDR_DEST_ID_MASK) >> MSI_ADDR_DEST_ID_SHIFT; irq.vector = (e->msi.data &MSI_DATA_VECTOR_MASK ) >>MSI_DATA_VECTOR_SHIFT ; - irq.dest_mode = (1 <<MSI_ADDR_DEST_MODE_SHIFT ) & e->msi.address_lo; + irq.dest_mode = ((e->msi.address_lo &MSI_ADDR_DEST_MODE_LOGICAL ) && + (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI )); irq.trig_mode = (1 <<MSI_DATA_TRIGGER_SHIFT ) & e->msi.data; irq.delivery_mode = e->msi.data &0x700 ; irq.level =1 ;
Quoted 6 lines
Quoted 2 lines
ie. the DM flag is only relevant if RH is set, and RH==0 is equivalent to RH==1 && DH==0.
Thing is, the spec specifically states that RH==1 should deliver to lowest priority - even though it doesn't state whats the relationship between delivery mode and RH bit.
The spec says "When RH is 1 and the physical destination mode is used [DM=0], the Destination ID field must not be set to 0xFF; it must point to a processor that is present and enabled to receive the interrupt."
As far as I understand, there is no "lowest prio" in the setup RH=1/DM=0.
I've cc'ed Kevin who just worked on the APIC model. Maybe he can provide some authoritative answer or dig it up @Intel.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 82 lines · Jan Kiszka
Quoted 74 lines · Sasha Levin
Quoted 73 lines · Jan Kiszka
Quoted 50 lines · Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Sasha Levin
The RH bit exists in the message address register (lower 32 bits of the address).
The bit indicates whether the message should go to the processor which was indicated in the destination ID bits, or whether it should go to the processor running at the lowest priority.
Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- virt/kvm/irq_comm.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)virt/kvm/irq_comm.c +16
-1@@ -134,7 +134,22 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, irq.level =1 ; irq.shorthand =0 ; -/* TODO Deal with RH bit of MSI message address */ +/* +* If the RH bit is set, we'll deliver to the processor running +* at the lowest priority. +*/ +if (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI ) { + irq.delivery_mode =MSI_DATA_DELIVERY_LOWPRI ; + }else { +/* +* If the RH bit is not set, we'll deliver to the specific +* processor mentioned in destination ID, and ignore the DM +* bit. +*/ + irq.dest_mode =MSI_ADDR_DEST_MODE_PHYSICAL ; + irq.delivery_mode =MSI_DATA_DELIVERY_FIXED ; + } +Quoted 8 lines
virt/kvm/irq_comm.c int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, · line 155
Quoted 3 lines
virt/kvm/irq_comm.c +0
-0return kvm_irq_delivery_to_apic (kvm,NULL , &irq); }Do you happen have a kvm unit test for this? Or how did you validate the change? It doesn't look incorrect to me, I'd just like to check it QEMU as well which apparently already has the logic above but also some contradictory comment.
Quoted 4 lines
Err, no, QEMU does not have this logic, it also ignores RH.
But the above bits make "irq.delivery_mode =
e->msi.data&0x700" pointless. And that strongly suggests something is still wrong.I tend to believe that this is what the spec tries to tell us:
virt/kvm/irq_comm.c +2
-1@@ -128,7 +128,8 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, MSI_ADDR_DEST_ID_MASK) >> MSI_ADDR_DEST_ID_SHIFT; irq.vector = (e->msi.data &MSI_DATA_VECTOR_MASK ) >>MSI_DATA_VECTOR_SHIFT ; - irq.dest_mode = (1 <<MSI_ADDR_DEST_MODE_SHIFT ) & e->msi.address_lo; + irq.dest_mode = ((e->msi.address_lo &MSI_ADDR_DEST_MODE_LOGICAL ) && + (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI )); irq.trig_mode = (1 <<MSI_DATA_TRIGGER_SHIFT ) & e->msi.data; irq.delivery_mode = e->msi.data &0x700 ; irq.level =1 ;Quoted 6 lines
Quoted 2 lines
ie. the DM flag is only relevant if RH is set, and RH==0 is equivalent to RH==1 && DH==0.
Thing is, the spec specifically states that RH==1 should deliver to lowest priority - even though it doesn't state whats the relationship between delivery mode and RH bit.
Quoted 4 lines
The spec says "When RH is 1 and the physical destination mode is used [DM=0], the Destination ID field must not be set to
0xFF; it must point to a processor that is present and enabled to receive the interrupt."
When RH=1 and DM=0 yes, but what happens when RH=1 and DM=1?
Quoted 1 line
From what I understand we need to select the processor running at the
lowest priority between the processors that are identified by the destination ID:
"If RH is 1 and DM is 1, the Destination ID Field is interpreted as in logical destination mode and the redirection is limited to only those processors that are part of the logical group of processors based on the processor's logical APIC ID and the Destination ID field in the message."
Quoted 7 lines
As far as I understand, there is no "lowest prio" in the setup RH=1/DM=0.
I've cc'ed Kevin who just worked on the APIC model. Maybe he can provide some authoritative answer or dig it up @Intel.
Jan
Signature · 1 line
Sasha.
Quoted 83 lines · Sasha Levin
Quoted 82 lines · Jan Kiszka
Quoted 80 lines · Sasha Levin
Quoted 73 lines · Jan Kiszka
Quoted 50 lines · Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Sasha Levin
The RH bit exists in the message address register (lower 32 bits of the address).
The bit indicates whether the message should go to the processor which was indicated in the destination ID bits, or whether it should go to the processor running at the lowest priority.
Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- virt/kvm/irq_comm.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)virt/kvm/irq_comm.c +16
-1@@ -134,7 +134,22 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, irq.level =1 ; irq.shorthand =0 ; -/* TODO Deal with RH bit of MSI message address */ +/* +* If the RH bit is set, we'll deliver to the processor running +* at the lowest priority. +*/ +if (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI ) { + irq.delivery_mode =MSI_DATA_DELIVERY_LOWPRI ; + }else { +/* +* If the RH bit is not set, we'll deliver to the specific +* processor mentioned in destination ID, and ignore the DM +* bit. +*/ + irq.dest_mode =MSI_ADDR_DEST_MODE_PHYSICAL ; + irq.delivery_mode =MSI_DATA_DELIVERY_FIXED ; + } +Quoted 8 lines
virt/kvm/irq_comm.c int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, · line 155
Quoted 3 lines
virt/kvm/irq_comm.c +0
-0return kvm_irq_delivery_to_apic (kvm,NULL , &irq); }Do you happen have a kvm unit test for this? Or how did you validate the change? It doesn't look incorrect to me, I'd just like to check it QEMU as well which apparently already has the logic above but also some contradictory comment.
Quoted 4 lines
Err, no, QEMU does not have this logic, it also ignores RH.
But the above bits make "irq.delivery_mode =
e->msi.data&0x700" pointless. And that strongly suggests something is still wrong.I tend to believe that this is what the spec tries to tell us:
virt/kvm/irq_comm.c +2
-1@@ -128,7 +128,8 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, MSI_ADDR_DEST_ID_MASK) >> MSI_ADDR_DEST_ID_SHIFT; irq.vector = (e->msi.data &MSI_DATA_VECTOR_MASK ) >>MSI_DATA_VECTOR_SHIFT ; - irq.dest_mode = (1 <<MSI_ADDR_DEST_MODE_SHIFT ) & e->msi.address_lo; + irq.dest_mode = ((e->msi.address_lo &MSI_ADDR_DEST_MODE_LOGICAL ) && + (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI )); irq.trig_mode = (1 <<MSI_DATA_TRIGGER_SHIFT ) & e->msi.data; irq.delivery_mode = e->msi.data &0x700 ; irq.level =1 ;Quoted 2 lines
ie. the DM flag is only relevant if RH is set, and RH==0 is equivalent to RH==1 && DH==0.
Thing is, the spec specifically states that RH==1 should deliver to lowest priority - even though it doesn't state whats the relationship between delivery mode and RH bit.
Quoted 6 lines
Quoted 4 lines
The spec says "When RH is 1 and the physical destination mode is used [DM=0], the Destination ID field must not be set to
0xFF; it must point to a processor that is present and enabled to receive the interrupt."When RH=1 and DM=0 yes, but what happens when RH=1 and DM=1?
irq.dest_mode becomes non-zero, and kvm_apic_match_dest uses kvm_apic_match_logical_addr for filtering out possible target CPUs.
Mmh, a remaining question is if kvm_irq_delivery_to_apic is then already doing the right thing, even for delivery_mode != APIC_DM_LOWEST.
Again my question to you: Did you observe unexpected behaviour with some real guests, or is this just based on code and spec study so far? If we had a test case, that could also provide valuable hints.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 89 lines · Jan Kiszka
Quoted 88 lines · Sasha Levin
Quoted 86 lines · Jan Kiszka
Quoted 74 lines · Sasha Levin
Quoted 73 lines · Jan Kiszka
Quoted 50 lines · Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Sasha Levin
The RH bit exists in the message address register (lower 32 bits of the address).
The bit indicates whether the message should go to the processor which was indicated in the destination ID bits, or whether it should go to the processor running at the lowest priority.
Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- virt/kvm/irq_comm.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)virt/kvm/irq_comm.c +16
-1@@ -134,7 +134,22 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, irq.level =1 ; irq.shorthand =0 ; -/* TODO Deal with RH bit of MSI message address */ +/* +* If the RH bit is set, we'll deliver to the processor running +* at the lowest priority. +*/ +if (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI ) { + irq.delivery_mode =MSI_DATA_DELIVERY_LOWPRI ; + }else { +/* +* If the RH bit is not set, we'll deliver to the specific +* processor mentioned in destination ID, and ignore the DM +* bit. +*/ + irq.dest_mode =MSI_ADDR_DEST_MODE_PHYSICAL ; + irq.delivery_mode =MSI_DATA_DELIVERY_FIXED ; + } +Quoted 8 lines
virt/kvm/irq_comm.c int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, · line 155
Quoted 3 lines
virt/kvm/irq_comm.c +0
-0return kvm_irq_delivery_to_apic (kvm,NULL , &irq); }Do you happen have a kvm unit test for this? Or how did you validate the change? It doesn't look incorrect to me, I'd just like to check it QEMU as well which apparently already has the logic above but also some contradictory comment.
Quoted 4 lines
Err, no, QEMU does not have this logic, it also ignores RH.
But the above bits make "irq.delivery_mode =
e->msi.data&0x700" pointless. And that strongly suggests something is still wrong.I tend to believe that this is what the spec tries to tell us:
virt/kvm/irq_comm.c +2
-1@@ -128,7 +128,8 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, MSI_ADDR_DEST_ID_MASK) >> MSI_ADDR_DEST_ID_SHIFT; irq.vector = (e->msi.data &MSI_DATA_VECTOR_MASK ) >>MSI_DATA_VECTOR_SHIFT ; - irq.dest_mode = (1 <<MSI_ADDR_DEST_MODE_SHIFT ) & e->msi.address_lo; + irq.dest_mode = ((e->msi.address_lo &MSI_ADDR_DEST_MODE_LOGICAL ) && + (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI )); irq.trig_mode = (1 <<MSI_DATA_TRIGGER_SHIFT ) & e->msi.data; irq.delivery_mode = e->msi.data &0x700 ; irq.level =1 ;Quoted 6 lines
Quoted 2 lines
ie. the DM flag is only relevant if RH is set, and RH==0 is equivalent to RH==1 && DH==0.
Thing is, the spec specifically states that RH==1 should deliver to lowest priority - even though it doesn't state whats the relationship between delivery mode and RH bit.
The spec says "When RH is 1 and the physical destination mode is used [DM=0], the Destination ID field must not be set to
0xFF; it must point to a processor that is present and enabled to receive the interrupt."
Quoted 8 lines
Quoted 1 line
When RH=1 and DM=0 yes, but what happens when RH=1 and DM=1?
irq.dest_mode becomes non-zero, and
kvm_apic_match_destuseskvm_apic_match_logical_addrfor filtering out possible target CPUs.Mmh, a remaining question is if
kvm_irq_delivery_to_apicis then already doing the right thing, even fordelivery_mode!=APIC_DM_LOWEST.
The missing part is that when RH=1 we must look for the lowest priority:
"Redirection hint indication (RH) - This bit indicates whether the message should be directed to the processor with the lowest interrupt priority among processors that can receive the interrupt."
So it's not enough to set dest_mode, we must also make sure that delivery_mode is set to low prio when RH=1.
Quoted 3 lines
Again my question to you: Did you observe unexpected behaviour with some real guests, or is this just based on code and spec study so far? If we had a test case, that could also provide valuable hints.
Sorry, no test case.
I've stumbled on the 'TODO' comment when I was digging into the MSI implementation in KVM and decided to implement it based on specs.
Quoted 3 lines
Jan
Signature · 1 line
Sasha.
Quoted 99 lines · Sasha Levin
Quoted 89 lines · Jan Kiszka
Quoted 88 lines · Sasha Levin
Quoted 86 lines · Jan Kiszka
Quoted 74 lines · Sasha Levin
Quoted 73 lines · Jan Kiszka
Quoted 50 lines · Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Sasha Levin
The RH bit exists in the message address register (lower 32 bits of the address).
The bit indicates whether the message should go to the processor which was indicated in the destination ID bits, or whether it should go to the processor running at the lowest priority.
Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- virt/kvm/irq_comm.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)virt/kvm/irq_comm.c +16
-1@@ -134,7 +134,22 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, irq.level =1 ; irq.shorthand =0 ; -/* TODO Deal with RH bit of MSI message address */ +/* +* If the RH bit is set, we'll deliver to the processor running +* at the lowest priority. +*/ +if (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI ) { + irq.delivery_mode =MSI_DATA_DELIVERY_LOWPRI ; + }else { +/* +* If the RH bit is not set, we'll deliver to the specific +* processor mentioned in destination ID, and ignore the DM +* bit. +*/ + irq.dest_mode =MSI_ADDR_DEST_MODE_PHYSICAL ; + irq.delivery_mode =MSI_DATA_DELIVERY_FIXED ; + } +Quoted 8 lines
virt/kvm/irq_comm.c int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, · line 155
Quoted 3 lines
virt/kvm/irq_comm.c +0
-0return kvm_irq_delivery_to_apic (kvm,NULL , &irq); }Do you happen have a kvm unit test for this? Or how did you validate the change? It doesn't look incorrect to me, I'd just like to check it QEMU as well which apparently already has the logic above but also some contradictory comment.
Quoted 4 lines
Err, no, QEMU does not have this logic, it also ignores RH.
But the above bits make "irq.delivery_mode =
e->msi.data&0x700" pointless. And that strongly suggests something is still wrong.I tend to believe that this is what the spec tries to tell us:
virt/kvm/irq_comm.c +2
-1@@ -128,7 +128,8 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, MSI_ADDR_DEST_ID_MASK) >> MSI_ADDR_DEST_ID_SHIFT; irq.vector = (e->msi.data &MSI_DATA_VECTOR_MASK ) >>MSI_DATA_VECTOR_SHIFT ; - irq.dest_mode = (1 <<MSI_ADDR_DEST_MODE_SHIFT ) & e->msi.address_lo; + irq.dest_mode = ((e->msi.address_lo &MSI_ADDR_DEST_MODE_LOGICAL ) && + (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI )); irq.trig_mode = (1 <<MSI_DATA_TRIGGER_SHIFT ) & e->msi.data; irq.delivery_mode = e->msi.data &0x700 ; irq.level =1 ;Quoted 6 lines
Quoted 2 lines
ie. the DM flag is only relevant if RH is set, and RH==0 is equivalent to RH==1 && DH==0.
Thing is, the spec specifically states that RH==1 should deliver to lowest priority - even though it doesn't state whats the relationship between delivery mode and RH bit.
The spec says "When RH is 1 and the physical destination mode is used [DM=0], the Destination ID field must not be set to
0xFF; it must point to a processor that is present and enabled to receive the interrupt."Quoted 8 lines
Quoted 1 line
When RH=1 and DM=0 yes, but what happens when RH=1 and DM=1?
irq.dest_mode becomes non-zero, and
kvm_apic_match_destuseskvm_apic_match_logical_addrfor filtering out possible target CPUs.Mmh, a remaining question is if
kvm_irq_delivery_to_apicis then already doing the right thing, even fordelivery_mode!=APIC_DM_LOWEST.
Quoted 8 lines
The missing part is that when RH=1 we must look for the lowest priority:
"Redirection hint indication (RH) - This bit indicates whether the message should be directed to the processor with the lowest interrupt priority among processors that can receive the interrupt."
So it's not enough to set
dest_mode, we must also make sure thatdelivery_modeis set to low prio when RH=1.
That's debatable. delivery_mode == APIC_DM_LOWEST includes this target selection, but also more. I have a bad feeling when we just overwrite delivery_mode as defined by the MSI data field instead of only patching kvm_irq_delivery_to_apic or kvm_is_dm_lowest_prio - if required.
Quoted 9 lines
Quoted 4 lines
Again my question to you: Did you observe unexpected behaviour with some real guests, or is this just based on code and spec study so far? If we had a test case, that could also provide valuable hints.
Sorry, no test case.
I've stumbled on the 'TODO' comment when I was digging into the MSI implementation in KVM and decided to implement it based on specs.
Then we definitely need some blessing by Intel to avoid subtle regressions.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 106 lines · Jan Kiszka
Quoted 105 lines · Sasha Levin
Quoted 89 lines · Jan Kiszka
Quoted 88 lines · Sasha Levin
Quoted 86 lines · Jan Kiszka
Quoted 74 lines · Sasha Levin
Quoted 73 lines · Jan Kiszka
Quoted 50 lines · Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Sasha Levin
The RH bit exists in the message address register (lower 32 bits of the address).
The bit indicates whether the message should go to the processor which was indicated in the destination ID bits, or whether it should go to the processor running at the lowest priority.
Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- virt/kvm/irq_comm.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)virt/kvm/irq_comm.c +16
-1@@ -134,7 +134,22 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, irq.level =1 ; irq.shorthand =0 ; -/* TODO Deal with RH bit of MSI message address */ +/* +* If the RH bit is set, we'll deliver to the processor running +* at the lowest priority. +*/ +if (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI ) { + irq.delivery_mode =MSI_DATA_DELIVERY_LOWPRI ; + }else { +/* +* If the RH bit is not set, we'll deliver to the specific +* processor mentioned in destination ID, and ignore the DM +* bit. +*/ + irq.dest_mode =MSI_ADDR_DEST_MODE_PHYSICAL ; + irq.delivery_mode =MSI_DATA_DELIVERY_FIXED ; + } +Quoted 8 lines
virt/kvm/irq_comm.c int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, · line 155
Quoted 3 lines
virt/kvm/irq_comm.c +0
-0return kvm_irq_delivery_to_apic (kvm,NULL , &irq); }Do you happen have a kvm unit test for this? Or how did you validate the change? It doesn't look incorrect to me, I'd just like to check it QEMU as well which apparently already has the logic above but also some contradictory comment.
Quoted 4 lines
Err, no, QEMU does not have this logic, it also ignores RH.
But the above bits make "irq.delivery_mode =
e->msi.data&0x700" pointless. And that strongly suggests something is still wrong.I tend to believe that this is what the spec tries to tell us:
virt/kvm/irq_comm.c +2
-1@@ -128,7 +128,8 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, MSI_ADDR_DEST_ID_MASK) >> MSI_ADDR_DEST_ID_SHIFT; irq.vector = (e->msi.data &MSI_DATA_VECTOR_MASK ) >>MSI_DATA_VECTOR_SHIFT ; - irq.dest_mode = (1 <<MSI_ADDR_DEST_MODE_SHIFT ) & e->msi.address_lo; + irq.dest_mode = ((e->msi.address_lo &MSI_ADDR_DEST_MODE_LOGICAL ) && + (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI )); irq.trig_mode = (1 <<MSI_DATA_TRIGGER_SHIFT ) & e->msi.data; irq.delivery_mode = e->msi.data &0x700 ; irq.level =1 ;Quoted 6 lines
Quoted 2 lines
ie. the DM flag is only relevant if RH is set, and RH==0 is equivalent to RH==1 && DH==0.
Thing is, the spec specifically states that RH==1 should deliver to lowest priority - even though it doesn't state whats the relationship between delivery mode and RH bit.
The spec says "When RH is 1 and the physical destination mode is used [DM=0], the Destination ID field must not be set to
0xFF; it must point to a processor that is present and enabled to receive the interrupt."Quoted 8 lines
Quoted 1 line
When RH=1 and DM=0 yes, but what happens when RH=1 and DM=1?
irq.dest_mode becomes non-zero, and
kvm_apic_match_destuseskvm_apic_match_logical_addrfor filtering out possible target CPUs.Mmh, a remaining question is if
kvm_irq_delivery_to_apicis then already doing the right thing, even fordelivery_mode!=APIC_DM_LOWEST.The missing part is that when RH=1 we must look for the lowest priority:
"Redirection hint indication (RH) - This bit indicates whether the message should be directed to the processor with the lowest interrupt priority among processors that can receive the interrupt."
Quoted 8 lines
Quoted 2 lines
So it's not enough to set
dest_mode, we must also make sure thatdelivery_modeis set to low prio when RH=1.That's debatable.
delivery_mode==APIC_DM_LOWESTincludes this target selection, but also more. I have a bad feeling when we just overwritedelivery_modeas defined by the MSI data field instead of only patchingkvm_irq_delivery_to_apicorkvm_is_dm_lowest_prio- if required.
Patching them how? To behave exactly like delivery_mode == APIC_DM_LOWEST in case RH bit is set? Then setting delivery_mode to APIC_DM_LOWEST will achieve the same goal.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Again my question to you: Did you observe unexpected behaviour with some real guests, or is this just based on code and spec study so far? If we had a test case, that could also provide valuable hints.
Quoted 7 lines
Quoted 4 lines
Sorry, no test case.
I've stumbled on the 'TODO' comment when I was digging into the MSI implementation in KVM and decided to implement it based on specs.
Then we definitely need some blessing by Intel to avoid subtle regressions.
Yes, if we are going to pursue that we need Intel to clarify what SDM means.
--
Gleb.
Quoted 110 lines · Gleb Natapov
Quoted 109 lines · Jan Kiszka
Quoted 107 lines · Sasha Levin
Quoted 89 lines · Jan Kiszka
Quoted 88 lines · Sasha Levin
Quoted 86 lines · Jan Kiszka
Quoted 74 lines · Sasha Levin
Quoted 73 lines · Jan Kiszka
Quoted 50 lines · Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Sasha Levin
The RH bit exists in the message address register (lower 32 bits of the address).
The bit indicates whether the message should go to the processor which was indicated in the destination ID bits, or whether it should go to the processor running at the lowest priority.
Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- virt/kvm/irq_comm.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)virt/kvm/irq_comm.c +16
-1@@ -134,7 +134,22 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, irq.level =1 ; irq.shorthand =0 ; -/* TODO Deal with RH bit of MSI message address */ +/* +* If the RH bit is set, we'll deliver to the processor running +* at the lowest priority. +*/ +if (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI ) { + irq.delivery_mode =MSI_DATA_DELIVERY_LOWPRI ; + }else { +/* +* If the RH bit is not set, we'll deliver to the specific +* processor mentioned in destination ID, and ignore the DM +* bit. +*/ + irq.dest_mode =MSI_ADDR_DEST_MODE_PHYSICAL ; + irq.delivery_mode =MSI_DATA_DELIVERY_FIXED ; + } +Quoted 8 lines
virt/kvm/irq_comm.c int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, · line 155
Quoted 3 lines
virt/kvm/irq_comm.c +0
-0return kvm_irq_delivery_to_apic (kvm,NULL , &irq); }Do you happen have a kvm unit test for this? Or how did you validate the change? It doesn't look incorrect to me, I'd just like to check it QEMU as well which apparently already has the logic above but also some contradictory comment.
Quoted 4 lines
Err, no, QEMU does not have this logic, it also ignores RH.
But the above bits make "irq.delivery_mode =
e->msi.data&0x700" pointless. And that strongly suggests something is still wrong.I tend to believe that this is what the spec tries to tell us:
virt/kvm/irq_comm.c +2
-1@@ -128,7 +128,8 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, MSI_ADDR_DEST_ID_MASK) >> MSI_ADDR_DEST_ID_SHIFT; irq.vector = (e->msi.data &MSI_DATA_VECTOR_MASK ) >>MSI_DATA_VECTOR_SHIFT ; - irq.dest_mode = (1 <<MSI_ADDR_DEST_MODE_SHIFT ) & e->msi.address_lo; + irq.dest_mode = ((e->msi.address_lo &MSI_ADDR_DEST_MODE_LOGICAL ) && + (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI )); irq.trig_mode = (1 <<MSI_DATA_TRIGGER_SHIFT ) & e->msi.data; irq.delivery_mode = e->msi.data &0x700 ; irq.level =1 ;Quoted 6 lines
Quoted 2 lines
ie. the DM flag is only relevant if RH is set, and RH==0 is equivalent to RH==1 && DH==0.
Thing is, the spec specifically states that RH==1 should deliver to lowest priority - even though it doesn't state whats the relationship between delivery mode and RH bit.
The spec says "When RH is 1 and the physical destination mode is used [DM=0], the Destination ID field must not be set to
0xFF; it must point to a processor that is present and enabled to receive the interrupt."Quoted 8 lines
Quoted 1 line
When RH=1 and DM=0 yes, but what happens when RH=1 and DM=1?
irq.dest_mode becomes non-zero, and
kvm_apic_match_destuseskvm_apic_match_logical_addrfor filtering out possible target CPUs.Mmh, a remaining question is if
kvm_irq_delivery_to_apicis then already doing the right thing, even fordelivery_mode!=APIC_DM_LOWEST.The missing part is that when RH=1 we must look for the lowest priority:
"Redirection hint indication (RH) - This bit indicates whether the message should be directed to the processor with the lowest interrupt priority among processors that can receive the interrupt."
So it's not enough to set
dest_mode, we must also make sure thatdelivery_modeis set to low prio when RH=1.
Quoted 8 lines
Quoted 5 lines
That's debatable.
delivery_mode==APIC_DM_LOWESTincludes this target selection, but also more. I have a bad feeling when we just overwritedelivery_modeas defined by the MSI data field instead of only patchingkvm_irq_delivery_to_apicorkvm_is_dm_lowest_prio- if required.Patching them how? To behave exactly like
delivery_mode==APIC_DM_LOWESTin case RH bit is set? Then settingdelivery_modetoAPIC_DM_LOWESTwill achieve the same goal.
/Wrt selecting the target CPU, but not regarding the vector type delivered to that CPU (think of obscure things like RH=1, delivery_mode=APIC_DM_NMI). If RH=1 only meant hard-wiring delivery_mode to single value, then this would be redundant encoding. And that's always suspicious (unless there is legacy involved).
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 9 lines · Jan Kiszka
Quoted 8 lines
Quoted 5 lines
That's debatable.
delivery_mode==APIC_DM_LOWESTincludes this target selection, but also more. I have a bad feeling when we just overwritedelivery_modeas defined by the MSI data field instead of only patchingkvm_irq_delivery_to_apicorkvm_is_dm_lowest_prio- if required.Patching them how? To behave exactly like
delivery_mode==APIC_DM_LOWESTin case RH bit is set? Then settingdelivery_modetoAPIC_DM_LOWESTwill achieve the same goal.
Quoted 6 lines
/Wrt selecting the target CPU, but not regarding the vector type delivered to that CPU (think of obscure things like RH=1, delivery_mode=APIC_DM_NMI). If RH=1 only meant hard-wiring
delivery_modeto single value, then this would be redundant encoding. And that's always suspicious (unless there is legacy involved).
Hmm, good point.
--
Gleb.
Quoted 50 lines · Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Sasha Levin
The RH bit exists in the message address register (lower 32 bits of the address).
The bit indicates whether the message should go to the processor which was indicated in the destination ID bits, or whether it should go to the processor running at the lowest priority.
Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- virt/kvm/irq_comm.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)virt/kvm/irq_comm.c +16
-1@@ -134,7 +134,22 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, irq.level =1 ; irq.shorthand =0 ; -/* TODO Deal with RH bit of MSI message address */ +/* +* If the RH bit is set, we'll deliver to the processor running +* at the lowest priority. +*/ +if (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI ) { + irq.delivery_mode =MSI_DATA_DELIVERY_LOWPRI ; + }else { +/* +* If the RH bit is not set, we'll deliver to the specific +* processor mentioned in destination ID, and ignore the DM +* bit. +*/ + irq.dest_mode =MSI_ADDR_DEST_MODE_PHYSICAL ; + irq.delivery_mode =MSI_DATA_DELIVERY_FIXED ; + } +Quoted 8 lines
virt/kvm/irq_comm.c int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, · line 155
Quoted 3 lines
virt/kvm/irq_comm.c +0
-0return kvm_irq_delivery_to_apic (kvm,NULL , &irq); }Do you happen have a kvm unit test for this? Or how did you validate the change? It doesn't look incorrect to me, I'd just like to check it QEMU as well which apparently already has the logic above but also some contradictory comment.
Quoted 5 lines
Err, no, QEMU does not have this logic, it also ignores RH.
But the above bits make "irq.delivery_mode =
e->msi.data&0x700" pointless. And that strongly suggests something is still wrong.
Yes, looks like delivery_mode assignment in the else clause is not needed. This RH bit is strange. How is it different from setting delivery mode to lowest priority in the data register? What practical problem Sasha tries to fix here?
--
Gleb.
Quoted 53 lines · Gleb Natapov
Quoted 52 lines · Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Sasha Levin
The RH bit exists in the message address register (lower 32 bits of the address).
The bit indicates whether the message should go to the processor which was indicated in the destination ID bits, or whether it should go to the processor running at the lowest priority.
Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- virt/kvm/irq_comm.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)virt/kvm/irq_comm.c +16
-1@@ -134,7 +134,22 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, irq.level =1 ; irq.shorthand =0 ; -/* TODO Deal with RH bit of MSI message address */ +/* +* If the RH bit is set, we'll deliver to the processor running +* at the lowest priority. +*/ +if (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI ) { + irq.delivery_mode =MSI_DATA_DELIVERY_LOWPRI ; + }else { +/* +* If the RH bit is not set, we'll deliver to the specific +* processor mentioned in destination ID, and ignore the DM +* bit. +*/ + irq.dest_mode =MSI_ADDR_DEST_MODE_PHYSICAL ; + irq.delivery_mode =MSI_DATA_DELIVERY_FIXED ; + } +Quoted 8 lines
virt/kvm/irq_comm.c int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, · line 155
Quoted 3 lines
virt/kvm/irq_comm.c +0
-0return kvm_irq_delivery_to_apic (kvm,NULL , &irq); }Do you happen have a kvm unit test for this? Or how did you validate the change? It doesn't look incorrect to me, I'd just like to check it QEMU as well which apparently already has the logic above but also some contradictory comment.
Err, no, QEMU does not have this logic, it also ignores RH.
Quoted 7 lines
Quoted 3 lines
But the above bits make "irq.delivery_mode =
e->msi.data&0x700" pointless. And that strongly suggests something is still wrong.Yes, looks like
delivery_modeassignment in the else clause is not needed. This RH bit is strange. How is it different from setting delivery mode to lowest priority in the data register? What practical problem Sasha tries to fix here?
Logical addressing should not be available without RH==1. It was so far nevertheless because we evaluated DM even if RH was 0.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 57 lines · Jan Kiszka
Quoted 56 lines · Gleb Natapov
Quoted 55 lines · Jan Kiszka
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Sasha Levin
The RH bit exists in the message address register (lower 32 bits of the address).
The bit indicates whether the message should go to the processor which was indicated in the destination ID bits, or whether it should go to the processor running at the lowest priority.
Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- virt/kvm/irq_comm.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)virt/kvm/irq_comm.c +16
-1@@ -134,7 +134,22 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, irq.level =1 ; irq.shorthand =0 ; -/* TODO Deal with RH bit of MSI message address */ +/* +* If the RH bit is set, we'll deliver to the processor running +* at the lowest priority. +*/ +if (e->msi.address_lo &MSI_ADDR_REDIRECTION_LOWPRI ) { + irq.delivery_mode =MSI_DATA_DELIVERY_LOWPRI ; + }else { +/* +* If the RH bit is not set, we'll deliver to the specific +* processor mentioned in destination ID, and ignore the DM +* bit. +*/ + irq.dest_mode =MSI_ADDR_DEST_MODE_PHYSICAL ; + irq.delivery_mode =MSI_DATA_DELIVERY_FIXED ; + } +Quoted 8 lines
virt/kvm/irq_comm.c int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, · line 155
Quoted 3 lines
virt/kvm/irq_comm.c +0
-0return kvm_irq_delivery_to_apic (kvm,NULL , &irq); }Do you happen have a kvm unit test for this? Or how did you validate the change? It doesn't look incorrect to me, I'd just like to check it QEMU as well which apparently already has the logic above but also some contradictory comment.
Err, no, QEMU does not have this logic, it also ignores RH.
But the above bits make "irq.delivery_mode =
e->msi.data&0x700" pointless. And that strongly suggests something is still wrong.
Quoted 8 lines
Quoted 4 lines
Yes, looks like
delivery_modeassignment in the else clause is not needed. This RH bit is strange. How is it different from setting delivery mode to lowest priority in the data register? What practical problem Sasha tries to fix here?Logical addressing should not be available without RH==1. It was so far nevertheless because we evaluated DM even if RH was 0.
Spec says "If RH is 0, then the DM bit is ignored". I don't know how switch (which DM bit really is) can be ignored though. It either logical of physical, there is not "ignore" state. You are saying that this mysterious phrase from the spec should be interpreted as "If RH is 0, then the DM bit is always treated as if it is 0" and you may be right, but clarification from Intel would be nice.
--
Gleb.