KVM: PIT: remove useless code from kvm_create_pit()
PATCH 1/2 KVM: PIT: remove useless code from kvm_create_pit()
kvm->arch.vpit will be set to the return value of kvm_create_pit(), so we do not need to set kvm->arch.vpit in kvm_create_pit(). This patch remove the useless code.
--- arch/x86/kvm/i8254.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
arch/x86/kvm/i8254.c +0 -1
@@ -626,7 +626,6 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)mutex_lock (&pit->pit_state.lock);spin_lock_init (&pit->pit_state.inject_lock); - kvm->arch.vpit = pit; pit->kvm = kvm; pit_state = &pit->pit_state;
Signature · 1 line
1.6.3.3
PATCH 2/2 KVM: PIT: unregister kvm irq notifier if fail to create pit
If fail to create pit, we should unregister kvm irq notifier which register in kvm_create_pit().
--- arch/x86/kvm/i8254.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
arch/x86/kvm/i8254.c +3 -2
@@ -662,8 +662,9 @@ fail_unregister:kvm_io_bus_unregister_dev (kvm,KVM_PIO_BUS , &pit->dev); fail: -if (pit->irq_source_id >=0 ) -kvm_free_irq_source_id (kvm, pit->irq_source_id); +kvm_unregister_irq_mask_notifier (kvm,0 , &pit->mask_notifier); +kvm_unregister_irq_ack_notifier (kvm, &pit_state->irq_ack_notifier); +kvm_free_irq_source_id (kvm, pit->irq_source_id);kfree (pit);return NULL ;
Signature · 1 line
1.6.3.3
PATCH 1/1 KVM: only set kvm->arch.vioapic when success to init ioapic
kvm->arch.vioapic is always set either kvm_ioapic_init() is success or fail. If kvm_ioapic_init() is fail, the kvm->arch.vioapic may point a freed memory.
--- virt/kvm/ioapic.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
virt/kvm/ioapic.c +2 -1
@@ -386,7 +386,6 @@ int kvm_ioapic_init(struct kvm *kvm)if (!ioapic)return -ENOMEM ;mutex_init (&ioapic->lock); - kvm->arch.vioapic = ioapic;kvm_ioapic_reset (ioapic);kvm_iodevice_init (&ioapic->dev, &ioapic_mmio_ops); ioapic->kvm = kvm;
@@ -395,6 +394,8 @@ int kvm_ioapic_init(struct kvm *kvm)mutex_unlock (&kvm->slots_lock);if (ret <0 )kfree (ioapic); +else + kvm->arch.vioapic = ioapic;return ret; }
Signature · 1 line
1.6.3.3
PATCH 1/1 KVM: ia64: clear kvm->arch.vioapic if fail to create irq chip
If fail to create irq chip due to fail of kvm_setup_default_irq_routing(), kvm->arch.vioapic is not set to NULL, this may cause KVM_GET_IRQCHIP and KVM_SET_IRQCHIP access to unexcepted memory.
--- arch/ia64/kvm/kvm-ia64.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
arch/ia64/kvm/kvm-ia64.c +1 -0
@@ -969,6 +969,7 @@ long kvm_arch_vm_ioctl(struct file *filp, r =kvm_setup_default_irq_routing (kvm);if (r) {kfree (kvm->arch.vioapic); + kvm->arch.vioapic =NULL ; goto out; }break ;
Signature · 1 line
1.6.3.3
Re: [PATCH] KVM: ia64: clear kvm->arch.vioapic if fail to create irq chip
Quoted 11 lines · Wei Yongjun
If fail to create irq chip due to fail of
kvm_setup_default_irq_routing(),kvm->arch.vioapicis not set to NULL, this may causeKVM_GET_IRQCHIPandKVM_SET_IRQCHIPaccess to unexcepted memory.Signed-off-by Wei Yongjun <[email protected]>--- arch/ia64/kvm/kvm-ia64.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
Please ignore this patch, I will send a update patch in other thread, thanks.
Re: [PATCH] KVM: only set kvm->arch.vioapic when success to init ioapic
In reply to Wei YongjunQuoted 22 lines · Wei Yongjun
kvm->arch.vioapicis always set eitherkvm_ioapic_init()is success or fail. Ifkvm_ioapic_init()is fail, thekvm->arch.vioapicmay point a freed memory.Signed-off-by Wei Yongjun <[email protected]>--- virt/kvm/ioapic.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)virt/kvm/ioapic.c +0
-1@@ -386,7 +386,6 @@ int kvm_ioapic_init(struct kvm *kvm)if (!ioapic)return -ENOMEM ;mutex_init (&ioapic->lock); - kvm->arch.vioapic = ioapic;kvm_ioapic_reset (ioapic);kvm_iodevice_init (&ioapic->dev, &ioapic_mmio_ops); ioapic->kvm = kvm;
virt/kvm/ioapic.c int kvm_ioapic_init(struct kvm *kvm) · line 401
Quoted 8 lines
virt/kvm/ioapic.c +2
-0@@ -395,6 +394,8 @@ int kvm_ioapic_init(struct kvm *kvm)mutex_unlock (&kvm->slots_lock);if (ret <0 )kfree (ioapic); +else + kvm->arch.vioapic = ioapic;return ret; }
Same thing as with the PIT issue, kvm->arch.vioapic must be set before kvm_io_bus_register_dev.
But you're right that kvm->arch.vioapic should be NULLified in case of failure.
PATCH v2 1/1 KVM: kvm->arch.vioapic should be NULL if kvm_ioapic_init() failure
kvm->arch.vioapic should be NULL in case of kvm_ioapic_init() failure due to cannot register io dev.
--- virt/kvm/ioapic.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
virt/kvm/ioapic.c +3 -1
@@ -393,8 +393,10 @@ int kvm_ioapic_init(struct kvm *kvm)mutex_lock (&kvm->slots_lock); ret =kvm_io_bus_register_dev (kvm,KVM_MMIO_BUS , &ioapic->dev);mutex_unlock (&kvm->slots_lock); -if (ret <0 ) +if (ret <0 ) { + kvm->arch.vioapic =NULL ;kfree (ioapic); + }return ret; }
Signature · 1 line
1.6.3.3
Re: [PATCHv2] KVM: kvm->arch.vioapic should be NULL if kvm_ioapic_init() failure
Quoted 10 lines · Wei Yongjun
kvm->arch.vioapicshould be NULL in case ofkvm_ioapic_init()failure due to cannot register io dev.Signed-off-by Wei Yongjun <[email protected]>--- virt/kvm/ioapic.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
Please ignore this patch, I will send in other thread, thanks.
Re: [PATCH 2/2] KVM: PIT: unregister kvm irq notifier if fail to create pit
In reply to Wei YongjunQuoted 7 lines · Wei Yongjun
If fail to create pit, we should unregister kvm irq notifier which register in
kvm_create_pit().Signed-off-by Wei Yongjun <[email protected]>--- arch/x86/kvm/i8254.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
ACK
Avi Kivity
AppliedRe: [PATCH 2/2] KVM: PIT: unregister kvm irq notifier if fail to create pit
In reply to Wei YongjunQuoted 3 lines · Wei Yongjun
If fail to create pit, we should unregister kvm irq notifier which register in
kvm_create_pit().
Applied, thanks.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 5 lines · Wei Yongjun
kvm->arch.vpitwill be set to the return value ofkvm_create_pit(), so we do not need to setkvm->arch.vpitinkvm_create_pit(). This patch remove the useless code.Signed-off-by Wei Yongjun <[email protected]>
The device could be accessed between kvm_io_bus_register_dev and kvm->arch.vpit assignment in the ioctl handler.
Quoted 16 lines
--- arch/x86/kvm/i8254.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)arch/x86/kvm/i8254.c +0
-1@@ -626,7 +626,6 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)mutex_lock (&pit->pit_state.lock);spin_lock_init (&pit->pit_state.inject_lock); - kvm->arch.vpit = pit; pit->kvm = kvm; pit_state = &pit->pit_state;