From patchwork Fri Apr 12 04:50:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glenn Enright X-Patchwork-Id: 10897233 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 411A91708 for ; Fri, 12 Apr 2019 04:53:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0267C28D6D for ; Fri, 12 Apr 2019 04:53:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E5AEE28E43; Fri, 12 Apr 2019 04:53:17 +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=-5.2 required=2.0 tests=BAYES_00,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 1BBC928D6D for ; Fri, 12 Apr 2019 04:53:17 +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 1hEo9d-0007KD-Qx; Fri, 12 Apr 2019 04:51:09 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hEo9d-0007K8-1P for xen-devel@lists.xen.org; Fri, 12 Apr 2019 04:51:09 +0000 X-Inumbo-ID: 94d4caf3-5cde-11e9-92d7-bc764e045a96 Received: from mail.rimuhosting.com (unknown [206.123.102.5]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 94d4caf3-5cde-11e9-92d7-bc764e045a96; Fri, 12 Apr 2019 04:51:06 +0000 (UTC) Received: from mail.rimuhosting.com (localhost [127.0.0.1]) by mail.rimuhosting.com (Postfix) with ESMTP id 6EB7C618B2; Fri, 12 Apr 2019 04:50:35 +0000 (UTC) Received: from [192.168.0.140] (office.rimuhosting.com [203.86.204.227]) by mail.rimuhosting.com (Postfix) with ESMTPSA id B1C1E618B1; Fri, 12 Apr 2019 04:50:34 +0000 (UTC) From: Glenn Enright To: xen-devel Organization: RimuHosting Message-ID: Date: Fri, 12 Apr 2019 16:50:33 +1200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 Content-Language: en-US Subject: [Xen-devel] [PATCH] livepatch-build-tools: Detect special section group sizes X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Reply-To: glenn@rimuhosting.com Cc: Ross Lagerwall , Konrad Wilk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP A recent xsa livepatch failed to generate due to the following message in create-diff-object.log ... /livepatch-build-tools/create-diff-object: ERROR: grant_table.o: kpatch_regenerate_special_section: 1162: group size mismatch for section .altinstructions This is similar to the issue reported and fixed in https://github.com/dynup/kpatch/pull/528 which says ... "Hard-coding the special section group sizes is unreliable. Instead, determine them dynamically by finding the related struct definitions in the DWARF metadata." Signed-off-by: Glenn Enright Reviewed-by: Ross Lagerwall --- CC: Ross Lagerwall CC: Konrad Rzeszutek Wilk This patch resulted in a loadable livepatch. The alt section size in my case was actually 14. --- create-diff-object.c | 30 ++++++++++++++++++++++++++++-- livepatch-build | 21 +++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/create-diff-object.c b/create-diff-object.c index 82f777e..f9f4abf 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -962,9 +962,35 @@ static int bug_frames_0_group_size(struct kpatch_elf *kelf, int offset) { return 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; } +int ex_table_group_size(struct kpatch_elf *kelf, int offset) +{ + static int size = 0; + char *str; + + if (!size) { + str = getenv("EX_STRUCT_SIZE"); + if (!str) + ERROR("EX_STRUCT_SIZE not set"); + size = atoi(str); + } + + return size; +} +int altinstructions_group_size(struct kpatch_elf *kelf, int offset) +{ + static int size = 0; + char *str; + + if (!size) { + str = getenv("ALT_STRUCT_SIZE"); + if (!str) + ERROR("ALT_STRUCT_SIZE not set"); + size = atoi(str); + } + + return size; +} /* * The rela groups in the .fixup section vary in size. The beginning of each * .fixup rela group is referenced by the .ex_table section. To find the size diff --git a/livepatch-build b/livepatch-build index c057fa1..6c3409c 100755 --- a/livepatch-build +++ b/livepatch-build @@ -304,6 +304,27 @@ if [ "${SKIP}" != "build" ]; then XEN_DEBUG="debug=$XEN_DEBUG" fi + echo "Reading special section data" + SPECIAL_VARS=$(readelf -wi "$XENSYMS" | + gawk --non-decimal-data ' + BEGIN { a = e = 0 } + a == 0 && /DW_AT_name.* alt_instr$/ {a = 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} + e == 1 {printf("export EX_STRUCT_SIZE=%d\n", $4); e = 2} + a == 2 && b == 2 && p == 2 && e == 2 {exit}') + + [[ -n $SPECIAL_VARS ]] && eval "$SPECIAL_VARS" + + if [[ -z $ALT_STRUCT_SIZE ]] || [[ -z $EX_STRUCT_SIZE ]]; then + die "can't find special struct size" + fi + for i in $ALT_STRUCT_SIZE $EX_STRUCT_SIZE; do + if [[ ! $i -gt 0 ]] || [[ ! $i -le 16 ]]; then + die "invalid special struct size $i" + fi + done + echo "Perform full initial build with ${CPUS} CPU(s)..." build_full