From patchwork Wed Mar 21 23:23:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 10300653 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7D3E160385 for ; Wed, 21 Mar 2018 23:24:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D6FB290CC for ; Wed, 21 Mar 2018 23:24:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6169629908; Wed, 21 Mar 2018 23:24:25 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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 EE4B6290CC for ; Wed, 21 Mar 2018 23:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754253AbeCUXYW (ORCPT ); Wed, 21 Mar 2018 19:24:22 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:49232 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754050AbeCUXYQ (ORCPT ); Wed, 21 Mar 2018 19:24:16 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w2LNDPoR048296; Wed, 21 Mar 2018 23:24:14 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-2017-10-26; bh=+vKcTgB3M15T9dYBzgvchk01zKSy8QydC251mGOBJhk=; b=bM73N4kssMZHTte3KYzBCdBeL7MRj7AkKcPl0dR4Tc2YHjX6wBMXYjO97/qo5zLnvU/P HFHy0pbPesFt9qnRhSj3/P2XEaDXufjtMPeMtcq6s7lOO6qVYnauuUorJpyglutN+tkf I0hxF1bFE6nsTZA2CiEl437Nwg6AixvhjJcwJqJSscLTH4G0aQUMbTbEAVlpxBHIUubv 2GZYmC3Sf+D6FnZB8q/bJytnBMZ0L4fpRBy5HHh8PgX51IOdJZu6d44UI8PQif0yKIpo H+pgvur9PdczKOIp0cUkKyz2DtF/47VxbrN6oBrQv6BgVomzHuYRaXB8jhGaX0BlqseV yg== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2gv0vdr0vp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Mar 2018 23:24:13 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w2LNODmT005393 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Mar 2018 23:24:13 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w2LNOCqi012490; Wed, 21 Mar 2018 23:24:12 GMT Received: from liran-pc.Home (/109.66.44.151) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 21 Mar 2018 16:24:12 -0700 From: Liran Alon To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: idan.brown@oracle.com, Elazar Leibovich , Liran Alon , Krish Sadhukhan Subject: [PATCH 6/7] x86: nVMX: Verify pass-through LAPIC & IO-APIC to guest Date: Thu, 22 Mar 2018 01:23:13 +0200 Message-Id: <1521674594-12085-7-git-send-email-liran.alon@oracle.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1521674594-12085-1-git-send-email-liran.alon@oracle.com> References: <1521674594-12085-1-git-send-email-liran.alon@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8839 signatures=668695 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=619 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1803200127 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Elazar Leibovich Test configures VMCS to run guest with LAPIC & IO-APIC pass-through: * MSR-bitmap is empty (no intercept on access to x2APIC MSRs). * No exit on external-interrupts * No tpr-shadow, virtualize-apic-access and virtualize-x2apic-mode. To verify pass-through works correctly, guest asserts irq-line to trigger a level-triggered interrupt that should be injected directly to guest. In guest interrupt-handler, a vmcall will verify remote_irr=1 before EOI. Then, guest issues EOI and another vmcall to verify remote_irr was cleared. Signed-off-by: Elazar Leibovich Co-authored-by: Liran Alon Signed-off-by: Liran Alon Signed-off-by: Krish Sadhukhan --- x86/unittests.cfg | 7 +++++++ x86/vmx_tests.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/x86/unittests.cfg b/x86/unittests.cfg index 639e487cd777..b6ad1b57e34e 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -551,6 +551,13 @@ extra_params = -cpu host,+vmx -m 2048 -append vmx_eoi_bitmap_ioapic_scan_test arch = x86_64 groups = vmx +[vmx_apic_passthrough] +file = vmx.flat +smp = 2 +extra_params = -cpu host,+vmx -m 2048 -append vmx_apic_passthrough_test +arch = x86_64 +groups = vmx + [debug] file = debug.flat arch = x86_64 diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index 0bf081846533..fe48981ead50 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -4018,6 +4018,57 @@ static void vmx_eoi_bitmap_ioapic_scan_test(void) report(__func__, 1); } +static void irq_78_handler_guest(isr_regs_t *regs) +{ + set_irq_line(0xf, 0); + vmcall(); + eoi(); + vmcall(); +} + +static void vmx_apic_passthrough_guest(void) +{ + handle_irq(0x78, irq_78_handler_guest); + irq_enable(); + + set_irq_line(0xf, 1); +} + +static void vmx_apic_passthrough_test(void) +{ + void *msr_bitmap = alloc_page(); + + u64 cpu_ctrl_0 = CPU_SECONDARY | CPU_MSR_BITMAP; + u64 cpu_ctrl_1 = 0; + + memset(msr_bitmap, 0x0, PAGE_SIZE); + vmcs_write(MSR_BITMAP, (u64)msr_bitmap); + + vmcs_write(PIN_CONTROLS, vmcs_read(PIN_CONTROLS) & ~PIN_EXTINT); + + 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); + + ioapic_set_redir(0xf, 0x78, TRIGGER_LEVEL); + test_set_guest(vmx_apic_passthrough_guest); + + /* Before EOI remote_irr should still be set */ + enter_guest(); + skip_exit_vmcall(); + TEST_ASSERT_EQ_MSG(1, (int)ioapic_read_redir(0xf).remote_irr, + "IOAPIC pass-through: remote_irr=1 before EOI"); + + /* After EOI remote_irr should be cleared */ + enter_guest(); + skip_exit_vmcall(); + TEST_ASSERT_EQ_MSG(0, (int)ioapic_read_redir(0xf).remote_irr, + "IOAPIC pass-through: remote_irr=0 after EOI"); + + /* Let L2 finish */ + enter_guest(); + report(__func__, 1); +} + #define TEST(name) { #name, .v2 = name } /* name/init/guest_main/exit_handler/syscall_handler/guest_regs */ @@ -4086,6 +4137,8 @@ struct vmx_test vmx_tests[] = { TEST(vmentry_movss_shadow_test), /* APICv tests */ TEST(vmx_eoi_bitmap_ioapic_scan_test), + /* APIC pass-through tests */ + TEST(vmx_apic_passthrough_test), /* Regression tests */ TEST(vmx_cr_load_test), { NULL, NULL, NULL, NULL, NULL, {0} },