From patchwork Wed Jul 14 20:37:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bobby Eshleman X-Patchwork-Id: 12377851 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2366C47E4D for ; Wed, 14 Jul 2021 20:38:34 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6CC3F613A9 for ; Wed, 14 Jul 2021 20:38:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6CC3F613A9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.156213.288269 (Exim 4.92) (envelope-from ) id 1m3leC-0000ez-V7; Wed, 14 Jul 2021 20:38:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 156213.288269; Wed, 14 Jul 2021 20:38:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m3leC-0000eq-Nz; Wed, 14 Jul 2021 20:38:24 +0000 Received: by outflank-mailman (input) for mailman id 156213; Wed, 14 Jul 2021 20:38:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m3leC-0000KG-5Z for xen-devel@lists.xenproject.org; Wed, 14 Jul 2021 20:38:24 +0000 Received: from mail-pj1-x102d.google.com (unknown [2607:f8b0:4864:20::102d]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b8a3144c-427d-4b48-93a9-b509a296a775; Wed, 14 Jul 2021 20:38:21 +0000 (UTC) Received: by mail-pj1-x102d.google.com with SMTP id p14-20020a17090ad30eb02901731c776526so4644124pju.4 for ; Wed, 14 Jul 2021 13:38:21 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:4c02:4c00::1]) by smtp.gmail.com with ESMTPSA id b17sm1785084pfm.54.2021.07.14.13.38.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 13:38:20 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list X-Inumbo-ID: b8a3144c-427d-4b48-93a9-b509a296a775 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jpxytOQI7mEBkhk32tjmUuolX/Q1Yn907IdDWiELMV8=; b=KykIMWqip6LoIXDyfSIq1qKR+Gka1EeLBtyAXfy1PAyEX8IAy2CQqBjYs+iQijhq6E oBqqmHG2YYeB3U5oMTWVRcfkb4fL00GONk9XjkW2XRkzrtYfVTBR7zG6+sb1SWWUPo0d RLhSFnIRmEu8g/8H2D+D3qiY/UDijfXhagimglVk+VqWzOCVeOuKfLBsUPbbEsN2KMJJ KiYBdkJSgZqe+49Pc1s8J2bv0NW8dGkSTnYbOejvZJe042W6lOnLymZPLhzXkIQrshvp 4cwmheN/i92dLZ/ybShqNLaI+2bKo4fmCKWh0DalRAW+MLXY23gi8R07mQij5NJfHjtJ GVpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=jpxytOQI7mEBkhk32tjmUuolX/Q1Yn907IdDWiELMV8=; b=VOvJt6baTOUJyBovXq8/mPrQHDyzgOgxbjw4AhHOEsMH5n+V9dAt/PfzlfySxR4TlO /T73+GEP9TZxgC4EcS7sCkutDEzZAFgUT1t+JV5XIzRXpcBi0rpqtGRT5BXAtEgD2FLA aslPolNUSyp8RVA41tnhqu7RRnpTWyKCQZouryldwnLYTNalbF1xhUcwD3DyFNFv1wbR 972iIeNBEi4U+zsNywghHJYqF/Djegsx+PcP+/g0GGh0ZsdPruCnD3XSqPsiOpKvoTy7 ClvQUrVrp9mGcHnTDC4oN1jtIQletQibqBY9vexoK0TrGwPvF4lOL/wbIQhlDCpaR0h+ /Xhw== X-Gm-Message-State: AOAM531w8B9uKqgg9DOkPdicJZ9Z7qkb+cACqiUOQ0UpLpRUdxEsImr+ 6a0I17zHUGxjTF20kKSVHz525V8xwWXgjksC X-Google-Smtp-Source: ABdhPJz+EAy20EOa/LMJc6vD8Yk4JeBto6hIMQMv4UVrk1D9AH1LmIfGafjTYMw04uoHk67badcmLw== X-Received: by 2002:a17:90b:fd6:: with SMTP id gd22mr5497865pjb.37.1626295100499; Wed, 14 Jul 2021 13:38:20 -0700 (PDT) Sender: Bobby Eshleman From: Bobby Eshleman To: xen-devel@lists.xenproject.org Cc: Bobby Eshleman , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Wei Liu , Elena Ufimtseva , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= , Jun Nakajima , Kevin Tian Subject: [PATCH v2 2/4] build: use common stubs for debugger_trap_* functions if !CONFIG_CRASH_DEBUG Date: Wed, 14 Jul 2021 13:37:45 -0700 Message-Id: X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 Previously Xen required all architectures implement the debugger_trap_* functions whether or not it actually needs them. This commit makes debugger_trap* functions resolve to arch-specific function definitions if CONFIG_CRASH_DEBUG=y, but resolves to a set of common no-op stubs if !CONFIG_CRASH_DEBUG, which avoids requiring every arch to carry its own stubs. This means asm/debugger.h may also be dropped for architectures that do not need this functionality. Inside xen/debugger.h: * If !CONFIG_CRASH_DEBUG, use stubs. * Otherwise, include arch-specific --- Changes in v2: - #include ordering (xen/.h before asm/.h, alphabetical order) - Other style (no double blanks in comments). - Removed dummy TRAP_invalid_op for ARM (not needed because the patch to remove the calls is now prior to this patch) - Removed common-izing of dbg_rw_mem xen/arch/arm/traps.c | 2 +- xen/arch/x86/debug.c | 2 +- xen/arch/x86/domain.c | 5 ++- xen/arch/x86/domctl.c | 2 +- xen/arch/x86/gdbstub.c | 4 +- xen/arch/x86/hvm/svm/svm.c | 2 +- xen/arch/x86/hvm/vmx/realmode.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 2 +- xen/arch/x86/nmi.c | 2 +- xen/arch/x86/traps.c | 2 +- xen/arch/x86/x86_64/gdbstub.c | 3 +- xen/common/domain.c | 2 +- xen/common/gdbstub.c | 3 +- xen/common/keyhandler.c | 2 +- xen/common/shutdown.c | 2 +- xen/drivers/char/console.c | 2 +- xen/include/asm-arm/debugger.h | 15 ------- xen/include/asm-x86/debugger.h | 60 ++++++---------------------- xen/include/xen/debugger.h | 69 +++++++++++++++++++++++++++++++++ 19 files changed, 103 insertions(+), 80 deletions(-) delete mode 100644 xen/include/asm-arm/debugger.h create mode 100644 xen/include/xen/debugger.h diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index dd09d2a4a9..10db98e01a 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -16,6 +16,7 @@ * GNU General Public License for more details. */ +#include #include #include #include @@ -41,7 +42,6 @@ #include #include #include -#include #include #include #include diff --git a/xen/arch/x86/debug.c b/xen/arch/x86/debug.c index d90dc93056..583a9a042a 100644 --- a/xen/arch/x86/debug.c +++ b/xen/arch/x86/debug.c @@ -14,12 +14,12 @@ * License along with this program; If not, see . */ +#include #include #include #include #include #include -#include #include typedef unsigned long dbgva_t; diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index ef1812dc14..5b948ff270 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -2539,9 +2540,9 @@ static int __init init_vcpu_kick_softirq(void) } __initcall(init_vcpu_kick_softirq); +#ifdef CONFIG_CRASH_DEBUG void domain_pause_for_debugger(void) { -#ifdef CONFIG_CRASH_DEBUG struct vcpu *curr = current; struct domain *d = curr->domain; @@ -2550,8 +2551,8 @@ void domain_pause_for_debugger(void) /* if gdbsx active, we just need to pause the domain */ if ( curr->arch.gdbsx_vcpu_event == 0 ) send_global_virq(VIRQ_DEBUGGER); -#endif } +#endif /* * Local variables: diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 26a76d2be9..24bdb86de7 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -33,7 +34,6 @@ #include #include #include -#include #include #include diff --git a/xen/arch/x86/gdbstub.c b/xen/arch/x86/gdbstub.c index 8f4f49fd3b..5e23d27f62 100644 --- a/xen/arch/x86/gdbstub.c +++ b/xen/arch/x86/gdbstub.c @@ -18,7 +18,9 @@ * You should have received a copy of the GNU General Public License * along with this program; If not, see . */ -#include +#include +#include +#include u16 gdb_arch_signal_num(struct cpu_user_regs *regs, unsigned long cookie) diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 642a64b747..ce1cbe7825 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -58,7 +59,6 @@ #include #include #include -#include #include #include #include diff --git a/xen/arch/x86/hvm/vmx/realmode.c b/xen/arch/x86/hvm/vmx/realmode.c index cc23afa788..57d230c4fe 100644 --- a/xen/arch/x86/hvm/vmx/realmode.c +++ b/xen/arch/x86/hvm/vmx/realmode.c @@ -9,12 +9,12 @@ * Keir Fraser */ +#include #include #include #include #include #include -#include #include #include #include diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index e09b7e3af9..00107e8a3b 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -51,7 +52,6 @@ #include #include #include -#include #include #include #include diff --git a/xen/arch/x86/nmi.c b/xen/arch/x86/nmi.c index ab94a96c4d..505358b656 100644 --- a/xen/arch/x86/nmi.c +++ b/xen/arch/x86/nmi.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -30,7 +31,6 @@ #include #include #include -#include #include #include diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index e60af16ddd..8561ffe3fe 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -62,7 +63,6 @@ #include #include #include -#include #include #include #include diff --git a/xen/arch/x86/x86_64/gdbstub.c b/xen/arch/x86/x86_64/gdbstub.c index 2626519c89..126af03f50 100644 --- a/xen/arch/x86/x86_64/gdbstub.c +++ b/xen/arch/x86/x86_64/gdbstub.c @@ -17,7 +17,8 @@ * along with this program; If not, see . */ -#include +#include +#include #define GDB_REG64(r) gdb_write_to_packet_hex(r, sizeof(u64), ctx) #define GDB_REG32(r) gdb_write_to_packet_hex(r, sizeof(u32), ctx) diff --git a/xen/common/domain.c b/xen/common/domain.c index 6b71c6d6a9..a87d814b38 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -33,7 +34,6 @@ #include #include #include -#include #include #include #include diff --git a/xen/common/gdbstub.c b/xen/common/gdbstub.c index 848c1f4327..c233eb2b49 100644 --- a/xen/common/gdbstub.c +++ b/xen/common/gdbstub.c @@ -38,12 +38,13 @@ #include #include #include -#include #include #include #include #include #include +#include +#include #include #include diff --git a/xen/common/keyhandler.c b/xen/common/keyhandler.c index 8b9f378371..1eafaef9b2 100644 --- a/xen/common/keyhandler.c +++ b/xen/common/keyhandler.c @@ -3,6 +3,7 @@ */ #include +#include #include #include #include @@ -20,7 +21,6 @@ #include #include #include -#include #include static unsigned char keypress_key; diff --git a/xen/common/shutdown.c b/xen/common/shutdown.c index abde48aa4c..f51d44fdc4 100644 --- a/xen/common/shutdown.c +++ b/xen/common/shutdown.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -8,7 +9,6 @@ #include #include #include -#include #include /* opt_noreboot: If true, machine will need manual reset on error. */ diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 7d0a603d03..3d1cdde821 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -26,7 +27,6 @@ #include #include #include -#include #include #include /* for do_console_io */ #include diff --git a/xen/include/asm-arm/debugger.h b/xen/include/asm-arm/debugger.h deleted file mode 100644 index ac776efa78..0000000000 --- a/xen/include/asm-arm/debugger.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __ARM_DEBUGGER_H__ -#define __ARM_DEBUGGER_H__ - -#define debugger_trap_fatal(v, r) (0) -#define debugger_trap_immediate() ((void) 0) - -#endif /* __ARM_DEBUGGER_H__ */ -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/xen/include/asm-x86/debugger.h b/xen/include/asm-x86/debugger.h index 99803bfd0c..c856c1b795 100644 --- a/xen/include/asm-x86/debugger.h +++ b/xen/include/asm-x86/debugger.h @@ -1,44 +1,26 @@ /****************************************************************************** - * asm/debugger.h - * - * Generic hooks into arch-dependent Xen. - * - * Each debugger should define two functions here: - * - * 1. debugger_trap_entry(): - * Called at start of any synchronous fault or trap, before any other work - * is done. The idea is that if your debugger deliberately caused the trap - * (e.g. to implement breakpoints or data watchpoints) then you can take - * appropriate action and return a non-zero value to cause early exit from - * the trap function. - * - * 2. debugger_trap_fatal(): - * Called when Xen is about to give up and crash. Typically you will use this - * hook to drop into a debug session. It can also be used to hook off - * deliberately caused traps (which you then handle and return non-zero). + * x86 Debugger Hooks * - * 3. debugger_trap_immediate(): - * Called if we want to drop into a debugger now. This is essentially the - * same as debugger_trap_fatal, except that we use the current register state - * rather than the state which was in effect when we took the trap. - * For example: if we're dying because of an unhandled exception, we call - * debugger_trap_fatal; if we're dying because of a panic() we call - * debugger_trap_immediate(). + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; If not, see . */ - #ifndef __X86_DEBUGGER_H__ #define __X86_DEBUGGER_H__ +#include +#include +#include #include #include #include void domain_pause_for_debugger(void); -#ifdef CONFIG_CRASH_DEBUG - -#include - static inline bool debugger_trap_fatal( unsigned int vector, struct cpu_user_regs *regs) { @@ -74,28 +56,10 @@ static inline bool debugger_trap_entry( return false; } -#else - -static inline bool debugger_trap_fatal( - unsigned int vector, struct cpu_user_regs *regs) -{ - return false; -} - -#define debugger_trap_immediate() ((void)0) - -static inline bool debugger_trap_entry( - unsigned int vector, struct cpu_user_regs *regs) -{ - return false; -} - -#endif - #ifdef CONFIG_GDBSX unsigned int dbg_rw_mem(unsigned long gva, XEN_GUEST_HANDLE_PARAM(void) buf, unsigned int len, domid_t domid, bool toaddr, uint64_t pgd3); -#endif +#endif /* CONFIG_GDBSX */ #endif /* __X86_DEBUGGER_H__ */ diff --git a/xen/include/xen/debugger.h b/xen/include/xen/debugger.h new file mode 100644 index 0000000000..64745fbe8f --- /dev/null +++ b/xen/include/xen/debugger.h @@ -0,0 +1,69 @@ +/****************************************************************************** + * Generic hooks into arch-dependent Xen. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; If not, see . + * + * Each debugger should define three functions here: + * + * 1. debugger_trap_entry(): + * Called at start of any synchronous fault or trap, before any other work + * is done. The idea is that if your debugger deliberately caused the trap + * (e.g. to implement breakpoints or data watchpoints) then you can take + * appropriate action and return a non-zero value to cause early exit from + * the trap function. + * + * 2. debugger_trap_fatal(): + * Called when Xen is about to give up and crash. Typically you will use this + * hook to drop into a debug session. It can also be used to hook off + * deliberately caused traps (which you then handle and return non-zero). + * + * 3. debugger_trap_immediate(): + * Called if we want to drop into a debugger now. This is essentially the + * same as debugger_trap_fatal, except that we use the current register state + * rather than the state which was in effect when we took the trap. + * For example: if we're dying because of an unhandled exception, we call + * debugger_trap_fatal; if we're dying because of a panic() we call + * debugger_trap_immediate(). + */ + +#ifndef __XEN_DEBUGGER_H__ +#define __XEN_DEBUGGER_H__ + +#ifdef CONFIG_CRASH_DEBUG + +#include + +#else + +#include +#include + +static inline void domain_pause_for_debugger(void) +{ +} + +static inline bool debugger_trap_fatal( + unsigned int vector, const struct cpu_user_regs *regs) +{ + return false; +} + +static inline void debugger_trap_immediate(void) +{ +} + +static inline bool debugger_trap_entry( + unsigned int vector, const struct cpu_user_regs *regs) +{ + return false; +} + +#endif /* CONFIG_CRASH_DEBUG */ + +#endif /* __XEN_DEBUGGER_H__ */