Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3160389pxk; Tue, 15 Sep 2020 11:35:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkAfS5XFlfJwQvej/BM3MlVkuYQN/mdtl1GPCzsh7nkYE65sZPa7JvqocTYe8V25ifVxtW X-Received: by 2002:a17:906:f92:: with SMTP id q18mr20860317ejj.237.1600194917173; Tue, 15 Sep 2020 11:35:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600194917; cv=none; d=google.com; s=arc-20160816; b=En+u1muaV7uOOfrUw++QbrM4ts9T+Z9TUNwO0u7ywnAElVYeAMHKnlzAJVlsS1HMki QkKz9/fjIDEkHvybwTL4aq/kqC/S50ZSyiq3rU8YNyMPteUGbZrw8X6gk6WG94qLBUq/ jPBdiiJdgaywrt9to5lhapchuMt3IUwgLEe1GbTmbmQwvbGHBW/vH9NdJwE0y1tiRjhO igsWPsAdA5xyGwWrbB0IC+XEtvbRHDTCmAK19VSPlYzn3plSztbWdvUFxBWPEwOuaFx4 QP7DI+qvSpIZS16/OKcWei6Syc7/i6SIhujX/72EMVneZJxdbLq4aGI7SqI0crvmg+RL MQ8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=mFajZDwEsGlu1vmbds/fWbOm0tluFkOSTiGWs+7OyyU=; b=z6QyY1Tk33+7JVh0czoB7t9IZac+DrgipeFIvu3PeoRYwslSjvLVoYKTMAvYE+FAmg xfP5iXMITY+dhM9toC4A7w5WXAMqg3QncruxIF9jPzy6PpIV6r43hN/+ux+T+InmQj+/ oVcd821b9uPnry7zlVDEh55gB6QzBIawG38C2VL9ltLoPdyOUF4Gt7ZT/R6TMGGW5d+D CGnqNo8OSozbsOhkGlaxrdUmHYciUiJaM34QG/uXgu/YLjm+c0/nOwAVv2O7X2sh6Fm/ cPkevJIFnt8jnHFj8oOFiDcgZAEqbrVjLNYoYrk5vbl0yLWzWJKHcBuLBmvLsHbtUEgu 86jA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bh20si9404553ejb.294.2020.09.15.11.34.54; Tue, 15 Sep 2020 11:35:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727732AbgIOSeF (ORCPT + 99 others); Tue, 15 Sep 2020 14:34:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:40912 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727970AbgIOSNI (ORCPT ); Tue, 15 Sep 2020 14:13:08 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D631F20936; Tue, 15 Sep 2020 18:13:05 +0000 (UTC) Date: Tue, 15 Sep 2020 14:13:04 -0400 From: Steven Rostedt To: Gaurav Kohli Cc: mingo@redhat.com, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: Re: [PATCH] trace: Fix race in trace_open and buffer resize call Message-ID: <20200915141304.41fa7c30@gandalf.local.home> In-Reply-To: <08d6f338-3be3-c5a2-ba4b-0116de9672c2@codeaurora.org> References: <1599199797-25978-1-git-send-email-gkohli@codeaurora.org> <2fe2a843-e2b5-acf8-22e4-7231d24a9382@codeaurora.org> <20200915092353.5b805468@gandalf.local.home> <08d6f338-3be3-c5a2-ba4b-0116de9672c2@codeaurora.org> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 15 Sep 2020 22:53:32 +0530 Gaurav Kohli wrote: > On 9/15/2020 6:53 PM, Steven Rostedt wrote: > > On Tue, 15 Sep 2020 10:38:03 +0530 > > Gaurav Kohli wrote: > > > >> > >> >>> +void ring_buffer_mutex_release(struct trace_buffer *buffer) > >> >>> +{ > >> >>> + mutex_unlock(&buffer->mutex); > >> >>> +} > >> >>> +EXPORT_SYMBOL_GPL(ring_buffer_mutex_release); > >> > > >> > I really do not like to export these. > >> > > >> > >> Actually available reader lock is not helping > >> here(&cpu_buffer->reader_lock), So i took ring buffer mutex lock to > >> resolve this(this came on 4.19/5.4), in latest tip it is trace buffer > >> lock. Due to this i have exported api. > > > > I'm saying, why don't you take the buffer->mutex in the > > ring_buffer_reset_online_cpus() function? And remove all the protection in > > tracing_reset_online_cpus()? > > Yes, got your point. then we can avoid export. Actually we are seeing > issue in older kernel like 4.19/4.14/5.4 and there below patch was not > present in stable branches: > > ommit b23d7a5f4a07 ("ring-buffer: speed up buffer resets by > > avoiding synchronize_rcu for each CPU") If you mark this patch for stable, you can add: Depends-on: b23d7a5f4a07 ("ring-buffer: speed up buffer resets by avoiding synchronize_rcu for each CPU") > > Actually i have also thought to take mutex lock in ring_buffer_reset_cpu > while doing individual cpu reset, but this could cause another problem: Hmm, I think we should also take the buffer lock in the reset_cpu() call too, and modify tracing_reset_cpu() the same way. > > Different cpu buffer may have different state, so i have taken lock in > tracing_reset_online_cpus. Why would different states be an issue in synchronizing? -- Steve > > > > void tracing_reset_online_cpus(struct array_buffer *buf) > > { > > struct trace_buffer *buffer = buf->buffer; > > > > if (!buffer) > > return; > > > > buf->time_start = buffer_ftrace_now(buf, buf->cpu); > > > > ring_buffer_reset_online_cpus(buffer); > > } > > > > The reset_online_cpus() is already doing the synchronization, we don't need > > to do it twice. > > > > I believe commit b23d7a5f4a07 ("ring-buffer: speed up buffer resets by > > avoiding synchronize_rcu for each CPU") made the synchronization in > > tracing_reset_online_cpus() obsolete. > > > > -- Steve > > > > Yes, with above patch no need to take lock in tracing_reset_online_cpus.