All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Oleksii <oleksii.kurochko@gmail.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Gianluca Guida <gianluca@rivosinc.com>,
	George Dunlap <george.dunlap@citrix.com>,
	Julien Grall <julien@xen.org>, Wei Liu <wl@xen.org>,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH v3 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME
Date: Tue, 28 Feb 2023 11:42:19 +0100	[thread overview]
Message-ID: <9b66ee51-17c3-0f8e-0fc2-4ff083952e9d@suse.com> (raw)
In-Reply-To: <507c5449a56ce5cf5758bef967d511bf545d8405.camel@gmail.com>

On 28.02.2023 11:30, Oleksii wrote:
> On Mon, 2023-02-27 at 15:23 +0100, Jan Beulich wrote:
>> On 24.02.2023 12:31, Oleksii Kurochko wrote:
>>> --- /dev/null
>>> +++ b/xen/common/bug.c
>>> @@ -0,0 +1,109 @@
>>> +#include <xen/bug.h>
>>> +#include <xen/debugger.h>
>>> +#include <xen/errno.h>
>>> +#include <xen/kernel.h>
>>> +#include <xen/livepatch.h>
>>> +#include <xen/string.h>
>>> +#include <xen/types.h>
>>> +#include <xen/virtual_region.h>
>>> +
>>> +#include <asm/processor.h>
>>> +
>>> +/* 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 = 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 )
>>> +    {
>>> +        for ( id = 0; id < BUGFRAME_NR; id++ )
>>> +        {
>>> +            const struct bug_frame *b;
>>> +            unsigned int i;
>>> +
>>> +            for ( i = 0, b = region->frame[id].bugs;
>>> +                  i < region->frame[id].n_bugs; b++, i++ )
>>> +            {
>>> +                if ( bug_loc(b) == pc )
>>> +                {
>>> +                    bug = b;
>>> +                    goto found;
>>> +                }
>>> +            }
>>> +        }
>>> +    }
>>> +
>>> + found:
>>> +    if ( !bug )
>>> +        return -EINVAL;
>>> +
>>> +    if ( id == BUGFRAME_run_fn )
>>> +    {
>>> +#ifdef BUG_FN_REG
>>> +        void (*fn)(const struct cpu_user_regs *) = (void *)regs-
>>>> BUG_FN_REG;
>>> +#else
>>> +        void (*fn)(const struct cpu_user_regs *) = bug_ptr(bug);
>>> +#endif
>>> +
>>> +        fn(regs);
>>> +
>>> +        return 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 ( debugger_trap_fatal(TRAP_invalid_op, regs) )
>>
>> TRAP_invalid_op is, as said, about to disappear on x86 as well. I
>> think
>> this construct wants abstracting by another asm/bug.h provided macro
>> (taking just regs).
>>
> Thanks for the link.
> 
> Nice idea to abstract 'debugger_trap_fatal(TRAP_invalid_op, regs)'.
> Actually we have to options here:
> 1. As you proposed abstract in <asm/bug.h>:
>    x86:  #define DEBUG_TRAP_FATAL(regs) debugger_trap_fatal(X86_EXC_GP,
> regs)
>    ARM: #define DEBUG_TRAP_FATAL(regs) 0
>    RISC-V: #define DEBUG_TRAP_FATAL(regs) 0
>   For ARM and RISC-V it doesn't use so we can skip the check if (
> DEBUG_TRAP_FATAL ).
> 
> 2. Abstract only TRAP_invalid_op in <asm/bug.h>
>   x86: #define TRAP_invalud_op X86_EXC_GP
>   RISC-V: #define TRAP_invalid_op 0
>   ARN: #define TRAP_invalid_op 0
>   
>   I am not sure if we have to provide real invalid opcodes for RISC-V
> and ARM as it looks like debug_trap_fatal() isn't used in ARM&RISC-V
> now.
> 
> Could you please suggest which one option is better?

I don't view 2 as a viable option. How an arch deals with invalid opcodes
is entirely arch-specific (including the naming). As to 1 - since we want
this solely for bug.c, I'd prefer if the wrapper macro's name would start
with BUG_, e.g. BUG_DEBUGGER_TRAP_FATAL() or BUG_TRAP_FATAL() or just
BUG_FATAL(). Further adding ARCH_ may also be wanted by other maintainers
(I'm neither pro nor con there).

Jan


  reply	other threads:[~2023-02-28 10:42 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-24 11:31 [PATCH v3 0/4] introduce generic implementation of macros from bug.h Oleksii Kurochko
2023-02-24 11:31 ` [PATCH v3 1/4] xen: introduce CONFIG_GENERIC_BUG_FRAME Oleksii Kurochko
2023-02-25 16:42   ` Julien Grall
2023-02-27  9:48     ` Jan Beulich
2023-02-28 17:21     ` Oleksii
2023-02-28 18:01       ` Julien Grall
2023-02-28 20:24         ` Oleksii
2023-02-27 14:23   ` Jan Beulich
2023-02-28 10:30     ` Oleksii
2023-02-28 10:42       ` Jan Beulich [this message]
2023-02-24 11:31 ` [PATCH v3 2/4] xen: change <asm/bug.h> to <xen/bug.h> Oleksii Kurochko
2023-02-25 16:47   ` Julien Grall
2023-02-28 12:38     ` Oleksii
2023-02-28 14:04       ` Julien Grall
2023-02-28 13:07     ` Oleksii
2023-02-28 13:30       ` Jan Beulich
2023-02-28 16:00         ` Oleksii
2023-02-27 14:29   ` Jan Beulich
2023-02-28 13:14     ` Oleksii
2023-02-24 11:31 ` [PATCH v3 3/4] xen/arm: switch ARM to use generic implementation of bug.h Oleksii Kurochko
2023-02-25 16:49   ` Julien Grall
2023-02-25 17:05     ` Julien Grall
2023-02-28 17:21       ` Oleksii
2023-02-28 17:57         ` Julien Grall
2023-03-01 12:31           ` Oleksii
2023-03-01 13:58             ` Julien Grall
2023-03-01 15:16               ` Oleksii
2023-03-01 15:21                 ` Julien Grall
2023-03-01 15:28                   ` Oleksii
2023-03-01 15:58                   ` Oleksii
2023-02-28 15:09     ` Oleksii
2023-02-28 17:48       ` Julien Grall
2023-03-01  8:58         ` Oleksii
2023-03-01  9:31           ` Julien Grall
2023-03-01 12:33             ` Oleksii
2023-02-24 11:31 ` [PATCH v3 4/4] xen/x86: switch x86 to use generic implemetation " Oleksii Kurochko
2023-02-27 14:46   ` Jan Beulich
2023-02-28 16:28     ` Oleksii
2023-02-28 16:36       ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9b66ee51-17c3-0f8e-0fc2-4ff083952e9d@suse.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=gianluca@rivosinc.com \
    --cc=julien@xen.org \
    --cc=oleksii.kurochko@gmail.com \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.