From patchwork Thu Sep 19 12:52:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 11152295 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0707B13BD for ; Thu, 19 Sep 2019 12:52:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D9B7821907 for ; Thu, 19 Sep 2019 12:52:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="NMGULGaF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390285AbfISMw4 (ORCPT ); Thu, 19 Sep 2019 08:52:56 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:57068 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389611AbfISMwz (ORCPT ); Thu, 19 Sep 2019 08:52:55 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x8JCnNcQ192172; Thu, 19 Sep 2019 12:52:32 GMT 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-2019-08-05; bh=GPM0gON8cO+0laMNOFmmLm7oLFNmncDUeC8XuWlpioc=; b=NMGULGaFwdrwGO/WYqLiN0kHToX4L1DJdap9pVzlM2lM7xcp6dIsIYazagL06hxhVih0 A418m/YawBaZvfE36z9Gf7QO2bhBL9U51w1tRviAl3qkLR8/8mV8UrwjO93vGolJjoN8 VVHnmSghZ8lFV7ZxDS0I1jhLpHfQq7zDxAIx7SIjl1niH00o+YmXFGrG90ZJ2H0QbILK R8Jwvvh5NbtroLl0/SK6ywfpY3/Hbr+UVoixSAGf2O1kTLh9zCy1B+B1at7CatzX2T1w gAZXAj+YNUibJKvJQ/3iKMs/aiP8L554u6SRyWYBekwROd+tK1lxDLIHFLNAlgGcqG18 MQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2v3vb4uqpe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Sep 2019 12:52:32 +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 x8JCmDTn178779; Thu, 19 Sep 2019 12:52:31 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 2v3vbs1ke3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Sep 2019 12:52:31 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x8JCqUdN012185; Thu, 19 Sep 2019 12:52:30 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 19 Sep 2019 05:52:29 -0700 From: Liran Alon To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: sean.j.christopherson@intel.com, jmattson@google.com, vkuznets@redhat.com, Liran Alon , Nikita Leshenko , Joao Martins , Krish Sadhukhan Subject: [PATCH kvm-unit-tests 1/8] x86: vmx: Refactor init of VMX caps to separate function Date: Thu, 19 Sep 2019 15:52:04 +0300 Message-Id: <20190919125211.18152-2-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190919125211.18152-1-liran.alon@oracle.com> References: <20190919125211.18152-1-liran.alon@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9384 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 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-1908290000 definitions=main-1909190121 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9384 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1908290000 definitions=main-1909190121 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is done as a preparation to future patches that will introduce ability to run VMX on CPUs other than BSP. Reviewed-by: Nikita Leshenko Reviewed-by: Joao Martins Reviewed-by: Krish Sadhukhan Signed-off-by: Liran Alon --- x86/vmx.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/x86/vmx.c b/x86/vmx.c index 6079420db33a..d74365049eeb 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -1247,19 +1247,8 @@ static int init_vmcs(struct vmcs **vmcs) return 0; } -static void init_vmx(void) +static void init_vmx_caps(void) { - ulong fix_cr0_set, fix_cr0_clr; - ulong fix_cr4_set, fix_cr4_clr; - - vmxon_region = alloc_page(); - - vmcs_root = alloc_page(); - - fix_cr0_set = rdmsr(MSR_IA32_VMX_CR0_FIXED0); - fix_cr0_clr = rdmsr(MSR_IA32_VMX_CR0_FIXED1); - fix_cr4_set = rdmsr(MSR_IA32_VMX_CR4_FIXED0); - fix_cr4_clr = rdmsr(MSR_IA32_VMX_CR4_FIXED1); basic.val = rdmsr(MSR_IA32_VMX_BASIC); ctrl_pin_rev.val = rdmsr(basic.ctrl ? MSR_IA32_VMX_TRUE_PIN : MSR_IA32_VMX_PINBASED_CTLS); @@ -1277,6 +1266,23 @@ static void init_vmx(void) ept_vpid.val = rdmsr(MSR_IA32_VMX_EPT_VPID_CAP); else ept_vpid.val = 0; +} + +static void init_vmx(void) +{ + ulong fix_cr0_set, fix_cr0_clr; + ulong fix_cr4_set, fix_cr4_clr; + + vmxon_region = alloc_page(); + + vmcs_root = alloc_page(); + + fix_cr0_set = rdmsr(MSR_IA32_VMX_CR0_FIXED0); + fix_cr0_clr = rdmsr(MSR_IA32_VMX_CR0_FIXED1); + fix_cr4_set = rdmsr(MSR_IA32_VMX_CR4_FIXED0); + fix_cr4_clr = rdmsr(MSR_IA32_VMX_CR4_FIXED1); + + init_vmx_caps(); write_cr0((read_cr0() & fix_cr0_clr) | fix_cr0_set); write_cr4((read_cr4() & fix_cr4_clr) | fix_cr4_set | X86_CR4_VMXE); From patchwork Thu Sep 19 12:52:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 11152303 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24E3B13BD for ; Thu, 19 Sep 2019 12:53:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 03D0C21929 for ; Thu, 19 Sep 2019 12:53:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="qsXl9ONd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390410AbfISMxI (ORCPT ); Thu, 19 Sep 2019 08:53:08 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:57428 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390407AbfISMxH (ORCPT ); Thu, 19 Sep 2019 08:53:07 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x8JCnbjM192525; Thu, 19 Sep 2019 12:52:35 GMT 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-2019-08-05; bh=lJgiKC7lFbl2F7BdBMLOkKGB5Q9KwyvK0fwuCh1ce3w=; b=qsXl9ONd5B3rhyXJG9BDVpABJ3ojVmH2UYb4CTSUzm5txKTqK6y+eNbhvWPg0Ly98aac oBthliYlG0vek7dUKK859hiqKjJ54GAsZhgVOxuEUzNcUqutYuf3jU7TGE6UwONaFbaH ACx4u38dAJj3MnIFsCBJe/g0v8yYNSz7+p3PLkIY4xi2nWUgaC/NTztVcMGKnuv9tIsf s8SIEbEhaFxXu/JMrVGQrf6XEWeVwFiMtAOuO5oLKpE5kBHI3ulRLpbXSKv5olrnNmha I2L5M4hfmnqFtPOKMjAHIzZonnmAuC7Izz2jg3jTk8B7OV5oEe69oK5M/7O4LTXz5M3O ww== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2v3vb4uqpt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Sep 2019 12:52:34 +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 x8JCn4Y2090503; Thu, 19 Sep 2019 12:52:34 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 2v3vb5ksw6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Sep 2019 12:52:34 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x8JCqXIr016880; Thu, 19 Sep 2019 12:52:33 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 19 Sep 2019 05:52:32 -0700 From: Liran Alon To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: sean.j.christopherson@intel.com, jmattson@google.com, vkuznets@redhat.com, Liran Alon , Nikita Leshenko , Joao Martins , Krish Sadhukhan Subject: [PATCH kvm-unit-tests 2/8] x86: vmx: Prepare init_vmx() for VMX support on AP CPUs Date: Thu, 19 Sep 2019 15:52:05 +0300 Message-Id: <20190919125211.18152-3-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190919125211.18152-1-liran.alon@oracle.com> References: <20190919125211.18152-1-liran.alon@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9384 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 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-1908290000 definitions=main-1909190121 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9384 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1908290000 definitions=main-1909190121 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is done as a prepartion for future patches that will add ability for running VMX in CPUs other than BSP. Reviewed-by: Nikita Leshenko Reviewed-by: Joao Martins Reviewed-by: Krish Sadhukhan Signed-off-by: Liran Alon --- x86/vmx.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/x86/vmx.c b/x86/vmx.c index d74365049eeb..a8d485c3bd09 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -1268,29 +1268,35 @@ static void init_vmx_caps(void) ept_vpid.val = 0; } -static void init_vmx(void) +static void init_vmx(u64 *vmxon_region) { ulong fix_cr0_set, fix_cr0_clr; ulong fix_cr4_set, fix_cr4_clr; - vmxon_region = alloc_page(); - - vmcs_root = alloc_page(); - fix_cr0_set = rdmsr(MSR_IA32_VMX_CR0_FIXED0); fix_cr0_clr = rdmsr(MSR_IA32_VMX_CR0_FIXED1); fix_cr4_set = rdmsr(MSR_IA32_VMX_CR4_FIXED0); fix_cr4_clr = rdmsr(MSR_IA32_VMX_CR4_FIXED1); - init_vmx_caps(); - write_cr0((read_cr0() & fix_cr0_clr) | fix_cr0_set); write_cr4((read_cr4() & fix_cr4_clr) | fix_cr4_set | X86_CR4_VMXE); *vmxon_region = basic.revision; +} +static void alloc_bsp_vmx_pages(void) +{ + vmxon_region = alloc_page(); guest_stack = alloc_page(); guest_syscall_stack = alloc_page(); + vmcs_root = alloc_page(); +} + +static void init_bsp_vmx(void) +{ + init_vmx_caps(); + alloc_bsp_vmx_pages(); + init_vmx(vmxon_region); } static void do_vmxon_off(void *data) @@ -1932,7 +1938,7 @@ int main(int argc, const char *argv[]) printf("WARNING: vmx not supported, add '-cpu host'\n"); goto exit; } - init_vmx(); + init_bsp_vmx(); if (test_wanted("test_vmx_feature_control", argv, argc)) { /* Sets MSR_IA32_FEATURE_CONTROL to 0x5 */ if (test_vmx_feature_control() != 0) From patchwork Thu Sep 19 12:52:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 11152301 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0FEF413BD for ; Thu, 19 Sep 2019 12:53:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E2BC221907 for ; Thu, 19 Sep 2019 12:53:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="m6o0Y66P" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390396AbfISMxB (ORCPT ); Thu, 19 Sep 2019 08:53:01 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:46674 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389585AbfISMxA (ORCPT ); Thu, 19 Sep 2019 08:53:00 -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 x8JCndYC151146; Thu, 19 Sep 2019 12:52:38 GMT 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-2019-08-05; bh=e2iJDhroKYhLvqIdq24XQuCMTOOmrlYdxxynevgpWpA=; b=m6o0Y66PD2ursS6KtT1A7iI+bP/vXkLcgifHFHqWQ7CbhLt5MnuyTZbTH3p5fTC0K/Fe pEvYJfg0qRlXieLEpGvwqsVwmkgkscnJHRxaTbEBT7pk9anMxi1SF0u0Uu7+vznDlpcV hZzdp++li5EJH5GB3R6rz7Z8LdMJXXayrxVWr3xgLsLbnsbsq6saHId+0aLGVfecMihB kJQXugZ6HGx7kYT6ifiuKwX2cqUS9zqF4vDD9p9LDUmvyVx5HbraodRg2iUX4zM2QCec f2f9ex6mLntEoBAzGkIEldSELT1JFY2Lj/0YOepUSpYYvfIHj6gfIgQ1sAC2TQFWF2x9 Zg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2v3vb4kpuw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Sep 2019 12:52:37 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x8JCn1P5155744; Thu, 19 Sep 2019 12:52:37 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 2v3vbac32f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Sep 2019 12:52:36 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x8JCqZLf016914; Thu, 19 Sep 2019 12:52:36 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 19 Sep 2019 05:52:35 -0700 From: Liran Alon To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: sean.j.christopherson@intel.com, jmattson@google.com, vkuznets@redhat.com, Liran Alon , Nikita Leshenko , Joao Martins , Krish Sadhukhan Subject: [PATCH kvm-unit-tests 3/8] x86: vmx: Expose vmx_init() to be used on AP CPUs Date: Thu, 19 Sep 2019 15:52:06 +0300 Message-Id: <20190919125211.18152-4-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190919125211.18152-1-liran.alon@oracle.com> References: <20190919125211.18152-1-liran.alon@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9384 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 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-1908290000 definitions=main-1909190121 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9384 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1908290000 definitions=main-1909190121 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Reviewed-by: Nikita Leshenko Reviewed-by: Joao Martins Reviewed-by: Krish Sadhukhan Signed-off-by: Liran Alon --- x86/vmx.c | 2 +- x86/vmx.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/x86/vmx.c b/x86/vmx.c index a8d485c3bd09..10b0a423dd23 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -1268,7 +1268,7 @@ static void init_vmx_caps(void) ept_vpid.val = 0; } -static void init_vmx(u64 *vmxon_region) +void init_vmx(u64 *vmxon_region) { ulong fix_cr0_set, fix_cr0_clr; ulong fix_cr4_set, fix_cr4_clr; diff --git a/x86/vmx.h b/x86/vmx.h index 75abf9a489dd..6127db3cfdd5 100644 --- a/x86/vmx.h +++ b/x86/vmx.h @@ -785,6 +785,8 @@ static inline bool invvpid(unsigned long type, u64 vpid, u64 gla) return ret; } +void init_vmx(u64 *vmxon_region); + const char *exit_reason_description(u64 reason); void print_vmexit_info(void); void print_vmentry_failure_info(struct vmentry_failure *failure); From patchwork Thu Sep 19 12:52:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 11152297 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E00B716B1 for ; Thu, 19 Sep 2019 12:52:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B4CC121907 for ; Thu, 19 Sep 2019 12:52:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Fmb97kn+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390310AbfISMw5 (ORCPT ); Thu, 19 Sep 2019 08:52:57 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:46592 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390293AbfISMw5 (ORCPT ); Thu, 19 Sep 2019 08:52:57 -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 x8JCndYD151146; Thu, 19 Sep 2019 12:52:40 GMT 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-2019-08-05; bh=b6j41riZbOO79A608VsM+KxEayDCIur5kteBhfLnWdg=; b=Fmb97kn+VD3wf5zJvPR9FBjucKghfofnE92V74QLip6+hVUOywu4DBC4cdqa30V585LC 263vVx7iuUKN4/8dztmcD1IFbrD1+pp1BFm6bDhbtiuMPANE84+MvU3EPNOc0eu1R3wN MA9IbvcTXT12G69fVbwIQ52Vhq/AFvPkOrS9oFe9iulh072pBm70qC1/yP0Dhkf/0eby ffvRkyw236vywo91UDKmKZlqqw6S6B+aIhU0iz6C0f8YlGKTOpH26NkwT6E3sFQwawDi deOy0IYUp0/+5nmEUwTXsXTa/xp7eKxc5ycAE+SgpvfxByBu1JXpwiqDYE8mYDWa66YY lQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2v3vb4kpvb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Sep 2019 12:52:40 +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 x8JCoJ7A095519; Thu, 19 Sep 2019 12:52:39 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 2v3vb5kt2w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Sep 2019 12:52:39 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x8JCqcSk024213; Thu, 19 Sep 2019 12:52:38 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 19 Sep 2019 05:52:37 -0700 From: Liran Alon To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: sean.j.christopherson@intel.com, jmattson@google.com, vkuznets@redhat.com, Liran Alon , Nikita Leshenko , Joao Martins , Krish Sadhukhan Subject: [PATCH kvm-unit-tests 4/8] x86: vmx: Support VMXON on AP CPUs VMX region Date: Thu, 19 Sep 2019 15:52:07 +0300 Message-Id: <20190919125211.18152-5-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190919125211.18152-1-liran.alon@oracle.com> References: <20190919125211.18152-1-liran.alon@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9384 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=890 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1909190121 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9384 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=963 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1909190121 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Reviewed-by: Nikita Leshenko Reviewed-by: Joao Martins Reviewed-by: Krish Sadhukhan Signed-off-by: Liran Alon --- x86/vmx.c | 25 ++++++++++++------------- x86/vmx.h | 9 +++++++-- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/x86/vmx.c b/x86/vmx.c index 10b0a423dd23..4b839ea8cc66 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -38,7 +38,7 @@ #include "smp.h" #include "apic.h" -u64 *vmxon_region; +u64 *bsp_vmxon_region; struct vmcs *vmcs_root; u32 vpid_cnt; void *guest_stack, *guest_syscall_stack; @@ -693,7 +693,7 @@ static void test_vmclear(void) vmcs_clear(tmp_root) == 1); /* Pass VMXON region */ - tmp_root = (struct vmcs *)vmxon_region; + tmp_root = (struct vmcs *)bsp_vmxon_region; report("test vmclear with vmxon region", vmcs_clear(tmp_root) == 1); @@ -1286,7 +1286,7 @@ void init_vmx(u64 *vmxon_region) static void alloc_bsp_vmx_pages(void) { - vmxon_region = alloc_page(); + bsp_vmxon_region = alloc_page(); guest_stack = alloc_page(); guest_syscall_stack = alloc_page(); vmcs_root = alloc_page(); @@ -1296,7 +1296,7 @@ static void init_bsp_vmx(void) { init_vmx_caps(); alloc_bsp_vmx_pages(); - init_vmx(vmxon_region); + init_vmx(bsp_vmxon_region); } static void do_vmxon_off(void *data) @@ -1346,12 +1346,12 @@ static int test_vmx_feature_control(void) static int test_vmxon(void) { int ret, ret1; - u64 *tmp_region = vmxon_region; + u64 *vmxon_region; int width = cpuid_maxphyaddr(); /* Unaligned page access */ - vmxon_region = (u64 *)((intptr_t)vmxon_region + 1); - ret1 = vmx_on(); + vmxon_region = (u64 *)((intptr_t)bsp_vmxon_region + 1); + ret1 = _vmx_on(vmxon_region); report("test vmxon with unaligned vmxon region", ret1); if (!ret1) { ret = 1; @@ -1359,8 +1359,8 @@ static int test_vmxon(void) } /* gpa bits beyond physical address width are set*/ - vmxon_region = (u64 *)((intptr_t)tmp_region | ((u64)1 << (width+1))); - ret1 = vmx_on(); + vmxon_region = (u64 *)((intptr_t)bsp_vmxon_region | ((u64)1 << (width+1))); + ret1 = _vmx_on(vmxon_region); report("test vmxon with bits set beyond physical address width", ret1); if (!ret1) { ret = 1; @@ -1368,8 +1368,7 @@ static int test_vmxon(void) } /* invalid revision indentifier */ - vmxon_region = tmp_region; - *vmxon_region = 0xba9da9; + *bsp_vmxon_region = 0xba9da9; ret1 = vmx_on(); report("test vmxon with invalid revision identifier", ret1); if (!ret1) { @@ -1378,7 +1377,7 @@ static int test_vmxon(void) } /* and finally a valid region */ - *vmxon_region = basic.revision; + *bsp_vmxon_region = basic.revision; ret = vmx_on(); report("test vmxon with valid vmxon region", !ret); @@ -1408,7 +1407,7 @@ static void test_vmptrld(void) /* Pass VMXON region */ assert(!vmcs_clear(vmcs)); assert(!make_vmcs_current(vmcs)); - tmp_root = (struct vmcs *)vmxon_region; + tmp_root = (struct vmcs *)bsp_vmxon_region; report("test vmptrld with vmxon region", make_vmcs_current(tmp_root) == 1); report("test vmptrld with vmxon region vm-instruction error", diff --git a/x86/vmx.h b/x86/vmx.h index 6127db3cfdd5..fdc6f7171826 100644 --- a/x86/vmx.h +++ b/x86/vmx.h @@ -660,13 +660,13 @@ extern union vmx_ctrl_msr ctrl_exit_rev; extern union vmx_ctrl_msr ctrl_enter_rev; extern union vmx_ept_vpid ept_vpid; -extern u64 *vmxon_region; +extern u64 *bsp_vmxon_region; void vmx_set_test_stage(u32 s); u32 vmx_get_test_stage(void); void vmx_inc_test_stage(void); -static int vmx_on(void) +static int _vmx_on(u64 *vmxon_region) { bool ret; u64 rflags = read_rflags() | X86_EFLAGS_CF | X86_EFLAGS_ZF; @@ -675,6 +675,11 @@ static int vmx_on(void) return ret; } +static int vmx_on(void) +{ + return _vmx_on(bsp_vmxon_region); +} + static int vmx_off(void) { bool ret; From patchwork Thu Sep 19 12:52:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 11152299 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E60E13BD for ; Thu, 19 Sep 2019 12:53:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F24B221929 for ; Thu, 19 Sep 2019 12:53:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="bxqxXC/A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390399AbfISMxB (ORCPT ); Thu, 19 Sep 2019 08:53:01 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:57266 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390392AbfISMxA (ORCPT ); Thu, 19 Sep 2019 08:53:00 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x8JCnMAr192145; Thu, 19 Sep 2019 12:52:42 GMT 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-2019-08-05; bh=9SZQUXKdrUQBvyYWQRH9Ad4ui8DD00uYNkCItZfCZtY=; b=bxqxXC/AlHecSvdSM1pn6Axsm94ZtTd1RLrEkJLap/VZD6l1Gu6oHUANC/q7WjzscWxM M+42op+e5LknddSkYGA4/F123Q04fPK22ht0u8zplXeT/7ZYhbm66pcID2Ldtq85ETBt zHTA9QDkA79P6gGgIfVnwRTCXHD89PTpAvEZXl0IK8DkelxWozoSjziTWKdpNpHt5a/u sQhJxAFfK/gOuYdMj4xgmlqr5E5IIRnfikUBkVCNI/vNn6KiFnkSLo4TeAd68lG6Ju6g YKAha74tT5Sw9R3qF1Mt4bUvCKI0ZB6T98Swf7luQhIvsIJ33HGKVuhdFI+AKxP3oNeA +Q== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2v3vb4uqqn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Sep 2019 12:52:42 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x8JCn0pf056533; Thu, 19 Sep 2019 12:52:41 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2v3vbg2dyx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Sep 2019 12:52:41 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x8JCqeqY012371; Thu, 19 Sep 2019 12:52:40 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 19 Sep 2019 05:52:40 -0700 From: Liran Alon To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: sean.j.christopherson@intel.com, jmattson@google.com, vkuznets@redhat.com, Liran Alon , Nikita Leshenko , Joao Martins , Krish Sadhukhan Subject: [PATCH kvm-unit-tests 5/8] x86: vmx: Use MSR_IA32_FEATURE_CONTROL bits names Date: Thu, 19 Sep 2019 15:52:08 +0300 Message-Id: <20190919125211.18152-6-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190919125211.18152-1-liran.alon@oracle.com> References: <20190919125211.18152-1-liran.alon@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9384 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=981 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1909190121 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9384 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1908290000 definitions=main-1909190121 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Avoid using hard-coded numbers to improve code readability. Reviewed-by: Nikita Leshenko Reviewed-by: Joao Martins Reviewed-by: Krish Sadhukhan Signed-off-by: Liran Alon --- x86/vmx.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/x86/vmx.c b/x86/vmx.c index 4b839ea8cc66..146734d334a1 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -1314,13 +1314,18 @@ static int test_vmx_feature_control(void) { u64 ia32_feature_control; bool vmx_enabled; + bool feature_control_locked; ia32_feature_control = rdmsr(MSR_IA32_FEATURE_CONTROL); - vmx_enabled = ((ia32_feature_control & 0x5) == 0x5); - if ((ia32_feature_control & 0x5) == 0x5) { + vmx_enabled = + ia32_feature_control & FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX; + feature_control_locked = + ia32_feature_control & FEATURE_CONTROL_LOCKED; + + if (vmx_enabled && feature_control_locked) { printf("VMX enabled and locked by BIOS\n"); return 0; - } else if (ia32_feature_control & 0x1) { + } else if (feature_control_locked) { printf("ERROR: VMX locked out by BIOS!?\n"); return 1; } @@ -1329,12 +1334,17 @@ static int test_vmx_feature_control(void) report("test vmxon with FEATURE_CONTROL cleared", test_for_exception(GP_VECTOR, &do_vmxon_off, NULL)); - wrmsr(MSR_IA32_FEATURE_CONTROL, 0x4); + wrmsr(MSR_IA32_FEATURE_CONTROL, FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX); report("test vmxon without FEATURE_CONTROL lock", test_for_exception(GP_VECTOR, &do_vmxon_off, NULL)); - wrmsr(MSR_IA32_FEATURE_CONTROL, 0x5); - vmx_enabled = ((rdmsr(MSR_IA32_FEATURE_CONTROL) & 0x5) == 0x5); + wrmsr(MSR_IA32_FEATURE_CONTROL, + FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX | + FEATURE_CONTROL_LOCKED); + + ia32_feature_control = rdmsr(MSR_IA32_FEATURE_CONTROL); + vmx_enabled = + ia32_feature_control & FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX; report("test enable VMX in FEATURE_CONTROL", vmx_enabled); report("test FEATURE_CONTROL lock bit", @@ -1922,6 +1932,7 @@ test_wanted(const char *name, const char *filters[], int filter_count) int main(int argc, const char *argv[]) { int i = 0; + bool vmx_enabled; setup_vm(); smp_init(); @@ -1943,8 +1954,13 @@ int main(int argc, const char *argv[]) if (test_vmx_feature_control() != 0) goto exit; } else { - if ((rdmsr(MSR_IA32_FEATURE_CONTROL) & 0x5) != 0x5) - wrmsr(MSR_IA32_FEATURE_CONTROL, 0x5); + vmx_enabled = rdmsr(MSR_IA32_FEATURE_CONTROL) & + FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX; + if (!vmx_enabled) { + wrmsr(MSR_IA32_FEATURE_CONTROL, + FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX | + FEATURE_CONTROL_LOCKED); + } } if (test_wanted("test_vmxon", argv, argc)) { From patchwork Thu Sep 19 12:52:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 11152309 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A0F713BD for ; Thu, 19 Sep 2019 12:53:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3948F21929 for ; Thu, 19 Sep 2019 12:53:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Th1qTpgU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390426AbfISMxM (ORCPT ); Thu, 19 Sep 2019 08:53:12 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:47022 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390421AbfISMxL (ORCPT ); Thu, 19 Sep 2019 08:53:11 -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 x8JCnMDs150977; Thu, 19 Sep 2019 12:52:44 GMT 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-2019-08-05; bh=yR/3L6I/MK1cQp7V3BAxxIdJ+4CObEwAFUUQTxSWvEs=; b=Th1qTpgUGv/6xColfVYP6buRe4yicD4utJUYXD53C5YIf8I1leAWP8Xh/02g/Djli/em U6ms8k+0YOZOJG+C80nulnFdHIxMZ8jj7T8NLnSfFXDH7+vF1xfCJEXscCk376DAGXpF vasrHb5SVSFmwinYqrcptjsa5/6K5W6eGL2S1qa/GwLNaX7sosmDQAxtgfS3UOjUj1LI n0/xx1rZhLcYs75DjLYy+Jg/iFr8SJjTR7+KM63rtmREnXuA8O6VcVZTpLDMltQJxYbn 0fWZZzNdKEf++TSQfdtMEcVWNHElZEU70w3IF88SBvenCW2kpi+crTEQwKurvB23VRM4 3g== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2v3vb4kpvu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Sep 2019 12:52:44 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x8JCn0XU056507; Thu, 19 Sep 2019 12:52:43 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2v3vbg2e1c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Sep 2019 12:52:43 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x8JCqhf3012384; Thu, 19 Sep 2019 12:52:43 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 19 Sep 2019 05:52:42 -0700 From: Liran Alon To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: sean.j.christopherson@intel.com, jmattson@google.com, vkuznets@redhat.com, Liran Alon , Nikita Leshenko , Joao Martins Subject: [PATCH kvm-unit-tests 6/8] x86: vmx: Expose util to enable VMX in MSR_IA32_FEATURE_CONTROL Date: Thu, 19 Sep 2019 15:52:09 +0300 Message-Id: <20190919125211.18152-7-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190919125211.18152-1-liran.alon@oracle.com> References: <20190919125211.18152-1-liran.alon@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9384 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 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-1908290000 definitions=main-1909190121 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9384 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1908290000 definitions=main-1909190121 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Reviewed-by: Nikita Leshenko Reviewed-by: Joao Martins Signed-off-by: Liran Alon --- x86/vmx.c | 22 ++++++++++++++-------- x86/vmx.h | 1 + 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/x86/vmx.c b/x86/vmx.c index 146734d334a1..b9328d9ca75c 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -1247,6 +1247,19 @@ static int init_vmcs(struct vmcs **vmcs) return 0; } +void enable_vmx(void) +{ + bool vmx_enabled = + rdmsr(MSR_IA32_FEATURE_CONTROL) & + FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX; + + if (!vmx_enabled) { + wrmsr(MSR_IA32_FEATURE_CONTROL, + FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX | + FEATURE_CONTROL_LOCKED); + } +} + static void init_vmx_caps(void) { basic.val = rdmsr(MSR_IA32_VMX_BASIC); @@ -1932,7 +1945,6 @@ test_wanted(const char *name, const char *filters[], int filter_count) int main(int argc, const char *argv[]) { int i = 0; - bool vmx_enabled; setup_vm(); smp_init(); @@ -1954,13 +1966,7 @@ int main(int argc, const char *argv[]) if (test_vmx_feature_control() != 0) goto exit; } else { - vmx_enabled = rdmsr(MSR_IA32_FEATURE_CONTROL) & - FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX; - if (!vmx_enabled) { - wrmsr(MSR_IA32_FEATURE_CONTROL, - FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX | - FEATURE_CONTROL_LOCKED); - } + enable_vmx(); } if (test_wanted("test_vmxon", argv, argc)) { diff --git a/x86/vmx.h b/x86/vmx.h index fdc6f7171826..e47134e29e83 100644 --- a/x86/vmx.h +++ b/x86/vmx.h @@ -790,6 +790,7 @@ static inline bool invvpid(unsigned long type, u64 vpid, u64 gla) return ret; } +void enable_vmx(void); void init_vmx(u64 *vmxon_region); const char *exit_reason_description(u64 reason); From patchwork Thu Sep 19 12:52:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 11152307 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EDA5413BD for ; Thu, 19 Sep 2019 12:53:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CC42A21907 for ; Thu, 19 Sep 2019 12:53:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="KnTs8t67" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390403AbfISMxK (ORCPT ); Thu, 19 Sep 2019 08:53:10 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:57446 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390407AbfISMxJ (ORCPT ); Thu, 19 Sep 2019 08:53:09 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x8JCnNIL192166; Thu, 19 Sep 2019 12:52:47 GMT 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-2019-08-05; bh=pr1JiXa876O3hDWJGIRpTY8ic1nctXxGY7hHyRF7hk4=; b=KnTs8t67M96pbV/o9TSy27DhphBsqKI8G8JsfllHbMXF3bcKj1mbtnSkc7dDJZkHn6Df iUTviCgXaFvQTd6x994nlWnB5F1Ahx5ncP4LMUa5Pcw4gxX5PVdPcNEeUFWCaziEKCog ATrkRiSwlI74xYhCK+CEolITG0l/ndtYUiNsqPOG5f8gzNqlMO5iuzh5Gfz1QICRhy2K 21Nvvj+j7DRu8DpdFlygHI3oOPGIx3tsuC3zs8w34Ak3yCFgMJGuzAMNND2d5xIVJ3TN Z2q8GY7i/ppHWv3710fbvNVqgab7StI8jG/8GKiugV9v0KCwx/7WdmwcOM/CUnEQrvZS Cg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2v3vb4uqr9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Sep 2019 12:52:46 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x8JCn4Zk156099; Thu, 19 Sep 2019 12:52:46 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 2v3vbac38v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Sep 2019 12:52:46 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x8JCqjZs027419; Thu, 19 Sep 2019 12:52:45 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 19 Sep 2019 05:52:44 -0700 From: Liran Alon To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: sean.j.christopherson@intel.com, jmattson@google.com, vkuznets@redhat.com, Liran Alon , Nikita Leshenko , Joao Martins Subject: [PATCH kvm-unit-tests 7/8] x86: vmx: Allow tests to hand-over test-vmcs between CPUs Date: Thu, 19 Sep 2019 15:52:10 +0300 Message-Id: <20190919125211.18152-8-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190919125211.18152-1-liran.alon@oracle.com> References: <20190919125211.18152-1-liran.alon@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9384 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=821 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1909190121 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9384 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=901 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1909190121 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org By exposing launched, test-vmcs can be hand-over between CPUs by VMCLEAR test-vmcs and resetting launched to false. Reviewed-by: Nikita Leshenko Reviewed-by: Joao Martins Signed-off-by: Liran Alon --- x86/vmx.h | 1 + 1 file changed, 1 insertion(+) diff --git a/x86/vmx.h b/x86/vmx.h index e47134e29e83..a8bc8472ed61 100644 --- a/x86/vmx.h +++ b/x86/vmx.h @@ -661,6 +661,7 @@ extern union vmx_ctrl_msr ctrl_enter_rev; extern union vmx_ept_vpid ept_vpid; extern u64 *bsp_vmxon_region; +extern bool launched; void vmx_set_test_stage(u32 s); u32 vmx_get_test_stage(void); From patchwork Thu Sep 19 12:52:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 11152305 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF66C195A for ; Thu, 19 Sep 2019 12:53:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9555C21907 for ; Thu, 19 Sep 2019 12:53:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="dv0knNVI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390401AbfISMxI (ORCPT ); Thu, 19 Sep 2019 08:53:08 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:46892 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390402AbfISMxI (ORCPT ); Thu, 19 Sep 2019 08:53: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 x8JCnMsc150959; Thu, 19 Sep 2019 12:52:50 GMT 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-2019-08-05; bh=BfbFOQhgQVFIXytUGWPysZKJ8YzqdrO8dYA/S6OR3VM=; b=dv0knNVI+aeDZNob1dbXZaW0qSZ0k4Eu0AJ9oFdLSRQEOOU/+A9XFEekOFCKmjwYDuW6 DZwHj3DRxWYGVrv1L8utBgS7d07LheT9UYvxFckmfa5br19IdthzYNqhONGEUCAdRX8Y hCz0WRssg3KdJ4+hpqkhxNL8vs+C2uL4t9FKac7GCWl6bqf4Iy2nm/qsBJawMI4YH6CZ EyezjJrtjzhNUk1gT07akHwxDpbzNbzxIExwyxysBWig8LfHmI3ZwSDGduSJhq4fryNU LOYHrVXl0L/ey/o/bxLMLRtttzMdIIvCoT5ZTw0O9byjv0WjM6eo2fs8OzSwrNY0BBOs 0g== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2v3vb4kpwf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Sep 2019 12:52:49 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x8JCn0wL155679; Thu, 19 Sep 2019 12:52:48 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2v3vbac3a7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Sep 2019 12:52:48 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x8JCqltd012419; Thu, 19 Sep 2019 12:52:47 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 19 Sep 2019 05:52:47 -0700 From: Liran Alon To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: sean.j.christopherson@intel.com, jmattson@google.com, vkuznets@redhat.com, Liran Alon , Nikita Leshenko , Krish Sadhukhan Subject: [PATCH kvm-unit-tests 8/8] x86: vmx: Test INIT processing during various CPU VMX states Date: Thu, 19 Sep 2019 15:52:11 +0300 Message-Id: <20190919125211.18152-9-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190919125211.18152-1-liran.alon@oracle.com> References: <20190919125211.18152-1-liran.alon@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9384 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 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-1908290000 definitions=main-1909190121 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9384 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1908290000 definitions=main-1909190121 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add vmx test to verify the functionality introduced by KVM commit: 4b9852f4f389 ("KVM: x86: Fix INIT signal handling in various CPU states"). The test verifies the following functionality: 1) An INIT signal received when CPU is in VMX operation is blocked until it exits VMX operation. 2) If there is an INIT signal pending when CPU is in VMX non-root mode, it result in VMExit with (reason == 3). 3) Exit from VMX non-root mode on VMExit do not clear pending INIT signal in LAPIC. 4) When CPU exits VMX operation, pending INIT signal in LAPIC is processed. Note: The test is excluded from the "vmx" test-suite as it ruins the execution environment of CPU1 because during the test it process an INIT signal. Reviewed-by: Nikita Leshenko Reviewed-by: Krish Sadhukhan Signed-off-by: Liran Alon --- x86/unittests.cfg | 10 +++- x86/vmx_tests.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+), 1 deletion(-) diff --git a/x86/unittests.cfg b/x86/unittests.cfg index 694ee3d42f3a..8156256146c3 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -227,7 +227,7 @@ extra_params = -cpu qemu64,+umip [vmx] file = vmx.flat -extra_params = -cpu host,+vmx -append "-exit_monitor_from_l2_test -ept_access* -vmx_smp* -vmx_vmcs_shadow_test" +extra_params = -cpu host,+vmx -append "-exit_monitor_from_l2_test -ept_access* -vmx_smp* -vmx_vmcs_shadow_test -vmx_init_signal_test" arch = x86_64 groups = vmx @@ -265,6 +265,14 @@ extra_params = -cpu host,+vmx -m 2048 -append vmx_apic_passthrough_thread_test arch = x86_64 groups = vmx +[vmx_init_signal_test] +file = vmx.flat +smp = 2 +extra_params = -cpu host,+vmx -m 2048 -append vmx_init_signal_test +arch = x86_64 +groups = vmx +timeout = 10 + [vmx_vmcs_shadow_test] file = vmx.flat extra_params = -cpu host,+vmx -append vmx_vmcs_shadow_test diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index 096640a56891..962990e30d33 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -8219,6 +8219,150 @@ static void vmx_apic_passthrough_thread_test(void) vmx_apic_passthrough(true); } +static u64 init_signal_test_exit_reason; +static bool init_signal_test_thread_continued; + +static void init_signal_test_thread(void *data) +{ + struct vmcs *test_vmcs = data; + + /* Enter VMX operation (i.e. exec VMXON) */ + u64 *ap_vmxon_region = alloc_page(); + enable_vmx(); + init_vmx(ap_vmxon_region); + _vmx_on(ap_vmxon_region); + + /* Signal CPU have entered VMX operation */ + vmx_set_test_stage(1); + + /* Wait for BSP CPU to send INIT signal */ + while (vmx_get_test_stage() != 2) + ; + + /* + * Signal that we continue as usual as INIT signal + * should be blocked while CPU is in VMX operation + */ + vmx_set_test_stage(3); + + /* Wait for signal to enter VMX non-root mode */ + while (vmx_get_test_stage() != 4) + ; + + /* Enter VMX non-root mode */ + test_set_guest(v2_null_test_guest); + make_vmcs_current(test_vmcs); + enter_guest(); + /* Save exit reason for BSP CPU to compare to expected result */ + init_signal_test_exit_reason = vmcs_read(EXI_REASON); + /* VMCLEAR test-vmcs so it could be loaded by BSP CPU */ + vmcs_clear(test_vmcs); + launched = false; + /* Signal that CPU exited to VMX root mode */ + vmx_set_test_stage(5); + + /* Wait for signal to exit VMX operation */ + while (vmx_get_test_stage() != 6) + ; + + /* Exit VMX operation (i.e. exec VMXOFF) */ + vmx_off(); + + /* + * Exiting VMX operation should result in latched + * INIT signal being processed. Therefore, we should + * never reach the below code. Thus, signal to BSP + * CPU if we have reached here so it is able to + * report an issue if it happens. + */ + init_signal_test_thread_continued = true; +} + +#define INIT_SIGNAL_TEST_DELAY 100000000ULL + +static void vmx_init_signal_test(void) +{ + struct vmcs *test_vmcs; + + if (cpu_count() < 2) { + report_skip(__func__); + return; + } + + /* VMCLEAR test-vmcs so it could be loaded by other CPU */ + vmcs_save(&test_vmcs); + vmcs_clear(test_vmcs); + + vmx_set_test_stage(0); + on_cpu_async(1, init_signal_test_thread, test_vmcs); + + /* Wait for other CPU to enter VMX operation */ + while (vmx_get_test_stage() != 1) + ; + + /* Send INIT signal to other CPU */ + apic_icr_write(APIC_DEST_PHYSICAL | APIC_DM_INIT | APIC_INT_ASSERT, + id_map[1]); + /* Signal other CPU we have sent INIT signal */ + vmx_set_test_stage(2); + + /* + * Wait reasonable amount of time for INIT signal to + * be received on other CPU and verify that other CPU + * have proceed as usual to next test stage as INIT + * signal should be blocked while other CPU in + * VMX operation + */ + delay(INIT_SIGNAL_TEST_DELAY); + report("INIT signal blocked when CPU in VMX operation", + vmx_get_test_stage() == 3); + /* No point to continue if we failed at this point */ + if (vmx_get_test_stage() != 3) + return; + + /* Signal other CPU to enter VMX non-root mode */ + init_signal_test_exit_reason = -1ull; + vmx_set_test_stage(4); + /* + * Wait reasonable amont of time for other CPU + * to exit to VMX root mode + */ + delay(INIT_SIGNAL_TEST_DELAY); + if (vmx_get_test_stage() != 5) { + report("Pending INIT signal haven't resulted in VMX exit", false); + return; + } + report("INIT signal during VMX non-root mode result in exit-reason %s (%lu)", + init_signal_test_exit_reason == VMX_INIT, + exit_reason_description(init_signal_test_exit_reason), + init_signal_test_exit_reason); + + /* Run guest to completion */ + make_vmcs_current(test_vmcs); + enter_guest(); + + /* Signal other CPU to exit VMX operation */ + init_signal_test_thread_continued = false; + vmx_set_test_stage(6); + + /* + * Wait reasonable amount of time for other CPU + * to run after INIT signal was processed + */ + delay(INIT_SIGNAL_TEST_DELAY); + report("INIT signal processed after exit VMX operation", + !init_signal_test_thread_continued); + + /* + * TODO: Send SIPI to other CPU to sipi_entry (See x86/cstart64.S) + * to re-init it to kvm-unit-tests standard environment. + * Somehow (?) verify that SIPI was indeed received. + */ + + /* Report success */ + report(__func__, 1); +} + enum vmcs_access { ACCESS_VMREAD, ACCESS_VMWRITE, @@ -8629,6 +8773,7 @@ struct vmx_test vmx_tests[] = { /* APIC pass-through tests */ TEST(vmx_apic_passthrough_test), TEST(vmx_apic_passthrough_thread_test), + TEST(vmx_init_signal_test), /* VMCS Shadowing tests */ TEST(vmx_vmcs_shadow_test), /* Regression tests */