Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp7608rdb; Wed, 14 Feb 2024 10:59:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXUYaO10/KtSwDt/DgEI5LWwKuY/UJtiOwClJ8Sb1zzOkSShbfjn7GP9/mgiKyOoAm4hN9sJjQUzkP8V7owFsQ2qxB8gmOd4mnNzM8Vhg== X-Google-Smtp-Source: AGHT+IE5zpjOhYJNcI1xzQDW8at2+SvTeTZaH2qgI4WJv/s3M4hTQ7qgevciD1AyuPgPyIuzODmc X-Received: by 2002:a17:906:eb50:b0:a3c:f4e8:ac38 with SMTP id mc16-20020a170906eb5000b00a3cf4e8ac38mr2336048ejb.9.1707937158254; Wed, 14 Feb 2024 10:59:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707937158; cv=pass; d=google.com; s=arc-20160816; b=NBaYQHAW0xgMzxK1CZOw6x/nL2kWAibGsPwrOE0sGdboeZUayD1dyzEy/Lt55CwV/u tCe2qrGuVXFoU4bRx+yQshZzK3tI6HONgyUU24rvxuieQ/3hEVyshRvsmZYdneXLY9Mh C1/qw9sNr81fzOVFX8gAvbFpu41OmBQwevLqZgWQkQUdxmdmpkAPfztB000eZwWoSOFl nkTxBq5D3+IvuYd8H9ZS5OcEBN5kpB/Zxy6Xe03fgGNkS2cbuoZBF2cV/Y5q7Ro1JKdh GzdUpXf/YHckL/mYuGQ8hbc418ihvLNCrYOaODNdNXKu8wJi869konPzqY97ivUfoiXn XCUQ== 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=jdsq0HiN/fDLEYKu2ku/YHzbo7FiB5Hk5+wibG0Q/1g=; fh=4zTOZ/EN3q9ywH0pmFY3uPCOjBOx46UBwgh/zQtOweY=; b=XoHmrkJTs//Lkhb0NWrW9rRvoaeOKVngd2X6kuZsawyNCuj3MHk2EToRqpvtxCpEa9 C/FxHUAg5d5gn91CSOp9LlLRd1MgSEpvMGUUYyIIawIfLXrwHUqytGEzyh7S0eYyAVzV NU9FbFbrqSIOJtCRsnt3ayAUvQ9zl515aDvReReEezdI0z8B7qNUDMToT/TzJVTGBECg k45uBq7iFQoyH3P9XdnO8HBbJOfbxoMZE21aOQZQLYtP+m0WrFZK8CjZrRtHugRiSe2U W3prugn2065dCdqDLeKyY4kO7ivIh0O6vCprXmIebnS8hVYnxnJVhRkHtGxbuSMMes1l lwPQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-65851-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65851-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCXxQ6LcJ90VJGPSSz6MZcqRB3cclpKDy4n0bA4fYzT2d5dcx+68tklTS8LK/hZbODVW0+M1xiMMpfvEbnrUIC3zGACB93kK3SP+ZXaYtA== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d13-20020a1709067f0d00b00a3d5a98bcc0si532024ejr.654.2024.02.14.10.59.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 10:59:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65851-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-65851-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65851-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 am.mirrors.kernel.org (Postfix) with ESMTPS id C96971F2C350 for ; Wed, 14 Feb 2024 18:58:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 177FB13A863; Wed, 14 Feb 2024 18:58:30 +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 8B072134738; Wed, 14 Feb 2024 18:58:29 +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=1707937109; cv=none; b=r2ZTEtir8FUEgQ7iUOqLWGDeVJzTYqIbPjy8AcahrPiJ0qpUPj3hGnAr27QuNFGFvm69ugPLrLCWvIhqvtsVyuOaTCsPAuc1N+SifXtmpJ8ogDz4LBgoW/c0M2dMWjeD3KjS/kbGBFK1e3aOTPb0hFBa4Y3V7z1KYGawJbwawBU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707937109; c=relaxed/simple; bh=NJ0teznko9avctRgXsk9CYac2kHQHkkdyHoR2QZxcIc=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j0jdL/FrbYLgZn25ECWlmfDgpeQwSZ+WRpzPVe7X8ByGyxB0u46EQvNKxQTR+Pvnp72K+59m43lXKsqKNmTyKwksuWS80e/31B9FYqwZBs3V/f7znguRD6+EfVX3J0t9P7jfLuHxIGlMEZ0MYO5anChRw3CB6mJv6cj4TxPiQqg= 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 478F5C433C7; Wed, 14 Feb 2024 18:58:27 +0000 (UTC) Date: Wed, 14 Feb 2024 13:59:58 -0500 From: Steven Rostedt To: "Masami Hiramatsu (Google)" Cc: Alexei Starovoitov , Florent Revest , linux-trace-kernel@vger.kernel.org, LKML , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Mark Rutland , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: Re: [PATCH v7 19/36] function_graph: Implement fgraph_reserve_data() and fgraph_retrieve_data() Message-ID: <20240214135958.23ed55e1@gandalf.local.home> In-Reply-To: <170723226123.502590.4924916690354403889.stgit@devnote2> References: <170723204881.502590.11906735097521170661.stgit@devnote2> <170723226123.502590.4924916690354403889.stgit@devnote2> X-Mailer: Claws Mail 3.19.1 (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 Wed, 7 Feb 2024 00:11:01 +0900 "Masami Hiramatsu (Google)" wrote: > From: Ste > +/** > + * fgraph_reserve_data - Reserve storage on the task's ret_stack > + * @idx: The index of fgraph_array > + * @size_bytes: The size in bytes to reserve > + * > + * Reserves space of up to FGRAPH_MAX_DATA_SIZE bytes on the > + * task's ret_stack shadow stack, for a given fgraph_ops during > + * the entryfunc() call. If entryfunc() returns zero, the storage > + * is discarded. An entryfunc() can only call this once per iteration. > + * The fgraph_ops retfunc() can retrieve this stored data with > + * fgraph_retrieve_data(). > + * > + * Returns: On success, a pointer to the data on the stack. > + * Otherwise, NULL if there's not enough space left on the > + * ret_stack for the data, or if fgraph_reserve_data() was called > + * more than once for a single entryfunc() call. > + */ > +void *fgraph_reserve_data(int idx, int size_bytes) > +{ > + unsigned long val; > + void *data; > + int curr_ret_stack = current->curr_ret_stack; > + int data_size; > + > + if (size_bytes > FGRAPH_MAX_DATA_SIZE) > + return NULL; > + > + /* Convert to number of longs + data word */ > + data_size = DIV_ROUND_UP(size_bytes, sizeof(long)); Hmm, the above is a fast path. I wonder if we should add a patch to make that into: if (unlikely(size_bytes & (sizeof(long) - 1))) data_size = DIV_ROUND_UP(size_bytes, sizeof(long)); else data_size = size_bytes >> (sizeof(long) == 4 ? 2 : 3); to keep from doing the division. -- Steve > + > + val = get_fgraph_entry(current, curr_ret_stack - 1); > + data = ¤t->ret_stack[curr_ret_stack]; > + > + curr_ret_stack += data_size + 1; > + if (unlikely(curr_ret_stack >= SHADOW_STACK_MAX_INDEX)) > + return NULL; > + > + val = make_fgraph_data(idx, data_size, __get_index(val) + data_size + 1); > + > + /* Set the last word to be reserved */ > + current->ret_stack[curr_ret_stack - 1] = val; > + > + /* Make sure interrupts see this */ > + barrier(); > + current->curr_ret_stack = curr_ret_stack; > + /* Again sync with interrupts, and reset reserve */ > + current->ret_stack[curr_ret_stack - 1] = val; > + > + return data; > +} > +