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: 1365 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp122060wru; Tue, 8 Nov 2022 19:45:31 -0800 (PST) X-Google-Smtp-Source: AMsMyM5oYNjmi3IC2BQYXc3k0rvF47txCweBLOZ+AS3p0P5Rar65x0qC9E/G3jzACFsBqK97CQLI X-Received: by 2002:a62:8141:0:b0:56b:c435:f003 with SMTP id t62-20020a628141000000b0056bc435f003mr59237942pfd.15.1667965531131; Tue, 08 Nov 2022 19:45:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667965531; cv=none; d=google.com; s=arc-20160816; b=YKt/3bEMYZXRMlNOAtCJhxM5CkjHkuta3DENMMqf5OzM9PoRbCPlU9jxZkEYUi33w2 IGlPtewTPsqPitXWZFo47nYbDs7DXuKKvL54GqfTxRbvqAibXXX4yI5a79XopvrWl2ah TLtdKWY1krwTZm6SA5EhAR3DhgtZV7Skf1TPVOCNGsRy+t2LIMBp3mSDFE8LbN+57uat 5w9CtvJ3avC8FKgouvfiOijtLzBAF1NFeVU1B7nzWq/YeKwIc2G2RHA6RApqjgEDA4uA l5kkK4Pgapc27UpPw0ZqzT4nnMN/BfaysSt0l/6+NkuLYW1boWt4UJNa6Z3dfkdewuST PVGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=iF0b5s+98G4TrJkekhHZ+dOQgcRNsa+t4EO2IaaGQDs=; b=fZd9I8hRH/6CHHO456Szn+gD/1hWtMfpKmG2Es9h1heBDWTTuGHBGBUmLxbuB3I4F8 5q3WfwczmiMyj3bov8NsOx5XXRwgx0oDBgKe1q8Qs8SeBzBQP7queDEm/W2yX+J1L/op MMZ6lY+oBHy3LY1QYg351xurpnH+gGEbusP7CaM8t/7o/3x03DtWslN/E+P31gbOFzwt Mtfu93dyb6LpH+7R2EZ/2VowekIOUMGaXfcFhD2yhP5lENw0UsnmC4f+ratmRfpDySBi g11j5RGhL00/WkuUBp8y/FZeS9VVMBFfJht8YeyZkcsjnL+J2bnQxX3KTo1pgw6FhG7d 2kYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eR125MQm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l23-20020a17090b079700b00212fb7e54ddsi178715pjz.81.2022.11.08.19.45.16; Tue, 08 Nov 2022 19:45:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eR125MQm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230216AbiKIDgn (ORCPT + 99 others); Tue, 8 Nov 2022 22:36:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229995AbiKIDgj (ORCPT ); Tue, 8 Nov 2022 22:36:39 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2D6C10EF for ; Tue, 8 Nov 2022 19:35:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667964945; 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=eR125MQmuJgx7Cyp7Wadha+T2RJ6LdUhev3C/Vj5uWsTolWQL65AcZB9XCcZ8T/nGOH6gM OSBWJsJvu8sVRqH5KKZ9bDBGyXX6BRq3fFNLbgXyRGbgj1XmoBZMekwU+2CX+ddJGv1eT/ bX1GkPqDcMjVzPYCODde2JZzBNJ2jKk= 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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748988624280395192?= X-GMAIL-MSGID: =?utf-8?q?1748988624280395192?= 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(-)