[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1466562866-31524-1-git-send-email-karahmed@amazon.de>
Date: Wed, 22 Jun 2016 04:34:26 +0200
From: KarimAllah Ahmed <karahmed@...zon.de>
To: linux-kernel@...r.kernel.org, kvm@...r.kernel.org, x86@...nel.org
Cc: KarimAllah Ahmed <karahmed@...zon.de>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
"H . Peter Anvin" <hpa@...or.com>,
Paolo Bonzini <pbonzini@...hat.com>,
Radim Krčmář <rkrcmar@...hat.com>,
Borislav Petkov <bp@...e.de>,
Denys Vlasenko <dvlasenk@...hat.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Toshi Kani <toshi.kani@....com>,
Tony Luck <tony.luck@...el.com>
Subject: [PATCH] kvm, x86: Properly check whether a pfn is an MMIO or not
pfn_valid check is not sufficient because it only checks if a page has a struct
page or not, if for example "mem=" was passed to the kernel some valid pages
won't have a struct page. This means that if guests were assigned valid memory
that lies after the mem= boundary it will be passed uncached to the guest no
matter what the guest caching attributes are for this memory.
Use the original e820 map to check whether a certain pfn belongs to RAM or not.
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Ingo Molnar <mingo@...hat.com>
Cc: H. Peter Anvin <hpa@...or.com>
Cc: Paolo Bonzini <pbonzini@...hat.com>
Cc: Radim Krčmář <rkrcmar@...hat.com>
Cc: Borislav Petkov <bp@...e.de>
Cc: Denys Vlasenko <dvlasenk@...hat.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Toshi Kani <toshi.kani@....com>
Cc: Tony Luck <tony.luck@...el.com>
Cc: linux-kernel@...r.kernel.org
Cc: kvm@...r.kernel.org
Cc: x86@...nel.org
Signed-off-by: KarimAllah Ahmed <karahmed@...zon.de>
---
arch/x86/include/asm/e820.h | 1 +
arch/x86/kernel/e820.c | 18 ++++++++++++++++++
arch/x86/kvm/mmu.c | 2 +-
3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
index 3ab0537..2d4f7d8 100644
--- a/arch/x86/include/asm/e820.h
+++ b/arch/x86/include/asm/e820.h
@@ -16,6 +16,7 @@ extern struct e820map e820_saved;
extern unsigned long pci_mem_start;
extern int e820_any_mapped(u64 start, u64 end, unsigned type);
extern int e820_all_mapped(u64 start, u64 end, unsigned type);
+extern bool e820_is_ram(u64 addr);
extern void e820_add_region(u64 start, u64 size, int type);
extern void e820_print_map(char *who);
extern int
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 621b501..387cdba 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -105,6 +105,24 @@ int __init e820_all_mapped(u64 start, u64 end, unsigned type)
return 0;
}
+bool
+e820_is_ram(u64 addr)
+{
+ int i;
+
+ for (i = 0; i < e820_saved.nr_map; i++) {
+ struct e820entry *ei = &e820_saved.map[i];
+
+ if (ei->type != E820_RAM)
+ continue;
+ if ((addr >= ei->addr) && (addr < (ei->addr + ei->size)))
+ return true;
+ }
+
+ return false;
+}
+EXPORT_SYMBOL_GPL(e820_is_ram);
+
/*
* Add a memory region to the kernel e820 map.
*/
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 24e8001..5e07bf5 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -2507,7 +2507,7 @@ static bool kvm_is_mmio_pfn(kvm_pfn_t pfn)
if (pfn_valid(pfn))
return !is_zero_pfn(pfn) && PageReserved(pfn_to_page(pfn));
- return true;
+ return !e820_is_ram(pfn << PAGE_SHIFT);
}
static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
--
2.8.2
Powered by blists - more mailing lists