[COMMIT master] make-release: don't use --tmpdir mktemp option
From: Eduardo Habkost ehabk...@redhat.com This allows the script to work on older systems, where 'mktemp --tmpdir' is not available. Signed-off-by: Eduardo Habkost ehabk...@redhat.com Signed-off-by: Marcelo Tosatti mtosa...@redhat.com diff --git a/kvm/scripts/make-release b/kvm/scripts/make-release index 64e77f9..c5f8c92 100755 --- a/kvm/scripts/make-release +++ b/kvm/scripts/make-release @@ -12,7 +12,7 @@ formal= releasedir=~/sf-release [[ -z $TMP ]] TMP=/tmp -tmpdir=`mktemp -d --tmpdir=$TMP qemu-kvm-make-release.XX` +tmpdir=`mktemp -d $TMP/qemu-kvm-make-release.XX` while [[ $1 = -* ]]; do opt=$1 shift -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[COMMIT master] p2v monitor command: translate guest physical address to host virtual address
From: Max Asbock masb...@linux.vnet.ibm.com Add command p2v to translate guest physical address to host virtual address. The p2v command provides one step in a chain of translations from guest virtual to guest physical to host virtual to host physical. Host physical is then used to inject a machine check error. As a consequence the HWPOISON code on the host and the MCE injection code in qemu-kvm are exercised. Signed-off-by: Max Asbock masb...@linux.vnet.ibm.com Signed-off-by: Jiajia Zheng jiajia.zh...@intel.com Signed-off-by: Huang Ying ying.hu...@intel.com Signed-off-by: Marcelo Tosatti mtosa...@redhat.com diff --git a/monitor.c b/monitor.c index 9072c06..df0cb33 100644 --- a/monitor.c +++ b/monitor.c @@ -2301,6 +2301,18 @@ static void do_inject_mce(Monitor *mon, const QDict *qdict) } #endif +static void do_p2v(Monitor *mon, const QDict *qdict) +{ +target_phys_addr_t size = TARGET_PAGE_SIZE; +target_phys_addr_t addr = qdict_get_int(qdict, addr); +void *vaddr; + +vaddr = cpu_physical_memory_map(addr, size, 0); +monitor_printf(mon, Guest physical address %p is mapped at + host virtual address %p\n, (void *)addr, vaddr); +cpu_physical_memory_unmap(vaddr, size, 0, 0); +} + static int do_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data) { const char *fdname = qdict_get_str(qdict, fdname); diff --git a/qemu-monitor.hx b/qemu-monitor.hx index 620f937..2698a42 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -459,6 +459,19 @@ Start gdbserver session (default @var{port}=1234) ETEXI { +.name = p2v, +.args_type = fmt:/,addr:l, +.params = /fmt addr, +.help = translate guest physical 'addr' to host virtual address, +.mhandler.cmd = do_p2v, +}, +STEXI +...@item p2v @var{addr} +...@findex mce +Translate guest physical @var{addr} to host virtual address. +ETEXI + +{ .name = x, .args_type = fmt:/,addr:l, .params = /fmt addr, -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[COMMIT master] make-release: don't use --mtime and --transform tar options
From: Eduardo Habkost ehabk...@redhat.com Those options are not available on older systems. Instead of --transform, just create the file inside the expected directory. Instead of --mtime, use 'touch' to set file mtime before running tar. Signed-off-by: Eduardo Habkost ehabk...@redhat.com Signed-off-by: Marcelo Tosatti mtosa...@redhat.com diff --git a/kvm/scripts/make-release b/kvm/scripts/make-release index c5f8c92..56302c3 100755 --- a/kvm/scripts/make-release +++ b/kvm/scripts/make-release @@ -52,20 +52,22 @@ mkdir -p $(dirname $tarball) git archive --prefix=$name/ --format=tar $commit $tarball mtime=`git show --format=%ct $commit^{commit} --` -tarargs=--owner=root --group=root --mti...@$mtime +tarargs=--owner=root --group=root -mkdir -p $tmpdir +mkdir -p $tmpdir/$name git cat-file -p ${commit}:roms | awk ' { print $4, $3 } ' \ - $tmpdir/EXTERNAL_DEPENDENCIES -tar -rf $tarball --transform s,^,$name/, -C $tmpdir \ + $tmpdir/$name/EXTERNAL_DEPENDENCIES +touch -d @$mtime $tmpdir/$name/EXTERNAL_DEPENDENCIES +tar -rf $tarball -C $tmpdir \ $tarargs \ -EXTERNAL_DEPENDENCIES +$name/EXTERNAL_DEPENDENCIES rm -rf $tmpdir if [[ -n $formal ]]; then -mkdir -p $tmpdir -echo $name $tmpdir/KVM_VERSION -tar -rf $tarball --transform s,^,$name/, -C $tmpdir KVM_VERSION \ +mkdir -p $tmpdir/$name +echo $name $tmpdir/$name/KVM_VERSION +touch -d @$mtime $tmpdir/$name/KVM_VERSION +tar -rf $tarball -C $tmpdir $name/KVM_VERSION \ $tarargs rm -rf $tmpdir fi -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[COMMIT master] kvm: allow tpr patching to write to write-protected vapic option rom
From: Avi Kivity a...@redhat.com Now that we allow the bios to write protect option roms, we need to allow the tpr patching code to write to this write protected memory. This means using cpu_physical_memory_write_rom() instead of the usual APIs. Fixes Windows XP without flexpriority. Signed-off-by: Avi Kivity a...@redhat.com diff --git a/kvm-tpr-opt.c b/kvm-tpr-opt.c index 46890e2..c929fc8 100644 --- a/kvm-tpr-opt.c +++ b/kvm-tpr-opt.c @@ -73,7 +73,7 @@ static uint8_t read_byte_virt(CPUState *env, target_ulong virt) static void write_byte_virt(CPUState *env, target_ulong virt, uint8_t b) { -stb_phys(map_addr(env, virt, NULL), b); +cpu_physical_memory_write_rom(map_addr(env, virt, NULL), b, 1); } struct vapic_bios { @@ -107,7 +107,7 @@ static void update_vbios_real_tpr(void) cpu_physical_memory_rw(vbios_desc_phys, (void *)vapic_bios, sizeof vapic_bios, 0); vapic_bios.real_tpr = real_tpr; vapic_bios.vcpu_shift = 7; -cpu_physical_memory_rw(vbios_desc_phys, (void *)vapic_bios, sizeof vapic_bios, 1); +cpu_physical_memory_write_rom(vbios_desc_phys, (void *)vapic_bios, sizeof vapic_bios); } static unsigned modrm_reg(uint8_t modrm) @@ -174,6 +174,7 @@ static int bios_is_mapped(CPUState *env, uint64_t rip) unsigned perms; uint32_t i; uint32_t offset, fixup, start = vapic_bios_addr ? : 0xe; +uint32_t patch; if (bios_enabled) return 1; @@ -198,7 +199,8 @@ static int bios_is_mapped(CPUState *env, uint64_t rip) for (i = vapic_bios.fixup_start; i vapic_bios.fixup_end; i += 4) { offset = ldl_phys(phys + i - vapic_bios.virt_base); fixup = phys + offset; - stl_phys(fixup, ldl_phys(fixup) + bios_addr - vapic_bios.virt_base); +patch = ldl_phys(fixup) + bios_addr - vapic_bios.virt_base; +cpu_physical_memory_write_rom(fixup, (uint8_t *)patch, 4); } vapic_phys = vapic_bios.vapic - vapic_bios.virt_base + phys; return 1; @@ -225,7 +227,7 @@ int kvm_tpr_enable_vapic(CPUState *env) return 0; kvm_enable_vapic(env, vapic_phys + (pcr_cpu 7)); -cpu_physical_memory_rw(vapic_phys + (pcr_cpu 7) + 4, one, 1, 1); +cpu_physical_memory_write_rom(vapic_phys + (pcr_cpu 7) + 4, one, 1); env-kvm_vcpu_update_vapic = 0; bios_enabled = 1; return 1; -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[COMMIT master] Revert p2v monitor command: translate guest physical address to host virtual address
From: Avi Kivity a...@redhat.com This reverts commit c3fe515c911b9828d6e3e659ac794cb7dc76cd66; needs to go through qemu.git. Signed-off-by: Avi Kivity a...@redhat.com diff --git a/monitor.c b/monitor.c index df0cb33..9072c06 100644 --- a/monitor.c +++ b/monitor.c @@ -2301,18 +2301,6 @@ static void do_inject_mce(Monitor *mon, const QDict *qdict) } #endif -static void do_p2v(Monitor *mon, const QDict *qdict) -{ -target_phys_addr_t size = TARGET_PAGE_SIZE; -target_phys_addr_t addr = qdict_get_int(qdict, addr); -void *vaddr; - -vaddr = cpu_physical_memory_map(addr, size, 0); -monitor_printf(mon, Guest physical address %p is mapped at - host virtual address %p\n, (void *)addr, vaddr); -cpu_physical_memory_unmap(vaddr, size, 0, 0); -} - static int do_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data) { const char *fdname = qdict_get_str(qdict, fdname); diff --git a/qemu-monitor.hx b/qemu-monitor.hx index 2698a42..620f937 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -459,19 +459,6 @@ Start gdbserver session (default @var{port}=1234) ETEXI { -.name = p2v, -.args_type = fmt:/,addr:l, -.params = /fmt addr, -.help = translate guest physical 'addr' to host virtual address, -.mhandler.cmd = do_p2v, -}, -STEXI -...@item p2v @var{addr} -...@findex mce -Translate guest physical @var{addr} to host virtual address. -ETEXI - -{ .name = x, .args_type = fmt:/,addr:l, .params = /fmt addr, -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[COMMIT master] KVM: x86 emulator: Eliminate compilation warning in x86_decode_insn()
From: Sheng Yang sh...@linux.intel.com Eliminate: arch/x86/kvm/emulate.c:801: warning: ‘sv’ may be used uninitialized in this function on gcc 4.1.2 Signed-off-by: Sheng Yang sh...@linux.intel.com Signed-off-by: Marcelo Tosatti mtosa...@redhat.com diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index aead72e..d0df25d 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -798,7 +798,7 @@ done: static void fetch_bit_operand(struct decode_cache *c) { - long sv, mask; + long sv = 0, mask; if (c-dst.type == OP_MEM c-src.type == OP_REG) { mask = ~(c-dst.bytes * 8 - 1); -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[COMMIT master] KVM: MMU: update 'root_hpa' out of loop in PAE shadow path
From: Xiao Guangrong xiaoguangr...@cn.fujitsu.com The value of 'vcpu-arch.mmu.pae_root' is not modified, so we can update 'root_hpa' out of the loop. Signed-off-by: Xiao Guangrong xiaoguangr...@cn.fujitsu.com Signed-off-by: Avi Kivity a...@redhat.com diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index c94c432..3630046 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -2393,8 +2393,8 @@ static int mmu_alloc_direct_roots(struct kvm_vcpu *vcpu) ++sp-root_count; spin_unlock(vcpu-kvm-mmu_lock); vcpu-arch.mmu.pae_root[i] = root | PT_PRESENT_MASK; - vcpu-arch.mmu.root_hpa = __pa(vcpu-arch.mmu.pae_root); } + vcpu-arch.mmu.root_hpa = __pa(vcpu-arch.mmu.pae_root); } else BUG(); @@ -2466,8 +2466,8 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu) spin_unlock(vcpu-kvm-mmu_lock); vcpu-arch.mmu.pae_root[i] = root | pm_mask; - vcpu-arch.mmu.root_hpa = __pa(vcpu-arch.mmu.pae_root); } + vcpu-arch.mmu.root_hpa = __pa(vcpu-arch.mmu.pae_root); /* * If we shadow a 32 bit page table with a long mode page -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[COMMIT master] KVM: MMU: set access bit for direct mapping
From: Xiao Guangrong xiaoguangr...@cn.fujitsu.com Set access bit while setup up direct page table if it's nonpaing or npt enabled, it's good for CPU's speculate access Signed-off-by: Xiao Guangrong xiaoguangr...@cn.fujitsu.com Signed-off-by: Avi Kivity a...@redhat.com diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 3630046..88203fa 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -2240,7 +2240,8 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write, __set_spte(iterator.sptep, __pa(sp-spt) | PT_PRESENT_MASK | PT_WRITABLE_MASK - | shadow_user_mask | shadow_x_mask); + | shadow_user_mask | shadow_x_mask + | shadow_accessed_mask); } } return pt_write; -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[COMMIT master] KVM: MMU: cleanup for error mask set while walk guest page table
From: Xiao Guangrong xiaoguangr...@cn.fujitsu.com Small cleanup for set page fault error code Signed-off-by: Xiao Guangrong xiaoguangr...@cn.fujitsu.com Signed-off-by: Avi Kivity a...@redhat.com diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h index 2bdd843..a83ff37 100644 --- a/arch/x86/kvm/paging_tmpl.h +++ b/arch/x86/kvm/paging_tmpl.h @@ -224,9 +224,7 @@ walk: is_cpuid_PSE36()) gfn += pse36_gfn_delta(pte); - access |= write_fault ? PFERR_WRITE_MASK : 0; - access |= fetch_fault ? PFERR_FETCH_MASK : 0; - access |= user_fault ? PFERR_USER_MASK : 0; + access |= write_fault | fetch_fault | user_fault; real_gpa = mmu-translate_gpa(vcpu, gfn_to_gpa(gfn), access); @@ -268,10 +266,9 @@ error: walker-error_code = 0; if (present) walker-error_code |= PFERR_PRESENT_MASK; - if (write_fault) - walker-error_code |= PFERR_WRITE_MASK; - if (user_fault) - walker-error_code |= PFERR_USER_MASK; + + walker-error_code |= write_fault | user_fault; + if (fetch_fault mmu-nx) walker-error_code |= PFERR_FETCH_MASK; if (rsvd_fault) @@ -673,9 +670,9 @@ static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr, u32 access, int r; r = FNAME(walk_addr)(walker, vcpu, vaddr, -!!(access PFERR_WRITE_MASK), -!!(access PFERR_USER_MASK), -!!(access PFERR_FETCH_MASK)); +access PFERR_WRITE_MASK, +access PFERR_USER_MASK, +access PFERR_FETCH_MASK); if (r) { gpa = gfn_to_gpa(walker.gfn); -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[COMMIT master] KVM: MMU: audit: fix vcpu's spte walking
From: Xiao Guangrong xiaoguangr...@cn.fujitsu.com After nested nested paging, it may using long mode to shadow 32/PAE paging guest, so this patch fix it Signed-off-by: Xiao Guangrong xiaoguangr...@cn.fujitsu.com Signed-off-by: Avi Kivity a...@redhat.com diff --git a/arch/x86/kvm/mmu_audit.c b/arch/x86/kvm/mmu_audit.c index bd2b1be..dcca3e7 100644 --- a/arch/x86/kvm/mmu_audit.c +++ b/arch/x86/kvm/mmu_audit.c @@ -51,7 +51,7 @@ static void mmu_spte_walk(struct kvm_vcpu *vcpu, inspect_spte_fn fn) if (!VALID_PAGE(vcpu-arch.mmu.root_hpa)) return; - if (vcpu-arch.mmu.shadow_root_level == PT64_ROOT_LEVEL) { + if (vcpu-arch.mmu.root_level == PT64_ROOT_LEVEL) { hpa_t root = vcpu-arch.mmu.root_hpa; sp = page_header(root); -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[COMMIT master] KVM: MMU: audit: unregister audit tracepoints before module unloaded
From: Xiao Guangrong xiaoguangr...@cn.fujitsu.com fix: Call Trace: [a01e46ba] ? kvm_mmu_pte_write+0x229/0x911 [kvm] [a01c6ba9] ? gfn_to_memslot+0x39/0xa0 [kvm] [a01c6c26] ? mark_page_dirty+0x16/0x2e [kvm] [a01c6d6f] ? kvm_write_guest_page+0x67/0x7f [kvm] [81066fbd] ? local_clock+0x2a/0x3b [a01d52ce] emulator_write_phys+0x46/0x54 [kvm] .. Code: Bad RIP value. RIP [a0172056] 0xa0172056 RSP 880134f69a70 CR2: a0172056 Signed-off-by: Xiao Guangrong xiaoguangr...@cn.fujitsu.com Signed-off-by: Avi Kivity a...@redhat.com diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 88203fa..afde64b 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -3355,15 +3355,6 @@ int kvm_mmu_setup(struct kvm_vcpu *vcpu) return init_kvm_mmu(vcpu); } -void kvm_mmu_destroy(struct kvm_vcpu *vcpu) -{ - ASSERT(vcpu); - - destroy_kvm_mmu(vcpu); - free_mmu_pages(vcpu); - mmu_free_memory_caches(vcpu); -} - void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot) { struct kvm_mmu_page *sp; @@ -3662,4 +3653,16 @@ EXPORT_SYMBOL_GPL(kvm_mmu_get_spte_hierarchy); #ifdef CONFIG_KVM_MMU_AUDIT #include mmu_audit.c +#else +static void mmu_audit_disable(void) { } #endif + +void kvm_mmu_destroy(struct kvm_vcpu *vcpu) +{ + ASSERT(vcpu); + + destroy_kvm_mmu(vcpu); + free_mmu_pages(vcpu); + mmu_free_memory_caches(vcpu); + mmu_audit_disable(); +} -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[COMMIT master] KVM: MMU: audit: introduce audit_printk to cleanup audit code
From: Xiao Guangrong xiaoguangr...@cn.fujitsu.com Introduce audit_printk, and record audit point instead audit name Signed-off-by: Xiao Guangrong xiaoguangr...@cn.fujitsu.com Signed-off-by: Avi Kivity a...@redhat.com diff --git a/arch/x86/kvm/mmu_audit.c b/arch/x86/kvm/mmu_audit.c index dcca3e7..66219af 100644 --- a/arch/x86/kvm/mmu_audit.c +++ b/arch/x86/kvm/mmu_audit.c @@ -19,7 +19,11 @@ #include linux/ratelimit.h -static const char *audit_msg; +static int audit_point; + +#define audit_printk(fmt, args...) \ + printk(KERN_ERR audit: (%s) error:\ + fmt, audit_point_name[audit_point], ##args) typedef void (*inspect_spte_fn) (struct kvm_vcpu *vcpu, u64 *sptep, int level); @@ -93,21 +97,18 @@ static void audit_mappings(struct kvm_vcpu *vcpu, u64 *sptep, int level) if (sp-unsync) { if (level != PT_PAGE_TABLE_LEVEL) { - printk(KERN_ERR audit: (%s) error: unsync sp: %p level = %d\n, - audit_msg, sp, level); + audit_printk(unsync sp: %p level = %d\n, sp, level); return; } if (*sptep == shadow_notrap_nonpresent_pte) { - printk(KERN_ERR audit: (%s) error: notrap spte in unsync sp: %p\n, - audit_msg, sp); + audit_printk(notrap spte in unsync sp: %p\n, sp); return; } } if (sp-role.direct *sptep == shadow_notrap_nonpresent_pte) { - printk(KERN_ERR audit: (%s) error: notrap spte in direct sp: %p\n, - audit_msg, sp); + audit_printk(notrap spte in direct sp: %p\n, sp); return; } @@ -124,10 +125,8 @@ static void audit_mappings(struct kvm_vcpu *vcpu, u64 *sptep, int level) hpa = pfn PAGE_SHIFT; if ((*sptep PT64_BASE_ADDR_MASK) != hpa) - printk(KERN_ERR xx audit error: (%s) levels %d - pfn %llx hpa %llx ent %llxn, - audit_msg, vcpu-arch.mmu.root_level, - pfn, hpa, *sptep); + audit_printk(levels %d pfn %llx hpa %llx ent %llxn, + vcpu-arch.mmu.root_level, pfn, hpa, *sptep); } static void inspect_spte_has_rmap(struct kvm *kvm, u64 *sptep) @@ -143,11 +142,9 @@ static void inspect_spte_has_rmap(struct kvm *kvm, u64 *sptep) if (!gfn_to_memslot(kvm, gfn)) { if (!printk_ratelimit()) return; - printk(KERN_ERR %s: no memslot for gfn %llx\n, -audit_msg, gfn); - printk(KERN_ERR %s: index %ld of sp (gfn=%llx)\n, - audit_msg, (long int)(sptep - rev_sp-spt), - rev_sp-gfn); + audit_printk(no memslot for gfn %llx\n, gfn); + audit_printk(index %ld of sp (gfn=%llx)\n, + (long int)(sptep - rev_sp-spt), rev_sp-gfn); dump_stack(); return; } @@ -156,8 +153,7 @@ static void inspect_spte_has_rmap(struct kvm *kvm, u64 *sptep) if (!*rmapp) { if (!printk_ratelimit()) return; - printk(KERN_ERR %s: no rmap for writable spte %llx\n, -audit_msg, *sptep); + audit_printk(no rmap for writable spte %llx\n, *sptep); dump_stack(); } } @@ -198,10 +194,8 @@ void audit_write_protection(struct kvm *kvm, struct kvm_mmu_page *sp) spte = rmap_next(kvm, rmapp, NULL); while (spte) { if (is_writable_pte(*spte)) - printk(KERN_ERR %s: (%s) shadow page has - writable mappings: gfn %llx role %x\n, - __func__, audit_msg, sp-gfn, - sp-role.word); + audit_printk(shadow page has writable mappings: gfn +%llx role %x\n, sp-gfn, sp-role.word); spte = rmap_next(kvm, rmapp, spte); } } @@ -228,14 +222,14 @@ static void audit_vcpu_spte(struct kvm_vcpu *vcpu) mmu_spte_walk(vcpu, audit_spte); } -static void kvm_mmu_audit(void *ignore, struct kvm_vcpu *vcpu, int audit_point) +static void kvm_mmu_audit(void *ignore, struct kvm_vcpu *vcpu, int point) { static DEFINE_RATELIMIT_STATE(ratelimit_state, 5 * HZ, 10); if (!__ratelimit(ratelimit_state)) return; - audit_msg = audit_point_name[audit_point]; + audit_point = point; audit_all_active_sps(vcpu-kvm); audit_vcpu_spte(vcpu); } -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to majord...@vger.kernel.org More majordomo info
[COMMIT master] KVM: MMU: Avoid sign extension in mmu_alloc_direct_roots() pae root address
From: Avi Kivity a...@redhat.com Signed-off-by: Avi Kivity a...@redhat.com diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index ba7e764..dc1b4fb 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -2374,7 +2374,7 @@ static int mmu_check_root(struct kvm_vcpu *vcpu, gfn_t root_gfn) static int mmu_alloc_direct_roots(struct kvm_vcpu *vcpu) { struct kvm_mmu_page *sp; - int i; + unsigned i; if (vcpu-arch.mmu.shadow_root_level == PT64_ROOT_LEVEL) { spin_lock(vcpu-kvm-mmu_lock); -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[COMMIT master] KVM: MMU: audit: check whether have unsync sps after root sync
From: Xiao Guangrong xiaoguangr...@cn.fujitsu.com After root synced, all unsync sps are synced, this patch add a check to make sure it's no unsync sps in VCPU's page table Signed-off-by: Xiao Guangrong xiaoguangr...@cn.fujitsu.com Signed-off-by: Avi Kivity a...@redhat.com diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index afde64b..ba7e764 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -53,14 +53,18 @@ enum { AUDIT_PRE_PAGE_FAULT, AUDIT_POST_PAGE_FAULT, AUDIT_PRE_PTE_WRITE, - AUDIT_POST_PTE_WRITE + AUDIT_POST_PTE_WRITE, + AUDIT_PRE_SYNC, + AUDIT_POST_SYNC }; char *audit_point_name[] = { pre page fault, post page fault, pre pte write, - post pte write + post pte write, + pre sync, + post sync }; #undef MMU_DEBUG @@ -2516,6 +2520,8 @@ static void mmu_sync_roots(struct kvm_vcpu *vcpu) if (!VALID_PAGE(vcpu-arch.mmu.root_hpa)) return; + + trace_kvm_mmu_audit(vcpu, AUDIT_PRE_SYNC); if (vcpu-arch.mmu.root_level == PT64_ROOT_LEVEL) { hpa_t root = vcpu-arch.mmu.root_hpa; sp = page_header(root); @@ -2531,6 +2537,7 @@ static void mmu_sync_roots(struct kvm_vcpu *vcpu) mmu_sync_children(vcpu, sp); } } + trace_kvm_mmu_audit(vcpu, AUDIT_POST_SYNC); } void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu) diff --git a/arch/x86/kvm/mmu_audit.c b/arch/x86/kvm/mmu_audit.c index 66219af..4aee32c 100644 --- a/arch/x86/kvm/mmu_audit.c +++ b/arch/x86/kvm/mmu_audit.c @@ -164,6 +164,14 @@ static void audit_sptes_have_rmaps(struct kvm_vcpu *vcpu, u64 *sptep, int level) inspect_spte_has_rmap(vcpu-kvm, sptep); } +static void audit_spte_after_sync(struct kvm_vcpu *vcpu, u64 *sptep, int level) +{ + struct kvm_mmu_page *sp = page_header(__pa(sptep)); + + if (audit_point == AUDIT_POST_SYNC sp-unsync) + audit_printk(meet unsync sp(%p) after sync root.\n, sp); +} + static void check_mappings_rmap(struct kvm *kvm, struct kvm_mmu_page *sp) { int i; @@ -179,7 +187,7 @@ static void check_mappings_rmap(struct kvm *kvm, struct kvm_mmu_page *sp) } } -void audit_write_protection(struct kvm *kvm, struct kvm_mmu_page *sp) +static void audit_write_protection(struct kvm *kvm, struct kvm_mmu_page *sp) { struct kvm_memory_slot *slot; unsigned long *rmapp; @@ -215,6 +223,7 @@ static void audit_spte(struct kvm_vcpu *vcpu, u64 *sptep, int level) { audit_sptes_have_rmaps(vcpu, sptep, level); audit_mappings(vcpu, sptep, level); + audit_spte_after_sync(vcpu, sptep, level); } static void audit_vcpu_spte(struct kvm_vcpu *vcpu) -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[COMMIT master] KVM: MMU: move access code parsing to FNAME(walk_addr) function
From: Xiao Guangrong xiaoguangr...@cn.fujitsu.com Move access code parsing from caller site to FNAME(walk_addr) function Signed-off-by: Xiao Guangrong xiaoguangr...@cn.fujitsu.com Signed-off-by: Avi Kivity a...@redhat.com diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h index a83ff37..9a5f7bb 100644 --- a/arch/x86/kvm/paging_tmpl.h +++ b/arch/x86/kvm/paging_tmpl.h @@ -116,16 +116,18 @@ static unsigned FNAME(gpte_access)(struct kvm_vcpu *vcpu, pt_element_t gpte) */ static int FNAME(walk_addr_generic)(struct guest_walker *walker, struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, - gva_t addr, int write_fault, - int user_fault, int fetch_fault) + gva_t addr, u32 access) { pt_element_t pte; gfn_t table_gfn; unsigned index, pt_access, uninitialized_var(pte_access); gpa_t pte_gpa; bool eperm, present, rsvd_fault; - int offset; - u32 access = 0; + int offset, write_fault, user_fault, fetch_fault; + + write_fault = access PFERR_WRITE_MASK; + user_fault = access PFERR_USER_MASK; + fetch_fault = access PFERR_FETCH_MASK; trace_kvm_mmu_pagetable_walk(addr, write_fault, user_fault, fetch_fault); @@ -215,6 +217,7 @@ walk: int lvl = walker-level; gpa_t real_gpa; gfn_t gfn; + u32 ac; gfn = gpte_to_gfn_lvl(pte, lvl); gfn += (addr PT_LVL_OFFSET_MASK(lvl)) PAGE_SHIFT; @@ -224,10 +227,10 @@ walk: is_cpuid_PSE36()) gfn += pse36_gfn_delta(pte); - access |= write_fault | fetch_fault | user_fault; + ac = write_fault | fetch_fault | user_fault; real_gpa = mmu-translate_gpa(vcpu, gfn_to_gpa(gfn), - access); + ac); if (real_gpa == UNMAPPED_GVA) return 0; @@ -282,21 +285,18 @@ error: } static int FNAME(walk_addr)(struct guest_walker *walker, - struct kvm_vcpu *vcpu, gva_t addr, - int write_fault, int user_fault, int fetch_fault) + struct kvm_vcpu *vcpu, gva_t addr, u32 access) { return FNAME(walk_addr_generic)(walker, vcpu, vcpu-arch.mmu, addr, - write_fault, user_fault, fetch_fault); + access); } static int FNAME(walk_addr_nested)(struct guest_walker *walker, struct kvm_vcpu *vcpu, gva_t addr, - int write_fault, int user_fault, - int fetch_fault) + u32 access) { return FNAME(walk_addr_generic)(walker, vcpu, vcpu-arch.nested_mmu, - addr, write_fault, user_fault, - fetch_fault); + addr, access); } static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, @@ -532,7 +532,6 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, { int write_fault = error_code PFERR_WRITE_MASK; int user_fault = error_code PFERR_USER_MASK; - int fetch_fault = error_code PFERR_FETCH_MASK; struct guest_walker walker; u64 *sptep; int write_pt = 0; @@ -550,8 +549,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, /* * Look up the guest pte for the faulting address. */ - r = FNAME(walk_addr)(walker, vcpu, addr, write_fault, user_fault, -fetch_fault); + r = FNAME(walk_addr)(walker, vcpu, addr, error_code); /* * The page is not mapped by the guest. Let the guest handle it. @@ -669,10 +667,7 @@ static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr, u32 access, gpa_t gpa = UNMAPPED_GVA; int r; - r = FNAME(walk_addr)(walker, vcpu, vaddr, -access PFERR_WRITE_MASK, -access PFERR_USER_MASK, -access PFERR_FETCH_MASK); + r = FNAME(walk_addr)(walker, vcpu, vaddr, access); if (r) { gpa = gfn_to_gpa(walker.gfn); @@ -690,10 +685,7 @@ static gpa_t FNAME(gva_to_gpa_nested)(struct kvm_vcpu *vcpu, gva_t vaddr, gpa_t gpa = UNMAPPED_GVA; int r; - r = FNAME(walk_addr_nested)(walker, vcpu, vaddr, - access PFERR_WRITE_MASK, -
[COMMIT master] KVM: Disable interrupts around get_kernel_ns()
From: Avi Kivity a...@redhat.com get_kernel_ns() wants preemption disabled. It doesn't make a lot of sense during the get/set ioctls (no way to make them non-racy) but the callee wants it. Signed-off-by: Avi Kivity a...@redhat.com diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3729bcb..899acbb 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3469,8 +3469,10 @@ long kvm_arch_vm_ioctl(struct file *filp, goto out; r = 0; + local_irq_disable(); now_ns = get_kernel_ns(); delta = user_ns.clock - now_ns; + local_irq_enable(); kvm-arch.kvmclock_offset = delta; break; } @@ -3478,8 +3480,10 @@ long kvm_arch_vm_ioctl(struct file *filp, struct kvm_clock_data user_ns; u64 now_ns; + local_irq_disable(); now_ns = get_kernel_ns(); user_ns.clock = kvm-arch.kvmclock_offset + now_ns; + local_irq_enable(); user_ns.flags = 0; r = -EFAULT; -- To unsubscribe from this list: send the line unsubscribe kvm-commits in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html