From patchwork Tue Oct 10 06:36:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 115349 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3401224qgn; Mon, 9 Oct 2017 23:35:04 -0700 (PDT) X-Received: by 10.84.141.1 with SMTP id 1mr11336286plu.234.1507617304659; Mon, 09 Oct 2017 23:35:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507617304; cv=none; d=google.com; s=arc-20160816; b=ZS1tp+zmao70gvHkpkbv4a5OtKIFwBPR6OgIWH+IVdteF6cACRaNzGNGCGq0JYEhxd beW3ZOS7/WF5jwVWQoXgdBDpsrqnAum2puqkn5hLnr6b9c5wZEMavBMuyTR3W3xZPggG Ynegd/L7EO16Gq+XT7pD9pHh1Iy7WTkyCKCiVvT/c/IkcsSld9FiZE9DgLUUGeX0m0A5 zm5fBGEUqSVbo8xezVwA+54OJvq3U8Pe1xH0z0cQkNLPJ7YvqDKeC0DeV1Uf0eiMVPmN 20qZ+VUp4cQ4vQ/xfgDDi+r/Yo8/c2ZVfyS3n5j2K0WaQtDICLeIpnZCludbzSJ/q+T7 Y4Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=fVNkswW2F9Q2QI2ZTaY0vlW/IrEbCVf8dY1cNKokZF4=; b=X8YLWRoBg+SFpuQSv4d9R9+q/Txl6BwmcSZG8mPmEGlfBhgyjM5kfnL8RJNe1t4hnT X6ERl7Lxr73yZPeqZmymmKzIXI62qzpP0Op57/ScQBuDAlfgu0yzddlVTgkl22YC9k2d fcFO6RtxuSKjyOz1/84z9dkGeEUbXgeyCs+rY4yX5HmEg8mwZAE+nlB9eS1i5rO4vfGt u78+miCTjBQU8LcKcIkUbM/4CQwjxQ1uIHs5o7IexPUComcwEqHscvD7DBZ6z3bsLKE7 vNb6McBPwz+fB51yZ1sKZowuxFsuNHVV3IVdH856QIY7gpaAyI31PnFICgwc6h4/PtzY fW+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dVQmLtc6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p5si8117352plk.185.2017.10.09.23.35.04; Mon, 09 Oct 2017 23:35:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dVQmLtc6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754585AbdJJGfC (ORCPT + 26 others); Tue, 10 Oct 2017 02:35:02 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:56541 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752528AbdJJGfB (ORCPT ); Tue, 10 Oct 2017 02:35:01 -0400 Received: by mail-pf0-f180.google.com with SMTP id b85so5079371pfj.13 for ; Mon, 09 Oct 2017 23:35:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fVNkswW2F9Q2QI2ZTaY0vlW/IrEbCVf8dY1cNKokZF4=; b=dVQmLtc6p5ZLKulcdCt8ddI103uxzC4QmTbqR5Q/jiiMuVreOoW/xUC1QqF3Y9ZXgb 4+DwMk19HRK7TBRIYdT7RNIeBT4NSb8oCXVj6KfDdddxRW1sCFSjsphlUxGMLmsdhSF1 IChoKfy9OjPLVAmJs/TPKncOmeN5USTaqWxTc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fVNkswW2F9Q2QI2ZTaY0vlW/IrEbCVf8dY1cNKokZF4=; b=JiH5wpZUnXincc1n8oPPqaVLW5OhjSBa8q/bt0e6L6JxzvIr/pKUWZifQuFY9OtlDd Cb4l/Fy0cwcaf5+fLIoQ7hbwYPjqyz72CGwHe5n/KLLfc9hPcckkwao06+Gmg0uz7InW d8YjiH1fm4qwEy4ftGq/FsD8BkszXvG8fxhIz2k5tn2577yLvfCAleSU9VquAxgMzwGt puXm1ihcBFrHw1tJoaDLg87GRvxPwQ/Ll0ELND8RTzwRKnFd4Xy1ZcqmpDT6IVfVRRbU TD/9G36isNffsYFD38nX/PKckrLYCUUA7nlljsFthUkM5hSo73tf3+MxnLau8b+vPAzt VN2Q== X-Gm-Message-State: AMCzsaWe1bLoEV/IVMd3D2YTkL6EiZkWJ59Lm5tyUIflNdWscLjJDeHX nup8EjNpoB/c8O8Lm/tWfPDXrQ== X-Google-Smtp-Source: AOwi7QD1aQDoOz5AFZ0I+szYTmDCZdTBz401hvPShAEckbPBbMXMxHqLfcm1wSa/AWdBQcPMsW7eSA== X-Received: by 10.84.236.12 with SMTP id q12mr7241000plk.204.1507617300575; Mon, 09 Oct 2017 23:35:00 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id z127sm17908752pfb.8.2017.10.09.23.34.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Oct 2017 23:35:00 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, julien.thierry@arm.com Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v5 01/10] include: pe.h: remove message[] from mz header definition Date: Tue, 10 Oct 2017 15:36:10 +0900 Message-Id: <20171010063619.6303-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171010063619.6303-1-takahiro.akashi@linaro.org> References: <20171010063619.6303-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org message[] field won't be part of the definition of mz header. This change is crucial for enabling kexec_file_load on arm64 because arm64's "Image" binary, as in PE format, doesn't have any data for it and accordingly the following check in pefile_parse_binary() will fail: chkaddr(cursor, mz->peaddr, sizeof(*pe)); Signed-off-by: AKASHI Takahiro Reviewed-by: Ard Biesheuvel Cc: David Howells Cc: Vivek Goyal Cc: Herbert Xu Cc: David S. Miller --- include/linux/pe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.14.1 diff --git a/include/linux/pe.h b/include/linux/pe.h index 143ce75be5f0..3482b18a48b5 100644 --- a/include/linux/pe.h +++ b/include/linux/pe.h @@ -166,7 +166,7 @@ struct mz_hdr { uint16_t oem_info; /* oem specific */ uint16_t reserved1[10]; /* reserved */ uint32_t peaddr; /* address of pe header */ - char message[64]; /* message to print */ + char message[]; /* message to print */ }; struct mz_reloc { From patchwork Tue Oct 10 06:36:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 115350 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3401302qgn; Mon, 9 Oct 2017 23:35:10 -0700 (PDT) X-Received: by 10.99.146.76 with SMTP id s12mr9309861pgn.354.1507617310463; Mon, 09 Oct 2017 23:35:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507617310; cv=none; d=google.com; s=arc-20160816; b=ywx5FRMYGb/LQGRcEew0YmWf44h89wTRZ/kTHZ9EYn1Rf4eOoV38AOQnvjaLfkQDQL hQgh4ZYOghoZlMamVl26yBhvQ6MMtZ8GrTYv5B0TQS7xhaj6ALZmgDKkR/FZVay41QVa 2t+Px21PEl6YFUSltXM5lxoJHA51Q0SO8kgEGALchb1or4PEh9P6J65cXXh1kim5l6u+ Qlk0eEtz5i5EGty78xARK05jaROn/I7fNvSV+x7boDSPbkTKiuz2ky9fHboNiSXhKv8m XIlKTCJbNrRbg8k9PwykTs3mWQ0OdCKZc8AMs5CH4Qy2Y/Im6YNopJdgJE8wZPLEVOz4 Vo0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=qXdYk7Urfs9sg9VuSaIsAvtksSYSR/RmSQ5t2VIYZpY=; b=FtFvBPtq7rEuUjcT88W57sBetJBCER7EQytwydETT8Y2MvC8ksjlqoyDwzyqrnRSw1 /VMD+A/kx6BRfnuYcpQ5HW05qPuz+C+cF/qG0P2GhLrZYvBDJ10vrrV7gHWTItZf6FVx c2NGRTZJIYZ/5mOPEfYGje73ekmGkVdoR+BBki8FQ/1FIhN/j2JJNhqDibVVkSt/lOdO MDArVbe6sLvLDeVyKdVoHBbkLA2F7KBq9BSQbJ6F15WQOH4RX5y+tKz6kOz8iCXhcOau wP8hV8OSdwrQwVJN8k7dNMpUq4ynV49DZ0sITJRoSPW2XA8TwRI3uS7x8W7QwyQTDc/g PrKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JR29Ddbw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p5si8117352plk.185.2017.10.09.23.35.10; Mon, 09 Oct 2017 23:35:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JR29Ddbw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755064AbdJJGfJ (ORCPT + 26 others); Tue, 10 Oct 2017 02:35:09 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:52404 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752528AbdJJGfG (ORCPT ); Tue, 10 Oct 2017 02:35:06 -0400 Received: by mail-pf0-f181.google.com with SMTP id a1so13003649pfj.9 for ; Mon, 09 Oct 2017 23:35:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qXdYk7Urfs9sg9VuSaIsAvtksSYSR/RmSQ5t2VIYZpY=; b=JR29Ddbw08ns1+XWOolVrUCZBNzMnZZ0e5xtyUI3vMmFVu/g2s8J/VeE6r0xxRMTXq WPevm7w7Gq5wceCAf4KYxocpjh0i/RhFyD1kLIyTqEOQSBlBgOVOKx+0RxgI5tY05Qj1 hRtQV7esI3HJmll0gmq4WUsuBd3skCR5P4NNA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qXdYk7Urfs9sg9VuSaIsAvtksSYSR/RmSQ5t2VIYZpY=; b=tV0JTMN7AutNZaGzgcFAkJPBKss23Jks/JYF8ERMVdt3nKHO76X1mFexbsG44DP+6l GedMC8MtuFDn/fB2rVxYncgjvd/wibOGhlxsX9aZMEhwvVjwQ/h9Zsictr84QLSRF6dR vZ6Btr2FwTuiD8P3OlXXQPgTcoK+JihGBNFayHHt21oll7ZEzyeJ2ZtnoUJzDVDY+J6s Dyr5atO7MyigsGYTcjjOZ+9YSx/2MMb6j8i7HLCg53zVCQVKhKGf/W4JOobjernafZrQ VjkVH38B+jsbhOWGE9GSi5McGrclPiU9HHBffL3pDCpr8hbso6uiz5F+poD5DrzypFRL UvJw== X-Gm-Message-State: AMCzsaVItUIuPnVKaBztd6kgCHVythjajFTw8l6AYRBOiMYfw+dTuIPW oerWNTApPvGVSIWmb2snVJboaA== X-Google-Smtp-Source: AOwi7QBS6IxobYwRQMWBinYpf0n3MCxqO++hwUIXagf6+cAsYQ7+vPNqGgBdPsofD8EE9w3UlIc/mA== X-Received: by 10.159.246.23 with SMTP id b23mr5225947pls.60.1507617305598; Mon, 09 Oct 2017 23:35:05 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id i3sm1162090pgs.82.2017.10.09.23.35.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Oct 2017 23:35:05 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, julien.thierry@arm.com Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro , Linus Torvalds Subject: [PATCH v5 02/10] resource: add walk_system_ram_res_rev() Date: Tue, 10 Oct 2017 15:36:11 +0900 Message-Id: <20171010063619.6303-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171010063619.6303-1-takahiro.akashi@linaro.org> References: <20171010063619.6303-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This function, being a variant of walk_system_ram_res() introduced in commit 8c86e70acead ("resource: provide new functions to walk through resources"), walks through a list of all the resources of System RAM in reversed order, i.e., from higher to lower. It will be used in kexec_file implementation on arm64. Signed-off-by: AKASHI Takahiro Cc: Vivek Goyal Cc: Andrew Morton Cc: Linus Torvalds --- include/linux/ioport.h | 3 +++ kernel/resource.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) -- 2.14.1 diff --git a/include/linux/ioport.h b/include/linux/ioport.h index f5cf32e80041..62eb62b98118 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -273,6 +273,9 @@ extern int walk_system_ram_res(u64 start, u64 end, void *arg, int (*func)(u64, u64, void *)); extern int +walk_system_ram_res_rev(u64 start, u64 end, void *arg, + int (*func)(u64, u64, void *)); +extern int walk_iomem_res_desc(unsigned long desc, unsigned long flags, u64 start, u64 end, void *arg, int (*func)(u64, u64, void *)); diff --git a/kernel/resource.c b/kernel/resource.c index 9b5f04404152..69c31454cb2e 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include @@ -469,6 +471,61 @@ int walk_system_ram_res(u64 start, u64 end, void *arg, return ret; } +int walk_system_ram_res_rev(u64 start, u64 end, void *arg, + int (*func)(u64, u64, void *)) +{ + struct resource res, *rams; + int rams_size = 16, i; + int ret = -1; + + /* create a list */ + rams = vmalloc(sizeof(struct resource) * rams_size); + if (!rams) + return ret; + + res.start = start; + res.end = end; + res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; + i = 0; + while ((res.start < res.end) && + (!find_next_iomem_res(&res, IORES_DESC_NONE, true))) { + if (i >= rams_size) { + /* re-alloc */ + struct resource *rams_new; + int rams_new_size; + + rams_new_size = rams_size + 16; + rams_new = vmalloc(sizeof(struct resource) + * rams_new_size); + if (!rams_new) + goto out; + + memcpy(rams_new, rams, + sizeof(struct resource) * rams_size); + vfree(rams); + rams = rams_new; + rams_size = rams_new_size; + } + + rams[i].start = res.start; + rams[i++].end = res.end; + + res.start = res.end + 1; + res.end = end; + } + + /* go reverse */ + for (i--; i >= 0; i--) { + ret = (*func)(rams[i].start, rams[i].end, arg); + if (ret) + break; + } + +out: + vfree(rams); + return ret; +} + #if !defined(CONFIG_ARCH_HAS_WALK_MEMORY) /* From patchwork Tue Oct 10 06:36:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 115351 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3401386qgn; Mon, 9 Oct 2017 23:35:17 -0700 (PDT) X-Received: by 10.159.194.6 with SMTP id x6mr9472212pln.359.1507617317188; Mon, 09 Oct 2017 23:35:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507617317; cv=none; d=google.com; s=arc-20160816; b=RtZ5LArzXXmrQcLqOOsx2AVyXJYmjEk/xV+a+M1bhLFIp8DMKxRhSJM/IgXp64Ozsg m4vyTWsO39VYwLK3i58agqupknhAZEfrIyCnxil7pHC3jgwdYs6PRnn5UfOYic8Fyz4k R6hp5BO9oViPZCl0sgH5fMmx2BIXbMFrzJjXmXinzcKlGLDoV09rAH7daC6i7nsTv5cs 4AztNJu6awyLR70Ho9Nkz7mTa0mH/1rKw1p0o6IeXAZ6SV9f4Yn7alTIEnU6t/euUhem 0fmv7NLEDJXXb8oYgQ6bMm13laFVg5i/EaB2Pwn1+zgjxojSQ7RNhwYuFOl8ltIH30gF hcQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=f9vfaZCysvTcBiGuEXLYfP3pxPVCS7k51QJrr8N345o=; b=DYoXvtEjHbUIKG3QC/eouXVEJiDhI0sTMmA9sq4Ha8Xa2u6CgmrmAx0ScdDEYfu/+L s6AYQ7U9PuPvW7PvEcakccNQjqjWvbXirsCgdui9+CXuXkcmFA2qkP8vifUG3KMK/7Rv Se7SIEL8KhbQjcmF2bEsbgBh4ccVsF5C9CSRVJiSLLmPTy1eXg6LO5USxQuYQTLDZgpu +44Vj4+9DNYKa4vYdUvz2LNvoVyLgwMUWtfli9t58quji67TyZwhXGr5kqUUmJQokwC1 eTjk2md4tRdUV5BNrCe0tZvQ87oHbeO23HE0VleHo38eES47ZB6r1zMPQ6jFC9ubwvrF Ym0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZVw3+oe6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v9si8591920plg.274.2017.10.09.23.35.16; Mon, 09 Oct 2017 23:35:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZVw3+oe6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755332AbdJJGfO (ORCPT + 26 others); Tue, 10 Oct 2017 02:35:14 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:51336 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755077AbdJJGfK (ORCPT ); Tue, 10 Oct 2017 02:35:10 -0400 Received: by mail-pf0-f176.google.com with SMTP id n14so14336302pfh.8 for ; Mon, 09 Oct 2017 23:35:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=f9vfaZCysvTcBiGuEXLYfP3pxPVCS7k51QJrr8N345o=; b=ZVw3+oe6jL5953MrTkdscdPNkBgXlSUJkL19HR0MxVXGxvQEF+UgePPx7Gm8O/RYyR KobFYaUqMS8hxqoPk+pwaghhsRRH+lDwJzk161th/ttXEzIVH7nZLVkdRlkuMHu5+J0R sk2doQvW8SMHD3+0GtIozG6PRkSbP0bdzPnJc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=f9vfaZCysvTcBiGuEXLYfP3pxPVCS7k51QJrr8N345o=; b=q1nJEWG3+vHhqgAZvoA0/7Wybmy2Tc0zrKuu8AnLrEWVSBh9Wn0GyzN+e3gzQJaS5S K2HqHZFtfmFto2YlgiJonAVfEq/t3DhzG7MyLOQGW6uTZUT/rxXjlJOzKMt2PDbNEuBN 5MYrP5uAumL+tj/szv7pD4xrFmrI7AlyeODc7FMc0QLdIhYShItb6wA90IByby6GwVoy KtqoXLUiQ52DV9TiFXsdmKCHmHCeHcP2dm+wBgaeREE7flxJiJc73BnyHDxVWuAu6EgQ 9H5hkJUoarHXZZnq6n4QSUsWYZRRCM1+XYvOga0x/bAF/UYWWZDX05BZpKu5MpFlIXLq QVfA== X-Gm-Message-State: AMCzsaXRKMMVgW5JpS+MmGew9b/RCHUT2poDVyeNqc3GMj7PfTUdUx6q W6mC8D6T3Bb49wgfXOMHwGXcCg== X-Google-Smtp-Source: AOwi7QBMv95OmP8dmhN+mi4mXsrWpgzgkDsURAoMU89Q1yJge4OTIzxeQlE6l1vXNfdxufw/rQt+BQ== X-Received: by 10.159.207.139 with SMTP id z11mr11024991plo.335.1507617309487; Mon, 09 Oct 2017 23:35:09 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id c7sm18915645pfc.55.2017.10.09.23.35.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Oct 2017 23:35:08 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, julien.thierry@arm.com Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v5 03/10] kexec_file: factor out arch_kexec_kernel_*() from x86, powerpc Date: Tue, 10 Oct 2017 15:36:12 +0900 Message-Id: <20171010063619.6303-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171010063619.6303-1-takahiro.akashi@linaro.org> References: <20171010063619.6303-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org arch_kexec_kernel_*() and arch_kimage_file_post_load_cleanup can now be duplicated among some architectures, so let's factor them out. Signed-off-by: AKASHI Takahiro Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He Cc: Michael Ellerman Cc: Thiago Jung Bauermann --- arch/powerpc/include/asm/kexec.h | 2 +- arch/powerpc/kernel/kexec_elf_64.c | 2 +- arch/powerpc/kernel/machine_kexec_file_64.c | 36 ++---------------- arch/x86/include/asm/kexec-bzimage64.h | 2 +- arch/x86/kernel/kexec-bzimage64.c | 2 +- arch/x86/kernel/machine_kexec_64.c | 45 +---------------------- include/linux/kexec.h | 15 ++++---- kernel/kexec_file.c | 57 +++++++++++++++++++++++++++-- 8 files changed, 70 insertions(+), 91 deletions(-) -- 2.14.1 diff --git a/arch/powerpc/include/asm/kexec.h b/arch/powerpc/include/asm/kexec.h index 25668bc8cb2a..23588952d8bd 100644 --- a/arch/powerpc/include/asm/kexec.h +++ b/arch/powerpc/include/asm/kexec.h @@ -92,7 +92,7 @@ static inline bool kdump_in_progress(void) } #ifdef CONFIG_KEXEC_FILE -extern struct kexec_file_ops kexec_elf64_ops; +extern const struct kexec_file_ops kexec_elf64_ops; #ifdef CONFIG_IMA_KEXEC #define ARCH_HAS_KIMAGE_ARCH diff --git a/arch/powerpc/kernel/kexec_elf_64.c b/arch/powerpc/kernel/kexec_elf_64.c index 9a42309b091a..6c78c11c7faf 100644 --- a/arch/powerpc/kernel/kexec_elf_64.c +++ b/arch/powerpc/kernel/kexec_elf_64.c @@ -657,7 +657,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf, return ret ? ERR_PTR(ret) : fdt; } -struct kexec_file_ops kexec_elf64_ops = { +const struct kexec_file_ops kexec_elf64_ops = { .probe = elf64_probe, .load = elf64_load, }; diff --git a/arch/powerpc/kernel/machine_kexec_file_64.c b/arch/powerpc/kernel/machine_kexec_file_64.c index 992c0d258e5d..e7ce78857f0b 100644 --- a/arch/powerpc/kernel/machine_kexec_file_64.c +++ b/arch/powerpc/kernel/machine_kexec_file_64.c @@ -31,8 +31,9 @@ #define SLAVE_CODE_SIZE 256 -static struct kexec_file_ops *kexec_file_loaders[] = { +const struct kexec_file_ops * const kexec_file_loaders[] = { &kexec_elf64_ops, + NULL }; int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, @@ -45,38 +46,7 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, if (image->type == KEXEC_TYPE_CRASH) return -ENOTSUPP; - for (i = 0; i < ARRAY_SIZE(kexec_file_loaders); i++) { - fops = kexec_file_loaders[i]; - if (!fops || !fops->probe) - continue; - - ret = fops->probe(buf, buf_len); - if (!ret) { - image->fops = fops; - return ret; - } - } - - return ret; -} - -void *arch_kexec_kernel_image_load(struct kimage *image) -{ - if (!image->fops || !image->fops->load) - return ERR_PTR(-ENOEXEC); - - return image->fops->load(image, image->kernel_buf, - image->kernel_buf_len, image->initrd_buf, - image->initrd_buf_len, image->cmdline_buf, - image->cmdline_buf_len); -} - -int arch_kimage_file_post_load_cleanup(struct kimage *image) -{ - if (!image->fops || !image->fops->cleanup) - return 0; - - return image->fops->cleanup(image->image_loader_data); + return _kexec_kernel_image_probe(image, buf, buf_len); } /** diff --git a/arch/x86/include/asm/kexec-bzimage64.h b/arch/x86/include/asm/kexec-bzimage64.h index d1b5d194e31d..284fd23d133b 100644 --- a/arch/x86/include/asm/kexec-bzimage64.h +++ b/arch/x86/include/asm/kexec-bzimage64.h @@ -1,6 +1,6 @@ #ifndef _ASM_KEXEC_BZIMAGE64_H #define _ASM_KEXEC_BZIMAGE64_H -extern struct kexec_file_ops kexec_bzImage64_ops; +extern const struct kexec_file_ops kexec_bzImage64_ops; #endif /* _ASM_KEXE_BZIMAGE64_H */ diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c index fb095ba0c02f..705654776c0c 100644 --- a/arch/x86/kernel/kexec-bzimage64.c +++ b/arch/x86/kernel/kexec-bzimage64.c @@ -538,7 +538,7 @@ static int bzImage64_verify_sig(const char *kernel, unsigned long kernel_len) } #endif -struct kexec_file_ops kexec_bzImage64_ops = { +const struct kexec_file_ops kexec_bzImage64_ops = { .probe = bzImage64_probe, .load = bzImage64_load, .cleanup = bzImage64_cleanup, diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c index 1f790cf9d38f..2cdd29d64181 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -30,8 +30,9 @@ #include #ifdef CONFIG_KEXEC_FILE -static struct kexec_file_ops *kexec_file_loaders[] = { +const struct kexec_file_ops * const kexec_file_loaders[] = { &kexec_bzImage64_ops, + NULL }; #endif @@ -363,27 +364,6 @@ void arch_crash_save_vmcoreinfo(void) /* arch-dependent functionality related to kexec file-based syscall */ #ifdef CONFIG_KEXEC_FILE -int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, - unsigned long buf_len) -{ - int i, ret = -ENOEXEC; - struct kexec_file_ops *fops; - - for (i = 0; i < ARRAY_SIZE(kexec_file_loaders); i++) { - fops = kexec_file_loaders[i]; - if (!fops || !fops->probe) - continue; - - ret = fops->probe(buf, buf_len); - if (!ret) { - image->fops = fops; - return ret; - } - } - - return ret; -} - void *arch_kexec_kernel_image_load(struct kimage *image) { vfree(image->arch.elf_headers); @@ -398,27 +378,6 @@ void *arch_kexec_kernel_image_load(struct kimage *image) image->cmdline_buf_len); } -int arch_kimage_file_post_load_cleanup(struct kimage *image) -{ - if (!image->fops || !image->fops->cleanup) - return 0; - - return image->fops->cleanup(image->image_loader_data); -} - -#ifdef CONFIG_KEXEC_VERIFY_SIG -int arch_kexec_kernel_verify_sig(struct kimage *image, void *kernel, - unsigned long kernel_len) -{ - if (!image->fops || !image->fops->verify_sig) { - pr_debug("kernel loader does not support signature verification."); - return -EKEYREJECTED; - } - - return image->fops->verify_sig(kernel, kernel_len); -} -#endif - /* * Apply purgatory relocations. * diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 2b7590f5483a..bfb37665a77f 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -208,7 +208,7 @@ struct kimage { unsigned long cmdline_buf_len; /* File operations provided by image loader */ - struct kexec_file_ops *fops; + const struct kexec_file_ops *fops; /* Image loader handling the kernel can store a pointer here */ void *image_loader_data; @@ -276,12 +276,13 @@ int crash_shrink_memory(unsigned long new_size); size_t crash_get_memory_size(void); void crash_free_reserved_phys_range(unsigned long begin, unsigned long end); -int __weak arch_kexec_kernel_image_probe(struct kimage *image, void *buf, - unsigned long buf_len); -void * __weak arch_kexec_kernel_image_load(struct kimage *image); -int __weak arch_kimage_file_post_load_cleanup(struct kimage *image); -int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, - unsigned long buf_len); +int _kexec_kernel_image_probe(struct kimage *image, void *buf, + unsigned long buf_len); +void *_kexec_kernel_image_load(struct kimage *image); +int _kimage_file_post_load_cleanup(struct kimage *image); +int _kexec_kernel_verify_sig(struct kimage *image, void *buf, + unsigned long buf_len); + int __weak arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, unsigned int relsec); int __weak arch_kexec_apply_relocations(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 9f48f4412297..bbb0177e20ab 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -26,30 +26,79 @@ #include #include "kexec_internal.h" +const __weak struct kexec_file_ops * const kexec_file_loaders[] = {NULL}; + static int kexec_calculate_store_digests(struct kimage *image); +int _kexec_kernel_image_probe(struct kimage *image, void *buf, + unsigned long buf_len) +{ + const struct kexec_file_ops *fops; + int ret = -ENOEXEC; + + for (fops = kexec_file_loaders[0]; fops && fops->probe; ++fops) { + ret = fops->probe(buf, buf_len); + if (!ret) { + image->fops = fops; + return ret; + } + } + + return ret; +} + /* Architectures can provide this probe function */ int __weak arch_kexec_kernel_image_probe(struct kimage *image, void *buf, unsigned long buf_len) { - return -ENOEXEC; + return _kexec_kernel_image_probe(image, buf, buf_len); +} + +void *_kexec_kernel_image_load(struct kimage *image) +{ + if (!image->fops || !image->fops->load) + return ERR_PTR(-ENOEXEC); + + return image->fops->load(image, image->kernel_buf, + image->kernel_buf_len, image->initrd_buf, + image->initrd_buf_len, image->cmdline_buf, + image->cmdline_buf_len); } void * __weak arch_kexec_kernel_image_load(struct kimage *image) { - return ERR_PTR(-ENOEXEC); + return _kexec_kernel_image_load(image); +} + +int _kimage_file_post_load_cleanup(struct kimage *image) +{ + if (!image->fops || !image->fops->cleanup) + return 0; + + return image->fops->cleanup(image->image_loader_data); } int __weak arch_kimage_file_post_load_cleanup(struct kimage *image) { - return -EINVAL; + return _kimage_file_post_load_cleanup(image); } #ifdef CONFIG_KEXEC_VERIFY_SIG +int _kexec_kernel_verify_sig(struct kimage *image, void *buf, + unsigned long buf_len) +{ + if (!image->fops || !image->fops->verify_sig) { + pr_debug("kernel loader does not support signature verification.\n"); + return -EKEYREJECTED; + } + + return image->fops->verify_sig(buf, buf_len); +} + int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, unsigned long buf_len) { - return -EKEYREJECTED; + return _kexec_kernel_verify_sig(image, buf, buf_len); } #endif From patchwork Tue Oct 10 06:36:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 115352 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3401424qgn; Mon, 9 Oct 2017 23:35:20 -0700 (PDT) X-Received: by 10.98.34.131 with SMTP id p3mr12248281pfj.1.1507617320065; Mon, 09 Oct 2017 23:35:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507617320; cv=none; d=google.com; s=arc-20160816; b=xeNy4vOPLtmhJDNpZ/CNzalFcJZKvvI+30sqAYa6mRvcGMky0DZvvh2rF7WXtGc0tr 3XXmPCzbfgTXLKpWjstbn46kRNbF63Zc91jQ+e4ANrXVib8bNTLMk97ucFuFrtpMwt53 agT9DqlojJbaiDd39TboUmfR9w9KbwTAKTHLmOg8X70jElmYUKO2g5MvLYU+wngNwy/p 2cNIjnFxJ/w4FY8X48lbyxM8Ro+Z/1fd3sULzqM7BrBEODE4vr6hUG+Rsw7p0qYxnIaR fQR5XGV92N+H1WC8GSrx8K1+7bIzCLqcvNHIU/CeIQHOeTbvs774il2ojGkotPhzSr+n cyfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=qAn4Bh5mytRuX7i4L4vD87jTz1KicRxAxyZ8GSGAESc=; b=UocoMIpKmMywhcrdNKm/yU1cJNuiWrfHh/7AsIefxwX4eoJPrKJEkGK3gK8NshOD9S zIYVAVRLdSf1/Br+H9/qy0dYnyRQNFP4R9/4M8GyJDQd1ZC8NiOIkKLatDZv16KIwHlv QXtxg7XzeP+hsj1IPB/FtHsIKWxuYjsNhYALaF78ZqgTrDDXgpB95dfo1fDIfhtflpKd KScqXUkMACpmY5rObURPmMeqXi5eavFaKgPCEyCgqtAV1WqrqCNYF+I5jVP1RS42GjHu KY/0ZEt8EofxUT2/B8CHmZi1KsIW6X1lZXSmpvKh4R4bc1ahQN4Af+ckK9VFqm+QpgnP G4ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aqLxS9lM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v9si8591920plg.274.2017.10.09.23.35.19; Mon, 09 Oct 2017 23:35:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aqLxS9lM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755414AbdJJGfR (ORCPT + 26 others); Tue, 10 Oct 2017 02:35:17 -0400 Received: from mail-pf0-f173.google.com ([209.85.192.173]:47968 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755272AbdJJGfO (ORCPT ); Tue, 10 Oct 2017 02:35:14 -0400 Received: by mail-pf0-f173.google.com with SMTP id z11so6299922pfk.4 for ; Mon, 09 Oct 2017 23:35:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qAn4Bh5mytRuX7i4L4vD87jTz1KicRxAxyZ8GSGAESc=; b=aqLxS9lMyg2L+fVNEbDwb3ov5OMVm6DifvTbCx0/Qy2RoD1oIJ4EVwlgaLFIGcbqnK XZ4Is9y0E002KyBvUttJQlAjW5MOTgvEcI7UzrlSlBTI4AVi3YUmkG3N6Ie+siMpSvV6 adHv5m7MSrZXdr+dSncpB2wGCCh/1DpAXMbFU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qAn4Bh5mytRuX7i4L4vD87jTz1KicRxAxyZ8GSGAESc=; b=UXV/kOdr/zq/VxN3KJhf4UrGKELYAlFb7emnNsQSUXGAaXzFJpOSQKKzGI0BkYXaLv eZ1hckFRdjQAyAsA55YZ5JsDwQLpc57X9Fbzr4Mn22GCK8ct3WyCYgjWVECmWIKSUIuB qIRrUR4EDjHwshhCPMe0MIG2BQVYGmgB9Et5jJ9ZwgYe1w17UcqnsulH/Nqq6Q7RXN86 LVkiVRIe8IvvUtpu03iSjuPn2KSXl39PA3fd7ABWhcDlVkjVv41tX2jmMLAwBePzqZpK 9Vo6+hSj7fdjiF5+FpFYhkMpmVrshsSkmhMFvpqB1hkOPb6oLLhtxI/ue1V0y+MfAwUx eHlA== X-Gm-Message-State: AMCzsaWC3/hopuG1zIhRVvwAJbphiyhRIZRGO4zvxhZ6kgUQ93pzhP9j sR0fCyV6BaRVGOR2JUJrXYoI6w== X-Google-Smtp-Source: AOwi7QCc5BoNmT3UI2MvTx1qr6uWwrdZX73KX7pVhDGtUGgWJrrYldJliXPQj/840MmGfd4FIONBSQ== X-Received: by 10.99.100.134 with SMTP id y128mr11302435pgb.45.1507617313591; Mon, 09 Oct 2017 23:35:13 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x1sm12663052pfk.131.2017.10.09.23.35.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Oct 2017 23:35:12 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, julien.thierry@arm.com Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v5 04/10] kexec_file: factor out crashdump elf header function from x86 Date: Tue, 10 Oct 2017 15:36:13 +0900 Message-Id: <20171010063619.6303-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171010063619.6303-1-takahiro.akashi@linaro.org> References: <20171010063619.6303-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org prepare_elf_headers() can also be useful for other architectures, including arm64. So let it factored out. Signed-off-by: AKASHI Takahiro Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- arch/x86/kernel/crash.c | 324 ------------------------------------------------ include/linux/kexec.h | 17 +++ kernel/kexec_file.c | 308 +++++++++++++++++++++++++++++++++++++++++++++ kernel/kexec_internal.h | 20 +++ 4 files changed, 345 insertions(+), 324 deletions(-) -- 2.14.1 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index 44404e2307bb..3c6b880f6dbf 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -41,34 +40,6 @@ /* Alignment required for elf header segment */ #define ELF_CORE_HEADER_ALIGN 4096 -/* This primarily represents number of split ranges due to exclusion */ -#define CRASH_MAX_RANGES 16 - -struct crash_mem_range { - u64 start, end; -}; - -struct crash_mem { - unsigned int nr_ranges; - struct crash_mem_range ranges[CRASH_MAX_RANGES]; -}; - -/* Misc data about ram ranges needed to prepare elf headers */ -struct crash_elf_data { - struct kimage *image; - /* - * Total number of ram ranges we have after various adjustments for - * crash reserved region, etc. - */ - unsigned int max_nr_ranges; - - /* Pointer to elf header */ - void *ehdr; - /* Pointer to next phdr */ - void *bufp; - struct crash_mem mem; -}; - /* Used while preparing memory map entries for second kernel */ struct crash_memmap_data { struct boot_params *params; @@ -209,301 +180,6 @@ void native_machine_crash_shutdown(struct pt_regs *regs) } #ifdef CONFIG_KEXEC_FILE -static int get_nr_ram_ranges_callback(u64 start, u64 end, void *arg) -{ - unsigned int *nr_ranges = arg; - - (*nr_ranges)++; - return 0; -} - - -/* Gather all the required information to prepare elf headers for ram regions */ -static void fill_up_crash_elf_data(struct crash_elf_data *ced, - struct kimage *image) -{ - unsigned int nr_ranges = 0; - - ced->image = image; - - walk_system_ram_res(0, -1, &nr_ranges, - get_nr_ram_ranges_callback); - - ced->max_nr_ranges = nr_ranges; - - /* Exclusion of crash region could split memory ranges */ - ced->max_nr_ranges++; - - /* If crashk_low_res is not 0, another range split possible */ - if (crashk_low_res.end) - ced->max_nr_ranges++; -} - -static int exclude_mem_range(struct crash_mem *mem, - unsigned long long mstart, unsigned long long mend) -{ - int i, j; - unsigned long long start, end; - struct crash_mem_range temp_range = {0, 0}; - - for (i = 0; i < mem->nr_ranges; i++) { - start = mem->ranges[i].start; - end = mem->ranges[i].end; - - if (mstart > end || mend < start) - continue; - - /* Truncate any area outside of range */ - if (mstart < start) - mstart = start; - if (mend > end) - mend = end; - - /* Found completely overlapping range */ - if (mstart == start && mend == end) { - mem->ranges[i].start = 0; - mem->ranges[i].end = 0; - if (i < mem->nr_ranges - 1) { - /* Shift rest of the ranges to left */ - for (j = i; j < mem->nr_ranges - 1; j++) { - mem->ranges[j].start = - mem->ranges[j+1].start; - mem->ranges[j].end = - mem->ranges[j+1].end; - } - } - mem->nr_ranges--; - return 0; - } - - if (mstart > start && mend < end) { - /* Split original range */ - mem->ranges[i].end = mstart - 1; - temp_range.start = mend + 1; - temp_range.end = end; - } else if (mstart != start) - mem->ranges[i].end = mstart - 1; - else - mem->ranges[i].start = mend + 1; - break; - } - - /* If a split happend, add the split to array */ - if (!temp_range.end) - return 0; - - /* Split happened */ - if (i == CRASH_MAX_RANGES - 1) { - pr_err("Too many crash ranges after split\n"); - return -ENOMEM; - } - - /* Location where new range should go */ - j = i + 1; - if (j < mem->nr_ranges) { - /* Move over all ranges one slot towards the end */ - for (i = mem->nr_ranges - 1; i >= j; i--) - mem->ranges[i + 1] = mem->ranges[i]; - } - - mem->ranges[j].start = temp_range.start; - mem->ranges[j].end = temp_range.end; - mem->nr_ranges++; - return 0; -} - -/* - * Look for any unwanted ranges between mstart, mend and remove them. This - * might lead to split and split ranges are put in ced->mem.ranges[] array - */ -static int elf_header_exclude_ranges(struct crash_elf_data *ced, - unsigned long long mstart, unsigned long long mend) -{ - struct crash_mem *cmem = &ced->mem; - int ret = 0; - - memset(cmem->ranges, 0, sizeof(cmem->ranges)); - - cmem->ranges[0].start = mstart; - cmem->ranges[0].end = mend; - cmem->nr_ranges = 1; - - /* Exclude crashkernel region */ - ret = exclude_mem_range(cmem, crashk_res.start, crashk_res.end); - if (ret) - return ret; - - if (crashk_low_res.end) { - ret = exclude_mem_range(cmem, crashk_low_res.start, crashk_low_res.end); - if (ret) - return ret; - } - - return ret; -} - -static int prepare_elf64_ram_headers_callback(u64 start, u64 end, void *arg) -{ - struct crash_elf_data *ced = arg; - Elf64_Ehdr *ehdr; - Elf64_Phdr *phdr; - unsigned long mstart, mend; - struct kimage *image = ced->image; - struct crash_mem *cmem; - int ret, i; - - ehdr = ced->ehdr; - - /* Exclude unwanted mem ranges */ - ret = elf_header_exclude_ranges(ced, start, end); - if (ret) - return ret; - - /* Go through all the ranges in ced->mem.ranges[] and prepare phdr */ - cmem = &ced->mem; - - for (i = 0; i < cmem->nr_ranges; i++) { - mstart = cmem->ranges[i].start; - mend = cmem->ranges[i].end; - - phdr = ced->bufp; - ced->bufp += sizeof(Elf64_Phdr); - - phdr->p_type = PT_LOAD; - phdr->p_flags = PF_R|PF_W|PF_X; - phdr->p_offset = mstart; - - /* - * If a range matches backup region, adjust offset to backup - * segment. - */ - if (mstart == image->arch.backup_src_start && - (mend - mstart + 1) == image->arch.backup_src_sz) - phdr->p_offset = image->arch.backup_load_addr; - - phdr->p_paddr = mstart; - phdr->p_vaddr = (unsigned long long) __va(mstart); - phdr->p_filesz = phdr->p_memsz = mend - mstart + 1; - phdr->p_align = 0; - ehdr->e_phnum++; - pr_debug("Crash PT_LOAD elf header. phdr=%p vaddr=0x%llx, paddr=0x%llx, sz=0x%llx e_phnum=%d p_offset=0x%llx\n", - phdr, phdr->p_vaddr, phdr->p_paddr, phdr->p_filesz, - ehdr->e_phnum, phdr->p_offset); - } - - return ret; -} - -static int prepare_elf64_headers(struct crash_elf_data *ced, - void **addr, unsigned long *sz) -{ - Elf64_Ehdr *ehdr; - Elf64_Phdr *phdr; - unsigned long nr_cpus = num_possible_cpus(), nr_phdr, elf_sz; - unsigned char *buf, *bufp; - unsigned int cpu; - unsigned long long notes_addr; - int ret; - - /* extra phdr for vmcoreinfo elf note */ - nr_phdr = nr_cpus + 1; - nr_phdr += ced->max_nr_ranges; - - /* - * kexec-tools creates an extra PT_LOAD phdr for kernel text mapping - * area on x86_64 (ffffffff80000000 - ffffffffa0000000). - * I think this is required by tools like gdb. So same physical - * memory will be mapped in two elf headers. One will contain kernel - * text virtual addresses and other will have __va(physical) addresses. - */ - - nr_phdr++; - elf_sz = sizeof(Elf64_Ehdr) + nr_phdr * sizeof(Elf64_Phdr); - elf_sz = ALIGN(elf_sz, ELF_CORE_HEADER_ALIGN); - - buf = vzalloc(elf_sz); - if (!buf) - return -ENOMEM; - - bufp = buf; - ehdr = (Elf64_Ehdr *)bufp; - bufp += sizeof(Elf64_Ehdr); - memcpy(ehdr->e_ident, ELFMAG, SELFMAG); - ehdr->e_ident[EI_CLASS] = ELFCLASS64; - ehdr->e_ident[EI_DATA] = ELFDATA2LSB; - ehdr->e_ident[EI_VERSION] = EV_CURRENT; - ehdr->e_ident[EI_OSABI] = ELF_OSABI; - memset(ehdr->e_ident + EI_PAD, 0, EI_NIDENT - EI_PAD); - ehdr->e_type = ET_CORE; - ehdr->e_machine = ELF_ARCH; - ehdr->e_version = EV_CURRENT; - ehdr->e_phoff = sizeof(Elf64_Ehdr); - ehdr->e_ehsize = sizeof(Elf64_Ehdr); - ehdr->e_phentsize = sizeof(Elf64_Phdr); - - /* Prepare one phdr of type PT_NOTE for each present cpu */ - for_each_present_cpu(cpu) { - phdr = (Elf64_Phdr *)bufp; - bufp += sizeof(Elf64_Phdr); - phdr->p_type = PT_NOTE; - notes_addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpu)); - phdr->p_offset = phdr->p_paddr = notes_addr; - phdr->p_filesz = phdr->p_memsz = sizeof(note_buf_t); - (ehdr->e_phnum)++; - } - - /* Prepare one PT_NOTE header for vmcoreinfo */ - phdr = (Elf64_Phdr *)bufp; - bufp += sizeof(Elf64_Phdr); - phdr->p_type = PT_NOTE; - phdr->p_offset = phdr->p_paddr = paddr_vmcoreinfo_note(); - phdr->p_filesz = phdr->p_memsz = VMCOREINFO_NOTE_SIZE; - (ehdr->e_phnum)++; - -#ifdef CONFIG_X86_64 - /* Prepare PT_LOAD type program header for kernel text region */ - phdr = (Elf64_Phdr *)bufp; - bufp += sizeof(Elf64_Phdr); - phdr->p_type = PT_LOAD; - phdr->p_flags = PF_R|PF_W|PF_X; - phdr->p_vaddr = (Elf64_Addr)_text; - phdr->p_filesz = phdr->p_memsz = _end - _text; - phdr->p_offset = phdr->p_paddr = __pa_symbol(_text); - (ehdr->e_phnum)++; -#endif - - /* Prepare PT_LOAD headers for system ram chunks. */ - ced->ehdr = ehdr; - ced->bufp = bufp; - ret = walk_system_ram_res(0, -1, ced, - prepare_elf64_ram_headers_callback); - if (ret < 0) - return ret; - - *addr = buf; - *sz = elf_sz; - return 0; -} - -/* Prepare elf headers. Return addr and size */ -static int prepare_elf_headers(struct kimage *image, void **addr, - unsigned long *sz) -{ - struct crash_elf_data *ced; - int ret; - - ced = kzalloc(sizeof(*ced), GFP_KERNEL); - if (!ced) - return -ENOMEM; - - fill_up_crash_elf_data(ced, image); - - /* By default prepare 64bit headers */ - ret = prepare_elf64_headers(ced, addr, sz); - kfree(ced); - return ret; -} - static int add_e820_entry(struct boot_params *params, struct e820_entry *entry) { unsigned int nr_e820_entries; diff --git a/include/linux/kexec.h b/include/linux/kexec.h index bfb37665a77f..648964cde163 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -162,6 +162,23 @@ int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, int (*func)(u64, u64, void *)); extern int kexec_add_buffer(struct kexec_buf *kbuf); int kexec_locate_mem_hole(struct kexec_buf *kbuf); +extern int prepare_elf_headers(struct kimage *image, void **addr, + unsigned long *sz); + +/* This primarily represents number of split ranges due to exclusion */ +#define CRASH_MAX_RANGES 16 + +struct crash_mem_range { + u64 start, end; +}; + +struct crash_mem { + unsigned int nr_ranges; + struct crash_mem_range ranges[CRASH_MAX_RANGES]; +}; + +extern int exclude_mem_range(struct crash_mem *mem, + unsigned long long mstart, unsigned long long mend); #endif /* CONFIG_KEXEC_FILE */ struct kimage { diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index bbb0177e20ab..2e21c3ab0165 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -22,6 +22,11 @@ #include #include #include +#include +#include +#include +#include +#include #include #include #include "kexec_internal.h" @@ -1070,3 +1075,306 @@ int kexec_purgatory_get_set_symbol(struct kimage *image, const char *name, return 0; } + +static int get_nr_ram_ranges_callback(u64 start, u64 end, void *arg) +{ + unsigned int *nr_ranges = arg; + + (*nr_ranges)++; + return 0; +} + + +/* Gather all the required information to prepare elf headers for ram regions */ +static void fill_up_crash_elf_data(struct crash_elf_data *ced, + struct kimage *image) +{ + unsigned int nr_ranges = 0; + + ced->image = image; + + walk_system_ram_res(0, -1, &nr_ranges, + get_nr_ram_ranges_callback); + + ced->max_nr_ranges = nr_ranges; + + /* Exclusion of crash region could split memory ranges */ + ced->max_nr_ranges++; + +#ifdef CONFIG_X86_64 + /* If crashk_low_res is not 0, another range split possible */ + if (crashk_low_res.end) + ced->max_nr_ranges++; +#endif +} + +int exclude_mem_range(struct crash_mem *mem, + unsigned long long mstart, unsigned long long mend) +{ + int i, j; + unsigned long long start, end; + struct crash_mem_range temp_range = {0, 0}; + + for (i = 0; i < mem->nr_ranges; i++) { + start = mem->ranges[i].start; + end = mem->ranges[i].end; + + if (mstart > end || mend < start) + continue; + + /* Truncate any area outside of range */ + if (mstart < start) + mstart = start; + if (mend > end) + mend = end; + + /* Found completely overlapping range */ + if (mstart == start && mend == end) { + mem->ranges[i].start = 0; + mem->ranges[i].end = 0; + if (i < mem->nr_ranges - 1) { + /* Shift rest of the ranges to left */ + for (j = i; j < mem->nr_ranges - 1; j++) { + mem->ranges[j].start = + mem->ranges[j+1].start; + mem->ranges[j].end = + mem->ranges[j+1].end; + } + } + mem->nr_ranges--; + return 0; + } + + if (mstart > start && mend < end) { + /* Split original range */ + mem->ranges[i].end = mstart - 1; + temp_range.start = mend + 1; + temp_range.end = end; + } else if (mstart != start) + mem->ranges[i].end = mstart - 1; + else + mem->ranges[i].start = mend + 1; + break; + } + + /* If a split happened, add the split to array */ + if (!temp_range.end) + return 0; + + /* Split happened */ + if (i == CRASH_MAX_RANGES - 1) { + pr_err("Too many crash ranges after split\n"); + return -ENOMEM; + } + + /* Location where new range should go */ + j = i + 1; + if (j < mem->nr_ranges) { + /* Move over all ranges one slot towards the end */ + for (i = mem->nr_ranges - 1; i >= j; i--) + mem->ranges[i + 1] = mem->ranges[i]; + } + + mem->ranges[j].start = temp_range.start; + mem->ranges[j].end = temp_range.end; + mem->nr_ranges++; + return 0; +} + +/* + * Look for any unwanted ranges between mstart, mend and remove them. This + * might lead to split and split ranges are put in ced->mem.ranges[] array + */ +static int elf_header_exclude_ranges(struct crash_elf_data *ced, + unsigned long long mstart, unsigned long long mend) +{ + struct crash_mem *cmem = &ced->mem; + int ret = 0; + + memset(cmem->ranges, 0, sizeof(cmem->ranges)); + + cmem->ranges[0].start = mstart; + cmem->ranges[0].end = mend; + cmem->nr_ranges = 1; + + /* Exclude crashkernel region */ + ret = exclude_mem_range(cmem, crashk_res.start, crashk_res.end); + if (ret) + return ret; + +#ifdef CONFIG_X86_64 + if (crashk_low_res.end) { + ret = exclude_mem_range(cmem, crashk_low_res.start, + crashk_low_res.end); + if (ret) + return ret; + } +#endif + + return ret; +} + +static int prepare_elf64_ram_headers_callback(u64 start, u64 end, void *arg) +{ + struct crash_elf_data *ced = arg; + Elf64_Ehdr *ehdr; + Elf64_Phdr *phdr; + unsigned long mstart, mend; +#ifdef CONFIG_X86_64 + struct kimage *image = ced->image; +#endif + struct crash_mem *cmem; + int ret, i; + + ehdr = ced->ehdr; + + /* Exclude unwanted mem ranges */ + ret = elf_header_exclude_ranges(ced, start, end); + if (ret) + return ret; + + /* Go through all the ranges in ced->mem.ranges[] and prepare phdr */ + cmem = &ced->mem; + + for (i = 0; i < cmem->nr_ranges; i++) { + mstart = cmem->ranges[i].start; + mend = cmem->ranges[i].end; + + phdr = ced->bufp; + ced->bufp += sizeof(Elf64_Phdr); + + phdr->p_type = PT_LOAD; + phdr->p_flags = PF_R|PF_W|PF_X; + phdr->p_offset = mstart; + +#ifdef CONFIG_X86_64 + /* + * If a range matches backup region, adjust offset to backup + * segment. + */ + if (mstart == image->arch.backup_src_start && + (mend - mstart + 1) == image->arch.backup_src_sz) + phdr->p_offset = image->arch.backup_load_addr; +#endif + + phdr->p_paddr = mstart; + phdr->p_vaddr = (unsigned long long) __va(mstart); + phdr->p_filesz = phdr->p_memsz = mend - mstart + 1; + phdr->p_align = 0; + ehdr->e_phnum++; + pr_debug("Crash PT_LOAD elf header. phdr=%p vaddr=0x%llx, paddr=0x%llx, sz=0x%llx e_phnum=%d p_offset=0x%llx\n", + phdr, phdr->p_vaddr, phdr->p_paddr, phdr->p_filesz, + ehdr->e_phnum, phdr->p_offset); + } + + return ret; +} + +static int prepare_elf64_headers(struct crash_elf_data *ced, + void **addr, unsigned long *sz) +{ + Elf64_Ehdr *ehdr; + Elf64_Phdr *phdr; + unsigned long nr_cpus = num_possible_cpus(), nr_phdr, elf_sz; + unsigned char *buf, *bufp; + unsigned int cpu; + unsigned long long notes_addr; + int ret; + + /* extra phdr for vmcoreinfo elf note */ + nr_phdr = nr_cpus + 1; + nr_phdr += ced->max_nr_ranges; + + /* + * kexec-tools creates an extra PT_LOAD phdr for kernel text mapping + * area on x86_64 (ffffffff80000000 - ffffffffa0000000). + * I think this is required by tools like gdb. So same physical + * memory will be mapped in two elf headers. One will contain kernel + * text virtual addresses and other will have __va(physical) addresses. + */ + + nr_phdr++; + elf_sz = sizeof(Elf64_Ehdr) + nr_phdr * sizeof(Elf64_Phdr); + elf_sz = ALIGN(elf_sz, ELF_CORE_HEADER_ALIGN); + + buf = vzalloc(elf_sz); + if (!buf) + return -ENOMEM; + + bufp = buf; + ehdr = (Elf64_Ehdr *)bufp; + bufp += sizeof(Elf64_Ehdr); + memcpy(ehdr->e_ident, ELFMAG, SELFMAG); + ehdr->e_ident[EI_CLASS] = ELFCLASS64; + ehdr->e_ident[EI_DATA] = ELFDATA2LSB; + ehdr->e_ident[EI_VERSION] = EV_CURRENT; + ehdr->e_ident[EI_OSABI] = ELF_OSABI; + memset(ehdr->e_ident + EI_PAD, 0, EI_NIDENT - EI_PAD); + ehdr->e_type = ET_CORE; + ehdr->e_machine = ELF_ARCH; + ehdr->e_version = EV_CURRENT; + ehdr->e_phoff = sizeof(Elf64_Ehdr); + ehdr->e_ehsize = sizeof(Elf64_Ehdr); + ehdr->e_phentsize = sizeof(Elf64_Phdr); + + /* Prepare one phdr of type PT_NOTE for each present cpu */ + for_each_present_cpu(cpu) { + phdr = (Elf64_Phdr *)bufp; + bufp += sizeof(Elf64_Phdr); + phdr->p_type = PT_NOTE; + notes_addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpu)); + phdr->p_offset = phdr->p_paddr = notes_addr; + phdr->p_filesz = phdr->p_memsz = sizeof(note_buf_t); + (ehdr->e_phnum)++; + } + + /* Prepare one PT_NOTE header for vmcoreinfo */ + phdr = (Elf64_Phdr *)bufp; + bufp += sizeof(Elf64_Phdr); + phdr->p_type = PT_NOTE; + phdr->p_offset = phdr->p_paddr = paddr_vmcoreinfo_note(); + phdr->p_filesz = phdr->p_memsz = VMCOREINFO_NOTE_SIZE; + (ehdr->e_phnum)++; + +#ifdef CONFIG_X86_64 + /* Prepare PT_LOAD type program header for kernel text region */ + phdr = (Elf64_Phdr *)bufp; + bufp += sizeof(Elf64_Phdr); + phdr->p_type = PT_LOAD; + phdr->p_flags = PF_R|PF_W|PF_X; + phdr->p_vaddr = (Elf64_Addr)_text; + phdr->p_filesz = phdr->p_memsz = _end - _text; + phdr->p_offset = phdr->p_paddr = __pa_symbol(_text); + (ehdr->e_phnum)++; +#endif + + /* Prepare PT_LOAD headers for system ram chunks. */ + ced->ehdr = ehdr; + ced->bufp = bufp; + ret = walk_system_ram_res(0, -1, ced, + prepare_elf64_ram_headers_callback); + if (ret < 0) + return ret; + + *addr = buf; + *sz = elf_sz; + return 0; +} + +/* Prepare elf headers. Return addr and size */ +int prepare_elf_headers(struct kimage *image, void **addr, unsigned long *sz) +{ + struct crash_elf_data *ced; + int ret; + + ced = kzalloc(sizeof(*ced), GFP_KERNEL); + if (!ced) + return -ENOMEM; + + fill_up_crash_elf_data(ced, image); + + /* By default prepare 64bit headers */ + ret = prepare_elf64_headers(ced, addr, sz); + kfree(ced); + return ret; +} diff --git a/kernel/kexec_internal.h b/kernel/kexec_internal.h index 50dfcb039a41..3c7a034f1fe1 100644 --- a/kernel/kexec_internal.h +++ b/kernel/kexec_internal.h @@ -16,6 +16,26 @@ extern struct mutex kexec_mutex; #ifdef CONFIG_KEXEC_FILE #include + +/* Alignment required for elf header segment */ +#define ELF_CORE_HEADER_ALIGN 4096 + +/* Misc data about ram ranges needed to prepare elf headers */ +struct crash_elf_data { + struct kimage *image; + /* + * Total number of ram ranges we have after various adjustments for + * crash reserved region, etc. + */ + unsigned int max_nr_ranges; + + /* Pointer to elf header */ + void *ehdr; + /* Pointer to next phdr */ + void *bufp; + struct crash_mem mem; +}; + void kimage_file_post_load_cleanup(struct kimage *image); extern char kexec_purgatory[]; extern size_t kexec_purgatory_size; From patchwork Tue Oct 10 06:36:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 115353 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3401474qgn; Mon, 9 Oct 2017 23:35:24 -0700 (PDT) X-Received: by 10.101.93.136 with SMTP id f8mr11342499pgt.60.1507617324331; Mon, 09 Oct 2017 23:35:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507617324; cv=none; d=google.com; s=arc-20160816; b=D0PDkaObGYg+qpS95ZDjPGO6GPckCPCtOIa9wj4PqudIET07BDnn8+VocWZ6ecRJxF Vc6L2dQ7hK4BUO2mZHzxHwNYl9qTC1dDHs7cqI7PUGTgdVK89GOKGefod/7j0Ms3jtk0 YeT52bYH8YVMh1Vrwzam2i2FKq+aA3UJhjQ1ToicUuzGaDOKsrVFRAWCiqQTc4sNiYkq q5qZHdWx//KrE5rKnYfadNhL2/ZXpT82SxGKfBGVV01v9KUhh5WpXNwiB6ljIk1Ty71U TzzC+G63wGf9Onb0ZMT+YI9ai/V72gLiEn66uvli5cUcuLj7hUScJ+yLY+jFrweA7tmV BNUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=XQ2hfwuqOxZtO/79mPkNiInqsdauHyfcRiwhgMReb/c=; b=I38mNm1Xjqg7B44Ymmg7In/qAsgH716HelZJNiE74GSHFIcZTjhQcfk8WgSA0/2OFf oYM5Gc5oVLDbvrcivwUrQP32iMyGA5kl32djVzH9T4tr+N936z63UIPywfuVMArOyRBj tx5VTKQ82Zf59Qp1/Cnc4XXLpVvkFrek3hpS83/wOUJxyDbxk7811k7JDkW7OCLEPMe4 2oAUa9zxEQPW4NKh6lGlbelxbWWjYYD0zMsQVYd01NInholzInpjlK0PiIngMYlVpwwt OczqfKIvYH49jTyFNxAidWviYxVI2U+t4rZzpmyhJHKk5MXJjZ2j+suZ2szVrmHUw3/O dE8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a4WDpHaI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f24si8659468pfk.415.2017.10.09.23.35.24; Mon, 09 Oct 2017 23:35:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a4WDpHaI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755466AbdJJGfV (ORCPT + 26 others); Tue, 10 Oct 2017 02:35:21 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:56244 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755388AbdJJGfR (ORCPT ); Tue, 10 Oct 2017 02:35:17 -0400 Received: by mail-pf0-f174.google.com with SMTP id 17so7901109pfn.12 for ; Mon, 09 Oct 2017 23:35:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XQ2hfwuqOxZtO/79mPkNiInqsdauHyfcRiwhgMReb/c=; b=a4WDpHaIHzL+++LwY8wnvqVIeD2K8zDqgq2b1xvoEaFRU1IhELc4fv0kyjNY2wh20v TUqCs8wSjE3btQ/Gdhp8+ZxTGZQHW//UKZcNypZMYYn4ET+QJSYPfEWaZayl+iD3mGMk lt0xmN6d79qucF8qPqlPiSU+yGJJw6emc/Q74= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XQ2hfwuqOxZtO/79mPkNiInqsdauHyfcRiwhgMReb/c=; b=AC4E1ywUeorhvzS1xbiG6uH8OT0oggyfWNvKrlXyZ/WtZnJ8cf1UzFqpzVumOF44br b6IptjO/5wMrZ//hUb4w5AjROv4F9D1G757QvD18zzTCqY6+JcdND4zJ8IwirojorX6s 0dZEjefq7pULYNfgStNHgE52aoJyLUvAn2PTupZKtPS+kG3UkaTh24OJtqSK4iMa5MWu PBXv0idIoPs8hFFCalvopUKmENxM3kkKW8azYkEYcKd3eUZT8mComCFgwnhsnCFGhQMM +aLTFYVxvDhvO6wyTusDsp8Ett4c5TClbtlnquCDbyVrvnSNRsTX9IIt++Yy5YZgItm8 Zz1g== X-Gm-Message-State: AMCzsaXfK2l6DmdW2uNLswivkTFrMvNMZROOjBRa30i6cvmfUMknN4oY P4aLx1xpgfjrIHP9nsYBuG4DPQ== X-Google-Smtp-Source: AOwi7QDARjHbMKsjTCPpCwOtN7BP0bJNHAew1EGZxU4hxPZjGqwfxzAM1zXkH08Cg/UHXt0lb28Arg== X-Received: by 10.98.35.18 with SMTP id j18mr6590017pfj.37.1507617317334; Mon, 09 Oct 2017 23:35:17 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t9sm1414172pgr.3.2017.10.09.23.35.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Oct 2017 23:35:16 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, julien.thierry@arm.com Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v5 05/10] asm-generic: add kexec_file_load system call to unistd.h Date: Tue, 10 Oct 2017 15:36:14 +0900 Message-Id: <20171010063619.6303-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171010063619.6303-1-takahiro.akashi@linaro.org> References: <20171010063619.6303-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The initial user of this system call number is arm64. Signed-off-by: AKASHI Takahiro Acked-by: Arnd Bergmann --- include/uapi/asm-generic/unistd.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.14.1 diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h index 061185a5eb51..086697fe3917 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -731,9 +731,11 @@ __SYSCALL(__NR_pkey_alloc, sys_pkey_alloc) __SYSCALL(__NR_pkey_free, sys_pkey_free) #define __NR_statx 291 __SYSCALL(__NR_statx, sys_statx) +#define __NR_kexec_file_load 292 +__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load) #undef __NR_syscalls -#define __NR_syscalls 292 +#define __NR_syscalls 293 /* * All syscalls below here should go away really, From patchwork Tue Oct 10 06:36:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 115354 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3401512qgn; Mon, 9 Oct 2017 23:35:27 -0700 (PDT) X-Received: by 10.101.71.135 with SMTP id e7mr11458336pgs.112.1507617327742; Mon, 09 Oct 2017 23:35:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507617327; cv=none; d=google.com; s=arc-20160816; b=J2V4KVtEJEcI4QwNERXtHbJ2N5CaK0i6sttBDtox2X6Y1U16bx8+JKkLp2/qASoWck zH5D3aqcX9pKVS0c1rXU0jAEodcnrjD6v8dqgvqpv+24acDkqy1lt93keqgdHi43l4hg 72b51QhCV4kK2epHYB8zEkcg+WIDz3j37dK9zTaeoocRAfNc1KF0isHAF4dziP/VdtkL rnRESsoyt9InQV03nK59tdO+5vmuVL917kHGwVMFf8Vjqb9wXIw7TiyBneEvMIwX0ZAD D9djQ3TwgECyuq/0GvnhtOuQsYCX+dLABYGQK1+0SaSnHsGNcC1UEUo6+HtG92E1Yh0t 2KUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=YaKBzkr/cIWgFVTBEsCUvwM4WhsObL1dHTAi6/jIrrg=; b=LbVVVHNK/bS/huev1+/M+t5ADSjS8yJaEzdB27zCQgPp2XG/WIjsj88yUqT0YeC7FK jMKntqnIy8uVqdXLGFuIGJuDGlBKp1oOvYwMuyOHsSwhHy0qqs79+efiWp42wzEBlfIa YNrFlOe1mMnPrffW0jADOzSr8wqMJ93g3ZA05rB/jY8kocBXsgX2kqu21VYCn0PgfURZ Jg8gC5Oel6bY2auqP07eSe80/CZacgj8sdDaT5zYgFht8DKPzaBtQ9iZrK2DS3KGz2qK o1AAwKemoSmgZvhuz8kKGFpFzCuBHU9q2HDCUCKZkZkwTwSOYTyWAyTqB99JgXF4Rm8C u4wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ucpa2wyg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f24si8659468pfk.415.2017.10.09.23.35.27; Mon, 09 Oct 2017 23:35:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ucpa2wyg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755523AbdJJGfY (ORCPT + 26 others); Tue, 10 Oct 2017 02:35:24 -0400 Received: from mail-pf0-f179.google.com ([209.85.192.179]:47980 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755450AbdJJGfV (ORCPT ); Tue, 10 Oct 2017 02:35:21 -0400 Received: by mail-pf0-f179.google.com with SMTP id z11so6300165pfk.4 for ; Mon, 09 Oct 2017 23:35:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YaKBzkr/cIWgFVTBEsCUvwM4WhsObL1dHTAi6/jIrrg=; b=Ucpa2wygpAP3zqGmPNYtc1wo+GPYBquKNMA18KC/BTl/A/gcKhA/srNVZRE/SBxx4o 6UwuQxhqwPANAwMRr/OlYhJ9deq7dqZ2A3I/JGVI43wiazo8rmCGoc7hNBOOgFOUlag2 zS5qVEw7hn7wLCO9Fpk/Jzx0oCe/JYk9Cmbzk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YaKBzkr/cIWgFVTBEsCUvwM4WhsObL1dHTAi6/jIrrg=; b=e3/QV7q6NpKdGWdvHpRphrCaQfWisJkS/3Ko6By4/rFN4s2bTNs85CB1fY+qISac5N jDimPqugWIGBAT9YMlEiCD5Si/kNJsCbeQBXwl5WNQpzdPGucyF8U59SYcv7L0OXMqdZ HAFvK7ijm8TZu9565/bih+hCW6RnBJei2Z5cUpr0SN54U8119iEIqco93Zm5xDPKLSIJ 31WHNNFq/y43AMlFEI2Voy/7ASTOOWI3C8ZpL24Tyzrursj2wocyudnUG7vq9Rf6Tz34 QBZF1e9gblB/FjYfufWmvnNc6tNp6bbzNu2nGL95zdJFjCKNyiE+8PMUINFMVRNoA0DC IgDg== X-Gm-Message-State: AMCzsaVJI4pBwX3s403wt07oYsteHc4ujyNOZGZhzfa6lKyaL3DFBach GEWe2pYexQSHQczeu5/i+FkPUw== X-Google-Smtp-Source: AOwi7QAyCUA9/v+Wq48KM7tKwHAPeRQ4ucUiGDCJ2eK0xdqwk3GrStIwLqPDoaH6YAPL2zw77X/aXg== X-Received: by 10.101.78.5 with SMTP id r5mr6877282pgt.94.1507617320462; Mon, 09 Oct 2017 23:35:20 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id c25sm16236348pgn.64.2017.10.09.23.35.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Oct 2017 23:35:19 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, julien.thierry@arm.com Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v5 06/10] arm64: kexec_file: create purgatory Date: Tue, 10 Oct 2017 15:36:15 +0900 Message-Id: <20171010063619.6303-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171010063619.6303-1-takahiro.akashi@linaro.org> References: <20171010063619.6303-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a basic purgatory, or a kind of glue code between the two kernels, for arm64. Since purgatory is assumed to be relocatable (not executable) object by kexec generic code, arch_kexec_apply_relocations_add() is required in general. Arm64's purgatory, however, is a simple asm and all the references can be resolved as local, no re-linking is needed here. Please note that even if we don't support digest check at purgatory we need purgatory_sha_regions and purgatory_sha256_digest as they are referenced by generic kexec code. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/Makefile | 1 + arch/arm64/purgatory/Makefile | 24 +++++++++++++++++++ arch/arm64/purgatory/entry.S | 55 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 arch/arm64/purgatory/Makefile create mode 100644 arch/arm64/purgatory/entry.S -- 2.14.1 diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 939b310913cf..cf39ec3baf5a 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -110,6 +110,7 @@ core-$(CONFIG_XEN) += arch/arm64/xen/ core-$(CONFIG_CRYPTO) += arch/arm64/crypto/ libs-y := arch/arm64/lib/ $(libs-y) core-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a +core-$(CONFIG_KEXEC_FILE) += arch/arm64/purgatory/ # Default target when executing plain make boot := arch/arm64/boot diff --git a/arch/arm64/purgatory/Makefile b/arch/arm64/purgatory/Makefile new file mode 100644 index 000000000000..c2127a2cbd51 --- /dev/null +++ b/arch/arm64/purgatory/Makefile @@ -0,0 +1,24 @@ +OBJECT_FILES_NON_STANDARD := y + +purgatory-y := entry.o + +targets += $(purgatory-y) +PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y)) + +LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined \ + -nostdlib -z nodefaultlib +targets += purgatory.ro + +$(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE + $(call if_changed,ld) + +targets += kexec_purgatory.c + +CMD_BIN2C = $(objtree)/scripts/basic/bin2c +quiet_cmd_bin2c = BIN2C $@ + cmd_bin2c = $(CMD_BIN2C) kexec_purgatory < $< > $@ + +$(obj)/kexec_purgatory.c: $(obj)/purgatory.ro FORCE + $(call if_changed,bin2c) + +obj-${CONFIG_KEXEC_FILE} += kexec_purgatory.o diff --git a/arch/arm64/purgatory/entry.S b/arch/arm64/purgatory/entry.S new file mode 100644 index 000000000000..fe6e968076db --- /dev/null +++ b/arch/arm64/purgatory/entry.S @@ -0,0 +1,55 @@ +/* + * kexec core purgatory + */ +#include +#include + +#define SHA256_DIGEST_SIZE 32 /* defined in crypto/sha.h */ + +.text + +ENTRY(purgatory_start) + /* Start new image. */ + ldr x17, __kernel_entry + ldr x0, __dtb_addr + mov x1, xzr + mov x2, xzr + mov x3, xzr + br x17 +END(purgatory_start) + +/* + * data section: + * kernel_entry and dtb_addr are global but also labelled as local, + * "__xxx:", to avoid unwanted re-linking. + * + * purgatory_sha_regions and purgatory_sha256_digest are referenced + * by kexec generic code and so must exist, but not actually used + * here because hash check is not that useful in purgatory. + */ +.align 3 + +.globl kernel_entry +kernel_entry: +__kernel_entry: + .quad 0 +END(kernel_entry) + +.globl dtb_addr +dtb_addr: +__dtb_addr: + .quad 0 +END(dtb_addr) + +.globl purgatory_sha_regions +purgatory_sha_regions: + .rept KEXEC_SEGMENT_MAX + .quad 0 + .quad 0 + .endr +END(purgatory_sha_regions) + +.globl purgatory_sha256_digest +purgatory_sha256_digest: + .skip SHA256_DIGEST_SIZE +END(purgatory_sha256_digest) From patchwork Tue Oct 10 06:36:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 115355 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3401552qgn; Mon, 9 Oct 2017 23:35:31 -0700 (PDT) X-Received: by 10.101.69.74 with SMTP id x10mr11352352pgr.294.1507617331155; Mon, 09 Oct 2017 23:35:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507617331; cv=none; d=google.com; s=arc-20160816; b=T7ogKJ0bVMPejpKUWDxbS/JerCIJGdE6n9m9baW9IX8J/l/2AJNvoqMRpO7zcTjFkr WEhKOtKLDRMXVW8k+tLZO3nKUPTYu0zXSvhS+qP5jl2uf/wKppDKZMDiYah/UH0ja48j 0FzkglfMxFMhJw3jKbxkXEYFV1zy3C7GLkC2W2xH9tujk+ZXrpU8a0RdPjSs1JCplmNR aPQI2byjw5D3GDIhMFukKnC7a9jAyeg9OKL1NpjEI9aU8WiGQWRn4ly5In4P0kLjAhhS Nanyp3PoX3IfcifixgWnZ+BvbOhslfbj6zfjvkTN3lVt+8EJJ8fiCTm+LhAu/U9MohyS oTPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=EUDVxNklGgTBLqy4+SSgleaRNqtOZvqCz83pUUNgi98=; b=N4vt2BuJjVT8JgZAqCQPpmmnFoYOQFVfTqjS8BnL+cUnuhSs86VdLjMDddY/RnBHRf Ufa8CjHSKefCoeP3ovHRFOfFTQJQlAewgahk1zi1KHhH+zNgq2MCywCdKR4vkSM5dWFL gId9bTQ+qzZN7W6OpotAVyfOq4qqFlbPomZQoR8rCyF7pe/cSThFYCZFE0/lHebfcNOL 0BpX32Fzijf2gHEFBP+JpT/C4xbRV4OeuM77/WhUsQv31zO1QDjo8G406o+SPtNmMWIv 14uc3IrnAloChKFi4cqzhjsIARgWLTCne4uxi4wC11awr0JQR0o4TJHH32cBVLbKVPaq clOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Yo18kmoP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j13si7765250pgs.541.2017.10.09.23.35.30; Mon, 09 Oct 2017 23:35:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Yo18kmoP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932100AbdJJGf2 (ORCPT + 26 others); Tue, 10 Oct 2017 02:35:28 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:52443 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755450AbdJJGfZ (ORCPT ); Tue, 10 Oct 2017 02:35:25 -0400 Received: by mail-pf0-f176.google.com with SMTP id a1so13004359pfj.9 for ; Mon, 09 Oct 2017 23:35:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EUDVxNklGgTBLqy4+SSgleaRNqtOZvqCz83pUUNgi98=; b=Yo18kmoPhfWqjAxe05oHj7i00UL0oymcPY5VuxNyF9+DScK1QHTtqR77keToLlOTly mkY11hgirG2eMlUFwpdeZfPvEjufMTFl0oBI9p/6DqoGhDAwj/QFdwgfqxVfuDkG/YVS XasZA1uP0EVr+4gswLlbbK6PedRI0NTcnsWjU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EUDVxNklGgTBLqy4+SSgleaRNqtOZvqCz83pUUNgi98=; b=EKaCEI6kALzz2LOfvQR9FpVZBMCGNcfXjt6bRRX4yt1002hsnNL/LLeqjDmdMXav+L GdQ/+IZrNJRlVkc2cvdBXQj3hwzHQzORohZuq7hQa0JDPRdu7CxAzlDBmGq6ouHnxcHH ZowJHVOjcKZcFLmyFWl2yEqwGWAHdZkHb9OYBJdprVF2eAzilnSFkdMSXVX8TcdhXSFx 9wJkcJ1e5ctLVnZt4EMwdx/pgHqgpvMC6CdHbOjBEgAVsBzsMVUR+71NBb+OyH5APEgD fioiVRvl5vG8QPYLv+fLjNngXxu7S7cn32wMa/arUE5sSD28yI6YUGNuCtvnrpvtcYSZ dMrg== X-Gm-Message-State: AMCzsaVfXHPzlbHuT+qUdkv2bW7LcbCxXk4O1n/I1qR3AtpoWFGYQoie q61XmPUnNeG1YLXoXwW6NrI/IQ== X-Google-Smtp-Source: AOwi7QD+JGMy1ycBELp77IKMz29Mb+ay/5sGFftAMTYCAKBmKNUDyexFEzGdRd398MU1qo9N3q1W4g== X-Received: by 10.98.57.215 with SMTP id u84mr8480017pfj.300.1507617324553; Mon, 09 Oct 2017 23:35:24 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id i84sm20402376pfj.105.2017.10.09.23.35.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Oct 2017 23:35:23 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, julien.thierry@arm.com Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v5 07/10] arm64: kexec_file: load initrd, device-tree and purgatory segments Date: Tue, 10 Oct 2017 15:36:16 +0900 Message-Id: <20171010063619.6303-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171010063619.6303-1-takahiro.akashi@linaro.org> References: <20171010063619.6303-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org load_other_segments() sets up and adds all the memory segments necessary other than kernel, including initrd, device-tree blob and purgatory. Most of the code was borrowed from kexec-tools' counterpart. arch_kimage_kernel_post_load_cleanup() is meant to free arm64-specific data allocated for loading kernel. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/include/asm/kexec.h | 22 ++++ arch/arm64/kernel/Makefile | 3 +- arch/arm64/kernel/machine_kexec_file.c | 213 +++++++++++++++++++++++++++++++++ 3 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/machine_kexec_file.c -- 2.14.1 diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index e17f0529a882..2fadd3cbf3af 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -93,6 +93,28 @@ static inline void crash_prepare_suspend(void) {} static inline void crash_post_resume(void) {} #endif +#ifdef CONFIG_KEXEC_FILE +#define ARCH_HAS_KIMAGE_ARCH + +struct kimage_arch { + void *dtb_buf; +}; + +struct kimage; + +#define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_cleanup +extern int arch_kimage_file_post_load_cleanup(struct kimage *image); + +extern int setup_dtb(struct kimage *image, + unsigned long initrd_load_addr, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len, + char **dtb_buf, size_t *dtb_buf_len); +extern int load_other_segments(struct kimage *image, + unsigned long kernel_load_addr, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len); +#endif + #endif /* __ASSEMBLY__ */ #endif diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index f2b4e816b6de..5df003d6157c 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -48,8 +48,9 @@ arm64-obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL) += acpi_parking_protocol.o arm64-obj-$(CONFIG_PARAVIRT) += paravirt.o arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o -arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o \ +arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c new file mode 100644 index 000000000000..81af1602e149 --- /dev/null +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -0,0 +1,213 @@ +/* + * kexec_file for arm64 + * + * Copyright (C) 2017 Linaro Limited + * Author: AKASHI Takahiro + * + * Most code is derived from arm64 port of kexec-tools + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#define pr_fmt(fmt) "kexec_file: " fmt + +#include +#include +#include +#include +#include +#include + +static int __dt_root_addr_cells; +static int __dt_root_size_cells; + +const struct kexec_file_ops * const kexec_file_loaders[] = { + NULL +}; + +int arch_kimage_file_post_load_cleanup(struct kimage *image) +{ + vfree(image->arch.dtb_buf); + image->arch.dtb_buf = NULL; + + return _kimage_file_post_load_cleanup(image); +} + +int arch_kexec_walk_mem(struct kexec_buf *kbuf, int (*func)(u64, u64, void *)) +{ + if (kbuf->image->type == KEXEC_TYPE_CRASH) + return walk_iomem_res_desc(crashk_res.desc, + IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY, + crashk_res.start, crashk_res.end, + kbuf, func); + else if (kbuf->top_down) + return walk_system_ram_res_rev(0, ULONG_MAX, kbuf, func); + else + return walk_system_ram_res(0, ULONG_MAX, kbuf, func); +} + +int setup_dtb(struct kimage *image, + unsigned long initrd_load_addr, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len, + char **dtb_buf, size_t *dtb_buf_len) +{ + char *buf = NULL; + size_t buf_size; + int nodeoffset; + u64 value; + int range_len; + int ret; + + /* duplicate dt blob */ + buf_size = fdt_totalsize(initial_boot_params); + range_len = (__dt_root_addr_cells + __dt_root_size_cells) * sizeof(u32); + + if (initrd_load_addr) + buf_size += fdt_prop_len("initrd-start", sizeof(u64)) + + fdt_prop_len("initrd-end", sizeof(u64)); + + if (cmdline) + buf_size += fdt_prop_len("bootargs", cmdline_len + 1); + + buf = vmalloc(buf_size); + if (!buf) { + ret = -ENOMEM; + goto out_err; + } + + ret = fdt_open_into(initial_boot_params, buf, buf_size); + if (ret) + goto out_err; + + nodeoffset = fdt_path_offset(buf, "/chosen"); + if (nodeoffset < 0) + goto out_err; + + /* add bootargs */ + if (cmdline) { + ret = fdt_setprop(buf, nodeoffset, "bootargs", + cmdline, cmdline_len + 1); + if (ret) + goto out_err; + } + + /* add initrd-* */ + if (initrd_load_addr) { + value = cpu_to_fdt64(initrd_load_addr); + ret = fdt_setprop(buf, nodeoffset, "initrd-start", + &value, sizeof(value)); + if (ret) + goto out_err; + + value = cpu_to_fdt64(initrd_load_addr + initrd_len); + ret = fdt_setprop(buf, nodeoffset, "initrd-end", + &value, sizeof(value)); + if (ret) + goto out_err; + } + + /* trim a buffer */ + fdt_pack(buf); + *dtb_buf = buf; + *dtb_buf_len = fdt_totalsize(buf); + + return 0; + +out_err: + vfree(buf); + return ret; +} + +int load_other_segments(struct kimage *image, unsigned long kernel_load_addr, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len) +{ + struct kexec_buf kbuf; + unsigned long initrd_load_addr = 0; + unsigned long purgatory_load_addr, dtb_load_addr; + char *dtb = NULL; + unsigned long dtb_len; + int ret = 0; + + kbuf.image = image; + /* not allocate anything below the kernel */ + kbuf.buf_min = kernel_load_addr; + + /* Load initrd */ + if (initrd) { + kbuf.buffer = initrd; + kbuf.bufsz = initrd_len; + kbuf.memsz = initrd_len; + kbuf.buf_align = PAGE_SIZE; + /* within 1GB-aligned window of up to 32GB in size */ + kbuf.buf_max = round_down(kernel_load_addr, SZ_1G) + + (unsigned long)SZ_1G * 31; + kbuf.top_down = 0; + + ret = kexec_add_buffer(&kbuf); + if (ret) + goto out_err; + initrd_load_addr = kbuf.mem; + + pr_debug("Loaded initrd at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + initrd_load_addr, initrd_len, initrd_len); + } + + /* Load dtb blob */ + ret = setup_dtb(image, initrd_load_addr, initrd_len, + cmdline, cmdline_len, &dtb, &dtb_len); + if (ret) { + pr_err("Preparing for new dtb failed\n"); + goto out_err; + } + + kbuf.buffer = dtb; + kbuf.bufsz = dtb_len; + kbuf.memsz = dtb_len; + /* not across 2MB boundary */ + kbuf.buf_align = SZ_2M; + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = 1; + + ret = kexec_add_buffer(&kbuf); + if (ret) + goto out_err; + dtb_load_addr = kbuf.mem; + image->arch.dtb_buf = dtb; + + pr_debug("Loaded dtb at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + dtb_load_addr, dtb_len, dtb_len); + + /* Load purgatory */ + ret = kexec_load_purgatory(image, kernel_load_addr, ULONG_MAX, 1, + &purgatory_load_addr); + if (ret) { + pr_err("Loading purgatory failed\n"); + goto out_err; + } + + ret = kexec_purgatory_get_set_symbol(image, "kernel_entry", + &kernel_load_addr, sizeof(kernel_load_addr), 0); + if (ret) { + pr_err("Setting symbol (kernel_entry) failed.\n"); + goto out_err; + } + + ret = kexec_purgatory_get_set_symbol(image, "dtb_addr", + &dtb_load_addr, sizeof(dtb_load_addr), 0); + if (ret) { + pr_err("Setting symbol (dtb_addr) failed.\n"); + goto out_err; + } + + pr_debug("Loaded purgatory at 0x%lx\n", purgatory_load_addr); + + return 0; + +out_err: + vfree(dtb); + image->arch.dtb_buf = NULL; + return ret; +} From patchwork Tue Oct 10 06:36:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 115356 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3401623qgn; Mon, 9 Oct 2017 23:35:35 -0700 (PDT) X-Received: by 10.84.225.145 with SMTP id u17mr11217273plj.105.1507617335375; Mon, 09 Oct 2017 23:35:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507617335; cv=none; d=google.com; s=arc-20160816; b=dv5V4HyF/zXq8yCR7Xej7HpiGwrXLFhsRW3Hiy3793RaBWSdevigmGAZJiB70iQVLD ygYN9G+wpywpHXInwD9aZ+FiKzyfT99KSrjcvqRBrh3g83kec+17V+YKf19xWQbPaVuE KKGbW4s/dsJy2z6DVsr732ILfKFJS/NkTgC5GA0Tb6EstOIFWqPEu7Za38KcutLKzULb znEzAN0j+fhKl564zx6gIow6s9nAVqrze9hllTbfRcn+C7wBWPP7DwmrO9Ej9Solu36e z1cyuGXplhx4df2moSfGhfTIBxtda6RxuznKDn6HN5jnij7En0EW+r8XjKU/2/wTbMHC lVsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=cPZtZ8IQXG2Y0h9HI9/zgf2taW78lJ3+VyfWUMoaYVI=; b=l5vPmWOk7SKQndd5ltsCCEXRjcPy4jwY41GurqAqcgP8ye2VO9etzBQI5bVoUvacr2 z5tkNS173YnhAKg2Ltt12dwf+ONbyfwyEHlhVf/Bg0wDuv9XV0etlthdsbs2ShybbhSZ DOJcJY/n62FU31O1t8P4BV0m8qu2pIEG6v2MfcRLHPjrKzNzp1fH9E6L9W5PObD//kQX XmuTmS5eVUawdBXNjUiIBYPJXUq+q2Uc7Gj+dW6iF05XETGy1VLSyDFTdasko9SX3Sb/ d6scxlxLtaxywQhD/jPzGl3+iPDKjtOSTVwtaf9vtXQKEkTsH/LnIdJ3L7pFAJXgB6aA 934A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YbeRimKj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v85si8447698pfk.276.2017.10.09.23.35.35; Mon, 09 Oct 2017 23:35:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YbeRimKj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932122AbdJJGfd (ORCPT + 26 others); Tue, 10 Oct 2017 02:35:33 -0400 Received: from mail-pf0-f171.google.com ([209.85.192.171]:43556 "EHLO mail-pf0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755450AbdJJGf2 (ORCPT ); Tue, 10 Oct 2017 02:35:28 -0400 Received: by mail-pf0-f171.google.com with SMTP id d2so13048403pfh.0 for ; Mon, 09 Oct 2017 23:35:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cPZtZ8IQXG2Y0h9HI9/zgf2taW78lJ3+VyfWUMoaYVI=; b=YbeRimKjg9Psw777u8MTjfQ1NyMDYVCUNWKV2dg9q9DYEkG10QpbbGXNkuBkA3tbSq aVjqav1pL332HaqmiZQ3F0ix00/VQgNlR6NuyIXAJNg2tpIeM72iQuTNls9kT4/3D9ym n6DnR2vgvRdLKJyYi6o6+D9MB5ullBaFt5udY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cPZtZ8IQXG2Y0h9HI9/zgf2taW78lJ3+VyfWUMoaYVI=; b=TFa0U8xSCr/fKvPZxYBIO1Rtp7zLaelLQnYzRFcIhXZj1AIHA+usrftYwfbtBo07jM iVF+9P7zcbOowzlIVM16hFSrjoI3ZZnAWS+bdUumtDNokkJ0Zqk2YNCO3QJ/ZVeyanyQ cCPB7y+24++huco435XYViGkT9AnxgxilUslAXeagXa4CZCJnRy3kGHvmbAs0z5nS41j nFgLwydp3LRc6qvZDZksGop0aau6njp7EqpRTcMCTON9yYg4mblsK4Q7xUMJl5ejCGfS oJRs9hGlkATxBQDznt42umuatiaOKFpkkioGvJ2+BcQPTfAbhMCca8BbM0G2qME6aKvv TnVg== X-Gm-Message-State: AMCzsaU9GQEQp891YevgI0oF2OIKaXwkoRTvRGIBER3Pd7hG3/tGAAgB x8bFYU92mLVxA7ap1KuyGHwmLQ== X-Google-Smtp-Source: AOwi7QCdS21kIoBNzt/aYFrleqU1uHapZAIZrajgnWNIm2cdHiC+uGbPXeeg61iAzrsrWzp7BVGYhg== X-Received: by 10.84.210.105 with SMTP id z96mr11280800plh.325.1507617328292; Mon, 09 Oct 2017 23:35:28 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id a78sm11781121pfl.122.2017.10.09.23.35.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Oct 2017 23:35:27 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, julien.thierry@arm.com Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v5 08/10] arm64: kexec_file: set up for crash dump adding elf core header Date: Tue, 10 Oct 2017 15:36:17 +0900 Message-Id: <20171010063619.6303-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171010063619.6303-1-takahiro.akashi@linaro.org> References: <20171010063619.6303-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org load_crashdump_segments() creates and loads a memory segment of elf core header for crash dump. "linux,usable-memory-range" and "linux,elfcorehdr" will add to the 2nd kernel's device-tree blob. The logic of this cod is also from kexec-tools. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/include/asm/kexec.h | 5 ++ arch/arm64/kernel/machine_kexec_file.c | 151 +++++++++++++++++++++++++++++++++ kernel/kexec_file.c | 2 +- 3 files changed, 157 insertions(+), 1 deletion(-) -- 2.14.1 diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 2fadd3cbf3af..edb702e64a8a 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -98,6 +98,10 @@ static inline void crash_post_resume(void) {} struct kimage_arch { void *dtb_buf; + /* Core ELF header buffer */ + void *elf_headers; + unsigned long elf_headers_sz; + unsigned long elf_load_addr; }; struct kimage; @@ -113,6 +117,7 @@ extern int load_other_segments(struct kimage *image, unsigned long kernel_load_addr, char *initrd, unsigned long initrd_len, char *cmdline, unsigned long cmdline_len); +extern int load_crashdump_segments(struct kimage *image); #endif #endif /* __ASSEMBLY__ */ diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 81af1602e149..cdedd4b05cac 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -19,6 +19,7 @@ #include #include #include +#include static int __dt_root_addr_cells; static int __dt_root_size_cells; @@ -32,6 +33,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) vfree(image->arch.dtb_buf); image->arch.dtb_buf = NULL; + vfree(image->arch.elf_headers); + image->arch.elf_headers = NULL; + image->arch.elf_headers_sz = 0; + return _kimage_file_post_load_cleanup(image); } @@ -48,6 +53,78 @@ int arch_kexec_walk_mem(struct kexec_buf *kbuf, int (*func)(u64, u64, void *)) return walk_system_ram_res(0, ULONG_MAX, kbuf, func); } +static int __init arch_kexec_file_init(void) +{ + /* Those values are used later on loading the kernel */ + __dt_root_addr_cells = dt_root_addr_cells; + __dt_root_size_cells = dt_root_size_cells; + + return 0; +} +late_initcall(arch_kexec_file_init); + +#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) +#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) + +static int fdt_prop_len(const char *prop_name, int len) +{ + return (strlen(prop_name) + 1) + + sizeof(struct fdt_property) + + FDT_TAGALIGN(len); +} + +static bool cells_size_fitted(unsigned long base, unsigned long size) +{ + /* if *_cells >= 2, cells can hold 64-bit values anyway */ + if ((__dt_root_addr_cells == 1) && (base >= (1ULL << 32))) + return false; + + if ((__dt_root_size_cells == 1) && (size >= (1ULL << 32))) + return false; + + return true; +} + +static void fill_property(void *buf, u64 val64, int cells) +{ + u32 val32; + + if (cells == 1) { + val32 = cpu_to_fdt32((u32)val64); + memcpy(buf, &val32, sizeof(val32)); + } else { + memset(buf, 0, cells * sizeof(u32) - sizeof(u64)); + buf += cells * sizeof(u32) - sizeof(u64); + + val64 = cpu_to_fdt64(val64); + memcpy(buf, &val64, sizeof(val64)); + } +} + +static int fdt_setprop_range(void *fdt, int nodeoffset, const char *name, + unsigned long addr, unsigned long size) +{ + void *buf, *prop; + size_t buf_size; + int result; + + buf_size = (__dt_root_addr_cells + __dt_root_size_cells) * sizeof(u32); + prop = buf = vmalloc(buf_size); + if (!buf) + return -ENOMEM; + + fill_property(prop, addr, __dt_root_addr_cells); + prop += __dt_root_addr_cells * sizeof(u32); + + fill_property(prop, size, __dt_root_size_cells); + + result = fdt_setprop(fdt, nodeoffset, name, buf, buf_size); + + vfree(buf); + + return result; +} + int setup_dtb(struct kimage *image, unsigned long initrd_load_addr, unsigned long initrd_len, char *cmdline, unsigned long cmdline_len, @@ -60,10 +137,26 @@ int setup_dtb(struct kimage *image, int range_len; int ret; + /* check ranges against root's #address-cells and #size-cells */ + if (image->type == KEXEC_TYPE_CRASH && + (!cells_size_fitted(image->arch.elf_load_addr, + image->arch.elf_headers_sz) || + !cells_size_fitted(crashk_res.start, + crashk_res.end - crashk_res.start + 1))) { + pr_err("Crash memory region doesn't fit into DT's root cell sizes.\n"); + ret = -EINVAL; + goto out_err; + } + /* duplicate dt blob */ buf_size = fdt_totalsize(initial_boot_params); range_len = (__dt_root_addr_cells + __dt_root_size_cells) * sizeof(u32); + if (image->type == KEXEC_TYPE_CRASH) + buf_size += fdt_prop_len("linux,elfcorehdr", range_len) + + fdt_prop_len("linux,usable-memory-range", + range_len); + if (initrd_load_addr) buf_size += fdt_prop_len("initrd-start", sizeof(u64)) + fdt_prop_len("initrd-end", sizeof(u64)); @@ -85,6 +178,23 @@ int setup_dtb(struct kimage *image, if (nodeoffset < 0) goto out_err; + if (image->type == KEXEC_TYPE_CRASH) { + /* add linux,elfcorehdr */ + ret = fdt_setprop_range(buf, nodeoffset, "linux,elfcorehdr", + image->arch.elf_load_addr, + image->arch.elf_headers_sz); + if (ret) + goto out_err; + + /* add linux,usable-memory-range */ + ret = fdt_setprop_range(buf, nodeoffset, + "linux,usable-memory-range", + crashk_res.start, + crashk_res.end - crashk_res.start + 1); + if (ret) + goto out_err; + } + /* add bootargs */ if (cmdline) { ret = fdt_setprop(buf, nodeoffset, "bootargs", @@ -211,3 +321,44 @@ int load_other_segments(struct kimage *image, unsigned long kernel_load_addr, image->arch.dtb_buf = NULL; return ret; } + +int load_crashdump_segments(struct kimage *image) +{ + void *elf_addr; + unsigned long elf_sz; + struct kexec_buf kbuf; + int ret; + + if (image->type != KEXEC_TYPE_CRASH) + return 0; + + /* Prepare elf headers and add a segment */ + ret = prepare_elf_headers(image, &elf_addr, &elf_sz); + if (ret) { + pr_err("Preparing elf core header failed\n"); + return ret; + } + + kbuf.image = image; + kbuf.buffer = elf_addr; + kbuf.bufsz = elf_sz; + kbuf.memsz = elf_sz; + kbuf.buf_align = PAGE_SIZE; + kbuf.buf_min = crashk_res.start; + kbuf.buf_max = crashk_res.end + 1; + kbuf.top_down = 1; + + ret = kexec_add_buffer(&kbuf); + if (ret) { + vfree(elf_addr); + return ret; + } + image->arch.elf_headers = elf_addr; + image->arch.elf_headers_sz = elf_sz; + image->arch.elf_load_addr = kbuf.mem; + + pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + image->arch.elf_load_addr, elf_sz, elf_sz); + + return ret; +} diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 2e21c3ab0165..fc791ba545cd 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -1336,7 +1336,7 @@ static int prepare_elf64_headers(struct crash_elf_data *ced, phdr->p_filesz = phdr->p_memsz = VMCOREINFO_NOTE_SIZE; (ehdr->e_phnum)++; -#ifdef CONFIG_X86_64 +#if defined(CONFIG_X86_64) || defined(CONFIG_ARM64) /* Prepare PT_LOAD type program header for kernel text region */ phdr = (Elf64_Phdr *)bufp; bufp += sizeof(Elf64_Phdr); From patchwork Tue Oct 10 06:36:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 115358 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3401934qgn; Mon, 9 Oct 2017 23:35:56 -0700 (PDT) X-Received: by 10.159.246.11 with SMTP id b11mr11314436pls.41.1507617356380; Mon, 09 Oct 2017 23:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507617356; cv=none; d=google.com; s=arc-20160816; b=YVqa4xr2uUdivF3yY9qsO1TZZG7cuhXmh10I/iYGnTptDfzYeKuvk42VEhpQ50It8I rNqCpQVEaYfz1LoMY2yNyo0tcBXdCrY/nVrY5i6SNaoSUCOrS7xJbOIRuaMLEud+ui0h JQTYvIbxVKkXaNeHU+QuuD4AUjrp2QBZ4GC40waXgFolvUFmbkotN08xYtjAh++ZkxJN tuN5Qs3/D3EPo2KnyJHwVAY9hiJyzgoLmGS/2CsAJI6vYtAYamrKn8ofAJ9achyNgtqC v/fgDHbTymI7sRObJvVEqxEVSwzSxJTFlojz84mVRU3lEeMK9kHFsBwshgRyCVUQAzxU s4Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=LfjyO5OybSisJOU4rvyfBiASP38tRI2/fuL2HzcwuHs=; b=VxJ8pXIeji48oY2Nj5PNCsm/lA87XGV5HvlnsIhd3k9B1HZBzF9SaqFyJB5hnYAdsv cyUkeAaUO3zmCuzxT6Use1qEcVPBQUMNBorEzFjKfAm2NuRUosUXTfCTretJ4HuAZjc+ ZTZRgfyYD9UKmD35Bt1gHiwgj14bNMB7fVU7JjZxDTzAsTT07o8UUtxm6CL3WoD+Ct/z 3eAjBuWoTCmBPVQ/pWK4AarOixshpVwIZF6Jo0eYxorzFPUd7nK3vvZOJhWNHpYQEe2j VkWNNV7W64Ut69E5GNszsCD5ISxR6ziBpRjsneTCx1CanVZcgVfIhAzGJLjvEM6NHiuW gupg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UG8NySGi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h75si8511926pfj.622.2017.10.09.23.35.56; Mon, 09 Oct 2017 23:35:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UG8NySGi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755582AbdJJGfy (ORCPT + 26 others); Tue, 10 Oct 2017 02:35:54 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:44115 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932108AbdJJGfc (ORCPT ); Tue, 10 Oct 2017 02:35:32 -0400 Received: by mail-pf0-f174.google.com with SMTP id x7so5942951pfa.1 for ; Mon, 09 Oct 2017 23:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LfjyO5OybSisJOU4rvyfBiASP38tRI2/fuL2HzcwuHs=; b=UG8NySGiMkVGNobKUj8nFkQ3UgjL01WVIF+c1gTtXN7lm74H9FmRd5nzcvrsnMSNTf 6ykRd8iGK7k1vbK6vDSlFLQMp3f0Jqv92E/Q6ua8YXCVaCUYOTAz9Q5iLum5367ChDUR BbVqEPV0CGnF0wf1RD7SsVZ0dnEO9BZQhWv88= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LfjyO5OybSisJOU4rvyfBiASP38tRI2/fuL2HzcwuHs=; b=bHKoDhVx8xqMVSLdCZNz6VLK8Q8Ph5L7efs/mPQuTkPMoatjNNeKOdwLbIazC1NwPB be3bFQ1hWv+TNIwqOQJwW4PEOVnQOCcT0rhjpvhxo1jXM/264d1LMNqPPuQnzrpCN0nc SnK+z+vYPUNayZChq4Zt/sY4eweTZlhMIW5I/aE8NIBBSzCv2npTvlggryHvLxFJxzer 3N+JXcAKD85zcIIkHSbcbkknAb/TVx7dxcUGt3is8M6IjtuDKs6KzftElIoWznOWzy+U fFiDOyAO4XLCSKsaXRU4CzZ56RRd0Yqjoaqqfbsa6t4gZSJrECJs5CDAdg7eB8vmNPtZ U8MA== X-Gm-Message-State: AMCzsaXJ7tcRvqE+bosBn2Imr7U/Qm3PxhxZqM7POlG5qU/nBSCm+nuG oRqvNuVx+guO7Y3GQ4wG5bMx6g== X-Google-Smtp-Source: AOwi7QBd+S3AHbuqwp7knbYGFOj25XFVyGfZ9aG3G8YThqC6i27JGIwznHgY+yIyBRkIWrcTYFi5rg== X-Received: by 10.98.86.135 with SMTP id h7mr12307511pfj.216.1507617331931; Mon, 09 Oct 2017 23:35:31 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id i187sm17699788pfc.19.2017.10.09.23.35.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Oct 2017 23:35:31 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, julien.thierry@arm.com Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v5 09/10] arm64: enable KEXEC_FILE config Date: Tue, 10 Oct 2017 15:36:18 +0900 Message-Id: <20171010063619.6303-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171010063619.6303-1-takahiro.akashi@linaro.org> References: <20171010063619.6303-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Modify arm64/Kconfig and Makefile to enable kexec_file_load support. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/Kconfig | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) -- 2.14.1 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 0df64a6a56d4..e37be8a59a88 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -757,6 +757,28 @@ config KEXEC but it is independent of the system firmware. And like a reboot you can start any kernel with it, not just Linux. +config KEXEC_FILE + bool "kexec file based system call" + select KEXEC_CORE + select BUILD_BIN2C + ---help--- + This is new version of kexec system call. This system call is + file based and takes file descriptors as system call argument + for kernel and initramfs as opposed to list of segments as + accepted by previous system call. + + In addition to this option, you need to enable a specific type + of image support. + +config KEXEC_VERIFY_SIG + bool "Verify kernel signature during kexec_file_load() syscall" + depends on KEXEC_FILE + select SYSTEM_DATA_VERIFICATION + ---help--- + Select this option to verify a signature with loaded kernel + image. If configured, any attempt of loading a image without + valid signature will fail. + config CRASH_DUMP bool "Build kdump crash kernel" help From patchwork Tue Oct 10 06:36:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 115357 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3401707qgn; Mon, 9 Oct 2017 23:35:42 -0700 (PDT) X-Received: by 10.99.63.199 with SMTP id m190mr11475942pga.239.1507617341966; Mon, 09 Oct 2017 23:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507617341; cv=none; d=google.com; s=arc-20160816; b=eYEw7cAPKIIcrwOMHSbvmAuRcedNOs/O3nv2YBWp8XG0S0sEInpysq29E3mHrOGrHh uOK7DFreLW5tK4r1FUOasKi6kij0j4u+agPuYGVpd6sfHq3piqesgUFQN0sQSykZZ0oz ls9DYvUuY6GhJyAgFqxXQEZhajqw97qL4N/1FfFErtJVzO9Pe5sP2DDjRTyI3pIcd6ix 13p+FlGPCZZ/aA3maYG7Zf8HaBCPuOuvhKdGBuKDdhVLNcMDoRodNmveIPzZvIoJ8hAa 16KSooSndwWHojjDcb9GtZD2fP9idf23o+LEzMoUmorGaIofSRq7apXr4zIoAUIvOtih /Wmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=CAa1rsfrAJTOc71d4UthiGrDWSfAmnSm6YQpHyveQSE=; b=B1PBuAwdxC2DFPbUXHeyJxuDE+RVPtBMKdUXpPlkN7Pse2O+spM+oHsyB1YRi09sXr zNopWKp946405iQfSWM59ZLAghxZzcVAhra6Q6tiGYn/vO0reI+4RxC3GwQAReEDU8Yp 1/2h2ZS3sxCpMj8QTQhnH0oX4le2iILwq7Q6jlb9fxg2ZQeLcJ71H1sZzQxLShvk4ZvG 6NDBqxUwD1Ns0/58TmQL4w5grBnE9vQiPMdRkg0CgUd6tf9dwTBE/QTQGQHwgihH3ur9 SOhFgST3VZJXdUhzuar+73XUAAnW/Ffz8kqLA1L9IYyyst3JEEfNeRvqj9a5XwsKVW0q Qy2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=U2UECbKR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v85si8447698pfk.276.2017.10.09.23.35.41; Mon, 09 Oct 2017 23:35:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=U2UECbKR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755556AbdJJGfj (ORCPT + 26 others); Tue, 10 Oct 2017 02:35:39 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:54555 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754108AbdJJGfg (ORCPT ); Tue, 10 Oct 2017 02:35:36 -0400 Received: by mail-pf0-f181.google.com with SMTP id m28so11309188pfi.11 for ; Mon, 09 Oct 2017 23:35:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CAa1rsfrAJTOc71d4UthiGrDWSfAmnSm6YQpHyveQSE=; b=U2UECbKR0uOBzTgVJJPRNRj76+Q9qeYus7CGdypgCyxXtzd+HBmkI1hGyqGwkIFybF a4gYXryUlYabSig1pbVf9xOfIqMuyxoZrvnDxaGrq6YCP4gVx/dQNnvvgoM5RwLoCgMe EcYtRTfFPpyrJYxL/55FmTKy5VMpmxEynRCvs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CAa1rsfrAJTOc71d4UthiGrDWSfAmnSm6YQpHyveQSE=; b=SWJSTJzG508fsySLt+O/2xy5yPnnHpOvxxQsuyQAYGtwp+JAydAtufHJNdiSKm0ieF kDiXDCcXMFo9xovE5wlzbr38dmcnWS4VeNCkz9k9gLEcRkc+eqPdHRifBIcXvNhOuYqd h9YoXZ3iXtX5JzPKcbhfv41tCbeU8elnt5zxEmp43vctBynhhIm2Cyh+hAqNXtjCuXs8 IeWEkE99G2g1yCw2qooraA/DZivIvkKtVQhvd5oxCtCE/Y4Y+wtY9Ol/R8LpZz3js08f doj2qnkvcG9UYqPRf8jcwC+NKVV24+Z4Tpjmc05K4Q/XB5cncY5pzv7/GIokRFHqzgk2 BkEg== X-Gm-Message-State: AMCzsaU5TkG+eev3ZduW1J3Ip1/znXR1iq/2lEKa+pYXt8+zzo7mJf5j EHq/3w8t/trzVKcgmi+YGtzrwg== X-Google-Smtp-Source: AOwi7QDygr4M5N3Htqp2GtE2A1y/FKpTsKdGFfrRrKJfh/okBMkjJHN2QQoPV7Rx3c2g4vsK28RHKg== X-Received: by 10.101.85.204 with SMTP id k12mr11079005pgs.439.1507617335620; Mon, 09 Oct 2017 23:35:35 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id h9sm19058700pfh.98.2017.10.09.23.35.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Oct 2017 23:35:35 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, julien.thierry@arm.com Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v5 10/10] arm64: kexec_file: add Image format support Date: Tue, 10 Oct 2017 15:36:19 +0900 Message-Id: <20171010063619.6303-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171010063619.6303-1-takahiro.akashi@linaro.org> References: <20171010063619.6303-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The "Image" binary will be loaded at the offset of TEXT_OFFSET from the start of system memory. TEXT_OFFSET is determined from the header of the image. Regarding kernel signature verification, it will be done through verify_pefile_signature() as arm64's "Image" binary can be seen as in PE format. This approach is consistent with x86 implementation. we can sign an image with sbsign command. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/Kconfig | 7 +++ arch/arm64/include/asm/kexec.h | 66 +++++++++++++++++++++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/kexec_image.c | 105 +++++++++++++++++++++++++++++++++ arch/arm64/kernel/machine_kexec_file.c | 3 + 5 files changed, 182 insertions(+) create mode 100644 arch/arm64/kernel/kexec_image.c -- 2.14.1 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index e37be8a59a88..a9ef277faa3e 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -770,10 +770,17 @@ config KEXEC_FILE In addition to this option, you need to enable a specific type of image support. +config KEXEC_FILE_IMAGE_FMT + bool "Enable Image support" + depends on KEXEC_FILE + ---help--- + Select this option to enable 'Image' kernel loading. + config KEXEC_VERIFY_SIG bool "Verify kernel signature during kexec_file_load() syscall" depends on KEXEC_FILE select SYSTEM_DATA_VERIFICATION + select SIGNED_PE_FILE_VERIFICATION if KEXEC_FILE_IMAGE_FMT ---help--- Select this option to verify a signature with loaded kernel image. If configured, any attempt of loading a image without diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index edb702e64a8a..2a63bf5f32ea 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -104,6 +104,72 @@ struct kimage_arch { unsigned long elf_load_addr; }; +/** + * struct arm64_image_header - arm64 kernel image header + * + * @pe_sig: Optional PE format 'MZ' signature + * @branch_code: Instruction to branch to stext + * @text_offset: Image load offset, little endian + * @image_size: Effective image size, little endian + * @flags: + * Bit 0: Kernel endianness. 0=little endian, 1=big endian + * @reserved: Reserved + * @magic: Magic number, "ARM\x64" + * @pe_header: Optional offset to a PE format header + **/ + +struct arm64_image_header { + u8 pe_sig[2]; + u8 pad[2]; + u32 branch_code; + u64 text_offset; + u64 image_size; + u64 flags; + u64 reserved[3]; + u8 magic[4]; + u32 pe_header; +}; + +static const u8 arm64_image_magic[4] = {'A', 'R', 'M', 0x64U}; +static const u8 arm64_image_pe_sig[2] = {'M', 'Z'}; + +/** + * arm64_header_check_magic - Helper to check the arm64 image header. + * + * Returns non-zero if header is OK. + */ + +static inline int arm64_header_check_magic(const struct arm64_image_header *h) +{ + if (!h) + return 0; + + if (!h->text_offset) + return 0; + + return (h->magic[0] == arm64_image_magic[0] + && h->magic[1] == arm64_image_magic[1] + && h->magic[2] == arm64_image_magic[2] + && h->magic[3] == arm64_image_magic[3]); +} + +/** + * arm64_header_check_pe_sig - Helper to check the arm64 image header. + * + * Returns non-zero if 'MZ' signature is found. + */ + +static inline int arm64_header_check_pe_sig(const struct arm64_image_header *h) +{ + if (!h) + return 0; + + return (h->pe_sig[0] == arm64_image_pe_sig[0] + && h->pe_sig[1] == arm64_image_pe_sig[1]); +} + +extern const struct kexec_file_ops kexec_image_ops; + struct kimage; #define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_cleanup diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 5df003d6157c..a1161bab6810 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -51,6 +51,7 @@ arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o +arm64-obj-$(CONFIG_KEXEC_FILE_IMAGE_FMT) += kexec_image.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c new file mode 100644 index 000000000000..b840b6ed6ed9 --- /dev/null +++ b/arch/arm64/kernel/kexec_image.c @@ -0,0 +1,105 @@ +/* + * Kexec image loader + + * Copyright (C) 2017 Linaro Limited + * Author: AKASHI Takahiro + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#define pr_fmt(fmt) "kexec_file(Image): " fmt + +#include +#include +#include +#include +#include +#include +#include + +static int image_probe(const char *kernel_buf, unsigned long kernel_len) +{ + const struct arm64_image_header *h; + + h = (const struct arm64_image_header *)(kernel_buf); + + if ((kernel_len < sizeof(*h)) || !arm64_header_check_magic(h)) + return -EINVAL; + + pr_debug("PE format: %s\n", + (arm64_header_check_pe_sig(h) ? "yes" : "no")); + + return 0; +} + +static void *image_load(struct kimage *image, char *kernel, + unsigned long kernel_len, char *initrd, + unsigned long initrd_len, char *cmdline, + unsigned long cmdline_len) +{ + struct kexec_buf kbuf; + struct arm64_image_header *h = (struct arm64_image_header *)kernel; + unsigned long text_offset, kernel_load_addr; + int ret; + + /* Create elf core header segment */ + ret = load_crashdump_segments(image); + if (ret) + goto out; + + /* Load the kernel */ + kbuf.image = image; + if (image->type == KEXEC_TYPE_CRASH) { + kbuf.buf_min = crashk_res.start; + kbuf.buf_max = crashk_res.end + 1; + } else { + kbuf.buf_min = 0; + kbuf.buf_max = ULONG_MAX; + } + kbuf.top_down = 0; + + kbuf.buffer = kernel; + kbuf.bufsz = kernel_len; + kbuf.memsz = le64_to_cpu(h->image_size); + text_offset = le64_to_cpu(h->text_offset); + kbuf.buf_align = SZ_2M; + + /* Adjust kernel segment with TEXT_OFFSET */ + kbuf.memsz += text_offset; + + ret = kexec_add_buffer(&kbuf); + if (ret) + goto out; + + image->segment[image->nr_segments - 1].mem += text_offset; + image->segment[image->nr_segments - 1].memsz -= text_offset; + kernel_load_addr = kbuf.mem + text_offset; + + pr_debug("Loaded kernel at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + kernel_load_addr, kbuf.bufsz, kbuf.memsz); + + /* Load additional data */ + ret = load_other_segments(image, kernel_load_addr, + initrd, initrd_len, cmdline, cmdline_len); + +out: + return ERR_PTR(ret); +} + +#ifdef CONFIG_KEXEC_VERIFY_SIG +static int image_verify_sig(const char *kernel, unsigned long kernel_len) +{ + return verify_pefile_signature(kernel, kernel_len, NULL, + VERIFYING_KEXEC_PE_SIGNATURE); +} +#endif + +const struct kexec_file_ops kexec_image_ops = { + .probe = image_probe, + .load = image_load, +#ifdef CONFIG_KEXEC_VERIFY_SIG + .verify_sig = image_verify_sig, +#endif +}; diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index cdedd4b05cac..75549bd64e24 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -25,6 +25,9 @@ static int __dt_root_addr_cells; static int __dt_root_size_cells; const struct kexec_file_ops * const kexec_file_loaders[] = { +#ifdef CONFIG_KEXEC_FILE_IMAGE_FMT + &kexec_image_ops, +#endif NULL };