From patchwork Thu Feb 2 01:41:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13125204 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 450E4C63797 for ; Thu, 2 Feb 2023 01:42:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA8586B007E; Wed, 1 Feb 2023 20:42:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D56AA6B0080; Wed, 1 Feb 2023 20:42:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF7B26B0081; Wed, 1 Feb 2023 20:42:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id AECFA6B007E for ; Wed, 1 Feb 2023 20:42:31 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 812CBAB51C for ; Thu, 2 Feb 2023 01:42:31 +0000 (UTC) X-FDA: 80420652102.19.573BF33 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf12.hostedemail.com (Postfix) with ESMTP id B316D4000F for ; Thu, 2 Feb 2023 01:42:28 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=iv03dHdB; spf=pass (imf12.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675302148; a=rsa-sha256; cv=none; b=mnyvzRP7avM8gWrXOi8Ii1h40qNttszdz1pKpsohJCKYw+MJFzicJa8yAh6nHunWmgKJWX A8FBEmIdstrfP4n288kUv3W4/QQTTqhokEsnD4WrxhDZelTAAXuksTHMmOhfW+td5QVjLu dUaXdNX7t1Z2K6irv6Z9CAjdK+HhFzU= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=iv03dHdB; spf=pass (imf12.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675302148; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=JYjNCZTedk1AJoVE/LTBpwn60v8SrzPue4uHPDh5wcE=; b=oGuNXhYYVixSyfycho0YAEj1J7rXXp9nsz7hyBnH7tM5IL5HGw0NBk7noqZtv8DPVetG2M akshh/eaWMxuks8gVcINVDR/h1lGP0e1ivRa5Q0wFa/WpLxeQFRpSZoPhfiefzxEXmjjuU zEOjv7/0miVTktdzXeHVux+feVKE5ng= Received: by mail-pl1-f170.google.com with SMTP id n13so361300plf.11 for ; Wed, 01 Feb 2023 17:42:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JYjNCZTedk1AJoVE/LTBpwn60v8SrzPue4uHPDh5wcE=; b=iv03dHdBcW/AZOHUDlopVCkZMKFM5RQoGCY65iwL3v1XSSn6aFyN06IJDrI7/Y1dPh CaFdxSXVVjpIPBxknyOfU6wiAXoOpTQA7lbpm7JbzsU7X3rmtw9j/uDnDsZC8p37KAOl T/651l6xryaOqGzHBqD/t2tGccpWOjcNcUV+37GFHt59GhVhWtoCFFWYkEDTdq+EfD1B nVdqLRlenGwkWXLqu5fy40pZ2DGJG04NOPHli4XhXuvWujUoeJyQU9rSdmhiMvX2tS3i jVmpex4Sk2c0aoGC+RK06Pwp+M0a7xsu2yZ4brDKq+6NUq/LJ1nCbzhjhvPG43MnxO94 5Pvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JYjNCZTedk1AJoVE/LTBpwn60v8SrzPue4uHPDh5wcE=; b=uHe6GOcSBfmWAMT1KWroc7iBY+kUX0r5camWlujq5pBCFIL/zEI7GtsBtva6DSHafR tUhMPF7xG+jRtugAesHymAG7OiKOb4cXWrLggjcyHhGoR6uCdprNsSbmuQmFjJzgjH4e 3JZa6+wtKrJOJqrJNcYi0k0N3Qfk+yhMoiwRnYhtbfCboel6R/DthOJc0KYllkJOjjBE 9r/25CwTbpi3Yq/r8jftvWmqBUDEk9W2hc7KTBI2s8DWyzyIHGTql376IjL/cFwt9soJ I83mVMwGXdWPnNN410hO7wFgz0w/KoYoxDLWIr4WRoPTQZ8gK+9Pi3GDTVP/BLNGP5T9 UCNQ== X-Gm-Message-State: AO0yUKUaa7Jb15UrJma9WIRsCcZ6VUKo3dHLHu78BE7Ps00+P5FaRe+a Z08jV/7zKNlL0f+QI6YNQYE= X-Google-Smtp-Source: AK7set9JBuOshDn5GHDps2tnszs7MZJQNL/kb7SOm046DT8cAbZupwyNErHhHuomwxoErVIBH3XDkA== X-Received: by 2002:a05:6a21:33aa:b0:bc:fe7e:cfd9 with SMTP id yy42-20020a056a2133aa00b000bcfe7ecfd9mr6068166pzb.18.1675302147552; Wed, 01 Feb 2023 17:42:27 -0800 (PST) Received: from vultr.guest ([2001:19f0:7001:3f48:5400:4ff:fe4a:8c8b]) by smtp.gmail.com with ESMTPSA id t191-20020a6381c8000000b004e8f7f23c4bsm6594205pgd.76.2023.02.01.17.42.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 17:42:27 -0800 (PST) From: Yafang Shao To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, tj@kernel.org, dennis@kernel.org, cl@linux.com, akpm@linux-foundation.org, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, vbabka@suse.cz, urezki@gmail.com Cc: linux-mm@kvack.org, bpf@vger.kernel.org, Yafang Shao , Christoph Hellwig Subject: [PATCH bpf-next 3/7] mm: vmalloc: introduce vsize() Date: Thu, 2 Feb 2023 01:41:54 +0000 Message-Id: <20230202014158.19616-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230202014158.19616-1-laoar.shao@gmail.com> References: <20230202014158.19616-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: B316D4000F X-Rspamd-Server: rspam01 X-Stat-Signature: h15xj4uisyi8ekuhgfytmkqw81pd37qb X-HE-Tag: 1675302148-957669 X-HE-Meta: U2FsdGVkX1/+MV2LS2FwDAHwcqaf90m956ZSUaAp0y2yNcXfytSHHYrvu6lp/qheTCz2fJD5/HGg2Nahaj3ozYQgM7YLqFqmKLZLjgR4c8N42rxhhMOtHgy07nVmn0tPjmDDLx/OmeZwRKvlQTb646rG9EMat2XGx1qSe/VuQB3ZacGrFMXfmW5fbEYb4nghN2p4QJoUhXBdgP2OxI7OTCD1p1dJ2WC1WwXWhRuet05W4cCT47m8jxMZwXG0GwOGX9lChnjvJNyDPx9bdpDvHp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l20oFifMvSwqQIZ1EiZZrSlF1dpwZ6DrSz7kJZO8ISHpsMGRnBiUQG2iehUAafIzkiosQmMVUJ3yzzGU/cLpJLICllBrTEwBBu0Leo26Hb0qWwDdSFYw9ELJNtn0KN+kkRTNXjO343KBjJqaQOweJUOHxVprNdknkQxaxBjHbN/qixJJIlgO/cGxB/1aomHKUwv+9oCqLbEA/mhKy+joPfInE3dswKxiKMSZrcwLLfdZPVz+GsLNTpKM= 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: Introduce a helper to report full size of underlying allocation of a vmalloc'ed address. Suggested-by: Uladzislau Rezki Signed-off-by: Yafang Shao Cc: Uladzislau Rezki Cc: Christoph Hellwig --- include/linux/vmalloc.h | 1 + mm/vmalloc.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 096d48a..7fbd390 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -297,4 +297,5 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets, static inline bool vmalloc_dump_obj(void *object) { return false; } #endif +size_t vsize(void *addr); #endif /* _LINUX_VMALLOC_H */ diff --git a/mm/vmalloc.c b/mm/vmalloc.c index ca71de7..8499eba 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4057,6 +4057,23 @@ bool vmalloc_dump_obj(void *object) } #endif +/* Report full size of underlying allocation of a vmalloc'ed addr */ +size_t vsize(void *addr) +{ + struct vmap_area *va; + size_t va_size = 0; + + if (!addr) + return 0; + + spin_lock(&vmap_area_lock); + va = __find_vmap_area((unsigned long)addr, &vmap_area_root); + if (va && va->vm) + va_size = va->vm->size; + spin_unlock(&vmap_area_lock); + return va_size; +} + #ifdef CONFIG_PROC_FS static void *s_start(struct seq_file *m, loff_t *pos) __acquires(&vmap_purge_lock)