From patchwork Wed Nov 9 03:35:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13037132 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FCB5C4332F for ; Wed, 9 Nov 2022 03:36:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 692ED6B0072; Tue, 8 Nov 2022 22:36:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 643246B0073; Tue, 8 Nov 2022 22:36:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50B6E8E0001; Tue, 8 Nov 2022 22:36:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3CA7D6B0072 for ; Tue, 8 Nov 2022 22:36:43 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 16C0880B1D for ; Wed, 9 Nov 2022 03:36:43 +0000 (UTC) X-FDA: 80112491886.03.50C0437 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id C23DB40010 for ; Wed, 9 Nov 2022 03:36:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667964946; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iF0b5s+98G4TrJkekhHZ+dOQgcRNsa+t4EO2IaaGQDs=; b=fSDo503j29NBLSK14BwRuHOj5F0Z/bi/DDAApO9WXG1tYItRH02+0Y9L+I/atx1GHprbdK pJoofuYL0PG63+rzZI98MVpIUNg1/SXsaVpiX4/qW8pAzen+lpSQ3N/FXykSFF//q7Rjl2 dgFQ1GJ8RG6ByWEh/pNTd40oabrKp0E= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-343-Sgm9KCncMEipjdTeGIl6GQ-1; Tue, 08 Nov 2022 22:35:42 -0500 X-MC-Unique: Sgm9KCncMEipjdTeGIl6GQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 14B98101A528; Wed, 9 Nov 2022 03:35:42 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-86.pek2.redhat.com [10.72.12.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C33B10197; Wed, 9 Nov 2022 03:35:37 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, stephen.s.brennan@oracle.com, urezki@gmail.com, hch@infradead.org, Baoquan He Subject: [PATCH RFC 0/3] mm/vmalloc.c: allow vread() to read out vm_map_ram areas Date: Wed, 9 Nov 2022 11:35:31 +0800 Message-Id: <20221109033535.269229-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667964997; a=rsa-sha256; cv=none; b=X+6eK/LTDKZ8g3hNwMCHAorLjkxJAJ3LtBdGP5c7nXxygNPggx0bncvvYiW0oToiikiKJX auTTpxLDtdjejdxA1LDkr+wCNF2Co1FbGKMQFsL/aYeQ2ljEbx00BIXBEur8T7dk14VnUM qjNWei85nASZ1JjihXD9nF3Io8RstdQ= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fSDo503j; spf=pass (imf04.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667964997; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=iF0b5s+98G4TrJkekhHZ+dOQgcRNsa+t4EO2IaaGQDs=; b=pwvBsl4jSXZA7cCHkp4LSdLbtnAp+QbztMRRRK7ucX9At4I0MwuS8uPIoGe5oW6fR78MQF p1Yc4t1P9wtq17zZFzuBe/iPUWPua38ePhM7t9WqTXl4jSU+PtdccXFEVZJpAZwmNmzpYa 6Lng7PXGcjUY7dkFTHD3prSnpC0qekg= Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fSDo503j; spf=pass (imf04.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: 3agr7ds3wn6jk4fu8fwhgqrszpmtc63g X-Rspamd-Queue-Id: C23DB40010 X-HE-Tag: 1667964997-819555 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Problem: *** Stephen reported vread() will skip vm_map_ram areas when reading out /proc/kcore with drgn utility. Please see below link to get more about it: /proc/kcore reads 0's for vmap_block https://lore.kernel.org/all/87ilk6gos2.fsf@oracle.com/T/#u Root cause: *** The normal vmalloc API uses struct vmap_area to manage the virtual kernel area allocated and associate a vm_struct to store more information and passed out. However, area reserved through vm_map_ram() interface doesn't allocate vm_struct to bind with. So the current code in vread() will skip the vm_map_ram area by 'if (!va->vm)' conditional checking. Solution: *** There are two types of vm_map_ram area. One is the whole vmap_area being reserved and mapped at one time; the other is the whole vmap_area with VMAP_BLOCK_SIZE size being reserved at one time, while mapped into split regions with smaller size several times. In patch 1 and 2, add flags into struct vmap_area to mark these two types of vm_map_ram area, meanwhile add bitmap field used_map into struct vmap_block to mark those regions being used to differentiate with dirty and free regions. With the help of above vmap_area->flags and vmap_block->used_map, we can recognize them in vread() and handle them respectively. Test: *** I don't know what system has vm_map_ram() area. So just pass compiling test and execute "makedumpfile --mem-usage /proc/kcore" to guarantee it won't impact the old kcore reading. [root@ibm-x3950x6-01 ~]# free -h total used free shared buff/cache available Mem: 3.9Ti 3.6Gi 3.9Ti 7.0Mi 497Mi 3.9Ti Swap: 8.0Gi 0B 8.0Gi [root@ibm-x3950x6-01 ~]# makedumpfile --mem-usage /proc/kcore The kernel version is not supported. The makedumpfile operation may be incomplete. TYPE PAGES EXCLUDABLE DESCRIPTION ---------------------------------------------------------------------- ZERO 327309 yes Pages filled with zero NON_PRI_CACHE 81750 yes Cache pages without private flag PRI_CACHE 83981 yes Cache pages with private flag USER 12735 yes User process pages FREE 1055688908 yes Free pages KERN_DATA 17464385 no Dumpable kernel data page size: 4096 Total pages on system: 1073659068 Total size on system: 4397707542528 Byte Baoquan He (3): mm/vmalloc.c: add used_map into vmap_block to track space of vmap_block mm/vmalloc.c: add flags to mark vm_map_ram area mm/vmalloc.c: allow vread() to read out vm_map_ram areas include/linux/vmalloc.h | 1 + mm/vmalloc.c | 81 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 75 insertions(+), 7 deletions(-)