aboutsummaryrefslogtreecommitdiffstats
path: root/arch/s390/kvm
diff options
context:
space:
mode:
authorKonstantin Weitz <konstantin.weitz@gmail.com>2013-04-17 11:36:29 -0400
committerMartin Schwidefsky <schwidefsky@de.ibm.com>2014-02-21 02:50:19 -0500
commitb31288fa83b2bcc8834e1e208e9526b8bd5ce361 (patch)
tree97b2372c7eeb7d7e792042e91f6489900aa38dfc /arch/s390/kvm
parent45961722f8e30ceab9d135b1ddc0947d53aef7c3 (diff)
s390/kvm: support collaborative memory management
This patch enables Collaborative Memory Management (CMM) for kvm on s390. CMM allows the guest to inform the host about page usage (see arch/s390/mm/cmm.c). The host uses this information to avoid swapping in unused pages in the page fault handler. Further, a CPU provided list of unused invalid pages is processed to reclaim swap space of not yet accessed unused pages. [ Martin Schwidefsky: patch reordering and cleanup ] Signed-off-by: Konstantin Weitz <konstantin.weitz@gmail.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Diffstat (limited to 'arch/s390/kvm')
-rw-r--r--arch/s390/kvm/kvm-s390.c25
-rw-r--r--arch/s390/kvm/kvm-s390.h2
-rw-r--r--arch/s390/kvm/priv.c41
3 files changed, 68 insertions, 0 deletions
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index e0676f390d57..10b5db3c9bc4 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -68,6 +68,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
68 { "instruction_storage_key", VCPU_STAT(instruction_storage_key) }, 68 { "instruction_storage_key", VCPU_STAT(instruction_storage_key) },
69 { "instruction_stsch", VCPU_STAT(instruction_stsch) }, 69 { "instruction_stsch", VCPU_STAT(instruction_stsch) },
70 { "instruction_chsc", VCPU_STAT(instruction_chsc) }, 70 { "instruction_chsc", VCPU_STAT(instruction_chsc) },
71 { "instruction_essa", VCPU_STAT(instruction_essa) },
71 { "instruction_stsi", VCPU_STAT(instruction_stsi) }, 72 { "instruction_stsi", VCPU_STAT(instruction_stsi) },
72 { "instruction_stfl", VCPU_STAT(instruction_stfl) }, 73 { "instruction_stfl", VCPU_STAT(instruction_stfl) },
73 { "instruction_tprot", VCPU_STAT(instruction_tprot) }, 74 { "instruction_tprot", VCPU_STAT(instruction_tprot) },
@@ -283,7 +284,11 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
283 if (kvm_is_ucontrol(vcpu->kvm)) 284 if (kvm_is_ucontrol(vcpu->kvm))
284 gmap_free(vcpu->arch.gmap); 285 gmap_free(vcpu->arch.gmap);
285 286
287 if (vcpu->arch.sie_block->cbrlo)
288 __free_page(__pfn_to_page(
289 vcpu->arch.sie_block->cbrlo >> PAGE_SHIFT));
286 free_page((unsigned long)(vcpu->arch.sie_block)); 290 free_page((unsigned long)(vcpu->arch.sie_block));
291
287 kvm_vcpu_uninit(vcpu); 292 kvm_vcpu_uninit(vcpu);
288 kmem_cache_free(kvm_vcpu_cache, vcpu); 293 kmem_cache_free(kvm_vcpu_cache, vcpu);
289} 294}
@@ -390,6 +395,8 @@ int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
390 395
391int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) 396int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
392{ 397{
398 struct page *cbrl;
399
393 atomic_set(&vcpu->arch.sie_block->cpuflags, CPUSTAT_ZARCH | 400 atomic_set(&vcpu->arch.sie_block->cpuflags, CPUSTAT_ZARCH |
394 CPUSTAT_SM | 401 CPUSTAT_SM |
395 CPUSTAT_STOPPED | 402 CPUSTAT_STOPPED |
@@ -401,6 +408,14 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
401 vcpu->arch.sie_block->ecb2 = 8; 408 vcpu->arch.sie_block->ecb2 = 8;
402 vcpu->arch.sie_block->eca = 0xC1002001U; 409 vcpu->arch.sie_block->eca = 0xC1002001U;
403 vcpu->arch.sie_block->fac = (int) (long) vfacilities; 410 vcpu->arch.sie_block->fac = (int) (long) vfacilities;
411 if (kvm_enabled_cmma()) {
412 cbrl = alloc_page(GFP_KERNEL | __GFP_ZERO);
413 if (cbrl) {
414 vcpu->arch.sie_block->ecb2 |= 0x80;
415 vcpu->arch.sie_block->ecb2 &= ~0x08;
416 vcpu->arch.sie_block->cbrlo = page_to_phys(cbrl);
417 }
418 }
404 hrtimer_init(&vcpu->arch.ckc_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS); 419 hrtimer_init(&vcpu->arch.ckc_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
405 tasklet_init(&vcpu->arch.tasklet, kvm_s390_tasklet, 420 tasklet_init(&vcpu->arch.tasklet, kvm_s390_tasklet,
406 (unsigned long) vcpu); 421 (unsigned long) vcpu);
@@ -761,6 +776,16 @@ static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason)
761 return rc; 776 return rc;
762} 777}
763 778
779bool kvm_enabled_cmma(void)
780{
781 if (!MACHINE_IS_LPAR)
782 return false;
783 /* only enable for z10 and later */
784 if (!MACHINE_HAS_EDAT1)
785 return false;
786 return true;
787}
788
764static int __vcpu_run(struct kvm_vcpu *vcpu) 789static int __vcpu_run(struct kvm_vcpu *vcpu)
765{ 790{
766 int rc, exit_reason; 791 int rc, exit_reason;
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index f9559b0bd620..564514f410f4 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -156,6 +156,8 @@ void s390_vcpu_block(struct kvm_vcpu *vcpu);
156void s390_vcpu_unblock(struct kvm_vcpu *vcpu); 156void s390_vcpu_unblock(struct kvm_vcpu *vcpu);
157void exit_sie(struct kvm_vcpu *vcpu); 157void exit_sie(struct kvm_vcpu *vcpu);
158void exit_sie_sync(struct kvm_vcpu *vcpu); 158void exit_sie_sync(struct kvm_vcpu *vcpu);
159/* are we going to support cmma? */
160bool kvm_enabled_cmma(void);
159/* implemented in diag.c */ 161/* implemented in diag.c */
160int kvm_s390_handle_diag(struct kvm_vcpu *vcpu); 162int kvm_s390_handle_diag(struct kvm_vcpu *vcpu);
161 163
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index 75beea632a10..aacb6b129914 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -636,8 +636,49 @@ static int handle_pfmf(struct kvm_vcpu *vcpu)
636 return 0; 636 return 0;
637} 637}
638 638
639static int handle_essa(struct kvm_vcpu *vcpu)
640{
641 /* entries expected to be 1FF */
642 int entries = (vcpu->arch.sie_block->cbrlo & ~PAGE_MASK) >> 3;
643 unsigned long *cbrlo, cbrle;
644 struct gmap *gmap;
645 int i;
646
647 VCPU_EVENT(vcpu, 5, "cmma release %d pages", entries);
648 gmap = vcpu->arch.gmap;
649 vcpu->stat.instruction_essa++;
650 if (!kvm_enabled_cmma() || !vcpu->arch.sie_block->cbrlo)
651 return kvm_s390_inject_program_int(vcpu, PGM_OPERATION);
652
653 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
654 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
655
656 if (((vcpu->arch.sie_block->ipb & 0xf0000000) >> 28) > 6)
657 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
658
659 /* Rewind PSW to repeat the ESSA instruction */
660 vcpu->arch.sie_block->gpsw.addr =
661 __rewind_psw(vcpu->arch.sie_block->gpsw, 4);
662 vcpu->arch.sie_block->cbrlo &= PAGE_MASK; /* reset nceo */
663 cbrlo = phys_to_virt(vcpu->arch.sie_block->cbrlo);
664 down_read(&gmap->mm->mmap_sem);
665 for (i = 0; i < entries; ++i) {
666 cbrle = cbrlo[i];
667 if (unlikely(cbrle & ~PAGE_MASK || cbrle < 2 * PAGE_SIZE))
668 /* invalid entry */
669 break;
670 /* try to free backing */
671 __gmap_zap(cbrle, gmap);
672 }
673 up_read(&gmap->mm->mmap_sem);
674 if (i < entries)
675 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
676 return 0;
677}
678
639static const intercept_handler_t b9_handlers[256] = { 679static const intercept_handler_t b9_handlers[256] = {
640 [0x8d] = handle_epsw, 680 [0x8d] = handle_epsw,
681 [0xab] = handle_essa,
641 [0xaf] = handle_pfmf, 682 [0xaf] = handle_pfmf,
642}; 683};
643 684