[PATCH] powerpc: net: bpf_jit_comp: Fix misuse of fallthrough

2020-09-28 Thread zhe.he
From: He Zhe 

The user defined label following "fallthrough" is not considered by GCC
and causes build failure.

kernel-source/include/linux/compiler_attributes.h:208:41: error: attribute
'fallthrough' not preceding a case label or default label [-Werror]
 208   define fallthrough _attribute((fallthrough_))
  ^

Signed-off-by: He Zhe 
---
 arch/powerpc/net/bpf_jit_comp.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
index 78d61f97371e..e809cb5a1631 100644
--- a/arch/powerpc/net/bpf_jit_comp.c
+++ b/arch/powerpc/net/bpf_jit_comp.c
@@ -475,7 +475,6 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 
*image,
case BPF_JMP | BPF_JSET | BPF_K:
case BPF_JMP | BPF_JSET | BPF_X:
true_cond = COND_NE;
-   fallthrough;
cond_branch:
/* same targets, can avoid doing the test :) */
if (filter[i].jt == filter[i].jf) {
-- 
2.26.2



[PATCH] SUNRPC: Flush dcache only when receiving more seeking

2020-09-18 Thread zhe.he
From: He Zhe 

commit ca07eda33e01 ("SUNRPC: Refactor svc_recvfrom()") introduces
svc_flush_bvec to after sock_recvmsg, but sometimes we receive less than we
seek, which triggers the following warning.

WARNING: CPU: 0 PID: 18266 at include/linux/bvec.h:101 
bvec_iter_advance+0x44/0xa8
Attempted to advance past end of bvec iter
Modules linked in: sch_fq_codel openvswitch nsh nf_conncount nf_nat
nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4
CPU: 1 PID: 18266 Comm: nfsd Not tainted 5.9.0-rc5 #1
Hardware name: Xilinx Zynq Platform
[<80112ec0>] (unwind_backtrace) from [<8010c3a8>] (show_stack+0x18/0x1c)
[<8010c3a8>] (show_stack) from [<80755214>] (dump_stack+0x9c/0xd0)
[<80755214>] (dump_stack) from [<80125e64>] (__warn+0xdc/0xf4)
[<80125e64>] (__warn) from [<80126244>] (warn_slowpath_fmt+0x84/0xac)
[<80126244>] (warn_slowpath_fmt) from [<80c88514>] (bvec_iter_advance+0x44/0xa8)
[<80c88514>] (bvec_iter_advance) from [<80c88940>] 
(svc_tcp_read_msg+0x10c/0x1bc)
[<80c88940>] (svc_tcp_read_msg) from [<80c895d4>] (svc_tcp_recvfrom+0x98/0x63c)
[<80c895d4>] (svc_tcp_recvfrom) from [<80c97bf4>] (svc_handle_xprt+0x48c/0x4f8)
[<80c97bf4>] (svc_handle_xprt) from [<80c98038>] (svc_recv+0x94/0x1e0)
[<80c98038>] (svc_recv) from [<804747cc>] (nfsd+0xf0/0x168)
[<804747cc>] (nfsd) from [<80148a0c>] (kthread+0x144/0x154)
[<80148a0c>] (kthread) from [<80100114>] (ret_from_fork+0x14/0x20)

Fixes: ca07eda33e01 ("SUNRPC: Refactor svc_recvfrom()")
Cc:  # 5.8+
Signed-off-by: He Zhe 
---
 net/sunrpc/svcsock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index d5805fa1d066..ea3bc9635448 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -277,7 +277,7 @@ static ssize_t svc_tcp_read_msg(struct svc_rqst *rqstp, 
size_t buflen,
buflen -= seek;
}
len = sock_recvmsg(svsk->sk_sock, , MSG_DONTWAIT);
-   if (len > 0)
+   if (len > (seek & PAGE_MASK))
svc_flush_bvec(bvec, len, seek);
 
/* If we read a full record, then assume there may be more
-- 
2.17.1



[PATCH] mips/oprofile: Fix fallthrough placement

2020-08-20 Thread zhe.he
From: He Zhe 

We want neither
"
include/linux/compiler_attributes.h:201:41: warning: statement will never
be executed [-Wswitch-unreachable]
  201 | # define fallthrough __attribute__((__fallthrough__))
  |  ^
"
nor
"
include/linux/compiler_attributes.h:201:41: warning: attribute
'fallthrough' not preceding a case label or default label
  201 | # define fallthrough __attribute__((__fallthrough__))
  |  ^
"

It's not worth adding one more macro. Let's simply place the fallthrough
in between the expansions.

Signed-off-by: He Zhe 
---
 arch/mips/oprofile/op_model_mipsxx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/mips/oprofile/op_model_mipsxx.c 
b/arch/mips/oprofile/op_model_mipsxx.c
index 1493c49ca47a..55d7b7fd18b6 100644
--- a/arch/mips/oprofile/op_model_mipsxx.c
+++ b/arch/mips/oprofile/op_model_mipsxx.c
@@ -245,7 +245,6 @@ static int mipsxx_perfcount_handler(void)
 
switch (counters) {
 #define HANDLE_COUNTER(n)  \
-   fallthrough;\
case n + 1: \
control = r_c0_perfctrl ## n(); \
counter = r_c0_perfcntr ## n(); \
@@ -256,8 +255,11 @@ static int mipsxx_perfcount_handler(void)
handled = IRQ_HANDLED;  \
}
HANDLE_COUNTER(3)
+   fallthrough;
HANDLE_COUNTER(2)
+   fallthrough;
HANDLE_COUNTER(1)
+   fallthrough;
HANDLE_COUNTER(0)
}
 
-- 
2.17.1



[PATCH] freezer: Add unsafe versions of freezable_schedule_timeout_interruptible for NFS

2020-07-06 Thread zhe.he
From: He Zhe 

commit 0688e64bc600 ("NFS: Allow signal interruption of NFS4ERR_DELAYed 
operations")
introduces nfs4_delay_interruptible which also needs an _unsafe version to
avoid the following call trace for the same reason explained in
commit 416ad3c9c006 ("freezer: add unsafe versions of freezable helpers for 
NFS")

CPU: 4 PID: 3968 Comm: rm Tainted: G W 5.8.0-rc4 #1
Hardware name: Marvell OcteonTX CN96XX board (DT)
Call trace:
dump_backtrace+0x0/0x1dc
show_stack+0x20/0x30
dump_stack+0xdc/0x150
debug_check_no_locks_held+0x98/0xa0
nfs4_delay_interruptible+0xd8/0x120
nfs4_handle_exception+0x130/0x170
nfs4_proc_rmdir+0x8c/0x220
nfs_rmdir+0xa4/0x360
vfs_rmdir.part.0+0x6c/0x1b0
do_rmdir+0x18c/0x210
__arm64_sys_unlinkat+0x64/0x7c
el0_svc_common.constprop.0+0x7c/0x110
do_el0_svc+0x24/0xa0
el0_sync_handler+0x13c/0x1b8
el0_sync+0x158/0x180

Signed-off-by: He Zhe 
---
 fs/nfs/nfs4proc.c   |  2 +-
 include/linux/freezer.h | 14 ++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index e32717fd1169..15ecfa474e37 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -414,7 +414,7 @@ static int nfs4_delay_interruptible(long *timeout)
 {
might_sleep();
 
-   freezable_schedule_timeout_interruptible(nfs4_update_delay(timeout));
+   
freezable_schedule_timeout_interruptible_unsafe(nfs4_update_delay(timeout));
if (!signal_pending(current))
return 0;
return __fatal_signal_pending(current) ? -EINTR :-ERESTARTSYS;
diff --git a/include/linux/freezer.h b/include/linux/freezer.h
index 21f5aa0b217f..27828145ca09 100644
--- a/include/linux/freezer.h
+++ b/include/linux/freezer.h
@@ -207,6 +207,17 @@ static inline long 
freezable_schedule_timeout_interruptible(long timeout)
return __retval;
 }
 
+/* DO NOT ADD ANY NEW CALLERS OF THIS FUNCTION */
+static inline long freezable_schedule_timeout_interruptible_unsafe(long 
timeout)
+{
+   long __retval;
+
+   freezer_do_not_count();
+   __retval = schedule_timeout_interruptible(timeout);
+   freezer_count_unsafe();
+   return __retval;
+}
+
 /* Like schedule_timeout_killable(), but should not block the freezer. */
 static inline long freezable_schedule_timeout_killable(long timeout)
 {
@@ -285,6 +296,9 @@ static inline void set_freezable(void) {}
 #define freezable_schedule_timeout_interruptible(timeout)  \
schedule_timeout_interruptible(timeout)
 
+#define freezable_schedule_timeout_interruptible_unsafe(timeout)   \
+   schedule_timeout_interruptible(timeout)
+
 #define freezable_schedule_timeout_killable(timeout)   \
schedule_timeout_killable(timeout)
 
-- 
2.17.1



[PATCH RT] printk: devkmsg: read: Return EPIPE when the first message user-space wants has gone

2019-09-24 Thread zhe.he
From: He Zhe 

When user-space wants to read the first message, that is when user->seq
is 0, and that message has gone, it currently automatically resets
user->seq to current first seq. This mis-aligns with mainline kernel.

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/ABI/testing/dev-kmsg#n39
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/printk/printk.c#n899

We should inform user-space that what it wants has gone by returning EPIPE
in such scenario.

Signed-off-by: He Zhe 
---
 kernel/printk/printk.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index e3fa33f2e23c..58c545a528b3 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -703,14 +703,10 @@ static ssize_t devkmsg_read(struct file *file, char 
__user *buf,
goto out;
}
 
-   if (user->seq == 0) {
-   user->seq = seq;
-   } else {
-   user->seq++;
-   if (user->seq < seq) {
-   ret = -EPIPE;
-   goto restore_out;
-   }
+   user->seq++;
+   if (user->seq < seq) {
+   ret = -EPIPE;
+   goto restore_out;
}
 
msg = (struct printk_log *)>msgbuf[0];
-- 
2.17.1



[PATCH] printk: Fix unnecessary returning broken pipe error from devkmsg_read

2019-09-18 Thread zhe.he
From: He Zhe 

When users read the buffer from start, there is no need to return -EPIPE
since the possible overflows will not affect the output.

Signed-off-by: He Zhe 
---
 kernel/printk/printk.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 1888f6a..4a6a129 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -886,7 +886,9 @@ static ssize_t devkmsg_read(struct file *file, char __user 
*buf,
logbuf_lock_irq();
}
 
-   if (user->seq < log_first_seq) {
+   if (user->seq == 0) {
+   user->seq = log_first_seq;
+   } else if (user->seq < log_first_seq) {
/* our last seen message is gone, return error and reset */
user->idx = log_first_idx;
user->seq = log_first_seq;
-- 
2.7.4



[PATCH] modules: page-align module section allocations only for arches supporting strict module rwx

2019-08-20 Thread zhe.he
From: He Zhe 

We should keep the case of "#define debug_align(X) (X)" for all arches
without CONFIG_HAS_STRICT_MODULE_RWX ability, which would save people, who
are sensitive to system size, a lot of memory when using modules,
especially for embedded systems. This is also the intention of the
original #ifdef... statement and still valid for now.

Note that this still keeps the effect of the fix of the following commit,
38f054d549a8 ("modules: always page-align module section allocations"),
since when CONFIG_ARCH_HAS_STRICT_MODULE_RWX is enabled, module pages are
aligned.

Signed-off-by: He Zhe 
---
This patch is based on the top of modules-next tree, 38f054d549a8.

 kernel/module.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/module.c b/kernel/module.c
index cd8df51..9ee9342 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -64,9 +64,14 @@
 
 /*
  * Modules' sections will be aligned on page boundaries
- * to ensure complete separation of code and data
+ * to ensure complete separation of code and data, but
+ * only when CONFIG_ARCH_HAS_STRICT_MODULE_RWX=y
  */
+#ifdef CONFIG_ARCH_HAS_STRICT_MODULE_RWX
 # define debug_align(X) ALIGN(X, PAGE_SIZE)
+#else
+# define debug_align(X) (X)
+#endif
 
 /* If this is set, the section belongs in the init part of the module */
 #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1))
-- 
2.7.4



[PATCH] gcc-plugins: Enable error message print

2019-08-13 Thread zhe.he
From: He Zhe 

Instead of sliently emptying CONFIG_PLUGIN_HOSTCC which is the dependency
of a series of configurations, the following error message would be easier
for users to find something is wrong and what is happening.

scripts/gcc-plugins/gcc-common.h:5:22: fatal error: bversion.h:
No such file or directory
compilation terminated.

Now that we have already got the error message switch, let's turn it on.

Signed-off-by: He Zhe 
---
 scripts/gcc-plugins/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/gcc-plugins/Kconfig b/scripts/gcc-plugins/Kconfig
index d33de0b..fe28cb9 100644
--- a/scripts/gcc-plugins/Kconfig
+++ b/scripts/gcc-plugins/Kconfig
@@ -3,7 +3,7 @@ preferred-plugin-hostcc := $(if-success,[ $(gcc-version) -ge 
40800 ],$(HOSTCXX),
 
 config PLUGIN_HOSTCC
string
-   default "$(shell,$(srctree)/scripts/gcc-plugin.sh 
"$(preferred-plugin-hostcc)" "$(HOSTCXX)" "$(CC)")" if CC_IS_GCC
+   default "$(shell,$(srctree)/scripts/gcc-plugin.sh --show-error 
"$(preferred-plugin-hostcc)" "$(HOSTCXX)" "$(CC)")" if CC_IS_GCC
help
  Host compiler used to build GCC plugins.  This can be $(HOSTCXX),
  $(HOSTCC), or a null string if GCC plugin is unsupported.
-- 
2.7.4



[PATCH] ARM: module: Avoid W and X mappings at the beginning

2019-08-10 Thread zhe.he
From: He Zhe 

It is more secure to map module memory as not-execute at the beginning.
Memory sections that need to be executable will be turned to executable
later in complete_formation.

This is a corresponding change for ARM to the following commit
commit f2c65fb3221a ("x86/modules: Avoid breaking W^X while loading modules")

Tested with test_bpf:
test_bpf: Summary: 378 PASSED, 0 FAILED, [0/366 JIT'ed]

Signed-off-by: He Zhe 
---
 arch/arm/kernel/module.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
index deef17f..197b3b9 100644
--- a/arch/arm/kernel/module.c
+++ b/arch/arm/kernel/module.c
@@ -45,12 +45,12 @@ void *module_alloc(unsigned long size)
gfp_mask |= __GFP_NOWARN;
 
p = __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
-   gfp_mask, PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE,
+   gfp_mask, PAGE_KERNEL, 0, NUMA_NO_NODE,
__builtin_return_address(0));
if (!IS_ENABLED(CONFIG_ARM_MODULE_PLTS) || p)
return p;
return __vmalloc_node_range(size, 1,  VMALLOC_START, VMALLOC_END,
-   GFP_KERNEL, PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE,
+   GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE,
__builtin_return_address(0));
 }
 #endif
-- 
2.7.4



[PATCH] module: Fix load failure when CONFIG_STRICT_MODULE_RWX is diabled

2019-08-10 Thread zhe.he
From: He Zhe 

When loading modules with CONFIG_ARCH_HAS_STRICT_MODULE_RWX enabled and
CONFIG_STRICT_MODULE_RWX disabled, the memory allocated for modules would
not be page-aligned and cause the following BUG during frob_text.

[ cut here ]
kernel BUG at kernel/module.c:1907!
Internal error: Oops - BUG: 0 [#1] ARM
Modules linked in:
CPU: 0 PID: 89 Comm: systemd-modules Not tainted 5.3.0-rc2 #1
Hardware name: ARM-Versatile (Device Tree Support)
PC is at frob_text.constprop.0+0x2c/0x40
LR is at load_module+0x14b4/0x1d28
pc : []lr : []psr: 2013
sp : ce44fe58  ip :   fp : 
r10:   r9 : ce44feb8  r8 : 
r7 : 0001  r6 : bf00032c  r5 : ce44ff40  r4 : bf000320
r3 : bf000400  r2 : 0fff  r1 : 0220  r0 : bf00
Flags: nzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment none
Control: 00093177  Table: 0e4c  DAC: 0051
Process systemd-modules (pid: 89, stack limit = 0x9fccc8dc)
Stack: (0xce44fe58 to 0xce45)
fe40:    cf1b05b8
fe60: 0001 ce47cf08 bf002754 c07ae5d8 d0a2a484 bf002060 bf0004f8 
fe80: b6d17910 c017cf1c ce47cf00 d0a29000 ce47cf00 ce44ff34 14fc 
fea0:   bf00025c 0001   6e72656b 6c65
fec0:        
fee0:      c0ac9048 7fff 
ff00: b6d17910 0005 017b c0009208 ce44e000  b6ebfe54 c008562c
ff20: 7fff  0003 cefd28f8 0001 d0a29000 14fc 
ff40: d0a292cb d0a29380 d0a29000 14fc d0a29f0c d0a29d90 d0a29a60 0520
ff60: 0710 0718 0826    0708 0023
ff80: 0024 001c  0016  c0ac9048 0041c620 
ffa0:  c0009000 0041c620  0005 b6d17910  
ffc0: 0041c620   017b 0041f078  004098b0 b6ebfe54
ffe0: bedb6bc8 bedb6bb8 b6d0f91c b6c945a0 6010 0005  
[] (frob_text.constprop.0) from [] 
(load_module+0x14b4/0x1d28)
[] (load_module) from [] (sys_finit_module+0xa0/0xc4)
[] (sys_finit_module) from [] (ret_fast_syscall+0x0/0x50)
Exception stack(0xce44ffa8 to 0xce44fff0)
ffa0:   0041c620  0005 b6d17910  
ffc0: 0041c620   017b 0041f078  004098b0 b6ebfe54
ffe0: bedb6bc8 bedb6bb8 b6d0f91c b6c945a0
Code: e7f001f2 e5931008 e1110002 0a01 (e7f001f2)
---[ end trace e904557128d9aed5 ]---

This patch enables page-aligned allocation when
CONFIG_ARCH_HAS_STRICT_MODULE_RWX is enabled.

Fixes: 93651f80dcb6 ("modules: fix compile error if don't have strict module 
rwx")
Signed-off-by: He Zhe 
---
 kernel/module.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index 5933395..9ee9342 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -65,9 +65,9 @@
 /*
  * Modules' sections will be aligned on page boundaries
  * to ensure complete separation of code and data, but
- * only when CONFIG_STRICT_MODULE_RWX=y
+ * only when CONFIG_ARCH_HAS_STRICT_MODULE_RWX=y
  */
-#ifdef CONFIG_STRICT_MODULE_RWX
+#ifdef CONFIG_ARCH_HAS_STRICT_MODULE_RWX
 # define debug_align(X) ALIGN(X, PAGE_SIZE)
 #else
 # define debug_align(X) (X)
-- 
2.7.4



[PATCH] nfsd4: Fix kernel crash when reading proc file reply_cache_stats

2019-08-06 Thread zhe.he
From: He Zhe 

reply_cache_stats uses wrong parameter as seq file private structure and
thus causes the following kernel crash when users read
/proc/fs/nfsd/reply_cache_stats

BUG: kernel NULL pointer dereference, address: 01f9
PGD 0 P4D 0
Oops:  [#3] SMP PTI
CPU: 6 PID: 1502 Comm: cat Tainted: G  D   5.3.0-rc3+ #1
Hardware name: Intel Corporation Broadwell Client platform/Basking Ridge, BIOS 
BDW-E2R1.86C.0118.R01.1503110618 03/11/2015
RIP: 0010:nfsd_reply_cache_stats_show+0x3b/0x2d0
Code: 41 54 49 89 f4 48 89 fe 48 c7 c7 b3 10 33 88 53 bb e8 03 00 00 e8 88 82 
d1 ff bf 58 89 41 00 e8 eb c5 85 00 48 83 eb 01 75 f0 <41> 8b 94 24 f8 01 00 00 
48 c7 c6 be 10 33 88 4c 89 ef bb e8 03 00
RSP: 0018:aa520106fe08 EFLAGS: 00010246
RAX: 00cfe1a77123 RBX:  RCX: 00291b46
RDX: 00cf RSI: 0006 RDI: 00291b28
RBP: aa520106fe20 R08: 0006 R09: 00cfe17e55dd
R10: a424e47c R11: 030b R12: 0001
R13: a424e5697000 R14: 0001 R15: a424e5697000
FS:  7f805735f580() GS:a424f8f8() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 01f9 CR3: 655ce005 CR4: 003606e0
Call Trace:
 seq_read+0x194/0x3e0
 __vfs_read+0x1b/0x40
 vfs_read+0x95/0x140
 ksys_read+0x61/0xe0
 __x64_sys_read+0x1a/0x20
 do_syscall_64+0x4d/0x120
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7f805728b861
Code: fe ff ff 50 48 8d 3d 86 b4 09 00 e8 79 e0 01 00 66 0f 1f 84 00 00 00 00 
00 48 8d 05 d9 19 0d 00 8b 00 85 c0 75 13 31 c0 0f 05 <48> 3d 00 f0 ff ff 77 57 
c3 66 0f 1f 44 00 00 48 83 ec 28 48 89 54
RSP: 002b:7ffea1ce3c38 EFLAGS: 0246 ORIG_RAX: 
RAX: ffda RBX: 0002 RCX: 7f805728b861
RDX: 0002 RSI: 7f8057183000 RDI: 0003
RBP: 7f8057183000 R08: 7f8057182010 R09: 
R10: 0022 R11: 0246 R12: 559a60e8ff10
R13: 0003 R14: 0002 R15: 0002
Modules linked in:
CR2: 01f9
---[ end trace 01613595153f0cba ]---
RIP: 0010:nfsd_reply_cache_stats_show+0x3b/0x2d0
Code: 41 54 49 89 f4 48 89 fe 48 c7 c7 b3 10 33 88 53 bb e8 03 00 00 e8 88 82 
d1 ff bf 58 89 41 00 e8 eb c5 85 00 48 83 eb 01 75 f0 <41> 8b 94 24 f8 01 00 00 
48 c7 c6 be 10 33 88 4c 89 ef bb e8 03 00
RSP: 0018:aa52004b3e08 EFLAGS: 00010246
RAX: 002bab45a7c6 RBX:  RCX: 00291b4c
RDX: 002b RSI: 0004 RDI: 00291b28
RBP: aa52004b3e20 R08: 0004 R09: 002bab1c8c7a
R10: a424e550 R11: 02a9 R12: 0001
R13: a424e4475000 R14: 0001 R15: a424e4475000
FS:  7f805735f580() GS:a424f8f8() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 01f9 CR3: 655ce005 CR4: 003606e0
Killed

Fixes: 3ba75830ce17 ("nfsd4: drc containerization")
Signed-off-by: He Zhe 
---
 fs/nfsd/nfscache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index 26ad75a..96352ab 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -571,7 +571,7 @@ nfsd_cache_append(struct svc_rqst *rqstp, struct kvec *data)
  */
 static int nfsd_reply_cache_stats_show(struct seq_file *m, void *v)
 {
-   struct nfsd_net *nn = v;
+   struct nfsd_net *nn = m->private;
 
seq_printf(m, "max entries:   %u\n", nn->max_drc_entries);
seq_printf(m, "num entries:   %u\n",
-- 
2.7.4



[PATCH] nfsd4: Fix kernel crash when reading proc file reply_cache_stats

2019-08-06 Thread zhe.he
From: He Zhe 

reply_cache_stats uses wrong parameter as seq file private structure and
thus causes the following kernel crash when users read
/proc/fs/nfsd/reply_cache_stats

m=a2ec03f7 v=f5777155
BUG: kernel NULL pointer dereference, address: 01f9
PGD 0 P4D 0
Oops:  [#3] SMP PTI
CPU: 6 PID: 1502 Comm: cat Tainted: G  D   5.3.0-rc3+ #1
Hardware name: Intel Corporation Broadwell Client platform/Basking Ridge, BIOS 
BDW-E2R1.86C.0118.R01.1503110618 03/11/2015
RIP: 0010:nfsd_reply_cache_stats_show+0x3b/0x2d0
Code: 41 54 49 89 f4 48 89 fe 48 c7 c7 b3 10 33 88 53 bb e8 03 00 00 e8 88 82 
d1 ff bf 58 89 41 00 e8 eb c5 85 00 48 83 eb 01 75 f0 <41> 8b 94 24 f8 01 00 00 
48 c7 c6 be 10 33 88 4c 89 ef bb e8 03 00
RSP: 0018:aa520106fe08 EFLAGS: 00010246
RAX: 00cfe1a77123 RBX:  RCX: 00291b46
RDX: 00cf RSI: 0006 RDI: 00291b28
RBP: aa520106fe20 R08: 0006 R09: 00cfe17e55dd
R10: a424e47c R11: 030b R12: 0001
R13: a424e5697000 R14: 0001 R15: a424e5697000
FS:  7f805735f580() GS:a424f8f8() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 01f9 CR3: 655ce005 CR4: 003606e0
Call Trace:
 seq_read+0x194/0x3e0
 __vfs_read+0x1b/0x40
 vfs_read+0x95/0x140
 ksys_read+0x61/0xe0
 __x64_sys_read+0x1a/0x20
 do_syscall_64+0x4d/0x120
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7f805728b861
Code: fe ff ff 50 48 8d 3d 86 b4 09 00 e8 79 e0 01 00 66 0f 1f 84 00 00 00 00 
00 48 8d 05 d9 19 0d 00 8b 00 85 c0 75 13 31 c0 0f 05 <48> 3d 00 f0 ff ff 77 57 
c3 66 0f 1f 44 00 00 48 83 ec 28 48 89 54
RSP: 002b:7ffea1ce3c38 EFLAGS: 0246 ORIG_RAX: 
RAX: ffda RBX: 0002 RCX: 7f805728b861
RDX: 0002 RSI: 7f8057183000 RDI: 0003
RBP: 7f8057183000 R08: 7f8057182010 R09: 
R10: 0022 R11: 0246 R12: 559a60e8ff10
R13: 0003 R14: 0002 R15: 0002
Modules linked in:
CR2: 01f9
---[ end trace 01613595153f0cba ]---
RIP: 0010:nfsd_reply_cache_stats_show+0x3b/0x2d0
Code: 41 54 49 89 f4 48 89 fe 48 c7 c7 b3 10 33 88 53 bb e8 03 00 00 e8 88 82 
d1 ff bf 58 89 41 00 e8 eb c5 85 00 48 83 eb 01 75 f0 <41> 8b 94 24 f8 01 00 00 
48 c7 c6 be 10 33 88 4c 89 ef bb e8 03 00
RSP: 0018:aa52004b3e08 EFLAGS: 00010246
RAX: 002bab45a7c6 RBX:  RCX: 00291b4c
RDX: 002b RSI: 0004 RDI: 00291b28
RBP: aa52004b3e20 R08: 0004 R09: 002bab1c8c7a
R10: a424e550 R11: 02a9 R12: 0001
R13: a424e4475000 R14: 0001 R15: a424e4475000
FS:  7f805735f580() GS:a424f8f8() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 01f9 CR3: 655ce005 CR4: 003606e0
Killed

Fixes: 3ba75830ce17 ("nfsd4: drc containerization")
Signed-off-by: He Zhe 
---
 fs/nfsd/nfscache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index 26ad75a..96352ab 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -571,7 +571,7 @@ nfsd_cache_append(struct svc_rqst *rqstp, struct kvec *data)
  */
 static int nfsd_reply_cache_stats_show(struct seq_file *m, void *v)
 {
-   struct nfsd_net *nn = v;
+   struct nfsd_net *nn = m->private;
 
seq_printf(m, "max entries:   %u\n", nn->max_drc_entries);
seq_printf(m, "num entries:   %u\n",
-- 
2.7.4



[PATCH 2/2] perf: Fix writing to illegal memory in handling cpumap mask

2019-08-02 Thread zhe.he
From: He Zhe 

cpu_map__snprint_mask would write to illegal memory pointed by zalloc(0)
when there is only one cpu.

This patch fixes the calculation and adds sanity check against the input
parameters.

Signed-off-by: He Zhe 
---
 tools/perf/util/cpumap.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 3acfbe3..39cce66 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -751,7 +751,10 @@ size_t cpu_map__snprint_mask(struct cpu_map *map, char 
*buf, size_t size)
unsigned char *bitmap;
int last_cpu = cpu_map__cpu(map, map->nr - 1);
 
-   bitmap = zalloc((last_cpu + 7) / 8);
+   if (buf == NULL)
+   return 0;
+
+   bitmap = zalloc(last_cpu / 8 + 1);
if (bitmap == NULL) {
buf[0] = '\0';
return 0;
-- 
2.7.4



[PATCH 1/2] perf: Fix failure to set cpumask when only one cpu

2019-08-02 Thread zhe.he
From: He Zhe 

The buffer containing string used to set cpumask is overwritten by end of
string later in cpu_map__snprint_mask due to not enough memory space, when
there is only one cpu. And thus causes the following failure.

$ perf ftrace ls
failed to reset ftrace

This patch fixes the calculation of cpumask string size.

Signed-off-by: He Zhe 
---
 tools/perf/builtin-ftrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 66d5a66..0193128 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -173,7 +173,7 @@ static int set_tracing_cpumask(struct cpu_map *cpumap)
int last_cpu;
 
last_cpu = cpu_map__cpu(cpumap, cpumap->nr - 1);
-   mask_size = (last_cpu + 3) / 4 + 1;
+   mask_size = last_cpu / 4 + 2; /* one more byte for EOS */
mask_size += last_cpu / 32; /* ',' is needed for every 32th cpus */
 
cpumask = malloc(mask_size);
-- 
2.7.4



[PATCH] netfilter: Fix remainder of pseudo-header protocol 0

2019-06-23 Thread zhe.he
From: He Zhe 

Since v5.1-rc1, some types of packets do not get unreachable reply with the
following iptables setting. Fox example,

$ iptables -A INPUT -p icmp --icmp-type 8 -j REJECT
$ ping 127.0.0.1 -c 1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
— 127.0.0.1 ping statistics —
1 packets transmitted, 0 received, 100% packet loss, time 0ms

We should have got the following reply from command line, but we did not.
>From 127.0.0.1 icmp_seq=1 Destination Port Unreachable

Yi Zhao reported it and narrowed it down to:
7fc38225363d ("netfilter: reject: skip csum verification for protocols that 
don't support it"),

This is because nf_ip_checksum still expects pseudo-header protocol type 0 for
packets that are of neither TCP or UDP, and thus ICMP packets are mistakenly
treated as TCP/UDP.

This patch corrects the conditions in nf_ip_checksum and all other places that
still call it with protocol 0.

Fixes: 7fc38225363d ("netfilter: reject: skip csum verification for protocols 
that don't support it")
Reported-by: Yi Zhao 
Signed-off-by: He Zhe 
---
 net/netfilter/nf_conntrack_proto_icmp.c | 2 +-
 net/netfilter/nf_nat_proto.c| 2 +-
 net/netfilter/utils.c   | 5 +++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/net/netfilter/nf_conntrack_proto_icmp.c 
b/net/netfilter/nf_conntrack_proto_icmp.c
index a824367..dd53e2b 100644
--- a/net/netfilter/nf_conntrack_proto_icmp.c
+++ b/net/netfilter/nf_conntrack_proto_icmp.c
@@ -218,7 +218,7 @@ int nf_conntrack_icmpv4_error(struct nf_conn *tmpl,
/* See ip_conntrack_proto_tcp.c */
if (state->net->ct.sysctl_checksum &&
state->hook == NF_INET_PRE_ROUTING &&
-   nf_ip_checksum(skb, state->hook, dataoff, 0)) {
+   nf_ip_checksum(skb, state->hook, dataoff, IPPROTO_ICMP)) {
icmp_error_log(skb, state, "bad hw icmp checksum");
return -NF_ACCEPT;
}
diff --git a/net/netfilter/nf_nat_proto.c b/net/netfilter/nf_nat_proto.c
index 07da077..83a24cc 100644
--- a/net/netfilter/nf_nat_proto.c
+++ b/net/netfilter/nf_nat_proto.c
@@ -564,7 +564,7 @@ int nf_nat_icmp_reply_translation(struct sk_buff *skb,
 
if (!skb_make_writable(skb, hdrlen + sizeof(*inside)))
return 0;
-   if (nf_ip_checksum(skb, hooknum, hdrlen, 0))
+   if (nf_ip_checksum(skb, hooknum, hdrlen, IPPROTO_ICMP))
return 0;
 
inside = (void *)skb->data + hdrlen;
diff --git a/net/netfilter/utils.c b/net/netfilter/utils.c
index 06dc555..51b454d 100644
--- a/net/netfilter/utils.c
+++ b/net/netfilter/utils.c
@@ -17,7 +17,8 @@ __sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook,
case CHECKSUM_COMPLETE:
if (hook != NF_INET_PRE_ROUTING && hook != NF_INET_LOCAL_IN)
break;
-   if ((protocol == 0 && !csum_fold(skb->csum)) ||
+   if ((protocol != IPPROTO_TCP && protocol != IPPROTO_UDP &&
+   !csum_fold(skb->csum)) ||
!csum_tcpudp_magic(iph->saddr, iph->daddr,
   skb->len - dataoff, protocol,
   skb->csum)) {
@@ -26,7 +27,7 @@ __sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook,
}
/* fall through */
case CHECKSUM_NONE:
-   if (protocol == 0)
+   if (protocol != IPPROTO_TCP && protocol != IPPROTO_UDP)
skb->csum = 0;
else
skb->csum = csum_tcpudp_nofold(iph->saddr, iph->daddr,
-- 
2.7.4



[PATCH] serial: 8250: Fix serial8250 initialization crash

2019-01-17 Thread zhe.he
From: He Zhe 

The initialization code of interrupt backoff work might reference NULL
pointer and cause the following crash, if no port was found.

[   10.017727] CPU 0 Unable to handle kernel paging request at virtual address 
01b0, epc == 807088e0, ra == 8070863c
 snip 
[   11.704470] [<807088e0>] serial8250_register_8250_port+0x318/0x4ac
[   11.747251] [<80708d74>] serial8250_probe+0x148/0x1c0
[   11.789301] [<80728450>] platform_drv_probe+0x40/0x94
[   11.830515] [<807264f8>] really_probe+0xf8/0x318
[   11.870876] [<80726b7c>] __driver_attach+0x110/0x12c
[   11.910960] [<80724374>] bus_for_each_dev+0x78/0xcc
[   11.951134] [<80725958>] bus_add_driver+0x200/0x234
[   11.989756] [<807273d8>] driver_register+0x84/0x148
[   12.029832] [<80d72f84>] serial8250_init+0x138/0x198
[   12.070447] [<80100e6c>] do_one_initcall+0x5c/0x2a0
[   12.110104] [<80d3a208>] kernel_init_freeable+0x370/0x484
[   12.150722] [<80a49420>] kernel_init+0x10/0xf8
[   12.191517] [<8010756c>] ret_from_kernel_thread+0x14/0x1c

This patch makes sure the initialization code can be reached only if a port
is found.

Fixes: commit 6d7f677a2afa ("serial: 8250: Rate limit serial port rx interrupts 
during input overruns")
Signed-off-by: He Zhe 
---
 drivers/tty/serial/8250/8250_core.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_core.c 
b/drivers/tty/serial/8250/8250_core.c
index 189ab12..e441221 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -1070,15 +1070,16 @@ int serial8250_register_8250_port(struct uart_8250_port 
*up)
 
ret = 0;
}
-   }
 
-   /* Initialise interrupt backoff work if required */
-   if (up->overrun_backoff_time_ms > 0) {
-   uart->overrun_backoff_time_ms = up->overrun_backoff_time_ms;
-   INIT_DELAYED_WORK(>overrun_backoff,
- serial_8250_overrun_backoff_work);
-   } else {
-   uart->overrun_backoff_time_ms = 0;
+   /* Initialise interrupt backoff work if required */
+   if (up->overrun_backoff_time_ms > 0) {
+   uart->overrun_backoff_time_ms =
+   up->overrun_backoff_time_ms;
+   INIT_DELAYED_WORK(>overrun_backoff,
+   serial_8250_overrun_backoff_work);
+   } else {
+   uart->overrun_backoff_time_ms = 0;
+   }
}
 
mutex_unlock(_mutex);
-- 
2.7.4



[PATCH] mm: kmemleak: Turn kmemleak_lock to spin lock and RCU primitives

2019-01-04 Thread zhe.he
From: He Zhe 

It's not necessary to keep consistency between readers and writers of
kmemleak_lock. RCU is more proper for this case. And in order to gain better
performance, we turn the reader locks to RCU read locks and writer locks to
normal spin locks.

"time echo scan > /sys/kernel/debug/kmemleak" is improved from around 1.010s to
0.475s, without lock debug options, tested on Intel Corporation Broadwell Client
platform/Basking Ridge.

spin_lock_nested is replaced with irqsave version since the original outside
irqsave lock is gone. Otherwise we might have the following potential deadlock,
reported by lockdep.

WARNING: HARDIRQ-safe -> HARDIRQ-unsafe lock order detected
4.20.0-standard #1 Not tainted
-
kmemleak/163 [HC0[0]:SC0[0]:HE0:SE1] is trying to acquire:
8d7de78e (&(>lock)->rlock/1){+.+.}, at: scan_block+0xc4/0x1e0

and this task is already holding:
9178399c (&(>lock)->rlock){..-.}, at: scan_gray_list+0xec/0x180
which would create a new lock dependency:
 (&(>lock)->rlock){..-.} -> (&(>lock)->rlock/1){+.+.}

but this new dependency connects a HARDIRQ-irq-safe lock:
 (&(>lock)->rlock){-.-.}

snip

   CPU0CPU1
   
  lock(&(>lock)->rlock/1);
   local_irq_disable();
   lock(&(>lock)->rlock);
   lock(&(>lock)->rlock);
  
lock(&(>lock)->rlock);

Signed-off-by: He Zhe 
Cc: catalin.mari...@arm.com
---
 mm/kmemleak.c | 38 --
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index f9d9dc2..ef9ea00 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -26,7 +26,7 @@
  *
  * The following locks and mutexes are used by kmemleak:
  *
- * - kmemleak_lock (rwlock): protects the object_list modifications and
+ * - kmemleak_lock (spinlock): protects the object_list modifications and
  *   accesses to the object_tree_root. The object_list is the main list
  *   holding the metadata (struct kmemleak_object) for the allocated memory
  *   blocks. The object_tree_root is a red black tree used to look-up
@@ -199,7 +199,7 @@ static LIST_HEAD(gray_list);
 /* search tree for object boundaries */
 static struct rb_root object_tree_root = RB_ROOT;
 /* rw_lock protecting the access to object_list and object_tree_root */
-static DEFINE_RWLOCK(kmemleak_lock);
+static DEFINE_SPINLOCK(kmemleak_lock);
 
 /* allocation caches for kmemleak internal data */
 static struct kmem_cache *object_cache;
@@ -515,9 +515,7 @@ static struct kmemleak_object *find_and_get_object(unsigned 
long ptr, int alias)
struct kmemleak_object *object;
 
rcu_read_lock();
-   read_lock_irqsave(_lock, flags);
object = lookup_object(ptr, alias);
-   read_unlock_irqrestore(_lock, flags);
 
/* check whether the object is still available */
if (object && !get_object(object))
@@ -537,13 +535,13 @@ static struct kmemleak_object 
*find_and_remove_object(unsigned long ptr, int ali
unsigned long flags;
struct kmemleak_object *object;
 
-   write_lock_irqsave(_lock, flags);
+   spin_lock_irqsave(_lock, flags);
object = lookup_object(ptr, alias);
if (object) {
rb_erase(>rb_node, _tree_root);
list_del_rcu(>object_list);
}
-   write_unlock_irqrestore(_lock, flags);
+   spin_unlock_irqrestore(_lock, flags);
 
return object;
 }
@@ -617,7 +615,7 @@ static struct kmemleak_object *create_object(unsigned long 
ptr, size_t size,
/* kernel backtrace */
object->trace_len = __save_stack_trace(object->trace);
 
-   write_lock_irqsave(_lock, flags);
+   spin_lock_irqsave(_lock, flags);
 
min_addr = min(min_addr, ptr);
max_addr = max(max_addr, ptr + size);
@@ -648,7 +646,7 @@ static struct kmemleak_object *create_object(unsigned long 
ptr, size_t size,
 
list_add_tail_rcu(>object_list, _list);
 out:
-   write_unlock_irqrestore(_lock, flags);
+   spin_unlock_irqrestore(_lock, flags);
return object;
 }
 
@@ -1334,7 +1332,7 @@ static void scan_block(void *_start, void *_end,
unsigned long *end = _end - (BYTES_PER_POINTER - 1);
unsigned long flags;
 
-   read_lock_irqsave(_lock, flags);
+   rcu_read_lock();
for (ptr = start; ptr < end; ptr++) {
struct kmemleak_object *object;
unsigned long pointer;
@@ -1350,14 +1348,8 @@ static void scan_block(void *_start, void *_end,
if (pointer < min_addr || pointer >= max_addr)
continue;
 
-   /*
-* No need for get_object() here since we hold kmemleak_lock.
-* object->use_count cannot be dropped to 0 while the object
-* is still present in object_tree_root and object_list
-* (with 

[PATCH] perf/x86/intel: Avoid unnecessary reallocations of memory allocated in cpu hotplug prepare state

2018-12-18 Thread zhe.he
From: He Zhe 

The memory of shared_regs excl_cntrs and constraint_list in struct cpu_hw_events
is currently allocated in hotplug prepare state and freed in dying state. The
memory can actually be reused across multiple cpu pluggings.

Besides, in preempt-rt full mode, the freeing can happen in atomic context and
thus cause the following BUG.

BUG: scheduling while atomic: migration/4/44/0x0002
 snip 
Preemption disabled at:
[] cpu_stopper_thread+0x71/0x100
CPU: 4 PID: 44 Comm: migration/4 Not tainted 4.19.8-rt6-preempt-rt #1
Hardware name: Intel Corporation Broadwell Client platform/Basking Ridge, BIOS 
BDW-E1R1.86C.0100.R03.1411050121 11/05/2014
Call Trace:
 dump_stack+0x4f/0x6a
 ? cpu_stopper_thread+0x71/0x100
 __schedule_bug.cold.16+0x38/0x55
 __schedule+0x484/0x6c0
 schedule+0x3d/0xf0
 rt_spin_lock_slowlock_locked+0x11a/0x2a0
 rt_spin_lock_slowlock+0x57/0x90
 __rt_spin_lock+0x26/0x30
 __write_rt_lock+0x23/0x1a0
 ? intel_pmu_cpu_dying+0x67/0x70
 rt_write_lock+0x2a/0x30
 find_and_remove_object+0x1e/0x80
 delete_object_full+0x10/0x20
 kmemleak_free+0x32/0x50
 kfree+0x104/0x1f0
 intel_pmu_cpu_dying+0x67/0x70
 ? x86_pmu_starting_cpu+0x30/0x30
 x86_pmu_dying_cpu+0x1a/0x30
 cpuhp_invoke_callback+0x9c/0x770
 ? cpu_disable_common+0x241/0x250
 take_cpu_down+0x70/0xa0
 multi_cpu_stop+0x62/0xc0
 ? cpu_stop_queue_work+0x130/0x130
 cpu_stopper_thread+0x79/0x100
 smpboot_thread_fn+0x217/0x2e0
 kthread+0x121/0x140
 ? sort_range+0x30/0x30
 ? kthread_park+0x90/0x90
 ret_from_fork+0x35/0x40

This patch changes to allocate the memory only when it has not been allocated,
and fill it with all zero when it has already been allocated, and remove the
unnecessary freeings.

Credit to Sebastian Andrzej Siewior for his suggestion.

Signed-off-by: He Zhe 
---
 arch/x86/events/core.c   |  2 +-
 arch/x86/events/intel/core.c | 45 
 arch/x86/events/perf_event.h |  5 ++---
 3 files changed, 23 insertions(+), 29 deletions(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 374a197..f07d1b1 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -2010,7 +2010,7 @@ static struct cpu_hw_events *allocate_fake_cpuc(void)
 
/* only needed, if we have extra_regs */
if (x86_pmu.extra_regs) {
-   cpuc->shared_regs = allocate_shared_regs(cpu);
+   allocate_shared_regs(>shared_regs, cpu);
if (!cpuc->shared_regs)
goto error;
}
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index ecc3e34..a3c18de 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -3398,13 +3398,16 @@ ssize_t intel_event_sysfs_show(char *page, u64 config)
return x86_event_sysfs_show(page, config, event);
 }
 
-struct intel_shared_regs *allocate_shared_regs(int cpu)
+void allocate_shared_regs(struct intel_shared_regs **pregs, int cpu)
 {
-   struct intel_shared_regs *regs;
+   struct intel_shared_regs *regs = *pregs;
int i;
 
-   regs = kzalloc_node(sizeof(struct intel_shared_regs),
-   GFP_KERNEL, cpu_to_node(cpu));
+   if (regs)
+   memset(regs, 0, sizeof(struct intel_shared_regs));
+   else
+   regs = *pregs = kzalloc_node(sizeof(struct intel_shared_regs),
+GFP_KERNEL, cpu_to_node(cpu));
if (regs) {
/*
 * initialize the locks to keep lockdep happy
@@ -3414,20 +3417,21 @@ struct intel_shared_regs *allocate_shared_regs(int cpu)
 
regs->core_id = -1;
}
-   return regs;
 }
 
-static struct intel_excl_cntrs *allocate_excl_cntrs(int cpu)
+static void allocate_excl_cntrs(struct intel_excl_cntrs **pc, int cpu)
 {
-   struct intel_excl_cntrs *c;
+   struct intel_excl_cntrs *c = *pc;
 
-   c = kzalloc_node(sizeof(struct intel_excl_cntrs),
-GFP_KERNEL, cpu_to_node(cpu));
+   if (c)
+   memset(c, 0, sizeof(struct intel_excl_cntrs));
+   else
+   c = *pc = kzalloc_node(sizeof(struct intel_excl_cntrs),
+  GFP_KERNEL, cpu_to_node(cpu));
if (c) {
raw_spin_lock_init(>lock);
c->core_id = -1;
}
-   return c;
 }
 
 static int intel_pmu_cpu_prepare(int cpu)
@@ -3435,7 +3439,7 @@ static int intel_pmu_cpu_prepare(int cpu)
struct cpu_hw_events *cpuc = _cpu(cpu_hw_events, cpu);
 
if (x86_pmu.extra_regs || x86_pmu.lbr_sel_map) {
-   cpuc->shared_regs = allocate_shared_regs(cpu);
+   allocate_shared_regs(>shared_regs, cpu);
if (!cpuc->shared_regs)
goto err;
}
@@ -3443,11 +3447,14 @@ static int intel_pmu_cpu_prepare(int cpu)
if (x86_pmu.flags & PMU_FL_EXCL_CNTRS) {
size_t sz = X86_PMC_IDX_MAX * sizeof(struct 

[PATCH v2] kmemleak: Turn kmemleak_lock to raw spinlock on RT

2018-11-22 Thread zhe.he
From: He Zhe 

kmemleak_lock, as a rwlock on RT, can possibly be held in atomic context and
causes the follow BUG.

BUG: scheduling while atomic: migration/15/132/0x0002
Modules linked in: iTCO_wdt iTCO_vendor_support intel_rapl pcc_cpufreq
pnd2_edac intel_powerclamp coretemp crct10dif_pclmul crct10dif_common
aesni_intel matroxfb_base aes_x86_64 matroxfb_g450 matroxfb_accel
crypto_simd matroxfb_DAC1064 cryptd glue_helper g450_pll matroxfb_misc
i2c_ismt i2c_i801 acpi_cpufreq
Preemption disabled at:
[] cpu_stopper_thread+0x71/0x100
CPU: 15 PID: 132 Comm: migration/15 Not tainted 4.19.0-rt1-preempt-rt #1
Hardware name: Intel Corp. Harcuvar/Server, BIOS 
HAVLCRB1.X64.0015.D62.1708310404 08/31/2017
Call Trace:
 dump_stack+0x4f/0x6a
 ? cpu_stopper_thread+0x71/0x100
 __schedule_bug.cold.16+0x38/0x55
 __schedule+0x484/0x6c0
 schedule+0x3d/0xe0
 rt_spin_lock_slowlock_locked+0x118/0x2a0
 rt_spin_lock_slowlock+0x57/0x90
 __rt_spin_lock+0x26/0x30
 __write_rt_lock+0x23/0x1a0
 ? intel_pmu_cpu_dying+0x67/0x70
 rt_write_lock+0x2a/0x30
 find_and_remove_object+0x1e/0x80
 delete_object_full+0x10/0x20
 kmemleak_free+0x32/0x50
 kfree+0x104/0x1f0
 ? x86_pmu_starting_cpu+0x30/0x30
 intel_pmu_cpu_dying+0x67/0x70
 x86_pmu_dying_cpu+0x1a/0x30
 cpuhp_invoke_callback+0x92/0x700
 take_cpu_down+0x70/0xa0
 multi_cpu_stop+0x62/0xc0
 ? cpu_stop_queue_work+0x130/0x130
 cpu_stopper_thread+0x79/0x100
 smpboot_thread_fn+0x20f/0x2d0
 kthread+0x121/0x140
 ? sort_range+0x30/0x30
 ? kthread_park+0x90/0x90
 ret_from_fork+0x35/0x40

And on v4.18 stable tree the following call trace, caused by grabbing
kmemleak_lock again, is also observed.

kernel BUG at kernel/locking/rtmutex.c:1048! 
invalid opcode:  [#1] PREEMPT SMP PTI 
CPU: 5 PID: 689 Comm: mkfs.ext4 Not tainted 4.18.16-rt9-preempt-rt #1 
Hardware name: Intel Corp. Harcuvar/Server, BIOS 
HAVLCRB1.X64.0015.D62.1708310404 08/31/2017 
RIP: 0010:rt_spin_lock_slowlock_locked+0x277/0x2a0 
Code: e8 5e 64 61 ff e9 bc fe ff ff e8 54 64 61 ff e9 b7 fe ff ff 0f 0b e8 98 
57 53 ff e9 43 fe ff ff e8 8e 57 53 ff e9 74 ff ff ff <0f> 0b 0f 0b 0f 0b 48 8b 
43 10 48 85 c0 74 06 48 3b 58 38 75 0b 49 
RSP: 0018:936846d4f3b0 EFLAGS: 00010046 
RAX: 8e3680361e00 RBX: 83a8b240 RCX: 0001 
RDX:  RSI: 8e3680361e00 RDI: 83a8b258 
RBP: 936846d4f3e8 R08: 8e3680361e01 R09: 82adfdf0 
R10: 827ede18 R11:  R12: 936846d4f3f8 
R13: 8e3680361e00 R14: 936846d4f3f8 R15: 0246 
FS: 7fc8b6bfd780() GS:8e369f34() knlGS: 
CS: 0010 DS:  ES:  CR0: 80050033 
CR2: 55fb5659e000 CR3: 0007fdd14000 CR4: 003406e0 
Call Trace: 
 ? preempt_count_add+0x74/0xc0 
 rt_spin_lock_slowlock+0x57/0x90 
 ? __kernel_text_address+0x12/0x40 
 ? __save_stack_trace+0x75/0x100 
 __rt_spin_lock+0x26/0x30 
 __write_rt_lock+0x23/0x1a0 
 rt_write_lock+0x2a/0x30 
 create_object+0x17d/0x2b0 
 kmemleak_alloc+0x34/0x50 
 kmem_cache_alloc+0x146/0x220 
 ? mempool_alloc_slab+0x15/0x20 
 mempool_alloc_slab+0x15/0x20 
 mempool_alloc+0x65/0x170 
 sg_pool_alloc+0x21/0x60 
 __sg_alloc_table+0x101/0x160 
 ? sg_free_table_chained+0x30/0x30 
 sg_alloc_table_chained+0x8b/0xb0 
 scsi_init_sgtable+0x31/0x90 
 scsi_init_io+0x44/0x130 
 sd_setup_write_same16_cmnd+0xef/0x150 
 sd_init_command+0x6bf/0xaa0 
 ? cgroup_base_stat_cputime_account_end.isra.0+0x26/0x60 
 ? elv_rb_del+0x2a/0x40 
 scsi_setup_cmnd+0x8e/0x140 
 scsi_prep_fn+0x5d/0x140 
 blk_peek_request+0xda/0x2f0 
 scsi_request_fn+0x33/0x550 
 ? cfq_rb_erase+0x23/0x40 
 __blk_run_queue+0x43/0x60 
 cfq_insert_request+0x2f3/0x5d0 
 __elv_add_request+0x160/0x290 
 blk_flush_plug_list+0x204/0x230 
 schedule+0x87/0xe0 
 __write_rt_lock+0x18b/0x1a0 
 rt_write_lock+0x2a/0x30 
 create_object+0x17d/0x2b0 
 kmemleak_alloc+0x34/0x50 
 __kmalloc_node+0x1cd/0x340 
 alloc_request_size+0x30/0x70 
 mempool_alloc+0x65/0x170 
 ? ioc_lookup_icq+0x54/0x70 
 get_request+0x4e3/0x8d0 
 ? wait_woken+0x80/0x80 
 blk_queue_bio+0x153/0x470 
 generic_make_request+0x1dc/0x3f0 
 submit_bio+0x49/0x140 
 ? next_bio+0x38/0x40 
 submit_bio_wait+0x59/0x90 
 blkdev_issue_discard+0x7a/0xd0 
 ? _raw_spin_unlock_irqrestore+0x18/0x50 
 blk_ioctl_discard+0xc7/0x110 
 blkdev_ioctl+0x57e/0x960 
 ? __wake_up+0x13/0x20 
 block_ioctl+0x3d/0x50 
 do_vfs_ioctl+0xa8/0x610 
 ? vfs_write+0x166/0x1b0 
 ksys_ioctl+0x67/0x90 
 __x64_sys_ioctl+0x1a/0x20 
 do_syscall_64+0x4d/0xf0 
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

kmemleak is an error detecting feature. We would not expect as good performance
as without it. As there is no raw rwlock defining helpers, we turn kmemleak_lock
to a raw spinlock.

Signed-off-by: He Zhe 
Cc: catalin.mari...@arm.com
Cc: bige...@linutronix.de
Cc: t...@linutronix.de
Cc: rost...@goodmis.org
---
v2: Remove stable tag as this is only for preempt-rt patchset

 mm/kmemleak.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git 

[PATCH v2] kmemleak: Turn kmemleak_lock to raw spinlock on RT

2018-11-22 Thread zhe.he
From: He Zhe 

kmemleak_lock, as a rwlock on RT, can possibly be held in atomic context and
causes the follow BUG.

BUG: scheduling while atomic: migration/15/132/0x0002
Modules linked in: iTCO_wdt iTCO_vendor_support intel_rapl pcc_cpufreq
pnd2_edac intel_powerclamp coretemp crct10dif_pclmul crct10dif_common
aesni_intel matroxfb_base aes_x86_64 matroxfb_g450 matroxfb_accel
crypto_simd matroxfb_DAC1064 cryptd glue_helper g450_pll matroxfb_misc
i2c_ismt i2c_i801 acpi_cpufreq
Preemption disabled at:
[] cpu_stopper_thread+0x71/0x100
CPU: 15 PID: 132 Comm: migration/15 Not tainted 4.19.0-rt1-preempt-rt #1
Hardware name: Intel Corp. Harcuvar/Server, BIOS 
HAVLCRB1.X64.0015.D62.1708310404 08/31/2017
Call Trace:
 dump_stack+0x4f/0x6a
 ? cpu_stopper_thread+0x71/0x100
 __schedule_bug.cold.16+0x38/0x55
 __schedule+0x484/0x6c0
 schedule+0x3d/0xe0
 rt_spin_lock_slowlock_locked+0x118/0x2a0
 rt_spin_lock_slowlock+0x57/0x90
 __rt_spin_lock+0x26/0x30
 __write_rt_lock+0x23/0x1a0
 ? intel_pmu_cpu_dying+0x67/0x70
 rt_write_lock+0x2a/0x30
 find_and_remove_object+0x1e/0x80
 delete_object_full+0x10/0x20
 kmemleak_free+0x32/0x50
 kfree+0x104/0x1f0
 ? x86_pmu_starting_cpu+0x30/0x30
 intel_pmu_cpu_dying+0x67/0x70
 x86_pmu_dying_cpu+0x1a/0x30
 cpuhp_invoke_callback+0x92/0x700
 take_cpu_down+0x70/0xa0
 multi_cpu_stop+0x62/0xc0
 ? cpu_stop_queue_work+0x130/0x130
 cpu_stopper_thread+0x79/0x100
 smpboot_thread_fn+0x20f/0x2d0
 kthread+0x121/0x140
 ? sort_range+0x30/0x30
 ? kthread_park+0x90/0x90
 ret_from_fork+0x35/0x40

And on v4.18 stable tree the following call trace, caused by grabbing
kmemleak_lock again, is also observed.

kernel BUG at kernel/locking/rtmutex.c:1048! 
invalid opcode:  [#1] PREEMPT SMP PTI 
CPU: 5 PID: 689 Comm: mkfs.ext4 Not tainted 4.18.16-rt9-preempt-rt #1 
Hardware name: Intel Corp. Harcuvar/Server, BIOS 
HAVLCRB1.X64.0015.D62.1708310404 08/31/2017 
RIP: 0010:rt_spin_lock_slowlock_locked+0x277/0x2a0 
Code: e8 5e 64 61 ff e9 bc fe ff ff e8 54 64 61 ff e9 b7 fe ff ff 0f 0b e8 98 
57 53 ff e9 43 fe ff ff e8 8e 57 53 ff e9 74 ff ff ff <0f> 0b 0f 0b 0f 0b 48 8b 
43 10 48 85 c0 74 06 48 3b 58 38 75 0b 49 
RSP: 0018:936846d4f3b0 EFLAGS: 00010046 
RAX: 8e3680361e00 RBX: 83a8b240 RCX: 0001 
RDX:  RSI: 8e3680361e00 RDI: 83a8b258 
RBP: 936846d4f3e8 R08: 8e3680361e01 R09: 82adfdf0 
R10: 827ede18 R11:  R12: 936846d4f3f8 
R13: 8e3680361e00 R14: 936846d4f3f8 R15: 0246 
FS: 7fc8b6bfd780() GS:8e369f34() knlGS: 
CS: 0010 DS:  ES:  CR0: 80050033 
CR2: 55fb5659e000 CR3: 0007fdd14000 CR4: 003406e0 
Call Trace: 
 ? preempt_count_add+0x74/0xc0 
 rt_spin_lock_slowlock+0x57/0x90 
 ? __kernel_text_address+0x12/0x40 
 ? __save_stack_trace+0x75/0x100 
 __rt_spin_lock+0x26/0x30 
 __write_rt_lock+0x23/0x1a0 
 rt_write_lock+0x2a/0x30 
 create_object+0x17d/0x2b0 
 kmemleak_alloc+0x34/0x50 
 kmem_cache_alloc+0x146/0x220 
 ? mempool_alloc_slab+0x15/0x20 
 mempool_alloc_slab+0x15/0x20 
 mempool_alloc+0x65/0x170 
 sg_pool_alloc+0x21/0x60 
 __sg_alloc_table+0x101/0x160 
 ? sg_free_table_chained+0x30/0x30 
 sg_alloc_table_chained+0x8b/0xb0 
 scsi_init_sgtable+0x31/0x90 
 scsi_init_io+0x44/0x130 
 sd_setup_write_same16_cmnd+0xef/0x150 
 sd_init_command+0x6bf/0xaa0 
 ? cgroup_base_stat_cputime_account_end.isra.0+0x26/0x60 
 ? elv_rb_del+0x2a/0x40 
 scsi_setup_cmnd+0x8e/0x140 
 scsi_prep_fn+0x5d/0x140 
 blk_peek_request+0xda/0x2f0 
 scsi_request_fn+0x33/0x550 
 ? cfq_rb_erase+0x23/0x40 
 __blk_run_queue+0x43/0x60 
 cfq_insert_request+0x2f3/0x5d0 
 __elv_add_request+0x160/0x290 
 blk_flush_plug_list+0x204/0x230 
 schedule+0x87/0xe0 
 __write_rt_lock+0x18b/0x1a0 
 rt_write_lock+0x2a/0x30 
 create_object+0x17d/0x2b0 
 kmemleak_alloc+0x34/0x50 
 __kmalloc_node+0x1cd/0x340 
 alloc_request_size+0x30/0x70 
 mempool_alloc+0x65/0x170 
 ? ioc_lookup_icq+0x54/0x70 
 get_request+0x4e3/0x8d0 
 ? wait_woken+0x80/0x80 
 blk_queue_bio+0x153/0x470 
 generic_make_request+0x1dc/0x3f0 
 submit_bio+0x49/0x140 
 ? next_bio+0x38/0x40 
 submit_bio_wait+0x59/0x90 
 blkdev_issue_discard+0x7a/0xd0 
 ? _raw_spin_unlock_irqrestore+0x18/0x50 
 blk_ioctl_discard+0xc7/0x110 
 blkdev_ioctl+0x57e/0x960 
 ? __wake_up+0x13/0x20 
 block_ioctl+0x3d/0x50 
 do_vfs_ioctl+0xa8/0x610 
 ? vfs_write+0x166/0x1b0 
 ksys_ioctl+0x67/0x90 
 __x64_sys_ioctl+0x1a/0x20 
 do_syscall_64+0x4d/0xf0 
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

kmemleak is an error detecting feature. We would not expect as good performance
as without it. As there is no raw rwlock defining helpers, we turn kmemleak_lock
to a raw spinlock.

Signed-off-by: He Zhe 
Cc: catalin.mari...@arm.com
Cc: bige...@linutronix.de
Cc: t...@linutronix.de
Cc: rost...@goodmis.org
---
v2: Remove stable tag as this is only for preempt-rt patchset

 mm/kmemleak.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git 

[PATCH] kmemleak: Turn kmemleak_lock to raw spinlock on RT

2018-11-12 Thread zhe.he
From: He Zhe 

kmemleak_lock, as a rwlock on RT, can possibly be held in atomic context and
causes the follow BUG.

BUG: scheduling while atomic: migration/15/132/0x0002
Modules linked in: iTCO_wdt iTCO_vendor_support intel_rapl pcc_cpufreq
pnd2_edac intel_powerclamp coretemp crct10dif_pclmul crct10dif_common
aesni_intel matroxfb_base aes_x86_64 matroxfb_g450 matroxfb_accel
crypto_simd matroxfb_DAC1064 cryptd glue_helper g450_pll matroxfb_misc
i2c_ismt i2c_i801 acpi_cpufreq
Preemption disabled at:
[] cpu_stopper_thread+0x71/0x100
CPU: 15 PID: 132 Comm: migration/15 Not tainted 4.19.0-rt1-preempt-rt #1
Hardware name: Intel Corp. Harcuvar/Server, BIOS 
HAVLCRB1.X64.0015.D62.1708310404 08/31/2017
Call Trace:
 dump_stack+0x4f/0x6a
 ? cpu_stopper_thread+0x71/0x100
 __schedule_bug.cold.16+0x38/0x55
 __schedule+0x484/0x6c0
 schedule+0x3d/0xe0
 rt_spin_lock_slowlock_locked+0x118/0x2a0
 rt_spin_lock_slowlock+0x57/0x90
 __rt_spin_lock+0x26/0x30
 __write_rt_lock+0x23/0x1a0
 ? intel_pmu_cpu_dying+0x67/0x70
 rt_write_lock+0x2a/0x30
 find_and_remove_object+0x1e/0x80
 delete_object_full+0x10/0x20
 kmemleak_free+0x32/0x50
 kfree+0x104/0x1f0
 ? x86_pmu_starting_cpu+0x30/0x30
 intel_pmu_cpu_dying+0x67/0x70
 x86_pmu_dying_cpu+0x1a/0x30
 cpuhp_invoke_callback+0x92/0x700
 take_cpu_down+0x70/0xa0
 multi_cpu_stop+0x62/0xc0
 ? cpu_stop_queue_work+0x130/0x130
 cpu_stopper_thread+0x79/0x100
 smpboot_thread_fn+0x20f/0x2d0
 kthread+0x121/0x140
 ? sort_range+0x30/0x30
 ? kthread_park+0x90/0x90
 ret_from_fork+0x35/0x40

And on v4.18 stable tree the following call trace, caused by grabbing
kmemleak_lock again, is also observed.

kernel BUG at kernel/locking/rtmutex.c:1048! 
invalid opcode:  [#1] PREEMPT SMP PTI 
CPU: 5 PID: 689 Comm: mkfs.ext4 Not tainted 4.18.16-rt9-preempt-rt #1 
Hardware name: Intel Corp. Harcuvar/Server, BIOS 
HAVLCRB1.X64.0015.D62.1708310404 08/31/2017 
RIP: 0010:rt_spin_lock_slowlock_locked+0x277/0x2a0 
Code: e8 5e 64 61 ff e9 bc fe ff ff e8 54 64 61 ff e9 b7 fe ff ff 0f 0b e8 98 
57 53 ff e9 43 fe ff ff e8 8e 57 53 ff e9 74 ff ff ff <0f> 0b 0f 0b 0f 0b 48 8b 
43 10 48 85 c0 74 06 48 3b 58 38 75 0b 49 
RSP: 0018:936846d4f3b0 EFLAGS: 00010046 
RAX: 8e3680361e00 RBX: 83a8b240 RCX: 0001 
RDX:  RSI: 8e3680361e00 RDI: 83a8b258 
RBP: 936846d4f3e8 R08: 8e3680361e01 R09: 82adfdf0 
R10: 827ede18 R11:  R12: 936846d4f3f8 
R13: 8e3680361e00 R14: 936846d4f3f8 R15: 0246 
FS: 7fc8b6bfd780() GS:8e369f34() knlGS: 
CS: 0010 DS:  ES:  CR0: 80050033 
CR2: 55fb5659e000 CR3: 0007fdd14000 CR4: 003406e0 
Call Trace: 
 ? preempt_count_add+0x74/0xc0 
 rt_spin_lock_slowlock+0x57/0x90 
 ? __kernel_text_address+0x12/0x40 
 ? __save_stack_trace+0x75/0x100 
 __rt_spin_lock+0x26/0x30 
 __write_rt_lock+0x23/0x1a0 
 rt_write_lock+0x2a/0x30 
 create_object+0x17d/0x2b0 
 kmemleak_alloc+0x34/0x50 
 kmem_cache_alloc+0x146/0x220 
 ? mempool_alloc_slab+0x15/0x20 
 mempool_alloc_slab+0x15/0x20 
 mempool_alloc+0x65/0x170 
 sg_pool_alloc+0x21/0x60 
 __sg_alloc_table+0x101/0x160 
 ? sg_free_table_chained+0x30/0x30 
 sg_alloc_table_chained+0x8b/0xb0 
 scsi_init_sgtable+0x31/0x90 
 scsi_init_io+0x44/0x130 
 sd_setup_write_same16_cmnd+0xef/0x150 
 sd_init_command+0x6bf/0xaa0 
 ? cgroup_base_stat_cputime_account_end.isra.0+0x26/0x60 
 ? elv_rb_del+0x2a/0x40 
 scsi_setup_cmnd+0x8e/0x140 
 scsi_prep_fn+0x5d/0x140 
 blk_peek_request+0xda/0x2f0 
 scsi_request_fn+0x33/0x550 
 ? cfq_rb_erase+0x23/0x40 
 __blk_run_queue+0x43/0x60 
 cfq_insert_request+0x2f3/0x5d0 
 __elv_add_request+0x160/0x290 
 blk_flush_plug_list+0x204/0x230 
 schedule+0x87/0xe0 
 __write_rt_lock+0x18b/0x1a0 
 rt_write_lock+0x2a/0x30 
 create_object+0x17d/0x2b0 
 kmemleak_alloc+0x34/0x50 
 __kmalloc_node+0x1cd/0x340 
 alloc_request_size+0x30/0x70 
 mempool_alloc+0x65/0x170 
 ? ioc_lookup_icq+0x54/0x70 
 get_request+0x4e3/0x8d0 
 ? wait_woken+0x80/0x80 
 blk_queue_bio+0x153/0x470 
 generic_make_request+0x1dc/0x3f0 
 submit_bio+0x49/0x140 
 ? next_bio+0x38/0x40 
 submit_bio_wait+0x59/0x90 
 blkdev_issue_discard+0x7a/0xd0 
 ? _raw_spin_unlock_irqrestore+0x18/0x50 
 blk_ioctl_discard+0xc7/0x110 
 blkdev_ioctl+0x57e/0x960 
 ? __wake_up+0x13/0x20 
 block_ioctl+0x3d/0x50 
 do_vfs_ioctl+0xa8/0x610 
 ? vfs_write+0x166/0x1b0 
 ksys_ioctl+0x67/0x90 
 __x64_sys_ioctl+0x1a/0x20 
 do_syscall_64+0x4d/0xf0 
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

kmemleak is an error detecting feature. We would not expect as good performance
as without it. As there is no raw rwlock defining helpers, we turn kmemleak_lock
to a raw spinlock.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: catalin.mari...@arm.com
Cc: bige...@linutronix.de
Cc: t...@linutronix.de
Cc: rost...@goodmis.org
---
 mm/kmemleak.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 

[PATCH] kmemleak: Turn kmemleak_lock to raw spinlock on RT

2018-11-12 Thread zhe.he
From: He Zhe 

kmemleak_lock, as a rwlock on RT, can possibly be held in atomic context and
causes the follow BUG.

BUG: scheduling while atomic: migration/15/132/0x0002
Modules linked in: iTCO_wdt iTCO_vendor_support intel_rapl pcc_cpufreq
pnd2_edac intel_powerclamp coretemp crct10dif_pclmul crct10dif_common
aesni_intel matroxfb_base aes_x86_64 matroxfb_g450 matroxfb_accel
crypto_simd matroxfb_DAC1064 cryptd glue_helper g450_pll matroxfb_misc
i2c_ismt i2c_i801 acpi_cpufreq
Preemption disabled at:
[] cpu_stopper_thread+0x71/0x100
CPU: 15 PID: 132 Comm: migration/15 Not tainted 4.19.0-rt1-preempt-rt #1
Hardware name: Intel Corp. Harcuvar/Server, BIOS 
HAVLCRB1.X64.0015.D62.1708310404 08/31/2017
Call Trace:
 dump_stack+0x4f/0x6a
 ? cpu_stopper_thread+0x71/0x100
 __schedule_bug.cold.16+0x38/0x55
 __schedule+0x484/0x6c0
 schedule+0x3d/0xe0
 rt_spin_lock_slowlock_locked+0x118/0x2a0
 rt_spin_lock_slowlock+0x57/0x90
 __rt_spin_lock+0x26/0x30
 __write_rt_lock+0x23/0x1a0
 ? intel_pmu_cpu_dying+0x67/0x70
 rt_write_lock+0x2a/0x30
 find_and_remove_object+0x1e/0x80
 delete_object_full+0x10/0x20
 kmemleak_free+0x32/0x50
 kfree+0x104/0x1f0
 ? x86_pmu_starting_cpu+0x30/0x30
 intel_pmu_cpu_dying+0x67/0x70
 x86_pmu_dying_cpu+0x1a/0x30
 cpuhp_invoke_callback+0x92/0x700
 take_cpu_down+0x70/0xa0
 multi_cpu_stop+0x62/0xc0
 ? cpu_stop_queue_work+0x130/0x130
 cpu_stopper_thread+0x79/0x100
 smpboot_thread_fn+0x20f/0x2d0
 kthread+0x121/0x140
 ? sort_range+0x30/0x30
 ? kthread_park+0x90/0x90
 ret_from_fork+0x35/0x40

And on v4.18 stable tree the following call trace, caused by grabbing
kmemleak_lock again, is also observed.

kernel BUG at kernel/locking/rtmutex.c:1048! 
invalid opcode:  [#1] PREEMPT SMP PTI 
CPU: 5 PID: 689 Comm: mkfs.ext4 Not tainted 4.18.16-rt9-preempt-rt #1 
Hardware name: Intel Corp. Harcuvar/Server, BIOS 
HAVLCRB1.X64.0015.D62.1708310404 08/31/2017 
RIP: 0010:rt_spin_lock_slowlock_locked+0x277/0x2a0 
Code: e8 5e 64 61 ff e9 bc fe ff ff e8 54 64 61 ff e9 b7 fe ff ff 0f 0b e8 98 
57 53 ff e9 43 fe ff ff e8 8e 57 53 ff e9 74 ff ff ff <0f> 0b 0f 0b 0f 0b 48 8b 
43 10 48 85 c0 74 06 48 3b 58 38 75 0b 49 
RSP: 0018:936846d4f3b0 EFLAGS: 00010046 
RAX: 8e3680361e00 RBX: 83a8b240 RCX: 0001 
RDX:  RSI: 8e3680361e00 RDI: 83a8b258 
RBP: 936846d4f3e8 R08: 8e3680361e01 R09: 82adfdf0 
R10: 827ede18 R11:  R12: 936846d4f3f8 
R13: 8e3680361e00 R14: 936846d4f3f8 R15: 0246 
FS: 7fc8b6bfd780() GS:8e369f34() knlGS: 
CS: 0010 DS:  ES:  CR0: 80050033 
CR2: 55fb5659e000 CR3: 0007fdd14000 CR4: 003406e0 
Call Trace: 
 ? preempt_count_add+0x74/0xc0 
 rt_spin_lock_slowlock+0x57/0x90 
 ? __kernel_text_address+0x12/0x40 
 ? __save_stack_trace+0x75/0x100 
 __rt_spin_lock+0x26/0x30 
 __write_rt_lock+0x23/0x1a0 
 rt_write_lock+0x2a/0x30 
 create_object+0x17d/0x2b0 
 kmemleak_alloc+0x34/0x50 
 kmem_cache_alloc+0x146/0x220 
 ? mempool_alloc_slab+0x15/0x20 
 mempool_alloc_slab+0x15/0x20 
 mempool_alloc+0x65/0x170 
 sg_pool_alloc+0x21/0x60 
 __sg_alloc_table+0x101/0x160 
 ? sg_free_table_chained+0x30/0x30 
 sg_alloc_table_chained+0x8b/0xb0 
 scsi_init_sgtable+0x31/0x90 
 scsi_init_io+0x44/0x130 
 sd_setup_write_same16_cmnd+0xef/0x150 
 sd_init_command+0x6bf/0xaa0 
 ? cgroup_base_stat_cputime_account_end.isra.0+0x26/0x60 
 ? elv_rb_del+0x2a/0x40 
 scsi_setup_cmnd+0x8e/0x140 
 scsi_prep_fn+0x5d/0x140 
 blk_peek_request+0xda/0x2f0 
 scsi_request_fn+0x33/0x550 
 ? cfq_rb_erase+0x23/0x40 
 __blk_run_queue+0x43/0x60 
 cfq_insert_request+0x2f3/0x5d0 
 __elv_add_request+0x160/0x290 
 blk_flush_plug_list+0x204/0x230 
 schedule+0x87/0xe0 
 __write_rt_lock+0x18b/0x1a0 
 rt_write_lock+0x2a/0x30 
 create_object+0x17d/0x2b0 
 kmemleak_alloc+0x34/0x50 
 __kmalloc_node+0x1cd/0x340 
 alloc_request_size+0x30/0x70 
 mempool_alloc+0x65/0x170 
 ? ioc_lookup_icq+0x54/0x70 
 get_request+0x4e3/0x8d0 
 ? wait_woken+0x80/0x80 
 blk_queue_bio+0x153/0x470 
 generic_make_request+0x1dc/0x3f0 
 submit_bio+0x49/0x140 
 ? next_bio+0x38/0x40 
 submit_bio_wait+0x59/0x90 
 blkdev_issue_discard+0x7a/0xd0 
 ? _raw_spin_unlock_irqrestore+0x18/0x50 
 blk_ioctl_discard+0xc7/0x110 
 blkdev_ioctl+0x57e/0x960 
 ? __wake_up+0x13/0x20 
 block_ioctl+0x3d/0x50 
 do_vfs_ioctl+0xa8/0x610 
 ? vfs_write+0x166/0x1b0 
 ksys_ioctl+0x67/0x90 
 __x64_sys_ioctl+0x1a/0x20 
 do_syscall_64+0x4d/0xf0 
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

kmemleak is an error detecting feature. We would not expect as good performance
as without it. As there is no raw rwlock defining helpers, we turn kmemleak_lock
to a raw spinlock.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: catalin.mari...@arm.com
Cc: bige...@linutronix.de
Cc: t...@linutronix.de
Cc: rost...@goodmis.org
---
 mm/kmemleak.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 

[PATCH v5 3/4] printk: Add KBUILD_MODNAME and remove a redundant print prefix

2018-09-29 Thread zhe.he
From: He Zhe 

Add KBUILD_MODNAME to make prints more clear.

Signed-off-by: He Zhe 
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
 kernel/printk/printk.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index c9a0be3..0f24d7f 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -16,6 +16,8 @@
  * 01Mar01 Andrew Morton
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
@@ -2695,7 +2697,7 @@ void register_console(struct console *newcon)
 
if (newcon->flags & CON_EXTENDED)
if (!nr_ext_console_drivers++)
-   pr_info("printk: continuation disabled due to ext 
consoles, expect more fragments in /dev/kmsg\n");
+   pr_info("continuation disabled due to ext consoles, 
expect more fragments in /dev/kmsg\n");
 
if (newcon->flags & CON_PRINTBUFFER) {
/*
-- 
2.7.4



[PATCH v5 3/4] printk: Add KBUILD_MODNAME and remove a redundant print prefix

2018-09-29 Thread zhe.he
From: He Zhe 

Add KBUILD_MODNAME to make prints more clear.

Signed-off-by: He Zhe 
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
 kernel/printk/printk.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index c9a0be3..0f24d7f 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -16,6 +16,8 @@
  * 01Mar01 Andrew Morton
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
@@ -2695,7 +2697,7 @@ void register_console(struct console *newcon)
 
if (newcon->flags & CON_EXTENDED)
if (!nr_ext_console_drivers++)
-   pr_info("printk: continuation disabled due to ext 
consoles, expect more fragments in /dev/kmsg\n");
+   pr_info("continuation disabled due to ext consoles, 
expect more fragments in /dev/kmsg\n");
 
if (newcon->flags & CON_PRINTBUFFER) {
/*
-- 
2.7.4



[PATCH v5 4/4] printk: Give error on attempt to set log buffer length to over 4G

2018-09-29 Thread zhe.he
From: He Zhe 

Give explicit error for users who want to use larger log buffer.

Signed-off-by: He Zhe 
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
 kernel/printk/printk.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index b84aac0..5ccfd5d 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1039,18 +1039,23 @@ void log_buf_vmcoreinfo_setup(void)
 static unsigned long __initdata new_log_buf_len;
 
 /* we practice scaling the ring buffer by powers of 2 */
-static void __init log_buf_len_update(unsigned size)
+static void __init log_buf_len_update(u64 size)
 {
+   if (size > UINT_MAX) {
+   size = UINT_MAX;
+   pr_err("log_buf over 4G is not supported.\n");
+   }
+
if (size)
size = roundup_pow_of_two(size);
if (size > log_buf_len)
-   new_log_buf_len = size;
+   new_log_buf_len = (unsigned long)size;
 }
 
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned int size;
+   u64 size;
 
if (!str)
return -EINVAL;
-- 
2.7.4



[PATCH v5 1/4] printk: Fix panic caused by passing log_buf_len to command line

2018-09-29 Thread zhe.he
From: He Zhe 

log_buf_len_setup does not check input argument before passing it to
simple_strtoull. The argument would be a NULL pointer if "log_buf_len",
without its value, is set in command line and thus causes the following
panic.

PANIC: early exception 0xe3 IP 10:aaeacd0d error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc4-yocto-standard+ #1
[0.00] RIP: 0010:_parse_integer_fixup_radix+0xd/0x70
...
[0.00] Call Trace:
[0.00]  simple_strtoull+0x29/0x70
[0.00]  memparse+0x26/0x90
[0.00]  log_buf_len_setup+0x17/0x22
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4ee
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
v2:
Split out the addition of pr_fmt and the unsigned update
v3:
Remove error message for NULL pointer
Add check and error message for over 4G use
v4:
Split each piece into one patch
v5:
Remove a redundant print prefix

 kernel/printk/printk.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 9bf5404..06045ab 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1048,7 +1048,12 @@ static void __init log_buf_len_update(unsigned size)
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned size = memparse(str, );
+   unsigned int size;
+
+   if (!str)
+   return -EINVAL;
+
+   size = memparse(str, );
 
log_buf_len_update(size);
 
-- 
2.7.4



[PATCH v5 2/4] printk: Correct wrong casting

2018-09-29 Thread zhe.he
From: He Zhe 

Correct wrong casting that might cut off the normal output.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
 kernel/printk/printk.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 06045ab..c9a0be3 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2356,8 +2356,9 @@ void console_unlock(void)
printk_safe_enter_irqsave(flags);
raw_spin_lock(_lock);
if (console_seq < log_first_seq) {
-   len = sprintf(text, "** %u printk messages dropped 
**\n",
- (unsigned)(log_first_seq - console_seq));
+   len = sprintf(text,
+ "** %llu printk messages dropped **\n",
+ log_first_seq - console_seq);
 
/* messages are gone, move to first one */
console_seq = log_first_seq;
-- 
2.7.4



[PATCH v5 4/4] printk: Give error on attempt to set log buffer length to over 4G

2018-09-29 Thread zhe.he
From: He Zhe 

Give explicit error for users who want to use larger log buffer.

Signed-off-by: He Zhe 
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
 kernel/printk/printk.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index b84aac0..5ccfd5d 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1039,18 +1039,23 @@ void log_buf_vmcoreinfo_setup(void)
 static unsigned long __initdata new_log_buf_len;
 
 /* we practice scaling the ring buffer by powers of 2 */
-static void __init log_buf_len_update(unsigned size)
+static void __init log_buf_len_update(u64 size)
 {
+   if (size > UINT_MAX) {
+   size = UINT_MAX;
+   pr_err("log_buf over 4G is not supported.\n");
+   }
+
if (size)
size = roundup_pow_of_two(size);
if (size > log_buf_len)
-   new_log_buf_len = size;
+   new_log_buf_len = (unsigned long)size;
 }
 
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned int size;
+   u64 size;
 
if (!str)
return -EINVAL;
-- 
2.7.4



[PATCH v5 1/4] printk: Fix panic caused by passing log_buf_len to command line

2018-09-29 Thread zhe.he
From: He Zhe 

log_buf_len_setup does not check input argument before passing it to
simple_strtoull. The argument would be a NULL pointer if "log_buf_len",
without its value, is set in command line and thus causes the following
panic.

PANIC: early exception 0xe3 IP 10:aaeacd0d error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc4-yocto-standard+ #1
[0.00] RIP: 0010:_parse_integer_fixup_radix+0xd/0x70
...
[0.00] Call Trace:
[0.00]  simple_strtoull+0x29/0x70
[0.00]  memparse+0x26/0x90
[0.00]  log_buf_len_setup+0x17/0x22
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4ee
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
v2:
Split out the addition of pr_fmt and the unsigned update
v3:
Remove error message for NULL pointer
Add check and error message for over 4G use
v4:
Split each piece into one patch
v5:
Remove a redundant print prefix

 kernel/printk/printk.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 9bf5404..06045ab 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1048,7 +1048,12 @@ static void __init log_buf_len_update(unsigned size)
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned size = memparse(str, );
+   unsigned int size;
+
+   if (!str)
+   return -EINVAL;
+
+   size = memparse(str, );
 
log_buf_len_update(size);
 
-- 
2.7.4



[PATCH v5 2/4] printk: Correct wrong casting

2018-09-29 Thread zhe.he
From: He Zhe 

Correct wrong casting that might cut off the normal output.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
 kernel/printk/printk.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 06045ab..c9a0be3 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2356,8 +2356,9 @@ void console_unlock(void)
printk_safe_enter_irqsave(flags);
raw_spin_lock(_lock);
if (console_seq < log_first_seq) {
-   len = sprintf(text, "** %u printk messages dropped 
**\n",
- (unsigned)(log_first_seq - console_seq));
+   len = sprintf(text,
+ "** %llu printk messages dropped **\n",
+ log_first_seq - console_seq);
 
/* messages are gone, move to first one */
console_seq = log_first_seq;
-- 
2.7.4



[PATCH v4 2/4] printk: Correct wrong casting

2018-09-29 Thread zhe.he
From: He Zhe 

Correct wrong casting that might cut off the normal output.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
 kernel/printk/printk.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 06045ab..c9a0be3 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2356,8 +2356,9 @@ void console_unlock(void)
printk_safe_enter_irqsave(flags);
raw_spin_lock(_lock);
if (console_seq < log_first_seq) {
-   len = sprintf(text, "** %u printk messages dropped 
**\n",
- (unsigned)(log_first_seq - console_seq));
+   len = sprintf(text,
+ "** %llu printk messages dropped **\n",
+ log_first_seq - console_seq);
 
/* messages are gone, move to first one */
console_seq = log_first_seq;
-- 
2.7.4



[PATCH v4 1/4] printk: Fix panic caused by passing log_buf_len to command line

2018-09-29 Thread zhe.he
From: He Zhe 

log_buf_len_setup does not check input argument before passing it to
simple_strtoull. The argument would be a NULL pointer if "log_buf_len",
without its value, is set in command line and thus causes the following
panic.

PANIC: early exception 0xe3 IP 10:aaeacd0d error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc4-yocto-standard+ #1
[0.00] RIP: 0010:_parse_integer_fixup_radix+0xd/0x70
...
[0.00] Call Trace:
[0.00]  simple_strtoull+0x29/0x70
[0.00]  memparse+0x26/0x90
[0.00]  log_buf_len_setup+0x17/0x22
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4ee
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
v2:
Split out the addition of pr_fmt and the unsigned update
v3:
Remove error message for NULL pointer
Add check and error message for over 4G use
v4:
Split each piece into one patch

 kernel/printk/printk.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 9bf5404..06045ab 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1048,7 +1048,12 @@ static void __init log_buf_len_update(unsigned size)
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned size = memparse(str, );
+   unsigned int size;
+
+   if (!str)
+   return -EINVAL;
+
+   size = memparse(str, );
 
log_buf_len_update(size);
 
-- 
2.7.4



[PATCH v4 2/4] printk: Correct wrong casting

2018-09-29 Thread zhe.he
From: He Zhe 

Correct wrong casting that might cut off the normal output.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
 kernel/printk/printk.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 06045ab..c9a0be3 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2356,8 +2356,9 @@ void console_unlock(void)
printk_safe_enter_irqsave(flags);
raw_spin_lock(_lock);
if (console_seq < log_first_seq) {
-   len = sprintf(text, "** %u printk messages dropped 
**\n",
- (unsigned)(log_first_seq - console_seq));
+   len = sprintf(text,
+ "** %llu printk messages dropped **\n",
+ log_first_seq - console_seq);
 
/* messages are gone, move to first one */
console_seq = log_first_seq;
-- 
2.7.4



[PATCH v4 1/4] printk: Fix panic caused by passing log_buf_len to command line

2018-09-29 Thread zhe.he
From: He Zhe 

log_buf_len_setup does not check input argument before passing it to
simple_strtoull. The argument would be a NULL pointer if "log_buf_len",
without its value, is set in command line and thus causes the following
panic.

PANIC: early exception 0xe3 IP 10:aaeacd0d error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc4-yocto-standard+ #1
[0.00] RIP: 0010:_parse_integer_fixup_radix+0xd/0x70
...
[0.00] Call Trace:
[0.00]  simple_strtoull+0x29/0x70
[0.00]  memparse+0x26/0x90
[0.00]  log_buf_len_setup+0x17/0x22
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4ee
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
v2:
Split out the addition of pr_fmt and the unsigned update
v3:
Remove error message for NULL pointer
Add check and error message for over 4G use
v4:
Split each piece into one patch

 kernel/printk/printk.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 9bf5404..06045ab 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1048,7 +1048,12 @@ static void __init log_buf_len_update(unsigned size)
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned size = memparse(str, );
+   unsigned int size;
+
+   if (!str)
+   return -EINVAL;
+
+   size = memparse(str, );
 
log_buf_len_update(size);
 
-- 
2.7.4



[PATCH v4 3/4] printk: Add KBUILD_MODNAME

2018-09-29 Thread zhe.he
From: He Zhe 

Add KBUILD_MODNAME to make prints more clear.

Signed-off-by: He Zhe 
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
 kernel/printk/printk.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index c9a0be3..b84aac0 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -16,6 +16,8 @@
  * 01Mar01 Andrew Morton
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
-- 
2.7.4



[PATCH v4 4/4] printk: Give error on attempt to set log buffer length to over 4G

2018-09-29 Thread zhe.he
From: He Zhe 

Give explicit error for users who want to use larger log buffer.

Signed-off-by: He Zhe 
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
 kernel/printk/printk.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index b84aac0..5ccfd5d 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1039,18 +1039,23 @@ void log_buf_vmcoreinfo_setup(void)
 static unsigned long __initdata new_log_buf_len;
 
 /* we practice scaling the ring buffer by powers of 2 */
-static void __init log_buf_len_update(unsigned size)
+static void __init log_buf_len_update(u64 size)
 {
+   if (size > UINT_MAX) {
+   size = UINT_MAX;
+   pr_err("log_buf over 4G is not supported.\n");
+   }
+
if (size)
size = roundup_pow_of_two(size);
if (size > log_buf_len)
-   new_log_buf_len = size;
+   new_log_buf_len = (unsigned long)size;
 }
 
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned int size;
+   u64 size;
 
if (!str)
return -EINVAL;
-- 
2.7.4



[PATCH v4 3/4] printk: Add KBUILD_MODNAME

2018-09-29 Thread zhe.he
From: He Zhe 

Add KBUILD_MODNAME to make prints more clear.

Signed-off-by: He Zhe 
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
 kernel/printk/printk.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index c9a0be3..b84aac0 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -16,6 +16,8 @@
  * 01Mar01 Andrew Morton
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
-- 
2.7.4



[PATCH v4 4/4] printk: Give error on attempt to set log buffer length to over 4G

2018-09-29 Thread zhe.he
From: He Zhe 

Give explicit error for users who want to use larger log buffer.

Signed-off-by: He Zhe 
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
 kernel/printk/printk.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index b84aac0..5ccfd5d 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1039,18 +1039,23 @@ void log_buf_vmcoreinfo_setup(void)
 static unsigned long __initdata new_log_buf_len;
 
 /* we practice scaling the ring buffer by powers of 2 */
-static void __init log_buf_len_update(unsigned size)
+static void __init log_buf_len_update(u64 size)
 {
+   if (size > UINT_MAX) {
+   size = UINT_MAX;
+   pr_err("log_buf over 4G is not supported.\n");
+   }
+
if (size)
size = roundup_pow_of_two(size);
if (size > log_buf_len)
-   new_log_buf_len = size;
+   new_log_buf_len = (unsigned long)size;
 }
 
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned int size;
+   u64 size;
 
if (!str)
return -EINVAL;
-- 
2.7.4



[PATCH v2 2/2] printk: Add KBUILD_MODNAME and correct wrong casting

2018-09-28 Thread zhe.he
From: He Zhe 

Add KBUILD_MODNAME to make prints more clear and correct wrong casting that
might cut off the normal output.

Signed-off-by: He Zhe 
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
v2:
Correct wrong cast in sprintf

 kernel/printk/printk.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 1c932b6..12ab154 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -16,6 +16,8 @@
  * 01Mar01 Andrew Morton
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
@@ -2362,8 +2364,9 @@ void console_unlock(void)
printk_safe_enter_irqsave(flags);
raw_spin_lock(_lock);
if (console_seq < log_first_seq) {
-   len = sprintf(text, "** %u printk messages dropped 
**\n",
- (unsigned)(log_first_seq - console_seq));
+   len = sprintf(text,
+ "** %llu printk messages dropped **\n",
+ log_first_seq - console_seq);
 
/* messages are gone, move to first one */
console_seq = log_first_seq;
-- 
2.7.4



[PATCH v2 2/2] printk: Add KBUILD_MODNAME and correct wrong casting

2018-09-28 Thread zhe.he
From: He Zhe 

Add KBUILD_MODNAME to make prints more clear and correct wrong casting that
might cut off the normal output.

Signed-off-by: He Zhe 
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
v2:
Correct wrong cast in sprintf

 kernel/printk/printk.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 1c932b6..12ab154 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -16,6 +16,8 @@
  * 01Mar01 Andrew Morton
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
@@ -2362,8 +2364,9 @@ void console_unlock(void)
printk_safe_enter_irqsave(flags);
raw_spin_lock(_lock);
if (console_seq < log_first_seq) {
-   len = sprintf(text, "** %u printk messages dropped 
**\n",
- (unsigned)(log_first_seq - console_seq));
+   len = sprintf(text,
+ "** %llu printk messages dropped **\n",
+ log_first_seq - console_seq);
 
/* messages are gone, move to first one */
console_seq = log_first_seq;
-- 
2.7.4



[PATCH v3 1/2] printk: Fix panic caused by passing log_buf_len to command line

2018-09-28 Thread zhe.he
From: He Zhe 

log_buf_len_setup does not check input argument before passing it to
simple_strtoull. The argument would be a NULL pointer if "log_buf_len",
without its value, is set in command line and thus causes the following
panic.

PANIC: early exception 0xe3 IP 10:aaeacd0d error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc4-yocto-standard+ #1
[0.00] RIP: 0010:_parse_integer_fixup_radix+0xd/0x70
...
[0.00] Call Trace:
[0.00]  simple_strtoull+0x29/0x70
[0.00]  memparse+0x26/0x90
[0.00]  log_buf_len_setup+0x17/0x22
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4ee
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic and a check to report if someone is
setting it over 4G.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
v2:
Split out the addition of pr_fmt and the unsigned update
v3:
Remove error message for NULL pointer
Add check and error message for over 4G use

 kernel/printk/printk.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 9bf5404..1c932b6 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1037,18 +1037,29 @@ void log_buf_vmcoreinfo_setup(void)
 static unsigned long __initdata new_log_buf_len;
 
 /* we practice scaling the ring buffer by powers of 2 */
-static void __init log_buf_len_update(unsigned size)
+static void __init log_buf_len_update(u64 size)
 {
+   if (size > UINT_MAX) {
+   size = UINT_MAX;
+   pr_err("log_buf over 4G is not supported.\n");
+   }
+
if (size)
size = roundup_pow_of_two(size);
if (size > log_buf_len)
-   new_log_buf_len = size;
+   new_log_buf_len = (unsigned long)size;
 }
 
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned size = memparse(str, );
+   u64 size;
+
+   if (!str) {
+   return -EINVAL;
+   }
+
+   size = memparse(str, );
 
log_buf_len_update(size);
 
-- 
2.7.4



[PATCH v3 1/2] printk: Fix panic caused by passing log_buf_len to command line

2018-09-28 Thread zhe.he
From: He Zhe 

log_buf_len_setup does not check input argument before passing it to
simple_strtoull. The argument would be a NULL pointer if "log_buf_len",
without its value, is set in command line and thus causes the following
panic.

PANIC: early exception 0xe3 IP 10:aaeacd0d error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc4-yocto-standard+ #1
[0.00] RIP: 0010:_parse_integer_fixup_radix+0xd/0x70
...
[0.00] Call Trace:
[0.00]  simple_strtoull+0x29/0x70
[0.00]  memparse+0x26/0x90
[0.00]  log_buf_len_setup+0x17/0x22
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4ee
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic and a check to report if someone is
setting it over 4G.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
v2:
Split out the addition of pr_fmt and the unsigned update
v3:
Remove error message for NULL pointer
Add check and error message for over 4G use

 kernel/printk/printk.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 9bf5404..1c932b6 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1037,18 +1037,29 @@ void log_buf_vmcoreinfo_setup(void)
 static unsigned long __initdata new_log_buf_len;
 
 /* we practice scaling the ring buffer by powers of 2 */
-static void __init log_buf_len_update(unsigned size)
+static void __init log_buf_len_update(u64 size)
 {
+   if (size > UINT_MAX) {
+   size = UINT_MAX;
+   pr_err("log_buf over 4G is not supported.\n");
+   }
+
if (size)
size = roundup_pow_of_two(size);
if (size > log_buf_len)
-   new_log_buf_len = size;
+   new_log_buf_len = (unsigned long)size;
 }
 
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned size = memparse(str, );
+   u64 size;
+
+   if (!str) {
+   return -EINVAL;
+   }
+
+   size = memparse(str, );
 
log_buf_len_update(size);
 
-- 
2.7.4



[PATCH v3 2/2] printk: Add KBUILD_MODNAME and correct wrong casting

2018-09-22 Thread zhe.he
From: He Zhe 

Add KBUILD_MODNAME to make prints more clear and correct wrong casting that
might cut off the normal output.

Signed-off-by: He Zhe 
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
v2:
Correct one more place
v3:
Correct wrong casting

 kernel/printk/printk.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index d9821c0..6b059a0 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -16,6 +16,8 @@
  * 01Mar01 Andrew Morton
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
@@ -2358,8 +2360,9 @@ void console_unlock(void)
printk_safe_enter_irqsave(flags);
raw_spin_lock(_lock);
if (console_seq < log_first_seq) {
-   len = sprintf(text, "** %u printk messages dropped 
**\n",
- (unsigned)(log_first_seq - console_seq));
+   len = sprintf(text,
+ "** %llu printk messages dropped **\n",
+ log_first_seq - console_seq);
 
/* messages are gone, move to first one */
console_seq = log_first_seq;
-- 
2.7.4



[PATCH v3 2/2] printk: Add KBUILD_MODNAME and correct wrong casting

2018-09-22 Thread zhe.he
From: He Zhe 

Add KBUILD_MODNAME to make prints more clear and correct wrong casting that
might cut off the normal output.

Signed-off-by: He Zhe 
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
v2:
Correct one more place
v3:
Correct wrong casting

 kernel/printk/printk.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index d9821c0..6b059a0 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -16,6 +16,8 @@
  * 01Mar01 Andrew Morton
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
@@ -2358,8 +2360,9 @@ void console_unlock(void)
printk_safe_enter_irqsave(flags);
raw_spin_lock(_lock);
if (console_seq < log_first_seq) {
-   len = sprintf(text, "** %u printk messages dropped 
**\n",
- (unsigned)(log_first_seq - console_seq));
+   len = sprintf(text,
+ "** %llu printk messages dropped **\n",
+ log_first_seq - console_seq);
 
/* messages are gone, move to first one */
console_seq = log_first_seq;
-- 
2.7.4



[PATCH v3 1/2] printk: Fix panic caused by passing log_buf_len to command line

2018-09-22 Thread zhe.he
From: He Zhe 

log_buf_len_setup does not check input argument before passing it to
simple_strtoull. The argument would be a NULL pointer if "log_buf_len",
without its value, is set in command line and thus causes the following
panic.

PANIC: early exception 0xe3 IP 10:aaeacd0d error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc4-yocto-standard+ #1
[0.00] RIP: 0010:_parse_integer_fixup_radix+0xd/0x70
...
[0.00] Call Trace:
[0.00]  simple_strtoull+0x29/0x70
[0.00]  memparse+0x26/0x90
[0.00]  log_buf_len_setup+0x17/0x22
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4ee
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
v2:
Split out the addition of pr_fmt and the unsigned update
v3:
Use more clear error info
Change unsigned to unsigned in to avoid checkpatch.pl warning

 kernel/printk/printk.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 9bf5404..d9821c0 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1048,7 +1048,14 @@ static void __init log_buf_len_update(unsigned size)
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned size = memparse(str, );
+   unsigned int size;
+
+   if (!str) {
+   pr_err("boot command line parameter value not provided\n");
+   return -EINVAL;
+   }
+
+   size = memparse(str, );
 
log_buf_len_update(size);
 
-- 
2.7.4



[PATCH v3 1/2] printk: Fix panic caused by passing log_buf_len to command line

2018-09-22 Thread zhe.he
From: He Zhe 

log_buf_len_setup does not check input argument before passing it to
simple_strtoull. The argument would be a NULL pointer if "log_buf_len",
without its value, is set in command line and thus causes the following
panic.

PANIC: early exception 0xe3 IP 10:aaeacd0d error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc4-yocto-standard+ #1
[0.00] RIP: 0010:_parse_integer_fixup_radix+0xd/0x70
...
[0.00] Call Trace:
[0.00]  simple_strtoull+0x29/0x70
[0.00]  memparse+0x26/0x90
[0.00]  log_buf_len_setup+0x17/0x22
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4ee
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
v2:
Split out the addition of pr_fmt and the unsigned update
v3:
Use more clear error info
Change unsigned to unsigned in to avoid checkpatch.pl warning

 kernel/printk/printk.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 9bf5404..d9821c0 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1048,7 +1048,14 @@ static void __init log_buf_len_update(unsigned size)
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned size = memparse(str, );
+   unsigned int size;
+
+   if (!str) {
+   pr_err("boot command line parameter value not provided\n");
+   return -EINVAL;
+   }
+
+   size = memparse(str, );
 
log_buf_len_update(size);
 
-- 
2.7.4



[PATCH v2 2/2] mm/page_alloc: Add KBUILD_MODNAME

2018-09-22 Thread zhe.he
From: He Zhe 

Add KBUILD_MODNAME to make prints more clear.

Signed-off-by: He Zhe 
Cc: a...@linux-foundation.org
Cc: mho...@suse.com
Cc: vba...@suse.cz
Cc: pasha.tatas...@oracle.com
Cc: mgor...@techsingularity.net
Cc: aaron...@intel.com
Cc: osalva...@suse.de
Cc: iamjoonsoo@lge.com
---
v2:
Split the addition of KBUILD_MODNAME out

 mm/page_alloc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index f34cae1..ead9556 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -14,6 +14,8 @@
  *  (lots of bits borrowed from Ingo Molnar & Andrew Morton)
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
-- 
2.7.4



[PATCH v2 2/2] mm/page_alloc: Add KBUILD_MODNAME

2018-09-22 Thread zhe.he
From: He Zhe 

Add KBUILD_MODNAME to make prints more clear.

Signed-off-by: He Zhe 
Cc: a...@linux-foundation.org
Cc: mho...@suse.com
Cc: vba...@suse.cz
Cc: pasha.tatas...@oracle.com
Cc: mgor...@techsingularity.net
Cc: aaron...@intel.com
Cc: osalva...@suse.de
Cc: iamjoonsoo@lge.com
---
v2:
Split the addition of KBUILD_MODNAME out

 mm/page_alloc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index f34cae1..ead9556 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -14,6 +14,8 @@
  *  (lots of bits borrowed from Ingo Molnar & Andrew Morton)
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
-- 
2.7.4



[PATCH v2 1/2] mm/page_alloc: Fix panic caused by passing debug_guardpage_minorder or kernelcore to command line

2018-09-22 Thread zhe.he
From: He Zhe 

debug_guardpage_minorder_setup and cmdline_parse_kernelcore do not check
input argument before using it. The argument would be a NULL pointer if
"debug_guardpage_minorder" or "kernelcore", without its value, is set in
command line and thus causes the following panic.

PANIC: early exception 0xe3 IP 10:a08146f1 error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc4-yocto-standard+ #11
[0.00] RIP: 0010:parse_option_str+0x11/0x90
...
[0.00] Call Trace:
[0.00]  cmdline_parse_kernelcore+0x19/0x41
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4ee
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic and adds KBUILD_MODNAME to
prints.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: a...@linux-foundation.org
Cc: mho...@suse.com
Cc: vba...@suse.cz
Cc: pasha.tatas...@oracle.com
Cc: mgor...@techsingularity.net
Cc: aaron...@intel.com
Cc: osalva...@suse.de
Cc: iamjoonsoo@lge.com
---
v2:
Use more clear error info
Split the addition of KBUILD_MODNAME out

 mm/page_alloc.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 89d2a2a..f34cae1 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -630,6 +630,12 @@ static int __init debug_guardpage_minorder_setup(char *buf)
 {
unsigned long res;
 
+   if (!buf) {
+   pr_err("kernel option debug_guardpage_minorder requires an \
+   argument\n");
+   return -EINVAL;
+   }
+
if (kstrtoul(buf, 10, ) < 0 ||  res > MAX_ORDER / 2) {
pr_err("Bad debug_guardpage_minorder value\n");
return 0;
@@ -6952,6 +6958,11 @@ static int __init cmdline_parse_core(char *p, unsigned 
long *core,
  */
 static int __init cmdline_parse_kernelcore(char *p)
 {
+   if (!p) {
+   pr_err("kernel option kernelcore requires an argument\n");
+   return -EINVAL;
+   }
+
/* parse kernelcore=mirror */
if (parse_option_str(p, "mirror")) {
mirrored_kernelcore = true;
-- 
2.7.4



[PATCH v2 1/2] mm/page_alloc: Fix panic caused by passing debug_guardpage_minorder or kernelcore to command line

2018-09-22 Thread zhe.he
From: He Zhe 

debug_guardpage_minorder_setup and cmdline_parse_kernelcore do not check
input argument before using it. The argument would be a NULL pointer if
"debug_guardpage_minorder" or "kernelcore", without its value, is set in
command line and thus causes the following panic.

PANIC: early exception 0xe3 IP 10:a08146f1 error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc4-yocto-standard+ #11
[0.00] RIP: 0010:parse_option_str+0x11/0x90
...
[0.00] Call Trace:
[0.00]  cmdline_parse_kernelcore+0x19/0x41
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4ee
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic and adds KBUILD_MODNAME to
prints.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: a...@linux-foundation.org
Cc: mho...@suse.com
Cc: vba...@suse.cz
Cc: pasha.tatas...@oracle.com
Cc: mgor...@techsingularity.net
Cc: aaron...@intel.com
Cc: osalva...@suse.de
Cc: iamjoonsoo@lge.com
---
v2:
Use more clear error info
Split the addition of KBUILD_MODNAME out

 mm/page_alloc.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 89d2a2a..f34cae1 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -630,6 +630,12 @@ static int __init debug_guardpage_minorder_setup(char *buf)
 {
unsigned long res;
 
+   if (!buf) {
+   pr_err("kernel option debug_guardpage_minorder requires an \
+   argument\n");
+   return -EINVAL;
+   }
+
if (kstrtoul(buf, 10, ) < 0 ||  res > MAX_ORDER / 2) {
pr_err("Bad debug_guardpage_minorder value\n");
return 0;
@@ -6952,6 +6958,11 @@ static int __init cmdline_parse_core(char *p, unsigned 
long *core,
  */
 static int __init cmdline_parse_kernelcore(char *p)
 {
+   if (!p) {
+   pr_err("kernel option kernelcore requires an argument\n");
+   return -EINVAL;
+   }
+
/* parse kernelcore=mirror */
if (parse_option_str(p, "mirror")) {
mirrored_kernelcore = true;
-- 
2.7.4



[PATCH v2 1/2] printk: Fix panic caused by passing log_buf_len to command line

2018-09-18 Thread zhe.he
From: He Zhe 

log_buf_len_setup does not check input argument before passing it to
simple_strtoull. The argument would be a NULL pointer if "log_buf_len",
without its value, is set in command line and thus causes the following
panic.

PANIC: early exception 0xe3 IP 10:aaeacd0d error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc4-yocto-standard+ #1
[0.00] RIP: 0010:_parse_integer_fixup_radix+0xd/0x70
...
[0.00] Call Trace:
[0.00]  simple_strtoull+0x29/0x70
[0.00]  memparse+0x26/0x90
[0.00]  log_buf_len_setup+0x17/0x22
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4ee
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
v2:
Split out the addition of pr_fmt and the unsigned update

 kernel/printk/printk.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 9bf5404..34c0403 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1048,7 +1048,14 @@ static void __init log_buf_len_update(unsigned size)
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned size = memparse(str, );
+   unsigned size;
+
+   if (!str) {
+   pr_err("Config string not provided\n");
+   return -EINVAL;
+   }
+
+   size = memparse(str, );
 
log_buf_len_update(size);
 
-- 
2.7.4



[PATCH v2 1/2] printk: Fix panic caused by passing log_buf_len to command line

2018-09-18 Thread zhe.he
From: He Zhe 

log_buf_len_setup does not check input argument before passing it to
simple_strtoull. The argument would be a NULL pointer if "log_buf_len",
without its value, is set in command line and thus causes the following
panic.

PANIC: early exception 0xe3 IP 10:aaeacd0d error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc4-yocto-standard+ #1
[0.00] RIP: 0010:_parse_integer_fixup_radix+0xd/0x70
...
[0.00] Call Trace:
[0.00]  simple_strtoull+0x29/0x70
[0.00]  memparse+0x26/0x90
[0.00]  log_buf_len_setup+0x17/0x22
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4ee
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
v2:
Split out the addition of pr_fmt and the unsigned update

 kernel/printk/printk.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 9bf5404..34c0403 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1048,7 +1048,14 @@ static void __init log_buf_len_update(unsigned size)
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned size = memparse(str, );
+   unsigned size;
+
+   if (!str) {
+   pr_err("Config string not provided\n");
+   return -EINVAL;
+   }
+
+   size = memparse(str, );
 
log_buf_len_update(size);
 
-- 
2.7.4



[PATCH v2 2/2] printk: Add KBUILD_MODNAME and correct bare use of unsigned

2018-09-18 Thread zhe.he
From: He Zhe 

Add KBUILD_MODNAME to make prints more clear. And use 'unsigned int' intead
of 'unsigned' according to checkpatch.pl's suggestion.

Signed-off-by: He Zhe 
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
v2:
Correct one more place

 kernel/printk/printk.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 34c0403..ece870f 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -16,6 +16,8 @@
  * 01Mar01 Andrew Morton
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
@@ -1048,7 +1050,7 @@ static void __init log_buf_len_update(unsigned size)
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned size;
+   unsigned int size;
 
if (!str) {
pr_err("Config string not provided\n");
@@ -2359,7 +2361,7 @@ void console_unlock(void)
raw_spin_lock(_lock);
if (console_seq < log_first_seq) {
len = sprintf(text, "** %u printk messages dropped 
**\n",
- (unsigned)(log_first_seq - console_seq));
+  (unsigned int)(log_first_seq - console_seq));
 
/* messages are gone, move to first one */
console_seq = log_first_seq;
-- 
2.7.4



[PATCH v2 2/2] printk: Add KBUILD_MODNAME and correct bare use of unsigned

2018-09-18 Thread zhe.he
From: He Zhe 

Add KBUILD_MODNAME to make prints more clear. And use 'unsigned int' intead
of 'unsigned' according to checkpatch.pl's suggestion.

Signed-off-by: He Zhe 
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
v2:
Correct one more place

 kernel/printk/printk.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 34c0403..ece870f 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -16,6 +16,8 @@
  * 01Mar01 Andrew Morton
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
@@ -1048,7 +1050,7 @@ static void __init log_buf_len_update(unsigned size)
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned size;
+   unsigned int size;
 
if (!str) {
pr_err("Config string not provided\n");
@@ -2359,7 +2361,7 @@ void console_unlock(void)
raw_spin_lock(_lock);
if (console_seq < log_first_seq) {
len = sprintf(text, "** %u printk messages dropped 
**\n",
- (unsigned)(log_first_seq - console_seq));
+  (unsigned int)(log_first_seq - console_seq));
 
/* messages are gone, move to first one */
console_seq = log_first_seq;
-- 
2.7.4



[PATCH] printk: Fix panic caused by passing log_buf_len to command line

2018-09-18 Thread zhe.he
From: He Zhe 

log_buf_len_setup does not check input argument before passing it to
simple_strtoull. The argument would be a NULL pointer if "log_buf_len",
without its value, is set in command line and thus causes the following
panic.

PANIC: early exception 0xe3 IP 10:aaeacd0d error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc4-yocto-standard+ #1
[0.00] RIP: 0010:_parse_integer_fixup_radix+0xd/0x70
...
[0.00] Call Trace:
[0.00]  simple_strtoull+0x29/0x70
[0.00]  memparse+0x26/0x90
[0.00]  log_buf_len_setup+0x17/0x22
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4ee
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic, adds KBUILD_MODNAME to
prints and correct bare use of 'unsigned'.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
 kernel/printk/printk.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 9bf5404..f6d4030 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -16,6 +16,8 @@
  * 01Mar01 Andrew Morton
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
@@ -1048,7 +1050,14 @@ static void __init log_buf_len_update(unsigned size)
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned size = memparse(str, );
+   unsigned int size;
+
+   if (!str) {
+   pr_err("Config string not provided\n");
+   return -EINVAL;
+   }
+
+   size = memparse(str, );
 
log_buf_len_update(size);
 
-- 
2.7.4



[PATCH] printk: Fix panic caused by passing log_buf_len to command line

2018-09-18 Thread zhe.he
From: He Zhe 

log_buf_len_setup does not check input argument before passing it to
simple_strtoull. The argument would be a NULL pointer if "log_buf_len",
without its value, is set in command line and thus causes the following
panic.

PANIC: early exception 0xe3 IP 10:aaeacd0d error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc4-yocto-standard+ #1
[0.00] RIP: 0010:_parse_integer_fixup_radix+0xd/0x70
...
[0.00] Call Trace:
[0.00]  simple_strtoull+0x29/0x70
[0.00]  memparse+0x26/0x90
[0.00]  log_buf_len_setup+0x17/0x22
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4ee
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic, adds KBUILD_MODNAME to
prints and correct bare use of 'unsigned'.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: pmla...@suse.com
Cc: sergey.senozhat...@gmail.com
Cc: rost...@goodmis.org
---
 kernel/printk/printk.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 9bf5404..f6d4030 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -16,6 +16,8 @@
  * 01Mar01 Andrew Morton
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
@@ -1048,7 +1050,14 @@ static void __init log_buf_len_update(unsigned size)
 /* save requested log_buf_len since it's too early to process it */
 static int __init log_buf_len_setup(char *str)
 {
-   unsigned size = memparse(str, );
+   unsigned int size;
+
+   if (!str) {
+   pr_err("Config string not provided\n");
+   return -EINVAL;
+   }
+
+   size = memparse(str, );
 
log_buf_len_update(size);
 
-- 
2.7.4



[PATCH] mm/page_alloc: Fix panic caused by passing debug_guardpage_minorder or kernelcore to command line

2018-09-18 Thread zhe.he
From: He Zhe 

debug_guardpage_minorder_setup and cmdline_parse_kernelcore do not check
input argument before using it. The argument would be a NULL pointer if
"debug_guardpage_minorder" or "kernelcore", without its value, is set in
command line and thus causes the following panic.

PANIC: early exception 0xe3 IP 10:a08146f1 error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc4-yocto-standard+ #1
[0.00] RIP: 0010:parse_option_str+0x11/0x90
...
[0.00] Call Trace:
[0.00]  cmdline_parse_kernelcore+0x19/0x41
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4ee
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic and adds KBUILD_MODNAME to
prints.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: a...@linux-foundation.org
Cc: mho...@suse.com
Cc: vba...@suse.cz
Cc: pasha.tatas...@oracle.com
Cc: mgor...@techsingularity.net
Cc: aaron...@intel.com
Cc: osalva...@suse.de
Cc: iamjoonsoo@lge.com
---
 mm/page_alloc.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 89d2a2a..d4cda06 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -14,6 +14,8 @@
  *  (lots of bits borrowed from Ingo Molnar & Andrew Morton)
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
@@ -630,6 +632,11 @@ static int __init debug_guardpage_minorder_setup(char *buf)
 {
unsigned long res;
 
+   if (!buf) {
+   pr_err("Config string not provided\n");
+   return -EINVAL;
+   }
+
if (kstrtoul(buf, 10, ) < 0 ||  res > MAX_ORDER / 2) {
pr_err("Bad debug_guardpage_minorder value\n");
return 0;
@@ -6952,6 +6959,11 @@ static int __init cmdline_parse_core(char *p, unsigned 
long *core,
  */
 static int __init cmdline_parse_kernelcore(char *p)
 {
+   if (!p) {
+   pr_err("Config string not provided\n");
+   return -EINVAL;
+   }
+
/* parse kernelcore=mirror */
if (parse_option_str(p, "mirror")) {
mirrored_kernelcore = true;
-- 
2.7.4



[PATCH] mm/page_alloc: Fix panic caused by passing debug_guardpage_minorder or kernelcore to command line

2018-09-18 Thread zhe.he
From: He Zhe 

debug_guardpage_minorder_setup and cmdline_parse_kernelcore do not check
input argument before using it. The argument would be a NULL pointer if
"debug_guardpage_minorder" or "kernelcore", without its value, is set in
command line and thus causes the following panic.

PANIC: early exception 0xe3 IP 10:a08146f1 error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc4-yocto-standard+ #1
[0.00] RIP: 0010:parse_option_str+0x11/0x90
...
[0.00] Call Trace:
[0.00]  cmdline_parse_kernelcore+0x19/0x41
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4ee
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic and adds KBUILD_MODNAME to
prints.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: a...@linux-foundation.org
Cc: mho...@suse.com
Cc: vba...@suse.cz
Cc: pasha.tatas...@oracle.com
Cc: mgor...@techsingularity.net
Cc: aaron...@intel.com
Cc: osalva...@suse.de
Cc: iamjoonsoo@lge.com
---
 mm/page_alloc.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 89d2a2a..d4cda06 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -14,6 +14,8 @@
  *  (lots of bits borrowed from Ingo Molnar & Andrew Morton)
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
@@ -630,6 +632,11 @@ static int __init debug_guardpage_minorder_setup(char *buf)
 {
unsigned long res;
 
+   if (!buf) {
+   pr_err("Config string not provided\n");
+   return -EINVAL;
+   }
+
if (kstrtoul(buf, 10, ) < 0 ||  res > MAX_ORDER / 2) {
pr_err("Bad debug_guardpage_minorder value\n");
return 0;
@@ -6952,6 +6959,11 @@ static int __init cmdline_parse_core(char *p, unsigned 
long *core,
  */
 static int __init cmdline_parse_kernelcore(char *p)
 {
+   if (!p) {
+   pr_err("Config string not provided\n");
+   return -EINVAL;
+   }
+
/* parse kernelcore=mirror */
if (parse_option_str(p, "mirror")) {
mirrored_kernelcore = true;
-- 
2.7.4



[PATCH] kernel/dma: Fix panic caused by passing swiotlb to command line

2018-09-16 Thread zhe.he
From: He Zhe 

setup_io_tlb_npages does not check input argument before passing it
to isdigit. The argument would be a NULL pointer if "swiotlb", without
its value, is set in command line and thus causes the following panic.

PANIC: early exception 0xe3 IP 10:bb9b8e9f error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc3-yocto-standard+ #9
[0.00] RIP: 0010:setup_io_tlb_npages+0xf/0x95
...
[0.00] Call Trace:
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4e6
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: konrad.w...@oracle.com
Cc: h...@lst.de
Cc: m.szyprow...@samsung.com
Cc: robin.mur...@arm.com
---
 kernel/dma/swiotlb.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 4f8a6db..46fc34e 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -109,6 +109,11 @@ static int late_alloc;
 static int __init
 setup_io_tlb_npages(char *str)
 {
+   if (!str) {
+   pr_err("Config string not provided\n");
+   return -EINVAL;
+   }
+
if (isdigit(*str)) {
io_tlb_nslabs = simple_strtoul(str, , 0);
/* avoid tail segment of size < IO_TLB_SEGSIZE */
-- 
2.7.4



[PATCH] kernel/dma: Fix panic caused by passing swiotlb to command line

2018-09-16 Thread zhe.he
From: He Zhe 

setup_io_tlb_npages does not check input argument before passing it
to isdigit. The argument would be a NULL pointer if "swiotlb", without
its value, is set in command line and thus causes the following panic.

PANIC: early exception 0xe3 IP 10:bb9b8e9f error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc3-yocto-standard+ #9
[0.00] RIP: 0010:setup_io_tlb_npages+0xf/0x95
...
[0.00] Call Trace:
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4e6
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: konrad.w...@oracle.com
Cc: h...@lst.de
Cc: m.szyprow...@samsung.com
Cc: robin.mur...@arm.com
---
 kernel/dma/swiotlb.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 4f8a6db..46fc34e 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -109,6 +109,11 @@ static int late_alloc;
 static int __init
 setup_io_tlb_npages(char *str)
 {
+   if (!str) {
+   pr_err("Config string not provided\n");
+   return -EINVAL;
+   }
+
if (isdigit(*str)) {
io_tlb_nslabs = simple_strtoul(str, , 0);
/* avoid tail segment of size < IO_TLB_SEGSIZE */
-- 
2.7.4



[PATCH] kernel/dma: Fix panic caused by passing cma to command line

2018-09-16 Thread zhe.he
From: He Zhe 

early_cma does not check input argument before passing it to
simple_strtoull. The argument would be a NULL pointer if "cma", without
its value, is set in command line and thus causes the following panic.

PANIC: early exception 0xe3 IP 10:a3e9db8d error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc3-yocto-standard+ #7
[0.00] RIP: 0010:_parse_integer_fixup_radix+0xd/0x70
...
[0.00] Call Trace:
[0.00]  simple_strtoull+0x29/0x70
[0.00]  memparse+0x26/0x90
[0.00]  early_cma+0x17/0x6a
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4e6
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: h...@lst.de
Cc: m.szyprow...@samsung.com
Cc: robin.mur...@arm.com
---
 kernel/dma/contiguous.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
index 286d823..b2a8790 100644
--- a/kernel/dma/contiguous.c
+++ b/kernel/dma/contiguous.c
@@ -49,7 +49,11 @@ static phys_addr_t limit_cmdline;
 
 static int __init early_cma(char *p)
 {
-   pr_debug("%s(%s)\n", __func__, p);
+   if (!p) {
+   pr_err("Config string not provided\n");
+   return -EINVAL;
+   }
+
size_cmdline = memparse(p, );
if (*p != '@')
return 0;
-- 
2.7.4



[PATCH] kernel/dma: Fix panic caused by passing cma to command line

2018-09-16 Thread zhe.he
From: He Zhe 

early_cma does not check input argument before passing it to
simple_strtoull. The argument would be a NULL pointer if "cma", without
its value, is set in command line and thus causes the following panic.

PANIC: early exception 0xe3 IP 10:a3e9db8d error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 
4.19.0-rc3-yocto-standard+ #7
[0.00] RIP: 0010:_parse_integer_fixup_radix+0xd/0x70
...
[0.00] Call Trace:
[0.00]  simple_strtoull+0x29/0x70
[0.00]  memparse+0x26/0x90
[0.00]  early_cma+0x17/0x6a
[0.00]  do_early_param+0x57/0x8e
[0.00]  parse_args+0x208/0x320
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_options+0x29/0x2d
[0.00]  ? rdinit_setup+0x30/0x30
[0.00]  parse_early_param+0x36/0x4d
[0.00]  setup_arch+0x336/0x99e
[0.00]  start_kernel+0x6f/0x4e6
[0.00]  x86_64_start_reservations+0x24/0x26
[0.00]  x86_64_start_kernel+0x6f/0x72
[0.00]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic.

Signed-off-by: He Zhe 
Cc: sta...@vger.kernel.org
Cc: h...@lst.de
Cc: m.szyprow...@samsung.com
Cc: robin.mur...@arm.com
---
 kernel/dma/contiguous.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
index 286d823..b2a8790 100644
--- a/kernel/dma/contiguous.c
+++ b/kernel/dma/contiguous.c
@@ -49,7 +49,11 @@ static phys_addr_t limit_cmdline;
 
 static int __init early_cma(char *p)
 {
-   pr_debug("%s(%s)\n", __func__, p);
+   if (!p) {
+   pr_err("Config string not provided\n");
+   return -EINVAL;
+   }
+
size_cmdline = memparse(p, );
if (*p != '@')
return 0;
-- 
2.7.4



[PATCH v2 2/2] x86: corruption-check: Change printk to the right fashion

2018-08-14 Thread zhe.he
From: He Zhe 

pr_* is preferred according to scripts/checkpatch.pl.

Signed-off-by: He Zhe 
---
v2:
- Split printk cleanups into a single patch
- Add pr_fmt for mod name

 arch/x86/kernel/check.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/check.c b/arch/x86/kernel/check.c
index cc8258a..a3d9649 100644
--- a/arch/x86/kernel/check.c
+++ b/arch/x86/kernel/check.c
@@ -1,4 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
@@ -128,7 +131,8 @@ void __init setup_bios_corruption_check(void)
}
 
if (num_scan_areas)
-   printk(KERN_INFO "Scanning %d areas for low memory 
corruption\n", num_scan_areas);
+   pr_info("Scanning %d areas for low memory corruption\n",
+   num_scan_areas);
 }
 
 
@@ -147,7 +151,7 @@ void check_for_bios_corruption(void)
for (; size; addr++, size -= sizeof(unsigned long)) {
if (!*addr)
continue;
-   printk(KERN_ERR "Corrupted low memory at %p (%lx phys) 
= %08lx\n",
+   pr_err("Corrupted low memory at %p (%lx phys) = 
%08lx\n",
   addr, __pa(addr), *addr);
corruption = 1;
*addr = 0;
@@ -172,7 +176,7 @@ static int start_periodic_check_for_corruption(void)
if (!num_scan_areas || !memory_corruption_check || 
corruption_check_period == 0)
return 0;
 
-   printk(KERN_INFO "Scanning for low memory corruption every %d 
seconds\n",
+   pr_info("Scanning for low memory corruption every %d seconds\n",
   corruption_check_period);
 
/* First time we run the checks right away */
-- 
2.7.4



[PATCH v2 2/2] x86: corruption-check: Change printk to the right fashion

2018-08-14 Thread zhe.he
From: He Zhe 

pr_* is preferred according to scripts/checkpatch.pl.

Signed-off-by: He Zhe 
---
v2:
- Split printk cleanups into a single patch
- Add pr_fmt for mod name

 arch/x86/kernel/check.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/check.c b/arch/x86/kernel/check.c
index cc8258a..a3d9649 100644
--- a/arch/x86/kernel/check.c
+++ b/arch/x86/kernel/check.c
@@ -1,4 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include 
 #include 
 #include 
@@ -128,7 +131,8 @@ void __init setup_bios_corruption_check(void)
}
 
if (num_scan_areas)
-   printk(KERN_INFO "Scanning %d areas for low memory 
corruption\n", num_scan_areas);
+   pr_info("Scanning %d areas for low memory corruption\n",
+   num_scan_areas);
 }
 
 
@@ -147,7 +151,7 @@ void check_for_bios_corruption(void)
for (; size; addr++, size -= sizeof(unsigned long)) {
if (!*addr)
continue;
-   printk(KERN_ERR "Corrupted low memory at %p (%lx phys) 
= %08lx\n",
+   pr_err("Corrupted low memory at %p (%lx phys) = 
%08lx\n",
   addr, __pa(addr), *addr);
corruption = 1;
*addr = 0;
@@ -172,7 +176,7 @@ static int start_periodic_check_for_corruption(void)
if (!num_scan_areas || !memory_corruption_check || 
corruption_check_period == 0)
return 0;
 
-   printk(KERN_INFO "Scanning for low memory corruption every %d 
seconds\n",
+   pr_info("Scanning for low memory corruption every %d seconds\n",
   corruption_check_period);
 
/* First time we run the checks right away */
-- 
2.7.4



[PATCH v2 1/2] x86: corruption-check: Passing memory_corruption_check to command line causes panic

2018-08-14 Thread zhe.he
From: He Zhe 

memory_corruption_check[{_period|_size}]'s handlers do not check input
argument before passing it to kstrtoul or simple_strtoull. The argument
would be a NULL pointer if each of the kernel parameters, without its
value, is set in command line and thus cause the following panic.

PANIC: early exception 0xe3 IP 10:73587c22 error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 4.18-rc8+ #2
[0.00] RIP: 0010:kstrtoull+0x2/0x10
...
[0.00] Call Trace
[0.00]  ? set_corruption_check+0x21/0x49
[0.00]  ? do_early_param+0x4d/0x82
[0.00]  ? parse_args+0x212/0x330
[0.00]  ? rdinit_setup+0x26/0x26
[0.00]  ? parse_early_options+0x20/0x23
[0.00]  ? rdinit_setup+0x26/0x26
[0.00]  ? parse_early_param+0x2d/0x39
[0.00]  ? setup_arch+0x2f7/0xbf4
[0.00]  ? start_kernel+0x5e/0x4c2
[0.00]  ? load_ucode_bsp+0x113/0x12f
[0.00]  ? secondary_startup_64+0xa5/0xb0

This patch adds checks to prevent the panic.

Cc: sta...@vger.kernel.org
Signed-off-by: He Zhe 
---
v2:
- Split out printk cleanups
- Add cc to sta...@vger.kernel.org
- Use more meaningful error message

 arch/x86/kernel/check.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/x86/kernel/check.c b/arch/x86/kernel/check.c
index 3339942..cc8258a 100644
--- a/arch/x86/kernel/check.c
+++ b/arch/x86/kernel/check.c
@@ -31,6 +31,11 @@ static __init int set_corruption_check(char *arg)
ssize_t ret;
unsigned long val;
 
+   if (!arg) {
+   pr_err("memory_corruption_check config string not provided\n");
+   return -EINVAL;
+   }
+
ret = kstrtoul(arg, 10, );
if (ret)
return ret;
@@ -45,6 +50,11 @@ static __init int set_corruption_check_period(char *arg)
ssize_t ret;
unsigned long val;
 
+   if (!arg) {
+   pr_err("memory_corruption_check_period config string not 
provided\n");
+   return -EINVAL;
+   }
+
ret = kstrtoul(arg, 10, );
if (ret)
return ret;
@@ -59,6 +69,11 @@ static __init int set_corruption_check_size(char *arg)
char *end;
unsigned size;
 
+   if (!arg) {
+   pr_err("memory_corruption_check_size config string not 
provided\n");
+   return -EINVAL;
+   }
+
size = memparse(arg, );
 
if (*end == '\0')
-- 
2.7.4



[PATCH v2 1/2] x86: corruption-check: Passing memory_corruption_check to command line causes panic

2018-08-14 Thread zhe.he
From: He Zhe 

memory_corruption_check[{_period|_size}]'s handlers do not check input
argument before passing it to kstrtoul or simple_strtoull. The argument
would be a NULL pointer if each of the kernel parameters, without its
value, is set in command line and thus cause the following panic.

PANIC: early exception 0xe3 IP 10:73587c22 error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 4.18-rc8+ #2
[0.00] RIP: 0010:kstrtoull+0x2/0x10
...
[0.00] Call Trace
[0.00]  ? set_corruption_check+0x21/0x49
[0.00]  ? do_early_param+0x4d/0x82
[0.00]  ? parse_args+0x212/0x330
[0.00]  ? rdinit_setup+0x26/0x26
[0.00]  ? parse_early_options+0x20/0x23
[0.00]  ? rdinit_setup+0x26/0x26
[0.00]  ? parse_early_param+0x2d/0x39
[0.00]  ? setup_arch+0x2f7/0xbf4
[0.00]  ? start_kernel+0x5e/0x4c2
[0.00]  ? load_ucode_bsp+0x113/0x12f
[0.00]  ? secondary_startup_64+0xa5/0xb0

This patch adds checks to prevent the panic.

Cc: sta...@vger.kernel.org
Signed-off-by: He Zhe 
---
v2:
- Split out printk cleanups
- Add cc to sta...@vger.kernel.org
- Use more meaningful error message

 arch/x86/kernel/check.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/x86/kernel/check.c b/arch/x86/kernel/check.c
index 3339942..cc8258a 100644
--- a/arch/x86/kernel/check.c
+++ b/arch/x86/kernel/check.c
@@ -31,6 +31,11 @@ static __init int set_corruption_check(char *arg)
ssize_t ret;
unsigned long val;
 
+   if (!arg) {
+   pr_err("memory_corruption_check config string not provided\n");
+   return -EINVAL;
+   }
+
ret = kstrtoul(arg, 10, );
if (ret)
return ret;
@@ -45,6 +50,11 @@ static __init int set_corruption_check_period(char *arg)
ssize_t ret;
unsigned long val;
 
+   if (!arg) {
+   pr_err("memory_corruption_check_period config string not 
provided\n");
+   return -EINVAL;
+   }
+
ret = kstrtoul(arg, 10, );
if (ret)
return ret;
@@ -59,6 +69,11 @@ static __init int set_corruption_check_size(char *arg)
char *end;
unsigned size;
 
+   if (!arg) {
+   pr_err("memory_corruption_check_size config string not 
provided\n");
+   return -EINVAL;
+   }
+
size = memparse(arg, );
 
if (*end == '\0')
-- 
2.7.4



[PATCH] scripts/gcc-goto.sh: Show stdout and stderr for potential errors

2018-08-09 Thread zhe.he
From: He Zhe 

The check may fail not only because ${CC} does not support the asm
feature, but also due to potential defects of ${CC} itself like what
we experienced below or even it's missing.

Assembler messages:
Fatal error: The input and output files must be distinct
(introduced by binutils-2.31 "Stop the assembler from overwriting its
output file.")

This patch enables stdout and stderr to give user direct error
information for those cases, while not polluting the output for normal
cases.

Signed-off-by: He Zhe 
---
 scripts/gcc-goto.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/gcc-goto.sh b/scripts/gcc-goto.sh
index 083c526..bd7fc8eb 100755
--- a/scripts/gcc-goto.sh
+++ b/scripts/gcc-goto.sh
@@ -3,7 +3,7 @@
 # Test for gcc 'asm goto' support
 # Copyright (C) 2010, Jason Baron 
 
-cat << "END" | $@ -x c - -c -o /dev/null >/dev/null 2>&1 && echo "y"
+cat << "END" | $@ -x c - -c -o /dev/null && echo "y"
 int main(void)
 {
 #if defined(__arm__) || defined(__aarch64__)
-- 
2.7.4



[PATCH] scripts/gcc-goto.sh: Show stdout and stderr for potential errors

2018-08-09 Thread zhe.he
From: He Zhe 

The check may fail not only because ${CC} does not support the asm
feature, but also due to potential defects of ${CC} itself like what
we experienced below or even it's missing.

Assembler messages:
Fatal error: The input and output files must be distinct
(introduced by binutils-2.31 "Stop the assembler from overwriting its
output file.")

This patch enables stdout and stderr to give user direct error
information for those cases, while not polluting the output for normal
cases.

Signed-off-by: He Zhe 
---
 scripts/gcc-goto.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/gcc-goto.sh b/scripts/gcc-goto.sh
index 083c526..bd7fc8eb 100755
--- a/scripts/gcc-goto.sh
+++ b/scripts/gcc-goto.sh
@@ -3,7 +3,7 @@
 # Test for gcc 'asm goto' support
 # Copyright (C) 2010, Jason Baron 
 
-cat << "END" | $@ -x c - -c -o /dev/null >/dev/null 2>&1 && echo "y"
+cat << "END" | $@ -x c - -c -o /dev/null && echo "y"
 int main(void)
 {
 #if defined(__arm__) || defined(__aarch64__)
-- 
2.7.4



[PATCH] x86: corruption-check: Passing memory_corruption_check to command line causes panic

2018-08-08 Thread zhe.he
From: He Zhe 

memory_corruption_check[{_period|_size}]'s handlers do not check input
argument before passing it to kstrtoul or simple_strtoull. The argument
would be a NULL pointer if each of the kernel parameters, without its
value, is set in command line and thus cause the following panic.

PANIC: early exception 0xe3 IP 10:73587c22 error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 4.18-rc8+ #2
[0.00] RIP: 0010:kstrtoull+0x2/0x10
...
[0.00] Call Trace
[0.00]  ? set_corruption_check+0x21/0x49
[0.00]  ? do_early_param+0x4d/0x82
[0.00]  ? parse_args+0x212/0x330
[0.00]  ? rdinit_setup+0x26/0x26
[0.00]  ? parse_early_options+0x20/0x23
[0.00]  ? rdinit_setup+0x26/0x26
[0.00]  ? parse_early_param+0x2d/0x39
[0.00]  ? setup_arch+0x2f7/0xbf4
[0.00]  ? start_kernel+0x5e/0x4c2
[0.00]  ? load_ucode_bsp+0x113/0x12f
[0.00]  ? secondary_startup_64+0xa5/0xb0

This patch adds checks to prevent the panic and changes some printk
to right fashion.

Signed-off-by: He Zhe 
---
 arch/x86/kernel/check.c | 22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/check.c b/arch/x86/kernel/check.c
index 3339942..d3d65d7 100644
--- a/arch/x86/kernel/check.c
+++ b/arch/x86/kernel/check.c
@@ -31,6 +31,11 @@ static __init int set_corruption_check(char *arg)
ssize_t ret;
unsigned long val;
 
+   if (!arg) {
+   pr_err("memory_corruption_check: null option\n");
+   return -EINVAL;
+   }
+
ret = kstrtoul(arg, 10, );
if (ret)
return ret;
@@ -45,6 +50,11 @@ static __init int set_corruption_check_period(char *arg)
ssize_t ret;
unsigned long val;
 
+   if (!arg) {
+   pr_err("memory_corruption_check_period: null option\n");
+   return -EINVAL;
+   }
+
ret = kstrtoul(arg, 10, );
if (ret)
return ret;
@@ -59,6 +69,11 @@ static __init int set_corruption_check_size(char *arg)
char *end;
unsigned size;
 
+   if (!arg) {
+   pr_err("memory_corruption_check_size: null option\n");
+   return -EINVAL;
+   }
+
size = memparse(arg, );
 
if (*end == '\0')
@@ -113,7 +128,8 @@ void __init setup_bios_corruption_check(void)
}
 
if (num_scan_areas)
-   printk(KERN_INFO "Scanning %d areas for low memory 
corruption\n", num_scan_areas);
+   pr_info("Scanning %d areas for low memory corruption\n",
+   num_scan_areas);
 }
 
 
@@ -132,7 +148,7 @@ void check_for_bios_corruption(void)
for (; size; addr++, size -= sizeof(unsigned long)) {
if (!*addr)
continue;
-   printk(KERN_ERR "Corrupted low memory at %p (%lx phys) 
= %08lx\n",
+   pr_err("Corrupted low memory at %p (%lx phys) = 
%08lx\n",
   addr, __pa(addr), *addr);
corruption = 1;
*addr = 0;
@@ -157,7 +173,7 @@ static int start_periodic_check_for_corruption(void)
if (!num_scan_areas || !memory_corruption_check || 
corruption_check_period == 0)
return 0;
 
-   printk(KERN_INFO "Scanning for low memory corruption every %d 
seconds\n",
+   pr_info("Scanning for low memory corruption every %d seconds\n",
   corruption_check_period);
 
/* First time we run the checks right away */
-- 
2.7.4



[PATCH] x86: corruption-check: Passing memory_corruption_check to command line causes panic

2018-08-08 Thread zhe.he
From: He Zhe 

memory_corruption_check[{_period|_size}]'s handlers do not check input
argument before passing it to kstrtoul or simple_strtoull. The argument
would be a NULL pointer if each of the kernel parameters, without its
value, is set in command line and thus cause the following panic.

PANIC: early exception 0xe3 IP 10:73587c22 error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 4.18-rc8+ #2
[0.00] RIP: 0010:kstrtoull+0x2/0x10
...
[0.00] Call Trace
[0.00]  ? set_corruption_check+0x21/0x49
[0.00]  ? do_early_param+0x4d/0x82
[0.00]  ? parse_args+0x212/0x330
[0.00]  ? rdinit_setup+0x26/0x26
[0.00]  ? parse_early_options+0x20/0x23
[0.00]  ? rdinit_setup+0x26/0x26
[0.00]  ? parse_early_param+0x2d/0x39
[0.00]  ? setup_arch+0x2f7/0xbf4
[0.00]  ? start_kernel+0x5e/0x4c2
[0.00]  ? load_ucode_bsp+0x113/0x12f
[0.00]  ? secondary_startup_64+0xa5/0xb0

This patch adds checks to prevent the panic and changes some printk
to right fashion.

Signed-off-by: He Zhe 
---
 arch/x86/kernel/check.c | 22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/check.c b/arch/x86/kernel/check.c
index 3339942..d3d65d7 100644
--- a/arch/x86/kernel/check.c
+++ b/arch/x86/kernel/check.c
@@ -31,6 +31,11 @@ static __init int set_corruption_check(char *arg)
ssize_t ret;
unsigned long val;
 
+   if (!arg) {
+   pr_err("memory_corruption_check: null option\n");
+   return -EINVAL;
+   }
+
ret = kstrtoul(arg, 10, );
if (ret)
return ret;
@@ -45,6 +50,11 @@ static __init int set_corruption_check_period(char *arg)
ssize_t ret;
unsigned long val;
 
+   if (!arg) {
+   pr_err("memory_corruption_check_period: null option\n");
+   return -EINVAL;
+   }
+
ret = kstrtoul(arg, 10, );
if (ret)
return ret;
@@ -59,6 +69,11 @@ static __init int set_corruption_check_size(char *arg)
char *end;
unsigned size;
 
+   if (!arg) {
+   pr_err("memory_corruption_check_size: null option\n");
+   return -EINVAL;
+   }
+
size = memparse(arg, );
 
if (*end == '\0')
@@ -113,7 +128,8 @@ void __init setup_bios_corruption_check(void)
}
 
if (num_scan_areas)
-   printk(KERN_INFO "Scanning %d areas for low memory 
corruption\n", num_scan_areas);
+   pr_info("Scanning %d areas for low memory corruption\n",
+   num_scan_areas);
 }
 
 
@@ -132,7 +148,7 @@ void check_for_bios_corruption(void)
for (; size; addr++, size -= sizeof(unsigned long)) {
if (!*addr)
continue;
-   printk(KERN_ERR "Corrupted low memory at %p (%lx phys) 
= %08lx\n",
+   pr_err("Corrupted low memory at %p (%lx phys) = 
%08lx\n",
   addr, __pa(addr), *addr);
corruption = 1;
*addr = 0;
@@ -157,7 +173,7 @@ static int start_periodic_check_for_corruption(void)
if (!num_scan_areas || !memory_corruption_check || 
corruption_check_period == 0)
return 0;
 
-   printk(KERN_INFO "Scanning for low memory corruption every %d 
seconds\n",
+   pr_info("Scanning for low memory corruption every %d seconds\n",
   corruption_check_period);
 
/* First time we run the checks right away */
-- 
2.7.4



[PATCH] kgdboc: Passing ekgdboc to command line causes panic

2018-08-08 Thread zhe.he
From: He Zhe 

kgdboc_option_setup does not check input argument before passing it
to strlen. The argument would be a NULL pointer if "ekgdboc", without
its value, is set in command line and thus cause the following panic.

PANIC: early exception 0xe3 IP 10:8fbbb620 error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 4.18-rc8+ #1
[0.00] RIP: 0010:strlen+0x0/0x20
...
[0.00] Call Trace
[0.00]  ? kgdboc_option_setup+0x9/0xa0
[0.00]  ? kgdboc_early_init+0x6/0x1b
[0.00]  ? do_early_param+0x4d/0x82
[0.00]  ? parse_args+0x212/0x330
[0.00]  ? rdinit_setup+0x26/0x26
[0.00]  ? parse_early_options+0x20/0x23
[0.00]  ? rdinit_setup+0x26/0x26
[0.00]  ? parse_early_param+0x2d/0x39
[0.00]  ? setup_arch+0x2f7/0xbf4
[0.00]  ? start_kernel+0x5e/0x4c2
[0.00]  ? load_ucode_bsp+0x113/0x12f
[0.00]  ? secondary_startup_64+0xa5/0xb0

This patch adds a check to prevent the panic and changes some printk
to right fashion.

Signed-off-by: He Zhe 
---
 drivers/tty/serial/kgdboc.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
index b4ba2b1..0003d6c 100644
--- a/drivers/tty/serial/kgdboc.c
+++ b/drivers/tty/serial/kgdboc.c
@@ -130,8 +130,13 @@ static void kgdboc_unregister_kbd(void)
 
 static int kgdboc_option_setup(char *opt)
 {
+   if (!opt) {
+   pr_err("kgdboc: null option\n");
+   return -EINVAL;
+   }
+
if (strlen(opt) >= MAX_CONFIG_LEN) {
-   printk(KERN_ERR "kgdboc: config string too long\n");
+   pr_err("kgdboc: config string too long\n");
return -ENOSPC;
}
strcpy(config, opt);
@@ -248,7 +253,7 @@ static int param_set_kgdboc_var(const char *kmessage,
int len = strlen(kmessage);
 
if (len >= MAX_CONFIG_LEN) {
-   printk(KERN_ERR "kgdboc: config string too long\n");
+   pr_err("kgdboc: config string too long\n");
return -ENOSPC;
}
 
@@ -259,8 +264,7 @@ static int param_set_kgdboc_var(const char *kmessage,
}
 
if (kgdb_connected) {
-   printk(KERN_ERR
-  "kgdboc: Cannot reconfigure while KGDB is connected.\n");
+   pr_err("kgdboc: Cannot reconfigure while KGDB is connected.\n");
 
return -EBUSY;
}
-- 
2.7.4



[PATCH] kgdboc: Passing ekgdboc to command line causes panic

2018-08-08 Thread zhe.he
From: He Zhe 

kgdboc_option_setup does not check input argument before passing it
to strlen. The argument would be a NULL pointer if "ekgdboc", without
its value, is set in command line and thus cause the following panic.

PANIC: early exception 0xe3 IP 10:8fbbb620 error 0 cr2 0x0
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 4.18-rc8+ #1
[0.00] RIP: 0010:strlen+0x0/0x20
...
[0.00] Call Trace
[0.00]  ? kgdboc_option_setup+0x9/0xa0
[0.00]  ? kgdboc_early_init+0x6/0x1b
[0.00]  ? do_early_param+0x4d/0x82
[0.00]  ? parse_args+0x212/0x330
[0.00]  ? rdinit_setup+0x26/0x26
[0.00]  ? parse_early_options+0x20/0x23
[0.00]  ? rdinit_setup+0x26/0x26
[0.00]  ? parse_early_param+0x2d/0x39
[0.00]  ? setup_arch+0x2f7/0xbf4
[0.00]  ? start_kernel+0x5e/0x4c2
[0.00]  ? load_ucode_bsp+0x113/0x12f
[0.00]  ? secondary_startup_64+0xa5/0xb0

This patch adds a check to prevent the panic and changes some printk
to right fashion.

Signed-off-by: He Zhe 
---
 drivers/tty/serial/kgdboc.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
index b4ba2b1..0003d6c 100644
--- a/drivers/tty/serial/kgdboc.c
+++ b/drivers/tty/serial/kgdboc.c
@@ -130,8 +130,13 @@ static void kgdboc_unregister_kbd(void)
 
 static int kgdboc_option_setup(char *opt)
 {
+   if (!opt) {
+   pr_err("kgdboc: null option\n");
+   return -EINVAL;
+   }
+
if (strlen(opt) >= MAX_CONFIG_LEN) {
-   printk(KERN_ERR "kgdboc: config string too long\n");
+   pr_err("kgdboc: config string too long\n");
return -ENOSPC;
}
strcpy(config, opt);
@@ -248,7 +253,7 @@ static int param_set_kgdboc_var(const char *kmessage,
int len = strlen(kmessage);
 
if (len >= MAX_CONFIG_LEN) {
-   printk(KERN_ERR "kgdboc: config string too long\n");
+   pr_err("kgdboc: config string too long\n");
return -ENOSPC;
}
 
@@ -259,8 +264,7 @@ static int param_set_kgdboc_var(const char *kmessage,
}
 
if (kgdb_connected) {
-   printk(KERN_ERR
-  "kgdboc: Cannot reconfigure while KGDB is connected.\n");
+   pr_err("kgdboc: Cannot reconfigure while KGDB is connected.\n");
 
return -EBUSY;
}
-- 
2.7.4



[PATCH 1/1] x86, kgdb: correct kgdb_arch_remove_breakpoint

2014-12-29 Thread zhe.he
From: He Zhe 

On 3.19-rc2, kgdbts boot time test fails with default parameter V1F100
"KGDB: BP remove failed: 81049070"
Then system is hanged.

When CONFIG_DEBUG_RODATA is on, kgdb_arch_set_breakpoint firstly tries
probe_kernel_write to set breakpoints and mark their type as BP_BREAKPOINT. If
fails it would use text_poke and mark their type as BP_POKE_BREAKPOINT.

On the other hand, kgdb_arch_remove_breakpoint uses probe_kernel_write to delete
breakpoints if they are BP_BREAKPOINT, or uses text_poke if they are
BP_POKE_BREAKPOINT.

The kgdbts' boot time test case loops for do_fork and/or sys_open may run
through initialization. During this procedure, the read only area is created. If
a breakpoint is marked as BP_BREAKPOINT before creating read only area and then
its address is put into that area, it would fail to be deleted due to
kgdb_arch_remove_breakpoint would use wrong function.

This patch:
 - Make kgdb_arch_remove_breakpoint work like kgdb_arch_set_breakpoint, trying
probe_kernel_write first then trying text_poke if fails.
 - Remove BP_POKE_BREAKPOINT as it is only used in these two functions.

Signed-off-by: He Zhe 
---
 arch/x86/kernel/kgdb.c | 25 +
 include/linux/kgdb.h   |  1 -
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
index 7ec1d5f..f5f7772 100644
--- a/arch/x86/kernel/kgdb.c
+++ b/arch/x86/kernel/kgdb.c
@@ -749,7 +749,6 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
char opc[BREAK_INSTR_SIZE];
 #endif /* CONFIG_DEBUG_RODATA */
 
-   bpt->type = BP_BREAKPOINT;
err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
BREAK_INSTR_SIZE);
if (err)
@@ -772,34 +771,36 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
return err;
if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
return -EINVAL;
-   bpt->type = BP_POKE_BREAKPOINT;
 #endif /* CONFIG_DEBUG_RODATA */
return err;
 }
 
 int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
 {
-#ifdef CONFIG_DEBUG_RODATA
int err;
+#ifdef CONFIG_DEBUG_RODATA
char opc[BREAK_INSTR_SIZE];
+#endif /* CONFIG_DEBUG_RODATA */
 
-   if (bpt->type != BP_POKE_BREAKPOINT)
-   goto knl_write;
+   err = probe_kernel_write((char *)bpt->bpt_addr,
+(char *)bpt->saved_instr, BREAK_INSTR_SIZE);
+#ifdef CONFIG_DEBUG_RODATA
+   if (!err)
+   return err;
/*
 * It is safe to call text_poke() because normal kernel execution
 * is stopped on all cores, so long as the text_mutex is not locked.
 */
if (mutex_is_locked(_mutex))
-   goto knl_write;
+   return -EBUSY;
text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
-   if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
-   goto knl_write;
-   return err;
-knl_write:
+   if (err)
+   return err;
+   if (memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
+   return -EINVAL;
 #endif /* CONFIG_DEBUG_RODATA */
-   return probe_kernel_write((char *)bpt->bpt_addr,
- (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
+   return err;
 }
 
 struct kgdb_arch arch_kgdb_ops = {
diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
index fc513db..cded3c75 100644
--- a/include/linux/kgdb.h
+++ b/include/linux/kgdb.h
@@ -63,7 +63,6 @@ enum kgdb_bptype {
BP_WRITE_WATCHPOINT,
BP_READ_WATCHPOINT,
BP_ACCESS_WATCHPOINT,
-   BP_POKE_BREAKPOINT,
 };
 
 enum kgdb_bpstate {
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/1] x86, kgdb: correct kgdb_arch_remove_breakpoint

2014-12-29 Thread zhe.he
From: He Zhe zhe...@windriver.com

On 3.19-rc2, kgdbts boot time test fails with default parameter V1F100
KGDB: BP remove failed: 81049070
Then system is hanged.

When CONFIG_DEBUG_RODATA is on, kgdb_arch_set_breakpoint firstly tries
probe_kernel_write to set breakpoints and mark their type as BP_BREAKPOINT. If
fails it would use text_poke and mark their type as BP_POKE_BREAKPOINT.

On the other hand, kgdb_arch_remove_breakpoint uses probe_kernel_write to delete
breakpoints if they are BP_BREAKPOINT, or uses text_poke if they are
BP_POKE_BREAKPOINT.

The kgdbts' boot time test case loops for do_fork and/or sys_open may run
through initialization. During this procedure, the read only area is created. If
a breakpoint is marked as BP_BREAKPOINT before creating read only area and then
its address is put into that area, it would fail to be deleted due to
kgdb_arch_remove_breakpoint would use wrong function.

This patch:
 - Make kgdb_arch_remove_breakpoint work like kgdb_arch_set_breakpoint, trying
probe_kernel_write first then trying text_poke if fails.
 - Remove BP_POKE_BREAKPOINT as it is only used in these two functions.

Signed-off-by: He Zhe zhe...@windriver.com
---
 arch/x86/kernel/kgdb.c | 25 +
 include/linux/kgdb.h   |  1 -
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
index 7ec1d5f..f5f7772 100644
--- a/arch/x86/kernel/kgdb.c
+++ b/arch/x86/kernel/kgdb.c
@@ -749,7 +749,6 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
char opc[BREAK_INSTR_SIZE];
 #endif /* CONFIG_DEBUG_RODATA */
 
-   bpt-type = BP_BREAKPOINT;
err = probe_kernel_read(bpt-saved_instr, (char *)bpt-bpt_addr,
BREAK_INSTR_SIZE);
if (err)
@@ -772,34 +771,36 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
return err;
if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
return -EINVAL;
-   bpt-type = BP_POKE_BREAKPOINT;
 #endif /* CONFIG_DEBUG_RODATA */
return err;
 }
 
 int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
 {
-#ifdef CONFIG_DEBUG_RODATA
int err;
+#ifdef CONFIG_DEBUG_RODATA
char opc[BREAK_INSTR_SIZE];
+#endif /* CONFIG_DEBUG_RODATA */
 
-   if (bpt-type != BP_POKE_BREAKPOINT)
-   goto knl_write;
+   err = probe_kernel_write((char *)bpt-bpt_addr,
+(char *)bpt-saved_instr, BREAK_INSTR_SIZE);
+#ifdef CONFIG_DEBUG_RODATA
+   if (!err)
+   return err;
/*
 * It is safe to call text_poke() because normal kernel execution
 * is stopped on all cores, so long as the text_mutex is not locked.
 */
if (mutex_is_locked(text_mutex))
-   goto knl_write;
+   return -EBUSY;
text_poke((void *)bpt-bpt_addr, bpt-saved_instr, BREAK_INSTR_SIZE);
err = probe_kernel_read(opc, (char *)bpt-bpt_addr, BREAK_INSTR_SIZE);
-   if (err || memcmp(opc, bpt-saved_instr, BREAK_INSTR_SIZE))
-   goto knl_write;
-   return err;
-knl_write:
+   if (err)
+   return err;
+   if (memcmp(opc, bpt-saved_instr, BREAK_INSTR_SIZE))
+   return -EINVAL;
 #endif /* CONFIG_DEBUG_RODATA */
-   return probe_kernel_write((char *)bpt-bpt_addr,
- (char *)bpt-saved_instr, BREAK_INSTR_SIZE);
+   return err;
 }
 
 struct kgdb_arch arch_kgdb_ops = {
diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
index fc513db..cded3c75 100644
--- a/include/linux/kgdb.h
+++ b/include/linux/kgdb.h
@@ -63,7 +63,6 @@ enum kgdb_bptype {
BP_WRITE_WATCHPOINT,
BP_READ_WATCHPOINT,
BP_ACCESS_WATCHPOINT,
-   BP_POKE_BREAKPOINT,
 };
 
 enum kgdb_bpstate {
-- 
1.8.3.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/