[Bug 53611] nVMX: Add nested EPT
https://bugzilla.kernel.org/show_bug.cgi?id=53611 --- Comment #1 from Nadav Har'El n...@math.technion.ac.il 2013-02-27 08:14:13 --- In addition to the known issues list in the announce file attached above, I thought of several more issues that should be considered: 1. When switching back and forth between L1 and L2 it will be a waste to throw away the EPT table already built. So I hope (need to check...) that the EPT table is cached. But what is the cache key - the cr3? But cr3 has a different meaning in L2 and L1, so it might not be correct to use that as the key. 2. When L0 swaps out pages, it needs to remove these entries in all EPT tables, including the cached EPT02 even if not currently used. Does this happen correctly? 3. If L1 uses EPT (nested EPT) and gives us a malformed EPT12 table, we may need to inject an EPT_MISCONFIGURATION exit when building the merged EPT02 entry. Typically, we do this building (see fetch in paging_tmpl.h) when handling an EPT violation exit from L2, so if we encounter this problem instead of reentering L2 immediately, we should exit to L1 with an EPT misconfigration. I'm not sure exactly how to notice this problem. Perhaps the pagetable walking code, which in our case walks EPT12 already notices a problem and does something (#GP perhaps?) and we need to have it do the EPT misconfig instead. But it is possible we need to add additional tests that are not done for normal page tables - in particularly regarding reserved bits, and especially bit 5 (in EPT it is reserved, in normal page tables it is the accessed bit). This issue is low priority, as it only deals with the error path; A well-written L1 will not caused EPT configurations anyway. -- Configure bugmail: https://bugzilla.kernel.org/userprefs.cgi?tab=email --- You are receiving this mail because: --- You are watching the assignee of the bug. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] target-i386: Improve x86_cpu_list output
On Wed, 27 Feb 2013 08:52:50 +0100 Jan Kiszka jan.kis...@web.de wrote: On 2013-02-27 08:37, Igor Mammedov wrote: On Wed, 27 Feb 2013 00:26:38 -0300 Eduardo Habkost ehabk...@redhat.com wrote: On Tue, Feb 26, 2013 at 10:57:56PM +0100, Igor Mammedov wrote: On Sat, 23 Feb 2013 16:45:00 +0100 Jan Kiszka jan.kis...@web.de wrote: From: Jan Kiszka jan.kis...@siemens.com Several issues fixed: - We were missing a bunch of feature lists. Fix this by simply dumping the meta list feature_word_info. - kvm_enabled() cannot be true at this point because accelerators are initialized much later during init. Simply dump unconditionally. Why not to move list_cpu after accelerators are initialized? Because help output is simply documentation and shouldn't depend on any other config option parsing or accelerator initialization at all? Don't see reason why it shouldn't. It's not a man page but a program and can do pretty much everything. Actually, requiring -enable-kvm -cpu ? to list the host type would be counterproductive - hardly any user will find this out, at best by chance. However ... - Add explanation for host CPU type. Signed-off-by: Jan Kiszka jan.kis...@siemens.com --- target-i386/cpu.c | 20 +--- 1 files changed, 9 insertions(+), 11 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index dfcf86e..6e742f0 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1453,18 +1453,16 @@ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf) snprintf(buf, sizeof(buf), %s, def-name); (*cpu_fprintf)(f, x86 %16s %-48s\n, buf, def-model_id); } -if (kvm_enabled()) { -(*cpu_fprintf)(f, x86 %16s\n, [host]); -} +(*cpu_fprintf)(f, x86 %16s %-48s\n, host, + KVM processor with all supported host features); + that would make 'host' visible to users even if QEMU compiled without KVM support. No big harm, but autotest could get confused when it gets 'host' CPU but QEMU doesn't run because it's not really supported. Then we have to fix the autotest test code to not try it without KVM. :-) Help output is not a probing mechanism (although we often misuse it as if it were), and I expect help output to be static and not depend on any subsystem initialization. Then fix help output and add to host line something like is available with -enable-kvm on command line and if your build was compiled --enable-kvm configure option, otherwise 'host' is misleading. Now even without 'host' in output of -cpu 'help', question why 'host' is not found periodically pops up on IRC. This change will just increase frequency of it. ...I will add (only available in KVM mode) here and wrap these lines in #ifdef CONFIG_KVM. That should be more acceptable, no? yes, it will be better. Jan -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2] target-i386: Improve x86_cpu_list output
Several issues fixed: - We were missing a bunch of feature lists. Fix this by simply dumping the meta list feature_word_info. - kvm_enabled() cannot be true at this point because accelerators are initialized much later during init. Also, hiding this makes it very hard to discover for users. Simply dump unconditionally if CONFIG_KVM is set. - Add explanation for host CPU type. Signed-off-by: Jan Kiszka jan.kis...@siemens.com --- Changes in v2: - Do not dump host type if CONFIG_KVM is not set - Explain that host depends on KVM mode target-i386/cpu.c | 23 --- 1 files changed, 12 insertions(+), 11 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 5582e5f..b4189c3 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1463,18 +1463,19 @@ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf) snprintf(buf, sizeof(buf), %s, def-name); (*cpu_fprintf)(f, x86 %16s %-48s\n, buf, def-model_id); } -if (kvm_enabled()) { -(*cpu_fprintf)(f, x86 %16s\n, [host]); -} +#ifdef CONFIG_KVM +(*cpu_fprintf)(f, x86 %16s %-48s\n, host, + KVM processor with all supported host features + (only available in KVM mode)); +#endif + (*cpu_fprintf)(f, \nRecognized CPUID flags:\n); -listflags(buf, sizeof(buf), (uint32_t)~0, feature_name, 1); -(*cpu_fprintf)(f, %s\n, buf); -listflags(buf, sizeof(buf), (uint32_t)~0, ext_feature_name, 1); -(*cpu_fprintf)(f, %s\n, buf); -listflags(buf, sizeof(buf), (uint32_t)~0, ext2_feature_name, 1); -(*cpu_fprintf)(f, %s\n, buf); -listflags(buf, sizeof(buf), (uint32_t)~0, ext3_feature_name, 1); -(*cpu_fprintf)(f, %s\n, buf); +for (i = 0; i ARRAY_SIZE(feature_word_info); i++) { +FeatureWordInfo *fw = feature_word_info[i]; + +listflags(buf, sizeof(buf), (uint32_t)~0, fw-feat_names, 1); +(*cpu_fprintf)(f, %s\n, buf); +} } CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) -- 1.7.3.4 -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [Qemu-devel] [PATCH v2] target-i386: Improve x86_cpu_list output
On Wed, 27 Feb 2013 10:15:51 +0100 Jan Kiszka jan.kis...@siemens.com wrote: Several issues fixed: - We were missing a bunch of feature lists. Fix this by simply dumping the meta list feature_word_info. - kvm_enabled() cannot be true at this point because accelerators are initialized much later during init. Also, hiding this makes it very hard to discover for users. Simply dump unconditionally if CONFIG_KVM is set. - Add explanation for host CPU type. Signed-off-by: Jan Kiszka jan.kis...@siemens.com Reviewed-By: Igor Mammedov imamm...@redhat.com --- Changes in v2: - Do not dump host type if CONFIG_KVM is not set - Explain that host depends on KVM mode target-i386/cpu.c | 23 --- 1 files changed, 12 insertions(+), 11 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 5582e5f..b4189c3 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1463,18 +1463,19 @@ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf) snprintf(buf, sizeof(buf), %s, def-name); (*cpu_fprintf)(f, x86 %16s %-48s\n, buf, def-model_id); } -if (kvm_enabled()) { -(*cpu_fprintf)(f, x86 %16s\n, [host]); -} +#ifdef CONFIG_KVM +(*cpu_fprintf)(f, x86 %16s %-48s\n, host, + KVM processor with all supported host features + (only available in KVM mode)); +#endif + (*cpu_fprintf)(f, \nRecognized CPUID flags:\n); -listflags(buf, sizeof(buf), (uint32_t)~0, feature_name, 1); -(*cpu_fprintf)(f, %s\n, buf); -listflags(buf, sizeof(buf), (uint32_t)~0, ext_feature_name, 1); -(*cpu_fprintf)(f, %s\n, buf); -listflags(buf, sizeof(buf), (uint32_t)~0, ext2_feature_name, 1); -(*cpu_fprintf)(f, %s\n, buf); -listflags(buf, sizeof(buf), (uint32_t)~0, ext3_feature_name, 1); -(*cpu_fprintf)(f, %s\n, buf); +for (i = 0; i ARRAY_SIZE(feature_word_info); i++) { +FeatureWordInfo *fw = feature_word_info[i]; + +listflags(buf, sizeof(buf), (uint32_t)~0, fw-feat_names, 1); +(*cpu_fprintf)(f, %s\n, buf); +} } CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2] target-i386: Improve x86_cpu_list output
Am 27.02.2013 10:15, schrieb Jan Kiszka: Several issues fixed: - We were missing a bunch of feature lists. Fix this by simply dumping the meta list feature_word_info. - kvm_enabled() cannot be true at this point because accelerators are initialized much later during init. Also, hiding this makes it very hard to discover for users. Simply dump unconditionally if CONFIG_KVM is set. - Add explanation for host CPU type. Signed-off-by: Jan Kiszka jan.kis...@siemens.com --- Changes in v2: - Do not dump host type if CONFIG_KVM is not set - Explain that host depends on KVM mode I had requested on v1 to not fix multiple issues in one patch, but I can split it myself on Friday if there's no other issues. Andreas target-i386/cpu.c | 23 --- 1 files changed, 12 insertions(+), 11 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 5582e5f..b4189c3 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1463,18 +1463,19 @@ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf) snprintf(buf, sizeof(buf), %s, def-name); (*cpu_fprintf)(f, x86 %16s %-48s\n, buf, def-model_id); } -if (kvm_enabled()) { -(*cpu_fprintf)(f, x86 %16s\n, [host]); -} +#ifdef CONFIG_KVM +(*cpu_fprintf)(f, x86 %16s %-48s\n, host, + KVM processor with all supported host features + (only available in KVM mode)); +#endif + (*cpu_fprintf)(f, \nRecognized CPUID flags:\n); -listflags(buf, sizeof(buf), (uint32_t)~0, feature_name, 1); -(*cpu_fprintf)(f, %s\n, buf); -listflags(buf, sizeof(buf), (uint32_t)~0, ext_feature_name, 1); -(*cpu_fprintf)(f, %s\n, buf); -listflags(buf, sizeof(buf), (uint32_t)~0, ext2_feature_name, 1); -(*cpu_fprintf)(f, %s\n, buf); -listflags(buf, sizeof(buf), (uint32_t)~0, ext3_feature_name, 1); -(*cpu_fprintf)(f, %s\n, buf); +for (i = 0; i ARRAY_SIZE(feature_word_info); i++) { +FeatureWordInfo *fw = feature_word_info[i]; + +listflags(buf, sizeof(buf), (uint32_t)~0, fw-feat_names, 1); +(*cpu_fprintf)(f, %s\n, buf); +} } CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) -- SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2] target-i386: Improve x86_cpu_list output
On 2013-02-27 10:33, Andreas Färber wrote: Am 27.02.2013 10:15, schrieb Jan Kiszka: Several issues fixed: - We were missing a bunch of feature lists. Fix this by simply dumping the meta list feature_word_info. - kvm_enabled() cannot be true at this point because accelerators are initialized much later during init. Also, hiding this makes it very hard to discover for users. Simply dump unconditionally if CONFIG_KVM is set. - Add explanation for host CPU type. Signed-off-by: Jan Kiszka jan.kis...@siemens.com --- Changes in v2: - Do not dump host type if CONFIG_KVM is not set - Explain that host depends on KVM mode I had requested on v1 to not fix multiple issues in one patch, but I can split it myself on Friday if there's no other issues. Sorry, missed that. But I also see no point in splitting up in this case, specifically as we no agree on the result. Jan -- Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: virtio-rng only returns zeros with CONFIG_HW_RANDOM=m
On Wed, Feb 27, 2013 at 10:43:37AM +1030, Rusty Russell wrote: Aurelien Jarno aurel...@aurel32.net writes: Hi, I have noticed that virtio-rng only returns zero for kernels = 2.6.33 built with CONFIG_HW_RANDOM=m. This is a bit much too predictable for a random generator ;-). Wow. Fortunately, all of SLES, RHEL, Ubuntu or Fedora set CONFIG_HW_RANDOM=y. What do they know that we don't? Oops, looks like Debian testing: config-3.2.0-4-amd64:CONFIG_HW_RANDOM=m The reason for that is virtio expects guest real addresses, while rng_core.ko (ie when built as a module) is passing a vmalloced buffer to the virtio-rng read function, declared as such: static u8 rng_buffer[SMP_CACHE_BYTES 32 ? 32 : SMP_CACHE_BYTES] __cacheline_aligned; Yuck... It would be nice if this has oopsed. Jens, what about this patch? Cheers, Rusty. Subject: scatterlist: sg_set_buf() argument must be in linear mapping. Signed-off-by: Rusty Russell ru...@rustcorp.com.au diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index 4bd6c06..9365375 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -111,6 +111,9 @@ static inline struct page *sg_page(struct scatterlist *sg) static inline void sg_set_buf(struct scatterlist *sg, const void *buf, unsigned int buflen) { +#ifdef CONFIG_DEBUG_SG + BUG_ON(!virt_addr_valid(buf)); +#endif sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf)); } I confirm this patch catches the issue. Thanks. Tested-by: Aurelien Jarno aurel...@aurel32.net -- Aurelien Jarno GPG: 1024D/F1BCDB73 aurel...@aurel32.net http://www.aurel32.net -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 0/6] KVM: Clean up and optimize set_memory_region() - part2
Note: this is based on the latest master branch. I'm sending this before 3.9-rc1 is released since this can cause extra conflicts unless we make this available to all arch before we start adding new stuff. Please review: every change is trivial and should not change anything. Takuya Yoshikawa (6): KVM: set_memory_region: Drop user_alloc from prepare/commit_memory_region() KVM: set_memory_region: Drop user_alloc from set_memory_region() KVM: set_memory_region: Make kvm_mr_change available to arch code KVM: set_memory_region: Refactor prepare_memory_region() KVM: set_memory_region: Refactor commit_memory_region() KVM: ARM: Remove kvm_arch_set_memory_region() arch/arm/kvm/arm.c | 15 ++-- arch/ia64/kvm/kvm-ia64.c | 25 ++--- arch/powerpc/include/asm/kvm_ppc.h |2 +- arch/powerpc/kvm/book3s_hv.c |4 +- arch/powerpc/kvm/book3s_pr.c |2 +- arch/powerpc/kvm/booke.c |2 +- arch/powerpc/kvm/powerpc.c | 13 +-- arch/s390/kvm/kvm-s390.c | 10 ++-- arch/x86/kvm/vmx.c |6 ++-- arch/x86/kvm/x86.c | 25 + include/linux/kvm_host.h | 35 +- virt/kvm/kvm_main.c| 40 --- 12 files changed, 67 insertions(+), 112 deletions(-) -- 1.7.4.1 -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/6] KVM: set_memory_region: Drop user_alloc from prepare/commit_memory_region()
X86 does not use this any more. The remaining user, s390's !user_alloc check, can be simply removed since KVM_SET_MEMORY_REGION ioctl is no longer supported. Note: fixed powerpc's indentations with spaces to suppress checkpatch errors. Signed-off-by: Takuya Yoshikawa yoshikawa_takuya...@lab.ntt.co.jp --- arch/arm/kvm/arm.c |6 ++ arch/ia64/kvm/kvm-ia64.c |6 ++ arch/powerpc/kvm/powerpc.c | 12 +--- arch/s390/kvm/kvm-s390.c |9 ++--- arch/x86/kvm/x86.c |6 ++ include/linux/kvm_host.h |6 ++ virt/kvm/kvm_main.c|4 ++-- 7 files changed, 17 insertions(+), 32 deletions(-) diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 5a93698..24cb5f6 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -231,16 +231,14 @@ int kvm_arch_set_memory_region(struct kvm *kvm, int kvm_arch_prepare_memory_region(struct kvm *kvm, struct kvm_memory_slot *memslot, struct kvm_memory_slot old, - struct kvm_userspace_memory_region *mem, - bool user_alloc) + struct kvm_userspace_memory_region *mem) { return 0; } void kvm_arch_commit_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem, - struct kvm_memory_slot old, - bool user_alloc) + struct kvm_memory_slot old) { } diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c index ad3126a..cbc5b04 100644 --- a/arch/ia64/kvm/kvm-ia64.c +++ b/arch/ia64/kvm/kvm-ia64.c @@ -1579,8 +1579,7 @@ int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages) int kvm_arch_prepare_memory_region(struct kvm *kvm, struct kvm_memory_slot *memslot, struct kvm_memory_slot old, - struct kvm_userspace_memory_region *mem, - bool user_alloc) + struct kvm_userspace_memory_region *mem) { unsigned long i; unsigned long pfn; @@ -1610,8 +1609,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, void kvm_arch_commit_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem, - struct kvm_memory_slot old, - bool user_alloc) + struct kvm_memory_slot old) { return; } diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 934413c..22b3315 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -411,18 +411,16 @@ int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages) } int kvm_arch_prepare_memory_region(struct kvm *kvm, - struct kvm_memory_slot *memslot, - struct kvm_memory_slot old, - struct kvm_userspace_memory_region *mem, - bool user_alloc) + struct kvm_memory_slot *memslot, + struct kvm_memory_slot old, + struct kvm_userspace_memory_region *mem) { return kvmppc_core_prepare_memory_region(kvm, memslot, mem); } void kvm_arch_commit_memory_region(struct kvm *kvm, - struct kvm_userspace_memory_region *mem, - struct kvm_memory_slot old, - bool user_alloc) + struct kvm_userspace_memory_region *mem, + struct kvm_memory_slot old) { kvmppc_core_commit_memory_region(kvm, mem, old); } diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 4cf35a0..07ac302 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -975,8 +975,7 @@ int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages) int kvm_arch_prepare_memory_region(struct kvm *kvm, struct kvm_memory_slot *memslot, struct kvm_memory_slot old, - struct kvm_userspace_memory_region *mem, - bool user_alloc) + struct kvm_userspace_memory_region *mem) { /* A few sanity checks. We can have exactly one memory slot which has to start at guest virtual zero and which has to be located at a @@ -997,16 +996,12 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, if (mem-memory_size 0xful) return -EINVAL; - if (!user_alloc) - return -EINVAL; - return 0; } void kvm_arch_commit_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem, - struct
[PATCH 2/6] KVM: set_memory_region: Drop user_alloc from set_memory_region()
Except ia64's stale code, KVM_SET_MEMORY_REGION support, this is only used for sanity checks in __kvm_set_memory_region() which can easily be changed to use slot id instead. Signed-off-by: Takuya Yoshikawa yoshikawa_takuya...@lab.ntt.co.jp --- arch/ia64/kvm/kvm-ia64.c | 18 -- arch/x86/kvm/vmx.c |6 +++--- include/linux/kvm_host.h | 10 +++--- virt/kvm/kvm_main.c | 18 +++--- 4 files changed, 13 insertions(+), 39 deletions(-) diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c index cbc5b04..43701f0 100644 --- a/arch/ia64/kvm/kvm-ia64.c +++ b/arch/ia64/kvm/kvm-ia64.c @@ -942,24 +942,6 @@ long kvm_arch_vm_ioctl(struct file *filp, int r = -ENOTTY; switch (ioctl) { - case KVM_SET_MEMORY_REGION: { - struct kvm_memory_region kvm_mem; - struct kvm_userspace_memory_region kvm_userspace_mem; - - r = -EFAULT; - if (copy_from_user(kvm_mem, argp, sizeof kvm_mem)) - goto out; - kvm_userspace_mem.slot = kvm_mem.slot; - kvm_userspace_mem.flags = kvm_mem.flags; - kvm_userspace_mem.guest_phys_addr = - kvm_mem.guest_phys_addr; - kvm_userspace_mem.memory_size = kvm_mem.memory_size; - r = kvm_vm_ioctl_set_memory_region(kvm, - kvm_userspace_mem, false); - if (r) - goto out; - break; - } case KVM_CREATE_IRQCHIP: r = -EFAULT; r = kvm_ioapic_init(kvm); diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 6667042..9245848 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -3692,7 +3692,7 @@ static int alloc_apic_access_page(struct kvm *kvm) kvm_userspace_mem.flags = 0; kvm_userspace_mem.guest_phys_addr = 0xfee0ULL; kvm_userspace_mem.memory_size = PAGE_SIZE; - r = __kvm_set_memory_region(kvm, kvm_userspace_mem, false); + r = __kvm_set_memory_region(kvm, kvm_userspace_mem); if (r) goto out; @@ -3722,7 +3722,7 @@ static int alloc_identity_pagetable(struct kvm *kvm) kvm_userspace_mem.guest_phys_addr = kvm-arch.ept_identity_map_addr; kvm_userspace_mem.memory_size = PAGE_SIZE; - r = __kvm_set_memory_region(kvm, kvm_userspace_mem, false); + r = __kvm_set_memory_region(kvm, kvm_userspace_mem); if (r) goto out; @@ -4362,7 +4362,7 @@ static int vmx_set_tss_addr(struct kvm *kvm, unsigned int addr) .flags = 0, }; - ret = kvm_set_memory_region(kvm, tss_mem, false); + ret = kvm_set_memory_region(kvm, tss_mem); if (ret) return ret; kvm-arch.tss_addr = addr; diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index b4757a1..84a994c 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -453,11 +453,9 @@ id_to_memslot(struct kvm_memslots *slots, int id) } int kvm_set_memory_region(struct kvm *kvm, - struct kvm_userspace_memory_region *mem, - bool user_alloc); + struct kvm_userspace_memory_region *mem); int __kvm_set_memory_region(struct kvm *kvm, - struct kvm_userspace_memory_region *mem, - bool user_alloc); + struct kvm_userspace_memory_region *mem); void kvm_arch_free_memslot(struct kvm_memory_slot *free, struct kvm_memory_slot *dont); int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages); @@ -553,9 +551,7 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log); int kvm_vm_ioctl_set_memory_region(struct kvm *kvm, - struct - kvm_userspace_memory_region *mem, - bool user_alloc); + struct kvm_userspace_memory_region *mem); int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level); long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index fd30370..5b3e41b 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -745,8 +745,7 @@ enum kvm_mr_change { * Must be called holding mmap_sem for write. */ int __kvm_set_memory_region(struct kvm *kvm, - struct kvm_userspace_memory_region *mem, - bool user_alloc) + struct kvm_userspace_memory_region *mem) { int r; gfn_t base_gfn; @@ -767,7 +766,7 @@ int __kvm_set_memory_region(struct kvm *kvm, if (mem-guest_phys_addr
[PATCH 3/6] KVM: set_memory_region: Make kvm_mr_change available to arch code
This will be used for cleaning up prepare/commit_memory_region() later. Signed-off-by: Takuya Yoshikawa yoshikawa_takuya...@lab.ntt.co.jp --- include/linux/kvm_host.h | 18 ++ virt/kvm/kvm_main.c | 18 -- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 84a994c..8eaf61f 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -452,6 +452,24 @@ id_to_memslot(struct kvm_memslots *slots, int id) return slot; } +/* + * KVM_SET_USER_MEMORY_REGION ioctl allows the following operations: + * - create a new memory slot + * - delete an existing memory slot + * - modify an existing memory slot + * -- move it in the guest physical memory space + * -- just change its flags + * + * Since flags can be changed by some of these operations, the following + * differentiation is the best we can do for __kvm_set_memory_region(): + */ +enum kvm_mr_change { + KVM_MR_CREATE, + KVM_MR_DELETE, + KVM_MR_MOVE, + KVM_MR_FLAGS_ONLY, +}; + int kvm_set_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem); int __kvm_set_memory_region(struct kvm *kvm, diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 5b3e41b..c7979ed 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -719,24 +719,6 @@ static struct kvm_memslots *install_new_memslots(struct kvm *kvm, } /* - * KVM_SET_USER_MEMORY_REGION ioctl allows the following operations: - * - create a new memory slot - * - delete an existing memory slot - * - modify an existing memory slot - * -- move it in the guest physical memory space - * -- just change its flags - * - * Since flags can be changed by some of these operations, the following - * differentiation is the best we can do for __kvm_set_memory_region(): - */ -enum kvm_mr_change { - KVM_MR_CREATE, - KVM_MR_DELETE, - KVM_MR_MOVE, - KVM_MR_FLAGS_ONLY, -}; - -/* * Allocate some memory and give it an address in the guest physical address * space. * -- 1.7.4.1 -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 4/6] KVM: set_memory_region: Refactor prepare_memory_region()
This patch drops the parameter old, a copy of the old memory slot, and adds a new parameter named change to know the change being requested. This not only cleans up the code but also removes extra copying of the memory slot structure. Signed-off-by: Takuya Yoshikawa yoshikawa_takuya...@lab.ntt.co.jp --- arch/arm/kvm/arm.c |4 ++-- arch/ia64/kvm/kvm-ia64.c |4 ++-- arch/powerpc/kvm/powerpc.c |4 ++-- arch/s390/kvm/kvm-s390.c |4 ++-- arch/x86/kvm/x86.c | 10 -- include/linux/kvm_host.h |4 ++-- virt/kvm/kvm_main.c|2 +- 7 files changed, 15 insertions(+), 17 deletions(-) diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 24cb5f6..96ebab7 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -230,8 +230,8 @@ int kvm_arch_set_memory_region(struct kvm *kvm, int kvm_arch_prepare_memory_region(struct kvm *kvm, struct kvm_memory_slot *memslot, - struct kvm_memory_slot old, - struct kvm_userspace_memory_region *mem) + struct kvm_userspace_memory_region *mem, + enum kvm_mr_change change) { return 0; } diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c index 43701f0..5c2b07e 100644 --- a/arch/ia64/kvm/kvm-ia64.c +++ b/arch/ia64/kvm/kvm-ia64.c @@ -1560,8 +1560,8 @@ int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages) int kvm_arch_prepare_memory_region(struct kvm *kvm, struct kvm_memory_slot *memslot, - struct kvm_memory_slot old, - struct kvm_userspace_memory_region *mem) + struct kvm_userspace_memory_region *mem, + enum kvm_mr_change change) { unsigned long i; unsigned long pfn; diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 22b3315..8aa51cd 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -412,8 +412,8 @@ int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages) int kvm_arch_prepare_memory_region(struct kvm *kvm, struct kvm_memory_slot *memslot, - struct kvm_memory_slot old, - struct kvm_userspace_memory_region *mem) + struct kvm_userspace_memory_region *mem, + enum kvm_mr_change change) { return kvmppc_core_prepare_memory_region(kvm, memslot, mem); } diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 07ac302..4288780 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -974,8 +974,8 @@ int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages) /* Section: memory related */ int kvm_arch_prepare_memory_region(struct kvm *kvm, struct kvm_memory_slot *memslot, - struct kvm_memory_slot old, - struct kvm_userspace_memory_region *mem) + struct kvm_userspace_memory_region *mem, + enum kvm_mr_change change) { /* A few sanity checks. We can have exactly one memory slot which has to start at guest virtual zero and which has to be located at a diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index b2dcb6e..d692be2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6906,23 +6906,21 @@ out_free: int kvm_arch_prepare_memory_region(struct kvm *kvm, struct kvm_memory_slot *memslot, - struct kvm_memory_slot old, - struct kvm_userspace_memory_region *mem) + struct kvm_userspace_memory_region *mem, + enum kvm_mr_change change) { - int npages = memslot-npages; - /* * Only private memory slots need to be mapped here since * KVM_SET_MEMORY_REGION ioctl is no longer supported. */ - if ((memslot-id = KVM_USER_MEM_SLOTS) npages !old.npages) { + if ((memslot-id = KVM_USER_MEM_SLOTS) (change == KVM_MR_CREATE)) { unsigned long userspace_addr; /* * MAP_SHARED to prevent internal slot pages from being moved * by fork()/COW. */ - userspace_addr = vm_mmap(NULL, 0, npages * PAGE_SIZE, + userspace_addr = vm_mmap(NULL, 0, memslot-npages * PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0); diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 8eaf61f..caa72cf 100644 --- a/include/linux/kvm_host.h +++
[PATCH 5/6] KVM: set_memory_region: Refactor commit_memory_region()
This patch makes the parameter old a const pointer to the old memory slot and adds a new parameter named change to know the change being requested: the former is for removing extra copying and the latter is for cleaning up the code. Signed-off-by: Takuya Yoshikawa yoshikawa_takuya...@lab.ntt.co.jp --- arch/arm/kvm/arm.c |3 ++- arch/ia64/kvm/kvm-ia64.c |3 ++- arch/powerpc/include/asm/kvm_ppc.h |2 +- arch/powerpc/kvm/book3s_hv.c |4 ++-- arch/powerpc/kvm/book3s_pr.c |2 +- arch/powerpc/kvm/booke.c |2 +- arch/powerpc/kvm/powerpc.c |3 ++- arch/s390/kvm/kvm-s390.c |3 ++- arch/x86/kvm/x86.c | 15 --- include/linux/kvm_host.h |3 ++- virt/kvm/kvm_main.c|2 +- 11 files changed, 24 insertions(+), 18 deletions(-) diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 96ebab7..b32dc44 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -238,7 +238,8 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, void kvm_arch_commit_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem, - struct kvm_memory_slot old) + const struct kvm_memory_slot *old, + enum kvm_mr_change change) { } diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c index 5c2b07e..7a54455 100644 --- a/arch/ia64/kvm/kvm-ia64.c +++ b/arch/ia64/kvm/kvm-ia64.c @@ -1591,7 +1591,8 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, void kvm_arch_commit_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem, - struct kvm_memory_slot old) + const struct kvm_memory_slot *old, + enum kvm_mr_change change) { return; } diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h index 44a657a..44fa9ad 100644 --- a/arch/powerpc/include/asm/kvm_ppc.h +++ b/arch/powerpc/include/asm/kvm_ppc.h @@ -152,7 +152,7 @@ extern int kvmppc_core_prepare_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem); extern void kvmppc_core_commit_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem, - struct kvm_memory_slot old); + const struct kvm_memory_slot *old); extern int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm, struct kvm_ppc_smmu_info *info); extern void kvmppc_core_flush_memslot(struct kvm *kvm, diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 80dcc53..1e521ba 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -1639,12 +1639,12 @@ int kvmppc_core_prepare_memory_region(struct kvm *kvm, void kvmppc_core_commit_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem, - struct kvm_memory_slot old) + const struct kvm_memory_slot *old) { unsigned long npages = mem-memory_size PAGE_SHIFT; struct kvm_memory_slot *memslot; - if (npages old.npages) { + if (npages old-npages) { /* * If modifying a memslot, reset all the rmap dirty bits. * If this is a new memslot, we don't need to do anything diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c index 5e93438..286e23e 100644 --- a/arch/powerpc/kvm/book3s_pr.c +++ b/arch/powerpc/kvm/book3s_pr.c @@ -1283,7 +1283,7 @@ int kvmppc_core_prepare_memory_region(struct kvm *kvm, void kvmppc_core_commit_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem, - struct kvm_memory_slot old) + const struct kvm_memory_slot *old) { } diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index 020923e..eb88fa6 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -1531,7 +1531,7 @@ int kvmppc_core_prepare_memory_region(struct kvm *kvm, void kvmppc_core_commit_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem, - struct kvm_memory_slot old) + const struct kvm_memory_slot *old) { } diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 8aa51cd..7b5d4d2 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -420,7 +420,8 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, void kvm_arch_commit_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem, -
[PATCH 6/6] KVM: ARM: Remove kvm_arch_set_memory_region()
This was replaced with prepare/commit long before: commit f7784b8ec9b6a041fa828cfbe9012fe51933f5ac KVM: split kvm_arch_set_memory_region into prepare and commit Signed-off-by: Takuya Yoshikawa yoshikawa_takuya...@lab.ntt.co.jp --- arch/arm/kvm/arm.c |8 1 files changed, 0 insertions(+), 8 deletions(-) diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index b32dc44..e4ad0bb 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -220,14 +220,6 @@ long kvm_arch_dev_ioctl(struct file *filp, return -EINVAL; } -int kvm_arch_set_memory_region(struct kvm *kvm, - struct kvm_userspace_memory_region *mem, - struct kvm_memory_slot old, - int user_alloc) -{ - return 0; -} - int kvm_arch_prepare_memory_region(struct kvm *kvm, struct kvm_memory_slot *memslot, struct kvm_userspace_memory_region *mem, -- 1.7.4.1 -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] KVM: nSVM/nVMX: Implement vmexit on INIT assertion
On Sun, Feb 24, 2013 at 03:08:53PM +0100, Jan Kiszka wrote: From: Jan Kiszka jan.kis...@siemens.com @@ -2390,6 +2390,21 @@ static int nested_svm_vmexit(struct vcpu_svm *svm) return 0; } +static bool nested_svm_handle_init_received(struct kvm_vcpu *vcpu) +{ + struct vcpu_svm *svm = to_svm(vcpu); + + if (!is_guest_mode(vcpu) || + !(svm-nested.intercept (1ULL INTERCEPT_INIT))) + return false; + + svm-vmcb-control.exit_code = SVM_EXIT_INIT; + svm-vmcb-control.exit_int_info = 0; + nested_svm_vmexit(svm); + + return true; +} [...] + if (vcpu-arch.mp_state == KVM_MP_STATE_INIT_RECEIVED + kvm_x86_ops-handle_init_received(vcpu)) { + /* nested vmexit, L1 is runnable now */ + vcpu-arch.mp_state = KVM_MP_STATE_RUNNABLE; + return 1; + } Hmm, looks like the INIT signal is lost after the VMEXIT. But on SVM the INIT signal is still pending an will be delivered when GIF becomes one again. Do I miss anything? Joerg -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] x86: kvmclock: Do not setup kvmclock vsyscall in the absence of that clock
On Sat, Feb 23, 2013 at 05:05:29PM +0100, Jan Kiszka wrote: From: Jan Kiszka jan.kis...@siemens.com This fixes boot lockups with no-kvmclock, when the host is not exposing this particular feature (QEMU: -cpu ...,-kvmclock) or when the kvmclock initialization failed for whatever reason. Signed-off-by: Jan Kiszka jan.kis...@siemens.com Applied, thanks. --- Should go to 3.8 as well, I presume. arch/x86/kernel/kvmclock.c |9 - 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index 5bedbdd..b730efa 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -160,8 +160,12 @@ int kvm_register_clock(char *txt) { int cpu = smp_processor_id(); int low, high, ret; - struct pvclock_vcpu_time_info *src = hv_clock[cpu].pvti; + struct pvclock_vcpu_time_info *src; + + if (!hv_clock) + return 0; + src = hv_clock[cpu].pvti; low = (int)__pa(src) | 1; high = ((u64)__pa(src) 32); ret = native_write_msr_safe(msr_kvm_system_time, low, high); @@ -276,6 +280,9 @@ int __init kvm_setup_vsyscall_timeinfo(void) struct pvclock_vcpu_time_info *vcpu_time; unsigned int size; + if (!hv_clock) + return 0; + size = PAGE_ALIGN(sizeof(struct pvclock_vsyscall_time_info)*NR_CPUS); preempt_disable(); -- 1.7.3.4 -- Gleb. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] KVM: nSVM/nVMX: Implement vmexit on INIT assertion
On Mon, Feb 25, 2013 at 10:04:50AM +0100, Jan Kiszka wrote: Is the nested-related state already saved on AMD, Jörg? If not, adding this one would not make things worse at least. Still, missing user space save/restore already breaks reset, not only migration (dunno if this is better on AMD). Not sure if this is what you are asking for, but nested state is at not saved/restored for migration or anything. This is a long-standing issue which needs to be fixed at some point. Joerg -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] KVM: nSVM/nVMX: Implement vmexit on INIT assertion
On 2013-02-27 12:17, Joerg Roedel wrote: On Sun, Feb 24, 2013 at 03:08:53PM +0100, Jan Kiszka wrote: From: Jan Kiszka jan.kis...@siemens.com @@ -2390,6 +2390,21 @@ static int nested_svm_vmexit(struct vcpu_svm *svm) return 0; } +static bool nested_svm_handle_init_received(struct kvm_vcpu *vcpu) +{ +struct vcpu_svm *svm = to_svm(vcpu); + +if (!is_guest_mode(vcpu) || +!(svm-nested.intercept (1ULL INTERCEPT_INIT))) +return false; + +svm-vmcb-control.exit_code = SVM_EXIT_INIT; +svm-vmcb-control.exit_int_info = 0; +nested_svm_vmexit(svm); + +return true; +} [...] +if (vcpu-arch.mp_state == KVM_MP_STATE_INIT_RECEIVED +kvm_x86_ops-handle_init_received(vcpu)) { +/* nested vmexit, L1 is runnable now */ +vcpu-arch.mp_state = KVM_MP_STATE_RUNNABLE; +return 1; +} Hmm, looks like the INIT signal is lost after the VMEXIT. But on SVM the INIT signal is still pending an will be delivered when GIF becomes one again. Do I miss anything? No, this is unsolved yet, see the other mail. Jan -- Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] KVM: nSVM/nVMX: Implement vmexit on INIT assertion
On 2013-02-27 12:20, Joerg Roedel wrote: On Mon, Feb 25, 2013 at 10:04:50AM +0100, Jan Kiszka wrote: Is the nested-related state already saved on AMD, Jörg? If not, adding this one would not make things worse at least. Still, missing user space save/restore already breaks reset, not only migration (dunno if this is better on AMD). Not sure if this is what you are asking for, but nested state is at not saved/restored for migration or anything. This is a long-standing issue which needs to be fixed at some point. As I suspected. That needs to be solved at some point, but for now it would not cause any regression to add another unsaved nested-related state (here: INIT asserted). That was my questions. Thanks, Jan -- Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] kvm-unit-test: disable syscall test in 32 bit mode
Fix this error on 32 bit systems: x86/msr.c:122:5: error: unknown register name ‘r11’ in ‘asm’ Signed-off-by: Michael S. Tsirkin m...@redhat.com --- x86/msr.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x86/msr.c b/x86/msr.c index 307835d..de7573d 100644 --- a/x86/msr.c +++ b/x86/msr.c @@ -112,6 +112,7 @@ static void test_msr_rw(int msr_index, unsigned long long input, unsigned long l static void test_syscall_lazy_load(void) { +#ifdef __x86_64__ extern void syscall_target(); u16 cs = read_cs(), ss = read_ss(); ulong tmp; @@ -123,6 +124,7 @@ static void test_syscall_lazy_load(void) write_ss(ss); // will crash horribly if broken report(MSR_*STAR eager loading, true); +#endif } int main(int ac, char **av) -- MST -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] kvm-unit-test: disable syscall test in 32 bit mode
On Wed, Feb 27, 2013 at 01:25:49PM +0200, Michael S. Tsirkin wrote: Fix this error on 32 bit systems: x86/msr.c:122:5: error: unknown register name ‘r11’ in ‘asm’ Signed-off-by: Michael S. Tsirkin m...@redhat.com Applied, thanks. --- x86/msr.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x86/msr.c b/x86/msr.c index 307835d..de7573d 100644 --- a/x86/msr.c +++ b/x86/msr.c @@ -112,6 +112,7 @@ static void test_msr_rw(int msr_index, unsigned long long input, unsigned long l static void test_syscall_lazy_load(void) { +#ifdef __x86_64__ extern void syscall_target(); u16 cs = read_cs(), ss = read_ss(); ulong tmp; @@ -123,6 +124,7 @@ static void test_syscall_lazy_load(void) write_ss(ss); // will crash horribly if broken report(MSR_*STAR eager loading, true); +#endif } int main(int ac, char **av) -- MST -- Gleb. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: virtio-rng only returns zeros with CONFIG_HW_RANDOM=m
On Wed, Feb 27 2013, Rusty Russell wrote: Aurelien Jarno aurel...@aurel32.net writes: Hi, I have noticed that virtio-rng only returns zero for kernels = 2.6.33 built with CONFIG_HW_RANDOM=m. This is a bit much too predictable for a random generator ;-). Wow. Fortunately, all of SLES, RHEL, Ubuntu or Fedora set CONFIG_HW_RANDOM=y. What do they know that we don't? Oops, looks like Debian testing: config-3.2.0-4-amd64:CONFIG_HW_RANDOM=m The reason for that is virtio expects guest real addresses, while rng_core.ko (ie when built as a module) is passing a vmalloced buffer to the virtio-rng read function, declared as such: static u8 rng_buffer[SMP_CACHE_BYTES 32 ? 32 : SMP_CACHE_BYTES] __cacheline_aligned; Yuck... It would be nice if this has oopsed. Jens, what about this patch? Cheers, Rusty. Subject: scatterlist: sg_set_buf() argument must be in linear mapping. Signed-off-by: Rusty Russell ru...@rustcorp.com.au diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index 4bd6c06..9365375 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -111,6 +111,9 @@ static inline struct page *sg_page(struct scatterlist *sg) static inline void sg_set_buf(struct scatterlist *sg, const void *buf, unsigned int buflen) { +#ifdef CONFIG_DEBUG_SG + BUG_ON(!virt_addr_valid(buf)); +#endif sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf)); } Looks good to me, in lieu of being able to return an error. Want me to queue it up? -- Jens Axboe -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] KVM: VMX: Make prepare_vmcs12 and load_vmcs12_host_state static
On Sat, Feb 23, 2013 at 03:07:47PM +0100, Jan Kiszka wrote: From: Jan Kiszka jan.kis...@siemens.com Both are only used locally. Signed-off-by: Jan Kiszka jan.kis...@siemens.com Applied, thanks. --- arch/x86/kvm/vmx.c |5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index d6ea4a7..7bd9f88 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -7295,7 +7295,7 @@ vmcs12_guest_cr4(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) * exit-information fields only. Other fields are modified by L1 with VMWRITE, * which already writes to vmcs12 directly. */ -void prepare_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) +static void prepare_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) { /* update guest state fields: */ vmcs12-guest_cr0 = vmcs12_guest_cr0(vcpu, vmcs12); @@ -7408,7 +7408,8 @@ void prepare_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) * Failures During or After Loading Guest State). * This function should be called when the active VMCS is L1's (vmcs01). */ -void load_vmcs12_host_state(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) +static void load_vmcs12_host_state(struct kvm_vcpu *vcpu, +struct vmcs12 *vmcs12) { if (vmcs12-vm_exit_controls VM_EXIT_LOAD_IA32_EFER) vcpu-arch.efer = vmcs12-host_ia32_efer; -- 1.7.3.4 -- Gleb. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] KVM: nVMX: Advertise PAUSE and WBINVD exiting support
On Sat, Feb 23, 2013 at 10:34:39PM +0100, Jan Kiszka wrote: From: Jan Kiszka jan.kis...@siemens.com These exits have no preconditions, and we already process the corresponding reasons in nested_vmx_exit_handled correctly. Signed-off-by: Jan Kiszka jan.kis...@siemens.com Applied, thanks. --- arch/x86/kvm/vmx.c |4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 7bd9f88..26d47e9 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2080,6 +2080,7 @@ static __init void nested_vmx_setup_ctls_msrs(void) CPU_BASED_MOV_DR_EXITING | CPU_BASED_UNCOND_IO_EXITING | CPU_BASED_USE_IO_BITMAPS | CPU_BASED_MONITOR_EXITING | CPU_BASED_RDPMC_EXITING | CPU_BASED_RDTSC_EXITING | + CPU_BASED_PAUSE_EXITING | CPU_BASED_ACTIVATE_SECONDARY_CONTROLS; /* * We can allow some features even when not supported by the @@ -2094,7 +2095,8 @@ static __init void nested_vmx_setup_ctls_msrs(void) nested_vmx_secondary_ctls_low, nested_vmx_secondary_ctls_high); nested_vmx_secondary_ctls_low = 0; nested_vmx_secondary_ctls_high = - SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES; + SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES | + SECONDARY_EXEC_WBINVD_EXITING; } static inline bool vmx_control_verify(u32 control, u32 low, u32 high) -- 1.7.3.4 -- Gleb. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] KVM: nVMX: Clear segment cache after switching between L1 and L2
On Sat, Feb 23, 2013 at 10:35:37PM +0100, Jan Kiszka wrote: From: Jan Kiszka jan.kis...@siemens.com Switching the VMCS obviously invalidates what may have been cached about the guest segments. Signed-off-by: Jan Kiszka jan.kis...@siemens.com Applied, thanks. --- Probably, the missing invalidations are harmless ATM, but you never know. arch/x86/kvm/vmx.c |4 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 94f3b66..d45f0e0 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -7236,6 +7236,8 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch) vcpu-cpu = cpu; put_cpu(); + vmx_segment_cache_clear(vmx); + vmcs12-launch_state = 1; prepare_vmcs02(vcpu, vmcs12); @@ -7504,6 +7506,8 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu) vcpu-cpu = cpu; put_cpu(); + vmx_segment_cache_clear(vmx); + /* if no vmcs02 cache requested, remove the one we used */ if (VMCS02_POOL_SIZE == 0) nested_free_vmcs02(vmx, vmx-nested.current_vmptr); -- 1.7.3.4 -- Gleb. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] KVM: nVMX: Use cached exit reason
On Sun, Feb 24, 2013 at 02:11:34PM +0100, Jan Kiszka wrote: From: Jan Kiszka jan.kis...@siemens.com No need to re-read what vmx_vcpu_run already picked up for us. Signed-off-by: Jan Kiszka jan.kis...@siemens.com Applied, thanks. --- arch/x86/kvm/vmx.c |4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index d45f0e0..ccb6456 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -6082,10 +6082,10 @@ static bool nested_vmx_exit_handled_cr(struct kvm_vcpu *vcpu, */ static bool nested_vmx_exit_handled(struct kvm_vcpu *vcpu) { - u32 exit_reason = vmcs_read32(VM_EXIT_REASON); u32 intr_info = vmcs_read32(VM_EXIT_INTR_INFO); struct vcpu_vmx *vmx = to_vmx(vcpu); struct vmcs12 *vmcs12 = get_vmcs12(vcpu); + u32 exit_reason = vmx-exit_reason; if (vmx-nested.nested_run_pending) return 0; @@ -7364,7 +7364,7 @@ static void prepare_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) /* update exit information fields: */ - vmcs12-vm_exit_reason = vmcs_read32(VM_EXIT_REASON); + vmcs12-vm_exit_reason = to_vmx(vcpu)-exit_reason; Well, this can be called after migration, so vcpu-exit_reason will be incorrect, but we all know how well migration works today with nested guests. vmcs12-exit_qualification = vmcs_readl(EXIT_QUALIFICATION); vmcs12-vm_exit_intr_info = vmcs_read32(VM_EXIT_INTR_INFO); -- 1.7.3.4 -- Gleb. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] arch/x86/kvm: beautify source code for __u32 irq which is never 0
On Wed, Feb 27, 2013 at 11:33:25AM +0800, Chen Gang wrote: irp-irq is __u32 which is never 0. Signed-off-by: Chen Gang gang.c...@asianux.com Applied, thanks. --- arch/x86/kvm/x86.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index f71500a..811c5c9 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2700,7 +2700,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu, static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_interrupt *irq) { - if (irq-irq 0 || irq-irq = KVM_NR_INTERRUPTS) + if (irq-irq = KVM_NR_INTERRUPTS) return -EINVAL; if (irqchip_in_kernel(vcpu-kvm)) return -ENXIO; -- 1.7.7.6 -- Gleb. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] kvm-unit-test: more documentation and runner script
Add documentation about using qemu-system for unit tests. Add runner script to select the correct binary and flags. Signed-off-by: Michael S. Tsirkin m...@redhat.com --- README | 10 +- x86-run | 27 +++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100755 x86-run diff --git a/README b/README index 4ceb869..214397c 100644 --- a/README +++ b/README @@ -10,10 +10,18 @@ To create the tests' images just type 'make' in this directory. Tests' images created in ./ARCH/*.flat An example of a test invocation: -qemu-system-x86_64 -device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out -serial stdio -kernel ./x86/msr.flat +Using qemu-kvm: + +qemu-kvm -device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out -serial stdio -kernel ./x86/msr.flat This invocation runs the msr test case. The test outputs to stdio. +Using qemu (supported since qemu 1.3): +qemu-system-x86_64 -enable-kvm -device pc-testdev -serial stdio -device isa-debug-exit,iobase=0xf4,iosize=0x4 -kernel ./x86/msr.flat +Or use a runner script to detect the correct invocation: +./x86-run ./x86/msr.flat +To select a specific qemu binary, specify the QEMU=path environment: +QEMU=/tmp/qemu/x86_64-softmmu/qemu-system-x86_64 ./x86-run ./x86/msr.flat Directory structure: .: Makefile and config files for the tests diff --git a/x86-run b/x86-run new file mode 100755 index 000..cf1d38a --- /dev/null +++ b/x86-run @@ -0,0 +1,27 @@ +#!/usr/bin/bash + +qemukvm=${QEMU:-qemu-kvm} +qemusystem=${QEMU:-qemu-system-x86_64} +if + ${qemukvm} -device '?' 21 | fgrep -e \testdev\ -e \pc-testdev\ /dev/null; +then + qemu=${qemukvm} +else + if + ${qemsystem} -device '?' 21 | fgrep -e \testdev\ -e \pc-testdev\ /dev/null; + then + qemu=${qemusystem} + else + echo QEMU binary ${QEMU} has no support for test device. Exiting. + exit 1 + fi +fi + +if + ${qemu} -device '?' 21 | fgrep pc-testdev /dev/null; +then + command=${qemu} -enable-kvm -device pc-testdev -serial stdio -device isa-debug-exit,iobase=0xf4,iosize=0x4 -kernel +else + command=${qemu} -device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out -serial stdio -kernel ./x86/msr.flat +fi +exec ${command} $@ -- MST -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 0/6] KVM: Clean up and optimize set_memory_region() - part2
On Wed, Feb 27, 2013 at 07:41:03PM +0900, Takuya Yoshikawa wrote: Note: this is based on the latest master branch. I'm sending this before 3.9-rc1 is released since this can cause extra conflicts unless we make this available to all arch before we start adding new stuff. I do not quite sure what you want me to do. Why can't this wait for 3.10? Please review: every change is trivial and should not change anything. Takuya Yoshikawa (6): KVM: set_memory_region: Drop user_alloc from prepare/commit_memory_region() KVM: set_memory_region: Drop user_alloc from set_memory_region() KVM: set_memory_region: Make kvm_mr_change available to arch code KVM: set_memory_region: Refactor prepare_memory_region() KVM: set_memory_region: Refactor commit_memory_region() KVM: ARM: Remove kvm_arch_set_memory_region() arch/arm/kvm/arm.c | 15 ++-- arch/ia64/kvm/kvm-ia64.c | 25 ++--- arch/powerpc/include/asm/kvm_ppc.h |2 +- arch/powerpc/kvm/book3s_hv.c |4 +- arch/powerpc/kvm/book3s_pr.c |2 +- arch/powerpc/kvm/booke.c |2 +- arch/powerpc/kvm/powerpc.c | 13 +-- arch/s390/kvm/kvm-s390.c | 10 ++-- arch/x86/kvm/vmx.c |6 ++-- arch/x86/kvm/x86.c | 25 + include/linux/kvm_host.h | 35 +- virt/kvm/kvm_main.c| 40 --- 12 files changed, 67 insertions(+), 112 deletions(-) -- 1.7.4.1 -- Gleb. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: virtio-rng only returns zeros with CONFIG_HW_RANDOM=m
On Wed, Feb 27, 2013 at 11:56:55AM +1030, Rusty Russell wrote: Aurelien Jarno aurel...@aurel32.net writes: Hi, I have noticed that virtio-rng only returns zero for kernels = 2.6.33 built with CONFIG_HW_RANDOM=m. This is a bit much too predictable for a random generator ;-). The reason for that is virtio expects guest real addresses, while rng_core.ko (ie when built as a module) is passing a vmalloced buffer to the virtio-rng read function, declared as such: static u8 rng_buffer[SMP_CACHE_BYTES 32 ? 32 : SMP_CACHE_BYTES] __cacheline_aligned; This is basically the same issue than the following one: https://lists.linux-foundation.org/pipermail/virtualization/2008-May/010946.html but introduced in a more subtle way in this commit: commit bb347d98079a547e80bd4722dee1de61e4dca0e8 Author: Ian Molton ian.mol...@collabora.co.uk Date: Tue Dec 1 15:26:33 2009 +0800 OK, I looked at doing a kmalloc and copy in virtio_rng, but it's very inelegant (we don't know what size of buffer to allocate). On the other hand, the rng API allows to return less bytes than requested, so it's possible to have a fixed buffer size of for example 64 or 128 bytes. But I agree it's better to do that in rng core. No driver other than virtio_rng cares about this issue, but it's still far easier to fix in the core. How's this? Works here... Subject: hw_random: make buffer usable in scatterlist. virtio_rng feeds the randomness buffer handed by the core directly into the scatterlist, since commit bb347d98079a547e80bd4722dee1de61e4dca0e8. However, if CONFIG_HW_RANDOM=m, the static buffer isn't a linear address (at least on most archs). We could fix this in virtio_rng, but it's actually far easier to just do it in the core as virtio_rng would have to allocate a buffer every time (it doesn't know how much the core will want to read). Reported-by: Aurelien Jarno aurel...@aurel32.net Signed-off-by: Rusty Russell ru...@rustcorp.com.au diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c index 1bafb40..69ae597 100644 --- a/drivers/char/hw_random/core.c +++ b/drivers/char/hw_random/core.c @@ -40,6 +40,7 @@ #include linux/init.h #include linux/miscdevice.h #include linux/delay.h +#include linux/slab.h #include asm/uaccess.h @@ -52,8 +53,12 @@ static struct hwrng *current_rng; static LIST_HEAD(rng_list); static DEFINE_MUTEX(rng_mutex); static int data_avail; -static u8 rng_buffer[SMP_CACHE_BYTES 32 ? 32 : SMP_CACHE_BYTES] - __cacheline_aligned; +static u8 *rng_buffer; + +static size_t rng_buffer_size(void) +{ + return SMP_CACHE_BYTES 32 ? 32 : SMP_CACHE_BYTES; +} static inline int hwrng_init(struct hwrng *rng) { @@ -116,7 +121,7 @@ static ssize_t rng_dev_read(struct file *filp, char __user *buf, if (!data_avail) { bytes_read = rng_get_data(current_rng, rng_buffer, - sizeof(rng_buffer), + rng_buffer_size(), !(filp-f_flags O_NONBLOCK)); if (bytes_read 0) { err = bytes_read; @@ -307,6 +312,14 @@ int hwrng_register(struct hwrng *rng) mutex_lock(rng_mutex); + /* kmalloc makes this safe for virt_to_page() in virtio_rng.c */ + err = -ENOMEM; + if (!rng_buffer) { + rng_buffer = kmalloc(rng_buffer_size(), GFP_KERNEL); + if (!rng_buffer) + goto out_unlock; + } + /* Must not register two RNGs with the same name. */ err = -EEXIST; list_for_each_entry(tmp, rng_list, list) { It works fine for me. Thanks for the patch. Tested-by: Aurelien Jarno aurel...@aurel32.net -- Aurelien Jarno GPG: 1024D/F1BCDB73 aurel...@aurel32.net http://www.aurel32.net -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: Is there any solution in KVM that like VAAI does in EXSI
Il 26/02/2013 16:13, Stefan Hajnoczi ha scritto: Is there any solution in KVM that works like VAAI does in EXSI, I found a PPT that posted in Sep. 2012, which said that storage offload will be consider in future. I am wondering anybody knows about this, or provide some information about this? Thin Provisioning support is being added to QEMU. Some configurations already work - virtio-scsi on a block device or raw file supports discard, for example. Linux recently got Zero Blocks support in the form of the BLKZEROOUT ioctl. It is not being exploited by QEMU or libvirt yet. Copy Offload, not aware of active development. Perhaps libvirt or libstoragemgmt will support it. Copy offload is in the works (still at the whiteboard stage, though). Paolo -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] kvm-unit-test: more documentation and runner script
On 02/27/2013 12:55 PM, Michael S. Tsirkin wrote: Add documentation about using qemu-system for unit tests. Add runner script to select the correct binary and flags. Signed-off-by: Michael S. Tsirkin m...@redhat.com --- README | 10 +- x86-run | 27 +++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100755 x86-run diff --git a/README b/README index 4ceb869..214397c 100644 --- a/README +++ b/README @@ -10,10 +10,18 @@ To create the tests' images just type 'make' in this directory. Tests' images created in ./ARCH/*.flat An example of a test invocation: -qemu-system-x86_64 -device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out -serial stdio -kernel ./x86/msr.flat +Using qemu-kvm: + +qemu-kvm -device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out -serial stdio -kernel ./x86/msr.flat This invocation runs the msr test case. The test outputs to stdio. +Using qemu (supported since qemu 1.3): +qemu-system-x86_64 -enable-kvm -device pc-testdev -serial stdio -device isa-debug-exit,iobase=0xf4,iosize=0x4 -kernel ./x86/msr.flat I think it is worth here to point out that with new qemu, after the unittest is done, the exit status of qemu is 1, different from the 'old style', whose exit status in successful completion is 0. +Or use a runner script to detect the correct invocation: +./x86-run ./x86/msr.flat +To select a specific qemu binary, specify the QEMU=path environment: +QEMU=/tmp/qemu/x86_64-softmmu/qemu-system-x86_64 ./x86-run ./x86/msr.flat Directory structure: .: Makefile and config files for the tests diff --git a/x86-run b/x86-run new file mode 100755 index 000..cf1d38a --- /dev/null +++ b/x86-run @@ -0,0 +1,27 @@ +#!/usr/bin/bash + +qemukvm=${QEMU:-qemu-kvm} +qemusystem=${QEMU:-qemu-system-x86_64} +if + ${qemukvm} -device '?' 21 | fgrep -e \testdev\ -e \pc-testdev\ /dev/null; +then + qemu=${qemukvm} +else + if + ${qemsystem} -device '?' 21 | fgrep -e \testdev\ -e \pc-testdev\ /dev/null; + then + qemu=${qemusystem} + else + echo QEMU binary ${QEMU} has no support for test device. Exiting. + exit 1 + fi +fi + +if + ${qemu} -device '?' 21 | fgrep pc-testdev /dev/null; +then + command=${qemu} -enable-kvm -device pc-testdev -serial stdio -device isa-debug-exit,iobase=0xf4,iosize=0x4 -kernel +else + command=${qemu} -device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out -serial stdio -kernel ./x86/msr.flat +fi +exec ${command} $@ ^ What about checking the exit status of qemu here and print something like test $@ PASS or test $@ FAIL? -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 0/5] kvm: Make ioeventfd usable on s390.
On 26/02/13 12:18, Michael S. Tsirkin wrote: virtio_ccw: pass a cookie value to kvm hypercall Lookups by channel/vq pair on host during virtio notifications might be expensive. Interpret hypercall return value as a cookie which host can use to do device lookups for the next notification more efficiently. Signed-off-by: Michael S. Tsirkin m...@redhat.com Seems to work fine. (as expected). Tested-by: Christian Borntraeger borntrae...@de.ibm.com Reviewed-by: Christian Borntraeger borntrae...@de.ibm.com --- diff --git a/drivers/s390/kvm/virtio_ccw.c b/drivers/s390/kvm/virtio_ccw.c index 2029b6c..1054f3a 100644 --- a/drivers/s390/kvm/virtio_ccw.c +++ b/drivers/s390/kvm/virtio_ccw.c @@ -77,6 +77,7 @@ struct virtio_ccw_vq_info { void *queue; struct vq_info_block *info_block; struct list_head node; + long cookie; }; #define KVM_VIRTIO_CCW_RING_ALIGN 4096 @@ -145,15 +146,18 @@ static int ccw_io_helper(struct virtio_ccw_device *vcdev, } static inline long do_kvm_notify(struct subchannel_id schid, - unsigned long queue_index) + unsigned long queue_index, + long cookie) { register unsigned long __nr asm(1) = KVM_S390_VIRTIO_CCW_NOTIFY; register struct subchannel_id __schid asm(2) = schid; register unsigned long __index asm(3) = queue_index; register long __rc asm(2); + register long __cookie asm(4) = cookie; asm volatile (diag 2,4,0x500\n - : =d (__rc) : d (__nr), d (__schid), d (__index) + : =d (__rc) : d (__nr), d (__schid), d (__index), + d(__cookie) : memory, cc); return __rc; } @@ -166,7 +170,7 @@ static void virtio_ccw_kvm_notify(struct virtqueue *vq) vcdev = to_vc_device(info-vq-vdev); ccw_device_get_schid(vcdev-cdev, schid); - do_kvm_notify(schid, virtqueue_get_queue_index(vq)); + info-cookie = do_kvm_notify(schid, virtqueue_get_queue_index(vq), info-cookie); } static int virtio_ccw_read_vq_conf(struct virtio_ccw_device *vcdev, -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [Bisected][-next-20130204+] [x86/kvm] udevd:[97]: segfault at ffffffffff5fd020 ip 00007fff069e277f sp 00007fff068c9ef8 error d
On Sun, Feb 24, 2013 at 04:23:44PM -0500, Peter Hurley wrote: On Tue, 2013-02-19 at 10:26 +0200, Gleb Natapov wrote: On Mon, Feb 18, 2013 at 08:12:21PM -0500, Peter Hurley wrote: On Mon, 2013-02-18 at 19:59 -0300, Marcelo Tosatti wrote: On Wed, Feb 13, 2013 at 06:57:09AM -0500, Peter Hurley wrote: On Wed, 2013-02-13 at 12:51 +0200, Gleb Natapov wrote: On Tue, Feb 12, 2013 at 04:39:03PM -0800, H. Peter Anvin wrote: On 02/12/2013 04:26 PM, Peter Hurley wrote: With -next-20130204+ in ubuntu 12.10 VM (so the 80x25 VGA device/console): [0.666410] udevd[97]: starting version 175 [0.674043] udevd[97]: udevd:[97]: segfault at ff5fd020 ip 7fff069e277f sp 7fff068c9ef8 error d and boots to an initramfs prompt. git bisect (log attached) blames: commit 7b5c4a65cc27f017c170b025f8d6d75dabb11c6f Merge: 3596f5b 949db15 Author: H. Peter Anvin h...@linux.intel.com Date: Fri Jan 25 16:31:21 2013 -0800 Merge tag 'v3.8-rc5' into x86/mm The __pa() fixup series that follows touches KVM code that is not present in the existing branch based on v3.7-rc5, so merge in the current upstream from Linus. Signed-off-by: H. Peter Anvin h...@linux.intel.com This only happens with the VGA device/console but that is the default configuration for Ubuntu/KVM because it blacklists pretty much every fb driver. I am guessing this is another bad use of __pa()... need to look into that. Can't find this commit on kvm.git or linux-2.6.git. Is it reproducible there? This is in the linux-next repo (any git tag after 'next-20130204' will reproduce this). It's a pretty large merge commit. This doesn't happen on 3.8-rc7. I'll try to repro this on kvm.git sometime this week. Otherwise, we can wait for it to show up in 3.9. Can you also drop 5dfd486c4750c9278c63fa96e6e85bdd2fb58e9d from linux-next and reproduce? Ok, found and fixed. This will need to go to stable for 3.8 as well. ACK, please send an email with the patch to kvm@vger.kernel.org. Regards, Peter Hurley --- % --- From: Peter Hurley pe...@hurleysoftware.com Date: Sun, 24 Feb 2013 10:55:09 -0500 Subject: [PATCH] x86/kvm: Fix pvclock vsyscall fixmap The physical memory fixmapped for the pvclock clock_gettime vsyscall was allocated, and thus is not a kernel symbol. __pa() is the proper method to use in this case. Fixes the crash below when booting a next-20130204+ smp guest on a 3.8-rc5+ KVM host. [0.666410] udevd[97]: starting version 175 [0.674043] udevd[97]: udevd:[97]: segfault at ff5fd020 ip 7fff069e277f sp 7fff068c9ef8 error d Signed-off-by: Peter Hurley pe...@hurleysoftware.com --- arch/x86/kernel/pvclock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c index 85c3959..2cb9470 100644 --- a/arch/x86/kernel/pvclock.c +++ b/arch/x86/kernel/pvclock.c @@ -185,7 +185,7 @@ int __init pvclock_init_vsyscall(struct pvclock_vsyscall_time_info *i, for (idx = 0; idx = (PVCLOCK_FIXMAP_END-PVCLOCK_FIXMAP_BEGIN); idx++) { __set_fixmap(PVCLOCK_FIXMAP_BEGIN + idx, - __pa_symbol(i) + (idx*PAGE_SIZE), + __pa(i) + (idx*PAGE_SIZE), PAGE_KERNEL_VVAR); } -- 1.8.1.2 -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] x86/kvm: Fix pvclock vsyscall fixmap
The physical memory fixmapped for the pvclock clock_gettime vsyscall was allocated, and thus is not a kernel symbol. __pa() is the proper method to use in this case. Fixes the crash below when booting a next-20130204+ smp guest on a 3.8-rc5+ KVM host. [0.666410] udevd[97]: starting version 175 [0.674043] udevd[97]: udevd:[97]: segfault at ff5fd020 ip 7fff069e277f sp 7fff068c9ef8 error d Signed-off-by: Peter Hurley pe...@hurleysoftware.com --- arch/x86/kernel/pvclock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c index 85c3959..2cb9470 100644 --- a/arch/x86/kernel/pvclock.c +++ b/arch/x86/kernel/pvclock.c @@ -185,7 +185,7 @@ int __init pvclock_init_vsyscall(struct pvclock_vsyscall_time_info *i, for (idx = 0; idx = (PVCLOCK_FIXMAP_END-PVCLOCK_FIXMAP_BEGIN); idx++) { __set_fixmap(PVCLOCK_FIXMAP_BEGIN + idx, -__pa_symbol(i) + (idx*PAGE_SIZE), +__pa(i) + (idx*PAGE_SIZE), PAGE_KERNEL_VVAR); } -- 1.8.1.2 -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] kvm-unit-test: more documentation and runner script
On Wed, Feb 27, 2013 at 03:10:01PM -0300, Lucas Meneghel Rodrigues wrote: On 02/27/2013 12:55 PM, Michael S. Tsirkin wrote: Add documentation about using qemu-system for unit tests. Add runner script to select the correct binary and flags. Signed-off-by: Michael S. Tsirkin m...@redhat.com --- README | 10 +- x86-run | 27 +++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100755 x86-run diff --git a/README b/README index 4ceb869..214397c 100644 --- a/README +++ b/README @@ -10,10 +10,18 @@ To create the tests' images just type 'make' in this directory. Tests' images created in ./ARCH/*.flat An example of a test invocation: -qemu-system-x86_64 -device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out -serial stdio -kernel ./x86/msr.flat +Using qemu-kvm: + +qemu-kvm -device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out -serial stdio -kernel ./x86/msr.flat This invocation runs the msr test case. The test outputs to stdio. +Using qemu (supported since qemu 1.3): +qemu-system-x86_64 -enable-kvm -device pc-testdev -serial stdio -device isa-debug-exit,iobase=0xf4,iosize=0x4 -kernel ./x86/msr.flat I think it is worth here to point out that with new qemu, after the unittest is done, the exit status of qemu is 1, different from the 'old style', whose exit status in successful completion is 0. +Or use a runner script to detect the correct invocation: +./x86-run ./x86/msr.flat +To select a specific qemu binary, specify the QEMU=path environment: +QEMU=/tmp/qemu/x86_64-softmmu/qemu-system-x86_64 ./x86-run ./x86/msr.flat Directory structure: .: Makefile and config files for the tests diff --git a/x86-run b/x86-run new file mode 100755 index 000..cf1d38a --- /dev/null +++ b/x86-run @@ -0,0 +1,27 @@ +#!/usr/bin/bash + +qemukvm=${QEMU:-qemu-kvm} +qemusystem=${QEMU:-qemu-system-x86_64} +if +${qemukvm} -device '?' 21 | fgrep -e \testdev\ -e \pc-testdev\ /dev/null; +then +qemu=${qemukvm} +else +if +${qemsystem} -device '?' 21 | fgrep -e \testdev\ -e \pc-testdev\ /dev/null; +then +qemu=${qemusystem} +else +echo QEMU binary ${QEMU} has no support for test device. Exiting. +exit 1 +fi +fi + +if +${qemu} -device '?' 21 | fgrep pc-testdev /dev/null; +then +command=${qemu} -enable-kvm -device pc-testdev -serial stdio -device isa-debug-exit,iobase=0xf4,iosize=0x4 -kernel +else +command=${qemu} -device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out -serial stdio -kernel ./x86/msr.flat +fi +exec ${command} $@ ^ What about checking the exit status of qemu here and print something like test $@ PASS or test $@ FAIL? How do we know how to interpret it? Overall I think it's best to rely on test output than on return status. -- MST -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] kvm-unit-test: more documentation and runner script
On 02/27/2013 05:44 PM, Michael S. Tsirkin wrote: +Using qemu (supported since qemu 1.3): +qemu-system-x86_64 -enable-kvm -device pc-testdev -serial stdio -device isa-debug-exit,iobase=0xf4,iosize=0x4 -kernel ./x86/msr.flat I think it is worth here to point out that with new qemu, after the unittest is done, the exit status of qemu is 1, different from the 'old style', whose exit status in successful completion is 0. ^ comment above +exec ${command} $@ ^ What about checking the exit status of qemu here and print something like test $@ PASS or test $@ FAIL? How do we know how to interpret it? Overall I think it's best to rely on test output than on return status. See comment above. Well, test output may be good for humans, but it is really not good for machines [1], that's why when the test suite was developed, the convention was to make qemu to exit with a given return code on success and others on failure. Anyway, it was just a suggestion, feel free to disregard it. [1] having to parse the output and try to guess what is a pass or fail is a mess at best, and should be avoided unless we positively have no saner way of doing it. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] kvm-unit-test: more documentation and runner script
On Wed, Feb 27, 2013 at 06:03:41PM -0300, Lucas Meneghel Rodrigues wrote: On 02/27/2013 05:44 PM, Michael S. Tsirkin wrote: +Using qemu (supported since qemu 1.3): +qemu-system-x86_64 -enable-kvm -device pc-testdev -serial stdio -device isa-debug-exit,iobase=0xf4,iosize=0x4 -kernel ./x86/msr.flat I think it is worth here to point out that with new qemu, after the unittest is done, the exit status of qemu is 1, different from the 'old style', whose exit status in successful completion is 0. ^ comment above +exec ${command} $@ ^ What about checking the exit status of qemu here and print something like test $@ PASS or test $@ FAIL? How do we know how to interpret it? Overall I think it's best to rely on test output than on return status. See comment above. Well, test output may be good for humans, but it is really not good for machines [1], that's why when the test suite was developed, the convention was to make qemu to exit with a given return code on success and others on failure. Right but given a qemu binary, how do I find out what it is on success and what it is on failure? Anyway, it was just a suggestion, feel free to disregard it. [1] having to parse the output and try to guess what is a pass or fail is a mess at best, and should be avoided unless we positively have no saner way of doing it. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
How well does KVM connect a physical drive to the VM?
I have a program which I need to run against a pile of drives. The program needs to boot to a dedicated machine and will only do one drive at a time, and I only have one machine I can tie up to use dedicated, making it a very slow process and requiring a manual drive change when the program is done poking in the SMART firmware. I also have a 4 bay eSATA box and an evil thought, I could do this in a VM, many VMs perhaps, if KVM really lets the VM see the drive. I propose to do something like this: qemu-kvm -m 600 -hda /dev/sdi -cdron diskfiddle.iso -boot d Before I try this I'd like an opinion, because while I can hot swap drives in the external enclosure, the enclosure warns against connecting to a powered computer, so I have to take a downtime. Thanks for any educated opinions. -- Bill Davidsen david...@tmr.com We are not out of the woods yet, but we know the direction and have taken the first step. The steps are many, but finite in number, and if we persevere we will reach our destination. -me, 2010 -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 0/6] KVM: Clean up and optimize set_memory_region() - part2
On Wed, 27 Feb 2013 18:23:45 +0200 Gleb Natapov g...@redhat.com wrote: On Wed, Feb 27, 2013 at 07:41:03PM +0900, Takuya Yoshikawa wrote: Note: this is based on the latest master branch. I'm sending this before 3.9-rc1 is released since this can cause extra conflicts unless we make this available to all arch before we start adding new stuff. I do not quite sure what you want me to do. Why can't this wait for 3.10? This is for 3.10. Sorry for my confusing explanation. I'd like to let each arch developer know the plan and get requests, if any, to make this the start of the 3.10 development, at least for stuff using set_memory_region related code. I just don't want to make this later in the next development cycle since people tend to queue up their own arch code soon. Thanks, Takuya -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 0/6] KVM: Clean up and optimize set_memory_region() - part2
[ Resending since my email client seemed to fail. ] On Wed, 27 Feb 2013 18:23:45 +0200 Gleb Natapov g...@redhat.com wrote: On Wed, Feb 27, 2013 at 07:41:03PM +0900, Takuya Yoshikawa wrote: Note: this is based on the latest master branch. I'm sending this before 3.9-rc1 is released since this can cause extra conflicts unless we make this available to all arch before we start adding new stuff. I do not quite sure what you want me to do. Why can't this wait for 3.10? Sorry for my confusing explanation. This is exactly for 3.10. I'd like to let the maintainers of arch code know the plan and make them prepared for the possible changes for the next development cycle. It would be nice if this won't make it difficult to sync later: people tend to queue up their own code soon. Thanks, Takuya -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 0/6] KVM: Clean up and optimize set_memory_region() - part2
On Wed, Feb 27, 2013 at 07:41:03PM +0900, Takuya Yoshikawa wrote: Note: this is based on the latest master branch. I'm sending this before 3.9-rc1 is released since this can cause extra conflicts unless we make this available to all arch before we start adding new stuff. Please review: every change is trivial and should not change anything. Takuya Yoshikawa (6): KVM: set_memory_region: Drop user_alloc from prepare/commit_memory_region() KVM: set_memory_region: Drop user_alloc from set_memory_region() KVM: set_memory_region: Make kvm_mr_change available to arch code KVM: set_memory_region: Refactor prepare_memory_region() KVM: set_memory_region: Refactor commit_memory_region() KVM: ARM: Remove kvm_arch_set_memory_region() arch/arm/kvm/arm.c | 15 ++-- arch/ia64/kvm/kvm-ia64.c | 25 ++--- arch/powerpc/include/asm/kvm_ppc.h |2 +- arch/powerpc/kvm/book3s_hv.c |4 +- arch/powerpc/kvm/book3s_pr.c |2 +- arch/powerpc/kvm/booke.c |2 +- arch/powerpc/kvm/powerpc.c | 13 +-- arch/s390/kvm/kvm-s390.c | 10 ++-- arch/x86/kvm/vmx.c |6 ++-- arch/x86/kvm/x86.c | 25 + include/linux/kvm_host.h | 35 +- virt/kvm/kvm_main.c| 40 --- 12 files changed, 67 insertions(+), 112 deletions(-) -- 1.7.4.1 Reviewed-by: Marcelo Tosatti mtosa...@redhat.com -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: virtio-rng only returns zeros with CONFIG_HW_RANDOM=m
Jens Axboe ax...@kernel.dk writes: On Wed, Feb 27 2013, Rusty Russell wrote: Subject: scatterlist: sg_set_buf() argument must be in linear mapping. Signed-off-by: Rusty Russell ru...@rustcorp.com.au diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index 4bd6c06..9365375 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -111,6 +111,9 @@ static inline struct page *sg_page(struct scatterlist *sg) static inline void sg_set_buf(struct scatterlist *sg, const void *buf, unsigned int buflen) { +#ifdef CONFIG_DEBUG_SG +BUG_ON(!virt_addr_valid(buf)); +#endif sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf)); } Looks good to me, in lieu of being able to return an error. Want me to queue it up? Please... it'll catch me the next time I make the same mistake :) (Though the static-definitions-in-modules-on-most-archs is a pretty nasty corner case). Thanks, Rusty. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: virtio-rng only returns zeros with CONFIG_HW_RANDOM=m
Aurelien Jarno aurel...@aurel32.net writes: On Wed, Feb 27, 2013 at 11:56:55AM +1030, Rusty Russell wrote: Aurelien Jarno aurel...@aurel32.net writes: Hi, I have noticed that virtio-rng only returns zero for kernels = 2.6.33 built with CONFIG_HW_RANDOM=m. This is a bit much too predictable for a random generator ;-). The reason for that is virtio expects guest real addresses, while rng_core.ko (ie when built as a module) is passing a vmalloced buffer to the virtio-rng read function, declared as such: static u8 rng_buffer[SMP_CACHE_BYTES 32 ? 32 : SMP_CACHE_BYTES] __cacheline_aligned; This is basically the same issue than the following one: https://lists.linux-foundation.org/pipermail/virtualization/2008-May/010946.html but introduced in a more subtle way in this commit: commit bb347d98079a547e80bd4722dee1de61e4dca0e8 Author: Ian Molton ian.mol...@collabora.co.uk Date: Tue Dec 1 15:26:33 2009 +0800 OK, I looked at doing a kmalloc and copy in virtio_rng, but it's very inelegant (we don't know what size of buffer to allocate). On the other hand, the rng API allows to return less bytes than requested, so it's possible to have a fixed buffer size of for example 64 or 128 bytes. But I agree it's better to do that in rng core. That's true, too. I'd really like Ian's feedback, since he was the one who made the change, but the previous email address bounced. Trying again... hw_random: make buffer usable in scatterlist. virtio_rng feeds the randomness buffer handed by the core directly into the scatterlist, since commit bb347d98079a547e80bd4722dee1de61e4dca0e8. However, if CONFIG_HW_RANDOM=m, the static buffer isn't a linear address (at least on most archs). We could fix this in virtio_rng, but it's actually far easier to just do it in the core as virtio_rng would have to allocate a buffer every time (it doesn't know how much the core will want to read). Reported-by: Aurelien Jarno aurel...@aurel32.net Tested-by: Aurelien Jarno aurel...@aurel32.net Signed-off-by: Rusty Russell ru...@rustcorp.com.au diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c index 1bafb40..69ae597 100644 --- a/drivers/char/hw_random/core.c +++ b/drivers/char/hw_random/core.c @@ -40,6 +40,7 @@ #include linux/init.h #include linux/miscdevice.h #include linux/delay.h +#include linux/slab.h #include asm/uaccess.h @@ -52,8 +53,12 @@ static struct hwrng *current_rng; static LIST_HEAD(rng_list); static DEFINE_MUTEX(rng_mutex); static int data_avail; -static u8 rng_buffer[SMP_CACHE_BYTES 32 ? 32 : SMP_CACHE_BYTES] - __cacheline_aligned; +static u8 *rng_buffer; + +static size_t rng_buffer_size(void) +{ + return SMP_CACHE_BYTES 32 ? 32 : SMP_CACHE_BYTES; +} static inline int hwrng_init(struct hwrng *rng) { @@ -116,7 +121,7 @@ static ssize_t rng_dev_read(struct file *filp, char __user *buf, if (!data_avail) { bytes_read = rng_get_data(current_rng, rng_buffer, - sizeof(rng_buffer), + rng_buffer_size(), !(filp-f_flags O_NONBLOCK)); if (bytes_read 0) { err = bytes_read; @@ -307,6 +312,14 @@ int hwrng_register(struct hwrng *rng) mutex_lock(rng_mutex); + /* kmalloc makes this safe for virt_to_page() in virtio_rng.c */ + err = -ENOMEM; + if (!rng_buffer) { + rng_buffer = kmalloc(rng_buffer_size(), GFP_KERNEL); + if (!rng_buffer) + goto out_unlock; + } + /* Must not register two RNGs with the same name. */ err = -EEXIST; list_for_each_entry(tmp, rng_list, list) { -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 0/7] KVM :PPC: Userspace Debug support
This patchset adds the userspace debug support for booke/bookehv. this is tested on powerpc e500v2/e500mc devices. Bharat Bhushan (7): KVM: PPC: booke: Added debug handler Added ONE_REG interface for debug instruction KVM: PPC: debug stub interface parameter defined booke: Save and restore debug registers on guest entry and exit bookehv: Save and restore debug registers on guest entry and exit Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER KVM: PPC: Add userspace debug stub support Documentation/virtual/kvm/api.txt |1 + arch/powerpc/include/asm/kvm_book3s.h |1 + arch/powerpc/include/asm/kvm_booke.h |2 + arch/powerpc/include/asm/kvm_host.h |6 ++ arch/powerpc/include/asm/kvm_ppc.h|2 +- arch/powerpc/include/uapi/asm/kvm.h | 41 + arch/powerpc/kernel/asm-offsets.c | 27 ++ arch/powerpc/kvm/book3s.c | 12 +++ arch/powerpc/kvm/book3s_emulate.c |2 +- arch/powerpc/kvm/book3s_pr.c |2 +- arch/powerpc/kvm/booke.c | 153 +--- arch/powerpc/kvm/booke_interrupts.S | 156 - arch/powerpc/kvm/bookehv_interrupts.S | 145 +- arch/powerpc/kvm/e500_emulate.c |6 ++ arch/powerpc/kvm/e500mc.c |3 +- arch/powerpc/kvm/powerpc.c|6 -- 16 files changed, 535 insertions(+), 30 deletions(-) -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 4/7] booke: Save and restore debug registers on guest entry and exit
On Guest entry: if guest is wants to use the debug register then save h/w debug register in host_dbg_reg and load the debug registers with shadow_dbg_reg. Otherwise leave h/w debug registers as is. On guest exit: If guest/user-space is using the debug resource then restore the h/w debug register with host_dbg_reg. No need to save guest debug register as shadow_dbg_reg is having required values. If guest is not using the debug resources then no need to restore h/w registers. Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com --- arch/powerpc/include/asm/kvm_host.h |5 ++ arch/powerpc/kernel/asm-offsets.c | 26 arch/powerpc/kvm/booke_interrupts.S | 114 +++ 3 files changed, 145 insertions(+), 0 deletions(-) diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index f4ba881..a9feeb0 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h @@ -504,7 +504,12 @@ struct kvm_vcpu_arch { u32 mmucfg; u32 epr; u32 crit_save; + /* guest debug registers*/ struct kvmppc_booke_debug_reg dbg_reg; + /* shadow debug registers */ + struct kvmppc_booke_debug_reg shadow_dbg_reg; + /* host debug registers*/ + struct kvmppc_booke_debug_reg host_dbg_reg; #endif gpa_t paddr_accessed; gva_t vaddr_accessed; diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c index 02048f3..22deda7 100644 --- a/arch/powerpc/kernel/asm-offsets.c +++ b/arch/powerpc/kernel/asm-offsets.c @@ -563,6 +563,32 @@ int main(void) DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear)); DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu, arch.fault_esr)); DEFINE(VCPU_CRIT_SAVE, offsetof(struct kvm_vcpu, arch.crit_save)); + DEFINE(VCPU_DBSR, offsetof(struct kvm_vcpu, arch.dbsr)); + DEFINE(VCPU_SHADOW_DBG, offsetof(struct kvm_vcpu, arch.shadow_dbg_reg)); + DEFINE(VCPU_HOST_DBG, offsetof(struct kvm_vcpu, arch.host_dbg_reg)); + DEFINE(KVMPPC_DBG_DBCR0, offsetof(struct kvmppc_booke_debug_reg, + dbcr0)); + DEFINE(KVMPPC_DBG_DBCR1, offsetof(struct kvmppc_booke_debug_reg, + dbcr1)); + DEFINE(KVMPPC_DBG_DBCR2, offsetof(struct kvmppc_booke_debug_reg, + dbcr2)); +#ifdef CONFIG_KVM_E500MC + DEFINE(KVMPPC_DBG_DBCR4, offsetof(struct kvmppc_booke_debug_reg, + dbcr4)); +#endif + DEFINE(KVMPPC_DBG_IAC1, offsetof(struct kvmppc_booke_debug_reg, +iac[0])); + DEFINE(KVMPPC_DBG_IAC2, offsetof(struct kvmppc_booke_debug_reg, +iac[1])); + DEFINE(KVMPPC_DBG_IAC3, offsetof(struct kvmppc_booke_debug_reg, +iac[2])); + DEFINE(KVMPPC_DBG_IAC4, offsetof(struct kvmppc_booke_debug_reg, +iac[3])); + DEFINE(KVMPPC_DBG_DAC1, offsetof(struct kvmppc_booke_debug_reg, +dac[0])); + DEFINE(KVMPPC_DBG_DAC2, offsetof(struct kvmppc_booke_debug_reg, +dac[1])); + DEFINE(VCPU_GUEST_DEBUG, offsetof(struct kvm_vcpu, guest_debug)); #endif /* CONFIG_PPC_BOOK3S */ #endif /* CONFIG_KVM */ diff --git a/arch/powerpc/kvm/booke_interrupts.S b/arch/powerpc/kvm/booke_interrupts.S index 2c6deb5..6d78e01 100644 --- a/arch/powerpc/kvm/booke_interrupts.S +++ b/arch/powerpc/kvm/booke_interrupts.S @@ -39,6 +39,8 @@ #define HOST_MIN_STACK_SIZE (HOST_NV_GPR(R31) + 4) #define HOST_STACK_SIZE (((HOST_MIN_STACK_SIZE + 15) / 16) * 16) /* Align. */ #define HOST_STACK_LR (HOST_STACK_SIZE + 4) /* In caller stack frame. */ +#define DBCR0_AC_BITS (DBCR0_IAC1 | DBCR0_IAC2 | DBCR0_IAC3 | DBCR0_IAC4 | \ +DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W) #define NEED_INST_MASK ((1BOOKE_INTERRUPT_PROGRAM) | \ (1BOOKE_INTERRUPT_DTLB_MISS) | \ @@ -54,6 +56,8 @@ (1BOOKE_INTERRUPT_DTLB_MISS) | \ (1BOOKE_INTERRUPT_ALIGNMENT)) +#define NEED_DEBUG_SAVE (1BOOKE_INTERRUPT_DEBUG) + .macro __KVM_HANDLER ivor_nr scratch srr0 /* Get pointer to vcpu and record exit number. */ mtspr \scratch , r4 @@ -215,6 +219,59 @@ _GLOBAL(kvmppc_resume_host) stw r9, VCPU_FAULT_ESR(r4) ..skip_esr: + lwz r9, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR0(r4) + rlwinm. r8, r9, 0, ~DBCR0_IDM + beq skip_load_host_debug + lwz r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR0(r4) + andis. r9, r9, DBCR0_AC_BITS@h + li r9, 0 + mtspr SPRN_DBCR0, r9 /* disable all debug event */ + beq skip_load_hw_bkpts + lwz r7,
[PATCH 3/7] KVM: PPC: debug stub interface parameter defined
This patch defines the interface parameter for KVM_SET_GUEST_DEBUG ioctl support. Follow up patches will use this for setting up hardware breakpoints, watchpoints and software breakpoints. Also kvm_arch_vcpu_ioctl_set_guest_debug() is brought one level below. This is because I am not sure what is required for book3s. So this ioctl behaviour will not change for book3s. Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com --- arch/powerpc/include/uapi/asm/kvm.h | 23 +++ arch/powerpc/kvm/book3s.c |6 ++ arch/powerpc/kvm/booke.c|6 ++ arch/powerpc/kvm/powerpc.c |6 -- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/include/uapi/asm/kvm.h b/arch/powerpc/include/uapi/asm/kvm.h index c2ff99c..15f9a00 100644 --- a/arch/powerpc/include/uapi/asm/kvm.h +++ b/arch/powerpc/include/uapi/asm/kvm.h @@ -272,8 +272,31 @@ struct kvm_debug_exit_arch { /* for KVM_SET_GUEST_DEBUG */ struct kvm_guest_debug_arch { + struct { + /* H/W breakpoint/watchpoint address */ + __u64 addr; + /* +* Type denotes h/w breakpoint, read watchpoint, write +* watchpoint or watchpoint (both read and write). +*/ +#define KVMPPC_DEBUG_NOTYPE0x0 +#define KVMPPC_DEBUG_BREAKPOINT(1UL 1) +#define KVMPPC_DEBUG_WATCH_WRITE (1UL 2) +#define KVMPPC_DEBUG_WATCH_READ(1UL 3) + __u32 type; + __u32 reserved; + } bp[16]; }; +/* Debug related defines */ +/* + * kvm_guest_debug-control is a 32 bit field. The lower 16 bits are generic + * and upper 16 bits are architecture specific. Architecture specific defines + * that ioctl is for setting hardware breakpoint or software breakpoint. + */ +#define KVM_GUESTDBG_USE_SW_BP 0x0001 +#define KVM_GUESTDBG_USE_HW_BP 0x0002 + /* definition of registers in kvm_run */ struct kvm_sync_regs { }; diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c index 975a401..cb85d73 100644 --- a/arch/powerpc/kvm/book3s.c +++ b/arch/powerpc/kvm/book3s.c @@ -613,6 +613,12 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, return 0; } +int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, + struct kvm_guest_debug *dbg) +{ + return -EINVAL; +} + void kvmppc_decrementer_func(unsigned long data) { struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data; diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index a41cd6d..1de93a8 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -1527,6 +1527,12 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) return r; } +int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, +struct kvm_guest_debug *dbg) +{ + return -EINVAL; +} + int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) { return -ENOTSUPP; diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 934413c..4c94ca9 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -532,12 +532,6 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) #endif } -int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, -struct kvm_guest_debug *dbg) -{ - return -EINVAL; -} - static void kvmppc_complete_dcr_load(struct kvm_vcpu *vcpu, struct kvm_run *run) { -- 1.7.0.4 -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/7] Added ONE_REG interface for debug instruction
This patch adds the one_reg interface to get the special instruction to be used for setting software breakpoint from userspace. Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com --- Documentation/virtual/kvm/api.txt |1 + arch/powerpc/include/asm/kvm_book3s.h |1 + arch/powerpc/include/asm/kvm_booke.h |2 ++ arch/powerpc/include/uapi/asm/kvm.h |4 arch/powerpc/kvm/book3s.c |6 ++ arch/powerpc/kvm/booke.c |6 ++ 6 files changed, 20 insertions(+), 0 deletions(-) diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt index cce500a..dbfcc04 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt @@ -1766,6 +1766,7 @@ registers, find a list below: PPC | KVM_REG_PPC_TSR | 32 PPC | KVM_REG_PPC_OR_TSR | 32 PPC | KVM_REG_PPC_CLEAR_TSR| 32 + PPC | KVM_REG_PPC_DEBUG_INST| 32 4.69 KVM_GET_ONE_REG diff --git a/arch/powerpc/include/asm/kvm_book3s.h b/arch/powerpc/include/asm/kvm_book3s.h index 5a56e1c..36164cc 100644 --- a/arch/powerpc/include/asm/kvm_book3s.h +++ b/arch/powerpc/include/asm/kvm_book3s.h @@ -458,6 +458,7 @@ static inline bool kvmppc_critical_section(struct kvm_vcpu *vcpu) #define OSI_SC_MAGIC_R40x77810F9B #define INS_DCBZ 0x7c0007ec +#define INS_TW 0x7c08 /* LPIDs we support with this build -- runtime limit may be lower */ #define KVMPPC_NR_LPIDS(LPID_RSVD + 1) diff --git a/arch/powerpc/include/asm/kvm_booke.h b/arch/powerpc/include/asm/kvm_booke.h index b7cd335..d3c1eb3 100644 --- a/arch/powerpc/include/asm/kvm_booke.h +++ b/arch/powerpc/include/asm/kvm_booke.h @@ -26,6 +26,8 @@ /* LPIDs we support with this build -- runtime limit may be lower */ #define KVMPPC_NR_LPIDS64 +#define KVMPPC_INST_EHPRIV 0x7c00021c + static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val) { vcpu-arch.gpr[num] = val; diff --git a/arch/powerpc/include/uapi/asm/kvm.h b/arch/powerpc/include/uapi/asm/kvm.h index ef072b1..c2ff99c 100644 --- a/arch/powerpc/include/uapi/asm/kvm.h +++ b/arch/powerpc/include/uapi/asm/kvm.h @@ -422,4 +422,8 @@ struct kvm_get_htab_header { #define KVM_REG_PPC_CLEAR_TSR (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x88) #define KVM_REG_PPC_TCR(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x89) #define KVM_REG_PPC_TSR(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x8a) + +/* Debugging: Special instruction for software breakpoint */ +#define KVM_REG_PPC_DEBUG_INST (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x8b) + #endif /* __LINUX_KVM_POWERPC_H */ diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c index a4b6452..975a401 100644 --- a/arch/powerpc/kvm/book3s.c +++ b/arch/powerpc/kvm/book3s.c @@ -530,6 +530,12 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) val = get_reg_val(reg-id, vcpu-arch.vscr.u[3]); break; #endif /* CONFIG_ALTIVEC */ + case KVM_REG_PPC_DEBUG_INST: { + u32 opcode = INS_TW; + r = copy_to_user((u32 __user *)(long)reg-addr, +opcode, sizeof(u32)); + break; + } default: r = -EINVAL; break; diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index 8b553c0..a41cd6d 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -1448,6 +1448,12 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) case KVM_REG_PPC_TSR: r = put_user(vcpu-arch.tsr, (u32 __user *)(long)reg-addr); break; + case KVM_REG_PPC_DEBUG_INST: { + u32 opcode = KVMPPC_INST_EHPRIV; + r = copy_to_user((u32 __user *)(long)reg-addr, +opcode, sizeof(u32)); + break; + } default: break; } -- 1.7.0.4 -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/7] KVM: PPC: booke: Added debug handler
Installed debug handler will be used for guest debug support and debug facility emulation features (patches for these features will follow this patch). Signed-off-by: Liu Yu yu@freescale.com [bharat.bhus...@freescale.com: Substantial changes] Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com --- arch/powerpc/include/asm/kvm_host.h |1 + arch/powerpc/kernel/asm-offsets.c |1 + arch/powerpc/kvm/booke_interrupts.S | 42 -- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index 8a72d59..f4ba881 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h @@ -503,6 +503,7 @@ struct kvm_vcpu_arch { u32 tlbcfg[4]; u32 mmucfg; u32 epr; + u32 crit_save; struct kvmppc_booke_debug_reg dbg_reg; #endif gpa_t paddr_accessed; diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c index 46f6afd..02048f3 100644 --- a/arch/powerpc/kernel/asm-offsets.c +++ b/arch/powerpc/kernel/asm-offsets.c @@ -562,6 +562,7 @@ int main(void) DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, arch.last_inst)); DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear)); DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu, arch.fault_esr)); + DEFINE(VCPU_CRIT_SAVE, offsetof(struct kvm_vcpu, arch.crit_save)); #endif /* CONFIG_PPC_BOOK3S */ #endif /* CONFIG_KVM */ diff --git a/arch/powerpc/kvm/booke_interrupts.S b/arch/powerpc/kvm/booke_interrupts.S index f4bb55c..2c6deb5 100644 --- a/arch/powerpc/kvm/booke_interrupts.S +++ b/arch/powerpc/kvm/booke_interrupts.S @@ -54,8 +54,7 @@ (1BOOKE_INTERRUPT_DTLB_MISS) | \ (1BOOKE_INTERRUPT_ALIGNMENT)) -.macro KVM_HANDLER ivor_nr scratch srr0 -_GLOBAL(kvmppc_handler_\ivor_nr) +.macro __KVM_HANDLER ivor_nr scratch srr0 /* Get pointer to vcpu and record exit number. */ mtspr \scratch , r4 mfspr r4, SPRN_SPRG_THREAD @@ -76,6 +75,43 @@ _GLOBAL(kvmppc_handler_\ivor_nr) bctr .endm +.macro KVM_HANDLER ivor_nr scratch srr0 +_GLOBAL(kvmppc_handler_\ivor_nr) + __KVM_HANDLER \ivor_nr \scratch \srr0 +.endm + +.macro KVM_DBG_HANDLER ivor_nr scratch srr0 +_GLOBAL(kvmppc_handler_\ivor_nr) + mtspr \scratch, r4 + mfspr r4, SPRN_SPRG_THREAD + lwz r4, THREAD_KVM_VCPU(r4) + stw r3, VCPU_CRIT_SAVE(r4) + mfcrr3 + mfspr r4, SPRN_CSRR1 + andi. r4, r4, MSR_PR + bne 1f + /* debug interrupt happened in enter/exit path */ + mfspr r4, SPRN_CSRR1 + rlwinm r4, r4, 0, ~MSR_DE + mtspr SPRN_CSRR1, r4 + lis r4, 0x + ori r4, r4, 0x + mtspr SPRN_DBSR, r4 + mfspr r4, SPRN_SPRG_THREAD + lwz r4, THREAD_KVM_VCPU(r4) + mtcrr3 + lwz r3, VCPU_CRIT_SAVE(r4) + mfspr r4, \scratch + rfci +1: /* debug interrupt happened in guest */ + mtcrr3 + mfspr r4, SPRN_SPRG_THREAD + lwz r4, THREAD_KVM_VCPU(r4) + lwz r3, VCPU_CRIT_SAVE(r4) + mfspr r4, \scratch + __KVM_HANDLER \ivor_nr \scratch \srr0 +.endm + .macro KVM_HANDLER_ADDR ivor_nr .long kvmppc_handler_\ivor_nr .endm @@ -100,7 +136,7 @@ KVM_HANDLER BOOKE_INTERRUPT_FIT SPRN_SPRG_RSCRATCH0 SPRN_SRR0 KVM_HANDLER BOOKE_INTERRUPT_WATCHDOG SPRN_SPRG_RSCRATCH_CRIT SPRN_CSRR0 KVM_HANDLER BOOKE_INTERRUPT_DTLB_MISS SPRN_SPRG_RSCRATCH0 SPRN_SRR0 KVM_HANDLER BOOKE_INTERRUPT_ITLB_MISS SPRN_SPRG_RSCRATCH0 SPRN_SRR0 -KVM_HANDLER BOOKE_INTERRUPT_DEBUG SPRN_SPRG_RSCRATCH_CRIT SPRN_CSRR0 +KVM_DBG_HANDLER BOOKE_INTERRUPT_DEBUG SPRN_SPRG_RSCRATCH_CRIT SPRN_CSRR0 KVM_HANDLER BOOKE_INTERRUPT_SPE_UNAVAIL SPRN_SPRG_RSCRATCH0 SPRN_SRR0 KVM_HANDLER BOOKE_INTERRUPT_SPE_FP_DATA SPRN_SPRG_RSCRATCH0 SPRN_SRR0 KVM_HANDLER BOOKE_INTERRUPT_SPE_FP_ROUND SPRN_SPRG_RSCRATCH0 SPRN_SRR0 -- 1.7.0.4 -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 7/7] KVM: PPC: Add userspace debug stub support
This patch adds the debug stub support on booke/bookehv. Now QEMU debug stub can use hw breakpoint, watchpoint and software breakpoint to debug guest. Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com --- arch/powerpc/include/uapi/asm/kvm.h | 22 +- arch/powerpc/kvm/booke.c| 143 +++--- arch/powerpc/kvm/e500_emulate.c |6 ++ arch/powerpc/kvm/e500mc.c |3 +- 4 files changed, 155 insertions(+), 19 deletions(-) diff --git a/arch/powerpc/include/uapi/asm/kvm.h b/arch/powerpc/include/uapi/asm/kvm.h index 15f9a00..d7ce449 100644 --- a/arch/powerpc/include/uapi/asm/kvm.h +++ b/arch/powerpc/include/uapi/asm/kvm.h @@ -25,6 +25,7 @@ /* Select powerpc specific features in linux/kvm.h */ #define __KVM_HAVE_SPAPR_TCE #define __KVM_HAVE_PPC_SMT +#define __KVM_HAVE_GUEST_DEBUG struct kvm_regs { __u64 pc; @@ -267,7 +268,24 @@ struct kvm_fpu { __u64 fpr[32]; }; +/* + * Defines for h/w breakpoint, watchpoint (read, write or both) and + * software breakpoint. + * These are used as type in KVM_SET_GUEST_DEBUG ioctl and status + * for KVM_DEBUG_EXIT. + */ +#define KVMPPC_DEBUG_NONE 0x0 +#define KVMPPC_DEBUG_BREAKPOINT(1UL 1) +#define KVMPPC_DEBUG_WATCH_WRITE (1UL 2) +#define KVMPPC_DEBUG_WATCH_READ(1UL 3) struct kvm_debug_exit_arch { + __u64 address; + /* +* exiting to userspace because of h/w breakpoint, watchpoint +* (read, write or both) and software breakpoint. +*/ + __u32 status; + __u32 reserved; }; /* for KVM_SET_GUEST_DEBUG */ @@ -279,10 +297,6 @@ struct kvm_guest_debug_arch { * Type denotes h/w breakpoint, read watchpoint, write * watchpoint or watchpoint (both read and write). */ -#define KVMPPC_DEBUG_NOTYPE0x0 -#define KVMPPC_DEBUG_BREAKPOINT(1UL 1) -#define KVMPPC_DEBUG_WATCH_WRITE (1UL 2) -#define KVMPPC_DEBUG_WATCH_READ(1UL 3) __u32 type; __u32 reserved; } bp[16]; diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index 1de93a8..21b0313 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -133,6 +133,30 @@ static void kvmppc_vcpu_sync_fpu(struct kvm_vcpu *vcpu) #endif } +static void kvmppc_vcpu_sync_debug(struct kvm_vcpu *vcpu) +{ + /* Synchronize guest's desire to get debug interrupts into shadow MSR */ +#ifndef CONFIG_KVM_BOOKE_HV + vcpu-arch.shadow_msr = ~MSR_DE; + vcpu-arch.shadow_msr |= vcpu-arch.shared-msr MSR_DE; +#endif + + /* Force enable debug interrupts when user space wants to debug */ + if (vcpu-guest_debug) { +#ifdef CONFIG_KVM_BOOKE_HV + /* +* Since there is no shadow MSR, sync MSR_DE into the guest +* visible MSR. Do not allow guest to change MSR[DE]. +*/ + vcpu-arch.shared-msr |= MSR_DE; + mtspr(SPRN_MSRP, mfspr(SPRN_MSRP) | MSRP_DEP); +#else + vcpu-arch.shadow_msr |= MSR_DE; + vcpu-arch.shared-msr = ~MSR_DE; +#endif + } +} + /* * Helper function for full MSR writes. No need to call this if only * EE/CE/ME/DE/RI are changing. @@ -150,6 +174,7 @@ void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr) kvmppc_mmu_msr_notify(vcpu, old_msr); kvmppc_vcpu_sync_spe(vcpu); kvmppc_vcpu_sync_fpu(vcpu); + kvmppc_vcpu_sync_debug(vcpu); } static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, @@ -736,6 +761,13 @@ static int emulation_exit(struct kvm_run *run, struct kvm_vcpu *vcpu) run-exit_reason = KVM_EXIT_DCR; return RESUME_HOST; + case EMULATE_EXIT_USER: + run-exit_reason = KVM_EXIT_DEBUG; + run-debug.arch.address = vcpu-arch.pc; + run-debug.arch.status = 0; + kvmppc_account_exit(vcpu, DEBUG_EXITS); + return RESUME_HOST; + case EMULATE_FAIL: printk(KERN_CRIT %s: emulation at %lx failed (%08x)\n, __func__, vcpu-arch.pc, vcpu-arch.last_inst); @@ -751,6 +783,28 @@ static int emulation_exit(struct kvm_run *run, struct kvm_vcpu *vcpu) } } +static int kvmppc_handle_debug(struct kvm_run *run, struct kvm_vcpu *vcpu) +{ + u32 dbsr = vcpu-arch.dbsr; + run-debug.arch.status = 0; + run-debug.arch.address = vcpu-arch.pc; + + if (dbsr (DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4)) { + run-debug.arch.status |= KVMPPC_DEBUG_BREAKPOINT; + } else { + if (dbsr (DBSR_DAC1W | DBSR_DAC2W)) + run-debug.arch.status |= KVMPPC_DEBUG_WATCH_WRITE; + else if (dbsr (DBSR_DAC1R | DBSR_DAC2R)) + run-debug.arch.status |= KVMPPC_DEBUG_WATCH_READ; + if
[PATCH 6/7] Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER
Instruction emulation return EMULATE_DO_PAPR when it requires exit to userspace on book3s. Similar return is required for booke. EMULATE_DO_PAPR reads out to be confusing so it is renamed to EMULATE_EXIT_USER. Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com --- arch/powerpc/include/asm/kvm_ppc.h |2 +- arch/powerpc/kvm/book3s_emulate.c |2 +- arch/powerpc/kvm/book3s_pr.c |2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h index 44a657a..8b81468 100644 --- a/arch/powerpc/include/asm/kvm_ppc.h +++ b/arch/powerpc/include/asm/kvm_ppc.h @@ -44,7 +44,7 @@ enum emulation_result { EMULATE_DO_DCR, /* kvm_run filled with DCR request */ EMULATE_FAIL, /* can't emulate this instruction */ EMULATE_AGAIN,/* something went wrong. go again */ - EMULATE_DO_PAPR, /* kvm_run filled with PAPR request */ + EMULATE_EXIT_USER,/* emulation requires exit to user-space */ }; extern int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu); diff --git a/arch/powerpc/kvm/book3s_emulate.c b/arch/powerpc/kvm/book3s_emulate.c index 836c569..cdd19d6 100644 --- a/arch/powerpc/kvm/book3s_emulate.c +++ b/arch/powerpc/kvm/book3s_emulate.c @@ -194,7 +194,7 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, run-papr_hcall.args[i] = gpr; } - emulated = EMULATE_DO_PAPR; + emulated = EMULATE_EXIT_USER; break; } #endif diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c index 73ed11c..8df2d2d 100644 --- a/arch/powerpc/kvm/book3s_pr.c +++ b/arch/powerpc/kvm/book3s_pr.c @@ -760,7 +760,7 @@ program_interrupt: run-exit_reason = KVM_EXIT_MMIO; r = RESUME_HOST_NV; break; - case EMULATE_DO_PAPR: + case EMULATE_EXIT_USER: run-exit_reason = KVM_EXIT_PAPR_HCALL; vcpu-arch.hcall_needed = 1; r = RESUME_HOST_NV; -- 1.7.0.4 -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 5/7] bookehv: Save and restore debug registers on guest entry and exit
On Guest entry: if guest is wants to use the debug register then save h/w debug register in host_dbg_reg and load the debug registers with shadow_dbg_reg. Otherwise leave h/w debug registers as is. On guest exit: If guest/user-space is using the debug resource then restore the h/w debug register with host_dbg_reg. No need to save guest debug register as shadow_dbg_reg is having required values. If guest is not using the debug resources then no need to restore h/w registers. Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com --- arch/powerpc/kvm/bookehv_interrupts.S | 145 - 1 files changed, 141 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/kvm/bookehv_interrupts.S b/arch/powerpc/kvm/bookehv_interrupts.S index e8ed7d6..0d830cc 100644 --- a/arch/powerpc/kvm/bookehv_interrupts.S +++ b/arch/powerpc/kvm/bookehv_interrupts.S @@ -62,6 +62,10 @@ #define NEED_EMU 0x0001 /* emulation -- save nv regs */ #define NEED_DEAR 0x0002 /* save faulting DEAR */ #define NEED_ESR 0x0004 /* save faulting ESR */ +#define NEED_DBSR 0x0008 /* save DBSR */ + +#define DBCR0_AC_BITS (DBCR0_IAC1 | DBCR0_IAC2 | DBCR0_IAC3 | DBCR0_IAC4 | \ +DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W) /* * On entry: @@ -201,6 +205,11 @@ PPC_STL r9, VCPU_FAULT_DEAR(r4) .endif + .if \flags NEED_DBSR + mfspr r9, SPRN_DBSR + stw r9, VCPU_DBSR(r4) + .endif + b kvmppc_resume_host .endm @@ -316,9 +325,9 @@ kvm_handler BOOKE_INTERRUPT_GUEST_DBELL, EX_PARAMS(GDBELL), \ kvm_handler BOOKE_INTERRUPT_GUEST_DBELL_CRIT, EX_PARAMS(CRIT), \ SPRN_CSRR0, SPRN_CSRR1, 0 kvm_handler BOOKE_INTERRUPT_DEBUG, EX_PARAMS(DBG), \ - SPRN_DSRR0, SPRN_DSRR1, 0 + SPRN_DSRR0, SPRN_DSRR1, NEED_DBSR kvm_handler BOOKE_INTERRUPT_DEBUG, EX_PARAMS(CRIT), \ - SPRN_CSRR0, SPRN_CSRR1, 0 + SPRN_CSRR0, SPRN_CSRR1, NEED_DBSR #else /* * For input register values, see arch/powerpc/include/asm/kvm_booke_hv_asm.h @@ -411,9 +420,9 @@ kvm_handler BOOKE_INTERRUPT_GUEST_DBELL, SPRN_GSRR0, SPRN_GSRR1, 0 kvm_lvl_handler BOOKE_INTERRUPT_GUEST_DBELL_CRIT, \ SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0 kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \ - SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0 + SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, NEED_DBSR kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \ - SPRN_SPRG_RSCRATCH_DBG, SPRN_DSRR0, SPRN_DSRR1, 0 + SPRN_SPRG_RSCRATCH_DBG, SPRN_DSRR0, SPRN_DSRR1, NEED_DBSR #endif /* Registers: @@ -423,6 +432,56 @@ kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \ * r14: KVM exit number */ _GLOBAL(kvmppc_resume_host) + /* +* If guest not used debug facility then hw debug registers +* already have proper host values. If guest used debug +* facility then restore host debug registers. +* No Need to save guest debug registers as they are already intact +* in guest/shadow registers. +*/ + lwz r9, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR0(r4) + rlwinm. r8, r9, 0, ~DBCR0_IDM + beq skip_load_host_debug + lwz r3, VCPU_HOST_DBG+KVMPPC_DBG_DBCR0(r4) + andis. r9, r9, DBCR0_AC_BITS@h + li r9, 0 + mtspr SPRN_DBCR0, r9 /* disable all debug event */ + beq skip_load_hw_bkpts + lwz r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR1(r4) + lwz r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR2(r4) + lwz r9, VCPU_HOST_DBG+KVMPPC_DBG_DBCR4(r4) + mtspr SPRN_DBCR1, r7 + PPC_LD(r6, VCPU_HOST_DBG+KVMPPC_DBG_IAC1, r4) + PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC2, r4) + mtspr SPRN_DBCR2, r8 + mtspr SPRN_DBCR4, r9 + mtspr SPRN_IAC1, r6 + mtspr SPRN_IAC2, r7 +#if CONFIG_PPC_ADV_DEBUG_IACS 2 + PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC3, r4) + PPC_LD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC4, r4) + mtspr SPRN_IAC3, r7 + mtspr SPRN_IAC4, r8 +#endif + PPC_LD(r8, VCPU_HOST_DBG+KVMPPC_DBG_DAC1, r4) + PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_DAC2, r4) + mtspr SPRN_DAC1, r8 + mtspr SPRN_DAC2, r9 +skip_load_hw_bkpts: + isync + /* Clear h/w DBSR */ + mfspr r8, SPRN_DBSR + mtspr SPRN_DBSR, r8 + isync + /* Clear EPCR.DUVD and set host DBCR0 */ + mfspr r8, SPRN_EPCR + rlwinm r8, r8, 0, ~SPRN_EPCR_DUVD + mtspr SPRN_EPCR, r8 + isync + mtspr SPRN_DBCR0, r3 + isync +skip_load_host_debug: + /* Save remaining volatile guest register state to vcpu. */ mfspr r3, SPRN_VRSAVE PPC_STL r0, VCPU_GPR(R0)(r4) @@ -662,6 +721,84 @@ lightweight_exit: mtspr SPRN_SPRG6W, r7 mtspr SPRN_SPRG7W, r8 + mfmsr r7 + rlwinm r7, r7, 0, ~MSR_DE + mtmsr r7 + /* +
buildbot failure in kvm on i386
The Buildbot has detected a new failure on builder i386 while building kvm. Full details are available at: http://buildbot.b1-systems.de/kvm/builders/i386/builds/824 Buildbot URL: http://buildbot.b1-systems.de/kvm/ Buildslave for this Build: b1_kvm_1 Build Reason: The Nightly scheduler named 'nightly_master' triggered this build Build Source Stamp: [branch master] HEAD Blamelist: BUILD FAILED: failed git sincerely, -The Buildbot
buildbot failure in kvm on ia64
The Buildbot has detected a new failure on builder ia64 while building kvm. Full details are available at: http://buildbot.b1-systems.de/kvm/builders/ia64/builds/829 Buildbot URL: http://buildbot.b1-systems.de/kvm/ Buildslave for this Build: b1_kvm_1 Build Reason: The Nightly scheduler named 'nightly_master' triggered this build Build Source Stamp: [branch master] HEAD Blamelist: BUILD FAILED: failed git sincerely, -The Buildbot
buildbot failure in kvm on ppc44x
The Buildbot has detected a new failure on builder ppc44x while building kvm. Full details are available at: http://buildbot.b1-systems.de/kvm/builders/ppc44x/builds/831 Buildbot URL: http://buildbot.b1-systems.de/kvm/ Buildslave for this Build: b1_kvm_1 Build Reason: The Nightly scheduler named 'nightly_master' triggered this build Build Source Stamp: [branch master] HEAD Blamelist: BUILD FAILED: failed git sincerely, -The Buildbot
buildbot failure in kvm on ppc64
The Buildbot has detected a new failure on builder ppc64 while building kvm. Full details are available at: http://buildbot.b1-systems.de/kvm/builders/ppc64/builds/828 Buildbot URL: http://buildbot.b1-systems.de/kvm/ Buildslave for this Build: b1_kvm_1 Build Reason: The Nightly scheduler named 'nightly_master' triggered this build Build Source Stamp: [branch master] HEAD Blamelist: BUILD FAILED: failed git sincerely, -The Buildbot N�r��yb�X��ǧv�^�){.n�+h����ܨ}���Ơz�j:+v���zZ+��+zf���h���~i���z��w���?��)ߢf
buildbot failure in kvm on x86_64
The Buildbot has detected a new failure on builder x86_64 while building kvm. Full details are available at: http://buildbot.b1-systems.de/kvm/builders/x86_64/builds/835 Buildbot URL: http://buildbot.b1-systems.de/kvm/ Buildslave for this Build: b1_kvm_1 Build Reason: The Nightly scheduler named 'nightly_master' triggered this build Build Source Stamp: [branch master] HEAD Blamelist: BUILD FAILED: failed git sincerely, -The Buildbot
Re: Tracing kvm: kvm_entry and kvm_exit
On 2/27/13 9:39 AM, David Ahern wrote: I have been playing with the live mode a bit lately. I'll add a debug to note 2 consecutive entry events without an exit -- see if it sheds some light on it. If you feel game take this for a spin: https://github.com/dsahern/linux/commits/perf-kvm-live-3.8 I pushed a few more commits that add debugs to show consecutive events (2 entries or 2 exits), max and min times for various exit reasons and an option to dump events that take longer than some threshold. If you dump the output to a file or run screen with logging you should be able to find when the 'long' event happens and which VMEXIT reason was the cause. Example screen dump: 21:47:37.935302 Analyze events for all VMs, all VCPUs: VM-EXITSamples Samples% Time% Min Time Max Time Avg time APIC_ACCESS97861.51% 0.02%1us 113us 7.81us ( +- 3.67% ) IO_INSTRUCTION21213.33% 0.00%2us 85us 9.20us ( +- 7.57% ) CR_ACCESS 93 5.85% 0.00%2us 66us 3.49us ( +- 19.73% ) EXTERNAL_INTERRUPT 53 3.33% 0.01%3us 135us 57.02us ( +- 6.59% ) EXCEPTION_NMI 26 1.64% 0.00%2us 3us 2.57us ( +- 1.74% ) PENDING_INTERRUPT 3 0.19% 0.00%1us 1us 1.85us ( +- 4.18% ) Total Samples:1590, Total events handled time:39942741.62us. 295170818723592 VM 11854, vcpu 3: APIC_ACCESS event took 113usec 295170819686668 VM 11854, vcpu 0: EXTERNAL_INTERRUPT event took 112usec 295172155051688 VM 11854, vcpu 0: EXTERNAL_INTERRUPT event took 119usec 295172841724899 VM 11854, vcpu 0: APIC_ACCESS event took 129usec 295172999633325 VM 11854, vcpu 0: EXTERNAL_INTERRUPT event took 111usec David -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [uq/master PATCH] target-i386: kvm: save/restore steal time MSR
On Tue, Feb 19, 2013 at 11:27:20PM -0300, Marcelo Tosatti wrote: Read and write steal time MSR, so that reporting is functional across migration. Signed-off-by: Marcelo Tosatti mtosa...@redhat.com Applied, thanks. diff --git a/target-i386/cpu.h b/target-i386/cpu.h index 7577e4f..17c7293 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -792,6 +792,7 @@ typedef struct CPUX86State { #endif uint64_t system_time_msr; uint64_t wall_clock_msr; +uint64_t steal_time_msr; uint64_t async_pf_en_msr; uint64_t pv_eoi_en_msr; diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 0cf413d..9ae9d74 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -68,6 +68,7 @@ static bool has_msr_tsc_deadline; static bool has_msr_async_pf_en; static bool has_msr_pv_eoi_en; static bool has_msr_misc_enable; +static bool has_msr_kvm_steal_time; static int lm_capable_kernel; bool kvm_allows_irq0_override(void) @@ -507,6 +508,8 @@ int kvm_arch_init_vcpu(CPUState *cs) has_msr_pv_eoi_en = c-eax (1 KVM_FEATURE_PV_EOI); +has_msr_kvm_steal_time = c-eax (1 KVM_FEATURE_STEAL_TIME); + cpu_x86_cpuid(env, 0, 0, limit, unused, unused, unused); for (i = 0; i = limit; i++) { @@ -1107,6 +1110,10 @@ static int kvm_put_msrs(X86CPU *cpu, int level) kvm_msr_entry_set(msrs[n++], MSR_KVM_PV_EOI_EN, env-pv_eoi_en_msr); } +if (has_msr_kvm_steal_time) { +kvm_msr_entry_set(msrs[n++], MSR_KVM_STEAL_TIME, + env-steal_time_msr); +} if (hyperv_hypercall_available()) { kvm_msr_entry_set(msrs[n++], HV_X64_MSR_GUEST_OS_ID, 0); kvm_msr_entry_set(msrs[n++], HV_X64_MSR_HYPERCALL, 0); @@ -1360,6 +1367,9 @@ static int kvm_get_msrs(X86CPU *cpu) if (has_msr_pv_eoi_en) { msrs[n++].index = MSR_KVM_PV_EOI_EN; } +if (has_msr_kvm_steal_time) { +msrs[n++].index = MSR_KVM_STEAL_TIME; +} if (env-mcg_cap) { msrs[n++].index = MSR_MCG_STATUS; @@ -1445,6 +1455,9 @@ static int kvm_get_msrs(X86CPU *cpu) case MSR_KVM_PV_EOI_EN: env-pv_eoi_en_msr = msrs[i].data; break; +case MSR_KVM_STEAL_TIME: +env-steal_time_msr = msrs[i].data; +break; } } diff --git a/target-i386/machine.c b/target-i386/machine.c index 8df6a6b..1feb9ca 100644 --- a/target-i386/machine.c +++ b/target-i386/machine.c @@ -287,6 +287,24 @@ static bool pv_eoi_msr_needed(void *opaque) return cpu-pv_eoi_en_msr != 0; } +static bool steal_time_msr_needed(void *opaque) +{ +CPUX86State *cpu = opaque; + +return cpu-steal_time_msr != 0; +} + +static const VMStateDescription vmstate_steal_time_msr = { +.name = cpu/steal_time_msr, +.version_id = 1, +.minimum_version_id = 1, +.minimum_version_id_old = 1, +.fields = (VMStateField []) { +VMSTATE_UINT64(steal_time_msr, CPUX86State), +VMSTATE_END_OF_LIST() +} +}; + static const VMStateDescription vmstate_async_pf_msr = { .name = cpu/async_pf_msr, .version_id = 1, @@ -494,6 +512,9 @@ static const VMStateDescription vmstate_cpu = { .vmsd = vmstate_pv_eoi_msr, .needed = pv_eoi_msr_needed, } , { +.vmsd = vmstate_steal_time_msr, +.needed = steal_time_msr_needed, +} , { .vmsd = vmstate_fpop_ip_dp, .needed = fpop_ip_dp_needed, }, { -- Gleb. -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH qemu-kvm] virtfs-proxy: fix build with F18
Ignoring return value of setfsgid(gid) and setfsuid(uid) causes warnings on F18. Check the return value: man page says glibc returns -1 on error. Signed-off-by: Michael S. Tsirkin m...@redhat.com --- fsdev/virtfs-proxy-helper.c | 7 +-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c index f9a8270..2f0d2b3 100644 --- a/fsdev/virtfs-proxy-helper.c +++ b/fsdev/virtfs-proxy-helper.c @@ -282,6 +282,7 @@ static int send_status(int sockfd, struct iovec *iovec, int status) */ static int setfsugid(int uid, int gid) { +int ret; /* * We still need DAC_OVERRIDE because we don't change * supplementary group ids, and hence may be subjected DAC rules @@ -290,8 +291,10 @@ static int setfsugid(int uid, int gid) CAP_DAC_OVERRIDE, }; -setfsgid(gid); -setfsuid(uid); +ret = setfsgid(gid); +assert(ret != -1); +ret = setfsuid(uid); +assert(ret != -1); if (uid != 0 || gid != 0) { return do_cap_set(cap_list, ARRAY_SIZE(cap_list), 0); -- MST -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCHv2] kvm-unit-test: more documentation and runner script
Add documentation about using qemu-system for unit tests. Add runner script to select the correct binary and flags. Signed-off-by: Michael S. Tsirkin m...@redhat.com --- Changes from v1: fix typo for qemu-system flags add lmr's comment about exit status README | 15 ++- x86-run | 27 +++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100755 x86-run diff --git a/README b/README index 4ceb869..db525e3 100644 --- a/README +++ b/README @@ -10,10 +10,23 @@ To create the tests' images just type 'make' in this directory. Tests' images created in ./ARCH/*.flat An example of a test invocation: -qemu-system-x86_64 -device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out -serial stdio -kernel ./x86/msr.flat +Using qemu-kvm: + +qemu-kvm -device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out -serial stdio -kernel ./x86/msr.flat This invocation runs the msr test case. The test outputs to stdio. +Using qemu (supported since qemu 1.3): +qemu-system-x86_64 -enable-kvm -device pc-testdev -serial stdio -device isa-debug-exit,iobase=0xf4,iosize=0x4 -kernel ./x86/msr.flat + +Or use a runner script to detect the correct invocation: +./x86-run ./x86/msr.flat +To select a specific qemu binary, specify the QEMU=path environment: +QEMU=/tmp/qemu/x86_64-softmmu/qemu-system-x86_64 ./x86-run ./x86/msr.flat +The exit status of the binary (and the script) is inconsistent: with +qemu-system, after the unittest is done, the exit status of qemu is 1, +different from the 'old style' qemu-kvm, whose exit status in successful +completion is 0. Directory structure: .: Makefile and config files for the tests diff --git a/x86-run b/x86-run new file mode 100755 index 000..e395a70 --- /dev/null +++ b/x86-run @@ -0,0 +1,27 @@ +#!/usr/bin/bash + +qemukvm=${QEMU:-qemu-kvm} +qemusystem=${QEMU:-qemu-system-x86_64} +if + ${qemukvm} -device '?' 21 | fgrep -e \testdev\ -e \pc-testdev\ /dev/null; +then + qemu=${qemukvm} +else + if + ${qemsystem} -device '?' 21 | fgrep -e \testdev\ -e \pc-testdev\ /dev/null; + then + qemu=${qemusystem} + else + echo QEMU binary ${QEMU} has no support for test device. Exiting. + exit 1 + fi +fi + +if + ${qemu} -device '?' 21 | fgrep pc-testdev /dev/null; +then + command=${qemu} -enable-kvm -device pc-testdev -serial stdio -device isa-debug-exit,iobase=0xf4,iosize=0x4 -kernel +else + command=${qemu} -device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out -serial stdio -kernel +fi +exec ${command} $@ -- MST -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 0/7] KVM :PPC: Userspace Debug support
This patchset adds the userspace debug support for booke/bookehv. this is tested on powerpc e500v2/e500mc devices. Bharat Bhushan (7): KVM: PPC: booke: Added debug handler Added ONE_REG interface for debug instruction KVM: PPC: debug stub interface parameter defined booke: Save and restore debug registers on guest entry and exit bookehv: Save and restore debug registers on guest entry and exit Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER KVM: PPC: Add userspace debug stub support Documentation/virtual/kvm/api.txt |1 + arch/powerpc/include/asm/kvm_book3s.h |1 + arch/powerpc/include/asm/kvm_booke.h |2 + arch/powerpc/include/asm/kvm_host.h |6 ++ arch/powerpc/include/asm/kvm_ppc.h|2 +- arch/powerpc/include/uapi/asm/kvm.h | 41 + arch/powerpc/kernel/asm-offsets.c | 27 ++ arch/powerpc/kvm/book3s.c | 12 +++ arch/powerpc/kvm/book3s_emulate.c |2 +- arch/powerpc/kvm/book3s_pr.c |2 +- arch/powerpc/kvm/booke.c | 153 +--- arch/powerpc/kvm/booke_interrupts.S | 156 - arch/powerpc/kvm/bookehv_interrupts.S | 145 +- arch/powerpc/kvm/e500_emulate.c |6 ++ arch/powerpc/kvm/e500mc.c |3 +- arch/powerpc/kvm/powerpc.c|6 -- 16 files changed, 535 insertions(+), 30 deletions(-) -- To unsubscribe from this list: send the line unsubscribe kvm-ppc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 3/7] KVM: PPC: debug stub interface parameter defined
This patch defines the interface parameter for KVM_SET_GUEST_DEBUG ioctl support. Follow up patches will use this for setting up hardware breakpoints, watchpoints and software breakpoints. Also kvm_arch_vcpu_ioctl_set_guest_debug() is brought one level below. This is because I am not sure what is required for book3s. So this ioctl behaviour will not change for book3s. Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com --- arch/powerpc/include/uapi/asm/kvm.h | 23 +++ arch/powerpc/kvm/book3s.c |6 ++ arch/powerpc/kvm/booke.c|6 ++ arch/powerpc/kvm/powerpc.c |6 -- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/include/uapi/asm/kvm.h b/arch/powerpc/include/uapi/asm/kvm.h index c2ff99c..15f9a00 100644 --- a/arch/powerpc/include/uapi/asm/kvm.h +++ b/arch/powerpc/include/uapi/asm/kvm.h @@ -272,8 +272,31 @@ struct kvm_debug_exit_arch { /* for KVM_SET_GUEST_DEBUG */ struct kvm_guest_debug_arch { + struct { + /* H/W breakpoint/watchpoint address */ + __u64 addr; + /* +* Type denotes h/w breakpoint, read watchpoint, write +* watchpoint or watchpoint (both read and write). +*/ +#define KVMPPC_DEBUG_NOTYPE0x0 +#define KVMPPC_DEBUG_BREAKPOINT(1UL 1) +#define KVMPPC_DEBUG_WATCH_WRITE (1UL 2) +#define KVMPPC_DEBUG_WATCH_READ(1UL 3) + __u32 type; + __u32 reserved; + } bp[16]; }; +/* Debug related defines */ +/* + * kvm_guest_debug-control is a 32 bit field. The lower 16 bits are generic + * and upper 16 bits are architecture specific. Architecture specific defines + * that ioctl is for setting hardware breakpoint or software breakpoint. + */ +#define KVM_GUESTDBG_USE_SW_BP 0x0001 +#define KVM_GUESTDBG_USE_HW_BP 0x0002 + /* definition of registers in kvm_run */ struct kvm_sync_regs { }; diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c index 975a401..cb85d73 100644 --- a/arch/powerpc/kvm/book3s.c +++ b/arch/powerpc/kvm/book3s.c @@ -613,6 +613,12 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, return 0; } +int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, + struct kvm_guest_debug *dbg) +{ + return -EINVAL; +} + void kvmppc_decrementer_func(unsigned long data) { struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data; diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index a41cd6d..1de93a8 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -1527,6 +1527,12 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) return r; } +int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, +struct kvm_guest_debug *dbg) +{ + return -EINVAL; +} + int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) { return -ENOTSUPP; diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 934413c..4c94ca9 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -532,12 +532,6 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) #endif } -int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, -struct kvm_guest_debug *dbg) -{ - return -EINVAL; -} - static void kvmppc_complete_dcr_load(struct kvm_vcpu *vcpu, struct kvm_run *run) { -- 1.7.0.4 -- To unsubscribe from this list: send the line unsubscribe kvm-ppc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/7] Added ONE_REG interface for debug instruction
This patch adds the one_reg interface to get the special instruction to be used for setting software breakpoint from userspace. Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com --- Documentation/virtual/kvm/api.txt |1 + arch/powerpc/include/asm/kvm_book3s.h |1 + arch/powerpc/include/asm/kvm_booke.h |2 ++ arch/powerpc/include/uapi/asm/kvm.h |4 arch/powerpc/kvm/book3s.c |6 ++ arch/powerpc/kvm/booke.c |6 ++ 6 files changed, 20 insertions(+), 0 deletions(-) diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt index cce500a..dbfcc04 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt @@ -1766,6 +1766,7 @@ registers, find a list below: PPC | KVM_REG_PPC_TSR | 32 PPC | KVM_REG_PPC_OR_TSR | 32 PPC | KVM_REG_PPC_CLEAR_TSR| 32 + PPC | KVM_REG_PPC_DEBUG_INST| 32 4.69 KVM_GET_ONE_REG diff --git a/arch/powerpc/include/asm/kvm_book3s.h b/arch/powerpc/include/asm/kvm_book3s.h index 5a56e1c..36164cc 100644 --- a/arch/powerpc/include/asm/kvm_book3s.h +++ b/arch/powerpc/include/asm/kvm_book3s.h @@ -458,6 +458,7 @@ static inline bool kvmppc_critical_section(struct kvm_vcpu *vcpu) #define OSI_SC_MAGIC_R40x77810F9B #define INS_DCBZ 0x7c0007ec +#define INS_TW 0x7c08 /* LPIDs we support with this build -- runtime limit may be lower */ #define KVMPPC_NR_LPIDS(LPID_RSVD + 1) diff --git a/arch/powerpc/include/asm/kvm_booke.h b/arch/powerpc/include/asm/kvm_booke.h index b7cd335..d3c1eb3 100644 --- a/arch/powerpc/include/asm/kvm_booke.h +++ b/arch/powerpc/include/asm/kvm_booke.h @@ -26,6 +26,8 @@ /* LPIDs we support with this build -- runtime limit may be lower */ #define KVMPPC_NR_LPIDS64 +#define KVMPPC_INST_EHPRIV 0x7c00021c + static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val) { vcpu-arch.gpr[num] = val; diff --git a/arch/powerpc/include/uapi/asm/kvm.h b/arch/powerpc/include/uapi/asm/kvm.h index ef072b1..c2ff99c 100644 --- a/arch/powerpc/include/uapi/asm/kvm.h +++ b/arch/powerpc/include/uapi/asm/kvm.h @@ -422,4 +422,8 @@ struct kvm_get_htab_header { #define KVM_REG_PPC_CLEAR_TSR (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x88) #define KVM_REG_PPC_TCR(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x89) #define KVM_REG_PPC_TSR(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x8a) + +/* Debugging: Special instruction for software breakpoint */ +#define KVM_REG_PPC_DEBUG_INST (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x8b) + #endif /* __LINUX_KVM_POWERPC_H */ diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c index a4b6452..975a401 100644 --- a/arch/powerpc/kvm/book3s.c +++ b/arch/powerpc/kvm/book3s.c @@ -530,6 +530,12 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) val = get_reg_val(reg-id, vcpu-arch.vscr.u[3]); break; #endif /* CONFIG_ALTIVEC */ + case KVM_REG_PPC_DEBUG_INST: { + u32 opcode = INS_TW; + r = copy_to_user((u32 __user *)(long)reg-addr, +opcode, sizeof(u32)); + break; + } default: r = -EINVAL; break; diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index 8b553c0..a41cd6d 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -1448,6 +1448,12 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) case KVM_REG_PPC_TSR: r = put_user(vcpu-arch.tsr, (u32 __user *)(long)reg-addr); break; + case KVM_REG_PPC_DEBUG_INST: { + u32 opcode = KVMPPC_INST_EHPRIV; + r = copy_to_user((u32 __user *)(long)reg-addr, +opcode, sizeof(u32)); + break; + } default: break; } -- 1.7.0.4 -- To unsubscribe from this list: send the line unsubscribe kvm-ppc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/7] KVM: PPC: booke: Added debug handler
Installed debug handler will be used for guest debug support and debug facility emulation features (patches for these features will follow this patch). Signed-off-by: Liu Yu yu@freescale.com [bharat.bhus...@freescale.com: Substantial changes] Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com --- arch/powerpc/include/asm/kvm_host.h |1 + arch/powerpc/kernel/asm-offsets.c |1 + arch/powerpc/kvm/booke_interrupts.S | 42 -- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index 8a72d59..f4ba881 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h @@ -503,6 +503,7 @@ struct kvm_vcpu_arch { u32 tlbcfg[4]; u32 mmucfg; u32 epr; + u32 crit_save; struct kvmppc_booke_debug_reg dbg_reg; #endif gpa_t paddr_accessed; diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c index 46f6afd..02048f3 100644 --- a/arch/powerpc/kernel/asm-offsets.c +++ b/arch/powerpc/kernel/asm-offsets.c @@ -562,6 +562,7 @@ int main(void) DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, arch.last_inst)); DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear)); DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu, arch.fault_esr)); + DEFINE(VCPU_CRIT_SAVE, offsetof(struct kvm_vcpu, arch.crit_save)); #endif /* CONFIG_PPC_BOOK3S */ #endif /* CONFIG_KVM */ diff --git a/arch/powerpc/kvm/booke_interrupts.S b/arch/powerpc/kvm/booke_interrupts.S index f4bb55c..2c6deb5 100644 --- a/arch/powerpc/kvm/booke_interrupts.S +++ b/arch/powerpc/kvm/booke_interrupts.S @@ -54,8 +54,7 @@ (1BOOKE_INTERRUPT_DTLB_MISS) | \ (1BOOKE_INTERRUPT_ALIGNMENT)) -.macro KVM_HANDLER ivor_nr scratch srr0 -_GLOBAL(kvmppc_handler_\ivor_nr) +.macro __KVM_HANDLER ivor_nr scratch srr0 /* Get pointer to vcpu and record exit number. */ mtspr \scratch , r4 mfspr r4, SPRN_SPRG_THREAD @@ -76,6 +75,43 @@ _GLOBAL(kvmppc_handler_\ivor_nr) bctr .endm +.macro KVM_HANDLER ivor_nr scratch srr0 +_GLOBAL(kvmppc_handler_\ivor_nr) + __KVM_HANDLER \ivor_nr \scratch \srr0 +.endm + +.macro KVM_DBG_HANDLER ivor_nr scratch srr0 +_GLOBAL(kvmppc_handler_\ivor_nr) + mtspr \scratch, r4 + mfspr r4, SPRN_SPRG_THREAD + lwz r4, THREAD_KVM_VCPU(r4) + stw r3, VCPU_CRIT_SAVE(r4) + mfcrr3 + mfspr r4, SPRN_CSRR1 + andi. r4, r4, MSR_PR + bne 1f + /* debug interrupt happened in enter/exit path */ + mfspr r4, SPRN_CSRR1 + rlwinm r4, r4, 0, ~MSR_DE + mtspr SPRN_CSRR1, r4 + lis r4, 0x + ori r4, r4, 0x + mtspr SPRN_DBSR, r4 + mfspr r4, SPRN_SPRG_THREAD + lwz r4, THREAD_KVM_VCPU(r4) + mtcrr3 + lwz r3, VCPU_CRIT_SAVE(r4) + mfspr r4, \scratch + rfci +1: /* debug interrupt happened in guest */ + mtcrr3 + mfspr r4, SPRN_SPRG_THREAD + lwz r4, THREAD_KVM_VCPU(r4) + lwz r3, VCPU_CRIT_SAVE(r4) + mfspr r4, \scratch + __KVM_HANDLER \ivor_nr \scratch \srr0 +.endm + .macro KVM_HANDLER_ADDR ivor_nr .long kvmppc_handler_\ivor_nr .endm @@ -100,7 +136,7 @@ KVM_HANDLER BOOKE_INTERRUPT_FIT SPRN_SPRG_RSCRATCH0 SPRN_SRR0 KVM_HANDLER BOOKE_INTERRUPT_WATCHDOG SPRN_SPRG_RSCRATCH_CRIT SPRN_CSRR0 KVM_HANDLER BOOKE_INTERRUPT_DTLB_MISS SPRN_SPRG_RSCRATCH0 SPRN_SRR0 KVM_HANDLER BOOKE_INTERRUPT_ITLB_MISS SPRN_SPRG_RSCRATCH0 SPRN_SRR0 -KVM_HANDLER BOOKE_INTERRUPT_DEBUG SPRN_SPRG_RSCRATCH_CRIT SPRN_CSRR0 +KVM_DBG_HANDLER BOOKE_INTERRUPT_DEBUG SPRN_SPRG_RSCRATCH_CRIT SPRN_CSRR0 KVM_HANDLER BOOKE_INTERRUPT_SPE_UNAVAIL SPRN_SPRG_RSCRATCH0 SPRN_SRR0 KVM_HANDLER BOOKE_INTERRUPT_SPE_FP_DATA SPRN_SPRG_RSCRATCH0 SPRN_SRR0 KVM_HANDLER BOOKE_INTERRUPT_SPE_FP_ROUND SPRN_SPRG_RSCRATCH0 SPRN_SRR0 -- 1.7.0.4 -- To unsubscribe from this list: send the line unsubscribe kvm-ppc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 7/7] KVM: PPC: Add userspace debug stub support
This patch adds the debug stub support on booke/bookehv. Now QEMU debug stub can use hw breakpoint, watchpoint and software breakpoint to debug guest. Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com --- arch/powerpc/include/uapi/asm/kvm.h | 22 +- arch/powerpc/kvm/booke.c| 143 +++--- arch/powerpc/kvm/e500_emulate.c |6 ++ arch/powerpc/kvm/e500mc.c |3 +- 4 files changed, 155 insertions(+), 19 deletions(-) diff --git a/arch/powerpc/include/uapi/asm/kvm.h b/arch/powerpc/include/uapi/asm/kvm.h index 15f9a00..d7ce449 100644 --- a/arch/powerpc/include/uapi/asm/kvm.h +++ b/arch/powerpc/include/uapi/asm/kvm.h @@ -25,6 +25,7 @@ /* Select powerpc specific features in linux/kvm.h */ #define __KVM_HAVE_SPAPR_TCE #define __KVM_HAVE_PPC_SMT +#define __KVM_HAVE_GUEST_DEBUG struct kvm_regs { __u64 pc; @@ -267,7 +268,24 @@ struct kvm_fpu { __u64 fpr[32]; }; +/* + * Defines for h/w breakpoint, watchpoint (read, write or both) and + * software breakpoint. + * These are used as type in KVM_SET_GUEST_DEBUG ioctl and status + * for KVM_DEBUG_EXIT. + */ +#define KVMPPC_DEBUG_NONE 0x0 +#define KVMPPC_DEBUG_BREAKPOINT(1UL 1) +#define KVMPPC_DEBUG_WATCH_WRITE (1UL 2) +#define KVMPPC_DEBUG_WATCH_READ(1UL 3) struct kvm_debug_exit_arch { + __u64 address; + /* +* exiting to userspace because of h/w breakpoint, watchpoint +* (read, write or both) and software breakpoint. +*/ + __u32 status; + __u32 reserved; }; /* for KVM_SET_GUEST_DEBUG */ @@ -279,10 +297,6 @@ struct kvm_guest_debug_arch { * Type denotes h/w breakpoint, read watchpoint, write * watchpoint or watchpoint (both read and write). */ -#define KVMPPC_DEBUG_NOTYPE0x0 -#define KVMPPC_DEBUG_BREAKPOINT(1UL 1) -#define KVMPPC_DEBUG_WATCH_WRITE (1UL 2) -#define KVMPPC_DEBUG_WATCH_READ(1UL 3) __u32 type; __u32 reserved; } bp[16]; diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index 1de93a8..21b0313 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -133,6 +133,30 @@ static void kvmppc_vcpu_sync_fpu(struct kvm_vcpu *vcpu) #endif } +static void kvmppc_vcpu_sync_debug(struct kvm_vcpu *vcpu) +{ + /* Synchronize guest's desire to get debug interrupts into shadow MSR */ +#ifndef CONFIG_KVM_BOOKE_HV + vcpu-arch.shadow_msr = ~MSR_DE; + vcpu-arch.shadow_msr |= vcpu-arch.shared-msr MSR_DE; +#endif + + /* Force enable debug interrupts when user space wants to debug */ + if (vcpu-guest_debug) { +#ifdef CONFIG_KVM_BOOKE_HV + /* +* Since there is no shadow MSR, sync MSR_DE into the guest +* visible MSR. Do not allow guest to change MSR[DE]. +*/ + vcpu-arch.shared-msr |= MSR_DE; + mtspr(SPRN_MSRP, mfspr(SPRN_MSRP) | MSRP_DEP); +#else + vcpu-arch.shadow_msr |= MSR_DE; + vcpu-arch.shared-msr = ~MSR_DE; +#endif + } +} + /* * Helper function for full MSR writes. No need to call this if only * EE/CE/ME/DE/RI are changing. @@ -150,6 +174,7 @@ void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr) kvmppc_mmu_msr_notify(vcpu, old_msr); kvmppc_vcpu_sync_spe(vcpu); kvmppc_vcpu_sync_fpu(vcpu); + kvmppc_vcpu_sync_debug(vcpu); } static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, @@ -736,6 +761,13 @@ static int emulation_exit(struct kvm_run *run, struct kvm_vcpu *vcpu) run-exit_reason = KVM_EXIT_DCR; return RESUME_HOST; + case EMULATE_EXIT_USER: + run-exit_reason = KVM_EXIT_DEBUG; + run-debug.arch.address = vcpu-arch.pc; + run-debug.arch.status = 0; + kvmppc_account_exit(vcpu, DEBUG_EXITS); + return RESUME_HOST; + case EMULATE_FAIL: printk(KERN_CRIT %s: emulation at %lx failed (%08x)\n, __func__, vcpu-arch.pc, vcpu-arch.last_inst); @@ -751,6 +783,28 @@ static int emulation_exit(struct kvm_run *run, struct kvm_vcpu *vcpu) } } +static int kvmppc_handle_debug(struct kvm_run *run, struct kvm_vcpu *vcpu) +{ + u32 dbsr = vcpu-arch.dbsr; + run-debug.arch.status = 0; + run-debug.arch.address = vcpu-arch.pc; + + if (dbsr (DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4)) { + run-debug.arch.status |= KVMPPC_DEBUG_BREAKPOINT; + } else { + if (dbsr (DBSR_DAC1W | DBSR_DAC2W)) + run-debug.arch.status |= KVMPPC_DEBUG_WATCH_WRITE; + else if (dbsr (DBSR_DAC1R | DBSR_DAC2R)) + run-debug.arch.status |= KVMPPC_DEBUG_WATCH_READ; + if
[PATCH 6/7] Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER
Instruction emulation return EMULATE_DO_PAPR when it requires exit to userspace on book3s. Similar return is required for booke. EMULATE_DO_PAPR reads out to be confusing so it is renamed to EMULATE_EXIT_USER. Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com --- arch/powerpc/include/asm/kvm_ppc.h |2 +- arch/powerpc/kvm/book3s_emulate.c |2 +- arch/powerpc/kvm/book3s_pr.c |2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h index 44a657a..8b81468 100644 --- a/arch/powerpc/include/asm/kvm_ppc.h +++ b/arch/powerpc/include/asm/kvm_ppc.h @@ -44,7 +44,7 @@ enum emulation_result { EMULATE_DO_DCR, /* kvm_run filled with DCR request */ EMULATE_FAIL, /* can't emulate this instruction */ EMULATE_AGAIN,/* something went wrong. go again */ - EMULATE_DO_PAPR, /* kvm_run filled with PAPR request */ + EMULATE_EXIT_USER,/* emulation requires exit to user-space */ }; extern int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu); diff --git a/arch/powerpc/kvm/book3s_emulate.c b/arch/powerpc/kvm/book3s_emulate.c index 836c569..cdd19d6 100644 --- a/arch/powerpc/kvm/book3s_emulate.c +++ b/arch/powerpc/kvm/book3s_emulate.c @@ -194,7 +194,7 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, run-papr_hcall.args[i] = gpr; } - emulated = EMULATE_DO_PAPR; + emulated = EMULATE_EXIT_USER; break; } #endif diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c index 73ed11c..8df2d2d 100644 --- a/arch/powerpc/kvm/book3s_pr.c +++ b/arch/powerpc/kvm/book3s_pr.c @@ -760,7 +760,7 @@ program_interrupt: run-exit_reason = KVM_EXIT_MMIO; r = RESUME_HOST_NV; break; - case EMULATE_DO_PAPR: + case EMULATE_EXIT_USER: run-exit_reason = KVM_EXIT_PAPR_HCALL; vcpu-arch.hcall_needed = 1; r = RESUME_HOST_NV; -- 1.7.0.4 -- To unsubscribe from this list: send the line unsubscribe kvm-ppc in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 5/7] bookehv: Save and restore debug registers on guest entry and exit
On Guest entry: if guest is wants to use the debug register then save h/w debug register in host_dbg_reg and load the debug registers with shadow_dbg_reg. Otherwise leave h/w debug registers as is. On guest exit: If guest/user-space is using the debug resource then restore the h/w debug register with host_dbg_reg. No need to save guest debug register as shadow_dbg_reg is having required values. If guest is not using the debug resources then no need to restore h/w registers. Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com --- arch/powerpc/kvm/bookehv_interrupts.S | 145 - 1 files changed, 141 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/kvm/bookehv_interrupts.S b/arch/powerpc/kvm/bookehv_interrupts.S index e8ed7d6..0d830cc 100644 --- a/arch/powerpc/kvm/bookehv_interrupts.S +++ b/arch/powerpc/kvm/bookehv_interrupts.S @@ -62,6 +62,10 @@ #define NEED_EMU 0x0001 /* emulation -- save nv regs */ #define NEED_DEAR 0x0002 /* save faulting DEAR */ #define NEED_ESR 0x0004 /* save faulting ESR */ +#define NEED_DBSR 0x0008 /* save DBSR */ + +#define DBCR0_AC_BITS (DBCR0_IAC1 | DBCR0_IAC2 | DBCR0_IAC3 | DBCR0_IAC4 | \ +DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W) /* * On entry: @@ -201,6 +205,11 @@ PPC_STL r9, VCPU_FAULT_DEAR(r4) .endif + .if \flags NEED_DBSR + mfspr r9, SPRN_DBSR + stw r9, VCPU_DBSR(r4) + .endif + b kvmppc_resume_host .endm @@ -316,9 +325,9 @@ kvm_handler BOOKE_INTERRUPT_GUEST_DBELL, EX_PARAMS(GDBELL), \ kvm_handler BOOKE_INTERRUPT_GUEST_DBELL_CRIT, EX_PARAMS(CRIT), \ SPRN_CSRR0, SPRN_CSRR1, 0 kvm_handler BOOKE_INTERRUPT_DEBUG, EX_PARAMS(DBG), \ - SPRN_DSRR0, SPRN_DSRR1, 0 + SPRN_DSRR0, SPRN_DSRR1, NEED_DBSR kvm_handler BOOKE_INTERRUPT_DEBUG, EX_PARAMS(CRIT), \ - SPRN_CSRR0, SPRN_CSRR1, 0 + SPRN_CSRR0, SPRN_CSRR1, NEED_DBSR #else /* * For input register values, see arch/powerpc/include/asm/kvm_booke_hv_asm.h @@ -411,9 +420,9 @@ kvm_handler BOOKE_INTERRUPT_GUEST_DBELL, SPRN_GSRR0, SPRN_GSRR1, 0 kvm_lvl_handler BOOKE_INTERRUPT_GUEST_DBELL_CRIT, \ SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0 kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \ - SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0 + SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, NEED_DBSR kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \ - SPRN_SPRG_RSCRATCH_DBG, SPRN_DSRR0, SPRN_DSRR1, 0 + SPRN_SPRG_RSCRATCH_DBG, SPRN_DSRR0, SPRN_DSRR1, NEED_DBSR #endif /* Registers: @@ -423,6 +432,56 @@ kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \ * r14: KVM exit number */ _GLOBAL(kvmppc_resume_host) + /* +* If guest not used debug facility then hw debug registers +* already have proper host values. If guest used debug +* facility then restore host debug registers. +* No Need to save guest debug registers as they are already intact +* in guest/shadow registers. +*/ + lwz r9, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR0(r4) + rlwinm. r8, r9, 0, ~DBCR0_IDM + beq skip_load_host_debug + lwz r3, VCPU_HOST_DBG+KVMPPC_DBG_DBCR0(r4) + andis. r9, r9, DBCR0_AC_BITS@h + li r9, 0 + mtspr SPRN_DBCR0, r9 /* disable all debug event */ + beq skip_load_hw_bkpts + lwz r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR1(r4) + lwz r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR2(r4) + lwz r9, VCPU_HOST_DBG+KVMPPC_DBG_DBCR4(r4) + mtspr SPRN_DBCR1, r7 + PPC_LD(r6, VCPU_HOST_DBG+KVMPPC_DBG_IAC1, r4) + PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC2, r4) + mtspr SPRN_DBCR2, r8 + mtspr SPRN_DBCR4, r9 + mtspr SPRN_IAC1, r6 + mtspr SPRN_IAC2, r7 +#if CONFIG_PPC_ADV_DEBUG_IACS 2 + PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC3, r4) + PPC_LD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC4, r4) + mtspr SPRN_IAC3, r7 + mtspr SPRN_IAC4, r8 +#endif + PPC_LD(r8, VCPU_HOST_DBG+KVMPPC_DBG_DAC1, r4) + PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_DAC2, r4) + mtspr SPRN_DAC1, r8 + mtspr SPRN_DAC2, r9 +skip_load_hw_bkpts: + isync + /* Clear h/w DBSR */ + mfspr r8, SPRN_DBSR + mtspr SPRN_DBSR, r8 + isync + /* Clear EPCR.DUVD and set host DBCR0 */ + mfspr r8, SPRN_EPCR + rlwinm r8, r8, 0, ~SPRN_EPCR_DUVD + mtspr SPRN_EPCR, r8 + isync + mtspr SPRN_DBCR0, r3 + isync +skip_load_host_debug: + /* Save remaining volatile guest register state to vcpu. */ mfspr r3, SPRN_VRSAVE PPC_STL r0, VCPU_GPR(R0)(r4) @@ -662,6 +721,84 @@ lightweight_exit: mtspr SPRN_SPRG6W, r7 mtspr SPRN_SPRG7W, r8 + mfmsr r7 + rlwinm r7, r7, 0, ~MSR_DE + mtmsr r7 + /* +