diff options
Diffstat (limited to 'arch/powerpc/kvm/book3s_hv.c')
-rw-r--r-- | arch/powerpc/kvm/book3s_hv.c | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index c6af1d623839..d084e412b3c5 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c | |||
@@ -56,7 +56,7 @@ | |||
56 | /* #define EXIT_DEBUG_INT */ | 56 | /* #define EXIT_DEBUG_INT */ |
57 | 57 | ||
58 | static void kvmppc_end_cede(struct kvm_vcpu *vcpu); | 58 | static void kvmppc_end_cede(struct kvm_vcpu *vcpu); |
59 | static int kvmppc_hv_setup_rma(struct kvm_vcpu *vcpu); | 59 | static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu); |
60 | 60 | ||
61 | void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu) | 61 | void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu) |
62 | { | 62 | { |
@@ -1068,11 +1068,15 @@ int kvmppc_vcpu_run(struct kvm_run *run, struct kvm_vcpu *vcpu) | |||
1068 | return -EINTR; | 1068 | return -EINTR; |
1069 | } | 1069 | } |
1070 | 1070 | ||
1071 | /* On the first time here, set up VRMA or RMA */ | 1071 | atomic_inc(&vcpu->kvm->arch.vcpus_running); |
1072 | /* Order vcpus_running vs. rma_setup_done, see kvmppc_alloc_reset_hpt */ | ||
1073 | smp_mb(); | ||
1074 | |||
1075 | /* On the first time here, set up HTAB and VRMA or RMA */ | ||
1072 | if (!vcpu->kvm->arch.rma_setup_done) { | 1076 | if (!vcpu->kvm->arch.rma_setup_done) { |
1073 | r = kvmppc_hv_setup_rma(vcpu); | 1077 | r = kvmppc_hv_setup_htab_rma(vcpu); |
1074 | if (r) | 1078 | if (r) |
1075 | return r; | 1079 | goto out; |
1076 | } | 1080 | } |
1077 | 1081 | ||
1078 | flush_fp_to_thread(current); | 1082 | flush_fp_to_thread(current); |
@@ -1090,6 +1094,9 @@ int kvmppc_vcpu_run(struct kvm_run *run, struct kvm_vcpu *vcpu) | |||
1090 | kvmppc_core_prepare_to_enter(vcpu); | 1094 | kvmppc_core_prepare_to_enter(vcpu); |
1091 | } | 1095 | } |
1092 | } while (r == RESUME_GUEST); | 1096 | } while (r == RESUME_GUEST); |
1097 | |||
1098 | out: | ||
1099 | atomic_dec(&vcpu->kvm->arch.vcpus_running); | ||
1093 | return r; | 1100 | return r; |
1094 | } | 1101 | } |
1095 | 1102 | ||
@@ -1305,7 +1312,7 @@ void kvmppc_core_commit_memory_region(struct kvm *kvm, | |||
1305 | { | 1312 | { |
1306 | } | 1313 | } |
1307 | 1314 | ||
1308 | static int kvmppc_hv_setup_rma(struct kvm_vcpu *vcpu) | 1315 | static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu) |
1309 | { | 1316 | { |
1310 | int err = 0; | 1317 | int err = 0; |
1311 | struct kvm *kvm = vcpu->kvm; | 1318 | struct kvm *kvm = vcpu->kvm; |
@@ -1324,6 +1331,15 @@ static int kvmppc_hv_setup_rma(struct kvm_vcpu *vcpu) | |||
1324 | if (kvm->arch.rma_setup_done) | 1331 | if (kvm->arch.rma_setup_done) |
1325 | goto out; /* another vcpu beat us to it */ | 1332 | goto out; /* another vcpu beat us to it */ |
1326 | 1333 | ||
1334 | /* Allocate hashed page table (if not done already) and reset it */ | ||
1335 | if (!kvm->arch.hpt_virt) { | ||
1336 | err = kvmppc_alloc_hpt(kvm, NULL); | ||
1337 | if (err) { | ||
1338 | pr_err("KVM: Couldn't alloc HPT\n"); | ||
1339 | goto out; | ||
1340 | } | ||
1341 | } | ||
1342 | |||
1327 | /* Look up the memslot for guest physical address 0 */ | 1343 | /* Look up the memslot for guest physical address 0 */ |
1328 | memslot = gfn_to_memslot(kvm, 0); | 1344 | memslot = gfn_to_memslot(kvm, 0); |
1329 | 1345 | ||
@@ -1435,13 +1451,14 @@ static int kvmppc_hv_setup_rma(struct kvm_vcpu *vcpu) | |||
1435 | 1451 | ||
1436 | int kvmppc_core_init_vm(struct kvm *kvm) | 1452 | int kvmppc_core_init_vm(struct kvm *kvm) |
1437 | { | 1453 | { |
1438 | long r; | 1454 | unsigned long lpcr, lpid; |
1439 | unsigned long lpcr; | ||
1440 | 1455 | ||
1441 | /* Allocate hashed page table */ | 1456 | /* Allocate the guest's logical partition ID */ |
1442 | r = kvmppc_alloc_hpt(kvm); | 1457 | |
1443 | if (r) | 1458 | lpid = kvmppc_alloc_lpid(); |
1444 | return r; | 1459 | if (lpid < 0) |
1460 | return -ENOMEM; | ||
1461 | kvm->arch.lpid = lpid; | ||
1445 | 1462 | ||
1446 | INIT_LIST_HEAD(&kvm->arch.spapr_tce_tables); | 1463 | INIT_LIST_HEAD(&kvm->arch.spapr_tce_tables); |
1447 | 1464 | ||
@@ -1451,7 +1468,6 @@ int kvmppc_core_init_vm(struct kvm *kvm) | |||
1451 | 1468 | ||
1452 | if (cpu_has_feature(CPU_FTR_ARCH_201)) { | 1469 | if (cpu_has_feature(CPU_FTR_ARCH_201)) { |
1453 | /* PPC970; HID4 is effectively the LPCR */ | 1470 | /* PPC970; HID4 is effectively the LPCR */ |
1454 | unsigned long lpid = kvm->arch.lpid; | ||
1455 | kvm->arch.host_lpid = 0; | 1471 | kvm->arch.host_lpid = 0; |
1456 | kvm->arch.host_lpcr = lpcr = mfspr(SPRN_HID4); | 1472 | kvm->arch.host_lpcr = lpcr = mfspr(SPRN_HID4); |
1457 | lpcr &= ~((3 << HID4_LPID1_SH) | (0xful << HID4_LPID5_SH)); | 1473 | lpcr &= ~((3 << HID4_LPID1_SH) | (0xful << HID4_LPID5_SH)); |