From patchwork Wed Feb 1 09:13:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 4805 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp171354wrn; Wed, 1 Feb 2023 01:23:19 -0800 (PST) X-Google-Smtp-Source: AK7set9SvzhL/edF0krc0l1NYdA3wCVcSoDzzApYEpOcM9euP3Yp1yBf4A1vCYJNflkrdhlaJFLH X-Received: by 2002:a17:906:2a0d:b0:878:7819:b8c3 with SMTP id j13-20020a1709062a0d00b008787819b8c3mr1412734eje.46.1675243399707; Wed, 01 Feb 2023 01:23:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675243399; cv=none; d=google.com; s=arc-20160816; b=BPp2CaCILPxdHOgIwnnt4jUn9jG0D4FoHAippEbn3+TnQNh7BNln4qbD43Uk3dB8PD 63L1u5ahdCyEsKInsWdwU5H50ssNMTriBGo3JeAfy6PsUw2waXxXK8lAH5KlN7SjAemz FRDHYlP9OCmY0FfutqiQ0jQhNOIV9zhIR49I+mO5mkcKSy29+wTywAg6cJYUP6dcKAgW Ckn3m8SeWgj21aUAa8BSiLGe9pRz6t5FQQvG3kNMmtVZS9lCqgP6aOvW6mZw7UMOXYRN y8X3gqJeQKi+BKCnkBH4mcs5/+gKh3KM1X1Uh9qf21wj4fGMJISLAD/3DMggHn/a8ABz zJAQ== 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=fJF72Zd85F4nvkHLPmd4ED2J4KvlszW2tzIwzQ+dNaM=; b=HEfgmH2P+d7/edcEvJchsouBbU5XgAXl0ZemTc/tRkpgu/ewT8L+0NkO54x78lLP0R hAtJrAF9xfgdmQoU3IhkqX+ClHFzr8efICuyEhnrW3dydMN6JPOW03SH6hU1i6zSFf9A Fe8hgbAdHAjRi+fpYP8y6DiMMRzYysWJjFviFNsMtoY3bIKfaHLZezc8h9fodHr6Dgr+ MCrLjhmLYGRjHXdbgPdDQY8+NEWsMi3r0LtEx6GDZxwLFlXPxeRfoQD+2jd2lTzNJnz3 N8ihQtuXYZplR82VWRO/hLwrxCTsQJI44BZNGD9b8NC4Sizrfay5NOL00YrwtIJ4hUER gtKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="guO/EpD/"; 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 gh32-20020a1709073c2000b008787bdc9990si15871807ejc.529.2023.02.01.01.22.55; Wed, 01 Feb 2023 01:23:19 -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="guO/EpD/"; 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 S231897AbjBAJOd (ORCPT + 99 others); Wed, 1 Feb 2023 04:14:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230189AbjBAJOb (ORCPT ); Wed, 1 Feb 2023 04:14:31 -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 1C68D199D7 for ; Wed, 1 Feb 2023 01:13:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675242828; 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=fJF72Zd85F4nvkHLPmd4ED2J4KvlszW2tzIwzQ+dNaM=; b=guO/EpD/CGu0zjxE3nrsowZCZ/wDZ8Pi9Uy1CMSevKv3vuPObGFHUUPQ9dHwmCSJUADbUI A0lQRG1/vEsfpyZBSl3WXkywdyEhYRM5WaCeHazIbM52iO8A33JG6yruRS2IE1sXim0d5h Rvln5KmgwvSRi6HFQJE1qUDdB+gRhjI= 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-659-qnPyJGJvPkuZbXLpej_Qrg-1; Wed, 01 Feb 2023 04:13:47 -0500 X-MC-Unique: qnPyJGJvPkuZbXLpej_Qrg-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 83D50800B23; Wed, 1 Feb 2023 09:13:46 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-13-89.pek2.redhat.com [10.72.13.89]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00D79492C3E; Wed, 1 Feb 2023 09:13:41 +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, lstoakes@gmail.com, willy@infradead.org, hch@infradead.org, error27@gmail.com, Baoquan He Subject: [PATCH v4 0/7] mm/vmalloc.c: allow vread() to read out vm_map_ram areas Date: Wed, 1 Feb 2023 17:13:32 +0800 Message-Id: <20230201091339.61761-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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?1756620023553150414?= X-GMAIL-MSGID: =?utf-8?q?1756620023553150414?= 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 commands to access kcore file to do statistics: makedumpfile --mem-usage /proc/kcore Changelog *** v3->v4: - Fix typo in pach 2 catched by Lorenzo. - Add WARN_ON(flags == VMAP_BLOCK) in vread() to address Dan's concern that VMAP_BLOCK could be set alone in vmap->flags. - Add checking on the returned value from xa_load() in vmap_ram_vread(), Uladzislau commented on the risk of this place. - Fix a bug in s_show() which is changed in patch 5. The old change will cause 'va->vm is NULL but the VMAP_RAM flag is not set' case wrongly handled. Please see below link for details. - https://lore.kernel.org/all/Y8aAmuUY9OxrYlLm@kili/T/#u - Add Uladzislau and Lorenzo's Reviewed-by. 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 | 126 ++++++++++++++++++++++++++++++----- 4 files changed, 111 insertions(+), 20 deletions(-) Tested-by: Stephen Brennan