From patchwork Thu Nov 15 21:47:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupesh Sharma X-Patchwork-Id: 10685023 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16F1013BF for ; Thu, 15 Nov 2018 21:48:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F4CE28509 for ; Thu, 15 Nov 2018 21:48:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E7322D281; Thu, 15 Nov 2018 21:48:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AF1A62D26A for ; Thu, 15 Nov 2018 21:48:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=z94a+VPYjidoqrRdQwg5zqxf/CuKebtch9T9FA8N4DQ=; b=tH8 I5y/qZMG7xMudMJeWnxLa3dayguY+uw+rQDT0TJiO2118La+FS5vmMZq3nccOUmBNRbrcfBLpNns+ EnDxXC/gNSInU4lWA0JoTbF75YT/4+kwPd28qq7c0kjzIAFj1vjb1mzb/PAHXbL5f8J/0ZwN8VCbT noQwpJV1my98gr6Ls1rFx/5Ua7nD6qBcgo4EIIFfYDCReBm/Xjr4mSFC+ZfD75XuIngGblj0rTon1 aLwf2inkkUXfFjkJOW4ABP1KvaH5x6ZtLK9vPL/2oFOCIeqJPaqcBxtPU9DMPel8rRSd1j302rx2G fjOCpGyWwD9UjkFJhZk06PpRWbWzihQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNPUq-0002Gu-SD; Thu, 15 Nov 2018 21:48:20 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNPUp-0002Gi-GP for linux-arm-kernel@bombadil.infradead.org; Thu, 15 Nov 2018 21:48:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=5lAnJ4Odmi3MOIXfrC7f3waSSM1TNTIQKK1l8SjDyk4=; b=XEuE/fsMsTYeyrNDPoxo/0SwM 3aPnAoGjsGdZMLa/e02TqT9ivZh7ub4WHpDvONW8IKTNfNGocj/l22cnPcxNXf6CPzwLVIPYQl412 VynNKsgErm7smK6rMhIE9PykjTT46V0WFHaO5daYbeOy0Utefkqw3VyZ68Fy7KAFJBHcjtlRy2F4f 9V7/+bL9jocIVmSrMpNZ2B6lkWqfL7Y/Za0j89da2B0ZsloP2i8JfGOWlbdi/pBbf078Nrb+FXanR K6g1hy6OQ8BvKCfdXVVZ+OcDDsWuxqLO3T1cs1UN7j2aoK3GdJlYZoxEd/EfW7XdAyMr2v23Mm/l7 IT8QwnTYQ==; Received: from mail-pg1-f196.google.com ([209.85.215.196]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNPUm-0007YW-0s for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 21:48:17 +0000 Received: by mail-pg1-f196.google.com with SMTP id w7so9582541pgp.13 for ; Thu, 15 Nov 2018 13:48:05 -0800 (PST) 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=5lAnJ4Odmi3MOIXfrC7f3waSSM1TNTIQKK1l8SjDyk4=; b=s3FtGpHplEs2r23j5Zd7TiTC9mB0kJGXxoLXHbdAVq1EMP/Pkxs6sE85tUDItl72Cj jmwnmtK38YV32C5kNOVOkasTVT98boZCLRnc28/MrsXWZq2ewtTJndK0kTQhzGtgQIh9 YMsaRRB0n++xVEMbwNObpqsA/Vm1bJ4tJOe5f73Z7gu7EWv1eagKA+uEXB6eRBTsJ3p6 zHnWoquqQw2ax3MGJKLnrcxlrpc6EDC3dP6GofhDzIVGUH2h35eJcLgqjBpcnIj5p3sM 9swaE4tyqL2UOJEIHjlv2PJfzetpqEf4f8IvOZCypTZTdmanLbINC48uA/a/coRa3R1u 4JbQ== X-Gm-Message-State: AGRZ1gKTSvwdTnML1XF5EBRBvpLrZ45ly+cK2z5SUEh9I3fzjn73NrtQ CwvvluJ4+qYrkN2UPoGZIiBH9g== X-Google-Smtp-Source: AJdET5fEUFYsOrWhggAIBt5LpnTwfSWI4BpkgRXA8eV3TdOGoYjbhoMyKq8WcjAiYnztQIGPRxPX7Q== X-Received: by 2002:a62:995c:: with SMTP id d89-v6mr8169321pfe.11.1542318483718; Thu, 15 Nov 2018 13:48:03 -0800 (PST) Received: from localhost ([122.177.154.119]) by smtp.gmail.com with ESMTPSA id z7sm17940256pga.6.2018.11.15.13.48.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Nov 2018 13:48:02 -0800 (PST) From: Bhupesh Sharma To: linux-kernel@vger.kernel.org Subject: [PATCH v2] x86_64, vmcoreinfo: Append 'page_offset_base' to vmcoreinfo Date: Fri, 16 Nov 2018 03:17:49 +0530 Message-Id: <1542318469-13699-1-git-send-email-bhsharma@redhat.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181115_164816_525655_AA39CC9F X-CRM114-Status: GOOD ( 25.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kazuhito Hagio , James Morse , Baoquan He , bhsharma@redhat.com, x86@kernel.org, kexec@lists.infradead.org, Omar Sandoval , Boris Petkov , Dave Anderson , Thomas Gleixner , bhupesh.linux@gmail.com, Ingo Molnar , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP x86_64 kernel uses 'page_offset_base' variable to point to the start of direct mapping of all physical memory. This variable is also updated for KASLR boot cases, so this can be exported via vmcoreinfo as a standard ABI between kernel and user-space, to allow user-space utilities to use the same for calculating the start of direct mapping of all physical memory. 'arch/x86/kernel/head64.c' sets the same as: unsigned long page_offset_base __ro_after_init = __PAGE_OFFSET_BASE_L4; and also uses the same to indicate the base of KASLR regions on x86_64: static __initdata struct kaslr_memory_region { unsigned long *base; unsigned long size_tb; } kaslr_regions[] = { { &page_offset_base, 0 }, .. snip .. Adding 'page_offset_base' to the vmcoreinfo can be specially useful for live-debugging of a running kernel via user-space utilities like makedumpfile (see [1]). Recently, I saw an issue with the 'makedumpfile' utility (see [2] for details), whose live debugging feature is broken with newer kernels (I tested the same with 4.19-rc8+ kernel), as KCORE_REMAP segments were added to kcore, thus leading to an additional sections in the same, and makedumpfile is not longer able to determine the start of direct mapping of all physical memory, as it relies on traversing the PT_LOAD segments inside kcore and using the last PT_LOAD segment to determine the start of direct mapping. Such user-space issues can be resolved if the user-space code instead uses a standard ABI to read the kernel exposed machine specific variables. With the kernel commit 23c85094fe1895caefdd ["proc/kcore: add vmcoreinfo note to /proc/kcore"]), it is now possible to use the vmcoreinfo present inside kcore as the standard ABI which can be used by the user-space utilities for reading the machine specific information (and hence for debugging a live kernel). User-space utilities like makedumpfile, kexec-tools and crash are either already using this ABI or are discussing patches which look to add the same feature. This helps in simplifying the overall code and also in reducing code-rewrite across the user-space utilities for getting values of these kernel symbols/variables. Accordingly this patch allows appending 'page_offset_base' for x86_64 platforms to vmcoreinfo, so that user-space tools can use the same as a standard interface to determine the start of direct mapping of all physical memory. Testing: ------- - I tested this patch (rebased on 'linux-next') on a x86_64 machine using the modified 'makedumpfile' user-space code (see [3] for my github tree which contains the same) for determining how many pages are dumpable when different dump_level is specified (which is one use-case of live-debugging via 'makedumpfile'). - I tested both the KASLR and non-KASLR boot cases with this patch. - Here is one sample log (for KASLR boot case) on my x86_64 machine: < snip..> The kernel doesn't support mmap(),read() will be used instead. TYPE PAGES EXCLUDABLE DESCRIPTION ---------------------------------------------------------------------- ZERO 21299 yes Pages filled with zero NON_PRI_CACHE 91785 yes Cache pages without private flag PRI_CACHE 1 yes Cache pages with private flag USER 14057 yes User process pages FREE 740346 yes Free pages KERN_DATA 58152 no Dumpable kernel data page size: 4096 Total pages on system: 925640 Total size on system: 3791421440 Byte [1]. MAN pages -> MAKEDUMPFILE(8) and CRASH(8) [2]. makedumpfile issue with latest kernels -> http://lists.infradead.org/pipermail/kexec/2018-October/021769.html [3]. https://github.com/bhupesh-sharma/makedumpfile/tree/add-page-offset-base-to-vmcore-v1 Cc: Boris Petkov Cc: Baoquan He Cc: Ingo Molnar Cc: Thomas Gleixner Cc: Kazuhito Hagio Cc: Dave Anderson Cc: James Morse Cc: Omar Sandoval Cc: x86@kernel.org Cc: kexec@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Bhupesh Sharma --- Changes since v1: - Fixed the build issue reported by build bot and tested this version with 'make allmodconfig'. - Reworded most of the commit log to explain the intent behind the patch. arch/x86/kernel/machine_kexec_64.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c index 4c8acdfdc5a7..6161d77c5bfb 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -356,6 +356,9 @@ void arch_crash_save_vmcoreinfo(void) VMCOREINFO_SYMBOL(init_top_pgt); vmcoreinfo_append_str("NUMBER(pgtable_l5_enabled)=%d\n", pgtable_l5_enabled()); +#ifdef CONFIG_RANDOMIZE_BASE + VMCOREINFO_NUMBER(page_offset_base); +#endif #ifdef CONFIG_NUMA VMCOREINFO_SYMBOL(node_data);