From patchwork Tue Aug 20 12:07:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11103695 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C753F912 for ; Tue, 20 Aug 2019 12:09:40 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A31962082F for ; Tue, 20 Aug 2019 12:09:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.de header.i=@amazon.de header.b="Y+mI0CbQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A31962082F Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i02vM-0004oy-RE; Tue, 20 Aug 2019 12:07:40 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i02vM-0004ot-7y for xen-devel@lists.xen.org; Tue, 20 Aug 2019 12:07:40 +0000 X-Inumbo-ID: 1b16f884-c343-11e9-b90c-bc764e2007e4 Received: from smtp-fw-6001.amazon.com (unknown [52.95.48.154]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1b16f884-c343-11e9-b90c-bc764e2007e4; Tue, 20 Aug 2019 12:07:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566302859; x=1597838859; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=HAXsjhTLWwcLFeLtiLgEL4pHnbKqXmrZ3SbE96+6/UM=; b=Y+mI0CbQ3ERXvYcOLRLalKTgSIqZMow0dAN+PLCJ5bMGEMrx7rmo7W8o 0AYsQdcIGkh/pclzOWx/5gcM6zKhTNSDRtWN+8VK5v4e+Ksnq4Db8QZUA DFzwd4eqLnn+vT0OOnEjw+f4KqykACPhX58LnQhF61JpKBePqyShmwk22 0=; X-IronPort-AV: E=Sophos;i="5.64,408,1559520000"; d="scan'208";a="410458113" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1e-57e1d233.us-east-1.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 20 Aug 2019 12:07:32 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1e-57e1d233.us-east-1.amazon.com (Postfix) with ESMTPS id 6EA7B141534; Tue, 20 Aug 2019 12:07:31 +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; Tue, 20 Aug 2019 12:07:31 +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; Tue, 20 Aug 2019 12:07:29 +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; Tue, 20 Aug 2019 12:07:27 +0000 From: Pawel Wieczorkiewicz To: Date: Tue, 20 Aug 2019 12:07:21 +0000 Message-ID: <20190820120721.88445-1-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190808123527.8340-1-wipawel@amazon.de> References: <20190808123527.8340-1-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [livepatch-build-tools part2 v3 5/6] create-diff-object: Add new entries to special sections array 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, wipawel@amazon.de, konrad.wilk@oracle.com Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Handle .livepatch.hooks* and .altinstr_replacement sections as the special sections with assigned group_size resolution function. By default each .livepatch.hooks* sections' entry is 8 bytes long (a pointer). The .altinstr_replacement section has undefined group_size. Allow to specify different .livepatch.hooks* section entry size using shell environment variable HOOK_STRUCT_SIZE. Add an explicit check to kpatch_regenerate_special_section() skipping regeneration of special sections, whose group_size is 0. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Andra-Irina Paraschiv Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey --- v3: * Added an explicit check to kpatch_regenerate_special_section() skipping regeneration of special sections, whose group_size is 0. v2: * Applied suggestions from Ross and neccessary changes enforced by previous patch of the series: - fixed indentation - used log_debug() instead of printf() - added aux. function undefined_group_size() returning 0 for a undefined group_size - added .altinstr_replacement to the special_sections array and fixed its group_size to undefined (0). --- create-diff-object.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/create-diff-object.c b/create-diff-object.c index c6183c3..0d231d5 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -995,6 +995,24 @@ static int altinstructions_group_size(struct kpatch_elf *kelf, int offset) return size; } +static int livepatch_hooks_group_size(struct kpatch_elf *kelf, int offset) +{ + static int size = 0; + char *str; + if (!size) { + str = getenv("HOOK_STRUCT_SIZE"); + size = str ? atoi(str) : 8; + } + + log_debug("livepatch_hooks_size=%d\n", size); + return size; +} + +static int undefined_group_size(struct kpatch_elf *kelf, int offset) +{ + return 0; +} + /* * 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 @@ -1072,6 +1090,18 @@ static struct special_section special_sections[] = { .name = ".altinstructions", .group_size = altinstructions_group_size, }, + { + .name = ".altinstr_replacement", + .group_size = undefined_group_size, + }, + { + .name = ".livepatch.hooks.load", + .group_size = livepatch_hooks_group_size, + }, + { + .name = ".livepatch.hooks.unload", + .group_size = livepatch_hooks_group_size, + }, {}, }; @@ -1142,6 +1172,15 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf, LIST_HEAD(newrelas); + src_offset = 0; + dest_offset = 0; + group_size = special->group_size(kelf, src_offset); + if (group_size == 0) { + log_normal("Skipping regeneration of a special section: %s\n", + special->name); + return; + } + src = sec->base->data->d_buf; /* alloc buffer for new base section */ dest = malloc(sec->base->sh.sh_size); @@ -1156,9 +1195,6 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf, } } - group_size = 0; - src_offset = 0; - dest_offset = 0; for ( ; src_offset < sec->base->sh.sh_size; src_offset += group_size) { group_size = special->group_size(kelf, src_offset);