浏览代码

oprofile: disable write access to oprofilefs while profiler is running

Oprofile counters are setup when profiling is disabled. Thus, writing
to oprofilefs has no immediate effect. Changes are updated only after
oprofile is reenabled.

To keep userland and kernel states synchronized, we now allow
configuration of oprofile only if profiling is disabled.  In this case
it checks if the profiler is running and then disables write access to
oprofilefs by returning -EBUSY. The change should be backward
compatible with current oprofile userland daemon.

Acked-by: Maynard Johnson <maynardj@us.ibm.com>
Cc: William Cohen <wcohen@redhat.com>
Cc: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Signed-off-by: Robert Richter <robert.richter@amd.com>
Robert Richter 14 年之前
父节点
当前提交
7df01d96b2
共有 4 个文件被更改,包括 18 次插入20 次删除
  1. 6 15
      drivers/oprofile/oprof.c
  2. 1 1
      drivers/oprofile/oprof.h
  3. 5 2
      drivers/oprofile/oprofile_files.c
  4. 6 2
      drivers/oprofile/oprofilefs.c

+ 6 - 15
drivers/oprofile/oprof.c

@@ -225,26 +225,17 @@ post_sync:
 	mutex_unlock(&start_mutex);
 	mutex_unlock(&start_mutex);
 }
 }
 
 
-int oprofile_set_backtrace(unsigned long val)
+int oprofile_set_ulong(unsigned long *addr, unsigned long val)
 {
 {
-	int err = 0;
+	int err = -EBUSY;
 
 
 	mutex_lock(&start_mutex);
 	mutex_lock(&start_mutex);
-
-	if (oprofile_started) {
-		err = -EBUSY;
-		goto out;
+	if (!oprofile_started) {
+		*addr = val;
+		err = 0;
 	}
 	}
-
-	if (!oprofile_ops.backtrace) {
-		err = -EINVAL;
-		goto out;
-	}
-
-	oprofile_backtrace_depth = val;
-
-out:
 	mutex_unlock(&start_mutex);
 	mutex_unlock(&start_mutex);
+
 	return err;
 	return err;
 }
 }
 
 

+ 1 - 1
drivers/oprofile/oprof.h

@@ -37,7 +37,7 @@ void oprofile_create_files(struct super_block *sb, struct dentry *root);
 int oprofile_timer_init(struct oprofile_operations *ops);
 int oprofile_timer_init(struct oprofile_operations *ops);
 void oprofile_timer_exit(void);
 void oprofile_timer_exit(void);
 
 
-int oprofile_set_backtrace(unsigned long depth);
+int oprofile_set_ulong(unsigned long *addr, unsigned long val);
 int oprofile_set_timeout(unsigned long time);
 int oprofile_set_timeout(unsigned long time);
 
 
 #endif /* OPROF_H */
 #endif /* OPROF_H */

+ 5 - 2
drivers/oprofile/oprofile_files.c

@@ -79,14 +79,17 @@ static ssize_t depth_write(struct file *file, char const __user *buf, size_t cou
 	if (*offset)
 	if (*offset)
 		return -EINVAL;
 		return -EINVAL;
 
 
+	if (!oprofile_ops.backtrace)
+		return -EINVAL;
+
 	retval = oprofilefs_ulong_from_user(&val, buf, count);
 	retval = oprofilefs_ulong_from_user(&val, buf, count);
 	if (retval)
 	if (retval)
 		return retval;
 		return retval;
 
 
-	retval = oprofile_set_backtrace(val);
-
+	retval = oprofile_set_ulong(&oprofile_backtrace_depth, val);
 	if (retval)
 	if (retval)
 		return retval;
 		return retval;
+
 	return count;
 	return count;
 }
 }
 
 

+ 6 - 2
drivers/oprofile/oprofilefs.c

@@ -91,16 +91,20 @@ static ssize_t ulong_read_file(struct file *file, char __user *buf, size_t count
 
 
 static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset)
 static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset)
 {
 {
-	unsigned long *value = file->private_data;
+	unsigned long value;
 	int retval;
 	int retval;
 
 
 	if (*offset)
 	if (*offset)
 		return -EINVAL;
 		return -EINVAL;
 
 
-	retval = oprofilefs_ulong_from_user(value, buf, count);
+	retval = oprofilefs_ulong_from_user(&value, buf, count);
+	if (retval)
+		return retval;
 
 
+	retval = oprofile_set_ulong(file->private_data, value);
 	if (retval)
 	if (retval)
 		return retval;
 		return retval;
+
 	return count;
 	return count;
 }
 }