From patchwork Tue Jul 25 09:34:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?S3Vhbi1ZaW5nIExlZSAo5p2O5Yag56mOKQ==?= X-Patchwork-Id: 13326206 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 C9D79C0015E for ; Tue, 25 Jul 2023 09:36:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6248B8D0001; Tue, 25 Jul 2023 05:36:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D4336B0074; Tue, 25 Jul 2023 05:36:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49C768D0001; Tue, 25 Jul 2023 05:36:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3AFE96B0071 for ; Tue, 25 Jul 2023 05:36:23 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 07159A0CCD for ; Tue, 25 Jul 2023 09:36:23 +0000 (UTC) X-FDA: 81049628646.27.0BBDD10 Received: from mailgw02.mediatek.com (mailgw02.mediatek.com [216.200.240.185]) by imf11.hostedemail.com (Postfix) with ESMTP id B07A640023 for ; Tue, 25 Jul 2023 09:36:20 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=mediatek.com header.s=dk header.b="fPlH0fl/"; dmarc=pass (policy=quarantine) header.from=mediatek.com; spf=pass (imf11.hostedemail.com: domain of kuan-ying.lee@mediatek.com designates 216.200.240.185 as permitted sender) smtp.mailfrom=kuan-ying.lee@mediatek.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690277780; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zBOKlXR9UJkQg3cVyddpTc3TB9/Vh3QFP5WBjAxlAXs=; b=38iAF9NjXPwM67hEl5E2Qt5ONy1KIOIUMSiUWiTW1dckIQd9NrYwhETgujgFMGpWMs+Mdq fdZD1HAYog+zZujWEs/5nppQxj3zz3Do7/jZIvCdvzKc2bqV4sZVkxNeuisnsyr2FTbuQh oSN6GRyQb5CKDfxYUw+YI45YJ88us9o= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=mediatek.com header.s=dk header.b="fPlH0fl/"; dmarc=pass (policy=quarantine) header.from=mediatek.com; spf=pass (imf11.hostedemail.com: domain of kuan-ying.lee@mediatek.com designates 216.200.240.185 as permitted sender) smtp.mailfrom=kuan-ying.lee@mediatek.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690277780; a=rsa-sha256; cv=none; b=1UbokHO7/6d97bIyB2qmdmA5PalGp0T0iAZiXM21ihi9T6gYCDPhnnFIwSj+uthRyOcFMg a65ZIk2mZhaHejkHY3nlxARQo2HV3V60Jhnb+N9RKFhGQfNk4LzMpA7zJ7uAqLlofcpglp p+pC3M0JFdHIyOpM4ZX8t5t8lH+q7iY= X-UUID: b26bf33c2ace11ee83ed1395ce914268-20230725 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=zBOKlXR9UJkQg3cVyddpTc3TB9/Vh3QFP5WBjAxlAXs=; b=fPlH0fl/qK/fGTOx9MFJrjJiZlR3A0t9YsNDioJvnwp2GO4ZN7QyG5mRwfiuppgStkWVWsu2OL76dJ8x4MWckLGGX9I16baPksfg/73E58elmbBeZeYyoDodYnuyT7sed4sV1NQeRes80jiMrcce7ai/ILCtacwjnsZ1lmgInXk=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.29,REQID:b2863479-bc35-4836-924a-86ccbb8e5f48,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:e7562a7,CLOUDID:e8d2c3b3-a467-4aa9-9e04-f584452e3794,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|1,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR: NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULN X-UUID: b26bf33c2ace11ee83ed1395ce914268-20230725 Received: from mtkmbs13n2.mediatek.inc [(172.21.101.108)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1877638208; Tue, 25 Jul 2023 02:36:14 -0700 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 25 Jul 2023 17:35:44 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Tue, 25 Jul 2023 17:35:44 +0800 From: Kuan-Ying Lee To: Jan Kiszka , Kieran Bingham , Matthias Brugger , AngeloGioacchino Del Regno CC: , , , , , , , Kuan-Ying Lee , , , Subject: [PATCH 8/8] scripts/gdb/vmalloc: add vmallocinfo support Date: Tue, 25 Jul 2023 17:34:58 +0800 Message-ID: <20230725093458.30064-9-Kuan-Ying.Lee@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20230725093458.30064-1-Kuan-Ying.Lee@mediatek.com> References: <20230725093458.30064-1-Kuan-Ying.Lee@mediatek.com> MIME-Version: 1.0 X-MTK: N X-Rspamd-Queue-Id: B07A640023 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: ym7stcex6nz9on4waurg6ap1cbeabimn X-HE-Tag: 1690277780-847166 X-HE-Meta: U2FsdGVkX1/jjfM9oDxD069GHROcEi4/rXGMapOGsdI3NeaXpcYQeD8g0Q7KG3zJ/SS+kzOqFH35h711YmwKTSUckfzAKfYrv0dW/9qVTz5Cb3/CC3al/EE9wmnAkTOOXC4armL2JRXaAoWUqwXAKvam5Z/kGlljm88/Wiqwz1w+rLIgt6ke5G40Sx6dh7v0gjbPQUUHtKMl81T4B2r94X/MjE0PbVun71JcfX+AB9rYTlcz5T2apnaoYyMDblB1ddxw0jYj7ssgj20t9veVVN2498He6cmgfD90uoESO3LG/S5bKofzXOOJSHLX2hvJFfrMNdyCo8qlnHETpskm9TJrN8GR9/OF4taGJWE5StluvfC74NpACcfaFlu8w9wXi6KKKFAMP/SP/kcYLB+io53sSp+C3XqLjf7jD1/rogDHzclrfji+QjNqvuF+x1LL0F0bCjp1htVesIMnNgOiDHIlBlkMmOxeDu0iRAAD3eZ7dmELDJT+EE/s2yuLM5U1X9cVtukjlcNBZr5ui37gArwdplIdggA0j5qgWOqC3HK9aSz3vZ38gENI1PRiBVnNKP/3zYXlbszujDWIy5tPXDzR/a3SJsOa0YFGQPhg9uS8SJtkhKstRcQ1wDrIBvE/ksTImmbo6aedgsCnIwufCTLetyMzird54DQCGmtuYAFL90RAYxEWZ6cjt3OXUO310he+Phf3L6+XCQtvIkqSP4NCq0vLENtuuEvpb6UkbDg9ob1n/8WOKRZwzBuMxN03KXB5YFV6tFpf4ZSvn9gF9Ri8S2BNN4kJN2T2NV3EHXSY4rO7Rczsc3xjtRO2wdftJ3D5gQ89Brtj/qAmQj2Lh2BF6df2YrMHbcWhQZiuZQWMgLFeyyK/nXjmiv3wTTgd5GvBzfLwLb+IEp3uZf8xJj5svTwMKdbxSkqMqqp4W+0QN1BsnxGatyUtks3GGlHOlGICWZp5gOjhDRkmlSO IwxQ8toh WmmSVW5rn55i9TudlvVYTfP30/lkvTvFA1M35hfMk2ZKnlpI+vSCNxc3TH6agDiHZiKTEwG9S/F3JH29EF7/8uPXly+3ZZHEBwijrGYsius+9+Wn+BhfKFcQef0C79CNrU49mfelPXu7b3aeuAxtFW3xiQyX3uR0PAKj92mUOzt5i2dQlzXfv6DtFZ0m13uNBGvxBLq5vgz1tVwpI00+GCb4OZ+sIfFYR93yjkUjC7WKT7Jk2FTd2THfmdQ== 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: This GDB script shows the vmallocinfo for user to analyze the vmalloc memory usage. Example output: 0xffff800008000000-0xffff800008009000 36864 pages=8 vmalloc 0xffff800008009000-0xffff80000800b000 8192 phys=0x8020000 ioremap 0xffff80000800b000-0xffff80000800d000 8192 pages=1 vmalloc 0xffff80000800d000-0xffff80000800f000 8192 pages=1 vmalloc 0xffff800008010000-0xffff80000ad30000 47316992 phys=0x40210000 vmap 0xffff80000ad30000-0xffff80000c1c0000 21561344 phys=0x42f30000 vmap 0xffff80000c1c0000-0xffff80000c370000 1769472 phys=0x443c0000 vmap 0xffff80000c370000-0xffff80000de90000 28442624 phys=0x44570000 vmap 0xffff80000de90000-0xffff80000f4c1000 23269376 phys=0x46090000 vmap 0xffff80000f4c1000-0xffff80000f4c3000 8192 pages=1 vmalloc 0xffff80000f4c3000-0xffff80000f4c5000 8192 pages=1 vmalloc 0xffff80000f4c5000-0xffff80000f4c7000 8192 pages=1 vmalloc Signed-off-by: Kuan-Ying Lee --- scripts/gdb/linux/constants.py.in | 8 +++++ scripts/gdb/linux/vmalloc.py | 56 +++++++++++++++++++++++++++++++ scripts/gdb/vmlinux-gdb.py | 1 + 3 files changed, 65 insertions(+) create mode 100644 scripts/gdb/linux/vmalloc.py diff --git a/scripts/gdb/linux/constants.py.in b/scripts/gdb/linux/constants.py.in index fa23f4e3546a..3cf3c0b9eaea 100644 --- a/scripts/gdb/linux/constants.py.in +++ b/scripts/gdb/linux/constants.py.in @@ -22,6 +22,7 @@ #include #include #include +#include #include /* We need to stringify expanded macros so that they can be parsed */ @@ -96,6 +97,13 @@ if IS_BUILTIN(CONFIG_ARM64): LX_GDBPARSED(VA_BITS_MIN) LX_GDBPARSED(MODULES_VSIZE) +/* linux/vmalloc.h */ +LX_VALUE(VM_IOREMAP) +LX_VALUE(VM_ALLOC) +LX_VALUE(VM_MAP) +LX_VALUE(VM_USERMAP) +LX_VALUE(VM_DMA_COHERENT) + /* linux/page_ext.h */ LX_GDBPARSED(PAGE_EXT_OWNER) LX_GDBPARSED(PAGE_EXT_OWNER_ALLOCATED) diff --git a/scripts/gdb/linux/vmalloc.py b/scripts/gdb/linux/vmalloc.py new file mode 100644 index 000000000000..48e4a4fae7bb --- /dev/null +++ b/scripts/gdb/linux/vmalloc.py @@ -0,0 +1,56 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2023 MediaTek Inc. +# +# Authors: +# Kuan-Ying Lee +# + +import gdb +import re +from linux import lists, utils, stackdepot, constants, mm + +vmap_area_type = utils.CachedType('struct vmap_area') +vmap_area_ptr_type = vmap_area_type.get_type().pointer() + +def is_vmalloc_addr(x): + pg_ops = mm.page_ops().ops + addr = pg_ops.kasan_reset_tag(x) + return addr >= pg_ops.VMALLOC_START and addr < pg_ops.VMALLOC_END + +class LxVmallocInfo(gdb.Command): + """Show vmallocinfo""" + + def __init__(self): + super(LxVmallocInfo, self).__init__("lx-vmallocinfo", gdb.COMMAND_DATA) + + def invoke(self, arg, from_tty): + vmap_area_list = gdb.parse_and_eval('vmap_area_list') + for vmap_area in lists.list_for_each_entry(vmap_area_list, vmap_area_ptr_type, "list"): + if not vmap_area['vm']: + gdb.write("0x%x-0x%x %10d vm_map_ram\n" % (vmap_area['va_start'], vmap_area['va_end'], + vmap_area['va_end'] - vmap_area['va_start'])) + continue + v = vmap_area['vm'] + gdb.write("0x%x-0x%x %10d" % (v['addr'], v['addr'] + v['size'], v['size'])) + if v['caller']: + gdb.write(" %s" % str(v['caller']).split(' ')[-1]) + if v['nr_pages']: + gdb.write(" pages=%d" % v['nr_pages']) + if v['phys_addr']: + gdb.write(" phys=0x%x" % v['phys_addr']) + if v['flags'] & constants.LX_VM_IOREMAP: + gdb.write(" ioremap") + if v['flags'] & constants.LX_VM_ALLOC: + gdb.write(" vmalloc") + if v['flags'] & constants.LX_VM_MAP: + gdb.write(" vmap") + if v['flags'] & constants.LX_VM_USERMAP: + gdb.write(" user") + if v['flags'] & constants.LX_VM_DMA_COHERENT: + gdb.write(" dma-coherent") + if is_vmalloc_addr(v['pages']): + gdb.write(" vpages") + gdb.write("\n") + +LxVmallocInfo() diff --git a/scripts/gdb/vmlinux-gdb.py b/scripts/gdb/vmlinux-gdb.py index 2526364f31fd..fc53cdf286f1 100644 --- a/scripts/gdb/vmlinux-gdb.py +++ b/scripts/gdb/vmlinux-gdb.py @@ -48,3 +48,4 @@ else: import linux.stackdepot import linux.page_owner import linux.slab + import linux.vmalloc