From patchwork Wed Aug 21 08:20:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106043 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 7A637174A for ; Wed, 21 Aug 2019 08:22:38 +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 5792C2339E for ; Wed, 21 Aug 2019 08:22:38 +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="q38xutvS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5792C2339E 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 1i0Lry-0000zp-R5; Wed, 21 Aug 2019 08:21:26 +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 1i0Lrx-0000wh-8t for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:21:25 +0000 X-Inumbo-ID: a98f9478-c3ec-11e9-adc2-12813bfff9fa Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a98f9478-c3ec-11e9-adc2-12813bfff9fa; Wed, 21 Aug 2019 08:21:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375683; x=1597911683; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=rTdq6bk4WUwGpssROk8t7Agg5oVsWJLKT4jR4h03AWY=; b=q38xutvSjms+IrOhJt5blYrpkRZ+o+bdSLeVL2fitgaG+CfHgC/B1k+R IK/aasYgeUtg6HSiWUbD9WX500DKfp5PraGTg+RxxIirsmyiDqj8qEHvR xkjR+cU8HvxQUy4YBm4d5YbqHny0uLBNbaaq3qd9UB34mS7Zq6TC/elcu s=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="695968500" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2a-8549039f.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 21 Aug 2019 08:21:23 +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-8549039f.us-west-2.amazon.com (Postfix) with ESMTPS id 34FB3A1EF6; Wed, 21 Aug 2019 08:21:22 +0000 (UTC) Received: from EX13D03EUA003.ant.amazon.com (10.43.165.89) 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:06 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D03EUA003.ant.amazon.com (10.43.165.89) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:05 +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:04 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:37 +0000 Message-ID: <20190821082056.91090-2-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 01/20] livepatch-gcc: Allow toolchain command with versions 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" Xen build system may enforce particular gcc version (e.g. gcc72). Make sure the livepatch-gcc script accepts all input toolchain gcc commands with or without version specified. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Martin Mazein Reviewed-by: Bjoern Doebel Reviewed-by: Ross Lagerwall --- livepatch-gcc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/livepatch-gcc b/livepatch-gcc index 634157a..617f865 100755 --- a/livepatch-gcc +++ b/livepatch-gcc @@ -25,7 +25,8 @@ shift declare -a args=("$@") keep=no -if [[ "$TOOLCHAINCMD" = "gcc" ]] ; then +declare -r GCC_RE='gcc.*' +if [[ "$TOOLCHAINCMD" =~ $GCC_RE ]] ; then while [ "$#" -gt 0 ]; do if [ "$1" = "-o" ]; then obj=$2 From patchwork Wed Aug 21 08:20:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106073 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 B33CF1395 for ; Wed, 21 Aug 2019 08:23:11 +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 8FAA622DA7 for ; Wed, 21 Aug 2019 08:23:11 +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="Pf9dIns4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FAA622DA7 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 1i0Ls3-00018w-T4; Wed, 21 Aug 2019 08:21:31 +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 1i0Ls2-000160-8x for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:21:30 +0000 X-Inumbo-ID: aaa54254-c3ec-11e9-adc2-12813bfff9fa Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id aaa54254-c3ec-11e9-adc2-12813bfff9fa; Wed, 21 Aug 2019 08:21:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375685; x=1597911685; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=M5rYvOQZXykHxCP4uOSw/7RKcONu+wXq+4nVaEqW9/E=; b=Pf9dIns4SAz8dq+GZQyFSDMM8XOtNyE/DX748ECdyp1XzbYmsrrDt3XK RjoTKmd8suz9ydr5LvCtNPrltxcfq35jj3WIkZGkqFhHcP5jscnTvoGM6 2kPtAudd5kIGXwpTa6BXCBslTT8GKrFe3E19hBtrbSfsKX1wum+FqYvIg w=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="695968508" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2b-55156cd4.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 21 Aug 2019 08:21:25 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-55156cd4.us-west-2.amazon.com (Postfix) with ESMTPS id C77B1A1CFF; Wed, 21 Aug 2019 08:21:24 +0000 (UTC) Received: from EX13D03EUA004.ant.amazon.com (10.43.165.93) 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:08 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D03EUA004.ant.amazon.com (10.43.165.93) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:07 +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:06 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:38 +0000 Message-ID: <20190821082056.91090-3-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 02/20] livepatch-gcc: Ignore built_in.o and prelink.o object files 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" Do not copy over the built_in.o and prelink.o object files when they get rebuilt as they are used for transient linking by Xen's build system. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Martin Pohlack Reviewed-by: Petre Eftime Reviewed-by: Ross Lagerwall --- livepatch-gcc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/livepatch-gcc b/livepatch-gcc index 617f865..01e4b8c 100755 --- a/livepatch-gcc +++ b/livepatch-gcc @@ -35,6 +35,8 @@ if [[ "$TOOLCHAINCMD" =~ $GCC_RE ]] ; then version.o|\ debug.o|\ *.xen-syms.*.o|\ + built_in.o|\ + prelink.o|\ .*.o) break ;; From patchwork Wed Aug 21 08:20:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106053 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 67B001395 for ; Wed, 21 Aug 2019 08:22:48 +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 44B262339F for ; Wed, 21 Aug 2019 08:22:48 +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="BDgOnt/7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 44B262339F 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 1i0Ls9-0001JZ-H4; Wed, 21 Aug 2019 08:21:37 +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 1i0Ls7-0001FH-8u for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:21:35 +0000 X-Inumbo-ID: abc3ae1e-c3ec-11e9-adc2-12813bfff9fa Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id abc3ae1e-c3ec-11e9-adc2-12813bfff9fa; Wed, 21 Aug 2019 08:21:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375687; x=1597911687; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=yjHoo2p+vw3cgZRsjQ4lY3ttQjWxdvrgMGCB7ylyfAU=; b=BDgOnt/71FUxWw2bCVF+kJPfczCFG/PLMwK448UAogjs3SDRBKcDwWwg zGmyVJSLvPpdwzlZfZz3FXAT5IaJt3cjIOT8PapOC0jMfL3+fA1bqKk7H 0KunQFfpgNA5O7b7LSpI+byFqzuWemZIP6oqF+q3XKpkCvXkJNPxuJz73 s=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="695968514" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2a-8549039f.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 21 Aug 2019 08:21:26 +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-8549039f.us-west-2.amazon.com (Postfix) with ESMTPS id 96A51A1BCD; Wed, 21 Aug 2019 08:21:26 +0000 (UTC) Received: from EX13D03EUA002.ant.amazon.com (10.43.165.166) 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:10 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D03EUA002.ant.amazon.com (10.43.165.166) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:09 +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:08 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:39 +0000 Message-ID: <20190821082056.91090-4-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 03/20] livepatch-build: Do not follow every symlink for patch file 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" In some build systems symlinks might be used for patch file names to point from target directories to actual patches. Following those symlinks breaks naming convention as the resulting built modules would be named after the actual hardlink insteads of the symlink. Livepatch-build obtains hotpatch name from the patch file, so it should not canonicalize the file path resolving all the symlinks to not lose the original symlink name. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Martin Pohlack Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey Reviewed-by: Ross Lagerwall --- livepatch-build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/livepatch-build b/livepatch-build index c057fa1..796838c 100755 --- a/livepatch-build +++ b/livepatch-build @@ -265,7 +265,9 @@ done [ -z "$DEPENDS" ] && die "Build-id dependency not given" SRCDIR="$(readlink -m -- "$srcarg")" -PATCHFILE="$(readlink -m -- "$patcharg")" +# We need an absolute path because we move around, but we need to +# retain the name of the symlink (= realpath -s) +PATCHFILE="$(readlink -f "$(dirname "$patcharg")")/$(basename "$patcharg")" CONFIGFILE="$(readlink -m -- "$configarg")" OUTPUT="$(readlink -m -- "$outputarg")" From patchwork Wed Aug 21 08:20:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106019 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 588D61864 for ; Wed, 21 Aug 2019 08:22:19 +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 32A3322DA7 for ; Wed, 21 Aug 2019 08:22:19 +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="U2D8W2wS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 32A3322DA7 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 1i0Ls3-00017o-Ce; Wed, 21 Aug 2019 08:21:31 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0Ls1-00014G-8t for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:21:29 +0000 X-Inumbo-ID: acd2f148-c3ec-11e9-ac23-bc764e2007e4 Received: from smtp-fw-4101.amazon.com (unknown [72.21.198.25]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id acd2f148-c3ec-11e9-ac23-bc764e2007e4; Wed, 21 Aug 2019 08:21:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375689; x=1597911689; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=ZVbLv5KK6ydhNuAuuxIX8qaTZMZ+ZGlSBBIGMaogF3A=; b=U2D8W2wSP6PmvYhWRR+rJTDu7GockHQY7zjmrA8txA+KdFAcL5gH3QvS xBDrdpwrXoRTMN5wIiqhpivKeVT9g2u+4YFOnFpzkAOeFhwnKHUPEAchU GIOlLW7Ci8QGmplCth4xxJRoYOUuQJozi0UkyT7YR5hw+TFhPUvNK1Qp1 A=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="780419082" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-168cbb73.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 21 Aug 2019 08:21:28 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2c-168cbb73.us-west-2.amazon.com (Postfix) with ESMTPS id ED134A2075; Wed, 21 Aug 2019 08:21:27 +0000 (UTC) Received: from EX13D05EUB004.ant.amazon.com (10.43.166.115) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:12 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D05EUB004.ant.amazon.com (10.43.166.115) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:11 +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:09 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:40 +0000 Message-ID: <20190821082056.91090-5-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 04/20] livepatch-build: Handle newly created object files 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" Up to now the livepatch-build ignores newly created object files. When patch applies new .c file and augments its Makefile to build it the resulting object file is not taken into account for final linking step. Such newly created object files can be detected by comparing patched/ and original/ directories and copied over to the output directory for the final linking step. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Andra-Irina Paraschiv Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey Reviewed-by: Ross Lagerwall --- livepatch-build | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/livepatch-build b/livepatch-build index 796838c..3c4bf13 100755 --- a/livepatch-build +++ b/livepatch-build @@ -146,6 +146,12 @@ function create_patch() fi done + NEW_FILES=$(comm -23 <(cd patched/xen && find . -type f -name '*.o' | sort) <(cd original/xen && find . -type f -name '*.o' | sort)) + for i in $NEW_FILES; do + cp "patched/$i" "output/$i" + CHANGED=1 + done + if [[ $ERROR -ne 0 ]]; then die "$ERROR error(s) encountered" fi From patchwork Wed Aug 21 08:20:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106081 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 DB7081395 for ; Wed, 21 Aug 2019 08:23:24 +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 B77CF22DA7 for ; Wed, 21 Aug 2019 08:23:24 +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="IGx22fe8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B77CF22DA7 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 1i0LsE-0001T0-5K; Wed, 21 Aug 2019 08:21:42 +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 1i0LsC-0001PS-Ao for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:21:40 +0000 X-Inumbo-ID: ade9578e-c3ec-11e9-adc2-12813bfff9fa Received: from smtp-fw-6001.amazon.com (unknown [52.95.48.154]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ade9578e-c3ec-11e9-adc2-12813bfff9fa; Wed, 21 Aug 2019 08:21:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375690; x=1597911690; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=SpnBPboP1CnYCqUkqCRpzA3Mo3QOK41CZ1FNd6HCGVo=; b=IGx22fe8Zk3HTWW4P/d6J3x5EMTKblXM7F1Mdl4jrs8/I1YN7TjlIRm5 SugpMlaW+AosAXhmfdeXaiN1j5ruIhM6yo8YPldw6vMVnyxI7g8JTBmaQ dd79waonKKSggHCbG/SnSj3/9Lzttpfjc4yGVPVjShM0nx8drEQe4FVwk k=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="410765145" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2b-55156cd4.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 21 Aug 2019 08:21:29 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-55156cd4.us-west-2.amazon.com (Postfix) with ESMTPS id 65D53A1F4A; Wed, 21 Aug 2019 08:21:29 +0000 (UTC) Received: from EX13D03EUA004.ant.amazon.com (10.43.165.93) 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:14 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D03EUA004.ant.amazon.com (10.43.165.93) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:13 +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:11 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:41 +0000 Message-ID: <20190821082056.91090-6-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 05/20] common: Add is_standard_section() helper 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: 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" Detect standard (always to be included) sections via their section header type. The standard sections: ".shstrtab", ".symtab", ".strtab" are either of type SHT_SYMTAB or SHT_STRTAB. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Andra-Irina Paraschiv Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey Reviewed-by: Ross Lagerwall --- common.c | 12 ++++++++++++ common.h | 1 + create-diff-object.c | 4 +--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/common.c b/common.c index bc63955..1fb07cb 100644 --- a/common.c +++ b/common.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "list.h" @@ -258,6 +259,17 @@ int is_debug_section(struct section *sec) return !strncmp(name, ".debug_", 7); } +int is_standard_section(struct section *sec) +{ + switch (sec->sh.sh_type) { + case SHT_STRTAB: + case SHT_SYMTAB: + return true; + default: + return false; + } +} + /* returns the offset of the string in the string table */ int offset_of_string(struct list_head *list, char *name) { diff --git a/common.h b/common.h index 7599fe7..cda690d 100644 --- a/common.h +++ b/common.h @@ -150,6 +150,7 @@ struct symbol *find_symbol_by_name(struct list_head *list, const char *name); int is_text_section(struct section *sec); int is_debug_section(struct section *sec); int is_rela_section(struct section *sec); +int is_standard_section(struct section *sec); int is_local_sym(struct symbol *sym); void rela_insn(struct section *sec, struct rela *rela, struct insn *insn); diff --git a/create-diff-object.c b/create-diff-object.c index 82f777e..4699ba0 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1278,9 +1278,7 @@ static void kpatch_include_standard_elements(struct kpatch_elf *kelf) list_for_each_entry(sec, &kelf->sections, list) { /* include these sections even if they haven't changed */ - if (!strcmp(sec->name, ".shstrtab") || - !strcmp(sec->name, ".strtab") || - !strcmp(sec->name, ".symtab") || + if (is_standard_section(sec) || should_include_str_section(sec->name)) { sec->include = 1; if (sec->secsym) From patchwork Wed Aug 21 08:20:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106063 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 4E43F174A for ; Wed, 21 Aug 2019 08:23:03 +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 2AAA62339E for ; Wed, 21 Aug 2019 08:23:03 +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="rDQVCw5m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2AAA62339E 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 1i0LsJ-0001ec-8J; Wed, 21 Aug 2019 08:21:47 +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 1i0LsH-0001a2-A0 for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:21:45 +0000 X-Inumbo-ID: aea4f6a7-c3ec-11e9-adc2-12813bfff9fa Received: from smtp-fw-6001.amazon.com (unknown [52.95.48.154]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id aea4f6a7-c3ec-11e9-adc2-12813bfff9fa; Wed, 21 Aug 2019 08:21:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375693; x=1597911693; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=QBL7vyAB8sS7gLIt9JcObmzXvg/bnnm2aii2dcmq544=; b=rDQVCw5m0BkwFqFzugALD1t4fKL4gVM2VFQAR6KzijeoOch7aGwaZDZs ZsdGjUmTLeMP/XeGo/7/YFn4GqOlc/N8BQyLyzowQvP5WIrJm1ApgM/IN 98gfp4pLn+YmyBSsyXTJ/FUrSzspY0WyaA+gWTo4LJxUxKd+ZMdSyNDWy w=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="410765150" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-1c1b5cdd.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 21 Aug 2019 08:21:32 +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-1c1b5cdd.us-west-2.amazon.com (Postfix) with ESMTPS id 5F2A3A073A; Wed, 21 Aug 2019 08:21:32 +0000 (UTC) Received: from EX13D03EUC001.ant.amazon.com (10.43.164.245) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:16 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D03EUC001.ant.amazon.com (10.43.164.245) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 01:21:15 -0700 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:13 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:42 +0000 Message-ID: <20190821082056.91090-7-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 06/20] common: Add is_referenced_section() helper 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: 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" This function checks if given section has an included corresponding RELA section and/or any of the symbols table symbols references the section. Section associated symbols are ignored here as there is always such a symbol for every section. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Andra-Irina Paraschiv Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey Reviewed-by: Ross Lagerwall --- common.c | 23 ++++++++++++++++++++++- common.h | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/common.c b/common.c index 1fb07cb..0ddc9fa 100644 --- a/common.c +++ b/common.c @@ -15,7 +15,7 @@ int is_rela_section(struct section *sec) { - return (sec->sh.sh_type == SHT_RELA); + return sec && (sec->sh.sh_type == SHT_RELA); } int is_local_sym(struct symbol *sym) @@ -270,6 +270,27 @@ int is_standard_section(struct section *sec) } } +int is_referenced_section(const struct section *sec, + const struct kpatch_elf *kelf) +{ + struct symbol *sym; + + if (is_rela_section(sec->rela) && sec->rela->include) + return true; + + list_for_each_entry(sym, &kelf->symbols, list) { + if (!sym->include || !sym->sec) + continue; + /* Ignore section associated sections */ + if (sym->type == STT_SECTION) + continue; + if (sym->sec->index == sec->index) + return true; + } + + return false; +} + /* returns the offset of the string in the string table */ int offset_of_string(struct list_head *list, char *name) { diff --git a/common.h b/common.h index cda690d..06e19e7 100644 --- a/common.h +++ b/common.h @@ -151,6 +151,8 @@ int is_text_section(struct section *sec); int is_debug_section(struct section *sec); int is_rela_section(struct section *sec); int is_standard_section(struct section *sec); +int is_referenced_section(const struct section *sec, + const struct kpatch_elf *kelf); int is_local_sym(struct symbol *sym); void rela_insn(struct section *sec, struct rela *rela, struct insn *insn); From patchwork Wed Aug 21 08:20:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106041 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 37CFA1395 for ; Wed, 21 Aug 2019 08:22:37 +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 145592339E for ; Wed, 21 Aug 2019 08:22:37 +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="S3Tes9wm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 145592339E 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 1i0LsN-0001nT-5I; Wed, 21 Aug 2019 08:21:51 +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 1i0LsM-0001ld-D4 for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:21:50 +0000 X-Inumbo-ID: b03afb32-c3ec-11e9-adc2-12813bfff9fa Received: from smtp-fw-6001.amazon.com (unknown [52.95.48.154]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b03afb32-c3ec-11e9-adc2-12813bfff9fa; Wed, 21 Aug 2019 08:21:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375694; x=1597911694; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=qqeo8XhVoqzWKP+lXIzjkBD7UidvojG69bSEW5ONYfw=; b=S3Tes9wmXbgvR5l3FHLlt0q3Qe7QmuMhnnC9B9YaCg2LzqfIKWPMqLgb IkQQGOjFUZeCM2rIzSkxT4LwJSRP+LElKTzFFv+BIW+RgD/3J2byWFCKf hZKU+W3c49MrKYb4iG7uA57pKFdv32mYUnwVcTwcyIqizzT5/BV+19+iw k=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="410765154" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-8549039f.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 21 Aug 2019 08:21:33 +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-8549039f.us-west-2.amazon.com (Postfix) with ESMTPS id 63606A1BCD; Wed, 21 Aug 2019 08:21:33 +0000 (UTC) Received: from EX13D05EUB004.ant.amazon.com (10.43.166.115) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:17 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D05EUB004.ant.amazon.com (10.43.166.115) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:17 +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:15 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:43 +0000 Message-ID: <20190821082056.91090-8-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 07/20] create-diff-object: Add is_special_section() helper 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: 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" This function determines, based on the given section name, if the sections belongs to the special sections category. 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 | 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 Wed Aug 21 08:20:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106087 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 983721395 for ; Wed, 21 Aug 2019 08:23:37 +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 74CE922DA7 for ; Wed, 21 Aug 2019 08:23:37 +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="QiT76y5M" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 74CE922DA7 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 1i0LsS-0001z0-KC; Wed, 21 Aug 2019 08:21:56 +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 1i0LsR-0001vz-BF for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:21:55 +0000 X-Inumbo-ID: b13bcef8-c3ec-11e9-adc2-12813bfff9fa Received: from smtp-fw-4101.amazon.com (unknown [72.21.198.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b13bcef8-c3ec-11e9-adc2-12813bfff9fa; Wed, 21 Aug 2019 08:21:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375696; x=1597911696; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=vReOtWQZJPcXrdN9qJItKSFxHc76IAEbDsTqNwkVAC4=; b=QiT76y5MTsomXfgcyCqBtPB7lHmEHj7owC6xCHsuTLBDIhiW0FrKIuzX wrDiimQNFZC6cQaOGpdLG9/ZvNiBqeFGgdvnY/UilgHiwQo4HjaKJJpBH 9nEBcgoL1y2SMQV82y9KZlYvgSfZrnDCWito5ouch5p1Zm1MRfUOtW5nE E=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="780419097" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2b-859fe132.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 21 Aug 2019 08:21:35 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-859fe132.us-west-2.amazon.com (Postfix) with ESMTPS id 3D885221949; Wed, 21 Aug 2019 08:21:35 +0000 (UTC) Received: from EX13D03EUC002.ant.amazon.com (10.43.164.60) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:19 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D03EUC002.ant.amazon.com (10.43.164.60) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:18 +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:17 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:44 +0000 Message-ID: <20190821082056.91090-9-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 08/20] 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: 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" 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 --- 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 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); From patchwork Wed Aug 21 08:20:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106035 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 95D431864 for ; Wed, 21 Aug 2019 08:22:32 +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 72E1A233A0 for ; Wed, 21 Aug 2019 08:22:32 +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="todnEN/I" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 72E1A233A0 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 1i0LsE-0001UV-UZ; Wed, 21 Aug 2019 08:21:42 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0LsD-0001Qp-0c for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:21:41 +0000 X-Inumbo-ID: b345b0ce-c3ec-11e9-b95f-bc764e2007e4 Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b345b0ce-c3ec-11e9-b95f-bc764e2007e4; Wed, 21 Aug 2019 08:21:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375700; x=1597911700; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=kxUpEOR3tSmnZdEVaSrNaaizAE6h1DkZ9GtcU05axTA=; b=todnEN/Iv8t6Zr9pIeTt2yAgpXNOGAA3HARkibw3x3aAWgd4W3/9EQNc RPopp9HszBQjEVoajJf+v+X867B/cuBLlhVl12ochfnRwDfltkYJMi/fe 1TtejMF3Cr0wFD/wC6uMr3rEK238t9mt6cUsGs9OchaJPddrmR5Qd+sU/ 0=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="695968556" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2a-f14f4a47.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 21 Aug 2019 08:21:39 +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-f14f4a47.us-west-2.amazon.com (Postfix) with ESMTPS id 9E5C4A2908; Wed, 21 Aug 2019 08:21:38 +0000 (UTC) Received: from EX13D05EUB001.ant.amazon.com (10.43.166.87) 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:23 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D05EUB001.ant.amazon.com (10.43.166.87) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:22 +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:21 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:46 +0000 Message-ID: <20190821082056.91090-11-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 10/20] create-diff-object: Do not include all .rodata sections 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" Older versions of GCC did not split .rodata.str sections by function. Because of that, the entire section was always included. The livepatch-build-tools commit [1] fixed patch creation and kept including all .rodata.str sections, in order to maintain existing behavior for GCC 6.1+. This means all .rodata.str sections are always included by default, regardless of whether they are needed or not. During stacked hotpatch builds it leads to unnecessary accumulation of the .rodata.str sections as each and every consecutive hotpatch module contains all the .rodata.str sections of previous modules. To prevent this situation, mark the .rodata.str sections for inclusion only if they are referenced by any of the current hotpatch symbols (or a corresponding RELA section). Extend patchability verification to detect all non-standard, non-rela, non-debug and non-special sections that are not referenced by any of the symbols or RELA sections. Rename should_include_str_section() to is_rodata_str_section(). [1] 2af6f1aa6233 Fix patch creation with GCC 6.1+ 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 | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/create-diff-object.c b/create-diff-object.c index 0d231d5..a90cf37 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1321,14 +1321,13 @@ static bool isnumber(const char *s) } /* - * String sections are always included even if unchanged. - * The format is either: + * The format of string sections is either: * .rodata..str1.[0-9]+ (new in GCC 6.1.0) * or .rodata.str1.[0-9]+ (older versions of GCC) - * For the new format we could be smarter and only include the needed - * strings sections. + * For the new format we only include the needed strings sections. + * For the old format all string sections are always included. */ -static bool should_include_str_section(const char *name) +static bool is_rodata_str_section(const char *name) { #define GCC_5_SECTION_NAME ".rodata.str1." #define GCC_6_SECTION_NAME ".str1." @@ -1356,8 +1355,7 @@ static void kpatch_include_standard_elements(struct kpatch_elf *kelf) list_for_each_entry(sec, &kelf->sections, list) { /* include these sections even if they haven't changed */ - if (is_standard_section(sec) || - should_include_str_section(sec->name)) { + if (is_standard_section(sec)) { sec->include = 1; if (sec->secsym) sec->secsym->include = 1; @@ -1368,6 +1366,20 @@ static void kpatch_include_standard_elements(struct kpatch_elf *kelf) list_entry(kelf->symbols.next, struct symbol, list)->include = 1; } +static void kpatch_include_standard_string_elements(struct kpatch_elf *kelf) +{ + struct section *sec; + + list_for_each_entry(sec, &kelf->sections, list) { + if (is_rodata_str_section(sec->name) && + is_referenced_section(sec, kelf)) { + sec->include = 1; + if (sec->secsym) + sec->secsym->include = 1; + } + } +} + #define inc_printf(fmt, ...) \ log_debug("%*s" fmt, recurselevel, "", ##__VA_ARGS__); @@ -1547,6 +1559,17 @@ static void kpatch_verify_patchability(struct kpatch_elf *kelf) errs++; } + if (sec->include) { + if (!is_standard_section(sec) && !is_rela_section(sec) && + !is_debug_section(sec) && !is_special_section(sec)) { + if (!is_referenced_section(sec, kelf)) { + log_normal("section %s included, but not referenced\n", + sec->name); + errs++; + } + } + } + /* * ensure we aren't including .data.* or .bss.* * (.data.unlikely is ok b/c it only has __warned vars) @@ -2078,6 +2101,8 @@ int main(int argc, char *argv[]) kpatch_include_debug_sections(kelf_patched); log_debug("Include hook elements\n"); kpatch_include_hook_elements(kelf_patched); + log_debug("Include standard string elements\n"); + kpatch_include_standard_string_elements(kelf_patched); log_debug("Include new globals\n"); new_globals_exist = kpatch_include_new_globals(kelf_patched); log_debug("new_globals_exist = %d\n", new_globals_exist); From patchwork Wed Aug 21 08:20:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106075 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 9B8AF1395 for ; Wed, 21 Aug 2019 08:23:14 +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 77EB922DA7 for ; Wed, 21 Aug 2019 08:23:14 +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="RiWIzlAr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 77EB922DA7 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 1i0Lsd-0002K0-7S; Wed, 21 Aug 2019 08:22:07 +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 1i0Lsb-0002Gg-98 for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:22:05 +0000 X-Inumbo-ID: b5db70b2-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 b5db70b2-c3ec-11e9-adc2-12813bfff9fa; Wed, 21 Aug 2019 08:21:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375704; x=1597911704; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=crehptxpzZcn/w9rVVjYZL9Nt7ha3q+3YwrmhUOuDNo=; b=RiWIzlAriqWHvkWMKXoBDBz4B8fEtVDbzc2jTDSdsjzLXmlPxjw+hzb7 jIag+ny+MVmMFeYpeGB1zwpTCcAGUTK1SqH6nbhSWDo213eO2764TRsg8 SKveV7Tic8iBQpJV1A8bKvCwyEPGnNhV2mCRjUHeLUoode8TxXyV4/AsI k=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="822132882" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-2b-baacba05.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:40 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-baacba05.us-west-2.amazon.com (Postfix) with ESMTPS id E2F6CA2460; Wed, 21 Aug 2019 08:21:39 +0000 (UTC) Received: from EX13D05EUB003.ant.amazon.com (10.43.166.253) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:25 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D05EUB003.ant.amazon.com (10.43.166.253) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:24 +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:22 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:47 +0000 Message-ID: <20190821082056.91090-12-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 11/20] create-diff-object: Do not create empty .livepatch.funcs section 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" When there is no changed function in the generated payload, do not create an empty .livepatch.funcs section. Hypervisor code considers such payloads as broken and rejects to load them. Such payloads without any changed functions may appear when only hooks are specified. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Martin Mazein Reviewed-by: Martin Pohlack Reviewed-by: Ross Lagerwall --- create-diff-object.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/create-diff-object.c b/create-diff-object.c index a90cf37..4e0f3be 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1843,6 +1843,11 @@ static void livepatch_create_patches_sections(struct kpatch_elf *kelf, if (sym->type == STT_FUNC && sym->status == CHANGED) nr++; + if (nr == 0) { + log_debug("No changed functions found. Skipping .livepatch.funcs section creation\n"); + return; + } + /* create text/rela section pair */ sec = create_section_pair(kelf, ".livepatch.funcs", sizeof(*funcs), nr); relasec = sec->rela; From patchwork Wed Aug 21 08:20:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106083 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 1804A1399 for ; Wed, 21 Aug 2019 08:23:26 +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 E967122DA7 for ; Wed, 21 Aug 2019 08:23:25 +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="hj++1gUr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E967122DA7 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 1i0LsH-0001aA-AT; Wed, 21 Aug 2019 08:21:45 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0LsF-0001VS-CU for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:21:43 +0000 X-Inumbo-ID: b4fd1f7e-c3ec-11e9-b95f-bc764e2007e4 Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b4fd1f7e-c3ec-11e9-b95f-bc764e2007e4; Wed, 21 Aug 2019 08:21:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375702; x=1597911702; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=7aVYeW5cNqin5qJvvkplbDWIdkv5EFumHOM5UQLhOfs=; b=hj++1gUrYXJol95EV07D/bztaRUABP7njql56bdhUfm9t/oKWXVHTTtI 6abDlVAreAfDq1PhuOU8DwwTk0W5ZrYEwdSnrD6JM+0gAFHvRYPMvllMN UZr0yaSxiv/EQt5IVDcfHtFu3fT7LZvI07nvVXF9XflKwtRYmApTHgBqB U=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="695968567" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2b-baacba05.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 21 Aug 2019 08:21:42 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-baacba05.us-west-2.amazon.com (Postfix) with ESMTPS id D44F5A243C; Wed, 21 Aug 2019 08:21:41 +0000 (UTC) Received: from EX13D03EUA002.ant.amazon.com (10.43.165.166) 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:27 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D03EUA002.ant.amazon.com (10.43.165.166) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:26 +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:24 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:48 +0000 Message-ID: <20190821082056.91090-13-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 12/20] create-diff-object: Extend patchability verification: STN_UNDEF 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" During verification check if all sections do not contain any entries with undefined symbols (STN_UNDEF). This situation can happen when a section is copied over from its original object to a patched object, but various symbols related to the section are not copied along. This scenario happens typically during stacked hotpatches creation (between 2 different hotpatch modules). Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Martin Pohlack Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey Reviewed-by: Andra-Irina Paraschiv Reviewed-by: Ross Lagerwall --- create-diff-object.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/create-diff-object.c b/create-diff-object.c index 4e0f3be..1c84f81 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1536,6 +1536,61 @@ static void kpatch_print_changes(struct kpatch_elf *kelf) } } +static inline int get_section_entry_size(const struct section *sec, + struct kpatch_elf *kelf) +{ + int entry_size; + + /* + * Base sections typically do not define fixed size elements. + * Detect section's element size in case it's a special section. + * Otherwise, skip it due to an unknown sh_entsize. + */ + entry_size = sec->sh.sh_entsize; + if (entry_size == 0) { + struct special_section *special; + + /* Find special section group_size. */ + for (special = special_sections; special->name; special++) { + if (!strcmp(sec->name, special->name)) + return special->group_size(kelf, 0); + } + } + + return entry_size; +} + +static int kpatch_section_has_undef_symbols(struct kpatch_elf *kelf, + const struct section *sec) +{ + int offset, entry_size; + struct rela *rela; + size_t d_size; + + entry_size = get_section_entry_size(sec, kelf); + if (entry_size == 0) + return false; + + d_size = sec->base->data->d_size; + for (offset = 0; offset < d_size; offset += entry_size) { + list_for_each_entry(rela, &sec->relas, list) { + if (rela->offset < offset || + rela->offset >= offset + entry_size) { + continue; + } + + if ((GELF_R_SYM(rela->rela.r_info) == STN_UNDEF) || + (!rela->sym->include && rela->sym->status == SAME)) { + log_normal("section %s has an entry with an undefined symbol: %s\n", + sec->name, rela->sym->name ?: "none"); + return true; + } + } + } + + return false; +} + static void kpatch_verify_patchability(struct kpatch_elf *kelf) { struct section *sec; @@ -1568,6 +1623,17 @@ static void kpatch_verify_patchability(struct kpatch_elf *kelf) errs++; } } + + /* Check if a RELA section does not contain any entries with + * undefined symbols (STN_UNDEF). This situation can happen + * when a section is copied over from its original object to + * a patched object, but various symbols related to the section + * are not copied along. + */ + if (is_rela_section(sec)) { + if (kpatch_section_has_undef_symbols(kelf, sec)) + errs++; + } } /* From patchwork Wed Aug 21 08:20:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106061 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 44BC61395 for ; Wed, 21 Aug 2019 08:23:02 +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 2142522DA7 for ; Wed, 21 Aug 2019 08:23:02 +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="Ckht7av1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2142522DA7 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 1i0LsK-0001gG-0D; Wed, 21 Aug 2019 08:21:48 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0LsI-0001bs-13 for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:21:46 +0000 X-Inumbo-ID: b5a9e4b6-c3ec-11e9-951b-bc764e2007e4 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b5a9e4b6-c3ec-11e9-951b-bc764e2007e4; Wed, 21 Aug 2019 08:21:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375704; x=1597911704; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=ene8YEpKFAVTL7TWWZzKcaMBSvzYKt7uNzuNS6Kz18k=; b=Ckht7av161pG7AunelFjAtWLkpM+wRh+/muBgv1DGSESnCfovPtIFIwt zbKa9cJ6n/kjA9bRcAlWJW07NSIwIk6NdH3fPjE9jCYLej0RXw1lQOrW3 pzAMB1NbJkjwOlxhonvgQHtKPCPvnDyDwLRGTY46U+2e0ZYz4FNDmZ5qy Y=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="822132900" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-2b-baacba05.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:43 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-baacba05.us-west-2.amazon.com (Postfix) with ESMTPS id B9759A2447; Wed, 21 Aug 2019 08:21:42 +0000 (UTC) Received: from EX13D05EUC002.ant.amazon.com (10.43.164.231) 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:29 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D05EUC002.ant.amazon.com (10.43.164.231) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:28 +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:26 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:49 +0000 Message-ID: <20190821082056.91090-14-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 13/20] create-diff-object: Strip all undefined entires of known size 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" The patched ELF object file contains all sections and symbols as resulted from the compilation. However, certain symbols may not be copied over to the resulting object file, due to being unchanged or not included for other reasons. In such situation the resulting object file has the entire sections copied along (with all their entries unchanged), while some of the corresponding symbols are not copied along at all. This leads to having incorrect undefined (STN_UNDEF) entries in the final hotpatch ELF file. The newly added function livepatch_strip_undefined_elements() detects and removes all undefined RELA entries as well as their corresponding PROGBITS section entries. Since the sections may contain elements of unknown size (sh.sh_entsize == 0), perform the strip only on sections with well defined entry sizes. After replacing the stripped rela list, it is assumed that the next invocation of the kpatch_rebuild_rela_section_data() will adjust all section header parameters according to the current state. The livepatch_strip_undefined_elements() is a superset of the kpatch_regenerate_special_section() in both scope (covers all RELA sections instead of just special sections) and granularity (checks all entries instead of whole groups) modulo the entries validity predicate. Unifying the functions results in a complicated code, which is hard to reason about. Thus, the kpatch_regenerate_special_section() is kept separate with its own predicate for special sections only, and livepatch_strip_undefined_elements() follows for all sections with the undefined symbol detecting predicate. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Martin Pohlack Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey Reviewed-by: Andra-Irina Paraschiv Reviewed-by: Ross Lagerwall --- create-diff-object.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 2 deletions(-) diff --git a/create-diff-object.c b/create-diff-object.c index 1c84f81..f01f1da 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1560,6 +1560,13 @@ static inline int get_section_entry_size(const struct section *sec, return entry_size; } +/* Check if RELA entry has undefined or unchanged/not-included symbols. */ +static inline bool has_rela_undefined_symbol(const struct rela *rela) +{ + return (GELF_R_SYM(rela->rela.r_info) == STN_UNDEF) || + (!rela->sym->include && (rela->sym->status == SAME)); +} + static int kpatch_section_has_undef_symbols(struct kpatch_elf *kelf, const struct section *sec) { @@ -1579,8 +1586,7 @@ static int kpatch_section_has_undef_symbols(struct kpatch_elf *kelf, continue; } - if ((GELF_R_SYM(rela->rela.r_info) == STN_UNDEF) || - (!rela->sym->include && rela->sym->status == SAME)) { + if (has_rela_undefined_symbol(rela)) { log_normal("section %s has an entry with an undefined symbol: %s\n", sec->name, rela->sym->name ?: "none"); return true; @@ -1994,6 +2000,125 @@ static void livepatch_create_patches_sections(struct kpatch_elf *kelf, } +/* + * The patched ELF object file contains all sections and symbols as resulted + * from the compilation. However, certain symbols may not be copied over to + * the resulting object file, due to being unchanged or not included for other + * reasons. + * In such situation the resulting object file has the entire sections copied + * along (with all their entries unchanged), while some of the corresponding + * symbols are not copied along at all. + * This leads to having incorrect dummy (STN_UNDEF) entries in the final + * hotpatch ELF file. + * This functions removes all undefined entries of known size from both + * RELA and PROGBITS sections of the patched elf object. + */ +static void livepatch_strip_undefined_elements(struct kpatch_elf *kelf) +{ + struct section *sec; + + list_for_each_entry(sec, &kelf->sections, list) { + struct rela *rela, *safe; + int src_offset = 0, dst_offset = 0; + int entry_size, align, aligned_size; + char *src, *dst; + LIST_HEAD(newrelas); + + /* use RELA section to find all its undefined entries */ + if (!is_rela_section(sec)) + continue; + + /* only known, fixed-size entries can be stripped */ + entry_size = get_section_entry_size(sec->base, kelf); + if (entry_size == 0) + continue; + + /* alloc buffer for new base section */ + dst = malloc(sec->base->sh.sh_size); + if (!dst) + ERROR("malloc"); + + /* + * Iterate through all entries of a corresponding base section + * for this RELA section. + */ + for ( src = sec->base->data->d_buf; + src_offset < sec->base->sh.sh_size; + src_offset += entry_size ) { + bool found_valid = false; + + list_for_each_entry_safe(rela, safe, &sec->relas, list) { + /* + * Check all RELA elements looking for + * corresponding entry references. + */ + if (rela->offset < src_offset || + rela->offset >= src_offset + entry_size) { + continue; + } + + /* + * Ignore all undefined (STN_UNDEF) or + * unchanged/not-included elements. + */ + if (has_rela_undefined_symbol(rela)) { + log_normal("Found a STN_UNDEF symbol %s in section %s\n", + rela->sym->name, sec->name); + continue; + } + + /* + * A correct match has been found, so move it + * to a new list. Original list will be destroyed + * along with the entire kelf object, so the + * reference must be preserved. + */ + found_valid = true; + list_del(&rela->list); + list_add_tail(&rela->list, &newrelas); + + rela->offset -= src_offset - dst_offset; + rela->rela.r_offset = rela->offset; + } + + /* there is a valid RELA entry, so copy current entry */ + if (found_valid) { + /* copy base section group */ + memcpy(dst + dst_offset, src + src_offset, entry_size); + dst_offset += entry_size; + } + } + + /* verify that entry_size is a divisor of aligned section size */ + align = sec->base->sh.sh_addralign; + aligned_size = ((sec->base->sh.sh_size + align - 1) / align) * align; + if (src_offset != aligned_size) { + ERROR("group size mismatch for section %s\n", + sec->base->name); + } + + if (!dst_offset) { + /* no changed or global functions referenced */ + sec->status = sec->base->status = SAME; + sec->include = sec->base->include = 0; + free(dst); + continue; + } + + /* overwrite with new relas list */ + list_replace(&newrelas, &sec->relas); + + /* + * Update text section data buf and size. + * + * The rela section's data buf and size will be + * regenerated in kpatch_rebuild_rela_section_data(). + */ + sec->base->data->d_buf = dst; + sec->base->data->d_size = dst_offset; + } +} + static int is_null_sym(struct symbol *sym) { return !strlen(sym->name); @@ -2190,6 +2315,8 @@ int main(int argc, char *argv[]) log_debug("Process special sections\n"); kpatch_process_special_sections(kelf_patched); + log_debug("Strip undefined elements of known size\n"); + livepatch_strip_undefined_elements(kelf_patched); log_debug("Verify patchability\n"); kpatch_verify_patchability(kelf_patched); From patchwork Wed Aug 21 08:20:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106059 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 601D81395 for ; Wed, 21 Aug 2019 08:23:01 +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 3C3B322DA7 for ; Wed, 21 Aug 2019 08:23:01 +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="MHmgKAHt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C3B322DA7 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 1i0Lsh-0002SX-SN; Wed, 21 Aug 2019 08:22:11 +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 1i0Lsg-0002Pn-9R for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:22:10 +0000 X-Inumbo-ID: b645c124-c3ec-11e9-adc2-12813bfff9fa Received: from smtp-fw-4101.amazon.com (unknown [72.21.198.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b645c124-c3ec-11e9-adc2-12813bfff9fa; Wed, 21 Aug 2019 08:21:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375704; x=1597911704; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=6v85FnJUP3YBpXSq0qwmcwthWxjgkPDkGI13doZjKzQ=; b=MHmgKAHtS1k+axEBfzatYhJes5xhj1AeMnkCfpqDiwbNam3nAF+e3fp9 ohXL+MFVg5d5/cl6bA8xdtTUT0FJn7YkoNKYmVgqyu6E72QwgTMBXd5bg BxSKe0GcuyGiMFdBi7IJXJPIElzkXHIhrzHCD/XicYxbme2xNgI5Mhkt8 0=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="780419122" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-d0be17ee.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 21 Aug 2019 08:21:44 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-d0be17ee.us-west-2.amazon.com (Postfix) with ESMTPS id 9FE83A1E80; Wed, 21 Aug 2019 08:21:43 +0000 (UTC) Received: from EX13D05EUC003.ant.amazon.com (10.43.164.207) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:30 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D05EUC003.ant.amazon.com (10.43.164.207) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21: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.60.129) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 21 Aug 2019 08:21:28 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:50 +0000 Message-ID: <20190821082056.91090-15-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 14/20] livepatch-build: Embed hypervisor build id into every hotpatch 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" This change is part of a independant stacked hotpatch modules feature. This feature allows to bypass dependencies between modules upon loading, but still verifies Xen build ID matching. With stacked hotpatch modules it is essential that each and every hotpatch is verified against the hypervisor build id upon upload. It must not be possible to successfully upload hotpatches built for incorrect version of the hypervisor. To achieve that always embed an additional ELF section: '.livpatch.xen_depends' containing the hypervisor build id. The hypervisor build id must be always provided as a command line parameter: --xen-depends. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Andra-Irina Paraschiv Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey --- livepatch-build | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/livepatch-build b/livepatch-build index 7068faf..3f0530e 100755 --- a/livepatch-build +++ b/livepatch-build @@ -30,6 +30,7 @@ DEBUG=n XEN_DEBUG=n SKIP= DEPENDS= +XEN_DEPENDS= PRELINK= XENSYMS=xen-syms @@ -163,6 +164,9 @@ function create_patch() # Create a dependency section perl -e "print pack 'VVVZ*H*', 4, 20, 3, 'GNU', '${DEPENDS}'" > depends.bin + # Create a Xen dependency section + perl -e "print pack 'VVVZ*H*', 4, 20, 3, 'GNU', '${XEN_DEPENDS}'" > xen_depends.bin + echo "Creating patch module..." if [ -z "$PRELINK" ]; then ld -r -o "${PATCHNAME}.livepatch" --build-id=sha1 $(find output -type f -name "*.o") || die @@ -174,6 +178,9 @@ function create_patch() objcopy --add-section .livepatch.depends=depends.bin "${PATCHNAME}.livepatch" objcopy --set-section-flags .livepatch.depends=alloc,readonly "${PATCHNAME}.livepatch" + + objcopy --add-section .livepatch.xen_depends=xen_depends.bin "${PATCHNAME}.livepatch" + objcopy --set-section-flags .livepatch.xen_depends=alloc,readonly "${PATCHNAME}.livepatch" } usage() { @@ -189,12 +196,13 @@ usage() { echo " --xen-debug Build debug Xen (if your .config does not have the options)" >&2 echo " --xen-syms Build against a xen-syms" >&2 echo " --depends Required build-id" >&2 + echo " --xen-depends Required Xen build-id" >&2 echo " --prelink Prelink" >&2 } find_tools || die "can't find supporting tools" -options=$(getopt -o hs:p:c:o:j:k:d -l "help,srcdir:,patch:,config:,output:,cpus:,skip:,debug,xen-debug,xen-syms:,depends:,prelink" -- "$@") || die "getopt failed" +options=$(getopt -o hs:p:c:o:j:k:d -l "help,srcdir:,patch:,config:,output:,cpus:,skip:,debug,xen-debug,xen-syms:,depends:,xen-depends:,prelink" -- "$@") || die "getopt failed" eval set -- "$options" @@ -253,6 +261,11 @@ while [[ $# -gt 0 ]]; do DEPENDS="$1" shift ;; + --xen-depends) + shift + XEN_DEPENDS="$1" + shift + ;; --prelink) PRELINK=--resolve shift @@ -269,6 +282,7 @@ done [ -z "$configarg" ] && die ".config not given" [ -z "$outputarg" ] && die "Output directory not given" [ -z "$DEPENDS" ] && die "Build-id dependency not given" +[ -z "$XEN_DEPENDS" ] && die "Xen Build-id dependency not given" SRCDIR="$(readlink -m -- "$srcarg")" # We need an absolute path because we move around, but we need to From patchwork Wed Aug 21 08:20:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106079 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 2FEFE1395 for ; Wed, 21 Aug 2019 08:23:23 +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 0C87A22DA7 for ; Wed, 21 Aug 2019 08:23:23 +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="i6kmsqfL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C87A22DA7 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 1i0Lsn-0002cd-Dx; Wed, 21 Aug 2019 08:22:17 +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 1i0Lsl-0002Ye-9y for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:22:15 +0000 X-Inumbo-ID: bb783c30-c3ec-11e9-adc2-12813bfff9fa Received: from smtp-fw-6002.amazon.com (unknown [52.95.49.90]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id bb783c30-c3ec-11e9-adc2-12813bfff9fa; Wed, 21 Aug 2019 08:21:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375713; x=1597911713; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=S7Jwy4t3EpCpk7fyUsDPxnKbkiyWUgaXiHUWKRb2soo=; b=i6kmsqfL27x7Rq1bugTAJihJihyIZapjpEqreaYpHobI74DLuNCJj5AJ WOXcoazhvGiaylE3ovyXY4S0GACVH3es6be6K52zVt/5xYu95ZEj6ffY4 lGnEQ5mUe3RSdoAORtvu+oQjx14i0a28I8VUFv5dLgOLjvUVyrI7Rknx6 w=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="416596276" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-168cbb73.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 21 Aug 2019 08:21:52 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2c-168cbb73.us-west-2.amazon.com (Postfix) with ESMTPS id 73012A2144; Wed, 21 Aug 2019 08:21:52 +0000 (UTC) Received: from EX13D05EUB003.ant.amazon.com (10.43.166.253) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:32 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D05EUB003.ant.amazon.com (10.43.166.253) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:31 +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:30 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:51 +0000 Message-ID: <20190821082056.91090-16-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 15/20] create-diff-object: Handle extra pre-|post- hooks 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" Include new sections containing optional pre-, post- action hooks. The following new section names are supported: - .livepatch.hooks.preapply - .livepatch.hooks.postapply - .livepatch.hooks.prerevert - .livepatch.hooks.postrevert Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Ross Lagerwall --- create-diff-object.c | 67 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/create-diff-object.c b/create-diff-object.c index f01f1da..44f4e6b 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1102,6 +1102,22 @@ static struct special_section special_sections[] = { .name = ".livepatch.hooks.unload", .group_size = livepatch_hooks_group_size, }, + { + .name = ".livepatch.hooks.preapply", + .group_size = livepatch_hooks_group_size, + }, + { + .name = ".livepatch.hooks.postapply", + .group_size = livepatch_hooks_group_size, + }, + { + .name = ".livepatch.hooks.prerevert", + .group_size = livepatch_hooks_group_size, + }, + { + .name = ".livepatch.hooks.postrevert", + .group_size = livepatch_hooks_group_size, + }, {}, }; @@ -1465,23 +1481,44 @@ static void kpatch_include_debug_sections(struct kpatch_elf *kelf) } } -static void kpatch_include_hook_elements(struct kpatch_elf *kelf) +#define IS_HOOK_SECTION(section, hook) ({ \ + !strcmp(((section))->name, ".livepatch.hooks." hook) || \ + !strcmp(((section))->name, ".rela.livepatch.hooks." hook); \ +}) + +#define IS_ACTION_HOOK_SECTION(section, action) ({ \ + IS_HOOK_SECTION(section, "pre" action) || \ + IS_HOOK_SECTION(section, "post" action); \ +}) + +#define IS_HOOK_SYM_NAME(symbol, hook) ({ \ + !strcmp(((symbol))->name, "livepatch_" hook "_data"); \ +}) + +#define IS_ACTION_HOOK_SYM_NAME(symbol, action) ({ \ + IS_HOOK_SYM_NAME(symbol, "pre" action) || \ + IS_HOOK_SYM_NAME(symbol, "post" action); \ +}) + +static int kpatch_include_hook_elements(struct kpatch_elf *kelf) { struct section *sec; struct symbol *sym; struct rela *rela; + int num_new_functions = 0; - /* include load/unload sections */ + /* include all supported hooks sections */ list_for_each_entry(sec, &kelf->sections, list) { - if (!strcmp(sec->name, ".livepatch.hooks.load") || - !strcmp(sec->name, ".livepatch.hooks.unload") || - !strcmp(sec->name, ".rela.livepatch.hooks.load") || - !strcmp(sec->name, ".rela.livepatch.hooks.unload")) { + if (IS_HOOK_SECTION(sec, "load") || + IS_HOOK_SECTION(sec, "unload") || + IS_ACTION_HOOK_SECTION(sec, "apply") || + IS_ACTION_HOOK_SECTION(sec, "revert")) { sec->include = 1; + num_new_functions++; if (is_rela_section(sec)) { /* include hook dependencies */ rela = list_entry(sec->relas.next, - struct rela, list); + struct rela, list); sym = rela->sym; log_normal("found hook: %s\n",sym->name); kpatch_include_symbol(sym, 0); @@ -1497,13 +1534,17 @@ static void kpatch_include_hook_elements(struct kpatch_elf *kelf) } /* - * Strip temporary global load/unload function pointer objects - * used by the kpatch_[load|unload]() macros. + * Strip temporary global function pointer objects for all + * supported hooks, used by the kpatch_[load|unload]() macros. */ list_for_each_entry(sym, &kelf->symbols, list) - if (!strcmp(sym->name, "livepatch_load_data") || - !strcmp(sym->name, "livepatch_unload_data")) + if (IS_HOOK_SYM_NAME(sym, "load") || + IS_HOOK_SYM_NAME(sym, "unload") || + IS_ACTION_HOOK_SYM_NAME(sym, "apply") || + IS_ACTION_HOOK_SYM_NAME(sym, "revert")) sym->include = 0; + + return num_new_functions; } static int kpatch_include_new_globals(struct kpatch_elf *kelf) @@ -2292,11 +2333,11 @@ int main(int argc, char *argv[]) kpatch_include_standard_elements(kelf_patched); log_debug("Include changed functions\n"); num_changed = kpatch_include_changed_functions(kelf_patched); - log_debug("num_changed = %d\n", num_changed); log_debug("Include debug sections\n"); kpatch_include_debug_sections(kelf_patched); log_debug("Include hook elements\n"); - kpatch_include_hook_elements(kelf_patched); + num_changed += kpatch_include_hook_elements(kelf_patched); + log_debug("num_changed = %d\n", num_changed); log_debug("Include standard string elements\n"); kpatch_include_standard_string_elements(kelf_patched); log_debug("Include new globals\n"); From patchwork Wed Aug 21 08:20:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106069 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 171231399 for ; Wed, 21 Aug 2019 08:23:06 +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 E750B22DA7 for ; Wed, 21 Aug 2019 08:23:05 +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="kDwh6tHH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E750B22DA7 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 1i0Lsr-0002j3-0c; Wed, 21 Aug 2019 08:22:21 +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 1i0Lsq-0002ho-9r for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:22:20 +0000 X-Inumbo-ID: bd554386-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 bd554386-c3ec-11e9-adc2-12813bfff9fa; Wed, 21 Aug 2019 08:21:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375717; x=1597911717; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=h/EcPi67Ay019LWMfejEBMe1LxzOgE+GmoRJDs9Vapk=; b=kDwh6tHHst0pzimHmB9zfCrvNbZFuskKuZRSe3XMDVnx6lRk/Cjwy8ZN 76JsgWEPa/YAn1LV8M+C62oMv8NzvGsxO9tNq8uiS2ZEtjtKpsQdCfDVg mwVdQaRR3zFiJ09nXqaSI2+P2g4SRVMCOjMGMVfOINMr+AaSRNh/i1TMy s=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="822132954" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-2a-6e2fc477.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:56 +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-6e2fc477.us-west-2.amazon.com (Postfix) with ESMTPS id 223D4A2691; Wed, 21 Aug 2019 08:21:56 +0000 (UTC) Received: from EX13D05EUB002.ant.amazon.com (10.43.166.45) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:34 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D05EUB002.ant.amazon.com (10.43.166.45) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:33 +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:32 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:52 +0000 Message-ID: <20190821082056.91090-17-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 16/20] create-diff-object: Handle optional apply|revert hooks 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" Include new sections containing optional apply and revert action hooks. The following new section names are supported: - .livepatch.hooks.apply - .livepatch.hooks.revert Signed-off-by: Pawel Wieczorkiewicz --- create-diff-object.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/create-diff-object.c b/create-diff-object.c index 44f4e6b..9918b6e 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1118,6 +1118,14 @@ static struct special_section special_sections[] = { .name = ".livepatch.hooks.postrevert", .group_size = livepatch_hooks_group_size, }, + { + .name = ".livepatch.hooks.apply", + .group_size = livepatch_hooks_group_size, + }, + { + .name = ".livepatch.hooks.revert", + .group_size = livepatch_hooks_group_size, + }, {}, }; @@ -1488,6 +1496,7 @@ static void kpatch_include_debug_sections(struct kpatch_elf *kelf) #define IS_ACTION_HOOK_SECTION(section, action) ({ \ IS_HOOK_SECTION(section, "pre" action) || \ + IS_HOOK_SECTION(section, action) || \ IS_HOOK_SECTION(section, "post" action); \ }) @@ -1497,6 +1506,7 @@ static void kpatch_include_debug_sections(struct kpatch_elf *kelf) #define IS_ACTION_HOOK_SYM_NAME(symbol, action) ({ \ IS_HOOK_SYM_NAME(symbol, "pre" action) || \ + IS_HOOK_SYM_NAME(symbol, action) || \ IS_HOOK_SYM_NAME(symbol, "post" action); \ }) From patchwork Wed Aug 21 08:20:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106071 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 D99FB1399 for ; Wed, 21 Aug 2019 08:23:08 +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 B63DE2339E for ; Wed, 21 Aug 2019 08:23:08 +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="cQtXwOXw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B63DE2339E 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-00029z-TZ; Wed, 21 Aug 2019 08:22:01 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0LsW-000278-DL for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:22:00 +0000 X-Inumbo-ID: beebc88c-c3ec-11e9-b95f-bc764e2007e4 Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id beebc88c-c3ec-11e9-b95f-bc764e2007e4; Wed, 21 Aug 2019 08:22:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375720; x=1597911720; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=SHPtK+MdOTX0fs8ZBKKhnURnVZ/MNKl1UfFqHp7tdS8=; b=cQtXwOXwQPsSML/H4fYLSZ3acatzww3lQ95pCw0R5S5+Db0CJb/CD2sI iPZeQz4hEm5LXEqT62038blpLXR/ed8gntAKcxFj6pSsjJfqHkzNGJQAz VqSniENuYZdgKqmGx2oueXUDisMKFe83GMqR2Milj5P9ZMXkprv7XEvQU k=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="695968628" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2a-e7be2041.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 21 Aug 2019 08:21:58 +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-e7be2041.us-west-2.amazon.com (Postfix) with ESMTPS id 3B4ACA1CFB; Wed, 21 Aug 2019 08:21:58 +0000 (UTC) Received: from EX13D03EUA002.ant.amazon.com (10.43.165.166) 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:36 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D03EUA002.ant.amazon.com (10.43.165.166) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:35 +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:34 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:53 +0000 Message-ID: <20190821082056.91090-18-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 17/20] create-diff-object: Add support for applied/reverted marker 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" With version 2 of a payload structure additional field is supported to track whether given function has been applied or reverted. There also comes additional 8-byte alignment padding to reserve place for future flags and options. The new fields are zero-out upon .livepatch.funcs section creation. Signed-off-by: Pawel Wieczorkiewicz --- common.h | 2 ++ create-diff-object.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/common.h b/common.h index 06e19e7..d8cde35 100644 --- a/common.h +++ b/common.h @@ -124,6 +124,8 @@ struct livepatch_patch_func { uint32_t old_size; uint8_t version; unsigned char pad[31]; + uint8_t applied; + uint8_t _pad[7]; }; struct special_section { diff --git a/create-diff-object.c b/create-diff-object.c index 9918b6e..d518503 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -2014,8 +2014,10 @@ static void livepatch_create_patches_sections(struct kpatch_elf *kelf, funcs[index].old_size = result.size; funcs[index].new_addr = 0; funcs[index].new_size = sym->sym.st_size; - funcs[index].version = 1; + funcs[index].version = 2; memset(funcs[index].pad, 0, sizeof funcs[index].pad); + funcs[index].applied = 0; + memset(funcs[index]._pad, 0, sizeof funcs[index]._pad); /* * Add a relocation that will populate From patchwork Wed Aug 21 08:20:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106057 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 3CC2D174A for ; Wed, 21 Aug 2019 08:22:56 +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 14A4C2339F for ; Wed, 21 Aug 2019 08:22:56 +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="k0XbpTvf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 14A4C2339F 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 1i0LsY-0002Bf-MX; Wed, 21 Aug 2019 08:22:02 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0LsX-00028G-1X for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:22:01 +0000 X-Inumbo-ID: bf96a946-c3ec-11e9-b95f-bc764e2007e4 Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id bf96a946-c3ec-11e9-b95f-bc764e2007e4; Wed, 21 Aug 2019 08:22:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375720; x=1597911720; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=QH2J0Nub2k8+laF1fjjLF3dOm5Yo7wtajyaXvAl27Zc=; b=k0XbpTvfDhKkDgjvOYbmZQs3hBAkXPuB9EuEeHcTxREofauSMAEhpACk McOODsLSmc6vV/T1lDGK0Ike3gs1dZN8HA8HR5b0kJb9oP4yephCPJHkZ t8CoqtojvaILn52jDOM7oPKImls2V8KRD1ZEymQSAsvfVfSuvm9/0HwCk k=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="695968635" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2a-90c42d1d.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 21 Aug 2019 08:22:00 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-90c42d1d.us-west-2.amazon.com (Postfix) with ESMTPS id E617FA1F41; Wed, 21 Aug 2019 08:21:59 +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:38 +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:37 +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:35 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:54 +0000 Message-ID: <20190821082056.91090-19-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 18/20] create-diff-object: Add support for expectations 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" Extend livepatch_patch_func to support a new field: expect. This new field describes the expected data, its length and whether expectation is enabled. The expectation's data is of opaque padding size. Bump the payload version for hotpatches built with expectations. The expectations are supported starting from version 3 of the payload. By default the expectation field is zero-out and the expectation is disabled unless explicitly specified in the patch. Signed-off-by: Pawel Wieczorkiewicz --- common.h | 11 ++++++++++- create-diff-object.c | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/common.h b/common.h index d8cde35..7c6fb73 100644 --- a/common.h +++ b/common.h @@ -115,6 +115,14 @@ struct kpatch_elf { }; #define PATCH_INSN_SIZE 5 +#define MAX_REPLACEMENT_SIZE 31 +struct livepatch_expectation { + uint8_t enabled : 1; + uint8_t len : 5; + uint8_t pad : 2; + uint8_t data[MAX_REPLACEMENT_SIZE]; +}; +typedef struct livepatch_expectation livepatch_expectation_t; struct livepatch_patch_func { char *name; @@ -123,9 +131,10 @@ struct livepatch_patch_func { uint32_t new_size; uint32_t old_size; uint8_t version; - unsigned char pad[31]; + unsigned char pad[MAX_REPLACEMENT_SIZE]; uint8_t applied; uint8_t _pad[7]; + livepatch_expectation_t expect; }; struct special_section { diff --git a/create-diff-object.c b/create-diff-object.c index d518503..75dc9b4 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -2014,10 +2014,11 @@ static void livepatch_create_patches_sections(struct kpatch_elf *kelf, funcs[index].old_size = result.size; funcs[index].new_addr = 0; funcs[index].new_size = sym->sym.st_size; - funcs[index].version = 2; + funcs[index].version = 3; memset(funcs[index].pad, 0, sizeof funcs[index].pad); funcs[index].applied = 0; memset(funcs[index]._pad, 0, sizeof funcs[index]._pad); + memset(&funcs[index].expect, 0, sizeof funcs[index].expect); /* * Add a relocation that will populate From patchwork Wed Aug 21 08:20:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106085 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 754371395 for ; Wed, 21 Aug 2019 08:23:34 +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 4F97222DA7 for ; Wed, 21 Aug 2019 08:23:34 +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="qF5pPE0X" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4F97222DA7 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 1i0Lsw-0002s2-Gs; Wed, 21 Aug 2019 08:22:26 +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 1i0Lsv-0002py-A2 for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:22:25 +0000 X-Inumbo-ID: c0915f12-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 c0915f12-c3ec-11e9-adc2-12813bfff9fa; Wed, 21 Aug 2019 08:22:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375722; x=1597911722; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=HMLHaYGnYdsl4+f8w+M2LsBhl1+9LxdtIOk2BKjFp5w=; b=qF5pPE0XLtJnNAn8l+gY8GZFlW9g4DrytH68XxonENQAJoPvW+ibVopZ U9nmAlp9+wQ7iSGIxHXPxm/FonUl5KXmhjfIrtzHj0zLEzX7WoPC5ffWi SOpfV3YOVbwtWPRv3tlpl6pXvRsrqSqiHYVGm8kIIvFGEMPMGCgWV2uf9 o=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="822132978" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-2a-69849ee2.us-west-2.amazon.com) ([10.47.22.34]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 21 Aug 2019 08:22:02 +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-69849ee2.us-west-2.amazon.com (Postfix) with ESMTPS id 9E67BA263B; Wed, 21 Aug 2019 08:22:01 +0000 (UTC) Received: from EX13D05EUC002.ant.amazon.com (10.43.164.231) 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:40 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D05EUC002.ant.amazon.com (10.43.164.231) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:39 +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:37 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:55 +0000 Message-ID: <20190821082056.91090-20-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 19/20] livepatch-build: Strip transient or unneeded symbols 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" In the process of creating a final hotpatch module file make sure to strip all transient symbols that have not been caught and removed by create-diff-object processing. For now these are only the hooks kpatch load/unload symbols. For all new object files that are carried along for the final linking the transient hooks symbols are not stripped and neither are any unneeded symbols. Strip them explicitly from resulting object file. Signed-off-by: Pawel Wieczorkiewicz --- livepatch-build | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/livepatch-build b/livepatch-build index 3f0530e..cc71640 100755 --- a/livepatch-build +++ b/livepatch-build @@ -111,6 +111,28 @@ function build_special() unset LIVEPATCH_CAPTURE_DIR } +strip_extra_symbols () +{ + local -r FILE="$1" + local -a STRIP_CMD_OPTS=() + local -a SYM_PREFIX=("livepatch_load_data_" + "livepatch_unload_data_" + "livepatch_preapply_data_" + "livepatch_apply_data_" + "livepatch_postapply_data_" + "livepatch_prerevert_data_" + "livepatch_revert_data_" + "livepatch_postrevert_data_") + + STRIP_CMD_OPTS+=("-w") + for sym in "${SYM_PREFIX[@]}"; do + STRIP_CMD_OPTS+=("-N") + STRIP_CMD_OPTS+=("\"${sym}*\"") + done + + strip "${STRIP_CMD_OPTS[@]}" "$FILE" +} + function create_patch() { echo "Extracting new and modified ELF sections..." @@ -150,6 +172,7 @@ function create_patch() NEW_FILES=$(comm -23 <(cd patched/xen && find . -type f -name '*.o' | sort) <(cd original/xen && find . -type f -name '*.o' | sort)) for i in $NEW_FILES; do cp "patched/$i" "output/$i" + strip --strip-unneeded "output/$i" CHANGED=1 done @@ -176,6 +199,8 @@ function create_patch() "${TOOLSDIR}"/prelink $debugopt output.o "${PATCHNAME}.livepatch" "$XENSYMS" &>> "${OUTPUT}/prelink.log" || die fi + strip_extra_symbols "${PATCHNAME}.livepatch" + objcopy --add-section .livepatch.depends=depends.bin "${PATCHNAME}.livepatch" objcopy --set-section-flags .livepatch.depends=alloc,readonly "${PATCHNAME}.livepatch" From patchwork Wed Aug 21 08:20:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106077 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 63E641395 for ; Wed, 21 Aug 2019 08:23:22 +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 404C22339F for ; Wed, 21 Aug 2019 08:23:22 +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="eAr3ee7t" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 404C22339F 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 1i0Lt1-00030Q-12; Wed, 21 Aug 2019 08:22:31 +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 1i0Lt0-0002ym-Ao for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:22:30 +0000 X-Inumbo-ID: c1cafc4e-c3ec-11e9-adc2-12813bfff9fa Received: from smtp-fw-4101.amazon.com (unknown [72.21.198.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c1cafc4e-c3ec-11e9-adc2-12813bfff9fa; Wed, 21 Aug 2019 08:22:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375724; x=1597911724; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=H2Jobcf7/B4qcCN5zZ1DZ3Id7Yd870t7Njz94pqBXLQ=; b=eAr3ee7tQTcaoHUva/5OsGxcujEz+ZSoQyauRftzcabu/EcOtc4KoFsn pK2mHDMIv4h7o1F+gLjh7OWik/VBjf8DHIP09FMwe5EzN4WT7UnKci0DC /F4+1LF+R56LREMeDm7VsIh9oA/k4r+psW+OuV1tOpPIi/4TaFMszAXRC I=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="780419169" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-2225282c.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 21 Aug 2019 08:22:03 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2c-2225282c.us-west-2.amazon.com (Postfix) with ESMTPS id F3777A18C4; Wed, 21 Aug 2019 08:22:02 +0000 (UTC) Received: from EX13D05EUC001.ant.amazon.com (10.43.164.118) 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:42 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D05EUC001.ant.amazon.com (10.43.164.118) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:41 +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:39 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:56 +0000 Message-ID: <20190821082056.91090-21-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 20/20] livepatch-build: Strip all metadata symbols from hotpatch modules 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" Strip all unneeded metadata symbols from generated hotpatch modules. The metadata symbols are the symbols from metadata-like sections (e.g. '.livepatch.funcs') or livepatch hooks symbols (defined by a set of prefixes. E.g. 'livepatch_load_data_'). By default the create-diff-object does not create symbols in metadata sections. However, such symbols may be implicitly added by speciying extra entries in the sections manually (in a given patch). The symbols are not needed for the hotpatch modules and should be stripped to avoid symbol names collisions and to save hotpatch files space. Signed-off-by: Pawel Wieczorkiewicz --- livepatch-build | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/livepatch-build b/livepatch-build index cc71640..e7c7c11 100755 --- a/livepatch-build +++ b/livepatch-build @@ -111,10 +111,39 @@ function build_special() unset LIVEPATCH_CAPTURE_DIR } -strip_extra_symbols () +elf_section_exists () +{ + local ELF="$1" + local SEC="$2" + + objdump -h -j "$SEC" "$ELF" &> /dev/null +} + +# Extract a set of unique symbols for a specified section. +elf_extract_section_symbols () +{ + local -r ELF="$1" + local -r SEC="$2" + + if elf_section_exists "$ELF" "$SEC" + then + # Example objdump command output to be parsed: + # + # SYMBOL TABLE: + # 0000000000000000 l d .livepatch.funcs 0000000000000000 .livepatch.funcs + objdump -w -j "$SEC" -t "$ELF" | awk '/^SYMBOL TABLE:/ {seen = 1; next} seen && $NF {print $NF}' | sort -u + fi +} + +# Strip all metadata symbols belonging to a metadata section +# or whose name starts with a livepatch hook prefix. +# The function constructs the 'strip' utility command line +# and then invokes strip with that command line. +strip_metadata_symbols () { local -r FILE="$1" local -a STRIP_CMD_OPTS=() + local -a SYM_SECTIONS=(".livepatch.funcs") local -a SYM_PREFIX=("livepatch_load_data_" "livepatch_unload_data_" "livepatch_preapply_data_" @@ -123,13 +152,35 @@ strip_extra_symbols () "livepatch_prerevert_data_" "livepatch_revert_data_" "livepatch_postrevert_data_") + local -a SYMS=() + # Enable wildcard STRIP_CMD_OPTS+=("-w") + + # Strip all livepatch hooks metadata symbols for sym in "${SYM_PREFIX[@]}"; do STRIP_CMD_OPTS+=("-N") STRIP_CMD_OPTS+=("\"${sym}*\"") done + # Find all symbols from metadata sections + # Note: There may be name conflicts between global + # and local symbols belonging to the same section. + # For the '.livepatch.funcs' section it is not a + # problem. Think about it before adding more sections. + for sec in "${SYM_SECTIONS[@]}"; do + SYMS+=($(elf_extract_section_symbols "$FILE" "$sec")) + done + + # Strip metadata sections' symbols + if [ ${#SYMS[@]} -gt 0 ] + then + for sym in "${SYMS[@]}"; do + STRIP_CMD_OPTS+=("-N") + STRIP_CMD_OPTS+=("${sym}") + done + fi + strip "${STRIP_CMD_OPTS[@]}" "$FILE" } @@ -199,7 +250,7 @@ function create_patch() "${TOOLSDIR}"/prelink $debugopt output.o "${PATCHNAME}.livepatch" "$XENSYMS" &>> "${OUTPUT}/prelink.log" || die fi - strip_extra_symbols "${PATCHNAME}.livepatch" + strip_metadata_symbols "${PATCHNAME}.livepatch" objcopy --add-section .livepatch.depends=depends.bin "${PATCHNAME}.livepatch" objcopy --set-section-flags .livepatch.depends=alloc,readonly "${PATCHNAME}.livepatch"