From patchwork Tue Sep 4 10:21:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 10587035 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 290721669 for ; Tue, 4 Sep 2018 10:22:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F5C429168 for ; Tue, 4 Sep 2018 10:22:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0383629170; Tue, 4 Sep 2018 10:22:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9AC9229168 for ; Tue, 4 Sep 2018 10:22:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726344AbeIDOrA (ORCPT ); Tue, 4 Sep 2018 10:47:00 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:56960 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726335AbeIDOrA (ORCPT ); Tue, 4 Sep 2018 10:47:00 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w84AIt60077793; Tue, 4 Sep 2018 10:22:30 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; s=corp-2018-07-02; bh=MID+rgah8ZOm6mf0uyPlxWkjPYCKqv/QrZnTzi3Av60=; b=td0acnpyNnBD2zw0MSoP3nDZJnbDyrFfo4LGIRQGMZuIEe60Twh/TBzl4Aq5J+WoECLw z7FxtyfhzmyXzo6GWvWKJ9Z38r5nXx/gn+wH4YqNysdKB9/Q9Y147zE8ZAiaFK6ICukt x5LjOVLy2FQGOLQE4Z6xmYZJzWQXANBpDNXiG8AmbmgluUTzgveOqEH2f/4yfXkFVY5Z V+3/KyCK+Rah4N2g+XzeD6PUtUr1sDh50SQpEljRY+bsP78+BTyKuRTrk0k7EGzER08G +5+DYue3tisantey7mPiS2pVXWI9iTadf/A2+Sc0oZC3Go7EcOrn3y3/tY/KkZPLzW1q Kw== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2m7jqpc9jf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 04 Sep 2018 10:22:30 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w84AMTri007754 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 4 Sep 2018 10:22:29 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w84AMTEd015082; Tue, 4 Sep 2018 10:22:29 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 04 Sep 2018 03:22:28 -0700 From: Liran Alon To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: idan.brown@oracle.com, Liran Alon Subject: [kvm-unit-tests PATCH 1/3] x86: VMX: Introduce util to disable intercept on x2APIC MSRs Date: Tue, 4 Sep 2018 13:21:56 +0300 Message-Id: <20180904102158.120866-2-liran.alon@oracle.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180904102158.120866-1-liran.alon@oracle.com> References: <20180904102158.120866-1-liran.alon@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9005 signatures=668708 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=818 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809040109 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Reviewed-by: Nikita Leshenko Reviewed-by: Darren Kenny Signed-off-by: Liran Alon --- x86/vmx_tests.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index 5d2e390ade88..4b8cc814e576 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -255,6 +255,37 @@ static void msr_bmp_init(void) vmcs_write(MSR_BITMAP, (u64)msr_bitmap); } +static void *get_msr_bitmap(void) +{ + void *msr_bitmap; + + if (vmcs_read(CPU_EXEC_CTRL0) & CPU_MSR_BITMAP) { + msr_bitmap = (void *)vmcs_read(MSR_BITMAP); + } else { + msr_bitmap = alloc_page(); + memset(msr_bitmap, 0xff, PAGE_SIZE); + vmcs_write(MSR_BITMAP, (u64)msr_bitmap); + vmcs_set_bits(CPU_EXEC_CTRL0, CPU_MSR_BITMAP); + } + + return msr_bitmap; +} + +static void disable_intercept_for_x2apic_msrs(void) +{ + unsigned long *msr_bitmap = (unsigned long *)get_msr_bitmap(); + u32 msr; + + for (msr = APIC_BASE_MSR; + msr < (APIC_BASE_MSR+0xff); + msr += BITS_PER_LONG) { + unsigned int word = msr / BITS_PER_LONG; + + msr_bitmap[word] = 0; + msr_bitmap[word + (0x800 / sizeof(long))] = 0; + } +} + static int test_ctrl_pat_init(struct vmcs *vmcs) { u64 ctrl_ent; @@ -4606,7 +4637,6 @@ static void vmx_eoi_bitmap_ioapic_scan_test_guest(void) static void vmx_eoi_bitmap_ioapic_scan_test(void) { - void *msr_bitmap; void *virtual_apic_page; if (!cpu_has_apicv() || (cpu_count() < 2)) { @@ -4614,15 +4644,12 @@ static void vmx_eoi_bitmap_ioapic_scan_test(void) return; } - msr_bitmap = alloc_page(); - virtual_apic_page = alloc_page(); - - u64 cpu_ctrl_0 = CPU_SECONDARY | CPU_TPR_SHADOW | CPU_MSR_BITMAP; + u64 cpu_ctrl_0 = CPU_SECONDARY | CPU_TPR_SHADOW; u64 cpu_ctrl_1 = CPU_VINTD | CPU_VIRT_X2APIC; - memset(msr_bitmap, 0x0, PAGE_SIZE); - vmcs_write(MSR_BITMAP, (u64)msr_bitmap); + disable_intercept_for_x2apic_msrs(); + virtual_apic_page = alloc_page(); vmcs_write(APIC_VIRT_ADDR, (u64)virtual_apic_page); vmcs_write(PIN_CONTROLS, vmcs_read(PIN_CONTROLS) | PIN_EXTINT); @@ -4689,20 +4716,15 @@ static void vmx_apic_passthrough_guest(void) static void vmx_apic_passthrough(bool set_irq_line_from_thread) { - void *msr_bitmap; - if (set_irq_line_from_thread && (cpu_count() < 2)) { report_skip(__func__); return; } - msr_bitmap = alloc_page(); - - u64 cpu_ctrl_0 = CPU_SECONDARY | CPU_MSR_BITMAP; + u64 cpu_ctrl_0 = CPU_SECONDARY; u64 cpu_ctrl_1 = 0; - memset(msr_bitmap, 0x0, PAGE_SIZE); - vmcs_write(MSR_BITMAP, (u64)msr_bitmap); + disable_intercept_for_x2apic_msrs(); vmcs_write(PIN_CONTROLS, vmcs_read(PIN_CONTROLS) & ~PIN_EXTINT); From patchwork Tue Sep 4 10:21:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 10587037 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B6D814E0 for ; Tue, 4 Sep 2018 10:22:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41AC629168 for ; Tue, 4 Sep 2018 10:22:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 363EF29170; Tue, 4 Sep 2018 10:22:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1E3F29168 for ; Tue, 4 Sep 2018 10:22:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727075AbeIDOrE (ORCPT ); Tue, 4 Sep 2018 10:47:04 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:43346 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726335AbeIDOrD (ORCPT ); Tue, 4 Sep 2018 10:47:03 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w84AIvjS027836; Tue, 4 Sep 2018 10:22:33 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; s=corp-2018-07-02; bh=u+M0dNKs4FjZxVId1bA1xnNFEeiz2MsEJPOtGFyX4+0=; b=D/4rZ/xUeP6Ra8foYYeg12veEGBHRt94WwQEeX4AU6WP54gwAQIoear382yRdBBJIpPD 48oammZLVRhMU047XZpAOi6uDv1qJ2jKpwl9PzfDVltqTRGAYRG+NOs3PNstfldyhst7 12XcaTt/8PSC3MVEnwEr9KWcWMLJBoCEUY6X+aMK60Lvjhfww5xCLO/p+huHGXVvWf/f lSd5MgsQxQX6s4th2FCWEC/wecNI5w37KYLuSTanCdCYtnDhFOyzCAx/MW/J43RsxGzT YmVhBtNKAUogL6EZWsHhhxlgRVMRFOmWn1W4Wm27WRaaja4tgn3bjO7C71Yl06xrd7pM 3g== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2m7kdqc5q6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 04 Sep 2018 10:22:33 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w84AMWDr005777 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 4 Sep 2018 10:22:32 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w84AMWW1030931; Tue, 4 Sep 2018 10:22:32 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 04 Sep 2018 03:22:32 -0700 From: Liran Alon To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: idan.brown@oracle.com, Liran Alon Subject: [kvm-unit-tests PATCH 2/3] x86: VMX: Introduce util to enable virtual interrupt delivery Date: Tue, 4 Sep 2018 13:21:57 +0300 Message-Id: <20180904102158.120866-3-liran.alon@oracle.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180904102158.120866-1-liran.alon@oracle.com> References: <20180904102158.120866-1-liran.alon@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9005 signatures=668708 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=840 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809040109 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Should not change semantics. Reviewed-by: Nikita Leshenko Reviewed-by: Darren Kenny Signed-off-by: Liran Alon --- x86/vmx_tests.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index 4b8cc814e576..835ae1e1e8b4 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -4589,6 +4589,28 @@ static bool cpu_has_apicv(void) (ctrl_pin_rev.clr & PIN_POST_INTR)); } +static void enable_vid(void) +{ + void *virtual_apic_page; + + assert(cpu_has_apicv()); + + disable_intercept_for_x2apic_msrs(); + + virtual_apic_page = alloc_page(); + vmcs_write(APIC_VIRT_ADDR, (u64)virtual_apic_page); + + vmcs_set_bits(PIN_CONTROLS, PIN_EXTINT); + + vmcs_write(EOI_EXIT_BITMAP0, 0x0); + vmcs_write(EOI_EXIT_BITMAP1, 0x0); + vmcs_write(EOI_EXIT_BITMAP2, 0x0); + vmcs_write(EOI_EXIT_BITMAP3, 0x0); + + vmcs_set_bits(CPU_EXEC_CTRL0, CPU_SECONDARY | CPU_TPR_SHADOW); + vmcs_set_bits(CPU_EXEC_CTRL1, CPU_VINTD | CPU_VIRT_X2APIC); +} + static void trigger_ioapic_scan_thread(void *data) { /* Wait until other CPU entered L2 */ @@ -4637,29 +4659,12 @@ static void vmx_eoi_bitmap_ioapic_scan_test_guest(void) static void vmx_eoi_bitmap_ioapic_scan_test(void) { - void *virtual_apic_page; - if (!cpu_has_apicv() || (cpu_count() < 2)) { report_skip(__func__); return; } - u64 cpu_ctrl_0 = CPU_SECONDARY | CPU_TPR_SHADOW; - u64 cpu_ctrl_1 = CPU_VINTD | CPU_VIRT_X2APIC; - - disable_intercept_for_x2apic_msrs(); - - virtual_apic_page = alloc_page(); - vmcs_write(APIC_VIRT_ADDR, (u64)virtual_apic_page); - vmcs_write(PIN_CONTROLS, vmcs_read(PIN_CONTROLS) | PIN_EXTINT); - - vmcs_write(EOI_EXIT_BITMAP0, 0x0); - vmcs_write(EOI_EXIT_BITMAP1, 0x0); - vmcs_write(EOI_EXIT_BITMAP2, 0x0); - vmcs_write(EOI_EXIT_BITMAP3, 0x0); - - vmcs_write(CPU_EXEC_CTRL0, vmcs_read(CPU_EXEC_CTRL0) | cpu_ctrl_0); - vmcs_write(CPU_EXEC_CTRL1, vmcs_read(CPU_EXEC_CTRL1) | cpu_ctrl_1); + enable_vid(); on_cpu_async(1, trigger_ioapic_scan_thread, NULL); test_set_guest(vmx_eoi_bitmap_ioapic_scan_test_guest); From patchwork Tue Sep 4 10:21:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 10587039 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D456C1669 for ; Tue, 4 Sep 2018 10:22:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB0BC29168 for ; Tue, 4 Sep 2018 10:22:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEF2D29170; Tue, 4 Sep 2018 10:22:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A53329168 for ; Tue, 4 Sep 2018 10:22:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727035AbeIDOrG (ORCPT ); Tue, 4 Sep 2018 10:47:06 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:43372 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726956AbeIDOrG (ORCPT ); Tue, 4 Sep 2018 10:47:06 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w84AIsjN027808; Tue, 4 Sep 2018 10:22:36 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; s=corp-2018-07-02; bh=83VI2d0IcOeFpdMCCTFbNf5oPT4yQsZ8HeO0TkQoJfA=; b=s4ghde6Y6xxQjuVWMs+VyjwRpBNVo//T7Mr2WE0otph4bulfH/IrnrVs81QpWb3rCUUc AEvl1ekNJqf99wcU2vA7lMP29whGXUJfXE41vV2tU6s7TDwtpmpUOeX92TbU+ah0UhNG 1ERqsjFiHw4WKCIPd+xj91Zc0zEL6e4PcMlm9tspAODMSwIHPOO0vYtOCFKw3wNVYIM/ cNv9MaIHruCEh+gNub89M9Rl5tDbvgLNUbW3oyHZyRRTje1GWiB1dSh6KH0Gz4K5YcjH g0RiOEXSCXVuWcpF+k9y+nLU0GPHwA/cbG+U0X2062Kzbt8fTm9Jho9Ksu6br08QHWWX Hw== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2m7kdqc5qf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 04 Sep 2018 10:22:36 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w84AMa3F007970 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 4 Sep 2018 10:22:36 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w84AMZob027318; Tue, 4 Sep 2018 10:22:35 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 04 Sep 2018 03:22:35 -0700 From: Liran Alon To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: idan.brown@oracle.com, Liran Alon Subject: [kvm-unit-tests PATCH 3/3] x86: VMX: Verify blocked vCPU in guest-mode wake when pending interrupt in RVI Date: Tue, 4 Sep 2018 13:21:58 +0300 Message-Id: <20180904102158.120866-4-liran.alon@oracle.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180904102158.120866-1-liran.alon@oracle.com> References: <20180904102158.120866-1-liran.alon@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9005 signatures=668708 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-1807170000 definitions=main-1809040109 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This test aims to verify that when entering a guest in HLT activity state but with a pending interrupt in RVI, the guest is in fact not halted and an interrupt is indeed injected. For more information, see commit message of kernel patch "KVM: nVMX: Wake blocked vCPU in guest-mode if pending interrupt in virtual APICv". Reviewed-by: Nikita Leshenko Reviewed-by: Darren Kenny Signed-off-by: Liran Alon --- x86/unittests.cfg | 7 +++++++ x86/vmx_tests.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/x86/unittests.cfg b/x86/unittests.cfg index 17733154eeec..40a8423d997f 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -579,6 +579,13 @@ extra_params = -cpu host,+vmx -m 2048 -append vmx_eoi_bitmap_ioapic_scan_test arch = x86_64 groups = vmx +[vmx_hlt_with_rvi_test] +file = vmx.flat +extra_params = -cpu host,+vmx -m 2048 -append vmx_hlt_with_rvi_test +arch = x86_64 +groups = vmx +timeout = 10 + [vmx_apic_passthrough] file = vmx.flat smp = 2 diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index 835ae1e1e8b4..9296a8a7143a 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -4683,6 +4683,47 @@ static void vmx_eoi_bitmap_ioapic_scan_test(void) report(__func__, 1); } +#define HLT_WITH_RVI_VECTOR (0xf1) + +bool vmx_hlt_with_rvi_guest_isr_fired; +static void vmx_hlt_with_rvi_guest_isr(isr_regs_t *regs) +{ + vmx_hlt_with_rvi_guest_isr_fired = true; + eoi(); +} + +static void vmx_hlt_with_rvi_guest(void) +{ + handle_irq(HLT_WITH_RVI_VECTOR, vmx_hlt_with_rvi_guest_isr); + + irq_enable(); + asm volatile ("nop"); + + vmcall(); +} + +static void vmx_hlt_with_rvi_test(void) +{ + if (!cpu_has_apicv()) { + report_skip(__func__); + return; + } + + enable_vid(); + + vmx_hlt_with_rvi_guest_isr_fired = false; + test_set_guest(vmx_hlt_with_rvi_guest); + + enter_guest(); + skip_exit_vmcall(); + + vmcs_write(GUEST_ACTV_STATE, ACTV_HLT); + vmcs_write(GUEST_INT_STATUS, HLT_WITH_RVI_VECTOR); + enter_guest(); + + report("Interrupt raised in guest", vmx_hlt_with_rvi_guest_isr_fired); +} + static void set_irq_line_thread(void *data) { /* Wait until other CPU entered L2 */ @@ -5130,6 +5171,7 @@ struct vmx_test vmx_tests[] = { TEST(vmentry_movss_shadow_test), /* APICv tests */ TEST(vmx_eoi_bitmap_ioapic_scan_test), + TEST(vmx_hlt_with_rvi_test), /* APIC pass-through tests */ TEST(vmx_apic_passthrough_test), TEST(vmx_apic_passthrough_thread_test),