[PATCH] tracing: Don't use the address of the buffer array name in copy_from_user

2016-04-18 Thread Wang Xiaoqiang
Hi, all,

>From 7dbacb179a4d5f9ac9d7e1b3733664b3b0fe23ae Mon Sep 17 00:00:00 2001
From: Wang Xiaoqiang <wangx...@lzu.edu.cn>
Date: Mon, 18 Apr 2016 14:58:15 +0800
Subject: [PATCH] tracing: Don't use the address of the buffer array name in
 copy_from_user

Fix the problem as follows:

...
char buf[64];
...
if (copy_from_user(, ubuf, cnt))
...

Even though the value of "" equals "buf", but there is no need
to get the address of the "buf" again. Use "buf" replace "".

Signed-off-by: Wang Xiaoqiang <wangx...@lzu.edu.cn>
---
 kernel/trace/trace.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index a2f0b9f..422ab57 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3658,7 +3658,7 @@ tracing_trace_options_write(struct file *filp, const char 
__user *ubuf,
if (cnt >= sizeof(buf))
return -EINVAL;
 
-   if (copy_from_user(, ubuf, cnt))
+   if (copy_from_user(buf, ubuf, cnt))
return -EFAULT;
 
buf[cnt] = 0;
@@ -4474,7 +4474,7 @@ tracing_set_trace_write(struct file *filp, const char 
__user *ubuf,
if (cnt > MAX_TRACER_SIZE)
cnt = MAX_TRACER_SIZE;
 
-   if (copy_from_user(, ubuf, cnt))
+   if (copy_from_user(buf, ubuf, cnt))
return -EFAULT;
 
buf[cnt] = 0;
@@ -5264,7 +5264,7 @@ static ssize_t tracing_clock_write(struct file *filp, 
const char __user *ubuf,
if (cnt >= sizeof(buf))
return -EINVAL;
 
-   if (copy_from_user(, ubuf, cnt))
+   if (copy_from_user(buf, ubuf, cnt))
return -EFAULT;
 
buf[cnt] = 0;
-- 
2.1.4




[PATCH] tracing: Don't use the address of the buffer array name in copy_from_user

2016-04-18 Thread Wang Xiaoqiang
Hi, all,

>From 7dbacb179a4d5f9ac9d7e1b3733664b3b0fe23ae Mon Sep 17 00:00:00 2001
From: Wang Xiaoqiang 
Date: Mon, 18 Apr 2016 14:58:15 +0800
Subject: [PATCH] tracing: Don't use the address of the buffer array name in
 copy_from_user

Fix the problem as follows:

...
char buf[64];
...
if (copy_from_user(, ubuf, cnt))
...

Even though the value of "" equals "buf", but there is no need
to get the address of the "buf" again. Use "buf" replace "".

Signed-off-by: Wang Xiaoqiang 
---
 kernel/trace/trace.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index a2f0b9f..422ab57 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3658,7 +3658,7 @@ tracing_trace_options_write(struct file *filp, const char 
__user *ubuf,
if (cnt >= sizeof(buf))
return -EINVAL;
 
-   if (copy_from_user(, ubuf, cnt))
+   if (copy_from_user(buf, ubuf, cnt))
return -EFAULT;
 
buf[cnt] = 0;
@@ -4474,7 +4474,7 @@ tracing_set_trace_write(struct file *filp, const char 
__user *ubuf,
if (cnt > MAX_TRACER_SIZE)
cnt = MAX_TRACER_SIZE;
 
-   if (copy_from_user(, ubuf, cnt))
+   if (copy_from_user(buf, ubuf, cnt))
return -EFAULT;
 
buf[cnt] = 0;
@@ -5264,7 +5264,7 @@ static ssize_t tracing_clock_write(struct file *filp, 
const char __user *ubuf,
if (cnt >= sizeof(buf))
return -EINVAL;
 
-   if (copy_from_user(, ubuf, cnt))
+   if (copy_from_user(buf, ubuf, cnt))
return -EFAULT;
 
buf[cnt] = 0;
-- 
2.1.4




[PATCH] kernel/signal.c: Convert printk(KERN_ ...) to pr_(...)

2016-04-13 Thread Wang Xiaoqiang
>From cca7a9ac8218d42f9acb1fbc1d9049468493d8a6 Mon Sep 17 00:00:00 2001
From: Wang Xiaoqiang <wangx...@lzu.edu.cn>
Date: Wed, 13 Apr 2016 19:51:55 +0800
Subject: [PATCH] kernel/signal.c: Convert printk(KERN_ ...) to
 pr_(...)

Use pr_ instead of printk(KERN_ ).

Signed-off-by: Wang Xiaoqiang <wangx...@lzu.edu.cn>
---
 kernel/signal.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/kernel/signal.c b/kernel/signal.c
index aa9bf00..a7c1604 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -224,7 +224,7 @@ static inline void print_dropped_signal(int sig)
if (!__ratelimit(_state))
return;
 
-   printk(KERN_INFO "%s/%d: reached RLIMIT_SIGPENDING, dropped signal 
%d\n",
+   pr_info("%s/%d: reached RLIMIT_SIGPENDING, dropped signal %d\n",
current->comm, current->pid, sig);
 }
 
@@ -1089,10 +1089,10 @@ static int send_signal(int sig, struct siginfo *info, 
struct task_struct *t,
 static void print_fatal_signal(int signr)
 {
struct pt_regs *regs = signal_pt_regs();
-   printk(KERN_INFO "potentially unexpected fatal signal %d.\n", signr);
+   pr_info("potentially unexpected fatal signal %d.\n", signr);
 
 #if defined(__i386__) && !defined(__arch_um__)
-   printk(KERN_INFO "code at %08lx: ", regs->ip);
+   pr_info("code at %08lx: ", regs->ip);
{
int i;
for (i = 0; i < 16; i++) {
@@ -1100,10 +1100,10 @@ static void print_fatal_signal(int signr)
 
if (get_user(insn, (unsigned char *)(regs->ip + i)))
break;
-   printk(KERN_CONT "%02x ", insn);
+   pr_cont("%02x ", insn);
}
}
-   printk(KERN_CONT "\n");
+   pr_cont("\n");
 #endif
preempt_disable();
show_regs(regs);
-- 
2.1.4




[PATCH] kernel/signal.c: Convert printk(KERN_ ...) to pr_(...)

2016-04-13 Thread Wang Xiaoqiang
>From cca7a9ac8218d42f9acb1fbc1d9049468493d8a6 Mon Sep 17 00:00:00 2001
From: Wang Xiaoqiang 
Date: Wed, 13 Apr 2016 19:51:55 +0800
Subject: [PATCH] kernel/signal.c: Convert printk(KERN_ ...) to
 pr_(...)

Use pr_ instead of printk(KERN_ ).

Signed-off-by: Wang Xiaoqiang 
---
 kernel/signal.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/kernel/signal.c b/kernel/signal.c
index aa9bf00..a7c1604 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -224,7 +224,7 @@ static inline void print_dropped_signal(int sig)
if (!__ratelimit(_state))
return;
 
-   printk(KERN_INFO "%s/%d: reached RLIMIT_SIGPENDING, dropped signal 
%d\n",
+   pr_info("%s/%d: reached RLIMIT_SIGPENDING, dropped signal %d\n",
current->comm, current->pid, sig);
 }
 
@@ -1089,10 +1089,10 @@ static int send_signal(int sig, struct siginfo *info, 
struct task_struct *t,
 static void print_fatal_signal(int signr)
 {
struct pt_regs *regs = signal_pt_regs();
-   printk(KERN_INFO "potentially unexpected fatal signal %d.\n", signr);
+   pr_info("potentially unexpected fatal signal %d.\n", signr);
 
 #if defined(__i386__) && !defined(__arch_um__)
-   printk(KERN_INFO "code at %08lx: ", regs->ip);
+   pr_info("code at %08lx: ", regs->ip);
{
int i;
for (i = 0; i < 16; i++) {
@@ -1100,10 +1100,10 @@ static void print_fatal_signal(int signr)
 
if (get_user(insn, (unsigned char *)(regs->ip + i)))
break;
-   printk(KERN_CONT "%02x ", insn);
+   pr_cont("%02x ", insn);
}
}
-   printk(KERN_CONT "\n");
+   pr_cont("\n");
 #endif
preempt_disable();
show_regs(regs);
-- 
2.1.4




[PATCH] memory-failure/hwpoison_user_mappings: move the comment about swap cache pages' check to proper location

2015-08-04 Thread Wang Xiaoqiang
Hi Naoya,

This patch just move the comment about swap cache pages' check to the
proper location in 'hwpoison_user_mappings' function.

Signed-off-by: Wang Xiaoqiang 
---
 mm/memory-failure.c |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 1cf7f29..3253abb 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -945,10 +945,6 @@ static int hwpoison_user_mappings(struct page *p, unsigned 
long pfn,
if (!(PageLRU(hpage) || PageHuge(p)))
return SWAP_SUCCESS;
 
-   /*
-* This check implies we don't kill processes if their pages
-* are in the swap cache early. Those are always late kills.
-*/
if (!page_mapped(hpage))
return SWAP_SUCCESS;
 
@@ -957,6 +953,10 @@ static int hwpoison_user_mappings(struct page *p, unsigned 
long pfn,
return SWAP_FAIL;
}
 
+   /*
+* This check implies we don't kill processes if their pages
+* are in the swap cache early. Those are always late kills.
+*/
if (PageSwapCache(p)) {
printk(KERN_ERR
   "MCE %#lx: keeping poisoned page in swap cache\n", pfn);
-- 
1.7.10.4



--
thx!
Wang Xiaoqiang


--
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] memory-failure/hwpoison_user_mappings: move the comment about swap cache pages' check to proper location

2015-08-04 Thread Wang Xiaoqiang
Hi Naoya,

This patch just move the comment about swap cache pages' check to the
proper location in 'hwpoison_user_mappings' function.

Signed-off-by: Wang Xiaoqiang wangx...@lzu.edu.cn
---
 mm/memory-failure.c |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 1cf7f29..3253abb 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -945,10 +945,6 @@ static int hwpoison_user_mappings(struct page *p, unsigned 
long pfn,
if (!(PageLRU(hpage) || PageHuge(p)))
return SWAP_SUCCESS;
 
-   /*
-* This check implies we don't kill processes if their pages
-* are in the swap cache early. Those are always late kills.
-*/
if (!page_mapped(hpage))
return SWAP_SUCCESS;
 
@@ -957,6 +953,10 @@ static int hwpoison_user_mappings(struct page *p, unsigned 
long pfn,
return SWAP_FAIL;
}
 
+   /*
+* This check implies we don't kill processes if their pages
+* are in the swap cache early. Those are always late kills.
+*/
if (PageSwapCache(p)) {
printk(KERN_ERR
   MCE %#lx: keeping poisoned page in swap cache\n, pfn);
-- 
1.7.10.4



--
thx!
Wang Xiaoqiang


--
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/


Re: [PATCH] memory_failure: remove redundant check for the PG_HWPoison flag of 'hpage'

2015-07-29 Thread Wang Xiaoqiang
On Wed, 29 Jul 2015 09:17:32 +
Naoya Horiguchi  wrote:

> # CC:ed linux-mm
> 
> Hi Xiaoqiang,
> 
> On Wed, Jul 29, 2015 at 03:52:46PM +0800, Wang Xiaoqiang wrote:
> > Hi,
> > 
> > I find a little problem in the memory_failure function in
> > mm/memory-failure.c . Please check it.
> > 
> > memory_failure: remove redundant check for the PG_HWPoison flag of
> > `hpage'.
> > 
> > Since we have check the PG_HWPoison flag by `PageHWPoison' before,
> > so the later check by `TestSetPageHWPoison' must return true, there
> > is no need to check again!
> 
> I'm afraid that this TestSetPageHWPoison is not redundant, because
> this code serializes the concurrent memory error events over the same
> hugetlb page (, where 'p' indicates the 4kB error page and 'hpage'
> indicates the head page.)
> 
> When an error hits a hugetlb page, set_page_hwpoison_huge_page() sets
> PageHWPoison flags over all subpages of the hugetlb page in the
> ascending order of pfn. So if we don't have this TestSet, memory
> error handler can run more than once on concurrent errors when the
> 1st memory error hits (for example) the 100th subpage and the 2nd
> memory error hits (for example) the 50th subpage.

In your example, the 100th subage enter the memory
error handler firstly, and then it uses the 
set_page_hwpoison_huge_page to set all subpages
with PG_HWPoison flag, the 50th page handler waits
for grab the lock_page(hpage) now. 

When the 100th page handler unlock the 'hpage', 
the 50th grab it, and now the 'hapge' has been 
set with PG_HWPosison. So PageHWPoison micro 
will return true, and the following code will
be executed:

if (PageHWPoison(hpage)) {
if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
|| (p != hpage && TestSetPageHWPoison(hpage))) {
atomic_long_sub(nr_pages, _poisoned_pages);
unlock_page(hpage);
return 0;
}   
}

Now 'p' is 50th subpage, it doesn't equal the 
'hpage' obviously, so if we don't have TestSetPageHWPoison
here, it still will ignore the 50th error.
Why the memory error handler can run more than once?
Hope to receive from you!

thx,
Wang Xiaoqiang


> 
> Thanks,
> Naoya Horiguchi
> 
> > Signed-off-by: Wang Xiaoqiang 
> > ---
> >  mm/memory-failure.c |2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> > index 1cf7f29..7794fd8 100644
> > --- a/mm/memory-failure.c
> > +++ b/mm/memory-failure.c
> > @@ -1115,7 +1115,7 @@ int memory_failure(unsigned long pfn, int
> > trapno, int flags) lock_page(hpage);
> > if (PageHWPoison(hpage)) {
> > if ((hwpoison_filter(p) &&
> > TestClearPageHWPoison(p))
> > -   || (p != hpage &&
> > TestSetPageHWPoison(hpage))) {
> > +       || p != hpage) {
> > atomic_long_sub(nr_pages,
> > _poisoned_pages); unlock_page(hpage);
> > return 0;
> > -- 
> > 1.7.10.4
> > 
> > 
> > 
> > --
> > thx!
> > Wang Xiaoqiang
> > 

--
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] memory_failure: remove redundant check for the PG_HWPoison flag of 'hpage'

2015-07-29 Thread Wang Xiaoqiang
Hi,

I find a little problem in the memory_failure function in
mm/memory-failure.c . Please check it.

memory_failure: remove redundant check for the PG_HWPoison flag of
`hpage'.

Since we have check the PG_HWPoison flag by `PageHWPoison' before,
so the later check by `TestSetPageHWPoison' must return true, there
is no need to check again!

Signed-off-by: Wang Xiaoqiang 
---
 mm/memory-failure.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 1cf7f29..7794fd8 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1115,7 +1115,7 @@ int memory_failure(unsigned long pfn, int trapno, int 
flags)
lock_page(hpage);
if (PageHWPoison(hpage)) {
if ((hwpoison_filter(p) && 
TestClearPageHWPoison(p))
-   || (p != hpage && 
TestSetPageHWPoison(hpage))) {
+   || p != hpage) {
atomic_long_sub(nr_pages, 
_poisoned_pages);
unlock_page(hpage);
return 0;
-- 
1.7.10.4



--
thx!
Wang Xiaoqiang

--
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/


Re: [PATCH] memory_failure: remove redundant check for the PG_HWPoison flag of 'hpage'

2015-07-29 Thread Wang Xiaoqiang
On Wed, 29 Jul 2015 09:17:32 +
Naoya Horiguchi n-horigu...@ah.jp.nec.com wrote:

 # CC:ed linux-mm
 
 Hi Xiaoqiang,
 
 On Wed, Jul 29, 2015 at 03:52:46PM +0800, Wang Xiaoqiang wrote:
  Hi,
  
  I find a little problem in the memory_failure function in
  mm/memory-failure.c . Please check it.
  
  memory_failure: remove redundant check for the PG_HWPoison flag of
  `hpage'.
  
  Since we have check the PG_HWPoison flag by `PageHWPoison' before,
  so the later check by `TestSetPageHWPoison' must return true, there
  is no need to check again!
 
 I'm afraid that this TestSetPageHWPoison is not redundant, because
 this code serializes the concurrent memory error events over the same
 hugetlb page (, where 'p' indicates the 4kB error page and 'hpage'
 indicates the head page.)
 
 When an error hits a hugetlb page, set_page_hwpoison_huge_page() sets
 PageHWPoison flags over all subpages of the hugetlb page in the
 ascending order of pfn. So if we don't have this TestSet, memory
 error handler can run more than once on concurrent errors when the
 1st memory error hits (for example) the 100th subpage and the 2nd
 memory error hits (for example) the 50th subpage.

In your example, the 100th subage enter the memory
error handler firstly, and then it uses the 
set_page_hwpoison_huge_page to set all subpages
with PG_HWPoison flag, the 50th page handler waits
for grab the lock_page(hpage) now. 

When the 100th page handler unlock the 'hpage', 
the 50th grab it, and now the 'hapge' has been 
set with PG_HWPosison. So PageHWPoison micro 
will return true, and the following code will
be executed:

if (PageHWPoison(hpage)) {
if ((hwpoison_filter(p)  TestClearPageHWPoison(p))
|| (p != hpage  TestSetPageHWPoison(hpage))) {
atomic_long_sub(nr_pages, num_poisoned_pages);
unlock_page(hpage);
return 0;
}   
}

Now 'p' is 50th subpage, it doesn't equal the 
'hpage' obviously, so if we don't have TestSetPageHWPoison
here, it still will ignore the 50th error.
Why the memory error handler can run more than once?
Hope to receive from you!

thx,
Wang Xiaoqiang


 
 Thanks,
 Naoya Horiguchi
 
  Signed-off-by: Wang Xiaoqiang wangx...@lzu.edu.cn
  ---
   mm/memory-failure.c |2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
  
  diff --git a/mm/memory-failure.c b/mm/memory-failure.c
  index 1cf7f29..7794fd8 100644
  --- a/mm/memory-failure.c
  +++ b/mm/memory-failure.c
  @@ -1115,7 +1115,7 @@ int memory_failure(unsigned long pfn, int
  trapno, int flags) lock_page(hpage);
  if (PageHWPoison(hpage)) {
  if ((hwpoison_filter(p) 
  TestClearPageHWPoison(p))
  -   || (p != hpage 
  TestSetPageHWPoison(hpage))) {
  +   || p != hpage) {
  atomic_long_sub(nr_pages,
  num_poisoned_pages); unlock_page(hpage);
  return 0;
  -- 
  1.7.10.4
  
  
  
  --
  thx!
  Wang Xiaoqiang
  

--
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] memory_failure: remove redundant check for the PG_HWPoison flag of 'hpage'

2015-07-29 Thread Wang Xiaoqiang
Hi,

I find a little problem in the memory_failure function in
mm/memory-failure.c . Please check it.

memory_failure: remove redundant check for the PG_HWPoison flag of
`hpage'.

Since we have check the PG_HWPoison flag by `PageHWPoison' before,
so the later check by `TestSetPageHWPoison' must return true, there
is no need to check again!

Signed-off-by: Wang Xiaoqiang wangx...@lzu.edu.cn
---
 mm/memory-failure.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 1cf7f29..7794fd8 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1115,7 +1115,7 @@ int memory_failure(unsigned long pfn, int trapno, int 
flags)
lock_page(hpage);
if (PageHWPoison(hpage)) {
if ((hwpoison_filter(p)  
TestClearPageHWPoison(p))
-   || (p != hpage  
TestSetPageHWPoison(hpage))) {
+   || p != hpage) {
atomic_long_sub(nr_pages, 
num_poisoned_pages);
unlock_page(hpage);
return 0;
-- 
1.7.10.4



--
thx!
Wang Xiaoqiang

--
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/