[Qemu-devel] [PATCH] kvm: don't register smram_listener when smm is off

Gonglei posted 1 patch 6 years, 11 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/1495865408-13848-1-git-send-email-arei.gonglei@huawei.com
Test checkpatch passed
Test docker passed
Test s390x passed
There is a newer version of this series
kvm-all.c         | 4 ++--
target/i386/kvm.c | 3 ++-
2 files changed, 4 insertions(+), 3 deletions(-)
[Qemu-devel] [PATCH] kvm: don't register smram_listener when smm is off
Posted by Gonglei 6 years, 11 months ago
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 <arei.gonglei@huawei.com>
---
 kvm-all.c         | 4 ++--
 target/i386/kvm.c | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 90b8573..92bdf2c 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1746,6 +1746,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;
@@ -1755,8 +1757,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;
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index 011d4a5..cb5b47e 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -1254,7 +1254,8 @@ 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) &&
+            pc_machine_is_smm_enabled(PC_MACHINE(ms))) {
         smram_machine_done.notify = register_smram_listener;
         qemu_add_machine_init_done_notifier(&smram_machine_done);
     }
-- 
1.8.3.1



Re: [Qemu-devel] [PATCH] kvm: don't register smram_listener when smm is off
Posted by Gonglei (Arei) 6 years, 10 months ago
Soft ping... :)



Regards,
-Gonglei


> -----Original Message-----
> From: Gonglei (Arei)
> Sent: Saturday, May 27, 2017 2:10 PM
> To: qemu-devel@nongnu.org
> Cc: pbonzini@redhat.com; Yechuan; Gonglei (Arei)
> Subject: [PATCH] kvm: don't register smram_listener when smm is off
> 
> 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 <arei.gonglei@huawei.com>
> ---
>  kvm-all.c         | 4 ++--
>  target/i386/kvm.c | 3 ++-
>  2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/kvm-all.c b/kvm-all.c
> index 90b8573..92bdf2c 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -1746,6 +1746,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;
> @@ -1755,8 +1757,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;
> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> index 011d4a5..cb5b47e 100644
> --- a/target/i386/kvm.c
> +++ b/target/i386/kvm.c
> @@ -1254,7 +1254,8 @@ 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) &&
> +            pc_machine_is_smm_enabled(PC_MACHINE(ms))) {
>          smram_machine_done.notify = register_smram_listener;
>          qemu_add_machine_init_done_notifier(&smram_machine_done);
>      }
> --
> 1.8.3.1
> 


Re: [Qemu-devel] [PATCH] kvm: don't register smram_listener when smm is off
Posted by Paolo Bonzini 6 years, 10 months ago

On 27/05/2017 08:10, Gonglei wrote:
> 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 <arei.gonglei@huawei.com>
> ---
>  kvm-all.c         | 4 ++--
>  target/i386/kvm.c | 3 ++-
>  2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/kvm-all.c b/kvm-all.c
> index 90b8573..92bdf2c 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -1746,6 +1746,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;
> @@ -1755,8 +1757,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;
> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> index 011d4a5..cb5b47e 100644
> --- a/target/i386/kvm.c
> +++ b/target/i386/kvm.c
> @@ -1254,7 +1254,8 @@ 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) &&
> +            pc_machine_is_smm_enabled(PC_MACHINE(ms))) {
>          smram_machine_done.notify = register_smram_listener;
>          qemu_add_machine_init_done_notifier(&smram_machine_done);
>      }
> 

I think this breaks

    x86_64-softmmu/qemu-system-x86_64 -M none -S --enable-kvm

You need to do a object_dynamic_cast before invoking PC_MACHINE(ms).

Thanks,

Paolo

Re: [Qemu-devel] [PATCH] kvm: don't register smram_listener when smm is off
Posted by Gonglei (Arei) 6 years, 10 months ago
> -----Original Message-----
> From: Paolo Bonzini [mailto:pbonzini@redhat.com]
> Sent: Thursday, June 01, 2017 6:04 PM
> To: Gonglei (Arei); qemu-devel@nongnu.org
> Cc: Yechuan
> Subject: Re: [PATCH] kvm: don't register smram_listener when smm is off
> 
> 
> 
> On 27/05/2017 08:10, Gonglei wrote:
> > 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 <arei.gonglei@huawei.com>
> > ---
> >  kvm-all.c         | 4 ++--
> >  target/i386/kvm.c | 3 ++-
> >  2 files changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/kvm-all.c b/kvm-all.c
> > index 90b8573..92bdf2c 100644
> > --- a/kvm-all.c
> > +++ b/kvm-all.c
> > @@ -1746,6 +1746,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;
> > @@ -1755,8 +1757,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;
> > diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> > index 011d4a5..cb5b47e 100644
> > --- a/target/i386/kvm.c
> > +++ b/target/i386/kvm.c
> > @@ -1254,7 +1254,8 @@ 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) &&
> > +            pc_machine_is_smm_enabled(PC_MACHINE(ms))) {
> >          smram_machine_done.notify = register_smram_listener;
> >
> qemu_add_machine_init_done_notifier(&smram_machine_done);
> >      }
> >
> 
> I think this breaks
> 
>     x86_64-softmmu/qemu-system-x86_64 -M none -S --enable-kvm
> 
> You need to do a object_dynamic_cast before invoking PC_MACHINE(ms).
> 
Good catch! V2 will be posted soon.

Thanks,
-Gonglei