All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Pawel Wieczorkiewicz <wipawel@amazon.de>
Cc: mpohlack@amazon.de, ross.lagerwall@citrix.com, xen-devel@lists.xen.org
Subject: Re: [livepatch-build-tools part2 4/6] livepatch-build: detect special section group sizes
Date: Thu, 25 Apr 2019 00:53:39 -0400	[thread overview]
Message-ID: <20190425045339.GE11831@char.us.oracle.com> (raw)
In-Reply-To: <20190416120716.26269-4-wipawel@amazon.de>

On Tue, Apr 16, 2019 at 12:07:14PM +0000, Pawel Wieczorkiewicz wrote:
> Hard-coding the special section group sizes is unreliable. Instead,
> determine them dynamically by finding the related struct definitions
> in the DWARF metadata.
> 
> This is a livepatch backport of kpatch upstream commit [1]:
> kpatch-build: detect special section group sizes 170449847136a48b19fc
> 
> Xen only deals with alt_instr, bug_frame and exception_table_entry
> structures, so sizes of these structers are obtained from xen-syms.
> 
> This change is needed since with recent Xen the alt_instr structure
> has changed size from 12 to 14 bytes.

Oh this is so much better than the "solution" we coded.

Thank you!

Ross, will commit to repo unless you have concerns..
> 
> [1] https://github.com/jpoimboe/kpatch/commit/170449847136a48b19fcceb19c1d4d257d386b56
> 
> Signed-off-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
> Reviewed-by: Bjoern Doebel <doebel@amazon.de>
> Reviewed-by: Martin Mazein <amazein@amazon.de>
> ---
>  create-diff-object.c | 60 ++++++++++++++++++++++++++++++++++++++++++++--------
>  livepatch-build      | 23 ++++++++++++++++++++
>  2 files changed, 74 insertions(+), 9 deletions(-)
> 
> diff --git a/create-diff-object.c b/create-diff-object.c
> index 1e6e617..b0b4dcb 100644
> --- a/create-diff-object.c
> +++ b/create-diff-object.c
> @@ -958,12 +958,54 @@ static void kpatch_mark_constant_labels_same(struct kpatch_elf *kelf)
>  	}
>  }
>  
> -static int bug_frames_0_group_size(struct kpatch_elf *kelf, int offset) { return 8; }
> -static int bug_frames_1_group_size(struct kpatch_elf *kelf, int offset) { return 8; }
> -static int bug_frames_2_group_size(struct kpatch_elf *kelf, int offset) { return 8; }
> -static int bug_frames_3_group_size(struct kpatch_elf *kelf, int offset) { return 16; }
> -static int ex_table_group_size(struct kpatch_elf *kelf, int offset) { return 8; }
> -static int altinstructions_group_size(struct kpatch_elf *kelf, int offset) { return 12; }
> +static int bug_frames_group_size(struct kpatch_elf *kelf, int offset)
> +{
> +    static int size = 0;
> +    char *str;
> +    if (!size) {
> +        str = getenv("BUG_STRUCT_SIZE");
> +        size = str ? atoi(str) : 8;
> +    }
> +
> +    return size;
> +}
> +
> +static int bug_frames_3_group_size(struct kpatch_elf *kelf, int offset)
> +{
> +    static int size = 0;
> +    char *str;
> +    if (!size) {
> +        str = getenv("BUG_STRUCT_SIZE");
> +        size = str ? atoi(str) : 16;
> +    }
> +
> +    return size;
> +}
> +
> +static int ex_table_group_size(struct kpatch_elf *kelf, int offset)
> +{
> +    static int size = 0;
> +    char *str;
> +    if (!size) {
> +        str = getenv("EX_STRUCT_SIZE");
> +        size = str ? atoi(str) : 8;
> +    }
> +
> +    return size;
> +}
> +
> +static int altinstructions_group_size(struct kpatch_elf *kelf, int offset)
> +{
> +    static int size = 0;
> +    char *str;
> +    if (!size) {
> +        str = getenv("ALT_STRUCT_SIZE");
> +        size = str ? atoi(str) : 12;
> +    }
> +
> +    printf("altinstr_size=%d\n", size);
> +    return size;
> +}
>  
>  /*
>   * The rela groups in the .fixup section vary in size.  The beginning of each
> @@ -1016,15 +1058,15 @@ static int fixup_group_size(struct kpatch_elf *kelf, int offset)
>  static struct special_section special_sections[] = {
>  	{
>  		.name		= ".bug_frames.0",
> -		.group_size	= bug_frames_0_group_size,
> +		.group_size	= bug_frames_group_size,
>  	},
>  	{
>  		.name		= ".bug_frames.1",
> -		.group_size	= bug_frames_1_group_size,
> +		.group_size	= bug_frames_group_size,
>  	},
>  	{
>  		.name		= ".bug_frames.2",
> -		.group_size	= bug_frames_2_group_size,
> +		.group_size	= bug_frames_group_size,
>  	},
>  	{
>  		.name		= ".bug_frames.3",
> diff --git a/livepatch-build b/livepatch-build
> index c057fa1..a6cae12 100755
> --- a/livepatch-build
> +++ b/livepatch-build
> @@ -284,6 +284,29 @@ echo "Output directory: ${OUTPUT}"
>  echo "================================================"
>  echo
>  
> +if [ -f "$XENSYMS" ]; then
> +    echo "Reading special section data"
> +    SPECIAL_VARS=$(readelf -wi "$XENSYMS" |
> +               gawk --non-decimal-data '
> +               BEGIN { a = b = e = 0 }
> +               a == 0 && /DW_AT_name.* alt_instr/ {a = 1; next}
> +               b == 0 && /DW_AT_name.* bug_frame/ {b = 1; next}
> +               e == 0 && /DW_AT_name.* exception_table_entry/ {e = 1; next}
> +               a == 1 {printf("export ALT_STRUCT_SIZE=%d\n", $4); a = 2}
> +               b == 1 {printf("export BUG_STRUCT_SIZE=%d\n", $4); b = 2}
> +               e == 1 {printf("export EX_STRUCT_SIZE=%d\n", $4); e = 2}
> +               a == 2 && b == 2 && e == 2 {exit}')
> +    [[ -n $SPECIAL_VARS ]] && eval "$SPECIAL_VARS"
> +    if [[ -z $ALT_STRUCT_SIZE ]] || [[ -z $BUG_STRUCT_SIZE ]] || [[ -z $EX_STRUCT_SIZE ]]; then
> +        die "can't find special struct size"
> +    fi
> +    for i in $ALT_STRUCT_SIZE $BUG_STRUCT_SIZE $EX_STRUCT_SIZE; do
> +        if [[ ! $i -gt 0 ]] || [[ ! $i -le 16 ]]; then
> +            die "invalid special struct size $i"
> +        fi
> +    done
> +fi
> +
>  if [ "${SKIP}" != "build" ]; then
>      [ -e "${OUTPUT}" ] && die "Output directory exists"
>      grep -q 'CONFIG_LIVEPATCH=y' "${CONFIGFILE}" || die "CONFIG_LIVEPATCH must be enabled"
> -- 
> 2.16.5
> 
> 
> 
> 
> Amazon Development Center Germany GmbH
> Krausenstr. 38
> 10117 Berlin
> Geschaeftsfuehrer: Christian Schlaeger, Ralf Herbrich
> Ust-ID: DE 289 237 879
> Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
> 
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2019-04-25  4:53 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-16 12:07 [livepatch-build-tools part2 1/6] common: Add is_standard_section() helper function Pawel Wieczorkiewicz
2019-04-16 12:07 ` [livepatch-build-tools part2 2/6] common: Add is_referenced_section() " Pawel Wieczorkiewicz
2019-04-29 15:14   ` Ross Lagerwall
2019-04-29 15:58     ` Wieczorkiewicz, Pawel
2019-04-16 12:07 ` [livepatch-build-tools part2 3/6] create-diff-object: Add is_special_section() " Pawel Wieczorkiewicz
2019-04-29 15:25   ` Ross Lagerwall
2019-04-30 12:18     ` Wieczorkiewicz, Pawel
2019-04-16 12:07 ` [livepatch-build-tools part2 4/6] livepatch-build: detect special section group sizes Pawel Wieczorkiewicz
2019-04-25  4:53   ` Konrad Rzeszutek Wilk [this message]
2019-04-29 14:14     ` Ross Lagerwall
2019-04-29 21:53       ` Glenn Enright
2019-04-29 14:10   ` Ross Lagerwall
2019-04-29 14:21     ` Ross Lagerwall
2019-04-29 15:19       ` Wieczorkiewicz, Pawel
2019-04-16 12:07 ` [livepatch-build-tools part2 5/6] create-diff-object: Add new entries to special sections array Pawel Wieczorkiewicz
2019-04-29 15:47   ` Ross Lagerwall
2019-04-30 13:01     ` Wieczorkiewicz, Pawel
2019-04-16 12:07 ` [livepatch-build-tools part2 6/6] create-diff-object: Do not include all .rodata sections Pawel Wieczorkiewicz
2019-04-29 16:11   ` Ross Lagerwall
2019-04-30 13:28     ` Wieczorkiewicz, Pawel
2019-04-29 15:07 ` [livepatch-build-tools part2 1/6] common: Add is_standard_section() helper function 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=20190425045339.GE11831@char.us.oracle.com \
    --to=konrad.wilk@oracle.com \
    --cc=mpohlack@amazon.de \
    --cc=ross.lagerwall@citrix.com \
    --cc=wipawel@amazon.de \
    --cc=xen-devel@lists.xen.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.