Commit 899f7b26 authored by Alexander Graf's avatar Alexander Graf

Merge commit 'origin/next' into kvm-ppc-next

parents 011da899 cbd29cb6
...@@ -55,6 +55,13 @@ static int psw_interrupts_disabled(struct kvm_vcpu *vcpu) ...@@ -55,6 +55,13 @@ static int psw_interrupts_disabled(struct kvm_vcpu *vcpu)
return 1; return 1;
} }
static u64 int_word_to_isc_bits(u32 int_word)
{
u8 isc = (int_word & 0x38000000) >> 27;
return (0x80 >> isc) << 24;
}
static int __interrupt_is_deliverable(struct kvm_vcpu *vcpu, static int __interrupt_is_deliverable(struct kvm_vcpu *vcpu,
struct kvm_s390_interrupt_info *inti) struct kvm_s390_interrupt_info *inti)
{ {
...@@ -96,7 +103,8 @@ static int __interrupt_is_deliverable(struct kvm_vcpu *vcpu, ...@@ -96,7 +103,8 @@ static int __interrupt_is_deliverable(struct kvm_vcpu *vcpu,
case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
if (psw_ioint_disabled(vcpu)) if (psw_ioint_disabled(vcpu))
return 0; return 0;
if (vcpu->arch.sie_block->gcr[6] & inti->io.io_int_word) if (vcpu->arch.sie_block->gcr[6] &
int_word_to_isc_bits(inti->io.io_int_word))
return 1; return 1;
return 0; return 0;
default: default:
...@@ -724,7 +732,8 @@ struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm, ...@@ -724,7 +732,8 @@ struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm,
list_for_each_entry(iter, &fi->list, list) { list_for_each_entry(iter, &fi->list, list) {
if (!is_ioint(iter->type)) if (!is_ioint(iter->type))
continue; continue;
if (cr6 && ((cr6 & iter->io.io_int_word) == 0)) if (cr6 &&
((cr6 & int_word_to_isc_bits(iter->io.io_int_word)) == 0))
continue; continue;
if (schid) { if (schid) {
if (((schid & 0x00000000ffff0000) >> 16) != if (((schid & 0x00000000ffff0000) >> 16) !=
...@@ -811,11 +820,14 @@ int kvm_s390_inject_vm(struct kvm *kvm, ...@@ -811,11 +820,14 @@ int kvm_s390_inject_vm(struct kvm *kvm,
if (!is_ioint(inti->type)) if (!is_ioint(inti->type))
list_add_tail(&inti->list, &fi->list); list_add_tail(&inti->list, &fi->list);
else { else {
u64 isc_bits = int_word_to_isc_bits(inti->io.io_int_word);
/* Keep I/O interrupts sorted in isc order. */ /* Keep I/O interrupts sorted in isc order. */
list_for_each_entry(iter, &fi->list, list) { list_for_each_entry(iter, &fi->list, list) {
if (!is_ioint(iter->type)) if (!is_ioint(iter->type))
continue; continue;
if (iter->io.io_int_word <= inti->io.io_int_word) if (int_word_to_isc_bits(iter->io.io_int_word)
<= isc_bits)
continue; continue;
break; break;
} }
......
...@@ -2995,14 +2995,11 @@ static int em_aad(struct x86_emulate_ctxt *ctxt) ...@@ -2995,14 +2995,11 @@ static int em_aad(struct x86_emulate_ctxt *ctxt)
ctxt->dst.val = (ctxt->dst.val & 0xffff0000) | al; ctxt->dst.val = (ctxt->dst.val & 0xffff0000) | al;
ctxt->eflags &= ~(X86_EFLAGS_PF | X86_EFLAGS_SF | X86_EFLAGS_ZF); /* Set PF, ZF, SF */
ctxt->src.type = OP_IMM;
if (!al) ctxt->src.val = 0;
ctxt->eflags |= X86_EFLAGS_ZF; ctxt->src.bytes = 1;
if (!(al & 1)) fastop(ctxt, em_or);
ctxt->eflags |= X86_EFLAGS_PF;
if (al & 0x80)
ctxt->eflags |= X86_EFLAGS_SF;
return X86EMUL_CONTINUE; return X86EMUL_CONTINUE;
} }
......
...@@ -832,8 +832,7 @@ static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn) ...@@ -832,8 +832,7 @@ static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn)
if (host_level == PT_PAGE_TABLE_LEVEL) if (host_level == PT_PAGE_TABLE_LEVEL)
return host_level; return host_level;
max_level = kvm_x86_ops->get_lpage_level() < host_level ? max_level = min(kvm_x86_ops->get_lpage_level(), host_level);
kvm_x86_ops->get_lpage_level() : host_level;
for (level = PT_DIRECTORY_LEVEL; level <= max_level; ++level) for (level = PT_DIRECTORY_LEVEL; level <= max_level; ++level)
if (has_wrprotected_page(vcpu->kvm, large_gfn, level)) if (has_wrprotected_page(vcpu->kvm, large_gfn, level))
...@@ -1106,8 +1105,7 @@ static void drop_large_spte(struct kvm_vcpu *vcpu, u64 *sptep) ...@@ -1106,8 +1105,7 @@ static void drop_large_spte(struct kvm_vcpu *vcpu, u64 *sptep)
/* /*
* Write-protect on the specified @sptep, @pt_protect indicates whether * Write-protect on the specified @sptep, @pt_protect indicates whether
* spte writ-protection is caused by protecting shadow page table. * spte write-protection is caused by protecting shadow page table.
* @flush indicates whether tlb need be flushed.
* *
* Note: write protection is difference between drity logging and spte * Note: write protection is difference between drity logging and spte
* protection: * protection:
...@@ -1116,10 +1114,9 @@ static void drop_large_spte(struct kvm_vcpu *vcpu, u64 *sptep) ...@@ -1116,10 +1114,9 @@ static void drop_large_spte(struct kvm_vcpu *vcpu, u64 *sptep)
* - for spte protection, the spte can be writable only after unsync-ing * - for spte protection, the spte can be writable only after unsync-ing
* shadow page. * shadow page.
* *
* Return true if the spte is dropped. * Return true if tlb need be flushed.
*/ */
static bool static bool spte_write_protect(struct kvm *kvm, u64 *sptep, bool pt_protect)
spte_write_protect(struct kvm *kvm, u64 *sptep, bool *flush, bool pt_protect)
{ {
u64 spte = *sptep; u64 spte = *sptep;
...@@ -1129,17 +1126,11 @@ spte_write_protect(struct kvm *kvm, u64 *sptep, bool *flush, bool pt_protect) ...@@ -1129,17 +1126,11 @@ spte_write_protect(struct kvm *kvm, u64 *sptep, bool *flush, bool pt_protect)
rmap_printk("rmap_write_protect: spte %p %llx\n", sptep, *sptep); rmap_printk("rmap_write_protect: spte %p %llx\n", sptep, *sptep);
if (__drop_large_spte(kvm, sptep)) {
*flush |= true;
return true;
}
if (pt_protect) if (pt_protect)
spte &= ~SPTE_MMU_WRITEABLE; spte &= ~SPTE_MMU_WRITEABLE;
spte = spte & ~PT_WRITABLE_MASK; spte = spte & ~PT_WRITABLE_MASK;
*flush |= mmu_spte_update(sptep, spte); return mmu_spte_update(sptep, spte);
return false;
} }
static bool __rmap_write_protect(struct kvm *kvm, unsigned long *rmapp, static bool __rmap_write_protect(struct kvm *kvm, unsigned long *rmapp,
...@@ -1151,11 +1142,8 @@ static bool __rmap_write_protect(struct kvm *kvm, unsigned long *rmapp, ...@@ -1151,11 +1142,8 @@ static bool __rmap_write_protect(struct kvm *kvm, unsigned long *rmapp,
for (sptep = rmap_get_first(*rmapp, &iter); sptep;) { for (sptep = rmap_get_first(*rmapp, &iter); sptep;) {
BUG_ON(!(*sptep & PT_PRESENT_MASK)); BUG_ON(!(*sptep & PT_PRESENT_MASK));
if (spte_write_protect(kvm, sptep, &flush, pt_protect)) {
sptep = rmap_get_first(*rmapp, &iter);
continue;
}
flush |= spte_write_protect(kvm, sptep, pt_protect);
sptep = rmap_get_next(&iter); sptep = rmap_get_next(&iter);
} }
...@@ -1959,9 +1947,9 @@ static void link_shadow_page(u64 *sptep, struct kvm_mmu_page *sp) ...@@ -1959,9 +1947,9 @@ static void link_shadow_page(u64 *sptep, struct kvm_mmu_page *sp)
{ {
u64 spte; u64 spte;
spte = __pa(sp->spt) spte = __pa(sp->spt) | PT_PRESENT_MASK | PT_WRITABLE_MASK |
| PT_PRESENT_MASK | PT_ACCESSED_MASK shadow_user_mask | shadow_x_mask | shadow_accessed_mask;
| PT_WRITABLE_MASK | PT_USER_MASK;
mmu_spte_set(sptep, spte); mmu_spte_set(sptep, spte);
} }
...@@ -2400,16 +2388,15 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep, ...@@ -2400,16 +2388,15 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
} }
static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
unsigned pt_access, unsigned pte_access, unsigned pte_access, int write_fault, int *emulate,
int write_fault, int *emulate, int level, gfn_t gfn, int level, gfn_t gfn, pfn_t pfn, bool speculative,
pfn_t pfn, bool speculative, bool host_writable) bool host_writable)
{ {
int was_rmapped = 0; int was_rmapped = 0;
int rmap_count; int rmap_count;
pgprintk("%s: spte %llx access %x write_fault %d gfn %llx\n", pgprintk("%s: spte %llx write_fault %d gfn %llx\n", __func__,
__func__, *sptep, pt_access, *sptep, write_fault, gfn);
write_fault, gfn);
if (is_rmap_spte(*sptep)) { if (is_rmap_spte(*sptep)) {
/* /*
...@@ -2525,7 +2512,7 @@ static int direct_pte_prefetch_many(struct kvm_vcpu *vcpu, ...@@ -2525,7 +2512,7 @@ static int direct_pte_prefetch_many(struct kvm_vcpu *vcpu,
return -1; return -1;
for (i = 0; i < ret; i++, gfn++, start++) for (i = 0; i < ret; i++, gfn++, start++)
mmu_set_spte(vcpu, start, ACC_ALL, access, 0, NULL, mmu_set_spte(vcpu, start, access, 0, NULL,
sp->role.level, gfn, page_to_pfn(pages[i]), sp->role.level, gfn, page_to_pfn(pages[i]),
true, true); true, true);
...@@ -2586,9 +2573,7 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write, ...@@ -2586,9 +2573,7 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write,
for_each_shadow_entry(vcpu, (u64)gfn << PAGE_SHIFT, iterator) { for_each_shadow_entry(vcpu, (u64)gfn << PAGE_SHIFT, iterator) {
if (iterator.level == level) { if (iterator.level == level) {
unsigned pte_access = ACC_ALL; mmu_set_spte(vcpu, iterator.sptep, ACC_ALL,
mmu_set_spte(vcpu, iterator.sptep, ACC_ALL, pte_access,
write, &emulate, level, gfn, pfn, write, &emulate, level, gfn, pfn,
prefault, map_writable); prefault, map_writable);
direct_pte_prefetch(vcpu, iterator.sptep); direct_pte_prefetch(vcpu, iterator.sptep);
...@@ -2596,6 +2581,8 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write, ...@@ -2596,6 +2581,8 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write,
break; break;
} }
drop_large_spte(vcpu, iterator.sptep);
if (!is_shadow_present_pte(*iterator.sptep)) { if (!is_shadow_present_pte(*iterator.sptep)) {
u64 base_addr = iterator.addr; u64 base_addr = iterator.addr;
...@@ -2605,11 +2592,7 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write, ...@@ -2605,11 +2592,7 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write,
iterator.level - 1, iterator.level - 1,
1, ACC_ALL, iterator.sptep); 1, ACC_ALL, iterator.sptep);
mmu_spte_set(iterator.sptep, link_shadow_page(iterator.sptep, sp);
__pa(sp->spt)
| PT_PRESENT_MASK | PT_WRITABLE_MASK
| shadow_user_mask | shadow_x_mask
| shadow_accessed_mask);
} }
} }
return emulate; return emulate;
......
...@@ -326,8 +326,8 @@ FNAME(prefetch_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, ...@@ -326,8 +326,8 @@ FNAME(prefetch_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
* we call mmu_set_spte() with host_writable = true because * we call mmu_set_spte() with host_writable = true because
* pte_prefetch_gfn_to_pfn always gets a writable pfn. * pte_prefetch_gfn_to_pfn always gets a writable pfn.
*/ */
mmu_set_spte(vcpu, spte, sp->role.access, pte_access, 0, mmu_set_spte(vcpu, spte, pte_access, 0, NULL, PT_PAGE_TABLE_LEVEL,
NULL, PT_PAGE_TABLE_LEVEL, gfn, pfn, true, true); gfn, pfn, true, true);
return true; return true;
} }
...@@ -470,9 +470,8 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr, ...@@ -470,9 +470,8 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr,
} }
clear_sp_write_flooding_count(it.sptep); clear_sp_write_flooding_count(it.sptep);
mmu_set_spte(vcpu, it.sptep, access, gw->pte_access, mmu_set_spte(vcpu, it.sptep, gw->pte_access, write_fault, &emulate,
write_fault, &emulate, it.level, it.level, gw->gfn, pfn, prefault, map_writable);
gw->gfn, pfn, prefault, map_writable);
FNAME(pte_prefetch)(vcpu, gw, it.sptep); FNAME(pte_prefetch)(vcpu, gw, it.sptep);
return emulate; return emulate;
......
...@@ -84,8 +84,7 @@ module_param(vmm_exclusive, bool, S_IRUGO); ...@@ -84,8 +84,7 @@ module_param(vmm_exclusive, bool, S_IRUGO);
static bool __read_mostly fasteoi = 1; static bool __read_mostly fasteoi = 1;
module_param(fasteoi, bool, S_IRUGO); module_param(fasteoi, bool, S_IRUGO);
static bool __read_mostly enable_apicv_reg_vid = 1; static bool __read_mostly enable_apicv_reg_vid;
module_param(enable_apicv_reg_vid, bool, S_IRUGO);
/* /*
* If nested=1, nested virtualization is supported, i.e., guests may use * If nested=1, nested virtualization is supported, i.e., guests may use
...@@ -95,12 +94,8 @@ module_param(enable_apicv_reg_vid, bool, S_IRUGO); ...@@ -95,12 +94,8 @@ module_param(enable_apicv_reg_vid, bool, S_IRUGO);
static bool __read_mostly nested = 0; static bool __read_mostly nested = 0;
module_param(nested, bool, S_IRUGO); module_param(nested, bool, S_IRUGO);
#define KVM_GUEST_CR0_MASK_UNRESTRICTED_GUEST \ #define KVM_GUEST_CR0_MASK (X86_CR0_NW | X86_CR0_CD)
(X86_CR0_WP | X86_CR0_NE | X86_CR0_NW | X86_CR0_CD) #define KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST (X86_CR0_WP | X86_CR0_NE)
#define KVM_GUEST_CR0_MASK \
(KVM_GUEST_CR0_MASK_UNRESTRICTED_GUEST | X86_CR0_PG | X86_CR0_PE)
#define KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST \
(X86_CR0_WP | X86_CR0_NE)
#define KVM_VM_CR0_ALWAYS_ON \ #define KVM_VM_CR0_ALWAYS_ON \
(KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST | X86_CR0_PG | X86_CR0_PE) (KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST | X86_CR0_PG | X86_CR0_PE)
#define KVM_CR4_GUEST_OWNED_BITS \ #define KVM_CR4_GUEST_OWNED_BITS \
...@@ -3137,11 +3132,11 @@ static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0) ...@@ -3137,11 +3132,11 @@ static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
struct vcpu_vmx *vmx = to_vmx(vcpu); struct vcpu_vmx *vmx = to_vmx(vcpu);
unsigned long hw_cr0; unsigned long hw_cr0;
hw_cr0 = (cr0 & ~KVM_GUEST_CR0_MASK);
if (enable_unrestricted_guest) if (enable_unrestricted_guest)
hw_cr0 = (cr0 & ~KVM_GUEST_CR0_MASK_UNRESTRICTED_GUEST) hw_cr0 |= KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST;
| KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST;
else { else {
hw_cr0 = (cr0 & ~KVM_GUEST_CR0_MASK) | KVM_VM_CR0_ALWAYS_ON; hw_cr0 |= KVM_VM_CR0_ALWAYS_ON;
if (vmx->rmode.vm86_active && (cr0 & X86_CR0_PE)) if (vmx->rmode.vm86_active && (cr0 & X86_CR0_PE))
enter_pmode(vcpu); enter_pmode(vcpu);
...@@ -5925,7 +5920,7 @@ static bool nested_vmx_exit_handled_msr(struct kvm_vcpu *vcpu, ...@@ -5925,7 +5920,7 @@ static bool nested_vmx_exit_handled_msr(struct kvm_vcpu *vcpu,
u32 msr_index = vcpu->arch.regs[VCPU_REGS_RCX]; u32 msr_index = vcpu->arch.regs[VCPU_REGS_RCX];
gpa_t bitmap; gpa_t bitmap;
if (!nested_cpu_has(get_vmcs12(vcpu), CPU_BASED_USE_MSR_BITMAPS)) if (!nested_cpu_has(vmcs12, CPU_BASED_USE_MSR_BITMAPS))
return 1; return 1;
/* /*
......
...@@ -6897,32 +6897,27 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, ...@@ -6897,32 +6897,27 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
bool user_alloc) bool user_alloc)
{ {
int npages = memslot->npages; int npages = memslot->npages;
int map_flags = MAP_PRIVATE | MAP_ANONYMOUS;
/* Prevent internal slot pages from being moved by fork()/COW. */ /*
if (memslot->id >= KVM_USER_MEM_SLOTS) * Only private memory slots need to be mapped here since
map_flags = MAP_SHARED | MAP_ANONYMOUS; * KVM_SET_MEMORY_REGION ioctl is no longer supported.
/*To keep backward compatibility with older userspace,
*x86 needs to handle !user_alloc case.
*/ */
if (!user_alloc) { if ((memslot->id >= KVM_USER_MEM_SLOTS) && npages && !old.npages) {
if (npages && !old.npages) {
unsigned long userspace_addr; unsigned long userspace_addr;
userspace_addr = vm_mmap(NULL, 0, /*
npages * PAGE_SIZE, * MAP_SHARED to prevent internal slot pages from being moved
* by fork()/COW.
*/
userspace_addr = vm_mmap(NULL, 0, npages * PAGE_SIZE,
PROT_READ | PROT_WRITE, PROT_READ | PROT_WRITE,
map_flags, MAP_SHARED | MAP_ANONYMOUS, 0);
0);
if (IS_ERR((void *)userspace_addr)) if (IS_ERR((void *)userspace_addr))
return PTR_ERR((void *)userspace_addr); return PTR_ERR((void *)userspace_addr);
memslot->userspace_addr = userspace_addr; memslot->userspace_addr = userspace_addr;
} }
}
return 0; return 0;
} }
...@@ -6935,7 +6930,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm, ...@@ -6935,7 +6930,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
int nr_mmu_pages = 0, npages = mem->memory_size >> PAGE_SHIFT; int nr_mmu_pages = 0, npages = mem->memory_size >> PAGE_SHIFT;
if (!user_alloc && !old.user_alloc && old.npages && !npages) { if ((mem->slot >= KVM_USER_MEM_SLOTS) && old.npages && !npages) {
int ret; int ret;
ret = vm_munmap(old.userspace_addr, ret = vm_munmap(old.userspace_addr,
......
...@@ -273,7 +273,6 @@ struct kvm_memory_slot { ...@@ -273,7 +273,6 @@ struct kvm_memory_slot {
unsigned long userspace_addr; unsigned long userspace_addr;
u32 flags; u32 flags;
short id; short id;
bool user_alloc;
}; };
static inline unsigned long kvm_dirty_bitmap_bytes(struct kvm_memory_slot *memslot) static inline unsigned long kvm_dirty_bitmap_bytes(struct kvm_memory_slot *memslot)
......
...@@ -839,7 +839,6 @@ int __kvm_set_memory_region(struct kvm *kvm, ...@@ -839,7 +839,6 @@ int __kvm_set_memory_region(struct kvm *kvm,
r = -ENOMEM; r = -ENOMEM;
if (change == KVM_MR_CREATE) { if (change == KVM_MR_CREATE) {
new.user_alloc = user_alloc;
new.userspace_addr = mem->userspace_addr; new.userspace_addr = mem->userspace_addr;
if (kvm_arch_create_memslot(&new, npages)) if (kvm_arch_create_memslot(&new, npages))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment