From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796373082; b=yRn1VzZjxP5KUp23nM77qZ9y3UaLuACnEssAq6WsK76C/wjzz6+x6khiwUrpYukuEkVk GonquaE2vo6TnSLFIl06QzbgdnKoj743BiybjtK4OYgiCCBiXTXS4VqN4Gx4I8IG6KAFS d5hXn2z+bvpGehartRLrc22laiqAuZz7IT9m3l8Lfi/XCXEHBQeaPd1qqEeOn4T5XQDl5 xJNEWXTUuvCYHeGGLyAYhPV0DMv5uTnAhmFG4Hr8Z8OeZr4/FaELMjVRYxRvr4eCr13uA NvPjoGyVpHjRWS2JbQdYw0CQ1A5vdW1+SM8eL/UPFVho8bXqZHxt9H+wuvIznwrMS+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796373082; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=vk/g/sLHE/XCj9FYucNEYotHbLHBjh9BNTM+KuAPAFA=; b=sEOi3oxjngihV9G/YyBsMIbWjNOsyOizymGB6hoMHFObLwWDWw4TuJzHo8XssjZdF1gc 1KN5VBBCYhYHhvsj/Jc/eoqymp+aAkCJlPOPsChy3lAsSCANM3tQVDLfbjquiFP7b4YV2 1fi+oLuYVAGkf780PccMGIHFhBFs6lr3CD5jSQiepYriwUBg7jJyFAgUPpSb+pxM1YVgQ LQfBitQQGO3cLR9IaWQ8wF6CdXi5xH3YrgsDPaJ49nWHF/QPKpUQw0Q2y2QoArHZ5A9JV yc4lOruoOwIgyqw0nGmVTQJzsDb3GXF3vkw3cZ3QlOwgAgz3UNn21l0UZYYj341jc3g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="RwJVoT/m"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6809E606A32C for ; Fri, 4 Dec 2026 08:31:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RwJVoT/m Received: by smtp.kernel.org (Postfix) with ESMTPSA id E54F21F000C2; Fri, 4 Dec 2026 08:31:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796373082; bh=vk/g/sLHE/XCj9FYucNEYotHbLHBjh9BNTM+KuAPAFA=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=RwJVoT/mCPPd4i8pPkJC0K98SEQzLHfDVJIuFtpxJOnbMPawcVYWu8+lPLj/sa3EN q0gRaPOtVZfURBJegJMRMh/Y5CX1JDWI1kE1uRw+PpnJolDLohUOTDkeO4PbJKEiIk IxyvgAE/m2vRARHQueL3K17uOUqvbwRUGezp3ua5cvrbdnU4oHYl6UqhxC7DxdmLJ/ X1Wpn9xtWnMc/ibZWaoGUGzOOrWp6hHCk0kpyCpCEqG0EjBAyH8oNz6w84JKfxkPi1 IGpt5k57CtNGOd3WR1KZfhvhX/kQ74s54X3KsoHg0AZbVakfype+I03rIyLJG8+aB/ 4IXFLVZknlKoQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] rv: Adapt handle racing preemptions in nrp Reply-To: sashiko-reviews@lists.linux.dev To: "Gabriele Monaco" , linux-trace-kernel@vger.kernel.org In-Reply-To: <20261204080908.129943-1-gmonaco@redhat.com> References: <20261204080908.129943-1-gmonaco@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 08:31:21 +0000 X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [Medium] rv: racing_resched self-loop in nrp drops new reschedule on vain schedule - [Medium] rv: nested preemption during racing preemption fails nrp guard check - [Low] rv: incorrect any_thread_running self-loop labels in nrp documentation - [Low] rv: need_resched guard on preempt_irq causes false positive at startup - [Low] rv: nrp attaches unused sched_process_exit probe and extra synchronize_rcu() - [Low] rv: missing Fixes trailer for nrp monitor introducing commit -- commit a94703095d16688d6cf8c217dc6265f8e208b268 Author: Gabriele Monaco > rv: Adapt handle racing preemptions in nrp > > As Prateek pointed out and Andrea validated, the schedule_entry event > may be seen before the set_need_resched event that caused the > preemption. This rare race can occur because the schedule_entry is > emitted before taking the rq lock. > The nrp model expects a strict order and catches this as a violation. > > Add a branch to handle this inverted order. Essentially allowing a > preemption provided the set_need_resched is visible before being done > scheduling (switch out or sched_exit if there was no switch). > > This weakens the model because it allows a preemption without > need_resched where the flag is simply set later in an event unrelated to > the preemption. > > Guard this by transforming nrp in a hybrid automaton and also mandate > the TIF is set when preemption occurs. > This applies in all preemption cases besides a nested preemption, > where the flag is cleared by a racing scheduler call. > > Cc: K Prateek Nayak > Cc: Andrea Righi > Cc: Nam Cao > Signed-off-by: Gabriele Monaco [Severity: Low] This fixes false-positive violations in the nrp monitor introduced with the monitor itself. Should this include: Fixes: e8440a88e56b ("rv: Add nrp and sssw per-task monitors") > diff --git a/Documentation/trace/rv/monitor_sched.rst b/Documentation/tra= ce/rv/monitor_sched.rst > index d3ba7edc202f6..c2cc8f25ac18c 100644 > --- a/Documentation/trace/rv/monitor_sched.rst > +++ b/Documentation/trace/rv/monitor_sched.rst [ ... ] > + schedule_entry #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D# > + schedule_exit H H > + irq_entry H H > + +----------------- H any_thread_running H [Severity: Low] Should this self-loop label use schedule_exit_vain instead of schedule_exit and also list sched_switch_preempt? Both nrp.dot and automaton_nrp in nrp.h use schedule_exit_vain (there is no schedule_exit event) and include sched_switch_preempt on that self-loop. > diff --git a/kernel/trace/rv/monitors/nrp/nrp.c b/kernel/trace/rv/monitor= s/nrp/nrp.c > index 4b5646a700946..be6f4a036079c 100644 > --- a/kernel/trace/rv/monitors/nrp/nrp.c > +++ b/kernel/trace/rv/monitors/nrp/nrp.c [ ... ] > +static inline bool ha_verify_guards(struct ha_monitor *ha_mon, > + enum states curr_state, enum events event, > + enum states next_state, u64 time_ns) > +{ > + bool res =3D true; > + > + if (curr_state =3D=3D any_thread_running_nrp && event =3D=3D schedule_e= ntry_preempt_nrp) > + res =3D ha_get_env(ha_mon, need_resched_nrp, time_ns) =3D=3D 1ull; [Severity: Medium] Can this guard trigger a false-positive error_env_nrp violation when an IRQ nests inside preempt_schedule_common() during a racing preemption? Because irq_entry self-loops in any_thread_running and racing_resched always returns to any_thread_running on completion, the monitor loses track of the nested preemption: CPU0 (task T) CPU1 [state: any_thread_running] __resched_curr(rq0, TIF_NEED_RESCHED) set_nr_and_not_polling() preempt_schedule_common() (before preempt_disable_notrace()) irq_entry -> any_thread_running preempt_schedule_irq() __schedule(SM_PREEMPT) schedule_entry_preempt -> racing_preempt trace_sched_set_need_resched_tp() sched_need_resched -> racing_resched clear_tsk_need_resched(T) schedule_exit_vain -> any_thread_running __schedule(SM_PREEMPT) schedule_entry_preempt <-- need_resched =3D=3D 0, error_env_nrp When the outer __schedule(SM_PREEMPT) runs after the IRQ returns, TIF_NEED_RESCHED is already cleared, so the guard fails and triggers a spurious monitor reaction and reset. > + else if (curr_state =3D=3D preempt_irq_nrp && event =3D=3D schedule_ent= ry_preempt_nrp) > + res =3D ha_get_env(ha_mon, need_resched_nrp, time_ns) =3D=3D 1ull; [Severity: Low] Can this guard on the initial state preempt_irq cause a false-positive error_env_nrp right after enabling or resetting the monitor? handle_sched_need_resched() starts an untracked task in preempt_irq. If that happens while a nested preempt_schedule_irq() is already running on another CPU, the inner schedule clears TIF_NEED_RESCHED before the outer __schedule(SM_PREEMPT) runs: CPU0 (task T) CPU1 [monitoring =3D=3D 0] __resched_curr(rq0, TIF_NEED_RESCHED) set_nr_and_not_polling() preempt_schedule_common() preempt_schedule_irq() __schedule(SM_PREEMPT) schedule_entry_preempt (ignored) trace_sched_set_need_resched_tp() -> starts in preempt_irq clear_tsk_need_resched(T) schedule_exit_vain -> preempt_irq __schedule(SM_PREEMPT) schedule_entry_preempt <-- need_resched =3D=3D 0, error_env_nrp Because preempt_irq -> nested_preempt was previously unguarded, this startup race did not trigger a spurious violation before. [ ... ] > static int enable_nrp(void) > { > int retval; > =20 > - retval =3D da_monitor_init(); > + retval =3D ha_monitor_init(); [Severity: Low] Does switching to ha_monitor_init() without HA_SKIP_AUTO_CLEANUP attach an unused sched_process_exit probe and add an extra synchronize_rcu()? nrp leaves HA_TIMER_TYPE at HA_TIMER_NONE, so ha_cancel_timer_sync() is a no-op, yet ha_monitor_enable_hook() still hooks sched_process_exit to run memory barriers and reset task_struct->rv on every exiting task. In addition, da_monitor_sync_hook() runs a redundant synchronize_rcu() in disable_nrp() right after tracepoint_synchronize_unregister(). Defining HA_SKIP_AUTO_CLEANUP here, or gating those hooks in ha_monitor.h on HA_TIMER_TYPE !=3D HA_TIMER_NONE, would avoid both costs. > diff --git a/kernel/trace/rv/monitors/nrp/nrp.h b/kernel/trace/rv/monitor= s/nrp/nrp.h > index 3270d4c0139fd..e2e71a940d326 100644 > --- a/kernel/trace/rv/monitors/nrp/nrp.h > +++ b/kernel/trace/rv/monitors/nrp/nrp.h [ ... ] > + { > + racing_preempt_nrp, > + racing_resched_nrp, > + INVALID_STATE, > + INVALID_STATE, > + INVALID_STATE, > + INVALID_STATE, > + }, > + { > + racing_resched_nrp, > + racing_resched_nrp, > + any_thread_running_nrp, > + INVALID_STATE, > + INVALID_STATE, > + any_thread_running_nrp, > + }, [Severity: Medium] Does self-looping racing_resched_nrp on sched_need_resched_nrp drop a new reschedule arriving before schedule_exit_vain_nrp and cause a spurious violation on the next preemption loop iteration? In __schedule(), when prev =3D=3D next, clear_tsk_need_resched() and raw_spin_rq_unlock_irq() run before trace_sched_exit_tp(false): CPU0 (task T) CPU1 [state: racing_resched] __schedule(SM_PREEMPT) [next =3D=3D prev] clear_tsk_need_resched(T) raw_spin_rq_unlock_irq(rq) resched_curr(rq) set TIF_NEED_RESCHED sched_need_resched -> racing_resched trace_sched_exit_tp(false) schedule_exit_vain -> any_thread_running preempt_schedule_common() loops (need_resched() is true) __schedule(SM_PREEMPT) schedule_entry_preempt -> racing_preempt sched_switch_preempt <-- INVALID_STATE, error_nrp Because TIF_NEED_RESCHED is already set, no further sched_need_resched event is emitted for the second __schedule(SM_PREEMPT), leaving the monitor in racing_preempt where completion hits INVALID_STATE. Transitioning racing_resched_nrp -> rescheduling_nrp on sched_need_resched_nrp (and updating nrp.dot to match) would preserve the pending reschedule across schedule_exit_vain_nrp. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204080908.1299= 43-1-gmonaco@redhat.com?part=3D1