Skip to content

Commit

Permalink
kvm: don't register smram_listener when smm is off
Browse files Browse the repository at this point in the history
If the user set disable smm by '-machine smm=off', we
should not register smram_listener so that we can
avoid waster memory in kvm since the added sencond
address space.

Meanwhile we should assign value of the global kvm_state
before invoking the kvm_arch_init(), because
pc_machine_is_smm_enabled() may use it by kvm_has_mm().

Signed-off-by: Gonglei <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
gongleiarei authored and bonzini committed Jun 7, 2017
1 parent 6bdcc01 commit d870cfd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions kvm-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -1748,6 +1748,8 @@ static int kvm_init(MachineState *ms)
kvm_ioeventfd_any_length_allowed =
(kvm_check_extension(s, KVM_CAP_IOEVENTFD_ANY_LENGTH) > 0);

kvm_state = s;

ret = kvm_arch_init(ms, s);
if (ret < 0) {
goto err;
Expand All @@ -1757,8 +1759,6 @@ static int kvm_init(MachineState *ms)
kvm_irqchip_create(ms, s);
}

kvm_state = s;

if (kvm_eventfds_allowed) {
s->memory_listener.listener.eventfd_add = kvm_mem_ioeventfd_add;
s->memory_listener.listener.eventfd_del = kvm_mem_ioeventfd_del;
Expand Down
4 changes: 3 additions & 1 deletion target/i386/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,9 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
}
}

if (kvm_check_extension(s, KVM_CAP_X86_SMM)) {
if (kvm_check_extension(s, KVM_CAP_X86_SMM) &&
object_dynamic_cast(OBJECT(ms), TYPE_PC_MACHINE) &&
pc_machine_is_smm_enabled(PC_MACHINE(ms))) {
smram_machine_done.notify = register_smram_listener;
qemu_add_machine_init_done_notifier(&smram_machine_done);
}
Expand Down

0 comments on commit d870cfd

Please sign in to comment.