From patchwork Tue Sep 4 09:37:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 10586999 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 34362920 for ; Tue, 4 Sep 2018 09:38:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2579D28CBC for ; Tue, 4 Sep 2018 09:38:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17E3828D66; Tue, 4 Sep 2018 09:38:12 +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 A554C28CBC for ; Tue, 4 Sep 2018 09:38:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726951AbeIDOC2 (ORCPT ); Tue, 4 Sep 2018 10:02:28 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:50516 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726247AbeIDOC1 (ORCPT ); Tue, 4 Sep 2018 10:02:27 -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 w849SYLl033262; Tue, 4 Sep 2018 09:38: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; s=corp-2018-07-02; bh=5AE4DFOLoN9G11OiUeaa6WIuDPc8EZdH+O50DiFlA84=; b=AaXTvmxi45g0gxPBaGwkYXtMAqr3vDwacHY0sv/gM2DAht9zSR4UVXg5/kgmecxmETM2 /CBZtbyW+315jQa/FGr/JDZxnRQqC6MoC+X1wk9YEk1lDxX8+IhOFpGzCV48EvB+VpL+ 8v9fynfIGDy3jyLsDmkRwZLszLV8saT1FPhABH+88DtbsZQw0tIIj82wfYEuStP99DrJ bJ8awS/pZwR2PsfRnQVbqzPFKBaWeRuO5A+cgVCugY/d9Zfop0j+9pLegAifk17ViBUV DxUiz+hpT2E5nh2uaJthSAdnZyWZhDNbXIMThwwmSKoQgVge2GlCzX59M/eyxao1Ehgv 8w== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2120.oracle.com with ESMTP id 2m7jqpc1mt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 04 Sep 2018 09:38:06 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w849c0xs010384 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 4 Sep 2018 09:38:00 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w849c0Qr027489; Tue, 4 Sep 2018 09:38:00 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 04 Sep 2018 09:38:00 +0000 From: Liran Alon To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: idan.brown@oracle.com, sean.j.christopherson@intel.com, Liran Alon Subject: [kvm-unit-tests PATCH 1/2] x86: VMX: Verify do not lose pending interrupt queued before entering guest Date: Tue, 4 Sep 2018 12:37:30 +0300 Message-Id: <20180904093731.28473-2-liran.alon@oracle.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180904093731.28473-1-liran.alon@oracle.com> References: <20180904093731.28473-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=995 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809040100 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch test the issue fixed by KVM commit "KVM: nVMX: Fix loss of pending event before entering L2". The test aim to verify that a pending interrupt while interrupts are disabled is dispatched when we enter into VMX guest instead of being lost. The test configures VMCS to intercept external-interrupts and then queue an interrupt by disabling interrupts and issue a self-IPI. At this point, we enter guest and we expect CPU to immediately exit guest on external-interrupt. To complete the test, we then re-enable interrupts, verify interrupt is dispatched and re-enter guest to verify it completes execution. Reviewed-by: Nikita Leshchenko Reviewed-by: Darren Kenny Signed-off-by: Liran Alon --- x86/unittests.cfg | 6 ++++++ x86/vmx_tests.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/x86/unittests.cfg b/x86/unittests.cfg index 9d3931921440..8d1c7db1cf6f 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -554,6 +554,12 @@ extra_params = -cpu host,+vmx -m 2560 -append vmx_cr_load_test arch = x86_64 groups = vmx +[vmx_pending_event_test] +file = vmx.flat +extra_params = -cpu host,+vmx -m 2560 -append vmx_pending_event_test +arch = x86_64 +groups = vmx + [vmx_eoi_bitmap_ioapic_scan] file = vmx.flat smp = 2 diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index 7a41732d058a..21b474db012b 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -4457,6 +4457,53 @@ static void vmx_cr_load_test(void) TEST_ASSERT(!write_cr4_checking(cr4 & ~X86_CR4_PCIDE)); } +bool vmx_pending_event_ipi_fired; +static void vmx_pending_event_ipi_isr(isr_regs_t *regs) +{ + vmx_pending_event_ipi_fired = true; + eoi(); +} + +bool vmx_pending_event_guest_run; +static void vmx_pending_event_guest(void) +{ + vmx_pending_event_guest_run = true; +} + +static void vmx_pending_event_test(void) +{ + int ipi_vector = 0xf1; + + vmx_pending_event_ipi_fired = false; + handle_irq(ipi_vector, vmx_pending_event_ipi_isr); + + vmx_pending_event_guest_run = false; + test_set_guest(vmx_pending_event_guest); + + vmcs_set_bits(PIN_CONTROLS, PIN_EXTINT); + + irq_disable(); + apic_icr_write(APIC_DEST_SELF | APIC_DEST_PHYSICAL | + APIC_DM_FIXED | ipi_vector, + 0); + + enter_guest(); + + assert_exit_reason(VMX_EXTINT); + report("Guest did not run before host received IPI", + !vmx_pending_event_guest_run); + + irq_enable(); + asm volatile ("nop"); + irq_disable(); + report("Got pending interrupt after IRQ enabled", + vmx_pending_event_ipi_fired); + + enter_guest(); + report("Guest finished running when no interrupt", + vmx_pending_event_guest_run); +} + static bool cpu_has_apicv(void) { return ((ctrl_cpu_rev[1].clr & CPU_APIC_REG_VIRT) && @@ -5016,6 +5063,7 @@ struct vmx_test vmx_tests[] = { TEST(vmx_vmcs_shadow_test), /* Regression tests */ TEST(vmx_cr_load_test), + TEST(vmx_pending_event_test), /* EPT access tests. */ TEST(ept_access_test_not_present), TEST(ept_access_test_read_only), From patchwork Tue Sep 4 09:37:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 10587001 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 8FF58180E for ; Tue, 4 Sep 2018 09:38:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82F0728CBC for ; Tue, 4 Sep 2018 09:38:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76D5C28D0E; Tue, 4 Sep 2018 09:38:12 +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 145A528CFF for ; Tue, 4 Sep 2018 09:38:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727142AbeIDOC2 (ORCPT ); Tue, 4 Sep 2018 10:02:28 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:50522 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726223AbeIDOC2 (ORCPT ); Tue, 4 Sep 2018 10:02:28 -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 w849SYLY033268; Tue, 4 Sep 2018 09:38: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; s=corp-2018-07-02; bh=D19ECtIGma6lCmdWf6C9rr1YQsl1Hmnmdvmvz7Wx5bk=; b=GEnnZPqtxvYH3EPCg/KvwZ/DVQXk3JpAd4SXbNRWRPXX+rZG6l8U/9YaTv7ONxsU3iXy vCrI9piU4MePdDLP/RT2rqXWqcVKKYqz74Bnckz+ynxUSlHgi2OxdIeHrA5w4Da07wIw gU9hRyf94kQnVo5nXoGy7f3fKJ2tKwjg5WqKyshvtSUfnIl5Cd9XTwtk/lmYQPXpf4ET OAewtAWhJ5MNyT5to7Rjee0+cSeU/NViFmrHWjF1k2h5w0ZsN/mHZRKFYVD4IXHnuoZZ E2TGstyKQFSt2ODf2tUdkUxvglaqx2KM1Nj+zCMWq/pXF2uBQPiQvqzo+ZlS63GEvXIz Jw== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2m7jqpc1mp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 04 Sep 2018 09:38:05 +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 w849c4Zx010832 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 4 Sep 2018 09:38:05 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w849c41D021553; Tue, 4 Sep 2018 09:38:04 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 04 Sep 2018 09:38:04 +0000 From: Liran Alon To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: idan.brown@oracle.com, sean.j.christopherson@intel.com, Liran Alon Subject: [kvm-unit-tests PATCH 2/2] x86: VMX: Verify do not lose pending interrupt queued before entering halted guest Date: Tue, 4 Sep 2018 12:37:31 +0300 Message-Id: <20180904093731.28473-3-liran.alon@oracle.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180904093731.28473-1-liran.alon@oracle.com> References: <20180904093731.28473-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=873 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809040100 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add test similar to previous patch ("x86: VMX: Verify do not lose pending interrupt queued before entering guest") but when guest is configured with HLT activity-state. Reviewed-by: Nikita Leshchenko Reviewed-by: Darren Kenny Signed-off-by: Liran Alon --- x86/unittests.cfg | 6 ++++++ x86/vmx_tests.c | 23 ++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/x86/unittests.cfg b/x86/unittests.cfg index 8d1c7db1cf6f..0774ddbafa52 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -560,6 +560,12 @@ extra_params = -cpu host,+vmx -m 2560 -append vmx_pending_event_test arch = x86_64 groups = vmx +[vmx_pending_event_hlt_test] +file = vmx.flat +extra_params = -cpu host,+vmx -m 2560 -append vmx_pending_event_hlt_test +arch = x86_64 +groups = vmx + [vmx_eoi_bitmap_ioapic_scan] file = vmx.flat smp = 2 diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index 21b474db012b..e27c8f3a6c9b 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -4467,10 +4467,11 @@ static void vmx_pending_event_ipi_isr(isr_regs_t *regs) bool vmx_pending_event_guest_run; static void vmx_pending_event_guest(void) { + vmcall(); vmx_pending_event_guest_run = true; } -static void vmx_pending_event_test(void) +static void vmx_pending_event_test_core(bool guest_hlt) { int ipi_vector = 0xf1; @@ -4482,6 +4483,12 @@ static void vmx_pending_event_test(void) vmcs_set_bits(PIN_CONTROLS, PIN_EXTINT); + enter_guest(); + skip_exit_vmcall(); + + if (guest_hlt) + vmcs_write(GUEST_ACTV_STATE, ACTV_HLT); + irq_disable(); apic_icr_write(APIC_DEST_SELF | APIC_DEST_PHYSICAL | APIC_DM_FIXED | ipi_vector, @@ -4499,11 +4506,24 @@ static void vmx_pending_event_test(void) report("Got pending interrupt after IRQ enabled", vmx_pending_event_ipi_fired); + if (guest_hlt) + vmcs_write(GUEST_ACTV_STATE, ACTV_ACTIVE); + enter_guest(); report("Guest finished running when no interrupt", vmx_pending_event_guest_run); } +static void vmx_pending_event_test(void) +{ + vmx_pending_event_test_core(false); +} + +static void vmx_pending_event_hlt_test(void) +{ + vmx_pending_event_test_core(true); +} + static bool cpu_has_apicv(void) { return ((ctrl_cpu_rev[1].clr & CPU_APIC_REG_VIRT) && @@ -5064,6 +5084,7 @@ struct vmx_test vmx_tests[] = { /* Regression tests */ TEST(vmx_cr_load_test), TEST(vmx_pending_event_test), + TEST(vmx_pending_event_hlt_test), /* EPT access tests. */ TEST(ept_access_test_not_present), TEST(ept_access_test_read_only),