2022-10-25 08:01:20

by David Gow

[permalink] [raw]
Subject: [PATCH v2 3/3] mm: slub: test: Use the kunit_get_current_test() function

Use the newly-added function kunit_get_current_test() instead of
accessing current->kunit_test directly. This function uses a static key
to return more quickly when KUnit is enabled, but no tests are actively
running. There should therefore be a negligible performance impact to
enabling the slub KUnit tests.

Other than the performance improvement, this should be a no-op.

Cc: Oliver Glitta <[email protected]>
Cc: Hyeonggon Yoo <[email protected]>
Cc: Christoph Lameter <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Andrew Morton <[email protected]>
Signed-off-by: David Gow <[email protected]>
---

This is intended as an example use of the new function. Other users
(such as KASAN) will be updated separately, as there would otherwise be
conflicts.

Assuming there are no objections, we'll take this whole series via the
kselftest/kunit tree.

There was no v1 of this patch. v1 of the series can be found here:
https://lore.kernel.org/linux-kselftest/[email protected]/T/#u

---
lib/slub_kunit.c | 1 +
mm/slub.c | 5 +++--
2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/slub_kunit.c b/lib/slub_kunit.c
index 7a0564d7cb7a..8fd19c8301ad 100644
--- a/lib/slub_kunit.c
+++ b/lib/slub_kunit.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include <kunit/test.h>
+#include <kunit/test-bug.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/module.h>
diff --git a/mm/slub.c b/mm/slub.c
index 157527d7101b..15d10d250ef2 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -39,6 +39,7 @@
#include <linux/memcontrol.h>
#include <linux/random.h>
#include <kunit/test.h>
+#include <kunit/test-bug.h>
#include <linux/sort.h>

#include <linux/debugfs.h>
@@ -603,10 +604,10 @@ static bool slab_add_kunit_errors(void)
{
struct kunit_resource *resource;

- if (likely(!current->kunit_test))
+ if (likely(!kunit_get_current_test()))
return false;

- resource = kunit_find_named_resource(current->kunit_test, "slab_errors");
+ resource = kunit_find_named_resource(kunit_get_current_test(), "slab_errors");
if (!resource)
return false;

--
2.38.0.135.g90850a2211-goog



2022-10-25 09:15:13

by Vlastimil Babka

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] mm: slub: test: Use the kunit_get_current_test() function

On 10/25/22 09:19, David Gow wrote:
> Use the newly-added function kunit_get_current_test() instead of
> accessing current->kunit_test directly. This function uses a static key
> to return more quickly when KUnit is enabled, but no tests are actively
> running. There should therefore be a negligible performance impact to
> enabling the slub KUnit tests.
>
> Other than the performance improvement, this should be a no-op.
>
> Cc: Oliver Glitta <[email protected]>
> Cc: Hyeonggon Yoo <[email protected]>
> Cc: Christoph Lameter <[email protected]>
> Cc: Vlastimil Babka <[email protected]>
> Cc: David Rientjes <[email protected]>
> Cc: Andrew Morton <[email protected]>
> Signed-off-by: David Gow <[email protected]>

Acked-by: Vlastimil Babka <[email protected]>

> ---
>
> This is intended as an example use of the new function. Other users
> (such as KASAN) will be updated separately, as there would otherwise be
> conflicts.
>
> Assuming there are no objections, we'll take this whole series via the
> kselftest/kunit tree.

OK, please do.

Some possible improvements below:

> There was no v1 of this patch. v1 of the series can be found here:
> https://lore.kernel.org/linux-kselftest/[email protected]/T/#u
>
> ---
> lib/slub_kunit.c | 1 +
> mm/slub.c | 5 +++--
> 2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/lib/slub_kunit.c b/lib/slub_kunit.c
> index 7a0564d7cb7a..8fd19c8301ad 100644
> --- a/lib/slub_kunit.c
> +++ b/lib/slub_kunit.c
> @@ -1,5 +1,6 @@
> // SPDX-License-Identifier: GPL-2.0
> #include <kunit/test.h>
> +#include <kunit/test-bug.h>
> #include <linux/mm.h>
> #include <linux/slab.h>
> #include <linux/module.h>
> diff --git a/mm/slub.c b/mm/slub.c
> index 157527d7101b..15d10d250ef2 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -39,6 +39,7 @@
> #include <linux/memcontrol.h>
> #include <linux/random.h>
> #include <kunit/test.h>
> +#include <kunit/test-bug.h>
> #include <linux/sort.h>
>
> #include <linux/debugfs.h>
> @@ -603,10 +604,10 @@ static bool slab_add_kunit_errors(void)
> {
> struct kunit_resource *resource;
>
> - if (likely(!current->kunit_test))
> + if (likely(!kunit_get_current_test()))

Given that kunit_get_current_test() is basically an inline
!static_branch_unlikely(), IMHO the likely() here doesn't add anything and
could be removed?

> return false;
>
> - resource = kunit_find_named_resource(current->kunit_test, "slab_errors");
> + resource = kunit_find_named_resource(kunit_get_current_test(), "slab_errors");

We just passed kunit_get_current_test() above so maybe we could just keep
using current->kunit_test here? Seems unnecessary adding another jump label.

> if (!resource)
> return false;
>


2022-10-25 15:56:55

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] mm: slub: test: Use the kunit_get_current_test() function

Hi David,

I love your patch! Yet something to improve:

[auto build test ERROR on vbabka-slab/for-next]
[also build test ERROR on kees/for-next/pstore linus/master v6.1-rc2 next-20221025]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/David-Gow/kunit-Provide-a-static-key-to-check-if-KUnit-is-actively-running-tests/20221025-152023
base: git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab.git for-next
patch link: https://lore.kernel.org/r/20221025071907.1251820-3-davidgow%40google.com
patch subject: [PATCH v2 3/3] mm: slub: test: Use the kunit_get_current_test() function
config: s390-defconfig (attached as .config)
compiler: s390-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/048f50673812037a89a222fd04beaeaa59a2c2bb
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review David-Gow/kunit-Provide-a-static-key-to-check-if-KUnit-is-actively-running-tests/20221025-152023
git checkout 048f50673812037a89a222fd04beaeaa59a2c2bb
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=s390 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

>> s390-linux-ld: mm/slub.o:(__jump_table+0xc8): undefined reference to `kunit_running'
s390-linux-ld: mm/slub.o: `kunit_running' non-PLT reloc for symbol defined in shared library and accessed from executable (rebuild file with -fPIC ?)
s390-linux-ld: final link failed: bad value
pahole: .tmp_vmlinux.btf: No such file or directory
.btf.vmlinux.bin.o: file not recognized: file format not recognized

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (2.24 kB)
.config.gz (20.95 kB)
Download all attachments

2022-10-25 22:44:21

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] mm: slub: test: Use the kunit_get_current_test() function

Hi David,

I love your patch! Yet something to improve:

[auto build test ERROR on vbabka-slab/for-next]
[also build test ERROR on kees/for-next/pstore linus/master v6.1-rc2 next-20221025]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/David-Gow/kunit-Provide-a-static-key-to-check-if-KUnit-is-actively-running-tests/20221025-152023
base: git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab.git for-next
patch link: https://lore.kernel.org/r/20221025071907.1251820-3-davidgow%40google.com
patch subject: [PATCH v2 3/3] mm: slub: test: Use the kunit_get_current_test() function
config: m68k-allmodconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/048f50673812037a89a222fd04beaeaa59a2c2bb
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review David-Gow/kunit-Provide-a-static-key-to-check-if-KUnit-is-actively-running-tests/20221025-152023
git checkout 048f50673812037a89a222fd04beaeaa59a2c2bb
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

m68k-linux-ld: mm/slub.o: in function `slab_add_kunit_errors':
>> slub.c:(.text+0x1262): undefined reference to `kunit_running'

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (1.97 kB)
.config.gz (64.35 kB)
Download all attachments