From patchwork Tue Oct 10 06:36:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 115348 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3400933qgn; Mon, 9 Oct 2017 23:34:45 -0700 (PDT) X-Received: by 10.99.103.68 with SMTP id b65mr11599832pgc.271.1507617285530; Mon, 09 Oct 2017 23:34:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507617285; cv=none; d=google.com; s=arc-20160816; b=RSAubHrTgvfDM1FrGiRC2nQuwKhyPbfMViYsZypCagfjA1HnbX00gqpBnNzkXkwYt/ ODrarUGQay9GP4+T4b8Un48EAFMcg5a/Y/cfknDs3xbjl2gK7nlorXr4lfC2LJhVE5rC 5I3Nb/rM2hwZUfTOjm/9i38gpqoM/bufneTNxcpyuY8V04Wam7bqNJiBUXrucVRbsyn4 FDH/8+2xgurjMdfFw/9lW/4jS/Q2OVwqtYv3D+TvitCEBEv+JJKD1ZPxJCYMecSy1IO5 5GfufctydgWO4FK7nQPwNjDGhOu7XPJYY9rYaSEGxRmQMezVYaYQOJhhXCzmHYs/6uN3 +Lsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=tM1XorSCFhcfZLu68xxa5woEGXd4bamOftf2C9pmX4Y=; b=mkrtul+v4X+bTUC4QcHB2usjf1U8bOvWmvMckrd4TXN4NpFwWNrf8qnFXoplLJSjhU K//ia5eoaNIASp1y2lLU3q1jLEQVF01L8i0noJoYa6iqsOLtJVrqdOf2Kn1FwVhyIXk1 zKSLcJrQ8YcfYuUBH8idHMFktebcVHPz1IwdDO21IqS2j1EF8dmc0lAFAyv1Vgcnz2TC NFphBib5zdBSN/kuVeuNUm3RwuyWCIUFn69w4RYhvct5Xt1jeRDgZVDkZRho9FO8N6hV CefA2Qs+bbMt2BtChUKs+CXjE/kL3sFIeBFsBV8GB8q8XkPu1rbDVRyRDJFx2gKPI+ha Yw3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QwqL8mYp; 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 m12si1231116plt.65.2017.10.09.23.34.45; Mon, 09 Oct 2017 23:34:45 -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=QwqL8mYp; 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 S1752305AbdJJGen (ORCPT + 26 others); Tue, 10 Oct 2017 02:34:43 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:47911 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751810AbdJJGem (ORCPT ); Tue, 10 Oct 2017 02:34:42 -0400 Received: by mail-pf0-f177.google.com with SMTP id z11so6298864pfk.4 for ; Mon, 09 Oct 2017 23:34:41 -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; bh=tM1XorSCFhcfZLu68xxa5woEGXd4bamOftf2C9pmX4Y=; b=QwqL8mYp9BqPW5m0Yq062bDd5SJ4UCM2/k4NRVWe7lU6vxDQu0t8zU5Nd1Jq4zckZi 0pB1LADRoDLj1nCqRvSLcJHohymMrQvZs96/DMoRR+9f3wKl7/vFuNi1BSYGqFRvI2sb hywbOetZ/MTauePsCwuz4T5HPe7M31eeLwS68= 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; bh=tM1XorSCFhcfZLu68xxa5woEGXd4bamOftf2C9pmX4Y=; b=NChvQDibAjwX3KvDUXaSzXDc+sLr2Ddg8uDOYPoJQQupeVAWco5r9tb353VAD5IJ0h n5Wt7/JcFMXGh9Ns/Xd/dRaKnEPX7MD2BnZWHNf/q9k+Wg7AIFURuFad52vqAX1C9X17 BKCzCvCoS6tZvr11PVzyg/Fp9WVLLjq4+/gw0pDLGOTWw+xG/YaxQhOkLUdt43w3pVYQ oliRU2vTyacAIfQa4OoCeMuHEU77NbXmZz6oSdNLJ1hto5YB3egZvuugvgixNMiieCFK qzhifhiLhuJwSruJ0iUysoYOJpG5BC4oK9qI/k0nQswTxFFql3UqpiCta7H+DCXx7P9w HBmQ== X-Gm-Message-State: AMCzsaVdgVhqUllSWATHUq59VKg9AYIWspd9AQ3uWbZMIVkL6hZLL26W ZmoaKOORsZQVYHypTqFDAIoqag== X-Google-Smtp-Source: AOwi7QByegSRInAB7pRH2P6pWghI6v71l/K8FyV2/+Tu/eDO6ZJMJBCkMn7EBz8x2uFVaPYK1iresQ== X-Received: by 10.99.116.25 with SMTP id p25mr11014349pgc.26.1507617281392; Mon, 09 Oct 2017 23:34:41 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id b3sm1886752pgr.81.2017.10.09.23.34.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Oct 2017 23:34:40 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, julien.thierry@arm.com Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v5 00/10] arm64: kexec: add kexec_file_load() support Date: Tue, 10 Oct 2017 15:36:09 +0900 Message-Id: <20171010063619.6303-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is the fifth round of implementing kexec_file_load() support on arm64.[1] Most of the code is based on kexec-tools (along with some kernel code from x86, which also came from kexec-tools). This patch series enables us to * load the kernel, Image, with kexec_file_load system call, and * optionally verify its signature at load time for trusted boot. To load the kernel via kexec_file_load system call, a small change is also needed to kexec-tools. See [2]. This enables '-s' option. As we discussed a long time ago, users may not be allowed to specify device-tree file of the 2nd kernel explicitly with kexec-tools, hence re-using the blob of the first kernel. Regarding a signing method, we conform with x86 (or rather Microsoft?) style of signing since the binary can also be seen as in PE format (assuming that CONFIG_EFI is enabled). Powerpc is also going to support extended-file-attribute-based verification[3] with vmlinux, but arm64 doesn't for now partly because we don't have TPM-based IMA at this moment. Accordingly, we can use the existing command, sbsign, to sign the kernel. $ sbsign --key ${KEY} --cert ${CERT} Image Please note that it is totally up to the system what key/certificate is used for signing, but one of easy ways to *try* this feature is to turn on CONFIG_MODULE_SIG so that we can reuse certs/signing_key.pem as a signing key, KEY and CERT above, for kernel. (This also enables CONFIG_CRYPTO_SHA1 by default.) Some concerns(or future works): * Even if the kernel is configured with CONFIG_RANDOMIZE_BASE, the 2nd kernel won't be placed at a randomized address. We will have to add some boot code similar to efi-stub to implement the feature. * While big-endian kernel can support kernel signing, I'm not sure that Image can be recognized as in PE format because x86 standard only defines little-endian-based format. * IMA(and extended file attribute)-based kexec * vmlinux support [1] http://git.linaro.org/people/takahiro.akashi/linux-aarch64.git branch:arm64/kexec_file [2] http://git.linaro.org/people/takahiro.akashi/kexec-tools.git branch:arm64/kexec_file [3] http://lkml.iu.edu//hypermail/linux/kernel/1707.0/03669.html Changes in v5 (Oct 10, 2017) * fix kbuild errors around patch #3 per Julien's comments, * fix a bug in walk_system_ram_res_rev() with some cleanup * modify fdt_setprop_range() to use vmalloc() * modify fill_property() to use memset() Changes in v4 (Oct 2, 2017) * reinstate x86's arch_kexec_kernel_image_load() * rename weak arch_kexec_kernel_xxx() to _kexec_kernel_xxx() for better re-use * constify kexec_file_loaders[] Changes in v3 (Sep 15, 2017) * fix kbuild test error * factor out arch_kexec_kernel_*() & arch_kimage_file_post_load_cleanup() * remove CONFIG_CRASH_CORE guard from kexec_file.c * add vmapped kernel region to vmcore for gdb backtracing (see prepare_elf64_headers()) * merge asm/kexec_file.h into asm/kexec.h * and some cleanups Changes in v2 (Sep 8, 2017) * move core-header-related functions from crash_core.c to kexec_file.c * drop hash-check code from purgatory * modify purgatory asm to remove arch_kexec_apply_relocations_add() * drop older kernel support * drop vmlinux support (at least, for this series) Patch #1 to #5 are all preparatory patches on generic side. Patch #6 is purgatory code. Patch #7 to #9 are common for enabling kexec_file_load. Patch #10 is for 'Image' support. AKASHI Takahiro (10): include: pe.h: remove message[] from mz header definition resource: add walk_system_ram_res_rev() kexec_file: factor out arch_kexec_kernel_*() from x86, powerpc kexec_file: factor out crashdump elf header function from x86 asm-generic: add kexec_file_load system call to unistd.h arm64: kexec_file: create purgatory arm64: kexec_file: load initrd, device-tree and purgatory segments arm64: kexec_file: set up for crash dump adding elf core header arm64: enable KEXEC_FILE config arm64: kexec_file: add Image format support arch/arm64/Kconfig | 29 +++ arch/arm64/Makefile | 1 + arch/arm64/include/asm/kexec.h | 93 +++++++ arch/arm64/kernel/Makefile | 4 +- arch/arm64/kernel/kexec_image.c | 105 ++++++++ arch/arm64/kernel/machine_kexec_file.c | 367 ++++++++++++++++++++++++++++ arch/arm64/purgatory/Makefile | 24 ++ arch/arm64/purgatory/entry.S | 55 +++++ arch/powerpc/include/asm/kexec.h | 2 +- arch/powerpc/kernel/kexec_elf_64.c | 2 +- arch/powerpc/kernel/machine_kexec_file_64.c | 36 +-- arch/x86/include/asm/kexec-bzimage64.h | 2 +- arch/x86/kernel/crash.c | 324 ------------------------ arch/x86/kernel/kexec-bzimage64.c | 2 +- arch/x86/kernel/machine_kexec_64.c | 45 +--- include/linux/ioport.h | 3 + include/linux/kexec.h | 32 ++- include/linux/pe.h | 2 +- include/uapi/asm-generic/unistd.h | 4 +- kernel/kexec_file.c | 365 ++++++++++++++++++++++++++- kernel/kexec_internal.h | 20 ++ kernel/resource.c | 57 +++++ 22 files changed, 1156 insertions(+), 418 deletions(-) create mode 100644 arch/arm64/kernel/kexec_image.c create mode 100644 arch/arm64/kernel/machine_kexec_file.c create mode 100644 arch/arm64/purgatory/Makefile create mode 100644 arch/arm64/purgatory/entry.S -- 2.14.1