s390x: Enable KVM huge page backing support
v4 cover s390x: Enable KVM huge page backing support
v4:
* Now using MiB
* Now supporting 4k memory backings
v3:
* Fixed Cap name
* Added mempath page size check and error reporting
Janosch Frank (2):
kvm: sync linux headers
s390x: Enable KVM huge page backing support
linux-headers/linux/kvm.h | 1 + target/s390x/kvm.c | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-)
Signature · 1 line
2.14.3
PATCH v4 1/2 kvm: sync linux headers
Import KVM_CAP_S390_HPAGE_1M.
Placeholder for proper sync.
--- linux-headers/linux/kvm.h | 1 + 1 file changed, 1 insertion(+)
linux-headers/linux/kvm.h +1 -0
@@ -949,6 +949,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_GET_MSR_FEATURES 153#define KVM_CAP_HYPERV_EVENTFD 154#define KVM_CAP_HYPERV_TLBFLUSH 155 +#define KVM_CAP_S390_HPAGE_1M 156#ifdef KVM_CAP_IRQ_ROUTING
Signature · 1 line
2.14.3
PATCH v4 2/2 s390x: Enable KVM huge page backing support
In reply to Janosch FrankQEMU 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.
--- target/s390x/kvm.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-)
target/s390x/kvm.c +32 -2
@@ -34,6 +34,8 @@#include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/timer.h" +#include "qemu/units.h" +#include "qemu/mmap-alloc.h" #include "sysemu/sysemu.h" #include "sysemu/hw_accel.h" #include "hw/hw.h"
@@ -139,6 +141,7 @@ static int cap_mem_op;static int cap_s390_irq;static int cap_ri;static int cap_gs; +static int cap_hpage_1m;static int active_cmma;
@@ -220,9 +223,9 @@ static void kvm_s390_enable_cmma(void) .attr = KVM_S390_VM_MEM_ENABLE_CMMA, }; -if (mem_path) { +if (cap_hpage_1m) {warn_report ("CMM will not be enabled because it is not " -"compatible with hugetlbfs." ); +"compatible with huge memory backings." );return ; } rc =kvm_vm_ioctl (kvm_state,KVM_SET_DEVICE_ATTR , &attr);
@@ -281,10 +284,37 @@ void kvm_s390_crypto_reset(void) } } +static int kvm_s390_configure_mempath_backing (KVMState *s) +{ +size_t path_psize =qemu_mempath_getpagesize (mem_path); + +if (path_psize ==4 * KiB) +return 0 ; + +if (path_psize !=1 * MiB) { +error_report ("Memory backing with 2G pages 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 ("Memory backing with 1M pages was specified, " +"but KVM does not support this memory backing" ); +return -EINVAL ; + } + + cap_hpage_1m =1 ; +return 0 ; +} +int kvm_arch_init (MachineState *ms,KVMState *s) {MachineClass *mc =MACHINE_GET_CLASS (ms); +if (mem_path &&kvm_s390_configure_mempath_backing (s)) { +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 );
Signature · 1 line
2.14.3
Quoted 35 lines · Janosch Frank
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 <[email protected]>--- target/s390x/kvm.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-)target/s390x/kvm.c +3
-0@@ -34,6 +34,8 @@#include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/timer.h" +#include "qemu/units.h" +#include "qemu/mmap-alloc.h" #include "sysemu/sysemu.h" #include "sysemu/hw_accel.h" #include "hw/hw.h" @@ -139,6 +141,7 @@ static int cap_mem_op;static int cap_s390_irq;static int cap_ri;static int cap_gs; +static int cap_hpage_1m;static int active_cmma;
target/s390x/kvm.c static void kvm_s390_enable_cmma(void) · line 228
Quoted 8 lines
target/s390x/kvm.c +2
-2@@ -220,9 +223,9 @@ static void kvm_s390_enable_cmma(void) .attr = KVM_S390_VM_MEM_ENABLE_CMMA, }; -if (mem_path) { +if (cap_hpage_1m) {warn_report ("CMM will not be enabled because it is not " -"compatible with hugetlbfs." ); +"compatible with huge memory backings." );
This implies some change to certain setups (tmpfs), but as they are absolutely not common (and never really were supported/expected to work), I think this is fine.
Quoted 42 lines
target/s390x/kvm.c +27
-0return ; } rc =kvm_vm_ioctl (kvm_state,KVM_SET_DEVICE_ATTR , &attr);@@ -281,10 +284,37 @@ void kvm_s390_crypto_reset(void) } } +static int kvm_s390_configure_mempath_backing (KVMState *s) +{ +size_t path_psize =qemu_mempath_getpagesize (mem_path); + +if (path_psize ==4 * KiB) +return 0 ; + +if (path_psize !=1 * MiB) { +error_report ("Memory backing with 2G pages 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 ("Memory backing with 1M pages was specified, " +"but KVM does not support this memory backing" ); +return -EINVAL ; + } + + cap_hpage_1m =1 ; +return 0 ; +} +int kvm_arch_init (MachineState *ms,KVMState *s) {MachineClass *mc =MACHINE_GET_CLASS (ms); +if (mem_path &&kvm_s390_configure_mempath_backing (s)) { +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 );
Signature · 3 lines
Thanks, David / dhildenb
Quoted 47 lines · Janosch Frank
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 <[email protected]>--- target/s390x/kvm.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-)target/s390x/kvm.c +5
-2@@ -34,6 +34,8 @@#include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/timer.h" +#include "qemu/units.h" +#include "qemu/mmap-alloc.h" #include "sysemu/sysemu.h" #include "sysemu/hw_accel.h" #include "hw/hw.h" @@ -139,6 +141,7 @@ static int cap_mem_op;static int cap_s390_irq;static int cap_ri;static int cap_gs; +static int cap_hpage_1m;static int active_cmma;@@ -220,9 +223,9 @@ static void kvm_s390_enable_cmma(void) .attr = KVM_S390_VM_MEM_ENABLE_CMMA, }; -if (mem_path) { +if (cap_hpage_1m) {warn_report ("CMM will not be enabled because it is not " -"compatible with hugetlbfs." ); +"compatible with huge memory backings." );return ; } rc =kvm_vm_ioctl (kvm_state,KVM_SET_DEVICE_ATTR , &attr);
target/s390x/kvm.c void kvm_s390_crypto_reset(void) · line 292
Quoted 9 lines
target/s390x/kvm.c +6
-0@@ -281,10 +284,37 @@ void kvm_s390_crypto_reset(void) } } +static int kvm_s390_configure_mempath_backing (KVMState *s) +{ +size_t path_psize =qemu_mempath_getpagesize (mem_path); + +if (path_psize ==4 * KiB) +return 0 ;
Missing curly braces.
target/s390x/kvm.c void kvm_s390_crypto_reset(void) · line 296
Quoted 3 lines
target/s390x/kvm.c +3
-0+if (path_psize !=1 * MiB) { +error_report ("Memory backing with 2G pages was specified, " +"but KVM does not support this memory backing" );
May I suggest to use a text that rather matches the condition of the if-statement (just in case there will be other sizes in the future...), e.g. "Memory backing is only supported for 1 MiB huge pages" or something similar.
Thomas
Quoted 9 lines · Thomas Huth
target/s390x/kvm.c void kvm_s390_crypto_reset(void) · line 292
Quoted 6 lines · Janosch Frank
target/s390x/kvm.c +6
-0+static int kvm_s390_configure_mempath_backing (KVMState *s) +{ +size_t path_psize =qemu_mempath_getpagesize (mem_path); + +if (path_psize ==4 * KiB) +return 0 ;Missing curly braces.
urgh, right, this is not the kernel.
Quoted 5 lines
target/s390x/kvm.c void kvm_s390_crypto_reset(void) · line 296
Quoted 4 lines
target/s390x/kvm.c +3
-0+if (path_psize !=1 * MiB) { +error_report ("Memory backing with 2G pages was specified, " +"but KVM does not support this memory backing" );
Quoted 7 lines
May I suggest to use a text that rather matches the condition of the if-statement (just in case there will be other sizes in the future...), e.g. "Memory backing is only supported for 1 MiB huge pages" or something similar.
Thomas
That's actually the gist of it. s390 supports 4k, 1M and 2G and looking at the POP I don't see a big chance of having any more sizes, as there are not a lot of software bits left and adding support in OSs is a pain. Also don't hold your breath for 2G, it would need a rewrite of gmap.c.
Also this is more explicit.
Quoted 23 lines · Janosch Frank
Quoted 9 lines · Thomas Huth
target/s390x/kvm.c void kvm_s390_crypto_reset(void) · line 292
Quoted 6 lines · Janosch Frank
target/s390x/kvm.c +6
-0+static int kvm_s390_configure_mempath_backing (KVMState *s) +{ +size_t path_psize =qemu_mempath_getpagesize (mem_path); + +if (path_psize ==4 * KiB) +return 0 ;Missing curly braces.
urgh, right, this is not the kernel.
Quoted 10 lines
target/s390x/kvm.c void kvm_s390_crypto_reset(void) · line 296
Quoted 4 lines
target/s390x/kvm.c +3
-0+if (path_psize !=1 * MiB) { +error_report ("Memory backing with 2G pages was specified, " +"but KVM does not support this memory backing" );May I suggest to use a text that rather matches the condition of the if-statement (just in case there will be other sizes in the future...), e.g. "Memory backing is only supported for 1 MiB huge pages" or something similar.
Quoted 7 lines
Quoted 2 lines
Thomas
That's actually the gist of it. s390 supports 4k, 1M and 2G and looking at the POP I don't see a big chance of having any more sizes, as there are not a lot of software bits left and adding support in OSs is a pain. Also don't hold your breath for 2G, it would need a rewrite of
gmap.c.
Well, never say never ... but if you want to keep the current text, that's fine for me, too.
Thomas
PATCH v5 1/1 s390x: Enable KVM huge page backing support
In reply to Janosch FrankQEMU 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.
---
Now featuring all of the required braces.
--- target/s390x/kvm.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)
target/s390x/kvm.c +33 -2
@@ -34,6 +34,8 @@#include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/timer.h" +#include "qemu/units.h" +#include "qemu/mmap-alloc.h" #include "sysemu/sysemu.h" #include "sysemu/hw_accel.h" #include "hw/hw.h"
@@ -139,6 +141,7 @@ static int cap_mem_op;static int cap_s390_irq;static int cap_ri;static int cap_gs; +static int cap_hpage_1m;static int active_cmma;
@@ -220,9 +223,9 @@ static void kvm_s390_enable_cmma(void) .attr = KVM_S390_VM_MEM_ENABLE_CMMA, }; -if (mem_path) { +if (cap_hpage_1m) {warn_report ("CMM will not be enabled because it is not " -"compatible with hugetlbfs." ); +"compatible with huge memory backings." );return ; } rc =kvm_vm_ioctl (kvm_state,KVM_SET_DEVICE_ATTR , &attr);
@@ -281,10 +284,38 @@ void kvm_s390_crypto_reset(void) } } +static int kvm_s390_configure_mempath_backing (KVMState *s) +{ +size_t path_psize =qemu_mempath_getpagesize (mem_path); + +if (path_psize ==4 * KiB) { +return 0 ; + } + +if (path_psize !=1 * MiB) { +error_report ("Memory backing with 2G pages 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 ("Memory backing with 1M pages was specified, " +"but KVM does not support this memory backing" ); +return -EINVAL ; + } + + cap_hpage_1m =1 ; +return 0 ; +} +int kvm_arch_init (MachineState *ms,KVMState *s) {MachineClass *mc =MACHINE_GET_CLASS (ms); +if (mem_path &&kvm_s390_configure_mempath_backing (s)) { +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 );
Signature · 1 line
2.14.3
Quoted 81 lines · Janosch Frank
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 <[email protected]>Reviewed-by David Hildenbrand <[email protected]>---
Now featuring all of the required braces.
--- target/s390x/kvm.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)target/s390x/kvm.c +29
-2@@ -34,6 +34,8 @@#include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/timer.h" +#include "qemu/units.h" +#include "qemu/mmap-alloc.h" #include "sysemu/sysemu.h" #include "sysemu/hw_accel.h" #include "hw/hw.h" @@ -139,6 +141,7 @@ static int cap_mem_op;static int cap_s390_irq;static int cap_ri;static int cap_gs; +static int cap_hpage_1m;static int active_cmma;@@ -220,9 +223,9 @@ static void kvm_s390_enable_cmma(void) .attr = KVM_S390_VM_MEM_ENABLE_CMMA, }; -if (mem_path) { +if (cap_hpage_1m) {warn_report ("CMM will not be enabled because it is not " -"compatible with hugetlbfs." ); +"compatible with huge memory backings." );return ; } rc =kvm_vm_ioctl (kvm_state,KVM_SET_DEVICE_ATTR , &attr);@@ -281,10 +284,38 @@ void kvm_s390_crypto_reset(void) } } +static int kvm_s390_configure_mempath_backing (KVMState *s) +{ +size_t path_psize =qemu_mempath_getpagesize (mem_path); + +if (path_psize ==4 * KiB) { +return 0 ; + } + +if (path_psize !=1 * MiB) { +error_report ("Memory backing with 2G pages 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 ("Memory backing with 1M pages was specified, " +"but KVM does not support this memory backing" ); +return -EINVAL ; + } + + cap_hpage_1m =1 ; +return 0 ; +} +int kvm_arch_init (MachineState *ms,KVMState *s)
target/s390x/kvm.c void kvm_s390_crypto_reset(void) · line 321
Quoted 10 lines
target/s390x/kvm.c +4
-0{MachineClass *mc =MACHINE_GET_CLASS (ms); +if (mem_path &&kvm_s390_configure_mempath_backing (s)) { +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 );
Looks good to me.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 80 lines · Janosch Frank
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 <[email protected]>Reviewed-by David Hildenbrand <[email protected]>---
Now featuring all of the required braces.
--- target/s390x/kvm.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)target/s390x/kvm.c +29
-2@@ -34,6 +34,8 @@#include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/timer.h" +#include "qemu/units.h" +#include "qemu/mmap-alloc.h" #include "sysemu/sysemu.h" #include "sysemu/hw_accel.h" #include "hw/hw.h" @@ -139,6 +141,7 @@ static int cap_mem_op;static int cap_s390_irq;static int cap_ri;static int cap_gs; +static int cap_hpage_1m;static int active_cmma;@@ -220,9 +223,9 @@ static void kvm_s390_enable_cmma(void) .attr = KVM_S390_VM_MEM_ENABLE_CMMA, }; -if (mem_path) { +if (cap_hpage_1m) {warn_report ("CMM will not be enabled because it is not " -"compatible with hugetlbfs." ); +"compatible with huge memory backings." );return ; } rc =kvm_vm_ioctl (kvm_state,KVM_SET_DEVICE_ATTR , &attr);@@ -281,10 +284,38 @@ void kvm_s390_crypto_reset(void) } } +static int kvm_s390_configure_mempath_backing (KVMState *s) +{ +size_t path_psize =qemu_mempath_getpagesize (mem_path); + +if (path_psize ==4 * KiB) { +return 0 ; + } + +if (path_psize !=1 * MiB) { +error_report ("Memory backing with 2G pages 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 ("Memory backing with 1M pages was specified, " +"but KVM does not support this memory backing" ); +return -EINVAL ; + } + + cap_hpage_1m =1 ; +return 0 ; +} +int kvm_arch_init (MachineState *ms,KVMState *s)
target/s390x/kvm.c void kvm_s390_crypto_reset(void) · line 321
Quoted 10 lines
target/s390x/kvm.c +4
-0{MachineClass *mc =MACHINE_GET_CLASS (ms); +if (mem_path &&kvm_s390_configure_mempath_backing (s)) { +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 );
Quoted 8 lines · On Wed, 1 Aug 2018 14:19:03 +0100 Janosch Frank <[email protected]> wrote:
v4:
* Now using MiB
* Now supporting 4k memory backingsv3:
* Fixed Cap name
* Added mempath page size check and error reporting
Quoted 8 lines
Janosch Frank (2):
kvm: sync linux headers
s390x: Enable KVM huge page backing supportlinux-headers/linux/kvm.h | 1 + target/s390x/kvm.c | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-)
Looks good to me.
Same comment as for the etoken patch: I'll queue this as soon as the kernel interface has landed (and we can do a proper headers update). Please ping me if I forget about it :)
Cornelia Huck
AppliedQuoted 20 lines · On Wed, 1 Aug 2018 18:01:59 +0200 Cornelia Huck <[email protected]> wrote:
Quoted 8 lines · On Wed, 1 Aug 2018 14:19:03 +0100 Janosch Frank <[email protected]> wrote:
v4:
* Now using MiB
* Now supporting 4k memory backingsv3:
* Fixed Cap name
* Added mempath page size check and error reportingQuoted 8 lines
Janosch Frank (2):
kvm: sync linux headers
s390x: Enable KVM huge page backing supportlinux-headers/linux/kvm.h | 1 + target/s390x/kvm.c | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-)
Quoted 5 lines
Looks good to me.
Same comment as for the etoken patch: I'll queue this as soon as the kernel interface has landed (and we can do a proper headers update). Please ping me if I forget about it :)
Same comment as for the etoken patch, again :) Just pushed out to s390-next.
Thanks, applied.
This series seems to have some coding style problems. See output below for more information:
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v4 0/2] s390x: Enable KVM huge page backing support
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 Switched to a new branch 'test'4290dbe857 s390x: Enable KVM huge page backing support adfd7a6890 kvm: sync linux headers
=== OUTPUT BEGIN ===
Checking PATCH 1/2: kvm: sync linux headers...
Checking PATCH 2/2: s390x: Enable KVM huge page backing support...
ERROR: braces {} are necessary for all arms of this statement #59: FILE: target/s390x/kvm.c:291:
+ if (path_psize == 4 * KiB)
[...]
total: 1 errors, 0 warnings, 63 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]