From nobody Mon Jun 8 05:25:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA4DD2773F7 for ; Mon, 1 Jun 2026 15:38:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328340; cv=none; b=clYB3u/LFjqvjxBCdV1CiHqcgwJesaSWkM5t0jp4lg8SMSySrGqvrDY8wofM4AtT1sHgky0ate9VGwZmcSVtdx9OEB898n64O5tqcPxqTcBKLIC2G8SLfNFUijo7xUIFBhpKJawvKEfaHNow7N8oMm3TR0mB3mMhqNBc9ngU8jM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328340; c=relaxed/simple; bh=pszbcYEsq//OiYCCHsvHwEvxJOtdPCbkTA8r8kgB3pg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RVST7JtQDr2iEixWsF8HSTaxK4IgUIxO6X5vtblD0uhW1joJai+ejS+IHCTt5hS0/x9gAkBJ559jtTd5/jmfFsaZLLRLWFH1gaw7t88npNuwpD6bIF+YKmG+R9niKkQEBOJY1EI8JFAxN78yS2VKihjlTzXnFWsegcNwHRteET0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Q1OnkE1u; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Q1OnkE1u" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780328338; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DLtoEvCNWgKdSfRoCmvaPssGV6PxlVLj7JwDVUvi37Q=; b=Q1OnkE1uVBagDpR2eC5ezcq5WqJ5SXGGM4FKrb0sUNSj9oLPLbwK9IYzYEJJKkvplolGQ6 GWLq/VAia0MI5L/ib9NcD7LqA9qb/SWG1Uff6eTjKQ4ItWCGJ5j0/mijvYSqWxuzvpNToq eVkpFo00uBV7Kr08S+fTXWcrU80jLW8= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-48-kA6b2zoNOSC5rzpzr3PF3A-1; Mon, 01 Jun 2026 11:38:55 -0400 X-MC-Unique: kA6b2zoNOSC5rzpzr3PF3A-1 X-Mimecast-MFC-AGG-ID: kA6b2zoNOSC5rzpzr3PF3A_1780328334 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E412F1955F68; Mon, 1 Jun 2026 15:38:51 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 47D001801939; Mon, 1 Jun 2026 15:38:45 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , Masami Hiramatsu , linux-trace-kernel@vger.kernel.org Cc: kernel test robot , Wen Yang , Nam Cao Subject: [PATCH v4 01/13] rv: Fix __user specifier usage in extract_params() Date: Mon, 1 Jun 2026 17:38:28 +0200 Message-ID: <20260601153840.124372-2-gmonaco@redhat.com> In-Reply-To: <20260601153840.124372-1-gmonaco@redhat.com> References: <20260601153840.124372-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The attributes variables extracted from syscalls in the helper are both defined with the __user specifier although only the actual pointer to user data should be marked. Remove the __user specifier from attr. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202604150820.Ny143u6X-lkp@int= el.com Fixes: b133207deb72 ("rv: Add nomiss deadline monitor") Reviewed-by: Wen Yang Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- kernel/trace/rv/monitors/deadline/deadline.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/trace/rv/monitors/deadline/deadline.h b/kernel/trace/rv= /monitors/deadline/deadline.h index 0bbfd2543..78fca873d 100644 --- a/kernel/trace/rv/monitors/deadline/deadline.h +++ b/kernel/trace/rv/monitors/deadline/deadline.h @@ -95,7 +95,8 @@ static inline u8 get_server_type(struct task_struct *tsk) static inline int extract_params(struct pt_regs *regs, long id, pid_t *pid= _out) { size_t size =3D offsetofend(struct sched_attr, sched_flags); - struct sched_attr __user *uattr, attr; + struct sched_attr __user *uattr; + struct sched_attr attr; int new_policy =3D -1, ret; unsigned long args[6]; =20 --=20 2.54.0 From nobody Mon Jun 8 05:25:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85C093BCD2A for ; Mon, 1 Jun 2026 15:39:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328342; cv=none; b=fPXMw8irlGFt+34+xMk4k6iC6AItZIvnWPCM5hHoq8f0cCtyJS0KC9SxS11/2a4iZElFFHmu1ZKaA+twmPrgS8SzH+mtEEcp5EaRFVGwMGiQTv48q/x3CS2CrHj9C7T9bNhLQM8wX/baN/zfR90wAllMl/vL/NIzqdeAz8WOuOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328342; c=relaxed/simple; bh=WbFGxdg8pRAiP0PRsmIIP8kQxut9lC2Tuq1OEeDZX9s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HMpOe/teALd89MaIXabsCFsAU/L4xkz91nOWrwFamYh9AF3ASrgTvGFpacfeLHQW7oetG0GG87miGSk/smlATObL2b6J5LgvAkuDfIui7djZq88L3aU8jhj9TdaQHYQulSBrH4J5OBA3Bn+NOq03Ol26N9AmLhKKL8Mduf1iSv8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JX3nmeeq; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JX3nmeeq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780328340; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FSg8i2czizW8RFFdY7nRaHerqQpNGmRLCju6bAU4vgw=; b=JX3nmeeqaPYuF736jZ1g87yQCfo1EdRqTAabayUDD3I7GXELNGtlz162BOii7qS3rCGHLe noqBGeUm5cXRVYdKQkRkZ9fJmUnJuaw2hbDAfHkY/aOjXA3Kl0KjMZVkywsEB0itv8cTDD JRYKnGrDsvCkQAdoTA9uixPrxGJ9Xxg= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-b6Lyb7ILPEWvLiBa1kOdTQ-1; Mon, 01 Jun 2026 11:38:56 -0400 X-MC-Unique: b6Lyb7ILPEWvLiBa1kOdTQ-1 X-Mimecast-MFC-AGG-ID: b6Lyb7ILPEWvLiBa1kOdTQ_1780328335 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 098C318005B8; Mon, 1 Jun 2026 15:38:55 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EC5B718004A3; Mon, 1 Jun 2026 15:38:52 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , linux-trace-kernel@vger.kernel.org Cc: stable@vger.kernel.org, Wen Yang , Nam Cao Subject: [PATCH v4 02/13] rv: Reset per-task DA monitors before releasing the slot Date: Mon, 1 Jun 2026 17:38:29 +0200 Message-ID: <20260601153840.124372-3-gmonaco@redhat.com> In-Reply-To: <20260601153840.124372-1-gmonaco@redhat.com> References: <20260601153840.124372-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Per-task monitors use task_mon_slot to determine which slot in the array to use for the monitor. During destruction, this slot is returned but this is done before resetting the monitor. As a result, the monitor's reset is in fact resetting a slot that is outside of the array (RV_PER_TASK_MONITOR_INIT). Release the slot only after the reset to avoid out-of-bound memory access. Fixes: f5587d1b6ec93 ("rv: Add Hybrid Automata monitor type") Cc: stable@vger.kernel.org Suggested-by: Wen Yang Reviewed-by: Wen Yang Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- include/rv/da_monitor.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h index 39765ff6f..1459fb3df 100644 --- a/include/rv/da_monitor.h +++ b/include/rv/da_monitor.h @@ -309,10 +309,11 @@ static inline void da_monitor_destroy(void) WARN_ONCE(1, "Disabling a disabled monitor: " __stringify(MONITOR_NAME)); return; } - rv_put_task_monitor_slot(task_mon_slot); - task_mon_slot =3D RV_PER_TASK_MONITOR_INIT; =20 da_monitor_reset_all(); + + rv_put_task_monitor_slot(task_mon_slot); + task_mon_slot =3D RV_PER_TASK_MONITOR_INIT; } =20 #elif RV_MON_TYPE =3D=3D RV_MON_PER_OBJ --=20 2.54.0 From nobody Mon Jun 8 05:25:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9833E3DB324 for ; Mon, 1 Jun 2026 15:39:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328369; cv=none; b=mEpL902IdEHXkgWzSBMssat8YRgcvZBGO8ZTsgoQrWNdOAS35C/m5iH5DFBBxn7B5paXJg9JK6/ZgjLiy1P6dPxlBuHF60cQDCK/k7X0/gIr2dRqb0MVY7er8q8plncK2l8ijbllHaKbxifV9LkypmFV8C8FJQUznf5XKlSXLjQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328369; c=relaxed/simple; bh=rt7PVioEGyjExEkO42rRcqYR0XN7bI9hxdnBpOgsBk8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DS0wGr1d6yL5+Wct6dkWsHJiKmgYLJ2Rh4FlcQMse3gk0Mc1mi3nebYzaCF/g74Vhy88eyCef5ul98OpeNlAQyETcAx5uESJG5r3yZspu7kpGf00tlzmMJh4qIuoTXdExod4njsUwJF95+vxRzW7JdcDLRl8alUsFHsdRl5rk8w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WKeqaWWi; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WKeqaWWi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780328364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RjnH9+WCgsTWGHXLYxnxil3w674m5wdbB8GjhbcCqcY=; b=WKeqaWWiPm+6MA+mWLX02Da1x66t1xfg6GdTIxeQz2QlA+HM+rmt+J3vyUUwYpc/saQ/LQ j4dP/eY/jjaJLohgikBTOAv116s/SmWyXI/9bPusD/O6Ozdw1Y1e22ScujFlx1Ip34u/zn PvaUdjPf108I9mOUv27/I1EjWE0MGdY= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-664-4vM2OKLVOFmCdlVj2XVhrw-1; Mon, 01 Jun 2026 11:39:00 -0400 X-MC-Unique: 4vM2OKLVOFmCdlVj2XVhrw-1 X-Mimecast-MFC-AGG-ID: 4vM2OKLVOFmCdlVj2XVhrw_1780328338 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1B0B419560B5; Mon, 1 Jun 2026 15:38:58 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 42D8E18004A3; Mon, 1 Jun 2026 15:38:56 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , linux-trace-kernel@vger.kernel.org Cc: Wen Yang , Nam Cao Subject: [PATCH v4 03/13] rv: Prevent in-flight per-task handlers from using invalid slots Date: Mon, 1 Jun 2026 17:38:30 +0200 Message-ID: <20260601153840.124372-4-gmonaco@redhat.com> In-Reply-To: <20260601153840.124372-1-gmonaco@redhat.com> References: <20260601153840.124372-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Per-task monitors use a slot in the task_struct->rv[] array and store that locally (e.g. task_mon_slot), this slot is returned during the destruction process but currently hanlers can be running while that slot is returning and this race may lead to accessing an invalid slot. Synchronise with all in-flight tracepoint handlers using tracepoint_synchronize_unregister() before returning the slot. Fixes: f5587d1b6ec9 ("rv: Add Hybrid Automata monitor type") Fixes: a9769a5b9878 ("rv: Add support for LTL monitors") Suggested-by: Wen Yang Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- include/rv/da_monitor.h | 4 ++++ include/rv/ltl_monitor.h | 1 + 2 files changed, 5 insertions(+) diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h index 1459fb3df..cc97cc5df 100644 --- a/include/rv/da_monitor.h +++ b/include/rv/da_monitor.h @@ -302,6 +302,9 @@ static int da_monitor_init(void) =20 /* * da_monitor_destroy - return the allocated slot + * + * Wait for all in-flight handlers before returning the slot to avoid + * out-of-bound accesses. */ static inline void da_monitor_destroy(void) { @@ -310,6 +313,7 @@ static inline void da_monitor_destroy(void) return; } =20 + tracepoint_synchronize_unregister(); da_monitor_reset_all(); =20 rv_put_task_monitor_slot(task_mon_slot); diff --git a/include/rv/ltl_monitor.h b/include/rv/ltl_monitor.h index eff60cd61..38e792401 100644 --- a/include/rv/ltl_monitor.h +++ b/include/rv/ltl_monitor.h @@ -77,6 +77,7 @@ static void ltl_monitor_destroy(void) { rv_detach_trace_probe(name, task_newtask, handle_task_newtask); =20 + tracepoint_synchronize_unregister(); rv_put_task_monitor_slot(ltl_monitor_slot); ltl_monitor_slot =3D RV_PER_TASK_MONITOR_INIT; } --=20 2.54.0 From nobody Mon Jun 8 05:25:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 593553D7A07 for ; Mon, 1 Jun 2026 15:39:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328349; cv=none; b=MDzSARn8q/DrM81BdxsfneagSxoKxOXWVJEoguJRviaZxvbBavca52i8GrdPYe55kovqcX8npVzPLXFF6gINS+3sgnWQcE/3LhpDOtCX1083TMseq2WPJOgmkz2dYPwVh9jekDMM6lXPqKLJuR/ASzjux2WOyS2X0V8eCdMfNqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328349; c=relaxed/simple; bh=gFdwMA8XHL/34A2qgdCDIwi1WjLV/OpiyLi0vEnRgYk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V7pj5Z7gGi6cswMIE0gJ77y7xD4YRRC9HAF+soYpQzyotkQJC87QaDuUUzXhA3ttqQGoFmS/mtgg8USnu43aPx0ZgZPGb1EEhmrElUXvqI7H3y7W+CX8Pc/+rFSEILT2wUYnIViscsrR1mJCK+USk/Qk3CC7TLjFFr812Hmo/7E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=d5PFWiQ0; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="d5PFWiQ0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780328347; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dl6dXWp6P9btDw571JyJSrz97r1npQl76nCQ2UqxzpM=; b=d5PFWiQ0fAZgR/yFKCFbfu+Acgz+EeGVL2KFqP8Zso6SwxbvZI29u+xahEi8RTh9nuLAKs 100Bc8l5Kojsf0ODjxnOx/oIQUHrSL+/O0oFUFneO3M4QfVojMRo4Cu1yB8TuZeq4NAEBV vx+ZZkRgit2IWUs+pTEadp8FievW08s= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-391-qG2RD2zjPbech16biPHcog-1; Mon, 01 Jun 2026 11:39:02 -0400 X-MC-Unique: qG2RD2zjPbech16biPHcog-1 X-Mimecast-MFC-AGG-ID: qG2RD2zjPbech16biPHcog_1780328341 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E99F619560B9; Mon, 1 Jun 2026 15:39:00 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 240321800577; Mon, 1 Jun 2026 15:38:58 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , linux-trace-kernel@vger.kernel.org Cc: Wen Yang , Nam Cao Subject: [PATCH v4 04/13] rv: Ensure all pending probes terminate on per-obj monitor destroy Date: Mon, 1 Jun 2026 17:38:31 +0200 Message-ID: <20260601153840.124372-5-gmonaco@redhat.com> In-Reply-To: <20260601153840.124372-1-gmonaco@redhat.com> References: <20260601153840.124372-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The monitor disable/destroy sequence detaches all probes and resets the monitor's data, however it doesn't wait for pending probes. This is an issue with per-object monitors, which free the monitor storage. Call tracepoint_synchronize_unregister() to make sure to wait for all pending probes before destroying the monitor storage. Fixes: 4a24127bd6cb ("rv: Add support for per-object monitors in DA/HA") Reviewed-by: Wen Yang Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- include/rv/da_monitor.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h index cc97cc5df..a7e103654 100644 --- a/include/rv/da_monitor.h +++ b/include/rv/da_monitor.h @@ -511,9 +511,10 @@ static inline void da_monitor_destroy(void) struct hlist_node *tmp; int bkt; =20 + tracepoint_synchronize_unregister(); /* - * This function is called after all probes are disabled, we need only - * worry about concurrency against old events. + * This function is called after all probes are disabled and no longer + * pending, we can safely assume no concurrent user. */ synchronize_rcu(); hash_for_each_safe(da_monitor_ht, bkt, tmp, mon_storage, node) { --=20 2.54.0 From nobody Mon Jun 8 05:25:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C0C137BE60 for ; Mon, 1 Jun 2026 15:39:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328351; cv=none; b=BZbJDZTET7bX2K2KKhh/mxSFxgjXDtkmY8qliRHV68k5A4lVoak6Mew3nKAPomJQiUyaNtodadUymoifg3BtF18LklxW4Qz6gt3UbEt/cJ1/rpZk0tX4waf9rvwKeQO8wNX/wlHuhF5Dk4DofsJ2w80l+i+qmf924IBfFLjyxnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328351; c=relaxed/simple; bh=aMI6ETwxmmNMEq4Pf/ssYWo3dsOyX8bUrocvUz48vCM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NXlnv3DuQNup1qY7s050iJPSOJziiGigH6is7M9Bb4vDurOlOBQPTV5JeK0vHva7llaXJQm234r7kNMt8P/Dvbpyf3cKEUJKpHP3cXAx6k8UFMCqp5SPzi0PXiY1BMmiT02JJOMB81DosttLOzwR82fQmL6hUuMfd+psrlm3sds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=SVJnFF8s; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SVJnFF8s" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780328349; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3TbSgf7lkZ2g4yFD6sbp+32F0/NjiAQOgCDqaL4CgCU=; b=SVJnFF8sGP++zpaLGB5f8R/WgqrB1YPLZlPLyOUaKiZb5PiIWRBDhVNlfn+P5YYVbZ5GLY x7FaNyCWK0UbhEsHow2iGiTWJ2APiiNBEberrNGDwbDLsmBLer1UcycmFfLW9ELdRB63if PCEFPTUU42DQUH+q5PWsJct58oenZaw= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-42-VwEkJ4wQMs-5OCySIk01Aw-1; Mon, 01 Jun 2026 11:39:06 -0400 X-MC-Unique: VwEkJ4wQMs-5OCySIk01Aw-1 X-Mimecast-MFC-AGG-ID: VwEkJ4wQMs-5OCySIk01Aw_1780328343 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B1AEF1955F22; Mon, 1 Jun 2026 15:39:03 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0168D18004A3; Mon, 1 Jun 2026 15:39:01 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , linux-trace-kernel@vger.kernel.org Cc: Wen Yang , Nam Cao Subject: [PATCH v4 05/13] rv: Fix monitor start ordering and memory ordering for monitoring flag Date: Mon, 1 Jun 2026 17:38:32 +0200 Message-ID: <20260601153840.124372-6-gmonaco@redhat.com> In-Reply-To: <20260601153840.124372-1-gmonaco@redhat.com> References: <20260601153840.124372-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" From: Wen Yang da_monitor_start() set monitoring=3D1 before calling da_monitor_init_hook(), may racing with the sched_switch handler: da_monitor_start() sched_switch handler ------------------------- --------------------------------- da_mon->monitoring =3D 1; if (da_monitoring(da_mon)) /* true */ ha_start_timer_ns(...); /* hrtimer->base =3D=3D NULL, crash = */ da_monitor_init_hook(da_mon); /* hrtimer_setup() sets base */ Fix the ordering and pair with release/acquire semantics: da_monitor_init_hook(da_mon); smp_store_release(&da_mon->monitoring, 1); /* da_monitor_start() */ return smp_load_acquire(&da_mon->monitoring); /* da_monitoring() */ On ARM64 a plain STR + LDR does not form a release-acquire pair, so the load can observe monitoring=3D1 while hrtimer->base is still NULL. The plain accesses are also data races under KCSAN. Use WRITE_ONCE for the monitoring=3D0 store in da_monitor_reset() to cover the reset path. Fixes: 792575348ff7 ("rv/include: Add deterministic automata monitor defini= tion via C macros") Signed-off-by: Wen Yang Reviewed-by: Gabriele Monaco Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- include/rv/da_monitor.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h index a7e103654..60dc39f26 100644 --- a/include/rv/da_monitor.h +++ b/include/rv/da_monitor.h @@ -82,7 +82,7 @@ static void react(enum states curr_state, enum events eve= nt) static inline void da_monitor_reset(struct da_monitor *da_mon) { da_monitor_reset_hook(da_mon); - da_mon->monitoring =3D 0; + WRITE_ONCE(da_mon->monitoring, 0); da_mon->curr_state =3D model_get_initial_state(); } =20 @@ -95,8 +95,9 @@ static inline void da_monitor_reset(struct da_monitor *da= _mon) static inline void da_monitor_start(struct da_monitor *da_mon) { da_mon->curr_state =3D model_get_initial_state(); - da_mon->monitoring =3D 1; da_monitor_init_hook(da_mon); + /* Pairs with smp_load_acquire in da_monitoring(). */ + smp_store_release(&da_mon->monitoring, 1); } =20 /* @@ -104,7 +105,8 @@ static inline void da_monitor_start(struct da_monitor *= da_mon) */ static inline bool da_monitoring(struct da_monitor *da_mon) { - return da_mon->monitoring; + /* Pairs with smp_store_release in da_monitor_start(). */ + return smp_load_acquire(&da_mon->monitoring); } =20 /* --=20 2.54.0 From nobody Mon Jun 8 05:25:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0F0C3DC4B6 for ; Mon, 1 Jun 2026 15:39:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328354; cv=none; b=eRo+VmCsacpjova1w4g/oHYIDm9YSSoZtpHNFHeJgy2EyYfR1vXshoLsfSsk7g2HrmQ7wNmB/SNviz7K1k99OkO4vPDzlLs6vQwPF/VCZXZ0W411AYlvN56ldYikhsID8QusjHfWOvKH803ZyU6l/4GF0Uoe7HsLe8V/Sf0E4to= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328354; c=relaxed/simple; bh=ILYQxoYncXSHvrIje0mVV0SNGbPlgaCUb0twdOMzYmg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hEohDWbsmjs7T5T3Q9lfPNVzkHNJq9bEL3OM+XHM2kKMkgFapc4ZMo93/w6ArHHzTuWd+eUkvO6KgagvSIYkDLVZ3ixbcbAHeBAPlO5mYKpaIey6bqlKSBAAJ4Rqa1fsjTSw7g/VmFmvlipjqsA0UzO8g/F6jTZRtcqeEl327EI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TXLwet1f; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TXLwet1f" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780328352; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YGM4KiSQXSjNQvu4sU9x9xm/FLK19+v8c0rWHk9XwsY=; b=TXLwet1fagbSIaly9mUBjjG7L4KutFJILc+hWrmgJWdoYCnh4+edxVFmyzOO9DsI/SVwbq kYSJxJ1Rdc4S3t8rDkLetehNoWg8i9xCwy/qZpTy/zeJN1bcLjkPPvpmyhgLuhq3JoP/vc 7KEXcjsN9iQZggxYosczDWk3okxDg4g= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-213-GyDohIjQOnuuzF1wTKhdZA-1; Mon, 01 Jun 2026 11:39:09 -0400 X-MC-Unique: GyDohIjQOnuuzF1wTKhdZA-1 X-Mimecast-MFC-AGG-ID: GyDohIjQOnuuzF1wTKhdZA_1780328347 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C7D4C19560AD; Mon, 1 Jun 2026 15:39:06 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E70BC18004A3; Mon, 1 Jun 2026 15:39:04 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , linux-trace-kernel@vger.kernel.org Cc: Wen Yang , Nam Cao Subject: [PATCH v4 06/13] rv: Do not rely on clean monitor when initialising HA Date: Mon, 1 Jun 2026 17:38:33 +0200 Message-ID: <20260601153840.124372-7-gmonaco@redhat.com> In-Reply-To: <20260601153840.124372-1-gmonaco@redhat.com> References: <20260601153840.124372-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Hybrid Automata monitors hook into the DA implementation when doing da_monitor_reset(). This function is called both on initialisation and teardown, HA monitors try to cancel a timer only when it's initialised relying on the da_mon->monitoring flag. This flag could however be corrupted during initialisation. This happens for instance on per-task monitors that share the same storage with different type of monitors like LTL or in case of races during a previous teardown. Stop relying on the monitoring flag during initialisation, assume that can have any value, so use a separate da_reset_state() skiping timer cancellation. New monitors (e.g. new tasks) are always zero-initialised so it is safe to rely on the monitoring flag for those. Reported-by: Wen Yang Closes: https://lore.kernel.org/lkml/d02c656aada7d071f083460a5c9a454363669b= 61.1778522945.git.wen.yang@linux.dev Suggested-by: Nam Cao Fixes: f5587d1b6ec9 ("rv: Add Hybrid Automata monitor type") Reviewed-by: Wen Yang Signed-off-by: Gabriele Monaco --- include/rv/da_monitor.h | 91 +++++++++++++++++++++++++++++++++-------- include/rv/ha_monitor.h | 2 +- 2 files changed, 76 insertions(+), 17 deletions(-) diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h index 60dc39f26..ec9bc88bd 100644 --- a/include/rv/da_monitor.h +++ b/include/rv/da_monitor.h @@ -76,14 +76,22 @@ static void react(enum states curr_state, enum events e= vent) model_get_state_name(curr_state)); } =20 +/* + * da_monitor_reset_state - reset a monitor and setting it to init state + */ +static inline void da_monitor_reset_state(struct da_monitor *da_mon) +{ + WRITE_ONCE(da_mon->monitoring, 0); + da_mon->curr_state =3D model_get_initial_state(); +} + /* * da_monitor_reset - reset a monitor and setting it to init state */ static inline void da_monitor_reset(struct da_monitor *da_mon) { da_monitor_reset_hook(da_mon); - WRITE_ONCE(da_mon->monitoring, 0); - da_mon->curr_state =3D model_get_initial_state(); + da_monitor_reset_state(da_mon); } =20 /* @@ -158,12 +166,28 @@ static struct da_monitor *da_get_monitor(void) return &DA_MON_NAME; } =20 +/* + * __da_monitor_reset_all - reset the single monitor + */ +static void __da_monitor_reset_all(void (*reset)(struct da_monitor *)) +{ + reset(da_get_monitor()); +} + /* * da_monitor_reset_all - reset the single monitor */ static void da_monitor_reset_all(void) { - da_monitor_reset(da_get_monitor()); + __da_monitor_reset_all(da_monitor_reset); +} + +/* + * da_monitor_reset_state_all - reset the single monitor + */ +static inline void da_monitor_reset_state_all(void) +{ + __da_monitor_reset_all(da_monitor_reset_state); } =20 /* @@ -171,7 +195,7 @@ static void da_monitor_reset_all(void) */ static inline int da_monitor_init(void) { - da_monitor_reset_all(); + da_monitor_reset_state_all(); return 0; } =20 @@ -202,25 +226,41 @@ static struct da_monitor *da_get_monitor(void) } =20 /* - * da_monitor_reset_all - reset all CPUs' monitor + * __da_monitor_reset_all - reset all CPUs' monitor */ -static void da_monitor_reset_all(void) +static void __da_monitor_reset_all(void (*reset)(struct da_monitor *)) { struct da_monitor *da_mon; int cpu; =20 for_each_cpu(cpu, cpu_online_mask) { da_mon =3D per_cpu_ptr(&DA_MON_NAME, cpu); - da_monitor_reset(da_mon); + reset(da_mon); } } =20 +/* + * da_monitor_reset_all - reset all CPUs' monitor + */ +static void da_monitor_reset_all(void) +{ + __da_monitor_reset_all(da_monitor_reset); +} + +/* + * da_monitor_reset_state_all - reset all CPUs' monitor + */ +static inline void da_monitor_reset_state_all(void) +{ + __da_monitor_reset_all(da_monitor_reset_state); +} + /* * da_monitor_init - initialize all CPUs' monitor */ static inline int da_monitor_init(void) { - da_monitor_reset_all(); + da_monitor_reset_state_all(); return 0; } =20 @@ -269,19 +309,29 @@ static inline da_id_type da_get_id(struct da_monitor = *da_mon) return da_get_target(da_mon)->pid; } =20 -static void da_monitor_reset_all(void) +static void __da_monitor_reset_all(void (*reset)(struct da_monitor *)) { struct task_struct *g, *p; int cpu; =20 read_lock(&tasklist_lock); for_each_process_thread(g, p) - da_monitor_reset(da_get_monitor(p)); + reset(da_get_monitor(p)); for_each_present_cpu(cpu) - da_monitor_reset(da_get_monitor(idle_task(cpu))); + reset(da_get_monitor(idle_task(cpu))); read_unlock(&tasklist_lock); } =20 +static void da_monitor_reset_all(void) +{ + __da_monitor_reset_all(da_monitor_reset); +} + +static inline void da_monitor_reset_state_all(void) +{ + __da_monitor_reset_all(da_monitor_reset_state); +} + /* * da_monitor_init - initialize the per-task monitor * @@ -298,7 +348,7 @@ static int da_monitor_init(void) =20 task_mon_slot =3D slot; =20 - da_monitor_reset_all(); + da_monitor_reset_state_all(); return 0; } =20 @@ -490,15 +540,24 @@ static inline void da_destroy_storage(da_id_type id) kfree_rcu(mon_storage, rcu); } =20 -static void da_monitor_reset_all(void) +static void __da_monitor_reset_all(void (*reset)(struct da_monitor *)) { struct da_monitor_storage *mon_storage; int bkt; =20 - rcu_read_lock(); + guard(rcu)(); hash_for_each_rcu(da_monitor_ht, bkt, mon_storage, node) - da_monitor_reset(&mon_storage->rv.da_mon); - rcu_read_unlock(); + reset(&mon_storage->rv.da_mon); +} + +static void da_monitor_reset_all(void) +{ + __da_monitor_reset_all(da_monitor_reset); +} + +static inline void da_monitor_reset_state_all(void) +{ + __da_monitor_reset_all(da_monitor_reset_state); } =20 static inline int da_monitor_init(void) diff --git a/include/rv/ha_monitor.h b/include/rv/ha_monitor.h index d59507e8c..bd8705556 100644 --- a/include/rv/ha_monitor.h +++ b/include/rv/ha_monitor.h @@ -153,12 +153,12 @@ static inline void ha_monitor_init_env(struct da_moni= tor *da_mon) * Called from a hook in the DA reset functions, it supplies the da_mon * corresponding to the current ha_mon. * Not all hybrid automata require the timer, still clear it for simplicit= y. + * Monitors that never started have their timer uninitialized, do not stop= those. */ static inline void ha_monitor_reset_env(struct da_monitor *da_mon) { struct ha_monitor *ha_mon =3D to_ha_monitor(da_mon); =20 - /* Initialisation resets the monitor before initialising the timer */ if (likely(da_monitoring(da_mon))) ha_cancel_timer(ha_mon); } --=20 2.54.0 From nobody Mon Jun 8 05:25:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B89F3DC877 for ; Mon, 1 Jun 2026 15:39:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328358; cv=none; b=S3DVij8wSevg0qVK4Nu/gZ+Iv3vitFJdGKWEzuPH7PCfn8qOKX9GeNwpr2HtqriN7WgdnApP44h9WqX3i2awvGtXEUX0j/Xt1gDeRAxky1s1K6yv8mUmaWJty1pBb4pda3OZkXeIN04g6GaVXLAoSyHtv0JOYcoCo5kzACFoYFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328358; c=relaxed/simple; bh=XFVpsirXpCVBHRwNRxyYJEu2HnWVHve4mygjh5Big6c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k9yOIjRCJGzcpBcBL4N203xOm9zkHW8hUF1+xjfQshEWV63g1r5sGspeheJCMrbibOE4AD26HneQDKYiAIf6Yt121ypNQHDQAILyO8AYLllSlHraJYmIJbTIdWcGZ/P1k95XB4ikEtcMuAQusgUmjTkM+mdttCv4OQR6ICK+mCU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=iA6oidbA; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iA6oidbA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780328355; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VyplG6HhVT1kgDw8Zq49+VYiEBBmCwKrGqUoIr49MPc=; b=iA6oidbAaCCUWrW7bAMX1uZLzqMBWaDB4JoUUhShycSccBsMlg1967WyGcg3MZ4omzoVLB oPlyPfzmrSQhL26J7JdcY+mhpVImVLXL/oUpuW2OzNLD29hMrtS6e1b/OlMJPV4Kooo90g ppgLaisDKcIK4FZJxPfZkDKwg/C5aME= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-524-GT4jrPNANVOaX6iWxUzzGg-1; Mon, 01 Jun 2026 11:39:12 -0400 X-MC-Unique: GT4jrPNANVOaX6iWxUzzGg-1 X-Mimecast-MFC-AGG-ID: GT4jrPNANVOaX6iWxUzzGg_1780328351 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3273319560BB; Mon, 1 Jun 2026 15:39:11 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 02623180075B; Mon, 1 Jun 2026 15:39:08 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , Masami Hiramatsu , linux-trace-kernel@vger.kernel.org Cc: Nam Cao , Wen Yang Subject: [PATCH v4 07/13] rv: Add automatic cleanup handlers for per-task HA monitors Date: Mon, 1 Jun 2026 17:38:34 +0200 Message-ID: <20260601153840.124372-8-gmonaco@redhat.com> In-Reply-To: <20260601153840.124372-1-gmonaco@redhat.com> References: <20260601153840.124372-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Hybrid automata monitors may start timers, depending on the model, these may remain active on an exiting task and cause false positives or even access freed memory. Add an enable/disable hook in the HA code, currently only populated by the per-task handler for registration and deregistration. This hooks to the sched_process_exit event and ensures the timer is stopped for every exiting task. The handler is enabled automatically but may be disabled, for instance if the monitor uses the event for another purpose (but should still manually ensure timers are stopped). Fixes: f5587d1b6ec9 ("rv: Add Hybrid Automata monitor type") Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- include/rv/ha_monitor.h | 60 +++++++++++++++++++ kernel/trace/rv/monitors/nomiss/nomiss.c | 4 +- kernel/trace/rv/monitors/opid/opid.c | 4 +- kernel/trace/rv/monitors/stall/stall.c | 4 +- .../rvgen/rvgen/templates/dot2k/main.c | 4 +- 5 files changed, 68 insertions(+), 8 deletions(-) diff --git a/include/rv/ha_monitor.h b/include/rv/ha_monitor.h index bd8705556..4002b5247 100644 --- a/include/rv/ha_monitor.h +++ b/include/rv/ha_monitor.h @@ -28,6 +28,7 @@ static inline void ha_monitor_init_env(struct da_monitor = *da_mon); static inline void ha_monitor_reset_env(struct da_monitor *da_mon); static inline void ha_setup_timer(struct ha_monitor *ha_mon); static inline bool ha_cancel_timer(struct ha_monitor *ha_mon); +static inline void ha_cancel_timer_sync(struct ha_monitor *ha_mon); static bool ha_monitor_handle_constraint(struct da_monitor *da_mon, enum states curr_state, enum events event, @@ -37,6 +38,26 @@ static bool ha_monitor_handle_constraint(struct da_monit= or *da_mon, #define da_monitor_init_hook ha_monitor_init_env #define da_monitor_reset_hook ha_monitor_reset_env =20 +#if !defined(HA_SKIP_AUTO_CLEANUP) && RV_MON_TYPE =3D=3D RV_MON_PER_TASK +/* + * Automatic cleanup handlers for per-task HA monitors, only skip if you k= now + * what you are doing (e.g. you want to implement cleanup manually in anot= her + * handler doing more things). + */ +static void ha_handle_sched_process_exit(void *data, struct task_struct *p, + bool group_dead); + +#define ha_monitor_enable_hook() = \ + rv_attach_trace_probe(__stringify(MONITOR_NAME), sched_process_exit, \ + ha_handle_sched_process_exit) +#define ha_monitor_disable_hook() = \ + rv_detach_trace_probe(__stringify(MONITOR_NAME), sched_process_exit, \ + ha_handle_sched_process_exit) +#else +#define ha_monitor_enable_hook() ((void)0) +#define ha_monitor_disable_hook() ((void)0) +#endif + #include #include =20 @@ -115,6 +136,22 @@ static enum hrtimer_restart ha_monitor_timer_callback(= struct hrtimer *hrtimer); #define ha_get_ns() 0 #endif /* HA_CLK_NS */ =20 +static int ha_monitor_init(void) +{ + int ret; + + ret =3D da_monitor_init(); + if (ret =3D=3D 0) + ha_monitor_enable_hook(); + return ret; +} + +static void ha_monitor_destroy(void) +{ + ha_monitor_disable_hook(); + da_monitor_destroy(); +} + /* Should be supplied by the monitor */ static u64 ha_get_env(struct ha_monitor *ha_mon, enum envs env, u64 time_n= s); static bool ha_verify_constraint(struct ha_monitor *ha_mon, @@ -200,6 +237,20 @@ static inline void ha_trace_error_env(struct ha_monito= r *ha_mon, { CONCATENATE(trace_error_env_, MONITOR_NAME)(id, curr_state, event, env); } + +#if !defined(HA_SKIP_AUTO_CLEANUP) && RV_MON_TYPE =3D=3D RV_MON_PER_TASK +static void ha_handle_sched_process_exit(void *data, struct task_struct *p, + bool group_dead) +{ + struct da_monitor *da_mon =3D da_get_monitor(p); + + if (likely(da_monitoring(da_mon))) { + da_monitor_reset(da_mon); + ha_cancel_timer_sync(to_ha_monitor(da_mon)); + } +} +#endif + #endif /* RV_MON_TYPE */ =20 /* @@ -412,6 +463,10 @@ static inline bool ha_cancel_timer(struct ha_monitor *= ha_mon) { return timer_delete(&ha_mon->timer); } +static inline void ha_cancel_timer_sync(struct ha_monitor *ha_mon) +{ + timer_delete_sync(&ha_mon->timer); +} #elif HA_TIMER_TYPE =3D=3D HA_TIMER_HRTIMER /* * Helper functions to handle the monitor timer. @@ -463,6 +518,10 @@ static inline bool ha_cancel_timer(struct ha_monitor *= ha_mon) { return hrtimer_try_to_cancel(&ha_mon->hrtimer) =3D=3D 1; } +static inline void ha_cancel_timer_sync(struct ha_monitor *ha_mon) +{ + hrtimer_cancel(&ha_mon->hrtimer); +} #else /* HA_TIMER_NONE */ /* * Start function is intentionally not defined, monitors using timers must @@ -473,6 +532,7 @@ static inline bool ha_cancel_timer(struct ha_monitor *h= a_mon) { return false; } +static inline void ha_cancel_timer_sync(struct ha_monitor *ha_mon) { } #endif =20 #endif diff --git a/kernel/trace/rv/monitors/nomiss/nomiss.c b/kernel/trace/rv/mon= itors/nomiss/nomiss.c index 31f90f363..8ead8783c 100644 --- a/kernel/trace/rv/monitors/nomiss/nomiss.c +++ b/kernel/trace/rv/monitors/nomiss/nomiss.c @@ -227,7 +227,7 @@ static int enable_nomiss(void) { int retval; =20 - retval =3D da_monitor_init(); + retval =3D ha_monitor_init(); if (retval) return retval; =20 @@ -263,7 +263,7 @@ static void disable_nomiss(void) rv_detach_trace_probe("nomiss", sched_switch, handle_sched_switch); rv_detach_trace_probe("nomiss", sched_wakeup, handle_sched_wakeup); =20 - da_monitor_destroy(); + ha_monitor_destroy(); } =20 static struct rv_monitor rv_this =3D { diff --git a/kernel/trace/rv/monitors/opid/opid.c b/kernel/trace/rv/monitor= s/opid/opid.c index 4594c7c46..2922318c6 100644 --- a/kernel/trace/rv/monitors/opid/opid.c +++ b/kernel/trace/rv/monitors/opid/opid.c @@ -73,7 +73,7 @@ static int enable_opid(void) { int retval; =20 - retval =3D da_monitor_init(); + retval =3D ha_monitor_init(); if (retval) return retval; =20 @@ -90,7 +90,7 @@ static void disable_opid(void) rv_detach_trace_probe("opid", sched_set_need_resched_tp, handle_sched_nee= d_resched); rv_detach_trace_probe("opid", sched_waking, handle_sched_waking); =20 - da_monitor_destroy(); + ha_monitor_destroy(); } =20 /* diff --git a/kernel/trace/rv/monitors/stall/stall.c b/kernel/trace/rv/monit= ors/stall/stall.c index 9ccfda6b0..3c38fb1a0 100644 --- a/kernel/trace/rv/monitors/stall/stall.c +++ b/kernel/trace/rv/monitors/stall/stall.c @@ -103,7 +103,7 @@ static int enable_stall(void) { int retval; =20 - retval =3D da_monitor_init(); + retval =3D ha_monitor_init(); if (retval) return retval; =20 @@ -120,7 +120,7 @@ static void disable_stall(void) rv_detach_trace_probe("stall", sched_switch, handle_sched_switch); rv_detach_trace_probe("stall", sched_wakeup, handle_sched_wakeup); =20 - da_monitor_destroy(); + ha_monitor_destroy(); } =20 static struct rv_monitor rv_this =3D { diff --git a/tools/verification/rvgen/rvgen/templates/dot2k/main.c b/tools/= verification/rvgen/rvgen/templates/dot2k/main.c index bf0999f66..889446760 100644 --- a/tools/verification/rvgen/rvgen/templates/dot2k/main.c +++ b/tools/verification/rvgen/rvgen/templates/dot2k/main.c @@ -35,7 +35,7 @@ static int enable_%%MODEL_NAME%%(void) { int retval; =20 - retval =3D da_monitor_init(); + retval =3D %%MONITOR_CLASS%%_monitor_init(); if (retval) return retval; =20 @@ -50,7 +50,7 @@ static void disable_%%MODEL_NAME%%(void) =20 %%TRACEPOINT_DETACH%% =20 - da_monitor_destroy(); + %%MONITOR_CLASS%%_monitor_destroy(); } =20 /* --=20 2.54.0 From nobody Mon Jun 8 05:25:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 998733DCD9B for ; Mon, 1 Jun 2026 15:39:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328362; cv=none; b=WxmTkTaZbv1MEbixkFHAJ1K16gZ5jR7qCiYq3bW77sAB5XCki4bpdWRdYN29VZmMhKRkroquR5SU2B7gVQbDNRoliUd4a806jamHwpSy8yhVLiKjL1CqA3ff0uZaKhx2KTSV/P5xVz85EWUrUTZRTBYAs2x56XEjfyH/LPak9QY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328362; c=relaxed/simple; bh=PMlgRCYhyNtdh+bETPsY60G3qbAEez425Ow7MttAeCY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uB6ehpYcpY241F/8ubcWXD9Cm0oH58kX2dSeBiMN5b/52KfS9eQIleRPjzcAl5/S581xanVaZm4Q7DwVpbBbGM9A7IJf9NrAfCYUsLoMwFWeoylIjlBIFlHA/jTyBP9Yd6nn2m2vdOyj9vZow5xZ5s6F77MqzUZcLuKrQ8uJYv4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=gTPxmf/K; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gTPxmf/K" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780328358; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ksjWZwFOwjAtg9cSIKj8AwnZ/7m3CqPw5YL+YlR1pw4=; b=gTPxmf/KhzSYSY0AxiBWp4OpxJiZIajXSW8UuA6M3AyCBTzmOKczpQdKw7M3XIqAXJpT5+ TfabhmAVaw7Whi/2yROiNiiQ1ob8aB9lfSOjs5wSthHvuAlEzxsC96/XhxehO8jy2cpqRu DHFQyrTi6XetDC3IXnP+ewyuuFabQ1w= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-199-e4Hxa7AAMuiMiHitquvvcQ-1; Mon, 01 Jun 2026 11:39:15 -0400 X-MC-Unique: e4Hxa7AAMuiMiHitquvvcQ-1 X-Mimecast-MFC-AGG-ID: e4Hxa7AAMuiMiHitquvvcQ_1780328354 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 27ED419560BA; Mon, 1 Jun 2026 15:39:14 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6B1501800577; Mon, 1 Jun 2026 15:39:12 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , linux-trace-kernel@vger.kernel.org Cc: Nam Cao , Wen Yang Subject: [PATCH v4 08/13] rv: Ensure synchronous cleanup for HA monitors Date: Mon, 1 Jun 2026 17:38:35 +0200 Message-ID: <20260601153840.124372-9-gmonaco@redhat.com> In-Reply-To: <20260601153840.124372-1-gmonaco@redhat.com> References: <20260601153840.124372-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" HA monitors may start timers, all cleanup functions currently stop the timers asynchronously to avoid sleeping in the wrong context. Nothing makes sure running callbacks terminate on cleanup. Run the entire HA timer callback in an RCU read-side critical section, this way we can simply synchronize_rcu() with any pending timer and are sure any cleanup using kfree_rcu() runs after callbacks terminated. Additionally make sure any unlikely callback running late won't run any code if the monitor is marked as disabled or if destruction started. Use memory barriers to serialise with racing resets. Fixes: f5587d1b6ec9 ("rv: Add Hybrid Automata monitor type") Fixes: 4a24127bd6cb ("rv: Add support for per-object monitors in DA/HA") Signed-off-by: Gabriele Monaco --- include/rv/da_monitor.h | 19 ++++++++++++++++--- include/rv/ha_monitor.h | 29 ++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h index ec9bc88bd..1f440c781 100644 --- a/include/rv/da_monitor.h +++ b/include/rv/da_monitor.h @@ -57,6 +57,15 @@ static struct rv_monitor rv_this; #define da_monitor_reset_hook(da_mon) #endif =20 +/* + * Hook to allow the implementation of hybrid automata: define it with a + * function that waits for the termination of all monitors background + * activities (e.g. all timers). This hook can sleep. + */ +#ifndef da_monitor_sync_hook +#define da_monitor_sync_hook() +#endif + /* * Type for the target id, default to int but can be overridden. * A long type can work as hash table key (PER_OBJ) but will be downgraded= to @@ -82,7 +91,8 @@ static void react(enum states curr_state, enum events eve= nt) static inline void da_monitor_reset_state(struct da_monitor *da_mon) { WRITE_ONCE(da_mon->monitoring, 0); - da_mon->curr_state =3D model_get_initial_state(); + /* Pair with load in __ha_monitor_timer_callback */ + smp_store_release(&da_mon->curr_state, model_get_initial_state()); } =20 /* @@ -205,6 +215,7 @@ static inline int da_monitor_init(void) static inline void da_monitor_destroy(void) { da_monitor_reset_all(); + da_monitor_sync_hook(); } =20 #elif RV_MON_TYPE =3D=3D RV_MON_PER_CPU @@ -270,6 +281,7 @@ static inline int da_monitor_init(void) static inline void da_monitor_destroy(void) { da_monitor_reset_all(); + da_monitor_sync_hook(); } =20 #elif RV_MON_TYPE =3D=3D RV_MON_PER_TASK @@ -367,6 +379,7 @@ static inline void da_monitor_destroy(void) =20 tracepoint_synchronize_unregister(); da_monitor_reset_all(); + da_monitor_sync_hook(); =20 rv_put_task_monitor_slot(task_mon_slot); task_mon_slot =3D RV_PER_TASK_MONITOR_INIT; @@ -573,13 +586,13 @@ static inline void da_monitor_destroy(void) int bkt; =20 tracepoint_synchronize_unregister(); + da_monitor_reset_all(); + da_monitor_sync_hook(); /* * This function is called after all probes are disabled and no longer * pending, we can safely assume no concurrent user. */ - synchronize_rcu(); hash_for_each_safe(da_monitor_ht, bkt, tmp, mon_storage, node) { - da_monitor_reset_hook(&mon_storage->rv.da_mon); hash_del_rcu(&mon_storage->node); kfree(mon_storage); } diff --git a/include/rv/ha_monitor.h b/include/rv/ha_monitor.h index 4002b5247..28d3c74ca 100644 --- a/include/rv/ha_monitor.h +++ b/include/rv/ha_monitor.h @@ -37,6 +37,7 @@ static bool ha_monitor_handle_constraint(struct da_monito= r *da_mon, #define da_monitor_event_hook ha_monitor_handle_constraint #define da_monitor_init_hook ha_monitor_init_env #define da_monitor_reset_hook ha_monitor_reset_env +#define da_monitor_sync_hook() synchronize_rcu() =20 #if !defined(HA_SKIP_AUTO_CLEANUP) && RV_MON_TYPE =3D=3D RV_MON_PER_TASK /* @@ -136,10 +137,13 @@ static enum hrtimer_restart ha_monitor_timer_callback= (struct hrtimer *hrtimer); #define ha_get_ns() 0 #endif /* HA_CLK_NS */ =20 +static bool ha_mon_destroying; + static int ha_monitor_init(void) { int ret; =20 + WRITE_ONCE(ha_mon_destroying, false); ret =3D da_monitor_init(); if (ret =3D=3D 0) ha_monitor_enable_hook(); @@ -148,6 +152,7 @@ static int ha_monitor_init(void) =20 static void ha_monitor_destroy(void) { + WRITE_ONCE(ha_mon_destroying, true); ha_monitor_disable_hook(); da_monitor_destroy(); } @@ -288,12 +293,30 @@ static bool ha_monitor_handle_constraint(struct da_mo= nitor *da_mon, return false; } =20 +/* + * __ha_monitor_timer_callback - generic callback representation + * + * This callback runs in an RCU read-side critical section to allow the + * destruction sequence to easily synchronize_rcu() with all pending timers + * after asynchronously disabling them. The ha_mon_destroying check ensures + * any callback entering the RCU section after synchronize_rcu() completes + * will see the flag and bail out immediately. + */ static inline void __ha_monitor_timer_callback(struct ha_monitor *ha_mon) { - enum states curr_state =3D READ_ONCE(ha_mon->da_mon.curr_state); DECLARE_SEQ_BUF(env_string, ENV_BUFFER_SIZE); - u64 time_ns =3D ha_get_ns(); - + enum states curr_state; + u64 time_ns; + + guard(rcu)(); + if (unlikely(READ_ONCE(ha_mon_destroying))) + return; + /* Ensure consistent curr_state if we race with da_monitor_reset */ + curr_state =3D smp_load_acquire(&ha_mon->da_mon.curr_state); + if (unlikely(!da_monitor_handling_event(&ha_mon->da_mon))) + return; + + time_ns =3D ha_get_ns(); ha_get_env_string(&env_string, ha_mon, time_ns); ha_react(curr_state, EVENT_NONE, env_string.buffer); ha_trace_error_env(ha_mon, model_get_state_name(curr_state), --=20 2.54.0 From nobody Mon Jun 8 05:25:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B29353DC877 for ; Mon, 1 Jun 2026 15:39:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328367; cv=none; b=cvn/4aUg9NT3/VHOIwL2K6UtL/bQZzm+OuKameBldsy//ZYlnmnUg1Dp2DTiCCrSmuULkvROSzGbD2Gh0HQRYvbMT+IMaKt2mnjgXEY6zEegGAPMt1m9GmbhSelKu9nhkYgqeY5308BaHPoi7qz0s6Gg5OXiCNHF32x7JYSyWZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328367; c=relaxed/simple; bh=g4g8Zam+hSZvn896CrlnvlPR1ryS4eqSi440uwjDUlw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DiavIbXYv7Eiw016aExNCpmQbuPRm4hUMAkVNcNKghmvvI+TXDhb16vRZveaWjS7hPyBSmOAj4VA9guEinhNg39DsMHrEKr3KPr/dgvSxt+SOHkVEHpQqPJd6fZ21zEOX8jj5lGFvSAHcPHKs2SvrnsyzBVl06uPmUW8KxMHyao= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=YVL5ZmW0; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YVL5ZmW0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780328362; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6qTDErs0Gx8rY0bmsBZBLWSpPtEJsBrp152kqGKFlZY=; b=YVL5ZmW0Mv38eJdlwDzNM5V47/XNctwtdWWAAgrbTm+TsmYy6ImvB2zxzmRroxvSdnLofA TtkO1RlT4S2Rdd/aFom8hQEtACZfMMO/gTiby2yqiDlqrZ8RtiH2lsLmhXkHdH/A9/vJq8 PWVOWuh2o61dOl61PuAXJ6RVdHS7vtw= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-540-gGF7-PLMOPOyQKNxxr07Sw-1; Mon, 01 Jun 2026 11:39:18 -0400 X-MC-Unique: gGF7-PLMOPOyQKNxxr07Sw-1 X-Mimecast-MFC-AGG-ID: gGF7-PLMOPOyQKNxxr07Sw_1780328357 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E5048195608B; Mon, 1 Jun 2026 15:39:16 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2C29B180075C; Mon, 1 Jun 2026 15:39:14 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , linux-trace-kernel@vger.kernel.org Cc: Wen Yang , Nam Cao Subject: [PATCH v4 09/13] rv: Prevent task migration while handling per-CPU events Date: Mon, 1 Jun 2026 17:38:36 +0200 Message-ID: <20260601153840.124372-10-gmonaco@redhat.com> In-Reply-To: <20260601153840.124372-1-gmonaco@redhat.com> References: <20260601153840.124372-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Tracepoint handlers are fully preemptible after a46023d5616 ("tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast"). When a per-CPU monitor handles an event, it retrieves the monitor state using a per-CPU pointer. If the event itself doesn't disable preemption, the task can migrate to a different CPU and we risk updating the wrong monitor. Mitigate this by explicitly disabling task migration before acquiring the monitor pointer. This cannot guarantee the monitor runs on the correct CPU but reduces the race condition window and prevents warnings. Reviewed-by: Wen Yang Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- include/rv/da_monitor.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h index 1f440c781..34b8fba9e 100644 --- a/include/rv/da_monitor.h +++ b/include/rv/da_monitor.h @@ -218,6 +218,10 @@ static inline void da_monitor_destroy(void) da_monitor_sync_hook(); } =20 +#ifndef da_implicit_guard +#define da_implicit_guard() +#endif + #elif RV_MON_TYPE =3D=3D RV_MON_PER_CPU /* * Functions to define, init and get a per-cpu monitor. @@ -284,6 +288,10 @@ static inline void da_monitor_destroy(void) da_monitor_sync_hook(); } =20 +#ifndef da_implicit_guard +#define da_implicit_guard() guard(migrate)() +#endif + #elif RV_MON_TYPE =3D=3D RV_MON_PER_TASK /* * Functions to define, init and get a per-task monitor. @@ -756,6 +764,7 @@ static inline bool __da_handle_start_run_event(struct d= a_monitor *da_mon, */ static inline void da_handle_event(enum events event) { + da_implicit_guard(); __da_handle_event(da_get_monitor(), event, 0); } =20 @@ -771,6 +780,7 @@ static inline void da_handle_event(enum events event) */ static inline bool da_handle_start_event(enum events event) { + da_implicit_guard(); return __da_handle_start_event(da_get_monitor(), event, 0); } =20 @@ -782,6 +792,7 @@ static inline bool da_handle_start_event(enum events ev= ent) */ static inline bool da_handle_start_run_event(enum events event) { + da_implicit_guard(); return __da_handle_start_run_event(da_get_monitor(), event, 0); } =20 --=20 2.54.0 From nobody Mon Jun 8 05:25:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD38E3DD526 for ; Mon, 1 Jun 2026 15:39:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328373; cv=none; b=m6VLYS0EULmv+/t9QqwObt0OeyDm8H3NEnyd06JRm3vzExkd3ChEgjpWMU4ssfhKS02y5I1t91W5DXcV8wxAgZEtYqTBBr0ev3I0BwsvNLk59NmxvbtcVEXPQNai5VcxmQdYJSe4HXDSB6dClF+S9O3/9kqVl/AzbNy5mzV84Mw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328373; c=relaxed/simple; bh=oGYDlULfgOSuXW+qyzO3rfB4JOQYXfdXeTf6EYeNE/8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qrp+g2ELYVWRczicwEOxPie4hhUpeA4dcrtwQn3xe0fzYw0eQuQdeCMdJEVw/2pQ+bPXDr98B+wFgtyiTon1GfWvquPrm0gnj6pEJr2mEWR17HyzfsnvHPpR9e1HJaLzU/cgZ3sUH9EPc/K5teEuSkHpNcs/Vq+hv03esjeGn3Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=h+KsG5c3; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="h+KsG5c3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780328367; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6vCX6wnnxLuIxViqLQBjsL4zOCYCEBSGVIqh4zvajm0=; b=h+KsG5c3C5Jxz15Zz8XC6/hqfxbcuMLs7cD0CnWgzs4em0v09jkMPD4z73JqDdRiDiiLQr s6f1YfrsKa2HyKiRfB0yvTyqx64npHkT2eM0pgKt8cSDTwb2YdD8agnJQC2OjbOPeGBJLV 0d8HbTl1m6tVJfuLNnan1mbSE9mL3Xs= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-624-wM68WgJ2P7iU8LVTyrNoeA-1; Mon, 01 Jun 2026 11:39:23 -0400 X-MC-Unique: wM68WgJ2P7iU8LVTyrNoeA-1 X-Mimecast-MFC-AGG-ID: wM68WgJ2P7iU8LVTyrNoeA_1780328360 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F3395195605C; Mon, 1 Jun 2026 15:39:19 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E7AAE18004A3; Mon, 1 Jun 2026 15:39:17 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , Masami Hiramatsu , linux-trace-kernel@vger.kernel.org Cc: Nam Cao , Wen Yang Subject: [PATCH v4 10/13] rv: Use 0 to check preemption enabled in opid Date: Mon, 1 Jun 2026 17:38:37 +0200 Message-ID: <20260601153840.124372-11-gmonaco@redhat.com> In-Reply-To: <20260601153840.124372-1-gmonaco@redhat.com> References: <20260601153840.124372-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Tracepoint handlers no longer run with preemption disabled by default since a46023d5616 ("tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast"), the opid monitor should now count 1 in the preemption count as preemption disabled. Change the rule for preempt_off to preempt > 0. Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- kernel/trace/rv/monitors/opid/opid.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/kernel/trace/rv/monitors/opid/opid.c b/kernel/trace/rv/monitor= s/opid/opid.c index 2922318c6..3b6a85e81 100644 --- a/kernel/trace/rv/monitors/opid/opid.c +++ b/kernel/trace/rv/monitors/opid/opid.c @@ -22,14 +22,8 @@ static u64 ha_get_env(struct ha_monitor *ha_mon, enum en= vs_opid env, u64 time_ns if (env =3D=3D irq_off_opid) return irqs_disabled(); else if (env =3D=3D preempt_off_opid) { - /* - * If CONFIG_PREEMPTION is enabled, then the tracepoint itself disables - * preemption (adding one to the preempt_count). Since we are - * interested in the preempt_count at the time the tracepoint was - * hit, we consider 1 as still enabled. - */ if (IS_ENABLED(CONFIG_PREEMPTION)) - return (preempt_count() & PREEMPT_MASK) > 1; + return (preempt_count() & PREEMPT_MASK) > 0; return true; } return ENV_INVALID_VALUE; --=20 2.54.0 From nobody Mon Jun 8 05:25:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EE3C3DD525 for ; Mon, 1 Jun 2026 15:39:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328376; cv=none; b=c0IM7NUOqw4MlWr1JZFKGbawsJnFW6FpAtHn4pGEZW631m4xXQShcP05a06ezXTpV1Uh9VQpSSgNhrIO9J+YqLGlYlD05Kp4bAHfwo4Lzgm4fiJG0ca7aoKtH0wwlFh6qwSdXNjpAlhJdX6e+qFI6CggcM303jDhYkbFcIuViqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328376; c=relaxed/simple; bh=r4rXFUN/7fBBSqKhfTbSPIeVBvqATlTpF9F/PA2nILo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qn9L+bXmKimG+lFSpqjq2UPj3doiHH5tD7DWMhjfwQzlPqYvd0EYsFpYDOkBYV0W9P2Z672iXEEGHP+KavRFQPOP+nx44MOJToR+UykhQaU7fGiFfmBXiybUmiKG/Rh+HtdQQlEutzb90A9safUyxlwyznTQQs21CW+5U6ml2Jg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=b/HMDJYH; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="b/HMDJYH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780328369; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z0Ewo6XUmfgoCK0Y2qNL9TNtZvTMryM4nesa/i9XQs8=; b=b/HMDJYHDDiLab4blWxAA+btIPLWSHDkXw7ELqj6ytGGZDiX9KykBWkt15UBkvZ0GS7MKO vbUrQ0blek2HXBgw7MfsLjOnDZ6pH/UHF4vDli3XSBpmoKssTkHhzqjyL+C/S9nMgYP99f s0o7aQVFG5h5kqPfPET1X4Mp6Kk4ybo= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-29-LMmJ_sO8MlyFKmF2twf76A-1; Mon, 01 Jun 2026 11:39:23 -0400 X-MC-Unique: LMmJ_sO8MlyFKmF2twf76A-1 X-Mimecast-MFC-AGG-ID: LMmJ_sO8MlyFKmF2twf76A_1780328362 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BD1C71956058; Mon, 1 Jun 2026 15:39:22 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0388A18004A3; Mon, 1 Jun 2026 15:39:20 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , linux-trace-kernel@vger.kernel.org Cc: Nam Cao , Wen Yang Subject: [PATCH v4 11/13] verification/rvgen: Fix suffix strip in dot2k Date: Mon, 1 Jun 2026 17:38:38 +0200 Message-ID: <20260601153840.124372-12-gmonaco@redhat.com> In-Reply-To: <20260601153840.124372-1-gmonaco@redhat.com> References: <20260601153840.124372-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" __start_to_invariant_check() and __get_constraint_env() parse the environment variable's name from sources that have it padded with the monitor name. This is removed using rstrip(), which is not meant to strip a substring but rather a set of characters. Use removesuffix() to actually get rid of the trailing _. Fixes: a82adadb16894 ("verification/rvgen: Add support for Hybrid Automata") Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- tools/verification/rvgen/rvgen/dot2k.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/verification/rvgen/rvgen/dot2k.py b/tools/verification/r= vgen/rvgen/dot2k.py index e6f476b90..110cfd69e 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -215,14 +215,14 @@ class ha2k(dot2k): def __get_constraint_env(self, constr: str) -> str: """Extract the second argument from an ha_ function""" env =3D constr.split("(")[1].split()[1].rstrip(")").rstrip(",") - assert env.rstrip(f"_{self.name}") in self.envs + assert env.removesuffix(f"_{self.name}") in self.envs return env =20 def __start_to_invariant_check(self, constr: str) -> str: # by default assume the timer has ns expiration env =3D self.__get_constraint_env(constr) clock_type =3D "ns" - if self.env_types.get(env.rstrip(f"_{self.name}")) =3D=3D "j": + if self.env_types.get(env.removesuffix(f"_{self.name}")) =3D=3D "j= ": clock_type =3D "jiffy" =20 return f"return ha_check_invariant_{clock_type}(ha_mon, {env}, tim= e_ns)" --=20 2.54.0 From nobody Mon Jun 8 05:25:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C61B03DDDD0 for ; Mon, 1 Jun 2026 15:39:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328374; cv=none; b=Zu9/5HcWqeJck2VeXFD/2G3b8wX3aguPFA+daoNhKXvY/6bxOmqU1spJihn/3Akz9dSSaxLYSYZQUUAHoOLt52W6wmkIiuBH0+9gp+saXK9qQ0gL7YCdcC9O2etn72248J9chPJhQEYnbBig4KIj8JDO+0EK402gr3FXS3glhj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328374; c=relaxed/simple; bh=ANdFDagE1FI9L4ciaaW1zLEpqNlIYVOqb5rOO66ytYw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PzXQOZSM8LMHLYGIFc03+NwK4Lt0pr7se+F5aTsn9RENwpBUsX4B7orJK/xqNLCuVGvQWxdormSKfgoMyyR4YwLIqofNJuLXCKI8PNSRAMrMF6WBAiuF/r+1S1MF7JTnJdftML5HgaO/9tdwpiqcgNBVgYs6YVMNbopTd/UvIhk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=hSoScG3e; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hSoScG3e" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780328369; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5rLOUc5HbPT/FYcWYXwCC9V4dfTGQw36C0sjysDza+o=; b=hSoScG3eaYrGvTWholTUME6WCEWwojeitJYaVaefhOC2KJtDt/Vm4ggV6jOZPC5oA2iXh6 RN9Rh2WL+TSKlEoWsEM580cV116dlEKKhKGDt3ZWFnLsXd7LP1HriXH1vnXU0ijPwjElcR j0hU0IWKDd+dCItYIxDVo1Zt6Yhhg6A= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-171-xxXPe-vyMRinj0o79rqR3w-1; Mon, 01 Jun 2026 11:39:26 -0400 X-MC-Unique: xxXPe-vyMRinj0o79rqR3w-1 X-Mimecast-MFC-AGG-ID: xxXPe-vyMRinj0o79rqR3w_1780328365 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 84C7C1956060; Mon, 1 Jun 2026 15:39:25 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BACDA18004A3; Mon, 1 Jun 2026 15:39:23 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , linux-trace-kernel@vger.kernel.org Cc: Wen Yang , Nam Cao Subject: [PATCH v4 12/13] rv: Fix read_lock scope in per-task DA cleanup Date: Mon, 1 Jun 2026 17:38:39 +0200 Message-ID: <20260601153840.124372-13-gmonaco@redhat.com> In-Reply-To: <20260601153840.124372-1-gmonaco@redhat.com> References: <20260601153840.124372-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The da_monitor_reset_all() function for per-task monitors takes tasklist_lock while iterating over tasks, then keeps it also while iterating over idle tasks (one per CPU). The latter is not necessary since the lock needs to guard only for_each_process_thread(). Use a scoped_guard for more compact syntax and adjust the scope only where the lock is necessary. Reviewed-by: Wen Yang Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- include/rv/da_monitor.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h index 34b8fba9e..08e5d0c59 100644 --- a/include/rv/da_monitor.h +++ b/include/rv/da_monitor.h @@ -334,12 +334,12 @@ static void __da_monitor_reset_all(void (*reset)(stru= ct da_monitor *)) struct task_struct *g, *p; int cpu; =20 - read_lock(&tasklist_lock); - for_each_process_thread(g, p) - reset(da_get_monitor(p)); + scoped_guard(read_lock, &tasklist_lock) { + for_each_process_thread(g, p) + reset(da_get_monitor(p)); + } for_each_present_cpu(cpu) reset(da_get_monitor(idle_task(cpu))); - read_unlock(&tasklist_lock); } =20 static void da_monitor_reset_all(void) --=20 2.54.0 From nobody Mon Jun 8 05:25:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D5813DEAC4 for ; Mon, 1 Jun 2026 15:39:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328377; cv=none; b=GmMX4jGZnRC1Qlcgp6VoDxoCHdmvU9cSJRK5jOOm408KOCSFPpr6qKOJo5gj97pKbDhUCFTQGpNup4m6yBO8mWeamVkZe0TNOeuNVLe+Ore7iegLzs+nC5j8PkZaMkGRm1Sf8igiXibIQ2YpPm61CS/6VhGtE0alCAlSCoFIbLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780328377; c=relaxed/simple; bh=tzcu2+zu8QYCWC1tbwf+18i2ydrhQ2My10Q6OmGHjDg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hlj+CNy2kjbtlQnNoB5xuz/RbfYLWnEE3uCbku19MJti9upw0lHsP3FBTOW4A2xD6Jy8AhuMYh1nbLbkalKBh8E/9BBEBvDBH4r76Vav54G0qkX64jPFNEDoLeuhatTJBf3Ll2GFCsKTY7hJJErg/mmNZP7+Q7oRxKkAbejiTsA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=BvnAlFQy; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BvnAlFQy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780328372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=21S+YDnCmGTIiaS+PRcKDrsm0i5RlvfONkwHhgcE6OM=; b=BvnAlFQyHmTtDA/TN/GSGjhGSRdJcRhM7TFPri/QrociHZZPkX880Rw+Tm8y+tiyC9Zhjd qwGRfo5zFEoV/TMye9wFIAk8+w+Q2deKfnJbfdU1DgQlFQkJS22Kebrg3p0cXWqiZXI5Py LlELPzXJ1pniN+xJqrgU3TzhPpPZ20U= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-617-RQTcRJkXN32--ZXbO_Z_pA-1; Mon, 01 Jun 2026 11:39:29 -0400 X-MC-Unique: RQTcRJkXN32--ZXbO_Z_pA-1 X-Mimecast-MFC-AGG-ID: RQTcRJkXN32--ZXbO_Z_pA_1780328368 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5F8DA19560AB; Mon, 1 Jun 2026 15:39:28 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 854E618004A3; Mon, 1 Jun 2026 15:39:26 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , linux-trace-kernel@vger.kernel.org Cc: Nam Cao , Wen Yang Subject: [PATCH v4 13/13] verification/rvgen: Generate cleanup hook for per-obj monitor Date: Mon, 1 Jun 2026 17:38:40 +0200 Message-ID: <20260601153840.124372-14-gmonaco@redhat.com> In-Reply-To: <20260601153840.124372-1-gmonaco@redhat.com> References: <20260601153840.124372-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Per-object monitors can allocate memory dynamically and such memory is required for the lifetime of the object, then it should be freed with the appropriate call. Force the generation scripts to add a cleanup function the user will need to wire to the appropriate event (e.g. sched_process_exit for tasks). This can be safely removed if the object will never cease to exist before disabling the monitor (e.g. if following only static variables). Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- tools/verification/rvgen/rvgen/dot2k.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/verification/rvgen/rvgen/dot2k.py b/tools/verification/r= vgen/rvgen/dot2k.py index 110cfd69e..3060aa4b9 100644 --- a/tools/verification/rvgen/rvgen/dot2k.py +++ b/tools/verification/rvgen/rvgen/dot2k.py @@ -17,6 +17,9 @@ from .automata import _EventConstraintKey, _StateConstrai= ntKey, AutomataError class dot2k(Monitor, Dot2c): template_dir =3D "dot2k" =20 + # only needed for the per-obj cleanup hook + cleanup_marker =3D "obj_cleanup" + def __init__(self, file_path, MonitorType, extra_params=3D{}): self.monitor_type =3D MonitorType Monitor.__init__(self, extra_params) @@ -56,18 +59,30 @@ class dot2k(Monitor, Dot2c): buff.append(f"\tda_{handle}({event}{self.enum_suffix});") buff.append("}") buff.append("") + if self.monitor_type =3D=3D "per_obj": + buff.append("/* XXX: obj is being destroyed, remove if not req= uired (e.g. obj is static) */") + buff.append(f"static void handle_{self.cleanup_marker}(void *d= ata, /* XXX: fill header */)") + buff.append("{") + buff.append("\tint id =3D /* XXX: how do I get the id? */;") + buff.append("\tda_destroy_storage(id);") + buff.append("}") + buff.append("") return '\n'.join(buff) =20 def fill_tracepoint_attach_probe(self) -> str: buff =3D [] for event in self.events: buff.append(f"\trv_attach_trace_probe(\"{self.name}\", /* XXX:= tracepoint */, handle_{event});") + if self.monitor_type =3D=3D "per_obj": + buff.append(f"\trv_attach_trace_probe(\"{self.name}\", /* XXX:= cleanup tracepoint */, handle_{self.cleanup_marker});") return '\n'.join(buff) =20 def fill_tracepoint_detach_helper(self) -> str: buff =3D [] for event in self.events: buff.append(f"\trv_detach_trace_probe(\"{self.name}\", /* XXX:= tracepoint */, handle_{event});") + if self.monitor_type =3D=3D "per_obj": + buff.append(f"\trv_detach_trace_probe(\"{self.name}\", /* XXX:= cleanup tracepoint */, handle_{self.cleanup_marker});") return '\n'.join(buff) =20 def fill_model_h_header(self) -> list[str]: --=20 2.54.0