Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1162373rdb; Fri, 22 Dec 2023 17:54:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IHUI5QIl+EzXPj5MpclpKKGPzTlZ9cpXb71N95WDGndX+2HBurj872Ek/UWQHu4CzctObRi X-Received: by 2002:a17:906:5a8e:b0:a22:faec:7d2e with SMTP id l14-20020a1709065a8e00b00a22faec7d2emr1134371ejq.113.1703296490263; Fri, 22 Dec 2023 17:54:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703296490; cv=none; d=google.com; s=arc-20160816; b=cracEvYb75QMgT4CwT4wxHMBckmlZ17t2c2ADwRgp/m/bG6btpA+CxFxuzRTYCbt7S 6c9HqLoafj7aqQV74EjDnioVPFsZpcQlOD4OC/tU3D4rgKgGVcX2EHv4faffR0mlE1oq J/HPNWFZIuhnZrnvYmQdEWuPRBLrl5H3pJklOkASJerpAhL2f7Dz0Yl7IhYaLrOqm8D1 1TYA90tw674eUe4ugUMnhyrzYNo0lI1mDvD2w9yJ8xgLWMDsfRf7hvG+OcYyREv1UtMv Czly6GWFBylaqpUN87MODeQodPrwFlLftHMd0uzdvhG6fpmtjFMLArONzVNBOF71gA2O vbaA== ARC-Message-Signature: i=1; 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 :date:subject:cc:to:from:dkim-signature; bh=Un40+94h5VRdMg5VfaQgh05to2gMxKh526dXQbalmzg=; fh=pC62+Xzu9rWxP3EwkFQHy3M37dHcdVo9RRC56IjE3s4=; b=Sa/QhenHAWTP4vBL4GIU5bEEiTw865cvJwNkMzxgn174z0iCSazxDd7/9TGv/4FGoV c3w0rDAFYs6mArLXcIo7UMgEWEnHH4ChAoTASauWa6J0koyhTPuBVjGTKUB2zoo5877+ 7JuwGOAjnNQpbv6DkBAb0zmf52CwS6noK/e3AehrtfCfjH+1l/B1rQUp/zfYrYTnJwXH XL88VJ5ZbQTxiKE6Tb5DzjCPBktOe+ds8MdKq62eXXiqaCtHZwSrAwllBCbEDqFnKfKo MpYHcMmKa66vYUSfgOCOayhkG7TnyhKYfGFpuigbup+NLxwBL3iKnBtZfAlN5EVvO1jN fV1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b=E7pFhVrk; spf=pass (google.com: domain of linux-kernel+bounces-10171-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10171-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=semihalf.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cw20-20020a170906c79400b00a1d551f6324si2365642ejb.355.2023.12.22.17.54.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 17:54:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10171-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b=E7pFhVrk; spf=pass (google.com: domain of linux-kernel+bounces-10171-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10171-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=semihalf.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 0AAC91F2368C for ; Sat, 23 Dec 2023 01:54:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2063FDDDC; Sat, 23 Dec 2023 01:52:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=semihalf.com header.i=@semihalf.com header.b="E7pFhVrk" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE742D314 for ; Sat, 23 Dec 2023 01:52:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=semihalf.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=semihalf.com Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-55322dbabf6so2522428a12.0 for ; Fri, 22 Dec 2023 17:52:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; t=1703296329; x=1703901129; 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=Un40+94h5VRdMg5VfaQgh05to2gMxKh526dXQbalmzg=; b=E7pFhVrkyu9eIMpbSSlk2mTtmqTh3/3/SSb9v9+MVWNxZ6YTROuwHn4DmeEiB1G5dz m8ly8rkIdgSYwZBNcJoSWI3JzL5S4qXWiXi4rtMcuRoNVsQbTG3+vjY1fLvwLQYcllG+ drXm9Tev2wU5D/nwQ4Bh7sD3j7vyXVD5DyX9TANggARtJVl0kKoMAYJwuzKD0VyVbp1Y 6K5/SUT1b7UKfPm4FbY5zJkd7oWMtNqbQ+UbC2DunLCV3Y64igdUtu/hXeDtmmXQPZRt cSxEjrRpX7J8ry2G7SsNHOnA/wl4tS/rzd05LAN3nF9jcDp2Q/4igvuP5B4KQdSipvBH rmgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703296329; x=1703901129; 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=Un40+94h5VRdMg5VfaQgh05to2gMxKh526dXQbalmzg=; b=gtmOKvDEsv157apnjvPsjXOtS4VmAghuw1WTJqxjs3bxWmujJ8eG16uXi5yjFESaSL w76CxtMjkHeJT5bzykNnzzL/U6vmcwXPwUH/IOUxybGlm/LMb1WYh72EEoElDiFIqXH9 sY2IVk69uK9Pqv5TBE5FQC68dvv4RQU94ypfu1vJwrzw3PcTBm27mw4Qofv+r24uSDiJ b7hpANL8mElGmptZEM2C+4XuTAg/Tu6E4h9Xm8Yb85Qv7zHfLmz3rKerw8msFRuk9nSq M+W48SJGZJdezm8SmpLBVnryHSczf4dB+oX81Ihq4Hhn8rdbqwCALKXSfoZ+g7As5B12 vWSw== X-Gm-Message-State: AOJu0Yxo1juWsWfiX1yn4xJg0urXqganCgOmEpcTXurrKED6GSW2N56I fhm5ugw7Tzw8M5NgD1em1ySc+UeDj3Bh X-Received: by 2002:a50:9992:0:b0:553:6348:7360 with SMTP id m18-20020a509992000000b0055363487360mr1173719edb.4.1703296329211; Fri, 22 Dec 2023 17:52:09 -0800 (PST) Received: from ukaszb-l.semihalf.net (alfa56.extreme-net.one.pl. [213.77.89.56]) by smtp.gmail.com with ESMTPSA id h2-20020a0564020e8200b005532a337d51sm3288494eda.44.2023.12.22.17.52.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 17:52:08 -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 , Simon Ser , John Ogness , Petr Mladek , Sergey Senozhatsky , linux-kernel@vger.kernel.org, upstream@semihalf.com Subject: [PATCH v3 11/22] dyndbg: don't close trace instance when in use Date: Sat, 23 Dec 2023 02:51:20 +0100 Message-ID: <20231223015131.2836090-12-lb@semihalf.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20231223015131.2836090-1-lb@semihalf.com> References: <20231223015131.2836090-1-lb@semihalf.com> 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=UTF-8 Content-Transfer-Encoding: 8bit Don't allow trace instance to be closed when it is still being used by at least one callsite. Signed-off-by: Ɓukasz Bartosik --- lib/dynamic_debug.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index dd4510ad124e..59682729ed3a 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -81,6 +81,7 @@ struct flag_settings { struct dd_private_tracebuf { const char *name; struct trace_array *arr; + int use_cnt; }; /* @@ -279,6 +280,7 @@ static int handle_trace_open_cmd(const char *arg) goto end; } + buf->use_cnt = 0; set_bit(idx, trc_tbl.bmap); v3pr_info("opened trace instance idx=%d, name=%s\n", idx, arg); end: @@ -301,6 +303,14 @@ static int handle_trace_close_cmd(const char *arg) buf = &trc_tbl.buf[idx]; + WARN_ON(buf->use_cnt < 0); + if (buf->use_cnt) { + pr_err("trace instance is being used name=%s, use_cnt=%d\n", + buf->name, buf->use_cnt); + ret = -EBUSY; + goto end; + } + trace_array_put(buf->arr); /* * don't destroy trace instance but let user do it manually @@ -321,6 +331,24 @@ static int handle_trace_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 (odst && (oflags & _DPRINTK_FLAGS_TRACE)) + trc_tbl.buf[odst].use_cnt--; + + if (ndst && (nflags & _DPRINTK_FLAGS_TRACE)) + trc_tbl.buf[ndst].use_cnt++; +} + static int ddebug_parse_cmd(char *words[], int nwords) { if (nwords != 1) @@ -447,6 +475,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); } } @@ -1628,6 +1657,15 @@ int ddebug_dyndbg_module_param_cb(char *param, char *val, const char *module) static void ddebug_table_free(struct ddebug_table *dt) { + + int dst, i; + + for (i = 0; i < dt->num_ddebugs; i++) { + dst = get_trace_dst(&dt->ddebugs[i]); + if (dst && (get_flags(&dt->ddebugs[i]) & _DPRINTK_FLAGS_TRACE)) + trc_tbl.buf[dst].use_cnt--; + } + list_del_init(&dt->link); kfree(dt); } -- 2.43.0.472.g3155946c3a-goog