From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YtIcN-0002Oo-4u for qemu-devel@nongnu.org; Fri, 15 May 2015 12:37:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YtIcJ-000186-7V for qemu-devel@nongnu.org; Fri, 15 May 2015 12:37:47 -0400 Received: from mail-wi0-x22b.google.com ([2a00:1450:400c:c05::22b]:36294) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YtIcJ-00017r-13 for qemu-devel@nongnu.org; Fri, 15 May 2015 12:37:43 -0400 Received: by wizk4 with SMTP id k4so294140397wiz.1 for ; Fri, 15 May 2015 09:37:42 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 15 May 2015 18:37:02 +0200 Message-Id: <1431707823-51230-7-git-send-email-pbonzini@redhat.com> In-Reply-To: <1431707823-51230-1-git-send-email-pbonzini@redhat.com> References: <1431707823-51230-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 6/7] i386: disable the region in /machine/smram when SMRAM is open List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, lersek@redhat.com, avi.kivity@gmail.com, kraxel@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 --- 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