Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1750480ybt; Thu, 2 Jul 2020 12:55:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUooXrrL7X0eNUftx0D95CpG/mZw6IZJXkKoYQhTWnIOqSf26zoJMXxg+xhdn9+pCZqWx8 X-Received: by 2002:a50:fe0c:: with SMTP id f12mr30631596edt.360.1593719702888; Thu, 02 Jul 2020 12:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593719702; cv=none; d=google.com; s=arc-20160816; b=pKA/RcXde2tYDbGPrNPVl53x24bIkeiEDOO3eapur6iWTUJc2QvahfxZXy6lhWyUfU 0cmSrQ32imdh9NNySkAXYOdO5vgm6xyyQyAK5lN8iOdAC1hAcFNqYwO/qLQiHlf5rtWr CIH8Q8WPHB+ivkh2gCIP/bF2p934eyBtoJbExp8ewZ9mj2tAWzmIoWMluO068ET6obo/ /EDGHIUwXMRokynefOaKatTM5ZXGdcwWDONkJT0uDD0Yqpl247XnIuR6QgzEFqzKgKM8 spHl6gxsZsAuSyMdp5Nf55GKyszjHEnqkvPYiuo5TWLVaaoNi95R4iTf6/IhwEfHu7SX fRkg== 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=HMEkXRk3PIL5QONYoCOMn6O1Dp6Jm5DuuR1nnmjMl7c=; b=I52mcIT4C+9sbd4O8xu/TIQrCr5ZruDIByTcGcGcLBxt7QJ87jiIgJy8/c7L3WKBRt CT3k7QobGUq6S58iLaChASzuRmHp1bjcugOaHemnjubmOQgLEM5hx4eaYR7USOXBubEP tIRbnxUlrzCnF0zpoimKdqnXz9QedxWrQpS8C3zHIkr8Pb+/E8HKZZ99cOahxhQ09QHd WkdIsK0o/gQvq/DM2/kuHfn8Bn+qY9FLWJ/mCfJp/qhrCCnhOie1MOSXUE3LuR6bJYLx RZZrf/aTa+eCaUjXH0Alt+n7IeQCZWhRgv7FTTagFsN5QWt3n1JIHr50U1wltVELfoFY SIDQ== 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 l2si6845140edk.332.2020.07.02.12.54.39; Thu, 02 Jul 2020 12:55:02 -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 S1726032AbgGBTyU (ORCPT + 99 others); Thu, 2 Jul 2020 15:54:20 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:40742 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725915AbgGBTyT (ORCPT ); Thu, 2 Jul 2020 15:54:19 -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 062J2B8T084082; Thu, 2 Jul 2020 15:54:08 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 320wfgt4g4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 Jul 2020 15:54:08 -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 062J9vH0114687; Thu, 2 Jul 2020 15:54:08 -0400 Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 320wfgt4fa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 Jul 2020 15:54:07 -0400 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 062Jj1Rm007779; Thu, 2 Jul 2020 19:54:05 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04fra.de.ibm.com with ESMTP id 31wwr831w3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 Jul 2020 19:54:05 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 062Jqfpg56099092 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 Jul 2020 19:52:41 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 79FF44C044; Thu, 2 Jul 2020 19:54:01 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 56FEE4C040; Thu, 2 Jul 2020 19:53:58 +0000 (GMT) Received: from hbathini.in.ibm.com (unknown [9.102.21.221]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 2 Jul 2020 19:53:58 +0000 (GMT) Subject: [PATCH v2 00/12] 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: Fri, 03 Jul 2020 01:23:57 +0530 Message-ID: <159371956443.21555.18251597651350106920.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.235,18.0.687 definitions=2020-07-02_09:2020-07-02,2020-07-02 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1015 suspectscore=0 impostorscore=0 mlxlogscore=999 cotscore=-2147483648 adultscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 spamscore=0 mlxscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007020125 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 sha256 digest along with other improvements in purgatory code. Will deal with those changes in a separate patch series later. The first patch adds a weak arch_kexec_locate_mem_hole() 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 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_locate_mem_hole() function to locate memory hole for kdump segments by accounting for the special memory regions, referred to as excluded memory ranges, and sets kbuf->mem when a suitable memory region is found. 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 next patch sets up the memory reserve map for the kexec kernel and also claims kdump support for kdump as all the necessary changes are added. The last patch fixes a lookup issue for `kexec -l -s` case when memory is reserved for crashkernel. Tested the changes successfully on P8, P9 lpars, couple of OpenPOWER boxes and a simulator. Changes in v2: * Introduced arch_kexec_locate_mem_hole() for override and dropped weak arch_kexec_add_buffer(). * Addressed warnings reported by lkp. * Added patch to address kexec load issue when memory is reserved for crashkernel. * Used the appropriate license header for the new files added. * Added an option to merge ranges to minimize reallocations while adding memory ranges. * Dropped within_crashkernel parameter for add_opal_mem_range() & add_rtas_mem_range() functions as it is not really needed. --- Hari Bathini (12): 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 ppc64/kexec_file: fix kexec load failure with lack of memory hole 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/include/asm/purgatory.h | 11 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 | 1509 ++++++++++++++++++++++++++++ arch/powerpc/kexec/ranges.c | 397 +++++++ arch/powerpc/mm/drmem.c | 87 +- arch/powerpc/mm/numa.c | 13 arch/powerpc/purgatory/Makefile | 28 - arch/powerpc/purgatory/purgatory_64.c | 36 + arch/powerpc/purgatory/trampoline.S | 117 -- arch/powerpc/purgatory/trampoline_64.S | 175 +++ include/linux/kexec.h | 29 - kernel/kexec_file.c | 16 19 files changed, 2413 insertions(+), 210 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/include/asm/purgatory.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