From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796177484; b=IswcAL3YuHQr7h0ArhT+hzlSYObjLPvNi3I5BZl+dDFT/Z1jnpO6WJhApGKwlZItX0mJ Mg3h8KPTobu0FjrVWLjaYRVqGFIx4knEUoQvUwxr+t0//3uwG3V7SpIRTRcz1kwEzFD5Q dcsYWCIoxAvbZG1gvHXFGLbCJH978nTeUwfhZ25aGfvFY68Lzo6uBOLrWEMQCVSgLOoXv FZJrdgfeq3BNKPKR53J/rS49p8pcy1Jb9hC4EMwdPvCz7HcU6Wi6A61x5GLb9kGeBS9Yu vpNQOuq5aFXbkDfe8Zgih9jCUpImQ4SRgoMz1B+E6pUfQ4GEiTZY/vYMA8pyjfW3Mdw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796177484; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=eaLrtAVoEdhx1KkO+saOfNlbgYPvpveU/C2lV7jFIfo=; b=vEguOfe8gGmTJfpkap2CUBsTx9Ko66rJC4wLEbo6ehF+VJOYY1AUb7zhK/Y8mK6XIvvT XDbs51KqHiy7NAYJ3pEHk9dBMOOHbwjstVB19PJ4Y2o4PjreM6mmG52pN75+mNgvC2Dh6 fM57s1ngUotNtdubbhi8wXNHf8nDWC1JjZDU1alV4XLmADprtIvQsGK7lNINVB5DJZvGo cPmGEXnkQoPdSY5WDYyeLkwtjXc4nNlhKwyzd0XPCZ0vktR+NPOGmM6c9qduB/+qEPfyH 6wZTcOqiy5dXnCU6b//o02PTBIvFZs2576n//0GSXIJXUAT7VoJVyi1YB3eXgpzU6zQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="gFKd7k/n"; arc=none smtp.remote-ip=209.85.221.43 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6863C606A31A for ; Wed, 2 Dec 2026 02:11:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6863C606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=gFKd7k/n Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-4c4b8e58c9aso2140161f8f.0 for ; Tue, 01 Dec 2026 18:11:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796177483; x=1796782283; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=eaLrtAVoEdhx1KkO+saOfNlbgYPvpveU/C2lV7jFIfo=; b=gFKd7k/nJtNsy4hkqb3NbUpH2R1r0KZHudfrqae3Bzb8PpFs7jIdT6bzRaaklk/xXA UUa7B0vXc+lwblhMXScTAzGqhCiAJSv6lzCSPJNwp1jOs6GKm0nPzY3Tm6v5VyZYB3lp rAOWMREhL7ZvRThghB4VkBbwvfh6ec5SDOQ/rqFojgWcEW3/b1GoDOGKnq1FBzH/3dSu Q13R8r9gxWqVU3xfIKxDC0AlNO3H8RUYoJplDyrsHiye4rSiujWi9ATMNQtORZ+WZx6u YI+HfqkdvuOLKoCH8GjzwCu+s30aOfrAIHKMYwwfHwjc9ugn5L0rQSZTwj3BXilK6GjL HuqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796177483; x=1796782283; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=eaLrtAVoEdhx1KkO+saOfNlbgYPvpveU/C2lV7jFIfo=; b=lJdAdZJiN7V6x4Qzj7O0tScsQJ5HI2MJ0IkgmakOq7JXpjlG347wrzlNiXLp9Xrzw6 +lwu0bj6RQhGQdzz+2V2EPpJMaj7uxOqApR4RXzmREpG6tBkkjmrWop/Ner4+SQ7oitE 17V9geZNFeKAub7Enn5CTE+zd5mUX7/KCWfQFAr/oLiUNOY/N5yPECZYbUiuljy5MKlK PaJFjAvOr2LoHBDdbiR9QMQxLK/DxexI3U+SXIt5BE7IFd6PHQLXvvx1W87CoGIyy8SD 06LlOtLhvC7xRoqgHQu2TL+uS7jy9Mby7xNxw+onnJCSVotFZctdAnhT03f3b+JyAbcl 1NLA== X-Forwarded-Encrypted: i=1; AL+hErHqSk5i2BnA35W6UNCkLczko/xRqcSlKIugEzCDPOAz9PsEN1lGxtRY14NA4ijQ2RwXhhiw3WaViT5jcYw/Dbjj8GI=@vger.kernel.org X-Gm-Message-State: APuU4Z+lsukNeJnHs8XO54vjntTYe63BqOteqH8R2+zD8CnqNgFqgZoI QcVSAB2YE8rh7NAUv5fOyyVb9Z2eXRwbeyrRwaODE7PXoe0II5oNUj5+ X-Gm-Gg: AZFdTZdmEMvhYXt07gpeZmjbp2ciPXH2ApEFDh73wc1/xY/336VX6HPZsJTZqp2gTBw 6WrZHtCoDaGGpWZbb6ntCZOfxW00rb6cr/ZhDO0UuT9PiGsEObArtfCe4l4cDoq040eWK09xbxt +YiGvTVjUm1G05PSTavi0JLhoLftNN109G339qJ6ZDfsRQfXXfRAmWTUs317LcWT99cMVsu+i7g OlMTug8ichRGXF5TaWRWxrQLBsxIN9FeLsyHi08KdL+yF6IapdHRyUy6bAwYgr7m+/mSVGoUCBi At4w/lcRBxJgvgCcV6Ue+N6SPh6Tn5Y46li15ibr0mld5+eyfVpJuvS469hVpn5D0CJpBd5pa9f u+0dyVtxASjmr+aW4atcKdp8TJ7DltgjWBfbi2lximqd862z77oCqzSvlehlw2jIszTGE+7ba45 ulGFXs4w/u/TQNXc9u5Qw1XfVxhgI6rNBT7lcc1c+C3YafGprOGQ88hvFEzCPf3Pk/9mWaR6zRi HgkDZ9lEo7PE0RDId+DOWWbdkm/36okG0mxcvio2IDv0dust81F9KX1OuSP5vl0T9FM1zcOse35 P6bnf6UF+T3HU1jlFhNICxtSbQDdWhsSNmhtjiEYaQHRvzyHCOfb61INBq1Wan3YdKxn6sqKGd6 g/H/VvllHC2o1MQwK6rJXP9F2JYz0C3oBsaX5dyER7l/8hH7oXREg/B/Xh3q7JM2tTBIMImu2WM 0qqVwWrPrEJn8hezBzL6MHs+PxmRbhzRnuVjJWygTxRuEAVatz6cSgZA== X-Received: by 2002:a05:600c:1d0a:b0:4bb:840c:72f2 with SMTP id 5b1f17b1804b1-4bb889323a1mr754774655e9.25.1796177482787; Tue, 01 Dec 2026 18:11:22 -0800 (PST) Received: from localhost.localdomain (dynamic-2a02-3100-a5c9-8d01-34fb-c870-a93e-3922.310.pool.telefonica.de. [2a02:3100:a5c9:8d01:34fb:c870:a93e:3922]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb90655f5asm748115915e9.1.2026.12.01.18.11.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 01 Dec 2026 18:11:22 -0800 (PST) From: Karl Mehltretter To: Steven Rostedt , Gabriele Monaco Cc: Karl Mehltretter , Jonathan Corbet , Shuah Khan , Randy Dunlap , Masami Hiramatsu , Mathieu Desnoyers , Nam Cao , Peter Zijlstra , Ingo Molnar , linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] rv: opid: Allow self-wakeups with interrupts enabled Date: Wed, 2 Dec 2026 03:11:08 +0100 Message-Id: <20261202021108.32564-1-kmehltretter@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On non-PREEMPT_RT kernels without threadirqs, the opid monitor reports a false positive when a task wakes itself from an inline softirq: rv: monitor opid does not allow event sched_waking on state any with env irq_off=0,preempt_off=1 For example, schedule_timeout() arms a non-TIMER_IRQSAFE timer for current and calls schedule(). If the timer expires inline on IRQ exit before the task switches out, expire_timers() enables interrupts and calls process_timeout() -> wake_up_process(current). The p == current fast path in try_to_wake_up() skips pi_lock and only disables preemption, so trace_sched_waking() runs with interrupts enabled. Commit 2b406fdb3338 ("rv: Convert the opid monitor to a hybrid automaton") enabled opid by default on non-PREEMPT_RT kernels but kept the irq_off == 1 guard for all wakeups. Split self-wakeups into a separate sched_waking_current event that only requires preemption to be disabled, leaving the existing guards for other wakeups and sched_need_resched unchanged. Update the model, documentation, and KUnit test. Fixes: 2b406fdb3338 ("rv: Convert the opid monitor to a hybrid automaton") Signed-off-by: Karl Mehltretter --- Tested on x86_64 v7.4-rc3 with an AF_UNIX SO_RCVTIMEO workload (6/6 unpatched vs 0/6 patched, 0/3 with threadirqs) and rv_test_opid on non-RT and PREEMPT_RT. Accepted IRQs-enabled sched_waking_current events were observed in the trace on patched runs. Restricting opid back to PREEMPT_RT would be an alternative, though the p == current fast path does not require IRQs disabled regardless. Assisted by an LLM. Documentation/trace/rv/monitor_sched.rst | 11 +++++-- kernel/trace/rv/monitors/opid/opid.c | 11 ++++++- kernel/trace/rv/monitors/opid/opid.h | 4 ++- kernel/trace/rv/monitors/opid/opid_kunit.c | 37 ++++++++++++++++++++++ tools/verification/models/sched/opid.dot | 2 +- 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/Documentation/trace/rv/monitor_sched.rst b/Documentation/trace/rv/monitor_sched.rst index d3ba7ed..aa50efa 100644 --- a/Documentation/trace/rv/monitor_sched.rst +++ b/Documentation/trace/rv/monitor_sched.rst @@ -344,9 +344,13 @@ can be triggered also by preemption, but cannot occur after the task got to Monitor opid ------------ -The operations with preemption and irq disabled (opid) monitor ensures -operations like ``wakeup`` and ``need_resched`` occur with interrupts and -preemption disabled. +The operations with preemption and irq disabled (opid) monitor checks +the interrupt and preemption state during ``wakeup`` and ``need_resched`` +operations. +Wakeups of tasks other than ``current`` require both interrupts and +preemption to be disabled. Self-wakeups do not take ``pi_lock`` and only +require preemption to be disabled, for instance when a timer expires in a +softirq running on interrupt exit. This is the ``sched_waking_current`` event. ``need_resched`` can be set by some RCU internals functions, in which case it doesn't match a task wakeup and might occur with only interrupts disabled. The interrupt and preemption status are validated by the hybrid automaton @@ -357,6 +361,7 @@ constraints when processing the events:: v #=========# sched_need_resched;irq_off == 1 H H sched_waking;irq_off == 1 && preempt_off == 1 + H H sched_waking_current;preempt_off == 1 H any H ------------------------------------------------+ H H | H H <-----------------------------------------------+ diff --git a/kernel/trace/rv/monitors/opid/opid.c b/kernel/trace/rv/monitors/opid/opid.c index 9ae619f..cd450eb 100644 --- a/kernel/trace/rv/monitors/opid/opid.c +++ b/kernel/trace/rv/monitors/opid/opid.c @@ -40,6 +40,8 @@ static inline bool ha_verify_guards(struct ha_monitor *ha_mon, else if (curr_state == any_opid && event == sched_waking_opid) res = ha_get_env(ha_mon, irq_off_opid, time_ns) == 1ull && ha_get_env(ha_mon, preempt_off_opid, time_ns) == 1ull; + else if (curr_state == any_opid && event == sched_waking_current_opid) + res = ha_get_env(ha_mon, preempt_off_opid, time_ns) == 1ull; return res; } @@ -60,7 +62,14 @@ static void handle_sched_need_resched(void *data, struct task_struct *tsk, int c static void handle_sched_waking(void *data, struct task_struct *p) { - da_handle_start_run_event(sched_waking_opid); + /* + * try_to_wake_up() wakes current without taking pi_lock, so interrupts + * can be enabled, e.g. when a timer expires in a softirq on irq exit. + */ + if (p == current) + da_handle_start_run_event(sched_waking_current_opid); + else + da_handle_start_run_event(sched_waking_opid); } static int enable_opid(void) diff --git a/kernel/trace/rv/monitors/opid/opid.h b/kernel/trace/rv/monitors/opid/opid.h index fb0aa4c..b8e9704 100644 --- a/kernel/trace/rv/monitors/opid/opid.h +++ b/kernel/trace/rv/monitors/opid/opid.h @@ -17,6 +17,7 @@ enum states_opid { enum events_opid { sched_need_resched_opid, sched_waking_opid, + sched_waking_current_opid, event_max_opid, }; @@ -45,13 +46,14 @@ static const struct automaton_opid automaton_opid = { .event_names = { "sched_need_resched", "sched_waking", + "sched_waking_current", }, .env_names = { "irq_off", "preempt_off", }, .function = { - { any_opid, any_opid }, + { any_opid, any_opid, any_opid }, }, .initial_state = any_opid, .final_states = { 1 }, diff --git a/kernel/trace/rv/monitors/opid/opid_kunit.c b/kernel/trace/rv/monitors/opid/opid_kunit.c index 3cb087a..dcaea97 100644 --- a/kernel/trace/rv/monitors/opid/opid_kunit.c +++ b/kernel/trace/rv/monitors/opid/opid_kunit.c @@ -21,6 +21,43 @@ static void rv_test_opid(struct kunit *test) RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) rv_opid_ops.handle_sched_waking(NULL, NULL); + /* Wakeup of another task with only preemption disabled */ + RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) { + scoped_guard(preempt) + rv_opid_ops.handle_sched_waking(NULL, NULL); + } + + /* Preemption is only checked with CONFIG_PREEMPTION */ + if (IS_ENABLED(CONFIG_PREEMPTION)) { + /* Wakeup of another task with only interrupts disabled */ + RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) { + scoped_guard(irq) + rv_opid_ops.handle_sched_waking(NULL, NULL); + } + + /* Wakeup of current with only interrupts disabled */ + RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) { + scoped_guard(irq) + rv_opid_ops.handle_sched_waking(NULL, current); + } + + /* Wakeup of current with preemption and interrupts enabled */ + RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) + rv_opid_ops.handle_sched_waking(NULL, current); + } + + /* Wakeup of current with only preemption disabled */ + scoped_guard(preempt) + rv_opid_ops.handle_sched_waking(NULL, current); + RV_KUNIT_EXPECT_NO_REACTION(test, ctx); + + /* Wakeup of current with preemption and interrupts disabled */ + scoped_guard(preempt) { + scoped_guard(irq) + rv_opid_ops.handle_sched_waking(NULL, current); + } + RV_KUNIT_EXPECT_NO_REACTION(test, ctx); + /* Need resched with interrupts enabled */ RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) { scoped_guard(preempt) diff --git a/tools/verification/models/sched/opid.dot b/tools/verification/models/sched/opid.dot index 511051f..35fbd6c 100644 --- a/tools/verification/models/sched/opid.dot +++ b/tools/verification/models/sched/opid.dot @@ -5,7 +5,7 @@ digraph state_automaton { {node [shape = doublecircle] "any"}; "__init_any" -> "any"; "any" [label = "any", color = green3]; - "any" -> "any" [ label = "sched_need_resched;irq_off == 1\nsched_waking;irq_off == 1 && preempt_off == 1" ]; + "any" -> "any" [ label = "sched_need_resched;irq_off == 1\nsched_waking;irq_off == 1 && preempt_off == 1\nsched_waking_current;preempt_off == 1" ]; { rank = min ; "__init_any"; "any"; -- 2.39.5 (Apple Git-154)