From patchwork Tue Apr 16 12:07:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 10902897 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BA05A17E1 for ; Tue, 16 Apr 2019 12:11:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1402289C6 for ; Tue, 16 Apr 2019 12:11:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95FF8289C9; Tue, 16 Apr 2019 12:11:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1863C289CA for ; Tue, 16 Apr 2019 12:11:07 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hGMu0-0000Hk-Qb; Tue, 16 Apr 2019 12:09:28 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hGMtz-0000HV-OM for xen-devel@lists.xen.org; Tue, 16 Apr 2019 12:09:27 +0000 X-Inumbo-ID: 79f57872-6040-11e9-92d7-bc764e045a96 Received: from smtp-fw-9101.amazon.com (unknown [207.171.184.25]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 79f57872-6040-11e9-92d7-bc764e045a96; Tue, 16 Apr 2019 12:09:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1555416565; x=1586952565; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=08Dlw/xFRKLf3C/QMzeNFODGPSjlMtj7Egts5GKTmBQ=; b=v9lhkq/UDPwoo3yxZI53WGkZJbsN3yeL1UidcZqQ9zHZALY6siaMccWE 446uhW76GMmepKVrstDva/NzJN+jCa83l+EEa8c92ScyrG5UT897Uqdo8 ooWvrBN0+azZYt09OIZSKq0UR/RF9FeC+vJYRHfdfFKwaz3n6Fy668psC 0=; X-IronPort-AV: E=Sophos;i="5.60,357,1549929600"; d="scan'208";a="799609739" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-1d-37fd6b3d.us-east-1.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 16 Apr 2019 12:08:08 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1d-37fd6b3d.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id x3GC7f6C051813 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Tue, 16 Apr 2019 12:07:43 GMT Received: from EX13D03EUA001.ant.amazon.com (10.43.165.33) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 16 Apr 2019 12:07:43 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D03EUA001.ant.amazon.com (10.43.165.33) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 16 Apr 2019 12:07:42 +0000 Received: from dev-dsk-wipawel-1a-0c4e6d58.eu-west-1.amazon.com (10.4.134.33) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 16 Apr 2019 12:07:39 +0000 From: Pawel Wieczorkiewicz To: Date: Tue, 16 Apr 2019 12:07:14 +0000 Message-ID: <20190416120716.26269-4-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190416120716.26269-1-wipawel@amazon.de> References: <20190416120716.26269-1-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [livepatch-build-tools part2 4/6] livepatch-build: detect special section group sizes X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: mpohlack@amazon.de, ross.lagerwall@citrix.com, Pawel Wieczorkiewicz , konrad.wilk@oracle.com Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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. [1] https://github.com/jpoimboe/kpatch/commit/170449847136a48b19fcceb19c1d4d257d386b56 Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Bjoern Doebel Reviewed-by: Martin Mazein --- 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"