From patchwork Tue Nov 7 08:09:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Leshenko X-Patchwork-Id: 10045837 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 673A86032D for ; Tue, 7 Nov 2017 08:10:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 546AD29033 for ; Tue, 7 Nov 2017 08:10:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 42F8B29C6C; Tue, 7 Nov 2017 08:10:21 +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=-6.9 required=2.0 tests=BAYES_00, 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 ADB1029033 for ; Tue, 7 Nov 2017 08:10:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932512AbdKGIKS (ORCPT ); Tue, 7 Nov 2017 03:10:18 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:51813 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932418AbdKGIKR (ORCPT ); Tue, 7 Nov 2017 03:10:17 -0500 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id vA78AEw0019276 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 7 Nov 2017 08:10:15 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id vA78AExU014879 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 7 Nov 2017 08:10:14 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id vA78ADN4012183; Tue, 7 Nov 2017 08:10:13 GMT Received: from nexus.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 07 Nov 2017 00:10:12 -0800 From: Nikita Leshenko To: kvm@vger.kernel.org, pbonzini@redhat.com, rkrcmar@redhat.com Cc: idan.brown@oracle.com, Nikita Leshenko , Konrad Rzeszutek Wilk Subject: [PATCH kvm-unit-tests] x86: ioapic: Test self-reconfiguration from interrupt handler Date: Tue, 7 Nov 2017 10:09:33 +0200 Message-Id: <20171107080933.20924-1-nikita.leshchenko@oracle.com> X-Mailer: git-send-email 2.13.3 X-Source-IP: userv0022.oracle.com [156.151.31.74] Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make sure that we can reconfigure the destination of an irq from the interrupt handler. Make sure that the EOI is correctly delivered to the IOAPIC and that remote_irr is reset to 0. This tests the fix introduced by commit "KVM: x86: ioapic: Fix level-triggered EOI and IOAPIC reconfigure race". Signed-off-by: Nikita Leshenko Reviewed-by: Liran Alon Signed-off-by: Konrad Rzeszutek Wilk --- x86/ioapic.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/x86/ioapic.c b/x86/ioapic.c index e5cc259..849add4 100644 --- a/x86/ioapic.c +++ b/x86/ioapic.c @@ -391,6 +391,43 @@ static void test_ioapic_level_retrigger_mask(void) set_mask(0x0e, false); } +static volatile int g_isr_84; + +static void ioapic_isr_84(isr_regs_t *regs) +{ + int line = 0xe; + ioapic_redir_entry_t e; + + ++g_isr_84; + set_irq_line(line, 0); + + e = ioapic_read_redir(line); + e.dest_id = 1; + + // Update only upper part of the register because we only change the + // destination, which resides in the upper part + ioapic_write_reg(0x10 + line * 2 + 1, ((u32 *)&e)[1]); + + eoi(); +} + +static void test_ioapic_self_reconfigure(void) +{ + ioapic_redir_entry_t e = { + .vector = 0x84, + .delivery_mode = 0, + .dest_mode = 0, + .dest_id = 0, + .trig_mode = TRIGGER_LEVEL, + }; + + handle_irq(0x84, ioapic_isr_84); + ioapic_write_redir(0xe, e); + set_irq_line(0x0e, 1); + e = ioapic_read_redir(0xe); + report("Reconfigure self", g_isr_84 == 1 && e.remote_irr == 0); +} + int main(void) { @@ -432,6 +469,8 @@ int main(void) test_ioapic_level_tmr_smp(false); test_ioapic_level_tmr_smp(true); test_ioapic_edge_tmr_smp(true); + + test_ioapic_self_reconfigure(); } return report_summary();