Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp810524ybt; Fri, 26 Jun 2020 12:05:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytmYUTQMc6wRLClcul9tjLeMyVew/tOPJY81iaMkms7h/mo1J/m7Np5AIHmDAWQzlVP2hX X-Received: by 2002:a50:f385:: with SMTP id g5mr4674642edm.347.1593198332457; Fri, 26 Jun 2020 12:05:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593198332; cv=none; d=google.com; s=arc-20160816; b=mmxzrnOhhKnhUi3gYQODKzBvhTnADH1D495wWS1519w1+6azOecjxdZuK3K6xjPix0 YfVVN3lGMFur63p+kbJFLKmfZHpy/ZzQGb+TbK/ykPPSnaHM2TbkPkwRjnvgjTUk1AX1 mevcmtEPpAVhuxQGPn7/GHPJCvFrES6N7drm5h3Tm+5WsqS6SN1pNVYnIBbmxq8he/mn 4S/NddcUU2HCSNzqaswHCIUC6vwiglhA7GSJDJo+gWhOAY6NIINBHFNjJzVcM1AF5oVK bm8869kbWMwNiTm3MQKgr5ppuPbiDQYz1m4QJHDw62xeBpxcULI9E8jJcpaScIRK+Ws+ Z26w== 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 :user-agent:message-id:date:cc:to:from:subject; bh=db7sFosNwsxJoJfzAZpQaqfAGc1FnjICuSQta/E/s4A=; b=I8PRtWOaJZnaMd1o4L5r67PcZe4Mo/dbVm1OvEEYDNUW1hoglvEtq0i8dZ/istqLz6 CMrsERsKUcq9jwdzlyIA0pk+7wuxiPNML6RYJy4yUeGiwqPWBQBbLG4QdRfMHNS/upeZ PQ8lkO3gO0MH2Y2Gr9prDN6uXAVaIypeBglJwTLBhqfXVjiXJfdWRt5pckkJDv515bjO G9L4cUfVNtobTf2Ja2mryDRv3e97lF6DiVLyiTNZXKIDXp6zRGF5MyM3u/TdFoVhF8P/ fYPqstBbLp4sNNjVWla69C3rQ6jPb6Zk9fzhEjVJeo5xRZey7jbKKA+JIehQJelX1exD KMXA== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lb19si16480621ejb.295.2020.06.26.12.05.07; Fri, 26 Jun 2020 12:05:32 -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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725806AbgFZTE5 (ORCPT + 99 others); Fri, 26 Jun 2020 15:04:57 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:17844 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725275AbgFZTE4 (ORCPT ); Fri, 26 Jun 2020 15:04:56 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05QJ3LYT042837; Fri, 26 Jun 2020 15:04:43 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31wjekr456-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Jun 2020 15:04:43 -0400 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 05QJ3Q82043212; Fri, 26 Jun 2020 15:04:43 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 31wjekr442-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Jun 2020 15:04:42 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 05QJ0iJp013024; Fri, 26 Jun 2020 19:04:40 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma03ams.nl.ibm.com with ESMTP id 31uus53cgt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Jun 2020 19:04:40 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 05QJ3Ib565339788 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Jun 2020 19:03:18 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CD17BA405C; Fri, 26 Jun 2020 19:04:37 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A91AAA4054; Fri, 26 Jun 2020 19:04:34 +0000 (GMT) Received: from hbathini.in.ibm.com (unknown [9.102.0.159]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 26 Jun 2020 19:04:34 +0000 (GMT) Subject: [PATCH 00/11] ppc64: enable kdump support for kexec_file_load syscall From: Hari Bathini To: Michael Ellerman , Andrew Morton Cc: Pingfan Liu , Kexec-ml , Mimi Zohar , Petr Tesarik , Mahesh J Salgaonkar , Sourabh Jain , lkml , linuxppc-dev , Eric Biederman , Thiago Jung Bauermann , Dave Young , Vivek Goyal Date: Sat, 27 Jun 2020 00:34:33 +0530 Message-ID: <159319825403.16351.7253978047621755765.stgit@hbathini.in.ibm.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-06-26_10:2020-06-26,2020-06-26 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 priorityscore=1501 impostorscore=0 adultscore=0 bulkscore=0 cotscore=-2147483648 mlxscore=0 clxscore=1011 lowpriorityscore=0 suspectscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006260134 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch series enables kdump support for kexec_file_load system call (kexec -s -p) on PPC64. The changes are inspired from kexec-tools code but heavily modified for kernel consumption. There is scope to expand purgatory to verify sha digest but tried to keep purgatory changes minimal in the interest of this series. The first patch adds a weak arch_kexec_add_buffer function to override locate memory hole logic suiting arch needs. There are some special regions in ppc64 which should be avoided while loading buffer & there are multiple callers to kexec_add_buffer making it too complicated to maintain range sanity and using generic lookup at the same time. The second patch marks ppc64 specific code within arch/powerpc/kexec and arch/powerpc/purgatory to make the subsequent code changes easy to understand. The next patch adds helper function to setup different memory ranges needed for loading kdump kernel, booting into it and exporting the crashing kernel's elfcore. The fourth patch overrides arch_kexec_add_buffer to locate memory hole for kdump segments by accounting for the special memory regions, referred to as excluded memory ranges, and calls __kexec_add_buffer with kbuf->mem set to skip the generic locate memory hole lookup. The fifth patch moves walk_drmem_lmbs() out of .init section with a few changes to reuse it for setting up kdump kernel's usable memory ranges. The next patch uses walk_drmem_lmbs() to look up the LMBs and set linux,drconf-usable-memory & linux,usable-memory properties in order to restrict kdump kernel's memory usage. The seventh patch adds relocation support for the purgatory. Patch 8 helps setup the stack for the purgatory. The next patch setups up backup region as a segment while loading kdump kernel and teaches purgatory to copy it from source to destination. Patch 10 builds the elfcore header for the running kernel & passes the info to kdump kernel via "elfcorehdr=" parameter to export as /proc/vmcore file. The last patch sets up the memory reserve map for the kexec kernel and also claims kdump support as all the necessary changes are added. Tested the changes successfully on P8, P9 lpars & an OpenPOWER box. --- Hari Bathini (11): kexec_file: allow archs to handle special regions while locating memory hole powerpc/kexec_file: mark PPC64 specific code powerpc/kexec_file: add helper functions for getting memory ranges ppc64/kexec_file: avoid stomping memory used by special regions powerpc/drmem: make lmb walk a bit more flexible ppc64/kexec_file: restrict memory usage of kdump kernel ppc64/kexec_file: add support to relocate purgatory ppc64/kexec_file: setup the stack for purgatory ppc64/kexec_file: setup backup region for kdump kernel ppc64/kexec_file: prepare elfcore header for crashing kernel ppc64/kexec_file: add appropriate regions for memory reserve map arch/powerpc/include/asm/crashdump-ppc64.h | 15 arch/powerpc/include/asm/drmem.h | 9 arch/powerpc/include/asm/kexec.h | 35 + arch/powerpc/include/asm/kexec_ranges.h | 18 arch/powerpc/kernel/prom.c | 13 arch/powerpc/kexec/Makefile | 2 arch/powerpc/kexec/elf_64.c | 35 + arch/powerpc/kexec/file_load.c | 78 + arch/powerpc/kexec/file_load_64.c | 1461 ++++++++++++++++++++++++++++ arch/powerpc/kexec/ranges.c | 387 +++++++ arch/powerpc/mm/drmem.c | 87 +- arch/powerpc/mm/numa.c | 13 arch/powerpc/purgatory/Makefile | 28 - arch/powerpc/purgatory/purgatory_64.c | 35 + arch/powerpc/purgatory/trampoline.S | 117 -- arch/powerpc/purgatory/trampoline_64.S | 153 +++ include/linux/kexec.h | 5 kernel/kexec_file.c | 37 + 18 files changed, 2327 insertions(+), 201 deletions(-) create mode 100644 arch/powerpc/include/asm/crashdump-ppc64.h create mode 100644 arch/powerpc/include/asm/kexec_ranges.h create mode 100644 arch/powerpc/kexec/file_load_64.c create mode 100644 arch/powerpc/kexec/ranges.c create mode 100644 arch/powerpc/purgatory/purgatory_64.c delete mode 100644 arch/powerpc/purgatory/trampoline.S create mode 100644 arch/powerpc/purgatory/trampoline_64.S