Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp138684rdb; Wed, 14 Feb 2024 15:48:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW6OD/lTrP2BKdaDwuOxgVb5imV+x4Y9EJL3fawVI1LgZyfd1hHt/uY6figoWRjcPUjSGrYXsEXOmlyuz7oHplAaxRN+DzyH+sCb/su0w== X-Google-Smtp-Source: AGHT+IF7xKAPo36SLn9fRMRw/vDec2Sq1PGnTyOrx6KyqFYcnYUP/YhEtM2jWG3HWAE/KgPOX2ID X-Received: by 2002:a17:90a:9709:b0:296:9d63:1d9f with SMTP id x9-20020a17090a970900b002969d631d9fmr173639pjo.47.1707954534268; Wed, 14 Feb 2024 15:48:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707954534; cv=pass; d=google.com; s=arc-20160816; b=U6rK0s0eyQxsMZzkr88gfCSWqrzLzKDhc9syCMukU7PO7wk5BcmvV6SvYmzTpwg3vP MJk9d3x9cNvlQjBBsFXCbMDPuXBK9geEesYldXv1RaNrYwUyBzfxMT2CrbkIzhSbkOc3 lyZRdPsZ6hTtC30IqlBkT534jK3Im7Kr5xTe+KkSugJ/n2jJLeLpUN2uoORVUSHNsfr1 dmNL1rhsTY47C8cUDtm9zYl41s6cJnIZ6Aa7Cxyt6cweV54g9TorafPSJmYpMI1P7Kwt u5Xn6iHdVaXiecOftT3C0fomqLcgyeywEFkJQ+WzNkkBnox/hS1HdrjBxRR4vzM4z1U3 qnaw== 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:dkim-signature; bh=pC9uszEpgmkRGeTTGctYr9NOzeA2yq2UeiCbDAvoC9Y=; fh=Ub95fBsiseQVLo56fdyDA2zH9Ec5p8qFryhFaIE+jLo=; b=K2TZAnVsaWhDUnG8A5KMIR0mnnjICukiArKcGJejyzMs5DR8pW01i0fcnF6bnMyNAX v6x8wkCOQynq6kaE7pZrjfjhwkKpP+1VVznG7XP/HAZJ353EFxb2inA/nFkMcLdm1Ymq ZLt2Z7RT9bqCwCQNURT1J9ROBkkb/6q5YvO2m07wMA3le2SNKCR5Qop9QWtdElpu43cT kpxJ1s2GY7cZhcclKGDR0uotRKmZ7uE+yXWQ5HAYXbNx1ezufiHPaPEAcbHipSwyS5h3 35Vev3o0zesDVd98146x46SGiDIxtX/WkzcSfrApNkjGfW+UUWQdxyoFEVDr3fARMVv6 5udw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="ROb/g6o4"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-66129-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66129-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k2-20020a170902ba8200b001db80f8fbf2si18300pls.262.2024.02.14.15.48.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 15:48:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66129-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="ROb/g6o4"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-66129-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66129-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 62C7A28E8B5 for ; Wed, 14 Feb 2024 23:46:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7288F145346; Wed, 14 Feb 2024 23:45:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ROb/g6o4" 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 8FE2D13DB90; Wed, 14 Feb 2024 23:45:58 +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=1707954358; cv=none; b=ijam2aRpr+124yIW6Usu1/ONrs88xIlM2qTz0Arcj4sbLk7ZpKNDD1r6RAMDV4Rp5ykNaDiOOqD8sgMRuu7fKO0yKKtZScimQd/vWwhDs/FLj7bJmrqTviWlFOQxcMsgfLC47MInUG5pxo721F+aLyfM6pplv/CM1fo/PQv6XMY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707954358; c=relaxed/simple; bh=hn5Jto1lbD3UHNlb8zUDUPu4Gm63tv903DcDXQ0+ApI=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=agpvCoibGdYldhjn0vRE4r+x706HBjRHiGCzvN0udnMcu9c0SCJYpW7AmVMAaxknfQl+KjFE3kOqwXrPp9wL/Xn0310ANYBitPvRvJI/+WJd4D6n591+7d8XNMcBuo3WZwaoqIcN5tlACFQRxXFHUeIC8/Hvp7rRYyzsJ4/I/50= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ROb/g6o4; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A81BDC433F1; Wed, 14 Feb 2024 23:45:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707954358; bh=hn5Jto1lbD3UHNlb8zUDUPu4Gm63tv903DcDXQ0+ApI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ROb/g6o4xeezKeZLKlXyLy3rPKgfQLts9chQg4z2aKEOn6iAzcTEYaZsmNGajI9NN G3xX8reIVUmp0jCg3fdzBXzBZW1gcW2IBX0xwrA7//yVVm609XLvRPY0SZJOKGsyUU dOZjWr6jSUoTfskYgTsK6Kh0PolaH5QBU7IpscamflkQxirQKnZSL4VrwIgFA6PEmS A9Zndmm5qaijY8dyxVZy1UbZeO5U/QomSplCyr5mgwn6XhqvAtdGxuxYIDUNNyeO0q 8E3vdGLhm9x3A0jS7D3OPDaAgpZvq9QFiaRvNQ5o9bSmcwZoLMRwZYRlzWsljy+NfY GkzGElWMW+CbQ== Date: Thu, 15 Feb 2024 08:45:52 +0900 From: Masami Hiramatsu (Google) To: Steven Rostedt 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: <20240215084552.b72d6d22ce1b93bb8e04b70a@kernel.org> In-Reply-To: <20240214135958.23ed55e1@gandalf.local.home> References: <170723204881.502590.11906735097521170661.stgit@devnote2> <170723226123.502590.4924916690354403889.stgit@devnote2> <20240214135958.23ed55e1@gandalf.local.home> X-Mailer: Sylpheed 3.7.0 (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, 14 Feb 2024 13:59:58 -0500 Steven Rostedt wrote: > 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. OK, I thought DIV_ROUND_UP was not much cost. Since sizeof(long) is fixed 4 or 8, so data_size = (size_bytes + sizeof(long) - 1) >> BITS_PER_LONG; will this work? Thanks, > > -- 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; > > +} > > + -- Masami Hiramatsu (Google)