From nobody Mon Feb 9 12:15:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1590607184; cv=none; d=zohomail.com; s=zohoarc; b=TBLXtqUv9Zyqy+w1r8lCm1+kCkqyj3Oi000vvfOUzF5nQ0Ng4WY15pkaypO4XkE7n+JhF7vUMx33fQ3Xb/XfL9xXYljqtTthzL/T8yaZVofNhRZeSRp0c1HRCGjdoO5pLnBCbNI7c+nBbLN3FtWMaU80E96Gz2PFQ7opdVLodSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590607184; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DPx3NV+HBShF3A+SGX7/nGopHPDfzzpUtmuGkSkWtvU=; b=BtQKTJmrujACnMhKJG6gX6a+d6qWZA3UYOY1L0sXRR1dNvN4aw0KF7Sz4hc8FAx0nUTA9prRGH7r+dBOWBwGOoqoUbOrTLCvPs5mblzRKkxviIFwl3jTgemSg+wtnoja2yc6cFG4j9loT0iBYMBWMbqSX3uNORKvWdO7NchWzww= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1590607184334130.30175304933687; Wed, 27 May 2020 12:19:44 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1je1a7-0003zq-FO; Wed, 27 May 2020 19:19:15 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1je1a6-0003zb-5F for xen-devel@lists.xenproject.org; Wed, 27 May 2020 19:19:14 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f27751dc-a04e-11ea-a777-12813bfff9fa; Wed, 27 May 2020 19:19:12 +0000 (UTC) X-Inumbo-ID: f27751dc-a04e-11ea-a777-12813bfff9fa Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: ija9DmiPgoPmZNcL3bjjdKcpLaVY+8guYONj0oMriHZeiKRsozlQ4o9aitlckvP1s6btqJjxh1 a18qRYR3chz2xqEmZi1iYjPkG72SPuWjfXyhVFoGpAviU1XOrbI66ZIQIbfdo4gTDSN5jj9AgB s6lRv7mYcHllksiQ687H74WJMWuU5rfZhBYRoEdw8kjtIZt8gT6+KHdasj18k6r8n/CwzOQovE kl3xiEYvA2VvsgwwvuZvjliwLI/IDNpuSXuy1dJz9R6NEaTju6WmHDxpgad7sSTQhi6ISl/cjt uPA= X-SBRS: 2.7 X-MesageID: 18591103 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.73,442,1583211600"; d="scan'208";a="18591103" From: Andrew Cooper To: Xen-devel Subject: [PATCH v2 02/14] x86/traps: Factor out extable_fixup() and make printing consistent Date: Wed, 27 May 2020 20:18:35 +0100 Message-ID: <20200527191847.17207-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200527191847.17207-1-andrew.cooper3@citrix.com> References: <20200527191847.17207-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" UD faults never had any diagnostics printed, and the others were inconsiste= nt. Don't use dprintk() because identifying traps.c is actively unhelpful in the message, as it is the location of the fixup, not the fault. Use the new vec_name() infrastructure, rather than leaving raw numbers for the log. (XEN) Running stub recovery selftests... (XEN) Fixup #UD[0000]: ffff82d07fffd040 [ffff82d07fffd040] -> ffff82d0403= ac9d6 (XEN) Fixup #GP[0000]: ffff82d07fffd041 [ffff82d07fffd041] -> ffff82d0403= ac9d6 (XEN) Fixup #SS[0000]: ffff82d07fffd040 [ffff82d07fffd040] -> ffff82d0403= ac9d6 (XEN) Fixup #BP[0000]: ffff82d07fffd041 [ffff82d07fffd041] -> ffff82d0403= ac9d6 Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 v2: * Rebase * Rename to extable_fixup() to better distinguish from fixup_page_fault() --- xen/arch/x86/traps.c | 77 ++++++++++++++++++++++++------------------------= ---- 1 file changed, 35 insertions(+), 42 deletions(-) diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 427178e649..eeb3e146ef 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -772,10 +772,31 @@ static void do_reserved_trap(struct cpu_user_regs *re= gs) trapnr, vec_name(trapnr), regs->error_code); } =20 +static bool extable_fixup(struct cpu_user_regs *regs, bool print) +{ + unsigned long fixup =3D search_exception_table(regs); + + if ( unlikely(fixup =3D=3D 0) ) + return false; + + /* + * Don't use dprintk() because the __FILE__ reference is unhelpful. + * Can currently be triggered by guests. Make sure we ratelimit. + */ + if ( IS_ENABLED(CONFIG_DEBUG) && print ) + printk(XENLOG_GUEST XENLOG_WARNING "Fixup %s[%04x]: %p [%ps] -> %p= \n", + vec_name(regs->entry_vector), regs->error_code, + _p(regs->rip), _p(regs->rip), _p(fixup)); + + regs->rip =3D fixup; + this_cpu(last_extable_addr) =3D regs->rip; + + return true; +} + static void do_trap(struct cpu_user_regs *regs) { unsigned int trapnr =3D regs->entry_vector; - unsigned long fixup; =20 if ( regs->error_code & X86_XEC_EXT ) goto hardware_trap; @@ -793,14 +814,8 @@ static void do_trap(struct cpu_user_regs *regs) return; } =20 - if ( likely((fixup =3D search_exception_table(regs)) !=3D 0) ) - { - dprintk(XENLOG_ERR, "Trap %u: %p [%ps] -> %p\n", - trapnr, _p(regs->rip), _p(regs->rip), _p(fixup)); - this_cpu(last_extable_addr) =3D regs->rip; - regs->rip =3D fixup; + if ( likely(extable_fixup(regs, true)) ) return; - } =20 hardware_trap: if ( debugger_trap_fatal(trapnr, regs) ) @@ -1108,12 +1123,8 @@ void do_invalid_op(struct cpu_user_regs *regs) } =20 die: - if ( (fixup =3D search_exception_table(regs)) !=3D 0 ) - { - this_cpu(last_extable_addr) =3D regs->rip; - regs->rip =3D fixup; + if ( likely(extable_fixup(regs, true)) ) return; - } =20 if ( debugger_trap_fatal(TRAP_invalid_op, regs) ) return; @@ -1129,16 +1140,8 @@ void do_int3(struct cpu_user_regs *regs) =20 if ( !guest_mode(regs) ) { - unsigned long fixup; - - if ( (fixup =3D search_exception_table(regs)) !=3D 0 ) - { - this_cpu(last_extable_addr) =3D regs->rip; - dprintk(XENLOG_DEBUG, "Trap %u: %p [%ps] -> %p\n", - TRAP_int3, _p(regs->rip), _p(regs->rip), _p(fixup)); - regs->rip =3D fixup; + if ( likely(extable_fixup(regs, true)) ) return; - } =20 if ( !debugger_trap_fatal(TRAP_int3, regs) ) printk(XENLOG_DEBUG "Hit embedded breakpoint at %p [%ps]\n", @@ -1415,7 +1418,7 @@ static int fixup_page_fault(unsigned long addr, struc= t cpu_user_regs *regs) =20 void do_page_fault(struct cpu_user_regs *regs) { - unsigned long addr, fixup; + unsigned long addr; unsigned int error_code; =20 addr =3D read_cr2(); @@ -1461,11 +1464,9 @@ void do_page_fault(struct cpu_user_regs *regs) if ( pf_type !=3D real_fault ) return; =20 - if ( likely((fixup =3D search_exception_table(regs)) !=3D 0) ) + if ( likely(extable_fixup(regs, false)) ) { perfc_incr(copy_user_faults); - this_cpu(last_extable_addr) =3D regs->rip; - regs->rip =3D fixup; return; } =20 @@ -1521,7 +1522,6 @@ void do_general_protection(struct cpu_user_regs *regs) #ifdef CONFIG_PV struct vcpu *v =3D current; #endif - unsigned long fixup; =20 if ( debugger_trap_entry(TRAP_gp_fault, regs) ) return; @@ -1588,14 +1588,8 @@ void do_general_protection(struct cpu_user_regs *reg= s) =20 gp_in_kernel: =20 - if ( likely((fixup =3D search_exception_table(regs)) !=3D 0) ) - { - dprintk(XENLOG_INFO, "GPF (%04x): %p [%ps] -> %p\n", - regs->error_code, _p(regs->rip), _p(regs->rip), _p(fixup)); - this_cpu(last_extable_addr) =3D regs->rip; - regs->rip =3D fixup; + if ( likely(extable_fixup(regs, true)) ) return; - } =20 hardware_gp: if ( debugger_trap_fatal(TRAP_gp_fault, regs) ) @@ -1754,18 +1748,17 @@ void do_device_not_available(struct cpu_user_regs *= regs) =20 if ( !guest_mode(regs) ) { - unsigned long fixup =3D search_exception_table(regs); - - gprintk(XENLOG_ERR, "#NM: %p [%ps] -> %p\n", - _p(regs->rip), _p(regs->rip), _p(fixup)); /* * We shouldn't be able to reach here, but for release builds have * the recovery logic in place nevertheless. */ - ASSERT_UNREACHABLE(); - BUG_ON(!fixup); - regs->rip =3D fixup; - return; + if ( extable_fixup(regs, true) ) + { + ASSERT_UNREACHABLE(); + return; + } + + fatal_trap(regs, false); } =20 #ifdef CONFIG_PV --=20 2.11.0