public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [linux-stable-rc:queue/4.19 3886/9999] arch/ia64/kernel/kprobes.c:414:24: error: implicit declaration of function '__kretprobe_trampoline_handler'; did you mean 'kretprobe_trampoline'?
@ 2022-04-12 17:59 kernel test robot
  2022-04-22 13:13 ` Masami Hiramatsu
  2022-04-26 14:25 ` [PATCH 4.19.y 0/3] ia64: kprobes: Fix build error on ia64 Masami Hiramatsu
  0 siblings, 2 replies; 9+ messages in thread
From: kernel test robot @ 2022-04-12 17:59 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: kbuild-all, linux-kernel, Greg Kroah-Hartman, Ingo Molnar,
	Sasha Levin

Hi Masami,

FYI, the error/warning still remains.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git queue/4.19
head:   bdfbd5df0daf1748bef4501ce255ce594ee8d55f
commit: d3380de483d55d904fb94a241406b34ed2fada7d [3886/9999] ia64: kprobes: Use generic kretprobe trampoline handler
config: ia64-allyesconfig (https://download.01.org/0day-ci/archive/20220413/202204130102.JZPa6KCQ-lkp@intel.com/config)
compiler: ia64-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git/commit/?id=d3380de483d55d904fb94a241406b34ed2fada7d
        git remote add linux-stable-rc https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git
        git fetch --no-tags linux-stable-rc queue/4.19
        git checkout d3380de483d55d904fb94a241406b34ed2fada7d
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=ia64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   arch/ia64/kernel/kprobes.c: In function 'get_kprobe_inst':
   arch/ia64/kernel/kprobes.c:338:22: warning: variable 'template' set but not used [-Wunused-but-set-variable]
     338 |         unsigned int template;
         |                      ^~~~~~~~
   arch/ia64/kernel/kprobes.c: At top level:
   arch/ia64/kernel/kprobes.c:412:15: warning: no previous prototype for 'trampoline_probe_handler' [-Wmissing-prototypes]
     412 | int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
         |               ^~~~~~~~~~~~~~~~~~~~~~~~
   arch/ia64/kernel/kprobes.c: In function 'trampoline_probe_handler':
>> arch/ia64/kernel/kprobes.c:414:24: error: implicit declaration of function '__kretprobe_trampoline_handler'; did you mean 'kretprobe_trampoline'? [-Werror=implicit-function-declaration]
     414 |         regs->cr_iip = __kretprobe_trampoline_handler(regs, kretprobe_trampoline, NULL);
         |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |                        kretprobe_trampoline
   At top level:
   arch/ia64/kernel/kprobes.c:928:13: warning: 'ia64_get_bsp_cfm' defined but not used [-Wunused-function]
     928 | static void ia64_get_bsp_cfm(struct unw_frame_info *info, void *arg)
         |             ^~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors

Kconfig warnings: (for reference only)
   WARNING: unmet direct dependencies detected for FRAME_POINTER
   Depends on DEBUG_KERNEL && (M68K || UML || SUPERH) || ARCH_WANT_FRAME_POINTERS
   Selected by
   - FAULT_INJECTION_STACKTRACE_FILTER && FAULT_INJECTION_DEBUG_FS && STACKTRACE_SUPPORT && !X86_64 && !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC && !X86


vim +414 arch/ia64/kernel/kprobes.c

   333	
   334	static void __kprobes get_kprobe_inst(bundle_t *bundle, uint slot,
   335		       	unsigned long *kprobe_inst, uint *major_opcode)
   336	{
   337		unsigned long kprobe_inst_p0, kprobe_inst_p1;
 > 338		unsigned int template;
   339	
   340		template = bundle->quad0.template;
   341	
   342		switch (slot) {
   343		  case 0:
   344			*major_opcode = (bundle->quad0.slot0 >> SLOT0_OPCODE_SHIFT);
   345			*kprobe_inst = bundle->quad0.slot0;
   346			  break;
   347		  case 1:
   348			*major_opcode = (bundle->quad1.slot1_p1 >> SLOT1_p1_OPCODE_SHIFT);
   349			kprobe_inst_p0 = bundle->quad0.slot1_p0;
   350			kprobe_inst_p1 = bundle->quad1.slot1_p1;
   351			*kprobe_inst = kprobe_inst_p0 | (kprobe_inst_p1 << (64-46));
   352			break;
   353		  case 2:
   354			*major_opcode = (bundle->quad1.slot2 >> SLOT2_OPCODE_SHIFT);
   355			*kprobe_inst = bundle->quad1.slot2;
   356			break;
   357		}
   358	}
   359	
   360	/* Returns non-zero if the addr is in the Interrupt Vector Table */
   361	static int __kprobes in_ivt_functions(unsigned long addr)
   362	{
   363		return (addr >= (unsigned long)__start_ivt_text
   364			&& addr < (unsigned long)__end_ivt_text);
   365	}
   366	
   367	static int __kprobes valid_kprobe_addr(int template, int slot,
   368					       unsigned long addr)
   369	{
   370		if ((slot > 2) || ((bundle_encoding[template][1] == L) && slot > 1)) {
   371			printk(KERN_WARNING "Attempting to insert unaligned kprobe "
   372					"at 0x%lx\n", addr);
   373			return -EINVAL;
   374		}
   375	
   376		if (in_ivt_functions(addr)) {
   377			printk(KERN_WARNING "Kprobes can't be inserted inside "
   378					"IVT functions at 0x%lx\n", addr);
   379			return -EINVAL;
   380		}
   381	
   382		return 0;
   383	}
   384	
   385	static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
   386	{
   387		unsigned int i;
   388		i = atomic_add_return(1, &kcb->prev_kprobe_index);
   389		kcb->prev_kprobe[i-1].kp = kprobe_running();
   390		kcb->prev_kprobe[i-1].status = kcb->kprobe_status;
   391	}
   392	
   393	static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
   394	{
   395		unsigned int i;
   396		i = atomic_read(&kcb->prev_kprobe_index);
   397		__this_cpu_write(current_kprobe, kcb->prev_kprobe[i-1].kp);
   398		kcb->kprobe_status = kcb->prev_kprobe[i-1].status;
   399		atomic_sub(1, &kcb->prev_kprobe_index);
   400	}
   401	
   402	static void __kprobes set_current_kprobe(struct kprobe *p,
   403				struct kprobe_ctlblk *kcb)
   404	{
   405		__this_cpu_write(current_kprobe, p);
   406	}
   407	
   408	static void kretprobe_trampoline(void)
   409	{
   410	}
   411	
   412	int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
   413	{
 > 414		regs->cr_iip = __kretprobe_trampoline_handler(regs, kretprobe_trampoline, NULL);
   415		/*
   416		 * By returning a non-zero value, we are telling
   417		 * kprobe_handler() that we don't want the post_handler
   418		 * to run (and have re-enabled preemption)
   419		 */
   420		return 1;
   421	}
   422	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [linux-stable-rc:queue/4.19 3886/9999] arch/ia64/kernel/kprobes.c:414:24: error: implicit declaration of function '__kretprobe_trampoline_handler'; did you mean 'kretprobe_trampoline'?
  2022-04-12 17:59 [linux-stable-rc:queue/4.19 3886/9999] arch/ia64/kernel/kprobes.c:414:24: error: implicit declaration of function '__kretprobe_trampoline_handler'; did you mean 'kretprobe_trampoline'? kernel test robot
@ 2022-04-22 13:13 ` Masami Hiramatsu
  2022-04-25 15:54   ` Greg Kroah-Hartman
  2022-04-26 14:25 ` [PATCH 4.19.y 0/3] ia64: kprobes: Fix build error on ia64 Masami Hiramatsu
  1 sibling, 1 reply; 9+ messages in thread
From: Masami Hiramatsu @ 2022-04-22 13:13 UTC (permalink / raw)
  To: kernel test robot
  Cc: kbuild-all, linux-kernel, Greg Kroah-Hartman, Ingo Molnar,
	Sasha Levin

Hi Greg,

Can you revert/drop this patch from 4.19 stable tree?
This patch is a part of bigger series, which introduces a generic
arch-independent kretprobe trampoline handler, but that is not for the
stable tree.

Also, the commit f5f96e3643dc33d6117cf7047e73512046e4858b is in the 4.19
stable tree, which fixes this commit. Thus that must be removed too.

Thank you,

On Wed, 13 Apr 2022 01:59:56 +0800
kernel test robot <lkp@intel.com> wrote:

> Hi Masami,
> 
> FYI, the error/warning still remains.
> 
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git queue/4.19
> head:   bdfbd5df0daf1748bef4501ce255ce594ee8d55f
> commit: d3380de483d55d904fb94a241406b34ed2fada7d [3886/9999] ia64: kprobes: Use generic kretprobe trampoline handler
> config: ia64-allyesconfig (https://download.01.org/0day-ci/archive/20220413/202204130102.JZPa6KCQ-lkp@intel.com/config)
> compiler: ia64-linux-gcc (GCC) 11.2.0
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git/commit/?id=d3380de483d55d904fb94a241406b34ed2fada7d
>         git remote add linux-stable-rc https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git
>         git fetch --no-tags linux-stable-rc queue/4.19
>         git checkout d3380de483d55d904fb94a241406b34ed2fada7d
>         # save the config file to linux build tree
>         mkdir build_dir
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=ia64 SHELL=/bin/bash
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All errors (new ones prefixed by >>):
> 
>    arch/ia64/kernel/kprobes.c: In function 'get_kprobe_inst':
>    arch/ia64/kernel/kprobes.c:338:22: warning: variable 'template' set but not used [-Wunused-but-set-variable]
>      338 |         unsigned int template;
>          |                      ^~~~~~~~
>    arch/ia64/kernel/kprobes.c: At top level:
>    arch/ia64/kernel/kprobes.c:412:15: warning: no previous prototype for 'trampoline_probe_handler' [-Wmissing-prototypes]
>      412 | int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
>          |               ^~~~~~~~~~~~~~~~~~~~~~~~
>    arch/ia64/kernel/kprobes.c: In function 'trampoline_probe_handler':
> >> arch/ia64/kernel/kprobes.c:414:24: error: implicit declaration of function '__kretprobe_trampoline_handler'; did you mean 'kretprobe_trampoline'? [-Werror=implicit-function-declaration]
>      414 |         regs->cr_iip = __kretprobe_trampoline_handler(regs, kretprobe_trampoline, NULL);
>          |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>          |                        kretprobe_trampoline
>    At top level:
>    arch/ia64/kernel/kprobes.c:928:13: warning: 'ia64_get_bsp_cfm' defined but not used [-Wunused-function]
>      928 | static void ia64_get_bsp_cfm(struct unw_frame_info *info, void *arg)
>          |             ^~~~~~~~~~~~~~~~
>    cc1: some warnings being treated as errors
> 
> Kconfig warnings: (for reference only)
>    WARNING: unmet direct dependencies detected for FRAME_POINTER
>    Depends on DEBUG_KERNEL && (M68K || UML || SUPERH) || ARCH_WANT_FRAME_POINTERS
>    Selected by
>    - FAULT_INJECTION_STACKTRACE_FILTER && FAULT_INJECTION_DEBUG_FS && STACKTRACE_SUPPORT && !X86_64 && !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC && !X86
> 
> 
> vim +414 arch/ia64/kernel/kprobes.c
> 
>    333	
>    334	static void __kprobes get_kprobe_inst(bundle_t *bundle, uint slot,
>    335		       	unsigned long *kprobe_inst, uint *major_opcode)
>    336	{
>    337		unsigned long kprobe_inst_p0, kprobe_inst_p1;
>  > 338		unsigned int template;
>    339	
>    340		template = bundle->quad0.template;
>    341	
>    342		switch (slot) {
>    343		  case 0:
>    344			*major_opcode = (bundle->quad0.slot0 >> SLOT0_OPCODE_SHIFT);
>    345			*kprobe_inst = bundle->quad0.slot0;
>    346			  break;
>    347		  case 1:
>    348			*major_opcode = (bundle->quad1.slot1_p1 >> SLOT1_p1_OPCODE_SHIFT);
>    349			kprobe_inst_p0 = bundle->quad0.slot1_p0;
>    350			kprobe_inst_p1 = bundle->quad1.slot1_p1;
>    351			*kprobe_inst = kprobe_inst_p0 | (kprobe_inst_p1 << (64-46));
>    352			break;
>    353		  case 2:
>    354			*major_opcode = (bundle->quad1.slot2 >> SLOT2_OPCODE_SHIFT);
>    355			*kprobe_inst = bundle->quad1.slot2;
>    356			break;
>    357		}
>    358	}
>    359	
>    360	/* Returns non-zero if the addr is in the Interrupt Vector Table */
>    361	static int __kprobes in_ivt_functions(unsigned long addr)
>    362	{
>    363		return (addr >= (unsigned long)__start_ivt_text
>    364			&& addr < (unsigned long)__end_ivt_text);
>    365	}
>    366	
>    367	static int __kprobes valid_kprobe_addr(int template, int slot,
>    368					       unsigned long addr)
>    369	{
>    370		if ((slot > 2) || ((bundle_encoding[template][1] == L) && slot > 1)) {
>    371			printk(KERN_WARNING "Attempting to insert unaligned kprobe "
>    372					"at 0x%lx\n", addr);
>    373			return -EINVAL;
>    374		}
>    375	
>    376		if (in_ivt_functions(addr)) {
>    377			printk(KERN_WARNING "Kprobes can't be inserted inside "
>    378					"IVT functions at 0x%lx\n", addr);
>    379			return -EINVAL;
>    380		}
>    381	
>    382		return 0;
>    383	}
>    384	
>    385	static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
>    386	{
>    387		unsigned int i;
>    388		i = atomic_add_return(1, &kcb->prev_kprobe_index);
>    389		kcb->prev_kprobe[i-1].kp = kprobe_running();
>    390		kcb->prev_kprobe[i-1].status = kcb->kprobe_status;
>    391	}
>    392	
>    393	static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
>    394	{
>    395		unsigned int i;
>    396		i = atomic_read(&kcb->prev_kprobe_index);
>    397		__this_cpu_write(current_kprobe, kcb->prev_kprobe[i-1].kp);
>    398		kcb->kprobe_status = kcb->prev_kprobe[i-1].status;
>    399		atomic_sub(1, &kcb->prev_kprobe_index);
>    400	}
>    401	
>    402	static void __kprobes set_current_kprobe(struct kprobe *p,
>    403				struct kprobe_ctlblk *kcb)
>    404	{
>    405		__this_cpu_write(current_kprobe, p);
>    406	}
>    407	
>    408	static void kretprobe_trampoline(void)
>    409	{
>    410	}
>    411	
>    412	int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
>    413	{
>  > 414		regs->cr_iip = __kretprobe_trampoline_handler(regs, kretprobe_trampoline, NULL);
>    415		/*
>    416		 * By returning a non-zero value, we are telling
>    417		 * kprobe_handler() that we don't want the post_handler
>    418		 * to run (and have re-enabled preemption)
>    419		 */
>    420		return 1;
>    421	}
>    422	
> 
> -- 
> 0-DAY CI Kernel Test Service
> https://01.org/lkp


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [linux-stable-rc:queue/4.19 3886/9999] arch/ia64/kernel/kprobes.c:414:24: error: implicit declaration of function '__kretprobe_trampoline_handler'; did you mean 'kretprobe_trampoline'?
  2022-04-22 13:13 ` Masami Hiramatsu
@ 2022-04-25 15:54   ` Greg Kroah-Hartman
  2022-04-26  6:47     ` Masami Hiramatsu
  0 siblings, 1 reply; 9+ messages in thread
From: Greg Kroah-Hartman @ 2022-04-25 15:54 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: kernel test robot, kbuild-all, linux-kernel, Ingo Molnar,
	Sasha Levin

On Fri, Apr 22, 2022 at 10:13:12PM +0900, Masami Hiramatsu wrote:
> Hi Greg,
> 
> Can you revert/drop this patch from 4.19 stable tree?

Can you please send a revert as I do not know what commit you are
referring to exactly.

> This patch is a part of bigger series, which introduces a generic
> arch-independent kretprobe trampoline handler, but that is not for the
> stable tree.
> 
> Also, the commit f5f96e3643dc33d6117cf7047e73512046e4858b is in the 4.19
> stable tree, which fixes this commit. Thus that must be removed too.

Same for this, can you send a revert?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [linux-stable-rc:queue/4.19 3886/9999] arch/ia64/kernel/kprobes.c:414:24: error: implicit declaration of function '__kretprobe_trampoline_handler'; did you mean 'kretprobe_trampoline'?
  2022-04-25 15:54   ` Greg Kroah-Hartman
@ 2022-04-26  6:47     ` Masami Hiramatsu
  0 siblings, 0 replies; 9+ messages in thread
From: Masami Hiramatsu @ 2022-04-26  6:47 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: kernel test robot, kbuild-all, linux-kernel, Ingo Molnar,
	Sasha Levin

On Mon, 25 Apr 2022 17:54:59 +0200
Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote:

> On Fri, Apr 22, 2022 at 10:13:12PM +0900, Masami Hiramatsu wrote:
> > Hi Greg,
> > 
> > Can you revert/drop this patch from 4.19 stable tree?
> 
> Can you please send a revert as I do not know what commit you are
> referring to exactly.
> 
> > This patch is a part of bigger series, which introduces a generic
> > arch-independent kretprobe trampoline handler, but that is not for the
> > stable tree.
> > 
> > Also, the commit f5f96e3643dc33d6117cf7047e73512046e4858b is in the 4.19
> > stable tree, which fixes this commit. Thus that must be removed too.
> 
> Same for this, can you send a revert?

OK, let me send it.

Thanks!

> 
> thanks,
> 
> greg k-h


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4.19.y 0/3] ia64: kprobes: Fix build error on ia64
  2022-04-12 17:59 [linux-stable-rc:queue/4.19 3886/9999] arch/ia64/kernel/kprobes.c:414:24: error: implicit declaration of function '__kretprobe_trampoline_handler'; did you mean 'kretprobe_trampoline'? kernel test robot
  2022-04-22 13:13 ` Masami Hiramatsu
@ 2022-04-26 14:25 ` Masami Hiramatsu
  2022-04-26 14:26   ` [PATCH 4.19.y 1/3] Revert "ia64: kprobes: Fix to pass correct trampoline address to the handler" Masami Hiramatsu
                     ` (3 more replies)
  1 sibling, 4 replies; 9+ messages in thread
From: Masami Hiramatsu @ 2022-04-26 14:25 UTC (permalink / raw)
  To: stable, Greg Kroah-Hartman
  Cc: mhiramat, linux-kernel, Ingo Molnar, Sasha Levin

Hi,

Kernel test bot reported that the ia64 build error on stable 4.19.y because
of the commit d3380de483d5 ("ia64: kprobes: Use generic kretprobe trampoline
handler").
I also found that this commit was involved by the backporting of commit
f5f96e3643dc ("ia64: kprobes: Fix to pass correct trampoline address to the
handler"), and this 2nd commit was backported wrong way. Actually, this 2nd
commit aimed to use dereference_function_descriptor() in kprobes@ia64, but
the comment (and Fixes tag) points the 1st commit. Thus I guess this mistake
happened.

So I re-backport the upstream commit a7fe2378454c ("ia64: kprobes: Fix to
pass correct trampoline address to the handler") correctly, without involving
the 1st commit.

Thank you,

---

Masami Hiramatsu (3):
      Revert "ia64: kprobes: Fix to pass correct trampoline address to the handler"
      Revert "ia64: kprobes: Use generic kretprobe trampoline handler"
      ia64: kprobes: Fix to pass correct trampoline address to the handler


 arch/ia64/kernel/kprobes.c |   78 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 75 insertions(+), 3 deletions(-)

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4.19.y 1/3] Revert "ia64: kprobes: Fix to pass correct trampoline address to the handler"
  2022-04-26 14:25 ` [PATCH 4.19.y 0/3] ia64: kprobes: Fix build error on ia64 Masami Hiramatsu
@ 2022-04-26 14:26   ` Masami Hiramatsu
  2022-04-26 14:26   ` [PATCH 4.19.y 2/3] Revert "ia64: kprobes: Use generic kretprobe trampoline handler" Masami Hiramatsu
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Masami Hiramatsu @ 2022-04-26 14:26 UTC (permalink / raw)
  To: stable, Greg Kroah-Hartman
  Cc: mhiramat, linux-kernel, Ingo Molnar, Sasha Levin

This reverts commit f5f96e3643dc33d6117cf7047e73512046e4858b.

The commit f5f96e3643dc ("ia64: kprobes: Fix to pass correct trampoline
address to the handler") was wrongly backported. It involves another
commit which is a part of another bigger series, so it should not be
backported to the stable tree.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 arch/ia64/kernel/kprobes.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/arch/ia64/kernel/kprobes.c b/arch/ia64/kernel/kprobes.c
index 9cfd3ac027b7..8207b897b49d 100644
--- a/arch/ia64/kernel/kprobes.c
+++ b/arch/ia64/kernel/kprobes.c
@@ -411,8 +411,7 @@ static void kretprobe_trampoline(void)
 
 int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
 {
-	regs->cr_iip = __kretprobe_trampoline_handler(regs,
-		dereference_function_descriptor(kretprobe_trampoline), NULL);
+	regs->cr_iip = __kretprobe_trampoline_handler(regs, kretprobe_trampoline, NULL);
 	/*
 	 * By returning a non-zero value, we are telling
 	 * kprobe_handler() that we don't want the post_handler
@@ -428,7 +427,7 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
 	ri->fp = NULL;
 
 	/* Replace the return addr with trampoline addr */
-	regs->b0 = (unsigned long)dereference_function_descriptor(kretprobe_trampoline);
+	regs->b0 = ((struct fnptr *)kretprobe_trampoline)->ip;
 }
 
 /* Check the instruction in the slot is break */
@@ -958,14 +957,14 @@ static struct kprobe trampoline_p = {
 int __init arch_init_kprobes(void)
 {
 	trampoline_p.addr =
-		dereference_function_descriptor(kretprobe_trampoline);
+		(kprobe_opcode_t *)((struct fnptr *)kretprobe_trampoline)->ip;
 	return register_kprobe(&trampoline_p);
 }
 
 int __kprobes arch_trampoline_kprobe(struct kprobe *p)
 {
 	if (p->addr ==
-		dereference_function_descriptor(kretprobe_trampoline))
+		(kprobe_opcode_t *)((struct fnptr *)kretprobe_trampoline)->ip)
 		return 1;
 
 	return 0;


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4.19.y 2/3] Revert "ia64: kprobes: Use generic kretprobe trampoline handler"
  2022-04-26 14:25 ` [PATCH 4.19.y 0/3] ia64: kprobes: Fix build error on ia64 Masami Hiramatsu
  2022-04-26 14:26   ` [PATCH 4.19.y 1/3] Revert "ia64: kprobes: Fix to pass correct trampoline address to the handler" Masami Hiramatsu
@ 2022-04-26 14:26   ` Masami Hiramatsu
  2022-04-26 14:26   ` [PATCH 4.19.y 3/3] ia64: kprobes: Fix to pass correct trampoline address to the handler Masami Hiramatsu
  2022-04-29  8:58   ` [PATCH 4.19.y 0/3] ia64: kprobes: Fix build error on ia64 Greg Kroah-Hartman
  3 siblings, 0 replies; 9+ messages in thread
From: Masami Hiramatsu @ 2022-04-26 14:26 UTC (permalink / raw)
  To: stable, Greg Kroah-Hartman
  Cc: mhiramat, linux-kernel, Ingo Molnar, Sasha Levin

This reverts commit d3380de483d55d904fb94a241406b34ed2fada7d.

Since this commit is a part of generic kretprobe trampoline
handler series, without the other patches in that series, this
causes a build error on ia64.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 arch/ia64/kernel/kprobes.c |   77 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 75 insertions(+), 2 deletions(-)

diff --git a/arch/ia64/kernel/kprobes.c b/arch/ia64/kernel/kprobes.c
index 8207b897b49d..aa41bd5cf9b7 100644
--- a/arch/ia64/kernel/kprobes.c
+++ b/arch/ia64/kernel/kprobes.c
@@ -409,9 +409,83 @@ static void kretprobe_trampoline(void)
 {
 }
 
+/*
+ * At this point the target function has been tricked into
+ * returning into our trampoline.  Lookup the associated instance
+ * and then:
+ *    - call the handler function
+ *    - cleanup by marking the instance as unused
+ *    - long jump back to the original return address
+ */
 int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
 {
-	regs->cr_iip = __kretprobe_trampoline_handler(regs, kretprobe_trampoline, NULL);
+	struct kretprobe_instance *ri = NULL;
+	struct hlist_head *head, empty_rp;
+	struct hlist_node *tmp;
+	unsigned long flags, orig_ret_address = 0;
+	unsigned long trampoline_address =
+		((struct fnptr *)kretprobe_trampoline)->ip;
+
+	INIT_HLIST_HEAD(&empty_rp);
+	kretprobe_hash_lock(current, &head, &flags);
+
+	/*
+	 * It is possible to have multiple instances associated with a given
+	 * task either because an multiple functions in the call path
+	 * have a return probe installed on them, and/or more than one return
+	 * return probe was registered for a target function.
+	 *
+	 * We can handle this because:
+	 *     - instances are always inserted at the head of the list
+	 *     - when multiple return probes are registered for the same
+	 *       function, the first instance's ret_addr will point to the
+	 *       real return address, and all the rest will point to
+	 *       kretprobe_trampoline
+	 */
+	hlist_for_each_entry_safe(ri, tmp, head, hlist) {
+		if (ri->task != current)
+			/* another task is sharing our hash bucket */
+			continue;
+
+		orig_ret_address = (unsigned long)ri->ret_addr;
+		if (orig_ret_address != trampoline_address)
+			/*
+			 * This is the real return address. Any other
+			 * instances associated with this task are for
+			 * other calls deeper on the call stack
+			 */
+			break;
+	}
+
+	regs->cr_iip = orig_ret_address;
+
+	hlist_for_each_entry_safe(ri, tmp, head, hlist) {
+		if (ri->task != current)
+			/* another task is sharing our hash bucket */
+			continue;
+
+		if (ri->rp && ri->rp->handler)
+			ri->rp->handler(ri, regs);
+
+		orig_ret_address = (unsigned long)ri->ret_addr;
+		recycle_rp_inst(ri, &empty_rp);
+
+		if (orig_ret_address != trampoline_address)
+			/*
+			 * This is the real return address. Any other
+			 * instances associated with this task are for
+			 * other calls deeper on the call stack
+			 */
+			break;
+	}
+	kretprobe_assert(ri, orig_ret_address, trampoline_address);
+
+	kretprobe_hash_unlock(current, &flags);
+
+	hlist_for_each_entry_safe(ri, tmp, &empty_rp, hlist) {
+		hlist_del(&ri->hlist);
+		kfree(ri);
+	}
 	/*
 	 * By returning a non-zero value, we are telling
 	 * kprobe_handler() that we don't want the post_handler
@@ -424,7 +498,6 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
 				      struct pt_regs *regs)
 {
 	ri->ret_addr = (kprobe_opcode_t *)regs->b0;
-	ri->fp = NULL;
 
 	/* Replace the return addr with trampoline addr */
 	regs->b0 = ((struct fnptr *)kretprobe_trampoline)->ip;


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4.19.y 3/3] ia64: kprobes: Fix to pass correct trampoline address to the handler
  2022-04-26 14:25 ` [PATCH 4.19.y 0/3] ia64: kprobes: Fix build error on ia64 Masami Hiramatsu
  2022-04-26 14:26   ` [PATCH 4.19.y 1/3] Revert "ia64: kprobes: Fix to pass correct trampoline address to the handler" Masami Hiramatsu
  2022-04-26 14:26   ` [PATCH 4.19.y 2/3] Revert "ia64: kprobes: Use generic kretprobe trampoline handler" Masami Hiramatsu
@ 2022-04-26 14:26   ` Masami Hiramatsu
  2022-04-29  8:58   ` [PATCH 4.19.y 0/3] ia64: kprobes: Fix build error on ia64 Greg Kroah-Hartman
  3 siblings, 0 replies; 9+ messages in thread
From: Masami Hiramatsu @ 2022-04-26 14:26 UTC (permalink / raw)
  To: stable, Greg Kroah-Hartman
  Cc: mhiramat, linux-kernel, Ingo Molnar, Sasha Levin

commit a7fe2378454cf46cd5e2776d05e72bbe8f0a468c upstream.

The following commit:

   Commit e792ff804f49 ("ia64: kprobes: Use generic kretprobe trampoline handler")

Passed the wrong trampoline address to __kretprobe_trampoline_handler(): it
passes the descriptor address instead of function entry address.

Pass the right parameter.

Also use correct symbol dereference function to get the function address
from 'kretprobe_trampoline' - an IA64 special.

Link: https://lkml.kernel.org/r/163163042696.489837.12551102356265354730.stgit@devnote2

Fixes: e792ff804f49 ("ia64: kprobes: Use generic kretprobe trampoline handler")
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: X86 ML <x86@kernel.org>
Cc: Daniel Xu <dxu@dxuuu.xyz>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Abhishek Sagar <sagar.abhishek@gmail.com>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Paul McKenney <paulmck@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 arch/ia64/kernel/kprobes.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/ia64/kernel/kprobes.c b/arch/ia64/kernel/kprobes.c
index aa41bd5cf9b7..7fc0806bbdc9 100644
--- a/arch/ia64/kernel/kprobes.c
+++ b/arch/ia64/kernel/kprobes.c
@@ -424,7 +424,7 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
 	struct hlist_node *tmp;
 	unsigned long flags, orig_ret_address = 0;
 	unsigned long trampoline_address =
-		((struct fnptr *)kretprobe_trampoline)->ip;
+		(unsigned long)dereference_function_descriptor(kretprobe_trampoline);
 
 	INIT_HLIST_HEAD(&empty_rp);
 	kretprobe_hash_lock(current, &head, &flags);
@@ -500,7 +500,7 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
 	ri->ret_addr = (kprobe_opcode_t *)regs->b0;
 
 	/* Replace the return addr with trampoline addr */
-	regs->b0 = ((struct fnptr *)kretprobe_trampoline)->ip;
+	regs->b0 = (unsigned long)dereference_function_descriptor(kretprobe_trampoline);
 }
 
 /* Check the instruction in the slot is break */
@@ -1030,14 +1030,14 @@ static struct kprobe trampoline_p = {
 int __init arch_init_kprobes(void)
 {
 	trampoline_p.addr =
-		(kprobe_opcode_t *)((struct fnptr *)kretprobe_trampoline)->ip;
+		dereference_function_descriptor(kretprobe_trampoline);
 	return register_kprobe(&trampoline_p);
 }
 
 int __kprobes arch_trampoline_kprobe(struct kprobe *p)
 {
 	if (p->addr ==
-		(kprobe_opcode_t *)((struct fnptr *)kretprobe_trampoline)->ip)
+		dereference_function_descriptor(kretprobe_trampoline))
 		return 1;
 
 	return 0;


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 4.19.y 0/3] ia64: kprobes: Fix build error on ia64
  2022-04-26 14:25 ` [PATCH 4.19.y 0/3] ia64: kprobes: Fix build error on ia64 Masami Hiramatsu
                     ` (2 preceding siblings ...)
  2022-04-26 14:26   ` [PATCH 4.19.y 3/3] ia64: kprobes: Fix to pass correct trampoline address to the handler Masami Hiramatsu
@ 2022-04-29  8:58   ` Greg Kroah-Hartman
  3 siblings, 0 replies; 9+ messages in thread
From: Greg Kroah-Hartman @ 2022-04-29  8:58 UTC (permalink / raw)
  To: Masami Hiramatsu; +Cc: stable, linux-kernel, Ingo Molnar, Sasha Levin

On Tue, Apr 26, 2022 at 11:25:54PM +0900, Masami Hiramatsu wrote:
> Hi,
> 
> Kernel test bot reported that the ia64 build error on stable 4.19.y because
> of the commit d3380de483d5 ("ia64: kprobes: Use generic kretprobe trampoline
> handler").
> I also found that this commit was involved by the backporting of commit
> f5f96e3643dc ("ia64: kprobes: Fix to pass correct trampoline address to the
> handler"), and this 2nd commit was backported wrong way. Actually, this 2nd
> commit aimed to use dereference_function_descriptor() in kprobes@ia64, but
> the comment (and Fixes tag) points the 1st commit. Thus I guess this mistake
> happened.
> 
> So I re-backport the upstream commit a7fe2378454c ("ia64: kprobes: Fix to
> pass correct trampoline address to the handler") correctly, without involving
> the 1st commit.
> 
> Thank you,

All now queued up, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-04-29  8:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-12 17:59 [linux-stable-rc:queue/4.19 3886/9999] arch/ia64/kernel/kprobes.c:414:24: error: implicit declaration of function '__kretprobe_trampoline_handler'; did you mean 'kretprobe_trampoline'? kernel test robot
2022-04-22 13:13 ` Masami Hiramatsu
2022-04-25 15:54   ` Greg Kroah-Hartman
2022-04-26  6:47     ` Masami Hiramatsu
2022-04-26 14:25 ` [PATCH 4.19.y 0/3] ia64: kprobes: Fix build error on ia64 Masami Hiramatsu
2022-04-26 14:26   ` [PATCH 4.19.y 1/3] Revert "ia64: kprobes: Fix to pass correct trampoline address to the handler" Masami Hiramatsu
2022-04-26 14:26   ` [PATCH 4.19.y 2/3] Revert "ia64: kprobes: Use generic kretprobe trampoline handler" Masami Hiramatsu
2022-04-26 14:26   ` [PATCH 4.19.y 3/3] ia64: kprobes: Fix to pass correct trampoline address to the handler Masami Hiramatsu
2022-04-29  8:58   ` [PATCH 4.19.y 0/3] ia64: kprobes: Fix build error on ia64 Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox