From patchwork Sat Dec 17 01:54:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13075745 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 C5909C4332F for ; Sat, 17 Dec 2022 01:54:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0B6888E0002; Fri, 16 Dec 2022 20:54:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 067D48E0001; Fri, 16 Dec 2022 20:54:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E72528E0002; Fri, 16 Dec 2022 20:54:49 -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 D8FCD8E0001 for ; Fri, 16 Dec 2022 20:54:49 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B535EAB9BF for ; Sat, 17 Dec 2022 01:54:49 +0000 (UTC) X-FDA: 80250129498.16.2D784E2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf12.hostedemail.com (Postfix) with ESMTP id F3C3740002 for ; Sat, 17 Dec 2022 01:54:47 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fiZzwKbK; spf=pass (imf12.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.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=1671242088; a=rsa-sha256; cv=none; b=2p3hq0t1pg2LIXtGx2kriLr1qD+HCbYAYA7FDNKH31Kcbz8muRQvdPzlDNpIjsCG4Z+FSg yjS/eIPcnRCVqakr/QUih16ZXikKP3RMAPC5shjbqIGIDVNreJRUJ8dNINHlpKqRz0l1Gb 4SbAchORX7LfhGXwmtGsCS9GOxCnG3I= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fiZzwKbK; spf=pass (imf12.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.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=1671242088; 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=KlAUk4Rvv2uJ6My8k7MBoYVwmIEIsjetFKSoMLOi3Uk=; b=f/kOLYl1AFhleOLx0Ann/u+Le3TzWlYM0PPChyZJHqhiXYBcY5HhWFW0/pNccJ0zbERui5 tAbF1uLGwCUlShm2oPYZuWOYYw3cEfT2UbVOS+rUHo5PP6O52y5gDw6lvRp3CbEsYBbnVL +Xi3hX0bL5FTe5DkrzJhBKkcm+PrqT4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671242087; 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=KlAUk4Rvv2uJ6My8k7MBoYVwmIEIsjetFKSoMLOi3Uk=; b=fiZzwKbK7SH0qWwTwKC+fPVo+GiM1+3GBW3RCQd9/oP9DwwLZ2ctbDTr2g4GATzx3y1z5T YHOIiIU9LulyaOP21FToPpTK0a6qUS5GDXBGxGyuv/HHKjHh3zeG4oa/brKVcew19HQe/l LyFziE3uk0akXSXmmARf9k704TDiOSk= 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-422-Y2byrGHOOMmErGkLv8UWzQ-1; Fri, 16 Dec 2022 20:54:43 -0500 X-MC-Unique: Y2byrGHOOMmErGkLv8UWzQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 63378802C1C; Sat, 17 Dec 2022 01:54:43 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-34.pek2.redhat.com [10.72.12.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 572DA400F5B; Sat, 17 Dec 2022 01:54:38 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, urezki@gmail.com, stephen.s.brennan@oracle.com, willy@infradead.org, akpm@linux-foundation.org, hch@infradead.org, Baoquan He Subject: [PATCH v2 0/7] mm/vmalloc.c: allow vread() to read out vm_map_ram areas Date: Sat, 17 Dec 2022 09:54:28 +0800 Message-Id: <20221217015435.73889-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspam-User: X-Rspamd-Queue-Id: F3C3740002 X-Rspamd-Server: rspam01 X-Stat-Signature: isfkez7s4uefhxeh4mngqrdsh3thggm5 X-HE-Tag: 1671242087-729014 X-HE-Meta: U2FsdGVkX18hXBLV1y+9BSqgN2GVkHFFyni4sM/+eJkbbjWCNBoiqeeoPDznNjZTzfgvX9jt9LCZKqpHVb5dUO0D6SduP5UU+addWjAiFZgoUs7IGtHkIRf4ZAfFWkAXYLFExOf8b1FerYi2ksE/O5iYxXS4EcV0xWNxiY7nzcaSZueAR+bgeREilCssTK/xyRtcWG1oQI/AAWDG964nmSKCHmKNA1/kQ4p351k6xStza8zZUr6h8LQvBQQmy0Qgd9oxRZZIeaURqMPC/J/rV8yerYaaByN9AAvLU4Txbl+MmrHyY7SGEsRCi0I8wSH8uhVWstoR/Saf7NyH5fH87fAkyQ2wkAteWOKg7woSHjPv8VnKtV2pTwFZ8BBbYWe8PSVgkmfw5lKazvg7HQnJfgWUwi16K+wLLSzs54Ic7vtjPf9LKaoTVETCtXdbbNIytbb4+x6ELLB4ESxKr3fjMyZk/Oqcz9kGyoYKfMAGT/gCsP0M1Q7nWId6ZykIEpiv/G/VGyrRcE86Tt7BV9b9izCGsOl3a2zihaPwlZJH/3nggZBFqYuBH/gzteZkOYTnXDp6oNwwuL9d1M3GVle8k4GgjMzoyp3wQ5jjOYnfKp57Em0R0Niz9qc8+bcds9n3DYHAj/IWyDG6g8SF/GdMGiNELpw4fuFRmqrYcVl2lNU8UI7TNL2j1KuA7nkwcbFoQwMwRUx35wwXZCPSauz91sukGLO7HtgO8iHch9kcFPia1RI1netgjFWq6vQDp5mns6KDrMnboFu0vP5N21bBb5dpKi66yhY0IT0Rqx7FsPIIwp69YatS4NEZNEVQSerksRYvla65ZxpZ6Zvmu4tdVrNdxUhxYlUNxi3fufeAXU7IwoGkR5gbQic7FJpC6KjZtqHLyNalk9fIAM+BWaCj9XyJAVaHS2taXLPXkH/6Usd40Z761uCjBblZcE2Qj5vdJNCLNiIBY1/O6kw+0KJ o0A== 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 through '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 via vb_alloc(). I will call the 2nd type vb region. 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 vb 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 them in vread() and handle them respectively in patch 3. Besides, *** In patch 5, let's ignore vmap area with VM_UNINITIALIZED set in vm->flags, because this kind of area is created by calling __vmalloc_node_range(), VM_UNINITIALIZED set indicating it has vm_struct associated with, but is still during the page allocating and mapping process. In patch 6 and 7, change area flag from VM_ALLOC to VM_IOREMAP in two places. This will show them as 'ioremap' in /proc/vmallocinfo, and exclude them from /proc/kcore. Testing *** Only did the basic testing. Changelog *** 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 | 106 +++++++++++++++++++++++++++++------ 4 files changed, 92 insertions(+), 19 deletions(-)