From: Ralf Baechle <ralf@linux-mips.org>
To: Jerin Jacob <jerinjacobk@gmail.com>
Cc: linux-mips@linux-mips.org, mbhat@netlogicmicro.com,
jchandra@broadcom.com
Subject: Re: [PATCH] MIPS: oprofile: Fix for BUG: using smp_processor_id() in preemptible [00000000] code: oprofiled/1362
Date: Thu, 1 Aug 2013 18:31:05 +0200 [thread overview]
Message-ID: <20130801163105.GC23583@linux-mips.org> (raw)
In-Reply-To: <1375369841-16427-1-git-send-email-jerinjacobk@gmail.com>
On Thu, Aug 01, 2013 at 08:40:41PM +0530, Jerin Jacob wrote:
> current_cpu_type() is not preemption-safe.
> If CONFIG_PREEMPT is enabled then mipsxx_reg_setup() can be called from preemptible state.
> Added get_cpu()/put_cpu() pair to make it preemption-safe.
>
> This was found while testing oprofile with CONFIG_DEBUG_PREEMPT enable.
[...]
Interesting. I wonder how many more of this kind of bug we got lurking
around.
In case of oprofile, we silently assume that all processors have the same
number of counters, the same style and number of counters. So it'd be
ok to just look at the boot CPU which is even simpler than your fix.
What do you think about below fix?
Thanks,
Ralf
arch/mips/include/asm/cpu-features.h | 2 ++
arch/mips/oprofile/op_model_mipsxx.c | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/mips/include/asm/cpu-features.h b/arch/mips/include/asm/cpu-features.h
index 1dc0860..fa44f3e 100644
--- a/arch/mips/include/asm/cpu-features.h
+++ b/arch/mips/include/asm/cpu-features.h
@@ -17,6 +17,8 @@
#define current_cpu_type() current_cpu_data.cputype
#endif
+#define boot_cpu_type() cpu_data[0].cputype
+
/*
* SMP assumption: Options of CPU 0 are a superset of all processors.
* This is true for all known MIPS systems.
diff --git a/arch/mips/oprofile/op_model_mipsxx.c b/arch/mips/oprofile/op_model_mipsxx.c
index e4b1140..3a2b6e9 100644
--- a/arch/mips/oprofile/op_model_mipsxx.c
+++ b/arch/mips/oprofile/op_model_mipsxx.c
@@ -166,7 +166,7 @@ static void mipsxx_reg_setup(struct op_counter_config *ctr)
reg.control[i] |= M_PERFCTL_USER;
if (ctr[i].exl)
reg.control[i] |= M_PERFCTL_EXL;
- if (current_cpu_type() == CPU_XLR)
+ if (boot_cpu_type() == CPU_XLR)
reg.control[i] |= M_PERFCTL_COUNT_ALL_THREADS;
reg.counter[i] = 0x80000000 - ctr[i].count;
}
next prev parent reply other threads:[~2013-08-01 16:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-01 15:10 [PATCH] MIPS: oprofile: Fix for BUG: using smp_processor_id() in preemptible [00000000] code: oprofiled/1362 Jerin Jacob
2013-08-01 16:31 ` Ralf Baechle [this message]
2013-08-02 10:27 ` Jerin Jacob
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130801163105.GC23583@linux-mips.org \
--to=ralf@linux-mips.org \
--cc=jchandra@broadcom.com \
--cc=jerinjacobk@gmail.com \
--cc=linux-mips@linux-mips.org \
--cc=mbhat@netlogicmicro.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.