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