From patchwork Tue Oct 24 06:23:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 116889 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5451161qgn; Mon, 23 Oct 2017 23:21:11 -0700 (PDT) X-Received: by 10.98.131.68 with SMTP id h65mr15712367pfe.148.1508826070964; Mon, 23 Oct 2017 23:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508826070; cv=none; d=google.com; s=arc-20160816; b=JoytxAmlGt5KarL3GvqoEXZXYdKwRbvHnCwkHBhueCPRZzcQVBsLLjRmr5Ub0E91Uj vHPYrwSwFLMvG+Y4ExTy7RpdQC4GiJvxvzbi1yb8mtv77Z+yzH+sJnAuTrfr9G75jjF8 BWve5Uf+ffbl+cZMqL5YxZXYCUq/OXdpzbQS1d20xl8TVkqBt0hnufZ5Ko9LLF4qYIKy Lxtj5YXZ+bfPAygZxtfqzAKMFs5MXtQxzgKgiUy4zkdOiK2KBpeSqONJxRq2wWpDc8Do qjgErCUcLpQe6kg5qK3P1XwGdPR6azzOJhhxgsArck+5ZhpxiSEqEbO+M86iPaZe3Rcn oP6A== 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=HJHyaIkgjgVRY4btE394S3yjVq2xKm05vPgN1BBiTkI=; b=YjnGoA8rH07Ihx8JuOyY7tJtCmtoGf+IQezGyDRxlU5Ouyn/oRQXd+AaNU5LRq4sw/ aNP98CntfonePxdVaBqGAT9d1dgTtGUL595DprRD6Jb8MlqaLslOz7xiJm8FgCm19z96 WgQanHkD2uklB5vrhvb6hvA+6AtI3sR9icWnXbfKiB0aOBGwv8kTBARZp9aPjezfVSCk cdpkn8+4Y4uV0wRkMYwCpBK1lQXX1z+5D15FC4xteG+DpdcE5xqGRCsdbRwWqWqVpJuP cSRdyK1vPsKh9+c0maygvsGDP5BfEKscczXtNVR0jva/fU1KN6H9KV4HrWq584pxdf+O W7ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WrW4fY2G; 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 h83si6498083pfk.250.2017.10.23.23.21.10; Mon, 23 Oct 2017 23:21:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WrW4fY2G; 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 S1751546AbdJXGVJ (ORCPT + 27 others); Tue, 24 Oct 2017 02:21:09 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:50599 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751319AbdJXGVG (ORCPT ); Tue, 24 Oct 2017 02:21:06 -0400 Received: by mail-pf0-f196.google.com with SMTP id b6so18934334pfh.7 for ; Mon, 23 Oct 2017 23:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=HJHyaIkgjgVRY4btE394S3yjVq2xKm05vPgN1BBiTkI=; b=WrW4fY2G53LqFw/xwNoCJ3gAqL9fdFFad+uvw5DpATMklWkyLVHAlngMdiEKKwrwzE MgDjUt0kJ5lWdanzrOrxh4TBeFWXb3HN1FFQob0Yv4AweUpP1MWkyXsTtzDV1JXMn5av SispoCbCTPzzZzqf5kl4pvTt9ocgKz34LSbmU= 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=HJHyaIkgjgVRY4btE394S3yjVq2xKm05vPgN1BBiTkI=; b=JRjl58E4vxyLDvsODmzGv4vjYdS+veoajYkF97YRz0U0Zl8UWYrJYdKiZkVZAVTWKe O9xRk5/Gt2deWgCPbsvFRzwPMwCHl5dn0jknCtub9EkByzLhxshDQ9sEVj/ldOLgSyiI H4zogAOejcoNozykCxQQ+dX7WKfYfKqng1UT4uOR8wHgI+R5taDginKUyCKjNDDmPe+6 xXfgyJdZHZ3jlNm0/TE+yS/PIPhtEUgc7a2JRBPJ54D1cSLJXddBpiflxTPmbrUZURvo +6Net9UQiQsoFRBtIEx6FU6bilkBTOdrZRPizuWbVI25MsvgvZBt9yYxkHkue9B/ZdZp dzVA== X-Gm-Message-State: AMCzsaXD0ieZYzY9d/vP5p/iyPTfUDe0M6cI2Tt0o27Whpsuv9t54uMz Mep/EhDMr8ETO5ZE0D0agcOTlQ== X-Google-Smtp-Source: ABhQp+SEQNSVVCwufdN257vIyS+E9SbiWOkxA+wQFGp9+XZXzHNRG9ud76m6hWg8wv4u2PM76lCQKQ== X-Received: by 10.101.67.196 with SMTP id n4mr13426328pgp.395.1508826065619; Mon, 23 Oct 2017 23:21:05 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id n72sm15902671pfi.92.2017.10.23.23.21.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 23:21:04 -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 00/10] arm64: kexec: add kexec_file_load() support Date: Tue, 24 Oct 2017 15:23:44 +0900 Message-Id: <20171024062354.22621-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 sixth 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. (Please use v7.2.1+ crash for v4.14+ kernel) 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 v6 (Oct 24, 2017) * fix a for-loop bug in _kexec_kernel_image_probe() per Julien 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 | 39 +-- 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(+), 421 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