[PATCH] oprofile: disable write access to oprofilefs whileprofiler is running

From: Robert Richter
Date: Tue Oct 05 2010 - 12:33:55 EST


On 05.10.10 06:36:57, Robert Richter wrote:
> 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.
>
> Cc: Maynard Johnson <maynardj@xxxxxxxxxx>
> Cc: William Cohen <wcohen@xxxxxxxxxx>
> Cc: Suravee Suthikulpanit <suravee.suthikulpanit@xxxxxxx>
> Signed-off-by: Robert Richter <robert.richter@xxxxxxx>
> ---
> drivers/oprofile/oprof.c | 19 +++++--------------
> drivers/oprofile/oprof.h | 2 +-
> drivers/oprofile/oprofile_files.c | 7 +++++--
> drivers/oprofile/oprofilefs.c | 8 ++++++--
> 4 files changed, 17 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
> index b4a6857..a7ab09e 100644
> --- a/drivers/oprofile/oprof.c
> +++ b/drivers/oprofile/oprof.c
> @@ -225,26 +225,17 @@ post_sync:
> 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);
> -
> if (oprofile_started) {

I did a late change which I never should do. It should be:

if (!oprofile_started) ...

The concept remains the same.

Updated patch below.

Sorry,

-Robert

> - err = -EBUSY;
> - goto out;
> - }
> -
> - if (!oprofile_ops.backtrace) {
> - err = -EINVAL;
> - goto out;
> + *addr = val;
> + err = 0;
> }
> -
> - oprofile_backtrace_depth = val;
> -
> -out:
> mutex_unlock(&start_mutex);
> +
> return err;
> }

--