Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp631336rdb; Mon, 15 Jan 2024 08:24:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJtL2T0ROz7cjzeMoKU+gkyoaJX3y/Nddq3I80e3UljnU0ka7cpTCvVE+Nb/MtFZ/OYG6N X-Received: by 2002:a05:620a:1a27:b0:783:1683:548 with SMTP id bk39-20020a05620a1a2700b0078316830548mr7649315qkb.64.1705335849499; Mon, 15 Jan 2024 08:24:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705335849; cv=none; d=google.com; s=arc-20160816; b=JoBQA64d0EHJdCspS7CSCpIsIdyHuNAIwuBYvJRAblSyBoQRl0eiE8B36ghDTlVJGR 94opfIoXC0EwemNEICSbqTUP+zSBXnCNqnE9yikxtyoHhCNleTTH9WGCbxdVrR3fDIDa sXxDK4FtUSoPX4NCvl+XwIGDiWReNMJwjW+jrNNW7WJlJAaupeBmugQoXAm/DIwGgaWp ekURNFT3jky87fTbmAuuymaBAgi5hKhePNp1xt7ihJvZMY13zEKLB2iLw4Y8wP5Pop4n WVsPM2A8o5Rx4ixtIe0bCxHtshPWR8zPR3nDAukPfx9o2GBhz45IklH8KMyqwcrsVs1V sviw== ARC-Message-Signature: i=1; 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=dTwqwfvk0gAm6b/pI2vlxwBglTI4GxES1Ep5MV+TbiE=; fh=9NsraGzYoFYIdTb+acwdk5gD6m8pHsK28rjiAl8maec=; b=AME3U5duZe+OTRJ4SIS3pTSUH8YHDhgkhd4KGp4YM7HWitXAyY0vzyNQJCVTekdH0E nycqKNTjeeQeSKY4PrpqmlG28UcVDjcXBDVejJw5LNUmaBSF/xk45y1QySNtlzIX0Tf/ YTbPKWKUzMyWK8fyHAYUd2y69Q2yB4WyhYJKOYyzK5usZP0tzVBb5QIDdanMQ0HjNAM8 hsj4WoKLNDUkGJIRBFn/kgEz2B6o8A93tVtyIwWPok5okN93bIszU0x2xH36tQzTPsYL 6r3T7lecYv78ZTVCCEuOOeWnC0Vh720J+JSBqA86xIU9gNPqwKEbvpQXXlYfRTLLyb7M EUDw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-26251-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26251-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id y12-20020a05620a09cc00b00781ed52f62fsi8261975qky.531.2024.01.15.08.24.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 08:24:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26251-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-26251-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26251-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 446F81C21D2C for ; Mon, 15 Jan 2024 16:24:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CD62717BAF; Mon, 15 Jan 2024 16:24:02 +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 5D69717BA4; Mon, 15 Jan 2024 16:24:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6E5FC433C7; Mon, 15 Jan 2024 16:24:00 +0000 (UTC) Date: Mon, 15 Jan 2024 11:23:59 -0500 From: Steven Rostedt To: Vincent Donnefort Cc: Masami Hiramatsu , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, mathieu.desnoyers@efficios.com, kernel-team@android.com Subject: Re: [PATCH v11 2/5] ring-buffer: Introducing ring-buffer mapping functions Message-ID: <20240115112359.65dcecbf@rorschach.local.home> In-Reply-To: <20240115110938.613380ca@rorschach.local.home> References: <20240111161712.1480333-1-vdonnefort@google.com> <20240111161712.1480333-3-vdonnefort@google.com> <20240115134303.1a673e37b8e7d35a33d8df52@kernel.org> <20240115110938.613380ca@rorschach.local.home> 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 Mon, 15 Jan 2024 11:09:38 -0500 Steven Rostedt wrote: > No. The ring buffer logic should not care if the user of it is swapping > the entire ring buffer or not. It only cares if parts of the ring > buffer is being swapped or not. That's not the level of scope it should > care about. If we do not want a swap to happen in update_max_tr() > that's not ring_buffer.c's problem. The code to prevent that from > happening should be 100% in trace.c. What needs to be done, and feel free to add this as a separate patch, is to have checks where snapshot is used. (All errors return -EBUSY) Before allowing mapping, check to see if: 1) the current tracer has "use_max_tr" set. 2) any event has a "snapshot" trigger set 3) Any function has a "snapshot" command set Fail if any of the above is true. Also in reverse, if the buffer is mapped, then fail: 1) a tracer being set that has "use_max_tr" set. 2) a "snapshot" command being set on a function 3) a "snapshot" trigger being set on an event. For the last two, we may be able to get away with just a below as well. Adding the tr->flags bit. We could also add a tr->snapshot count to keep track of everything that is using a snapshot, and if that count is non-zero, mapping fails. diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 2a7c6fd934e9..f534f74ae80f 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -1175,6 +1175,12 @@ static void tracing_snapshot_instance_cond(struct trace_array *tr, return; } + if (tr->flags & TRACE_ARRAY_FL_MAPPED) { + trace_array_puts(tr, "*** BUFFER IS MEMORY MAPPED ***\n"); + trace_array_puts(tr, "*** Can not use snapshot (sorry) ***\n"); + return; + } + local_irq_save(flags); update_max_tr(tr, current, smp_processor_id(), cond_data); local_irq_restore(flags); -- Steve