* [PATCH v2 1/2] selftests: harness: remove unneeded __constructor_order_last()
2024-07-27 14:37 [PATCH v2 0/2] selftests: harness: refactor __constructor_order Masahiro Yamada
@ 2024-07-27 14:37 ` Masahiro Yamada
2024-08-06 4:27 ` [PATCH v2 0/2] selftests: harness: refactor __constructor_order Kees Cook
1 sibling, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2024-07-27 14:37 UTC (permalink / raw)
To: Kees Cook, Andy Lutomirski, Will Drewry
Cc: linux-kernel, Masahiro Yamada, Alexandre Belloni,
Benjamin Tissoires, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Janosch Frank, Jiri Kosina, Shuah Khan, bpf,
kvm, linux-input, linux-kselftest, linux-rtc
__constructor_order_last() is unneeded.
If __constructor_order_last() is not called on backward-order systems,
__constructor_order will remain 0 instead of being set to
_CONSTRUCTOR_ORDER_BACKWARD (= -1).
__LIST_APPEND() will still take the 'else' branch, so there is no
difference in the behavior.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
Changes in v2:
- reword "reverse-order" to "backward-order" in commit description
.../selftests/drivers/s390x/uvdevice/test_uvdevice.c | 6 ------
tools/testing/selftests/hid/hid_bpf.c | 6 ------
tools/testing/selftests/kselftest_harness.h | 10 +---------
tools/testing/selftests/rtc/rtctest.c | 7 -------
4 files changed, 1 insertion(+), 28 deletions(-)
diff --git a/tools/testing/selftests/drivers/s390x/uvdevice/test_uvdevice.c b/tools/testing/selftests/drivers/s390x/uvdevice/test_uvdevice.c
index ea0cdc37b44f..7ee7492138c6 100644
--- a/tools/testing/selftests/drivers/s390x/uvdevice/test_uvdevice.c
+++ b/tools/testing/selftests/drivers/s390x/uvdevice/test_uvdevice.c
@@ -257,12 +257,6 @@ TEST_F(attest_fixture, att_inval_addr)
att_inval_addr_test(&self->uvio_attest.meas_addr, _metadata, self);
}
-static void __attribute__((constructor)) __constructor_order_last(void)
-{
- if (!__constructor_order)
- __constructor_order = _CONSTRUCTOR_ORDER_BACKWARD;
-}
-
int main(int argc, char **argv)
{
int fd = open(UV_PATH, O_ACCMODE);
diff --git a/tools/testing/selftests/hid/hid_bpf.c b/tools/testing/selftests/hid/hid_bpf.c
index dc0408a831d0..f2bd20ca88bb 100644
--- a/tools/testing/selftests/hid/hid_bpf.c
+++ b/tools/testing/selftests/hid/hid_bpf.c
@@ -1331,12 +1331,6 @@ static int libbpf_print_fn(enum libbpf_print_level level,
return 0;
}
-static void __attribute__((constructor)) __constructor_order_last(void)
-{
- if (!__constructor_order)
- __constructor_order = _CONSTRUCTOR_ORDER_BACKWARD;
-}
-
int main(int argc, char **argv)
{
/* Use libbpf 1.0 API mode */
diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 40723a6a083f..71648d2102cb 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -488,12 +488,6 @@
* Use once to append a main() to the test file.
*/
#define TEST_HARNESS_MAIN \
- static void __attribute__((constructor)) \
- __constructor_order_last(void) \
- { \
- if (!__constructor_order) \
- __constructor_order = _CONSTRUCTOR_ORDER_BACKWARD; \
- } \
int main(int argc, char **argv) { \
return test_harness_run(argc, argv); \
}
@@ -891,7 +885,6 @@ static struct __fixture_metadata *__fixture_list = &_fixture_global;
static int __constructor_order;
#define _CONSTRUCTOR_ORDER_FORWARD 1
-#define _CONSTRUCTOR_ORDER_BACKWARD -1
static inline void __register_fixture(struct __fixture_metadata *f)
{
@@ -1337,8 +1330,7 @@ static int test_harness_run(int argc, char **argv)
static void __attribute__((constructor)) __constructor_order_first(void)
{
- if (!__constructor_order)
- __constructor_order = _CONSTRUCTOR_ORDER_FORWARD;
+ __constructor_order = _CONSTRUCTOR_ORDER_FORWARD;
}
#endif /* __KSELFTEST_HARNESS_H */
diff --git a/tools/testing/selftests/rtc/rtctest.c b/tools/testing/selftests/rtc/rtctest.c
index 63ce02d1d5cc..9647b14b47c5 100644
--- a/tools/testing/selftests/rtc/rtctest.c
+++ b/tools/testing/selftests/rtc/rtctest.c
@@ -410,13 +410,6 @@ TEST_F_TIMEOUT(rtc, alarm_wkalm_set_minute, 65) {
ASSERT_EQ(new, secs);
}
-static void __attribute__((constructor))
-__constructor_order_last(void)
-{
- if (!__constructor_order)
- __constructor_order = _CONSTRUCTOR_ORDER_BACKWARD;
-}
-
int main(int argc, char **argv)
{
switch (argc) {
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2 0/2] selftests: harness: refactor __constructor_order
2024-07-27 14:37 [PATCH v2 0/2] selftests: harness: refactor __constructor_order Masahiro Yamada
2024-07-27 14:37 ` [PATCH v2 1/2] selftests: harness: remove unneeded __constructor_order_last() Masahiro Yamada
@ 2024-08-06 4:27 ` Kees Cook
2024-08-06 19:36 ` Shuah Khan
1 sibling, 1 reply; 4+ messages in thread
From: Kees Cook @ 2024-08-06 4:27 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Andy Lutomirski, Will Drewry, linux-kernel, Alexandre Belloni,
Benjamin Tissoires, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Janosch Frank, Jiri Kosina, Shuah Khan, bpf,
kvm, linux-input, linux-kselftest, linux-rtc
On Sat, Jul 27, 2024 at 11:37:35PM +0900, Masahiro Yamada wrote:
>
> This series refactors __constructor_order because
> __constructor_order_last() is unneeded.
>
> No code change since v1.
> I reworded "reverse-order" to "backward-order" in commit description.
>
>
> Masahiro Yamada (2):
> selftests: harness: remove unneeded __constructor_order_last()
> selftests: harness: rename __constructor_order for clarification
Thanks for resending this!
Reviewed-by: Kees Cook <kees@kernel.org>
Shuah, do you want to take this via kselftest? If not, I can carry it...
-Kees
--
Kees Cook
^ permalink raw reply [flat|nested] 4+ messages in thread