linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Yang Jihong <yangjihong1@huawei.com>
Cc: <tglx@linutronix.de>, <mingo@redhat.com>, <bp@alien8.de>,
	<dave.hansen@linux.intel.com>, <x86@kernel.org>, <hpa@zytor.com>,
	<naveen.n.rao@linux.ibm.com>, <anil.s.keshavamurthy@intel.com>,
	<davem@davemloft.net>, <ast@kernel.org>, <peterz@infradead.org>,
	<linux-kernel@vger.kernel.org>,
	<linux-trace-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/3] x86/kprobes: Fix __recover_optprobed_insn check optimizing logic
Date: Thu, 16 Feb 2023 00:08:49 +0900	[thread overview]
Message-ID: <20230216000849.f0e332ebf35150cb5d5c4a29@kernel.org> (raw)
In-Reply-To: <20230215115430.236046-3-yangjihong1@huawei.com>

On Wed, 15 Feb 2023 19:54:29 +0800
Yang Jihong <yangjihong1@huawei.com> wrote:

> Since the following commit:
> 
>   commit f66c0447cca1 ("kprobes: Set unoptimized flag after unoptimizing code")
> 
> modified the update timing of the KPROBE_FLAG_OPTIMIZED, a optimized_kprobe
> may be in the optimizing or unoptimizing state when op.kp->flags
> has KPROBE_FLAG_OPTIMIZED and op->list is not empty.
> 
> The __recover_optprobed_insn check logic is incorrect, a kprobe in the
> unoptimizing state may be incorrectly determined as unoptimizing.
> As a result, incorrect instructions are copied.

Ah, good catch!

> 
> The optprobe_queued_unopt function needs to be exported for invoking in
> arch directory.
> 
> Fixes: f66c0447cca1 ("kprobes: Set unoptimized flag after unoptimizing code")

Cc: stable@vger.kernel.org

> Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
> ---
>  arch/x86/kernel/kprobes/opt.c | 4 ++--
>  include/linux/kprobes.h       | 1 +
>  kernel/kprobes.c              | 2 +-
>  3 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
> index e57e07b0edb6..3718d6863555 100644
> --- a/arch/x86/kernel/kprobes/opt.c
> +++ b/arch/x86/kernel/kprobes/opt.c
> @@ -46,8 +46,8 @@ unsigned long __recover_optprobed_insn(kprobe_opcode_t *buf, unsigned long addr)
>  		/* This function only handles jump-optimized kprobe */
>  		if (kp && kprobe_optimized(kp)) {
>  			op = container_of(kp, struct optimized_kprobe, kp);
> -			/* If op->list is not empty, op is under optimizing */
> -			if (list_empty(&op->list))
> +			/* If op is [un]optimized or under unoptimizing */

Hmm, this is a bit confusing comment. If it is unoptimized, the kprobe_optimized() returns false.
Thus the comment should be /* If op is optimized or under unoptimizing */.

Thank you,

> +			if (list_empty(&op->list) || optprobe_queued_unopt(op))
>  				goto found;
>  		}
>  	}
> diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
> index a0b92be98984..ab39285f71a6 100644
> --- a/include/linux/kprobes.h
> +++ b/include/linux/kprobes.h
> @@ -378,6 +378,7 @@ extern void opt_pre_handler(struct kprobe *p, struct pt_regs *regs);
>  DEFINE_INSN_CACHE_OPS(optinsn);
>  
>  extern void wait_for_kprobe_optimizer(void);
> +bool optprobe_queued_unopt(struct optimized_kprobe *op);
>  #else /* !CONFIG_OPTPROBES */
>  static inline void wait_for_kprobe_optimizer(void) { }
>  #endif /* CONFIG_OPTPROBES */
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 0730e595f4c1..bf60eb26c873 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -661,7 +661,7 @@ void wait_for_kprobe_optimizer(void)
>  	mutex_unlock(&kprobe_mutex);
>  }
>  
> -static bool optprobe_queued_unopt(struct optimized_kprobe *op)
> +bool optprobe_queued_unopt(struct optimized_kprobe *op)
>  {
>  	struct optimized_kprobe *_op;
>  
> -- 
> 2.30.GIT
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

  reply	other threads:[~2023-02-15 15:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-15 11:54 [PATCH 0/3] kprobes: Fix issues related to optkprobe Yang Jihong
2023-02-15 11:54 ` [PATCH 1/3] kprobes: Fixed probe nodes not correctly removed when forcibly unoptimized Yang Jihong
2023-02-15 14:55   ` Masami Hiramatsu
2023-02-16  2:52     ` Yang Jihong
2023-02-15 11:54 ` [PATCH 2/3] x86/kprobes: Fix __recover_optprobed_insn check optimizing logic Yang Jihong
2023-02-15 15:08   ` Masami Hiramatsu [this message]
2023-02-16  2:53     ` Yang Jihong
2023-02-15 11:54 ` [PATCH 3/3] x86/kprobes: Fix arch_check_optimized_kprobe check within optimized_kprobe range Yang Jihong
2023-02-15 15:48   ` Masami Hiramatsu
2023-02-16  2:56     ` Yang Jihong

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=20230216000849.f0e332ebf35150cb5d5c4a29@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=anil.s.keshavamurthy@intel.com \
    --cc=ast@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=naveen.n.rao@linux.ibm.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=yangjihong1@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).