qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, lersek@redhat.com,
	avi.kivity@gmail.com, kraxel@redhat.com
Subject: [Qemu-devel] [PATCH 6/7] i386: disable the region in /machine/smram when SMRAM is open
Date: Fri, 15 May 2015 18:37:02 +0200	[thread overview]
Message-ID: <1431707823-51230-7-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1431707823-51230-1-git-send-email-pbonzini@redhat.com>

This patch provides some help from the chipset in handling SMRAM.

SMRAM regions can overlap with e.g. PCI BARs.  When this happens, PCI
BARs will be hidden behind SMRAM and will cause a userspace MMIO exit.
This can be achieved easily with KVM just by giving a higher priority
to the SMRAM region.  The SMRAM region is changed to a KVM_MEM_X86_SMRAM
memory slot and causes a MMIO exit when outside SMM.

Unfortunately, when SMRAM is open, the SMRAM region in system memory
would be treated like a PCI BAR and would be hidden behind SMRAM.  In
order to avoid this, disable the region in /machine/smram when SMRAM
is open.  Then the KVM address space will include the SMRAM region
through system memory (thus without the flag) rather than through
/machine/smram.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/pci-host/piix.c |  6 ++++++
 hw/pci-host/q35.c  | 20 +++++++++++++-------
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index 3f23851..ee8a680 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -142,6 +142,12 @@ static void i440fx_update_memory_mappings(PCII440FXState *d)
                               !(pd->config[I440FX_SMRAM] & SMRAM_D_OPEN));
     memory_region_set_enabled(&d->smram,
                               pd->config[I440FX_SMRAM] & SMRAM_G_SMRAME);
+
+    /* KVM requires disabling the region in /machine/smram when SMRAM
+     * is open.
+     */
+    memory_region_set_enabled(&d->low_smram,
+                              !(pd->config[I440FX_SMRAM] & SMRAM_D_OPEN));
     memory_region_transaction_commit();
 }
 
diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c
index 60a9f2c..3a016fa 100644
--- a/hw/pci-host/q35.c
+++ b/hw/pci-host/q35.c
@@ -305,18 +305,24 @@ static void mch_update_smram(MCHPCIState *mch)
         memory_region_set_enabled(&mch->smram_region, h_smrame);
         /* Show high SMRAM if H_SMRAME = 1 */
         memory_region_set_enabled(&mch->open_high_smram, h_smrame);
+
+        /* KVM requires disabling the region in /machine/smram when SMRAM
+         * is open.
+         */
+        memory_region_set_enabled(&mch->low_smram, false);
+        memory_region_set_enabled(&mch->high_smram, false);
     } else {
         /* Hide high SMRAM and low SMRAM */
         memory_region_set_enabled(&mch->smram_region, true);
         memory_region_set_enabled(&mch->open_high_smram, false);
-    }
 
-    if (pd->config[MCH_HOST_BRIDGE_SMRAM] & SMRAM_G_SMRAME) {
-        memory_region_set_enabled(&mch->low_smram, !h_smrame);
-        memory_region_set_enabled(&mch->high_smram, h_smrame);
-    } else {
-        memory_region_set_enabled(&mch->low_smram, false);
-        memory_region_set_enabled(&mch->high_smram, false);
+        if (pd->config[MCH_HOST_BRIDGE_SMRAM] & SMRAM_G_SMRAME) {
+            memory_region_set_enabled(&mch->low_smram, !h_smrame);
+            memory_region_set_enabled(&mch->high_smram, h_smrame);
+        } else {
+            memory_region_set_enabled(&mch->low_smram, false);
+            memory_region_set_enabled(&mch->high_smram, false);
+        }
     }
 
     if (pd->config[MCH_HOST_BRIDGE_ESMRAMC] & MCH_HOST_BRIDGE_ESMRAMC_T_EN) {
-- 
1.8.3.1

  parent reply	other threads:[~2015-05-15 16:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-15 16:36 [Qemu-devel] [RFC PATCH 0/7] x86: SMRAM implementation for KVM Paolo Bonzini
2015-05-15 16:36 ` [Qemu-devel] [PATCH 1/7] kvm-all: put kvm_mem_flags to more work Paolo Bonzini
2015-05-15 16:36 ` [Qemu-devel] [PATCH 2/7] kvm-all: remove useless typedef Paolo Bonzini
2015-05-15 16:36 ` [Qemu-devel] [PATCH 3/7] kvm-all: move KVMState definitions to kvm_int.h Paolo Bonzini
2015-05-15 16:37 ` [Qemu-devel] [PATCH 4/7] kvm-all: add KVM address space Paolo Bonzini
2015-05-15 16:37 ` [Qemu-devel] [PATCH 5/7] memory: add kvm_mem_flags to MemoryRegion Paolo Bonzini
2015-05-15 16:37 ` Paolo Bonzini [this message]
2015-05-15 16:37 ` [Qemu-devel] [PATCH 7/7] kvm-i386: register SMRAM regions with KVM_MEM_X86_SMRAM 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=1431707823-51230-7-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=avi.kivity@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=lersek@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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).