From patchwork Fri Oct 26 22:43:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupesh Sharma X-Patchwork-Id: 10657933 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 04A8714E2 for ; Fri, 26 Oct 2018 22:43:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E48B92C9D5 for ; Fri, 26 Oct 2018 22:43:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D2C952C9FD; Fri, 26 Oct 2018 22:43:56 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE 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 024352C9D5 for ; Fri, 26 Oct 2018 22:43:55 +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=CqcZ3q38wxKxG1z1lvnunvdojHuhvX0d13ru5znbOYY=; b=m2m BU+suQFFKl9ChpEjOPCK3ckLoYEoB13DP+WjsrylvjqRqJbf6DhW3Owm+Ppm9rP7sc1NNygT3m6vP 1LHmtdV6pwzGBiauQBd4GK+nP5BtV9AY+iovdwMNH19X8Qv3S6ifKhK9Fd2A0YouKfuZKwW2LKBig w0wG4Py7u7/uQOLlEZ8fdR02zLp0XHYxfvTy6RXwmGUeKhBHKLz3YyAq6owa3vZSU90JtdwhQWa5O hh3LUlpSeC8A5+RIHH5KNBXvc2bOoV2Ag+tfUh56edck7ktYGnJDFnDf/t3cby8hHoTHxST4XYrJ0 /dwnVLV40fLnTaiOQ5fQmu0fdlHsLKQ==; 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 1gGApc-00066J-MX; Fri, 26 Oct 2018 22:43:52 +0000 Received: from mail-pf1-f194.google.com ([209.85.210.194]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gGApX-0005u0-Cq for linux-arm-kernel@lists.infradead.org; Fri, 26 Oct 2018 22:43:50 +0000 Received: by mail-pf1-f194.google.com with SMTP id r64-v6so1195866pfb.13 for ; Fri, 26 Oct 2018 15:43:37 -0700 (PDT) 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=blV1uJceTF8g3thIB+bJ4AMvV9RpGbBxHFqhV8wcVWY=; b=l2/GBDduMDVvHKINvJP3Og0Qx3eezXJ4081gULl3WD/FMpgVe92YAibXz3XAKKTeZW 3gU+O0f7jYGWwG6DsDE+92idjOXm0h0D1w0wUA1Ga6hKH95ZMmDT79V4g9TYx5gll81P 29MGTdLVdm5M/+LYZvIIiGnmwNkVUA4w2jgEoNCZ2KF5bYWPffADi9qSxC5Cath1Km1c EFd8TZCnsLfHmKd+tHl/VRCQZV4DolvWc7MDH0VTmzGwi0hxoU25yEhltymStvNVsxM3 MfJPZ3jC1pCF7A46o+WyDJxrPi3ollFIQTBT+ZYhYGrYVie7feN4oCODEVCjJxsK+T7a rcNQ== X-Gm-Message-State: AGRZ1gKZXKTFLaLS2vKnV/qy9Qr8RL+kBKE6iRws7tVOJiAZOt0iScYm XC+daLH+2MbJtZyMda66qb/DwA== X-Google-Smtp-Source: AJdET5e/bcKInsqnrhbi4oNxCzrdVQL6r76ZUq3UwC1E3h4qD235BEcrSC8W9E+hJtUxYqjVUVZByg== X-Received: by 2002:a62:9316:: with SMTP id b22-v6mr5756155pfe.193.1540593816503; Fri, 26 Oct 2018 15:43:36 -0700 (PDT) Received: from localhost ([182.69.238.40]) by smtp.gmail.com with ESMTPSA id c14-v6sm12860976pfc.92.2018.10.26.15.43.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Oct 2018 15:43:35 -0700 (PDT) From: Bhupesh Sharma To: linux-kernel@vger.kernel.org Subject: [PATCH] x86_64, vmcoreinfo: Append 'page_offset_base' to vmcoreinfo Date: Sat, 27 Oct 2018 04:13:08 +0530 Message-Id: <1540593788-28181-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-20181026_154347_453114_E3943376 X-CRM114-Status: GOOD ( 17.65 ) 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 Since commit 23c85094fe1895caefdd ["proc/kcore: add vmcoreinfo note to /proc/kcore"]), '/proc/kcore' contains a new PT_NOTE which carries the VMCOREINFO information. If the same is available, one can use it in user-land to retrieve machine specific symbols or strings being appended to the vmcoreinfo even for live-debugging of the primary kernel as a standard interface exposed by kernel for sharing machine specific details with the user-land. In the past I had a discussion with James, where he suggested this approach (please see [0]) and I really liked the idea. Since then I have been working on unifying the implementations of (atleast) the commonly used user-space utilities that provide live-debugging capabilities (tools like 'makedumpfile' and 'crash-utility', see [1] for details of these tools). For the same, when live debugging on x86_64 machines, user-space tools currently rely on different mechanisms to determine the 'page_offset_base' value (i.e. start of direct mapping of all physical memory). One of the approach used by 'makedumpfile' user-space tool for e.g. is to calculate the same from the last PT_LOAD available in '/proc/kcore', which can be flaky as and when new sections (for e.g. KCORE_REMAP which was added to recent kernels) are added to kcore. For other architectures like arm64, I have already proposed using the vmcoreinfo note (in '/proc/kcore') in the user-space utilities to determine machine specific details like VA_BITS, PAGE_OFFSET, kasrl_offset() (see [2] for details), for which different user-space tools earlier used different (and at times flaky) approaches like: - Reading kernel CONFIGs from user-space and determining CONFIG values like VA_BITS from there. - Reading symbols from '/proc/kallsyms' and determining their values via '/dev/mem' interface. - Reading symbols from 'vmlinux' and determing their values from reading memory. 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 I understand that there might be some reservations about exporting such machine-specific details in the vmcoreinfo, but to unify the implementations across user-land and archs, perhaps this would be good starting point to start a discussion. [0]. https://www.mail-archive.com/kexec@lists.infradead.org/msg20300.html [1]. MAN pages -> MAKEDUMPFILE(8) and CRASH(8) [2]. https://www.spinics.net/lists/kexec/msg21608.html http://lists.infradead.org/pipermail/kexec/2018-October/021725.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 --- arch/x86/kernel/machine_kexec_64.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c index 4c8acdfdc5a7..834ccefef867 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -356,6 +356,7 @@ void arch_crash_save_vmcoreinfo(void) VMCOREINFO_SYMBOL(init_top_pgt); vmcoreinfo_append_str("NUMBER(pgtable_l5_enabled)=%d\n", pgtable_l5_enabled()); + VMCOREINFO_NUMBER(page_offset_base); #ifdef CONFIG_NUMA VMCOREINFO_SYMBOL(node_data);