From patchwork Thu Nov 15 05:52:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 151174 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6594340ljp; Wed, 14 Nov 2018 21:53:37 -0800 (PST) X-Google-Smtp-Source: AJdET5c3s+4Hs9+6s5LRzElLli9x6aIkSB6ZUNnbjeG/tKWrIH43YQeV9bn/Zp6+BUykXUEsEXGe X-Received: by 2002:a62:6981:: with SMTP id e123-v6mr5047058pfc.104.1542261216961; Wed, 14 Nov 2018 21:53:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542261216; cv=none; d=google.com; s=arc-20160816; b=NSYgdKlPnoRZ/v7nnXLMUy6n9qJMdd64wmC5tGZsUxvIt8LpuUx8WQZnQgj232awOS cPJ7vigjMEvKiwC/2RI4L/VdEBk5fC6JnExQUu5t1zUdrnmEOB4399OBT0KRtM5j8TZh ETl+4ldOPkdY8US3dZ9SerQkyTzDsSWD7e0YnnJiTFc9+ZKBosSdVdLwZfrtvpxoGpVC /WJff/uauZ0ccV+hA/DtcM65TdY93BQZaUj+ExzFFS60N/RyDeUOjBEwcH9CbD/d0b7s oqNSiwu1PNpMphogied5UcqkDhU02BZb600ePX8QWZg6fg1BrvbAWEgqUFZ10lrzQ1We cqug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=M0hbeCh1UKPHriGwoJtqoIhFiJS4pqBvteNzMpOOqEM=; b=E4WXGaMEJQvpatYKl/iAk7kTAkX2tRO74A71oEUhQOPsvDDHwkul0ZvMB2y+ImGbR1 mmyd4ZjEJ3VabyRl3Ht9sSmf29BEVnvBeir7pjXAQ5hcL+vjSWSC6gRkuaMr0b9DZ3To J9lqr63TgJNo4YMuvnwjvQXmhasKut1tx6sATpZdjq+LEmUKhynGxPljlSPEZu5exq4k AemlhKTeRrNQWZf6gox4tVOEJNbdnNvcRAblW7QPQIUwrJAN26jQuiQtEtJV6cliWSs/ IlSOrsO3ZKR+HA04AQeW9ZVTOM/YY+gcqdOZcChK9J82tS1eqkwsMCKXLVetsFhQ9sme OFNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j2R2QQRz; 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 d3-v6si28833972plj.372.2018.11.14.21.53.36; Wed, 14 Nov 2018 21:53:36 -0800 (PST) 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=j2R2QQRz; 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 S1729046AbeKOQAA (ORCPT + 32 others); Thu, 15 Nov 2018 11:00:00 -0500 Received: from mail-yw1-f66.google.com ([209.85.161.66]:42372 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726943AbeKOP77 (ORCPT ); Thu, 15 Nov 2018 10:59:59 -0500 Received: by mail-yw1-f66.google.com with SMTP id x2so1844713ywc.9 for ; Wed, 14 Nov 2018 21:53:33 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=M0hbeCh1UKPHriGwoJtqoIhFiJS4pqBvteNzMpOOqEM=; b=j2R2QQRzTmCm/H2I7k4eBK4g/dz0MuUN8Tu6rMbhngctlQhlCchBaEqc//rA6ZgW5p 6LvDiN/tCVGaLrs/lHTim7I4nTw6D2cmaOYnxEiqHPdW2l21rr795UQx4wEFBdW/3Ypj Xcq/MCZFRBF3DdYdwMiY3mH9hkdcbyiqO1ve0= 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:mime-version:content-transfer-encoding; bh=M0hbeCh1UKPHriGwoJtqoIhFiJS4pqBvteNzMpOOqEM=; b=WWly00ZKDO3FVJb6aOW5CKWvhVEY2/9ssO/IvaR2/yfFcyUb5qFduLEezKOX7/J8pj P5ezW+6aEKl6OcH+cr+hZkMe7GqrqfBX6JDZD2D/RFIyo8afZFfTuenf1Zk1H887RtDf zfKfWaPmfyaWmX9u/DfIEBictqnx5econuYDJVvhywhhqcRW4t8Pv0Eo/xN1soaR2MXy WVV7CKC6aiQu94N16jjh/qNB7BsRNeY9iLSblqk7jVUlD/qSuEYNR9wOobNFgjVkBLS3 SsFcpDotKl3I5v9wLQbltCh1AAqTDBrU8yz8f8J0VBWKJGMYxPjYSQnaF1+XqHTHGXrG DwiA== X-Gm-Message-State: AGRZ1gLZGR31jX6HLQKp4AHwXfbBoMHId/DWPsbvUCpFkuZ8ErmBqmZZ G8i2LDQomNAnZmR88OgdQ9yE5w== X-Received: by 2002:a81:7897:: with SMTP id t145-v6mr4653791ywc.466.1542261212771; Wed, 14 Nov 2018 21:53:32 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id s129-v6sm6769228ywc.41.2018.11.14.21.53.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:32 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro , Rob Herring , Frank Rowand , devicetree@vger.kernel.org Subject: [PATCH v16 12/16] arm64: kexec_file: add crash dump support Date: Thu, 15 Nov 2018 14:52:51 +0900 Message-Id: <20181115055254.2812-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Enabling crash dump (kdump) includes * prepare contents of ELF header of a core dump file, /proc/vmcore, using crash_prepare_elf64_headers(), and * add two device tree properties, "linux,usable-memory-range" and "linux,elfcorehdr", which represent respectively a memory range to be used by crash dump kernel and the header's location Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse Cc: Rob Herring Cc: Frank Rowand Cc: devicetree@vger.kernel.org --- arch/arm64/include/asm/kexec.h | 4 ++ arch/arm64/kernel/machine_kexec_file.c | 97 +++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 3 deletions(-) -- 2.19.0 diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 67e4cb75d1fd..660705515e33 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -99,6 +99,10 @@ static inline void crash_post_resume(void) {} struct kimage_arch { void *dtb; unsigned long dtb_mem; + /* Core ELF header buffer */ + void *elf_headers; + unsigned long elf_headers_mem; + unsigned long elf_headers_sz; }; extern const struct kexec_file_ops kexec_image_ops; diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 7e9d5ed3e238..ab296b98d633 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -16,11 +16,15 @@ #include #include #include +#include #include #include +#include #include /* relevant device tree properties */ +#define FDT_PSTR_KEXEC_ELFHDR "linux,elfcorehdr" +#define FDT_PSTR_MEM_RANGE "linux,usable-memory-range" #define FDT_PSTR_INITRD_STA "linux,initrd-start" #define FDT_PSTR_INITRD_END "linux,initrd-end" #define FDT_PSTR_BOOTARGS "bootargs" @@ -35,6 +39,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) vfree(image->arch.dtb); image->arch.dtb = NULL; + vfree(image->arch.elf_headers); + image->arch.elf_headers = NULL; + image->arch.elf_headers_sz = 0; + return kexec_image_post_load_cleanup_default(image); } @@ -49,6 +57,22 @@ static int setup_dtb(struct kimage *image, if (nodeoffset < 0) return -EINVAL; + if (image->type == KEXEC_TYPE_CRASH) { + /* add linux,elfcorehdr */ + ret = fdt_setprop_reg(dtb, nodeoffset, FDT_PSTR_KEXEC_ELFHDR, + image->arch.elf_headers_mem, + image->arch.elf_headers_sz); + if (ret) + return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL); + + /* add linux,usable-memory-range */ + ret = fdt_setprop_reg(dtb, nodeoffset, FDT_PSTR_MEM_RANGE, + crashk_res.start, + crashk_res.end - crashk_res.start + 1); + if (ret) + return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL); + } + /* add bootargs */ if (cmdline) { ret = fdt_setprop_string(dtb, nodeoffset, FDT_PSTR_BOOTARGS, @@ -86,7 +110,8 @@ static int setup_dtb(struct kimage *image, } /* - * More space needed so that we can add initrd and bootargs. + * More space needed so that we can add initrd, bootargs, + * userable-memory-range and elfcorehdr. */ #define DTB_EXTRA_SPACE 0x1000 @@ -132,6 +157,43 @@ static int create_dtb(struct kimage *image, } } +static int prepare_elf_headers(void **addr, unsigned long *sz) +{ + struct crash_mem *cmem; + unsigned int nr_ranges; + int ret; + u64 i; + phys_addr_t start, end; + + nr_ranges = 1; /* for exclusion of crashkernel region */ + for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, + MEMBLOCK_NONE, &start, &end, NULL) + nr_ranges++; + + cmem = kmalloc(sizeof(struct crash_mem) + + sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL); + if (!cmem) + return -ENOMEM; + + cmem->max_nr_ranges = nr_ranges; + cmem->nr_ranges = 0; + for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, + MEMBLOCK_NONE, &start, &end, NULL) { + cmem->ranges[cmem->nr_ranges].start = start; + cmem->ranges[cmem->nr_ranges].end = end - 1; + cmem->nr_ranges++; + } + + /* Exclude crashkernel region */ + ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); + + if (!ret) + ret = crash_prepare_elf64_headers(cmem, true, addr, sz); + + kfree(cmem); + return ret; +} + int load_other_segments(struct kimage *image, unsigned long kernel_load_addr, unsigned long kernel_size, @@ -139,14 +201,43 @@ int load_other_segments(struct kimage *image, char *cmdline) { struct kexec_buf kbuf; - void *dtb = NULL; - unsigned long initrd_load_addr = 0, dtb_len; + void *headers, *dtb = NULL; + unsigned long headers_sz, initrd_load_addr = 0, dtb_len; int ret = 0; kbuf.image = image; /* not allocate anything below the kernel */ kbuf.buf_min = kernel_load_addr + kernel_size; + /* load elf core header */ + if (image->type == KEXEC_TYPE_CRASH) { + ret = prepare_elf_headers(&headers, &headers_sz); + if (ret) { + pr_err("Preparing elf core header failed\n"); + goto out_err; + } + + kbuf.buffer = headers; + kbuf.bufsz = headers_sz; + kbuf.mem = 0; + kbuf.memsz = headers_sz; + kbuf.buf_align = SZ_64K; /* largest supported page size */ + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = true; + + ret = kexec_add_buffer(&kbuf); + if (ret) { + vfree(headers); + goto out_err; + } + image->arch.elf_headers = headers; + image->arch.elf_headers_mem = kbuf.mem; + image->arch.elf_headers_sz = headers_sz; + + pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + image->arch.elf_headers_mem, headers_sz, headers_sz); + } + /* load initrd */ if (initrd) { kbuf.buffer = initrd;