From patchwork Mon Oct 2 06:14:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 114546 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp325320qgn; Sun, 1 Oct 2017 23:12:32 -0700 (PDT) X-Received: by 10.99.99.197 with SMTP id x188mr11824370pgb.421.1506924752643; Sun, 01 Oct 2017 23:12:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506924752; cv=none; d=google.com; s=arc-20160816; b=K0Hxhi9/Cb8JOid3/LB51aK3RLEQW+RFnHd2pA+4kHYEP2a/4+hpUQ68h2hyK3HkF6 DLAwc7eavzVNYjJgOsG1ErX6wm3vndNicwhWpaAL2jRzl6CTTPD+yhMu0G+QDuxEvpwM BHvHPh6z7iG5QpdiYAvW9f6DmItETDdj/er/H4bW7N+NXr8kUj11p2hWPD2RAFyD8XLS foZs7yKeARdKHAa+qQLYZkq0rxGwkoVJD5WAsBiXkQbj+jc3mySN+d4M49x7VBkWKkQQ OpLJ4mimZMTZOYR41ic3Ea6IbAE0Gh6vJi4JZaArEjdvuHJ6huGk/foZ5wQsnIfd6XZN gZ9A== 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=UnCApDIlnHYybEY1DxBbgu27z1z33M2Zf1Fv9hHaI3g=; b=q9EWY+2fy1xBOVRScE9tGCbeVWynqBlZXVKWeLDRHsxBqzymxIG71oqKKuNVfVWZrZ Nbr6VJgreMi7L/v5yjDjbRKWr9e6mA1nH99pRIkCumecDAEV+Npc0E4rhfETdCOLN/wE EPd8qDHspJpce7h0FWSchik2gLNC3ZwWS1BfrwPXsOar8kXgQrljy4CrycpO/eymBkfB UbTOrRtBf3TivNiC/OgzSQQGykiBol133MLHXDwsI39RLla3wPOguNNeyGuoHf6CbDcU tXX+u5CkIhWdxh1nwGqpN/ifnAx3NMvo858EW1P5MExarWwsWKWwDnDBye32YWrjAzGs 8aow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cl6rwrgz; 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 d27si7217372pfm.453.2017.10.01.23.12.32; Sun, 01 Oct 2017 23:12:32 -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=cl6rwrgz; 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 S1750923AbdJBGMa (ORCPT + 26 others); Mon, 2 Oct 2017 02:12:30 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:55737 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750760AbdJBGM2 (ORCPT ); Mon, 2 Oct 2017 02:12:28 -0400 Received: by mail-pf0-f182.google.com with SMTP id h8so1883324pfa.12 for ; Sun, 01 Oct 2017 23:12: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; bh=UnCApDIlnHYybEY1DxBbgu27z1z33M2Zf1Fv9hHaI3g=; b=cl6rwrgzLE+XJpWFRvU+/nwisEkXtTZ0fwaVpXhlbX7S57yMTTUCFVeaydiwVi9b7S 3IxTHYCnfSbCg4DGz742CvmNSr6+YVWTfr/SqThKVx0ZO7D9ecoZIdZje+ORY/TXzMzm rHvzpIm/NizCiPbOpnAw5vgXxB+emU5WqX9xM= 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=UnCApDIlnHYybEY1DxBbgu27z1z33M2Zf1Fv9hHaI3g=; b=Sw7RyfJBGjElw/1maSG7/8UiXsivMQL+DISKbEScwvK4bk17RyejKLICz/ia6CjRc4 CJmYx6JoT1Jew16wWGFKxH5TIwf8sMPGavQGYqQLPzO6MFSeZXXuBv7lJrO7tmQFFBHa t4zdgSktswHrOsJU/vLORycf5mlMKnHZI6oXTMlupLvF3D0YLYxTcKJXLOj575KUZM8v cIDSVeAIYUCJPHpdOK6aV2IQzKAnAuzAjCOv9kJADAdWoqFzweZsObbjh17hKde9nbZv Q61ViqAaGYERhUStv1FTrCzz3/6TCWwAnFkL8FNmnNEQmc5WJKWlKDY/G5iyJrg4PgG2 i3wQ== X-Gm-Message-State: AHPjjUgYLN+y8JBAgIXgIn0pRf2eb4zUfIZj6+VsVK5hMvCD+B1PIeMX QVozXahorF3Hemexwcsrp1OJAQ== X-Google-Smtp-Source: AOwi7QC2gFprZgtElC9E8Zz+hQ9lnzplxryHaEuP9Lbotsxo5QO1DTHtkN7mohKifpVHopXNs4YY0A== X-Received: by 10.101.92.6 with SMTP id u6mr11955824pgr.198.1506924747920; Sun, 01 Oct 2017 23:12:27 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x11sm3758188pgq.29.2017.10.01.23.12.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Oct 2017 23:12: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 Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v4 00/10] arm64: kexec: add kexec_file_load() support Date: Mon, 2 Oct 2017 15:14:21 +0900 Message-Id: <20171002061431.11117-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 fourth 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 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 | 365 +++++++++++++++++++++++++++ arch/arm64/purgatory/Makefile | 24 ++ arch/arm64/purgatory/entry.S | 55 +++++ arch/powerpc/kernel/kexec_elf_64.c | 2 +- arch/powerpc/kernel/machine_kexec_file_64.c | 36 +-- 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 | 371 +++++++++++++++++++++++++++- kernel/kexec_internal.h | 20 ++ kernel/resource.c | 59 +++++ 20 files changed, 1159 insertions(+), 417 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