From nobody Sun Sep 28 00:34:09 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1561083609; cv=none; d=zoho.com; s=zohoarc; b=GEi48Xi+ijUoglFPe8vG2wggw4lPrw+IeHEvPu68xOK1kJtV6WsIoc+Z+MGsO3TGPvJ1nnkEFhljWkhls0mEA9AMvYUY4mA/iP5vMown7ecwx9k8fXSSJOW+73g5542+BNnpa3FzCjzhOuO1hZEM02y3MGfFzNIt3zOgaocZ2xg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561083609; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=jcz8Kl2eMkWbOjfqltPmtGPE3+YHm3y2OunQ4bM4BqY=; b=TuMHNEji/4Cj2vRFFej8CpvPxI4DM1lEGowk/3JNhjOSPMhU8wNWzvzqOZXeMh+hpUTr1tfGXEBWX/nRblc2hs95l/qbIU/0fp1KVfwf1scdlEn/pN1g6uqXUQ7yDPOGlB+o4yFfxOyBiainTusw5GqaRlry3+KoQkX53Aqq678= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1561083609455445.47601599595; Thu, 20 Jun 2019 19:20:09 -0700 (PDT) Received: from localhost ([::1]:54220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1he99n-0007Jp-FM for importer@patchew.org; Thu, 20 Jun 2019 22:20:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41327) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1he8a7-0006gO-4o for qemu-devel@nongnu.org; Thu, 20 Jun 2019 21:43:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1he8a3-0006fN-JL for qemu-devel@nongnu.org; Thu, 20 Jun 2019 21:43:10 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:55297) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1he8a2-0006Ly-RI for qemu-devel@nongnu.org; Thu, 20 Jun 2019 21:43:07 -0400 Received: by mail-wm1-x330.google.com with SMTP id a15so4783763wmj.5 for ; Thu, 20 Jun 2019 18:42:51 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d1sm1123125wru.41.2019.06.20.18.42.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2019 18:42:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=jcz8Kl2eMkWbOjfqltPmtGPE3+YHm3y2OunQ4bM4BqY=; b=JcoY2zFT9zydt62h0pV6ZNhwCgiwOMQfXkaF5d8wPtDr5uyu0rtwSHSBOx0tkQNTzx CrrZbD7kjwmDmYXuPf1UU4tXcpawUpsfcl1PAaSEVudYMSrvDnbPUQMx364iJWvqLGL4 TXRgWGv3ns/m1c1wMkXcPqfIpDXBNvlSZexaLEC8yjid3YqBptM3MYQmxa+GDMAUH+28 9+O5SgIhY+ZdWOZqasW/7OkI5eiafJLR7s10C4fZL8BiMeEOwfuZS3scmtA7Vh0rc1wS UEJDNcq0Od0td9r/KHOUJO6bV7PR0v8+TmcwA2ZTKxztO67tXSFGS/2dRqN2/Vl7lMsx 7yJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=jcz8Kl2eMkWbOjfqltPmtGPE3+YHm3y2OunQ4bM4BqY=; b=j3Hl0itYZR8WemZ1VnCFCpwY4swVbXEwYl2Ad6oFYYyJIJMm5+9ZoXBE+xS58f1ci5 Nf6qiAyNiMpqmp16q1QjrCFuA1XfQV7Aj/jS1qvAKkxpzwp25QBGc4DTBeAilIJQC33I aRGDXDopw2kteAvCzSDu9rzmXLriGLVhNbIEN42X9BONZ7CLeoZmHfhhwp2fdqxSqAoX JxMppdEAOEBlxanXigNGcq4SLiOS0awZvHVDfF0jQ0/bz6HrhF0HWgLFUTUtHKtaB7Oi IzSmqYSu5Hbr9cMeFvYsvi5+1lnBI1Wf84pyosK3r9DMUn5M5F0msgGEUcFnRf7+6lq8 TqLA== X-Gm-Message-State: APjAAAXBMi/xpCzqUUqOr854IAV9NTuBG2Fyq1sz2wQlOFg8bmxw3Peo MNbwfULBB+1rKMYytbF5pfWDeszp X-Google-Smtp-Source: APXvYqyuElKYczP/eQLYpwxJkA/qA2rQEIk+rDkWTE8/F1qrRRW3kN7Jpj5QAZ237S5bzOQg44Fwhw== X-Received: by 2002:a05:600c:291:: with SMTP id 17mr1494901wmk.32.1561081369968; Thu, 20 Jun 2019 18:42:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 03:42:22 +0200 Message-Id: <1561081350-3723-18-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561081350-3723-1-git-send-email-pbonzini@redhat.com> References: <1561081350-3723-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::330 Subject: [Qemu-devel] [PULL 17/25] target/i386: kvm: Block migration for vCPUs exposed with nested virtualization X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liran Alon Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Liran Alon Commit d98f26073beb ("target/i386: kvm: add VMX migration blocker") added a migration blocker for vCPU exposed with Intel VMX. However, migration should also be blocked for vCPU exposed with AMD SVM. Both cases should be blocked because QEMU should extract additional vCPU state from KVM that should be migrated as part of vCPU VMState. E.g. Whether vCPU is running in guest-mode or host-mode. Fixes: d98f26073beb ("target/i386: kvm: add VMX migration blocker") Reviewed-by: Maran Wilson Signed-off-by: Liran Alon Message-Id: <20190619162140.133674-6-liran.alon@oracle.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 6 ------ target/i386/cpu.h | 22 ++++++++++++++++++++++ target/i386/kvm.c | 14 +++++++------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index c330fd9..61e44cb 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5215,12 +5215,6 @@ static int x86_cpu_filter_features(X86CPU *cpu) return rv; } =20 -#define IS_INTEL_CPU(env) ((env)->cpuid_vendor1 =3D=3D CPUID_VENDOR_INTEL_= 1 && \ - (env)->cpuid_vendor2 =3D=3D CPUID_VENDOR_INTEL_= 2 && \ - (env)->cpuid_vendor3 =3D=3D CPUID_VENDOR_INTEL_= 3) -#define IS_AMD_CPU(env) ((env)->cpuid_vendor1 =3D=3D CPUID_VENDOR_AMD_1 &&= \ - (env)->cpuid_vendor2 =3D=3D CPUID_VENDOR_AMD_2 &&= \ - (env)->cpuid_vendor3 =3D=3D CPUID_VENDOR_AMD_3) static void x86_cpu_realizefn(DeviceState *dev, Error **errp) { CPUState *cs =3D CPU(dev); diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 7f48136..4ae4145 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -722,6 +722,13 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS]; =20 #define CPUID_VENDOR_HYGON "HygonGenuine" =20 +#define IS_INTEL_CPU(env) ((env)->cpuid_vendor1 =3D=3D CPUID_VENDOR_INTEL_= 1 && \ + (env)->cpuid_vendor2 =3D=3D CPUID_VENDOR_INTEL_= 2 && \ + (env)->cpuid_vendor3 =3D=3D CPUID_VENDOR_INTEL_= 3) +#define IS_AMD_CPU(env) ((env)->cpuid_vendor1 =3D=3D CPUID_VENDOR_AMD_1 &&= \ + (env)->cpuid_vendor2 =3D=3D CPUID_VENDOR_AMD_2 &&= \ + (env)->cpuid_vendor3 =3D=3D CPUID_VENDOR_AMD_3) + #define CPUID_MWAIT_IBE (1U << 1) /* Interrupts can exit capability */ #define CPUID_MWAIT_EMX (1U << 0) /* enumeration supported */ =20 @@ -1848,6 +1855,21 @@ static inline int32_t x86_get_a20_mask(CPUX86State *= env) } } =20 +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); diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 9864aa0..f9872f1 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1299,7 +1299,7 @@ static int hyperv_init_vcpu(X86CPU *cpu) } =20 static Error *invtsc_mig_blocker; -static Error *vmx_mig_blocker; +static Error *nested_virt_mig_blocker; =20 #define KVM_MAX_CPUID_ENTRIES 100 =20 @@ -1597,13 +1597,13 @@ int kvm_arch_init_vcpu(CPUState *cs) !!(c->ecx & CPUID_EXT_SMX); } =20 - if ((env->features[FEAT_1_ECX] & CPUID_EXT_VMX) && !vmx_mig_blocker) { - error_setg(&vmx_mig_blocker, - "Nested VMX virtualization does not support live migrat= ion yet"); - r =3D migrate_add_blocker(vmx_mig_blocker, &local_err); + if (cpu_has_nested_virt(env) && !nested_virt_mig_blocker) { + error_setg(&nested_virt_mig_blocker, + "Nested virtualization does not support live migration = yet"); + r =3D migrate_add_blocker(nested_virt_mig_blocker, &local_err); if (local_err) { error_report_err(local_err); - error_free(vmx_mig_blocker); + error_free(nested_virt_mig_blocker); return r; } } @@ -1674,7 +1674,7 @@ int kvm_arch_init_vcpu(CPUState *cs) fail: migrate_del_blocker(invtsc_mig_blocker); fail2: - migrate_del_blocker(vmx_mig_blocker); + migrate_del_blocker(nested_virt_mig_blocker); =20 return r; } --=20 1.8.3.1