Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp680535rdb; Thu, 30 Nov 2023 15:42:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFuWGAKkuSIIsHFgbV3zZGWreH1Wf/k3dfezXMBduFQanD4Oc/D/UTfX39FOveQvt8FzJ4 X-Received: by 2002:a05:6a20:729e:b0:18b:826e:e611 with SMTP id o30-20020a056a20729e00b0018b826ee611mr26240915pzk.40.1701387769721; Thu, 30 Nov 2023 15:42:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701387769; cv=none; d=google.com; s=arc-20160816; b=FTD5jhX/juIjCfjWkfBmlk0g9uVIgHAR68cG8smmynXARofik531zGsIAP5nNygGhO D7OIhq3Cdbc3r1yGX02ip//lGDCghEdEAa2ZvdtaA40GeCUMqtMS97m504WFiA8BcHH3 XXiEwe/GH4elOo3922S59wprZasc+qGFgqAR4TMpDO/eb/KEcvtGhXORUwO61wqL7NHA PR1ZBJfs2qyP6ExxKVGx1ayp9tbNoleA9HL9aUaNDoRRuhD9SFdyvGcyHsLbu7lAIgLZ fHAEmtBUZYUFTo6TRMENljAM4EAovHLKn9UiGqaieiiEuD0cFIPaLjm5XqgSoPSYbWuc MWCw== 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=CzVtATo7qejOLEB4sJXRSm13xDxtkLHgydWT8VzDoHc=; fh=Xr9EZaLbYspLudo3lCz3I6iQD6BKril0MIzT5DobTXc=; b=GsV+wd0qjuU+bKdN6y/FkeSk67Mqzh+NuXzKIqxJxJNud5soZ1Zi3gubF2CAhrpP/h 2/ldeR0ePdWXn1U0enKFGt9a011nJhCtdpzOo1ogxf/rNtJCZ0DSc92LuakvUAB/Awbz fLjAcaVqaBbiCIsZ4W0AZSphY2aFus+7ZDSQwBjRPQMHLhZ+84m7EhQ5Z4pGpjnvgwxM 273hEP4Qj2lEBJiWwz8OBj1K1kY3aWWP8ZAJyUoLNSVsOPhR8wit9C0WIMsnKrmbfiAJ Pb4XGBaZ0r+IA0f4yB07JgNsjghbmnOOzYOOp+y0K+mZivKu6sp7z0DXC/pZ+Bq/5mfg JY5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b=ueInL2FU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id u3-20020a656703000000b005b74ce91e9fsi2256640pgf.672.2023.11.30.15.42.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 15:42:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b=ueInL2FU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id AF4B680DBAF9; Thu, 30 Nov 2023 15:42:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377289AbjK3XmY (ORCPT + 99 others); Thu, 30 Nov 2023 18:42:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377303AbjK3XmV (ORCPT ); Thu, 30 Nov 2023 18:42:21 -0500 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AFD81BE7 for ; Thu, 30 Nov 2023 15:41:58 -0800 (PST) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a00d5b0ec44so215747866b.0 for ; Thu, 30 Nov 2023 15:41:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; t=1701387716; x=1701992516; 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=CzVtATo7qejOLEB4sJXRSm13xDxtkLHgydWT8VzDoHc=; b=ueInL2FUUEfz1oq4Yg9M5U7h/fVM/pA3nFnhAfjuZv5HfmgWkP75NJa1SlwTR0nbMZ lDBi3OoEJgzFPIhnZsQBr82hRf0IMKok9SJwL0qzRJYpPuIeOyAWZlhs4UH8dMcsoEsw 6Ngs5fbl3XxPxiCj9jBsZGxyAKpNz9rQZDTDkkKsab/HvengCWVD6HNOLPLShVsYEMXX UG4tw8LjfxhXdl0CP6k1O5yEyslUjqx2Ds8HPquDJ8hUkysxoIU7qA7nSxH7sXyjr6Yo p3tX7QPL6XK66L1XCSuq4mKDDNC09F6xUQurjzH648SKKZUOp7R9hjLCDG/51bcAcPMo ztFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701387716; x=1701992516; 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=CzVtATo7qejOLEB4sJXRSm13xDxtkLHgydWT8VzDoHc=; b=aFnkNvdjb0/Ke3mVXYAcmyoNNsR0yw/J/oQUkrvz8iYZbZq8sntK9/Hzt2cmwC3Hlc 41HCvHorxvfae2iIgK48Qae7Phr7J4Xe5beX4h4Ng2lmG+fjvsIdhdK3TdIZd40w0I7s uG4bxcWkrz6YTJFR+2mt52vhwVaddm/GM99dTJdOuE1zNfYEnhWgwMLY7FkWR2pSQpr5 hlkVSvkX8ynsdwcEWpNn1Jmvt5cT6USGMRFMIFKVIEe6EnABoCT8bsIkd0NL/IqJZlnr NWvn5FbNwyl1Cv4SM8p2ofgxfbo8BsfvqGOm/I2GOXzkRLxJzWg8iKVPeeAdJYUaL04X KIdw== X-Gm-Message-State: AOJu0Yz0YMIFpX2ERJAVp0jUiwUFk4rsxhKFbu8gY5HRlJpF4GnY2n7b XTTk4DuSQps+Ow6JguKqs36Q X-Received: by 2002:a17:907:511:b0:a19:a19b:4268 with SMTP id wj17-20020a170907051100b00a19a19b4268mr121632ejb.211.1701387716688; Thu, 30 Nov 2023 15:41:56 -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.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 15:41:56 -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 11/15] dyndbg: don't close trace instance when in use Date: Fri, 1 Dec 2023 00:40:44 +0100 Message-ID: <20231130234048.157509-12-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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 30 Nov 2023 15:42:46 -0800 (PST) Don't allow trace instance to be closed when it is still being used by at least one callsite. Signed-off-by: Ɓukasz Bartosik --- include/linux/dynamic_debug.h | 3 ++- lib/dynamic_debug.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h index 56f152e75604..5555857d9ba5 100644 --- a/include/linux/dynamic_debug.h +++ b/include/linux/dynamic_debug.h @@ -186,7 +186,8 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor, .filename = __FILE__, \ .format = (fmt), \ .lineno = __LINE__, \ - .ctrl = { .flags = _DPRINTK_FLAGS_DEFAULT }, \ + .ctrl = { .flags = _DPRINTK_FLAGS_DEFAULT, \ + .trace_dst = TRACE_DST_MAX }, \ .class_id = cls, \ _DPRINTK_KEY_INIT \ }; \ diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 43e94023a4eb..73b6818e5fab 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -81,6 +81,7 @@ struct flag_settings { struct ddebug_trace_inst { const char *name; struct trace_array *arr; + int use_cnt; }; /* @@ -274,6 +275,7 @@ static int handle_tr_opend_cmd(const char *arg) goto end; } + inst->use_cnt = 0; set_bit(idx, tr.bmap); v3pr_info("opened trace instance idx=%d, name=%s\n", idx, arg); end: @@ -296,6 +298,14 @@ static int handle_tr_close_cmd(const char *arg) inst = &tr.inst[idx]; + WARN_ON(inst->use_cnt < 0); + if (inst->use_cnt) { + pr_err("trace instance is being used name=%s, use_cnt=%d\n", + inst->name, inst->use_cnt); + ret = -EBUSY; + goto end; + } + trace_array_put(inst->arr); /* * don't destroy trace instance but let user do it manually @@ -316,6 +326,26 @@ static int handle_tr_close_cmd(const char *arg) return ret; } +static +void update_tr_dst(const struct _ddebug *desc, const struct dd_ctrl *nctrl) +{ + int oflags = get_flags(desc), odst = get_trace_dst(desc); + int nflags = nctrl->flags, ndst = nctrl->trace_dst; + + if (oflags & _DPRINTK_FLAGS_TRACE && + nflags & _DPRINTK_FLAGS_TRACE && + odst == ndst) + return; + + if (oflags & _DPRINTK_FLAGS_TRACE && + odst != TRACE_DST_MAX) + tr.inst[odst].use_cnt--; + + if (nflags & _DPRINTK_FLAGS_TRACE && + ndst != TRACE_DST_MAX) + tr.inst[ndst].use_cnt++; +} + static int ddebug_parse_cmd(char *words[], int nwords) { int ret; @@ -447,6 +477,7 @@ static int ddebug_change(const struct ddebug_query *query, dt->mod_name, dp->function, ddebug_describe_flags(get_flags(dp), &fbuf), ddebug_describe_flags(nctrl.flags, &nbuf)); + update_tr_dst(dp, &nctrl); set_ctrl(dp, &nctrl); } } -- 2.43.0.rc2.451.g8631bc7472-goog