[tip: core/rcu] rcutorture: Replace rcu_torture_stall string with %s

2021-04-11 Thread tip-bot2 for Stephen Zhang
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 0a27fff30a5e561dc77e9cb1bf9cf462e1735179
Gitweb:
https://git.kernel.org/tip/0a27fff30a5e561dc77e9cb1bf9cf462e1735179
Author:Stephen Zhang 
AuthorDate:Sat, 23 Jan 2021 17:54:17 +08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:22:28 -08:00

rcutorture: Replace rcu_torture_stall string with %s

This commit replaces a hard-coded "rcu_torture_stall" string in a
pr_alert() format with "%s" and __func__.

Signed-off-by: Stephen Zhang 
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/rcutorture.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 99657ff..271726e 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -1971,8 +1971,8 @@ static int rcu_torture_stall(void *args)
local_irq_disable();
else if (!stall_cpu_block)
preempt_disable();
-   pr_alert("rcu_torture_stall start on CPU %d.\n",
-raw_smp_processor_id());
+   pr_alert("%s start on CPU %d.\n",
+ __func__, raw_smp_processor_id());
while (ULONG_CMP_LT((unsigned long)ktime_get_seconds(),
stop_at))
if (stall_cpu_block)
@@ -1983,7 +1983,7 @@ static int rcu_torture_stall(void *args)
preempt_enable();
cur_ops->readunlock(idx);
}
-   pr_alert("rcu_torture_stall end.\n");
+   pr_alert("%s end.\n", __func__);
torture_shutdown_absorb("rcu_torture_stall");
while (!kthread_should_stop())
schedule_timeout_interruptible(10 * HZ);


[tip: core/rcu] torture: Replace torture_init_begin string with %s

2021-04-11 Thread tip-bot2 for Stephen Zhang
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 4ac9de07b24f93a87ad38c497ad00fe2451203e7
Gitweb:
https://git.kernel.org/tip/4ac9de07b24f93a87ad38c497ad00fe2451203e7
Author:Stephen Zhang 
AuthorDate:Sat, 23 Jan 2021 16:34:01 +08:00
Committer: Paul E. McKenney 
CommitterDate: Mon, 08 Mar 2021 14:22:28 -08:00

torture: Replace torture_init_begin string with %s

This commit replaces a hard-coded "torture_init_begin" string in
a pr_alert() format with "%s" and __func__.

Signed-off-by: Stephen Zhang 
Signed-off-by: Paul E. McKenney 
---
 kernel/torture.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/torture.c b/kernel/torture.c
index 01e336f..0a315c3 100644
--- a/kernel/torture.c
+++ b/kernel/torture.c
@@ -816,9 +816,9 @@ bool torture_init_begin(char *ttype, int v)
 {
mutex_lock(_mutex);
if (torture_type != NULL) {
-   pr_alert("torture_init_begin: Refusing %s init: %s running.\n",
-ttype, torture_type);
-   pr_alert("torture_init_begin: One torture test at a time!\n");
+   pr_alert("%s: Refusing %s init: %s running.\n",
+ __func__, ttype, torture_type);
+   pr_alert("%s: One torture test at a time!\n", __func__);
mutex_unlock(_mutex);
return false;
}


Re: [PATCH v1] clang_tools:gen_compile_commands: Change the default source directory

2021-02-15 Thread Stephen Zhang
Masahiro Yamada  于2021年2月15日周一 上午1:10写道:
>
> So, what is the problem?
>
>
>
>
> --
> Best Regards
> Masahiro Yamada

Okay,it seems that I misunderstood what you said before.

--
Best Regards
Stephen Zhang


Re: [PATCH v1] clang_tools:gen_compile_commands: Change the default source directory

2021-02-15 Thread Stephen Zhang
Nathan Chancellor  于2021年2月15日周一 上午7:28写道:
>
> This will actually work for the regular build system as it uses the full
> path to the files when O= is outside of the source tree. My comment
> applies only to the tools/ build system, which Masahiro has explicitly
> said he does not want this script to support.
>
> Cheers,
> Nathan

Thanks for the clarification. I start to get what you mean.

Cheers,
Stephen


Re: [PATCH v1] clang_tools:gen_compile_commands: Change the default source directory

2021-02-14 Thread Stephen Zhang
Masahiro Yamada  于2021年2月13日周六 下午8:46写道:
> This is the steps I tested.
>
>
> masahiro@oscar:~/ref/linux$ make O=build  defconfig all -j24
>   [ snip ]
> masahiro@oscar:~/ref/linux$
> ./scripts/clang-tools/gen_compile_commands.py  -d build
> masahiro@oscar:~/ref/linux$ grep '"file":' compile_commands.json |
> grep scripts/ | head -n5
> "file": "/home/masahiro/ref/linux/scripts/mod/empty.c"
> "file": "/home/masahiro/ref/linux/scripts/mod/sumversion.c"
> "file": "/home/masahiro/ref/linux/scripts/mod/file2alias.c"
> "file": "/home/masahiro/ref/linux/scripts/mod/modpost.c"
> "file": "/home/masahiro/ref/linux/build/scripts/kconfig/parser.tab.c"
>
> --
> Best Regards
> Masahiro Yamada

Thanks. Nathan had a detailed description about  this:

> $ make O=build
>
> will work with '-d .' because the .cmd files are in '.' and the source
> files will be placed relative to '.', which is correct. Your command
> does not work for two reasons:
>
> 1. You are using a build directory that is not a subpath of the source
> directory. In other words, this script would not work for
>
> $ make O=/tmp/build
>
> because '-d /tmp/build' needs to be used to find the .cmd files but then
> the relative path of the source files is messed up, as you point out.

This may help you reproduce the problem. So you shoud try:

>masahiro@oscar:~/ref/linux$ make O=/tmp/build  defconfig all -j24

where the build directory  is not a subpath of the source directory.

--
Best Regards
Stephen Zhang


Re: [PATCH v1] clang_tools:gen_compile_commands: Change the default source directory

2021-02-12 Thread Stephen Zhang
Masahiro Yamada  于2021年2月11日周四 下午10:16写道:
> Please stop.
>
>
> Commit 6ca4c6d25949117dc5b4845612e290b6d89e70a8
> removed the tools/ support.
>
>
> There exist two build systems in the Linux source tree.
> Kbuild covers the entire tree except tools/.
> The tools/ directory adopts a different build system.
>
> It is a pity that the tools/ directory
> went in a wrong direction, and people
> try to fix problems in a wrong layer.
>
>
> You are not the first person to send to
> tweak obj/source trees of this script.
>
> You can not do this correctly
> without terribly messing up the code.
>
> Please do not try to support tools/.
>
>
>
> --
> Best Regards
> Masahiro Yamada

Thanks for the suggestion.But what we try to support is scripts/
instead of tools/. 'tools/' here is to help explaining the problem.
Or am I just misunderstanding your words?

--
Best Regards
Stephen Zhang


Re: [PATCH v1] clang_tools:gen_compile_commands: Change the default source directory

2021-02-11 Thread Stephen Zhang
Nathan Chancellor  于2021年2月11日周四 上午2:24写道:
>
> On Wed, Feb 10, 2021 at 08:15:27PM +0800, Stephen Zhang wrote:
> > Nathan Chancellor  于2021年2月10日周三 上午3:27写道:
> >
> > > Just as an FYI, your email was HTML, which means it won't hit LKML.
> >
> >
> > Thanks for pointing that out. The existence of a GFW makes it difficult for
> > me to connect
> > to the mail server.  so I use git client to send patches only and reply to
> > emails with
> > gmail  web client.
>
> You can configure your Gmail web client to send text responses by
> default by clicking on the three dot menu in the compose window then
> chose the "plain text mode" option.
>

Thanks, this has always been a problem for me.

> The build directory needs to be involved because that is where the .cmd
> files will be but the source directory needs to be known because the
> source files in the .cmd files are relative to the source directory, not
> the build directory. This happens to work in most situations like I
> point out above but not always.
>
> I think that my patch is most likely the way to go unless others feel
> differently. It would be nice if you could give it a go.
>
> Cheers,
> Nathan

Do you mean  my patch's failure  in some cases  is because the build
directoty isn't involved after using "-d" to specify the source directory?

Actually, the build directory has already been involved by the "path"
argument. See:

def main():
for path in paths:
 
if os.path.isdir(path):
cmdfiles = cmdfiles_in_dir(path)
.

where the value of paths  is passed by  the "path" argument. Do I miss
something?

Cheers,
Stephen


[PATCH v1] clang_tools:gen_compile_commands: Change the default source directory

2021-02-08 Thread Stephen Zhang
The default source directory is set equal to build directory which
specified by "-d".But it is designed to be set to the current working
directoy by default, as the help messge says.It makes a differece when
source directory and build directory are in separted directorys.

Signed-off-by: Stephen Zhang 
---
 scripts/clang-tools/gen_compile_commands.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/clang-tools/gen_compile_commands.py 
b/scripts/clang-tools/gen_compile_commands.py
index 1996370..add9e47 100755
--- a/scripts/clang-tools/gen_compile_commands.py
+++ b/scripts/clang-tools/gen_compile_commands.py
@@ -64,7 +64,7 @@ def parse_arguments():
 os.path.abspath(args.directory),
 args.output,
 args.ar,
-args.paths if len(args.paths) > 0 else [args.directory])
+args.paths if len(args.paths) > 0 else [os.getcwd()])
 
 
 def cmdfiles_in_dir(directory):
-- 
1.8.3.1



[PATCH v4] kdb: kdb_support: Fix debugging information problem

2021-02-04 Thread Stephen Zhang
There are several common patterns.

0:
kdb_printf("...",...);

which is the normal one.

1:
kdb_printf("%s: "...,__func__,...)

We could improve '1' to this :

#define kdb_func_printf(format, args...) \
   kdb_printf("%s: " format, __func__, ## args)

2:
if(KDB_DEBUG(AR))
kdb_printf("%s "...,__func__,...);

We could improve '2' to this :
#define kdb_dbg_printf(mask, format, args...) \
   do { \
if (KDB_DEBUG(mask)) \
kdb_func_printf(format, ## 
args); \
   } while (0)

In additon, we changed the format code of size_t to %zu.

Signed-off-by: Stephen Zhang 
---
v1->v2 Changelog:
- Add 'mask' parameter in kdb_dbg_printf()

Thanks to Daniel and Doug's suggestions and review.

v2->v4 Changelog:
- Adjust alignment for some lines.

Suggested by Douglas Anderson.

 kernel/debug/kdb/kdb_private.h | 10 
 kernel/debug/kdb/kdb_support.c | 53 --
 2 files changed, 30 insertions(+), 33 deletions(-)

diff --git a/kernel/debug/kdb/kdb_private.h b/kernel/debug/kdb/kdb_private.h
index a4281fb..0a56d35 100644
--- a/kernel/debug/kdb/kdb_private.h
+++ b/kernel/debug/kdb/kdb_private.h
@@ -254,4 +254,14 @@ extern unsigned long kdb_task_state(const struct 
task_struct *p,
 #defineKDB_WORD_SIZE   ((int)sizeof(unsigned long))
 
 #endif /* CONFIG_KGDB_KDB */
+
+#define kdb_func_printf(format, args...) \
+   kdb_printf("%s: " format, __func__, ## args)
+
+#define kdb_dbg_printf(mask, format, args...) \
+   do { \
+   if (KDB_DEBUG(mask)) \
+   kdb_func_printf(format, ## args); \
+   } while (0)
+
 #endif /* !_KDBPRIVATE_H */
diff --git a/kernel/debug/kdb/kdb_support.c b/kernel/debug/kdb/kdb_support.c
index 6226502..f7c1885 100644
--- a/kernel/debug/kdb/kdb_support.c
+++ b/kernel/debug/kdb/kdb_support.c
@@ -39,20 +39,15 @@
  */
 int kdbgetsymval(const char *symname, kdb_symtab_t *symtab)
 {
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbgetsymval: symname=%s, symtab=%px\n", symname,
-  symtab);
+   kdb_dbg_printf(AR, "symname=%s, symtab=%px\n", symname, symtab);
memset(symtab, 0, sizeof(*symtab));
symtab->sym_start = kallsyms_lookup_name(symname);
if (symtab->sym_start) {
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbgetsymval: returns 1, "
-  "symtab->sym_start=0x%lx\n",
-  symtab->sym_start);
+   kdb_dbg_printf(AR, "returns 1, symtab->sym_start=0x%lx\n",
+  symtab->sym_start);
return 1;
}
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbgetsymval: returns 0\n");
+   kdb_dbg_printf(AR, "returns 0\n");
return 0;
 }
 EXPORT_SYMBOL(kdbgetsymval);
@@ -87,16 +82,14 @@ int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab)
 #define knt1_size 128  /* must be >= kallsyms table size */
char *knt1 = NULL;
 
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbnearsym: addr=0x%lx, symtab=%px\n", addr, 
symtab);
+   kdb_dbg_printf(AR, "addr=0x%lx, symtab=%px\n", addr, symtab);
memset(symtab, 0, sizeof(*symtab));
 
if (addr < 4096)
goto out;
knt1 = debug_kmalloc(knt1_size, GFP_ATOMIC);
if (!knt1) {
-   kdb_printf("kdbnearsym: addr=0x%lx cannot kmalloc knt1\n",
-  addr);
+   kdb_func_printf("addr=0x%lx cannot kmalloc knt1\n", addr);
goto out;
}
symtab->sym_name = kallsyms_lookup(addr,  , ,
@@ -147,11 +140,8 @@ int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab)
 
if (symtab->mod_name == NULL)
symtab->mod_name = "kernel";
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbnearsym: returns %d symtab->sym_start=0x%lx, "
-  "symtab->mod_name=%px, symtab->sym_name=%px (%s)\n", ret,
-  symtab->sym_start, symtab->mod_name, symtab->sym_name,
-  symtab->sym_name);
+   kdb_dbg_printf(AR, "returns %d symtab->sym_start=0x%lx, 
symtab->mod_name=%px, symtab->sym_name=%px (%s)\n",
+  ret, symtab->sym_start, symtab->mod_name, 
symtab->sym_name, symtab->sym_name);
 
 out:
debug_kfree(knt1);
@@ -328,7 +318,7 @@ int kdb_getarea_size(void *res, unsigned long addr, size_t 
size)
int ret = copy_from_kernel_nofault((char *)res, (char *)addr, size);
if (ret) {
   

[PATCH v3] kdb: kdb_support: Fix debugging information problem

2021-01-30 Thread Stephen Zhang
There are several common patterns.

0:
kdb_printf("...",...);

which is the normal one.

1:
kdb_printf("%s: "...,__func__,...)

We could improve '1' to this :

#define kdb_func_printf(format, args...) \
   kdb_printf("%s: " format, __func__, ## args)

2:
if(KDB_DEBUG(AR))
kdb_printf("%s "...,__func__,...);

We could improve '2' to this :
#define kdb_dbg_printf(mask, format, args...) \
   do { \
if (KDB_DEBUG(mask)) \
kdb_func_printf(format, ## 
args); \
   } while (0)

In additon, we changed the format code of size_t to %zu.

Signed-off-by: Stephen Zhang 
---
v1->v2 Changelog:
- Add 'mask' parameter in kdb_dbg_printf()

Thanks to Daniel and Doug's suggestions and review.

v2->v3 Changelog:
- Adjust alignment for some lines.

Suggested by Douglas Anderson.

 kernel/debug/kdb/kdb_private.h | 10 
 kernel/debug/kdb/kdb_support.c | 53 ++
 2 files changed, 32 insertions(+), 31 deletions(-)

diff --git a/kernel/debug/kdb/kdb_private.h b/kernel/debug/kdb/kdb_private.h
index a4281fb..0a56d35 100644
--- a/kernel/debug/kdb/kdb_private.h
+++ b/kernel/debug/kdb/kdb_private.h
@@ -254,4 +254,14 @@ extern unsigned long kdb_task_state(const struct 
task_struct *p,
 #defineKDB_WORD_SIZE   ((int)sizeof(unsigned long))
 
 #endif /* CONFIG_KGDB_KDB */
+
+#define kdb_func_printf(format, args...) \
+   kdb_printf("%s: " format, __func__, ## args)
+
+#define kdb_dbg_printf(mask, format, args...) \
+   do { \
+   if (KDB_DEBUG(mask)) \
+   kdb_func_printf(format, ## args); \
+   } while (0)
+
 #endif /* !_KDBPRIVATE_H */
diff --git a/kernel/debug/kdb/kdb_support.c b/kernel/debug/kdb/kdb_support.c
index 6226502..99a6232 100644
--- a/kernel/debug/kdb/kdb_support.c
+++ b/kernel/debug/kdb/kdb_support.c
@@ -39,20 +39,15 @@
  */
 int kdbgetsymval(const char *symname, kdb_symtab_t *symtab)
 {
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbgetsymval: symname=%s, symtab=%px\n", symname,
-  symtab);
+   kdb_dbg_printf(AR, "symname=%s, symtab=%px\n", symname, symtab);
memset(symtab, 0, sizeof(*symtab));
symtab->sym_start = kallsyms_lookup_name(symname);
if (symtab->sym_start) {
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbgetsymval: returns 1, "
-  "symtab->sym_start=0x%lx\n",
-  symtab->sym_start);
+   kdb_dbg_printf(AR, "returns 1,symtab->sym_start=0x%lx\n",
+ symtab->sym_start);
return 1;
}
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbgetsymval: returns 0\n");
+   kdb_dbg_printf(AR, "returns 0\n");
return 0;
 }
 EXPORT_SYMBOL(kdbgetsymval);
@@ -87,15 +82,14 @@ int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab)
 #define knt1_size 128  /* must be >= kallsyms table size */
char *knt1 = NULL;
 
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbnearsym: addr=0x%lx, symtab=%px\n", addr, 
symtab);
+   kdb_dbg_printf(AR, "addr=0x%lx, symtab=%px\n", addr, symtab);
memset(symtab, 0, sizeof(*symtab));
 
if (addr < 4096)
goto out;
knt1 = debug_kmalloc(knt1_size, GFP_ATOMIC);
if (!knt1) {
-   kdb_printf("kdbnearsym: addr=0x%lx cannot kmalloc knt1\n",
+   kdb_func_printf("addr=0x%lx cannot kmalloc knt1\n",
   addr);
goto out;
}
@@ -147,11 +141,10 @@ int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab)
 
if (symtab->mod_name == NULL)
symtab->mod_name = "kernel";
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbnearsym: returns %d symtab->sym_start=0x%lx, "
-  "symtab->mod_name=%px, symtab->sym_name=%px (%s)\n", ret,
-  symtab->sym_start, symtab->mod_name, symtab->sym_name,
-  symtab->sym_name);
+   kdb_dbg_printf(AR, "returns %d symtab->sym_start=0x%lx, "
+   "symtab->mod_name=%px, symtab->sym_name=%px (%s)\n", ret,
+   symtab->sym_start, symtab->mod_name, symtab->sym_name,
+   symtab->sym_name);
 
 out:
debug_kfree(knt1);
@@ -328,7 +321,7 @@ int kdb_getarea_size(void *res, unsigned long addr, size_t 
size)
int ret = copy_from_kernel_nofault((char *)res, (char *)addr, size);
if (ret) {
if (!KDB_STAT

[PATCH v2] kdb: kdb_support: Fix debugging information problem

2021-01-27 Thread Stephen Zhang
There are several common patterns.

0:
kdb_printf("...",...);

which is the normal one.

1:
kdb_printf("%s: "...,__func__,...)

We could improve '1' to this :

#define kdb_func_printf(format, args...) \
   kdb_printf("%s: " format, __func__, ## args)

2:
if(KDB_DEBUG(AR))
kdb_printf("%s "...,__func__,...);

We could improve '2' to this :
#define kdb_dbg_printf(mask, format, args...) \
   do { \
if (KDB_DEBUG(mask)) \
kdb_func_printf(format, ## 
args); \
   } while (0)

In additon, we changed the format code of size_t to %zu.

Signed-off-by: Stephen Zhang 
---
v1->v2 Changelog:
- Add 'mask' parameter in kdb_dbg_printf()

Thanks to Daniel and Doug's suggestions and review.

 kernel/debug/kdb/kdb_private.h | 10 
 kernel/debug/kdb/kdb_support.c | 56 +++---
 2 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/kernel/debug/kdb/kdb_private.h b/kernel/debug/kdb/kdb_private.h
index a4281fb..0a56d35 100644
--- a/kernel/debug/kdb/kdb_private.h
+++ b/kernel/debug/kdb/kdb_private.h
@@ -254,4 +254,14 @@ extern unsigned long kdb_task_state(const struct 
task_struct *p,
 #defineKDB_WORD_SIZE   ((int)sizeof(unsigned long))
 
 #endif /* CONFIG_KGDB_KDB */
+
+#define kdb_func_printf(format, args...) \
+   kdb_printf("%s: " format, __func__, ## args)
+
+#define kdb_dbg_printf(mask, format, args...) \
+   do { \
+   if (KDB_DEBUG(mask)) \
+   kdb_func_printf(format, ## args); \
+   } while (0)
+
 #endif /* !_KDBPRIVATE_H */
diff --git a/kernel/debug/kdb/kdb_support.c b/kernel/debug/kdb/kdb_support.c
index 6226502..0f6fc77 100644
--- a/kernel/debug/kdb/kdb_support.c
+++ b/kernel/debug/kdb/kdb_support.c
@@ -39,20 +39,17 @@
  */
 int kdbgetsymval(const char *symname, kdb_symtab_t *symtab)
 {
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbgetsymval: symname=%s, symtab=%px\n", symname,
-  symtab);
+   kdb_dbg_printf(AR, "symname=%s, symtab=%px\n", symname,
+   symtab);
memset(symtab, 0, sizeof(*symtab));
symtab->sym_start = kallsyms_lookup_name(symname);
if (symtab->sym_start) {
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbgetsymval: returns 1, "
-  "symtab->sym_start=0x%lx\n",
-  symtab->sym_start);
+   kdb_dbg_printf(AR, "returns 1, "
+   "symtab->sym_start=0x%lx\n",
+   symtab->sym_start);
return 1;
}
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbgetsymval: returns 0\n");
+   kdb_dbg_printf(AR, "returns 0\n");
return 0;
 }
 EXPORT_SYMBOL(kdbgetsymval);
@@ -87,15 +84,14 @@ int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab)
 #define knt1_size 128  /* must be >= kallsyms table size */
char *knt1 = NULL;
 
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbnearsym: addr=0x%lx, symtab=%px\n", addr, 
symtab);
+   kdb_dbg_printf(AR, "addr=0x%lx, symtab=%px\n", addr, symtab);
memset(symtab, 0, sizeof(*symtab));
 
if (addr < 4096)
goto out;
knt1 = debug_kmalloc(knt1_size, GFP_ATOMIC);
if (!knt1) {
-   kdb_printf("kdbnearsym: addr=0x%lx cannot kmalloc knt1\n",
+   kdb_func_printf("addr=0x%lx cannot kmalloc knt1\n",
   addr);
goto out;
}
@@ -147,11 +143,10 @@ int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab)
 
if (symtab->mod_name == NULL)
symtab->mod_name = "kernel";
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbnearsym: returns %d symtab->sym_start=0x%lx, "
-  "symtab->mod_name=%px, symtab->sym_name=%px (%s)\n", ret,
-  symtab->sym_start, symtab->mod_name, symtab->sym_name,
-  symtab->sym_name);
+   kdb_dbg_printf(AR, "returns %d symtab->sym_start=0x%lx, "
+   "symtab->mod_name=%px, symtab->sym_name=%px (%s)\n", ret,
+   symtab->sym_start, symtab->mod_name, symtab->sym_name,
+   symtab->sym_name);
 
 out:
debug_kfree(knt1);
@@ -328,7 +323,7 @@ int kdb_getarea_size(void *res, unsigned long addr, size_t 
size)
int ret = copy_from_kernel_nofault((char *)res, (char *)addr, size);
if (ret) {
if (!KDB_STATE(SUPPRESS)) {
-   kdb_printf(&quo

[PATCH] kdb: kdb_support: Fix debugging information problem

2021-01-27 Thread Stephen Zhang
There are several common patterns.

0:
kdb_printf("...",...);

which is the normal one.

1:
kdb_printf("%s: "...,__func__,...)

We could improve '1' to this :

#define kdb_func_printf(format, args...) \
   kdb_printf("%s: " format, __func__, ## args)

2:
if(KDB_DEBUG(AR))
kdb_printf("%s "...,__func__,...);

We could improve '2' to this :
#define kdb_dbg_printf(mask, format, args...) \
   do { \
if (KDB_DEBUG(mask)) \
kdb_func_printf(format, ## 
args); \
   } while (0)

In additon, we changed the format code of size_t to %zu.

Signed-off-by: Stephen Zhang 
---
 kernel/debug/kdb/kdb_private.h | 10 
 kernel/debug/kdb/kdb_support.c | 56 +++---
 2 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/kernel/debug/kdb/kdb_private.h b/kernel/debug/kdb/kdb_private.h
index a4281fb..0a56d35 100644
--- a/kernel/debug/kdb/kdb_private.h
+++ b/kernel/debug/kdb/kdb_private.h
@@ -254,4 +254,14 @@ extern unsigned long kdb_task_state(const struct 
task_struct *p,
 #defineKDB_WORD_SIZE   ((int)sizeof(unsigned long))
 
 #endif /* CONFIG_KGDB_KDB */
+
+#define kdb_func_printf(format, args...) \
+   kdb_printf("%s: " format, __func__, ## args)
+
+#define kdb_dbg_printf(mask, format, args...) \
+   do { \
+   if (KDB_DEBUG(mask)) \
+   kdb_func_printf(format, ## args); \
+   } while (0)
+
 #endif /* !_KDBPRIVATE_H */
diff --git a/kernel/debug/kdb/kdb_support.c b/kernel/debug/kdb/kdb_support.c
index 6226502..0f6fc77 100644
--- a/kernel/debug/kdb/kdb_support.c
+++ b/kernel/debug/kdb/kdb_support.c
@@ -39,20 +39,17 @@
  */
 int kdbgetsymval(const char *symname, kdb_symtab_t *symtab)
 {
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbgetsymval: symname=%s, symtab=%px\n", symname,
-  symtab);
+   kdb_dbg_printf(AR, "symname=%s, symtab=%px\n", symname,
+   symtab);
memset(symtab, 0, sizeof(*symtab));
symtab->sym_start = kallsyms_lookup_name(symname);
if (symtab->sym_start) {
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbgetsymval: returns 1, "
-  "symtab->sym_start=0x%lx\n",
-  symtab->sym_start);
+   kdb_dbg_printf(AR, "returns 1, "
+   "symtab->sym_start=0x%lx\n",
+   symtab->sym_start);
return 1;
}
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbgetsymval: returns 0\n");
+   kdb_dbg_printf(AR, "returns 0\n");
return 0;
 }
 EXPORT_SYMBOL(kdbgetsymval);
@@ -87,15 +84,14 @@ int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab)
 #define knt1_size 128  /* must be >= kallsyms table size */
char *knt1 = NULL;
 
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbnearsym: addr=0x%lx, symtab=%px\n", addr, 
symtab);
+   kdb_dbg_printf(AR, "addr=0x%lx, symtab=%px\n", addr, symtab);
memset(symtab, 0, sizeof(*symtab));
 
if (addr < 4096)
goto out;
knt1 = debug_kmalloc(knt1_size, GFP_ATOMIC);
if (!knt1) {
-   kdb_printf("kdbnearsym: addr=0x%lx cannot kmalloc knt1\n",
+   kdb_func_printf("addr=0x%lx cannot kmalloc knt1\n",
   addr);
goto out;
}
@@ -147,11 +143,10 @@ int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab)
 
if (symtab->mod_name == NULL)
symtab->mod_name = "kernel";
-   if (KDB_DEBUG(AR))
-   kdb_printf("kdbnearsym: returns %d symtab->sym_start=0x%lx, "
-  "symtab->mod_name=%px, symtab->sym_name=%px (%s)\n", ret,
-  symtab->sym_start, symtab->mod_name, symtab->sym_name,
-  symtab->sym_name);
+   kdb_dbg_printf(AR, "returns %d symtab->sym_start=0x%lx, "
+   "symtab->mod_name=%px, symtab->sym_name=%px (%s)\n", ret,
+   symtab->sym_start, symtab->mod_name, symtab->sym_name,
+   symtab->sym_name);
 
 out:
debug_kfree(knt1);
@@ -328,7 +323,7 @@ int kdb_getarea_size(void *res, unsigned long addr, size_t 
size)
int ret = copy_from_kernel_nofault((char *)res, (char *)addr, size);
if (ret) {
if (!KDB_STATE(SUPPRESS)) {
-   kdb_printf("kdb_getarea: Bad address 0x%lx\n", addr);
+   kdb_func_printf("Ba

[PATCH] KVM: x86/mmu: Add '__func__' in rmap_printk()

2021-01-26 Thread Stephen Zhang
Given the common pattern:

rmap_printk("%s:"..., __func__,...)

we could improve this by adding '__func__' in rmap_printk().

Signed-off-by: Stephen Zhang 
---
 arch/x86/kvm/mmu/mmu.c  | 20 ++--
 arch/x86/kvm/mmu/mmu_internal.h |  2 +-
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 6d16481..1460705 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -844,17 +844,17 @@ static int pte_list_add(struct kvm_vcpu *vcpu, u64 *spte,
int i, count = 0;
 
if (!rmap_head->val) {
-   rmap_printk("pte_list_add: %p %llx 0->1\n", spte, *spte);
+   rmap_printk("%p %llx 0->1\n", spte, *spte);
rmap_head->val = (unsigned long)spte;
} else if (!(rmap_head->val & 1)) {
-   rmap_printk("pte_list_add: %p %llx 1->many\n", spte, *spte);
+   rmap_printk("%p %llx 1->many\n", spte, *spte);
desc = mmu_alloc_pte_list_desc(vcpu);
desc->sptes[0] = (u64 *)rmap_head->val;
desc->sptes[1] = spte;
rmap_head->val = (unsigned long)desc | 1;
++count;
} else {
-   rmap_printk("pte_list_add: %p %llx many->many\n", spte, *spte);
+   rmap_printk("%p %llx many->many\n", spte, *spte);
desc = (struct pte_list_desc *)(rmap_head->val & ~1ul);
while (desc->sptes[PTE_LIST_EXT-1]) {
count += PTE_LIST_EXT;
@@ -906,14 +906,14 @@ static void __pte_list_remove(u64 *spte, struct 
kvm_rmap_head *rmap_head)
pr_err("%s: %p 0->BUG\n", __func__, spte);
BUG();
} else if (!(rmap_head->val & 1)) {
-   rmap_printk("%s:  %p 1->0\n", __func__, spte);
+   rmap_printk("%p 1->0\n", spte);
if ((u64 *)rmap_head->val != spte) {
pr_err("%s:  %p 1->BUG\n", __func__, spte);
BUG();
}
rmap_head->val = 0;
} else {
-   rmap_printk("%s:  %p many->many\n", __func__, spte);
+   rmap_printk("%p many->many\n", spte);
desc = (struct pte_list_desc *)(rmap_head->val & ~1ul);
prev_desc = NULL;
while (desc) {
@@ -1115,7 +1115,7 @@ static bool spte_write_protect(u64 *sptep, bool 
pt_protect)
  !(pt_protect && spte_can_locklessly_be_made_writable(spte)))
return false;
 
-   rmap_printk("rmap_write_protect: spte %p %llx\n", sptep, *sptep);
+   rmap_printk("spte %p %llx\n", sptep, *sptep);
 
if (pt_protect)
spte &= ~SPTE_MMU_WRITEABLE;
@@ -1142,7 +1142,7 @@ static bool spte_clear_dirty(u64 *sptep)
 {
u64 spte = *sptep;
 
-   rmap_printk("rmap_clear_dirty: spte %p %llx\n", sptep, *sptep);
+   rmap_printk("spte %p %llx\n", sptep, *sptep);
 
MMU_WARN_ON(!spte_ad_enabled(spte));
spte &= ~shadow_dirty_mask;
@@ -1184,7 +1184,7 @@ static bool spte_set_dirty(u64 *sptep)
 {
u64 spte = *sptep;
 
-   rmap_printk("rmap_set_dirty: spte %p %llx\n", sptep, *sptep);
+   rmap_printk("spte %p %llx\n", sptep, *sptep);
 
/*
 * Similar to the !kvm_x86_ops.slot_disable_log_dirty case,
@@ -1331,7 +1331,7 @@ static bool kvm_zap_rmapp(struct kvm *kvm, struct 
kvm_rmap_head *rmap_head)
bool flush = false;
 
while ((sptep = rmap_get_first(rmap_head, ))) {
-   rmap_printk("%s: spte %p %llx.\n", __func__, sptep, *sptep);
+   rmap_printk("spte %p %llx.\n", sptep, *sptep);
 
pte_list_remove(rmap_head, sptep);
flush = true;
@@ -1363,7 +1363,7 @@ static int kvm_set_pte_rmapp(struct kvm *kvm, struct 
kvm_rmap_head *rmap_head,
 
 restart:
for_each_rmap_spte(rmap_head, , sptep) {
-   rmap_printk("kvm_set_pte_rmapp: spte %p %llx gfn %llx (%d)\n",
+   rmap_printk("spte %p %llx gfn %llx (%d)\n",
sptep, *sptep, gfn, level);
 
need_flush = 1;
diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h
index bfc6389..5ec15e4 100644
--- a/arch/x86/kvm/mmu/mmu_internal.h
+++ b/arch/x86/kvm/mmu/mmu_internal.h
@@ -12,7 +12,7 @@
 extern bool dbg;
 
 #define pgprintk(x...) do { if (dbg) printk(x); } while (0)
-#define rmap_printk(x...) do { if (dbg) printk(x); } while (0)
+#define rmap_printk(fmt, args...) do { if (dbg) printk("%s: " fmt, __func__, 
## args); } while (0)
 #define MMU_WARN_ON(x) WARN_ON(x)
 #else
 #define pgprintk(x...) do { } while (0)
-- 
1.8.3.1



[PATCH] mm/memfd: replace strcpy() by strscpy()

2021-01-23 Thread Stephen Zhang
The strcpy() function is being deprecated. Replace it by the safer
strscpy().

Signed-off-by: Stephen Zhang 
---
 mm/memfd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memfd.c b/mm/memfd.c
index 2647c89..bb90862 100644
--- a/mm/memfd.c
+++ b/mm/memfd.c
@@ -278,7 +278,7 @@ long memfd_fcntl(struct file *file, unsigned int cmd, 
unsigned long arg)
if (!name)
return -ENOMEM;
 
-   strcpy(name, MFD_NAME_PREFIX);
+   strscpy(name, MFD_NAME_PREFIX, len + MFD_NAME_PREFIX_LEN);
if (copy_from_user([MFD_NAME_PREFIX_LEN], uname, len)) {
error = -EFAULT;
goto err_name;
-- 
1.8.3.1



[PATCH] rcutorture: replace the function name with %s

2021-01-23 Thread Stephen Zhang
Better to replace the function name with %s in case of changes.

Signed-off-by: Stephen Zhang 
---
 kernel/rcu/rcutorture.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 2440f89..e561641 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -2016,8 +2016,8 @@ static int rcu_torture_stall(void *args)
local_irq_disable();
else if (!stall_cpu_block)
preempt_disable();
-   pr_alert("rcu_torture_stall start on CPU %d.\n",
-raw_smp_processor_id());
+   pr_alert("%s start on CPU %d.\n",
+ __func__, raw_smp_processor_id());
while (ULONG_CMP_LT((unsigned long)ktime_get_seconds(),
stop_at))
if (stall_cpu_block)
@@ -2028,7 +2028,7 @@ static int rcu_torture_stall(void *args)
preempt_enable();
cur_ops->readunlock(idx);
}
-   pr_alert("rcu_torture_stall end.\n");
+   pr_alert("%s end.\n", __func__);
torture_shutdown_absorb("rcu_torture_stall");
while (!kthread_should_stop())
schedule_timeout_interruptible(10 * HZ);
-- 
1.8.3.1



[PATCH] genirq/irqdomain: Fix debugging information in irq_create_mapping_affinity()

2021-01-23 Thread Stephen Zhang
Replace the function name with __func__ in case of changes.

Signed-off-by: Stephen Zhang 
---
 kernel/irq/irqdomain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index 6aacd34..2cad63e 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -661,7 +661,7 @@ unsigned int irq_create_mapping_affinity(struct irq_domain 
*domain,
struct device_node *of_node;
int virq;
 
-   pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
+   pr_debug("%s(0x%p, 0x%lx)\n",  __func__, domain, hwirq);
 
/* Look for default domain if nececssary */
if (domain == NULL)
-- 
1.8.3.1



[PATCH] torture: replace the function name with %s

2021-01-23 Thread Stephen Zhang
Better to replace the function name with %s.

Signed-off-by: Stephen Zhang 
---
 kernel/torture.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/torture.c b/kernel/torture.c
index 01e336f..0a315c3 100644
--- a/kernel/torture.c
+++ b/kernel/torture.c
@@ -816,9 +816,9 @@ bool torture_init_begin(char *ttype, int v)
 {
mutex_lock(_mutex);
if (torture_type != NULL) {
-   pr_alert("torture_init_begin: Refusing %s init: %s running.\n",
-ttype, torture_type);
-   pr_alert("torture_init_begin: One torture test at a time!\n");
+   pr_alert("%s: Refusing %s init: %s running.\n",
+ __func__, ttype, torture_type);
+   pr_alert("%s: One torture test at a time!\n", __func__);
mutex_unlock(_mutex);
return false;
}
-- 
1.8.3.1



[PATCH] workqueue: Use %s instead of function name

2021-01-23 Thread Stephen Zhang
It is better to replace the function name with %s, in case the function
name changes.

Signed-off-by: Stephen Zhang 
---
 kernel/workqueue.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 9880b6c..8b1b616 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -2964,8 +2964,8 @@ void drain_workqueue(struct workqueue_struct *wq)
 
if (++flush_cnt == 10 ||
(flush_cnt % 100 == 0 && flush_cnt <= 1000))
-   pr_warn("workqueue %s: drain_workqueue() isn't complete 
after %u tries\n",
-   wq->name, flush_cnt);
+   pr_warn("workqueue %s: %s() isn't complete after %u 
tries\n",
+   wq->name, __func__, flush_cnt);
 
mutex_unlock(>mutex);
goto reflush;
-- 
1.8.3.1



[PATCH] mm/early_ioremap.c: Use __func__ instead of function name

2021-01-22 Thread Stephen Zhang
It is better to use __func__ instead of function name.

Signed-off-by: Stephen Zhang 
---
 mm/early_ioremap.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/mm/early_ioremap.c b/mm/early_ioremap.c
index a0018ad..164607c 100644
--- a/mm/early_ioremap.c
+++ b/mm/early_ioremap.c
@@ -181,17 +181,17 @@ void __init early_iounmap(void __iomem *addr, unsigned 
long size)
}
}
 
-   if (WARN(slot < 0, "early_iounmap(%p, %08lx) not found slot\n",
-addr, size))
+   if (WARN(slot < 0, "%s(%p, %08lx) not found slot\n",
+ __func__, addr, size))
return;
 
if (WARN(prev_size[slot] != size,
-"early_iounmap(%p, %08lx) [%d] size not consistent %08lx\n",
-addr, size, slot, prev_size[slot]))
+"%s(%p, %08lx) [%d] size not consistent %08lx\n",
+ __func__, addr, size, slot, prev_size[slot]))
return;
 
-   WARN(early_ioremap_debug, "early_iounmap(%p, %08lx) [%d]\n",
-addr, size, slot);
+   WARN(early_ioremap_debug, "%s(%p, %08lx) [%d]\n",
+ __func__, addr, size, slot);
 
virt_addr = (unsigned long)addr;
if (WARN_ON(virt_addr < fix_to_virt(FIX_BTMAP_BEGIN)))
-- 
1.8.3.1



[PATCH] mm/swapfile.c: fix debugging information problem

2021-01-22 Thread Stephen Zhang
Once the function name is changed, it may be easy to forget to modify
the corresponding code here.

Signed-off-by: Stephen Zhang 
---
 mm/swapfile.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 9fffc5a..12a18b8 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1158,13 +1158,13 @@ static struct swap_info_struct 
*__swap_info_get(swp_entry_t entry)
return p;
 
 bad_offset:
-   pr_err("swap_info_get: %s%08lx\n", Bad_offset, entry.val);
+   pr_err("%s: %s%08lx\n", __func__, Bad_offset, entry.val);
goto out;
 bad_device:
-   pr_err("swap_info_get: %s%08lx\n", Unused_file, entry.val);
+   pr_err("%s: %s%08lx\n", __func__, Unused_file, entry.val);
goto out;
 bad_nofile:
-   pr_err("swap_info_get: %s%08lx\n", Bad_file, entry.val);
+   pr_err("%s: %s%08lx\n", __func__, Bad_file, entry.val);
 out:
return NULL;
 }
@@ -1181,7 +1181,7 @@ static struct swap_info_struct 
*_swap_info_get(swp_entry_t entry)
return p;
 
 bad_free:
-   pr_err("swap_info_get: %s%08lx\n", Unused_offset, entry.val);
+   pr_err("%s: %s%08lx\n", __func__, Unused_offset, entry.val);
 out:
return NULL;
 }
-- 
1.8.3.1



[PATCH] KVM: x86/mmu: improve robustness of some functions

2021-01-22 Thread Stephen Zhang
If the name of this function changes, you can easily
forget to modify the code in the corresponding place.
In fact, such errors already exist in spte_write_protect
 and spte_clear_dirty.

Signed-off-by: Stephen Zhang 
---
 arch/x86/kvm/mmu/mmu.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 6d16481..09462c3d 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -844,17 +844,17 @@ static int pte_list_add(struct kvm_vcpu *vcpu, u64 *spte,
int i, count = 0;
 
if (!rmap_head->val) {
-   rmap_printk("pte_list_add: %p %llx 0->1\n", spte, *spte);
+   rmap_printk("%s: %p %llx 0->1\n", __func__, spte, *spte);
rmap_head->val = (unsigned long)spte;
} else if (!(rmap_head->val & 1)) {
-   rmap_printk("pte_list_add: %p %llx 1->many\n", spte, *spte);
+   rmap_printk("%s: %p %llx 1->many\n", __func__, spte, *spte);
desc = mmu_alloc_pte_list_desc(vcpu);
desc->sptes[0] = (u64 *)rmap_head->val;
desc->sptes[1] = spte;
rmap_head->val = (unsigned long)desc | 1;
++count;
} else {
-   rmap_printk("pte_list_add: %p %llx many->many\n", spte, *spte);
+   rmap_printk("%s: %p %llx many->many\n", __func__, spte, *spte);
desc = (struct pte_list_desc *)(rmap_head->val & ~1ul);
while (desc->sptes[PTE_LIST_EXT-1]) {
count += PTE_LIST_EXT;
@@ -1115,7 +1115,7 @@ static bool spte_write_protect(u64 *sptep, bool 
pt_protect)
  !(pt_protect && spte_can_locklessly_be_made_writable(spte)))
return false;
 
-   rmap_printk("rmap_write_protect: spte %p %llx\n", sptep, *sptep);
+   rmap_printk("%s: spte %p %llx\n", __func__, sptep, *sptep);
 
if (pt_protect)
spte &= ~SPTE_MMU_WRITEABLE;
@@ -1142,7 +1142,7 @@ static bool spte_clear_dirty(u64 *sptep)
 {
u64 spte = *sptep;
 
-   rmap_printk("rmap_clear_dirty: spte %p %llx\n", sptep, *sptep);
+   rmap_printk("%s: spte %p %llx\n", __func__, sptep, *sptep);
 
MMU_WARN_ON(!spte_ad_enabled(spte));
spte &= ~shadow_dirty_mask;
@@ -1184,7 +1184,7 @@ static bool spte_set_dirty(u64 *sptep)
 {
u64 spte = *sptep;
 
-   rmap_printk("rmap_set_dirty: spte %p %llx\n", sptep, *sptep);
+   rmap_printk("%s: spte %p %llx\n", __func__, sptep, *sptep);
 
/*
 * Similar to the !kvm_x86_ops.slot_disable_log_dirty case,
@@ -1363,8 +1363,8 @@ static int kvm_set_pte_rmapp(struct kvm *kvm, struct 
kvm_rmap_head *rmap_head,
 
 restart:
for_each_rmap_spte(rmap_head, , sptep) {
-   rmap_printk("kvm_set_pte_rmapp: spte %p %llx gfn %llx (%d)\n",
-   sptep, *sptep, gfn, level);
+   rmap_printk("%s: spte %p %llx gfn %llx (%d)\n",
+ __func__, sptep, *sptep, gfn, level);
 
need_flush = 1;
 
-- 
1.8.3.1



[PATCH] KVM: x86: change in pv_eoi_get_pending() to make code more readable

2020-12-17 Thread Stephen Zhang
Signed-off-by: Stephen Zhang 
---
 arch/x86/kvm/lapic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 3136e05..7882322 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -674,7 +674,7 @@ static bool pv_eoi_get_pending(struct kvm_vcpu *vcpu)
   (unsigned long long)vcpu->arch.pv_eoi.msr_val);
return false;
}
-   return val & 0x1;
+   return val & KVM_PV_EOI_ENABLED;
 }
 
 static void pv_eoi_set_pending(struct kvm_vcpu *vcpu)
-- 
1.8.3.1



[PATCH] kvm:vmx:changes in handle_io() for code cleanup.

2020-12-10 Thread Stephen Zhang
Signed-off-by: Stephen Zhang 
---
 arch/x86/kvm/vmx/vmx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 47b8357..e1954df 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -4899,15 +4899,15 @@ static int handle_triple_fault(struct kvm_vcpu *vcpu)
 static int handle_io(struct kvm_vcpu *vcpu)
 {
unsigned long exit_qualification;
-   int size, in, string;
+   int size, in;
unsigned port;
 
exit_qualification = vmx_get_exit_qual(vcpu);
-   string = (exit_qualification & 16) != 0;
 
++vcpu->stat.io_exits;
 
-   if (string)
+   /* String instruction */
+   if (exit_qualification & BIT(4))
return kvm_emulate_instruction(vcpu, 0);
 
port = exit_qualification >> 16;
-- 
1.8.3.1



[PATCH] kvm:vmx:code changes in handle_io() to save some CPU cycles.

2020-12-10 Thread Stephen Zhang
code changes in handle_io() to save some CPU cycles.

Signed-off-by: Stephen Zhang 
---
 arch/x86/kvm/vmx/vmx.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 47b8357..109bcf64 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -4899,15 +4899,14 @@ static int handle_triple_fault(struct kvm_vcpu *vcpu)
 static int handle_io(struct kvm_vcpu *vcpu)
 {
unsigned long exit_qualification;
-   int size, in, string;
+   int size, in;
unsigned port;
 
exit_qualification = vmx_get_exit_qual(vcpu);
-   string = (exit_qualification & 16) != 0;
 
++vcpu->stat.io_exits;
 
-   if (string)
+   if (exit_qualification & 16)
return kvm_emulate_instruction(vcpu, 0);
 
port = exit_qualification >> 16;
-- 
1.8.3.1