diff mbox

[01/11] s390x/kvm: Rework cmma management

Message ID 1499864265-144136-2-git-send-email-borntraeger@de.ibm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Christian Borntraeger July 12, 2017, 12:57 p.m. UTC
From: Janosch Frank <frankja@linux.vnet.ibm.com>

Let's keep track of cmma enablement and move the mem_path check into
the actual enablement. This now also warns users that do not use
cpu-models about disabled cmma when using huge pages.

Signed-off-by: Janosch Frank <frankja@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 target/s390x/cpu.h |  1 +
 target/s390x/kvm.c | 26 +++++++++++++++++---------
 2 files changed, 18 insertions(+), 9 deletions(-)

Comments

Cornelia Huck July 12, 2017, 1:49 p.m. UTC | #1
On Wed, 12 Jul 2017 14:57:35 +0200
Christian Borntraeger <borntraeger@de.ibm.com> wrote:

> From: Janosch Frank <frankja@linux.vnet.ibm.com>
> 
> Let's keep track of cmma enablement and move the mem_path check into
> the actual enablement. This now also warns users that do not use
> cpu-models about disabled cmma when using huge pages.
> 
> Signed-off-by: Janosch Frank <frankja@linux.vnet.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
>  target/s390x/cpu.h |  1 +
>  target/s390x/kvm.c | 26 +++++++++++++++++---------
>  2 files changed, 18 insertions(+), 9 deletions(-)

> @@ -177,6 +179,11 @@ int kvm_s390_set_mem_limit(KVMState *s, uint64_t new_limit, uint64_t *hw_limit)
>      return kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &attr);
>  }
>  
> +int kvm_s390_cmma_active(void)
> +{
> +    return active_cmma;
> +}

This is rather "has cmma ever been enabled"...

> +
>  static bool kvm_s390_cmma_available(void)
>  {
>      static bool initialized, value;
> @@ -197,7 +204,7 @@ void kvm_s390_cmma_reset(void)
>          .attr = KVM_S390_VM_MEM_CLR_CMMA,
>      };
>  
> -    if (mem_path || !kvm_s390_cmma_available()) {
> +    if (!kvm_s390_cmma_active()) {
>          return;
>      }

...as you don't clear it on reset, right?

Confused me a bit at first, but

Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Janosch Frank July 13, 2017, 5:37 a.m. UTC | #2
On 12.07.2017 15:49, Cornelia Huck wrote:
> On Wed, 12 Jul 2017 14:57:35 +0200
> Christian Borntraeger <borntraeger@de.ibm.com> wrote:
> 
>> From: Janosch Frank <frankja@linux.vnet.ibm.com>
>>
>> Let's keep track of cmma enablement and move the mem_path check into
>> the actual enablement. This now also warns users that do not use
>> cpu-models about disabled cmma when using huge pages.
>>
>> Signed-off-by: Janosch Frank <frankja@linux.vnet.ibm.com>
>> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
>> ---
>>  target/s390x/cpu.h |  1 +
>>  target/s390x/kvm.c | 26 +++++++++++++++++---------
>>  2 files changed, 18 insertions(+), 9 deletions(-)
> 
>> @@ -177,6 +179,11 @@ int kvm_s390_set_mem_limit(KVMState *s, uint64_t new_limit, uint64_t *hw_limit)
>>      return kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &attr);
>>  }
>>  
>> +int kvm_s390_cmma_active(void)
>> +{
>> +    return active_cmma;
>> +}
> 
> This is rather "has cmma ever been enabled"...
> 
>> +
>>  static bool kvm_s390_cmma_available(void)
>>  {
>>      static bool initialized, value;
>> @@ -197,7 +204,7 @@ void kvm_s390_cmma_reset(void)
>>          .attr = KVM_S390_VM_MEM_CLR_CMMA,
>>      };
>>  
>> -    if (mem_path || !kvm_s390_cmma_available()) {
>> +    if (!kvm_s390_cmma_active()) {
>>          return;
>>      }
> 
> ...as you don't clear it on reset, right?

I guess you mean KVM_S390_VM_MEM_CLR_CMMA, yes that only
manipulates/clears the PGSTE values but can not disable the cmma
facility. Disabling that on a running VM would be "interesting" at best.

> 
> Confused me a bit at first, but
> 
> Reviewed-by: Cornelia Huck <cohuck@redhat.com>

Thanks!
diff mbox

Patch

diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h
index bdb9bdb..8ab75c0 100644
--- a/target/s390x/cpu.h
+++ b/target/s390x/cpu.h
@@ -1158,6 +1158,7 @@  int kvm_s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch,
                                     int vq, bool assign);
 int kvm_s390_cpu_restart(S390CPU *cpu);
 int kvm_s390_get_memslot_count(KVMState *s);
+int kvm_s390_cmma_active(void);
 void kvm_s390_cmma_reset(void);
 int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state);
 void kvm_s390_reset_vcpu(S390CPU *cpu);
diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
index a3d0019..7a2a7c0 100644
--- a/target/s390x/kvm.c
+++ b/target/s390x/kvm.c
@@ -140,6 +140,8 @@  static int cap_mem_op;
 static int cap_s390_irq;
 static int cap_ri;
 
+static int active_cmma;
+
 static void *legacy_s390_alloc(size_t size, uint64_t *align);
 
 static int kvm_s390_query_mem_limit(KVMState *s, uint64_t *memory_limit)
@@ -177,6 +179,11 @@  int kvm_s390_set_mem_limit(KVMState *s, uint64_t new_limit, uint64_t *hw_limit)
     return kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &attr);
 }
 
+int kvm_s390_cmma_active(void)
+{
+    return active_cmma;
+}
+
 static bool kvm_s390_cmma_available(void)
 {
     static bool initialized, value;
@@ -197,7 +204,7 @@  void kvm_s390_cmma_reset(void)
         .attr = KVM_S390_VM_MEM_CLR_CMMA,
     };
 
-    if (mem_path || !kvm_s390_cmma_available()) {
+    if (!kvm_s390_cmma_active()) {
         return;
     }
 
@@ -213,7 +220,13 @@  static void kvm_s390_enable_cmma(void)
         .attr = KVM_S390_VM_MEM_ENABLE_CMMA,
     };
 
+    if (mem_path) {
+        error_report("Warning: CMM will not be enabled because it is not "
+                     "compatible to hugetlbfs.");
+        return;
+    }
     rc = kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
+    active_cmma = !rc;
     trace_kvm_enable_cmma(rc);
 }
 
@@ -2641,7 +2654,7 @@  void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
 
     if (!model) {
         /* compatibility handling if cpu models are disabled */
-        if (kvm_s390_cmma_available() && !mem_path) {
+        if (kvm_s390_cmma_available()) {
             kvm_s390_enable_cmma();
         }
         return;
@@ -2672,13 +2685,8 @@  void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
         error_setg(errp, "KVM: Error configuring CPU subfunctions: %d", rc);
         return;
     }
-    /* enable CMM via CMMA - disable on hugetlbfs */
+    /* enable CMM via CMMA */
     if (test_bit(S390_FEAT_CMM, model->features)) {
-        if (mem_path) {
-            error_report("Warning: CMM will not be enabled because it is not "
-                         "compatible to hugetlbfs.");
-        } else {
-            kvm_s390_enable_cmma();
-        }
+        kvm_s390_enable_cmma();
     }
 }