From: Janosch Frank <frankja@linux.ibm.com>
Subject: KVM: s390: Properly lock mm context allow_gmap_hpage_1m setting
Patch-mainline: v4.19-rc3
Git-commit: df88f3181f10565c6e3a89eb6f0f9e6afaaf15f1
References: FATE#326372, LTC#169184, bsc#1113484
Summary: kernel: Introduce huge page KVM backing support
Description: This adds the KVM support for libhugetlbfs backings of
s390 KVM guests.
Upstream-Description:
KVM: s390: Properly lock mm context allow_gmap_hpage_1m setting
We have to do down_write on the mm semaphore to set a bitfield in the
mm context.
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Fixes: a4499382 ("KVM: s390: Add huge page enablement control")
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Acked-by: Petr Tesarik <ptesarik@suse.com>
---
arch/s390/include/asm/mmu.h | 8 +++++++-
arch/s390/kvm/kvm-s390.c | 2 ++
2 files changed, 9 insertions(+), 1 deletion(-)
--- a/arch/s390/include/asm/mmu.h
+++ b/arch/s390/include/asm/mmu.h
@@ -17,7 +17,13 @@ typedef struct {
unsigned long asce;
unsigned long asce_limit;
unsigned long vdso_base;
- /* The mmu context allocates 4K page tables. */
+ /*
+ * The following bitfields need a down_write on the mm
+ * semaphore when they are written to. As they are only
+ * written once, they can be read without a lock.
+ *
+ * The mmu context allocates 4K page tables.
+ */
unsigned int alloc_pgste:1;
/* The mmu context uses extended page tables. */
unsigned int has_pgste:1;
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -674,7 +674,9 @@ static int kvm_vm_ioctl_enable_cap(struc
r = -EINVAL;
else {
r = 0;
+ down_write(&kvm->mm->mmap_sem);
kvm->mm->context.allow_gmap_hpage_1m = 1;
+ up_write(&kvm->mm->mmap_sem);
/*
* We might have to create fake 4k page
* tables. To avoid that the hardware works on