From nobody Sun Nov 24 22:27:40 2024 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 3CF5D19B3D3 for ; Fri, 1 Nov 2024 10:36:08 +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=1730457369; cv=none; b=q7Y/QyfZ1IhszZTusVTzhIM5jx+jtCLmEdyLYY0CvQjXtUUumgEzlAalYqxzoB31IrwFKvb3047s1h4YTZ4wfY4+VvT2dIMiQq7yVGNYjuHfddSzpOoH9ZaoXBq+xZ7M9POA8UfeDZVoyDBPLqS6oGSWByhJirLSMOY99H7P8Mw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457369; c=relaxed/simple; bh=0ECHqyMrwF1RhGCyzmASRVHGaUNHJ0obns2rz4Str50=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Rwjm3DiOVayocGXPflMXdpuWD58y6k6kvHMS4qwfrC0ZLYqep1gc9awWgryv6fImtPpvSsxaszletpohzrE1NscX88qddQq3JTU2WPTFZTMDT7gZsi4Ct1zLibgGbLSXnmtGqFWeTr3pcRHWCiZSvnMrkF2MTUvx5Yr5vaJ1SBY= 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 D117CC4CED1; Fri, 1 Nov 2024 10:36:08 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t6p1f-00000005S4c-0T84; Fri, 01 Nov 2024 06:37:07 -0400 Message-ID: <20241101103706.970906571@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 01 Nov 2024 06:36:48 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Ryan Roberts Subject: [for-next][PATCH 01/11] tracing: Make percpu stack trace buffer invariant to PAGE_SIZE References: <20241101103647.011707614@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ryan Roberts Previously the size of "struct ftrace_stacks" depended upon PAGE_SIZE. For the common 4K page size, on a 64-bit system, sizeof(struct ftrace_stacks) was 32K. But for a 64K page size, sizeof(struct ftrace_stacks) was 512K. But ftrace stack usage requirements should be invariant to page size. So let's redefine FTRACE_KSTACK_ENTRIES so that "struct ftrace_stacks" is always sized at 32K for 64-bit and 16K for 32-bit. As a side effect, it removes the PAGE_SIZE compile-time constant assumption from this code, which is required to reach the goal of boot-time page size selection. Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20241021141832.3668264-1-ryan.roberts@arm.com Signed-off-by: Ryan Roberts Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index bdb776e6ceb9..f1d613d924e9 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -2898,7 +2898,7 @@ trace_function(struct trace_array *tr, unsigned long = ip, unsigned long /* Allow 4 levels of nesting: normal, softirq, irq, NMI */ #define FTRACE_KSTACK_NESTING 4 =20 -#define FTRACE_KSTACK_ENTRIES (PAGE_SIZE / FTRACE_KSTACK_NESTING) +#define FTRACE_KSTACK_ENTRIES (SZ_4K / FTRACE_KSTACK_NESTING) =20 struct ftrace_stack { unsigned long calls[FTRACE_KSTACK_ENTRIES]; --=20 2.45.2 From nobody Sun Nov 24 22:27:40 2024 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 3CF081714D3; Fri, 1 Nov 2024 10:36:09 +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=1730457369; cv=none; b=tk69Bnvdh8rkiG0hJdjHol5/foWLYnJyKTeSra5PT7sgrm/MTHY51x7JU4ujw8SpajtRWL0+xhKaie5JnSJ6sOKXr4Nrwa8SOhvIooZB9HV+6GUtQo/4AOYBoNxFn+uLnsbNpJr8EhmgyjCCGKuL/oSqrc72tuYexz0ovpBgWoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457369; c=relaxed/simple; bh=r0HBzAMNW4cdfSo8/EYXNRnjNpcS4i8uBOVnnKDm0bc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=AbLm0iebXzisyKUb6qqggoa7WVSotcRBJCDdhPaYQoPegUZ+0XSx8N+lELJgMTLeC6qhC0pFLrauONWPTQLIMdXAgWQqjSzzyYwkETVlW8DoeOQaUBH3ojq8zwr2navrRnd/r0Os8BFzdQOG2cKSbvWy+mgcg2PeRSc1Svm5Enk= 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 E58BBC4CED2; Fri, 1 Nov 2024 10:36:08 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t6p1f-00000005S57-18Bj; Fri, 01 Nov 2024 06:37:07 -0400 Message-ID: <20241101103707.130624298@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 01 Nov 2024 06:36:49 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , linux-hardening@vger.kernel.org, Kees Cook , Justin Stitt Subject: [for-next][PATCH 02/11] tracing: Replace multiple deprecated strncpy with memcpy References: <20241101103647.011707614@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Justin Stitt strncpy() is deprecated for use on NUL-terminated destination strings [1] a= nd as such we should prefer more robust and less ambiguous string interfaces. String copy operations involving manual pointer offset and length calculations followed by explicit NUL-byte assignments are best changed to either strscpy or memcpy. strscpy is not a drop-in replacement as @len would need a one subtracted from it to avoid truncating the source string. To not sabotage readability of the current code, use memcpy (retaining the manual NUL assignment) as this unambiguously describes the desired behavior. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncp= y-on-nul-terminated-strings [1] Link: https://github.com/KSPP/linux/issues/90 [2] Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: linux-hardening@vger.kernel.org Link: https://lore.kernel.org/20241014-strncpy-kernel-trace-trace_events_fi= lter-c-v2-1-d821e81e371e@google.com Reviewed-by: Kees Cook Signed-off-by: Justin Stitt Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_filter.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events= _filter.c index 0c611b281a5b..78051de581e7 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -1616,7 +1616,7 @@ static int parse_pred(const char *str, void *data, goto err_free; } =20 - strncpy(num_buf, str + s, len); + memcpy(num_buf, str + s, len); num_buf[len] =3D 0; =20 ret =3D kstrtoul(num_buf, 0, &ip); @@ -1694,7 +1694,7 @@ static int parse_pred(const char *str, void *data, if (!pred->regex) goto err_mem; pred->regex->len =3D len; - strncpy(pred->regex->pattern, str + s, len); + memcpy(pred->regex->pattern, str + s, len); pred->regex->pattern[len] =3D 0; =20 } else if (!strncmp(str + i, "CPUS", 4)) { @@ -1859,7 +1859,7 @@ static int parse_pred(const char *str, void *data, if (!pred->regex) goto err_mem; pred->regex->len =3D len; - strncpy(pred->regex->pattern, str + s, len); + memcpy(pred->regex->pattern, str + s, len); pred->regex->pattern[len] =3D 0; =20 filter_build_regex(pred); @@ -1919,7 +1919,7 @@ static int parse_pred(const char *str, void *data, goto err_free; } =20 - strncpy(num_buf, str + s, len); + memcpy(num_buf, str + s, len); num_buf[len] =3D 0; =20 /* Make sure it is a value */ --=20 2.45.2 From nobody Sun Nov 24 22:27:40 2024 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 39833170A15 for ; Fri, 1 Nov 2024 10:36:09 +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=1730457369; cv=none; b=JHpqO2H9VLmBm17A3AUmPB5K33vmrh9j63ur7gT+Aig4N15i8DwtHUZN/jWok5OmbcRoXjMu7dHreABNWbq07/Ka9BhwNgatisP3sfpPH303vhjSUKDqMeFfeBidYGfcTnquxhDMW8xmLqxj9yz0UcTNLHR4qWqeskyg2SPQIzM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457369; c=relaxed/simple; bh=SMhlUXDywZmsmR5JCajBo7bNNnC0nDLpb7NZhtflYME=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=OgX0SgH1CMXkjaQALWJD+K+gLEw7NVz9ogBtyXVT6yp31FZ2wYa/sSIHBYL9RXGHQkJlprkQgMDHXlF749HWVynLCGf2Ar8LiJoCQ4/FmK263E6LAzN8YpQYeKWU1H5wsKr9XQUsgxUcSz7NWYA58uRHW8RTLlsoO1RsmmQOssQ= 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 1CEB3C4CED7; Fri, 1 Nov 2024 10:36:09 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t6p1f-00000005S5b-1mLU; Fri, 01 Nov 2024 06:37:07 -0400 Message-ID: <20241101103707.290109005@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 01 Nov 2024 06:36:50 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Yuran Pereira , Nir Lichtman , Douglas Anderson Subject: [for-next][PATCH 03/11] kdb: Replace the use of simple_strto with safer kstrto in kdb_main References: <20241101103647.011707614@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yuran Pereira The simple_str* family of functions perform no error checking in scenarios where the input value overflows the intended output variable. This results in these functions successfully returning even when the output does not match the input string. Or as it was mentioned [1], "...simple_strtol(), simple_strtoll(), simple_strtoul(), and simple_strtoull() functions explicitly ignore overflows, which may lead to unexpected results in callers." Hence, the use of those functions is discouraged. This patch replaces all uses of the simple_strto* series of functions with their safer kstrto* alternatives. Side effects of this patch: - Every string to long or long long conversion using kstrto* is now checked for failure. - kstrto* errors are handled with appropriate `KDB_BADINT` wherever applicable. - A good side effect is that we end up saving a few lines of code since unlike in simple_strto* functions, kstrto functions do not need an additional "end pointer" variable, and the return values of the latter can be directly checked in an "if" statement without the need to define additional `ret` or `err` variables. This, of course, results in cleaner, yet still easy to understand code. [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-s= trtol-simple-strtoll-simple-strtoul-simple-strtoull Link: https://lore.kernel.org/20241028191916.GA918454@lichtman.org Signed-off-by: Yuran Pereira [nir: addressed review comments by fixing styling, invalid conversion and a= missing error return] Signed-off-by: Nir Lichtman Reviewed-by: Douglas Anderson Signed-off-by: Steven Rostedt (Google) Acked-by: Steven Rostedt (Google) --- kernel/debug/kdb/kdb_main.c | 69 +++++++++++-------------------------- 1 file changed, 21 insertions(+), 48 deletions(-) diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c index f5f7d7fb5936..f8703ab760d9 100644 --- a/kernel/debug/kdb/kdb_main.c +++ b/kernel/debug/kdb/kdb_main.c @@ -306,8 +306,8 @@ static int kdbgetulenv(const char *match, unsigned long= *value) return KDB_NOTENV; if (strlen(ep) =3D=3D 0) return KDB_NOENVVALUE; - - *value =3D simple_strtoul(ep, NULL, 0); + if (kstrtoul(ep, 0, value)) + return KDB_BADINT; =20 return 0; } @@ -402,42 +402,23 @@ static void kdb_printenv(void) */ int kdbgetularg(const char *arg, unsigned long *value) { - char *endp; - unsigned long val; - - val =3D simple_strtoul(arg, &endp, 0); - - if (endp =3D=3D arg) { - /* - * Also try base 16, for us folks too lazy to type the - * leading 0x... - */ - val =3D simple_strtoul(arg, &endp, 16); - if (endp =3D=3D arg) + /* + * If the first fails, also try base 16, for us + * folks too lazy to type the leading 0x... + */ + if (kstrtoul(arg, 0, value)) { + if (kstrtoul(arg, 16, value)) return KDB_BADINT; } - - *value =3D val; - return 0; } =20 int kdbgetu64arg(const char *arg, u64 *value) { - char *endp; - u64 val; - - val =3D simple_strtoull(arg, &endp, 0); - - if (endp =3D=3D arg) { - - val =3D simple_strtoull(arg, &endp, 16); - if (endp =3D=3D arg) + if (kstrtou64(arg, 0, value)) { + if (kstrtou64(arg, 16, value)) return KDB_BADINT; } - - *value =3D val; - return 0; } =20 @@ -473,10 +454,10 @@ int kdb_set(int argc, const char **argv) */ if (strcmp(argv[1], "KDBDEBUG") =3D=3D 0) { unsigned int debugflags; - char *cp; + int ret; =20 - debugflags =3D simple_strtoul(argv[2], &cp, 0); - if (cp =3D=3D argv[2] || debugflags & ~KDB_DEBUG_FLAG_MASK) { + ret =3D kstrtouint(argv[2], 0, &debugflags); + if (ret || debugflags & ~KDB_DEBUG_FLAG_MASK) { kdb_printf("kdb: illegal debug flags '%s'\n", argv[2]); return 0; @@ -1619,10 +1600,10 @@ static int kdb_md(int argc, const char **argv) if (!argv[0][3]) valid =3D 1; else if (argv[0][3] =3D=3D 'c' && argv[0][4]) { - char *p; - repeat =3D simple_strtoul(argv[0] + 4, &p, 10); + if (kstrtouint(argv[0] + 4, 10, &repeat)) + return KDB_BADINT; mdcount =3D ((repeat * bytesperword) + 15) / 16; - valid =3D !*p; + valid =3D 1; } last_repeat =3D repeat; } else if (strcmp(argv[0], "md") =3D=3D 0) @@ -2083,15 +2064,10 @@ static int kdb_dmesg(int argc, const char **argv) if (argc > 2) return KDB_ARGCOUNT; if (argc) { - char *cp; - lines =3D simple_strtol(argv[1], &cp, 0); - if (*cp) + if (kstrtoint(argv[1], 0, &lines)) lines =3D 0; - if (argc > 1) { - adjust =3D simple_strtoul(argv[2], &cp, 0); - if (*cp || adjust < 0) - adjust =3D 0; - } + if (argc > 1 && (kstrtoint(argv[2], 0, &adjust) || adjust < 0)) + adjust =3D 0; } =20 /* disable LOGGING if set */ @@ -2428,14 +2404,12 @@ static int kdb_help(int argc, const char **argv) static int kdb_kill(int argc, const char **argv) { long sig, pid; - char *endp; struct task_struct *p; =20 if (argc !=3D 2) return KDB_ARGCOUNT; =20 - sig =3D simple_strtol(argv[1], &endp, 0); - if (*endp) + if (kstrtol(argv[1], 0, &sig)) return KDB_BADINT; if ((sig >=3D 0) || !valid_signal(-sig)) { kdb_printf("Invalid signal parameter.<-signal>\n"); @@ -2443,8 +2417,7 @@ static int kdb_kill(int argc, const char **argv) } sig =3D -sig; =20 - pid =3D simple_strtol(argv[2], &endp, 0); - if (*endp) + if (kstrtol(argv[2], 0, &pid)) return KDB_BADINT; if (pid <=3D 0) { kdb_printf("Process ID must be large than 0.\n"); --=20 2.45.2 From nobody Sun Nov 24 22:27:40 2024 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 6A0F819B5B8 for ; Fri, 1 Nov 2024 10:36:09 +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=1730457369; cv=none; b=H2M53z0r5RTgprr+DztWNpLn54RklE4/e+ZVSxf4czU/i3+0ToEN6wkYcz8imlDpQqBw1AQSnTA5zLxNsIcxs86RxEsWypXTuX0JaE4sHGFX6mqurXcft6ogwEKpIwOAWbIE5v9PPL75+l8CaYi17CT1bMSagYtEfwBNq7q9y8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457369; c=relaxed/simple; bh=95zVCe3LTNyFUw2de0ZA5FJbzmALpCG7UjAKLiG8h3w=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=oyOvc6qTZx+8zlsnEUYQmUHXRsPMzYVJTqmRFYPhN0CypL835i65nsXKDquwe8UQBbi63n4pIgsXAJc08IVduoDLzbp95AmdelY3B2IBTEfNN+ADmwFqFs6vcIfnPC4nnNDvONb8Sy+wVIUq8N2c3S7J7Fii/Xr+f/lJp3LkPO0= 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 45DC6C4AF0F; Fri, 1 Nov 2024 10:36:09 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t6p1f-00000005S65-2SOk; Fri, 01 Nov 2024 06:37:07 -0400 Message-ID: <20241101103707.445466201@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 01 Nov 2024 06:36:51 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Yuran Pereira , Douglas Anderson , Nir Lichtman Subject: [for-next][PATCH 04/11] trace: kdb: Replace simple_strtoul with kstrtoul in kdb_ftdump References: <20241101103647.011707614@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yuran Pereira The function simple_strtoul performs no error checking in scenarios where the input value overflows the intended output variable. This results in this function successfully returning, even when the output does not match the input string (aka the function returns successfully even when the result is wrong). Or as it was mentioned [1], "...simple_strtol(), simple_strtoll(), simple_strtoul(), and simple_strtoull() functions explicitly ignore overflows, which may lead to unexpected results in callers." Hence, the use of those functions is discouraged. This patch replaces all uses of the simple_strtoul with the safer alternatives kstrtoint and kstrtol. [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-s= trtol-simple-strtoll-simple-strtoul-simple-strtoull Link: https://lore.kernel.org/20241028192100.GB918454@lichtman.org Signed-off-by: Yuran Pereira Reviewed-by: Douglas Anderson Acked-by: Masami Hiramatsu (Google) [nir: style fixes] Signed-off-by: Nir Lichtman Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_kdb.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/kernel/trace/trace_kdb.c b/kernel/trace/trace_kdb.c index 59857a1ee44c..1e72d20b3c2f 100644 --- a/kernel/trace/trace_kdb.c +++ b/kernel/trace/trace_kdb.c @@ -96,22 +96,19 @@ static int kdb_ftdump(int argc, const char **argv) { int skip_entries =3D 0; long cpu_file; - char *cp; + int err; int cnt; int cpu; =20 if (argc > 2) return KDB_ARGCOUNT; =20 - if (argc) { - skip_entries =3D simple_strtol(argv[1], &cp, 0); - if (*cp) - skip_entries =3D 0; - } + if (argc && kstrtoint(argv[1], 0, &skip_entries)) + return KDB_BADINT; =20 if (argc =3D=3D 2) { - cpu_file =3D simple_strtol(argv[2], &cp, 0); - if (*cp || cpu_file >=3D NR_CPUS || cpu_file < 0 || + err =3D kstrtol(argv[2], 0, &cpu_file); + if (err || cpu_file >=3D NR_CPUS || cpu_file < 0 || !cpu_online(cpu_file)) return KDB_BADINT; } else { --=20 2.45.2 From nobody Sun Nov 24 22:27:40 2024 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 AB37D19CC0A for ; Fri, 1 Nov 2024 10:36:09 +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=1730457369; cv=none; b=mMz6H/O8VG6ns/oNlzmUMh772rvOMRZlu4deOW305lzxmzV9vs0EwpC3qHEeSPP4eU+6zgHj7eN7+yWzrvYFeN35yFUwWEp41DozH9pDu7j6nss1qXV+tyzauEjx3mFKsIVQIZ+cFPU6Zh6SPJImPPaJHk+Gr88e/N4SZwmP2bI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457369; c=relaxed/simple; bh=Ez/a3amP2ErzSlOSsur8sWuIM/pilTzGoEhqFsAiIHY=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=NkEeYMkOxEW0lw1H4RLrC9BgXavHcNgD/1lzUs/iDr1Ty4CB326+bmPsjOkKYHbEJW8al3m1voWOTn5iWmxBIlHsNCgw2WCHT6XixsLz4a3Wtk2zzrTuheU5ms9NCXUXyt4yAu9Cg82pzESuic9C2Vc3W9+teIj7DFcKLneqK5c= 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 84BBFC4CEF7; Fri, 1 Nov 2024 10:36:09 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t6p1f-00000005S6Z-38bq; Fri, 01 Nov 2024 06:37:07 -0400 Message-ID: <20241101103707.606872077@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 01 Nov 2024 06:36:52 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Douglas Anderson , Nir Lichtman Subject: [for-next][PATCH 05/11] kdb: Remove fallback interpretation of arbitrary numbers as hex References: <20241101103647.011707614@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Nir Lichtman Remove logic that enables a fallback of interpreting numbers supplied in KD= B CLI to be interpreted as hex without explicit "0x" prefix as this can be confus= ing for the end users. Link: https://lore.kernel.org/20241028192228.GC918454@lichtman.org Suggested-by: Douglas Anderson Reviewed-by: Douglas Anderson Signed-off-by: Nir Lichtman Signed-off-by: Steven Rostedt (Google) --- kernel/debug/kdb/kdb_main.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c index f8703ab760d9..5f4be507d79f 100644 --- a/kernel/debug/kdb/kdb_main.c +++ b/kernel/debug/kdb/kdb_main.c @@ -402,23 +402,15 @@ static void kdb_printenv(void) */ int kdbgetularg(const char *arg, unsigned long *value) { - /* - * If the first fails, also try base 16, for us - * folks too lazy to type the leading 0x... - */ - if (kstrtoul(arg, 0, value)) { - if (kstrtoul(arg, 16, value)) - return KDB_BADINT; - } + if (kstrtoul(arg, 0, value)) + return KDB_BADINT; return 0; } =20 int kdbgetu64arg(const char *arg, u64 *value) { - if (kstrtou64(arg, 0, value)) { - if (kstrtou64(arg, 16, value)) - return KDB_BADINT; - } + if (kstrtou64(arg, 0, value)) + return KDB_BADINT; return 0; } =20 --=20 2.45.2 From nobody Sun Nov 24 22:27:40 2024 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 B68FD19CC0F for ; Fri, 1 Nov 2024 10:36:09 +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=1730457369; cv=none; b=tx2zi1KrF/L/NDubU6g6TKX5APvNHSaZPwT3hn9R5AGBSVRCnfSQM/BarhjEUSiTCjLlWKMfqPojl877m63hySyGDYoThF/XIIFFwr/L7OQLQwee/kONbqbP9h+hCdJYedlDlXmVsHAdqFMG/YM3V0j3LabXDrRCrGsCTN221/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457369; c=relaxed/simple; bh=R29ZQy0FjvDDGvhe1C1bVyTO8g35Xi9DDb1KTVaw4lw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Pd+8ICkU6FwejRyr5iAzrSq2ApTKYZLCc19v+s2vzIURrZOvGNQy7y0D5W/uqlb27PXIl/SPJ82liLUsvUU3dCcz6XvARuZVQl0nk2dYBIUQ9aHTVbDYsyy9o3iBr/3MGVu9jEvqi3ZTiBHDryxhYtqKoPawIK6qU/89i07cZgY= 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 A0C34C4CED5; Fri, 1 Nov 2024 10:36:09 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t6p1f-00000005S73-3oST; Fri, 01 Nov 2024 06:37:07 -0400 Message-ID: <20241101103707.768085371@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 01 Nov 2024 06:36:53 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Peter Zijlstra , Sebastian Andrzej Siewior Subject: [for-next][PATCH 06/11] tracing: Remove TRACE_FLAG_IRQS_NOSUPPORT References: <20241101103647.011707614@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Sebastian Andrzej Siewior It was possible to enable tracing with no IRQ tracing support. The tracing infrastructure would then record TRACE_FLAG_IRQS_NOSUPPORT as the only tracing flag and show an 'X' in the output. The last user of this feature was PPC32 which managed to implement it during PowerPC merge in 2009. Since then, it was unused and the PPC32 dependency was finally removed in commit 0ea5ee035133a ("tracing: Remove PPC32 wart from config TRACING_SUPPORT"). Since the PowerPC merge the code behind !CONFIG_TRACE_IRQFLAGS_SUPPORT with TRACING enabled can no longer be selected used and the 'X' is not displayed or recorded. Remove the CONFIG_TRACE_IRQFLAGS_SUPPORT from the tracing code. Remove TRACE_FLAG_IRQS_NOSUPPORT. Cc: Peter Zijlstra Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20241022110112.XJI8I9T2@linutronix.de Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Steven Rostedt (Google) --- Documentation/trace/ftrace.rst | 3 --- include/linux/trace_events.h | 13 ------------- kernel/trace/trace_output.c | 1 - 3 files changed, 17 deletions(-) diff --git a/Documentation/trace/ftrace.rst b/Documentation/trace/ftrace.rst index 4073ca48af4a..74d5bd801b1a 100644 --- a/Documentation/trace/ftrace.rst +++ b/Documentation/trace/ftrace.rst @@ -1031,9 +1031,6 @@ explains which is which. CPU#: The CPU which the process was running on. =20 irqs-off: 'd' interrupts are disabled. '.' otherwise. - .. caution:: If the architecture does not support a way to - read the irq flags variable, an 'X' will always - be printed here. =20 need-resched: - 'N' both TIF_NEED_RESCHED and PREEMPT_NEED_RESCHED is set, diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index f8f2e52653df..016b29a56c87 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -184,7 +184,6 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs= _status); =20 enum trace_flag_type { TRACE_FLAG_IRQS_OFF =3D 0x01, - TRACE_FLAG_IRQS_NOSUPPORT =3D 0x02, TRACE_FLAG_NEED_RESCHED =3D 0x04, TRACE_FLAG_HARDIRQ =3D 0x08, TRACE_FLAG_SOFTIRQ =3D 0x10, @@ -193,7 +192,6 @@ enum trace_flag_type { TRACE_FLAG_BH_OFF =3D 0x80, }; =20 -#ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT static inline unsigned int tracing_gen_ctx_flags(unsigned long irqflags) { unsigned int irq_status =3D irqs_disabled_flags(irqflags) ? @@ -207,17 +205,6 @@ static inline unsigned int tracing_gen_ctx(void) local_save_flags(irqflags); return tracing_gen_ctx_flags(irqflags); } -#else - -static inline unsigned int tracing_gen_ctx_flags(unsigned long irqflags) -{ - return tracing_gen_ctx_irq_test(TRACE_FLAG_IRQS_NOSUPPORT); -} -static inline unsigned int tracing_gen_ctx(void) -{ - return tracing_gen_ctx_irq_test(TRACE_FLAG_IRQS_NOSUPPORT); -} -#endif =20 static inline unsigned int tracing_gen_ctx_dec(void) { diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index 868f2f912f28..2ee6613dce6d 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -460,7 +460,6 @@ int trace_print_lat_fmt(struct trace_seq *s, struct tra= ce_entry *entry) (entry->flags & TRACE_FLAG_IRQS_OFF && bh_off) ? 'D' : (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' : bh_off ? 'b' : - (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' : '.'; =20 switch (entry->flags & (TRACE_FLAG_NEED_RESCHED | --=20 2.45.2 From nobody Sun Nov 24 22:27:40 2024 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 D2A3419CC3D; Fri, 1 Nov 2024 10:36:09 +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=1730457369; cv=none; b=Q2dCEUDDdm/lC00ZDm1cs8Lh4QN2HW8eK6NS6PQTY/bN0dg5yPMQZcBjZ3KZqusI22L9nA51U5RhrUSLC+zjp9JS4M3h21nsFX8fKcpD7NQ+x2b+X3immdxLwCzS/nd6898iaSgdalkUKX1QW/OcSbthISE8AfD4g4UMOD6hDLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457369; c=relaxed/simple; bh=drjD33H1A93Y9HA2C7fqgn5h3eLkonWWJtgOmnbJrAg=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=M16EG1bCyU+9EOcA19qWG6cqzmADP9HabnDuyhsSfvZX5HigngYK/+QTe7Y1vezj7eAMra1dbZ2VlVpeWaFsFTlue/bLLmzQK1osLv1GTqI7hKhGmsrDUaV2fxqSg9fIB/Yo5aOYTQwPJ4f4dOfWUmHni24yRebv2Ll3m7wF2nc= 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 B6409C4CED8; Fri, 1 Nov 2024 10:36:09 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t6p1g-00000005S7X-0Hpo; Fri, 01 Nov 2024 06:37:08 -0400 Message-ID: <20241101103707.928299599@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 01 Nov 2024 06:36:54 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Jordan Rife , Michael Jeanson , Thomas Gleixner , Peter Zijlstra , Alexei Starovoitov , Yonghong Song , "Paul E. McKenney" , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Namhyung Kim , Andrii Nakryiko , bpf@vger.kernel.org, Joel Fernandes , linux-trace-kernel@vger.kernel.org Subject: [for-next][PATCH 07/11] tracing: Introduce tracepoint extended structure References: <20241101103647.011707614@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Mathieu Desnoyers Shrink the struct tracepoint size from 80 bytes to 72 bytes on x86-64 by moving the (typically NULL) regfunc/unregfunc pointers to an extended structure. Tested-by: Jordan Rife Cc: Michael Jeanson Cc: Thomas Gleixner Cc: Masami Hiramatsu Cc: Peter Zijlstra Cc: Alexei Starovoitov Cc: Yonghong Song Cc: Paul E. McKenney Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin Cc: Namhyung Kim Cc: Andrii Nakryiko Cc: bpf@vger.kernel.org Cc: Joel Fernandes Cc: Jordan Rife Cc: linux-trace-kernel@vger.kernel.org Link: https://lore.kernel.org/20241031152056.744137-2-mathieu.desnoyers@eff= icios.com Signed-off-by: Mathieu Desnoyers Signed-off-by: Steven Rostedt (Google) --- include/linux/tracepoint-defs.h | 8 ++++++-- include/linux/tracepoint.h | 19 +++++++++++++------ kernel/tracepoint.c | 9 ++++----- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/include/linux/tracepoint-defs.h b/include/linux/tracepoint-def= s.h index 60a6e8314d4c..967c08d9da84 100644 --- a/include/linux/tracepoint-defs.h +++ b/include/linux/tracepoint-defs.h @@ -29,6 +29,11 @@ struct tracepoint_func { int prio; }; =20 +struct tracepoint_ext { + int (*regfunc)(void); + void (*unregfunc)(void); +}; + struct tracepoint { const char *name; /* Tracepoint name */ struct static_key_false key; @@ -36,9 +41,8 @@ struct tracepoint { void *static_call_tramp; void *iterator; void *probestub; - int (*regfunc)(void); - void (*unregfunc)(void); struct tracepoint_func __rcu *funcs; + struct tracepoint_ext *ext; }; =20 #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index 0dc67fad706c..862ab49177a4 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -302,7 +302,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(t= racepoint_ptr_t *p) * structures, so we create an array of pointers that will be used for ite= ration * on the tracepoints. */ -#define DEFINE_TRACE_FN(_name, _reg, _unreg, proto, args) \ +#define __DEFINE_TRACE_EXT(_name, _ext, proto, args) \ static const char __tpstrtab_##_name[] \ __section("__tracepoints_strings") =3D #_name; \ extern struct static_call_key STATIC_CALL_KEY(tp_func_##_name); \ @@ -316,9 +316,9 @@ static inline struct tracepoint *tracepoint_ptr_deref(t= racepoint_ptr_t *p) .static_call_tramp =3D STATIC_CALL_TRAMP_ADDR(tp_func_##_name), \ .iterator =3D &__traceiter_##_name, \ .probestub =3D &__probestub_##_name, \ - .regfunc =3D _reg, \ - .unregfunc =3D _unreg, \ - .funcs =3D NULL }; \ + .funcs =3D NULL, \ + .ext =3D _ext, \ + }; \ __TRACEPOINT_ENTRY(_name); \ int __traceiter_##_name(void *__data, proto) \ { \ @@ -341,8 +341,15 @@ static inline struct tracepoint *tracepoint_ptr_deref(= tracepoint_ptr_t *p) } \ DEFINE_STATIC_CALL(tp_func_##_name, __traceiter_##_name); =20 -#define DEFINE_TRACE(name, proto, args) \ - DEFINE_TRACE_FN(name, NULL, NULL, PARAMS(proto), PARAMS(args)); +#define DEFINE_TRACE_FN(_name, _reg, _unreg, _proto, _args) \ + static struct tracepoint_ext __tracepoint_ext_##_name =3D { \ + .regfunc =3D _reg, \ + .unregfunc =3D _unreg, \ + }; \ + __DEFINE_TRACE_EXT(_name, &__tracepoint_ext_##_name, PARAMS(_proto), PARA= MS(_args)); + +#define DEFINE_TRACE(_name, _proto, _args) \ + __DEFINE_TRACE_EXT(_name, NULL, PARAMS(_proto), PARAMS(_args)); =20 #define EXPORT_TRACEPOINT_SYMBOL_GPL(name) \ EXPORT_SYMBOL_GPL(__tracepoint_##name); \ diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c index 6474e2cf22c9..5658dc92f5b5 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c @@ -278,8 +278,8 @@ static int tracepoint_add_func(struct tracepoint *tp, struct tracepoint_func *old, *tp_funcs; int ret; =20 - if (tp->regfunc && !static_key_enabled(&tp->key)) { - ret =3D tp->regfunc(); + if (tp->ext && tp->ext->regfunc && !static_key_enabled(&tp->key)) { + ret =3D tp->ext->regfunc(); if (ret < 0) return ret; } @@ -362,9 +362,8 @@ static int tracepoint_remove_func(struct tracepoint *tp, switch (nr_func_state(tp_funcs)) { case TP_FUNC_0: /* 1->0 */ /* Removed last function */ - if (tp->unregfunc && static_key_enabled(&tp->key)) - tp->unregfunc(); - + if (tp->ext && tp->ext->unregfunc && static_key_enabled(&tp->key)) + tp->ext->unregfunc(); static_branch_disable(&tp->key); /* Set iterator static call */ tracepoint_update_call(tp, tp_funcs); --=20 2.45.2 From nobody Sun Nov 24 22:27:40 2024 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 655221A725A; Fri, 1 Nov 2024 10:36:10 +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=1730457370; cv=none; b=oMEAmZDWTACRRO4uOWSALnjIHQJvHrDVKZainEW8FONMseTzv6CYcBBVhZHSgYsYSqYTy6/NLJX89B13VkZBjfqjWOrwvhtuCSYE8/HvRcAml5jDRluOA8FeAhxxibR3MmQgQonEM499L4pc548r+32ydOZ6oIaHXGyvQPWBuEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457370; c=relaxed/simple; bh=ujP8lD5I+crem6/NpkOWLrztI+nFB968C4oWwq+i+0o=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=HDQqDf0RGC03L3luiSAln2jeJKDVjQ9SwyqpBF348gCGFdkLwm0PRK1RZK3exFIFvXVdnQI+IGSPLyiyApkrsUsellhJXxOtCA+FqChxi3ZTAH5YrLTwVqBtVhzFaSLovCeFkEpurqXyd/dDDajBeRxmVMFdykzh6Wszpgw1WZQ= 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 E0B55C4CEF9; Fri, 1 Nov 2024 10:36:09 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t6p1g-00000005S81-0yeL; Fri, 01 Nov 2024 06:37:08 -0400 Message-ID: <20241101103708.089444209@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 01 Nov 2024 06:36:55 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Andrii Nakryiko , Jordan Rife , Michael Jeanson , Thomas Gleixner , Peter Zijlstra , Alexei Starovoitov , Yonghong Song , "Paul E. McKenney" , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Namhyung Kim , Andrii Nakryiko , bpf@vger.kernel.org, Joel Fernandes , linux-trace-kernel@vger.kernel.org Subject: [for-next][PATCH 08/11] tracing: Introduce tracepoint_is_faultable() References: <20241101103647.011707614@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Mathieu Desnoyers Introduce a "faultable" flag within the extended structure to know whether a tracepoint needs rcu tasks trace grace period before reclaim. This can be queried using tracepoint_is_faultable(). Acked-by: Andrii Nakryiko Tested-by: Jordan Rife Cc: Michael Jeanson Cc: Thomas Gleixner Cc: Masami Hiramatsu Cc: Peter Zijlstra Cc: Alexei Starovoitov Cc: Yonghong Song Cc: Paul E. McKenney Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin Cc: Namhyung Kim Cc: Andrii Nakryiko Cc: bpf@vger.kernel.org Cc: Joel Fernandes Cc: Jordan Rife Cc: linux-trace-kernel@vger.kernel.org Link: https://lore.kernel.org/20241031152056.744137-3-mathieu.desnoyers@eff= icios.com Signed-off-by: Mathieu Desnoyers Signed-off-by: Steven Rostedt (Google) --- include/linux/tracepoint-defs.h | 2 ++ include/linux/tracepoint.h | 24 ++++++++++++++++++++++++ include/trace/define_trace.h | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/linux/tracepoint-defs.h b/include/linux/tracepoint-def= s.h index 967c08d9da84..aebf0571c736 100644 --- a/include/linux/tracepoint-defs.h +++ b/include/linux/tracepoint-defs.h @@ -32,6 +32,8 @@ struct tracepoint_func { struct tracepoint_ext { int (*regfunc)(void); void (*unregfunc)(void); + /* Flags. */ + unsigned int faultable:1; }; =20 struct tracepoint { diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index 862ab49177a4..906f3091d23d 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -104,6 +104,12 @@ void for_each_tracepoint_in_module(struct module *mod, * tracepoint_synchronize_unregister must be called between the last trace= point * probe unregistration and the end of module exit to make sure there is no * caller executing a probe when it is freed. + * + * An alternative is to use the following for batch reclaim associated + * with a given tracepoint: + * + * - tracepoint_is_faultable() =3D=3D false: call_rcu() + * - tracepoint_is_faultable() =3D=3D true: call_rcu_tasks_trace() */ #ifdef CONFIG_TRACEPOINTS static inline void tracepoint_synchronize_unregister(void) @@ -111,9 +117,17 @@ static inline void tracepoint_synchronize_unregister(v= oid) synchronize_rcu_tasks_trace(); synchronize_rcu(); } +static inline bool tracepoint_is_faultable(struct tracepoint *tp) +{ + return tp->ext && tp->ext->faultable; +} #else static inline void tracepoint_synchronize_unregister(void) { } +static inline bool tracepoint_is_faultable(struct tracepoint *tp) +{ + return false; +} #endif =20 #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS @@ -345,6 +359,15 @@ static inline struct tracepoint *tracepoint_ptr_deref(= tracepoint_ptr_t *p) static struct tracepoint_ext __tracepoint_ext_##_name =3D { \ .regfunc =3D _reg, \ .unregfunc =3D _unreg, \ + .faultable =3D false, \ + }; \ + __DEFINE_TRACE_EXT(_name, &__tracepoint_ext_##_name, PARAMS(_proto), PARA= MS(_args)); + +#define DEFINE_TRACE_SYSCALL(_name, _reg, _unreg, _proto, _args) \ + static struct tracepoint_ext __tracepoint_ext_##_name =3D { \ + .regfunc =3D _reg, \ + .unregfunc =3D _unreg, \ + .faultable =3D true, \ }; \ __DEFINE_TRACE_EXT(_name, &__tracepoint_ext_##_name, PARAMS(_proto), PARA= MS(_args)); =20 @@ -389,6 +412,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(t= racepoint_ptr_t *p) #define __DECLARE_TRACE_SYSCALL __DECLARE_TRACE =20 #define DEFINE_TRACE_FN(name, reg, unreg, proto, args) +#define DEFINE_TRACE_SYSCALL(name, reg, unreg, proto, args) #define DEFINE_TRACE(name, proto, args) #define EXPORT_TRACEPOINT_SYMBOL_GPL(name) #define EXPORT_TRACEPOINT_SYMBOL(name) diff --git a/include/trace/define_trace.h b/include/trace/define_trace.h index ff5fa17a6259..63fea2218afa 100644 --- a/include/trace/define_trace.h +++ b/include/trace/define_trace.h @@ -48,7 +48,7 @@ =20 #undef TRACE_EVENT_SYSCALL #define TRACE_EVENT_SYSCALL(name, proto, args, struct, assign, print, reg,= unreg) \ - DEFINE_TRACE_FN(name, reg, unreg, PARAMS(proto), PARAMS(args)) + DEFINE_TRACE_SYSCALL(name, reg, unreg, PARAMS(proto), PARAMS(args)) =20 #undef TRACE_EVENT_NOP #define TRACE_EVENT_NOP(name, proto, args, struct, assign, print) --=20 2.45.2 From nobody Sun Nov 24 22:27:40 2024 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 7F2741A726B; Fri, 1 Nov 2024 10:36:10 +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=1730457370; cv=none; b=pfpQVJm7XBc+428OxjEFyfEcInuVkZ1IfmxYI3/KqtZzh14qCWGS4c92/lVRsY445IK6nyqTF8+UX+7PQ6lFfNhrXGboP/9ReXJ2KkwbY+kgoJ1aSm0eLVZiyQ2ZyzYi6823w4aenV1I6LGCZrofickQVnnGmJAIltVM2sEFLBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457370; c=relaxed/simple; bh=xxPVhVtwZlCs28URhdLLLEJa8UByNgRj/zGcg84wWvA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=PR6A1c+OPKpwq1yQ1jBLW4FD6NPMpz1wdKt1ufI74IIXmr1yjDwHM0Z+/vGX/U2P/wFeYgO1T1Cc//tGwmfJytiRQgjBKWkHJDkVrJNyMhfU4SS1y6pfXG13g2xlrIFI8rFcG8KI4nABn71N4rBxXQ12Tx3TdABAjrtu0Ys6WFA= 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 1349BC4CEDA; Fri, 1 Nov 2024 10:36:10 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t6p1g-00000005S8Y-1fDO; Fri, 01 Nov 2024 06:37:08 -0400 Message-ID: <20241101103708.252744660@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 01 Nov 2024 06:36:56 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , syzbot+b390c8062d8387b6272a@syzkaller.appspotmail.com, Jordan Rife , Michael Jeanson , Thomas Gleixner , Peter Zijlstra , Alexei Starovoitov , Yonghong Song , "Paul E. McKenney" , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Namhyung Kim , Andrii Nakryiko , bpf@vger.kernel.org, Joel Fernandes , linux-trace-kernel@vger.kernel.org Subject: [for-next][PATCH 09/11] tracing: Fix syscall tracepoint use-after-free References: <20241101103647.011707614@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Mathieu Desnoyers The grace period used internally within tracepoint.c:release_probes() uses call_rcu() to batch waiting for quiescence of old probe arrays, rather than using the tracepoint_synchronize_unregister() which blocks while waiting for quiescence. With the introduction of faultable syscall tracepoints, this causes use-after-free issues reproduced with syzkaller. Fix this by using the appropriate call_rcu() or call_rcu_tasks_trace() before invoking the rcu_free_old_probes callback. This can be chosen using the tracepoint_is_faultable() API. A similar issue exists in bpf use of call_rcu(). Fixing this is left to a separate change. Reported-by: syzbot+b390c8062d8387b6272a@syzkaller.appspotmail.com Fixes: a363d27cdbc2 ("tracing: Allow system call tracepoints to handle page= faults") Tested-by: Jordan Rife Cc: Michael Jeanson Cc: Thomas Gleixner Cc: Masami Hiramatsu Cc: Peter Zijlstra Cc: Alexei Starovoitov Cc: Yonghong Song Cc: Paul E. McKenney Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin Cc: Namhyung Kim Cc: Andrii Nakryiko Cc: bpf@vger.kernel.org Cc: Joel Fernandes Cc: Jordan Rife Cc: linux-trace-kernel@vger.kernel.org Link: https://lore.kernel.org/20241031152056.744137-4-mathieu.desnoyers@eff= icios.com Signed-off-by: Mathieu Desnoyers Signed-off-by: Steven Rostedt (Google) --- kernel/tracepoint.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c index 5658dc92f5b5..1848ce7e2976 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c @@ -106,13 +106,16 @@ static void rcu_free_old_probes(struct rcu_head *head) kfree(container_of(head, struct tp_probes, rcu)); } =20 -static inline void release_probes(struct tracepoint_func *old) +static inline void release_probes(struct tracepoint *tp, struct tracepoint= _func *old) { if (old) { struct tp_probes *tp_probes =3D container_of(old, struct tp_probes, probes[0]); =20 - call_rcu(&tp_probes->rcu, rcu_free_old_probes); + if (tracepoint_is_faultable(tp)) + call_rcu_tasks_trace(&tp_probes->rcu, rcu_free_old_probes); + else + call_rcu(&tp_probes->rcu, rcu_free_old_probes); } } =20 @@ -334,7 +337,7 @@ static int tracepoint_add_func(struct tracepoint *tp, break; } =20 - release_probes(old); + release_probes(tp, old); return 0; } =20 @@ -405,7 +408,7 @@ static int tracepoint_remove_func(struct tracepoint *tp, WARN_ON_ONCE(1); break; } - release_probes(old); + release_probes(tp, old); return 0; } =20 --=20 2.45.2 From nobody Sun Nov 24 22:27:40 2024 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 BFD911AA782; Fri, 1 Nov 2024 10:36:10 +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=1730457370; cv=none; b=N4FFp5xIfpXMWn5GbmNN4IkVMo4Ok4WCXV5BLRqNuqY6QrFaJn4A/r5sqKFomrSStQMtbC6bRzpcJDNxfqPgsaJuYcbBU/fjDLC7qWxSEqOtLJwlgx2TbURxQK8UIYv3scFb3ryXiBZOpQ3doYuDfV/TtfGuGp8RN4mpaRsSdio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457370; c=relaxed/simple; bh=E5aIvIh/79Y8klDUzv69R95Ek4HDw81gwTgCQmUzMWU=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=rhL+055zV6Vrbq2OHUx7KZpC9pfuaf6Acg5YvqC/cAr9bpKN70kLE+vYV8NmIeRJ/elwkZ2nwehAaDkMnHKNATFEH8lu9F95avE1GD4+vt/VvBPDEt0AjzSnalBIySBup2IvY2hSiSIOnH4ab9pl9lVaAOIL1T/Q5WSvJ6/7ndA= 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 4689CC4CED2; Fri, 1 Nov 2024 10:36:10 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t6p1g-00000005S92-2L6K; Fri, 01 Nov 2024 06:37:08 -0400 Message-ID: <20241101103708.417405830@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 01 Nov 2024 06:36:57 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Thomas Gleixner , Jordan Rife , Michael Jeanson , Peter Zijlstra , Alexei Starovoitov , Yonghong Song , "Paul E. McKenney" , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Namhyung Kim , Andrii Nakryiko , bpf@vger.kernel.org, Joel Fernandes , linux-trace-kernel@vger.kernel.org Subject: [for-next][PATCH 10/11] tracing: Add might_fault() check in __DECLARE_TRACE_SYSCALL References: <20241101103647.011707614@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Mathieu Desnoyers Catch incorrect use of syscall tracepoints even if no probes are registered by adding a might_fault() check in trace_##name() emitted by __DECLARE_TRACE_SYSCALL. Suggested-by: Thomas Gleixner Tested-by: Jordan Rife Cc: Thomas Gleixner Cc: Michael Jeanson Cc: Masami Hiramatsu Cc: Peter Zijlstra Cc: Alexei Starovoitov Cc: Yonghong Song Cc: Paul E. McKenney Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin Cc: Namhyung Kim Cc: Andrii Nakryiko Cc: bpf@vger.kernel.org Cc: Joel Fernandes Cc: Jordan Rife Cc: linux-trace-kernel@vger.kernel.org Link: https://lore.kernel.org/20241031152056.744137-5-mathieu.desnoyers@eff= icios.com Signed-off-by: Mathieu Desnoyers Signed-off-by: Steven Rostedt (Google) --- include/linux/tracepoint.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index 906f3091d23d..425123e921ac 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -301,6 +301,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(t= racepoint_ptr_t *p) __DECLARE_TRACE_COMMON(name, PARAMS(proto), PARAMS(args), cond, PARAMS(da= ta_proto)) \ static inline void trace_##name(proto) \ { \ + might_fault(); \ if (static_branch_unlikely(&__tracepoint_##name.key)) \ __DO_TRACE(name, \ TP_ARGS(args), \ --=20 2.45.2 From nobody Sun Nov 24 22:27:40 2024 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 BFD221AA781 for ; Fri, 1 Nov 2024 10:36:10 +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=1730457370; cv=none; b=h1NhzxCjZrzoy9QGF+w5r6qhkMy+cFeOwQfthQahUozu/P1fuPun8b12JJGFUEYVeseSOjpKk4xxTvwA17wRcaQL3IGfuYDNL44JXyMr7rdMj0Pi7Lsr0UR+CVfVheJUwP4NdWrPehTQsQHqxdZ+hR2sstqoAR0mABYyP8SR5BE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457370; c=relaxed/simple; bh=vAHb8kUiQkoZ4OsNQ/q+0l4qiZnMCMPsG95aghsEG60=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=FDv8AJRc/ZpAbU3J95LDiksUEo5TXoOGQx1tknVzjCqXJ00A2/geMQcoRy/CA/9eOrHSnuVrhkfl6G2N1wXqW3f0Wj8jGNVK3l0U5largrcN4iDNiKzXsvCviNAKaZlrycGG3e/KBX6faYb+vDrTRsekQt39kPghtBUePgQZJIQ= 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 6F53BC4CED1; Fri, 1 Nov 2024 10:36:10 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t6p1g-00000005S9X-3063; Fri, 01 Nov 2024 06:37:08 -0400 Message-ID: <20241101103708.577077710@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 01 Nov 2024 06:36:58 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Jinjie Ruan Subject: [for-next][PATCH 11/11] tracing: Replace strncpy() with strscpy() when copying comm References: <20241101103647.011707614@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jinjie Ruan Replace the depreciated[1] strncpy() calls with strscpy() when copying comm. Link: https://github.com/KSPP/linux/issues/90 [1] Cc: Cc: Link: https://lore.kernel.org/20241031120139.1343025-1-ruanjinjie@huawei.com Signed-off-by: Jinjie Ruan Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 2 +- kernel/trace/trace_events_hist.c | 4 ++-- kernel/trace/trace_sched_switch.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index f1d613d924e9..a587fd7d7447 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -1921,7 +1921,7 @@ __update_max_tr(struct trace_array *tr, struct task_s= truct *tsk, int cpu) max_data->critical_start =3D data->critical_start; max_data->critical_end =3D data->critical_end; =20 - strncpy(max_data->comm, tsk->comm, TASK_COMM_LEN); + strscpy(max_data->comm, tsk->comm); max_data->pid =3D tsk->pid; /* * If tsk =3D=3D current, then use current_uid(), as that does not use diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_h= ist.c index cc2924ad32a3..c288b92fc4df 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -1599,7 +1599,7 @@ static inline void save_comm(char *comm, struct task_= struct *task) return; } =20 - strncpy(comm, task->comm, TASK_COMM_LEN); + strscpy(comm, task->comm, TASK_COMM_LEN); } =20 static void hist_elt_data_free(struct hist_elt_data *elt_data) @@ -3405,7 +3405,7 @@ static bool cond_snapshot_update(struct trace_array *= tr, void *cond_data) elt_data =3D context->elt->private_data; track_elt_data =3D track_data->elt.private_data; if (elt_data->comm) - strncpy(track_elt_data->comm, elt_data->comm, TASK_COMM_LEN); + strscpy(track_elt_data->comm, elt_data->comm, TASK_COMM_LEN); =20 track_data->updated =3D true; =20 diff --git a/kernel/trace/trace_sched_switch.c b/kernel/trace/trace_sched_s= witch.c index 8a407adb0e1c..573b5d8e8a28 100644 --- a/kernel/trace/trace_sched_switch.c +++ b/kernel/trace/trace_sched_switch.c @@ -187,7 +187,7 @@ static inline char *get_saved_cmdlines(int idx) =20 static inline void set_cmdline(int idx, const char *cmdline) { - strncpy(get_saved_cmdlines(idx), cmdline, TASK_COMM_LEN); + strscpy(get_saved_cmdlines(idx), cmdline, TASK_COMM_LEN); } =20 static void free_saved_cmdlines_buffer(struct saved_cmdlines_buffer *s) --=20 2.45.2