Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp749096pxb; Fri, 29 Oct 2021 20:25:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6kOV52WnJ87XvtJGtB9J+SRseFkuVWf4wH847SSJZJdS+/DKV754uuVekVyViOTgPlsyN X-Received: by 2002:a17:906:5d11:: with SMTP id g17mr18705769ejt.175.1635564322293; Fri, 29 Oct 2021 20:25:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635564322; cv=none; d=google.com; s=arc-20160816; b=BQ875rPxRzmu2puYzN3S/tJr5s7q9CnjnD5fAh7VUgjFiiVWtCZX/L27i5b3WedhUk qC7vETFOpj+SAtbo1fs3v+GOKdIv8D4/fUJCGjochpsP6nfxPS4pAzzyKxSrHjRmEWyc F//ZwF5U2LX1BQCL0vWi+z50K+BG2/59BhNDXBDdQ2bCV8UvpJ0QbnnB1XlTbQmZ6xnU UxeQV0xa4kDPYGXGCEl//osLQ2pk2Omdvtm+OpsjlqiH4Un/3zOZTPjZ2nfUbXLjbIld 2om842Xb9+u/p4o+0KIcRtAiGqZN9WIHdKrhgkEL0sZyNya6zdYwpPovusyWij2+TuiU aqIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=WG/B18aAjNulLPyOn0hI8mBw4EG9RbmsV0tiIkkjHgA=; b=iSxsdUx8lmCCyjlMy6ukveJqEWtLU0RvHHwUlPOtrGhw5qkYYTTrhe9tVauhZi4ger j/NC5R9wwZHWDJSvTrxSKo/Y8+sAB9E3yDbV1KY9SfTxlHm5O+15SV9J1Oc9Eh1SMRW9 B4kr0ADmTfcU0nM1PaGcNyCXwd11Pip0sbTVj6DE6TREfVq38jumXpDzcQPGXTLW0TYZ 1Faapf+KJIlgbQXgmE8ptw8+8ollRYAk05c4iTJWqClL5huXwh71erZH4rWvLF651KRA ues0ySRGp6wZGqkswSZ/7Su94ByNjqjNcD1jNgQ0gLo7Im9SLSZP7eWtcGMHVTnLtYYb 5RKw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z19si14663116edd.610.2021.10.29.20.24.23; Fri, 29 Oct 2021 20:25:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231654AbhJ3DTT (ORCPT + 99 others); Fri, 29 Oct 2021 23:19:19 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:14881 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229829AbhJ3DTT (ORCPT ); Fri, 29 Oct 2021 23:19:19 -0400 Received: from dggeme706-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Hh4G20D8pz8vfp; Sat, 30 Oct 2021 11:16:42 +0800 (CST) Received: from huawei.com (10.67.174.53) by dggeme706-chm.china.huawei.com (10.1.199.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.15; Sat, 30 Oct 2021 11:16:47 +0800 From: Liao Chang To: , , , , , , , , , , , CC: , , , Subject: [PATCH 0/3] riscv: kexec: add kexec_file_load() support Date: Sat, 30 Oct 2021 11:18:29 +0800 Message-ID: <20211030031832.165457-1-liaochang1@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.174.53] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeme706-chm.china.huawei.com (10.1.199.102) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patchset implement kexec_file_load() support on riscv, Most of the code is based on the kexec-tool-patch repo developed by Nick Kossifids. This patch series enables us to load the riscv vmlinux by specifying its file decriptor, instead of user-filled buffer via kexec_file_load() syscall. Contrary to kexec_load() system call, we reuse the dt blob of the first kernel to the 2nd explicitly. To use kexec_file_load() system call, instead of kexec_load(), at kexec command, '-s' options must be specified. The patch for kexec_tools has to be apply to riscv architecture source like this: int elf_riscv_load(int argc, char **argv, const char *buf, off_t len, ... if (info->file_mode) { return prepare_kexec_file_options(info); } ... Add following routine to prepare cmdline_ptr, cmdline_len and initrd_fd for syscall kexec_file_load: int prepare_kexec_file_options(struct kexec_info *info) { int fd; ssize_t result; struct stat stats; if (arch_options.cmdline) { info->command_line = (char *)arch_options.cmdline; info->command_line_len = strlen(info->command_line) + 1; } if (!arch_options.initrd_path) { info->initrd_fd = -1; return 0; } fd = open(arch_options.initrd_path, O_RDONLY | _O_BINARY); if (fd < 0) { fprintf(stderr, "Cannot open `%s': %s\n", arch_options.initrd_path, strerror(errno)); return -EINVAL; } result = fstat(fd, &stats); if (result < 0) { close(fd); fprintf(stderr, "Cannot stat: %s: %s\n", arch_options.initrd_path, strerror(errno)); return -EINVAL; } info->initrd_fd = fd; return 0; } The basic usage of kexec_file is: 1) Reload capture kernel image: $ kexec -s -l --reuse-cmdline 2) Startup capture kernel: $ kexec -e For future work: * Support for kdump and purgatory. * Support for kernel image verification. * Support physical address randomization. Liao Chang (3): kexec_file: Fix kexec_file.c build error for riscv platform RISC-V: use memcpy for kexec_file mode RISC-V: Add kexec_file support arch/riscv/Kconfig | 11 ++ arch/riscv/include/asm/kexec.h | 4 + arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/elf_kexec.c | 189 +++++++++++++++++++++++++ arch/riscv/kernel/machine_kexec.c | 5 +- arch/riscv/kernel/machine_kexec_file.c | 14 ++ include/linux/kexec.h | 2 +- kernel/kexec_file.c | 4 +- 8 files changed, 226 insertions(+), 4 deletions(-) create mode 100644 arch/riscv/kernel/elf_kexec.c create mode 100644 arch/riscv/kernel/machine_kexec_file.c -- 2.17.1