mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Ingo Molnar <mingo@elte.hu>,
	Masami Hiramatsu <mhiramat@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Use test_and_clear_bit() instead atomic_dec_and_test() for stop_machine
Date: Tue, 22 May 2012 17:46:33 -0400	[thread overview]
Message-ID: <20120522214633.GB30024@home.goodmis.org> (raw)
In-Reply-To: <87ehqct7a3.fsf@devron.myhome.or.jp>

On Wed, May 23, 2012 at 03:11:48AM +0900, OGAWA Hirofumi wrote:
> [forgot to Cc: lkml, resend]
> 
> Hi,
> 
> Maybe, nobody using debug patch in atomic_dec_and_test()...  Well,
> anyway, how about this?

What debug patch?

> 
> 
> 
> stop_machine_first is just to see if it is first one or not.  So, there
> is no reason to use atomic_dec_and_test(), and makes the value below 0.
> 
> I think it is not desirable, because this usage only triggers
> atomic_dec_and_test() underflow debug patch. (the patch tests result
> of atomic_dec_and_test() is < 0)

Well it should only underflow if you have a box with more than 2 billion
CPUs.

> 
> So, this uses test_and_clear_bit() instead.
> 
> Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
> ---
> 
>  arch/x86/kernel/alternative.c |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff -puN arch/x86/kernel/alternative.c~stop_machine-use-test_and_set_bit arch/x86/kernel/alternative.c
> --- linux/arch/x86/kernel/alternative.c~stop_machine-use-test_and_set_bit	2012-05-23 02:48:01.000000000 +0900
> +++ linux-hirofumi/arch/x86/kernel/alternative.c	2012-05-23 02:48:01.000000000 +0900
> @@ -650,7 +650,7 @@ void *__kprobes text_poke(void *addr, co
>   * Cross-modifying kernel text with stop_machine().
>   * This code originally comes from immediate value.
>   */
> -static atomic_t stop_machine_first;
> +static unsigned long stop_machine_first;

The down side to this is that it adds 4 more bytes on a 64bit
machine. (sizeof(unsigned log) == 8 and sizeof(atomic_t) == 4)

You could probably also set it to -1, and do a atomic_inc_and_test(),
would that also cause the debug to trigger too?

-- Steve

>  static int wrote_text;
>  
>  struct text_poke_params {
> @@ -664,7 +664,7 @@ static int __kprobes stop_machine_text_p
>  	struct text_poke_param *p;
>  	int i;
>  
> -	if (atomic_dec_and_test(&stop_machine_first)) {
> +	if (test_and_clear_bit(0, &stop_machine_first)) {
>  		for (i = 0; i < tpp->nparams; i++) {
>  			p = &tpp->params[i];
>  			text_poke(p->addr, p->opcode, p->len);
> @@ -714,7 +714,7 @@ void *__kprobes text_poke_smp(void *addr
>  	p.len = len;
>  	tpp.params = &p;
>  	tpp.nparams = 1;
> -	atomic_set(&stop_machine_first, 1);
> +	stop_machine_first = 1;
>  	wrote_text = 0;
>  	/* Use __stop_machine() because the caller already got online_cpus. */
>  	__stop_machine(stop_machine_text_poke, (void *)&tpp, cpu_online_mask);
> @@ -736,7 +736,7 @@ void __kprobes text_poke_smp_batch(struc
>  {
>  	struct text_poke_params tpp = {.params = params, .nparams = n};
>  
> -	atomic_set(&stop_machine_first, 1);
> +	stop_machine_first = 1;
>  	wrote_text = 0;
>  	__stop_machine(stop_machine_text_poke, (void *)&tpp, cpu_online_mask);
>  }

  reply	other threads:[~2012-05-22 21:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87likkt7u6.fsf@devron.myhome.or.jp>
2012-05-22 18:11 ` OGAWA Hirofumi
2012-05-22 21:46   ` Steven Rostedt [this message]
2012-05-23  2:44     ` OGAWA Hirofumi
2012-05-23  4:19       ` OGAWA Hirofumi
2012-05-23  8:43         ` Steven Rostedt
2012-06-07 12:54         ` Steven Rostedt
2012-06-07 13:18           ` OGAWA Hirofumi

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=20120522214633.GB30024@home.goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@redhat.com \
    --cc=mingo@elte.hu \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®