From patchwork Thu Aug 8 12:23:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11084073 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 8DED313B1 for ; Thu, 8 Aug 2019 12:25:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74D0F28694 for ; Thu, 8 Aug 2019 12:25:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6268F2883A; Thu, 8 Aug 2019 12:25:50 +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 F24D628694 for ; Thu, 8 Aug 2019 12:25:49 +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 1hvhSQ-0003Xs-UB; Thu, 08 Aug 2019 12:23:50 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hvhSP-0003Xm-To for xen-devel@lists.xen.org; Thu, 08 Aug 2019 12:23:50 +0000 X-Inumbo-ID: 5dfd7508-b9d7-11e9-bf43-ab86a4908789 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5dfd7508-b9d7-11e9-bf43-ab86a4908789; Thu, 08 Aug 2019 12:23:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1565267026; x=1596803026; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=zfluy9OxooAdZWBZYasAC8ZsEchgo63lERiexEBAoHc=; b=wH/xm48zXCoEzWAIW9geqXm70iHaLXD6NFIEOR85xzsJvD0DrPRE2KpD ZICFLNiQLou9Uv77KqUaEMlx80oi/+KtI0vsyYTLnW/z2fEU5S53QHkAM uz4KSS2TyDiGkN25bUP4WtbuRhYff7aQhuBUBl2KcCjuoE+oTroE88n6Q M=; X-IronPort-AV: E=Sophos;i="5.64,361,1559520000"; d="scan'208";a="817918258" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-2a-119b4f96.us-west-2.amazon.com) ([10.47.22.34]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 08 Aug 2019 12:23:41 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-119b4f96.us-west-2.amazon.com (Postfix) with ESMTPS id 6022D1A55E1; Thu, 8 Aug 2019 12:23:41 +0000 (UTC) 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; Thu, 8 Aug 2019 12:23:40 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D03EUA001.ant.amazon.com (10.43.165.33) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 8 Aug 2019 12:23:40 +0000 Received: from dev-dsk-wipawel-1a-0c4e6d58.eu-west-1.amazon.com (10.4.134.33) by mail-relay.amazon.com (10.43.60.129) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Thu, 8 Aug 2019 12:23:38 +0000 From: Pawel Wieczorkiewicz To: Date: Thu, 8 Aug 2019 12:23:34 +0000 Message-ID: <20190808122334.6671-1-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190416120716.26269-3-wipawel@amazon.de> References: <20190416120716.26269-3-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [livepatch-build-tools part2 v2 3/6] create-diff-object: Add is_special_section() helper function function 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 This function determines, based on the given section name, if the sections belongs to the special sections category. Add more special sections to special_sections[] along with a new undefined_group_size() helper function returning 0 (undefined). New special sections are: .altinstr_replacement. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Andra-Irina Paraschiv Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey Reviewed-by: Ross Lagerwall --- v2: * Applied suggestions from Ross: - const for the parameter - reusing special_sections array rather than duplicating it * moving the function from common.c to create-diff-object.c * strictly checking for full section names --- create-diff-object.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/create-diff-object.c b/create-diff-object.c index 4699ba0..0df3fea 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1045,6 +1045,18 @@ static struct special_section special_sections[] = { {}, }; +static int is_special_section(const struct section *sec) +{ + struct special_section *special; + + for (special = special_sections; special->name; special++) { + if (!strcmp(sec->name, special->name)) + return true; + } + + return false; +} + static int should_keep_rela_group(struct section *sec, int start, int size) { struct rela *rela; From patchwork Thu Aug 8 12:29:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11084075 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 28A88112C for ; Thu, 8 Aug 2019 12:31:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17D1C2877F for ; Thu, 8 Aug 2019 12:31:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0BE9F28793; Thu, 8 Aug 2019 12:31:03 +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 7D4DE2877F for ; Thu, 8 Aug 2019 12:31:02 +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 1hvhXo-0003px-8i; Thu, 08 Aug 2019 12:29:24 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hvhXm-0003pd-7p for xen-devel@lists.xen.org; Thu, 08 Aug 2019 12:29:22 +0000 X-Inumbo-ID: 2505df6e-b9d8-11e9-8980-bc764e045a96 Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 2505df6e-b9d8-11e9-8980-bc764e045a96; Thu, 08 Aug 2019 12:29:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1565267360; x=1596803360; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=jFuRUVpsM4kJWRU93R+7hjzJ2+0PHC2XYVGbEEqrb2I=; b=j/GnCA4OvclFFbenDX1/HWCYO5uZVumylJzY73AWAonIJp3qOcB7RDgO xPIvWN7rJsKVUsbDU4zZ/VDybRHiQYGK5h9XZzLkHY1BFckTQTYLIqpUT ffg35K9SaiYus85M5n2EsmSnYccIRBFuQQPL8L6/U0YscjTPjh5Fmxd4P I=; X-IronPort-AV: E=Sophos;i="5.64,361,1559520000"; d="scan'208";a="692032166" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2b-4ff6265a.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 08 Aug 2019 12:29:17 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2b-4ff6265a.us-west-2.amazon.com (Postfix) with ESMTPS id 58C83A2208; Thu, 8 Aug 2019 12:29:17 +0000 (UTC) Received: from EX13D05EUC001.ant.amazon.com (10.43.164.118) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 8 Aug 2019 12:29:16 +0000 Received: from EX13MTAUWC001.ant.amazon.com (10.43.162.135) by EX13D05EUC001.ant.amazon.com (10.43.164.118) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 8 Aug 2019 12:29:15 +0000 Received: from dev-dsk-wipawel-1a-0c4e6d58.eu-west-1.amazon.com (10.4.134.33) by mail-relay.amazon.com (10.43.162.232) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Thu, 8 Aug 2019 12:29:13 +0000 From: Pawel Wieczorkiewicz To: Date: Thu, 8 Aug 2019 12:29:09 +0000 Message-ID: <20190808122909.7162-1-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190416120716.26269-4-wipawel@amazon.de> References: <20190416120716.26269-4-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [livepatch-build-tools part2 v2 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 structures 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 Reviewed-by: Ross Lagerwall --- v2: * Applied suggestions from Ross: - moved the livepatch-build hunk after build_full() call and re-using newly built xen-syms - dropped the redundant bug_frames_3_group_size() --- create-diff-object.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- livepatch-build | 22 ++++++++++++++++++++++ 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/create-diff-object.c b/create-diff-object.c index 0df3fea..c6183c3 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -958,12 +958,42 @@ 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 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; + } + + log_debug("altinstr_size=%d\n", size); + return size; +} /* * The rela groups in the .fixup section vary in size. The beginning of each @@ -1016,19 +1046,19 @@ 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", - .group_size = bug_frames_3_group_size, + .group_size = bug_frames_group_size, }, { .name = ".fixup", diff --git a/livepatch-build b/livepatch-build index 3c4bf13..7068faf 100755 --- a/livepatch-build +++ b/livepatch-build @@ -315,6 +315,28 @@ if [ "${SKIP}" != "build" ]; then echo "Perform full initial build with ${CPUS} CPU(s)..." build_full + echo "Reading special section data" + # Using xen-syms built in the previous step by build_full(). + SPECIAL_VARS=$(readelf -wi "$OUTPUT/xen-syms" | + 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 + echo "Apply patch and build with ${CPUS} CPU(s)..." cd "$SRCDIR" || die patch -s -N -p1 -f --fuzz=0 < "$PATCHFILE" || die