Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: s390: backup the currently enabled gmap when scheduled out

Nested virtualization will have to enable own gmaps. Current code
would enable the wrong gmap whenever scheduled out and back in,
therefore resulting in the wrong gmap being enabled.

This patch reenables the last enabled gmap, therefore avoiding having to
touch vcpu->arch.gmap when enabling a different gmap.

Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>

authored by

David Hildenbrand and committed by
Christian Borntraeger
37d9df98 65d0b0d4

+19 -3
+1
arch/s390/include/asm/gmap.h
··· 94 94 95 95 void gmap_enable(struct gmap *gmap); 96 96 void gmap_disable(struct gmap *gmap); 97 + struct gmap *gmap_get_enabled(void); 97 98 int gmap_map_segment(struct gmap *gmap, unsigned long from, 98 99 unsigned long to, unsigned long len); 99 100 int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len);
+2
arch/s390/include/asm/kvm_host.h
··· 551 551 struct hrtimer ckc_timer; 552 552 struct kvm_s390_pgm_info pgm; 553 553 struct gmap *gmap; 554 + /* backup location for the currently enabled gmap when scheduled out */ 555 + struct gmap *enabled_gmap; 554 556 struct kvm_guestdbg_info_arch guestdbg; 555 557 unsigned long pfault_token; 556 558 unsigned long pfault_select;
+5 -3
arch/s390/kvm/kvm-s390.c
··· 1719 1719 1720 1720 save_access_regs(vcpu->arch.host_acrs); 1721 1721 restore_access_regs(vcpu->run->s.regs.acrs); 1722 - gmap_enable(vcpu->arch.gmap); 1722 + gmap_enable(vcpu->arch.enabled_gmap); 1723 1723 atomic_or(CPUSTAT_RUNNING, &vcpu->arch.sie_block->cpuflags); 1724 1724 if (vcpu->arch.cputm_enabled && !is_vcpu_idle(vcpu)) 1725 1725 __start_cpu_timer_accounting(vcpu); ··· 1732 1732 if (vcpu->arch.cputm_enabled && !is_vcpu_idle(vcpu)) 1733 1733 __stop_cpu_timer_accounting(vcpu); 1734 1734 atomic_andnot(CPUSTAT_RUNNING, &vcpu->arch.sie_block->cpuflags); 1735 - gmap_disable(vcpu->arch.gmap); 1735 + vcpu->arch.enabled_gmap = gmap_get_enabled(); 1736 + gmap_disable(vcpu->arch.enabled_gmap); 1736 1737 1737 1738 /* Save guest register state */ 1738 1739 save_fpu_regs(); ··· 1782 1781 vcpu->arch.gmap = vcpu->kvm->arch.gmap; 1783 1782 sca_add_vcpu(vcpu); 1784 1783 } 1785 - 1784 + /* make vcpu_load load the right gmap on the first trigger */ 1785 + vcpu->arch.enabled_gmap = vcpu->arch.gmap; 1786 1786 } 1787 1787 1788 1788 static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu)
+11
arch/s390/mm/gmap.c
··· 270 270 } 271 271 EXPORT_SYMBOL_GPL(gmap_disable); 272 272 273 + /** 274 + * gmap_get_enabled - get a pointer to the currently enabled gmap 275 + * 276 + * Returns a pointer to the currently enabled gmap. 0 if none is enabled. 277 + */ 278 + struct gmap *gmap_get_enabled(void) 279 + { 280 + return (struct gmap *) S390_lowcore.gmap; 281 + } 282 + EXPORT_SYMBOL_GPL(gmap_get_enabled); 283 + 273 284 /* 274 285 * gmap_alloc_table is assumed to be called with mmap_sem held 275 286 */