From patchwork Wed Aug 21 08:20:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106051 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 870C9174A for ; Wed, 21 Aug 2019 08:22:47 +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 63F3F2339E for ; Wed, 21 Aug 2019 08:22:47 +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="wCdxRaPI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 63F3F2339E 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 1i0LsX-00028k-8p; Wed, 21 Aug 2019 08:22:01 +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 1i0LsW-00026r-9P for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:22:00 +0000 X-Inumbo-ID: b4c4723c-c3ec-11e9-adc2-12813bfff9fa Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b4c4723c-c3ec-11e9-adc2-12813bfff9fa; Wed, 21 Aug 2019 08:21:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375703; x=1597911703; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=/W7j3nr4ngA5/YC+oCnJXUrP5wTjAmMXZSW82JwTywk=; b=wCdxRaPIX7akvNAe3BL19g6C9CtNsSWoW/kEN2y7JQGuzONMHfaYfveh OWlimf9OibOk+x6vlz9uD6Kua8NjMpYECRDJuSf5qp5Q/b1HLM+R7O2ZZ lR8hautPNtgyhgyzA4tI/n/pJUYA+hH590ebZYQtjeXgucaZ8bLN0XAv1 M=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="822132867" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-2b-8cc5d68b.us-west-2.amazon.com) ([10.47.22.34]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 21 Aug 2019 08:21:36 +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-8cc5d68b.us-west-2.amazon.com (Postfix) with ESMTPS id 2B75BA0631; Wed, 21 Aug 2019 08:21:36 +0000 (UTC) Received: from EX13D05EUC004.ant.amazon.com (10.43.164.38) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:21 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D05EUC004.ant.amazon.com (10.43.164.38) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:20 +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; Wed, 21 Aug 2019 08:21:19 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:45 +0000 Message-ID: <20190821082056.91090-10-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190821082056.91090-1-wipawel@amazon.de> References: <20190821082056.91090-1-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH 09/20] 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: wipawel@amazon.com, Konrad Rzeszutek Wilk , Andrew Cooper , Ross Lagerwall , mpohlack@amazon.com, Pawel Wieczorkiewicz 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 Reviewed-by: Ross Lagerwall --- 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);