Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp896746rwb; Wed, 7 Dec 2022 06:22:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf6WHYLfrYjUUIxjoFCXlWrf5qqj1xkfDFQGnWvqR0yVuM8y7iLjaXeznkEoHvQck/Xj4ikY X-Received: by 2002:a17:906:2a9a:b0:7bb:e82a:83d with SMTP id l26-20020a1709062a9a00b007bbe82a083dmr49499053eje.612.1670422940881; Wed, 07 Dec 2022 06:22:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670422940; cv=none; d=google.com; s=arc-20160816; b=sta0ljVcY+UTs51tCLSqM1mPVEWk4j2M6rXIb14NmhVA+QBvklYjS+chWDOLkbWv+0 4ulHxaw1GCr/lbvgzWhkmRjCAvz06aQlqNgszd9ecFZRqWxdheEk3Qxt8HgvRYir7RXN NQH2yX2KaJuoGNfWc3V0Y99QjYGvqEQ8AYQ43YhwwjSUxOSbuXtWRF8DcpNLR7yABAhP DGPoMjUjCOrLZj2MFV88dAwEak1DtQuRDfoh8C4VOA6uP+AW9Kv2KpOvYi91C+h3suhZ +lVp08IWB7QPSnYkn1D7KvQ58wu2KjDrY/2yCBNLWEPMqp1CS5r1Gq41YqDci1NbGLRn NlcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=ZuAOcVMtX88NkGMB1k00XIJ8mjbi5/kg0iHZ7qxe+gc=; b=rX0KeGTS+F8g/ZBIkmU5vlfMwpdJgCC2zszpiNK37NVpkaBJBRd/Q1QfNKYHLJOGUr ToBAIWkSXQmJ9lQQEHbaxX9r/EECTRE/3g3GgaMiH9FyPfeCCOx2lkn1evNy3yxoadqu HkFqtjHXcu37AnXRCoENDNI7dwylwXppfdaAYWzjXi7zuY5iFTG/oTcqSopGpRB10W3v 56rzkvLSOJH9Jdt0a9kRQxjkxHEH17C/gBwuVIlQzuQSYbeM/LrGG8ladMHbhi7ngomY rGKZ3cI1YYXj0gzukw6TWZ6Y4pda5TR4tbLX9GXzb8dVtXOSjUMghnMQ4UsuKSTkKiNf VbWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b14-20020aa7c6ce000000b00457ebe79577si3814370eds.623.2022.12.07.06.21.59; Wed, 07 Dec 2022 06:22:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230129AbiLGNwr (ORCPT + 75 others); Wed, 7 Dec 2022 08:52:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229741AbiLGNwn (ORCPT ); Wed, 7 Dec 2022 08:52:43 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C705D6344; Wed, 7 Dec 2022 05:52:39 -0800 (PST) Received: from dggpeml100012.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NRzBy0p85zqSqk; Wed, 7 Dec 2022 21:48:26 +0800 (CST) Received: from localhost.localdomain (10.67.175.61) by dggpeml100012.china.huawei.com (7.185.36.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 7 Dec 2022 21:52:36 +0800 From: Zheng Yejian To: , , CC: , , Subject: [PATCH] tracing/hist: Fix issue of losting command info in error_log Date: Wed, 7 Dec 2022 21:53:26 +0800 Message-ID: <20221207135326.3483216-1-zhengyejian1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.175.61] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml100012.china.huawei.com (7.185.36.121) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When input some constructed invalid 'trigger' command, command info in 'error_log' are lost [1]. The root cause is that there is a path that event_hist_trigger_parse() is recursely called once and 'last_cmd' which save origin command is cleared, then later calling of hist_err() will no longer record origin command info: event_hist_trigger_parse() { last_cmd_set() // <1> 'last_cmd' save origin command here at first create_actions() { onmatch_create() { action_create() { trace_action_create() { trace_action_create_field_var() { create_field_var_hist() { event_hist_trigger_parse() { // <2> recursely called once hist_err_clear() // <3> 'last_cmd' is cleared here } hist_err() // <4> No longer find origin command!!! Since 'glob' is empty string while running into the recurse call, we can trickly check it and bypass the call of hist_err_clear() to solve it. [1] # cd /sys/kernel/tracing # echo "my_synth_event int v1; int v2; int v3;" >> synthetic_events # echo 'hist:keys=pid' >> events/sched/sched_waking/trigger # echo "hist:keys=next_pid:onmatch(sched.sched_waking).my_synth_event(\ pid,pid1)" >> events/sched/sched_switch/trigger # cat error_log [ 8.405018] hist:sched:sched_switch: error: Couldn't find synthetic event Command: hist:keys=next_pid:onmatch(sched.sched_waking).my_synth_event(pid,pid1) ^ [ 8.816902] hist:sched:sched_switch: error: Couldn't find field Command: hist:keys=next_pid:onmatch(sched.sched_waking).my_synth_event(pid,pid1) ^ [ 8.816902] hist:sched:sched_switch: error: Couldn't parse field variable Command: hist:keys=next_pid:onmatch(sched.sched_waking).my_synth_event(pid,pid1) ^ [ 8.999880] : error: Couldn't find field Command: ^ [ 8.999880] : error: Couldn't parse field variable Command: ^ [ 8.999880] : error: Couldn't find field Command: ^ [ 8.999880] : error: Couldn't create histogram for field Command: ^ Fixes: f404da6e1d46 ("tracing: Add 'last error' error facility for hist triggers") Signed-off-by: Zheng Yejian --- kernel/trace/trace_events_hist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 1c82478e8dff..b6e5724a9ea3 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -6438,7 +6438,7 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops, if (se) se->ref++; out: - if (ret == 0) + if (ret == 0 && glob[0]) hist_err_clear(); return ret; -- 2.25.1