From nobody Thu May 16 21:43:31 2024 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; dkim=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1677748868; cv=none; d=zohomail.com; s=zohoarc; b=P0qZmVw19ra5K85U14v/2garyqfUniRHsPw/HbQi/HrNf6i/nDOKM2Lc2p7ySGndXLjHiDtI2SWwghFfkvC5w6aMSe/3SkPuwHd5PmuC0Vvpvk6oDqt50e1GGolno6xyRmYTYjGbZO96If/zDglmJVkeUtp8zuf1TpKM6n4LzRs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677748868; h=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=53O6F3Y/lUSSbSaXTtwi3xq/SfW6F0A22Z3VPCt/Nwk=; b=cRJYJ32pfLTJfvr/GipwRaMPDtdt8WjMsFVvPCop+gn99E3uGDklxkhYszQRgV/2V9ueMBsxBuOOE1Cdzv9a9RDHWHHuxMoWfNPMEZZWVbXFlpWiajhoH9Y51fRgBzBogmvlwf9tAPULlPfqGEaL1ZyweR49RUonbUuzZ9us7mo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1677748868326636.1823156676195; Thu, 2 Mar 2023 01:21:08 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.504739.777090 (Exim 4.92) (envelope-from ) id 1pXf79-0007pi-Mn; Thu, 02 Mar 2023 09:20:39 +0000 Received: by outflank-mailman (output) from mailman id 504739.777090; Thu, 02 Mar 2023 09:20:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pXf79-0007oB-GA; Thu, 02 Mar 2023 09:20:39 +0000 Received: by outflank-mailman (input) for mailman id 504739; Thu, 02 Mar 2023 09:20:38 +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 1pXf77-0007lr-Qw for xen-devel@lists.xenproject.org; Thu, 02 Mar 2023 09:20:38 +0000 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [2a00:1450:4864:20::12d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7d78722b-b8db-11ed-96aa-2f268f93b82a; Thu, 02 Mar 2023 10:20:36 +0100 (CET) Received: by mail-lf1-x12d.google.com with SMTP id i28so8507716lfv.0 for ; Thu, 02 Mar 2023 01:20:35 -0800 (PST) Received: from fedora.. (46.204.108.203.nat.umts.dynamic.t-mobile.pl. [46.204.108.203]) by smtp.gmail.com with ESMTPSA id g7-20020a2eb5c7000000b002946be8475esm2018442ljn.135.2023.03.02.01.20.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 01:20:34 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 7d78722b-b8db-11ed-96aa-2f268f93b82a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677748835; 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=53O6F3Y/lUSSbSaXTtwi3xq/SfW6F0A22Z3VPCt/Nwk=; b=m5SBOgVHfAvnjUCU/92VZxJXEzM639zCVG6+jIX8GgOsiGIQM1y5V8SURItoTw0eOw a0HUrPNOh3pMl7/g+TBBPC8vvxiWrs9Y7BJBSpP5MiwQYz3PJasSe/AQ4N4UNizLHx6j D7SvmVR4sxN68Rjyx61PhOxsdwCyIklTXwyG/5CXiOSbBdS6EbNBZpAPCqChqTwmlzme nSD5cShCEStewHH0atQ6MGSi/c6E//MTlBgRtK9MVWcoAXoBrAjznc6EASc2Xaa0uBsO EJY654JnB6TJZalDFLpIDv5g9wr4caJMvf6RlKwanUU7n+itt696piO9ej8PawNs0uHn QfoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677748835; 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=53O6F3Y/lUSSbSaXTtwi3xq/SfW6F0A22Z3VPCt/Nwk=; b=CLce1q3p1tcZBx+cYR6WDIuTAFfySwZ5UQSWR/Igyy+kpB3RKZacPUoFM4ZJ8fUR4P 2vNoytLu8/sjD2RK7+wxjDY0shvPJ4iAQf7/9zIUh87ko95eHU6olfXcKZKsm9avLCAG ZS62BUg2avdzSPAHKJSPp6fOqn2xx6T74MNYrm1rCc86oENLHaLdEI9smYhDkJ2J3HQl 7F1gyZaNE6vMmhYtQ+zuLo8GtEk0UPmGNQe7uXjWjTqRW2Tmxb/jwmYMfJG0KKnW2WDK pY/NUZEurWk0SHcTPVu9Lsnld0bKVgzCsV3puKabsYw0byjPvJKpGPcPMA9NlsMBGXgX AQyA== X-Gm-Message-State: AO0yUKXlCK49WeaT+a1YWSRwA3bmFGlRk98r+hH68Drp0Q1QetoRZROd KEQaGI4naxBymJIyAxtlAsL8n0V3Ddg= X-Google-Smtp-Source: AK7set/9i2sCPg4ML36hUgcejeZLbMX4LRGA4E06Jm3W+f+nhZSlcqOU17IGst+xMEtLhW0U1FXNoA== X-Received: by 2002:ac2:5325:0:b0:4db:2876:f9aa with SMTP id f5-20020ac25325000000b004db2876f9aamr2470945lfh.68.1677748835068; Thu, 02 Mar 2023 01:20:35 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Julien Grall , Jan Beulich , Andrew Cooper , Stefano Stabellini , Oleksii Kurochko , George Dunlap , Wei Liu Subject: [PATCH v4 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME Date: Thu, 2 Mar 2023 11:20:25 +0200 Message-Id: <87aead3acad38f3ce31990ccbbf3076c8cf32762.1677747527.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1677748869365100003 Content-Type: text/plain; charset="utf-8" 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 The following changes were done in comparison with x86 implementation of bug.h: * Add inclusion of arch-specific header * Rename the guard and remove x86 specific changes * Wrap macros BUG_FRAME/run_in_exception_handler/WARN/BUG/assert_failed into #ifndef "BUG_FRAME/run_in_exception_handler/WARN/BUG/assert_failed" thereby each architecture can override the generic implementation of mac= ros. * Add #if{n}def __ASSEMBLY__ ... #endif * Introduce BUG_FRAME_STRUCTURE define to be able to change the structure = of bug frame and macros (bug_*()) related to the 'struct bug_frame' * Introduce BUG_INSTR and BUG_ASM_CONST to make _ASM_BUGFRAME_TEXT reusabl= e between architectures * Make macros related to bug frame structure more generic. Signed-off-by: Oleksii Kurochko --- Changes in V4: * common/bug.c: - Use BUG_DEBUGGER_TRAP_FATAL(regs) mnacros instead of debugger_trap_fata= l(TRAP_invalid_op, regs) in as TRAP_invalid_op is x86-specific thereby BUG_DEBUGG= ER_TRAP_FATAL should be defined for each architecture. - add information about what do_bug_frame() returns. - invert the condition 'if ( region )' in do_bug_frame() to reduce the in= dention. - change type of variable i from 'unsigned int' to 'size_t' as it is com= pared with n_bugs which has type 'size_t' * xen/bug.h: - Introduce generic BUG_DEBUGGER_TRAP_FATAL(regs) mnacros which is used t= o deal with=20 debugger_trap_fatal(TRAP_invalid_op, regs) where TRAP_invalid_op is x86= -specific - remove '#include ' as it doesn't need any more after s= witch to x86 implementation. - remove '#include ' as it isn't needed any more - move bug_*() macros inside '#ifndef BUG_FRAME_STRUCT' - add to fix compile issue with BUILD_ON()... - Add documentation for BUG_ASM_CONST. * Update the commit message --- Changes in V3: * Add debugger_trap_fatal() to do_bug_frame(). It simplifies usage of do_bug_frame() for x86 so making handle_bug_frame() and find_bug_frame() not needed anymore. * Update do_bug_frame() to return -EINVAL if something goes wrong; otherwi= se id of bug_frame * Update _ASM_BUGFRAME_TEXT to make it more portable. * Drop unnecessary comments. * define stub value for TRAP_invalid_op in case if wasn't defined in arch-specific folders. --- 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_fra= me() functions to make it reusable by x86. - code style fixes --- xen/common/Kconfig | 3 + xen/common/Makefile | 1 + xen/common/bug.c | 107 ++++++++++++++++++++++++++++ xen/include/xen/bug.h | 158 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 269 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 =20 +config GENERIC_BUG_FRAME + bool + config HAS_ALTERNATIVE bool =20 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) +=3D argo.o obj-y +=3D bitmap.o +obj-$(CONFIG_GENERIC_BUG_FRAME) +=3D bug.o obj-$(CONFIG_HYPFS_CONFIG) +=3D config_data.o obj-$(CONFIG_CORE_PARKING) +=3D core_parking.o obj-y +=3D cpu.o diff --git a/xen/common/bug.c b/xen/common/bug.c new file mode 100644 index 0000000000..290f4fcc8b --- /dev/null +++ b/xen/common/bug.c @@ -0,0 +1,107 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/* + * Returns a negative value in case of an error otherwise the bug type. + */ +int do_bug_frame(struct cpu_user_regs *regs, unsigned long pc) +{ + const struct bug_frame *bug =3D NULL; + const struct virtual_region *region; + const char *prefix =3D "", *filename, *predicate; + unsigned long fixup; + unsigned int id =3D BUGFRAME_NR, lineno; + + region =3D find_text_region(pc); + if ( !region ) + return -EINVAL; + + for ( id =3D 0; id < BUGFRAME_NR; id++ ) + { + const struct bug_frame *b; + size_t i; + + for ( i =3D 0, b =3D region->frame[id].bugs; + i < region->frame[id].n_bugs; b++, i++ ) + { + if ( bug_loc(b) =3D=3D pc ) + { + bug =3D b; + goto found; + } + } + } + + found: + if ( !bug ) + return -EINVAL; + + if ( id =3D=3D BUGFRAME_run_fn ) + { +#ifdef BUG_FN_REG + void (*fn)(const struct cpu_user_regs *) =3D (void *)regs->BUG_FN_= REG; +#else + void (*fn)(const struct cpu_user_regs *) =3D bug_ptr(bug); +#endif + + fn(regs); + + return id; + } + + /* WARN, BUG or ASSERT: decode the filename pointer and line number. */ + filename =3D bug_ptr(bug); + if ( !is_kernel(filename) && !is_patch(filename) ) + return -EINVAL; + fixup =3D strlen(filename); + if ( fixup > 50 ) + { + filename +=3D fixup - 47; + prefix =3D "..."; + } + lineno =3D bug_line(bug); + + switch ( id ) + { + case BUGFRAME_warn: + printk("Xen WARN at %s%s:%d\n", prefix, filename, lineno); + show_execution_state(regs); + + return id; + + case BUGFRAME_bug: + printk("Xen BUG at %s%s:%d\n", prefix, filename, lineno); + + if ( BUG_DEBUGGER_TRAP_FATAL(regs) ) + return id; + + 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 =3D bug_msg(bug); + if ( !is_kernel(predicate) && !is_patch(predicate) ) + predicate =3D ""; + + printk("Assertion '%s' failed at %s%s:%d\n", + predicate, prefix, filename, lineno); + + if ( BUG_DEBUGGER_TRAP_FATAL(regs) ) + return id; + + show_execution_state(regs); + panic("Assertion '%s' failed at %s%s:%d\n", + predicate, prefix, filename, lineno); + } + + return id; +} diff --git a/xen/include/xen/bug.h b/xen/include/xen/bug.h new file mode 100644 index 0000000000..722ec5c23b --- /dev/null +++ b/xen/include/xen/bug.h @@ -0,0 +1,158 @@ +#ifndef __XEN_BUG_H__ +#define __XEN_BUG_H__ + +#define BUGFRAME_run_fn 0 +#define BUGFRAME_warn 1 +#define BUGFRAME_bug 2 +#define BUGFRAME_assert 3 + +#define BUGFRAME_NR 4 + +#ifndef BUG_FRAME_STRUCT +#define BUG_DISP_WIDTH 24 +#define BUG_LINE_LO_WIDTH (31 - BUG_DISP_WIDTH) +#define BUG_LINE_HI_WIDTH (31 - BUG_DISP_WIDTH) +#endif + +#include + +#ifndef BUG_DEBUGGER_TRAP_FATAL +#define BUG_DEBUGGER_TRAP_FATAL(regs) 0 +#endif + +#ifndef __ASSEMBLY__ + +#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[]; +}; + +#define bug_loc(b) ((unsigned long)(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]) + +#endif /* BUG_FRAME_STRUCT */ + +/* + * Generic implementation has been based on x86 implementation where + * '%c' to deal with punctation sign ($, # depending on architecture) + * before immediate. + * + * Not all architecture's compilers have full support of '%c' and not for = all + * assemblers punctation sign is used before immediate. + * Thereby it was decided to introduce BUG_ASM_CONST. + */ +#ifndef BUG_ASM_CONST +#define BUG_ASM_CONST "" +#endif + +#if !defined(_ASM_BUGFRAME_TEXT) || !defined(_ASM_BUGFRAME_INFO) + +#define _ASM_BUGFRAME_TEXT(second_frame) = \ + ".Lbug%=3D:"BUG_INSTR"\n" = \ + " .pushsection .bug_frames.%"BUG_ASM_CONST"[bf_type], \"a\", %%progb= its\n" \ + " .p2align 2\n" = \ + ".Lfrm%=3D:\n" = \ + " .long (.Lbug%=3D - .Lfrm%=3D) + %"BUG_ASM_CONST"[bf_line_hi]\n" = \ + " .long (%"BUG_ASM_CONST"[bf_ptr] - .Lfrm%=3D) + %"BUG_ASM_CONST"[bf= _line_lo]\n"\ + " .if " #second_frame "\n" = \ + " .long 0, %"BUG_ASM_CONST"[bf_msg] - .Lfrm%=3D\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) + +#endif /* _ASM_BUGFRAME_TEXT || _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) >=3D 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) =3D=3D (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 + +#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; + +/* + * Returns a negative value in case of an error otherwise the bug type. + */ +int do_bug_frame(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[]; + +#endif /* !__ASSEMBLY__ */ + +#endif /* __XEN_BUG_H__ */ +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.39.0 From nobody Thu May 16 21:43:31 2024 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; dkim=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1677748870; cv=none; d=zohomail.com; s=zohoarc; b=dJhRzJyqsp7BvytibKLbqwWIC8EzZJ5DZQhsrnaBmZ0zaxQO/8UPAQ9gHTDCtO6q+5DzvDzNtk8nX4kZBfKVabAmBOEKYCyY5af9BNshPZ1Begp6oYLquJiE2Wq3DxzE5XFOS9X5mmzXeh/vxwE/1G3Q1BNZ+ul3s1m0qcNrQqg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677748870; h=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=1Waw8pBXblK+xZc6vswBktKkR2DVB9FDOMeQq9ioH4E=; b=Lfgu1sy/Kw7w+SeheJ+yNrx93inwCFic7abdaHB+kg+Gb/aVpV71sFGmvw3tSFSocwkHLmmSqNnc8MplmgdTlvTtRIS9pg08XilIA6tsQ/32JgWZ1OA3iDqdFYW+/Pa6+xSWknevOdCMODGfJ49sXzFUSV+UI4dxcp/Cj5w8b5s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1677748870102473.24925076419265; Thu, 2 Mar 2023 01:21:10 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.504740.777104 (Exim 4.92) (envelope-from ) id 1pXf7B-0008GF-2t; Thu, 02 Mar 2023 09:20:41 +0000 Received: by outflank-mailman (output) from mailman id 504740.777104; Thu, 02 Mar 2023 09:20:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pXf7A-0008G8-Uw; Thu, 02 Mar 2023 09:20:40 +0000 Received: by outflank-mailman (input) for mailman id 504740; Thu, 02 Mar 2023 09:20:39 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pXf78-0007lq-V8 for xen-devel@lists.xenproject.org; Thu, 02 Mar 2023 09:20:39 +0000 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [2a00:1450:4864:20::236]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7e169d6e-b8db-11ed-a550-8520e6686977; Thu, 02 Mar 2023 10:20:37 +0100 (CET) Received: by mail-lj1-x236.google.com with SMTP id y14so16896179ljq.4 for ; Thu, 02 Mar 2023 01:20:37 -0800 (PST) Received: from fedora.. (46.204.108.203.nat.umts.dynamic.t-mobile.pl. [46.204.108.203]) by smtp.gmail.com with ESMTPSA id g7-20020a2eb5c7000000b002946be8475esm2018442ljn.135.2023.03.02.01.20.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 01:20:36 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 7e169d6e-b8db-11ed-a550-8520e6686977 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677748836; 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=1Waw8pBXblK+xZc6vswBktKkR2DVB9FDOMeQq9ioH4E=; b=jD/sJ3fX1ZQEmzUegARf5sCcr4BHt3w57fF0l2sqRqmELn+egrLWYc57LhWBpIf+0m D4ix54rHtbTlwWKSJllBxLzfOY5I6HFjwdHYCkUgNHkD5ZN9Rd/7coZSML3edlfBZ8/h NPC3C2PRysVfj/lAs5JVXCh3xSeCI1++tzOJNyjwI8YHu9B0fpj78Sm0DjVgDJ5SQZDs 7vl/jLrVRuxrNt52O3/X+cn6Rve0j3alJfAk/HNFZ8Xh3wgaWX9l9ST04J8hWAebZXmg MRSReRd1egytau2nwGzfHz/jxUTw5WYb22lX7T/GsWmqV9v2gmAyZXsa8C69BNdyskJE ohow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677748836; 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=1Waw8pBXblK+xZc6vswBktKkR2DVB9FDOMeQq9ioH4E=; b=UPaWzrVReC8CmWwgyrdlHp0zY5H0BDLw7eSwJEcdRzjPYN+KQATRTM5uLpRfY/SqZn UgXrCaHroljmSi7KxZN5YaluY7jiTRpVoyq7StmdPitjrN8khDHpWCKNtzgE8JBtF42P tug/Z4rdz9uzIcexCmSANrjJBuawlqcW0emjtBH9lzO1s6csVyg75IggF8ap/VFcecjx wLarccqbTMK7Ksbh1kbnyB88yk+5CZGScZM1xeJHtJDYuBi6Z8V53mjiwj/rEAZnDMa4 maGP8QBaHEJyIsDO5NGrZzbQToMj3dePYFP3gUgfmlZhydsafhwIDRBwim1tp5FMqFeA DYKg== X-Gm-Message-State: AO0yUKWfGi3XHuJRwtZngx1iOkdWeSS73WQR9y6IwMMLqaC+nlkyI9IC JH1lJH00Tt/z84Du1Of5mNpwjY9TKVY= X-Google-Smtp-Source: AK7set8zoA9Df/E9ozpTWURcy/nv4HyMYrsSvPmGf6TrUsZ2mvz1m0P9tgiMRQ/QExJInckVTwa9hA== X-Received: by 2002:a2e:9e94:0:b0:295:93eb:1c01 with SMTP id f20-20020a2e9e94000000b0029593eb1c01mr2982466ljk.25.1677748836505; Thu, 02 Mar 2023 01:20:36 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Julien Grall , Jan Beulich , Andrew Cooper , Stefano Stabellini , Oleksii Kurochko , Bertrand Marquis , Volodymyr Babchuk , George Dunlap , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v4 2/4] xen: change to Date: Thu, 2 Mar 2023 11:20:26 +0200 Message-Id: <147cddf155d738bd5ed3023bb5152ce95a73c21d.1677747527.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1677748871399100001 Content-Type: text/plain; charset="utf-8" The idea of the patch is to change all to and keep Xen compilable with adding only minimal amount of changes: 1. It was added "#include " to ARM's "" as it uses uint_{16,32}t in 'struct bug_frame'. 2. It was added '#define BUG_FRAME_STRUCT' which means that ARM hasn't been switched to generic implementation yet. 3. It was added '#define BUG_FRAME_STRUCT' which means that x86 hasn't been switched to generic implementation yet. 4. BUGFRAME_* and _start_bug_frame[], _stop_bug_frame_*[] were removed for ARM & x86 to deal with compilation errors such as: redundant redeclaration of ... In the following two patches x86 and ARM archictectures will be switched fully: * xen/arm: switch ARM to use generic implementation of bug.h * xen/x86: switch x86 to use generic implemetation of bug.h Signed-off-by: Oleksii Kurochko --- Changes in V4: - defines BUG_DISP_WIDTH, BUG_LINE_LO_WIDTH, BUG_LINE_HI_WIDTH were moved = into "ifndef BUG_FRAME_STRUCT" in as they are specific for 'struc= t bug_frame' and so should co-exist together. So the defines were back to until BUG_FRA= ME_STRUCT will be defined in . - Update the comment message. --- Changes in V3: * Update patch 2 not to break compilation: move some parts from patches 3 = and 4 to patch 2: * move some generic parts from to * add define BUG_FRAME_STRUCT in ARM's --- Changes in V2: * Put [PATCH v1 4/4] xen: change to as second patc= h, update the patch to change all to among the whol= e project to not break build. * Update the commit message. --- xen/arch/arm/include/asm/bug.h | 17 ++++------------- 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/arch/x86/include/asm/bug.h | 15 ++------------- xen/drivers/cpufreq/cpufreq.c | 2 +- xen/include/xen/lib.h | 2 +- 9 files changed, 13 insertions(+), 33 deletions(-) diff --git a/xen/arch/arm/include/asm/bug.h b/xen/arch/arm/include/asm/bug.h index f4088d0913..9315662c6e 100644 --- a/xen/arch/arm/include/asm/bug.h +++ b/xen/arch/arm/include/asm/bug.h @@ -1,6 +1,8 @@ #ifndef __ARM_BUG_H__ #define __ARM_BUG_H__ =20 +#include + #if defined(CONFIG_ARM_32) # include #elif defined(CONFIG_ARM_64) @@ -13,6 +15,8 @@ #define BUG_LINE_LO_WIDTH (31 - BUG_DISP_WIDTH) #define BUG_LINE_HI_WIDTH (31 - BUG_DISP_WIDTH) =20 +#define BUG_FRAME_STRUCT + struct bug_frame { signed int loc_disp; /* Relative address to the bug address */ signed int file_disp; /* Relative address to the filename */ @@ -26,13 +30,6 @@ struct bug_frame { #define bug_line(b) ((b)->line) #define bug_msg(b) ((const char *)(b) + (b)->msg_disp) =20 -#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 @@ -89,12 +86,6 @@ struct bug_frame { unreachable(); \ } while (0) =20 -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/div64.h b/xen/arch/arm/include/asm/di= v64.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 @@ =20 #elif __GNUC__ >=3D 4 =20 -#include +#include =20 /* * 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 @@ */ =20 #include -#include #include +#include #include #include =20 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 . */ =20 +#include #include #include -#include #include #include =20 diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufre= q/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 @@ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~~~ */ =20 +#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/as= m/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/arch/x86/include/asm/bug.h b/xen/arch/x86/include/asm/bug.h index b7265bdfbe..79133e53e7 100644 --- a/xen/arch/x86/include/asm/bug.h +++ b/xen/arch/x86/include/asm/bug.h @@ -5,15 +5,10 @@ #define BUG_LINE_LO_WIDTH (31 - BUG_DISP_WIDTH) #define BUG_LINE_HI_WIDTH (31 - BUG_DISP_WIDTH) =20 -#define BUGFRAME_run_fn 0 -#define BUGFRAME_warn 1 -#define BUGFRAME_bug 2 -#define BUGFRAME_assert 3 - -#define BUGFRAME_NR 4 - #ifndef __ASSEMBLY__ =20 +#define BUG_FRAME_STRUCT + struct bug_frame { signed int loc_disp:BUG_DISP_WIDTH; unsigned int line_hi:BUG_LINE_HI_WIDTH; @@ -80,12 +75,6 @@ struct bug_frame { unreachable(); \ } while (0) =20 -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__ */ =20 /* 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 @@ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~~~ */ =20 +#include #include #include #include @@ -39,7 +40,6 @@ #include #include #include -#include #include #include =20 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 @@ =20 #ifndef __ASSEMBLY__ =20 +#include #include #include #include #include #include -#include =20 #define BUG_ON(p) do { if (unlikely(p)) BUG(); } while (0) #define WARN_ON(p) ({ \ --=20 2.39.0 From nobody Thu May 16 21:43:31 2024 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; dkim=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1677748874; cv=none; d=zohomail.com; s=zohoarc; b=iLqDzGkORX4tW075ezb6Bo08iXa/l6TiZjZQtICeGjYbJzkpjvl5enXmPSKYkZ0RupUSMkFPtRS+/R0oYmvFCNyZ/Im3XIiB0D9hcEwnNeOlEvCpb7sHTXMqZxSPcq3Vwb5aBpwZlGQ4WbyqEBeGP55VLqdIFS3ZW/XoDv242/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677748874; h=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=dM/RkD/avfzVVu0C/hvbwQrGX6kwBtF555pillP6hiE=; b=grMrLKHMr7XjbsLaMDXkjjdf7qpnMSXh+nuV9z1g43XeyF7D/UsTTItI+5shNBQYHszSCXWRLVOeYSVeZ42n1Gh/8PlkjUQMyDX2e9VaULmHgih6D5eP6gZIIqLyvFU6Ld7tp3/rriFGs+RrXyoVPY4cK141oLaU+OT3aohYs2M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1677748874559609.6724888032303; Thu, 2 Mar 2023 01:21:14 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.504741.777108 (Exim 4.92) (envelope-from ) id 1pXf7B-0008JO-9X; Thu, 02 Mar 2023 09:20:41 +0000 Received: by outflank-mailman (output) from mailman id 504741.777108; Thu, 02 Mar 2023 09:20:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pXf7B-0008I7-5p; Thu, 02 Mar 2023 09:20:41 +0000 Received: by outflank-mailman (input) for mailman id 504741; Thu, 02 Mar 2023 09:20:39 +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 1pXf79-0007lr-LC for xen-devel@lists.xenproject.org; Thu, 02 Mar 2023 09:20:39 +0000 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [2a00:1450:4864:20::22a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7f1fb397-b8db-11ed-96aa-2f268f93b82a; Thu, 02 Mar 2023 10:20:38 +0100 (CET) Received: by mail-lj1-x22a.google.com with SMTP id z5so16885279ljc.8 for ; Thu, 02 Mar 2023 01:20:38 -0800 (PST) Received: from fedora.. (46.204.108.203.nat.umts.dynamic.t-mobile.pl. [46.204.108.203]) by smtp.gmail.com with ESMTPSA id g7-20020a2eb5c7000000b002946be8475esm2018442ljn.135.2023.03.02.01.20.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 01:20:37 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 7f1fb397-b8db-11ed-96aa-2f268f93b82a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677748838; 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=dM/RkD/avfzVVu0C/hvbwQrGX6kwBtF555pillP6hiE=; b=RA2mJU0DAf226UrKgzi7XezZgh1dtD2TWYqMLlwyWLKwXfI5NCc464PEte8CTua1YT 4nCfU1AJogxCtQkVCfOrDWZ7aN6LGdxrALfTDbVgzEt5ueLrt3eJqHKsBVHa7xJgY1jS PwOvtGc5p4dZESr9Ey2P9M5Z5Ek3rstyTbHQwY7ozJDTtVoibUMHsemaIXEw+3TMfaTN jJTW4xMzCLJxZnFyszBcmWHXR48DZWvYoDXxNpbplhRRjtJTRzNDisk18Jd3Frp1GvoQ N4vSbjuvG/aGDjN2B7Ozylcf+pISeXEwOnCIgHYqxrFNoZlvvXzxP37hsgRqZnfmrtAX oOVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677748838; 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=dM/RkD/avfzVVu0C/hvbwQrGX6kwBtF555pillP6hiE=; b=e2kHH+Qi3JIr2o7SMcfgZ1U7itnGEzDmOTN9KBDyS6VKzfkFR/zG2DrI4jE+TCnHTK tejKAVlCr9gXF/0vpYESsSTLUQispKNgzH4ZeBWxEb24I4wSaXdJp/vkibZELEXGyicA L/AOx3st4Vy0Ao1/ZdkmLZCuctNUIN5/d7Xc+t9pYfHT3TEh6QHW8Mn8K9GrY6HxofnQ a5iEz/pn9TnZ1tCd6QhNldvQBi1NOdU5vnwXybb893Sy0HcgwCusYGQC6v+prGyKlxUc F6V4t2fHRKlYZ7wR5E1nvTbCd9pOogYrU68mAV7jEJSwG91tkJYIfbkVsVjGiCXN5+iA PThw== X-Gm-Message-State: AO0yUKX5OIo2WWirv/iX1hNN5cXCDGQO7HZDREVJJxqTalFKQGZIDAGp 5rS8KqDCxm1wHRFYN7jcRzujThBAu8E= X-Google-Smtp-Source: AK7set/mKnWUyffQvM5R/vyp3h0pXHy7dkX8lDS+Y/SbHC6tneNJClqyK8WL1MnId8D/VrgfnR6eRw== X-Received: by 2002:a2e:7d0a:0:b0:295:9be0:212b with SMTP id y10-20020a2e7d0a000000b002959be0212bmr2993371ljc.8.1677748838135; Thu, 02 Mar 2023 01:20:38 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Julien Grall , Jan Beulich , Andrew Cooper , Stefano Stabellini , Oleksii Kurochko , Bertrand Marquis , Volodymyr Babchuk , George Dunlap , Wei Liu Subject: [PATCH v4 3/4] xen/arm: switch ARM to use generic implementation of bug.h Date: Thu, 2 Mar 2023 11:20:27 +0200 Message-Id: X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1677748875379100001 Content-Type: text/plain; charset="utf-8" The following changes were made: * make GENERIC_BUG_FRAME mandatory for ARM * As do_bug_frame() returns -EINVAL in case something goes wrong otherwise id of bug frame. Thereby 'if' cases where do_bug_frame() was updated to check if the returned value is less than 0 * Switch ARM's implementation of bug.h macros to generic one Signed-off-by: Oleksii Kurochko --- Changes in V4: * Switch ARM implementation to generic one * Remove BUG_FN_REG from arm{16,32}/bug.h as it isn't needed after switch = to generic implementation * Update commit message --- Changes in V3: * As prototype and what do_bug_frame() returns was changed so patch 3 and 4 was updated to use a new version of do_bug_frame --- 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/arm32/traps.c | 2 +- xen/arch/arm/include/asm/arm32/bug.h | 2 - xen/arch/arm/include/asm/arm64/bug.h | 2 - xen/arch/arm/include/asm/bug.h | 75 +------------------------- xen/arch/arm/include/asm/traps.h | 2 - xen/arch/arm/traps.c | 81 +--------------------------- xen/common/bug.c | 4 -- 8 files changed, 4 insertions(+), 165 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 =20 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/arm32/traps.c b/xen/arch/arm/arm32/traps.c index a2fc1c22cb..61c61132c7 100644 --- a/xen/arch/arm/arm32/traps.c +++ b/xen/arch/arm/arm32/traps.c @@ -48,7 +48,7 @@ void do_trap_undefined_instruction(struct cpu_user_regs *= regs) if ( instr !=3D BUG_OPCODE ) goto die; =20 - if ( do_bug_frame(regs, pc) ) + if ( do_bug_frame(regs, pc) < 0 ) goto die; =20 regs->pc +=3D 4; diff --git a/xen/arch/arm/include/asm/arm32/bug.h b/xen/arch/arm/include/as= m/arm32/bug.h index 25cce151dc..3e66f35969 100644 --- a/xen/arch/arm/include/asm/arm32/bug.h +++ b/xen/arch/arm/include/asm/arm32/bug.h @@ -10,6 +10,4 @@ =20 #define BUG_INSTR ".word " __stringify(BUG_OPCODE) =20 -#define BUG_FN_REG r0 - #endif /* __ARM_ARM32_BUG_H__ */ diff --git a/xen/arch/arm/include/asm/arm64/bug.h b/xen/arch/arm/include/as= m/arm64/bug.h index 5e11c0dfd5..59f664d7de 100644 --- a/xen/arch/arm/include/asm/arm64/bug.h +++ b/xen/arch/arm/include/asm/arm64/bug.h @@ -6,6 +6,4 @@ =20 #define BUG_INSTR "brk " __stringify(BRK_BUG_FRAME_IMM) =20 -#define BUG_FN_REG x0 - #endif /* __ARM_ARM64_BUG_H__ */ diff --git a/xen/arch/arm/include/asm/bug.h b/xen/arch/arm/include/asm/bug.h index 9315662c6e..1d87533044 100644 --- a/xen/arch/arm/include/asm/bug.h +++ b/xen/arch/arm/include/asm/bug.h @@ -11,80 +11,7 @@ # error "unknown ARM variant" #endif =20 -#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 */ - signed int file_disp; /* Relative address to the filename */ - signed int msg_disp; /* Relative address to the predicate (for ASSE= RT) */ - uint16_t line; /* Line number */ - 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_line(b) ((b)->line) -#define bug_msg(b) ((const char *)(b) + (b)->msg_disp) - -/* 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 - * Xen image. BUGFRAME_run_fn needs to be handled separately. - */ -#define BUG_FRAME(type, line, file, has_msg, msg) do { = \ - BUILD_BUG_ON((line) >> 16); = \ - BUILD_BUG_ON((type) >=3D BUGFRAME_NR); = \ - asm ("1:"BUG_INSTR"\n" = \ - ".pushsection .rodata.str, \"aMS\", %progbits, 1\n" = \ - "2:\t.asciz " __stringify(file) "\n" = \ - "3:\n" = \ - ".if " #has_msg "\n" = \ - "\t.asciz " #msg "\n" = \ - ".endif\n" = \ - ".popsection\n" = \ - ".pushsection .bug_frames." __stringify(type) ", \"a\", %progbits= \n"\ - "4:\n" = \ - ".p2align 2\n" = \ - ".long (1b - 4b)\n" = \ - ".long (2b - 4b)\n" = \ - ".long (3b - 4b)\n" = \ - ".hword " __stringify(line) ", 0\n" = \ - ".popsection"); = \ -} while (0) - -/* - * GCC will not allow to use "i" when PIE is enabled (Xen doesn't set the - * flag but instead rely on the default value from the compiler). So the - * easiest way to implement run_in_exception_handler() is to pass the to - * be called function in a fixed register. - */ -#define run_in_exception_handler(fn) do { = \ - asm ("mov " __stringify(BUG_FN_REG) ", %0\n" = \ - "1:"BUG_INSTR"\n" = \ - ".pushsection .bug_frames." __stringify(BUGFRAME_run_fn) "," = \ - " \"a\", %%progbits\n" = \ - "2:\n" = \ - ".p2align 2\n" = \ - ".long (1b - 2b)\n" = \ - ".long 0, 0, 0\n" = \ - ".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) +#define BUG_ASM_CONST "c" =20 #endif /* __ARM_BUG_H__ */ /* diff --git a/xen/arch/arm/include/asm/traps.h b/xen/arch/arm/include/asm/tr= aps.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 hs= r); void do_trap_smc(struct cpu_user_regs *regs, const union hsr hsr); void do_trap_hvc_smccc(struct cpu_user_regs *regs); =20 -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..9c6eb66422 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 struc= t cpu_user_regs *regs) panic("CPU%d: Unexpected Trap: %s\n", smp_processor_id(), msg); } =20 -int do_bug_frame(const struct cpu_user_regs *regs, vaddr_t pc) -{ - const struct bug_frame *bug =3D NULL; - const char *prefix =3D "", *filename, *predicate; - unsigned long fixup; - int id =3D -1, lineno; - const struct virtual_region *region; - - region =3D find_text_region(pc); - if ( region ) - { - for ( id =3D 0; id < BUGFRAME_NR; id++ ) - { - const struct bug_frame *b; - unsigned int i; - - for ( i =3D 0, b =3D region->frame[id].bugs; - i < region->frame[id].n_bugs; b++, i++ ) - { - if ( ((vaddr_t)bug_loc(b)) =3D=3D pc ) - { - bug =3D b; - goto found; - } - } - } - } - found: - if ( !bug ) - return -ENOENT; - - if ( id =3D=3D BUGFRAME_run_fn ) - { - void (*fn)(const struct cpu_user_regs *) =3D (void *)regs->BUG_FN_= REG; - - fn(regs); - return 0; - } - - /* WARN, BUG or ASSERT: decode the filename pointer and line number. */ - filename =3D bug_file(bug); - if ( !is_kernel(filename) ) - return -EINVAL; - fixup =3D strlen(filename); - if ( fixup > 50 ) - { - filename +=3D fixup - 47; - prefix =3D "..."; - } - lineno =3D 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 =3D bug_msg(bug); - if ( !is_kernel(predicate) ) - predicate =3D ""; - - 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) { @@ -1292,7 +1213,7 @@ static void do_trap_brk(struct cpu_user_regs *regs, c= onst union hsr hsr) switch ( hsr.brk.comment ) { case BRK_BUG_FRAME_IMM: - if ( do_bug_frame(regs, regs->pc) ) + if ( do_bug_frame(regs, regs->pc) < 0 ) goto die; =20 regs->pc +=3D 4; diff --git a/xen/common/bug.c b/xen/common/bug.c index 290f4fcc8b..e636edd85a 100644 --- a/xen/common/bug.c +++ b/xen/common/bug.c @@ -46,11 +46,7 @@ int do_bug_frame(struct cpu_user_regs *regs, unsigned lo= ng pc) =20 if ( id =3D=3D BUGFRAME_run_fn ) { -#ifdef BUG_FN_REG - void (*fn)(const struct cpu_user_regs *) =3D (void *)regs->BUG_FN_= REG; -#else void (*fn)(const struct cpu_user_regs *) =3D bug_ptr(bug); -#endif =20 fn(regs); =20 --=20 2.39.0 From nobody Thu May 16 21:43:31 2024 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; dkim=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1677748866; cv=none; d=zohomail.com; s=zohoarc; b=OWtXBeIlgjHRJhBSbY2GR6qE2SO3kp92kkX6GaCIphSRPlsl0nAS3zQqM2DN7kPgHeDCjY6JhbGoNPUv3NmR6qAnmeZ/Dm6O9vFl+0jwrDvMpE1pc6Zfs9J/1L9jb92G8tBDKnH2fEa4toPnuAyBNF21cFXFUU5FLwK2WJRa9jg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677748866; h=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=uPYrgRCWywkVLO74D9udXA+9/9Qyzd34sCcyyXMkS2Y=; b=QFaXacRk0s5mDiVjgIoNfQSHZ1yRd2OLFDSFApMLXP0G75dvVf8DR+KpwRro90++yEFTCy72JGcxXYQ/P8fwNcZsCDHtG2jfTWEsaIcmU6BeVzyHU5J3x0H/1/0IOg/iyt31S5EfgaQb065enbFd7bDbiHna/huQUVdF5OGPogc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 167774886688234.78628737518795; Thu, 2 Mar 2023 01:21:06 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.504742.777124 (Exim 4.92) (envelope-from ) id 1pXf7C-0000Ku-PX; Thu, 02 Mar 2023 09:20:42 +0000 Received: by outflank-mailman (output) from mailman id 504742.777124; Thu, 02 Mar 2023 09:20:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pXf7C-0000Kj-Lk; Thu, 02 Mar 2023 09:20:42 +0000 Received: by outflank-mailman (input) for mailman id 504742; Thu, 02 Mar 2023 09:20:41 +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 1pXf7B-0007lr-4P for xen-devel@lists.xenproject.org; Thu, 02 Mar 2023 09:20:41 +0000 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [2a00:1450:4864:20::22e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 80341584-b8db-11ed-96aa-2f268f93b82a; Thu, 02 Mar 2023 10:20:40 +0100 (CET) Received: by mail-lj1-x22e.google.com with SMTP id by8so16876931ljb.7 for ; Thu, 02 Mar 2023 01:20:40 -0800 (PST) Received: from fedora.. (46.204.108.203.nat.umts.dynamic.t-mobile.pl. [46.204.108.203]) by smtp.gmail.com with ESMTPSA id g7-20020a2eb5c7000000b002946be8475esm2018442ljn.135.2023.03.02.01.20.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 01:20:39 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 80341584-b8db-11ed-96aa-2f268f93b82a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677748840; 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=uPYrgRCWywkVLO74D9udXA+9/9Qyzd34sCcyyXMkS2Y=; b=kploAvBGBe/Y7GmJwmv32QXnF7m3C9Pu2+IIxr1nhBwSq8xgGfxG8ktGUxxCySmeiJ cmOVrHD2RgFvbcz9XmQCWis5rCXieiO9yNTg468LCQ/QmgkCSznXSy5pseArQ7CyB5ip yGaUxYpHgnI5yr6Vf+374An25kZKs7vHz7384ecv91mDzZznh1W+TDhaektphtr0XC+L Fk6MrJ2XecuXo/l0ZGYfUgbxPZeboT6RW5jzZPIKop1qBG+6OnrRfd3rcO7VjV93k4SM um6+CPkxAbteR0juOtglGK7yUF4hS/yuWCBAruOk0U4A7NOFnSvxYLwjtfE/Ep8HvaM4 cFHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677748840; 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=uPYrgRCWywkVLO74D9udXA+9/9Qyzd34sCcyyXMkS2Y=; b=K5enyWxMcIt11vONE31bqkRVVaJFKHrxHncVwIN+2DSfgjf8tjnRyC8E/rvtTxwWCM fjDO6eKWIGdrcs1+ciIjF8bB3pUauICyvuyjGuwc+NvI5afwZmgSup7Y5+IJnzpjNovj TocTCtx5iKEu/tML9RjkiKoidofhW1d5gnKs4EJAmYZw4kRXGmJKZ621GtS16RQ8gsYZ KS5FLJ5XWc/kBsC4kii9eD7m9P0/i5X6GEqQPfACWwIwIH932fXa6FV6PFdkKcUCl/FZ kLCR5crjfi492YgzPoRq2qZh/jthIA/y9nQ0nKBWvKoYdeBa1DLzVFdcVu2KSh/SYCGO 50EQ== X-Gm-Message-State: AO0yUKWqXZnkP4xQKfSrBh99+pKXcb7k/VmVg/l3yF2WD6xdTcL8lHdX SHkHA877FXhZPsGq/2XngBk//ePhAo4= X-Google-Smtp-Source: AK7set/O0Fwd90V2JfkZtuCYj9I5bhF8RryfFAjvNJxijqs8RJzMTM/gZnNzOjMxD+bKTahOtFwuMQ== X-Received: by 2002:a2e:b55c:0:b0:295:74f5:fcab with SMTP id a28-20020a2eb55c000000b0029574f5fcabmr3081757ljn.39.1677748839886; Thu, 02 Mar 2023 01:20:39 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Julien Grall , Jan Beulich , Andrew Cooper , Stefano Stabellini , Oleksii Kurochko , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v4 4/4] xen/x86: switch x86 to use generic implemetation of bug.h Date: Thu, 2 Mar 2023 11:20:28 +0200 Message-Id: <636d049e3962547dfa793e4878ef2683b12df798.1677747527.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1677748867562100001 Content-Type: text/plain; charset="utf-8" The following changes were made: * Make GENERIC_BUG_FRAME mandatory for X86 * Update asm/bug.h using generic implementation in * Change prototype of debugger_trap_fatal() in asm/debugger.h to align it with generic prototype in . * Update do_invalid_op using generic do_bug_frame() Signed-off-by: Oleksii Kurochko --- Changes in V4: * Back comment /* !__ASSEMBLY__ */ for #else case in * Remove changes related to x86/.../asm/debuger.h as do_bug_frame() protot= ype was updated and cpu_user_regs isn't const any more. --- Changes in V3: * As prototype and what do_bug_frame() returns was changed so patch 3 and 4 was updated to use a new version of do_bug_frame * MODIFIER was change to BUG_ASM_CONST to align with generic implementation --- Changes in V2: * Remove all unnecessary things from as they were introduced = in . * Define BUG_INSTR =3D 'ud2' and MODIFIER =3D '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 | 73 ++---------------------------- xen/arch/x86/traps.c | 81 +++------------------------------- 3 files changed, 11 insertions(+), 144 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 79133e53e7..2a8d3f84b8 100644 --- a/xen/arch/x86/include/asm/bug.h +++ b/xen/arch/x86/include/asm/bug.h @@ -1,79 +1,12 @@ #ifndef __X86_BUG_H__ #define __X86_BUG_H__ =20 -#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_DEBUGGER_TRAP_FATAL(regs) debugger_trap_fatal(X86_EXC_GP,regs) =20 #ifndef __ASSEMBLY__ =20 -#define 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[]; -}; - -#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%=3D: ud2\n" = \ - ".pushsection .bug_frames.%c[bf_type], \"a\", @progbits\n" = \ - ".p2align 2\n" = \ - ".Lfrm%=3D:\n" = \ - ".long (.Lbug%=3D - .Lfrm%=3D) + %c[bf_line_hi]\n" = \ - ".long (%c[bf_ptr] - .Lfrm%=3D) + %c[bf_line_lo]\n" = \ - ".if " #second_frame "\n" = \ - ".long 0, %c[bf_msg] - .Lfrm%=3D\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) >=3D 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) =3D=3D (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) +#define BUG_INSTR "ud2" +#define BUG_ASM_CONST "c" =20 #else /* !__ASSEMBLY__ */ =20 diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index cade9e12f8..7c33ebceff 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -24,6 +24,7 @@ * Gareth Hughes , May 2000 */ =20 +#include #include #include #include @@ -1166,12 +1167,9 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, u= int32_t leaf, =20 void do_invalid_op(struct cpu_user_regs *regs) { - const struct bug_frame *bug =3D NULL; u8 bug_insn[2]; - const char *prefix =3D "", *filename, *predicate, *eip =3D (char *)reg= s->rip; - unsigned long fixup; - int id =3D -1, lineno; - const struct virtual_region *region; + const char *eip =3D (char *)regs->rip; + int id; =20 if ( likely(guest_mode(regs)) ) { @@ -1185,83 +1183,18 @@ void do_invalid_op(struct cpu_user_regs *regs) memcmp(bug_insn, "\xf\xb", sizeof(bug_insn)) ) goto die; =20 - region =3D find_text_region(regs->rip); - if ( region ) - { - for ( id =3D 0; id < BUGFRAME_NR; id++ ) - { - const struct bug_frame *b; - unsigned int i; - - for ( i =3D 0, b =3D region->frame[id].bugs; - i < region->frame[id].n_bugs; b++, i++ ) - { - if ( bug_loc(b) =3D=3D eip ) - { - bug =3D b; - goto found; - } - } - } - } - - found: - if ( !bug ) + id =3D do_bug_frame(regs, regs->rip); + if ( id < 0 ) goto die; - eip +=3D sizeof(bug_insn); - if ( id =3D=3D BUGFRAME_run_fn ) - { - void (*fn)(struct cpu_user_regs *) =3D bug_ptr(bug); - - fn(regs); - fixup_exception_return(regs, (unsigned long)eip); - return; - } =20 - /* WARN, BUG or ASSERT: decode the filename pointer and line number. */ - filename =3D bug_ptr(bug); - if ( !is_kernel(filename) && !is_patch(filename) ) - goto die; - fixup =3D strlen(filename); - if ( fixup > 50 ) - { - filename +=3D fixup - 47; - prefix =3D "..."; - } - lineno =3D bug_line(bug); + eip +=3D sizeof(bug_insn); =20 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 =3D bug_msg(bug); - if ( !is_kernel(predicate) && !is_patch(predicate) ) - predicate =3D ""; - - 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); } =20 die: --=20 2.39.0