[PATCH 3/6] rv: Show the mixed enable state of containers

From
Wei Li <hidden>
Date
2026-11-04 09:21:53
Also in
linux-doc
Reply to
Wei Li, 2026-11-04
From: Wei Li <redacted>

The enable file of a container reports 0 or 1 only currently. A
partially enabled container is indistinguishable from a fully enabled
one. Tracefs draws this distinction with the "X" value in
system_enable_read().

Turn the enabled field into enum rv_monitor_state.  Refresh the
container state when a nested monitor is enabled or disabled.

Signed-off-by: Wei Li <redacted>
---
 include/linux/rv.h   | 12 ++++++++++-
 kernel/trace/rv/rv.c | 50 +++++++++++++++++++++++++++++++++++++-------
 2 files changed, 54 insertions(+), 8 deletions(-)
diff --git a/include/linux/rv.h b/include/linux/rv.h
index 541ba404926a..37ca94d3c4a4 100644
--- a/include/linux/rv.h
+++ b/include/linux/rv.h
@@ -136,10 +136,20 @@ struct rv_reactor {
 };
 #endif
 
+/*
+ * Monitor state. A plain monitor is either disabled or enabled. A container
+ * monitor tracks its children, may be mixed if only some are.
+ */
+enum rv_monitor_state {
+	RV_MON_DISABLED		= 0,
+	RV_MON_ENABLED		= 1,
+	RV_MON_MIXED		= 2,
+};
+
 struct rv_monitor {
 	const char		*name;
 	const char		*description;
-	bool			enabled;
+	enum rv_monitor_state	enabled;
 	int			(*enable)(void);
 	void			(*disable)(void);
 	void			(*reset)(void);
diff --git a/kernel/trace/rv/rv.c b/kernel/trace/rv/rv.c
index 4e689d4590ae..7846e4092b9c 100644
--- a/kernel/trace/rv/rv.c
+++ b/kernel/trace/rv/rv.c
@@ -235,12 +235,15 @@ bool rv_is_container_monitor(struct rv_monitor *mon)
 static ssize_t monitor_enable_read_data(struct file *filp, char __user *user_buf, size_t count,
 					loff_t *ppos)
 {
+	const char set_to_char[3] = { '0', '1', 'X' };
 	struct rv_monitor *mon = filp->private_data;
-	const char *buff;
+	char buff[2];
 
-	buff = mon->enabled ? "1\n" : "0\n";
+	guard(mutex)(&rv_interface_lock);
+	buff[0] = set_to_char[mon->enabled];
+	buff[1] = '\n';
 
-	return simple_read_from_buffer(user_buf, count, ppos, buff, strlen(buff)+1);
+	return simple_read_from_buffer(user_buf, count, ppos, buff, 2);
 }
 
 /*
@@ -269,10 +272,22 @@ static int __rv_disable_monitor(struct rv_monitor *mon, bool sync)
 
 static void rv_disable_single(struct rv_monitor *mon)
 {
+	struct rv_monitor *cntr = mon->parent;
+	struct rv_monitor *p = cntr;
+
 	__rv_disable_monitor(mon, true);
+	if (!cntr)
+		return;
+	cntr->enabled = 0;
+	list_for_each_entry_continue(p, &rv_monitors_list, list) {
+		if (p->parent != cntr)
+			break;
+		if (p->enabled)
+			cntr->enabled = 2;
+	}
 }
 
-static int rv_enable_single(struct rv_monitor *mon)
+static int __rv_enable_monitor(struct rv_monitor *mon)
 {
 	int retval;
 
@@ -289,6 +304,27 @@ static int rv_enable_single(struct rv_monitor *mon)
 	return retval;
 }
 
+static int rv_enable_single(struct rv_monitor *mon)
+{
+	struct rv_monitor *cntr = mon->parent;
+	struct rv_monitor *p = cntr;
+	int retval;
+
+	retval = __rv_enable_monitor(mon);
+
+	if (!retval && cntr) {
+		cntr->enabled = 1;
+		list_for_each_entry_continue(p, &rv_monitors_list, list) {
+			if (p->parent != cntr)
+				break;
+			if (!p->enabled)
+				cntr->enabled = 2;
+		}
+	}
+
+	return retval;
+}
+
 static int rv_update_single(struct rv_monitor *mon, rvmon_update_fn_t update, void *data)
 {
 	int retval = 0;
@@ -297,7 +333,7 @@ static int rv_update_single(struct rv_monitor *mon, rvmon_update_fn_t update, vo
 	enabled = __rv_disable_monitor(mon, true);
 	update(mon, data);
 	if (enabled)
-		retval = rv_enable_single(mon);
+		retval = __rv_enable_monitor(mon);
 
 	return retval;
 }
@@ -325,7 +361,7 @@ static int rv_enable_container(struct rv_monitor *mon)
 	list_for_each_entry_continue(p, &rv_monitors_list, list) {
 		if (retval || p->parent != mon)
 			break;
-		retval = rv_enable_single(p);
+		retval = __rv_enable_monitor(p);
 	}
 	if (retval)
 		rv_disable_container(mon);
@@ -533,7 +569,7 @@ static void *enabled_monitors_next(struct seq_file *m, void *p, loff_t *pos)
 	(*pos)++;
 
 	list_for_each_entry_continue(mon, &rv_monitors_list, list) {
-		if (mon->enabled)
+		if (mon->enabled == RV_MON_ENABLED)
 			return &mon->list;
 	}
 
-- 
2.55.0
Thread (10 messages) 10 messages, 2 authors, last reply 12d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help