kvm: Implement kvm_irqchip_in_kernel like kvm_enabled

To both avoid that kvm_irqchip_in_kernel always has to be paired with
kvm_enabled and that the former ends up in a function call, implement it
like the latter. This means keeping the state in a global variable and
defining kvm_irqchip_in_kernel as a preprocessor macro.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
This commit is contained in:
Jan Kiszka 2012-01-31 19:17:52 +01:00 committed by Marcelo Tosatti
parent 39d6960aab
commit 3d4b26494f
6 changed files with 16 additions and 24 deletions

View File

@ -889,7 +889,7 @@ static DeviceState *apic_init(void *env, uint8_t apic_id)
DeviceState *dev;
static int apic_mapped;
if (kvm_enabled() && kvm_irqchip_in_kernel()) {
if (kvm_irqchip_in_kernel()) {
dev = qdev_create(NULL, "kvm-apic");
} else {
dev = qdev_create(NULL, "apic");
@ -908,7 +908,7 @@ static DeviceState *apic_init(void *env, uint8_t apic_id)
}
/* KVM does not support MSI yet. */
if (!kvm_enabled() || !kvm_irqchip_in_kernel()) {
if (!kvm_irqchip_in_kernel()) {
msi_supported = true;
}

View File

@ -104,7 +104,7 @@ static void ioapic_init(GSIState *gsi_state)
SysBusDevice *d;
unsigned int i;
if (kvm_enabled() && kvm_irqchip_in_kernel()) {
if (kvm_irqchip_in_kernel()) {
dev = qdev_create(NULL, "kvm-ioapic");
} else {
dev = qdev_create(NULL, "ioapic");
@ -183,7 +183,7 @@ static void pc_init1(MemoryRegion *system_memory,
}
gsi_state = g_malloc0(sizeof(*gsi_state));
if (kvm_enabled() && kvm_irqchip_in_kernel()) {
if (kvm_irqchip_in_kernel()) {
kvm_piix3_setup_irq_routing(pci_enabled);
gsi = qemu_allocate_irqs(kvm_piix3_gsi_handler, gsi_state,
GSI_NUM_PINS);
@ -209,7 +209,7 @@ static void pc_init1(MemoryRegion *system_memory,
}
isa_bus_irqs(isa_bus, gsi);
if (kvm_enabled() && kvm_irqchip_in_kernel()) {
if (kvm_irqchip_in_kernel()) {
i8259 = kvm_i8259_init(isa_bus);
} else if (xen_enabled()) {
i8259 = xen_interrupt_controller_init();

View File

@ -74,7 +74,6 @@ struct KVMState
#ifdef KVM_CAP_SET_GUEST_DEBUG
struct kvm_sw_breakpoint_head kvm_sw_breakpoints;
#endif
int irqchip_in_kernel;
int pit_in_kernel;
int xsave, xcrs;
int many_ioeventfds;
@ -88,6 +87,7 @@ struct KVMState
};
KVMState *kvm_state;
bool kvm_kernel_irqchip;
static const KVMCapabilityInfo kvm_required_capabilites[] = {
KVM_CAP_INFO(USER_MEMORY),
@ -193,11 +193,6 @@ static void kvm_reset_vcpu(void *opaque)
kvm_arch_reset_vcpu(env);
}
int kvm_irqchip_in_kernel(void)
{
return kvm_state->irqchip_in_kernel;
}
int kvm_pit_in_kernel(void)
{
return kvm_state->pit_in_kernel;
@ -742,7 +737,7 @@ int kvm_irqchip_set_irq(KVMState *s, int irq, int level)
struct kvm_irq_level event;
int ret;
assert(s->irqchip_in_kernel);
assert(kvm_irqchip_in_kernel());
event.level = level;
event.irq = irq;
@ -862,7 +857,7 @@ static int kvm_irqchip_create(KVMState *s)
if (kvm_check_extension(s, KVM_CAP_IRQ_INJECT_STATUS)) {
s->irqchip_inject_ioctl = KVM_IRQ_LINE_STATUS;
}
s->irqchip_in_kernel = 1;
kvm_kernel_irqchip = true;
kvm_init_irq_routing(s);
@ -1315,7 +1310,7 @@ int kvm_has_gsi_routing(void)
int kvm_allows_irq0_override(void)
{
return !kvm_enabled() || !kvm_irqchip_in_kernel() || kvm_has_gsi_routing();
return !kvm_irqchip_in_kernel() || kvm_has_gsi_routing();
}
void kvm_setup_guest_memory(void *start, size_t size)

View File

@ -16,11 +16,6 @@
#include "gdbstub.h"
#include "kvm.h"
int kvm_irqchip_in_kernel(void)
{
return 0;
}
int kvm_pit_in_kernel(void)
{
return 0;

8
kvm.h
View File

@ -23,11 +23,14 @@
#endif
extern int kvm_allowed;
extern bool kvm_kernel_irqchip;
#if defined CONFIG_KVM || !defined NEED_CPU_H
#define kvm_enabled() (kvm_allowed)
#define kvm_enabled() (kvm_allowed)
#define kvm_irqchip_in_kernel() (kvm_kernel_irqchip)
#else
#define kvm_enabled() (0)
#define kvm_enabled() (0)
#define kvm_irqchip_in_kernel() (false)
#endif
struct kvm_run;
@ -80,7 +83,6 @@ int kvm_set_signal_mask(CPUState *env, const sigset_t *sigset);
#endif
int kvm_pit_in_kernel(void);
int kvm_irqchip_in_kernel(void);
int kvm_on_sigbus_vcpu(CPUState *env, int code, void *addr);
int kvm_on_sigbus(int code, void *addr);

View File

@ -1356,7 +1356,7 @@ static int kvm_get_apic(CPUState *env)
struct kvm_lapic_state kapic;
int ret;
if (apic && kvm_enabled() && kvm_irqchip_in_kernel()) {
if (apic && kvm_irqchip_in_kernel()) {
ret = kvm_vcpu_ioctl(env, KVM_GET_LAPIC, &kapic);
if (ret < 0) {
return ret;
@ -1372,7 +1372,7 @@ static int kvm_put_apic(CPUState *env)
DeviceState *apic = env->apic_state;
struct kvm_lapic_state kapic;
if (apic && kvm_enabled() && kvm_irqchip_in_kernel()) {
if (apic && kvm_irqchip_in_kernel()) {
kvm_put_apic_state(apic, &kapic);
return kvm_vcpu_ioctl(env, KVM_SET_LAPIC, &kapic);