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),