diff mbox series

[3/3] mm/memory: Use exception ip to search exception tables

Message ID 20240201-exception_ip-v1-3-aa26ab3ee0b5@flygoat.com (mailing list archive)
State New
Headers show
Series Handle delay slot for extable lookup | expand

Commit Message

Jiaxun Yang Feb. 1, 2024, 3:46 p.m. UTC
On architectures with delay slot, instruction_pointer() may differ
from where exception was triggered.

Use exception_ip we just introduced to search exception tables to
get rid of the problem.

Fixes: 4bce37a68ff8 ("mips/mm: Convert to using lock_mm_and_find_vma()")
Reported-by: Xi Ruoyao <xry111@xry111.site>
Link: https://lore.kernel.org/r/75e9fd7b08562ad9b456a5bdaacb7cc220311cc9.camel@xry111.site/
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 mm/memory.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

kernel test robot Feb. 3, 2024, 1:15 p.m. UTC | #1
Hi Jiaxun,

kernel test robot noticed the following build errors:

[auto build test ERROR on 06f658aadff0e483ee4f807b0b46c9e5cba62bfa]

url:    https://github.com/intel-lab-lkp/linux/commits/Jiaxun-Yang/ptrace-Introduce-exception_ip-arch-hook/20240201-234906
base:   06f658aadff0e483ee4f807b0b46c9e5cba62bfa
patch link:    https://lore.kernel.org/r/20240201-exception_ip-v1-3-aa26ab3ee0b5%40flygoat.com
patch subject: [PATCH 3/3] mm/memory: Use exception ip to search exception tables
config: i386-buildonly-randconfig-002-20240203 (https://download.01.org/0day-ci/archive/20240203/202402032150.DmM8VjRz-lkp@intel.com/config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240203/202402032150.DmM8VjRz-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202402032150.DmM8VjRz-lkp@intel.com/

All errors (new ones prefixed by >>):

   mm/memory.c: In function 'get_mmap_lock_carefully':
>> mm/memory.c:5484:22: error: implicit declaration of function 'exception_ip' [-Werror=implicit-function-declaration]
      unsigned long ip = exception_ip(regs);
                         ^~~~~~~~~~~~
   cc1: some warnings being treated as errors


vim +/exception_ip +5484 mm/memory.c

  5477	
  5478	static inline bool get_mmap_lock_carefully(struct mm_struct *mm, struct pt_regs *regs)
  5479	{
  5480		if (likely(mmap_read_trylock(mm)))
  5481			return true;
  5482	
  5483		if (regs && !user_mode(regs)) {
> 5484			unsigned long ip = exception_ip(regs);
  5485			if (!search_exception_tables(ip))
  5486				return false;
  5487		}
  5488	
  5489		return !mmap_read_lock_killable(mm);
  5490	}
  5491
kernel test robot Feb. 3, 2024, 1:37 p.m. UTC | #2
Hi Jiaxun,

kernel test robot noticed the following build errors:

[auto build test ERROR on 06f658aadff0e483ee4f807b0b46c9e5cba62bfa]

url:    https://github.com/intel-lab-lkp/linux/commits/Jiaxun-Yang/ptrace-Introduce-exception_ip-arch-hook/20240201-234906
base:   06f658aadff0e483ee4f807b0b46c9e5cba62bfa
patch link:    https://lore.kernel.org/r/20240201-exception_ip-v1-3-aa26ab3ee0b5%40flygoat.com
patch subject: [PATCH 3/3] mm/memory: Use exception ip to search exception tables
config: arm64-randconfig-001-20240203 (https://download.01.org/0day-ci/archive/20240203/202402032112.NBimLx5h-lkp@intel.com/config)
compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240203/202402032112.NBimLx5h-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202402032112.NBimLx5h-lkp@intel.com/

All errors (new ones prefixed by >>):

>> mm/memory.c:5484:22: error: call to undeclared function 'exception_ip'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
                   unsigned long ip = exception_ip(regs);
                                      ^
   mm/memory.c:5509:22: error: call to undeclared function 'exception_ip'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
                   unsigned long ip = exception_ip(regs);
                                      ^
   2 errors generated.


vim +/exception_ip +5484 mm/memory.c

  5477	
  5478	static inline bool get_mmap_lock_carefully(struct mm_struct *mm, struct pt_regs *regs)
  5479	{
  5480		if (likely(mmap_read_trylock(mm)))
  5481			return true;
  5482	
  5483		if (regs && !user_mode(regs)) {
> 5484			unsigned long ip = exception_ip(regs);
  5485			if (!search_exception_tables(ip))
  5486				return false;
  5487		}
  5488	
  5489		return !mmap_read_lock_killable(mm);
  5490	}
  5491
diff mbox series

Patch

diff --git a/mm/memory.c b/mm/memory.c
index 8d14ba440929..49433612444a 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -5481,7 +5481,7 @@  static inline bool get_mmap_lock_carefully(struct mm_struct *mm, struct pt_regs
 		return true;
 
 	if (regs && !user_mode(regs)) {
-		unsigned long ip = instruction_pointer(regs);
+		unsigned long ip = exception_ip(regs);
 		if (!search_exception_tables(ip))
 			return false;
 	}
@@ -5506,7 +5506,7 @@  static inline bool upgrade_mmap_lock_carefully(struct mm_struct *mm, struct pt_r
 {
 	mmap_read_unlock(mm);
 	if (regs && !user_mode(regs)) {
-		unsigned long ip = instruction_pointer(regs);
+		unsigned long ip = exception_ip(regs);
 		if (!search_exception_tables(ip))
 			return false;
 	}