Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp709956lqj; Sun, 2 Jun 2024 19:37:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVA1BWoj8KRw1Ji8cKzTFDoVNO+gAdUuulj+E+621wVRSG73oEXerrBOCKBAWiL4RP/pKymrY8w5YG4ndQMRI/fx0bk89T3wg6Uk9/vOA== X-Google-Smtp-Source: AGHT+IF4XEAmZqSW/hwzTPErhBWDhj/WpGCYwP0DBBs0vWj6t5IIP1VyBHCMHw+8htfHfYKZWisf X-Received: by 2002:a17:906:ae8b:b0:a68:a944:2699 with SMTP id a640c23a62f3a-a68a9442eabmr440884666b.4.1717382261931; Sun, 02 Jun 2024 19:37:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717382261; cv=pass; d=google.com; s=arc-20160816; b=IVhHwB2/znNBsqPg+wmGB4gPffOpX+BflzKv6F7PX1DYwZn4jQ5o7136ppIt4yI0eS dKSoF3KNLdtGGcX4W862HvAzIR73P+BqNUoWnwnGnnJHFb+1WVwjrAOrzhzzuE+Gd/is RCk1x6skrCpwxuS2Yq+jAGZKZCzKU93WEyXUjBoVmeFtudHj2o/4g23PpHwFk4EaMR/v n9HyRJki7kYwMHCwO10ek5MkxJC+knibJ+OrsORPIBS/HFMuTYebGfQyQBzECndFaXrT 0tbTb1UtLGkeQg6tUiRYaebwUMVzDAQzYWWKkv9t2M7b1HcJTQAzVOLSAGFQFnBziIoB powA== 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=m/zrbOc4DBa4w/g54mK1Ryj0O7UvjWGGQmuIq/kiMZw=; fh=jPbTOLaFRquCWSHePkx5JyHgrJfqc0pfK3tHoljjLqk=; b=t/cl4WB1m0Btdzk2zARWmOYytwdrpXBrwnPw9B4Yg36ExVi1gb0avtkgItuOXIHhmu OPiwsAILftRlP1iYLHQ2J1zrISb9rglYj8rHGJAF4FT9AlpnOIQ50p88A4mypChz7oZX DyD5tIDeAh9llGJpVpO97IrtV9NmyRdRisZUSjzO+b8x0ElPbDuZvrsIBtbrDgkDuOZn bn7zpeUteRNbYTXcWM/pRvdUH2dwo7dsMfAoT8lQq8ZhYAA6Sc/y1bRyxloC77leTarw /ofVhMyJtIUsribxtlB9xR0IAoY1XaIBi0AOzwtsjFbqAe1tAVKoEf4keVuHzA4O39a5 /sdQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JaZ1Qs4j; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-198547-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198547-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a67eb722fd1si341205266b.920.2024.06.02.19.37.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jun 2024 19:37:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198547-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JaZ1Qs4j; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-198547-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198547-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 am.mirrors.kernel.org (Postfix) with ESMTPS id A720D1F21633 for ; Mon, 3 Jun 2024 02:37:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2ED0D882B; Mon, 3 Jun 2024 02:37:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JaZ1Qs4j" 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 4BD662566; Mon, 3 Jun 2024 02:37:30 +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=1717382250; cv=none; b=jkdrdGzwvh1MHNniJvSxBoR9poIoGTgfTiOGqRKUyEypfnoH+fnX8X6Kk6auxbHAflg1/Y01+lHzIurxDcBZsdwGjRr8nHYcOCtBaSaOkgplljUrVP2bc89xCtIsk2NnUX0JGqnTjfsBdSFOH6irXc2UsPQZAemvVZvkcLOHasc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717382250; c=relaxed/simple; bh=NIzaEEdmhkDh0uGhxZPp5iX+ogXWqvyKuKECBW+n7O0=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=CK+hT1Cb94eWXs4efN21wlwwpVmSPckhAlnF8TlG9T9C6PdxIGvCeLEhgure19PizwO14eYlnHch0wkOrBcUP48pH/T3+lmxjqmdLexfbyck6YUFIpqj5fEkoun0QiCyAbR9DJm4X66BrVk9tx9Pa+tjtlOv7jXMqoRiIZr97fs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JaZ1Qs4j; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8A3AC2BBFC; Mon, 3 Jun 2024 02:37:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717382250; bh=NIzaEEdmhkDh0uGhxZPp5iX+ogXWqvyKuKECBW+n7O0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=JaZ1Qs4jkK7eicqpf+ZVdQ1SaHd5SmbcssQBSbE4iOc0WoSt0WLKrecFRW2wDVgdS SNn5ZWMPBxaXvE5qiKjEprt/dKFJYLMR7mFPa7RJpabL7t983AzQ0IYGrnVqO1TwyV gsgrapyOQ2kNVE/1ru+zjW4sj2Uiw2/anoy+/y3Ib9b8MHRL1PQND97NRXEa+pkf18 t6KQR+IPkfV79/mqCMTxJuvbk6rIvtdSNsaL+p6+3LSLZ3PUK7DWccu6RpB12Fv5Nb QLxjZIgFnukVllECh4huW3R5Lu3Os2WXvGyYn/m6TRRQQaLFypp6Jov9MS1ZOAFRew 9lcST+XFzf5NQ== Date: Mon, 3 Jun 2024 11:37:23 +0900 From: Masami Hiramatsu (Google) To: Steven Rostedt Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Alexei Starovoitov , Florent Revest , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: Re: [PATCH v2 11/27] ftrace: Allow subops filtering to be modified Message-Id: <20240603113723.b192c8c346e0ed55cb94b61a@kernel.org> In-Reply-To: <20240602033832.870736657@goodmis.org> References: <20240602033744.563858532@goodmis.org> <20240602033832.870736657@goodmis.org> 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 Sat, 01 Jun 2024 23:37:55 -0400 Steven Rostedt wrote: [...] > > +static int ftrace_hash_move_and_update_subops(struct ftrace_ops *subops, > + struct ftrace_hash **orig_subhash, > + struct ftrace_hash *hash, > + int enable) > +{ > + struct ftrace_ops *ops = subops->managed; > + struct ftrace_hash **orig_hash; > + struct ftrace_hash *save_hash; > + struct ftrace_hash *new_hash; > + int ret; > + > + /* Manager ops can not be subops (yet) */ > + if (WARN_ON_ONCE(!ops || ops->flags & FTRACE_OPS_FL_SUBOP)) > + return -EINVAL; This does return if ops->flags & FTRACE_OPS_FL_SUBOP, but --> (1) > + > + /* Move the new hash over to the subops hash */ > + save_hash = *orig_subhash; > + *orig_subhash = __ftrace_hash_move(hash); > + if (!*orig_subhash) { > + *orig_subhash = save_hash; > + return -ENOMEM; > + } > + > + /* Create a new_hash to hold the ops new functions */ > + if (enable) { > + orig_hash = &ops->func_hash->filter_hash; > + new_hash = append_hashes(ops); > + } else { > + orig_hash = &ops->func_hash->notrace_hash; > + new_hash = intersect_hashes(ops); > + } > + > + /* Move the hash over to the new hash */ > + ret = ftrace_hash_move_and_update_ops(ops, orig_hash, new_hash, enable); This also a bit wired to me. maybe we need simple version like `__ftrace_hash_move_and_update_ops()` And call it from ftrace_hash_move_and_update_ops() and here? > + > + free_ftrace_hash(new_hash); > + > + if (ret) { > + /* Put back the original hash */ > + free_ftrace_hash_rcu(*orig_subhash); > + *orig_subhash = save_hash; > + } else { > + free_ftrace_hash_rcu(save_hash); > + } > + return ret; > +} > + > + > static u64 ftrace_update_time; > unsigned long ftrace_update_tot_cnt; > unsigned long ftrace_number_of_pages; > @@ -4770,8 +4823,33 @@ static int ftrace_hash_move_and_update_ops(struct ftrace_ops *ops, > { > struct ftrace_ops_hash old_hash_ops; > struct ftrace_hash *old_hash; > + struct ftrace_ops *op; > int ret; > > + if (ops->flags & FTRACE_OPS_FL_SUBOP) > + return ftrace_hash_move_and_update_subops(ops, orig_hash, hash, enable); (1) This calls ftrace_hash_move_and_update_subops() if ops->flags & FTRACE_OPS_FL_SUBOP ? Thank you, > + > + /* > + * If this ops is not enabled, it could be sharing its filters > + * with a subop. If that's the case, update the subop instead of > + * this ops. Shared filters are only allowed to have one ops set > + * at a time, and if we update the ops that is not enabled, > + * it will not affect subops that share it. > + */ > + if (!(ops->flags & FTRACE_OPS_FL_ENABLED)) { > + /* Check if any other manager subops maps to this hash */ > + do_for_each_ftrace_op(op, ftrace_ops_list) { > + struct ftrace_ops *subops; > + > + list_for_each_entry(subops, &op->subop_list, list) { > + if ((subops->flags & FTRACE_OPS_FL_ENABLED) && > + subops->func_hash == ops->func_hash) { > + return ftrace_hash_move_and_update_subops(subops, orig_hash, hash, enable); > + } > + } > + } while_for_each_ftrace_op(op); > + } > + > old_hash = *orig_hash; > old_hash_ops.filter_hash = ops->func_hash->filter_hash; > old_hash_ops.notrace_hash = ops->func_hash->notrace_hash; > -- > 2.43.0 > > -- Masami Hiramatsu (Google)