From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752251AbcEYNgM (ORCPT ); Wed, 25 May 2016 09:36:12 -0400 Received: from smtprelay0253.hostedemail.com ([216.40.44.253]:51838 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750733AbcEYNgK (ORCPT ); Wed, 25 May 2016 09:36:10 -0400 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::,RULES_HIT:41:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:3138:3139:3140:3141:3142:3353:3622:3743:3865:3866:3867:3868:3870:3871:3872:3873:4250:5007:6119:6261:7875:7901:7903:10004:10400:10450:10455:10848:10967:11026:11232:11658:11914:12043:12438:12517:12519:12740:13069:13161:13229:13311:13357:13439:14096:14097:14181:14659:14721:19904:19999:21080:21324:21433,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: eye63_357075ec7eb37 X-Filterd-Recvd-Size: 2484 Date: Wed, 25 May 2016 09:36:04 -0400 From: Steven Rostedt To: Peter Zijlstra Cc: Andy Lutomirski , linux-kernel@vger.kernel.org, Ingo Molnar Subject: Re: [PATCH] tracing: Choose static tp_printk buffer by explicit nesting count Message-ID: <20160525093604.3dc597a5@gandalf.local.home> In-Reply-To: <20160525131640.GG3192@twins.programming.kicks-ass.net> References: <08104c3c8b9b8091fdcc6b4ca2c8c5dcc9dfd77d.1464130297.git.luto@kernel.org> <20160525131640.GG3192@twins.programming.kicks-ass.net> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 25 May 2016 15:16:40 +0200 Peter Zijlstra wrote: > > static char *get_trace_buf(void) > > { > > + struct trace_buffer_struct *buffer = this_cpu_ptr(trace_percpu_buffer); > > > > + if (!buffer || buffer->nesting >= 4) > > return NULL; > > This is buggy fwiw; you need to unconditionally increment > buffer->nesting to match the unconditional decrement. > > Otherwise 5 'increments' and 5 decrements will land you at -1. As I said, I did a quick look and haven't reviewed it. Peter, thanks for looking at it. > > > > > + return &buffer->buffer[buffer->nesting++][0]; > > +} > > + > > +static void put_trace_buf(void) > > +{ > > + this_cpu_dec(trace_percpu_buffer->nesting); > > } > > So I don't know about tracing; but for perf this construct would not > work 'properly'. > > The per context counter -- which is lost in this scheme -- guards > against in-context recursion. > > Only if we nest from another context do we allow generation of a new > event. The ring buffer itself has a context check, where if you try to record another event nested in the same context, it will simply return NULL. But this buffer is only used for trace_printk() to manipulate a printf format. It writes into here first, and then copies it into the tracing ring buffer. If it happens at a nested event within the same context, then trace_buffer_lock_reserve() will return NULL and the event wont be recorded. -- Steve