Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp673512rdb; Fri, 26 Jan 2024 07:24:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGD0QxxTYh98Bj7iWhbCKgCooAlN5PD658h1Ko/fzZ+Xf2gNj9CyyRgJZN855JAaS01J0/M X-Received: by 2002:a05:6214:1c4c:b0:686:ba26:9d23 with SMTP id if12-20020a0562141c4c00b00686ba269d23mr8303qvb.3.1706282680292; Fri, 26 Jan 2024 07:24:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706282680; cv=pass; d=google.com; s=arc-20160816; b=kt4i+EeUtyHnM0uYcS0XEZQXav53dbwyynLVBV9HGGVcmYdvHL0Pk4TUihkClISqJk 6hFeqFMmnpw+l1BTHkm6A5BG8X0uD/AgRLO2g+9RmrDC8juODlxbB1Ofyom1Nwy+fGnr XNTcjjKeNdZvyxJwj3lN49YfktQFXijoMugQ+nnQSdU2Fm+V88/MOtJB9H57qIFkhlfC rngUeoTxvr6YEogcST6STUNr0s5jsemdOHHte/NyMTsameROuJl82vXRyiUYQMopbjKP yDp38JPOMtAsZhaSeo+PFfaTC8tS9AK7mo/TEZCAYg5TaCTsSxwCEd5yo+qyRuVoxdQq xicQ== 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=l0i9pWctJd2nrh7oD+L6vNaqLHy6KX+X2MPoOFMjc4o=; fh=MHFbjiEyIRiJDyyjklkE8bixMO1uD9yEJOq7UyhE4VE=; b=yNjSrCyqKbPucOtEySU/GAWH9uPg4e9qYidtW9kMVVwM5/96nvQf5xq7lvIoOCEIh+ w3VKhXyCeoxFKd54nO9ttqCV5fyEgwh2VOMU7DLtyGecpgvMFJzCTHSrkepTAaWVd9A4 vz32cw+r90v/D1fe0ejUxDNwvfmFmx1CLotmHEqRVIzqPjm7NpOkpzfid1B/eCyOT5Ns aJoLWU21h7RY3oZqho8lcruga5ds/eqH4Qml3Y0TgCa12j47lWcG0/7KHy8tBgchKX45 O2Gsz9NMfC8/9Zf+PnrfrXnQFyjbPgDNSEypXnY7hIQTsJ+m1S6PtHeZC4Q5HroKNwS+ bq1A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uOrmoKKP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-40266-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40266-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 j14-20020a05621419ce00b0067efac3f6f5si1500775qvc.67.2024.01.26.07.24.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 07:24:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40266-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uOrmoKKP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-40266-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40266-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 117781C21183 for ; Fri, 26 Jan 2024 15:24:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC4CB1CFAD; Fri, 26 Jan 2024 15:24:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uOrmoKKP" 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 1C9BD1D526; Fri, 26 Jan 2024 15:24:20 +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=1706282661; cv=none; b=fuQCAqedJZAoJ8rdaDIKjiKrs651ilD/MZPUyMv9G2cM9w8MC6Ama7Pjg4yM6+AtpATwMDavCxJEMRANAQOstcpTvQGIXsQfyaarUdlD6u7WScJ9c5YIiPF47c8uYjSn/GUPBhFjA7lqY3MO26v1ObmCfAR6VSiAKIVS+l1hJnk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706282661; c=relaxed/simple; bh=bgOxmLLVYSKMNC9czTxSMRA8wJQdkCUFghdAMXJg18U=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=EUGIyUQjSRMsYoHF6AsY2vYNsyUopPoZrenq00OJtT1ZXcZJcf9/VyfFLwm4INvc04pG6JGo+rmZ+A/Yn74WrRgGeIFVZdc3VC1+oB3y/basYIAKCgEzK/oj5hxQ4JyF0CSKx6FZql0zPp2/yn63+9yzIKDAZ6PhQPNc5VulqGg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uOrmoKKP; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9A36C433C7; Fri, 26 Jan 2024 15:24:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706282660; bh=bgOxmLLVYSKMNC9czTxSMRA8wJQdkCUFghdAMXJg18U=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=uOrmoKKPHgHwqifQmN5xAl63YrrtrfhDpY3l3HmG5+V2gz9iqF2sng9TY4+w07UF0 aPrZxn4W67F5MLikBia+9nmbJQ55880qxg7hnp07lYN5Sg8NMCFd6azVnBYpBeYDU3 wAwc90yVhWeDZ5s2Y+/712MFSLf6qSfFsOkaEB+/50ztHgl6q+ci7OQ93BMa/O0WSH /9JFWLRLNyokDN80MjA2nPC5lIMyNAPR/EVriEgDaGqq2mhp5TajJzePAN2qyVEGus 5j12xQLpgqcxB8wxV/Y6J6Sh4Sd9JAu3VPO1Kca1/1vltz3vP27bbdkN5yW0XxPSvX a+NkEuLuQoXFQ== Date: Sat, 27 Jan 2024 00:24:14 +0900 From: Masami Hiramatsu (Google) To: Jiri Olsa Cc: Alexei Starovoitov , Steven Rostedt , Florent Revest , linux-trace-kernel@vger.kernel.org, LKML , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Mark Rutland , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: Re: [PATCH v6 32/36] fprobe: Rewrite fprobe on function-graph tracer Message-Id: <20240127002414.660f2e477d210bc54ca4df89@kernel.org> In-Reply-To: References: <170505424954.459169.10630626365737237288.stgit@devnote2> <170505462606.459169.1375700979988728260.stgit@devnote2> 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 Thu, 25 Jan 2024 16:11:51 +0100 Jiri Olsa wrote: > On Fri, Jan 12, 2024 at 07:17:06PM +0900, Masami Hiramatsu (Google) wrote: > > SNIP > > > * Register @fp to ftrace for enabling the probe on the address given by @addrs. > > @@ -298,23 +547,27 @@ EXPORT_SYMBOL_GPL(register_fprobe); > > */ > > int register_fprobe_ips(struct fprobe *fp, unsigned long *addrs, int num) > > { > > - int ret; > > - > > - if (!fp || !addrs || num <= 0) > > - return -EINVAL; > > - > > - fprobe_init(fp); > > + struct fprobe_hlist *hlist_array; > > + int ret, i; > > > > - ret = ftrace_set_filter_ips(&fp->ops, addrs, num, 0, 0); > > + ret = fprobe_init(fp, addrs, num); > > if (ret) > > return ret; > > > > - ret = fprobe_init_rethook(fp, num); > > - if (!ret) > > - ret = register_ftrace_function(&fp->ops); > > + mutex_lock(&fprobe_mutex); > > + > > + hlist_array = fp->hlist_array; > > + ret = fprobe_graph_add_ips(addrs, num); > > so fprobe_graph_add_ips registers the ftrace_ops and actually starts > the tracing.. and in the code below we prepare fprobe data that is > checked in the ftrace_ops callback.. should we do this this earlier > before calling fprobe_graph_add_ips/register_ftrace_graph? Good catch! but I think this is safe because fprobe_entry() checks the fprobe_ip_table[] (insert_fprobe_node updates it) at first. Thus until the hash table is updated, fprobe_entry() handler will return soon. ---- static int fprobe_entry(unsigned long func, unsigned long ret_ip, struct ftrace_regs *fregs, struct fgraph_ops *gops) { struct fprobe_hlist_node *node, *first; unsigned long *fgraph_data = NULL; unsigned long header; int reserved_words; struct fprobe *fp; int used, ret; if (WARN_ON_ONCE(!fregs)) return 0; first = node = find_first_fprobe_node(func); if (unlikely(!first)) return 0; ---- The fprobe_table (add_fprobe_hash updates it) is used for return handler, that will be used by fprobe_return(). So I think it should be safe too. Or I might missed something? Thank you, > > jirka > > > + if (!ret) { > > + add_fprobe_hash(fp); > > + for (i = 0; i < hlist_array->size; i++) > > + insert_fprobe_node(&hlist_array->array[i]); > > + } > > + mutex_unlock(&fprobe_mutex); > > > > if (ret) > > fprobe_fail_cleanup(fp); > > + > > return ret; > > } > > EXPORT_SYMBOL_GPL(register_fprobe_ips); > > @@ -352,14 +605,13 @@ EXPORT_SYMBOL_GPL(register_fprobe_syms); > > SNIP -- Masami Hiramatsu (Google)