From patchwork Tue Oct 24 06:23:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 116890 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5451437qgn; Mon, 23 Oct 2017 23:21:33 -0700 (PDT) X-Received: by 10.84.191.228 with SMTP id a91mr12206095pld.176.1508826093273; Mon, 23 Oct 2017 23:21:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508826093; cv=none; d=google.com; s=arc-20160816; b=mfL2c3IpXuHoe8P8okBtbC5qD1dIh2QXBl340YBRKH7hQtb1PhCCE6+onSs1+lF5fU /rdlonfi3W7D4Y22Cm7IGHKAaDIaFE8DWQlOrpfmrl3KOHHDFkz0LmB3X3roMninw+6B tVBPb/Srl345wVAHgga5MEUEzU/uWoFEljshNuu8Se+eUf8es25pUtZAUhjaGq/xKOPo LQ2MSjIpiVVyMXr+Djjqk7szvNFzo5Vq2iKQCB2Mqm7ilu/YjNPfkHfasvgFzafs3p7Z Js+E2uokZjPYXx1QU04cKb4r7Wna1xEfJqQyrT0wRj9bhXVFMr5vb2tNZlfkucqvob9E 8QCA== 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=q+ScqRinzrqWEJCa+9Qwoyvi4UZAjuKQmB2zEkfC6K22c3T+xENUBcI+fYpiVcrRBC zgAx+SxcKknTVytxBB+vt56IMRIHoG4piog8BhxmCXilQ0It/A9hvjO+03cR+74UQq84 MU3P9Rb/iYm34Wv7yn3f6MxbyrMKijk0T9S+vmYkjrJkGv3w2JA3cYQip5pCwFT1r10O kwiLGfH9RO1M7eSjwCcEBGXIBq8BG9NZp71BSZUM6kof/Zh6saNspFIjlZXbCxTPE7Mr oqhKgm/0q3nFiSpsNu7WD6CFat1JXZ6FRMLv/c5XVyLyHG2FVk/HP9kW1j578A9H5Xnk P6lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UHV7Hfa+; 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 b23si6522798pfm.307.2017.10.23.23.21.33; Mon, 23 Oct 2017 23:21:33 -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=UHV7Hfa+; 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 S1751707AbdJXGVb (ORCPT + 27 others); Tue, 24 Oct 2017 02:21:31 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:49751 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751645AbdJXGV2 (ORCPT ); Tue, 24 Oct 2017 02:21:28 -0400 Received: by mail-pg0-f68.google.com with SMTP id g6so13719871pgn.6 for ; Mon, 23 Oct 2017 23:21: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=fVNkswW2F9Q2QI2ZTaY0vlW/IrEbCVf8dY1cNKokZF4=; b=UHV7Hfa+CTTYKGAq7S74hXsMBMC9wc4A+IF3psUurs0mELG4np4WVnraFWw+916B5H ZqJ8ine0O/hnWtno6nSDkWok5lpCbQbLEuvwDSrfBa6nPAWpsuXzIDNwzB9y3uBaFsGm 9+YxFw+b5/UrMduzQ718eJk9x+dtsoOMyE230= 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=MxkLTMJegII11cePwGOhVGhBofV19aFJGQegQ5VBTzLys3kHtXcZs2o8/oZwnDJJkK di7Wi6yfLSbEzqBUc0LjMBiTwP8xXZYKlEwdtI5AE7TORlb03X6iGl0qrvUKSibenbUm fI6jYuc4UvWhtBpw9mEWdu1b/dzUMkJDQvIGzkhYkVdLwolaPma8pYjnjtI4K3S0ED3y AXhzpalb4LQ6phy4ZqWT5fSYSzc6GGjse2kjy1G7SI8QzseO9YHAfNQfx9xVWJpg6JL0 gKP+AGGnT+He0Vkkeytm5jof2QDxZ0N4/acIotse0g2dl8mALSyRIrY8rIN3eNoV5ouB 4cZw== X-Gm-Message-State: AMCzsaXRCKnv58layeKUpx9iHMYRkX4pnGsODoLktUWnxH8Ijtrc38rQ t3ONrjiY3sPs3atd4GSjgGrYd6+BgqU= X-Google-Smtp-Source: ABhQp+RIndR3eV23fIB5vregj0b/pJ7kpUXzQRjk29sV9lb4vhE8szABbMBedhOExmb6Ftp7qyQICA== X-Received: by 10.101.76.6 with SMTP id u6mr13752111pgq.93.1508826088274; Mon, 23 Oct 2017 23:21:28 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t25sm14836084pfh.67.2017.10.23.23.21.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 23:21: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 v6 01/10] include: pe.h: remove message[] from mz header definition Date: Tue, 24 Oct 2017 15:23:45 +0900 Message-Id: <20171024062354.22621-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171024062354.22621-1-takahiro.akashi@linaro.org> References: <20171024062354.22621-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 24 06:23:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 116891 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5451614qgn; Mon, 23 Oct 2017 23:21:46 -0700 (PDT) X-Received: by 10.99.179.5 with SMTP id i5mr13281304pgf.199.1508826106327; Mon, 23 Oct 2017 23:21:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508826106; cv=none; d=google.com; s=arc-20160816; b=nFTSw2po+WwvxskxtVT6OYQsozBShhDQBgCnjcKZZdAFuy+lwNHtoTWmCd8qWv8dKo mZ3O1uVddk2ji7BRw7vdDTQDSwYimDj36XDAT2Ia86HdRctwNpdUjuBBKzS8hbTFh2Hh bcHJySBBnjxHCCCAU4yCJJgmZorhcbrEIkKMEMC0WIKux25ryGbGQ5JNeuTvLmAJ03UO bDyfAXJhRxV+D6+4Ps3yL3xa+mnWBHiW9DRp2pwoJ7WrgyQULm962N+NZl+DR37dPFOQ qTZ0vP9zrtcqd5c1+jveWnZGH2Xzh3Y6kfY/v9JlNSZJFkkxSpOJ0lx/U509LMlZHyPT nAEA== 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=wQSztW4+hDNo5VvYEAWIqJvJgHq8OBhVaHybOs/n95QPPvBHnTBULL+T4KKDCNGPIr oQPd+41pt4+m2LIe+CfZcq7VsPpE9Nx9fluYZzBrP9+AqGoTqHkpXpLEcGyGBPVJYisv 1DPMBGPmdj1nQN4H5AJN70IgdlvLVSlc8zF3JnKiB1GDXkYEjkPQOx7airGzso7HbRGD XsqDusps25tfl1Mb5pObrNYa/PbMGTvw7ON4AvWNNTWSl8KayApz0fqRd48cVi2iuvpw KhGUCH76KomdIE0nPMfzXS6Bw1n2lK2Eaij35dtfvfWiAo+SHe9n79KT8iKTPgW1CBEt h4xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dTWW0y17; 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 k82si6521617pfg.374.2017.10.23.23.21.46; Mon, 23 Oct 2017 23:21:46 -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=dTWW0y17; 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 S1751751AbdJXGVo (ORCPT + 27 others); Tue, 24 Oct 2017 02:21:44 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:48645 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751546AbdJXGVk (ORCPT ); Tue, 24 Oct 2017 02:21:40 -0400 Received: by mail-pf0-f195.google.com with SMTP id b79so18950133pfk.5 for ; Mon, 23 Oct 2017 23:21:39 -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=dTWW0y17MbKiPffEyu5o1xonMuIgJsqiCZlO9T6r8rQZYihaMUfJuXr0ILc3PoVrS6 YV11j3QRO9g/ceM5To719AxvBkSFepXUgd11ugmLYNyXQY/2CMVs0WuUkNxDLyBDt5ll M8ti12s8orojszJOoOXzdChXGUdG0bQgnK21A= 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=DX3fkxr6EqAyWZ+lmeXZOXp6pmVdCkbfNZ6oi103+oj50s6KxMbD1vHJ0i58+RsysV V3RjWhL2o0whxy3xoB048U+U8cA9rxhN7sxZhnwoRY2oaKzXlr/U/99UGIXJ+cJWQzNk Z213wuPt7XbNUi7ZsE08mxkQGKAJzFMzTpwUUkTuxfnbMJaD6ahNshaff7yP97KaxcM2 xBtG0itR9Mc4VPO1EfGYJwEi7i3vyDgG0hVcfUT6TCTFfMLxXNPJIvyysUT2MknwhEXG yHchCI5J+jEo1vGUq1LWkF9GPTJ2PTtS9sWap3G9UJJyFzExptR4as7tWB3SVWMIEurY fScA== X-Gm-Message-State: AMCzsaUdMWJPubje+FCFIObuEsp9zCx63a1f2DFXC88gT6l2cS2rLE0W U6marTZ/WGWJxSE10q7fbS8WVA== X-Google-Smtp-Source: ABhQp+TeQn5EA+D3a1NrqZhI+UBb+CYOWSoX7f5SbkMMeswHYDSg1BUHiUYk/46flBoEiD+1arRIrg== X-Received: by 10.99.119.4 with SMTP id s4mr13624685pgc.377.1508826099592; Mon, 23 Oct 2017 23:21:39 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id u197sm17569500pgb.33.2017.10.23.23.21.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 23:21:38 -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 v6 02/10] resource: add walk_system_ram_res_rev() Date: Tue, 24 Oct 2017 15:23:46 +0900 Message-Id: <20171024062354.22621-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171024062354.22621-1-takahiro.akashi@linaro.org> References: <20171024062354.22621-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 24 06:23:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 116892 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5451792qgn; Mon, 23 Oct 2017 23:21:59 -0700 (PDT) X-Received: by 10.101.88.142 with SMTP id d14mr13503906pgu.36.1508826119843; Mon, 23 Oct 2017 23:21:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508826119; cv=none; d=google.com; s=arc-20160816; b=aMdrEkG4cT1iD2+vb5pJx+fQYC1HrwDSojnNgn9NP8K8gghfhsI4DmF0JO4nfRhr2p f8hKz846KKrNpbDDhdDFlLOaPQAGu3uZSXSeVf3nGDlnvm1U3DoqvgljQ6ZzNC9yZ49c WNdmSConkAnQPN8EyGpsBpbrOFHX18h8i+Hr2WQQzyWHeoDfhfigiykvqFyDQeUB/D5I FohxVLxTWVgTgp3jbGZiIoe0q8DeKqAILwB0ZHbV+h3L70q6AbR8vnod4Cz3rgBr0bkX 3paIj8j1DEzkiZViCCyo9+AgJnYfuftN5giRVydtNBFA2AKf7ViohC2nzpBa3NjpaG8E poTg== 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=MG0rvzg3UVcuuYMeHIaCFkT7JoPVFjnLYnkZQS9km60=; b=M2HlPbXEx+TltTXcx7sIOV+1p0f0NznLxVwVvce970znTN/OrSHSt4uXr/qSHnDUfe Jkj+k82Q8vyAu7SJsuNcmhXVsOqy2AhTlsxLz3XvRXG1U+ijYWE1Nn+/IY7fel16EeYx d9ja/rqDM4yafmXOULuOKCoH2rbwtXM7zxf48ZdTkhNE4J64mCvjL8pEYbRJpnFjX9Ww 8zH/mAAqzFM8SWi71ZGLyrHnQt1p0CvSc5zugb2KN9jLVztN9a5siI9JyNJ1CUqAkA5q WWqKrTgpWM+AwBuiAzYu4BRYn/Qo0x/Du90N2Sh3B25zJFEn1X0kRZEg6gANH80tptoY CH+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GkB4QHiy; 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 r26si6563548pfg.11.2017.10.23.23.21.59; Mon, 23 Oct 2017 23:21:59 -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=GkB4QHiy; 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 S932111AbdJXGV5 (ORCPT + 27 others); Tue, 24 Oct 2017 02:21:57 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:45449 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751766AbdJXGVx (ORCPT ); Tue, 24 Oct 2017 02:21:53 -0400 Received: by mail-pf0-f193.google.com with SMTP id d28so18942394pfe.2 for ; Mon, 23 Oct 2017 23:21:53 -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=MG0rvzg3UVcuuYMeHIaCFkT7JoPVFjnLYnkZQS9km60=; b=GkB4QHiyW+/mW6YO9zO0PWEP0QvhV5yJeSj1CIT8XPgI+2JbSK/7J5qBuZzWh+2O+J 6UmhqVPZAKTcHeilkrXHKY4nHzExIKyzNfALjkUgjNPA9GNkhsK9W0U1HxUO8olEypbB YTu2RpUlzknuR9y3Xq2dXmP/wR4TZ0Q9S1I84= 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=MG0rvzg3UVcuuYMeHIaCFkT7JoPVFjnLYnkZQS9km60=; b=aDYqlO5Qt0OLAwba90GmGpLIPUx6L2Fn5/fll4FVhsMsN4mitnRVuCJaKYHQ0JDODe idirOIlRNImHKGisbGlHViOY+K4VUjKGvMs4vYOiy92t9jUS4762W9f+V3jSbNmD+QVE j2FyoD0ekjPCM/BRuwXagzUfE3LXZus+JERsrNle4apK+ubO+HfsuzR4vk6etvUqWTAR 9o8lqA+ivTeyCMgnXlTvQC60FtJhp4u7vsZZ0mgn/bTSwhA9LK28uFhky6VMe3zO7vbD SQZxlKIv+9LLhGULvo92TOE7krngWaxSpTpJRhmcjv7JdN8yO/5ZxZvKheMDtkBddfT/ u0rA== X-Gm-Message-State: AMCzsaU4CWtdsiE24Y6ysoFdx+G0AncgUypd00MprvNY33lrJW+WzLTx pvuU+0A+R+jgUApFXg1kpj6A9g== X-Google-Smtp-Source: ABhQp+Sl+KqAvgPuV7cZQZamsCM6WM/jh8Zqv5DoxWVmJ6ucUn2auMtsbnP3NVN2Re5MkFHquwKL8A== X-Received: by 10.98.16.66 with SMTP id y63mr15079784pfi.192.1508826112662; Mon, 23 Oct 2017 23:21:52 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id q13sm12388589pgt.87.2017.10.23.23.21.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 23:21:51 -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 v6 03/10] kexec_file: factor out arch_kexec_kernel_*() from x86, powerpc Date: Tue, 24 Oct 2017 15:23:47 +0900 Message-Id: <20171024062354.22621-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171024062354.22621-1-takahiro.akashi@linaro.org> References: <20171024062354.22621-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 | 39 ++------------------ 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(+), 94 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..cd2a7671f5c6 100644 --- a/arch/powerpc/kernel/machine_kexec_file_64.c +++ b/arch/powerpc/kernel/machine_kexec_file_64.c @@ -31,52 +31,19 @@ #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, unsigned long buf_len) { - int i, ret = -ENOEXEC; - struct kexec_file_ops *fops; - /* We don't support crash kernels yet. */ 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..fd87be4e0576 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 * const *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 24 06:23:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 116893 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5451895qgn; Mon, 23 Oct 2017 23:22:08 -0700 (PDT) X-Received: by 10.84.192.37 with SMTP id b34mr11972010pld.221.1508826128317; Mon, 23 Oct 2017 23:22:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508826128; cv=none; d=google.com; s=arc-20160816; b=V6SUF3eY2HfqyEnIIsVGpxyVWE/ovsjVhlCBYIstbI6ZrUxzio9n+4smzHUbZQx5s9 e4PIK3s7w4dW+TSePoG0WmEQpELBNe9l9aMhzG82klieuL2mS2ujEao1T9ydi12N6xCd VXI8gRxmLubv54uanicS5yE2BDBwuCM2RG3/lDYEXZ+STySjgckLcfDeKiaN1RTNQT5O fqfkL9E83LzoHeb73Pd+AKvodSLRt3K5qE0UWysel07x6Gep3rvx6JLE1FYboRaQK/IM NDPzLdoW7ZnvaYsD2kqEYn8IqoTw300ynErOvkEOX3wXY8DLiDMVixytDkwUwg7eGHpg /Chg== 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=lZNB2j3/xS1pDejP3Ql1D+IJ4VoIF6xva+dNt/n9i90=; b=VOsgx1doLFbqLFeOGgqIwxH5/mW+k+i4+B3gNPZOT+LNKHbXAKuTLh4MlXvxqWGhi6 BMhLi6mwiDg5yx0X08jxc3GmgT7jiHK4dpcITQ8h0TDRDwpAWQ0AqDkIUY8rjTjCZ+vB zV07cm3GHImsfaW0dewLrNIopH2bUPEzkkJvskwuq6LkQYLeodEO8d0rxl5j4duD9EW3 Rm6lkc33rtAcKcm3/fUpGC+wuer9OlDeDTHJyA9FdX6RBuGH0dOB/+E7VM/BTGgwYbiA YxkOhxHGe4VbU1MdupiVALOVUqruPfr8U0MNkCRBom9+1ZqtPAw8HuF6Rz5DymhnenWc /dvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GYoYXVPM; 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 w26si2056016pfi.366.2017.10.23.23.22.08; Mon, 23 Oct 2017 23:22:08 -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=GYoYXVPM; 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 S1751810AbdJXGWF (ORCPT + 27 others); Tue, 24 Oct 2017 02:22:05 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:53270 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751766AbdJXGV6 (ORCPT ); Tue, 24 Oct 2017 02:21:58 -0400 Received: by mail-pf0-f196.google.com with SMTP id t188so18940191pfd.10 for ; Mon, 23 Oct 2017 23:21:58 -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=lZNB2j3/xS1pDejP3Ql1D+IJ4VoIF6xva+dNt/n9i90=; b=GYoYXVPM14J+wu9TGBlq2NQ/7pZlv9rmPCC9iw9mus/qPY8IPw0hzoXxffNc+7lnzv oBNfUyZMAcCYk0nBOz8RaODBFlEVyXXRloEynUYs8Ry2ii4qM1/Fk5tR4WKCL6MOV9TH SgGnsJnkO4GvXvxCEK+8r3G89IDpD4Ua/6byg= 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=lZNB2j3/xS1pDejP3Ql1D+IJ4VoIF6xva+dNt/n9i90=; b=SgzeNG+5G+WrH6BZU96b06+A9R1tU41UoK/usvdiSc119u6SWD9r3GfPpR+ca22NTr F3jgF3+5A63gaGROYPMZ5pZ+zBagYUtiLZkngKeP3/rWdQmLFurr1BfeEUYDPRl1GdZ/ W3vDHktIOYTVpFptZBvGeHAvk7o68iWbwrBDqL/nr7TswHq9waXtOmeQWzGiTU6nFtNK yp4+La7auq+iL5QWq1+4QwomRpr3n0CYJe8rZ8UdvxhwTNSCMADuyIafUbi2jY4AqiU9 fytc8zkJ6/BWbk4cJyLLkR9/WjnZrdLdGsR6Lt1Gc9C8q0bLP5/OoNpRbQjHOwZkubt4 UodA== X-Gm-Message-State: AMCzsaXQcL/8InPE6vS5z0tkJ6riDvWZqwHFgG8n9KRZ/UCdsPCrWcEN NV4S+FcI85VbTzd4qy6MoA283Q== X-Google-Smtp-Source: ABhQp+Tl93qerPdFA/BjFkcTU4lfYaxpjwrSGlPLcwdIp+FNLkZc5mpTC6mLgqNpFKX0GfiI6JXyfw== X-Received: by 10.99.123.83 with SMTP id k19mr13651412pgn.338.1508826117765; Mon, 23 Oct 2017 23:21:57 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id e18sm14855623pfi.57.2017.10.23.23.21.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 23:21:57 -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 v6 04/10] kexec_file: factor out crashdump elf header function from x86 Date: Tue, 24 Oct 2017 15:23:48 +0900 Message-Id: <20171024062354.22621-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171024062354.22621-1-takahiro.akashi@linaro.org> References: <20171024062354.22621-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 fd87be4e0576..e3960ad5886d 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 24 06:23:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 116894 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5451921qgn; Mon, 23 Oct 2017 23:22:10 -0700 (PDT) X-Received: by 10.84.240.6 with SMTP id y6mr11859331plk.78.1508826129969; Mon, 23 Oct 2017 23:22:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508826129; cv=none; d=google.com; s=arc-20160816; b=wI8MR+CAS+h1gvvAwTlsoDp48H9wPOCPwKDDDfyKV9zGnCuM1q3wyNLj3KI4TAmWTC 33FzHlrSi4RugpCrR5r3pyytKaVbsfy78jqcb/3jk4ITA38er8/1NPXd2+fw3PZfpRIi OGNeH2QY2/FChQws7ledOMokSS0mNlispXP5lxWPGcJslgmN2fS52cnQTxG41kNRWEw1 nFDvm9ht8ik0UM0FZe4bltQQP6gNlEUzKhC7YTTFKxO5YtWHyAKn2uRL5nZJaXANHghS 66z7JyVLRoUl5VO2CQeufWohQGta+mrumiyz8X2qAzEkOp5vw49sHTxCfYh3OFNBHuwj 7kLQ== 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=PAYANYDUMGNEbHRDumKtAPkP2MsZyBjJWkes1vgNXiJ+KQB8Ehs+EtAstapuBgnvTv Tz8jCjbe/cMmztjPS0adN0iKSE534BV3oZZvK7U0Ff7DBW8+tAaoVSeeKkMw9fgVZeWr ZNG8OWk2QIwWgCOXnn+fsgACeqJDYOGbHBftsDGSAI3XSQWo7fLxQktdqzNbixkcVOEd DgzfOR8sy7jzNkBNEfbZBCCEXoFWlhJRFwF//M4DAG0hrF0XLlLA1omiXa0blZVmNytf BEvjeOKoQYJx99eNrVH3CrE0sMw1I9+7HTim8i+vApwUWs0ZMtBQFep0b65AstHRt2Tn T8Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Tl0P4m5R; 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 w26si2056016pfi.366.2017.10.23.23.22.09; Mon, 23 Oct 2017 23:22:09 -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=Tl0P4m5R; 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 S932175AbdJXGWI (ORCPT + 27 others); Tue, 24 Oct 2017 02:22:08 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:56146 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751793AbdJXGWE (ORCPT ); Tue, 24 Oct 2017 02:22:04 -0400 Received: by mail-pg0-f67.google.com with SMTP id 15so9030397pgc.12 for ; Mon, 23 Oct 2017 23:22:04 -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=Tl0P4m5RE3LlhcSms2HevI28dC1hlWqNOt3VwYd4TFRiDC5tcnMgRurzKX6B1soKxA jLH7aR7+WpbuJRWPUSPyDmZ0NTiEFxU4C5eUi5NZO0X3E4aVG5GHlfyfILl4q8zcwd3R CuvCuJhd88h1Jn1rWb3ggSX5wT2tstReBUp2s= 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=pa2BJ7TKbnGAkaPY/GOXvl3U5t2Tr4h+XL7tpdC7D7eHr6BmLOK1+FH5DMqB1YItcM 5Z/q7fb69Bu2/Dvb2U30I1LnM9mYMjhNa44Ru5BWNufK95+nRVaQku6P1aadvrNYwvA+ SLjiU/mnMOgRrTB9JEfaG1ADTOtKCzuYDo3Z7c+9vnCOzkTVUvQQGxwjXZ+GMUH1emoa yHKt2OFtQYVqTsEWvzdby4MMrxr92KSCChavvQVKgeua8Fz9KONYfrdBqJ5X3r3BaZu2 opqP2BYPTOHxNQzrHuiPFxfSJ5HvAsM2npoH9tuEEaeTrEn2Jlw3D8Qe6Y7jg3F3x4LQ Ie7w== X-Gm-Message-State: AMCzsaVB5yHF1d5/iyLGP7GG/vdIKIPQf0gMdwV2Ep3cwbnNuj9KL8ru +rq5eiAuVwkFjueCA/jK5X6HRg== X-Google-Smtp-Source: ABhQp+QPtvUERkJ4VtfEeYzrTjyurQcrq5SAjhjNEh9r2cwzVpolu9BhePtC6nnWgp764MrTYOelAw== X-Received: by 10.98.212.91 with SMTP id u27mr12131699pfl.201.1508826123708; Mon, 23 Oct 2017 23:22:03 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id z8sm16231219pfl.135.2017.10.23.23.22.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 23:22:02 -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 v6 05/10] asm-generic: add kexec_file_load system call to unistd.h Date: Tue, 24 Oct 2017 15:23:49 +0900 Message-Id: <20171024062354.22621-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171024062354.22621-1-takahiro.akashi@linaro.org> References: <20171024062354.22621-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 24 06:23:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 116895 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5452056qgn; Mon, 23 Oct 2017 23:22:19 -0700 (PDT) X-Received: by 10.101.82.129 with SMTP id y1mr13990654pgp.137.1508826139569; Mon, 23 Oct 2017 23:22:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508826139; cv=none; d=google.com; s=arc-20160816; b=laN4dEKD0/jMZdMpjg2zxoIcoMJnJXTv+frkfGuKUabsqDNpL0Ah3NU/OTrqFuS12z UnC5C8IjKVS7RW8c0aS8JWOPGIocBCf/+c6VYg0/N04+gM3CP8qYbEzEIYX8lYyS+aFz uDuhyPiCt1/ZEd5EmMkmWkp+qhTJNXBZzyJERH7e/XEVKM+VbWzJY/X0tWz7YrIxpcdY qp7euNcKVqCfaLUS9T0O4/mJG/sC0gy22zAK1ijt2wLTLjh66Axr0F0m/iqUBcPDIsHW VBm+RZaGURJAhwBW+VmcbOXysAXRpAEb42EgNthUG8W73KWfqZdO7WxBBryPBxU2Qqyz qxCw== 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=Cl2bSvhfUab/MaZ9GJMkQjDpew9Nvt8LbXEhjt6fbpx6wpJMeJxF70/mzRfRujtvvZ e2LQqRd6Q0vu/h4a4/HhVQDhMihIEnXkcNJh052QoMOu94bYF7BKAnjfNXGiG1rHaV9i +Yp7P1lKdOaZ9NNaByWLR440um2Hl1n0KDp85dJDGW1OCZCn+hAy/RD0PXvZBT++ukYz YCw4B9UbM/UnU0mobirYHhkNPMe3uqPuvwMmOSW+jsFAfKMEq2C9OY/FX5eMBB49jTjz uyV2kvIQwQck/AfbWrzzi1rrbSkHOUIdGk7N4/lzJLki+YoYo3ChjGiat0DpGzdLMKuR pniQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XhkNVxJX; 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 9si6529013pfw.188.2017.10.23.23.22.19; Mon, 23 Oct 2017 23:22:19 -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=XhkNVxJX; 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 S932199AbdJXGWQ (ORCPT + 27 others); Tue, 24 Oct 2017 02:22:16 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:57334 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932176AbdJXGWJ (ORCPT ); Tue, 24 Oct 2017 02:22:09 -0400 Received: by mail-pg0-f65.google.com with SMTP id m18so13704662pgd.13 for ; Mon, 23 Oct 2017 23:22:08 -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=XhkNVxJX6OGyKQSDRfzpCTd5UAC+/mOAyYubQv28Q5h3QYenh+EWLvSOQNNDA1BNDX TbJCeaECtCO2aehrquPD0Gznuv5LIewLtZTwq3PdjTdf+XFfxUft2brutJlfKW/SouIS zGqG63ZzxrQa38ppE7nLH7Q7H+GSHD6eIspHA= 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=HUpO1yeVyhwtM3rQr+cKDkkvmt7u9UXJ/SnKn2Zv8lPsnHhZpcjid7zMrWZNpKAtY3 6ZYR7gu2opP5Leq7lKj6Zu/UmzgHtGTG3qrf1fdHOYUK6qnAra0Op8YUL7dS2k6bY2bS DPpX/Bxt3OndHAt+4oMle/ihdeUBHGR9cEWJl1yDC1TCXxcZ/dK/cC3oldy0FnbBWvH7 6PKHt1e+pcbGyrxTYOc4bHzyBnuKGBfmEU6XAhts6kTDpilIZbuq7bC9ghpBcoeMxG0v uqkvvXME7PYbdhND9+qWnpWBq1n7HeyDBTHbWMPg7Skc0iNMeI4/6uVAwjW8PaGI+Bkn lR9A== X-Gm-Message-State: AMCzsaVQYWcBrmVkSOwDU6f5/su5RlQnNUtdY1+6uDRxZ12FDLIOTrQl Mi8v++IRhlgPF6g2OWdQFIgwGg== X-Google-Smtp-Source: ABhQp+QTiQkyKVdXdgmlWjeMX4zBlvO0K+gW9zGtUrglMVNnpL71ee+Ac9tGN34BhAy/OkbDkQTUqA== X-Received: by 10.99.161.17 with SMTP id b17mr13740525pgf.292.1508826127494; Mon, 23 Oct 2017 23:22:07 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 9sm13409636pgg.42.2017.10.23.23.22.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 23:22:06 -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 v6 06/10] arm64: kexec_file: create purgatory Date: Tue, 24 Oct 2017 15:23:50 +0900 Message-Id: <20171024062354.22621-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171024062354.22621-1-takahiro.akashi@linaro.org> References: <20171024062354.22621-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 24 06:23:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 116899 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5452620qgn; Mon, 23 Oct 2017 23:23:12 -0700 (PDT) X-Received: by 10.98.65.27 with SMTP id o27mr15666973pfa.327.1508826192741; Mon, 23 Oct 2017 23:23:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508826192; cv=none; d=google.com; s=arc-20160816; b=fGE+Vb8Tb+BkTrI+PHe+GhGSkbVqVdYnz269RH/2Kebclxlh2hrWbH9b1QVwKSoHvA zfQtK6j+VXC4JWO3EW3I/gqhKUI/sWy2Bpdkzcf4Y+cd1PcY5w+pE+tZI1HE+tC6LgzS cpglSGVZRlU9WZZC1sKdsGvXbvo1agrejBTWTAl3BSuUU7rkNWcirzzvlpyjTVeRByij QS90EiX3p3Qk2COIfOEBtZd88D1yLRejfDT/0A5VD3dM45V6X8YD9aA79x27B5rDFvRE m/r+Jn5+skfjp8UKX3d2ObzH34i3hvaroFETVxmVvQRRLMqZwloxjJMAp/sHOk+rZ+gS jg0w== 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=x6cl0n3wYLele3BpUujoQRSDRp4Sh1YQsYgGMGz1bTg69y1Y0bz9wijgOw9dG2g4ov 7jzoU3lZgcqbzqVD6ml3hek6BcZDX/hl1XPjstoSXWJhsMOq9Vj4irajWyTW5Sk17VIu 4NQFMMFOvKoNhfk+/U7gbWX71Bx+rfYKXmE0HLGc7l6mjQYpeyCVmj0wJGsWKdOVZeuV JcxXGRNEShvFURds9chvD8wnRs7HSwN7K/qiOwT4S01yHvbx3uIdljh2myB9ej0aGplO Ex6Y+sTTHd/To57fP/4mHHVmNFQWfCWPqBIuJ4j/A7r6FibvqKvUbjB0rQt9b+hvUqdv VN8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eeSwUGau; 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 l6si6000209pgn.429.2017.10.23.23.23.12; Mon, 23 Oct 2017 23:23:12 -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=eeSwUGau; 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 S1751746AbdJXGXK (ORCPT + 27 others); Tue, 24 Oct 2017 02:23:10 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:43744 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932177AbdJXGWL (ORCPT ); Tue, 24 Oct 2017 02:22:11 -0400 Received: by mail-pg0-f68.google.com with SMTP id s75so13711423pgs.0 for ; Mon, 23 Oct 2017 23:22:11 -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=eeSwUGauJwdlbjZDjI6qvSU7yxdKBQlGVxgvzjoIICts3+wQep+qtDOJOeF7scfPLI 9Q2+At9G1m5s57acBJmtYLs9zJiIB9LMokiV5GL9YvVFYrng5xkUBfa/u0BXEZoj9aWf rZQMhoddx08YGARaZ7aiIxmq8WZwqjwr8IIKo= 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=lSj3iT60MNCnRzsP4ryOII+LAhPzi7gh1fF9F2saaRX7go0QRW35Elw3rC4qt68eFR Z6M5WByqACNS/D/xoXCB+YQHXDyx+UFwU0k/Z5o5+BG6Q6NhjPRv9reVoH90PsxGKYoM V/+HviWBgXuaz0ojMK2GKKNYhLF0CZgG/RKVQDQDLo/SX1+btTZ8ECPZoq/zcco7pQl4 wU04Ij5qcgKYq5xD56ojJdaC99uV39DRC1BXHw2QQmZBY48dX9gSqBg/kMWRiYvrH2xv s0VF2iPNu8a1f3FThy/Jg+qJbPmu2YPJZ2pAlLgdSHZ6Hx+dNV7CZvbZXKpfpl4EjMFt fCMQ== X-Gm-Message-State: AMCzsaWOFdVMFCQ+egHFuOf3z7EdbSEPO6T47uQJBQ5G+eosPIJA5Na8 v4DelZhidbSssi/622Wf66NWwg== X-Google-Smtp-Source: ABhQp+SWp+tN9NgivVY1+ag3s+q5BGWA6UnGUSCZ3h5d/vLaaW/PtF42ZCFXgCiK8Fy/hwsjmdDdMw== X-Received: by 10.99.154.66 with SMTP id e2mr13818401pgo.116.1508826130923; Mon, 23 Oct 2017 23:22:10 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id c9sm16617653pfj.76.2017.10.23.23.22.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 23:22:10 -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 v6 07/10] arm64: kexec_file: load initrd, device-tree and purgatory segments Date: Tue, 24 Oct 2017 15:23:51 +0900 Message-Id: <20171024062354.22621-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171024062354.22621-1-takahiro.akashi@linaro.org> References: <20171024062354.22621-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 24 06:23:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 116896 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5452099qgn; Mon, 23 Oct 2017 23:22:24 -0700 (PDT) X-Received: by 10.98.7.85 with SMTP id b82mr15520939pfd.262.1508826144433; Mon, 23 Oct 2017 23:22:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508826144; cv=none; d=google.com; s=arc-20160816; b=gYP6zXpCByxQVgyevUj+VOnxWRn4LxQq4jqtLIW4DNHro4QsmTFw9rHNHRiPxPSHUd TmDb9BlDbKQfPwnsw5tcDk68w1y3dcHRz1yFAJsitbZBkQgKELoiDUWv43ixZ4HI/efJ hBxeq8DGI66KxpwusZ8WAI7+R9M2pN8jiFF+bnB2TVzLKdqdgZ81HImYnRbAAbWQM1HF LXFTckfvnyAirAqxdpy0s1QEAP5aAs15Pryf9HCObCnX/KpglCDjeBYxsdA0olDavF/L mBIAONApeXrY4mYd8qnbbc6M7mwxPSu8a04QSS0YUl26Ud3+bFPbf8JvQVqWh/E7ZG2m lQuw== 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=NNRnUj0GxFuF8Fiv3BgzjSz68tsXjQybjQ7xPXkCO/0=; b=nLoIxyiQ2GUqmphOTkw+T+e3jZvZoEh4vlm9QWuBlZ0CeGslQDQIQVZUilpciaWmaQ VGHB2WAwiN8eKBSJl/YP2GH5oJ7qcB1IjIq2cdZQnxJF7+Yy8lb51hU3iwZ4A9FnhXjM 8krzz3/wfrdyuriu5tETQp3rL646GP9ibNqiCMJOc5fsCjAEqv3MElsR114psjWW9Adt eBRJsDsVpTfPRoU2bnxstXy/pUhBY6JQO/rtIi7n5NFqPFS8x7rG2sqKRgNzVyro1lj2 NZ4hkW3ZpTxEdgJzsh+psZfCt5nmi8CRGDADqYMkopVvR35GKaNouvE6GsMYIDZsO4bI ne+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D/8iEP5C; 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 z3si5039005plb.116.2017.10.23.23.22.24; Mon, 23 Oct 2017 23:22: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=D/8iEP5C; 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 S932227AbdJXGWW (ORCPT + 27 others); Tue, 24 Oct 2017 02:22:22 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:54416 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932195AbdJXGWP (ORCPT ); Tue, 24 Oct 2017 02:22:15 -0400 Received: by mail-pg0-f65.google.com with SMTP id l24so13706910pgu.11 for ; Mon, 23 Oct 2017 23:22:15 -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=NNRnUj0GxFuF8Fiv3BgzjSz68tsXjQybjQ7xPXkCO/0=; b=D/8iEP5C4riUgg1oKHYTroHfVcw67JRG5UUSX0GxWt3WIGoEiSNofO1CseEloqQeUK 6JeG3AbUyhjkzHHT2883ANwTiG8WH1XdWhjRdqBlqNBL4w73i/VTOjS5tnK+Iv/MdrJb zP3+RcptSm/ws2uY/hcxyU4HRzPnGZPyhlQE4= 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=NNRnUj0GxFuF8Fiv3BgzjSz68tsXjQybjQ7xPXkCO/0=; b=lFjdFXOBA06YVlrIo6KrY5o4obmDd/lVOBOxPGbXVF9kNpVnz49Z3IXJi5PnEkJka/ JOLeIRvjJkua3GBpWImZHI85+IJcdTKLoiR4k3RVTpXezGvH62fAy1PNxGVPBDh/M6Ig NuVC2kPYvGvDf0u1z52b3Hy8mN+GgI/DaE1OMl+H/aU0i7gfibayGOSr+lAwPUuIDNIS TURUUD61zWJUROkt4g2Dx/TDq/bNs8NTOPyXQzLsBt7xrrKxZxh1o9kh854mcQcuI/5h CgSJz2fr2RitFb+nvMf0dUe6LofcvfcwN3ZRuDE1TEKpBjhdqli29EyChnywL//wcblx MlHg== X-Gm-Message-State: AMCzsaX2vEXsTeX/Daeg4B46Xxyb6PaQ/KDHdrNO9lA04e/GS+0+twI2 YH41x7iYSJP6SS6BA4PN5hKhcQ== X-Google-Smtp-Source: ABhQp+Rol+yWG/qsGROM03M+LDXXPB771N9YSZbR/vrh1kX0Pk6VQgyAh2U+vtmkg5A96zRH5SD2Vg== X-Received: by 10.159.253.147 with SMTP id q19mr9271814pls.54.1508826135210; Mon, 23 Oct 2017 23:22:15 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id k3sm16640403pfc.44.2017.10.23.23.22.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 23:22:14 -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 v6 08/10] arm64: kexec_file: set up for crash dump adding elf core header Date: Tue, 24 Oct 2017 15:23:52 +0900 Message-Id: <20171024062354.22621-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171024062354.22621-1-takahiro.akashi@linaro.org> References: <20171024062354.22621-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 e3960ad5886d..a745027876be 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 24 06:23:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 116898 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5452372qgn; Mon, 23 Oct 2017 23:22:51 -0700 (PDT) X-Received: by 10.99.109.14 with SMTP id i14mr14186661pgc.355.1508826171247; Mon, 23 Oct 2017 23:22:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508826171; cv=none; d=google.com; s=arc-20160816; b=ICo/zb1beU266EGGM22wj3SftP++BGvTT1SYa2N6JmIw2oq2cu2+KuxqgoctZ1buv8 EHW9qSOOiIH0EFCCqu8phGP6NmppwHQNyNFyPbi0+oWg0+nIZ9d/wJZT5JlSDnQQ8AMC 3JbVLkT9WS5aXilRB0/B1FtYn6ToB9yRVmoOdUUVJWYPgTS1VXAE4trcPLWdr4PtcQv/ uDJMw98PsQGC0OtRNwVHv9vReEi/Rx8/M3zste53ajMtPadeI1iPKkD9doW7cJ6BrU0T WCBpXBLx4fhNZjGRGI5cdYQjetq2AZTEaYTguZrtMtFX10jFyOwQEXxVposfepl3+Y6L QCwQ== 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=RSOPKrnwZQUp23GGxKdfE5Ro5wKjTYCGPMeVxwKAZ5t7jMCQNa4OqbCK1Qorz/Y4d/ rjECXzm9WS5RM5aaAJGcmjHqe5LAjBF0Y8VuoUik/g/B7JNef0KlyzHUtgIQKjOzPyuo mfYNjZvyP75KNX2nJs/mrRaoUpbipEfCJVKPthegGUuj9jWYY5urQLQHycaWUnafZTxG k4QY6uXQc9RHR8Hswt51IcGgXkPszecDVdSZxV8hbYNyqOeRcjg64S/Jk+dMQsh4vgDv aBAFPqkBEgWK6mlyOqBb+k+w0hEsni8TM6h8OSJ3D5pZveBQ14Ubi/+HKKuWgwbTUJGr yXhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jp+/AazU; 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 w9si6512516pfk.551.2017.10.23.23.22.51; Mon, 23 Oct 2017 23:22:51 -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=jp+/AazU; 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 S932236AbdJXGWt (ORCPT + 27 others); Tue, 24 Oct 2017 02:22:49 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:53664 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932204AbdJXGWT (ORCPT ); Tue, 24 Oct 2017 02:22:19 -0400 Received: by mail-pg0-f68.google.com with SMTP id s2so13708575pge.10 for ; Mon, 23 Oct 2017 23:22:19 -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=jp+/AazUtsdj68N9nrgtVuFNLe1DiP3kM9NBPwwfnvHQ39SQJ9fzq5oEOuX6kBRGIO 8xkEMC4rt6dN3diKrtIGh7ZatntQQaxkp4UaKhsU6gaDt7DBgE5sKZ3Xo0eGtfifuQlw PMbJXaapkwqLVlPCOqaB8N+wGPy8SDg2m47Gc= 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=d9pvABRbZ6uG793l2YmI605DiCm4dBMtn8WbEmiAkWNf8ajG/yfiJO+a6ngQa4vpCq qd1AeONciY0r4XSfC7NW0qnGc/NvNwXZDbSbyckU7ujyb9QnKvF3tC03wfg3/1Qc3+Dv zVCun97VnYb6pD+9eNj9EpWt2rRiv7DBkuZK60Quc/S38t60MSpsGZs+0PWTO317osX/ AWZCddg/WhuuqjyknlD3V4SnVc5U5nyJtiZ4k6L7s5lzOXxxF8+zZMMe9UxMe5PfU2dm Pwofbxc/pUqntCeZYanZs6zkk4ziaifWxEx1wj/2dBvgVSWZRqh7F9mVvdnx2trd+ZKN Ehpg== X-Gm-Message-State: AMCzsaXcLYJNPOqSC0YZfyy+KoWxqQVrwR8A7KHrZKUQTfwzTfA5Ue94 NOeR7tlBxigGCzHJVMcO5Nkx/Q== X-Google-Smtp-Source: ABhQp+QVZFpb8/RYXA5DuYn3rNbdwP+zGjEYDnkhKL/NNcXfgjxilrTRHn2B7XBg4glUf2DWb7F+1g== X-Received: by 10.98.14.195 with SMTP id 64mr15347518pfo.197.1508826139275; Mon, 23 Oct 2017 23:22:19 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id g5sm13017821pgq.94.2017.10.23.23.22.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 23:22:18 -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 v6 09/10] arm64: enable KEXEC_FILE config Date: Tue, 24 Oct 2017 15:23:53 +0900 Message-Id: <20171024062354.22621-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171024062354.22621-1-takahiro.akashi@linaro.org> References: <20171024062354.22621-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 24 06:23:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 116897 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5452191qgn; Mon, 23 Oct 2017 23:22:33 -0700 (PDT) X-Received: by 10.98.74.149 with SMTP id c21mr15365023pfj.200.1508826153093; Mon, 23 Oct 2017 23:22:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508826153; cv=none; d=google.com; s=arc-20160816; b=A1ZOLwV5L1ZZ5rNMDJtKCtGV80hpw19bkBVrwRTYUFGnQZXnp7OSqX+p9hygYn5+da yqDo2ZT+LoPnvNJj6+YO8+9JzvV+0Ycxp6PBa+nDOPMZlAv7Bqa0XErFMkG2yuYY3CVG CenxkxnsXFXKmyOWbfRBWd21rhjFzccyffcqqmnj4SveAhZJ/XEu1uXi9fFVOPviJPtV ApF7XPjhrHXtKPiyfJiXLUtKI+oNXuTa6nE1Me1M/5XUAtSzoP+azabLE/mh0ckrVoix lp9MCDMPNGfeM27Z2oj5ZkHBY+qPNdBtrBp2GTXqExPjS7t5KP+DHobjZaksilKWktkL Jssg== 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=Yd1/qv0IQ0Ed+X5UcvtRUhvaD0dEwFVbDiW2Zgz7gHQJnGnSL9J6rgJCSaemPQrkvA ksgz+EEPWNLUPDnG9G0+I8sUsX5ux6B2M5O68S1PJR5U8hytKpvobmYtwDRvbAEecAnd LQ0r27ehsczyAJ4fGjZ1wjpiSkLIRPkCwK85ZCA6Ju3NkPA69cMCIWkwm5ESmq37ochC rLb/stijzqhAGHpy5FsbgUOMhmUMz6/UUa3w48Yjx95dnS0L/F8WeB89V6JtYwdnNwPv mOcQhvjWAcH9H6vsiuxEzXFNBpzfIhbvjLszWee39mew8mHYVLSBp1Bn2ZC/DqRNp79t He+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ByULKX+W; 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 w2si4990037plz.643.2017.10.23.23.22.32; Mon, 23 Oct 2017 23:22:33 -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=ByULKX+W; 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 S1751826AbdJXGW3 (ORCPT + 27 others); Tue, 24 Oct 2017 02:22:29 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:48705 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932195AbdJXGWY (ORCPT ); Tue, 24 Oct 2017 02:22:24 -0400 Received: by mail-pf0-f194.google.com with SMTP id b79so18951302pfk.5 for ; Mon, 23 Oct 2017 23:22:24 -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=ByULKX+W/Vo7CsEBHs6DlyIu7abO1frOwqVNm2lk7yZ7flnTKJ121QXHPFwDbGbE7b Pbd3Ufd72n/XHVG+9dnNbdBjEsa+JqbNzZ7Tbtr0PrrfeBB6XPpTAcDkzrkTu8DdCnhU E208R++kc4SxWyQNzBWOLXgS4mIEIjCBJmgNY= 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=INyL+2xg5iD5n1YKc31k962naTjYH1Lzj2T867zXTOy71k862c4r4/oFSs+A0iUXrK IGb0MABuCzIkGt2anN7XTtPP1WY+h+h0Df6xX2OurrTsu0wGMT8vH83A0ydc4LuAhHnw wl8FV/6vMAO9SZ7c0aZVi8LvVhy4DXJORPg2gwldbMuZett0uwXyNZLSAg3AKiYbBPCL 20VD0oX+84cHFz8GT4s2qqoszDH38I8eG/tKJqTrgFKn/xmaCdjiUsbz3b0Txcdw/mYm tiBY30hCf/TKG0U8XlcoO5jhd5BupBvoUe/Xr41/9SWFUYsVQ1o9uCe6BXd+LffzLZNy xM7A== X-Gm-Message-State: AMCzsaW1ID5AYapold7XUu3QMLlHtKtIL1kC5ttpHy0+7l+hF7YXNdO7 fGEOK+NVKJFQb+HGbIqxoaHgkQ== X-Google-Smtp-Source: ABhQp+Q7k3M1l0BF646YZPE4NpAkMaOSsLcnOemTM26Wu0RKyupsCAgNc3Up2PBRb9STy4fkgRHQ7Q== X-Received: by 10.99.96.208 with SMTP id u199mr14132646pgb.323.1508826143346; Mon, 23 Oct 2017 23:22:23 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id a78sm15943548pfl.122.2017.10.23.23.22.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 23:22:22 -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 v6 10/10] arm64: kexec_file: add Image format support Date: Tue, 24 Oct 2017 15:23:54 +0900 Message-Id: <20171024062354.22621-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171024062354.22621-1-takahiro.akashi@linaro.org> References: <20171024062354.22621-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 };