From patchwork Wed Jun 12 02:16:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13694341 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 EF1BBC27C78 for ; Wed, 12 Jun 2024 02:17:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6EDA56B0135; Tue, 11 Jun 2024 22:17:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 69D306B0136; Tue, 11 Jun 2024 22:17:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58CDE6B0137; Tue, 11 Jun 2024 22:17:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3AAA06B0135 for ; Tue, 11 Jun 2024 22:17:15 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A58ECC0736 for ; Wed, 12 Jun 2024 02:17:14 +0000 (UTC) X-FDA: 82220624388.12.0B0D06E Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf16.hostedemail.com (Postfix) with ESMTP id 70A6518000B for ; Wed, 12 Jun 2024 02:17:11 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of "SRS0=9b5n=NO=goodmis.org=rostedt@kernel.org" designates 145.40.73.55 as permitted sender) smtp.mailfrom="SRS0=9b5n=NO=goodmis.org=rostedt@kernel.org"; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718158632; a=rsa-sha256; cv=none; b=QQ37pCQGcQdk15GIyYGcoOXpEbYm4jnoIrNiGywRMI864UENozL1op+hWrRNUDC1wjfmC/ /L5pJlp5mBX7MF6eRiTXkSLAPi3rpyKkgHC5J11OHtv4RqYTifqiTa7PUFC+5YiiX600zm pvzkryD4aJS9SxXtyoHlNUY3zvKAznU= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of "SRS0=9b5n=NO=goodmis.org=rostedt@kernel.org" designates 145.40.73.55 as permitted sender) smtp.mailfrom="SRS0=9b5n=NO=goodmis.org=rostedt@kernel.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718158632; 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: references:references; bh=ThqnLmRpsQGN4xu6Y6odrqca3Sbrpfi9MpT8PdxlZgU=; b=5mCvxoFScKDZN//LgW7TZr7h8QCzqOOwXqumu1M3Z3khjvHMRhf7o66hu9sjZlK+OSHEsk eD5FtUZAFXzNQXnkBig6xiFIG0OY8pQgpK8YFbruFTgEfzncOP3SVCG2N7YMPuM9QL1IZO k/TKHN+RETNhBRLZ93TEdXwyxwvs9tA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 55F1ECE1F8E; Wed, 12 Jun 2024 02:17:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5ABB5C4AF61; Wed, 12 Jun 2024 02:17:06 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sHDYB-00000001XMf-29YO; Tue, 11 Jun 2024 22:17:23 -0400 Message-ID: <20240612021723.374491025@goodmis.org> User-Agent: quilt/0.68 Date: Tue, 11 Jun 2024 22:16:50 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Vincent Donnefort , Joel Fernandes , Daniel Bristot de Oliveira , Ingo Molnar , Peter Zijlstra , suleiman@google.com, Thomas Gleixner , Vineeth Pillai , Youssef Esmat , Beau Belgrave , Alexander Graf , Baoquan He , Borislav Petkov , "Paul E. McKenney" , David Howells , Mike Rapoport , Dave Hansen , Tony Luck , Guenter Roeck , Ross Zwisler , Kees Cook , linux-mm@kvack.org Subject: [PATCH v5 08/13] tracing: Add option to use memmapped memory for trace boot instance References: <20240612021642.941740855@goodmis.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 70A6518000B X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: wtmwzotxhku9hfatwamnhah7oi4xc6n4 X-HE-Tag: 1718158631-955971 X-HE-Meta: U2FsdGVkX1/e9CiWnUBG54ZZQHvq4TU7ThBR7ezcx9JKO/cE6PGSKweuMZPuV4Lal9XujGVEDx9lqEUKAweNjLLT4H70OQeSQbLirMTVaWu6KWk1lxbvT9GPNpGr4qkkMiIoSMPW7z77+00Zy2oKPOQgy5ivM2OoOAI2jrs96eK69ryJpbY9LnAlosOFXDWoIr6YT64d0ncrfpACdHDv5+v1/HwLjSulM3cwNEmS2tWSY9hOjlPEFQPKw3ujzfWFGy6uiCuy7yfsk7IBPilEiheUWaji6ixLsKQQulwmmCzXL5XwWzFYSc5lRq7tFJUEE3+rai7xUKCDCoBeXXkbnn0Kc8K1VRL7Swv0fcILRloXPhXDhAeeOIrGKgBBqrL2LS/9WhL6Ek+9Kw8zLQNE54n11i9eFPWZbuBQ4LCaWFOIRHiHIq+aBpGHJvIyyRFH01aysSauwzSZpTLBYrPLm/GxBL6sqLHV7iyStfB4VF2Rs9m5HjFIwF4X6VsUts0ulbS4wANd3HtTvXqFrqgxim3fnAKVW5W/zlswjREiS3esUemd9AtVKDUqhX6r/v2XD0xQIhoPFVqxQSUl2iqpEkSsFgfOCQDPeuE/1/ikqsUc4/AZMPY17OIrARSGfBrfXkZJ2oVzbKDd3xypOoe5SzAAKZ4F5EbkP3KnoRCT84xUnB8FyGWeABC730qPsz0+3DXdcX0wx+cf9+LO0ZORY5/6ap0mXF27r1WRJkDwgh0B9DcsjkZGvFHdkDS20tENZSrhpKbUBoB28Sjh3tYYzLuLL1l6Pa8xr1a0L5WOJfzNuIsjDfZBAOSKIv9R07K8HVunEEvjQKyu839331oTBxvfU6Olw1hII9kLkxirPutsaRCDZzSWVcenFPOhI9d3VZpbBYYJ3bipwyO02XVfrWEyeDONVoqI1OzUs58Slxn0GLK0xpPSZl8/En5BKoK/y7pJs1B5U/PuhhtfiX6 DGUzXvfp qav9vc8Lk462DXtiWAzeCsl3sPfeGuOWrv7zrBCVEPExj8o6TScjZLKcLF5+ZCE3dG0Au8jYut9cAcCczm1+e3WUNF5EBK6pKumDHmc0cGAZYBHirg9CXbCPrkOKeE9XVaWH9jkGWXltSKNmzUdeArrOgUAexFdYcfH1FX3l2EgkWGsLU0OJ9hmdJwtCcQaYTfGkmpnC3jqYLCBSBrJ52pOHT2m5dwcptvBHxd/+gwS6jxWQrak7AZJ6zGetgMulPjjTDRicNut8rkHGDRi4S3dbG8Wz/yp6Lm11b8ci09C28ddNHuKO5vF8KYaDsyjjFcuZHOPUlvbdy6NynAqRrgf3Wrh82ISWXj+RyzmL4OTEaKVTVeQma+PI1iWHm5t+n+HsY7N8TCrC2ksl7PLxR8ipNJc8AfY/PybCx 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: List-Subscribe: List-Unsubscribe: From: "Steven Rostedt (Google)" Add an option to the trace_instance kernel command line parameter that allows it to use the reserved memory from memmap boot parameter. memmap=12M$0x284500000 trace_instance=boot_mapped@0x284500000:12M The above will reserves 12 megs at the physical address 0x284500000. The second parameter will create a "boot_mapped" instance and use the memory reserved as the memory for the ring buffer. That will create an instance called "boot_mapped": /sys/kernel/tracing/instances/boot_mapped Note, because the ring buffer is using a defined memory ranged, it will act just like a memory mapped ring buffer. It will not have a snapshot buffer, as it can't swap out the buffer. The snapshot files as well as any tracers that uses a snapshot will not be present in the boot_mapped instance. Cc: linux-mm@kvack.org Signed-off-by: Steven Rostedt (Google) --- .../admin-guide/kernel-parameters.txt | 9 +++ kernel/trace/trace.c | 75 +++++++++++++++++-- 2 files changed, 78 insertions(+), 6 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index b600df82669d..ff26b6094e79 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6754,6 +6754,15 @@ the same thing would happen if it was left off). The irq_handler_entry event, and all events under the "initcall" system. + If memory has been reserved (see memmap for x86), the instance + can use that memory: + + memmap=12M$0x284500000 trace_instance=boot_map@0x284500000:12M + + The above will create a "boot_map" instance that uses the physical + memory at 0x284500000 that is 12Megs. The per CPU buffers of that + instance will be split up accordingly. + trace_options=[option-list] [FTRACE] Enable or disable tracer options at boot. The option-list is a comma delimited list of options diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 622fe670949d..dfde26aa3211 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -9504,6 +9504,31 @@ static int instance_mkdir(const char *name) return ret; } +static u64 map_pages(u64 start, u64 size) +{ + struct page **pages; + phys_addr_t page_start; + unsigned int page_count; + unsigned int i; + void *vaddr; + + page_count = DIV_ROUND_UP(size, PAGE_SIZE); + + page_start = start; + pages = kmalloc_array(page_count, sizeof(struct page *), GFP_KERNEL); + if (!pages) + return 0; + + for (i = 0; i < page_count; i++) { + phys_addr_t addr = page_start + i * PAGE_SIZE; + pages[i] = pfn_to_page(addr >> PAGE_SHIFT); + } + vaddr = vmap(pages, page_count, VM_MAP, PAGE_KERNEL); + kfree(pages); + + return (u64)(unsigned long)vaddr; +} + /** * trace_array_get_by_name - Create/Lookup a trace array, given its name. * @name: The name of the trace array to be looked up/created. @@ -10350,6 +10375,7 @@ __init static void enable_instances(void) { struct trace_array *tr; char *curr_str; + char *name; char *str; char *tok; @@ -10358,19 +10384,56 @@ __init static void enable_instances(void) str = boot_instance_info; while ((curr_str = strsep(&str, "\t"))) { + unsigned long start = 0; + unsigned long size = 0; + unsigned long addr = 0; tok = strsep(&curr_str, ","); + name = strsep(&tok, "@"); + if (tok) { + start = memparse(tok, &tok); + if (!start) { + pr_warn("Tracing: Invalid boot instance address for %s\n", + name); + continue; + } + } - if (IS_ENABLED(CONFIG_TRACER_MAX_TRACE)) - do_allocate_snapshot(tok); + if (start) { + if (*tok != ':') { + pr_warn("Tracing: No size specified for instance %s\n", name); + continue; + } + tok++; + size = memparse(tok, &tok); + if (!size) { + pr_warn("Tracing: Invalid boot instance size for %s\n", + name); + continue; + } + addr = map_pages(start, size); + if (addr) { + pr_info("Tracing: mapped boot instance %s at physical memory 0x%lx of size 0x%lx\n", + name, start, size); + } else { + pr_warn("Tracing: Failed to map boot instance %s\n", name); + continue; + } + } else { + /* Only non mapped buffers have snapshot buffers */ + if (IS_ENABLED(CONFIG_TRACER_MAX_TRACE)) + do_allocate_snapshot(name); + } - tr = trace_array_get_by_name(tok, NULL); + tr = trace_array_create_systems(name, NULL, addr, size); if (!tr) { - pr_warn("Failed to create instance buffer %s\n", curr_str); + pr_warn("Tracing: Failed to create instance buffer %s\n", curr_str); continue; } - /* Allow user space to delete it */ - trace_array_put(tr); + + /* Only allow non mapped buffers to be deleted */ + if (!start) + trace_array_put(tr); while ((tok = strsep(&curr_str, ","))) { early_enable_events(tr, tok, true);