From nobody Thu May 16 22:00:24 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=1677238299; cv=none; d=zohomail.com; s=zohoarc; b=ky6keNysvDjQmq5y0xM9OByh2PuHjdThzzUsr/SUU3tiR8yA8PL13W65f+rZ2mgtJBl6FCqJpVF7OFy0io7+MMQ2UDk4Dnc897m4+lxZO0R/Mh24e5n2o2Q3Lo2YFbYteiwvdquFwOKMNa9u6iHUhglfd9Jtt8q+9yQp7b6scfA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677238299; 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=AgBxbMPWe3EyzCfXpR5m0OP7A2Ia8jQUyV6vwTk/ZCU=; b=iyYhnc7sRCDVSk0nCmWxBnB/nlnvg4h27XKk/lW3E9KmlYVc41dgZ5WF9N8crsnTEdCpyvtYPh3kjHBSateygkNBTLPAlItHv0k5ghbk8lhrx0Jb+dXp1YfzoJ/1JyaGlirIDFqHI4kLR7wRDYbqcufj6lw+D6xphQJS/F4vmOI= 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 167723829902469.9474403981128; Fri, 24 Feb 2023 03:31:39 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.500922.772478 (Exim 4.92) (envelope-from ) id 1pVWIH-0004oZ-RH; Fri, 24 Feb 2023 11:31:17 +0000 Received: by outflank-mailman (output) from mailman id 500922.772478; Fri, 24 Feb 2023 11:31:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pVWIH-0004oO-NA; Fri, 24 Feb 2023 11:31:17 +0000 Received: by outflank-mailman (input) for mailman id 500922; Fri, 24 Feb 2023 11:31:16 +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 1pVWIG-0004Yi-2S for xen-devel@lists.xenproject.org; Fri, 24 Feb 2023 11:31:16 +0000 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [2a00:1450:4864:20::130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id becefdc9-b436-11ed-a82a-c9ca1d2f71af; Fri, 24 Feb 2023 12:31:14 +0100 (CET) Received: by mail-lf1-x130.google.com with SMTP id i9so17342115lfc.6 for ; Fri, 24 Feb 2023 03:31:14 -0800 (PST) Received: from 34-6F-24-FC-D2-65.. (46.204.108.92.nat.umts.dynamic.t-mobile.pl. [46.204.108.92]) by smtp.gmail.com with ESMTPSA id v19-20020a2ea613000000b00295a815e555sm92682ljp.134.2023.02.24.03.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 03:31:13 -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: becefdc9-b436-11ed-a82a-c9ca1d2f71af DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AgBxbMPWe3EyzCfXpR5m0OP7A2Ia8jQUyV6vwTk/ZCU=; b=OavmJP0f9Si3LbeNdFM7APxBmB+wWffF4AoIbo4dpvWh4tqRxJcWFlklAIGZWIH4ej ciMkdIvPEerKsGvfEae25dyJ6/CJTbWlf+1BQCKQ1+4ybAOrfrpUgTswSroHlQi54XX5 h0OXhQpoZ4heUcPb9z1lZxAJ56lgORd/ngXP/c1ir7AiYvB6KeR30XrvKOojp+QKE4np qjOCZjxdqcnT9Yb/pUw1nZuBYtQb6vPBUomvstl/4JL16StS2ZKLFRCPKV9s5b/0C1Uw APCZU+l19vonmNG1inN7VH3rMva4wSpY16pso1NzSDiBWQZDYfbcLE2Df6yxSl43R+5W 8bsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AgBxbMPWe3EyzCfXpR5m0OP7A2Ia8jQUyV6vwTk/ZCU=; b=AnfZOxCtguhd4CCo9lmNFUDLDrOQCZGh+14KR2sp05j5RLlPcjtJ9a6w6n9voCYd5S 3oVDSPbD6iOsPzPhuEQNqgiTYsu2oupC3IDcOKxeUX8b3QhQUtaBBRhIgCQdjqeKGscP yyidw0zaTKj4Cs31h6Izy1eLVd5fZjISyKR1rhzB0n+CPSbyYXcQ0YEz04gJHK2/Raxr w/B//NvgYjKSY1dsurw575efiyVs6kLNdfqM8rinGayHIw4EiUKuv+M8ltGp4qdiS5zs RgI8n6Fhwk4z3O4LZ1VHzrVodB7USUHCvO4/Kw4HmPnQ2EEA5I6QixrSubfCUCohac8i c6Rg== X-Gm-Message-State: AO0yUKWDZndo4EejglVc8H2V9iD0aGqFHZPEdEBQ8wZ52Nij3ZKPB59G grORbmxVv+0e0hP+YTLHyTD3QJcUKAY= X-Google-Smtp-Source: AK7set9A/YDVjjVV+2W/FAHrKbqpSzjpwJZ8sJ1tl3wkhL6E4yqeC+r2iZMxCzCYrfNUnD+K9a55rA== X-Received: by 2002:a05:6512:3089:b0:4db:787:e43b with SMTP id z9-20020a056512308900b004db0787e43bmr6985309lfd.8.1677238273501; Fri, 24 Feb 2023 03:31:13 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Andrew Cooper , Stefano Stabellini , Gianluca Guida , Oleksii Kurochko , George Dunlap , Julien Grall , Wei Liu Subject: [PATCH v3 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME Date: Fri, 24 Feb 2023 13:31:04 +0200 Message-Id: <932b0fd2a211d2d837d00e1bda87a84ad680fe7b.1677233393.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: 1677238299792100001 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 Signed-off-by: Oleksii Kurochko --- 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 | 109 ++++++++++++++++++++++++++++++ xen/include/xen/bug.h | 150 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 263 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..f81724fc9b --- /dev/null +++ b/xen/common/bug.c @@ -0,0 +1,109 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/* Set default value for TRAP_invalid_op as it is defined only for X86 now= */ +#ifndef TRAP_invalid_op +#define TRAP_invalid_op 0 +#endif + +int do_bug_frame(const 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 ) + { + 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 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 ( debugger_trap_fatal(TRAP_invalid_op, 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 ( debugger_trap_fatal(TRAP_invalid_op, 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..4b18cfa69c --- /dev/null +++ b/xen/include/xen/bug.h @@ -0,0 +1,150 @@ +#ifndef __XEN_BUG_H__ +#define __XEN_BUG_H__ + +#define BUG_DISP_WIDTH 24 +#define BUG_LINE_LO_WIDTH (31 - BUG_DISP_WIDTH) +#define BUG_LINE_HI_WIDTH (31 - BUG_DISP_WIDTH) + +#define BUGFRAME_run_fn 0 +#define BUGFRAME_warn 1 +#define BUGFRAME_bug 2 +#define BUGFRAME_assert 3 + +#define BUGFRAME_NR 4 + +#include + +#ifndef __ASSEMBLY__ + +#include +#include +#include + +#ifndef BUG_FRAME_STRUCT + +struct bug_frame { + signed int loc_disp:BUG_DISP_WIDTH; + unsigned int line_hi:BUG_LINE_HI_WIDTH; + signed int ptr_disp:BUG_DISP_WIDTH; + unsigned int line_lo:BUG_LINE_LO_WIDTH; + signed int msg_disp[]; +}; + +#endif /* BUG_FRAME_STRUCT */ + +#ifndef bug_loc +#define bug_loc(b) ((unsigned long)(b) + (b)->loc_disp) +#endif + +#ifndef bug_ptr +#define bug_ptr(b) ((const void *)(b) + (b)->ptr_disp) +#endif + +#ifndef bug_line +#define bug_line(b) (((((b)->line_hi + ((b)->loc_disp < 0)) & = \ + ((1 << BUG_LINE_HI_WIDTH) - 1)) << = \ + BUG_LINE_LO_WIDTH) + = \ + (((b)->line_lo + ((b)->ptr_disp < 0)) & = \ + ((1 << BUG_LINE_LO_WIDTH) - 1))) +#endif + +#ifndef bug_msg +#define bug_msg(b) ((const char *)(b) + (b)->msg_disp[1]) +#endif + +#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; + +int do_bug_frame(const struct cpu_user_regs *regs, unsigned long pc); + +#endif /* CONFIG_GENERIC_BUG_FRAME */ + +extern const struct bug_frame __start_bug_frames[], + __stop_bug_frames_0[], + __stop_bug_frames_1[], + __stop_bug_frames_2[], + __stop_bug_frames_3[]; + +#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 22:00:24 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=1677238301; cv=none; d=zohomail.com; s=zohoarc; b=gOZOYc9YS2rrKoNaGWK+EtdfFdkWHdQE+VxYc+IscSFneZBtSWUHEvyuehb7nsijs5cctJDIZ9jfIPNAe/OaKVercLXQtvP++z2Zc9TFu2ygaNRrMQ9xh+KEkx+RvnWaMjQfYq+37c3vjUoJ9ohTusYUvKTrvykvXpRT+lAOOWY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677238301; 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=FHOe3gWUHwieeNaUAZbwaaYvn/OKztq6D7rxSzkp37U=; b=RHOR65N4HANLp1WF0SgJ76onC0o5fbEL4BLCNcSiEINnIWRkOUxkRuUQQgXHRp+1z2ETjsrgwLvJUVif+wsXHTxxlz3XevKupCKsGk+Ki3k6MbAVQJ90sFjl1amgfX0Ce8OhM0ZpfmWL8KWSx+DEOGfhvMp7ydsIwpf7xf10tHs= 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 1677238301236277.04448738741416; Fri, 24 Feb 2023 03:31:41 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.500923.772488 (Exim 4.92) (envelope-from ) id 1pVWIJ-00054R-2k; Fri, 24 Feb 2023 11:31:19 +0000 Received: by outflank-mailman (output) from mailman id 500923.772488; Fri, 24 Feb 2023 11:31:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pVWII-00054K-Vw; Fri, 24 Feb 2023 11:31:18 +0000 Received: by outflank-mailman (input) for mailman id 500923; Fri, 24 Feb 2023 11:31:16 +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 1pVWIG-0004Z5-S3 for xen-devel@lists.xenproject.org; Fri, 24 Feb 2023 11:31:16 +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 bfdc4502-b436-11ed-88bb-e56d68cac8db; Fri, 24 Feb 2023 12:31:15 +0100 (CET) Received: by mail-lj1-x22e.google.com with SMTP id j17so14012390ljq.11 for ; Fri, 24 Feb 2023 03:31:15 -0800 (PST) Received: from 34-6F-24-FC-D2-65.. (46.204.108.92.nat.umts.dynamic.t-mobile.pl. [46.204.108.92]) by smtp.gmail.com with ESMTPSA id v19-20020a2ea613000000b00295a815e555sm92682ljp.134.2023.02.24.03.31.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 03:31:15 -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: bfdc4502-b436-11ed-88bb-e56d68cac8db DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FHOe3gWUHwieeNaUAZbwaaYvn/OKztq6D7rxSzkp37U=; b=nXD0eeC04kAsS+A9n1ec0duP6Z7xCP0jiZLGU+57mD38kYw4rCpdJF2NAKbEHt42Qb 3zFp9xusxhT7PvWfJdDL022rDqS86UjH9fDwcyZ8rZWSau9y8fJDejuzzVWFhtcq0ZLT kzI//i4ZvmWw8ufi43iQfGYI/KxpyVSgkEa9ZH4Z6fv9qZdkVCE0/O0zYz4SbAlvNjfc gS1d4ymufnvzquYKIOX+kaY78Rcm1v2sPPRVGjI+N7//kQ7zw5VVNqAg96kElnHYC3b+ ydujYcdlT9N8EG/NUMvk0whCagM8jQWVAKoklxkdjyESqiQFYlDJ/NTwKjpCraobqQ1L fybA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FHOe3gWUHwieeNaUAZbwaaYvn/OKztq6D7rxSzkp37U=; b=CUmwMPKIcvICgiwi0sMZepmizHWgU0LDlGv7r8V5tR9yDjmIKKYwwJhI0jIaFGyg+P YPc+TcRDrVRsptLuPz34i8I8NlnAHSChBclhD2JKlt+y8GOhKsTbzual37HZivaJ6lfd ugDJ5MX1tG3CIJRTn77/WjZ5BlQzEORz7iPbcMjKOp23KkPhnC5CvXAqkNNRRPMT6DYE iDnGoP7FxIWqspA43RoeBZwUDKSScftfcR7MuPmWSQ8Sum52HiQ/LWw50EnTpym2tJWQ I5NBiVPjfauL45nELcmgAB73hkUqItJuQ0QHynVtcjNkTQeofBSjCEodWlj/qIEzkKWQ hkwQ== X-Gm-Message-State: AO0yUKXpnC0uaXu+GAhzust7RhW6ir1z8+/8BPV24gR52SkcS4BH5olJ 4/HsDp4rLoER+hF06AyTogbNiT45+OA= X-Google-Smtp-Source: AK7set+Xij/4ZC2hO7U4EhhN2RDupsNnQZm8MtDj4vPEbhS3DrR1uAbQI3sKaR+ET+UKMLFn0h4gVA== X-Received: by 2002:a2e:be08:0:b0:282:d00d:4be6 with SMTP id z8-20020a2ebe08000000b00282d00d4be6mr7174601ljq.40.1677238275282; Fri, 24 Feb 2023 03:31:15 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Andrew Cooper , Stefano Stabellini , Gianluca Guida , Oleksii Kurochko , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , George Dunlap , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v3 2/4] xen: change to Date: Fri, 24 Feb 2023 13:31:05 +0200 Message-Id: <19404db4a577e17dffef85a101449a507965be19.1677233393.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: 1677238301807100005 Content-Type: text/plain; charset="utf-8" Since the generic version of bug.h stuff was introduced use instead of unnecessary Signed-off-by: Oleksii Kurochko --- 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 | 19 +++---------------- 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 | 19 ++----------------- xen/drivers/cpufreq/cpufreq.c | 2 +- xen/include/xen/lib.h | 2 +- 9 files changed, 12 insertions(+), 40 deletions(-) diff --git a/xen/arch/arm/include/asm/bug.h b/xen/arch/arm/include/asm/bug.h index f4088d0913..cacaf014ab 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) @@ -9,9 +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 =20 struct bug_frame { signed int loc_disp; /* Relative address to the bug address */ @@ -26,13 +26,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 +82,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..4b3e7b019d 100644 --- a/xen/arch/x86/include/asm/bug.h +++ b/xen/arch/x86/include/asm/bug.h @@ -1,19 +1,10 @@ #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 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 +71,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 22:00:24 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=1677238300; cv=none; d=zohomail.com; s=zohoarc; b=ArW0FcpSFm8cvVxZs2VXDa1+aojfiWSJdiM+C3AnbNqIMSVQIWtqj6Y73zj3x6fz4Dmv+GROANajVKalgjmPn+YOYnHLtkCuLV2bpPa7gisOPypzBxhNekRx5HoWxSAnUJ2cOM4skj7e8LjnUttCRL9fmuhW0vbxz2r2RFiBeks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677238300; 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=cOshq+qKbDwQMkJNLbvBoFxXJPrCc7l4QBus5ql+hrQ=; b=MXzckqI4FU2lKwE5YaSO7tDc+UtcAbhsxXf710t3NQsW/6AJJGUGNJ5DU0iNq7061MflT71NN+3Rg8qj4qfJy4Zx2WYRsONl7Uq/CjrjzOWeC5dtUo7QmcQ3ucz85z1sTGSTDyOl5iveL0dpLt6TGj2G7k+cZ4kHe2XJo96iImk= 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 1677238300518514.5274582837783; Fri, 24 Feb 2023 03:31:40 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.500924.772498 (Exim 4.92) (envelope-from ) id 1pVWIK-0005Ly-JX; Fri, 24 Feb 2023 11:31:20 +0000 Received: by outflank-mailman (output) from mailman id 500924.772498; Fri, 24 Feb 2023 11:31:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pVWIK-0005Lp-G8; Fri, 24 Feb 2023 11:31:20 +0000 Received: by outflank-mailman (input) for mailman id 500924; Fri, 24 Feb 2023 11:31:19 +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 1pVWII-0004Yi-Tf for xen-devel@lists.xenproject.org; Fri, 24 Feb 2023 11:31:19 +0000 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [2a00:1450:4864:20::22d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c0a5b9b2-b436-11ed-a82a-c9ca1d2f71af; Fri, 24 Feb 2023 12:31:17 +0100 (CET) Received: by mail-lj1-x22d.google.com with SMTP id z5so13859968ljc.8 for ; Fri, 24 Feb 2023 03:31:17 -0800 (PST) Received: from 34-6F-24-FC-D2-65.. (46.204.108.92.nat.umts.dynamic.t-mobile.pl. [46.204.108.92]) by smtp.gmail.com with ESMTPSA id v19-20020a2ea613000000b00295a815e555sm92682ljp.134.2023.02.24.03.31.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 03:31:16 -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: c0a5b9b2-b436-11ed-a82a-c9ca1d2f71af DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cOshq+qKbDwQMkJNLbvBoFxXJPrCc7l4QBus5ql+hrQ=; b=ltuWFLkn+rkcMbJuSMNyb6XPd72AvRfFGSala1oi+RzSSOdI7Ohr0onvF9IOhOWlLZ PBT78GgpjF8IRzcqfm9HmNgXB+zdJjiMs2HKPLqUD7ngbqoMmDzhwENTHwr+V07HJj+S TBVliYoR7gwBW53VH+oN55AHL2xdT5sjP1man/UzEoWlNg0f0nqK/ghC2YSkeVU8PXSi /QGKe2M8FOFahEjwDhYolyn+fafZJsqzI101HBAlaOgY+U7/NqEcJ6Jf9EPTdmhjVsF1 9Ybw7ProSQLRcjHiM3X7TsDAG9XIFytKrXuxqW+w2vAyiv8WEg9wNUV11QJ6VjXA4EVu hbcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cOshq+qKbDwQMkJNLbvBoFxXJPrCc7l4QBus5ql+hrQ=; b=lhl5cWcwwUkSfBJiJ7bt5KAEG1fXWYgsJ1prJn4TePO9jo8Q7hStNDAlZTOwd+VefY yD1zgxPSLZFL4g8uNrSu21aapZwSXxxgiqrWyq0iVVga2/WaazhV5O0PnA0MXPciyvU2 UVDPtQMP/H3dOyR0yu52NILKse/VBXUvmA3I+pZadD71h52g9stbLeXORTUAVta2zfAN oXaPWiPu5rGLygzl0xbj4IX59M9DV1TYto27IXo1hBIW5eW4l2HCanJXBWiRjmdW3pyN wlObUSjivOn3Ip7NMc84uwlxT2OqLz2LpFm85fJwcQPYepZZbigLUWQI/kAa8g0PINoA lIbA== X-Gm-Message-State: AO0yUKXMO4LYddTBR8V1UnuRJpUjwB8B7O7YRnzMjl58iCWwSXdBt8G5 eLVw9kvyHVKcUO4iOfs8J1UZy/Qix1g= X-Google-Smtp-Source: AK7set/RR8/tgFB4o0vxWajvTbl5KSLp0dIFfXf1evPIchk774YEk111cWWnIw900IE+GgreQPHusg== X-Received: by 2002:a05:651c:39c:b0:294:6d1d:cbf2 with SMTP id e28-20020a05651c039c00b002946d1dcbf2mr5031499ljp.40.1677238276713; Fri, 24 Feb 2023 03:31:16 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Andrew Cooper , Stefano Stabellini , Gianluca Guida , Oleksii Kurochko , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v3 3/4] xen/arm: switch ARM to use generic implementation of bug.h Date: Fri, 24 Feb 2023 13:31:06 +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: 1677238301506100003 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 * Change macros bug_file() to bug_ptr() to align it with generic implementation. Signed-off-by: Oleksii Kurochko --- 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/bug.h | 15 +----- xen/arch/arm/include/asm/traps.h | 2 - xen/arch/arm/traps.c | 81 +------------------------------- 5 files changed, 4 insertions(+), 97 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/bug.h b/xen/arch/arm/include/asm/bug.h index cacaf014ab..e6cc37e1d6 100644 --- a/xen/arch/arm/include/asm/bug.h +++ b/xen/arch/arm/include/asm/bug.h @@ -21,8 +21,7 @@ struct bug_frame { uint32_t pad0:16; /* Padding for 8-bytes align */ }; =20 -#define bug_loc(b) ((const void *)(b) + (b)->loc_disp) -#define bug_file(b) ((const void *)(b) + (b)->file_disp); +#define bug_ptr(b) ((const void *)(b) + (b)->file_disp) #define bug_line(b) ((b)->line) #define bug_msg(b) ((const char *)(b) + (b)->msg_disp) =20 @@ -70,18 +69,6 @@ struct bug_frame { ".popsection" :: "r" (fn) : __stringify(BUG_FN_REG) ); = \ } while (0) =20 -#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) - #endif /* __ARM_BUG_H__ */ /* * Local variables: 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; --=20 2.39.0 From nobody Thu May 16 22:00:24 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=1677238302; cv=none; d=zohomail.com; s=zohoarc; b=hgEsh3VutU/+sXbTKAh+89VQih7eaYLg9hCPVm0fFhXolM+pwiPE4yY87MaK8DLf3Ryj+0TT43BXW0+gPBZkAm/57fZLCR9O3U/aGHx3n7DGOapEF20v3biTnZbJIFwwKIF13l8yBcMzzrfrZDFO9VlGWlFm8WaR0+ls/a3WpHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677238302; 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=0G6bE1AlT3k8lziFMWj2l/M2niQSqBi5lrDekN1qx28=; b=EFIjeyWKlenwGNnBCWO71T6B/MyMzupnX+1m/NXE2aIsWk7rFjW9neFc4kerVg2ezSbDVBCHgPP9x3jHrOYPJj5kfr1llfJqZz+lk3kW5kTG7Cos50U9DOqCkC3g2/SxiJzC4ZCPw6Ut1dhx+rt4WInIX8zXp4+qoWgFbYsvIAM= 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 1677238302567179.74381761063682; Fri, 24 Feb 2023 03:31:42 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.500925.772508 (Exim 4.92) (envelope-from ) id 1pVWIM-0005eg-TG; Fri, 24 Feb 2023 11:31:22 +0000 Received: by outflank-mailman (output) from mailman id 500925.772508; Fri, 24 Feb 2023 11:31:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pVWIM-0005eV-Pn; Fri, 24 Feb 2023 11:31:22 +0000 Received: by outflank-mailman (input) for mailman id 500925; Fri, 24 Feb 2023 11:31:20 +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 1pVWIK-0004Yi-IV for xen-devel@lists.xenproject.org; Fri, 24 Feb 2023 11:31:20 +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 c16ed476-b436-11ed-a82a-c9ca1d2f71af; Fri, 24 Feb 2023 12:31:18 +0100 (CET) Received: by mail-lj1-x235.google.com with SMTP id a10so13919272ljq.1 for ; Fri, 24 Feb 2023 03:31:18 -0800 (PST) Received: from 34-6F-24-FC-D2-65.. (46.204.108.92.nat.umts.dynamic.t-mobile.pl. [46.204.108.92]) by smtp.gmail.com with ESMTPSA id v19-20020a2ea613000000b00295a815e555sm92682ljp.134.2023.02.24.03.31.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 03:31:17 -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: c16ed476-b436-11ed-a82a-c9ca1d2f71af DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0G6bE1AlT3k8lziFMWj2l/M2niQSqBi5lrDekN1qx28=; b=GYUYtzeTNuhG3D/yG/hHVooXpxlTJ0x1pReKqll9NUaF9Vu0cEEK1hg3/zR3JOMXQ8 lDdRVSQFNDZlkxD8kj+VY4W7rge5cwmIGQ+ZXa3XpeD7lOcIZp/Y3kw7foaF46eanqg+ MB2JJ97nWiir3SLqq0fjOjmOddvri+8ZsaJvOpvFy88SZ+4T1vfhWUBwBYI8NR3OKsGo dx8xUMCl8rzmx8tH939fPYX0+HeWNlKykOXiRsrw8SrI5fYVSKnkIcH+fOMzToapoo7K c0cKow1BGl9yo6VU+RkDZf+A/O44J8Mhp0PkAzTALbeUhijVzhc15zrYWqNMGrC4WtSx U7XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0G6bE1AlT3k8lziFMWj2l/M2niQSqBi5lrDekN1qx28=; b=jLjd0/pDDBuDOsBcQ49ost2w0cix1//Ex20I8Nk7GZtIlzl5Cylb080MAD4E2A/VZp FRW/8G7gAtzo190o+FX2u/XsQ4cnVNh0NlOwpBBF+AAbgYUv2iLfgqHf72ID2oN30Iv3 jldIrf2jmvMIu6VMVeWcSnufXyf+dR9DNbT7rsccsP3KUTC3CQlVUkILwS+DrJBv5Pvc 2vfSsK19NrYV8mOKYgG8UxlW8vlUQ0hD4H7v7SMZikQFG7ST7FZX6cmYJybpG4QXgXM7 QnTj0LSE9QqlRAfSnjps81E0DHk5axuB+tf0pX4xc+H/Lx6f1DLm0NYFpnWb54aIMhkm ZhbQ== X-Gm-Message-State: AO0yUKUifjhZEyFh9g20PEu0VmyzOk7nngQ4Mak25U2eWu5z+kaO0j38 bgIXww17nEMWtwol3bb89xR/ZPzmL5U= X-Google-Smtp-Source: AK7set9jt2Oel6r7VafLykfXdQdGunzpx2L3B48YkrPx2A0fDH3ADfKCtJqxLLOjL5rKb+ZkWvQ5AA== X-Received: by 2002:a2e:b045:0:b0:293:4be1:29df with SMTP id d5-20020a2eb045000000b002934be129dfmr5548154ljl.36.1677238277999; Fri, 24 Feb 2023 03:31:17 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Andrew Cooper , Stefano Stabellini , Gianluca Guida , Oleksii Kurochko , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v3 4/4] xen/x86: switch x86 to use generic implemetation of bug.h Date: Fri, 24 Feb 2023 13:31:07 +0200 Message-Id: <38bb75b9add8655288347aa4df1394450e4e10c9.1677233393.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: 1677238303549100007 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 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/include/asm/debugger.h | 4 +- xen/arch/x86/traps.c | 81 +++-------------------------- 4 files changed, 14 insertions(+), 145 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 4b3e7b019d..d7eb41baf3 100644 --- a/xen/arch/x86/include/asm/bug.h +++ b/xen/arch/x86/include/asm/bug.h @@ -3,75 +3,10 @@ =20 #ifndef __ASSEMBLY__ =20 -#define BUG_FRAME_STRUCT +#define BUG_INSTR "ud2" +#define BUG_ASM_CONST "c" =20 -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) - -#else /* !__ASSEMBLY__ */ +#else =20 /* * Construct a bugframe, suitable for using in assembly code. Should alwa= ys @@ -113,6 +48,6 @@ struct bug_frame { #define ASSERT_FAILED(msg) \ BUG_FRAME BUGFRAME_assert, __LINE__, __FILE__, 1, msg =20 -#endif /* !__ASSEMBLY__ */ +#endif /* __ASSEMBLY__ */ =20 #endif /* __X86_BUG_H__ */ diff --git a/xen/arch/x86/include/asm/debugger.h b/xen/arch/x86/include/asm= /debugger.h index a5c299c6c3..1873dc5779 100644 --- a/xen/arch/x86/include/asm/debugger.h +++ b/xen/arch/x86/include/asm/debugger.h @@ -14,9 +14,9 @@ =20 /* Returns true if GDB handled the trap, or it is surviveable. */ static inline bool debugger_trap_fatal( - unsigned int vector, struct cpu_user_regs *regs) + unsigned int vector, const struct cpu_user_regs *regs) { - int rc =3D __trap_to_gdb(regs, vector); + int rc =3D __trap_to_gdb((struct cpu_user_regs *)regs, vector); =20 if ( rc =3D=3D 0 ) return true; 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