diff mbox series

[v3,2/2] s390x: Enable KVM huge page backing support

Message ID 20180731120908.9202-3-frankja@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series s390x: Enable KVM huge page backing support | expand

Commit Message

Janosch Frank July 31, 2018, 12:09 p.m. UTC
QEMU has had huge page support for a longer time already, but KVM
memory management under s390x needed some changes to work with huge
backings.

Now that we have support, let's enable it if requested and
available. Otherwise we now properly tell the user if there is no
support and back out instead of failing to run the VM later on.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 target/s390x/kvm.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Cornelia Huck July 31, 2018, 1:06 p.m. UTC | #1
On Tue, 31 Jul 2018 13:09:08 +0100
Janosch Frank <frankja@linux.ibm.com> wrote:

> QEMU has had huge page support for a longer time already, but KVM
> memory management under s390x needed some changes to work with huge
> backings.
> 
> Now that we have support, let's enable it if requested and
> available. Otherwise we now properly tell the user if there is no
> support and back out instead of failing to run the VM later on.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> ---
>  target/s390x/kvm.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
> index d923cf4240..f961c3b84a 100644
> --- a/target/s390x/kvm.c
> +++ b/target/s390x/kvm.c
> @@ -34,6 +34,7 @@
>  #include "qapi/error.h"
>  #include "qemu/error-report.h"
>  #include "qemu/timer.h"
> +#include "qemu/mmap-alloc.h"
>  #include "sysemu/sysemu.h"
>  #include "sysemu/hw_accel.h"
>  #include "hw/hw.h"
> @@ -285,6 +286,20 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
>  {
>      MachineClass *mc = MACHINE_GET_CLASS(ms);
>  
> +    if (mem_path) {
> +        if (qemu_mempath_getpagesize(mem_path) != (1 << 20)) {

1 * MiB ?

> +            error_report("Huge page backing with pages > 1M was specified, "
> +                         "but KVM does not support this memory backing");
> +            return -EINVAL;
> +
> +        }
> +        if (kvm_vm_enable_cap(s, KVM_CAP_S390_HPAGE_1M, 0)) {
> +            error_report("Huge page backing with 1M pages was specified, "
> +                         "but KVM does not support this memory backing");
> +            return -EINVAL;
> +        }
> +    }
> +
>      mc->default_cpu_type = S390_CPU_TYPE_NAME("host");
>      cap_sync_regs = kvm_check_extension(s, KVM_CAP_SYNC_REGS);
>      cap_async_pf = kvm_check_extension(s, KVM_CAP_ASYNC_PF);
Janosch Frank July 31, 2018, 1:19 p.m. UTC | #2
On 31.07.2018 15:06, Cornelia Huck wrote:
> On Tue, 31 Jul 2018 13:09:08 +0100
> Janosch Frank <frankja@linux.ibm.com> wrote:
> 
>> QEMU has had huge page support for a longer time already, but KVM
>> memory management under s390x needed some changes to work with huge
>> backings.
>>
>> Now that we have support, let's enable it if requested and
>> available. Otherwise we now properly tell the user if there is no
>> support and back out instead of failing to run the VM later on.
>>
>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>> ---
>>  target/s390x/kvm.c | 15 +++++++++++++++
>>  1 file changed, 15 insertions(+)
>>
>> diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
>> index d923cf4240..f961c3b84a 100644
>> --- a/target/s390x/kvm.c
>> +++ b/target/s390x/kvm.c
>> @@ -34,6 +34,7 @@
>>  #include "qapi/error.h"
>>  #include "qemu/error-report.h"
>>  #include "qemu/timer.h"
>> +#include "qemu/mmap-alloc.h"
>>  #include "sysemu/sysemu.h"
>>  #include "sysemu/hw_accel.h"
>>  #include "hw/hw.h"
>> @@ -285,6 +286,20 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
>>  {
>>      MachineClass *mc = MACHINE_GET_CLASS(ms);
>>  
>> +    if (mem_path) {
>> +        if (qemu_mempath_getpagesize(mem_path) != (1 << 20)) {
> 
> 1 * MiB ?

I only looked for page size definitions, didn't know it exists, yes 1 *
MiB is a bit nicer.

I'd wait for more comments before sending the v4 out, so consider this
fixed.

> 
>> +            error_report("Huge page backing with pages > 1M was specified, "
>> +                         "but KVM does not support this memory backing");
>> +            return -EINVAL;
>> +
>> +        }
>> +        if (kvm_vm_enable_cap(s, KVM_CAP_S390_HPAGE_1M, 0)) {
>> +            error_report("Huge page backing with 1M pages was specified, "
>> +                         "but KVM does not support this memory backing");
>> +            return -EINVAL;
>> +        }
>> +    }
>> +
>>      mc->default_cpu_type = S390_CPU_TYPE_NAME("host");
>>      cap_sync_regs = kvm_check_extension(s, KVM_CAP_SYNC_REGS);
>>      cap_async_pf = kvm_check_extension(s, KVM_CAP_ASYNC_PF);
> 
>
Thomas Huth Aug. 1, 2018, 11:30 a.m. UTC | #3
On 07/31/2018 02:09 PM, Janosch Frank wrote:
> QEMU has had huge page support for a longer time already, but KVM
> memory management under s390x needed some changes to work with huge
> backings.
> 
> Now that we have support, let's enable it if requested and
> available. Otherwise we now properly tell the user if there is no
> support and back out instead of failing to run the VM later on.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> ---
>  target/s390x/kvm.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
> index d923cf4240..f961c3b84a 100644
> --- a/target/s390x/kvm.c
> +++ b/target/s390x/kvm.c
> @@ -34,6 +34,7 @@
>  #include "qapi/error.h"
>  #include "qemu/error-report.h"
>  #include "qemu/timer.h"
> +#include "qemu/mmap-alloc.h"
>  #include "sysemu/sysemu.h"
>  #include "sysemu/hw_accel.h"
>  #include "hw/hw.h"
> @@ -285,6 +286,20 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
>  {
>      MachineClass *mc = MACHINE_GET_CLASS(ms);
>  
> +    if (mem_path) {
> +        if (qemu_mempath_getpagesize(mem_path) != (1 << 20)) {
> +            error_report("Huge page backing with pages > 1M was specified, "
> +                         "but KVM does not support this memory backing");
> +            return -EINVAL;

I think you should use ">" instead of "!=" here. It does not make much
too much sense, but it is still possible that the user specifies a
mem_path with 4k, and you don't want to trigger the error message here
(try something like qemu-system-s390x -mem-path /tmp/... for example).

 Thomas
diff mbox series

Patch

diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
index d923cf4240..f961c3b84a 100644
--- a/target/s390x/kvm.c
+++ b/target/s390x/kvm.c
@@ -34,6 +34,7 @@ 
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "qemu/timer.h"
+#include "qemu/mmap-alloc.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/hw_accel.h"
 #include "hw/hw.h"
@@ -285,6 +286,20 @@  int kvm_arch_init(MachineState *ms, KVMState *s)
 {
     MachineClass *mc = MACHINE_GET_CLASS(ms);
 
+    if (mem_path) {
+        if (qemu_mempath_getpagesize(mem_path) != (1 << 20)) {
+            error_report("Huge page backing with pages > 1M was specified, "
+                         "but KVM does not support this memory backing");
+            return -EINVAL;
+
+        }
+        if (kvm_vm_enable_cap(s, KVM_CAP_S390_HPAGE_1M, 0)) {
+            error_report("Huge page backing with 1M pages was specified, "
+                         "but KVM does not support this memory backing");
+            return -EINVAL;
+        }
+    }
+
     mc->default_cpu_type = S390_CPU_TYPE_NAME("host");
     cap_sync_regs = kvm_check_extension(s, KVM_CAP_SYNC_REGS);
     cap_async_pf = kvm_check_extension(s, KVM_CAP_ASYNC_PF);