2021-06-26 07:28:37

by Kefeng Wang

[permalink] [raw]
Subject: [PATCH 0/9] sections: Unify kernel sections range check and use

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: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

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


2021-06-26 07:28:45

by Kefeng Wang

[permalink] [raw]
Subject: [PATCH 5/9] kallsyms: Rename is_kernel() and is_kernel_text()

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 <[email protected]>
Cc: Daniel Borkmann <[email protected]>
Cc: Sami Tolvanen <[email protected]>
Cc: Nathan Chancellor <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: [email protected]
Signed-off-by: Kefeng Wang <[email protected]>
---
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

2021-06-26 07:29:16

by Kefeng Wang

[permalink] [raw]
Subject: [PATCH 8/9] powerpc/mm: Use is_kernel_text() and is_kernel_inittext() helper

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 <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: [email protected]
Signed-off-by: Kefeng Wang <[email protected]>
---
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

2021-06-26 07:29:27

by Kefeng Wang

[permalink] [raw]
Subject: [PATCH 7/9] s390: kprobes: Use is_kernel() helper

Use is_kernel() helper instead of is_kernel_addr().

Cc: Heiko Carstens <[email protected]>
Cc: Vasily Gorbik <[email protected]>
Cc: Christian Borntraeger <[email protected]>
Cc: [email protected]
Signed-off-by: Kefeng Wang <[email protected]>
---
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

2021-06-26 07:29:45

by Kefeng Wang

[permalink] [raw]
Subject: [PATCH 6/9] sections: Add new is_kernel() and is_kernel_text()

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 <[email protected]>
Cc: Andrey Ryabinin <[email protected]>
Signed-off-by: Kefeng Wang <[email protected]>
---
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

2021-06-26 07:30:26

by Kefeng Wang

[permalink] [raw]
Subject: [PATCH 4/9] sections: Move is_kernel_inittext() into sections.h

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 <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: [email protected]
Signed-off-by: Kefeng Wang <[email protected]>
---
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

2021-06-26 07:31:01

by Kefeng Wang

[permalink] [raw]
Subject: [PATCH 1/9] kallsyms: Remove arch specific text and data check

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

Cc: Arnd Bergmann <[email protected]>
Signed-off-by: Kefeng Wang <[email protected]>
---
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

2021-06-26 07:31:27

by Kefeng Wang

[permalink] [raw]
Subject: [PATCH 9/9] dma-debug: Use memory_intersects() directly

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

Cc: Christoph Hellwig <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Cc: Robin Murphy <[email protected]>
Cc: [email protected]
Signed-off-by: Kefeng Wang <[email protected]>
---
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

2021-06-28 06:13:03

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH 9/9] dma-debug: Use memory_intersects() directly

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.

2021-06-28 06:31:40

by Kefeng Wang

[permalink] [raw]
Subject: Re: [PATCH 9/9] dma-debug: Use memory_intersects() directly


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/[email protected]/T/#t

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

2021-06-28 10:04:44

by Heiko Carstens

[permalink] [raw]
Subject: Re: [PATCH 7/9] s390: kprobes: Use is_kernel() helper

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 <[email protected]>
> Cc: Vasily Gorbik <[email protected]>
> Cc: Christian Borntraeger <[email protected]>
> Cc: [email protected]
> Signed-off-by: Kefeng Wang <[email protected]>
> ---
> 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!

2021-06-28 11:11:30

by Kefeng Wang

[permalink] [raw]
Subject: Re: [PATCH 7/9] s390: kprobes: Use is_kernel() helper


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 <[email protected]>
>> Cc: Vasily Gorbik <[email protected]>
>> Cc: Christian Borntraeger <[email protected]>
>> Cc: [email protected]
>> Signed-off-by: Kefeng Wang <[email protected]>
>> ---
>> 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/[email protected]

>
> Thanks!
> .
>