Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2422327rdb; Wed, 21 Feb 2024 07:15:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUv/95Ix8R3YmuHjRjOQnzgJFXuFNhrXUQKYTTSS87txJ8u6Uc5OkcC+KyFrbYAT7NsC8+0I6YbdtRpLaXkHUkGfT7BdKycYh3f+HJTSw== X-Google-Smtp-Source: AGHT+IGK4lMA5+RrOEBicegbYWcD9kqnqrKAOyzGSg1oZ7iXW6oEJ6wghkC3HUqOmJaMmqOjGXEC X-Received: by 2002:a05:6a00:1ace:b0:6e4:9ba6:d153 with SMTP id f14-20020a056a001ace00b006e49ba6d153mr1707880pfv.8.1708528547187; Wed, 21 Feb 2024 07:15:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708528547; cv=pass; d=google.com; s=arc-20160816; b=WA/DDMvngMIfVn/NxMdIwpWucK7209cXTAbSts9bbf51SQeGEkxCXXlMwKUyryM/Zd VeYRR7j/DC58b5l9BeTkRwGeXLkhvALiWb2eSB5KRUxYJdgxeFR3kmJfGci8wRSbcbF4 egQaq9JEanlKwZi/xikzw3U/CqlBAtB1pcXDrfpLL8TwUMP0xn4Ti9asmdARDNuEkhU+ jR14bn3ePPjN9pGQxAEWZu+vAvM5YXlIf/znuUzGIv/nk7P6FLS5kZvk4HIh2IAMMke6 ytb4coLcRnNkOpncXe8SrTGfM1+rlcIyMbhp/du+Y/DUrqS/43vcLGJ1PfgVMXnG7Gp9 w6OA== 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=vmPDznbjkGOK5yNGOH2/SzhbqEwWnMLbKcXX3WdSUPY=; fh=UgJ1M/WLDuBX5Hd7iWpdBibTSPJm5+ZRhFuzMIW+uy0=; b=u0EdRReGMuaeqkeL6nqIPnVoBypdjTAR4sOfdIA6NTPgJdiDqbbyUbqcoM0vUTU9Fy m5mlwojvQrs0EBHmlEb0VMnT3NzgI4v3FP/XrQfSssK2NdXvpJrINXdhAGK5D93eNyTW g7sLwil5HT9UZA8qCU8lHfvenR4tSIzHrG0noCfYBwbyRLoPCfa9yFnh14FcjRIQ3fRH +Bb87dwVnJ/DrVOg6BdQ6+IfK6ciYM+3ugiP9+rLaI86QiPyEsLED68Y9Q6ybOQAS/Sz gV6Tl+3jxMsTiycDH0yf/H2PdmGfN2N7ROfktHtNJUYd0IGpKswbnwUig759P+EY01Ro c7YQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-74966-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74966-linux.lists.archive=gmail.com@vger.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 z24-20020a637e18000000b005dc13a2e7c1si8129754pgc.117.2024.02.21.07.15.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:15:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74966-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; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-74966-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74966-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 918DC28A90A for ; Wed, 21 Feb 2024 15:07:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 177827FBCA; Wed, 21 Feb 2024 15:06:47 +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 8E8A07FBA9; Wed, 21 Feb 2024 15:06:46 +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=1708528006; cv=none; b=g9mhDgnbJwXOPzPWeI3c1s2v7gyinI+XrYim2flwOKjxuylV8RWXLjiM+S6T7gKzqzauwk7ZJVDv2prf6WZAg6bt3Yq46ANT5puo3z7sdl6T939Fdibs+xL555vokTI00WBCVq9+rog0fFqv6BV+lvqAovX8YzOkj1eCk+cca1g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708528006; c=relaxed/simple; bh=x4tyllg3kVsxkFGprOI8+rA4D5kFS9LnDsPy0r+Wi6w=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OjeZGV1ngBqg0vrSQBpx3jwDneZDLu5Zjl2RZlHKcYFPLOZIMxPR25s/vFde6rKcopZL+FImmUOiVdzRkEAFdd5TpUfP1VztTMXO5Qx5IlD3qoH+wmsKA78CbiwM5+R5+UbM8B1RjSvCLbUobUtaVXkhHL/DVlupUpWCuhki8xc= 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 707B6C43394; Wed, 21 Feb 2024 15:06:45 +0000 (UTC) Date: Wed, 21 Feb 2024 10:08:33 -0500 From: Steven Rostedt To: Beau Belgrave Cc: mhiramat@kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, mathieu.desnoyers@efficios.com Subject: Re: [PATCH v3 2/4] tracing/user_events: Introduce multi-format events Message-ID: <20240221100833.1eb5c254@gandalf.local.home> In-Reply-To: <20240214175046.240-3-beaub@linux.microsoft.com> References: <20240214175046.240-1-beaub@linux.microsoft.com> <20240214175046.240-3-beaub@linux.microsoft.com> 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, 14 Feb 2024 17:50:44 +0000 Beau Belgrave wrote: > +static char *user_event_group_system_multi_name(void) > +{ > + char *system_name; > + int len = sizeof(USER_EVENTS_MULTI_SYSTEM) + 1; FYI, the sizeof() will include the "\0" so no need for "+ 1", but I don't think this matters as for what I mention below. > + > + system_name = kmalloc(len, GFP_KERNEL); > + > + if (!system_name) > + return NULL; > + > + snprintf(system_name, len, "%s", USER_EVENTS_MULTI_SYSTEM); > + > + return system_name; Hmm, the above looks like an open coded version of: system_name = kstrdup(USER_EVENTS_MULTI_SYSTEM, GFP_KERNEL); > +} > + > static struct user_event_group *current_user_event_group(void) > { > return init_group; > @@ -367,6 +390,11 @@ static struct user_event_group *user_event_group_create(void) > if (!group->system_name) > goto error; > > + group->system_multi_name = user_event_group_system_multi_name(); > + > + if (!group->system_multi_name) > + goto error; > + > mutex_init(&group->reg_mutex); > hash_init(group->register_table); > > @@ -1482,6 +1510,11 @@ static int destroy_user_event(struct user_event *user) > hash_del(&user->node); > > user_event_destroy_validators(user); > + > + /* If we have different names, both must be freed */ > + if (EVENT_NAME(user) != EVENT_TP_NAME(user)) > + kfree(EVENT_TP_NAME(user)); > + > kfree(user->call.print_fmt); > kfree(EVENT_NAME(user)); > kfree(user); > @@ -1504,12 +1537,24 @@ static struct user_event *find_user_event(struct user_event_group *group, > *outkey = key; > > hash_for_each_possible(group->register_table, user, node, key) { > + /* > + * Single-format events shouldn't return multi-format > + * events. Callers expect the underlying tracepoint to match > + * the name exactly in these cases. Only check like-formats. > + */ > + if (EVENT_MULTI_FORMAT(flags) != EVENT_MULTI_FORMAT(user->reg_flags)) > + continue; > + > if (strcmp(EVENT_NAME(user), name)) > continue; > > if (user_fields_match(user, argc, argv)) > return user_event_get(user); > > + /* Scan others if this is a multi-format event */ > + if (EVENT_MULTI_FORMAT(flags)) > + continue; > + > return ERR_PTR(-EADDRINUSE); > } > > @@ -1889,8 +1934,12 @@ static bool user_event_match(const char *system, const char *event, > struct user_event *user = container_of(ev, struct user_event, devent); > bool match; > > - match = strcmp(EVENT_NAME(user), event) == 0 && > - (!system || strcmp(system, USER_EVENTS_SYSTEM) == 0); > + match = strcmp(EVENT_NAME(user), event) == 0; > + > + if (match && system) { > + match = strcmp(system, user->group->system_name) == 0 || > + strcmp(system, user->group->system_multi_name) == 0; > + } > > if (match) > match = user_fields_match(user, argc, argv); > @@ -1923,6 +1972,39 @@ static int user_event_trace_register(struct user_event *user) > return ret; > } > > +static int user_event_set_tp_name(struct user_event *user) > +{ > + lockdep_assert_held(&user->group->reg_mutex); > + > + if (EVENT_MULTI_FORMAT(user->reg_flags)) { > + char *multi_name; > + int len; > + > + len = snprintf(NULL, 0, "%s.%llx", user->reg_name, > + user->group->multi_id) + 1; > + > + multi_name = kzalloc(len, GFP_KERNEL_ACCOUNT); > + > + if (!multi_name) > + return -ENOMEM; > + > + snprintf(multi_name, len, "%s.%llx", user->reg_name, > + user->group->multi_id); I believe the above can be replaced with: multi_name = kasprintf(GFP_KERNEL_ACCOUNT, "%s.%llx", user->reg_name, user->group->multi_id); if (!multi_name) return -ENOMEM; -- Steve > + > + user->call.name = multi_name; > + user->tracepoint.name = multi_name; > + > + /* Inc to ensure unique multi-event name next time */ > + user->group->multi_id++; > + } else { > + /* Non Multi-format uses register name */ > + user->call.name = user->reg_name; > + user->tracepoint.name = user->reg_name; > + } > + > + return 0; > +}