All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/9] sections: Unify kernel sections range check and use
@ 2021-06-26  7:34 ` Kefeng Wang
  0 siblings, 0 replies; 24+ messages in thread
From: Kefeng Wang @ 2021-06-26  7:34 UTC (permalink / raw)
  To: Arnd Bergmann, linux-arch, linux-kernel
  Cc: Kefeng Wang, linuxppc-dev, linux-s390, iommu, bpf

There are three head files(kallsyms.h, kernel.h and sections.h) which
include the kernel sections range check, let's make some cleanup and
unify them.

1. cleanup arch specific text/data check and fix address boundary check in kallsyms.h
2. make all the basic kernel range check function into sections.h
3. update all the callers, and use the helper in sections.h to simplify the code
4. use memory_intersects() in sections.h instead of private overlap for dma-debug

Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-s390@vger.kernel.org
Cc: linux-arch@vger.kernel.org 
Cc: iommu@lists.linux-foundation.org
Cc: bpf@vger.kernel.org 

Kefeng Wang (9):
  kallsyms: Remove arch specific text and data check
  kallsyms: Fix address-checks for kernel related range
  sections: Move and rename core_kernel_data() to is_kernel_data()
  sections: Move is_kernel_inittext() into sections.h
  kallsyms: Rename is_kernel() and is_kernel_text()
  sections: Add new is_kernel() and is_kernel_text()
  s390: kprobes: Use is_kernel() helper
  powerpc/mm: Use is_kernel_text() and is_kernel_inittext() helper
  dma-debug: Use memory_intersects() directly

 arch/powerpc/mm/pgtable_32.c   |  7 +---
 arch/s390/kernel/kprobes.c     |  9 +----
 arch/x86/kernel/unwind_orc.c   |  2 +-
 arch/x86/net/bpf_jit_comp.c    |  2 +-
 include/asm-generic/sections.h | 71 ++++++++++++++++++++++++++--------
 include/linux/kallsyms.h       | 21 +++-------
 include/linux/kernel.h         |  2 -
 kernel/cfi.c                   |  2 +-
 kernel/dma/debug.c             | 14 +------
 kernel/extable.c               | 33 ++--------------
 kernel/locking/lockdep.c       |  3 --
 kernel/trace/ftrace.c          |  2 +-
 mm/kasan/report.c              |  2 +-
 net/sysctl_net.c               |  2 +-
 14 files changed, 76 insertions(+), 96 deletions(-)

-- 
2.26.2


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

* [PATCH 0/9] sections: Unify kernel sections range check and use
@ 2021-06-26  7:34 ` Kefeng Wang
  0 siblings, 0 replies; 24+ messages in thread
From: Kefeng Wang @ 2021-06-26  7:34 UTC (permalink / raw)
  To: Arnd Bergmann, linux-arch, linux-kernel
  Cc: linux-s390, Kefeng Wang, bpf, linuxppc-dev, iommu

There are three head files(kallsyms.h, kernel.h and sections.h) which
include the kernel sections range check, let's make some cleanup and
unify them.

1. cleanup arch specific text/data check and fix address boundary check in kallsyms.h
2. make all the basic kernel range check function into sections.h
3. update all the callers, and use the helper in sections.h to simplify the code
4. use memory_intersects() in sections.h instead of private overlap for dma-debug

Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-s390@vger.kernel.org
Cc: linux-arch@vger.kernel.org 
Cc: iommu@lists.linux-foundation.org
Cc: bpf@vger.kernel.org 

Kefeng Wang (9):
  kallsyms: Remove arch specific text and data check
  kallsyms: Fix address-checks for kernel related range
  sections: Move and rename core_kernel_data() to is_kernel_data()
  sections: Move is_kernel_inittext() into sections.h
  kallsyms: Rename is_kernel() and is_kernel_text()
  sections: Add new is_kernel() and is_kernel_text()
  s390: kprobes: Use is_kernel() helper
  powerpc/mm: Use is_kernel_text() and is_kernel_inittext() helper
  dma-debug: Use memory_intersects() directly

 arch/powerpc/mm/pgtable_32.c   |  7 +---
 arch/s390/kernel/kprobes.c     |  9 +----
 arch/x86/kernel/unwind_orc.c   |  2 +-
 arch/x86/net/bpf_jit_comp.c    |  2 +-
 include/asm-generic/sections.h | 71 ++++++++++++++++++++++++++--------
 include/linux/kallsyms.h       | 21 +++-------
 include/linux/kernel.h         |  2 -
 kernel/cfi.c                   |  2 +-
 kernel/dma/debug.c             | 14 +------
 kernel/extable.c               | 33 ++--------------
 kernel/locking/lockdep.c       |  3 --
 kernel/trace/ftrace.c          |  2 +-
 mm/kasan/report.c              |  2 +-
 net/sysctl_net.c               |  2 +-
 14 files changed, 76 insertions(+), 96 deletions(-)

-- 
2.26.2


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

* [PATCH 0/9] sections: Unify kernel sections range check and use
@ 2021-06-26  7:34 ` Kefeng Wang
  0 siblings, 0 replies; 24+ messages in thread
From: Kefeng Wang @ 2021-06-26  7:34 UTC (permalink / raw)
  To: Arnd Bergmann, linux-arch, linux-kernel
  Cc: linux-s390, Kefeng Wang, bpf, linuxppc-dev, iommu

There are three head files(kallsyms.h, kernel.h and sections.h) which
include the kernel sections range check, let's make some cleanup and
unify them.

1. cleanup arch specific text/data check and fix address boundary check in kallsyms.h
2. make all the basic kernel range check function into sections.h
3. update all the callers, and use the helper in sections.h to simplify the code
4. use memory_intersects() in sections.h instead of private overlap for dma-debug

Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-s390@vger.kernel.org
Cc: linux-arch@vger.kernel.org 
Cc: iommu@lists.linux-foundation.org
Cc: bpf@vger.kernel.org 

Kefeng Wang (9):
  kallsyms: Remove arch specific text and data check
  kallsyms: Fix address-checks for kernel related range
  sections: Move and rename core_kernel_data() to is_kernel_data()
  sections: Move is_kernel_inittext() into sections.h
  kallsyms: Rename is_kernel() and is_kernel_text()
  sections: Add new is_kernel() and is_kernel_text()
  s390: kprobes: Use is_kernel() helper
  powerpc/mm: Use is_kernel_text() and is_kernel_inittext() helper
  dma-debug: Use memory_intersects() directly

 arch/powerpc/mm/pgtable_32.c   |  7 +---
 arch/s390/kernel/kprobes.c     |  9 +----
 arch/x86/kernel/unwind_orc.c   |  2 +-
 arch/x86/net/bpf_jit_comp.c    |  2 +-
 include/asm-generic/sections.h | 71 ++++++++++++++++++++++++++--------
 include/linux/kallsyms.h       | 21 +++-------
 include/linux/kernel.h         |  2 -
 kernel/cfi.c                   |  2 +-
 kernel/dma/debug.c             | 14 +------
 kernel/extable.c               | 33 ++--------------
 kernel/locking/lockdep.c       |  3 --
 kernel/trace/ftrace.c          |  2 +-
 mm/kasan/report.c              |  2 +-
 net/sysctl_net.c               |  2 +-
 14 files changed, 76 insertions(+), 96 deletions(-)

-- 
2.26.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH 1/9] kallsyms: Remove arch specific text and data check
  2021-06-26  7:34 ` Kefeng Wang
  (?)
  (?)
@ 2021-06-26  7:34 ` Kefeng Wang
  -1 siblings, 0 replies; 24+ messages in thread
From: Kefeng Wang @ 2021-06-26  7:34 UTC (permalink / raw)
  To: Arnd Bergmann, linux-arch, linux-kernel; +Cc: Kefeng Wang

After commit 4ba66a976072 ("arch: remove blackfin port"),
no need arch-specific text/data check.

Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 include/asm-generic/sections.h | 16 ----------------
 include/linux/kallsyms.h       |  3 +--
 kernel/locking/lockdep.c       |  3 ---
 3 files changed, 1 insertion(+), 21 deletions(-)

diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index d16302d3eb59..817309e289db 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -64,22 +64,6 @@ extern __visible const void __nosave_begin, __nosave_end;
 #define dereference_kernel_function_descriptor(p) ((void *)(p))
 #endif
 
-/* random extra sections (if any).  Override
- * in asm/sections.h */
-#ifndef arch_is_kernel_text
-static inline int arch_is_kernel_text(unsigned long addr)
-{
-	return 0;
-}
-#endif
-
-#ifndef arch_is_kernel_data
-static inline int arch_is_kernel_data(unsigned long addr)
-{
-	return 0;
-}
-#endif
-
 /*
  * Check if an address is part of freed initmem. This is needed on architectures
  * with virt == phys kernel mapping, for code that wants to check if an address
diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index 1a7968cf7679..d773732cc8eb 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -33,8 +33,7 @@ static inline int is_kernel_inittext(unsigned long addr)
 
 static inline int is_kernel_text(unsigned long addr)
 {
-	if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
-	    arch_is_kernel_text(addr))
+	if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext))
 		return 1;
 	return in_gate_area_no_mm(addr);
 }
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 922288b7c03d..8a9c6c9fd0a3 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -803,9 +803,6 @@ static int static_obj(const void *obj)
 	if ((addr >= start) && (addr < end))
 		return 1;
 
-	if (arch_is_kernel_data(addr))
-		return 1;
-
 	/*
 	 * in-kernel percpu var?
 	 */
-- 
2.26.2


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

* [PATCH 2/9] kallsyms: Fix address-checks for kernel related range
  2021-06-26  7:34 ` Kefeng Wang
                   ` (2 preceding siblings ...)
  (?)
@ 2021-06-26  7:34 ` Kefeng Wang
  2021-07-05  3:35   ` Sergey Senozhatsky
  2021-07-07 12:43   ` Petr Mladek
  -1 siblings, 2 replies; 24+ messages in thread
From: Kefeng Wang @ 2021-06-26  7:34 UTC (permalink / raw)
  To: Arnd Bergmann, linux-arch, linux-kernel
  Cc: Kefeng Wang, Sergey Senozhatsky, Petr Mladek

The is_kernel_inittext/is_kernel_text/is_kernel function should not
include the end address(the labels _einittext, _etext and _end) when
check the address range.

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Petr Mladek <pmladek@suse.com>
Fixes: 04b8eb7a4ccd ("symbol lookup: introduce dereference_symbol_descriptor()")
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 include/linux/kallsyms.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index d773732cc8eb..c44c26977805 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -26,21 +26,21 @@ struct module;
 static inline int is_kernel_inittext(unsigned long addr)
 {
 	if (addr >= (unsigned long)_sinittext
-	    && addr <= (unsigned long)_einittext)
+	    && addr < (unsigned long)_einittext)
 		return 1;
 	return 0;
 }
 
 static inline int is_kernel_text(unsigned long addr)
 {
-	if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext))
+	if ((addr >= (unsigned long)_stext && addr < (unsigned long)_etext))
 		return 1;
 	return in_gate_area_no_mm(addr);
 }
 
 static inline int is_kernel(unsigned long addr)
 {
-	if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
+	if (addr >= (unsigned long)_stext && addr < (unsigned long)_end)
 		return 1;
 	return in_gate_area_no_mm(addr);
 }
-- 
2.26.2


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

* [PATCH 3/9] sections: Move and rename core_kernel_data() to is_kernel_data()
  2021-06-26  7:34 ` Kefeng Wang
                   ` (3 preceding siblings ...)
  (?)
@ 2021-06-26  7:34 ` Kefeng Wang
  2021-06-29  1:05   ` Steven Rostedt
  -1 siblings, 1 reply; 24+ messages in thread
From: Kefeng Wang @ 2021-06-26  7:34 UTC (permalink / raw)
  To: Arnd Bergmann, linux-arch, linux-kernel
  Cc: Kefeng Wang, Steven Rostedt, Ingo Molnar, David S. Miller

Move core_kernel_data() into sections.h and rename it to
is_kernel_data(), also make it return bool value, then
update all the callers.

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 include/asm-generic/sections.h | 14 ++++++++++++++
 include/linux/kernel.h         |  1 -
 kernel/extable.c               | 18 ------------------
 kernel/trace/ftrace.c          |  2 +-
 net/sysctl_net.c               |  2 +-
 5 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 817309e289db..5727e67f4b7a 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -142,6 +142,20 @@ static inline bool init_section_intersects(void *virt, size_t size)
 	return memory_intersects(__init_begin, __init_end, virt, size);
 }
 
+/**
+ * is_kernel_data - checks if the pointer address is located in the
+ *		    .data section
+ *
+ * @addr: address to check
+ *
+ * Returns: true if the address is located in .data, false otherwise.
+ */
+static inline bool is_kernel_data(unsigned long addr)
+{
+	return addr >= (unsigned long)_sdata &&
+	       addr < (unsigned long)_edata;
+}
+
 /**
  * is_kernel_rodata - checks if the pointer address is located in the
  *                    .rodata section
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 1b2f0a7e00d6..0622418bafbc 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -230,7 +230,6 @@ extern char *next_arg(char *args, char **param, char **val);
 
 extern int core_kernel_text(unsigned long addr);
 extern int init_kernel_text(unsigned long addr);
-extern int core_kernel_data(unsigned long addr);
 extern int __kernel_text_address(unsigned long addr);
 extern int kernel_text_address(unsigned long addr);
 extern int func_ptr_is_kernel_text(void *ptr);
diff --git a/kernel/extable.c b/kernel/extable.c
index b0ea5eb0c3b4..da26203841d4 100644
--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -82,24 +82,6 @@ int notrace core_kernel_text(unsigned long addr)
 	return 0;
 }
 
-/**
- * core_kernel_data - tell if addr points to kernel data
- * @addr: address to test
- *
- * Returns true if @addr passed in is from the core kernel data
- * section.
- *
- * Note: On some archs it may return true for core RODATA, and false
- *  for others. But will always be true for core RW data.
- */
-int core_kernel_data(unsigned long addr)
-{
-	if (addr >= (unsigned long)_sdata &&
-	    addr < (unsigned long)_edata)
-		return 1;
-	return 0;
-}
-
 int __kernel_text_address(unsigned long addr)
 {
 	if (kernel_text_address(addr))
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 72ef4dccbcc4..a21b13ebe98e 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -323,7 +323,7 @@ int __register_ftrace_function(struct ftrace_ops *ops)
 	if (!ftrace_enabled && (ops->flags & FTRACE_OPS_FL_PERMANENT))
 		return -EBUSY;
 
-	if (!core_kernel_data((unsigned long)ops))
+	if (!is_kernel_data((unsigned long)ops))
 		ops->flags |= FTRACE_OPS_FL_DYNAMIC;
 
 	add_ftrace_ops(&ftrace_ops_list, ops);
diff --git a/net/sysctl_net.c b/net/sysctl_net.c
index f6cb0d4d114c..f1687c351755 100644
--- a/net/sysctl_net.c
+++ b/net/sysctl_net.c
@@ -144,7 +144,7 @@ static void ensure_safe_net_sysctl(struct net *net, const char *path,
 		addr = (unsigned long)ent->data;
 		if (is_module_address(addr))
 			where = "module";
-		else if (core_kernel_data(addr))
+		else if (is_kernel_data(addr))
 			where = "kernel";
 		else
 			continue;
-- 
2.26.2


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

* [PATCH 4/9] sections: Move is_kernel_inittext() into sections.h
  2021-06-26  7:34 ` Kefeng Wang
                   ` (4 preceding siblings ...)
  (?)
@ 2021-06-26  7:34 ` Kefeng Wang
  -1 siblings, 0 replies; 24+ messages in thread
From: Kefeng Wang @ 2021-06-26  7:34 UTC (permalink / raw)
  To: Arnd Bergmann, linux-arch, linux-kernel
  Cc: Kefeng Wang, Ingo Molnar, Thomas Gleixner, x86

The is_kernel_inittext() and init_kernel_text() are with same
functionality, let's just keep is_kernel_inittext() and move
it into sections.h, then update all the callers.

Cc: Ingo Molnar <mingo@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: x86@kernel.org 
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 arch/x86/kernel/unwind_orc.c   |  2 +-
 include/asm-generic/sections.h | 14 ++++++++++++++
 include/linux/kallsyms.h       |  8 --------
 include/linux/kernel.h         |  1 -
 kernel/extable.c               | 12 ++----------
 5 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c
index a1202536fc57..d92ec2ced059 100644
--- a/arch/x86/kernel/unwind_orc.c
+++ b/arch/x86/kernel/unwind_orc.c
@@ -175,7 +175,7 @@ static struct orc_entry *orc_find(unsigned long ip)
 	}
 
 	/* vmlinux .init slow lookup: */
-	if (init_kernel_text(ip))
+	if (is_kernel_inittext(ip))
 		return __orc_find(__start_orc_unwind_ip, __start_orc_unwind,
 				  __stop_orc_unwind_ip - __start_orc_unwind_ip, ip);
 
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 5727e67f4b7a..9d622416a59c 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -170,4 +170,18 @@ static inline bool is_kernel_rodata(unsigned long addr)
 	       addr < (unsigned long)__end_rodata;
 }
 
+/**
+ * is_kernel_inittext - checks if the pointer address is located in the
+ *                    .init.text section
+ *
+ * @addr: address to check
+ *
+ * Returns: true if the address is located in .init.text, false otherwise.
+ */
+static inline bool is_kernel_inittext(unsigned long addr)
+{
+	return addr >= (unsigned long)_sinittext &&
+	       addr < (unsigned long)_einittext;
+}
+
 #endif /* _ASM_GENERIC_SECTIONS_H_ */
diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index c44c26977805..3e172fc65fae 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -23,14 +23,6 @@
 struct cred;
 struct module;
 
-static inline int is_kernel_inittext(unsigned long addr)
-{
-	if (addr >= (unsigned long)_sinittext
-	    && addr < (unsigned long)_einittext)
-		return 1;
-	return 0;
-}
-
 static inline int is_kernel_text(unsigned long addr)
 {
 	if ((addr >= (unsigned long)_stext && addr < (unsigned long)_etext))
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 0622418bafbc..d4ba46cf4737 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -229,7 +229,6 @@ extern bool parse_option_str(const char *str, const char *option);
 extern char *next_arg(char *args, char **param, char **val);
 
 extern int core_kernel_text(unsigned long addr);
-extern int init_kernel_text(unsigned long addr);
 extern int __kernel_text_address(unsigned long addr);
 extern int kernel_text_address(unsigned long addr);
 extern int func_ptr_is_kernel_text(void *ptr);
diff --git a/kernel/extable.c b/kernel/extable.c
index da26203841d4..98ca627ac5ef 100644
--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -62,14 +62,6 @@ const struct exception_table_entry *search_exception_tables(unsigned long addr)
 	return e;
 }
 
-int init_kernel_text(unsigned long addr)
-{
-	if (addr >= (unsigned long)_sinittext &&
-	    addr < (unsigned long)_einittext)
-		return 1;
-	return 0;
-}
-
 int notrace core_kernel_text(unsigned long addr)
 {
 	if (addr >= (unsigned long)_stext &&
@@ -77,7 +69,7 @@ int notrace core_kernel_text(unsigned long addr)
 		return 1;
 
 	if (system_state < SYSTEM_RUNNING &&
-	    init_kernel_text(addr))
+	    is_kernel_inittext(addr))
 		return 1;
 	return 0;
 }
@@ -94,7 +86,7 @@ int __kernel_text_address(unsigned long addr)
 	 * Since we are after the module-symbols check, there's
 	 * no danger of address overlap:
 	 */
-	if (init_kernel_text(addr))
+	if (is_kernel_inittext(addr))
 		return 1;
 	return 0;
 }
-- 
2.26.2


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

* [PATCH 5/9] kallsyms: Rename is_kernel() and is_kernel_text()
  2021-06-26  7:34 ` Kefeng Wang
                   ` (5 preceding siblings ...)
  (?)
@ 2021-06-26  7:34 ` Kefeng Wang
  -1 siblings, 0 replies; 24+ messages in thread
From: Kefeng Wang @ 2021-06-26  7:34 UTC (permalink / raw)
  To: Arnd Bergmann, linux-arch, linux-kernel
  Cc: Kefeng Wang, Alexei Starovoitov, Daniel Borkmann, Sami Tolvanen,
	Nathan Chancellor, bpf

The is_kernel[_text]() function check the address whether or not
in kernel[_text] ranges, also they will check the address whether
or not in gate area, so use better name.

Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: Nathan Chancellor <nathan@kernel.org> 
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: bpf@vger.kernel.org
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 arch/x86/net/bpf_jit_comp.c | 2 +-
 include/linux/kallsyms.h    | 8 ++++----
 kernel/cfi.c                | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 2a2e290fa5d8..b1ed4a0bfc86 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -376,7 +376,7 @@ static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
 int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
 		       void *old_addr, void *new_addr)
 {
-	if (!is_kernel_text((long)ip) &&
+	if (!is_kernel_text_or_gate_area((long)ip) &&
 	    !is_bpf_text_address((long)ip))
 		/* BPF poking in modules is not supported */
 		return -EINVAL;
diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index 3e172fc65fae..814e1cc8eabf 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -23,14 +23,14 @@
 struct cred;
 struct module;
 
-static inline int is_kernel_text(unsigned long addr)
+static inline int is_kernel_text_or_gate_area(unsigned long addr)
 {
 	if ((addr >= (unsigned long)_stext && addr < (unsigned long)_etext))
 		return 1;
 	return in_gate_area_no_mm(addr);
 }
 
-static inline int is_kernel(unsigned long addr)
+static inline int is_kernel_or_gate_area(unsigned long addr)
 {
 	if (addr >= (unsigned long)_stext && addr < (unsigned long)_end)
 		return 1;
@@ -40,9 +40,9 @@ static inline int is_kernel(unsigned long addr)
 static inline int is_ksym_addr(unsigned long addr)
 {
 	if (IS_ENABLED(CONFIG_KALLSYMS_ALL))
-		return is_kernel(addr);
+		return is_kernel_or_gate_area(addr);
 
-	return is_kernel_text(addr) || is_kernel_inittext(addr);
+	return is_kernel_text_or_gate_area(addr) || is_kernel_inittext(addr);
 }
 
 static inline void *dereference_symbol_descriptor(void *ptr)
diff --git a/kernel/cfi.c b/kernel/cfi.c
index e17a56639766..e7d90eff4382 100644
--- a/kernel/cfi.c
+++ b/kernel/cfi.c
@@ -282,7 +282,7 @@ static inline cfi_check_fn find_check_fn(unsigned long ptr)
 {
 	cfi_check_fn fn = NULL;
 
-	if (is_kernel_text(ptr))
+	if (is_kernel_text_or_gate_area(ptr))
 		return __cfi_check;
 
 	/*
-- 
2.26.2


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

* [PATCH 6/9] sections: Add new is_kernel() and is_kernel_text()
  2021-06-26  7:34 ` Kefeng Wang
                   ` (6 preceding siblings ...)
  (?)
@ 2021-06-26  7:34 ` Kefeng Wang
  -1 siblings, 0 replies; 24+ messages in thread
From: Kefeng Wang @ 2021-06-26  7:34 UTC (permalink / raw)
  To: Arnd Bergmann, linux-arch, linux-kernel; +Cc: Kefeng Wang, Andrey Ryabinin

The new is_kernel() check the kernel address ranges, and the
new is_kernel_text() check the kernel text section ranges.

Then use them to make some code clear.

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 include/asm-generic/sections.h | 27 +++++++++++++++++++++++++++
 include/linux/kallsyms.h       |  4 ++--
 kernel/extable.c               |  3 +--
 mm/kasan/report.c              |  2 +-
 4 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 9d622416a59c..06066d89137d 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -170,6 +170,20 @@ static inline bool is_kernel_rodata(unsigned long addr)
 	       addr < (unsigned long)__end_rodata;
 }
 
+/**
+ * is_kernel_text - checks if the pointer address is located in the
+ *                  .text section
+ *
+ * @addr: address to check
+ *
+ * Returns: true if the address is located in .text, false otherwise.
+ */
+static inline bool is_kernel_text(unsigned long addr)
+{
+	return addr >= (unsigned long)_stext &&
+	       addr < (unsigned long)_etext;
+}
+
 /**
  * is_kernel_inittext - checks if the pointer address is located in the
  *                    .init.text section
@@ -184,4 +198,17 @@ static inline bool is_kernel_inittext(unsigned long addr)
 	       addr < (unsigned long)_einittext;
 }
 
+/**
+ * is_kernel - checks if the pointer address is located in the kernel range
+ *
+ * @addr: address to check
+ *
+ * Returns: true if the address is located in kernel range, false otherwise.
+ */
+static inline bool is_kernel(unsigned long addr)
+{
+	return addr >= (unsigned long)_stext &&
+	       addr < (unsigned long)_end;
+}
+
 #endif /* _ASM_GENERIC_SECTIONS_H_ */
diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index 814e1cc8eabf..60460df66e83 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -25,14 +25,14 @@ struct module;
 
 static inline int is_kernel_text_or_gate_area(unsigned long addr)
 {
-	if ((addr >= (unsigned long)_stext && addr < (unsigned long)_etext))
+	if (is_kernel_text(addr))
 		return 1;
 	return in_gate_area_no_mm(addr);
 }
 
 static inline int is_kernel_or_gate_area(unsigned long addr)
 {
-	if (addr >= (unsigned long)_stext && addr < (unsigned long)_end)
+	if (is_kernel(addr))
 		return 1;
 	return in_gate_area_no_mm(addr);
 }
diff --git a/kernel/extable.c b/kernel/extable.c
index 98ca627ac5ef..0ba383d850ff 100644
--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -64,8 +64,7 @@ const struct exception_table_entry *search_exception_tables(unsigned long addr)
 
 int notrace core_kernel_text(unsigned long addr)
 {
-	if (addr >= (unsigned long)_stext &&
-	    addr < (unsigned long)_etext)
+	if (is_kernel_text(addr))
 		return 1;
 
 	if (system_state < SYSTEM_RUNNING &&
diff --git a/mm/kasan/report.c b/mm/kasan/report.c
index 8fff1825b22c..3971917c73c5 100644
--- a/mm/kasan/report.c
+++ b/mm/kasan/report.c
@@ -212,7 +212,7 @@ static void describe_object(struct kmem_cache *cache, void *object,
 
 static inline bool kernel_or_module_addr(const void *addr)
 {
-	if (addr >= (void *)_stext && addr < (void *)_end)
+	if (is_kernel((unsigned long)addr))
 		return true;
 	if (is_module_address((unsigned long)addr))
 		return true;
-- 
2.26.2


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

* [PATCH 7/9] s390: kprobes: Use is_kernel() helper
  2021-06-26  7:34 ` Kefeng Wang
                   ` (7 preceding siblings ...)
  (?)
@ 2021-06-26  7:34 ` Kefeng Wang
  2021-06-28 10:02   ` Heiko Carstens
  -1 siblings, 1 reply; 24+ messages in thread
From: Kefeng Wang @ 2021-06-26  7:34 UTC (permalink / raw)
  To: Arnd Bergmann, linux-arch, linux-kernel
  Cc: Kefeng Wang, Heiko Carstens, Vasily Gorbik,
	Christian Borntraeger, linux-s390

Use is_kernel() helper instead of is_kernel_addr().

Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: linux-s390@vger.kernel.org
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 arch/s390/kernel/kprobes.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/arch/s390/kernel/kprobes.c b/arch/s390/kernel/kprobes.c
index 528bb31815c3..7e7a8d5219bb 100644
--- a/arch/s390/kernel/kprobes.c
+++ b/arch/s390/kernel/kprobes.c
@@ -92,11 +92,6 @@ static void copy_instruction(struct kprobe *p)
 }
 NOKPROBE_SYMBOL(copy_instruction);
 
-static inline int is_kernel_addr(void *addr)
-{
-	return addr < (void *)_end;
-}
-
 static int s390_get_insn_slot(struct kprobe *p)
 {
 	/*
@@ -105,7 +100,7 @@ static int s390_get_insn_slot(struct kprobe *p)
 	 * field can be patched and executed within the insn slot.
 	 */
 	p->ainsn.insn = NULL;
-	if (is_kernel_addr(p->addr))
+	if (is_kernel(p->addr))
 		p->ainsn.insn = get_s390_insn_slot();
 	else if (is_module_addr(p->addr))
 		p->ainsn.insn = get_insn_slot();
@@ -117,7 +112,7 @@ static void s390_free_insn_slot(struct kprobe *p)
 {
 	if (!p->ainsn.insn)
 		return;
-	if (is_kernel_addr(p->addr))
+	if (is_kernel(p->addr))
 		free_s390_insn_slot(p->ainsn.insn, 0);
 	else
 		free_insn_slot(p->ainsn.insn, 0);
-- 
2.26.2


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

* [PATCH 8/9] powerpc/mm: Use is_kernel_text() and is_kernel_inittext() helper
  2021-06-26  7:34 ` Kefeng Wang
@ 2021-06-26  7:34   ` Kefeng Wang
  -1 siblings, 0 replies; 24+ messages in thread
From: Kefeng Wang @ 2021-06-26  7:34 UTC (permalink / raw)
  To: Arnd Bergmann, linux-arch, linux-kernel
  Cc: Kefeng Wang, Michael Ellerman, Benjamin Herrenschmidt,
	Paul Mackerras, linuxppc-dev

Use is_kernel_text() and is_kernel_inittext() helper to simplify code,
also drop etext, _stext, _sinittext, _einittext declaration which
already declared in section.h.

Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 arch/powerpc/mm/pgtable_32.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c
index dcf5ecca19d9..13c798308c2e 100644
--- a/arch/powerpc/mm/pgtable_32.c
+++ b/arch/powerpc/mm/pgtable_32.c
@@ -33,8 +33,6 @@
 
 #include <mm/mmu_decl.h>
 
-extern char etext[], _stext[], _sinittext[], _einittext[];
-
 static u8 early_fixmap_pagetable[FIXMAP_PTE_SIZE] __page_aligned_data;
 
 notrace void __init early_ioremap_init(void)
@@ -104,14 +102,13 @@ static void __init __mapin_ram_chunk(unsigned long offset, unsigned long top)
 {
 	unsigned long v, s;
 	phys_addr_t p;
-	int ktext;
+	bool ktext;
 
 	s = offset;
 	v = PAGE_OFFSET + s;
 	p = memstart_addr + s;
 	for (; s < top; s += PAGE_SIZE) {
-		ktext = ((char *)v >= _stext && (char *)v < etext) ||
-			((char *)v >= _sinittext && (char *)v < _einittext);
+		ktext = (is_kernel_text(v) || is_kernel_inittext(v));
 		map_kernel_page(v, p, ktext ? PAGE_KERNEL_TEXT : PAGE_KERNEL);
 		v += PAGE_SIZE;
 		p += PAGE_SIZE;
-- 
2.26.2


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

* [PATCH 8/9] powerpc/mm: Use is_kernel_text() and is_kernel_inittext() helper
@ 2021-06-26  7:34   ` Kefeng Wang
  0 siblings, 0 replies; 24+ messages in thread
From: Kefeng Wang @ 2021-06-26  7:34 UTC (permalink / raw)
  To: Arnd Bergmann, linux-arch, linux-kernel
  Cc: Kefeng Wang, Paul Mackerras, linuxppc-dev

Use is_kernel_text() and is_kernel_inittext() helper to simplify code,
also drop etext, _stext, _sinittext, _einittext declaration which
already declared in section.h.

Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 arch/powerpc/mm/pgtable_32.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c
index dcf5ecca19d9..13c798308c2e 100644
--- a/arch/powerpc/mm/pgtable_32.c
+++ b/arch/powerpc/mm/pgtable_32.c
@@ -33,8 +33,6 @@
 
 #include <mm/mmu_decl.h>
 
-extern char etext[], _stext[], _sinittext[], _einittext[];
-
 static u8 early_fixmap_pagetable[FIXMAP_PTE_SIZE] __page_aligned_data;
 
 notrace void __init early_ioremap_init(void)
@@ -104,14 +102,13 @@ static void __init __mapin_ram_chunk(unsigned long offset, unsigned long top)
 {
 	unsigned long v, s;
 	phys_addr_t p;
-	int ktext;
+	bool ktext;
 
 	s = offset;
 	v = PAGE_OFFSET + s;
 	p = memstart_addr + s;
 	for (; s < top; s += PAGE_SIZE) {
-		ktext = ((char *)v >= _stext && (char *)v < etext) ||
-			((char *)v >= _sinittext && (char *)v < _einittext);
+		ktext = (is_kernel_text(v) || is_kernel_inittext(v));
 		map_kernel_page(v, p, ktext ? PAGE_KERNEL_TEXT : PAGE_KERNEL);
 		v += PAGE_SIZE;
 		p += PAGE_SIZE;
-- 
2.26.2


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

* [PATCH 9/9] dma-debug: Use memory_intersects() directly
  2021-06-26  7:34 ` Kefeng Wang
@ 2021-06-26  7:34   ` Kefeng Wang
  -1 siblings, 0 replies; 24+ messages in thread
From: Kefeng Wang @ 2021-06-26  7:34 UTC (permalink / raw)
  To: Arnd Bergmann, linux-arch, linux-kernel
  Cc: Kefeng Wang, Christoph Hellwig, Marek Szyprowski, Robin Murphy, iommu

Use memory_intersects() directly instead of private overlap() function.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: iommu@lists.linux-foundation.org
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 kernel/dma/debug.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
index 14de1271463f..8ef737223999 100644
--- a/kernel/dma/debug.c
+++ b/kernel/dma/debug.c
@@ -1066,20 +1066,10 @@ static void check_for_stack(struct device *dev,
 	}
 }
 
-static inline bool overlap(void *addr, unsigned long len, void *start, void *end)
-{
-	unsigned long a1 = (unsigned long)addr;
-	unsigned long b1 = a1 + len;
-	unsigned long a2 = (unsigned long)start;
-	unsigned long b2 = (unsigned long)end;
-
-	return !(b1 <= a2 || a1 >= b2);
-}
-
 static void check_for_illegal_area(struct device *dev, void *addr, unsigned long len)
 {
-	if (overlap(addr, len, _stext, _etext) ||
-	    overlap(addr, len, __start_rodata, __end_rodata))
+	if (memory_intersects(_stext, _etext, addr, len) ||
+	    memory_intersects(__start_rodata, __end_rodata, addr, len))
 		err_printk(dev, NULL, "device driver maps memory from kernel text or rodata [addr=%p] [len=%lu]\n", addr, len);
 }
 
-- 
2.26.2


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

* [PATCH 9/9] dma-debug: Use memory_intersects() directly
@ 2021-06-26  7:34   ` Kefeng Wang
  0 siblings, 0 replies; 24+ messages in thread
From: Kefeng Wang @ 2021-06-26  7:34 UTC (permalink / raw)
  To: Arnd Bergmann, linux-arch, linux-kernel
  Cc: Kefeng Wang, Robin Murphy, Christoph Hellwig, iommu

Use memory_intersects() directly instead of private overlap() function.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: iommu@lists.linux-foundation.org
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 kernel/dma/debug.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
index 14de1271463f..8ef737223999 100644
--- a/kernel/dma/debug.c
+++ b/kernel/dma/debug.c
@@ -1066,20 +1066,10 @@ static void check_for_stack(struct device *dev,
 	}
 }
 
-static inline bool overlap(void *addr, unsigned long len, void *start, void *end)
-{
-	unsigned long a1 = (unsigned long)addr;
-	unsigned long b1 = a1 + len;
-	unsigned long a2 = (unsigned long)start;
-	unsigned long b2 = (unsigned long)end;
-
-	return !(b1 <= a2 || a1 >= b2);
-}
-
 static void check_for_illegal_area(struct device *dev, void *addr, unsigned long len)
 {
-	if (overlap(addr, len, _stext, _etext) ||
-	    overlap(addr, len, __start_rodata, __end_rodata))
+	if (memory_intersects(_stext, _etext, addr, len) ||
+	    memory_intersects(__start_rodata, __end_rodata, addr, len))
 		err_printk(dev, NULL, "device driver maps memory from kernel text or rodata [addr=%p] [len=%lu]\n", addr, len);
 }
 
-- 
2.26.2

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH 9/9] dma-debug: Use memory_intersects() directly
  2021-06-26  7:34   ` Kefeng Wang
@ 2021-06-28  6:11     ` Christoph Hellwig
  -1 siblings, 0 replies; 24+ messages in thread
From: Christoph Hellwig @ 2021-06-28  6:11 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Arnd Bergmann, linux-arch, linux-kernel, Christoph Hellwig,
	Marek Szyprowski, Robin Murphy, iommu

You've sent me a patch 9 out of 9 without the previous 8 patches.  There
is no way I can sensibly review this series.

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

* Re: [PATCH 9/9] dma-debug: Use memory_intersects() directly
@ 2021-06-28  6:11     ` Christoph Hellwig
  0 siblings, 0 replies; 24+ messages in thread
From: Christoph Hellwig @ 2021-06-28  6:11 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: linux-arch, Arnd Bergmann, linux-kernel, iommu, Robin Murphy,
	Christoph Hellwig

You've sent me a patch 9 out of 9 without the previous 8 patches.  There
is no way I can sensibly review this series.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH 9/9] dma-debug: Use memory_intersects() directly
  2021-06-28  6:11     ` Christoph Hellwig
@ 2021-06-28  6:29       ` Kefeng Wang
  -1 siblings, 0 replies; 24+ messages in thread
From: Kefeng Wang @ 2021-06-28  6:29 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Arnd Bergmann, linux-arch, linux-kernel, Marek Szyprowski,
	Robin Murphy, iommu


On 2021/6/28 14:11, Christoph Hellwig wrote:
> You've sent me a patch 9 out of 9 without the previous 8 patches.  There
> is no way I can sensibly review this series.

The full patches is 
https://lore.kernel.org/linux-arch/20210626073439.150586-1-wangkefeng.wang@huawei.com/T/#t

This patch is not very relevant about the above 8 patches, only use the 
existing function to simplify code.


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

* Re: [PATCH 9/9] dma-debug: Use memory_intersects() directly
@ 2021-06-28  6:29       ` Kefeng Wang
  0 siblings, 0 replies; 24+ messages in thread
From: Kefeng Wang @ 2021-06-28  6:29 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-arch, Arnd Bergmann, linux-kernel, iommu, Robin Murphy


On 2021/6/28 14:11, Christoph Hellwig wrote:
> You've sent me a patch 9 out of 9 without the previous 8 patches.  There
> is no way I can sensibly review this series.

The full patches is 
https://lore.kernel.org/linux-arch/20210626073439.150586-1-wangkefeng.wang@huawei.com/T/#t

This patch is not very relevant about the above 8 patches, only use the 
existing function to simplify code.

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH 7/9] s390: kprobes: Use is_kernel() helper
  2021-06-26  7:34 ` [PATCH 7/9] s390: kprobes: Use is_kernel() helper Kefeng Wang
@ 2021-06-28 10:02   ` Heiko Carstens
  2021-06-28 11:09     ` Kefeng Wang
  0 siblings, 1 reply; 24+ messages in thread
From: Heiko Carstens @ 2021-06-28 10:02 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Arnd Bergmann, linux-arch, linux-kernel, Vasily Gorbik,
	Christian Borntraeger, linux-s390

On Sat, Jun 26, 2021 at 03:34:37PM +0800, Kefeng Wang wrote:
> Use is_kernel() helper instead of is_kernel_addr().
> 
> Cc: Heiko Carstens <hca@linux.ibm.com>
> Cc: Vasily Gorbik <gor@linux.ibm.com>
> Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> Cc: linux-s390@vger.kernel.org
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
>  arch/s390/kernel/kprobes.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
...
> -static inline int is_kernel_addr(void *addr)
> -{
> -	return addr < (void *)_end;
> -}
> -
>  static int s390_get_insn_slot(struct kprobe *p)
>  {
>  	/*
> @@ -105,7 +100,7 @@ static int s390_get_insn_slot(struct kprobe *p)
>  	 * field can be patched and executed within the insn slot.
>  	 */
>  	p->ainsn.insn = NULL;
> -	if (is_kernel_addr(p->addr))
> +	if (is_kernel(p->addr))
>  		p->ainsn.insn = get_s390_insn_slot();
>  	else if (is_module_addr(p->addr))
>  		p->ainsn.insn = get_insn_slot();
> @@ -117,7 +112,7 @@ static void s390_free_insn_slot(struct kprobe *p)
>  {
>  	if (!p->ainsn.insn)
>  		return;
> -	if (is_kernel_addr(p->addr))
> +	if (is_kernel(p->addr))
>  		free_s390_insn_slot(p->ainsn.insn, 0);
>  	else
>  		free_insn_slot(p->ainsn.insn, 0);

Given that this makes sense its own, and I can't follow the discussion
of the patch series due to missing cc, I applied this to the s390 tree
- and also fixed up the missing unsigned long casts.

Thanks!

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

* Re: [PATCH 7/9] s390: kprobes: Use is_kernel() helper
  2021-06-28 10:02   ` Heiko Carstens
@ 2021-06-28 11:09     ` Kefeng Wang
  0 siblings, 0 replies; 24+ messages in thread
From: Kefeng Wang @ 2021-06-28 11:09 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: Arnd Bergmann, linux-arch, linux-kernel, Vasily Gorbik,
	Christian Borntraeger, linux-s390


On 2021/6/28 18:02, Heiko Carstens wrote:
> On Sat, Jun 26, 2021 at 03:34:37PM +0800, Kefeng Wang wrote:
>> Use is_kernel() helper instead of is_kernel_addr().
>>
>> Cc: Heiko Carstens <hca@linux.ibm.com>
>> Cc: Vasily Gorbik <gor@linux.ibm.com>
>> Cc: Christian Borntraeger <borntraeger@de.ibm.com>
>> Cc: linux-s390@vger.kernel.org
>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
>> ---
>>   arch/s390/kernel/kprobes.c | 9 ++-------
>>   1 file changed, 2 insertions(+), 7 deletions(-)
> ...
>> -static inline int is_kernel_addr(void *addr)
>> -{
>> -	return addr < (void *)_end;
>> -}
>> -
>>   static int s390_get_insn_slot(struct kprobe *p)
>>   {
>>   	/*
>> @@ -105,7 +100,7 @@ static int s390_get_insn_slot(struct kprobe *p)
>>   	 * field can be patched and executed within the insn slot.
>>   	 */
>>   	p->ainsn.insn = NULL;
>> -	if (is_kernel_addr(p->addr))
>> +	if (is_kernel(p->addr))
>>   		p->ainsn.insn = get_s390_insn_slot();
>>   	else if (is_module_addr(p->addr))
>>   		p->ainsn.insn = get_insn_slot();
>> @@ -117,7 +112,7 @@ static void s390_free_insn_slot(struct kprobe *p)
>>   {
>>   	if (!p->ainsn.insn)
>>   		return;
>> -	if (is_kernel_addr(p->addr))
>> +	if (is_kernel(p->addr))
>>   		free_s390_insn_slot(p->ainsn.insn, 0);
>>   	else
>>   		free_insn_slot(p->ainsn.insn, 0);
> Given that this makes sense its own, and I can't follow the discussion
> of the patch series due to missing cc, I applied this to the s390 tree
> - and also fixed up the missing unsigned long casts.

Thanks Heiko, I got some tips(someone says, not send all patches to all 
the people who maybe not care

about the other patches), so I only send this one to you,  but the 
patches is cc to all the maillist,

and it could be check from 
https://lore.kernel.org/linux-arch/20210626073439.150586-1-wangkefeng.wang@huawei.com

>
> Thanks!
> .
>

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

* Re: [PATCH 3/9] sections: Move and rename core_kernel_data() to is_kernel_data()
  2021-06-26  7:34 ` [PATCH 3/9] sections: Move and rename core_kernel_data() to is_kernel_data() Kefeng Wang
@ 2021-06-29  1:05   ` Steven Rostedt
  2021-06-29  6:36     ` Kefeng Wang
  0 siblings, 1 reply; 24+ messages in thread
From: Steven Rostedt @ 2021-06-29  1:05 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Arnd Bergmann, linux-arch, linux-kernel, Ingo Molnar, David S. Miller

On Sat, 26 Jun 2021 15:34:33 +0800
Kefeng Wang <wangkefeng.wang@huawei.com> wrote:

> Move core_kernel_data() into sections.h and rename it to
> is_kernel_data(), also make it return bool value, then
> update all the callers.

Removing the "core" part of "core_kernel_data()" is misleading. As
modules can have kernel data, but this will return false on module data
(as it should). This is similar to core_kernel_text() which this series
doesn't seem to touch.

I'd like to keep the "core" in the name which makes it obvious this is
not about module data, and if someone were to make it about module
data, it will break ftrace synchronization.

-- Steve

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

* Re: [PATCH 3/9] sections: Move and rename core_kernel_data() to is_kernel_data()
  2021-06-29  1:05   ` Steven Rostedt
@ 2021-06-29  6:36     ` Kefeng Wang
  0 siblings, 0 replies; 24+ messages in thread
From: Kefeng Wang @ 2021-06-29  6:36 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Arnd Bergmann, linux-arch, linux-kernel, Ingo Molnar, David S. Miller


On 2021/6/29 9:05, Steven Rostedt wrote:
> On Sat, 26 Jun 2021 15:34:33 +0800
> Kefeng Wang <wangkefeng.wang@huawei.com> wrote:
>
>> Move core_kernel_data() into sections.h and rename it to
>> is_kernel_data(), also make it return bool value, then
>> update all the callers.
> Removing the "core" part of "core_kernel_data()" is misleading. As
> modules can have kernel data, but this will return false on module data
> (as it should). This is similar to core_kernel_text() which this series
> doesn't seem to touch.

Yes, The series only collect and move the basic part(aka, the 'core' 
part, which only

contains the start/end address check of sections) into 
include/asm-generic/sections.h,

the core_kernel_text() contains system_state validation, it's not 
inappropriate into sections.h,

so it won't be modified and moved.

>
> I'd like to keep the "core" in the name which makes it obvious this is
> not about module data, and if someone were to make it about module
> data, it will break ftrace synchronization.

After this series, we have 5 APIs, only use core_kernel_data() is a 
little strange,

  * is_kernel_data()       --- come from core_kernel_data() in kernel.h
  * is_kernel_rodata()    --- already in sections.h
  * is_kernel_text()        --- come from kallsyms.h
  * is_kernel_inittext()   --- come from kernel.h and kallsyms.h
  * is_kernel()                --- come from kallsyms.h

Could we rename is_kernel_data() to is_kernel_core_data(), and add some 
comment your mentioned,

or any better naming, thanks.

>
> -- Steve
> .
>

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

* Re: [PATCH 2/9] kallsyms: Fix address-checks for kernel related range
  2021-06-26  7:34 ` [PATCH 2/9] kallsyms: Fix address-checks for kernel related range Kefeng Wang
@ 2021-07-05  3:35   ` Sergey Senozhatsky
  2021-07-07 12:43   ` Petr Mladek
  1 sibling, 0 replies; 24+ messages in thread
From: Sergey Senozhatsky @ 2021-07-05  3:35 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Arnd Bergmann, linux-arch, linux-kernel, Sergey Senozhatsky, Petr Mladek

On (21/06/26 15:34), Kefeng Wang wrote:
> The is_kernel_inittext/is_kernel_text/is_kernel function should not
> include the end address(the labels _einittext, _etext and _end) when
> check the address range.
> 
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> Cc: Petr Mladek <pmladek@suse.com>
> Fixes: 04b8eb7a4ccd ("symbol lookup: introduce dereference_symbol_descriptor()")
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>

Acked-by: Sergey Senozhatsky <senozhatsky@chromium.org>

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

* Re: [PATCH 2/9] kallsyms: Fix address-checks for kernel related range
  2021-06-26  7:34 ` [PATCH 2/9] kallsyms: Fix address-checks for kernel related range Kefeng Wang
  2021-07-05  3:35   ` Sergey Senozhatsky
@ 2021-07-07 12:43   ` Petr Mladek
  1 sibling, 0 replies; 24+ messages in thread
From: Petr Mladek @ 2021-07-07 12:43 UTC (permalink / raw)
  To: Kefeng Wang; +Cc: Arnd Bergmann, linux-arch, linux-kernel, Sergey Senozhatsky

On Sat 2021-06-26 15:34:32, Kefeng Wang wrote:
> The is_kernel_inittext/is_kernel_text/is_kernel function should not
> include the end address(the labels _einittext, _etext and _end) when
> check the address range.

Great catch!

> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> Cc: Petr Mladek <pmladek@suse.com>
> Fixes: 04b8eb7a4ccd ("symbol lookup: introduce dereference_symbol_descriptor()")

This commit just moved the code from kernel/kallsyms.c. It was broken
even before the git history ;-)

> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>

Reviewed-by: Petr Mladek <pmladek@suse.com>

Best Regards,
Petr

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

end of thread, other threads:[~2021-07-07 12:43 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-26  7:34 [PATCH 0/9] sections: Unify kernel sections range check and use Kefeng Wang
2021-06-26  7:34 ` Kefeng Wang
2021-06-26  7:34 ` Kefeng Wang
2021-06-26  7:34 ` [PATCH 1/9] kallsyms: Remove arch specific text and data check Kefeng Wang
2021-06-26  7:34 ` [PATCH 2/9] kallsyms: Fix address-checks for kernel related range Kefeng Wang
2021-07-05  3:35   ` Sergey Senozhatsky
2021-07-07 12:43   ` Petr Mladek
2021-06-26  7:34 ` [PATCH 3/9] sections: Move and rename core_kernel_data() to is_kernel_data() Kefeng Wang
2021-06-29  1:05   ` Steven Rostedt
2021-06-29  6:36     ` Kefeng Wang
2021-06-26  7:34 ` [PATCH 4/9] sections: Move is_kernel_inittext() into sections.h Kefeng Wang
2021-06-26  7:34 ` [PATCH 5/9] kallsyms: Rename is_kernel() and is_kernel_text() Kefeng Wang
2021-06-26  7:34 ` [PATCH 6/9] sections: Add new " Kefeng Wang
2021-06-26  7:34 ` [PATCH 7/9] s390: kprobes: Use is_kernel() helper Kefeng Wang
2021-06-28 10:02   ` Heiko Carstens
2021-06-28 11:09     ` Kefeng Wang
2021-06-26  7:34 ` [PATCH 8/9] powerpc/mm: Use is_kernel_text() and is_kernel_inittext() helper Kefeng Wang
2021-06-26  7:34   ` Kefeng Wang
2021-06-26  7:34 ` [PATCH 9/9] dma-debug: Use memory_intersects() directly Kefeng Wang
2021-06-26  7:34   ` Kefeng Wang
2021-06-28  6:11   ` Christoph Hellwig
2021-06-28  6:11     ` Christoph Hellwig
2021-06-28  6:29     ` Kefeng Wang
2021-06-28  6:29       ` Kefeng Wang

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.