From patchwork Thu Jun 22 19:12:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 9805163 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 72B41600C5 for ; Thu, 22 Jun 2017 19:15:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61384286F4 for ; Thu, 22 Jun 2017 19:15:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5431E286F6; Thu, 22 Jun 2017 19:15:24 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C40DB286F4 for ; Thu, 22 Jun 2017 19:15:23 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dO7XD-0007nD-Lt; Thu, 22 Jun 2017 19:12:55 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dO7XB-0007n7-TR for xen-devel@lists.xen.org; Thu, 22 Jun 2017 19:12:53 +0000 Received: from [193.109.254.147] by server-10.bemta-6.messagelabs.com id D3/E7-03613-5B61C495; Thu, 22 Jun 2017 19:12:53 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmkeJIrShJLcpLzFFi42JxWrrBXneLmE+ kwcq1ehZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa0bD/X1sBZvFK36c6GdvYLwm1MXIySEh4C9x 49UrFhCbTUBfYveLT0wgtoiAusTpjousXYwcHMwCfhKHHviChIUFEiRm3HwJVs4ioCpxrvMNM 4jNK+AhsfXeQSaIkXIS54//BItzCthLvPlzCswWErCTWHDoLRuErSZxrf8SO0SvoMTJmU/AZj ILSEgcfPGCeQIj7ywkqVlIUgsYmVYxqhenFpWlFuka6iUVZaZnlOQmZuboGhqY6eWmFhcnpqf mJCYV6yXn525iBAYOAxDsYNz53OkQoyQHk5Io7+Zi70ghvqT8lMqMxOKM+KLSnNTiQ4wyHBxK Erz/RXwihQSLUtNTK9Iyc4AhDJOW4OBREuH9wgeU5i0uSMwtzkyHSJ1iVJQS55UUBUoIgCQyS vPg2mBxc4lRVkqYlxHoECGegtSi3MwSVPlXjOIcjErCvEbAKBTiycwrgZv+CmgxE9DiF0c8QB aXJCKkpBoYtSz3bn5ltDlqSze70+fVh55cYgv+/bZ6xXfbHjfu+uK14andj982e/UIzv94xd2 qrzhpybpdwTylPdHd1hFBYpbv226fElaZGbVn6sf2U2LxE3paU6PldmZ/ab14f/cn5jT2J3Hr RD++WR2Yd2nNk6vbqkRrH3qXHZBi+rEo5NWpVzddt3CoKLEUZyQaajEXFScCACKk3VGWAgAA X-Env-Sender: prvs=339760969=Andrew.Cooper3@citrix.com X-Msg-Ref: server-15.tower-27.messagelabs.com!1498158771!56179416!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 59282 invoked from network); 22 Jun 2017 19:12:52 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-15.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 22 Jun 2017 19:12:52 -0000 X-IronPort-AV: E=Sophos;i="5.39,374,1493683200"; d="scan'208";a="437539667" From: Andrew Cooper To: Xen-devel Date: Thu, 22 Jun 2017 20:12:47 +0100 Message-ID: <1498158767-4923-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <593AABBC02000078001614E1@prv-mh.provo.novell.com> References: <593AABBC02000078001614E1@prv-mh.provo.novell.com> MIME-Version: 1.0 Cc: Andrew Cooper , Jan Beulich Subject: [Xen-devel] [PATCH for-4.8] x86/pv: Fix the handling of `int $x` for vectors which alias exceptions X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP The claim at the top of c/s 2e426d6eecf "x86/traps: Drop use_error_code parameter from do_{,guest_}trap()" is only actually true for hardware exceptions. It is not true for `int $x` instructions (which never push error code), irrespective of whether the vector aliases an exception or not. Furthermore, c/s 6480cc6280e "x86/traps: Fix failed ASSERT() in do_guest_trap()" really should have helped highlight that a regression had been introduced. Modify pv_inject_event() to understand event types other than X86_EVENTTYPE_HW_EXCEPTION, and introduce pv_inject_sw_interrupt() for the `int $x` handling code. Add further assertions to pv_inject_event() concerning the type of events passed in, which in turn requires that do_guest_trap() set its type appropriately (which is now used exclusively for hardware exceptions). This is logically a backport of c/s 5c4f579e0ee4f38cad5636bbf8ce700a394338d0 from Xen 4.9, but disentangled from the other injection work. Signed-off-by: Andrew Cooper --- CC: Jan Beulich --- xen/arch/x86/traps.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 19ac652..8c992ce 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -625,14 +625,24 @@ void fatal_trap(const struct cpu_user_regs *regs, bool_t show_remote) (regs->eflags & X86_EFLAGS_IF) ? "" : ", IN INTERRUPT CONTEXT"); } -static void do_guest_trap(unsigned int trapnr, - const struct cpu_user_regs *regs) +static void pv_inject_event( + unsigned int trapnr, const struct cpu_user_regs *regs, unsigned int type) { struct vcpu *v = current; struct trap_bounce *tb; const struct trap_info *ti; - const bool use_error_code = - ((trapnr < 32) && (TRAP_HAVE_EC & (1u << trapnr))); + bool use_error_code; + + if ( type == X86_EVENTTYPE_HW_EXCEPTION ) + { + ASSERT(trapnr < 32); + use_error_code = TRAP_HAVE_EC & (1u << trapnr); + } + else + { + ASSERT(type == X86_EVENTTYPE_SW_INTERRUPT); + use_error_code = false; + } trace_pv_trap(trapnr, regs->eip, use_error_code, regs->error_code); @@ -658,6 +668,12 @@ static void do_guest_trap(unsigned int trapnr, trapstr(trapnr), trapnr, regs->error_code); } +static void do_guest_trap( + unsigned int trapnr, const struct cpu_user_regs *regs) +{ + pv_inject_event(trapnr, regs, X86_EVENTTYPE_HW_EXCEPTION); +} + static void instruction_done( struct cpu_user_regs *regs, unsigned long eip, unsigned int bpmatch) { @@ -3685,7 +3701,7 @@ void do_general_protection(struct cpu_user_regs *regs) if ( permit_softint(TI_GET_DPL(ti), v, regs) ) { regs->eip += 2; - do_guest_trap(vector, regs); + pv_inject_event(vector, regs, X86_EVENTTYPE_SW_INTERRUPT); return; } }