From patchwork Mon Feb 20 16:40:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13146714 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 0F170C678D5 for ; Mon, 20 Feb 2023 16:41:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.498236.769071 (Exim 4.92) (envelope-from ) id 1pU9Dy-0006l3-Ph; Mon, 20 Feb 2023 16:41:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 498236.769071; Mon, 20 Feb 2023 16:41:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pU9Dy-0006kw-Lp; Mon, 20 Feb 2023 16:41:10 +0000 Received: by outflank-mailman (input) for mailman id 498236; Mon, 20 Feb 2023 16:41:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pU9Dx-0006Vi-20 for xen-devel@lists.xenproject.org; Mon, 20 Feb 2023 16:41:09 +0000 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [2a00:1450:4864:20::236]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 60147f3f-b13d-11ed-933d-83870f6b2ba8; Mon, 20 Feb 2023 17:41:08 +0100 (CET) Received: by mail-lj1-x236.google.com with SMTP id y44so1882976ljq.7 for ; Mon, 20 Feb 2023 08:41:08 -0800 (PST) Received: from 34-6F-24-FC-D2-65.. (46.204.108.92.nat.umts.dynamic.t-mobile.pl. [46.204.108.92]) by smtp.gmail.com with ESMTPSA id f8-20020a2e6a08000000b002934d555783sm65798ljc.6.2023.02.20.08.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 08:41:07 -0800 (PST) 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 Sender: "Xen-devel" X-Inumbo-ID: 60147f3f-b13d-11ed-933d-83870f6b2ba8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QRAP5KqQXYqAUnB17tHsxH6vdQ6lhjVqsW3lN6eZV4Y=; b=SYhVFq1KNWKNHzP99mNP54m4dLKi/BDsJP7iTrd+If6fwXFSvjeAGA1WSTw2cVXyXl pmuG9MGMnVXv+AaINVfCvOelfOf80k+gQo9rTy8ZZT7DZoeIRSanzTnoU+nwUQu6aScH DsuVSmq2YfmMXaM2/3V0H57Vg763TzoqJh7Ev5IIfu8zxbzDHentDVODxBmeOWp/7I6K +Eiw7VetcdAt4sY7L1AMqTMgG/L0n1Itm6puuiXcqZWAlR+i2zy0cbJkzlnDfJOz45+K ECQiENnnAJPpVMB98msRgRX/50b+em4jA7jiDK66Xa+I3mP6RmJkitj9JkwQLFfq/Ew+ gy9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QRAP5KqQXYqAUnB17tHsxH6vdQ6lhjVqsW3lN6eZV4Y=; b=tumk9muWxEyMEeVniu/3M3I3nAjpNIG59aEdGdEoFk2wGkZJuxa64lnEbjhJ3sISy7 OnhreChGSsNjLSukCpFe2rC6GCM1yuw4zYNafFvmfamLrO0BNmKwTXsPR4xpeSZYSCtM nADaY+Wxbs0v0q2NoYCOKB9pRRR2OP6qFE3TsdX+sJVHdHqq7DYQpdA5qU/xiu1wuEGK uCKeIAjeQ+wBGjtJUC3lkNdgovXprFuz970Gs3Yj3ByMkU5eXi2GDWMYLJ1W7zZrO4Wi SNQeLqpT6mwpPOWfZC9x54Fd2a7+/So7yTRgm/5AeMcV2EuYlcTazSXqnr/Tgz8rKxcl KJIw== X-Gm-Message-State: AO0yUKUVwCdRON96L/H7UQoUHDF7c4u+e8WSArYwG9Jr6stneEyLCoAp 2ftprHNRbYm1EnFNes0SgblMY+rk9Cc= X-Google-Smtp-Source: AK7set9SWDvh2MqHKwEbdHQ91ctqf9v82DKc6GEWskqkDFUTB7n/ByGNtMv3bd0dVnQW0vANDstqAw== X-Received: by 2002:a2e:9599:0:b0:290:6500:40f0 with SMTP id w25-20020a2e9599000000b00290650040f0mr696117ljh.42.1676911267595; Mon, 20 Feb 2023 08:41:07 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Andrew Cooper , Stefano Stabellini , Gianluca Guida , Oleksii Kurochko , George Dunlap , Julien Grall , Wei Liu Subject: [PATCH v2 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME Date: Mon, 20 Feb 2023 18:40:57 +0200 Message-Id: X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 A large part of the content of the bug.h is repeated among all architectures, so it was decided to create a new config CONFIG_GENERIC_BUG_FRAME. The version of from x86 was taken as the base version. The patch introduces the following stuff: * common bug.h header * generic implementation of do_bug_frame() * new config CONFIG_GENERIC_BUG_FRAME Signed-off-by: Oleksii Kurochko --- Changes in V2: - Switch to x86 implementation as generic as it is more compact ( at least from the point of view of bug frame structure ). - Rename CONFIG_GENERIC_DO_BUG_FRAME to CONFIG_GENERIC_BUG_FRAME. - Change the macro bug_loc(b) to avoid the need for a cast: #define bug_loc(b) ((unsigned long)(b) + (b)->loc_disp) - Rename BUG_FRAME_STUFF to BUG_FRAME_STRUCT - Make macros related to bug frame structure more generic. - Introduce BUG_INSTR and MODIFIER to make _ASM_BUGFRAME_TEXT reusable between x86 and RISC-V. - Rework do_bug_frame() and introduce find_bug_frame() and handle_bug_frame() functions to make it reusable by x86. - code style fixes --- xen/common/Kconfig | 3 + xen/common/Makefile | 1 + xen/common/bug.c | 113 +++++++++++++++++++++++++++++ xen/include/xen/bug.h | 161 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 278 insertions(+) create mode 100644 xen/common/bug.c create mode 100644 xen/include/xen/bug.h diff --git a/xen/common/Kconfig b/xen/common/Kconfig index f1ea3199c8..b226323537 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -28,6 +28,9 @@ config ALTERNATIVE_CALL config ARCH_MAP_DOMAIN_PAGE bool +config GENERIC_BUG_FRAME + bool + config HAS_ALTERNATIVE bool diff --git a/xen/common/Makefile b/xen/common/Makefile index bbd75b4be6..46049eac35 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -1,5 +1,6 @@ obj-$(CONFIG_ARGO) += argo.o obj-y += bitmap.o +obj-$(CONFIG_GENERIC_BUG_FRAME) += bug.o obj-$(CONFIG_HYPFS_CONFIG) += config_data.o obj-$(CONFIG_CORE_PARKING) += core_parking.o obj-y += cpu.o diff --git a/xen/common/bug.c b/xen/common/bug.c new file mode 100644 index 0000000000..5eab3ebb53 --- /dev/null +++ b/xen/common/bug.c @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include +#include +#include + +#include + +const struct bug_frame* find_bug_frame(unsigned long pc, unsigned int *id) +{ + const struct bug_frame *bug = NULL; + const struct virtual_region *region; + + region = find_text_region(pc); + if ( region ) + { + for ( *id = 0; *id < BUGFRAME_NR; (*id)++ ) + { + const struct bug_frame *b; + unsigned int i; + + for ( i = 0, b = region->frame[*id].bugs; + i < region->frame[*id].n_bugs; b++, i++ ) + { + if ( bug_loc(b) == pc ) + { + bug = b; + goto found; + } + } + } + } + + found: + return bug; +} + +int handle_bug_frame(const struct cpu_user_regs *regs, + const struct bug_frame *bug, + unsigned int id) +{ + const char *prefix = "", *filename, *predicate; + unsigned long fixup; + unsigned int lineno; + + if ( id == BUGFRAME_run_fn ) + { +#ifdef ARM + void (*fn)(const struct cpu_user_regs *) = (void *)regs->BUG_FN_REG; +#else + void (*fn)(const struct cpu_user_regs *) = bug_ptr(bug); +#endif + + fn(regs); + return 0; + } + + /* WARN, BUG or ASSERT: decode the filename pointer and line number. */ + filename = bug_ptr(bug); + if ( !is_kernel(filename) && !is_patch(filename) ) + return -EINVAL; + fixup = strlen(filename); + if ( fixup > 50 ) + { + filename += fixup - 47; + prefix = "..."; + } + lineno = bug_line(bug); + + switch ( id ) + { + case BUGFRAME_warn: + printk("Xen WARN at %s%s:%d\n", prefix, filename, lineno); + show_execution_state(regs); + return 0; + + case BUGFRAME_bug: + printk("Xen BUG at %s%s:%d\n", prefix, filename, lineno); + + show_execution_state(regs); + panic("Xen BUG at %s%s:%d\n", prefix, filename, lineno); + + case BUGFRAME_assert: + /* ASSERT: decode the predicate string pointer. */ + predicate = bug_msg(bug); + if ( !is_kernel(predicate) ) + predicate = ""; + + printk("Assertion '%s' failed at %s%s:%d\n", + predicate, prefix, filename, lineno); + + show_execution_state(regs); + panic("Assertion '%s' failed at %s%s:%d\n", + predicate, prefix, filename, lineno); + } + + return -EINVAL; +} + +int do_bug_frame(const struct cpu_user_regs *regs, unsigned long pc) +{ + const struct bug_frame *bug = NULL; + unsigned int id; + + bug = find_bug_frame(pc, &id); + if (!bug) + return -ENOENT; + + return handle_bug_frame(regs, bug, id); +} + diff --git a/xen/include/xen/bug.h b/xen/include/xen/bug.h new file mode 100644 index 0000000000..4aedebeb18 --- /dev/null +++ b/xen/include/xen/bug.h @@ -0,0 +1,161 @@ +#ifndef __XEN_BUG_H__ +#define __XEN_BUG_H__ + +#define BUG_DISP_WIDTH 24 +#define BUG_LINE_LO_WIDTH (31 - BUG_DISP_WIDTH) +#define BUG_LINE_HI_WIDTH (31 - BUG_DISP_WIDTH) + +#define BUGFRAME_run_fn 0 +#define BUGFRAME_warn 1 +#define BUGFRAME_bug 2 +#define BUGFRAME_assert 3 + +#define BUGFRAME_NR 4 + +#ifndef __ASSEMBLY__ + +#include +#include +#include +#include + +#include + +#ifndef BUG_FRAME_STRUCT + +struct bug_frame { + signed int loc_disp:BUG_DISP_WIDTH; + unsigned int line_hi:BUG_LINE_HI_WIDTH; + signed int ptr_disp:BUG_DISP_WIDTH; + unsigned int line_lo:BUG_LINE_LO_WIDTH; + signed int msg_disp[]; +}; + +#endif /* BUG_FRAME_STRUCT */ + +#ifndef bug_loc +#define bug_loc(b) ((unsigned long)(b) + (b)->loc_disp) +#endif /* bug_loc */ + +#ifndef bug_ptr +#define bug_ptr(b) ((const void *)(b) + (b)->ptr_disp) +#endif /* bug_ptr */ + +#ifndef bug_line +#define bug_line(b) (((((b)->line_hi + ((b)->loc_disp < 0)) & \ + ((1 << BUG_LINE_HI_WIDTH) - 1)) << \ + BUG_LINE_LO_WIDTH) + \ + (((b)->line_lo + ((b)->ptr_disp < 0)) & \ + ((1 << BUG_LINE_LO_WIDTH) - 1))) +#endif /* bug_line */ + +#ifndef bug_msg +#define bug_msg(b) ((const char *)(b) + (b)->msg_disp[1]) +#endif /* bug_msg */ + +#ifndef _ASM_BUGFRAME_TEXT + +#define _ASM_BUGFRAME_TEXT(second_frame) \ + ".Lbug%=:"BUG_INSTR"\n" \ + ".pushsection .bug_frames.%"MODIFIER"[bf_type], \"a\", @progbits\n" \ + ".p2align 2\n" \ + ".Lfrm%=:\n" \ + ".long (.Lbug%= - .Lfrm%=) + %"MODIFIER"[bf_line_hi]\n" \ + ".long (%"MODIFIER"[bf_ptr] - .Lfrm%=) + %"MODIFIER"[bf_line_lo]\n" \ + ".if " #second_frame "\n" \ + ".long 0, %"MODIFIER"[bf_msg] - .Lfrm%=\n" \ + ".endif\n" \ + ".popsection\n" + +#endif /* _ASM_BUGFRAME_TEXT */ + +#ifndef _ASM_BUGFRAME_INFO + +#define _ASM_BUGFRAME_INFO(type, line, ptr, msg) \ + [bf_type] "i" (type), \ + [bf_ptr] "i" (ptr), \ + [bf_msg] "i" (msg), \ + [bf_line_lo] "i" ((line & ((1 << BUG_LINE_LO_WIDTH) - 1)) \ + << BUG_DISP_WIDTH), \ + [bf_line_hi] "i" (((line) >> BUG_LINE_LO_WIDTH) << BUG_DISP_WIDTH) + +#endif /* _ASM_BUGFRAME_INFO */ + +#ifndef BUG_FRAME + +#define BUG_FRAME(type, line, ptr, second_frame, msg) do { \ + BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH)); \ + BUILD_BUG_ON((type) >= BUGFRAME_NR); \ + asm volatile ( _ASM_BUGFRAME_TEXT(second_frame) \ + :: _ASM_BUGFRAME_INFO(type, line, ptr, msg) ); \ +} while (0) + +#endif + +#ifndef run_in_exception_handler + +/* + * TODO: untangle header dependences, break BUILD_BUG_ON() out of xen/lib.h, + * and use a real static inline here to get proper type checking of fn(). + */ +#define run_in_exception_handler(fn) \ + do { \ + (void)((fn) == (void (*)(struct cpu_user_regs *))NULL); \ + BUG_FRAME(BUGFRAME_run_fn, 0, fn, 0, NULL); \ + } while ( 0 ) + +#endif /* run_in_exception_handler */ + +#ifndef WARN +#define WARN() BUG_FRAME(BUGFRAME_warn, __LINE__, __FILE__, 0, NULL) +#endif /* WARN */ + +#ifndef BUG +#define BUG() do { \ + BUG_FRAME(BUGFRAME_bug, __LINE__, __FILE__, 0, NULL); \ + unreachable(); \ +} while (0) +#endif + +#ifndef assert_failed +#define assert_failed(msg) do { \ + BUG_FRAME(BUGFRAME_assert, __LINE__, __FILE__, 1, msg); \ + unreachable(); \ +} while (0) +#endif + +#ifdef CONFIG_GENERIC_BUG_FRAME + +struct cpu_user_regs; + +const struct bug_frame* find_bug_frame(unsigned long pc, unsigned int *id); + +int handle_bug_frame(const struct cpu_user_regs *regs, + const struct bug_frame *bug, + unsigned int id); + +int do_bug_frame(const struct cpu_user_regs *regs, unsigned long pc); + +#endif /* CONFIG_GENERIC_BUG_FRAME */ + +extern const struct bug_frame __start_bug_frames[], + __stop_bug_frames_0[], + __stop_bug_frames_1[], + __stop_bug_frames_2[], + __stop_bug_frames_3[]; + +#else /* !__ASSEMBLY__ */ + +#include + +#endif /* __ASSEMBLY__ */ + +#endif /* __XEN_BUG_H__ */ +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Mon Feb 20 16:40:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13146712 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 6F089C64EC7 for ; Mon, 20 Feb 2023 16:41:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.498237.769082 (Exim 4.92) (envelope-from ) id 1pU9E0-00070M-2i; Mon, 20 Feb 2023 16:41:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 498237.769082; Mon, 20 Feb 2023 16:41:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pU9Dz-00070F-UX; Mon, 20 Feb 2023 16:41:11 +0000 Received: by outflank-mailman (input) for mailman id 498237; Mon, 20 Feb 2023 16:41:10 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pU9Dy-0006Vi-F1 for xen-devel@lists.xenproject.org; Mon, 20 Feb 2023 16:41:10 +0000 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [2a00:1450:4864:20::235]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 610e7f9e-b13d-11ed-933d-83870f6b2ba8; Mon, 20 Feb 2023 17:41:09 +0100 (CET) Received: by mail-lj1-x235.google.com with SMTP id l8so1771380ljq.3 for ; Mon, 20 Feb 2023 08:41:09 -0800 (PST) Received: from 34-6F-24-FC-D2-65.. (46.204.108.92.nat.umts.dynamic.t-mobile.pl. [46.204.108.92]) by smtp.gmail.com with ESMTPSA id f8-20020a2e6a08000000b002934d555783sm65798ljc.6.2023.02.20.08.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 08:41:09 -0800 (PST) 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 Sender: "Xen-devel" X-Inumbo-ID: 610e7f9e-b13d-11ed-933d-83870f6b2ba8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c1MpbYkthmfF/j5tbT9Ls4HfPFbZX5FNFb/Z6pTJAxg=; b=UiIfZFboHwH67hlEPkfcEEE/34XyvkKLZ3y8Q8ltELBBsTV2cs9LT1uyKUQU3ovcXZ 8shObelEr+mzCYJipWEmbrz7VcsdwZvJjjl2mgTRAjHrcGrLM4Fxw48XGarvD7jBhS+d 7V2Hb4o5oHHiSR+97ncsNbwkpfDL9Y+94sFMuUzqL06Dtc1/WuXyvqSsMrYTlHOGMWlx a4jwBtMy6nnMYIjGtrYDgR8/4XVCRIdBaiMIuz8UbV0sgtQo5qbZrNG1JHV34jQFpATp b+mZKbJJw68kQhyBAtbSBrIgGy8FKizpzfUBiCKgIAowhCAAZv8cMQpmOY7GWluqz3s6 6D9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c1MpbYkthmfF/j5tbT9Ls4HfPFbZX5FNFb/Z6pTJAxg=; b=5xKKEqDKHOT4t2uPcqMStuA9UcgvSgf4TT1/eReTSkC5A2n691oK59sOgpnQgWu0UY R8jrfNVkvyUFcbfgpKwoxC9bbxPDe3bk3zl1XYRBUNet9yFTFfF1Pvtfvp86LsLpQoh0 QK7UA9je45Jyd0AAlQXSi+Uki1GA5zz7v4oPcDy8hEGL2KWVV2/zPyYFKiCuLVYkHrTP VsvPf9+9GL0/B/jWcWBjPbmmzxFxtEeB6WiK/cQjKYMP+CeMjcHKYysW/zzoUAKCJLqS hGmQTI5CFLTTWoy1+qwnxYHMIPOTAoJaqOi1JrzAxlNT2nhaaLSThpDnkn+l4uKLbU4c 7XVg== X-Gm-Message-State: AO0yUKWsjCe7XGgevRr5e12BZGtQl9UBaLZJtX2SBLugLjhQHPGSB/r7 VVf0bA9Fr3wilppcC/9CswNjhvfXPsw= X-Google-Smtp-Source: AK7set89y+om3PEExn5kE/pMZmu/hwZFPshETVGlfRftqChwkTdlUAQ7Jc7yBHswtwsGxg9jGWk1sQ== X-Received: by 2002:a05:651c:2128:b0:293:fea:c912 with SMTP id a40-20020a05651c212800b002930feac912mr822844ljq.13.1676911269268; Mon, 20 Feb 2023 08:41:09 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Andrew Cooper , Stefano Stabellini , Gianluca Guida , Oleksii Kurochko , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , George Dunlap , Wei Liu , =?utf-8?q?R?= =?utf-8?q?oger_Pau_Monn=C3=A9?= Subject: [PATCH v2 2/4] xen: change to Date: Mon, 20 Feb 2023 18:40:58 +0200 Message-Id: X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Since the generic version of bug.h stuff was introduced use instead of unnecessary Signed-off-by: Oleksii Kurochko --- Changes in V2: * Put [PATCH v1 4/4] xen: change to as second patch, update the patch to change all to among the whole project to not break build. * Update the commit message. --- xen/arch/arm/include/asm/div64.h | 2 +- xen/arch/arm/vgic/vgic-v2.c | 2 +- xen/arch/arm/vgic/vgic.c | 2 +- xen/arch/x86/acpi/cpufreq/cpufreq.c | 2 +- xen/arch/x86/include/asm/asm_defns.h | 2 +- xen/drivers/cpufreq/cpufreq.c | 2 +- xen/include/xen/lib.h | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/include/asm/div64.h b/xen/arch/arm/include/asm/div64.h index 1cd58bc51a..fc667a80f9 100644 --- a/xen/arch/arm/include/asm/div64.h +++ b/xen/arch/arm/include/asm/div64.h @@ -74,7 +74,7 @@ #elif __GNUC__ >= 4 -#include +#include /* * If the divisor happens to be constant, we determine the appropriate diff --git a/xen/arch/arm/vgic/vgic-v2.c b/xen/arch/arm/vgic/vgic-v2.c index 1a99d3a8b4..c90e88fddb 100644 --- a/xen/arch/arm/vgic/vgic-v2.c +++ b/xen/arch/arm/vgic/vgic-v2.c @@ -16,8 +16,8 @@ */ #include -#include #include +#include #include #include diff --git a/xen/arch/arm/vgic/vgic.c b/xen/arch/arm/vgic/vgic.c index f0f2ea5021..b9463a5f27 100644 --- a/xen/arch/arm/vgic/vgic.c +++ b/xen/arch/arm/vgic/vgic.c @@ -15,9 +15,9 @@ * along with this program. If not, see . */ +#include #include #include -#include #include #include diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufreq/cpufreq.c index c27cbb2304..18ff2a443b 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -27,6 +27,7 @@ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +#include #include #include #include @@ -35,7 +36,6 @@ #include #include #include -#include #include #include #include diff --git a/xen/arch/x86/include/asm/asm_defns.h b/xen/arch/x86/include/asm/asm_defns.h index d9431180cf..a8526cf36c 100644 --- a/xen/arch/x86/include/asm/asm_defns.h +++ b/xen/arch/x86/include/asm/asm_defns.h @@ -6,7 +6,7 @@ /* NB. Auto-generated from arch/.../asm-offsets.c */ #include #endif -#include +#include #include #include #include diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c index a94520ee57..354f78580b 100644 --- a/xen/drivers/cpufreq/cpufreq.c +++ b/xen/drivers/cpufreq/cpufreq.c @@ -26,6 +26,7 @@ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +#include #include #include #include @@ -39,7 +40,6 @@ #include #include #include -#include #include #include diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h index 05ee1e18af..e914ccade0 100644 --- a/xen/include/xen/lib.h +++ b/xen/include/xen/lib.h @@ -24,12 +24,12 @@ #ifndef __ASSEMBLY__ +#include #include #include #include #include #include -#include #define BUG_ON(p) do { if (unlikely(p)) BUG(); } while (0) #define WARN_ON(p) ({ \ From patchwork Mon Feb 20 16:40:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13146715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E5DA3C677F1 for ; Mon, 20 Feb 2023 16:41:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.498238.769093 (Exim 4.92) (envelope-from ) id 1pU9E3-0007Ig-DY; Mon, 20 Feb 2023 16:41:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 498238.769093; Mon, 20 Feb 2023 16:41:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pU9E3-0007IT-9q; Mon, 20 Feb 2023 16:41:15 +0000 Received: by outflank-mailman (input) for mailman id 498238; Mon, 20 Feb 2023 16:41:13 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pU9E1-0006Vi-K6 for xen-devel@lists.xenproject.org; Mon, 20 Feb 2023 16:41:13 +0000 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [2a00:1450:4864:20::234]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 62e5efd1-b13d-11ed-933d-83870f6b2ba8; Mon, 20 Feb 2023 17:41:12 +0100 (CET) Received: by mail-lj1-x234.google.com with SMTP id e9so1716249ljn.9 for ; Mon, 20 Feb 2023 08:41:12 -0800 (PST) Received: from 34-6F-24-FC-D2-65.. (46.204.108.92.nat.umts.dynamic.t-mobile.pl. [46.204.108.92]) by smtp.gmail.com with ESMTPSA id f8-20020a2e6a08000000b002934d555783sm65798ljc.6.2023.02.20.08.41.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 08:41:11 -0800 (PST) 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 Sender: "Xen-devel" X-Inumbo-ID: 62e5efd1-b13d-11ed-933d-83870f6b2ba8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6vX3xq5gnben6ES0t2bFojgyY8cI1GFCJsQxOuCPDvE=; b=L3M4mVlMD3bSf6SRIPTWrEs+BMqXjJ2CSXtS9rAVuApr8G427G/XwkFRuftlgx0Cnu xnl4yBKbm/OcQUVcxWMhDUot7TJmQxeI2kovl8yDGUcB4Wo1h++PbdFcOVL3SAm4rvs8 TdWg/L4ih5sZVCmcHts75X3Yh22ICYuwbCZUk8X+EkQMTF+nhMTQPbpMGpuhYpOa4d4R oLJ3W9Vlerc8rwNpRvMoY2BnQ5DFXGfu3AILgRapAX+m4c/jOp9ILgXvMXgDF1ysBoRY WKXGdRtrLOlB2NRiX/2uK2Ngpy/AaHRKTWJX06FvVVmvgrl4ERZ9ODkTGso1oUVg+zaG +ThA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6vX3xq5gnben6ES0t2bFojgyY8cI1GFCJsQxOuCPDvE=; b=fn7rwbVptoce5WLuYYR4qjpwirEbo0eE2FDtC77Xj2NlikoSC85SBQKMGNbF0JJI5L gc9fAO7PGJLxnvIL8lVgprvUw/zKpedJJcg5ByBKnTwdLBALfkQprXuZmSgg7perRRRd XqmpFescF+xjxp7eya05PONIpysSJltmvkfisU9pbxSLzZamzyC8Zzg9qLSoE9R56BmR BsH9I+ab5+W5fybQ6uZp8JcwhOUz+FSFyLHqRdQz+mRBMTVuuz1pvxD7KPHbBP1yhLKZ xSe6ss1L7kNAUvzFSFVD4qsfJKJYJQsarcjLTa3QkRKPGTOvdcUE0uMpr9bP0+DKbayC SW+A== X-Gm-Message-State: AO0yUKV/FK3fH/1M3oK9FfLuF1TgdTqtNF1Q2cwg5rBAivqeTpl7DgW2 h+GTK0rGN4cOY+0a4es6s9cq3QWwQlY= X-Google-Smtp-Source: AK7set+9tUQdYT6JIbBO5d4ChaBSfxuBfihRwSW+P2DNFufmkvsKvtu3gKuL7h4Iz+JME9t0r4xi8A== X-Received: by 2002:a2e:8708:0:b0:294:7327:4a0d with SMTP id m8-20020a2e8708000000b0029473274a0dmr652623lji.20.1676911272396; Mon, 20 Feb 2023 08:41:12 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Andrew Cooper , Stefano Stabellini , Gianluca Guida , Oleksii Kurochko , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v2 3/4] xen/arm: switch ARM to use generic implementation of bug.h Date: Mon, 20 Feb 2023 18:40:59 +0200 Message-Id: X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Signed-off-by: Oleksii Kurochko --- Changes in V2: * Rename bug_file() in ARM implementation to bug_ptr() as generic do_bug_frame() uses bug_ptr(). * Remove generic parts from bug.h * Remove declaration of 'int do_bug_frame(...)' from as it was introduced in --- xen/arch/arm/Kconfig | 1 + xen/arch/arm/include/asm/bug.h | 32 +------------ xen/arch/arm/include/asm/traps.h | 2 - xen/arch/arm/traps.c | 79 -------------------------------- 4 files changed, 3 insertions(+), 111 deletions(-) diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 239d3aed3c..aad6644a7b 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -12,6 +12,7 @@ config ARM_64 config ARM def_bool y + select GENERIC_BUG_FRAME select HAS_ALTERNATIVE select HAS_DEVICE_TREE select HAS_PASSTHROUGH diff --git a/xen/arch/arm/include/asm/bug.h b/xen/arch/arm/include/asm/bug.h index f4088d0913..174cee477d 100644 --- a/xen/arch/arm/include/asm/bug.h +++ b/xen/arch/arm/include/asm/bug.h @@ -9,9 +9,7 @@ # error "unknown ARM variant" #endif -#define BUG_DISP_WIDTH 24 -#define BUG_LINE_LO_WIDTH (31 - BUG_DISP_WIDTH) -#define BUG_LINE_HI_WIDTH (31 - BUG_DISP_WIDTH) +#define BUG_FRAME_STRUCT struct bug_frame { signed int loc_disp; /* Relative address to the bug address */ @@ -21,18 +19,10 @@ struct bug_frame { uint32_t pad0:16; /* Padding for 8-bytes align */ }; -#define bug_loc(b) ((const void *)(b) + (b)->loc_disp) -#define bug_file(b) ((const void *)(b) + (b)->file_disp); +#define bug_ptr(b) ((const void *)(b) + (b)->file_disp) #define bug_line(b) ((b)->line) #define bug_msg(b) ((const char *)(b) + (b)->msg_disp) -#define BUGFRAME_run_fn 0 -#define BUGFRAME_warn 1 -#define BUGFRAME_bug 2 -#define BUGFRAME_assert 3 - -#define BUGFRAME_NR 4 - /* Many versions of GCC doesn't support the asm %c parameter which would * be preferable to this unpleasantness. We use mergeable string * sections to avoid multiple copies of the string appearing in the @@ -77,24 +67,6 @@ struct bug_frame { ".popsection" :: "r" (fn) : __stringify(BUG_FN_REG) ); \ } while (0) -#define WARN() BUG_FRAME(BUGFRAME_warn, __LINE__, __FILE__, 0, "") - -#define BUG() do { \ - BUG_FRAME(BUGFRAME_bug, __LINE__, __FILE__, 0, ""); \ - unreachable(); \ -} while (0) - -#define assert_failed(msg) do { \ - BUG_FRAME(BUGFRAME_assert, __LINE__, __FILE__, 1, msg); \ - unreachable(); \ -} while (0) - -extern const struct bug_frame __start_bug_frames[], - __stop_bug_frames_0[], - __stop_bug_frames_1[], - __stop_bug_frames_2[], - __stop_bug_frames_3[]; - #endif /* __ARM_BUG_H__ */ /* * Local variables: diff --git a/xen/arch/arm/include/asm/traps.h b/xen/arch/arm/include/asm/traps.h index 883dae368e..c6518008ec 100644 --- a/xen/arch/arm/include/asm/traps.h +++ b/xen/arch/arm/include/asm/traps.h @@ -69,8 +69,6 @@ void do_cp(struct cpu_user_regs *regs, const union hsr hsr); void do_trap_smc(struct cpu_user_regs *regs, const union hsr hsr); void do_trap_hvc_smccc(struct cpu_user_regs *regs); -int do_bug_frame(const struct cpu_user_regs *regs, vaddr_t pc); - void noreturn do_unexpected_trap(const char *msg, const struct cpu_user_regs *regs); void do_trap_hyp_sync(struct cpu_user_regs *regs); diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 061c92acbd..751c3277aa 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -1197,85 +1197,6 @@ void do_unexpected_trap(const char *msg, const struct cpu_user_regs *regs) panic("CPU%d: Unexpected Trap: %s\n", smp_processor_id(), msg); } -int do_bug_frame(const struct cpu_user_regs *regs, vaddr_t pc) -{ - const struct bug_frame *bug = NULL; - const char *prefix = "", *filename, *predicate; - unsigned long fixup; - int id = -1, lineno; - const struct virtual_region *region; - - region = find_text_region(pc); - if ( region ) - { - for ( id = 0; id < BUGFRAME_NR; id++ ) - { - const struct bug_frame *b; - unsigned int i; - - for ( i = 0, b = region->frame[id].bugs; - i < region->frame[id].n_bugs; b++, i++ ) - { - if ( ((vaddr_t)bug_loc(b)) == pc ) - { - bug = b; - goto found; - } - } - } - } - found: - if ( !bug ) - return -ENOENT; - - if ( id == BUGFRAME_run_fn ) - { - void (*fn)(const struct cpu_user_regs *) = (void *)regs->BUG_FN_REG; - - fn(regs); - return 0; - } - - /* WARN, BUG or ASSERT: decode the filename pointer and line number. */ - filename = bug_file(bug); - if ( !is_kernel(filename) ) - return -EINVAL; - fixup = strlen(filename); - if ( fixup > 50 ) - { - filename += fixup - 47; - prefix = "..."; - } - lineno = bug_line(bug); - - switch ( id ) - { - case BUGFRAME_warn: - printk("Xen WARN at %s%s:%d\n", prefix, filename, lineno); - show_execution_state(regs); - return 0; - - case BUGFRAME_bug: - printk("Xen BUG at %s%s:%d\n", prefix, filename, lineno); - show_execution_state(regs); - panic("Xen BUG at %s%s:%d\n", prefix, filename, lineno); - - case BUGFRAME_assert: - /* ASSERT: decode the predicate string pointer. */ - predicate = bug_msg(bug); - if ( !is_kernel(predicate) ) - predicate = ""; - - printk("Assertion '%s' failed at %s%s:%d\n", - predicate, prefix, filename, lineno); - show_execution_state(regs); - panic("Assertion '%s' failed at %s%s:%d\n", - predicate, prefix, filename, lineno); - } - - return -EINVAL; -} - #ifdef CONFIG_ARM_64 static void do_trap_brk(struct cpu_user_regs *regs, const union hsr hsr) { From patchwork Mon Feb 20 16:41:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13146711 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id D7152C64EC4 for ; Mon, 20 Feb 2023 16:41:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.498239.769104 (Exim 4.92) (envelope-from ) id 1pU9E4-0007Zs-NM; Mon, 20 Feb 2023 16:41:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 498239.769104; Mon, 20 Feb 2023 16:41:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pU9E4-0007Zj-Iz; Mon, 20 Feb 2023 16:41:16 +0000 Received: by outflank-mailman (input) for mailman id 498239; Mon, 20 Feb 2023 16:41:15 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pU9E3-0006Vi-6U for xen-devel@lists.xenproject.org; Mon, 20 Feb 2023 16:41:15 +0000 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [2a00:1450:4864:20::235]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 63d86e37-b13d-11ed-933d-83870f6b2ba8; Mon, 20 Feb 2023 17:41:14 +0100 (CET) Received: by mail-lj1-x235.google.com with SMTP id l8so1771605ljq.3 for ; Mon, 20 Feb 2023 08:41:14 -0800 (PST) Received: from 34-6F-24-FC-D2-65.. (46.204.108.92.nat.umts.dynamic.t-mobile.pl. [46.204.108.92]) by smtp.gmail.com with ESMTPSA id f8-20020a2e6a08000000b002934d555783sm65798ljc.6.2023.02.20.08.41.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 08:41:13 -0800 (PST) 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 Sender: "Xen-devel" X-Inumbo-ID: 63d86e37-b13d-11ed-933d-83870f6b2ba8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=brWuH85TZkY9/IYxdPrwIkUjLxv9KxBhQf85+vQ58wk=; b=MmRKeCMdzrG6DgNv6Ggsgf8G/lMwhwCFonQEkCwdQDcQFu9ccqxj95wBG/IVOZaqnk Cn/Q0rk1b86MC+30UZd9NkmfPhLhAhJU7EVQLoI1wsBrv+2PAc6bZAcjnN/NohTxQ+pd G6xq1V8F1sVLqA9lXsE7KNvT4FURLrQ70PaUcwFpGDIFFh6yBZ3mwzHPqgR9W/3P3hWW fb6L5cXlx6isYkbd4QLSRu0tXhXj6MA2pERQmEnA2FP07hRbM6OLMcjDaYuKUB9ozDmL qTCctEWwAALncKXrK8hSO+BJt4zAahcE5X4kuWrsGRn0N3nAGlcutP6XeBh45iOzPyhT zuZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=brWuH85TZkY9/IYxdPrwIkUjLxv9KxBhQf85+vQ58wk=; b=aA8BOoE1Qfz5Q1LiyzCGu7y+n64+YWfpXrwiZUJa9rAkVw2k1nTqGuA7yVuFsrDbrm Zuj4ZLSgvKUEiRdLbLX7IgefwdCmomEQg7Eg1Ri5aSj5dpEEA1c7jOXNcN+XSy/4xSaB +vbvAbbcJnCGh3Fb7w1IXq8E3cUJ//dNDBrtsUSTeCcpPf6nOXgteCdTYLGMWv/pso4H ZtuU11hCSg+t5wTNhwjPP5/PRfLVZP3zurkmarf2GdlJjDS04pEGfZiYNFwmhKEvcwNS DvM1ZCCZd17yqrKsQyQ+tbrYap7VcFJYvYRG/tJUDeKo1hNtclSheVJRlq6jRZof+Azc CgbQ== X-Gm-Message-State: AO0yUKXXITzrmVcGBgcN+lyPwaVgna6BR/KJGLhWHmST1QDt7Qb+iCmL oOT5WWqlKaeneq9Vz3jKeWtmfcvamvs= X-Google-Smtp-Source: AK7set+NVAnmJghQX6aiBFVCLKdpyaj6Mv2mvGiPVfX8m5pajdpOfDnIQD0R+mBYQPtZNwJfbjXQjg== X-Received: by 2002:a05:651c:1543:b0:293:5312:b021 with SMTP id y3-20020a05651c154300b002935312b021mr354992ljp.14.1676911273817; Mon, 20 Feb 2023 08:41:13 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Andrew Cooper , Stefano Stabellini , Gianluca Guida , Oleksii Kurochko , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= , Wei Liu Subject: [PATCH v2 4/4] xen/x86: switch x86 to use generic implemetation of bug.h Date: Mon, 20 Feb 2023 18:41:00 +0200 Message-Id: <14900d647181be59b5b7d90c013f0914ed273088.1676909088.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Signed-off-by: Oleksii Kurochko --- Changes in V2: * Remove all unnecessary things from as they were introduced in . * Define BUG_INSTR = 'ud2' and MODIFIER = 'c' ( it is needed to skip '$' when use an imidiate in x86 assembly ) * Update do_invalid_op() to re-use handle_bug_frame() and find_bug_frame() from generic implemetation of CONFIG_GENERIC_BUG_FRAME * Code style fixes. --- xen/arch/x86/Kconfig | 1 + xen/arch/x86/include/asm/bug.h | 88 ++-------------------------------- xen/arch/x86/traps.c | 81 +++++-------------------------- 3 files changed, 18 insertions(+), 152 deletions(-) diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 6a7825f4ba..b0ff1f3ee6 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -11,6 +11,7 @@ config X86 select ARCH_MAP_DOMAIN_PAGE select ARCH_SUPPORTS_INT128 select CORE_PARKING + select GENERIC_BUG_FRAME select HAS_ALTERNATIVE select HAS_COMPAT select HAS_CPUFREQ diff --git a/xen/arch/x86/include/asm/bug.h b/xen/arch/x86/include/asm/bug.h index b7265bdfbe..31fc687669 100644 --- a/xen/arch/x86/include/asm/bug.h +++ b/xen/arch/x86/include/asm/bug.h @@ -1,92 +1,12 @@ #ifndef __X86_BUG_H__ #define __X86_BUG_H__ -#define BUG_DISP_WIDTH 24 -#define BUG_LINE_LO_WIDTH (31 - BUG_DISP_WIDTH) -#define BUG_LINE_HI_WIDTH (31 - BUG_DISP_WIDTH) - -#define BUGFRAME_run_fn 0 -#define BUGFRAME_warn 1 -#define BUGFRAME_bug 2 -#define BUGFRAME_assert 3 - -#define BUGFRAME_NR 4 - #ifndef __ASSEMBLY__ -struct bug_frame { - signed int loc_disp:BUG_DISP_WIDTH; - unsigned int line_hi:BUG_LINE_HI_WIDTH; - signed int ptr_disp:BUG_DISP_WIDTH; - unsigned int line_lo:BUG_LINE_LO_WIDTH; - signed int msg_disp[]; -}; - -#define bug_loc(b) ((const void *)(b) + (b)->loc_disp) -#define bug_ptr(b) ((const void *)(b) + (b)->ptr_disp) -#define bug_line(b) (((((b)->line_hi + ((b)->loc_disp < 0)) & \ - ((1 << BUG_LINE_HI_WIDTH) - 1)) << \ - BUG_LINE_LO_WIDTH) + \ - (((b)->line_lo + ((b)->ptr_disp < 0)) & \ - ((1 << BUG_LINE_LO_WIDTH) - 1))) -#define bug_msg(b) ((const char *)(b) + (b)->msg_disp[1]) - -#define _ASM_BUGFRAME_TEXT(second_frame) \ - ".Lbug%=: ud2\n" \ - ".pushsection .bug_frames.%c[bf_type], \"a\", @progbits\n" \ - ".p2align 2\n" \ - ".Lfrm%=:\n" \ - ".long (.Lbug%= - .Lfrm%=) + %c[bf_line_hi]\n" \ - ".long (%c[bf_ptr] - .Lfrm%=) + %c[bf_line_lo]\n" \ - ".if " #second_frame "\n" \ - ".long 0, %c[bf_msg] - .Lfrm%=\n" \ - ".endif\n" \ - ".popsection\n" \ - -#define _ASM_BUGFRAME_INFO(type, line, ptr, msg) \ - [bf_type] "i" (type), \ - [bf_ptr] "i" (ptr), \ - [bf_msg] "i" (msg), \ - [bf_line_lo] "i" ((line & ((1 << BUG_LINE_LO_WIDTH) - 1)) \ - << BUG_DISP_WIDTH), \ - [bf_line_hi] "i" (((line) >> BUG_LINE_LO_WIDTH) << BUG_DISP_WIDTH) - -#define BUG_FRAME(type, line, ptr, second_frame, msg) do { \ - BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH)); \ - BUILD_BUG_ON((type) >= BUGFRAME_NR); \ - asm volatile ( _ASM_BUGFRAME_TEXT(second_frame) \ - :: _ASM_BUGFRAME_INFO(type, line, ptr, msg) ); \ -} while (0) - - -#define WARN() BUG_FRAME(BUGFRAME_warn, __LINE__, __FILE__, 0, NULL) -#define BUG() do { \ - BUG_FRAME(BUGFRAME_bug, __LINE__, __FILE__, 0, NULL); \ - unreachable(); \ -} while (0) - -/* - * TODO: untangle header dependences, break BUILD_BUG_ON() out of xen/lib.h, - * and use a real static inline here to get proper type checking of fn(). - */ -#define run_in_exception_handler(fn) \ - do { \ - (void)((fn) == (void (*)(struct cpu_user_regs *))NULL); \ - BUG_FRAME(BUGFRAME_run_fn, 0, fn, 0, NULL); \ - } while ( 0 ) - -#define assert_failed(msg) do { \ - BUG_FRAME(BUGFRAME_assert, __LINE__, __FILE__, 1, msg); \ - unreachable(); \ -} while (0) - -extern const struct bug_frame __start_bug_frames[], - __stop_bug_frames_0[], - __stop_bug_frames_1[], - __stop_bug_frames_2[], - __stop_bug_frames_3[]; +#define BUG_INSTR "ud2" +#define MODIFIER "c" -#else /* !__ASSEMBLY__ */ +#else /* * Construct a bugframe, suitable for using in assembly code. Should always @@ -128,6 +48,6 @@ extern const struct bug_frame __start_bug_frames[], #define ASSERT_FAILED(msg) \ BUG_FRAME BUGFRAME_assert, __LINE__, __FILE__, 1, msg -#endif /* !__ASSEMBLY__ */ +#endif /* __ASSEMBLY__ */ #endif /* __X86_BUG_H__ */ diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index cade9e12f8..39f153a53b 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -24,6 +24,7 @@ * Gareth Hughes , May 2000 */ +#include #include #include #include @@ -1168,10 +1169,8 @@ void do_invalid_op(struct cpu_user_regs *regs) { const struct bug_frame *bug = NULL; u8 bug_insn[2]; - const char *prefix = "", *filename, *predicate, *eip = (char *)regs->rip; - unsigned long fixup; - int id = -1, lineno; - const struct virtual_region *region; + const char *eip = (char *)regs->rip; + unsigned int id; if ( likely(guest_mode(regs)) ) { @@ -1185,83 +1184,29 @@ void do_invalid_op(struct cpu_user_regs *regs) memcmp(bug_insn, "\xf\xb", sizeof(bug_insn)) ) goto die; - region = find_text_region(regs->rip); - if ( region ) - { - for ( id = 0; id < BUGFRAME_NR; id++ ) - { - const struct bug_frame *b; - unsigned int i; - - for ( i = 0, b = region->frame[id].bugs; - i < region->frame[id].n_bugs; b++, i++ ) - { - if ( bug_loc(b) == eip ) - { - bug = b; - goto found; - } - } - } - } - - found: + bug = find_bug_frame((unsigned long)eip, &id); if ( !bug ) goto die; + eip += sizeof(bug_insn); - if ( id == BUGFRAME_run_fn ) - { - void (*fn)(struct cpu_user_regs *) = bug_ptr(bug); - fn(regs); - fixup_exception_return(regs, (unsigned long)eip); - return; + switch ( id ) + { + case BUGFRAME_bug: + case BUGFRAME_assert: + if ( debugger_trap_fatal(TRAP_invalid_op, regs) ) + return; } - /* WARN, BUG or ASSERT: decode the filename pointer and line number. */ - filename = bug_ptr(bug); - if ( !is_kernel(filename) && !is_patch(filename) ) + if ( handle_bug_frame(regs, bug, id) ) goto die; - fixup = strlen(filename); - if ( fixup > 50 ) - { - filename += fixup - 47; - prefix = "..."; - } - lineno = bug_line(bug); switch ( id ) { + case BUGFRAME_run_fn: case BUGFRAME_warn: - printk("Xen WARN at %s%s:%d\n", prefix, filename, lineno); - show_execution_state(regs); fixup_exception_return(regs, (unsigned long)eip); return; - - case BUGFRAME_bug: - printk("Xen BUG at %s%s:%d\n", prefix, filename, lineno); - - if ( debugger_trap_fatal(TRAP_invalid_op, regs) ) - return; - - show_execution_state(regs); - panic("Xen BUG at %s%s:%d\n", prefix, filename, lineno); - - case BUGFRAME_assert: - /* ASSERT: decode the predicate string pointer. */ - predicate = bug_msg(bug); - if ( !is_kernel(predicate) && !is_patch(predicate) ) - predicate = ""; - - printk("Assertion '%s' failed at %s%s:%d\n", - predicate, prefix, filename, lineno); - - if ( debugger_trap_fatal(TRAP_invalid_op, regs) ) - return; - - show_execution_state(regs); - panic("Assertion '%s' failed at %s%s:%d\n", - predicate, prefix, filename, lineno); } die: