From nobody Fri May 3 07:24:52 2024 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=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1562361686; cv=none; d=zoho.com; s=zohoarc; b=khEzvgZPmS1uSQ7UE6mcSTEsVCD28QZ6u92dHRIOLWA5XlsUoXW4rp9q+920gdivMzapr+P4kx2q1Rux/0fcgvrxAPEJui9/HHkvVWeMUWJKX5wkbGI/+ZJDHJcy54yo9y5DtttlBqXOUxnYD9PBTMsCqKy9L+o9rP/OuqapNhI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562361686; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=HMkjJwPA8RsubI7elVoiQ6HwDpd2t3xNOxViQul4hvM=; b=QH8sds8uWS3GVxJIhNAZLo8MSaRIPGHwhZCHI79Lp+1VDSHX6KCTrU4ApMzEZFbZ0D/rddhoKGet6rqMxh/K5IkhfTFkebGKPO0RH/G0/n3A9Q5rNG5T91bpxeOS3jga4+VmQY1zfn9hKBuCDQ3TXXXsODKmXNfZdbvyDVI/twU= 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 1562361686338628.2502470709098; Fri, 5 Jul 2019 14:21:26 -0700 (PDT) Received: from localhost ([::1]:56282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hjVdn-00055i-0E for importer@patchew.org; Fri, 05 Jul 2019 17:21:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43115) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hjVQJ-0001Nv-Df for qemu-devel@nongnu.org; Fri, 05 Jul 2019 17:07:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hjVQG-00005L-KS for qemu-devel@nongnu.org; Fri, 05 Jul 2019 17:07:14 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:44684) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hjVQ9-0008Iv-41 for qemu-devel@nongnu.org; Fri, 05 Jul 2019 17:07:08 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x65L40Y7119968; Fri, 5 Jul 2019 21:07:01 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 2te61emgfs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 05 Jul 2019 21:07:01 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x65L2WNq175954; Fri, 5 Jul 2019 21:07:00 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2th5qmx762-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 05 Jul 2019 21:07:00 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x65L6wQa013862; Fri, 5 Jul 2019 21:06:58 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 05 Jul 2019 14:06:58 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=HMkjJwPA8RsubI7elVoiQ6HwDpd2t3xNOxViQul4hvM=; b=UWDRNAQQhedLQBnYxQDgCyjveW7efcxIg2zD1MkEVWCJPYl0bx8WiQPURPCdtwuuZQts C1kK68oiUMwJa36kym/uGPsTDQKnTYTuEdXJL86Y7G/gI0eWtG3/72lmrwxQliqM4U5x 7YzQ8xoS0tELP/JvPAgPCZlVvnVQteFQ5iJw1DfotHzDA7/ICzL83Q/9Q5wkPvy8L4bs GpWUNBx+v9fuTT1EvWnOq7gvZAefX3pngXXHHH09ahHU+2lzTp6osMe/NbPJ+OrgpeMF tpcSAmppkaRIb8z61/Wy8VNvWwSS3pobU/2kd1fkq29zHCu31mmtutX3VtwsjiX5XsIh lw== From: Liran Alon To: qemu-devel@nongnu.org Date: Sat, 6 Jul 2019 00:06:33 +0300 Message-Id: <20190705210636.3095-2-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190705210636.3095-1-liran.alon@oracle.com> References: <20190705210636.3095-1-liran.alon@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9309 signatures=668688 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=832 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907050266 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9309 signatures=668688 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=887 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907050266 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [PATCH 1/4] target/i386: kvm: Init nested-state for VMX when vCPU expose VMX 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: pbonzini@redhat.com, Joao Martins , Liran Alon , ehabkost@redhat.com, kvm@vger.kernel.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Reviewed-by: Joao Martins Signed-off-by: Liran Alon Reviewed-by: Maran Wilson --- target/i386/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index e4b4f5756a34..b57f873ec9e8 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1714,7 +1714,7 @@ int kvm_arch_init_vcpu(CPUState *cs) =20 env->nested_state->size =3D max_nested_state_len; =20 - if (IS_INTEL_CPU(env)) { + if (cpu_has_vmx(env)) { struct kvm_vmx_nested_state_hdr *vmx_hdr =3D &env->nested_state->hdr.vmx; =20 --=20 2.20.1 From nobody Fri May 3 07:24:52 2024 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=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1562361547; cv=none; d=zoho.com; s=zohoarc; b=J1M/oZDo5506ekAmbmOkMveLxprjZlnzTSfqempNO9knpXXeoEqPAzCGwDQUQmkOFR+SFk7uMNoEwyOQYsTZlVQZt1fms3qj56pjaiLR8v6JTejTCEn2zxhY5YHVOvviC1in1cR9jFQsmKSJsMGbGyAGt7MaEMG4oF8yulVtvZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562361547; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=sSX5aIb6pbrZni5vNE5EzSGZsrAPvnkvicgxxh+1deg=; b=BV1xhX35D+FswHcR5woDaCXjozC2k7sacr9xxugmZHH1BMGwBjSkrinlNfXjOuwG8oI1HB3i/waLjXPW1jmc5CE6kY7MaUvgA7BdG68L+eTtWbYQ/RDSjWKkczARAbdvydDzCJ+fJ2kk9QQaplG4J97CsGYcz0CBatVs7soVq2Q= 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 (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562361547150716.6982236783857; Fri, 5 Jul 2019 14:19:07 -0700 (PDT) Received: from localhost ([::1]:56266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hjVbe-0002hT-Ce for importer@patchew.org; Fri, 05 Jul 2019 17:18:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43117) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hjVQJ-0001Nx-DZ for qemu-devel@nongnu.org; Fri, 05 Jul 2019 17:07:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hjVQG-00005B-KK for qemu-devel@nongnu.org; Fri, 05 Jul 2019 17:07:14 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:35906) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hjVQ9-0008J4-40 for qemu-devel@nongnu.org; Fri, 05 Jul 2019 17:07:08 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x65L3vH1025588; Fri, 5 Jul 2019 21:07:01 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2te5tc4j6d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 05 Jul 2019 21:07:01 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x65L2ULs175825; Fri, 5 Jul 2019 21:07:01 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 2th5qmx76h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 05 Jul 2019 21:07:01 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x65L70ax030850; Fri, 5 Jul 2019 21:07:00 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 05 Jul 2019 14:07:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=sSX5aIb6pbrZni5vNE5EzSGZsrAPvnkvicgxxh+1deg=; b=2H2Sg3VC4gyG44Hc9EYoACCOWiSas3tNxNak7pFM/GjtmLcn4NaP+lF7Gi5gUUiRpFcV BNgFRxOz3dMuDHW9u9ov6E3HeBKMakwGHIMY+aPXNZY8jZMutGv5QS60V8TfLeWC10wM OiG4jCx0h8+wu8Xgz0U4SlUF0rz74fpq+tF8jUk/T1RIa5dkBr80v2PD7Du/FPeJRiSL 9NsjjvSnY2brUcu+pO0qy7NT71quMm15aofCwtqzyK3tlgqD0QXW5AxLc3zIFhFVFlzt CGF/xzHtIs0LjhCv4nSyIYdD+B6PTJiiqcxt09Bqr9ecAW/kmZgoa1Nt9lC/k4vtg5ST bQ== From: Liran Alon To: qemu-devel@nongnu.org Date: Sat, 6 Jul 2019 00:06:34 +0300 Message-Id: <20190705210636.3095-3-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190705210636.3095-1-liran.alon@oracle.com> References: <20190705210636.3095-1-liran.alon@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9309 signatures=668688 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=827 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907050266 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9309 signatures=668688 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=871 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907050266 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.78 Subject: [Qemu-devel] [PATCH 2/4] target/i386: kvm: Init nested-state for vCPU exposed with SVM 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: pbonzini@redhat.com, Joao Martins , Liran Alon , ehabkost@redhat.com, kvm@vger.kernel.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Reviewed-by: Joao Martins Signed-off-by: Liran Alon Reviewed-by: Maran Wilson --- target/i386/cpu.h | 5 +++++ target/i386/kvm.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 93345792f4cb..cdb0e43676a9 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1867,6 +1867,11 @@ static inline bool cpu_has_vmx(CPUX86State *env) return env->features[FEAT_1_ECX] & CPUID_EXT_VMX; } =20 +static inline bool cpu_has_svm(CPUX86State *env) +{ + return env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_SVM; +} + /* 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 b57f873ec9e8..4e2c8652168f 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1721,6 +1721,8 @@ int kvm_arch_init_vcpu(CPUState *cs) env->nested_state->format =3D KVM_STATE_NESTED_FORMAT_VMX; vmx_hdr->vmxon_pa =3D -1ull; vmx_hdr->vmcs12_pa =3D -1ull; + } else if (cpu_has_svm(env)) { + env->nested_state->format =3D KVM_STATE_NESTED_FORMAT_SVM; } } =20 --=20 2.20.1 From nobody Fri May 3 07:24:52 2024 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=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1562361739; cv=none; d=zoho.com; s=zohoarc; b=hONyzPP0mqxeMxcOaXcAt//85ug99/FS1enU1QldS6EBO4z8jRUazQwHUJ+iZlbnMIadUwX6mkGE0WmgLyolbP1PBOr546j4H4GqpfIROXtB+g/1FGidrUIePMITzSdtnHVROuSGhxe03Dp2iWC2Inc4V9mNBb3HM/JuwoabbpA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562361739; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=mRUp3UE+E2D0bvC2nURNQ62ackyCJAb7LpNyWjews3I=; b=UZh+zQO+zHJCgu/7nywc84NuFDmO4MKdHkUz9+jtGe8ymMXSwdXCnAWya1Aj9VIqFGgCmML0qutm3RnbAM1HmDlQTxImxIyYBFUxa3ykANX7RITgbxHO3g5HfPBKOSNRz6bSAA94AzxSsv8oCa756CKFFkniigCb4HoS7775HjA= 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 (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 156236173959846.668908195645145; Fri, 5 Jul 2019 14:22:19 -0700 (PDT) Received: from localhost ([::1]:56292 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hjVeq-00061D-Hb for importer@patchew.org; Fri, 05 Jul 2019 17:22:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43157) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hjVQM-0001Pk-8D for qemu-devel@nongnu.org; Fri, 05 Jul 2019 17:07:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hjVQL-000086-8g for qemu-devel@nongnu.org; Fri, 05 Jul 2019 17:07:18 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:44712) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hjVQJ-0008NL-Fa for qemu-devel@nongnu.org; Fri, 05 Jul 2019 17:07:16 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x65L3rJF119866; Fri, 5 Jul 2019 21:07:04 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2te61emgg0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 05 Jul 2019 21:07:04 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x65L2Tb0107276; Fri, 5 Jul 2019 21:07:04 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2thxrvm495-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 05 Jul 2019 21:07:03 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x65L72ls025541; Fri, 5 Jul 2019 21:07:02 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 05 Jul 2019 14:07:02 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=mRUp3UE+E2D0bvC2nURNQ62ackyCJAb7LpNyWjews3I=; b=RFj8+UhJbo1BBp1h12iKJIXOQNTeexWnR0f+i5LWCPlInVaiVNGfRoXDTRIUlpOQ2tuJ TbdlKAqdFum1h1SubbkStuyQtA+eKI+YrBeCVANNy86MX2V8oztylKlPbD+idZr/9+9X ZXmXrT5fp9C4iZ2IO+4mDMziFcKQdSUo9ynAIgPGp/nTIx/vrNgkiX55OTP9/vBnVxYE 0GQalW4pnYN4URSz35AZ/NeoKRh3zZzRfTQNX2FUdbqlYL0/98us078Evzq9if31yHIf 8HXIsJ8s9vjo6FleER/dVTRCfHpF9SLzIwGGwYz0TDwrFVZB300XIfQbZexIEqYuFwbB 0w== From: Liran Alon To: qemu-devel@nongnu.org Date: Sat, 6 Jul 2019 00:06:35 +0300 Message-Id: <20190705210636.3095-4-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190705210636.3095-1-liran.alon@oracle.com> References: <20190705210636.3095-1-liran.alon@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9309 signatures=668688 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=661 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907050266 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9309 signatures=668688 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=705 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907050266 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [PATCH 3/4] target/i386: kvm: Save nested-state only in case vCPU have set VMXON region 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: pbonzini@redhat.com, Joao Martins , Liran Alon , ehabkost@redhat.com, kvm@vger.kernel.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Having (nested_state->hdr.vmx.vmxon_pa !=3D -1ull) signals that vCPU have s= et at some point in time a VMXON region. Note that even though when vCPU enters SMM mode it temporarily exit VMX operation, KVM still reports (vmxon_pa != =3D -1ull). Therefore, this field can be used as a reliable indicator on when we requir= e to send VMX nested-state as part of migration stream. Reviewed-by: Joao Martins Signed-off-by: Liran Alon Reviewed-by: Maran Wilson --- target/i386/machine.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/target/i386/machine.c b/target/i386/machine.c index 851b249d1a39..20bda9f80154 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -997,9 +997,8 @@ static bool vmx_nested_state_needed(void *opaque) { struct kvm_nested_state *nested_state =3D opaque; =20 - return ((nested_state->format =3D=3D KVM_STATE_NESTED_FORMAT_VMX) && - ((nested_state->hdr.vmx.vmxon_pa !=3D -1ull) || - (nested_state->hdr.vmx.smm.flags & KVM_STATE_NESTED_SMM_VMXON= ))); + return (nested_state->format =3D=3D KVM_STATE_NESTED_FORMAT_VMX) && + (nested_state->hdr.vmx.vmxon_pa !=3D -1ull); } =20 static const VMStateDescription vmstate_vmx_nested_state =3D { --=20 2.20.1 From nobody Fri May 3 07:24:52 2024 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=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1562361351; cv=none; d=zoho.com; s=zohoarc; b=Gjeks2Ysc+svkLfMl7nH54YxFBJ1lqGCCeHtUc+InQrRxuyOZ1wMlQ47iQEYruWm/ytUVSgZidGI5VgTTvfefJpJMw9JEztx8XwQx3652R63X55+ZmoDczQjXeHh4DgsjQJMRTDMxKqsqaMB4PmCmkPphPdt4wqjPVqCG9KQPLE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562361351; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=c1/s290z5etu0n2dhhW4gTKM/KYEKjonva5/EhYLZIU=; b=aBJiyz1kHalkL49jxkaZFXHSEs6djuUiwocE9xkNiqcLcozcv5saxTUGDodD6A5Q2hgiQirgxvvJ5L8GvdeE9somWBXoLg+SRnZGqZyu/J3KFV8kMY9LIxGjf0Ju5V3g8Y1TIpzMz39RdPdO+1ebRln6iSLetQ2vAzBLNv0L4mM= 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 1562361351714578.6156626641846; Fri, 5 Jul 2019 14:15:51 -0700 (PDT) Received: from localhost ([::1]:56244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hjVYX-0000oS-3p for importer@patchew.org; Fri, 05 Jul 2019 17:15:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43215) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hjVQP-0001Qt-6a for qemu-devel@nongnu.org; Fri, 05 Jul 2019 17:07:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hjVQM-00008T-0P for qemu-devel@nongnu.org; Fri, 05 Jul 2019 17:07:21 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:44740) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hjVQK-0008Oi-K3 for qemu-devel@nongnu.org; Fri, 05 Jul 2019 17:07:17 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x65L3ssF119898; Fri, 5 Jul 2019 21:07:06 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2te61emgg7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 05 Jul 2019 21:07:06 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x65L2X1w107403; Fri, 5 Jul 2019 21:07:05 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 2thxrvm49m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 05 Jul 2019 21:07:05 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x65L744d030880; Fri, 5 Jul 2019 21:07:04 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 05 Jul 2019 14:07:04 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=c1/s290z5etu0n2dhhW4gTKM/KYEKjonva5/EhYLZIU=; b=GqFIVJ+LGAkA/7QG8/2sY22kgXgTR/GX92pg2il3KbclJ+vyFhXi/+Zfq4oOUetdGzgE 4OprN6smZGcLb1oNPgc2Ifw91FO98/IQNY8A5i0xe6rx/eNuK3dK3TuRCRe+CQTmjf4j LRTqIYEhpHccp5jw+jJxPU0jXg00+KihuiKMIpMAGmCgKiJCtRaUfAyp3vAUjXfIs6wZ FORMAdyeYecRlaSMH2yHP9PCcAEhbs6mZHooThE99+uzwKTWFgo1XXDeHLp2/0vkj7QC VKSejnb9wqeTmt0g9Sp3soj67dVJPeERAbfdVycDDEPjSQRd1PA/r+Xf8/5BPlJa2bIR eQ== From: Liran Alon To: qemu-devel@nongnu.org Date: Sat, 6 Jul 2019 00:06:36 +0300 Message-Id: <20190705210636.3095-5-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190705210636.3095-1-liran.alon@oracle.com> References: <20190705210636.3095-1-liran.alon@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9309 signatures=668688 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907050266 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9309 signatures=668688 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907050266 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [PATCH 4/4] target/i386: kvm: Demand nested migration kernel capabilities only when vCPU may have enabled VMX 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: pbonzini@redhat.com, Joao Martins , Liran Alon , ehabkost@redhat.com, kvm@vger.kernel.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Previous to this change, a vCPU exposed with VMX running on a kernel withou= t KVM_CAP_NESTED_STATE or KVM_CAP_EXCEPTION_PAYLOAD resulted in adding a migration blocker. This w= as because when code was written it was thought there is no way to reliabely know if a vCPU is u= tilising VMX or not at runtime. However, it turns out that this can be known to some extent: In order for a vCPU to enter VMX operation it must have CR4.VMXE set. Since it was set, CR4.VMXE must remain set as long as vCPU is in VMX operation. This is because CR4.VMXE is one of the bits set in MSR_IA32_VMX_CR4_FIXED1. There is one exception to above statement when vCPU enters SMM mode. When a vCPU enters SMM mode, it temporarily exit VMX operation and may also reset CR4.VMXE during execution in SMM mode. When vCPU exits SMM mode, vCPU state is restored to be in VMX operation and CR4.VMXE is restored to it's original value of being set. Therefore, when vCPU is not in SMM mode, we can infer whether VMX is being used by examining CR4.VMXE. Otherwise, we cannot know for certain but assume the worse that vCPU may utilise VMX. Summaring all the above, a vCPU may have enabled VMX in case CR4.VMXE is set or vCPU is in SMM mode. Therefore, remove migration blocker and check before migration (cpu_pre_sav= e()) if vCPU may have enabled VMX. If true, only then require relevant kernel ca= pabilities. While at it, demand KVM_CAP_EXCEPTION_PAYLOAD only when vCPU is in guest-mo= de and there is a pending/injected exception. Otherwise, this kernel capability is not required for proper migration. Reviewed-by: Joao Martins Signed-off-by: Liran Alon Reviewed-by: Maran Wilson Tested-by: Maran Wilson --- target/i386/cpu.h | 22 ++++++++++++++++++++++ target/i386/kvm.c | 26 ++++++-------------------- target/i386/kvm_i386.h | 1 + target/i386/machine.c | 24 ++++++++++++++++++++---- 4 files changed, 49 insertions(+), 24 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index cdb0e43676a9..c752c4d936ee 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1872,6 +1872,28 @@ static inline bool cpu_has_svm(CPUX86State *env) return env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_SVM; } =20 +/* + * In order for a vCPU to enter VMX operation it must have CR4.VMXE set. + * Since it was set, CR4.VMXE must remain set as long as vCPU is in + * VMX operation. This is because CR4.VMXE is one of the bits set + * in MSR_IA32_VMX_CR4_FIXED1. + * + * There is one exception to above statement when vCPU enters SMM mode. + * When a vCPU enters SMM mode, it temporarily exit VMX operation and + * may also reset CR4.VMXE during execution in SMM mode. + * When vCPU exits SMM mode, vCPU state is restored to be in VMX operation + * and CR4.VMXE is restored to it's original value of being set. + * + * Therefore, when vCPU is not in SMM mode, we can infer whether + * VMX is being used by examining CR4.VMXE. Otherwise, we cannot + * know for certain. + */ +static inline bool cpu_vmx_maybe_enabled(CPUX86State *env) +{ + return cpu_has_vmx(env) && + ((env->cr[4] & CR4_VMXE_MASK) || (env->hflags & HF_SMM_MASK)); +} + /* 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 4e2c8652168f..d3af445eeb5d 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -128,6 +128,11 @@ bool kvm_has_adjust_clock_stable(void) return (ret =3D=3D KVM_CLOCK_TSC_STABLE); } =20 +bool kvm_has_exception_payload(void) +{ + return has_exception_payload; +} + bool kvm_allows_irq0_override(void) { return !kvm_irqchip_in_kernel() || kvm_has_gsi_routing(); @@ -1341,7 +1346,6 @@ static int hyperv_init_vcpu(X86CPU *cpu) } =20 static Error *invtsc_mig_blocker; -static Error *nested_virt_mig_blocker; =20 #define KVM_MAX_CPUID_ENTRIES 100 =20 @@ -1640,22 +1644,6 @@ int kvm_arch_init_vcpu(CPUState *cs) !!(c->ecx & CPUID_EXT_SMX); } =20 - if (cpu_has_vmx(env) && !nested_virt_mig_blocker && - ((kvm_max_nested_state_length() <=3D 0) || !has_exception_payload)= ) { - error_setg(&nested_virt_mig_blocker, - "Kernel do not provide required capabilities for " - "nested virtualization migration. " - "(CAP_NESTED_STATE=3D%d, CAP_EXCEPTION_PAYLOAD=3D%d)", - kvm_max_nested_state_length() > 0, - has_exception_payload); - r =3D migrate_add_blocker(nested_virt_mig_blocker, &local_err); - if (local_err) { - error_report_err(local_err); - error_free(nested_virt_mig_blocker); - return r; - } - } - if (env->mcg_cap & MCG_LMCE_P) { has_msr_mcg_ext_ctl =3D has_msr_feature_control =3D true; } @@ -1670,7 +1658,7 @@ int kvm_arch_init_vcpu(CPUState *cs) if (local_err) { error_report_err(local_err); error_free(invtsc_mig_blocker); - goto fail2; + return r; } } } @@ -1741,8 +1729,6 @@ int kvm_arch_init_vcpu(CPUState *cs) =20 fail: migrate_del_blocker(invtsc_mig_blocker); - fail2: - migrate_del_blocker(nested_virt_mig_blocker); =20 return r; } diff --git a/target/i386/kvm_i386.h b/target/i386/kvm_i386.h index 3057ba4f7d19..06fe06bdb3d6 100644 --- a/target/i386/kvm_i386.h +++ b/target/i386/kvm_i386.h @@ -35,6 +35,7 @@ bool kvm_allows_irq0_override(void); bool kvm_has_smm(void); bool kvm_has_adjust_clock_stable(void); +bool kvm_has_exception_payload(void); void kvm_synchronize_all_tsc(void); void kvm_arch_reset_vcpu(X86CPU *cs); void kvm_arch_do_init_vcpu(X86CPU *cs); diff --git a/target/i386/machine.c b/target/i386/machine.c index 20bda9f80154..c04021937722 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -7,6 +7,7 @@ #include "hw/isa/isa.h" #include "migration/cpu.h" #include "hyperv.h" +#include "kvm_i386.h" =20 #include "sysemu/kvm.h" #include "sysemu/tcg.h" @@ -232,10 +233,25 @@ static int cpu_pre_save(void *opaque) } =20 #ifdef CONFIG_KVM - /* Verify we have nested virtualization state from kernel if required = */ - if (kvm_enabled() && cpu_has_vmx(env) && !env->nested_state) { - error_report("Guest enabled nested virtualization but kernel " - "does not support saving of nested state"); + /* + * In case vCPU may have enabled VMX, we need to make sure kernel have + * required capabilities in order to perform migration correctly: + * + * 1) We must be able to extract vCPU nested-state from KVM. + * + * 2) In case vCPU is running in guest-mode and it has a pending excep= tion, + * we must be able to determine if it's in a pending or injected state. + * Note that in case KVM don't have required capability to do so, + * a pending/injected exception will always appear as an + * injected exception. + */ + if (kvm_enabled() && cpu_vmx_maybe_enabled(env) && + (!env->nested_state || + (!kvm_has_exception_payload() && (env->hflags & HF_GUEST_MASK) && + env->exception_injected))) { + error_report("Guest maybe enabled nested virtualization but kernel= " + "does not support required capabilities to save vCPU " + "nested state"); return -EINVAL; } #endif --=20 2.20.1