From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8D92451064 for ; Fri, 22 May 2026 14:35:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779460506; cv=none; b=iMi14caqFVCp7fn6ovgCGTrf9yz5pUwnbsbTGrbBuYY84fsJENu+qa7t1oPcil+4Yy71Dk9ZeOVaSU6RBnWT1DdPPcnuhWQxYajdmttA9bkBShAb9Wk5xb+cTx4WHl5cN4Yj13x8DP2w5y38GYzTh/4e0+ZinAHsCzk0KLWdQwM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779460506; c=relaxed/simple; bh=ML5DPmH8xDlMiMsCh4nnqHrdM6tVPBcebCq7uFh9bRA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=tUV+Twm9IqAL03OEpQD0o3VrvpzRWl5mwcTsqKetaIz53qm9s8NFBEfLo74phLEXx5dN2LecdUW/WYsc340fQK4Cyt7ehhWwZHB4R/qVpiCwpRxyCFpuQvxS9l7LR1vSj0yXVdD7opy2Ge5txxABoyp04auS71KqsS6cKonRhE0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=R6P0CeHQ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="R6P0CeHQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CEB91F000E9; Fri, 22 May 2026 14:35:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779460503; bh=Lek57FEU9LjQRAZbraWhQYi0Mm3HHqNBbES1zu8B+Kw=; h=Date:From:To:Cc:Subject:References; b=R6P0CeHQzlZdkGvdZ1Unmhb30RXhXjJkD3Umh1YiSEFKLmhUoL+mTSzrujqBO1XR0 iljWCf0vwgIkyPS2XJNo+lVYriJcrApMqWZkZ35aQ0r4ZzCuno/zP4wVn4ni2oUikY 9TlkSeKtz+J6I5D0ZtwxRH4++/6uJKIitM5zEjsfr48InvWJHT4Eov/jinh1aBKygC 60fshZBs6k70cPBwE+3eAW5hrUiFi9rWKRYymRb35l8T9WyI8cpfaHNzpKpL0LRKxi d8yABIjZCxAU8Gz6++X0sWPA2x2D7nZzTy6qb5eE4FIB3vjXhhSHZWDCHOH3R/QlON y2G6p33RPk0og== Received: from rostedt by gandalf with local (Exim 4.99.2) (envelope-from ) id 1wQQyF-000000066Cd-19Co; Fri, 22 May 2026 10:35:27 -0400 Message-ID: <20260522143527.139109060@kernel.org> User-Agent: quilt/0.69 Date: Fri, 22 May 2026 10:35:22 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Kees Cook , "Gustavo A. R. Silva" , Rosen Penev Subject: [for-next][PATCH 14/15] tracing: Simplify pages allocation for tracing_map logic References: <20260522143508.298439732@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 From: Rosen Penev Change to a flexible array member to allocate together with the array struct. Simplifies code slightly by removing no longer correct null checks for pages and removing kfrees. Cc: Mathieu Desnoyers Cc: Kees Cook Cc: "Gustavo A. R. Silva" Link: https://patch.msgid.link/20260520215006.12008-1-rosenp@gmail.com Signed-off-by: Rosen Penev Acked-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt --- kernel/trace/tracing_map.c | 30 +++++++++++------------------- kernel/trace/tracing_map.h | 2 +- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/kernel/trace/tracing_map.c b/kernel/trace/tracing_map.c index 0dd7927df22a..d7922f40dbe2 100644 --- a/kernel/trace/tracing_map.c +++ b/kernel/trace/tracing_map.c @@ -288,9 +288,6 @@ static void tracing_map_array_clear(struct tracing_map_array *a) { unsigned int i; - if (!a->pages) - return; - for (i = 0; i < a->n_pages; i++) memset(a->pages[i], 0, PAGE_SIZE); } @@ -302,9 +299,6 @@ static void tracing_map_array_free(struct tracing_map_array *a) if (!a) return; - if (!a->pages) - goto free; - for (i = 0; i < a->n_pages; i++) { if (!a->pages[i]) break; @@ -312,9 +306,6 @@ static void tracing_map_array_free(struct tracing_map_array *a) free_page((unsigned long)a->pages[i]); } - kfree(a->pages); - - free: kfree(a); } @@ -322,24 +313,25 @@ static struct tracing_map_array *tracing_map_array_alloc(unsigned int n_elts, unsigned int entry_size) { struct tracing_map_array *a; + unsigned int entry_size_shift; + unsigned int entries_per_page; + unsigned int n_pages; unsigned int i; - a = kzalloc_obj(*a); + entry_size_shift = fls(roundup_pow_of_two(entry_size) - 1); + entries_per_page = PAGE_SIZE / (1 << entry_size_shift); + n_pages = max(1, n_elts / entries_per_page); + + a = kzalloc_flex(*a, pages, n_pages); if (!a) return NULL; - a->entry_size_shift = fls(roundup_pow_of_two(entry_size) - 1); - a->entries_per_page = PAGE_SIZE / (1 << a->entry_size_shift); - a->n_pages = n_elts / a->entries_per_page; - if (!a->n_pages) - a->n_pages = 1; + a->entry_size_shift = entry_size_shift; + a->entries_per_page = entries_per_page; + a->n_pages = n_pages; a->entry_shift = fls(a->entries_per_page) - 1; a->entry_mask = (1 << a->entry_shift) - 1; - a->pages = kcalloc(a->n_pages, sizeof(void *), GFP_KERNEL); - if (!a->pages) - goto free; - for (i = 0; i < a->n_pages; i++) { a->pages[i] = (void *)get_zeroed_page(GFP_KERNEL); if (!a->pages[i]) diff --git a/kernel/trace/tracing_map.h b/kernel/trace/tracing_map.h index 99c37eeebc16..18a02959d77b 100644 --- a/kernel/trace/tracing_map.h +++ b/kernel/trace/tracing_map.h @@ -167,7 +167,7 @@ struct tracing_map_array { unsigned int entry_shift; unsigned int entry_mask; unsigned int n_pages; - void **pages; + void *pages[] __counted_by(n_pages); }; #define TRACING_MAP_ARRAY_ELT(array, idx) \ -- 2.53.0