Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1963333lql; Wed, 13 Mar 2024 13:12:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUrS5irhsTas8uHxbmKxul8HQq2Rd/hLeQXdWPb+2Ip9v/C8+V1t/fiCZppPgYunDr2d7kaL44mtUs7/5X3DD3kIysWMkFF/0yKATy9GA== X-Google-Smtp-Source: AGHT+IHv4Wuu4cN9xeucCIKo+j0FYWm2VBX8b6PbS7q2uvHWyc5LpLusERXS+oUlV1Gylj2CgghM X-Received: by 2002:a67:ff89:0:b0:474:c79e:f4fa with SMTP id v9-20020a67ff89000000b00474c79ef4famr839241vsq.23.1710360748933; Wed, 13 Mar 2024 13:12:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710360748; cv=pass; d=google.com; s=arc-20160816; b=Ow5Yts3mA5pJiqZqTikke8itfyouoOAD7HwNHnT7GeHl1JVzpvgB+fdAIlEvhENRCD EwJ16+TQPQzg5SQCQO2TDB86HTuBtUha0ghsUUwe5wcZuZqd2NskDrEJ6z8CxvAY3Wo8 Idwi98ews+LmhOXM/H3i+3PSY1Xfn4oGKvPzttNXjDJVo0weJjrcaoI7ADbI+6gKSWfA 6Nw8l2LCU/bK4waX26nm8ArkIzO7G7CKj+RhfEjfEb1/akZ52/rnqNTJtAOIBTbe+Uu2 cBSi2csFqrRyTt7S/i8Y8LicSFGpF3A9kWRnie9EqLjxQJjtu31U85pdNt2XbPtE+BK+ bl1g== 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=ju4VnT4fQ0/ovPLDFfkT/jNGcP0m70wIdpfYbPHrNio=; fh=nPY7Ay+tpT9pLJA9/al1Q0QE4Y9AIA5mgBBWvDrnJhk=; b=dgPDb/w2zmJ4y5eMJGi1CZrlHTOxWJ+3ElIJPQI/YPDA4J9kxtQ+XLuN2DcqCJPED+ ETm1UoGff4pg9qPhP8hH2KXaYVyrtN7jvI1RCBf6+gPfBFF1BnHLvOLwD/e/4VNkJPuA +NT6Lew5RkIbCWA33qUmRR8eGujBYA1RuQ12BapQrjfbVoq46BZbF7fxQFRgS7x3SCoB UUrsEIMPqjgfkldF2/cnbZGWXPZv2i5Qvx59iqIV7wgqYEHMBb1JqvVepyvaPKq4cGtO uE9EQeO6ow2t6S9L34rL8g3PJAY5ygEh5h8aJOOhd1RFYncpO5wECGE7Of5anayuIQWt ragA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-102477-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102477-linux.lists.archive=gmail.com@vger.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 3-20020a0562140d0300b00690ab4beb40si10204025qvh.287.2024.03.13.13.12.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 13:12:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-102477-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; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-102477-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102477-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A59A21C2276E for ; Wed, 13 Mar 2024 20:12:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6253251C33; Wed, 13 Mar 2024 20:12:13 +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 D536B50243; Wed, 13 Mar 2024 20:12:12 +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=1710360732; cv=none; b=FGWrJ/NsQcU6ZWaYW9SGc7yv7DMvRodnYIjpk3NE8AOJqLpobO6mrvnz/AsJ6KtY7vDePwMX50eYkpcXtOthF1reNQ5yYxwM2j5J4/Af814KnqjjsUbMSZnWuNfyTdZrpgr/gVXHxCAYfv4TB8fdMw3aiyfmxwFakyXsmJduABQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710360732; c=relaxed/simple; bh=DoSvdQHEHpaTFMIhARnfPiNgrJvH1Ozx282n9iN1Boc=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UEHvMzLk1OQ2fg/YnN4zkndK7c946d5l8oWAJoOCxBPdb6crhL0mbMN0ClYZygJwu6/nzCeRa+Po+7mvXNWlD1JUv0lORfKIrDCfrSzGj8Inx8qfCV9pHrywRTRgu3g5VubLJ4GlZ+2cw3ApmxIK6vPmNwN8V+RKbao17Pa+THM= 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 9E8C4C433C7; Wed, 13 Mar 2024 20:12:11 +0000 (UTC) Date: Wed, 13 Mar 2024 16:14:20 -0400 From: Steven Rostedt To: Nathan Chancellor Cc: LKML , Linux Trace Kernel , Masami Hiramatsu , Mathieu Desnoyers , kernel test robot , llvm@lists.linux.dev Subject: Re: [PATCH] tracing: Use strcmp() in __assign_str() WARN_ON() check Message-ID: <20240313161420.3b668558@gandalf.local.home> In-Reply-To: <20240313134550.68a11319@gandalf.local.home> References: <20240312113002.00031668@gandalf.local.home> <20240313165903.GA3021536@dev-arch.thelio-3990X> <20240313134550.68a11319@gandalf.local.home> 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, 13 Mar 2024 13:45:50 -0400 Steven Rostedt wrote: > Let me test to make sure that when src is a string "like this" that it does > the strcmp(). Otherwise, we may have to always do the strcmp(), which I > really would like to avoid. I added the below patch and enabled sched_switch and it triggered the warning (expected if it went the strcmp() path). I then changed it to be: #define __assign_str(dst, src) \ do { \ char *__str__ = __get_str(dst); \ int __len__ = __get_dynamic_array_len(dst) - 1; \ WARN_ON_ONCE(__builtin_constant_p(src) ? \ strcmp((src), __data_offsets.dst##_ptr_) : \ - (src) != __data_offsets.dst##_ptr_); \ + (src) == __data_offsets.dst##_ptr_); \ memcpy(__str__, __data_offsets.dst##_ptr_ ? : \ EVENT_NULL_STR, __len__); \ __str__[__len__] = '\0'; \ } while (0) And the sched_switch did not trigger (expected). So it seems that it should not be a problem. Note, I only tested this with gcc and not clang. But I guess there's also the case where we have: __assign_str(str, field ? field : "NULL") But hopefully that's not an issue. -- Steve diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index dbb01b4b7451..eaacd0c4e899 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -236,6 +236,7 @@ TRACE_EVENT(sched_switch, __array( char, next_comm, TASK_COMM_LEN ) __field( pid_t, next_pid ) __field( int, next_prio ) + __string( test, "this") ), TP_fast_assign( @@ -246,6 +247,7 @@ TRACE_EVENT(sched_switch, memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN); __entry->next_pid = next->pid; __entry->next_prio = next->prio; + __assign_str(test, "this"); /* XXX SCHED_DEADLINE */ ), diff --git a/include/trace/stages/stage6_event_callback.h b/include/trace/stages/stage6_event_callback.h index 83da83a0c14f..cf301c723fd0 100644 --- a/include/trace/stages/stage6_event_callback.h +++ b/include/trace/stages/stage6_event_callback.h @@ -36,7 +36,7 @@ char *__str__ = __get_str(dst); \ int __len__ = __get_dynamic_array_len(dst) - 1; \ WARN_ON_ONCE(__builtin_constant_p(src) ? \ - strcmp((src), __data_offsets.dst##_ptr_) : \ + !strcmp((src), __data_offsets.dst##_ptr_) : \ (src) != __data_offsets.dst##_ptr_); \ memcpy(__str__, __data_offsets.dst##_ptr_ ? : \ EVENT_NULL_STR, __len__); \