Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp681662rdb; Thu, 30 Nov 2023 15:45:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTcaTlHIAUxuu0x+v5/hMqSOovGaNtGA4iGEhkfD0GvwSDtEEe3f/HR/qTMdR9jCzvu0k2 X-Received: by 2002:a17:90b:4a03:b0:286:2e6e:b886 with SMTP id kk3-20020a17090b4a0300b002862e6eb886mr5999404pjb.17.1701387946152; Thu, 30 Nov 2023 15:45:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701387946; cv=none; d=google.com; s=arc-20160816; b=PmC6E/MEtru4acNVm2BBReNedCNsOVAtLvLCe0PrEw34z0hbaN17OjUSma3kgWJMdw OGw/x52a+mJhTL6qZaTvK2hQWMDis/x95x5o8RdRSpyQSWAUcH2m7Z1mWrahiQkUr5oD 0fcWH6sE407BLnHYE6D8n4ArVEQOm1YkYJf/huUoMdjmhSQKfizWMWhIuWZVZhFw/4p0 sEoo+kGWFYpT9m/og/3aDUJGPzcIZ+bQNNgqtcjrhaQP3CWZ6oX6GLkRO8xNKvKkHnrg a9Gc4EceRPXFjeqS7USAwJBppqY37+EkDH/z6WkNVIP7cnr0wauxPbzgSnFlapz2iz7I WYjg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KhfAqA+0zx3rIVvOFQAX3/ztaO69KpdJ+hg2RHJWvzk=; fh=Xr9EZaLbYspLudo3lCz3I6iQD6BKril0MIzT5DobTXc=; b=E7VhsW5s3WFnS5QAmDOSs7EpHr/yVhoCZRKEJU8Es+L9Aa8yHNKbvltOowHqbVzXaP X8KmLbYGzRSRNa/Na7GI4WVfvohqiXCWvYzo9RnfTLqOmeyXb20bd3joXBqNX9OXXtTN Y9xjkatJH1oEjAQ76T0mlaodKHCXv4AL681OKof4r5G1VxXGmg0gwGDCU/wZqlB78sdo 5n3bHLoKWQeVfhHSTivKTtZWLt1BxrekJiFXOUfYQFmdIOsPiUo98MypMGcddeORPXfc YdK6tz0D0YQEjxbD89GGGNg0g0uYFPgmqF4xiSXE6rSUCeo/OEQKeOeDjxQ8x7GPIbrP SlFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b=c8ncx3GB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=semihalf.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id gd22-20020a17090b0fd600b002858f6b5e89si4344493pjb.185.2023.11.30.15.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 15:45:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b=c8ncx3GB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=semihalf.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 1A3D7803D55E; Thu, 30 Nov 2023 15:45:23 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377329AbjK3Xo5 (ORCPT + 99 others); Thu, 30 Nov 2023 18:44:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377302AbjK3Xoy (ORCPT ); Thu, 30 Nov 2023 18:44:54 -0500 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5975C2D61 for ; Thu, 30 Nov 2023 15:42:34 -0800 (PST) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2c9c4df1287so20619761fa.2 for ; Thu, 30 Nov 2023 15:42:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; t=1701387733; x=1701992533; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KhfAqA+0zx3rIVvOFQAX3/ztaO69KpdJ+hg2RHJWvzk=; b=c8ncx3GBqw9KndPcCRYJc/Bu0MGSN6PQREwX+L1mVOMBMazdpU9F6O1lVWy1R+1SO9 KFeMRTb+vHmn+3LxvnJU361JzlhbqAZGm3tp1jdDO76eGMil8wHXX9GZ7avulmZTD6Cg rK8vsO+cOgdT/JBPMtSDsXEH8DeNZqiK1+E1wJJLLELTHjlQLq0+d8kCmuAgML0+hBOk zgBbwR9Y1AB6P+OVwzvIgJLhTv5+FNhN/NVRYzORcPVkqEs492hXQO61ee/mpjqGttkV h0b/Ki6yA69VDc4M9HHujPwXJZ+nFvcA5wPZQs41QHlAD1KYDHElViLOCR/ipGwBXuiF mTgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701387733; x=1701992533; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KhfAqA+0zx3rIVvOFQAX3/ztaO69KpdJ+hg2RHJWvzk=; b=uQ9+OrFq4ZzFVvN1Iv+wMBxuGb2Bmn200mFS8nsRYUG4Xqhul9iP/cg44mG5GxGqHd YNF/T8ssjme/7loX5fz+JM3R0b1KmopWBBUwRK2x1EJzXNHpOb5pNa6lfoSh8iB/ubX0 rxDRFw9spntxZUc2mskNa3WFOteaEzwdsD/SOXECsFCI9UgX0XTgBGxNkEk2l5aMzQyB lpHdJwKqwKW/KsnqZB3NL8d+AnUC7swLPqCCHf6hFqBp9p3x46cMJbh5HhFOnEdvMbwD HDWt/5PmWuinc0aCMp91j7iuLs7rz4kctT4fULaOuE5jz5Q6B8XUQ0X29Q5sLEj2Wvbb SQgQ== X-Gm-Message-State: AOJu0YyTktRgqiYCWoueAL9IpGnCouEgHrZTYn3LMqA/EjaLusioxr+3 rJUCPZc1AzrxFXbR7ZLM/uNx X-Received: by 2002:a2e:4949:0:b0:2c9:d874:20dc with SMTP id b9-20020a2e4949000000b002c9d87420dcmr193433ljd.102.1701387733098; Thu, 30 Nov 2023 15:42:13 -0800 (PST) Received: from ukaszb-l.semihalf.net (public-gprs368940.centertel.pl. [37.47.72.109]) by smtp.gmail.com with ESMTPSA id 9-20020a170906100900b009ddaf5ebb6fsm1210175ejm.177.2023.11.30.15.42.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 15:42:12 -0800 (PST) From: =?UTF-8?q?=C5=81ukasz=20Bartosik?= To: Jason Baron , Jim Cromie , Andrew Morton , Kees Cook , Douglas Anderson Cc: Guenter Roeck , Yaniv Tzoreff , Benson Leung , Steven Rostedt , Vincent Whitchurch , Pekka Paalanen , Sean Paul , Daniel Vetter , linux-kernel@vger.kernel.org, upstream@semihalf.com Subject: [PATCH v2 14/15] dyndbg: write debug logs to trace instance Date: Fri, 1 Dec 2023 00:40:47 +0100 Message-ID: <20231130234048.157509-15-lb@semihalf.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231130234048.157509-1-lb@semihalf.com> References: <20231130234048.157509-1-lb@semihalf.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 30 Nov 2023 15:45:23 -0800 (PST) When trace is enabled (T flag is set) and trace destination field is set to a value in range [0..62] (TRACE_DST_MAX(63) is reserved for writing to trace events) then debug logs will be written to a trace instance pointed by inst[trace destination].name, e.g. when trace destination value is 2 and inst[2].name is set to tbt then debug logs will be written to /tracing/instances/tbt instance. Before using trace instance as a destination for writing debug logs it has to be explicitly opened with open command. Signed-off-by: Ɓukasz Bartosik --- lib/dynamic_debug.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index ae05b3728520..afcc536c2e91 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -141,6 +141,11 @@ static inline bool has_tr_default_dst(void) return tr.default_dst != DST_NOT_SET; } +static inline bool is_tr_event_dst(const struct _ddebug *desc) +{ + return desc->ctrl.trace_dst == TRACE_DST_MAX; +} + static int find_tr_instance(const char *name) { int idx; @@ -1251,8 +1256,8 @@ static DEFINE_PER_CPU(struct ddebug_trace_bufs, ddebug_trace_bufs); static DEFINE_PER_CPU(int, ddebug_trace_reserve); __printf(3, 0) -static void ddebug_trace(struct _ddebug *desc, const struct device *dev, - const char *fmt, va_list args) +static void ddebug_trace_event(struct _ddebug *desc, const struct device *dev, + const char *fmt, va_list args) { struct ddebug_trace_buf *buf; int bufidx; @@ -1283,6 +1288,18 @@ static void ddebug_trace(struct _ddebug *desc, const struct device *dev, preempt_enable_notrace(); } +__printf(2, 0) +static void ddebug_trace_instance(struct _ddebug *desc, const char *fmt, + va_list *args) +{ + struct va_format vaf = { .fmt = fmt, .va = args}; + struct trace_array *arr = tr.inst[get_trace_dst(desc)].arr; + + WARN_ON_ONCE(!arr); + + trace_array_printk(arr, 0, "%pV", &vaf); +} + __printf(2, 3) static void ddebug_printk(struct _ddebug *desc, const char *fmt, ...) { @@ -1295,7 +1312,11 @@ static void ddebug_printk(struct _ddebug *desc, const char *fmt, ...) * All callers include the KERN_DEBUG prefix to keep the * vprintk case simple; strip it out for tracing. */ - ddebug_trace(desc, NULL, fmt + strlen(KERN_DEBUG), args); + if (is_tr_event_dst(desc)) + ddebug_trace_event(desc, NULL, + fmt + strlen(KERN_DEBUG), args); + else + ddebug_trace_instance(desc, fmt, &args); va_end(args); } @@ -1317,7 +1338,10 @@ static void ddebug_dev_printk(struct _ddebug *desc, const struct device *dev, va_list args; va_start(args, fmt); - ddebug_trace(desc, dev, fmt, args); + if (is_tr_event_dst(desc)) + ddebug_trace_event(desc, dev, fmt, args); + else + ddebug_trace_instance(desc, fmt, &args); va_end(args); } -- 2.43.0.rc2.451.g8631bc7472-goog