Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1657127rdb; Sat, 3 Feb 2024 16:56:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IEoThqObCfr7Ub0qSD89ZazfKvQXbJIce2hdWiCJDxxUQjbNLA2fZ4eG4o43LCL1HNG17UQ X-Received: by 2002:a17:90a:dc03:b0:296:6702:b042 with SMTP id i3-20020a17090adc0300b002966702b042mr1734303pjv.9.1707008212101; Sat, 03 Feb 2024 16:56:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707008212; cv=pass; d=google.com; s=arc-20160816; b=upZTQ3HYOg6U43cvt8FKidFx6JT5BZDkorVPGmbdIyUGQVByrWmx352lvhwsWz+6zN 0mq0YCLf+GRZA55HG8GMrc7UTsRAxaiR2fVlgnxJwC8Wo67b3ZnuuzPZzv1JuiCQFHvU mPLXgd3I851Wh3HH/s3d4eli82ROkxR55yY07UFeOSTUPdCYVHZrG8o/+XsIYSRytPdS TILHxtR1BdpnnfdECEv1ZiFf2pHz+CnxSs5WEE+qeZyUmjmnQayZa2waEMNsQR5LhWeN Dvi75AMCFnIiFtnBjGbFMwjtIOivOL+dSk4WHW4hD0QXgtfHfaIfpGORoAoJQahnQ3gq CIJw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date; bh=TEmovdONAfakoGgKxpPZ1wEpWBPnmf61mZ0SR2HmLFs=; fh=Uh7+U0+yhZKceIimXX8LY6rk3r+MdPlHGR6Lpi6SenA=; b=uJyitXoSUG6s8HxR7I7WrWuhckVe00Q6m0Lgkds53WC6kZwDiDEJcq5kcW26mdiXl6 OoYMtSBw7QA7aYa+e0pBmGenLXcJ4eL0SsR81J5tRn6uJbuJQIhK85f5Iv4HTt0etfKc FLC2RorUv/9LUxTGFnDRc/kP4Z1F0GGvVEvBqr1bOkdvd2NGd9a0ZPYwOnFDj0v+gpbO 9CxGuP53+/7F4DRjbo/v1kjcCmYykzjEul7ILhlHENtUjxqDqlnDZf0BMJhwF7XSdWwe 2CKFQ3HcJ59aX9Vr0N3eKRQCqTEUakWfc0ZRkYqYTaOFC9joHwyZPqrmYysIP/7RVWGN HNVQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51333-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51333-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVkrAClTl19GkjjEIlqjyHsoFX5vTIgExmlOzyQZYJibEKLqKpv0I6zS0gSHLK7DSQ/uKyCfPhV2r5I1pMuVBRtHHqWVAQCFKTjGEo/sw== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e17-20020a17090301d100b001d71ef41515si1762711plh.446.2024.02.03.16.56.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 16:56:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51333-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51333-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51333-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 12255B214D2 for ; Sun, 4 Feb 2024 00:54:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65535EC3; Sun, 4 Feb 2024 00:54:34 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C9E24629; Sun, 4 Feb 2024 00:54:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707008073; cv=none; b=DsQnLwwJU0H05Ma886+aSRKVk3fLb6vkDext26O5aq9NUQlIxySY5mgd6AEu8Hs0duRpzgxgrghL/1JEfH7mg43WT6aoxmMZaO7zffYco0yLFEAh1hpEAPJgmsK51BqH26EWs22mUBLlglaqpjRmRvPAtoxv1GQ3EoZJLPc7gBo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707008073; c=relaxed/simple; bh=8+TMVLIlwovQgAOFetceIDM9IyzbQckUF0NQPc0zzsw=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IsPsvsz8R8QG+UL0+x8tIG5NIQBeHH8k8slIgkD5B15tOCV10WDYj0UO/vvGivl94XBxEvwpWxvX+yUlNs6pEqSelTDs/xWUT8GBKwPJotE28JjcCrn8nqN1jaKvBPR1QIqymNdNdncvPQYRPV0auf1CgxmduH3HrNv9Xs1zwmA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 841C3C433C7; Sun, 4 Feb 2024 00:54:32 +0000 (UTC) Date: Sat, 3 Feb 2024 19:54:30 -0500 From: Steven Rostedt To: Vincent Donnefort Cc: Masami Hiramatsu , g@google.com, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, mathieu.desnoyers@efficios.com, kernel-team@android.com Subject: Re: [PATCH v13 2/6] ring-buffer: Introducing ring-buffer mapping functions Message-ID: <20240203195430.51171d85@rorschach.local.home> In-Reply-To: References: <20240129142802.2145305-1-vdonnefort@google.com> <20240129142802.2145305-3-vdonnefort@google.com> <20240130235510.c92a31ee6998697dd49d2600@kernel.org> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 30 Jan 2024 16:22:06 +0000 Vincent Donnefort wrote: > > > +static void rb_update_meta_page(struct ring_buffer_per_cpu *cpu_buffer) > > > +{ > > > + struct trace_buffer_meta *meta = cpu_buffer->meta_page; > > > + > > > + WRITE_ONCE(meta->reader.read, cpu_buffer->reader_page->read); > > > + WRITE_ONCE(meta->reader.id, cpu_buffer->reader_page->id); > > > + WRITE_ONCE(meta->reader.lost_events, cpu_buffer->lost_events); > > > + > > > + WRITE_ONCE(meta->entries, local_read(&cpu_buffer->entries)); > > > + WRITE_ONCE(meta->overrun, local_read(&cpu_buffer->overrun)); > > > + WRITE_ONCE(meta->read, cpu_buffer->read); > > > +} > > > + > > > static void > > > rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer) > > > { > > > @@ -5204,6 +5225,9 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer) > > > cpu_buffer->lost_events = 0; > > > cpu_buffer->last_overrun = 0; > > > > > > + if (cpu_buffer->mapped) > > > > There are some cpu_buffer->mapped are accessed via WRITE_ONCE/READ_ONCE() > > but others are not. What makes those different? > > The cpu_buffer->mapped is READ_ONCE for the section where it is not protected > with a lock. That is (in this version) only ring_buffer_swap_cpu(). > > That said... > > a. This is not enough protection at this level, Ideally the _map should also > call synchronize_rcu() to make sure the _swap does see the ->mapped > 0. > > b. With refcount for the snapshot in trace/trace.c, it is not possible for those > functions to race. trace_arm_snapshot() and tracing_buffers_mmap() are mutually > exclusive and already stabilized with the trace mutex. > > So how about I completely remove those WRITE_ONCE/READ_ONCE and just rely on the > protection given in trace/trace.c instead of duplicating it in > trace/ring_buffer.c? I would add a comment and replace the READ_ONCE with WARN_ON_ONCE(): /* It is up to the callers to not swap mapped buffers */ if (WARN_ON_ONCE(cpu_buffer_a->mapped || cpu_buffer_b->mapped)) { ret = -EBUSY; goto out; } -- Steve