From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 6/7] kvm-all: kvm_irqchip_create is not expected to fail
Date: Mon, 18 May 2015 17:28:39 +0200 [thread overview]
Message-ID: <1431962920-47525-7-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1431962920-47525-1-git-send-email-pbonzini@redhat.com>
KVM_CREATE_IRQCHIP should never fail, and so should its userspace
wrapper kvm_irqchip_create. The function does not do anything
if the irqchip capability is not available, as is the case for PPC.
With this patch, kvm_arch_init can allocate memory and it will not
be leaked.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
kvm-all.c | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/kvm-all.c b/kvm-all.c
index f8552a9..ce18b40 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1391,27 +1391,31 @@ int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq)
false);
}
-static int kvm_irqchip_create(MachineState *machine, KVMState *s)
+static void kvm_irqchip_create(MachineState *machine, KVMState *s)
{
int ret;
- if (!machine_kernel_irqchip_allowed(machine) ||
- (!kvm_check_extension(s, KVM_CAP_IRQCHIP) &&
- (kvm_vm_enable_cap(s, KVM_CAP_S390_IRQCHIP, 0) < 0))) {
- return 0;
+ if (kvm_check_extension(s, KVM_CAP_IRQCHIP)) {
+ ;
+ } else if (kvm_check_extension(s, KVM_CAP_S390_IRQCHIP)) {
+ ret = kvm_vm_enable_cap(s, KVM_CAP_S390_IRQCHIP, 0);
+ if (ret < 0) {
+ fprintf(stderr, "Enable kernel irqchip failed: %s\n", strerror(-ret));
+ exit(1);
+ }
+ } else {
+ return;
}
/* First probe and see if there's a arch-specific hook to create the
* in-kernel irqchip for us */
ret = kvm_arch_irqchip_create(s);
- if (ret < 0) {
- return ret;
- } else if (ret == 0) {
+ if (ret == 0) {
ret = kvm_vm_ioctl(s, KVM_CREATE_IRQCHIP);
- if (ret < 0) {
- fprintf(stderr, "Create kernel irqchip failed\n");
- return ret;
- }
+ }
+ if (ret < 0) {
+ fprintf(stderr, "Create kernel irqchip failed: %s\n", strerror(-ret));
+ exit(1);
}
kvm_kernel_irqchip = true;
@@ -1422,8 +1426,6 @@ static int kvm_irqchip_create(MachineState *machine, KVMState *s)
kvm_halt_in_kernel_allowed = true;
kvm_init_irq_routing(s);
-
- return 0;
}
/* Find number of supported CPUs using the recommended
@@ -1640,9 +1642,8 @@ static int kvm_init(MachineState *ms)
goto err;
}
- ret = kvm_irqchip_create(ms, s);
- if (ret < 0) {
- goto err;
+ if (machine_kernel_irqchip_allowed(ms)) {
+ kvm_irqchip_create(ms, s);
}
kvm_state = s;
--
1.8.3.1
next prev parent reply other threads:[~2015-05-18 15:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-18 15:28 [Qemu-devel] [PATCH 0/7] kvm-i386: QEMU support for SMRAM Paolo Bonzini
2015-05-18 15:28 ` [Qemu-devel] [PATCH 1/7] kvm-all: put kvm_mem_flags to more work Paolo Bonzini
2015-05-18 15:28 ` [Qemu-devel] [PATCH 2/7] kvm-all: remove useless typedef Paolo Bonzini
2015-05-18 15:28 ` [Qemu-devel] [PATCH 3/7] kvm-all: move internal types to kvm_int.h Paolo Bonzini
2015-05-18 15:28 ` [Qemu-devel] [PATCH 4/7] kvm-all: make KVM's memory listener more generic Paolo Bonzini
2015-05-18 15:28 ` [Qemu-devel] [PATCH 5/7] kvm-all: add support for multiple address spaces Paolo Bonzini
2015-05-18 15:28 ` Paolo Bonzini [this message]
2015-05-18 15:28 ` [Qemu-devel] [PATCH 7/7] target-i386: register a separate KVM address space including SMRAM regions Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1431962920-47525-7-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).