LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [Patch v1] KVM: x86: Initializing all kvm_lapic_irq fields
@ 2020-03-11 18:34 Nitesh Narayan Lal
2020-03-11 18:49 ` Paolo Bonzini
0 siblings, 1 reply; 3+ messages in thread
From: Nitesh Narayan Lal @ 2020-03-11 18:34 UTC (permalink / raw)
To: kvm, linux-kernel, mtosatti, vkuznets, sean.j.christopherson,
wanpengli, jmattson, joro, pbonzini
Previously all fields of structure kvm_lapic_irq were not initialized
before it was passed to kvm_bitmap_or_dest_vcpus(). Which will cause
an issue when any of those fields are used for processing a request.
This patch initializes all the fields of kvm_lapic_irq based on the
values which are passed through the ioapic redirect_entry object.
Fixes: 7ee30bc132c6("KVM: x86: deliver KVM IOAPIC scan request to target vCPUs")
Signed-off-by: Nitesh Narayan Lal <nitesh@redhat.com>
---
arch/x86/kvm/ioapic.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c
index 7668fed..3a8467d 100644
--- a/arch/x86/kvm/ioapic.c
+++ b/arch/x86/kvm/ioapic.c
@@ -378,12 +378,15 @@ static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val)
if (e->fields.delivery_mode == APIC_DM_FIXED) {
struct kvm_lapic_irq irq;
- irq.shorthand = APIC_DEST_NOSHORT;
irq.vector = e->fields.vector;
irq.delivery_mode = e->fields.delivery_mode << 8;
- irq.dest_id = e->fields.dest_id;
irq.dest_mode =
kvm_lapic_irq_dest_mode(!!e->fields.dest_mode);
+ irq.level = 1;
+ irq.trig_mode = e->fields.trig_mode;
+ irq.shorthand = APIC_DEST_NOSHORT;
+ irq.dest_id = e->fields.dest_id;
+ irq.msi_redir_hint = false;
bitmap_zero(&vcpu_bitmap, 16);
kvm_bitmap_or_dest_vcpus(ioapic->kvm, &irq,
&vcpu_bitmap);
--
1.8.3.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Patch v1] KVM: x86: Initializing all kvm_lapic_irq fields
2020-03-11 18:34 [Patch v1] KVM: x86: Initializing all kvm_lapic_irq fields Nitesh Narayan Lal
@ 2020-03-11 18:49 ` Paolo Bonzini
2020-03-11 19:05 ` Nitesh Narayan Lal
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2020-03-11 18:49 UTC (permalink / raw)
To: Nitesh Narayan Lal, kvm, linux-kernel, mtosatti, vkuznets,
sean.j.christopherson, wanpengli, jmattson, joro
On 11/03/20 19:34, Nitesh Narayan Lal wrote:
> Previously all fields of structure kvm_lapic_irq were not initialized
> before it was passed to kvm_bitmap_or_dest_vcpus(). Which will cause
> an issue when any of those fields are used for processing a request.
> This patch initializes all the fields of kvm_lapic_irq based on the
> values which are passed through the ioapic redirect_entry object.
Can you explain better how the bug manifests itself?
Thanks,
Paolo
> Fixes: 7ee30bc132c6("KVM: x86: deliver KVM IOAPIC scan request to target vCPUs")
> Signed-off-by: Nitesh Narayan Lal <nitesh@redhat.com>
> ---
> arch/x86/kvm/ioapic.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c
> index 7668fed..3a8467d 100644
> --- a/arch/x86/kvm/ioapic.c
> +++ b/arch/x86/kvm/ioapic.c
> @@ -378,12 +378,15 @@ static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val)
> if (e->fields.delivery_mode == APIC_DM_FIXED) {
> struct kvm_lapic_irq irq;
>
> - irq.shorthand = APIC_DEST_NOSHORT;
> irq.vector = e->fields.vector;
> irq.delivery_mode = e->fields.delivery_mode << 8;
> - irq.dest_id = e->fields.dest_id;
> irq.dest_mode =
> kvm_lapic_irq_dest_mode(!!e->fields.dest_mode);
> + irq.level = 1;
> + irq.trig_mode = e->fields.trig_mode;
> + irq.shorthand = APIC_DEST_NOSHORT;
> + irq.dest_id = e->fields.dest_id;
> + irq.msi_redir_hint = false;
> bitmap_zero(&vcpu_bitmap, 16);
> kvm_bitmap_or_dest_vcpus(ioapic->kvm, &irq,
> &vcpu_bitmap);
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Patch v1] KVM: x86: Initializing all kvm_lapic_irq fields
2020-03-11 18:49 ` Paolo Bonzini
@ 2020-03-11 19:05 ` Nitesh Narayan Lal
0 siblings, 0 replies; 3+ messages in thread
From: Nitesh Narayan Lal @ 2020-03-11 19:05 UTC (permalink / raw)
To: Paolo Bonzini, kvm, linux-kernel, mtosatti, vkuznets,
sean.j.christopherson, wanpengli, jmattson, joro
[-- Attachment #1.1: Type: text/plain, Size: 2241 bytes --]
On 3/11/20 2:49 PM, Paolo Bonzini wrote:
> On 11/03/20 19:34, Nitesh Narayan Lal wrote:
>> Previously all fields of structure kvm_lapic_irq were not initialized
>> before it was passed to kvm_bitmap_or_dest_vcpus(). Which will cause
>> an issue when any of those fields are used for processing a request.
>> This patch initializes all the fields of kvm_lapic_irq based on the
>> values which are passed through the ioapic redirect_entry object.
> Can you explain better how the bug manifests itself?
For example not initializing the irq.msi_redir_hint field, could lead to a
situation where it carries garbage (non-zero) value.
This will lead to misbehavior of kvm_apic_map_get_dest_lapic() when it invokes
the kvm_lowest_prio_delivery(), that will return true because of non-zero
msi_redir_hint field.
To be on the safe side, I thought of initializing other struct fields as well.
If the above explanation makes sense, I can include it in the patch
subject and send a second version of this patch?
>
> Thanks,
>
> Paolo
>
>> Fixes: 7ee30bc132c6("KVM: x86: deliver KVM IOAPIC scan request to target vCPUs")
>> Signed-off-by: Nitesh Narayan Lal <nitesh@redhat.com>
>> ---
>> arch/x86/kvm/ioapic.c | 7 +++++--
>> 1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c
>> index 7668fed..3a8467d 100644
>> --- a/arch/x86/kvm/ioapic.c
>> +++ b/arch/x86/kvm/ioapic.c
>> @@ -378,12 +378,15 @@ static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val)
>> if (e->fields.delivery_mode == APIC_DM_FIXED) {
>> struct kvm_lapic_irq irq;
>>
>> - irq.shorthand = APIC_DEST_NOSHORT;
>> irq.vector = e->fields.vector;
>> irq.delivery_mode = e->fields.delivery_mode << 8;
>> - irq.dest_id = e->fields.dest_id;
>> irq.dest_mode =
>> kvm_lapic_irq_dest_mode(!!e->fields.dest_mode);
>> + irq.level = 1;
>> + irq.trig_mode = e->fields.trig_mode;
>> + irq.shorthand = APIC_DEST_NOSHORT;
>> + irq.dest_id = e->fields.dest_id;
>> + irq.msi_redir_hint = false;
>> bitmap_zero(&vcpu_bitmap, 16);
>> kvm_bitmap_or_dest_vcpus(ioapic->kvm, &irq,
>> &vcpu_bitmap);
>>
--
Nitesh
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-03-11 19:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11 18:34 [Patch v1] KVM: x86: Initializing all kvm_lapic_irq fields Nitesh Narayan Lal
2020-03-11 18:49 ` Paolo Bonzini
2020-03-11 19:05 ` Nitesh Narayan Lal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).