From patchwork Sat May 23 00:26:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 11566465 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 A4BC5739 for ; Sat, 23 May 2020 01:07:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DBB320756 for ; Sat, 23 May 2020 01:07:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="nbw9m4B3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387515AbgEWBHM (ORCPT ); Fri, 22 May 2020 21:07:12 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:55010 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387481AbgEWBHL (ORCPT ); Fri, 22 May 2020 21:07:11 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 04N12vmE141487; Sat, 23 May 2020 01:07:05 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-2020-01-29; bh=b3wjFY2nfeMXo73nP9tjwYwmaSSSRj72YCwuvzzjD3A=; b=nbw9m4B3qT859CBxh2jLOHeFBXRihjs4aIVKHFlUnF6ShaAcCfbG4pYLTD9kktnX6kx/ I17DabwF9f2XMou17mg45rUitjTmdvHGE7Nh0AkVX263qwL74MlCTK56RgIjGRk9Ke9V Lqr4LGm6vkRfdpwTpcvPSTfBSklpiBJDh8niyAep7F/aZPogCK+DOmkNOkzbJK6YPtq6 j3btXj6tUmo1cXhrimxxL2M4TzdsJo8PUh3uPdmmgb6p2HPwRfH2F6vP4it5c7pY+1DH qKDpsANv2Ha9WouLe66yJa6dgChTtVZNskfSNlssGGw8ymNPVhjfveRVQjzSrboI4Gp5 Ag== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 31284mg7qm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 23 May 2020 01:07:05 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 04N13LNU110813; Sat, 23 May 2020 01:07:05 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 3150259y3q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 23 May 2020 01:07:05 +0000 Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 04N174BD021215; Sat, 23 May 2020 01:07:04 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 22 May 2020 18:07:04 -0700 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, sean.j.christopherson@intel.com Subject: [PATCH 1/3] kvm-unit-tests: nVMX: Test GUEST_BASE_GDTR and GUEST_BASE_IDTR on vmentry of nested guests Date: Fri, 22 May 2020 20:26:01 -0400 Message-Id: <20200523002603.32450-2-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200523002603.32450-1-krish.sadhukhan@oracle.com> References: <20200523002603.32450-1-krish.sadhukhan@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9629 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 suspectscore=13 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005230005 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9629 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=13 mlxscore=0 cotscore=-2147483648 impostorscore=0 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 phishscore=0 spamscore=0 bulkscore=0 adultscore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005230005 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org According to section "Checks on Guest Descriptor-Table Registers" in Intel SDM vol 3C, the following check is performed on the Guest Descriptor-Table Registers on vmentry of nested guests: - On processors that support Intel 64 architecture, the base-address fields must contain canonical addresses. Signed-off-by: Krish Sadhukhan --- x86/vmx_tests.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index 68f93d3..fa27d99 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -7827,6 +7827,11 @@ static void vmx_guest_state_area_test(void) test_load_guest_perf_global_ctrl(); test_load_guest_bndcfgs(); +#ifdef __x86_64__ + test_canonical(GUEST_BASE_GDTR, "GUEST_BASE_GDTR", false); + test_canonical(GUEST_BASE_IDTR, "GUEST_BASE_IDTR", false); +#endif + /* * Let the guest finish execution */ From patchwork Sat May 23 00:26:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 11566471 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 825B960D for ; Sat, 23 May 2020 01:09:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A21D20738 for ; Sat, 23 May 2020 01:09:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="VhBku3K+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387465AbgEWBJM (ORCPT ); Fri, 22 May 2020 21:09:12 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:41946 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387427AbgEWBJM (ORCPT ); Fri, 22 May 2020 21:09:12 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 04N18EAL104070; Sat, 23 May 2020 01:09:06 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-2020-01-29; bh=N/SrwxTYPSrc6MLiJ/PyaDtJ37vMII8cDYkNARaK814=; b=VhBku3K+ne7oPscxjdtfSsXQ36P7bI/FL9wi1VkCsNOGcYkQLYDd/HjUDuy7cWe6akVv w1K/0qjjcsozgxYk1Pr+c6wK/PbW3omj5OSvZ6Zi/AGOv1tIsPI7UWtb6+SIt9U5BbCR NrFvVDltbH6thJbyNDMoZFk9en9pxB3iZuOQ50JckD9xKUL3RpzYuEfruQ6KbsUteQTY Xot733Fxn88xyEN0LVeaYSo0u4GAe4Z9i1W5eSRv+QfPCYGgeQJhGXW9AaSve4kuS8kc tI1FF4urx3/SrcCwn2MOJUl6j45Cq1lk0amtq0cJUz15ISjf7eElXmSZuui0xq9Pw96C bQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 316qrvr7du-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 23 May 2020 01:09:06 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 04N13I1R167160; Sat, 23 May 2020 01:07:05 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 312t3g8aby-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 23 May 2020 01:07:05 +0000 Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 04N174P8029335; Sat, 23 May 2020 01:07:04 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 22 May 2020 18:07:04 -0700 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, sean.j.christopherson@intel.com Subject: [PATCH 2/3] kvm-unit-tests: nVMX: Optimize test_guest_dr7() by factoring out the loops into a macro Date: Fri, 22 May 2020 20:26:02 -0400 Message-Id: <20200523002603.32450-3-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200523002603.32450-1-krish.sadhukhan@oracle.com> References: <20200523002603.32450-1-krish.sadhukhan@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9629 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 malwarescore=0 suspectscore=13 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005230005 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9629 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 impostorscore=0 malwarescore=0 cotscore=-2147483648 suspectscore=13 adultscore=0 phishscore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005230006 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Signed-off-by: Krish Sadhukhan --- x86/vmx_tests.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index fa27d99..f400408 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -7704,6 +7704,19 @@ static void vmx_host_state_area_test(void) test_load_host_perf_global_ctrl(); } +#define TEST_GUEST_VMCS_FIELD_RESERVED_BITS(start, end, inc, fld, str_name,\ + val, msg, xfail) \ +{ \ + u64 tmp; \ + int i; \ + \ + for (i = start; i <= end; i = i + inc) { \ + tmp = val | (1ull << i); \ + vmcs_write(fld, tmp); \ + test_guest_state(msg, xfail, val, str_name); \ + } \ +} + /* * If the "load debug controls" VM-entry control is 1, bits 63:32 in * the DR7 field must be 0. @@ -7714,26 +7727,17 @@ static void test_guest_dr7(void) { u32 ent_saved = vmcs_read(ENT_CONTROLS); u64 dr7_saved = vmcs_read(GUEST_DR7); - u64 val; - int i; if (ctrl_enter_rev.set & ENT_LOAD_DBGCTLS) { - vmcs_clear_bits(ENT_CONTROLS, ENT_LOAD_DBGCTLS); - for (i = 0; i < 64; i++) { - val = 1ull << i; - vmcs_write(GUEST_DR7, val); - test_guest_state("ENT_LOAD_DBGCTLS disabled", false, - val, "GUEST_DR7"); - } + vmcs_write(ENT_CONTROLS, ent_saved & ~ENT_LOAD_DBGCTLS); + TEST_GUEST_VMCS_FIELD_RESERVED_BITS(0, 63, 4, GUEST_DR7, + "GUEST_DR7", dr7_saved, "ENT_LOAD_DBGCTLS disabled", false); } if (ctrl_enter_rev.clr & ENT_LOAD_DBGCTLS) { - vmcs_set_bits(ENT_CONTROLS, ENT_LOAD_DBGCTLS); - for (i = 0; i < 64; i++) { - val = 1ull << i; - vmcs_write(GUEST_DR7, val); - test_guest_state("ENT_LOAD_DBGCTLS enabled", i >= 32, - val, "GUEST_DR7"); - } + vmcs_write(ENT_CONTROLS, ent_saved | ENT_LOAD_DBGCTLS); + TEST_GUEST_VMCS_FIELD_RESERVED_BITS(0, 63, 4, GUEST_DR7, + "GUEST_DR7", dr7_saved, "ENT_LOAD_DBGCTLS enabled", + i >= 32); } vmcs_write(GUEST_DR7, dr7_saved); vmcs_write(ENT_CONTROLS, ent_saved); From patchwork Sat May 23 00:26:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 11566461 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 B5F66739 for ; Sat, 23 May 2020 01:07:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F12920738 for ; Sat, 23 May 2020 01:07:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="fgeaX9M4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387494AbgEWBHL (ORCPT ); Fri, 22 May 2020 21:07:11 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:54994 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387475AbgEWBHK (ORCPT ); Fri, 22 May 2020 21:07:10 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 04N12hvR140755; Sat, 23 May 2020 01:07:06 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-2020-01-29; bh=Gif6rYrgQ7jMQBVu8ERVcS36qGe2iNG99oyOQ8j0sBc=; b=fgeaX9M4vdDHxj31B3gj6z9o6D7pzRuTh8ejXYa4vVbM7qJNPZ+z60hkC1s/rBsUtkk7 2LbmTxiBhm0zXGsMCH8urrGVH+mnK/iDxB5GKhp0x9sZH1nJMTMO6vfqRMnMiusCpn93 IvIejxBb/FQS1XYHirUPqocPgXt6+E4hG6F2Hx0kM9qLeqIQHR6GFrTD99ONwYky11Dl jG9ZRMRRhT9RBIAuSzTK8PqAMeiB16AsIyE0uVhsKlsIxTpYfMS92BU0dGleFOGOT1ih nw0lacjRLNe8L460cfNwyJsufveVIFP8JyrGErEGNV6VklSI/fWzQy372/85z2E6ORy/ ag== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 31284mg7qp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 23 May 2020 01:07:05 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 04N13JVM167319; Sat, 23 May 2020 01:07:05 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 312t3g8ac2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 23 May 2020 01:07:05 +0000 Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 04N1752S006848; Sat, 23 May 2020 01:07:05 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 22 May 2020 18:07:04 -0700 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, sean.j.christopherson@intel.com Subject: [PATCH 3/3] kvm-unit-tests: nVMX: Test GUEST_LIMIT_GDTR and GUEST_LIMIT_IDTR on vmentry of nested guests Date: Fri, 22 May 2020 20:26:03 -0400 Message-Id: <20200523002603.32450-4-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200523002603.32450-1-krish.sadhukhan@oracle.com> References: <20200523002603.32450-1-krish.sadhukhan@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9629 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 malwarescore=0 suspectscore=13 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005230005 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9629 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=13 mlxscore=0 cotscore=-2147483648 impostorscore=0 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 phishscore=0 spamscore=0 bulkscore=0 adultscore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005230005 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org According to section "Checks on Guest Descriptor-Table Registers" in Intel SDM vol 3C, the following checks are performed on the Guest Descriptor-Table Registers on vmentry of nested guests: - Bits 31:16 of each limit field must be 0. Signed-off-by: Krish Sadhukhan --- x86/vmx_tests.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index f400408..7b6205d 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -7836,6 +7836,17 @@ static void vmx_guest_state_area_test(void) test_canonical(GUEST_BASE_IDTR, "GUEST_BASE_IDTR", false); #endif + u32 guest_desc_limit_saved = vmcs_read(GUEST_LIMIT_GDTR); + TEST_GUEST_VMCS_FIELD_RESERVED_BITS(16, 31, 4, GUEST_LIMIT_GDTR, + "GUEST_LIMIT_GDTR", guest_desc_limit_saved, "GUEST_LIMIT_GDTR", + true); + vmcs_write(GUEST_LIMIT_GDTR, guest_desc_limit_saved); + guest_desc_limit_saved = vmcs_read(GUEST_LIMIT_IDTR); + TEST_GUEST_VMCS_FIELD_RESERVED_BITS(16, 31, 4, GUEST_LIMIT_IDTR, + "GUEST_LIMIT_IDTR", guest_desc_limit_saved, "GUEST_LIMIT_IDTR", + true); + vmcs_write(GUEST_LIMIT_IDTR, guest_desc_limit_saved); + /* * Let the guest finish execution */