From patchwork Fri Mar 3 10:38:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13158641 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 C6EFEC7EE30 for ; Fri, 3 Mar 2023 10:38:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.505812.778771 (Exim 4.92) (envelope-from ) id 1pY2o6-0005zM-Sn; Fri, 03 Mar 2023 10:38:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 505812.778771; Fri, 03 Mar 2023 10:38:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pY2o6-0005zF-PS; Fri, 03 Mar 2023 10:38:34 +0000 Received: by outflank-mailman (input) for mailman id 505812; Fri, 03 Mar 2023 10:38:33 +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 1pY2o5-0005jk-0V for xen-devel@lists.xenproject.org; Fri, 03 Mar 2023 10:38:33 +0000 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [2a00:1450:4864:20::235]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8a6857bb-b9af-11ed-a550-8520e6686977; Fri, 03 Mar 2023 11:38:31 +0100 (CET) Received: by mail-lj1-x235.google.com with SMTP id by8so1845781ljb.7 for ; Fri, 03 Mar 2023 02:38:31 -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 d11-20020ac25ecb000000b004cb3a55feacsm338760lfq.100.2023.03.03.02.38.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Mar 2023 02:38:30 -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: 8a6857bb-b9af-11ed-a550-8520e6686977 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677839910; 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=z0btyJLxCS4oC/gYXylIv4FuqUMmEv/UhCtI0T1c0CE=; b=UsYVgGWdzpwcN/sQurakmDzwejOeY5cEuqHxomNZzZzQZdxEcq4TRTNs2KhH7ISfrI Z8S/g7epjrUW0/i2BBljpvnhHTeDkJyrubVwB3tbLFfG56Db4f/xoEU+7HIXkpKQN8dC uRbndhE1J09yFLCo7mBCj2QebJAJxp7ssR0AOB1NlNjKFvLB0IjZAY6U/AmPkThrNTAF TOP4tgyUj3sRJQmyGSc6n4Y28NASWwsItSqHJmdaSlorXzACJuw3WoqY/oPRVAyawXUL llfdfdxflySqULDwwTEyiFsTMe5vQLneO5pfuclXV/MGvS/AhPgAft4yQGdXnDTCChdN eiHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677839910; 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=z0btyJLxCS4oC/gYXylIv4FuqUMmEv/UhCtI0T1c0CE=; b=UZXUJihwIElInsRnQtb7rv00gDaaR/0t7U9KvJ2KRkI5V7s+FhZ/+Y/t8TLS85yXRU uqV3zhx0/ecfhQmzGKJrLqfounYKu/xDYmo7e8sKL0RpsKlqH4CvFhV8DSSYZOLuIt4r XOuqr5CKiI0l3xNd5YGaE92HW93yFxz82SbnYqDcx9xJMsjlRLJlyasdusz/T/k+coJP 4QOecYobCUN2tdrKfDzi5Lhw3/2gxovlpSF7rAku1G7JBusuHkAZxhN3CGXcnhxSyZMD yPlxuNuhie2fats9emE+Oc8Z8KIWg3zFVzKSc63xxaxaRtkCnTN0SvR0Kz3FcaCuU+zq jqrw== X-Gm-Message-State: AO0yUKVFyfrHjytJ034SP9x04ul08wfWmZ9rtHEJAs3svMgzmcYLkuJQ OLXzSjCtye6BAV8CJDzO5qwAcBhlu+U= X-Google-Smtp-Source: AK7set94tuJDuHpOxMQSgFl62vtMemMA5N+hFm1GFapBKWd8m7NVKeGzA+MYzHT++TRnzgXDLdk2cA== X-Received: by 2002:a2e:9b16:0:b0:295:a542:8b47 with SMTP id u22-20020a2e9b16000000b00295a5428b47mr447905lji.8.1677839910377; Fri, 03 Mar 2023 02:38:30 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Julien Grall , Jan Beulich , Andrew Cooper , Stefano Stabellini , Gianluca Guida , Oleksii Kurochko , George Dunlap , Wei Liu Subject: [PATCH v5 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME Date: Fri, 3 Mar 2023 12:38:22 +0200 Message-Id: <5cd3dd5233cf41ad54ce1cd98b706085b95bfcee.1677839409.git.oleksii.kurochko@gmail.com> 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 V5: * Remove "#ifdef BUG_FN_REG..." from generic do_bug_frame() as ARM will use generic implementation fully. --- Changes in V4: * common/bug.c: - Use BUG_DEBUGGER_TRAP_FATAL(regs) mnacros instead of debugger_trap_fatal(TRAP_invalid_op, regs) in as TRAP_invalid_op is x86-specific thereby BUG_DEBUGGER_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 indention. - change type of variable i from 'unsigned int' to 'size_t' as it is compared with n_bugs which has type 'size_t' * xen/bug.h: - Introduce generic BUG_DEBUGGER_TRAP_FATAL(regs) mnacros which is used to deal with debugger_trap_fatal(TRAP_invalid_op, regs) where TRAP_invalid_op is x86-specific - remove '#include ' as it doesn't need any more after switch 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; otherwise 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_frame() functions to make it reusable by x86. - code style fixes --- xen/common/Kconfig | 3 + xen/common/Makefile | 1 + xen/common/bug.c | 103 +++++++++++++++++++++++++++ xen/include/xen/bug.h | 158 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 265 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..e636edd85a --- /dev/null +++ b/xen/common/bug.c @@ -0,0 +1,103 @@ +#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 = NULL; + const struct virtual_region *region; + const char *prefix = "", *filename, *predicate; + unsigned long fixup; + unsigned int id = BUGFRAME_NR, lineno; + + region = find_text_region(pc); + if ( !region ) + return -EINVAL; + + for ( id = 0; id < BUGFRAME_NR; id++ ) + { + const struct bug_frame *b; + size_t 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: + if ( !bug ) + return -EINVAL; + + if ( id == BUGFRAME_run_fn ) + { + void (*fn)(const struct cpu_user_regs *) = bug_ptr(bug); + + fn(regs); + + return id; + } + + /* 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 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 = 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 ( 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%=:"BUG_INSTR"\n" \ + " .pushsection .bug_frames.%"BUG_ASM_CONST"[bf_type], \"a\", %%progbits\n" \ + " .p2align 2\n" \ + ".Lfrm%=:\n" \ + " .long (.Lbug%= - .Lfrm%=) + %"BUG_ASM_CONST"[bf_line_hi]\n" \ + " .long (%"BUG_ASM_CONST"[bf_ptr] - .Lfrm%=) + %"BUG_ASM_CONST"[bf_line_lo]\n"\ + " .if " #second_frame "\n" \ + " .long 0, %"BUG_ASM_CONST"[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) + +#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) >= 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 + +#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: + */ From patchwork Fri Mar 3 10:38:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13158637 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 CFC36C678D4 for ; Fri, 3 Mar 2023 10:38:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.505813.778777 (Exim 4.92) (envelope-from ) id 1pY2o7-000655-B2; Fri, 03 Mar 2023 10:38:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 505813.778777; Fri, 03 Mar 2023 10:38:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pY2o7-000639-4X; Fri, 03 Mar 2023 10:38:35 +0000 Received: by outflank-mailman (input) for mailman id 505813; Fri, 03 Mar 2023 10:38:34 +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 1pY2o6-0005jk-5R for xen-devel@lists.xenproject.org; Fri, 03 Mar 2023 10:38:34 +0000 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [2a00:1450:4864:20::136]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8b2a5923-b9af-11ed-a550-8520e6686977; Fri, 03 Mar 2023 11:38:32 +0100 (CET) Received: by mail-lf1-x136.google.com with SMTP id r27so2954708lfe.10 for ; Fri, 03 Mar 2023 02:38:32 -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 d11-20020ac25ecb000000b004cb3a55feacsm338760lfq.100.2023.03.03.02.38.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Mar 2023 02:38:31 -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: 8b2a5923-b9af-11ed-a550-8520e6686977 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677839912; 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=oruXISOzbtYmsjJP9608NUUX4p1qMmDHX62cBBlU67Q=; b=T4ZzVZJADkACXJpTwzSpuzk0Juamfu/B3GEmo4X+fYL4UDjugiv+PmRUe9SMftPY5/ cLPNG1H+v3g4j6OTXb6vA0ne9NybG8sSedxoyn6x2Qfs364q7Ta+KLEoJP632Bs2f0O2 hM4MeW2wItSmczmPWAix8xlkukalRficE2kDzLVRuS0gZzwdNmSPggie9ZvII0XvVvf7 bIYG5A2AyhsaqTYtgYqunRZWUIfQvD0C496hWUO4GEiimbprM3FZu1k0rXVgIl0rnpsN Dk6SGAQsoiczHQLxXljR1inHq9r2qrBKvaTrGFL/xvSRivNGqaE115AZfcwqviP/Zzyk 6+AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677839912; 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=oruXISOzbtYmsjJP9608NUUX4p1qMmDHX62cBBlU67Q=; b=qU1rQgCOMtuyitZ0gbmcco5j7gw/xIh0lASkbJd67luvf6qleLThGsXem2GpK9Z5GV reHQQPKJXx7RMSLEFGPxU/2LyXxsIqTY5s8eLQhIhchHYKEaqElUeqcA77aLWXT5GSuw xg4OUqCg2cphn4Ga4MXln0UueTuUHmB7KreTFTN9oYmnZqYXuHXP7JKQ4jtzDS9/BNwj z33XjzpIp2++Kel8EGfAWExXC7bSGpFnHd9IrgoP1qlcfsK7MmMjUI5s0LzFEApvLJmQ 7a7lQagVQNuuWzsDJ8bNodsVPnsHiry7DQN5N0p9UPpmrPGNiD4Ib2hlLno7BuSsZZ0W 9beg== X-Gm-Message-State: AO0yUKXa/qyfC1qdCXDp6CulrJeKVXpqt5UsJDYEkLCw6F3Dbgls3JD7 XRh6MmheGgIlrhjiMXbKMMkEDUdf2Kw= X-Google-Smtp-Source: AK7set8z6ttBU7k62qkCUu7V/uYCbZELCN61J9yKFY7e74qSUh/e4Qn70pVNDvPiDGzfpGNlxomjPw== X-Received: by 2002:ac2:598c:0:b0:4b0:1305:6ebf with SMTP id w12-20020ac2598c000000b004b013056ebfmr387484lfn.53.1677839911779; Fri, 03 Mar 2023 02:38:31 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Julien Grall , Jan Beulich , Andrew Cooper , Stefano Stabellini , Gianluca Guida , Oleksii Kurochko , Bertrand Marquis , Volodymyr Babchuk , George Dunlap , Wei Liu , =?utf-8?q?R?= =?utf-8?q?oger_Pau_Monn=C3=A9?= Subject: [PATCH v5 2/4] xen: change to Date: Fri, 3 Mar 2023 12:38:23 +0200 Message-Id: X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 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 Acked-by: Jan Beulich --- Changes in V5: - Nothing changed --- 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 'struct bug_frame' and so should co-exist together. So the defines were back to until BUG_FRAME_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 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/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__ +#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) +#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) -#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) -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/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/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) -#define BUGFRAME_run_fn 0 -#define BUGFRAME_warn 1 -#define BUGFRAME_bug 2 -#define BUGFRAME_assert 3 - -#define BUGFRAME_NR 4 - #ifndef __ASSEMBLY__ +#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) -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__ */ /* 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 Fri Mar 3 10:38:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13158640 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 02FC6C7EE36 for ; Fri, 3 Mar 2023 10:38:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.505815.778796 (Exim 4.92) (envelope-from ) id 1pY2o9-0006bJ-Tz; Fri, 03 Mar 2023 10:38:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 505815.778796; Fri, 03 Mar 2023 10:38:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pY2o9-0006Zy-P4; Fri, 03 Mar 2023 10:38:37 +0000 Received: by outflank-mailman (input) for mailman id 505815; Fri, 03 Mar 2023 10:38:35 +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 1pY2o7-0005jk-GL for xen-devel@lists.xenproject.org; Fri, 03 Mar 2023 10:38:35 +0000 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [2a00:1450:4864:20::134]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8becb00e-b9af-11ed-a550-8520e6686977; Fri, 03 Mar 2023 11:38:33 +0100 (CET) Received: by mail-lf1-x134.google.com with SMTP id j11so2929136lfg.13 for ; Fri, 03 Mar 2023 02:38:33 -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 d11-20020ac25ecb000000b004cb3a55feacsm338760lfq.100.2023.03.03.02.38.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Mar 2023 02:38:33 -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: 8becb00e-b9af-11ed-a550-8520e6686977 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677839913; 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=pjC6qCxDVrnhK8is2cy4/nO3uhLVsjHLR9u3r1p2UmU=; b=SLdEwtUSgDExuV2l2xk/frQE00QmcThDuav/hLFwg6XYUc4mU8HtFXqxh+SiiOZMgS Rirt2RrfEUH12Vvy/Bsuqw/v1WZzjZaRd/+cxEjcYtWx837bnjXglEtWRT5CDwffQDqL PByf5h4WN3GZ9B+6SDumdnI+cUGkeZ35L4uy8nCaptlwjlTVuSOvc9cldrQtxm/z9acQ uqKRW4Xx1oasacqrIzERxxt4R0D5iqEkBa5oouZ6GCiChtRCjjKLTtvux0UpmCkJS16O kqJX5xU9MIb+hdwo7bO9tCAGanJbsmTh+XBkzGHezX/Mwn+pPQT4uGBRkaStbknZWuMG PdQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677839913; 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=pjC6qCxDVrnhK8is2cy4/nO3uhLVsjHLR9u3r1p2UmU=; b=mLzA0i8t6PEn6C8BniNl39fyd9lw/2TZtBvXO3kYtcVNSzOuf18kJEQwu77siFAzb6 /hCO0OBK92Q+6e43B6Rj82LJNW9G4O5UBS79k0HVL9XHne0h0uEe+LZqWC+6qXxO0fUY 0QjQUVC710hbRUvbMbIuEKD0kZ7lrpI7sSovuB5+nt6WkmUx1IFd7NHrPYIj/lGfC4cq E+il0BjgWPkMwN4PfWQB3rObuOJ0MGkQXx6Xy6elScABN/cCKQj99/HVElKcZZ+gN4VX k0NbfZRyGLBURJaZn6AtFkJfYnZ7Rlb/+17q5OlA5rYP4bOsfNR7p2L9Ysm9ZwRRapLj ghZQ== X-Gm-Message-State: AO0yUKWJ/HsWGj/y9mkEnA/leDpCsV+QREHMWlXCJ975rgM1OiAp0Ku/ xxmNAP7SwmfpD6zAqT4CJ7llTeMJbjo= X-Google-Smtp-Source: AK7set/lQXWktVdhg6yA5gda5sdT8hi1AiCS9S9fr1cj1LhWvojXbYSQFvvRDHze29xpDjlSWStHgA== X-Received: by 2002:ac2:51a8:0:b0:4cc:7308:8f40 with SMTP id f8-20020ac251a8000000b004cc73088f40mr436479lfk.40.1677839913143; Fri, 03 Mar 2023 02:38:33 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Julien Grall , Jan Beulich , Andrew Cooper , Stefano Stabellini , Gianluca Guida , Oleksii Kurochko , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v5 3/4] xen/arm: switch ARM to use generic implementation of bug.h Date: Fri, 3 Mar 2023 12:38:24 +0200 Message-Id: <9de74cc424d5f198ac76ff46394aa5b99502d24e.1677839409.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 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 V5: * Nothing changed --- 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 +--------------------------- 7 files changed, 4 insertions(+), 161 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/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 != BUG_OPCODE ) goto die; - if ( do_bug_frame(regs, pc) ) + if ( do_bug_frame(regs, pc) < 0 ) goto die; regs->pc += 4; diff --git a/xen/arch/arm/include/asm/arm32/bug.h b/xen/arch/arm/include/asm/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 @@ #define BUG_INSTR ".word " __stringify(BUG_OPCODE) -#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/asm/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 @@ #define BUG_INSTR "brk " __stringify(BRK_BUG_FRAME_IMM) -#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 -#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 ASSERT) */ - 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) >= 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" #endif /* __ARM_BUG_H__ */ /* 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..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 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) { @@ -1292,7 +1213,7 @@ static void do_trap_brk(struct cpu_user_regs *regs, const 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; regs->pc += 4; From patchwork Fri Mar 3 10:38:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13158639 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 C684BC64EC4 for ; Fri, 3 Mar 2023 10:38:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.505814.778790 (Exim 4.92) (envelope-from ) id 1pY2o9-0006XG-I3; Fri, 03 Mar 2023 10:38:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 505814.778790; Fri, 03 Mar 2023 10:38:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pY2o9-0006X5-Eh; Fri, 03 Mar 2023 10:38:37 +0000 Received: by outflank-mailman (input) for mailman id 505814; Fri, 03 Mar 2023 10:38:35 +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 1pY2o7-00068S-MC for xen-devel@lists.xenproject.org; Fri, 03 Mar 2023 10:38:35 +0000 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [2a00:1450:4864:20::12b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8cad6d7a-b9af-11ed-96af-2f268f93b82a; Fri, 03 Mar 2023 11:38:34 +0100 (CET) Received: by mail-lf1-x12b.google.com with SMTP id j11so2929178lfg.13 for ; Fri, 03 Mar 2023 02:38:34 -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 d11-20020ac25ecb000000b004cb3a55feacsm338760lfq.100.2023.03.03.02.38.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Mar 2023 02:38:34 -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: 8cad6d7a-b9af-11ed-96af-2f268f93b82a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677839914; 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=fUiRMVPR0ilpfT8Ki5uaE/L5ncki0uX/6QKrZCFiFtE=; b=F3oV1tXW3akzyk4y1Hd41DCm5wIO/YmVWNW40gcL/mU9jOQkA9XtoNn184cmjNyEdO C53/k+UofL13XkS46Lw9+HiT2HNIi0kfTMSek8wuwjHVaTOSm0R9xWsxAvfQqkp5f/yg sEhTkOCnALPTJywLe1v/cqyBtU7gxaKp5jt01qtdLujYeN2E0CDcWweOF3Ir6gB74eWf PVCAGFi7kVJEh9g2LHJSJ3xscSRFVMEF+dEzDHiwQmPDNzfT7f1crpy8PFe2V51hA/FX bmUTGgZgwm7A9tGyZqt16EX/BsgUqrMOeoNiTtoUfiQhYFxSAXJHNeuQ5V6dqQgNOLgX aA1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677839914; 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=fUiRMVPR0ilpfT8Ki5uaE/L5ncki0uX/6QKrZCFiFtE=; b=cADuxZA/1Z/YsP+gL5lAEaNYJ6syoq6Txg1a7heoUImOKPnyolJZSVJRFw142RrVyd J19G3EOVru3uL+x6nYkdkWQgWBZmjjLWW0mZrEvt1nh1+z0XXB29fLdzTJwG8QRcc30M HV00IzZ8Uoa7THCBNIEKpL0ia9DfUXdEnd36U9Y1ALZPLejOZ6Gwllz2h2EhT3VZu3uU 4+3ATX3UG2gUSQY7Zf3bj1HKIXxjBIGvtVKmOoZmOwOJlObQU7oEQHB/2sFf7Uw2L8Tt cLh+EORkVOgf7DiJfCBHp27B7/HIu/8hjIqgOUNcAalZ4nDxBT9yo0hdM7d+n0AeXst3 0VGg== X-Gm-Message-State: AO0yUKXlzMLay9YKCRFDM4ZeIgfiiDxoo+IJ6Yny9kuyZbPaWUtz4bP+ lb5TnB1aOEh8hzz0Q8dZ8xI/iJ/fHug= X-Google-Smtp-Source: AK7set/iZaFpQdjpJ/6luiC9gfz02zE1/t2IZW6zTNcaO9VgdL2599powdfaTIRtOycugQ7uVrL8ow== X-Received: by 2002:a05:6512:3b98:b0:4d8:86c1:477d with SMTP id g24-20020a0565123b9800b004d886c1477dmr1476662lfv.18.1677839914238; Fri, 03 Mar 2023 02:38:34 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Julien Grall , 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 v5 4/4] xen/x86: switch x86 to use generic implemetation of bug.h Date: Fri, 3 Mar 2023 12:38:25 +0200 Message-Id: <4a478638449e66a76e1671db38ec29b9e3108201.1677839409.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 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 V5: * Nothing changed --- Changes in V4: * Back comment /* !__ASSEMBLY__ */ for #else case in * Remove changes related to x86/.../asm/debuger.h as do_bug_frame() prototype 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 = '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 | 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__ -#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) #ifndef __ASSEMBLY__ -#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%=: 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) +#define BUG_INSTR "ud2" +#define BUG_ASM_CONST "c" #else /* !__ASSEMBLY__ */ 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 */ +#include #include #include #include @@ -1166,12 +1167,9 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf, 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; + int id; 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; - 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: - if ( !bug ) + id = do_bug_frame(regs, regs->rip); + if ( id < 0 ) 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; - } - /* WARN, BUG or ASSERT: decode the filename pointer and line number. */ - filename = bug_ptr(bug); - if ( !is_kernel(filename) && !is_patch(filename) ) - goto die; - fixup = strlen(filename); - if ( fixup > 50 ) - { - filename += fixup - 47; - prefix = "..."; - } - lineno = bug_line(bug); + eip += sizeof(bug_insn); 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: