From nobody Thu Nov 28 05:41:40 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=1678900953; cv=none; d=zohomail.com; s=zohoarc; b=JWno1uIvqUwNNLJYD7kWuEX8b8urrNh8orDTHYyqhr4fHXfb062hILG8cgBn5JOxy09+BCv6dRWfH7AJsWMdL1jM6lIDNfP9q54+KzQsv82UoakQQ2U1zEl9RUyMXAuF8pb2G5bOy22a3BEG0YfG3xL+HodcoCEUiplSNXooLQU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678900953; 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=UTxWYaZ2frOrsHQfZxZgybwYZqZzEeFQvzL+aan7ZLk=; b=NjVoLJdYtmlNmziww2EV+GzLKBzhu1O4An1pKigYVD1AmaT9s+FYTLV/Tv4kWvczq1NIX+pzVWnzGqjrDeQxLg/anMprnYZuz9Eg00RmthEsX5w5Es8Rgm/fF0KQSuOA8+XXtONPrmT5raUMXBpShQx6Fjxh32BDcqNeiDb5gig= 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 1678900953763718.1574116015803; Wed, 15 Mar 2023 10:22:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.510156.787399 (Exim 4.92) (envelope-from ) id 1pcUpA-0006Dg-BJ; Wed, 15 Mar 2023 17:22:04 +0000 Received: by outflank-mailman (output) from mailman id 510156.787399; Wed, 15 Mar 2023 17:22:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pcUpA-0006DZ-70; Wed, 15 Mar 2023 17:22:04 +0000 Received: by outflank-mailman (input) for mailman id 510156; Wed, 15 Mar 2023 17:22:02 +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 1pcUp8-0004sk-GB for xen-devel@lists.xenproject.org; Wed, 15 Mar 2023 17:22:02 +0000 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [2a00:1450:4864:20::52d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e5df2c88-c355-11ed-87f5-c1b5be75604c; Wed, 15 Mar 2023 18:22:01 +0100 (CET) Received: by mail-ed1-x52d.google.com with SMTP id z21so13076044edb.4 for ; Wed, 15 Mar 2023 10:22:01 -0700 (PDT) Received: from fedora.. (46.204.101.131.nat.umts.dynamic.t-mobile.pl. [46.204.101.131]) by smtp.gmail.com with ESMTPSA id d20-20020a50cd54000000b004fd1ee3f723sm2736315edj.67.2023.03.15.10.21.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 10:22:00 -0700 (PDT) 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: e5df2c88-c355-11ed-87f5-c1b5be75604c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678900921; 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=UTxWYaZ2frOrsHQfZxZgybwYZqZzEeFQvzL+aan7ZLk=; b=pK51OAl0zCAfWlJ0KoGa3Dj7ksaEXZaKkSfHWwH6a7vE5kjXgoVoRpGyhqtfAmXobO 3TJSjUU9bnwl8wJvs7wuxYHBSU43RPNRGAt8Z4/vJbYQouiy76y437giP7zx3Ivt0Dda 5Vx17IRxwbPDRlhd2+YJS4cqVQObUIY7gONRGqoakwAz48pjn7JvSNSE1Wp0q9uOvvJD 2w2wPM78Eqsix71c6n7ohT8X4KnFxsTGK+ditrTa8XshFBJp7pBlob0fn92ToLCVv7va z5Arit2x0TMLjyalEAJVgqgmxv0To4w1csQs+kVVqV3izpHTCnLTDwuEOb0jnzXth7Ph EgkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678900921; 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=UTxWYaZ2frOrsHQfZxZgybwYZqZzEeFQvzL+aan7ZLk=; b=yHZel6QMqkFaz2LPCBCIehBPUuUufe2/Pszr3P8uZqxWxzOWpHCh/aPYzJH2rncePI HJA6qCUMrZf77Nl3yPeRfNP8vJwI9qdTYwGcKjwqzxrO7PVl5Sn6SBRrQN+fAyZegXbj WO/5IgolvkWx7wNhpJdkxTK6V7cO7NJMeF/GZLGBAnlp9u6smCN0dHJ4PHeSTaU/mXmT 4osXsX7bEMA/U0tAzx1iRq/oHCpz5Dg6JomWyliwl344j5oOKk34p+eb0EtH26ro5GF3 iqVlpz4DPzrZ+cv9aDZbTdI9MsIvHVfn+rrnZMJkednOBIV2GJ85aysSl6TIK7/CSFrD SQvw== X-Gm-Message-State: AO0yUKXTwQVgETRYFGVoQ4cTjPga5pQhv9r3bS/cecL/55v3Z5ntJFOz aOO9+kQlOgY1J2pDXlUquz1pCMv7IOw= X-Google-Smtp-Source: AK7set9uxGLlfOEIIFcEuL+v60xGzR/kAPLF0oxi0sVmzIJHNMqjJ8obC4RfCmEfVBGVpOTQIZVQVQ== X-Received: by 2002:a05:6402:4d1:b0:4fa:ba60:8188 with SMTP id n17-20020a05640204d100b004faba608188mr3839986edw.8.1678900920756; Wed, 15 Mar 2023 10:22:00 -0700 (PDT) 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=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v8 5/5] xen/x86: switch x86 to use generic implemetation of bug.h Date: Wed, 15 Mar 2023 19:21:47 +0200 Message-Id: <5e252e8dacea5c4f2fdbb4f7970e34a862987639.1678900513.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1678900954409100004 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 * Update do_invalid_op using generic do_bug_frame() * Define BUG_DEBUGGER_TRAP_FATAL to debugger_trap_fatal(X86_EXC_GP,regs) * type of eip variable was changed to 'const void *' * add '#include ' Signed-off-by: Oleksii Kurochko Reviewed-by: Jan Beulich --- Changes in V8: * move from to to fix compilati= on issue. The following compilation issue occurs: In file included from ./arch/x86/include/asm/smp.h:10, from ./include/xen/smp.h:4, from ./arch/x86/include/asm/processor.h:10, from ./arch/x86/include/asm/system.h:6, from ./arch/x86/include/asm/atomic.h:5, from ./include/xen/gdbstub.h:24, from ./arch/x86/include/asm/debugger.h:10, from ./include/xen/debugger.h:24, from ./arch/x86/include/asm/bug.h:7, from ./include/xen/bug.h:15, from ./include/xen/lib.h:27, from ./include/xen/perfc.h:6, from arch/x86/x86_64/asm-offsets.c:9: ./include/xen/cpumask.h: In function 'cpumask_check': ./include/xen/cpumask.h:84:9: error: implicit declaration of function = 'ASSERT' [-Werror=3Dimplicit-function-declaration] 84 | ASSERT(cpu < nr_cpu_ids); It happens in case when CONFIG_CRASH_DEBUG is enabled and the reason for= that is when is included in :9 the "layout" of would be the following: #include : #include : #include : .... cpumask.h: .... ASSERT(cpu < nr_cpu_ids); return cpu; ....=20 .... #define ASSERT ... .... Thereby ASSERT is defined after it was used in . * Rebase the patch series on the top of the latest staging: it was a merge= conflict inisde x86/Kconfig. --- Changes in V7: * update the commit message * make eip 'const void *' * change [eip =3D (unsigned char *)eip + sizeof(bug_insn);] to [eip +=3D s= izeof(bug_insn);] * add '#include ' to * add Reviewed-by: Jan Beulich --- Changes in V6: * update the commit message * update the type of eip to 'void *' in do_invalid_op() * fix the logic of do_invalid_op() * move macros BUG_DEBUGGER_TRAP_FATAL under #ifndef __ASSEMBLY__ as it is not necessary to be in assembly code. --- 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() protot= ype was updated and cpu_user_regs isn't const any more. --- Changes in V3: * As prototype and what do_bug_frame() returns was changed so patch 3 and 4 was updated to use a new version of do_bug_frame * MODIFIER was change to BUG_ASM_CONST to align with generic implementation --- Changes in V2: * Remove all unnecessary things from as they were introduced = in . * Define BUG_INSTR =3D 'ud2' and MODIFIER =3D 'c' ( it is needed to skip = '$' when use an imidiate in x86 assembly ) * Update do_invalid_op() to re-use handle_bug_frame() and find_bug_frame() from generic implemetation of CONFIG_GENERIC_BUG_FRAME * Code style fixes. --- xen/arch/x86/Kconfig | 1 + xen/arch/x86/include/asm/bug.h | 69 ++--------------------------- xen/arch/x86/traps.c | 81 ++++------------------------------ 3 files changed, 12 insertions(+), 139 deletions(-) diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 2a5c3304e2..406445a358 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 imply 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..f852cd0ee9 100644 --- a/xen/arch/x86/include/asm/bug.h +++ b/xen/arch/x86/include/asm/bug.h @@ -3,73 +3,10 @@ =20 #ifndef __ASSEMBLY__ =20 -#define BUG_FRAME_STRUCT +#define BUG_DEBUGGER_TRAP_FATAL(regs) debugger_trap_fatal(X86_EXC_GP,regs) =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) +#define BUG_INSTR "ud2" +#define BUG_ASM_CONST "c" =20 #else /* !__ASSEMBLY__ */ =20 diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index cade9e12f8..c36e3f855b 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 void *eip =3D (const void *)regs->rip; + int id; =20 if ( likely(guest_mode(regs)) ) { @@ -1185,83 +1183,20 @@ 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); + return; } =20 die: --=20 2.39.2