diff mbox series

[2/2] kunit: no longer call module_info(test, "Y") for kunit modules

Message ID 20220817164851.3574140-3-joefradley@google.com (mailing list archive)
State Accepted
Commit 7d97635b72813d80f909ad24d7a64b2fe9a29c0b
Delegated to: Brendan Higgins
Headers show
Series kunit: add boot time parameter to enable KUnit | expand

Commit Message

Joe Fradley Aug. 17, 2022, 4:48 p.m. UTC
Because KUnit test execution is not a guarantee with the kunit.enable
parameter we want to be careful to only taint the kernel only if an
actual test runs. Calling module_info(test, "Y") for every KUnit module
automatically causes the kernel to be tainted upon module load. Therefore,
we're removing this call and relying on the KUnit framework to taint the
kernel or not.

Signed-off-by: Joe Fradley <joefradley@google.com>
---
 include/kunit/test.h | 1 -
 1 file changed, 1 deletion(-)

Comments

David Gow Aug. 19, 2022, 8:34 a.m. UTC | #1
On Thu, Aug 18, 2022 at 12:49 AM Joe Fradley <joefradley@google.com> wrote:
>
> Because KUnit test execution is not a guarantee with the kunit.enable
> parameter we want to be careful to only taint the kernel only if an
> actual test runs. Calling module_info(test, "Y") for every KUnit module
> automatically causes the kernel to be tainted upon module load. Therefore,
> we're removing this call and relying on the KUnit framework to taint the
> kernel or not.
>
> Signed-off-by: Joe Fradley <joefradley@google.com>
> ---

Thanks!

This definitely fixes an assumption I'd had about KUnit-usage which
definitely doesn't hold: that all KUnit tests would be in their own
modules (or at least that those modules wouldn't need to be loaded on
otherwise production systems). Given this isn't the case for a number
of modules (thuderbolt, apparmor, probably soon amdgpu), it makles
sense to get rid of this and only taint the kernel when the test is
actually run, not just when it's loaded.

This could be considered a fix for c272612cb4a2 ("kunit: Taint the
kernel when KUnit tests are run"), as it'd already be possible to
load, e.g., thunderbolt, but prevent the tests from executing with a
filter glob which doesn't match any tests. That possibly shouldn't
taint the kernel.

Reviewed-by: David Gow <davidgow@google.com>
Fixes: c272612cb4a2 ("kunit: Taint the kernel when KUnit tests are run")

Cheers,
-- David

>  include/kunit/test.h | 1 -
>  1 file changed, 1 deletion(-)
>
> diff --git a/include/kunit/test.h b/include/kunit/test.h
> index c958855681cc..f23d3954aa17 100644
> --- a/include/kunit/test.h
> +++ b/include/kunit/test.h
> @@ -251,7 +251,6 @@ static inline int kunit_run_all_tests(void)
>  #endif /* IS_BUILTIN(CONFIG_KUNIT) */
>
>  #define __kunit_test_suites(unique_array, ...)                                \
> -       MODULE_INFO(test, "Y");                                                \
>         static struct kunit_suite *unique_array[]                              \
>         __aligned(sizeof(struct kunit_suite *))                                \
>         __used __section(".kunit_test_suites") = { __VA_ARGS__ }
> --
> 2.37.1.595.g718a3a8f04-goog
>
Joe Fradley Aug. 22, 2022, 8:47 p.m. UTC | #2
On Fri, Aug 19, 2022 at 1:34 AM David Gow <davidgow@google.com> wrote:
>
> On Thu, Aug 18, 2022 at 12:49 AM Joe Fradley <joefradley@google.com> wrote:
> >
> > Because KUnit test execution is not a guarantee with the kunit.enable
> > parameter we want to be careful to only taint the kernel only if an
> > actual test runs. Calling module_info(test, "Y") for every KUnit module
> > automatically causes the kernel to be tainted upon module load. Therefore,
> > we're removing this call and relying on the KUnit framework to taint the
> > kernel or not.
> >
> > Signed-off-by: Joe Fradley <joefradley@google.com>
> > ---
>
> Thanks!
>
> This definitely fixes an assumption I'd had about KUnit-usage which
> definitely doesn't hold: that all KUnit tests would be in their own
> modules (or at least that those modules wouldn't need to be loaded on
> otherwise production systems). Given this isn't the case for a number
> of modules (thuderbolt, apparmor, probably soon amdgpu), it makles
> sense to get rid of this and only taint the kernel when the test is
> actually run, not just when it's loaded.
>
> This could be considered a fix for c272612cb4a2 ("kunit: Taint the
> kernel when KUnit tests are run"), as it'd already be possible to
> load, e.g., thunderbolt, but prevent the tests from executing with a
> filter glob which doesn't match any tests. That possibly shouldn't
> taint the kernel.

Great, thank you for the review.

>
> Reviewed-by: David Gow <davidgow@google.com>
> Fixes: c272612cb4a2 ("kunit: Taint the kernel when KUnit tests are run")
>
> Cheers,
> -- David
>
> >  include/kunit/test.h | 1 -
> >  1 file changed, 1 deletion(-)
> >
> > diff --git a/include/kunit/test.h b/include/kunit/test.h
> > index c958855681cc..f23d3954aa17 100644
> > --- a/include/kunit/test.h
> > +++ b/include/kunit/test.h
> > @@ -251,7 +251,6 @@ static inline int kunit_run_all_tests(void)
> >  #endif /* IS_BUILTIN(CONFIG_KUNIT) */
> >
> >  #define __kunit_test_suites(unique_array, ...)                                \
> > -       MODULE_INFO(test, "Y");                                                \
> >         static struct kunit_suite *unique_array[]                              \
> >         __aligned(sizeof(struct kunit_suite *))                                \
> >         __used __section(".kunit_test_suites") = { __VA_ARGS__ }
> > --
> > 2.37.1.595.g718a3a8f04-goog
> >
Brendan Higgins Aug. 22, 2022, 8:57 p.m. UTC | #3
On Wed, Aug 17, 2022 at 12:49 PM 'Joe Fradley' via KUnit Development
<kunit-dev@googlegroups.com> wrote:
>
> Because KUnit test execution is not a guarantee with the kunit.enable
> parameter we want to be careful to only taint the kernel only if an
> actual test runs. Calling module_info(test, "Y") for every KUnit module
> automatically causes the kernel to be tainted upon module load. Therefore,
> we're removing this call and relying on the KUnit framework to taint the
> kernel or not.
>
> Signed-off-by: Joe Fradley <joefradley@google.com>

Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
diff mbox series

Patch

diff --git a/include/kunit/test.h b/include/kunit/test.h
index c958855681cc..f23d3954aa17 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -251,7 +251,6 @@  static inline int kunit_run_all_tests(void)
 #endif /* IS_BUILTIN(CONFIG_KUNIT) */
 
 #define __kunit_test_suites(unique_array, ...)				       \
-	MODULE_INFO(test, "Y");						       \
 	static struct kunit_suite *unique_array[]			       \
 	__aligned(sizeof(struct kunit_suite *))				       \
 	__used __section(".kunit_test_suites") = { __VA_ARGS__ }