From patchwork Mon Apr 1 02:28:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glenn Enright X-Patchwork-Id: 10878953 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 5C66A14DE for ; Mon, 1 Apr 2019 02:31:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 30B1B28812 for ; Mon, 1 Apr 2019 02:31:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C1AF2881E; Mon, 1 Apr 2019 02:31:00 +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 EDDCA28812 for ; Mon, 1 Apr 2019 02:30:58 +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 1hAmhC-0003Ho-Ij; Mon, 01 Apr 2019 02:29:10 +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 1hAmhA-0003Hh-Qq for xen-devel@lists.xen.org; Mon, 01 Apr 2019 02:29:08 +0000 X-Inumbo-ID: ea2edc5a-5425-11e9-bd63-13da0021aa0a Received: from mail.rimuhosting.com (unknown [206.123.102.5]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id ea2edc5a-5425-11e9-bd63-13da0021aa0a; Mon, 01 Apr 2019 02:29:03 +0000 (UTC) Received: from mail.rimuhosting.com (localhost [127.0.0.1]) by mail.rimuhosting.com (Postfix) with ESMTP id 44EFF61975; Mon, 1 Apr 2019 02:29:02 +0000 (UTC) Received: from [192.168.0.140] (office.rimuhosting.com [203.86.204.227]) by mail.rimuhosting.com (Postfix) with ESMTPSA id 7690561877; Mon, 1 Apr 2019 02:29:01 +0000 (UTC) To: xen-devel@lists.xen.org From: Glenn Enright Organization: RimuHosting Message-ID: <8a1e6171-0238-4e64-5879-44233d3dec64@rimuhosting.com> Date: Mon, 1 Apr 2019 15:28:59 +1300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 Content-Language: en-GB Subject: [Xen-devel] livepatch-build-tools: fix section mismatch 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@citrix.com, Konrad Rzeszutek Wilk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP I hit an issue generating a livepatch for a recent xsa. I saw the following lines from the 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 looks really similar to the issue reported and fixed in https://github.com/dynup/kpatch/pull/528 The attached patch is based on that report, and resulted in a good livepatch. The alt section size in my case was actually 14. Regards, Glenn 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