From nobody Mon Jun 8 09:48:24 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 1E28F2E7BD9 for ; Sat, 30 May 2026 14:17:06 +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=1780150628; cv=none; b=HFbDuu1bNNzo/G67u5Knf3bAgnbk9/bp95vOYJcvYF+isrHV2nJHnCwU1D49lCw7C0sTJd+dTYXUIlRX9Tuo7FvVwDEXr/Brn5mieVu9fDlvriLEBHC7zfA2HM4NBU9WDmbTrn/8qvO7im4xRYkYqOOw0URplC6+DS5ER2EOrGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780150628; c=relaxed/simple; bh=pszbcYEsq//OiYCCHsvHwEvxJOtdPCbkTA8r8kgB3pg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QEZL14b0q/eqkPRhWwnR2NFuqiKsqUwdgzAOiwl794lhz3JA9IUpZIsfcP6Ef1pu46P5GsT6F8F0FKsQqmEpREddb8eycZFnkFzf/5cnKfezCvbv648rzuVJd/MnKl1hraK61CWOVA9vodPk6jYwSE35SBG4cjN5sdBEOvOrOIg= 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=eWLjrOax; 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="eWLjrOax" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780150626; 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=eWLjrOax0xY/PcD84SzClSdwyfzBexZptANoac5BRze0kRlkZG2DQjP8RMWqbPfNXOdLW/ mQsray7HLJ38zZgFNAcb/Q2H7KY4EumYcQDtn7xYqH5JtEeGI2voL6tn6tjqZJOZEN7a+0 Ec+qvexSXoGxueOFUgmW8hWopNWPKNo= 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-94-MxRiYWTlM6iLOp91a73rEQ-1; Sat, 30 May 2026 10:17:02 -0400 X-MC-Unique: MxRiYWTlM6iLOp91a73rEQ-1 X-Mimecast-MFC-AGG-ID: MxRiYWTlM6iLOp91a73rEQ_1780150620 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 6D7131956096; Sat, 30 May 2026 14:17: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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BB6D030001BB; Sat, 30 May 2026 14:16:57 +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 v3 01/13] rv: Fix __user specifier usage in extract_params() Date: Sat, 30 May 2026 16:16:40 +0200 Message-ID: <20260530141652.58084-2-gmonaco@redhat.com> In-Reply-To: <20260530141652.58084-1-gmonaco@redhat.com> References: <20260530141652.58084-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.4 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 09:48:24 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 B5B5C3064AE for ; Sat, 30 May 2026 14:17:11 +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=1780150632; cv=none; b=GgVcF+/G9VQJ7JmfIV29biNdn067PSEy+/j9UdNYDS+NkFBWuMJcRuBF2tTDRXo6BnLWBgIFdLlSJBPdhMCc956rcW1unB56vdc5/FJxBDAUqK+K60Zf9rO697oQ81hHHFSup1w7LNjx5Y6BJ/4nkwM5WigsF1ni6UFM5zq1dJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780150632; c=relaxed/simple; bh=WbFGxdg8pRAiP0PRsmIIP8kQxut9lC2Tuq1OEeDZX9s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rEz9whgw8EeRs49f1tDz0J05UU/iVmgItOEfhsag5jxvbawGzKqOv1Ub5wLWkNs/+Bx+8/sSbzV80khLSqhTZ3Fa9Qy607KAkkVgR/1+h3N1JHB0pFe360Dcs5usNy8bDXCm2FTwNKX2xfyZ3A21cK7ncInK4mbhf8j/CnIMju0= 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=VMc6/Kx9; 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="VMc6/Kx9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780150630; 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=VMc6/Kx95hvR02UxPTDl/2MACUxEX8spz043nuKK6Xy0uGuqAPHG5T+fC30SmL7rvDsagh qKV3dAFZEzcPRXCQf7Kp/9p6n9Kj5hKMp1PRn5R6liShcf3G0OL6S8cLFE5X/ji9Qpg4tL yLaOX1IFdAjqlOx4vVSlhVymj+ro8Fk= 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-607-xl3W6iZqPB2cjIpCo1B9-g-1; Sat, 30 May 2026 10:17:05 -0400 X-MC-Unique: xl3W6iZqPB2cjIpCo1B9-g-1 X-Mimecast-MFC-AGG-ID: xl3W6iZqPB2cjIpCo1B9-g_1780150624 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 A66351956046; Sat, 30 May 2026 14:17: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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5F8E430001BB; Sat, 30 May 2026 14:17:01 +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 v3 02/13] rv: Reset per-task DA monitors before releasing the slot Date: Sat, 30 May 2026 16:16:41 +0200 Message-ID: <20260530141652.58084-3-gmonaco@redhat.com> In-Reply-To: <20260530141652.58084-1-gmonaco@redhat.com> References: <20260530141652.58084-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.4 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 09:48:24 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 B465A30567E for ; Sat, 30 May 2026 14:17:15 +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=1780150636; cv=none; b=QpnkQ/XBE/p3i7xWck5ZQniOZplweT6A9KWIDJDRA66uw4vv+EZoPnp9RszhaslmO3xGrdmJsCJpCz9ToqwP6c7KC7OSC6uGjTeK1Yj1k8WwOlFj2k38bSXpkUtCf8RXmbLbpHvT0XdyfXyB/BXBcm2H6qVkDqq9hNcEaUdq5tU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780150636; c=relaxed/simple; bh=rt7PVioEGyjExEkO42rRcqYR0XN7bI9hxdnBpOgsBk8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p3nDPEZSRX4/1rebdxgz4hUztzU7Ex35V2cZgKb+fIe0IUIh2jVw5oZYo8X8E9/I3h1dNLR8ghzveHBBIVnWjweTXeDLrurp/NDCETcr+I15fU7VGR3BA+FBiNiYWZpVJe0ERUON4/pWXOfHhqcCVqnAFlQyrHC0Z/Do2eIYoMA= 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=Iu/5qdni; 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="Iu/5qdni" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780150634; 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=Iu/5qdnis6MYXjBlOXr9Huiptdu6DFq4oqC8HoPsGjU31PnQXJiWWjlta5Sa3+NOIUz7XB sSWq5CvGcKQwCCXmIf8f1027gqVvo7ZmuWz41s79nYtOG0AF+TuCbZEQtm+whG4M7sKz+U QYAwHDZFt1FBN4DUmlUTQr1783jylso= 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-694-iHL4KIDAMWCKDgoj33jHEg-1; Sat, 30 May 2026 10:17:08 -0400 X-MC-Unique: iHL4KIDAMWCKDgoj33jHEg-1 X-Mimecast-MFC-AGG-ID: iHL4KIDAMWCKDgoj33jHEg_1780150627 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 F257D1956089; Sat, 30 May 2026 14:17: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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DD83330001BB; Sat, 30 May 2026 14:17: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 v3 03/13] rv: Prevent in-flight per-task handlers from using invalid slots Date: Sat, 30 May 2026 16:16:42 +0200 Message-ID: <20260530141652.58084-4-gmonaco@redhat.com> In-Reply-To: <20260530141652.58084-1-gmonaco@redhat.com> References: <20260530141652.58084-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.4 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 09:48:24 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 DA1F43064AE for ; Sat, 30 May 2026 14:17:15 +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=1780150637; cv=none; b=ckb+TMrpK1XGEzaBb2uvQ5N/NZOr6fnSbp/6OkN/ZUh3FWbejYaNVeGvpRv0ProXB4niex4vwliP8uHkWgLAHxc1bFIQ9hKnzE/RjNPygdTPUHhf3m7cMkpgNFRHnDH80ONrWwCx4gvt6fIBUZ68tHJkeLExt7RrDa1SJICl0hc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780150637; c=relaxed/simple; bh=gFdwMA8XHL/34A2qgdCDIwi1WjLV/OpiyLi0vEnRgYk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ufwo89Ygid2C/VkWh9FvLedbOPdE7BbQ11azvUBec7N99F6HJ6dlHNN9n2QTu0x2o4aXZQ9j0n8Gc8/ZbgCbYdtLNm75/nt0kAdHShbfXPe7GW1lu9e1iYHX7Zv35/kuZFMPAxvxqSKT8rzwHWhB4y8SvgvmjXbUKjogOgchDG0= 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=cM2LMQHG; 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="cM2LMQHG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780150635; 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=cM2LMQHGAaKlG6nzNTYALeuMT5RwpOQltPGje7+B8Eo6Gnt+vrG/QP2gdMaV1Qun7o3ake 5/Zy9erXk8+k4zv3tMrJjOHnLKDwI7lhc6V7Ybihx66hryGy5kb9K/plwA6eXCASFClgyH XuZccZVHmhL0RrZPN9xeXoE1+mGQicM= 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-104-BBFmwEcXNT6rK4MMcnNAeg-1; Sat, 30 May 2026 10:17:11 -0400 X-MC-Unique: BBFmwEcXNT6rK4MMcnNAeg-1 X-Mimecast-MFC-AGG-ID: BBFmwEcXNT6rK4MMcnNAeg_1780150630 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 D0C6F19560B2; Sat, 30 May 2026 14:17:09 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E673730001BB; Sat, 30 May 2026 14:17:07 +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 v3 04/13] rv: Ensure all pending probes terminate on per-obj monitor destroy Date: Sat, 30 May 2026 16:16:43 +0200 Message-ID: <20260530141652.58084-5-gmonaco@redhat.com> In-Reply-To: <20260530141652.58084-1-gmonaco@redhat.com> References: <20260530141652.58084-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.4 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 09:48:24 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 7E8873033EC for ; Sat, 30 May 2026 14:17:18 +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=1780150639; cv=none; b=NoJxVbynmiph0IOd0KTyW9na4XQ+ivslRV9GeIB4fxhaz/qWjQqLj0mX7LpRZgtgKLn184AV4u3MbxR+w8C39v7m5lW4XIqzMQdWiaC9y/1bHMtGU4LRv6FNuGPzWjaKWziqrujqLtxrJWlf+Amn81Np299BtFERQh4ipA2W1e4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780150639; c=relaxed/simple; bh=aMI6ETwxmmNMEq4Pf/ssYWo3dsOyX8bUrocvUz48vCM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mCK39273azlyw6m0aEV5vk+/YO2+4yCLqPIXyYk5Ed+ssJan8nzLxDwVtRVYrGLGnIQqvix01xP5R6u3JPzmTdRJcEE1Y6eR1KHQdDQsyDwdiGw0rAcEseKh8bbpZamoHjbIec2P9OpLel4iN+lZjhxbz9wWT2tH08FgdrDEFaA= 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=W/DoFaeD; 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="W/DoFaeD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780150637; 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=W/DoFaeDXfTFBVIIWl4X9cj8joOOqddWBbeznDUbp7mkn5slbrIZjdmjFXATsbwjJr1qVP Llh+YMIoakHLD0XGelQqdP+mLT2J7qs0uFOtNSbg7bDVOU1uhgRyuY3vMbdwumUmF8UDX6 S+zIXOj+cxxL7Ya0UxkGQc9rXroKZNQ= Received: from mx-prod-mc-08.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-651-Ztj-yjVKNFiifEV6NvOlhQ-1; Sat, 30 May 2026 10:17:13 -0400 X-MC-Unique: Ztj-yjVKNFiifEV6NvOlhQ-1 X-Mimecast-MFC-AGG-ID: Ztj-yjVKNFiifEV6NvOlhQ_1780150632 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BC9361800343; Sat, 30 May 2026 14:17:12 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C60E730001BB; Sat, 30 May 2026 14:17:10 +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 v3 05/13] rv: Fix monitor start ordering and memory ordering for monitoring flag Date: Sat, 30 May 2026 16:16:44 +0200 Message-ID: <20260530141652.58084-6-gmonaco@redhat.com> In-Reply-To: <20260530141652.58084-1-gmonaco@redhat.com> References: <20260530141652.58084-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.4 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 09:48:24 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 029C12E7F17 for ; Sat, 30 May 2026 14:17:22 +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=1780150644; cv=none; b=Kkhq8XI7gSvtk7pGzt2imhvHdawquYbNkA4qRC8T9/1em1jUFCMJ0yjIw8/UP6Ypg5I5c5wqdD1hKnL+YsRuoUElpExQAJk+AlFTcOPLzIHMaQ8EHy6GlD2UgjoH6jwkmn66r/Ou11nLGOUnoQMuar9WrFuf174iuOiAZ2aY2IQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780150644; c=relaxed/simple; bh=Eaq8qvBAwg7VHIzxB0rCY5AtycOS0waCgj7kaoTbYaM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=txARX1CqqU1FV3gqsNrvTZzvB3E7PlnJEpOr+3KBTwNWpzagL2G+qBLUSbBKPzjK2lbIs5EzO9xqa7n+Jce5/X0lBb1tzWgoL/mmp/cNEf1rO2kRLGZPrUmlK3GiZ+7GttLASodud2TBUzmLq0moEUe0sslJBbIrkIe6W2t6HhA= 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=a8z7wx3L; 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="a8z7wx3L" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780150641; 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=1ArcgV16oTYvnYACXoWOEb9nPutGeKmH808+7QPaO4Y=; b=a8z7wx3LwJTrpLptPJEc4YN9ThncXtakdDRNy20Qj/1bA2ZrkfwiQ5NPXFgsIQDlnD0vsf jO3xltR0ddQ1n0PvZEjn93ff87MGTow/OmEBXkxW65e7g0IoMvy8Mx8TmYAxE7okRQ2SYu yzGIdyq9eEwHbdunrYpWcoXr5n6aG5g= 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-650-I2mZxVpGNNCucsEuR3mcjQ-1; Sat, 30 May 2026 10:17:18 -0400 X-MC-Unique: I2mZxVpGNNCucsEuR3mcjQ-1 X-Mimecast-MFC-AGG-ID: I2mZxVpGNNCucsEuR3mcjQ_1780150636 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 C4EFA18005BA; Sat, 30 May 2026 14:17: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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8BC3D30001BB; Sat, 30 May 2026 14:17:14 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , Masami Hiramatsu , linux-trace-kernel@vger.kernel.org Cc: Wen Yang , Nam Cao Subject: [PATCH v3 06/13] rv: Do not rely on clean monitor when initialising HA Date: Sat, 30 May 2026 16:16:45 +0200 Message-ID: <20260530141652.58084-7-gmonaco@redhat.com> In-Reply-To: <20260530141652.58084-1-gmonaco@redhat.com> References: <20260530141652.58084-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.4 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 skip timer cancellation in any case when a local flag is set. New monitors (e.g. new tasks) are always zero-initialised so they are safe. Reported-by: Wen Yang Closes: https://lore.kernel.org/lkml/d02c656aada7d071f083460a5c9a454363669b= 61.1778522945.git.wen.yang@linux.dev Fixes: f5587d1b6ec9 ("rv: Add Hybrid Automata monitor type") Reviewed-by: Wen Yang Signed-off-by: Gabriele Monaco --- include/rv/ha_monitor.h | 31 ++++++++++++++++++- 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, 38 insertions(+), 9 deletions(-) diff --git a/include/rv/ha_monitor.h b/include/rv/ha_monitor.h index d59507e8c..ad3347af1 100644 --- a/include/rv/ha_monitor.h +++ b/include/rv/ha_monitor.h @@ -115,6 +115,35 @@ 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_initializing; + +static int ha_monitor_init(void) +{ + int ret; + + ha_mon_initializing =3D true; + ret =3D da_monitor_init(); + ha_mon_initializing =3D false; + return ret; +} + +static void ha_monitor_destroy(void) +{ + da_monitor_destroy(); +} + +/* + * ha_monitor_uninitialized - are fields like the timer initialized? + * + * On a clean monitor, we can assume an active monitor (monitoring) is + * initialized, however the monitoring field cannot be trusted during + * initialization. + */ +static inline bool ha_monitor_uninitialized(struct da_monitor *da_mon) +{ + return ha_mon_initializing || !da_monitoring(da_mon); +} + /* 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, @@ -159,7 +188,7 @@ static inline void ha_monitor_reset_env(struct da_monit= or *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))) + if (likely(!ha_monitor_uninitialized(da_mon))) ha_cancel_timer(ha_mon); } =20 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 09:48:24 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 01ED938F62F for ; Sat, 30 May 2026 14:17:25 +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=1780150647; cv=none; b=Jq4FEs+Dflk8NbdvO635fGt4xplKkyqbwZjovZL1QQeRYar6dYn1YH1TnyGSh6QOHxYUQU9OuZxYEVzjWhM3BZuzU6r8+XsfxFuJf8C5zN0EsDxhmT9b4pTmfoPQ32B3zBKtiwkSfM2xPHH8gS0V6GS9j8bvqpIPZjohh6+nSFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780150647; c=relaxed/simple; bh=qi0L9LIA+fI+0b7vwfe1ljJPHVtvHgwWYrpe/8OqpLk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CCfEK5DgpuutUHOocpRUbJAOc9dK7Fv4HNOI8ZiK6BxC2Qm0N0j9Y+V4fYRm8uCsVqqY3QWLUy+S3KNadrvunom4+bDC7cCQVrgyPgY+Dg9CSlPYos56GPzJDjtJmPzwGsj1m6PSkZH83JO6jpicSrMGMHIiD9rgNu1YR8eIrgw= 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=gXNJCa6b; 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="gXNJCa6b" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780150645; 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=vT4w/Ow74J+m2Lbf9BXQF20oc8LgcRemn11BpAcG52I=; b=gXNJCa6bK+8sC2mdiVUKXU7xF/YfGd6LeWDcbC2qCCfRJqqPtt0kn7+gglfxXiPE3nMUIm PI54tN3nQcwPShYLci07qJLyB2cuachyzxJkVGhgmckbttVLwi0EhaidM7oSmZN8RomHt0 l7FDxg2XNPncy4hayIEOUyT6Jv+PfpY= 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-183-W4XU2b56NxWmiQtTvQvq8g-1; Sat, 30 May 2026 10:17:21 -0400 X-MC-Unique: W4XU2b56NxWmiQtTvQvq8g-1 X-Mimecast-MFC-AGG-ID: W4XU2b56NxWmiQtTvQvq8g_1780150640 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 0F95B195608C; Sat, 30 May 2026 14:17:20 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D22853002D2D; Sat, 30 May 2026 14:17:17 +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 v3 07/13] rv: Add automatic cleanup handlers for per-task HA monitors Date: Sat, 30 May 2026 16:16:46 +0200 Message-ID: <20260530141652.58084-8-gmonaco@redhat.com> In-Reply-To: <20260530141652.58084-1-gmonaco@redhat.com> References: <20260530141652.58084-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.4 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") Signed-off-by: Gabriele Monaco Reviewed-by: Nam Cao --- include/rv/ha_monitor.h | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/include/rv/ha_monitor.h b/include/rv/ha_monitor.h index ad3347af1..0aeb6bc38 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 @@ -123,12 +144,15 @@ static int ha_monitor_init(void) =20 ha_mon_initializing =3D true; ret =3D da_monitor_init(); + if (ret =3D=3D 0) + ha_monitor_enable_hook(); ha_mon_initializing =3D false; return ret; } =20 static void ha_monitor_destroy(void) { + ha_monitor_disable_hook(); da_monitor_destroy(); } =20 @@ -229,6 +253,18 @@ 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(!ha_monitor_uninitialized(da_mon))) + ha_cancel_timer_sync(to_ha_monitor(da_mon)); +} +#endif + #endif /* RV_MON_TYPE */ =20 /* @@ -441,6 +477,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. @@ -492,6 +532,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 @@ -502,6 +546,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 --=20 2.54.0 From nobody Mon Jun 8 09:48:24 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 185BA30C372 for ; Sat, 30 May 2026 14:17:26 +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=1780150648; cv=none; b=CaqBJeBeZYTV82nP8tOTU7a0sCZppVjgA7B5HlOUlUFt62d+z2KaBVEWqLDVzjj5sbNRxTDCKddtuzTE/qanDECzi+70Ua6JKB8o5UB3l6vrlgacwrqMQPrgEUP4aTcgMudFv9v58V6EKstbjzfJ8m8WqbOuh5euFCFJTllPWg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780150648; c=relaxed/simple; bh=q95X7DBoJG+Hx0/FniTyYU92WAwPBSBeoofnKheh75I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bP2aa4aQh2xpdZQp7M3/vesru94VMcE6Nac/XCosmQlUZGmbD5WvZ/80P4/yXB2RhgaRsSalMdE/QfGnk2u4M+Ycws6jwvu/p83fRmo08n+0oq5r3dMbtDiI2fzkIjmThgHsw5RrhqEl0VsAL+hjWxgdSiF88p0vl09Tbobo2wU= 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=CR+8IZoE; 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="CR+8IZoE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780150646; 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=0qrmonuq6odMLHrrpshTudsgnB0v77ap74VkT9rmxcg=; b=CR+8IZoEkdhzh5BnUG7ZuudrwMu8XC8UilJZ0/5lB88xXTJbMlrvtXCusI0dsNA9vKnw2g gOcV6GFIcBrLiYTh5knLybyCCbKJs6dlpQnHI1lP9DDkNmrT7Nw/+s3l8yPEY5ai8OxHOE LpOnFYbyGepWZORgPI3WKIpU3zwzqGQ= 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-301-QCx1QrtEOAiRVCejkL96zg-1; Sat, 30 May 2026 10:17:24 -0400 X-MC-Unique: QCx1QrtEOAiRVCejkL96zg-1 X-Mimecast-MFC-AGG-ID: QCx1QrtEOAiRVCejkL96zg_1780150643 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 2BE6A1956089; Sat, 30 May 2026 14:17:23 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4C0BC30001BB; Sat, 30 May 2026 14:17:21 +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 v3 08/13] rv: Ensure synchronous cleanup for HA monitors Date: Sat, 30 May 2026 16:16:47 +0200 Message-ID: <20260530141652.58084-9-gmonaco@redhat.com> In-Reply-To: <20260530141652.58084-1-gmonaco@redhat.com> References: <20260530141652.58084-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.4 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 | 26 +++++++++++++++++++++----- include/rv/ha_monitor.h | 28 +++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h index 60dc39f26..03c1150b1 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 @@ -83,7 +92,8 @@ 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(); + /* Pair with load in __ha_monitor_timer_callback */ + smp_store_release(&da_mon->curr_state, model_get_initial_state()); } =20 /* @@ -181,6 +191,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 @@ -230,6 +241,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 @@ -317,6 +329,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; @@ -495,10 +508,9 @@ static void da_monitor_reset_all(void) 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(); } =20 static inline int da_monitor_init(void) @@ -514,13 +526,17 @@ static inline void da_monitor_destroy(void) int bkt; =20 tracepoint_synchronize_unregister(); + scoped_guard(rcu) { + hash_for_each_rcu(da_monitor_ht, bkt, mon_storage, node) { + da_monitor_reset_hook(&mon_storage->rv.da_mon); + } + } + 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 0aeb6bc38..86bd1cab8 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 /* @@ -137,11 +138,13 @@ static enum hrtimer_restart ha_monitor_timer_callback= (struct hrtimer *hrtimer); #endif /* HA_CLK_NS */ =20 static bool ha_mon_initializing; +static bool ha_mon_destroying; =20 static int ha_monitor_init(void) { int ret; =20 + WRITE_ONCE(ha_mon_destroying, false); ha_mon_initializing =3D true; ret =3D da_monitor_init(); if (ret =3D=3D 0) @@ -152,6 +155,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(); } @@ -302,12 +306,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 09:48:24 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 9E3563AFAEA for ; Sat, 30 May 2026 14:17:30 +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=1780150651; cv=none; b=SI1c80ClTUSnnzoFnpwVaZhLDva6QvIiKnaP7/OJ9hkKJotrND1x9P4gNpc0NkfCnqk06GHFOtdekYEJHhDPKYcgA1fXu1WfzpVRViT1jD74YteJfakkJ18b2O0NsbcMI1UB7rh0V70uyTdESGvpj3ZP0/KHeZ3eUdUT5Y8rVJg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780150651; c=relaxed/simple; bh=2auu0wUshBdL3euNr84+3mM8Nb18AhruiK26RqQIyJY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W9BY0u890s47XFLfvWxzStc93cdFxn39/R69o29sqlUXVlGbA7QNtSvMLHy+Vwef8+roQpteXIjsKTh0OUXycFCnmZB+MWUDgskRxN9qM+8z4F8mGxZt5rSbSSRQaIlPJaw4ndAiHe+jhBuOXTRLzbTw1wVO9P/oTkTZ6eS9uSU= 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=R0yuLU5J; 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="R0yuLU5J" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780150649; 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=8s8nZxVKOrACxNdZkFQ3oVHcJBxN3VpVUQ3IcWWpAAQ=; b=R0yuLU5Jt3MwESB2pYeh8wm8I+YogQrnfzvJyNTkQGjl1Butr0s9Ek1gWcasWxR1xjQHBI kWZzDcMF7AMKOMOC5nc2pnl9yOro10Mqt6xcdWbMxrTsmzWdQn/tZxLEphYPvnKzbZl8Ig DDTxdxfc94tMHGWyybnmMjXF2v4wqw0= 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-452-07erGJtsNqGkmUvjPaAPhQ-1; Sat, 30 May 2026 10:17:27 -0400 X-MC-Unique: 07erGJtsNqGkmUvjPaAPhQ-1 X-Mimecast-MFC-AGG-ID: 07erGJtsNqGkmUvjPaAPhQ_1780150646 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 72BAA195608F; Sat, 30 May 2026 14:17:26 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2972830001BB; Sat, 30 May 2026 14:17: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 v3 09/13] rv: Prevent task migration while handling per-CPU events Date: Sat, 30 May 2026 16:16:48 +0200 Message-ID: <20260530141652.58084-10-gmonaco@redhat.com> In-Reply-To: <20260530141652.58084-1-gmonaco@redhat.com> References: <20260530141652.58084-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.4 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 03c1150b1..ae8c35fcb 100644 --- a/include/rv/da_monitor.h +++ b/include/rv/da_monitor.h @@ -194,6 +194,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. @@ -244,6 +248,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. @@ -700,6 +708,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 @@ -715,6 +724,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 @@ -726,6 +736,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 09:48:24 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 08C0E30B508 for ; Sat, 30 May 2026 14:17:35 +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=1780150657; cv=none; b=Nnhh8DPYuGkAgZKtrZu7qm9W0DENigEspOLD4WGOYxYtR65k17IF/4VgeaGNx08AsYAi6rw9fBXJnaXSxgLx6H+E96lPNsfzFMLUkpAczxquyO45q0lL2qhiZQvcgThaDkXv+WCvjFBZail/Ju6dcAsEyPwiTqhNGXqe9F3bCVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780150657; c=relaxed/simple; bh=dXsrP4TL3rMdvbYgcsppSeBzkUR4NUGfNW4/c1f+jwQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BUpqk7CefnehrqyyP08MdCS27CMmDFtuyhwcEi2jgx4VJ9H8BN2ava7V30oj+8eZvT0EMaJ53vPRlMLes2Fgf0J1lTNsBFhaEXREtTS87srwMf0pqio3EPOhyAnRC/mRWgMRwIX+J+kF8OgmIf9a53SYxgKy3v45QNj0xqUxYL4= 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=amLEIiiO; 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="amLEIiiO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780150655; 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=76JYe2UfOZXC8uyARcR9DHU+vZw6MDU2He4odYWsbfA=; b=amLEIiiOreoVR/dzxKrtykyt3SIrWHSLifvNbpswc3pz0y4YKD52wZ3vEvQPLLPJ0kO94G 5qGqUtAk3gtP3BfGes3h7y93V5FqxdAg+U/LOXwALQ7l7lf97LfqmA9EG6z44mfwV2DPmw nbVZ5ftL2jQ1Pff49FqjFrj7nnx4ef8= Received: from mx-prod-mc-08.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-81--kDJX1H1O6ySHx3mOsiuKA-1; Sat, 30 May 2026 10:17:30 -0400 X-MC-Unique: -kDJX1H1O6ySHx3mOsiuKA-1 X-Mimecast-MFC-AGG-ID: -kDJX1H1O6ySHx3mOsiuKA_1780150649 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 84E801800451; Sat, 30 May 2026 14:17:29 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7A27730001BB; Sat, 30 May 2026 14:17:27 +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 v3 10/13] rv: Use 0 to check preemption enabled in opid Date: Sat, 30 May 2026 16:16:49 +0200 Message-ID: <20260530141652.58084-11-gmonaco@redhat.com> In-Reply-To: <20260530141652.58084-1-gmonaco@redhat.com> References: <20260530141652.58084-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.4 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. Signed-off-by: Gabriele Monaco Reviewed-by: Nam Cao --- 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 09:48:24 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 31574304BB2 for ; Sat, 30 May 2026 14:17:38 +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=1780150659; cv=none; b=cU0Jynd3pWd+iZ2cHoUdtBl4ibPoV5djyoKn3HwTid3CoZtmR4T7wrQvYOwVWPCDJqhzL68XwS6n3z+4+GRk/lyACgv/VAktyswqIPN6r5VKWnLOeIGdGW/YD0F+lVsnPoHQ/FaYHDfkjOFqZ7Tdo0yAsLfzjpBTuySea6eY7oM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780150659; c=relaxed/simple; bh=gTgst4RG82v+Pzr7Y9TZwyGFXX+pyH41XUeKD8aNXY4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PzVUqtohFRXHunxVscuPXWQyb5e9XQZ+aqJUH9/KVCo4UTmsalvz/jeir1uXhx+FzxvIUfXmLNgBKaUSqmKe0G7QlqbGX8zxZJKiU67lAAaSYDpH3wMamglEzIk1qOS7tkg62XiS812fbnfnB9oWV6b6NTcHmvklzMUuhsoQ4Qc= 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=SGKUfZXJ; 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="SGKUfZXJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780150657; 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=o9EXyjATGOAG3X90xS7c9ANBwF437oeU5IhxqaG7rLg=; b=SGKUfZXJMmhKBF3rntYunJdABNrmab+rDPZgGPsB3M0CcG6nLuh6/1p3vVTURKY+icGF+o ioCNN+QzCRp5TLR8RBZdoK21vpc16KzzlXmBfYn+N/IuPsAqZpEnscH7Pvq760Io5yqkfY Z6UQWIk33IR93YZwIkdO8Wk460AFjyI= 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-125-hl6vEHqvMcqdBbzP15S16A-1; Sat, 30 May 2026 10:17:33 -0400 X-MC-Unique: hl6vEHqvMcqdBbzP15S16A-1 X-Mimecast-MFC-AGG-ID: hl6vEHqvMcqdBbzP15S16A_1780150652 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 843741956096; Sat, 30 May 2026 14:17:32 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AA9273002D2D; Sat, 30 May 2026 14:17:30 +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 v3 11/13] verification/rvgen: Fix suffix strip in dot2k Date: Sat, 30 May 2026 16:16:50 +0200 Message-ID: <20260530141652.58084-12-gmonaco@redhat.com> In-Reply-To: <20260530141652.58084-1-gmonaco@redhat.com> References: <20260530141652.58084-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.4 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") Signed-off-by: Gabriele Monaco Reviewed-by: Nam Cao --- 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 09:48:24 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 283AB37AA8C for ; Sat, 30 May 2026 14:17:42 +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=1780150663; cv=none; b=GfV3TUJ9qG2J7ysOjv/6A2Tl8R+Rf+D+wiXqhLYoWBZZncUoIwyANAbMPUdKyAYxQuDTDjsE7y7/Q7GE/jpHlO2HwsAsCui7DCCyuMgUA4unHinSYst864VSfHKv2Xa/SunlSaGhFETOVsXNEgcD+Pq3BRb+CzK80vTofYoCMmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780150663; c=relaxed/simple; bh=VUpfsFc62bFNBVbMzaTza0SKHhnDqyPiMbii4gCBqEw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oe8PjnlTwoqvUpDxdillpVon+SpxFnWr8SbDpeMRldB8rnZFe/z53pW8RfdlkwQUxi7+/BqMlsYtSmfwX92EpVdgfW3TKcV2YRORroMtW9j7aUVzgA9mYYOvNv0JLXS427ompmRqaCzmBi1J3s+L/jYIdg3cLQE+dk4W1CVK34g= 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=RlmYtgPO; 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="RlmYtgPO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780150661; 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=PNimF1QAk1+ATYYd1bb8YN+Y+pOQsQfgOs4cRpBAAPE=; b=RlmYtgPOHBQvG1o8uZhN4D3DI9KWm2Zxkxj5roR9rLAoRXySfGAzXRPQpQvz/h5R0Wh1ha i4aVouJezNGxLelTyshNiC3qlwJ1hhQc5YTfTZyxQoWGW31tSnZIHkW12YCIZ3chilyRqd sZiH3d3W14P0WCsc5eGvD23h51y307I= 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-271-KZjYUwxRPcSiLEqG-k0dmg-1; Sat, 30 May 2026 10:17:36 -0400 X-MC-Unique: KZjYUwxRPcSiLEqG-k0dmg-1 X-Mimecast-MFC-AGG-ID: KZjYUwxRPcSiLEqG-k0dmg_1780150655 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 6BA29180044D; Sat, 30 May 2026 14:17:35 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9335D30001BB; Sat, 30 May 2026 14:17:33 +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 v3 12/13] rv: Fix read_lock scope in per-task DA cleanup Date: Sat, 30 May 2026 16:16:51 +0200 Message-ID: <20260530141652.58084-13-gmonaco@redhat.com> In-Reply-To: <20260530141652.58084-1-gmonaco@redhat.com> References: <20260530141652.58084-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.4 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 ae8c35fcb..f4fc22cac 100644 --- a/include/rv/da_monitor.h +++ b/include/rv/da_monitor.h @@ -294,12 +294,12 @@ static void da_monitor_reset_all(void) 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)); + scoped_guard(read_lock, &tasklist_lock) { + for_each_process_thread(g, p) + da_monitor_reset(da_get_monitor(p)); + } for_each_present_cpu(cpu) da_monitor_reset(da_get_monitor(idle_task(cpu))); - read_unlock(&tasklist_lock); } =20 /* --=20 2.54.0 From nobody Mon Jun 8 09:48:24 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 437423BF676 for ; Sat, 30 May 2026 14:17:42 +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=1780150663; cv=none; b=oTwL2QJCqWc71qaJ/i3sgz3pMSit9iIZd37wSx8tmX8oNtkRSoXJSzPcRGCKEoXpeQNV1e9dGiTFTfe+8nc6AEpdh/7LbG5m1cX1ApahWYnsaZgFuvvBWJLYA8GC/VnMBkZK3NPofLqGA+R7tDd+PVdAORmvDsxw/g01WV3iRBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780150663; c=relaxed/simple; bh=v9Q52fnEGJvcPbiWONH0PwZhcDfz+qUXKqRJo/i1nhE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QmB3Yce0r30lmLBauGhg/Y3/QvLgfn//UfZFIDn3TSOwdj4sUHxcaKITiElJbHp1vX+QJ/wncN4gxp3Jtm3LL+708c7GgTg0y7f1ydjOcnIwwreREdRCud/B7Lf+5eyOZhPq+v8u0z/PjC66VQRj/XCIcLE6d6pPl0UwVEXGbvU= 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=Qjows1xr; 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="Qjows1xr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780150661; 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=APqx5zgx+UWLkpKTsxBYfSqwUD6XZTNzSrSngpPoAvs=; b=Qjows1xrhcSh/ue5Jh/cHrRrBGlwmDqZn8bIu+N57r9CJGDAO6yGt0SQnXH43jS8sL1dL9 fxIwM51rlUGleTAIoGKrApQz27volsuj3s/Oxug+j9/AlU7atyMsztmOwQVUh06DlqbwwU k9sZ6huQzQ30u23xe8ytoddlg/Wfj7w= Received: from mx-prod-mc-08.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-388-mMKdVh2lPkCkfmcm70IQ8A-1; Sat, 30 May 2026 10:17:39 -0400 X-MC-Unique: mMKdVh2lPkCkfmcm70IQ8A-1 X-Mimecast-MFC-AGG-ID: mMKdVh2lPkCkfmcm70IQ8A_1780150658 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4A6531800359; Sat, 30 May 2026 14:17:38 +0000 (UTC) Received: from fedora-pc.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7981D30001BB; Sat, 30 May 2026 14:17:36 +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 v3 13/13] verification/rvgen: Generate cleanup hook for per-obj monitor Date: Sat, 30 May 2026 16:16:52 +0200 Message-ID: <20260530141652.58084-14-gmonaco@redhat.com> In-Reply-To: <20260530141652.58084-1-gmonaco@redhat.com> References: <20260530141652.58084-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.4 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). Signed-off-by: Gabriele Monaco Reviewed-by: Nam Cao --- 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