target/i386: kvm: Fix treatment of AMD SVM in nested migration
cover target/i386: kvm: Fix treatment of AMD SVM in nested migration
Hi,
This patch series aims to fix the recent patch-series that was just merged to upstream QEMU master branch which adds support for nested migration.
The already merged patch-series was modified during merge to allow migration of vCPU exposed with SVM even though kernel does not support save/restore of required nested state. This was done because of considering backwards-compatability.
However, during discussion made after merge, it was realised that since QEMU commit 75d373ef9729 ("target-i386: Disable SVM by default in KVM mode"), an AMD vCPU that is virtualized by KVM doesn't expose SVM by default, even if you use "-cpu host". Therefore, it is unlikely that vCPU expose SVM CPUID flag when user is not running an SVM workload inside guest.
Therefore, this patch series change code back to original intent to block migration in case of vCPU exposed with SVM if kernel does not support required capabilities tos ave/restore nested-state.
Regards,
-Liran
PATCH 1/2 target/i386: kvm: Block migration on vCPU exposed with SVM when kernel lacks caps to save/restore nested state
Commit 18ab37ba1cee ("target/i386: kvm: Block migration for vCPUs exposed with nested virtualization") was originally suppose to block migration for vCPUs exposed with nested virtualization, either Intel VMX or AMD SVM. However, during merge to upstream, commit was changed such that it doesn't even compile...
This was done unintentionally in an attempt to modify submitted patch-series such that commit 12604092e26c ("target/i386: kvm: Add nested migration blocker only when kernel lacks required capabilities") will only block migration of vCPU exposed with VMX but still allow migration of vCPU exposed with SVM.
However, since QEMU commit 75d373ef9729 ("target-i386: Disable SVM by default in KVM mode"), an AMD vCPU that is virtualized by KVM doesn’t expose SVM by default, even if you use "-cpu host". Therefore, it is unlikely that vCPU expose SVM CPUID flag when user is not running an SVM workload inside guest.
Therefore, change code back to original intent to block migration in case of vCPU exposed with SVM if kernel does not support required capabilities to save/restore nested-state.
--- target/i386/cpu.h | 10 ++++++++++ target/i386/kvm.c | 2 +- target/i386/machine.c | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-)
target/i386/cpu.h +10 -0
@@ -1867,6 +1867,16 @@ static inline bool cpu_has_vmx(CPUX86State *env)return env->features[FEAT_1_ECX ] &CPUID_EXT_VMX ; } +static inline bool cpu_has_svm (CPUX86State *env) +{ +return env->features[FEAT_8000_0001_ECX ] &CPUID_EXT3_SVM ; +} + +static inline bool cpu_has_nested_virt (CPUX86State *env) +{ +return (cpu_has_vmx (env) ||cpu_has_svm (env)); +} +/* fpu_helper.c */ void update_fp_status (CPUX86State *env);void update_mxcsr_status (CPUX86State *env);
target/i386/kvm.c +1 -1
@@ -1640,7 +1640,7 @@ int kvm_arch_init_vcpu(CPUState *cs) !!(c->ecx &CPUID_EXT_SMX ); } -if (cpu_has_vmx (env) && !nested_virt_mig_blocker && +if (cpu_has_nested_virt (env) && !nested_virt_mig_blocker && ((kvm_max_nested_state_length () <=0 ) || !has_exception_payload)) {error_setg (&nested_virt_mig_blocker, "Kernel do not provide required capabilities for "
target/i386/machine.c +1 -1
@@ -233,7 +233,7 @@ static int cpu_pre_save(void *opaque)#ifdef CONFIG_KVM /* Verify we have nested virtualization state from kernel if required */ -if (kvm_enabled () &&cpu_has_vmx (env) && !env->nested_state) { +if (kvm_enabled () &&cpu_has_nested_virt (env) && !env->nested_state) {error_report ("Guest enabled nested virtualization but kernel " "does not support saving of nested state" );return -EINVAL ;
Signature · 1 line
2.20.1
PATCH 2/2 target/i386: kvm: Init nested-state in case of vCPU exposed with SVM
In reply to Liran AlonEven though current most upstream kernel does not support save/restore of nested-state in case of AMD SVM, prepare QEMU code to init relevant nested-state struct fields.
--- target/i386/kvm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
target/i386/kvm.c +3 -2
@@ -1714,13 +1714,14 @@ int kvm_arch_init_vcpu(CPUState *cs) env->nested_state->size = max_nested_state_len; -if (IS_INTEL_CPU (env)) { +if (cpu_has_vmx (env)) {struct kvm_vmx_nested_state_hdr *vmx_hdr = &env->nested_state->hdr.vmx; - env->nested_state->format =KVM_STATE_NESTED_FORMAT_VMX ; vmx_hdr->vmxon_pa =-1ull ; vmx_hdr->vmcs12_pa =-1ull ; + }else if (cpu_has_svm (env)) { + env->nested_state->format =KVM_STATE_NESTED_FORMAT_SVM ; } }
Signature · 1 line
2.20.1
Quoted 5 lines · Liran Alon
However, during discussion made after merge, it was realised that since QEMU commit
75d373ef9729("target-i386: Disable SVM by default in KVM mode"), an AMD vCPU that is virtualized by KVM doesn't expose SVM by default, even if you use "-cpu host". Therefore, it is unlikely that vCPU expose SVM CPUID flag when user is not running an SVM workload inside guest.
libvirt has "host-model" mode, which constructs a "-cpu model,+feature,+feature" command line option that matches the host as good as possible. This lets libvirt check migratability while retaining a lot of the benefits of "-cpu host", and is the default for OpenStack for example. I need to check if libvirt adds SVM to this configuration, if it does the QEMU commit you mention is unfortunately not enough.
Paolo
Quoted 11 lines · Paolo Bonzini
Quoted 5 lines · Liran Alon
However, during discussion made after merge, it was realised that since QEMU commit
75d373ef9729("target-i386: Disable SVM by default in KVM mode"), an AMD vCPU that is virtualized by KVM doesn't expose SVM by default, even if you use "-cpu host". Therefore, it is unlikely that vCPU expose SVM CPUID flag when user is not running an SVM workload inside guest.
Quoted 8 lines
libvirt has "host-model" mode, which constructs a "-cpu model,+feature,+feature" command line option that matches the host as good as possible. This lets libvirt check migratability while retaining a lot of the benefits of "-cpu host", and is the default for OpenStack for example. I need to check if libvirt adds SVM to this configuration, if it does the QEMU commit you mention is unfortunately not enough.
Paolo
Hmm nice catch. I haven’t thought about it (Not familiar much with libvirt). I agree that if libvirt adds SVM to this configuration than we must not block migration for an AMD vCPU that is exposed with SVM… :(
Please update once you figure out libvirt behaviour regarding this, -Liran
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Subject: [Qemu-devel] [PATCH 0/2] target/i386: kvm: Fix treatment of AMD SVM in nested migration
Type: series
Message-id: [email protected]
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'a5de9408a8 target/i386: kvm: Init nested-state in case of vCPU exposed with SVM06ca99d907 target/i386: kvm: Block migration on vCPU exposed with SVM when kernel lacks caps to save/restore nested state
=== OUTPUT BEGIN ===
1/2 Checking commit 06ca99d907bc (target/i386: kvm: Block migration on vCPU exposed with SVM when kernel lacks caps to save/restore nested state)
ERROR: return is not a function, parentheses are not required
#46: FILE: target/i386/cpu.h:1877:
+ return (cpu_has_vmx(env) || cpu_has_svm(env));
total: 1 errors, 0 warnings, 32 lines checked
Patch 1/2 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
2/2 Checking commit a5de9408a89a (target/i386: kvm: Init nested-state in case of vCPU exposed with SVM) === OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Quoted 38 lines · On 22 Jun 2019, at 5:39, [email protected] wrote:
Hi,
This series seems to have some coding style problems. See output below for more information:
Subject: [Qemu-devel] [PATCH 0/2] target/i386: kvm: Fix treatment of AMD SVM in nested migration
Type: series
Message-id: [email protected]=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base >/dev/null|| exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl--mailback base..
=== TEST SCRIPT END ===From https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_patchew-2Dproject_qemu&d=DwIGaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=Jk6Q8nNzkQ6LJ6g42qARkg6ryIDGQr-yKXPNGZbpTx0&m=XheZ4_IReq-ruli16BfJeGb3_F7yec8LhFweZ5i6zf8&s=QFR1iC1wuS3a7nr5wT0nl1N49SaJCGcwFH_g0Uv7FrU&e=
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'a5de9408a8target/i386: kvm: Init nested-state in case of vCPU exposed with SVM06ca99d907target/i386: kvm: Block migration on vCPU exposed with SVM when kernel lacks caps to save/restore nested state=== OUTPUT BEGIN ===
1/2 Checking commit06ca99d907bc(target/i386: kvm: Block migration on vCPU exposed with SVM when kernel lacks caps to save/restore nested state)
ERROR: return is not a function, parentheses are not required
#46: FILE:target/i386/cpu.h:1877:
+ return (cpu_has_vmx(env)||cpu_has_svm(env));
Quoted 8 lines
total: 1 errors, 0 warnings, 32 lines checked
Patch 1/2 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in
MAINTAINERS.2/2 Checking commit
a5de9408a89a(target/i386: kvm: Init nested-state in case of vCPU exposed with SVM) === OUTPUT END ===
I kinda disagree that adding parentheses at return statements is a bad thing… Why do we enforce such a coding convention?
Anyway, I think this can be fixed when applying if we decide to apply this.
-Liran
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed the asan build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-fedora V=1 NETWORK=1
time make docker-test-debug@fedora TARGET_LIST=x86_64-softmmu J=14 NETWORK=1 === TEST SCRIPT END ===
Configure options:
--enable-werror --target-list=x86_64-softmmu --prefix=/tmp/qemu-test/install --python=/usr/bin/python3 --enable-debug --enable-sanitizers --cxx=clang++ --cc=clang --host-cc=clang
ERROR: "clang" either does not exist or does not work
# QEMU configure log Sun Jun 23 08:35:11 UTC 2019
# Configured with: '/tmp/qemu-test/src/configure' '--enable-werror' '--target-list=x86_64-softmmu' '--prefix=/tmp/qemu-test/install' '--python=/usr/bin/python3' '--enable-debug' '--enable-sanitizers' '--cxx=clang++' '--cc=clang' '--host-cc=clang'
---
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 638 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 640 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 642 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 644 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 646 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 648 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 650 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 652 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 654 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 656 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 690 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 692 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 698 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 704 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 714 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 716 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 722 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 728 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object check_define main
lines: 92 122 621 730 0
clang -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
funcs: do_compiler do_cc compile_object main
lines: 92 122 1871 0
clang -m64 -mcx16 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -c -o config-temp/qemu-conf.o config-temp/qemu-conf.c
ccache: error: Failed to create temporary file for /var/tmp/ccache/tmp/qemu-conf.stdout: Permission denied
Failed to run 'configure'
Traceback (most recent call last):
File "./tests/docker/docker.py", line 615, in <module>
The full log is available at
http://patchew.org/logs/[email protected]/testing.asan/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]