From patchwork Fri Jan 13 03:19:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13099673 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 B2AB4C54EBE for ; Fri, 13 Jan 2023 03:19:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0B3218E0002; Thu, 12 Jan 2023 22:19:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 064018E0001; Thu, 12 Jan 2023 22:19:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6CF18E0002; Thu, 12 Jan 2023 22:19:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D76AD8E0001 for ; Thu, 12 Jan 2023 22:19:39 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B09B0160152 for ; Fri, 13 Jan 2023 03:19:39 +0000 (UTC) X-FDA: 80348320878.04.C61146D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 70C2340010 for ; Fri, 13 Jan 2023 03:19:37 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YANmIHQF; spf=pass (imf12.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=1673579978; 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=heSo2zYyjsWra8J2esyq7BRIle6U3yRJN+38qcrwJ7Y=; b=oirnuiE9Y2jkBAshNetuuyDRxzvXtv7bmItm6IWvPu7ONYfxNewXkJaHIMFUdEfGEa+YTH zvNOYIUcf66ZF9iNy1EDZSnUBVudm28MmvSSa7rvh0SlmyQs/n5ZUvdYdnzPHgtVFFtOwa /uAgeEj1ENtrxDcNUDAy4blIdEh7uuI= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YANmIHQF; spf=pass (imf12.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673579978; a=rsa-sha256; cv=none; b=FYexDkrR0hzvmMqAWxlr4nP57W0BUJlKzthVKG4Ky4ZfGEqnKkqAwVSuon3x6NTKw+rR0q jXkthPzkkpVupgBjQO1zoXFTYs9aArnO6tMPD+rMEXRH8aVKo4HyKxOpOUnILzJMPNS7JM u92TicVwvn6DftTf6iTeIEcFZQFSi7E= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673579977; 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=heSo2zYyjsWra8J2esyq7BRIle6U3yRJN+38qcrwJ7Y=; b=YANmIHQFbrFph0gRb+8aRcBzW7q/e3vLqXc7oZt+9w+dhFU7KvKAOXW9NLvHlUlk61JvYl eaE10kCHVj/hGufXuX48KPwPKQCD1nbZ1+889sCS3dkqW0+WJLCJDcxTef93csOb72BemI 4I8/VJwYxQG76SlNx+DNkpyh6njiC7Q= 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-175-O1TZpb1QMjSPeoEQH3OjOA-1; Thu, 12 Jan 2023 22:19:33 -0500 X-MC-Unique: O1TZpb1QMjSPeoEQH3OjOA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0CF36811E6E; Fri, 13 Jan 2023 03:19:33 +0000 (UTC) Received: from fedora.redhat.com (ovpn-12-229.pek2.redhat.com [10.72.12.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3891C4078903; Fri, 13 Jan 2023 03:19:25 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, urezki@gmail.com, lstoakes@gmail.com, stephen.s.brennan@oracle.com, willy@infradead.org, akpm@linux-foundation.org, hch@infradead.org, Baoquan He Subject: [PATCH v3 0/7] mm/vmalloc.c: allow vread() to read out vm_map_ram areas Date: Fri, 13 Jan 2023 11:19:14 +0800 Message-Id: <20230113031921.64716-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 70C2340010 X-Rspam-User: X-Stat-Signature: psc6gafw8jen58grtj6s3j58iqu9j4uk X-HE-Tag: 1673579977-746552 X-HE-Meta: U2FsdGVkX1+UTDRiKUUmAUiYUKMYeb/XSysl+lRq2TmUkBs+m7VcwwBenwD0qb093jZI6y9fu3rwIQLCUPC4x3pY9jxOTnhA83ngWP+hcqzqzTb7OZGyjTkBxXpquWO/AV/3mk8yJXWAofj53wJCFYZS0fyBFhOldszu7T2O2NwjuZUO8sr95nJpevtTg5D3oXaNQjBTPlB2cEXPtMQbzxHgLkor2MCfjXLiD4X62nGFjlZl/NO0kszH3QuPunvnfUctHxio3tOoprJYWfDv82Cqz6BZqQpU7eH0TGiT2nO4sT2l4ouGv7lhSyETRGuFKT7XYHht9by+XSQoL0dJgI45gsQELEYt/K7004wMlhIUcVE2t+EzdJu0rAN4PzlGy4nhZM1PyKRUdaFwL3S8suCRMABll397jrflHz8DBCWK4UrILg2UBRd1jUddcoMGW3v9E8S9gQK6eYbdnFG8KkRUV9pYOZp+fsfj3CUTAHYLLJIcCw0/t+3lN5jibe9/D2ir/9dvIv2d5jVR9rucAqwD0B9NNouK+7qmREZRINtEAYvRMSbzAG+cIbEspJ//7FTeIOm9cixHWc9IzYlQqWM3l+98qWDjo1ZTffzzsLgFtdlgPQYsh/1ndClmfCn2fNAYHIHfdh5jK0Ig0fYBZokYnclsc24l75i/sg6ye3+R1SLjlM4MDphE28VUCDy/E6eNGltEuVNWgYYiq+x8FdhJfq0o2aGi0YnnqTc5dH97wa90TDD9dtFMf/XteQE3vbUQgq35qaLMpW/pZqDAoDiFG78IE7niVBNqCxGIdquslEYOfrdUJwLU4tH1pmBFmh38lMETibqMEz3kgYdBH6a8vCZCEe3G5iw+T8NMNqqJu+pBHAFLwmaAog1SrRzJcMWk8jgCqfg9aoypy+4PtuMdJbiKr3+y9ZDLB+5nWU7z+eOOMqre278C6ms0kT0uNlLYqqpGtQrej8HZ8Bc Feg== 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 details. /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 pass out. However, area reserved through vm_map_ram() interface doesn't allocate vm_struct to associate with. So the current code in vread() will skip the vm_map_ram area through 'if (!va->vm)' conditional checking. Solution: *** To mark the area reserved through vm_map_ram() interface, add field 'flags' into struct vmap_area. Bit 0 indicates this is vm_map_ram area created through vm_map_ram() interface, bit 1 marks out the type of vm_map_ram area which makes use of vmap_block to manage split regions via vb_alloc/free(). And also add bitmap field 'used_map' into struct vmap_block to mark those further subdivided regions being used to differentiate with dirty and free regions in vmap_block. With the help of above vmap_area->flags and vmap_block->used_map, we can recognize and handle vm_map_ram areas successfully. All these are done in patch 1~3. Meanwhile, do some improvement on areas related to vm_map_ram areas in patch 4, 5. And also change area flag from VM_ALLOC to VM_IOREMAP in patch 6, 7 because this will show them as 'ioremap' in /proc/vmallocinfo, and exclude them from /proc/kcore. Testing *** Only did the basic testing on kvm guest, and run below command to access kcore file to do statistics: makedumpfile --mem-usage /proc/kcore Changelog *** v2->v3: - Benefited from find_unlink_vmap_area() introduced by Uladzislau, do not need to worry about the va->vm and va->flags reset during freeing. - Change to identify vm_map_area with VMAP_RAM in vmap->flags in vread(). - Rename the old vb_vread() to vmap_ram_vread(). - Handle two kinds of vm_map_area area reading in vmap_ram_vread() respectively. - Fix bug of the while loop code block in vmap_block reading, found by Lorenzo. - Improve conditional check related to vm_map_ram area, suggested by Lorenzo. v1->v2: - Change alloc_vmap_area() to pass in va_flags so that we can pass and set vmap_area->flags for vm_map_ram area. With this, no extra action need be added to acquire vmap_area_lock when doing the vmap_area->flags setting. Uladzislau reviewed v1 and pointed out the issue. - Improve vb_vread() to cover the case where reading is started from a dirty or free region. RFC->v1: - Add a new field flags in vmap_area to mark vm_map_ram area. It cold be risky reusing the vm union in vmap_area in RFC. I will consider reusing the union in vmap_area to save memory later. Now just take the simpler way to let's focus on resolving the main problem. - Add patch 4~7 for optimization. Baoquan He (7): 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 mm/vmalloc: explicitly identify vm_map_ram area when shown in /proc/vmcoreinfo mm/vmalloc: skip the uninitilized vmalloc areas powerpc: mm: add VM_IOREMAP flag to the vmalloc area sh: mm: set VM_IOREMAP flag to the vmalloc area arch/powerpc/kernel/pci_64.c | 2 +- arch/sh/kernel/cpu/sh4/sq.c | 2 +- include/linux/vmalloc.h | 1 + mm/vmalloc.c | 114 ++++++++++++++++++++++++++++++----- 4 files changed, 101 insertions(+), 18 deletions(-)