From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796177484; b=lByVx0gHPjGhffRzC3Nakb1iKwXfQDk+Zy4eL4rlmUjX0aLfrZ4o5QX7dDPm0ebEJHhP amUF9BXLWjs9xtTJakqnZdCPDN0EfS2kr+LCWG+JEpkySZ3AjvLfCxflHJA6/Dx67LeRK YH0h1FGV7Bgc+PnmXuaOHAM0DwC+ezz0MNcbXWE+E/l072rzr/hflF25EOCrS12At3V1p SCezFUAJl9FAgrPIFj676zS15B8n8ewzkWu6mzyk6Fl/aVkaWPNgFwn7AZk8f7bsXD25u NrTUTMNTGCstRg32U0r/cxKJHghpj8VDD9WYGhdTvbaq0sIxRgU6NTTK7x/KAi9JxSw== 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=HhwVzmd6biucgq3+yHDpZegkCOmzyoWK289cMikNgEkU7kKXC8wjF/RnfM0JIlMWbSVG DA0mGdx3fcCU8y4oK1Z5tCNSo0PDUHw4BgAv0em266XSB91k/N629BpAJnLOQDp176y7B Hxcvx02dTDYO65d7d3nVVWmk1RRBP+6ShOI+98aTv6Kw1eRCdQD0twNTWJBJy2AoCQWxs XIqNft/EkKohuOBlRgmq4O+A6VoPRoKu4ZHKb/LOcKrK5NW5vigfwn21vcJ7O+4XAyZ1Z PbD+CxZYZFSpPtIn8zPeVNWEaidqco6Pvixqw634pCvYgC9aIotkB2uI71xepZiMxIA== 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.128.44 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 777C9606A323 for ; Wed, 2 Dec 2026 02:11:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 777C9606A323 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-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4b467581b98so116021875e9.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=c1MbdP/Je2bUOVxH0kN+ET9FpuH4FUp8IkiGnr2UasPcXPGOCr8597XmUVi1l2PxqC tEArgxhNEjw2vh3o5IwvPY1m/ZbVAty1YhBWDtyKBvSlBUOof9by4yVmiItDTQW8dRLE BfZNrsoRCoupGKpZsCxqK8cgKEpXGXNSHU6iWAp0FIGQHwluksz8N1+VlXQpgRp/xqYN ZfYPWivNDwfdgy2UkAyZ5BkWA9FD5OfW8ZnPl7fM8zpBA2eEdkr2SWrBOuK5fDbl57P8 ZvzWdKkCGybBVfEuFLRprEfNAjl9Gtadd5Ne+oR0EIjghNM51R37S5fdvUZdbvighfEW NLdw== X-Forwarded-Encrypted: i=1; AL+hErG9HL44OhxLrRM2/eDcPU6DAtCSb/KcJuUBbNogBchLJSMVr/dQiPLSilO1kEMSUvG/24kPqSkOtvZzwBY=@vger.kernel.org X-Gm-Message-State: APuU4Z8fmEzDnoLHS+DlMOq/qAuFsLEEp7lWUlSbqAjEo7C3mx7mDKCC S/2q6DqJ4xaX7uoOu2rn4WrH9na45jE4+OtVCH5vTuTusk6kFnc5xHqjhlGIYw== X-Gm-Gg: AZFdTZeZpQfjcIZZPAtaHLgco0K8Zu5sHQhO+Mr/zwr7NMI+sfPuIkDSwBTnijbGHv4 IQMrydrNcw0INri8cRkiMjDBkM/ReT5gch+X4zl5tlv95a9q3Os0nGIFu634gsNVRGBsYhk0s5J H4i7ogm8PvIcDr4ha3D/iuZToGzGz8QXKlEw2tAbWsQtY2zr+M0d8cr2bi1qedPmwnM/apGnesY wwRB/DQ7Dbir7mKtDMHMVzHwLTtwepEiQ92CGmER6+WmMAEz1bGs6VYOcUWYjZuUJ8Z73r+6m6W 94EYofWXziyFs/XYBfokPDlkxfr5nx92yMVN6glBaUTpn4x1ssNMcSmj1EsKw32D5gbaUdDxx0h dS4CCNnsPueW7mZWmX754qoFLlpn5Nk2sk1l/HWQQpwOlO1vl5dJInzFwxAlz0hWT/AYS2JkYiE ysGQx3dYN/vcz7N7SLpn/mqE+BUmta6CxSqa1rm3Gv3fPYq4nyEkIIORiEjjIJmU06yKK9nMFuU 8H35IUvabXB+UfurRZp9ciJbyBDl0wHmK/TWTCWkMI14iuVkXlyb0j+IZnNDGNyOxXdoVQAju+Y 2uBJegbhWcW9ZClCkhrfsv+q726VNEd3dXdgp84r5QtDz4ZmsQIL5DGgQkeflKUEI/KhHDj3etd gDzxjowNl//cSt2C8qXlteB+anhF3PQX1moqS02fKBHB9i/uI5dbZpuOBTWcvA37u6vXMmwTodh 3d9pC+S7KinBfWn2cNrqfDHu7M4nmkdPIq+XxXcJNdmcQJ7wuTdefL+A== 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-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)