* [PATCH] KVM/PPC Patch for KVM issue in real mode
@ 2016-11-29 12:09 ` Balbir Singh
0 siblings, 0 replies; 4+ messages in thread
From: Balbir Singh @ 2016-11-29 12:09 UTC (permalink / raw)
To: kvm, kvm-ppc; +Cc: Paul Mackerras, Paolo Bonzini, Radim K
Some KVM functions for book3s_hv are called in real mode.
In real mode the top 4 bits of the address space are ignored,
hence an address beginning with 0xc0000000+offset is the
same as 0xd0000000+offset. The issue was observed when
a kvm memslot resolution lead to random values when
accessed from kvmppc_h_enter(). The issue is hit if the
KVM host is running with a page size of 4K, since
kvzalloc() looks at size < PAGE_SIZE. On systems with
64K the issue is not observed easily, it largely depends
on the size of the structure being allocated.
The proposed fix moves all KVM allocations for book3s_hv
to kzalloc() until all structures used in real mode are
audited. For safety allocations are moved to kmalloc
space. The impact is a large allocation on systems with
4K page size.
Signed-off-by: Balbir Singh <bsingharora@gmail.com>
---
arch/powerpc/include/asm/kvm_host.h | 18 ++++++++++++++++++
include/linux/kvm_host.h | 11 +++++++++++
virt/kvm/kvm_main.c | 2 +-
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index f15713a..efcdc1d 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -733,6 +733,24 @@ struct kvm_vcpu_arch {
#define __KVM_HAVE_ARCH_WQP
#define __KVM_HAVE_CREATE_DEVICE
+#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
+#define __KVM_HAVE_ARCH_VZALLOC_OVERRIDE
+#endif
+
+/*
+ * KVM uses some of these data structures -- the ones
+ * from kvzalloc() in real mode. If the data structure
+ * happens to come from a vmalloc'd range then its access
+ * in real mode will lead to problems due to the aliasing
+ * issue - (top 4 bits are ignore).
+ * A 0xd000+offset will point to a 0xc000+offset in realmode
+ * Hence we want our data structures from come from kmalloc'd
+ * regions, so that we don't have these aliasing issues
+ */
+static inline void *kvm_arch_vzalloc(unsigned long size)
+{
+ return kzalloc(size, GFP_KERNEL);
+}
static inline void kvm_arch_hardware_disable(void) {}
static inline void kvm_arch_hardware_unsetup(void) {}
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 01c0b9c..0c88af5 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -19,6 +19,7 @@
#include <linux/preempt.h>
#include <linux/msi.h>
#include <linux/slab.h>
+#include <linux/vmalloc.h>
#include <linux/rcupdate.h>
#include <linux/ratelimit.h>
#include <linux/err.h>
@@ -793,6 +794,16 @@ static inline bool kvm_arch_has_noncoherent_dma(struct kvm *kvm)
return false;
}
#endif
+
+#ifdef __KVM_HAVE_ARCH_VZALLOC_OVERRIDE
+static void *kvm_arch_vzalloc(unsigned long size);
+#else
+static inline void *kvm_arch_vzalloc(unsigned long size)
+{
+ return vzalloc(size);
+}
+#endif
+
#ifdef __KVM_HAVE_ARCH_ASSIGNED_DEVICE
void kvm_arch_start_assignment(struct kvm *kvm);
void kvm_arch_end_assignment(struct kvm *kvm);
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index fbf04c0..57e3dca 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -689,7 +689,7 @@ static struct kvm *kvm_create_vm(unsigned long type)
void *kvm_kvzalloc(unsigned long size)
{
if (size > PAGE_SIZE)
- return vzalloc(size);
+ return kvm_arch_vzalloc(size);
else
return kzalloc(size, GFP_KERNEL);
}
--
2.5.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] KVM/PPC Patch for KVM issue in real mode
@ 2016-11-29 12:09 ` Balbir Singh
0 siblings, 0 replies; 4+ messages in thread
From: Balbir Singh @ 2016-11-29 12:09 UTC (permalink / raw)
To: kvm, kvm-ppc; +Cc: Paul Mackerras, Paolo Bonzini, Radim K
Some KVM functions for book3s_hv are called in real mode.
In real mode the top 4 bits of the address space are ignored,
hence an address beginning with 0xc0000000+offset is the
same as 0xd0000000+offset. The issue was observed when
a kvm memslot resolution lead to random values when
accessed from kvmppc_h_enter(). The issue is hit if the
KVM host is running with a page size of 4K, since
kvzalloc() looks at size < PAGE_SIZE. On systems with
64K the issue is not observed easily, it largely depends
on the size of the structure being allocated.
The proposed fix moves all KVM allocations for book3s_hv
to kzalloc() until all structures used in real mode are
audited. For safety allocations are moved to kmalloc
space. The impact is a large allocation on systems with
4K page size.
Signed-off-by: Balbir Singh <bsingharora@gmail.com>
---
arch/powerpc/include/asm/kvm_host.h | 18 ++++++++++++++++++
include/linux/kvm_host.h | 11 +++++++++++
virt/kvm/kvm_main.c | 2 +-
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index f15713a..efcdc1d 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -733,6 +733,24 @@ struct kvm_vcpu_arch {
#define __KVM_HAVE_ARCH_WQP
#define __KVM_HAVE_CREATE_DEVICE
+#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
+#define __KVM_HAVE_ARCH_VZALLOC_OVERRIDE
+#endif
+
+/*
+ * KVM uses some of these data structures -- the ones
+ * from kvzalloc() in real mode. If the data structure
+ * happens to come from a vmalloc'd range then its access
+ * in real mode will lead to problems due to the aliasing
+ * issue - (top 4 bits are ignore).
+ * A 0xd000+offset will point to a 0xc000+offset in realmode
+ * Hence we want our data structures from come from kmalloc'd
+ * regions, so that we don't have these aliasing issues
+ */
+static inline void *kvm_arch_vzalloc(unsigned long size)
+{
+ return kzalloc(size, GFP_KERNEL);
+}
static inline void kvm_arch_hardware_disable(void) {}
static inline void kvm_arch_hardware_unsetup(void) {}
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 01c0b9c..0c88af5 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -19,6 +19,7 @@
#include <linux/preempt.h>
#include <linux/msi.h>
#include <linux/slab.h>
+#include <linux/vmalloc.h>
#include <linux/rcupdate.h>
#include <linux/ratelimit.h>
#include <linux/err.h>
@@ -793,6 +794,16 @@ static inline bool kvm_arch_has_noncoherent_dma(struct kvm *kvm)
return false;
}
#endif
+
+#ifdef __KVM_HAVE_ARCH_VZALLOC_OVERRIDE
+static void *kvm_arch_vzalloc(unsigned long size);
+#else
+static inline void *kvm_arch_vzalloc(unsigned long size)
+{
+ return vzalloc(size);
+}
+#endif
+
#ifdef __KVM_HAVE_ARCH_ASSIGNED_DEVICE
void kvm_arch_start_assignment(struct kvm *kvm);
void kvm_arch_end_assignment(struct kvm *kvm);
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index fbf04c0..57e3dca 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -689,7 +689,7 @@ static struct kvm *kvm_create_vm(unsigned long type)
void *kvm_kvzalloc(unsigned long size)
{
if (size > PAGE_SIZE)
- return vzalloc(size);
+ return kvm_arch_vzalloc(size);
else
return kzalloc(size, GFP_KERNEL);
}
--
2.5.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] KVM/PPC Patch for KVM issue in real mode
2016-11-29 12:09 ` Balbir Singh
@ 2016-11-29 19:16 ` kbuild test robot
-1 siblings, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2016-11-29 19:16 UTC (permalink / raw)
To: Balbir Singh
Cc: kbuild-all, kvm, kvm-ppc, Paul Mackerras, Paolo Bonzini, Radim K
[-- Attachment #1: Type: text/plain, Size: 1965 bytes --]
Hi Balbir,
[auto build test ERROR on kvm/linux-next]
[also build test ERROR on v4.9-rc7 next-20161129]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Balbir-Singh/KVM-PPC-Patch-for-KVM-issue-in-real-mode/20161129-233307
base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git linux-next
config: powerpc-ppa8548_defconfig (attached as .config)
compiler: powerpc-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=powerpc
All errors (new ones prefixed by >>):
In file included from arch/powerpc/include/asm/kvm_ppc.h:30:0,
from arch/powerpc/kernel/dbell.c:20:
>> include/linux/kvm_host.h:807:21: error: redefinition of 'kvm_arch_vzalloc'
static inline void *kvm_arch_vzalloc(unsigned long size)
^~~~~~~~~~~~~~~~
In file included from include/linux/kvm_host.h:37:0,
from arch/powerpc/include/asm/kvm_ppc.h:30,
from arch/powerpc/kernel/dbell.c:20:
arch/powerpc/include/asm/kvm_host.h:725:21: note: previous definition of 'kvm_arch_vzalloc' was here
static inline void *kvm_arch_vzalloc(unsigned long size)
^~~~~~~~~~~~~~~~
vim +/kvm_arch_vzalloc +807 include/linux/kvm_host.h
801 }
802 #endif
803
804 #ifdef __KVM_HAVE_ARCH_VZALLOC_OVERRIDE
805 static void *kvm_arch_vzalloc(unsigned long size);
806 #else
> 807 static inline void *kvm_arch_vzalloc(unsigned long size)
808 {
809 return vzalloc(size);
810 }
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 12778 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] KVM/PPC Patch for KVM issue in real mode
@ 2016-11-29 19:16 ` kbuild test robot
0 siblings, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2016-11-29 19:16 UTC (permalink / raw)
To: kvm-ppc
[-- Attachment #1: Type: text/plain, Size: 1965 bytes --]
Hi Balbir,
[auto build test ERROR on kvm/linux-next]
[also build test ERROR on v4.9-rc7 next-20161129]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Balbir-Singh/KVM-PPC-Patch-for-KVM-issue-in-real-mode/20161129-233307
base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git linux-next
config: powerpc-ppa8548_defconfig (attached as .config)
compiler: powerpc-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=powerpc
All errors (new ones prefixed by >>):
In file included from arch/powerpc/include/asm/kvm_ppc.h:30:0,
from arch/powerpc/kernel/dbell.c:20:
>> include/linux/kvm_host.h:807:21: error: redefinition of 'kvm_arch_vzalloc'
static inline void *kvm_arch_vzalloc(unsigned long size)
^~~~~~~~~~~~~~~~
In file included from include/linux/kvm_host.h:37:0,
from arch/powerpc/include/asm/kvm_ppc.h:30,
from arch/powerpc/kernel/dbell.c:20:
arch/powerpc/include/asm/kvm_host.h:725:21: note: previous definition of 'kvm_arch_vzalloc' was here
static inline void *kvm_arch_vzalloc(unsigned long size)
^~~~~~~~~~~~~~~~
vim +/kvm_arch_vzalloc +807 include/linux/kvm_host.h
801 }
802 #endif
803
804 #ifdef __KVM_HAVE_ARCH_VZALLOC_OVERRIDE
805 static void *kvm_arch_vzalloc(unsigned long size);
806 #else
> 807 static inline void *kvm_arch_vzalloc(unsigned long size)
808 {
809 return vzalloc(size);
810 }
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 12778 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-11-29 19:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-29 12:09 [PATCH] KVM/PPC Patch for KVM issue in real mode Balbir Singh
2016-11-29 12:09 ` Balbir Singh
2016-11-29 19:16 ` kbuild test robot
2016-11-29 19:16 ` kbuild test robot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.