Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4747804yba; Wed, 10 Apr 2019 04:12:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqz9AW8mWTsWtmEe2dTGk421EN5fD7yf3GjEveS6kiUU2bJqycAV4WQ3W7gFNN/vI8/k3J/k X-Received: by 2002:a62:e501:: with SMTP id n1mr19337204pff.17.1554894740761; Wed, 10 Apr 2019 04:12:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554894740; cv=none; d=google.com; s=arc-20160816; b=oT/sOqY0V8xPS/8fduqyqbiPRPlH8ri54n6eMZNr5BWM8LJpjf5QZXlHEHlTc9y3dJ TpccyFW4MkorQ7brJjTOULTX9H+NwAbFB9xWD26qk/uWPnSiU+y6umjylFQr68Qsrubr eSAg8J8VQwX63IModE/TGsasyzpN0frfAUOn63S9uQX7Hk5m3LQp5QGpdk7cQ70RZMH6 /Z3gNaw50Ur0/ElMqMflM6B/hDY0+OyRAEzYnHWVwlXPDLT1VNxCtZT1jr7uLgKolPom YCQyQY5CGQj1JnRe1oc6BwT6AeVZbyNz3ZWz9bMcquZr/DdT4xq1XY+OcyvdODEWFx9s wjNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:subject:cc:to :from:date:user-agent:message-id; bh=ys5K8rcZt/IGngZyuQEJEkooRHUNuP2LcdYB/OXT2qw=; b=dadcVdFfzGG/PxqYc/sPFLfhei07rKxlSjP3pNB1NRYvYsZk8BXbLdc/Rv52H+VOxJ b+y2xqDg1ek1H65we9dLntZDKbRF/BazDTojqDdz9DVJZrl+MFdwkXOrcGdukKH4Sa8Y TK0v6hysKV6y+voyKwf5F1LJsHBVQzYMV6+2SWt4mZNWCmu7MawW4ROSUVHK8qUVTNpg d528sa+K43bJmcgFbTkSNJw5e4XCMFwBxS9gNZE9psWxUcPIqmY0+ZhgF4CO2qemTZ1/ yFIK7QjiuEHuiVEbq+p7ozth77VsOWGv3kUE7fAx/fH3Mm7XG7mcFqPS8yLtci9xUqKJ sPqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q23si25130315pll.21.2019.04.10.04.12.04; Wed, 10 Apr 2019 04:12:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731035AbfDJLF7 (ORCPT + 99 others); Wed, 10 Apr 2019 07:05:59 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:58840 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728813AbfDJLFx (ORCPT ); Wed, 10 Apr 2019 07:05:53 -0400 Received: from localhost ([127.0.0.1] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1hEB39-00057a-FC; Wed, 10 Apr 2019 13:05:51 +0200 Message-Id: <20190410103645.315084160@linutronix.de> User-Agent: quilt/0.65 Date: Wed, 10 Apr 2019 12:28:13 +0200 From: Thomas Gleixner To: LKML Cc: Josh Poimboeuf , x86@kernel.org, Andy Lutomirski , Steven Rostedt , Alexander Potapenko Subject: [RFC patch 19/41] lib/stackdepot: Provide functions which operate on plain storage arrays References: <20190410102754.387743324@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The struct stack_trace indirection in the stack depot functions is a truly pointless excercise which requires horrible code at the callsites. Provide interfaces based on plain storage arrays. Signed-off-by: Thomas Gleixner --- include/linux/stackdepot.h | 4 ++ lib/stackdepot.c | 66 ++++++++++++++++++++++++++++++++------------- 2 files changed, 51 insertions(+), 19 deletions(-) --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -26,7 +26,11 @@ typedef u32 depot_stack_handle_t; struct stack_trace; depot_stack_handle_t depot_save_stack(struct stack_trace *trace, gfp_t flags); +depot_stack_handle_t stack_depot_save(unsigned long *entries, + unsigned int nr_entries, gfp_t gfp_flags); void depot_fetch_stack(depot_stack_handle_t handle, struct stack_trace *trace); +unsigned int stack_depot_fetch(depot_stack_handle_t handle, + unsigned long **entries); #endif --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -194,40 +194,56 @@ static inline struct stack_record *find_ return NULL; } -void depot_fetch_stack(depot_stack_handle_t handle, struct stack_trace *trace) +/** + * stack_depot_fetch - Fetch stack entries from a depot + * + * @entries: Pointer to store the entries address + */ +unsigned int stack_depot_fetch(depot_stack_handle_t handle, + unsigned long **entries) { union handle_parts parts = { .handle = handle }; void *slab = stack_slabs[parts.slabindex]; size_t offset = parts.offset << STACK_ALLOC_ALIGN; struct stack_record *stack = slab + offset; - trace->nr_entries = trace->max_entries = stack->size; - trace->entries = stack->entries; - trace->skip = 0; + *entries = stack->entries; + return stack->size; +} +EXPORT_SYMBOL_GPL(stack_depot_fetch); + +void depot_fetch_stack(depot_stack_handle_t handle, struct stack_trace *trace) +{ + unsigned int nent = stack_depot_fetch(handle, &trace->entries); + + trace->max_entries = trace->nr_entries = nent; } EXPORT_SYMBOL_GPL(depot_fetch_stack); /** - * depot_save_stack - save stack in a stack depot. - * @trace - the stacktrace to save. - * @alloc_flags - flags for allocating additional memory if required. + * stack_depot_save - Save a stack trace from an array * - * Returns the handle of the stack struct stored in depot. + * @entries: Pointer to storage array + * @nr_entries: Size of the storage array + * @alloc_flags: Allocation gfp flags + * + * Returns the handle of the stack struct stored in depot */ -depot_stack_handle_t depot_save_stack(struct stack_trace *trace, - gfp_t alloc_flags) +depot_stack_handle_t stack_depot_save(unsigned long *entries, + unsigned int nr_entries, + gfp_t alloc_flags) { - u32 hash; - depot_stack_handle_t retval = 0; struct stack_record *found = NULL, **bucket; - unsigned long flags; + depot_stack_handle_t retval = 0; struct page *page = NULL; void *prealloc = NULL; + unsigned long flags; + u32 hash; - if (unlikely(trace->nr_entries == 0)) + if (unlikely(nr_entries == 0)) goto fast_exit; - hash = hash_stack(trace->entries, trace->nr_entries); + hash = hash_stack(entries, nr_entries); bucket = &stack_table[hash & STACK_HASH_MASK]; /* @@ -235,8 +251,8 @@ depot_stack_handle_t depot_save_stack(st * The smp_load_acquire() here pairs with smp_store_release() to * |bucket| below. */ - found = find_stack(smp_load_acquire(bucket), trace->entries, - trace->nr_entries, hash); + found = find_stack(smp_load_acquire(bucket), entries, + nr_entries, hash); if (found) goto exit; @@ -264,10 +280,10 @@ depot_stack_handle_t depot_save_stack(st spin_lock_irqsave(&depot_lock, flags); - found = find_stack(*bucket, trace->entries, trace->nr_entries, hash); + found = find_stack(*bucket, entries, nr_entries, hash); if (!found) { struct stack_record *new = - depot_alloc_stack(trace->entries, trace->nr_entries, + depot_alloc_stack(entries, nr_entries, hash, &prealloc, alloc_flags); if (new) { new->next = *bucket; @@ -297,4 +313,16 @@ depot_stack_handle_t depot_save_stack(st fast_exit: return retval; } +EXPORT_SYMBOL_GPL(stack_depot_save); + +/** + * depot_save_stack - save stack in a stack depot. + * @trace - the stacktrace to save. + * @alloc_flags - flags for allocating additional memory if required. + */ +depot_stack_handle_t depot_save_stack(struct stack_trace *trace, + gfp_t alloc_flags) +{ + return stack_depot_save(trace->entries, trace->nr_entries, alloc_flags); +} EXPORT_SYMBOL_GPL(depot_save_stack);