Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp540589lqm; Wed, 1 May 2024 08:17:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU2rRsgFHc61pRiq90NnZ3/MOdYycMfDdOzQqC0MjH2vuJMZjM6th1DcjfOexbv9XA/sFxrQseBjuVv190HncmHUZNHSGM+tI7I8HEhfQ== X-Google-Smtp-Source: AGHT+IEqRxTLFm+bvOVzetVLa4l/7MsMtMIfkQVcVJnVaBv6G2KIJuNzlbpol1UZNZymO2t9sA2b X-Received: by 2002:a05:620a:462b:b0:790:8726:bc9 with SMTP id br43-20020a05620a462b00b0079087260bc9mr3578110qkb.24.1714576664492; Wed, 01 May 2024 08:17:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714576664; cv=pass; d=google.com; s=arc-20160816; b=lE371WAQH5bGcR3pbSHf7vYdebBoItvmRQAnAvGzNuwWqFoWCk70t8/95ckQMMfytA g0rErpKVw/mvW73Te1a8BTzZ+pgrxQbfvJxQV5gPWEvJ29I5WvsSR0RfXUTviCz/g+bX BvylzH0Bql1O+iN/lI0DDgRF6MTM0KjEPA2VMXyAYvRdmPHpZDiYycpVsFXTArq8NJk8 rrSV2gBO1b3zgG8PhKI43Z4FNsMJboNLM9GLdQ2fZo/J7XV0qLdWdm2v1CfcXDzTlDXW cQztBm/iMtrW4VAkZFVy9h+/Uo6OR2zxjfAjy7armOxPNKXOkjay81SNAcwK5KqOWDIX uKqw== ARC-Message-Signature: i=2; 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:sender:dkim-signature; bh=QwEgxIWnM32F+RkCian+6qBxGOxyE8YmncEkkrcQ/lM=; fh=RQ+J2N2Gu1QMRF4DWWDsBOO956eFSnLe0drlwyj+B6c=; b=LlgkAQb1xsPGoBbAWV24odaVkVFqlTeksdwzYGEyDqlM1CEpYH+sO5zVG78svLTEJt 5VCqF82KI2MUwBGPPqfrM2a3mYKNxCRgFqwpqyzW/TeiDDLGy32MsPmWPpnLIWnEdIvH 83JioUWZ7r3mjm0r1zraIpqo89897Ys3X5VfPgzvH3FjNEe2QXOItOg6n5RoE4uP21Xo Ez4HDQPIPz5FFTzc6MbcBQm+Qj5IP0lugUlKDO6qi1F7iI4mS01Vqhu7gMY7InnRWHbB ULU/R3FYRqqH76OmtUrXcKBU5t0pFHp8u50nODm5CGNyCC+ItUFtNhC4uXI4rPD2CnP4 Wm6g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=X1ven8NB; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-165438-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165438-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y18-20020a37e312000000b0078d61cefbaesi30033523qki.441.2024.05.01.08.17.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 08:17:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165438-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=X1ven8NB; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-165438-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165438-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 2E1261C2129F for ; Wed, 1 May 2024 15:17:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 999AA12FB32; Wed, 1 May 2024 15:13:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="X1ven8NB" Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (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 47FC2132C1C; Wed, 1 May 2024 15:13:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714576438; cv=none; b=mBBONblxVNv1Y/ARDatc0p7Aco8wztygGyRAp5rM2sFApqc/gLjiY3vuAktM0B2XC/ERSklWQoX66dtdkApfaBRYMF2/ogLDZdn13wPrRydlZtXLmI6jaBN+sq+03syrs9dYhSuj8opZDyAFn57xLvLk81AQq11TQ4/MZj9l6/U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714576438; c=relaxed/simple; bh=1TaXLchZIIQq8Q0S2iJIFahxmDwj+k6Fd0DD6Br6kYc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JDRa5U7Y3K1227vQPArRYuvlmR+fzfd7Mtj0sUe+yGfldcuaHzgd106ATtkMDd4VILnbzqO9nk0ycJnZVLSd6R9GOKdPtvcdJHnLwVlFI8xMvjkNbNFbep1vx7TGXjStGvqN7hrBEyDsrqGCMqJv5P5eH03A3NEmzx+KcPIUDxA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=X1ven8NB; arc=none smtp.client-ip=209.85.215.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-5f415fd71f8so5457712a12.3; Wed, 01 May 2024 08:13:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714576436; x=1715181236; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=QwEgxIWnM32F+RkCian+6qBxGOxyE8YmncEkkrcQ/lM=; b=X1ven8NBleWzrRTMgwOri4X3SE57V+hNuwcnm00eSapPyhOIhGmNWweqXjqQowZh4a AvqvJAyapoh2WKiti/aNPwc+e61BpXX7uvF7kYB8YdO7JOk7tGpkMydFqIJFhgXygGJg qp75n/yqxVDdL+n6yBhQ5d/cTGLWGU5jvnOJZn+bM7fWEZ7OuzZVgcLdELppi6Uqnl1c JwmNtOR734Q3cA1kCNQJbBfJzv2W9KgDfcTIQlLm5X4Dty1KQcv1Bt47R0SIzSK47Gmu HQVAASIiHujV78dur9phn3jVxjwZbjb3Ms9tqd9iXGOtbcZb7GEYhGC25CAwBpnQdQWP 9+BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714576436; x=1715181236; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=QwEgxIWnM32F+RkCian+6qBxGOxyE8YmncEkkrcQ/lM=; b=j4R7TAgW44S3NKEZeR9J10AjnQjwKAB9CscRTWN9BX09ZZlCjGypLD5+9gyyLbBcIz 7tI8lURx0IyNKFTst5zKOlEO0s3Cfd7KScQBjuVLdpzo1jOSb6SPavFYcFhAP4MZzv0V Dt0bawyefXIGvckHEYffvQhM8QndKzVJgYFLBtaBDuNTW+m9hTaA7DKDlFlwE/yyDmQw nlxWCvPjpxM2+CieSZfBK0noDVQ6zMrg2I5WH+5fh/iU02tFw291tQVjAJbkPCepaRhG jBge7M/j9PLYnnrCB3B/LeKJnJi9RwhME8PNK4Do2qF71N6jzZ92WFKTQUBi5giayg3H Fj6g== X-Forwarded-Encrypted: i=1; AJvYcCWLRZRRUMO0R4K3+F+xlRp7gT2hNkPAEPDP6wryuN9P/2aR3c7kygSELjd9rxhCQMbNMWmY3/pKPIWsLholFeHLe97h X-Gm-Message-State: AOJu0YyOa4xghoHaMtr/8J4kTgEdhmFX3N33dXg5bbeSR9W47JcNUURN ID5INTY40xdO/5fAYBmdLQhSiipQLAWZg4fW2jTAypliSrUaVVNM X-Received: by 2002:a17:90b:4b41:b0:2af:8fa4:40e with SMTP id mi1-20020a17090b4b4100b002af8fa4040emr2675934pjb.1.1714576435472; Wed, 01 May 2024 08:13:55 -0700 (PDT) Received: from localhost (dhcp-141-239-159-203.hawaiiantel.net. [141.239.159.203]) by smtp.gmail.com with ESMTPSA id o9-20020a17090aac0900b002ad059491f6sm1443299pjq.5.2024.05.01.08.13.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 08:13:55 -0700 (PDT) Sender: Tejun Heo From: Tejun Heo To: torvalds@linux-foundation.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@kernel.org, joshdon@google.com, brho@google.com, pjt@google.com, derkling@google.com, haoluo@google.com, dvernet@meta.com, dschatzberg@meta.com, dskarlat@cs.cmu.edu, riel@surriel.com, changwoo@igalia.com, himadrics@inria.fr, memxor@gmail.com, andrea.righi@canonical.com, joel@joelfernandes.org Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, kernel-team@meta.com, David Vernet , Tejun Heo Subject: [PATCH 19/39] sched_ext: Print sched_ext info when dumping stack Date: Wed, 1 May 2024 05:09:54 -1000 Message-ID: <20240501151312.635565-20-tj@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240501151312.635565-1-tj@kernel.org> References: <20240501151312.635565-1-tj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: David Vernet It would be useful to see what the sched_ext scheduler state is, and what scheduler is running, when we're dumping a task's stack. This patch therefore adds a new print_scx_info() function that's called in the same context as print_worker_info() and print_stop_info(). An example dump follows. BUG: kernel NULL pointer dereference, address: 0000000000000999 #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page PGD 0 P4D 0 Oops: 0002 [#1] PREEMPT SMP CPU: 13 PID: 2047 Comm: insmod Tainted: G O 6.6.0-work-10323-gb58d4cae8e99-dirty #34 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS unknown 2/2/2022 Sched_ext: qmap (enabled+all), task: runnable_at=-17ms RIP: 0010:init_module+0x9/0x1000 [test_module] ... v3: - scx_ops_enable_state_str[] definition moved to an earlier patch as it's now used by core implementation. - Convert jiffy delta to msecs using jiffies_to_msecs() instead of multiplying by (HZ / MSEC_PER_SEC). The conversion is implemented in jiffies_delta_msecs(). v2: - We are now using scx_ops_enable_state_str[] outside CONFIG_SCHED_DEBUG. Move it outside of CONFIG_SCHED_DEBUG and to the top. This was reported by Changwoo and Andrea. Signed-off-by: David Vernet Reported-by: Changwoo Min Reported-by: Andrea Righi Signed-off-by: Tejun Heo --- include/linux/sched/ext.h | 2 ++ kernel/sched/core.c | 1 + kernel/sched/ext.c | 53 +++++++++++++++++++++++++++++++++++++++ lib/dump_stack.c | 1 + 4 files changed, 57 insertions(+) diff --git a/include/linux/sched/ext.h b/include/linux/sched/ext.h index 2608a8f548db..123d6dffdf26 100644 --- a/include/linux/sched/ext.h +++ b/include/linux/sched/ext.h @@ -155,10 +155,12 @@ struct sched_ext_entity { }; void sched_ext_free(struct task_struct *p); +void print_scx_info(const char *log_lvl, struct task_struct *p); #else /* !CONFIG_SCHED_CLASS_EXT */ static inline void sched_ext_free(struct task_struct *p) {} +static inline void print_scx_info(const char *log_lvl, struct task_struct *p) {} #endif /* CONFIG_SCHED_CLASS_EXT */ #endif /* _LINUX_SCHED_EXT_H */ diff --git a/kernel/sched/core.c b/kernel/sched/core.c index aae9c1297622..42fe654bf946 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -9272,6 +9272,7 @@ void sched_show_task(struct task_struct *p) print_worker_info(KERN_INFO, p); print_stop_info(KERN_INFO, p); + print_scx_info(KERN_INFO, p); show_stack(p, NULL, KERN_INFO); put_task_stack(p); } diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 8d2ff81e8dd4..ff080b5f0330 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -577,6 +577,14 @@ static __printf(3, 4) void scx_ops_exit_kind(enum scx_exit_kind kind, #define SCX_HAS_OP(op) static_branch_likely(&scx_has_op[SCX_OP_IDX(op)]) +static long jiffies_delta_msecs(unsigned long at, unsigned long now) +{ + if (time_after(at, now)) + return jiffies_to_msecs(at - now); + else + return -(long)jiffies_to_msecs(now - at); +} + /* if the highest set bit is N, return a mask with bits [N+1, 31] set */ static u32 higher_bits(u32 flags) { @@ -3695,6 +3703,51 @@ static const struct sysrq_key_op sysrq_sched_ext_reset_op = { .enable_mask = SYSRQ_ENABLE_RTNICE, }; +/** + * print_scx_info - print out sched_ext scheduler state + * @log_lvl: the log level to use when printing + * @p: target task + * + * If a sched_ext scheduler is enabled, print the name and state of the + * scheduler. If @p is on sched_ext, print further information about the task. + * + * This function can be safely called on any task as long as the task_struct + * itself is accessible. While safe, this function isn't synchronized and may + * print out mixups or garbages of limited length. + */ +void print_scx_info(const char *log_lvl, struct task_struct *p) +{ + enum scx_ops_enable_state state = scx_ops_enable_state(); + const char *all = READ_ONCE(scx_switching_all) ? "+all" : ""; + char runnable_at_buf[22] = "?"; + struct sched_class *class; + unsigned long runnable_at; + + if (state == SCX_OPS_DISABLED) + return; + + /* + * Carefully check if the task was running on sched_ext, and then + * carefully copy the time it's been runnable, and its state. + */ + if (copy_from_kernel_nofault(&class, &p->sched_class, sizeof(class)) || + class != &ext_sched_class) { + printk("%sSched_ext: %s (%s%s)", log_lvl, scx_ops.name, + scx_ops_enable_state_str[state], all); + return; + } + + if (!copy_from_kernel_nofault(&runnable_at, &p->scx.runnable_at, + sizeof(runnable_at))) + scnprintf(runnable_at_buf, sizeof(runnable_at_buf), "%+ldms", + jiffies_delta_msecs(runnable_at, jiffies)); + + /* print everything onto one line to conserve console space */ + printk("%sSched_ext: %s (%s%s), task: runnable_at=%s", + log_lvl, scx_ops.name, scx_ops_enable_state_str[state], all, + runnable_at_buf); +} + void __init init_sched_ext_class(void) { s32 cpu, v; diff --git a/lib/dump_stack.c b/lib/dump_stack.c index 222c6d6c8281..9581ef4efec5 100644 --- a/lib/dump_stack.c +++ b/lib/dump_stack.c @@ -68,6 +68,7 @@ void dump_stack_print_info(const char *log_lvl) print_worker_info(log_lvl, current); print_stop_info(log_lvl, current); + print_scx_info(log_lvl, current); } /** -- 2.44.0