All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ross Lagerwall <ross.lagerwall@citrix.com>
To: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	xen-devel@lists.xenproject.org, mpohlack@amazon.com,
	andrew.cooper3@citrix.com, stefano.stabellini@citrix.com,
	jbeulich@suse.com, ian.jackson@eu.citrix.com,
	ian.campbell@citrix.com, wei.liu2@citrix.com,
	sasha.levin@oracle.com
Subject: Re: [PATCH v2 11/13] xsplice: Add support for bug frames. (v2)
Date: Tue, 19 Jan 2016 14:42:56 +0000	[thread overview]
Message-ID: <569E4B70.7000204@citrix.com> (raw)
In-Reply-To: <1452808031-706-12-git-send-email-konrad.wilk@oracle.com>

On 01/14/2016 09:47 PM, Konrad Rzeszutek Wilk wrote:
> From: Ross Lagerwall <ross.lagerwall@citrix.com>
>
> Add support for handling bug frames contained with xsplice modules. If a
> trap occurs search either the kernel bug table or an applied payload's
> bug table depending on the instruction pointer.
>
> Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
snip

> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

> diff --git a/xen/common/xsplice.c b/xen/common/xsplice.c
> index 5abeb28..02cb4a8 100644
> --- a/xen/common/xsplice.c
> +++ b/xen/common/xsplice.c
> @@ -43,7 +43,10 @@ struct payload {
>       struct list_head applied_list;       /* Linked to 'applied_list'. */
>       struct xsplice_patch_func *funcs;    /* The array of functions to patch. */
>       unsigned int nfuncs;                 /* Nr of functions to patch. */
> -
> +    size_t core_size;                    /* Only .text size. */
> +    size_t core_text_size;               /* Everything else - .data,.rodata, etc. */

These comments are the wrong way around.

> +    struct bug_frame *start_bug_frames[BUGFRAME_NR]; /* .bug.frame patching. */
> +    struct bug_frame *stop_bug_frames[BUGFRAME_NR];
>       char name[XEN_XSPLICE_NAME_SIZE + 1];/* Name of it. */
>   };
>
> @@ -544,26 +547,27 @@ static void free_payload_data(struct payload *payload)
>       payload->payload_pages = 0;
>   }
>
> -static void calc_section(struct xsplice_elf_sec *sec, size_t *core_size)
> +static void calc_section(struct xsplice_elf_sec *sec, size_t *size)
>   {
> -    size_t align_size = ROUNDUP(*core_size, sec->sec->sh_addralign);
> +    size_t align_size = ROUNDUP(*size, sec->sec->sh_addralign);
>       sec->sec->sh_entsize = align_size;
> -    *core_size = sec->sec->sh_size + align_size;
> +    *size = sec->sec->sh_size + align_size;
>   }
>
>   static int move_payload(struct payload *payload, struct xsplice_elf *elf)
>   {
>       uint8_t *buf;
>       unsigned int i;
> -    size_t core_size = 0;
> +    size_t size = 0;
>
>       /* Compute text regions */
>       for ( i = 0; i < elf->hdr->e_shnum; i++ )
>       {
>           if ( (elf->sec[i].sec->sh_flags & (SHF_ALLOC|SHF_EXECINSTR)) ==
>                (SHF_ALLOC|SHF_EXECINSTR) )
> -            calc_section(&elf->sec[i], &core_size);
> +            calc_section(&elf->sec[i], &size);
>       }
> +    payload->core_text_size = size;
>
>       /* Compute rw data */
>       for ( i = 0; i < elf->hdr->e_shnum; i++ )
> @@ -571,7 +575,7 @@ static int move_payload(struct payload *payload, struct xsplice_elf *elf)
>           if ( (elf->sec[i].sec->sh_flags & SHF_ALLOC) &&
>                !(elf->sec[i].sec->sh_flags & SHF_EXECINSTR) &&
>                (elf->sec[i].sec->sh_flags & SHF_WRITE) )
> -            calc_section(&elf->sec[i], &core_size);
> +            calc_section(&elf->sec[i], &size);
>       }
>
>       /* Compute ro data */
> @@ -580,16 +584,17 @@ static int move_payload(struct payload *payload, struct xsplice_elf *elf)
>           if ( (elf->sec[i].sec->sh_flags & SHF_ALLOC) &&
>                !(elf->sec[i].sec->sh_flags & SHF_EXECINSTR) &&
>                !(elf->sec[i].sec->sh_flags & SHF_WRITE) )
> -            calc_section(&elf->sec[i], &core_size);
> +            calc_section(&elf->sec[i], &size);
>       }
> +    payload->core_size = size;
>
> -    buf = alloc_payload(core_size);
> +    buf = alloc_payload(size);
>       if ( !buf ) {
>           printk(XENLOG_ERR "%s: Could not allocate memory for module\n",
>                  elf->name);
>           return -ENOMEM;
>       }
> -    memset(buf, 0, core_size);
> +    memset(buf, 0, size);
>
>       for ( i = 0; i < elf->hdr->e_shnum; i++ )
>       {
> @@ -604,7 +609,7 @@ static int move_payload(struct payload *payload, struct xsplice_elf *elf)
>       }
>
>       payload->payload_address = buf;
> -    payload->payload_pages = PFN_UP(core_size);
> +    payload->payload_pages = PFN_UP(size);

These renames should be folded into the originating patch (patch 8) or 
dropped.

>
>       return 0;
>   }
> @@ -647,6 +652,22 @@ static int find_special_sections(struct payload *payload,
>               if ( f->pad[j] )
>                   return -EINVAL;
>       }
> +    for ( i = 0; i < BUGFRAME_NR; i++ )
> +    {
> +        char str[14];
> +
> +        snprintf(str, sizeof str, ".bug_frames.%d", i);
> +        sec = xsplice_elf_sec_by_name(elf, str);
> +        if ( !sec )
> +            continue;
> +
> +        if ( ( !sec->sec->sh_size ) ||
> +             ( sec->sec->sh_size % sizeof (struct bug_frame) ) )
> +            return -EINVAL;
> +
> +        payload->start_bug_frames[i] = (struct bug_frame *)sec->load_addr;
> +        payload->stop_bug_frames[i] = (struct bug_frame *)(sec->load_addr + sec->sec->sh_size);
> +    }
>       return 0;
>   }
>
> @@ -942,6 +963,72 @@ void do_xsplice(void)
>       }
>   }
>
> +
> +/*
> + * Functions for handling special sections.
> + */
> +struct bug_frame *xsplice_find_bug(const char *eip, int *id)
> +{
> +    struct payload *data;
> +    struct bug_frame *bug;
> +    int i;
> +
> +    /* No locking since this list is only ever changed during apply or revert
> +     * context. */
> +    list_for_each_entry ( data, &applied_list, applied_list )
> +    {
> +        for (i = 0; i < 4; i++) {

BUGFRAME_NR

> +            if (!data->start_bug_frames[i])
> +                continue;
> +            if ( !((void *)eip >= data->payload_address &&
> +                   (void *)eip < (data->payload_address + data->core_text_size)))
> +                continue;
> +
> +            for ( bug = data->start_bug_frames[i]; bug != data->stop_bug_frames[i]; ++bug ) {
> +                if ( bug_loc(bug) == eip )
> +                {
> +                    *id = i;
> +                    return bug;
> +                }
> +            }
> +        }
> +    }
> +
> +    return NULL;
> +}
> +

-- 
Ross Lagerwall

  reply	other threads:[~2016-01-19 14:43 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-14 21:46 [PATCH v2] xSplice v1 implementation Konrad Rzeszutek Wilk
2016-01-14 21:46 ` [PATCH v2 01/13] xsplice: Design document (v5) Konrad Rzeszutek Wilk
2016-01-19 11:14   ` Wei Liu
2016-01-19 14:31   ` Ross Lagerwall
2016-02-05 18:27     ` Konrad Rzeszutek Wilk
2016-02-05 18:34     ` Konrad Rzeszutek Wilk
2016-02-05 15:25   ` Jan Beulich
2016-02-05 21:47     ` Konrad Rzeszutek Wilk
2016-02-09  8:25       ` Jan Beulich
2016-01-14 21:47 ` [PATCH v2 02/13] hypervisor/arm/keyhandler: Declare struct cpu_user_regs; Konrad Rzeszutek Wilk
2016-01-14 21:47 ` [PATCH v2 03/13] xen/xsplice: Hypervisor implementation of XEN_XSPLICE_op (v7) Konrad Rzeszutek Wilk
2016-01-19 14:30   ` Ross Lagerwall
2016-02-06 22:35   ` Doug Goldstein
2016-02-09  8:28     ` Jan Beulich
2016-02-09 14:39     ` Konrad Rzeszutek Wilk
2016-01-14 21:47 ` [PATCH v2 04/13] libxc: Implementation of XEN_XSPLICE_op in libxc (v4) Konrad Rzeszutek Wilk
2016-01-19 11:14   ` Wei Liu
2016-01-14 21:47 ` [PATCH v2 05/13] xen-xsplice: Tool to manipulate xsplice payloads (v3) Konrad Rzeszutek Wilk
2016-01-19 11:14   ` Wei Liu
2016-01-19 14:30   ` Ross Lagerwall
2016-01-14 21:47 ` [PATCH v2 06/13] elf: Add relocation types to elfstructs.h Konrad Rzeszutek Wilk
2016-01-14 21:47 ` [PATCH v2 07/13] xsplice: Add helper elf routines (v2) Konrad Rzeszutek Wilk
2016-01-19 14:33   ` Ross Lagerwall
2016-02-05 18:38     ` Konrad Rzeszutek Wilk
2016-02-05 20:34       ` Konrad Rzeszutek Wilk
2016-01-14 21:47 ` [PATCH v2 08/13] xsplice: Implement payload loading (v2) Konrad Rzeszutek Wilk
2016-01-19 14:34   ` Ross Lagerwall
2016-01-19 16:59     ` Konrad Rzeszutek Wilk
2016-01-25 11:21       ` Ross Lagerwall
2016-01-19 16:45   ` Ross Lagerwall
2016-01-14 21:47 ` [PATCH v2 09/13] xsplice: Implement support for applying/reverting/replacing patches. (v2) Konrad Rzeszutek Wilk
2016-01-19 14:39   ` Ross Lagerwall
2016-01-19 16:55     ` Konrad Rzeszutek Wilk
2016-01-25 11:43       ` Ross Lagerwall
2016-02-05 19:30         ` Konrad Rzeszutek Wilk
2016-01-14 21:47 ` [PATCH v2 10/13] xen_hello_world.xsplice: Test payload for patching 'xen_extra_version' Konrad Rzeszutek Wilk
2016-01-19 11:14   ` Wei Liu
2016-01-19 14:57   ` Ross Lagerwall
2016-01-19 16:47   ` Ross Lagerwall
2016-01-14 21:47 ` [PATCH v2 11/13] xsplice: Add support for bug frames. (v2) Konrad Rzeszutek Wilk
2016-01-19 14:42   ` Ross Lagerwall [this message]
2016-01-14 21:47 ` [PATCH v2 12/13] xsplice: Add support for exception tables. (v2) Konrad Rzeszutek Wilk
2016-01-14 21:47 ` [PATCH v2 13/13] xsplice: Add support for alternatives Konrad Rzeszutek Wilk
2016-01-15 16:58 ` [PATCH v2] xSplice v1 implementation Konrad Rzeszutek Wilk
2016-01-25 11:57   ` Ross Lagerwall

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=569E4B70.7000204@citrix.com \
    --to=ross.lagerwall@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=konrad.wilk@oracle.com \
    --cc=mpohlack@amazon.com \
    --cc=sasha.levin@oracle.com \
    --cc=stefano.stabellini@citrix.com \
    --cc=wei.liu2@citrix.com \
    --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.