Received: by 10.213.65.68 with SMTP id h4csp518782imn; Fri, 23 Mar 2018 09:28:15 -0700 (PDT) X-Google-Smtp-Source: AG47ELsbb1XnxGM/NUR0RfH456/eEm0g0GWvZmZCqL+H6XCa9TMUcuPIsrwCGCglZvbjC64JUo4q X-Received: by 2002:a17:902:8492:: with SMTP id c18-v6mr29729383plo.40.1521822495205; Fri, 23 Mar 2018 09:28:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521822495; cv=none; d=google.com; s=arc-20160816; b=vET1zFQ4fPyudzV2F4xRouen+KwEXdzsZfJpG996HlXYO9jP0vdRXdccnZ8snznu31 mbfYMjG2Cv7uHwhYGyozwrFcd791JRUImfILzQb1C6TcXeQUnPg0g0nkbxYmmTTnnZCi mz+2t/jiqJz0Qs8NGGMmDAKjqr/0XXioYkT9asXI1k6gpKH66DeMt7UVPOc5bMHOwI+N DxOtEDiq4vk4+voGsi3vOBPNYuaEoTYP89fpC+c2/RCLADgV+6xjHSVARanbGQnspC1Z dFvyzdpHlJ5F8yqKQI77wGwa6pn1B6bLLgoJVfTUhOwmlh6+sYJB6lmEHkQj0L2Po5YP c2qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=mu3IM1dpXjw8PIKlPMlVOY/FoR6oOsUlvktwB+kK30c=; b=02KAaCeo76qNwpsREMYgPpyNqD/OfmV+7XHQrPEd9i3km5BLWjhA3UsBy4AzQkvuWB +o2pp+741kLmruTPN/3fkLVtFpUCiFtmiaucxhf45V4RhANsHHrzkmg9Y3n+L4NkkCm4 OSiiClh6rOAHGlYzGHyJ5xJIu6jNoYGryNvom2n3mxxPxpXQ5poGaIpse557pJSThkoz m5Zgi+14dB74nV+sCzDuJbMhhhym7OejgN6ldlH5QzOMuiD7F4NpOO2gzeprmfvcNmRM yQZKSt6x7OumnRTfgUIZ3+0CfOmOlcASDaY5Ra/S9hvv1IJ3au/4TZisOC5FcgU4rypV dKLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=EOFdwDnk; 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 70-v6si8935100ple.639.2018.03.23.09.28.01; Fri, 23 Mar 2018 09:28:15 -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; dkim=pass header.i=@ffwll.ch header.s=google header.b=EOFdwDnk; 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 S1752327AbeCWQ0T (ORCPT + 99 others); Fri, 23 Mar 2018 12:26:19 -0400 Received: from mail-io0-f175.google.com ([209.85.223.175]:34457 "EHLO mail-io0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752025AbeCWQ0S (ORCPT ); Fri, 23 Mar 2018 12:26:18 -0400 Received: by mail-io0-f175.google.com with SMTP id r18so15813032ioa.1 for ; Fri, 23 Mar 2018 09:26:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=mu3IM1dpXjw8PIKlPMlVOY/FoR6oOsUlvktwB+kK30c=; b=EOFdwDnkac3dGcUD4GWImtar+TkWu3hFKad48BRcnsVjNevXSbWwqptt1hhwZmis2Z Wpj3FmWQUs3P31fKCg2UIfEf31I0E2slzx8kwf36Kiv5ceREj1rWp8lvDQw2IX2sqIC3 BhAJuY2oxwpIA2nMTlKV7MEJLoXe+vkB73un4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=mu3IM1dpXjw8PIKlPMlVOY/FoR6oOsUlvktwB+kK30c=; b=CN2Oeuqsd1i5nhim+ORx5yzKP8x3oVDCmDezSWHj9e9/fWdTyE1YjkzWo42wdfqEvd /N0j7DTBFUM1W+h28msN8SniiK4BEv4v7RWRNvW+WhToa9AJP59eIJ3aDivTcTIBFYN7 jPt6lx9fudpv5ZTmyw0GhgCovVrxkRW9pnyfA+19lxKcWmuD6+GxIBdTEESFbcjlcGJ/ Uqir9bCekl5J+woCexh2FxMSXS/rQSDnUCgs4GaPwBbE53smPut+Ul6kH39P9+Cw5LQP zwmgB9a9GKcvQ2yEV9Ww3GF4bsvZ+EJqiJ19xXe8vdyoyQLeoVh76JMmP1zGnEZAvsyo mv2A== X-Gm-Message-State: AElRT7GngNHy+GACHjEBKBRlL9cDjmnziscDS+V0Mgk7KP87O4GzPSgi 0oo6bs8z3n0KWFitWeGa6XjEYGVA89oIHjb1w1lxjQ== X-Received: by 10.107.197.130 with SMTP id v124mr4197903iof.55.1521822377792; Fri, 23 Mar 2018 09:26:17 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.40.129 with HTTP; Fri, 23 Mar 2018 09:26:17 -0700 (PDT) X-Originating-IP: [212.51.149.109] In-Reply-To: References: <20180320160258.11381-1-daniel.vetter@ffwll.ch> From: Daniel Vetter Date: Fri, 23 Mar 2018 17:26:17 +0100 Message-ID: Subject: Re: [PATCH] RFC: debugobjects: capture stack traces at _init() time To: Thomas Gleixner Cc: Intel Graphics Development , LKML , Philippe Ombredanne , Greg Kroah-Hartman , Kate Stewart , Waiman Long , Daniel Vetter 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 On Tue, Mar 20, 2018 at 8:44 PM, Thomas Gleixner wrote: > On Tue, 20 Mar 2018, Daniel Vetter wrote: > >> Sometimes it's really easy to know which object has gone boom and >> where the offending code is, and sometimes it's really hard. One case >> we're trying to hunt down is when module unload catches a live debug >> object, with a module with lots of them. >> >> Capture a full stack trace from debug_object_init() and dump it when >> there's a problem. >> >> FIXME: Should we have a separate Kconfig knob for the backtraces, >> they're quite expensive? Atm I'm just selecting it for the general >> debug object stuff. > > Just make it boot time enabled. We really want to be able to switch it off. > >> +#define ODEBUG_STACKDEPTH 32 > > Do we really need it that deep? I doubt that. Entirely arbitrary, I just needed this to start hunting a rare crash we're seeing in CI and stitched something together. I agree we probably don't need that much. >> +static noinline depot_stack_handle_t save_stack(struct debug_obj *obj) >> +{ >> + unsigned long entries[ODEBUG_STACKDEPTH]; >> + struct stack_trace trace = { >> + .entries = entries, >> + .max_entries = ODEBUG_STACKDEPTH, >> + .skip = 2 >> + }; >> + >> + save_stack_trace(&trace); >> + if (trace.nr_entries != 0 && >> + trace.entries[trace.nr_entries-1] == ULONG_MAX) >> + trace.nr_entries--; >> + >> + /* May be called under spinlock, so avoid sleeping */ >> + return depot_save_stack(&trace, GFP_NOWAIT); > > I really don't like the idea of unconditional allocations in that code > path. We went great length to make it perform halfways sane with the > pool. Though we should actually have per cpu pools to avoid the lock > contention, but thats a different problem. > > I'd rather make the storage a fixed size allocation which is appended > to the debug object. Something like this: > > struct debug_obj_trace { > struct stack_trace trace; > unsigned long entries[ODEBUG_STACKDEPTH]; > }; > > struct debug_obj { > unsigned int astate; > void *object; > struct debug_obj_descr *descr; > struct debug_obj_trace trace[0]; > }; > > void __init debug_objects_mem_init(void) > { > unsigned long objsize = sizeof (struct debug_obj); > > if (!debug_objects_enabled) > return; > > if (debug_objects_trace_stack) > objsize += sizeof(struct debug_obj_trace); > > obj_cache = kmem_cache_create("debug_objects_cache", objsize, 0, > SLAB_DEBUG_OBJECTS, NULL); > > __debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack) > { > .... > case ODEBUG_STATE_NONE: > case ODEBUG_STATE_INIT: > case ODEBUG_STATE_INACTIVE: > if (debug_object_trace_stack) { > obj->trace[0].trace.entries = obj->trace[0].entries; > save_stack_trace(&trace[0].trace); > } > > That means we need to size the static objects which are used during early > boot with stack under the assumption that stack tracing is enabled, but > that's simple enough. > > Hmm? Yeah looks reasonable, and gives us an easy Kconfig/boot-time option to enable/disable it. I'm a bit swamped, but I'll try to respin. Thanks very much for the look and suggesting a cleaner integration approach - the allocations and recursion into the stack depot really did not result in clean code. Thanks, Daniel > Thanks, > > tglx -- Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch