Skip to contentSkip to conversation

SMM: disable smram region if smm is disabled

PATCH In review Anthony Xu 2 participants 5 messages May 16, 2017 – May 18, 2017

lore
Share & tools
lore

Anthony Xu

author
#0 lore raw

PATCH 1/1 SMM: disable smram region if smm is disabled

when smm is disabled, smram is not used, so disable it

---
 hw/pci-host/piix.c | 45 +++++++++++++++--------------
 hw/pci-host/q35.c  | 83 +++++++++++++++++++++++++++++-------------------------
 kvm-all.c          |  3 +-
 target/i386/kvm.c  |  2 +-
 4 files changed, 70 insertions(+), 63 deletions(-)
hw/pci-host/piix.c +24 -21
index bf4221d..ce43f87 100644
@@ -142,10 +142,12 @@ static void i440fx_update_memory_mappings(PCII440FXState *d)
         pam_update(&d->pam_regions[i], i,
                    pd->config[I440FX_PAM + ((i + 1) / 2)]);
     }
-    memory_region_set_enabled(&d->smram_region,
-                              !(pd->config[I440FX_SMRAM] & SMRAM_D_OPEN));
-    memory_region_set_enabled(&d->smram,
-                              pd->config[I440FX_SMRAM] & SMRAM_G_SMRAME);
+    if (pc_machine_is_smm_enabled(PC_MACHINE(current_machine))) {
+        memory_region_set_enabled(&d->smram_region,
+                !(pd->config[I440FX_SMRAM] & SMRAM_D_OPEN));
+        memory_region_set_enabled(&d->smram,
+                pd->config[I440FX_SMRAM] & SMRAM_G_SMRAME);
+    }
     memory_region_transaction_commit();
 }
 
@@ -355,23 +357,24 @@ PCIBus *i440fx_init(const char *host_type, const char *pci_type,
     pc_pci_as_mapping_init(OBJECT(f), f->system_memory,
                            f->pci_address_space);
 
-    /* if *disabled* show SMRAM to all CPUs */
-    memory_region_init_alias(&f->smram_region, OBJECT(d), "smram-region",
-                             f->pci_address_space, 0xa0000, 0x20000);
-    memory_region_add_subregion_overlap(f->system_memory, 0xa0000,
-                                        &f->smram_region, 1);
-    memory_region_set_enabled(&f->smram_region, true);
-
-    /* smram, as seen by SMM CPUs */
-    memory_region_init(&f->smram, OBJECT(d), "smram", 1ull << 32);
-    memory_region_set_enabled(&f->smram, true);
-    memory_region_init_alias(&f->low_smram, OBJECT(d), "smram-low",
-                             f->ram_memory, 0xa0000, 0x20000);
-    memory_region_set_enabled(&f->low_smram, true);
-    memory_region_add_subregion(&f->smram, 0xa0000, &f->low_smram);
-    object_property_add_const_link(qdev_get_machine(), "smram",
-                                   OBJECT(&f->smram), &error_abort);
-
+    if (pc_machine_is_smm_enabled(PC_MACHINE(current_machine))) {
+        /* if *disabled* show SMRAM to all CPUs */
+        memory_region_init_alias(&f->smram_region, OBJECT(d), "smram-region",
+                f->pci_address_space, 0xa0000, 0x20000);
+        memory_region_add_subregion_overlap(f->system_memory, 0xa0000,
+                &f->smram_region, 1);
+        memory_region_set_enabled(&f->smram_region, true);
+
+        /* smram, as seen by SMM CPUs */
+        memory_region_init(&f->smram, OBJECT(d), "smram", 1ull << 32);
+        memory_region_set_enabled(&f->smram, true);
+        memory_region_init_alias(&f->low_smram, OBJECT(d), "smram-low",
+                f->ram_memory, 0xa0000, 0x20000);
+        memory_region_set_enabled(&f->low_smram, true);
+        memory_region_add_subregion(&f->smram, 0xa0000, &f->low_smram);
+        object_property_add_const_link(qdev_get_machine(), "smram",
+                OBJECT(&f->smram), &error_abort);
+    }
     init_pam(dev, f->ram_memory, f->system_memory, f->pci_address_space,
              &f->pam_regions[0], PAM_BIOS_BASE, PAM_BIOS_SIZE);
     for (i = 0; i < 12; ++i) {
hw/pci-host/q35.c +44 -39

96 lines not on this page · raw message

kvm-all.c +1 -2
index 90b8573..1250fff 100644
@@ -1583,6 +1583,7 @@ static int kvm_init(MachineState *ms)
     const char *kvm_type;
 
     s = KVM_STATE(ms->accelerator);
+    kvm_state = s;
 
     /*
      * On systems where the kernel can support different base page
@@ -1755,8 +1756,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;
target/i386/kvm.c +1 -1
index 55865db..65716b6 100644
@@ -1254,7 +1254,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
         }
     }
 
-    if (kvm_check_extension(s, KVM_CAP_X86_SMM)) {
+    if (pc_machine_is_smm_enabled(PC_MACHINE(ms))) {
         smram_machine_done.notify = register_smram_listener;
         qemu_add_machine_init_done_notifier(&smram_machine_done);
     }
Signature · 1 line
1.8.3.1
#2 lore raw
Quoted 6 lines · Anthony Xu
Quoted 3 lines

when smm is disabled, smram is not used, so disable it

What is the benefit?

This patch removes 1 memory region for i440 platform and 3 memory regions for q35 platform. That makes functions which iterates memory region tree a little bit fast even the memory regions are disabled.

Anthony

#3 lore raw
Quoted 10 lines · Anthony
Quoted 6 lines · Anthony Xu
Quoted 3 lines

when smm is disabled, smram is not used, so disable it

What is the benefit?

This patch removes 1 memory region for i440 platform and 3 memory regions for q35 platform. That makes functions which iterates memory region tree a little bit fast even the memory regions are disabled.

Does it translate to anything measurable in benchmarks? Could you leave the regions there, but skip the creation of the SMRAM address space in register_smram_listener when the machine doesn't have SMM enabled?

Paolo

#4 lore raw
Quoted 6 lines · Anthony
Quoted 5 lines
Quoted 5 lines · Anthony Xu
Quoted 3 lines

when smm is disabled, smram is not used, so disable it

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

What is the benefit?

This patch removes 1 memory region for i440 platform and 3 memory

regions

Quoted 2 lines

for q35 platform. That makes functions which iterates memory region tree a little bit fast even the memory regions are disabled.

Does it translate to anything measurable in benchmarks?

Yes , we see boot time improvement with this patch in our setup (skip guest BIOS, disable guest PAM).

Quoted 3 lines

Could you leave
the regions there, but skip the creation of the SMRAM address space in register_smram_listener when the machine doesn't have SMM enabled?

Sounds like you have concerns on removing smram regions. What are your concerns?

-Anthony