mirror of
https://github.com/torvalds/linux.git
synced 2024-12-26 21:02:19 +00:00
9cf7c0e465
When enabling the current KVM code on e500mc, I get the following oops: Oops: Exception in kernel mode, sig: 4 [#1] SMP NR_CPUS=8 P2041 RDB Modules linked in: NIP: c067df4c LR: c067df44 CTR: 00000000 REGS: ee055ed0 TRAP: 0700 Not tainted (3.2.0-10391-g36c5afe) MSR: 00029002 <CE,EE,ME> CR: 24042022 XER: 00000000 TASK = ee0429b0[1] 'swapper/0' THREAD: ee054000 CPU: 2 GPR00: c067df44 ee055f80 ee0429b0 00000000 00000058 0000003f ee211600 60c6b864 GPR08: 7cc903a6 0000002c 00000000 00000001 44042082 2d180088 00000000 00000000 GPR16: c0000a00 00000014 3fffffff 03fe9000 00000015 7ff3be68 c06e0000 00000000 GPR24: 00000000 00000000 00001720 c067df1c c06e0000 00000000 ee054000 c06ab51c NIP [c067df4c] kvmppc_e500_init+0x30/0xf8 LR [c067df44] kvmppc_e500_init+0x28/0xf8 Call Trace: [ee055f80] [c067df44] kvmppc_e500_init+0x28/0xf8 (unreliable) [ee055fb0] [c0001d30] do_one_initcall+0x50/0x1f0 [ee055fe0] [c06721dc] kernel_init+0xa4/0x14c [ee055ff0] [c000e910] kernel_thread+0x4c/0x68 Instruction dump: 9421ffd0 7c0802a6 93410018 9361001c 90010034 93810020 93a10024 93c10028 93e1002c 4bfffe7d 2c030000 408200a4 <7c1082a6> 90010008 7c1182a6 9001000c ---[ end trace b8ef4903fcbf9dd3 ]--- Since it doesn't make sense to run the init function on any non-supported platform, we can just call our "is this platform supported?" function and bail out of init() if it's not. Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Avi Kivity <avi@redhat.com>
265 lines
6.3 KiB
C
265 lines
6.3 KiB
C
/*
|
|
* Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved.
|
|
*
|
|
* Author: Yu Liu, <yu.liu@freescale.com>
|
|
*
|
|
* Description:
|
|
* This file is derived from arch/powerpc/kvm/44x.c,
|
|
* by Hollis Blanchard <hollisb@us.ibm.com>.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License, version 2, as
|
|
* published by the Free Software Foundation.
|
|
*/
|
|
|
|
#include <linux/kvm_host.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/err.h>
|
|
#include <linux/export.h>
|
|
|
|
#include <asm/reg.h>
|
|
#include <asm/cputable.h>
|
|
#include <asm/tlbflush.h>
|
|
#include <asm/kvm_e500.h>
|
|
#include <asm/kvm_ppc.h>
|
|
|
|
#include "booke.h"
|
|
#include "e500_tlb.h"
|
|
|
|
void kvmppc_core_load_host_debugstate(struct kvm_vcpu *vcpu)
|
|
{
|
|
}
|
|
|
|
void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu)
|
|
{
|
|
}
|
|
|
|
void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
|
|
{
|
|
kvmppc_e500_tlb_load(vcpu, cpu);
|
|
}
|
|
|
|
void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
|
|
{
|
|
kvmppc_e500_tlb_put(vcpu);
|
|
|
|
#ifdef CONFIG_SPE
|
|
if (vcpu->arch.shadow_msr & MSR_SPE)
|
|
kvmppc_vcpu_disable_spe(vcpu);
|
|
#endif
|
|
}
|
|
|
|
int kvmppc_core_check_processor_compat(void)
|
|
{
|
|
int r;
|
|
|
|
if (strcmp(cur_cpu_spec->cpu_name, "e500v2") == 0)
|
|
r = 0;
|
|
else
|
|
r = -ENOTSUPP;
|
|
|
|
return r;
|
|
}
|
|
|
|
int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
|
|
{
|
|
struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
|
|
|
|
kvmppc_e500_tlb_setup(vcpu_e500);
|
|
|
|
/* Registers init */
|
|
vcpu->arch.pvr = mfspr(SPRN_PVR);
|
|
vcpu_e500->svr = mfspr(SPRN_SVR);
|
|
|
|
vcpu->arch.cpu_type = KVM_CPU_E500V2;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* 'linear_address' is actually an encoding of AS|PID|EADDR . */
|
|
int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu,
|
|
struct kvm_translation *tr)
|
|
{
|
|
int index;
|
|
gva_t eaddr;
|
|
u8 pid;
|
|
u8 as;
|
|
|
|
eaddr = tr->linear_address;
|
|
pid = (tr->linear_address >> 32) & 0xff;
|
|
as = (tr->linear_address >> 40) & 0x1;
|
|
|
|
index = kvmppc_e500_tlb_search(vcpu, eaddr, pid, as);
|
|
if (index < 0) {
|
|
tr->valid = 0;
|
|
return 0;
|
|
}
|
|
|
|
tr->physical_address = kvmppc_mmu_xlate(vcpu, index, eaddr);
|
|
/* XXX what does "writeable" and "usermode" even mean? */
|
|
tr->valid = 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
|
|
{
|
|
struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
|
|
|
|
sregs->u.e.features |= KVM_SREGS_E_ARCH206_MMU | KVM_SREGS_E_SPE |
|
|
KVM_SREGS_E_PM;
|
|
sregs->u.e.impl_id = KVM_SREGS_E_IMPL_FSL;
|
|
|
|
sregs->u.e.impl.fsl.features = 0;
|
|
sregs->u.e.impl.fsl.svr = vcpu_e500->svr;
|
|
sregs->u.e.impl.fsl.hid0 = vcpu_e500->hid0;
|
|
sregs->u.e.impl.fsl.mcar = vcpu_e500->mcar;
|
|
|
|
sregs->u.e.mas0 = vcpu->arch.shared->mas0;
|
|
sregs->u.e.mas1 = vcpu->arch.shared->mas1;
|
|
sregs->u.e.mas2 = vcpu->arch.shared->mas2;
|
|
sregs->u.e.mas7_3 = vcpu->arch.shared->mas7_3;
|
|
sregs->u.e.mas4 = vcpu->arch.shared->mas4;
|
|
sregs->u.e.mas6 = vcpu->arch.shared->mas6;
|
|
|
|
sregs->u.e.mmucfg = mfspr(SPRN_MMUCFG);
|
|
sregs->u.e.tlbcfg[0] = vcpu_e500->tlb0cfg;
|
|
sregs->u.e.tlbcfg[1] = vcpu_e500->tlb1cfg;
|
|
sregs->u.e.tlbcfg[2] = 0;
|
|
sregs->u.e.tlbcfg[3] = 0;
|
|
|
|
sregs->u.e.ivor_high[0] = vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_UNAVAIL];
|
|
sregs->u.e.ivor_high[1] = vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_DATA];
|
|
sregs->u.e.ivor_high[2] = vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_ROUND];
|
|
sregs->u.e.ivor_high[3] =
|
|
vcpu->arch.ivor[BOOKE_IRQPRIO_PERFORMANCE_MONITOR];
|
|
|
|
kvmppc_get_sregs_ivor(vcpu, sregs);
|
|
}
|
|
|
|
int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
|
|
{
|
|
struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
|
|
|
|
if (sregs->u.e.impl_id == KVM_SREGS_E_IMPL_FSL) {
|
|
vcpu_e500->svr = sregs->u.e.impl.fsl.svr;
|
|
vcpu_e500->hid0 = sregs->u.e.impl.fsl.hid0;
|
|
vcpu_e500->mcar = sregs->u.e.impl.fsl.mcar;
|
|
}
|
|
|
|
if (sregs->u.e.features & KVM_SREGS_E_ARCH206_MMU) {
|
|
vcpu->arch.shared->mas0 = sregs->u.e.mas0;
|
|
vcpu->arch.shared->mas1 = sregs->u.e.mas1;
|
|
vcpu->arch.shared->mas2 = sregs->u.e.mas2;
|
|
vcpu->arch.shared->mas7_3 = sregs->u.e.mas7_3;
|
|
vcpu->arch.shared->mas4 = sregs->u.e.mas4;
|
|
vcpu->arch.shared->mas6 = sregs->u.e.mas6;
|
|
}
|
|
|
|
if (!(sregs->u.e.features & KVM_SREGS_E_IVOR))
|
|
return 0;
|
|
|
|
if (sregs->u.e.features & KVM_SREGS_E_SPE) {
|
|
vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_UNAVAIL] =
|
|
sregs->u.e.ivor_high[0];
|
|
vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_DATA] =
|
|
sregs->u.e.ivor_high[1];
|
|
vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_ROUND] =
|
|
sregs->u.e.ivor_high[2];
|
|
}
|
|
|
|
if (sregs->u.e.features & KVM_SREGS_E_PM) {
|
|
vcpu->arch.ivor[BOOKE_IRQPRIO_PERFORMANCE_MONITOR] =
|
|
sregs->u.e.ivor_high[3];
|
|
}
|
|
|
|
return kvmppc_set_sregs_ivor(vcpu, sregs);
|
|
}
|
|
|
|
struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
|
|
{
|
|
struct kvmppc_vcpu_e500 *vcpu_e500;
|
|
struct kvm_vcpu *vcpu;
|
|
int err;
|
|
|
|
vcpu_e500 = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
|
|
if (!vcpu_e500) {
|
|
err = -ENOMEM;
|
|
goto out;
|
|
}
|
|
|
|
vcpu = &vcpu_e500->vcpu;
|
|
err = kvm_vcpu_init(vcpu, kvm, id);
|
|
if (err)
|
|
goto free_vcpu;
|
|
|
|
err = kvmppc_e500_tlb_init(vcpu_e500);
|
|
if (err)
|
|
goto uninit_vcpu;
|
|
|
|
vcpu->arch.shared = (void*)__get_free_page(GFP_KERNEL|__GFP_ZERO);
|
|
if (!vcpu->arch.shared)
|
|
goto uninit_tlb;
|
|
|
|
return vcpu;
|
|
|
|
uninit_tlb:
|
|
kvmppc_e500_tlb_uninit(vcpu_e500);
|
|
uninit_vcpu:
|
|
kvm_vcpu_uninit(vcpu);
|
|
free_vcpu:
|
|
kmem_cache_free(kvm_vcpu_cache, vcpu_e500);
|
|
out:
|
|
return ERR_PTR(err);
|
|
}
|
|
|
|
void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
|
|
{
|
|
struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
|
|
|
|
free_page((unsigned long)vcpu->arch.shared);
|
|
kvm_vcpu_uninit(vcpu);
|
|
kvmppc_e500_tlb_uninit(vcpu_e500);
|
|
kmem_cache_free(kvm_vcpu_cache, vcpu_e500);
|
|
}
|
|
|
|
static int __init kvmppc_e500_init(void)
|
|
{
|
|
int r, i;
|
|
unsigned long ivor[3];
|
|
unsigned long max_ivor = 0;
|
|
|
|
r = kvmppc_core_check_processor_compat();
|
|
if (r)
|
|
return r;
|
|
|
|
r = kvmppc_booke_init();
|
|
if (r)
|
|
return r;
|
|
|
|
/* copy extra E500 exception handlers */
|
|
ivor[0] = mfspr(SPRN_IVOR32);
|
|
ivor[1] = mfspr(SPRN_IVOR33);
|
|
ivor[2] = mfspr(SPRN_IVOR34);
|
|
for (i = 0; i < 3; i++) {
|
|
if (ivor[i] > max_ivor)
|
|
max_ivor = ivor[i];
|
|
|
|
memcpy((void *)kvmppc_booke_handlers + ivor[i],
|
|
kvmppc_handlers_start + (i + 16) * kvmppc_handler_len,
|
|
kvmppc_handler_len);
|
|
}
|
|
flush_icache_range(kvmppc_booke_handlers,
|
|
kvmppc_booke_handlers + max_ivor + kvmppc_handler_len);
|
|
|
|
return kvm_init(NULL, sizeof(struct kvmppc_vcpu_e500), 0, THIS_MODULE);
|
|
}
|
|
|
|
static void __exit kvmppc_e500_exit(void)
|
|
{
|
|
kvmppc_booke_exit();
|
|
}
|
|
|
|
module_init(kvmppc_e500_init);
|
|
module_exit(kvmppc_e500_exit);
|