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=1796111853; b=yUxooXyzxdP63zCKI+M8ClXwYDZsFWABQgcJpNnz086/0k9BVF+ZhxwUTycJJtJBRFcj OFC4ofYj2PFQoqggA6k1aSUpQrXoO/lzcHFm/jq8QUnoNQrRAq6HUl7IBfExKAcj5kdX9 37NBEu6XmfCRTYRj3nM+1MG7MFuSZMmod4LsV7lSx7yxg+/T2vcqAn79xYTbXsdkMagsZ +iteG5VJ5+9vTviIGUDPbu/delvbMTrPCSnR+jrj58H/c2eJ/Bjq4bmPzg2s4RJk1Z7ob ux6iXfUOEZWmGUuqYk+/2GupEMIU5dh0dsyx220JW+8Dw3sajlJfJKCqmzX0X0iRzjQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796111853; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Duv7XbBAT0QTqb4xY44Bw23Y30eXcR3JqYY0TD8SM9M=; b=xiXhOXQhM9OUyEVDO0C14ZvUdpLn22lC/k65hpSrYrDuAhIUG7Wq3wIak5ShQMyV5CFa fZUc4YQgmmGi/6J7xMNSjTxpNN8iaiw8iM4TEZUddnxBiC5c73gV7609Bz0wz6LzVQp2h +BLEFrDhQaFv62i0f9UvVsPKJJE2o19BvYcwu2ioiD4wkrMDwt/udugwqZI+Y+FAxBlJ7 X+9LUDwAKT1nktbwbS1jbUhBYOaZRsppyPBAAT9QTbjgUW6CSQ+RwIA8jDdeT5xZdvGSO D+LKLztJacN8efzzHR956Mm1ymWWjMMcELieIU//7Lc4h+QDvUKTQaLrUfUwMnG4WeA== 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=Ob9foHVs; 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 572A6606A320 for ; Tue, 1 Dec 2026 07:57:33 +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=Ob9foHVs Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0EE61F000C1; Tue, 1 Dec 2026 07:57:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796111852; bh=Duv7XbBAT0QTqb4xY44Bw23Y30eXcR3JqYY0TD8SM9M=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=Ob9foHVsPCFBagfdCWaaICVwD9ehAyp+t1LnBYwR+kdPQfLSbAibop9xEMK2WYygF P7RqGgOojVi3aJb78drLoneem+UsVSGL70S86AFuUW6xRxC27lqmZouGUthpGciFXG FfsKmblJSqZNxa8fVHpGSdh4kD4kr/SMZC8L7eJ9QOU/EI4mHQS0nHN+qYh8DPlilO S6N56jX/Gp8pK56qfJIucajOtUWT+0ZPnJo+IjRjp3bpAaz+Zi0eKVf32PsSBQZSrP cwQieXIizNinwlFy80D0/S7xEjYl9tSuO0BMbBdG4uHC2Y4LA+DcVDoYpFbvkEARhr HCy4ExQv6ttjw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] rv: Represent uninitialised and dying DA monitors Reply-To: sashiko-reviews@lists.linux.dev To: "Gabriele Monaco" , linux-trace-kernel@vger.kernel.org In-Reply-To: <20261201073453.56226-2-gmonaco@redhat.com> References: <20261201073453.56226-2-gmonaco@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 07:57:32 +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 3 potential issues to consider: - [Medium] rv: missing release-acquire ordering on started in da_monitor_started() - [Medium] rv: TOCTOU race on da_mon->dead leaves active timer in freed storage - [Medium] rv: uncanceled lingering timer in ha_monitor_init_env() on restart It also noticed 1 related pre-existing issue this patch does not introduce: - [Critical] rv: data race in __da_handle_start_run_event() [1] -- commit 6a4e0fa63b29a97676bbea1165f00da0397f7006 Author: Gabriele Monaco rv: Represent uninitialised and dying DA monitors This commit adds started and dead flags to struct da_monitor to track whether a monitor has been initialized at least once and whether its storage is being destroyed, updating HA timer setup and cleanup paths to check these flags instead of monitoring. > diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h > index 6fc5ef8142aca..807547639a42c 100644 > --- a/include/rv/da_monitor.h > +++ b/include/rv/da_monitor.h > @@ -96,6 +96,32 @@ static inline void da_monitor_reset_state(struct da_mo= nitor *da_mon) > smp_store_release(&da_mon->curr_state, model_get_initial_state()); > } > =20 > +/* > + * da_monitor_reset_init - reset a monitor and clear the startup flags > + */ > +static inline void da_monitor_reset_init(struct da_monitor *da_mon) > +{ > + WRITE_ONCE(da_mon->started, false); > + WRITE_ONCE(da_mon->dead, false); > + da_monitor_reset_state(da_mon); > +} > + > +/* > + * da_monitor_started - returns true once da_monitor_start() ran > + */ > +static inline bool da_monitor_started(struct da_monitor *da_mon) > +{ > + return READ_ONCE(da_mon->started); > +} > + > +/* > + * da_monitor_dead - returns true once the monitor storage is being dest= royed > + */ > +static inline bool da_monitor_dead(struct da_monitor *da_mon) > +{ > + return READ_ONCE(da_mon->dead); > +} > + > /* > * da_monitor_reset - reset a monitor and setting it to init state > */ > @@ -115,6 +141,7 @@ static inline void da_monitor_start(struct da_monitor= *da_mon) > { > da_mon->curr_state =3D model_get_initial_state(); > da_monitor_init_hook(da_mon); > + WRITE_ONCE(da_mon->started, true); > /* Pairs with smp_load_acquire in da_monitoring(). */ > smp_store_release(&da_mon->monitoring, 1); > } [Severity: Medium] Does da_mon->started need release-acquire ordering between da_monitor_start() and da_monitor_started()? Commit 2b9a8c27417e ("rv: Fix monitor start ordering and memory ordering for monitoring flag") paired smp_store_release(&da_mon->monitoring, 1) with smp_load_acquire(&da_mon->monitoring) so that timer initialization stores in da_monitor_init_hook() -> ha_setup_timer() are visible before another CPU observes monitoring =3D=3D 1. This patch replaces da_monitoring(da_mon) with da_monitor_started(da_mon) in ha_monitor_reset_env() and ha_handle_sched_process_exit(), but accesses da_mon->started with plain WRITE_ONCE() and READ_ONCE(). CPU0 CPU1 da_monitor_start() da_monitor_init_hook() ha_setup_timer() WRITE_ONCE(da_mon->started, 1) ha_monitor_reset_env() if (da_monitor_started(da_mon)) ha_cancel_timer(ha_mon) hrtimer_try_to_cancel() /* hrtimer->base =3D=3D NULL */ On weakly ordered architectures such as arm64, CPU1 can observe da_mon->started =3D=3D true before the stores in ha_setup_timer() are visib= le, causing ha_cancel_timer() or ha_cancel_timer_sync() to operate on an uninitialized timer and dereference a NULL hrtimer->base. Using smp_store_release(&da_mon->started, true) paired with smp_load_acquire(&da_mon->started) would preserve the ordering. [ ... ] > @@ -562,6 +593,7 @@ static inline void da_destroy_storage(da_id_type id) > =20 > if (!mon_storage) > return; > + WRITE_ONCE(mon_storage->rv.da_mon.dead, true); > da_monitor_reset_hook(&mon_storage->rv.da_mon); > hash_del_rcu(&mon_storage->node); > kfree_rcu(mon_storage, rcu); [Severity: Medium] Can an in-flight event handler that passed da_monitor_dead() before dead is set arm the timer after da_destroy_storage() (or ha_handle_sched_process_exit()) has already cancelled it? CPU0 CPU1 __da_handle_start_run_event() if (da_monitor_dead(da_mon)) da_destroy_storage() WRITE_ONCE(da_mon.dead, true) da_monitor_reset_hook() /* started =3D=3D false, skips cancel= */ hash_del_rcu(&mon_storage->node) kfree_rcu(mon_storage, rcu) da_monitor_start(da_mon) ha_setup_timer() __da_handle_event_common() ... ha_start_timer_ns() <-- timer armed after cancel The same race occurs if da_mon->started was already true and CPU0 is inside da_event() before reaching ha_setup_invariants() -> ha_start_timer_ns() when CPU1 runs da_monitor_reset_hook(). Once the RCU grace period elapses, mon_storage (or task_struct for per-task monitors) is freed while the timer remains queued, causing a use-after-free when the timer expires. [ ... ] > @@ -736,6 +768,8 @@ static inline bool __da_handle_start_event(struct da_= monitor *da_mon, > { > if (!da_monitor_enabled()) > return 0; > + if (unlikely(da_monitor_dead(da_mon))) > + return 0; > if (unlikely(!da_monitoring(da_mon))) { > da_monitor_start(da_mon); > return 0; > @@ -751,6 +785,8 @@ static inline bool __da_handle_start_run_event(struct= da_monitor *da_mon, > { > if (!da_monitor_enabled()) > return 0; > + if (unlikely(da_monitor_dead(da_mon))) > + return 0; > if (unlikely(!da_monitoring(da_mon))) > da_monitor_start(da_mon); [Severity: Critical] This problem wasn't introduced by this patch, but nothing serializes concurrent start events in __da_handle_start_run_event() or __da_handle_start_event() [1], can two CPUs still call da_monitor_start() and ha_setup_timer() concurrently on the same monitor? CPU0 CPU1 __da_handle_start_run_event() __da_handle_start_run_event() if (!da_monitoring(da_mon)) if (!da_monitoring(da_mon)) da_monitor_start() da_monitor_start() ha_monitor_init_env() ha_monitor_init_env() if (!da_monitor_started()) if (!da_monitor_started()) ha_setup_timer() ha_setup_timer() <-- corruption Both CPUs can observe !da_monitoring(da_mon) and !da_monitor_started(da_mon) before either sets started or monitoring, running timer_setup() or hrtimer_setup() concurrently on the same timer (or re-initializing an already queued timer) and corrupting timer list and debugobjects state. > diff --git a/include/rv/ha_monitor.h b/include/rv/ha_monitor.h > index 6e1c7fe5449a3..67a0d50e99bf2 100644 > --- a/include/rv/ha_monitor.h > +++ b/include/rv/ha_monitor.h > @@ -186,7 +186,8 @@ static inline void ha_monitor_init_env(struct da_moni= tor *da_mon) > struct ha_monitor *ha_mon =3D to_ha_monitor(da_mon); > =20 > ha_monitor_reset_all_stored(ha_mon); > - ha_setup_timer(ha_mon); > + if (!da_monitor_started(da_mon)) > + ha_setup_timer(ha_mon); > } [Severity: Medium] Should ha_monitor_init_env() cancel an existing timer when da_monitor_started(da_mon) is already true? When a reset races with an event arming the timer (the scenario described in the changelog), the monitor is left with monitoring =3D=3D 0, started =3D=3D true, and a queued timer. On the next start event, da_monitor_start() -> ha_monitor_init_env() resets env_store[] to ENV_INVALID_VALUE, skips ha_setup_timer() because started is true, and sets curr_state to the initial state and monitoring =3D 1 without cancelling the lingering timer. If that timer expires before another state transition re-arms or cancels it, __ha_monitor_timer_callback() sees da_monitor_handling_event() =3D=3D true and triggers a false-positive ha_react() in the initial state. [1] https://sashiko.dev/#/bug/linux-554ed765-b9c7-486b-bf80-1a4691988567 --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201073453.5622= 6-2-gmonaco@redhat.com?part=3D1