public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v2] Add case about arch_prctl syscall.
@ 2024-04-19  7:07 lufei
  2024-04-19 15:46 ` Cyril Hrubis
                   ` (4 more replies)
  0 siblings, 5 replies; 21+ messages in thread
From: lufei @ 2024-04-19  7:07 UTC (permalink / raw)
  To: ltp; +Cc: lufei

Add testcase about arch_prctl syscall.

Signed-off-by: Lu Fei <lufei@uniontech.com>
---
 configure.ac                                  |  1 +
 .../kernel/syscalls/arch_prctl/.gitignore     |  1 +
 testcases/kernel/syscalls/arch_prctl/Makefile |  8 +++
 .../kernel/syscalls/arch_prctl/arch_prctl01.c | 56 +++++++++++++++++++
 4 files changed, 66 insertions(+)
 create mode 100644 testcases/kernel/syscalls/arch_prctl/.gitignore
 create mode 100644 testcases/kernel/syscalls/arch_prctl/Makefile
 create mode 100644 testcases/kernel/syscalls/arch_prctl/arch_prctl01.c

diff --git a/configure.ac b/configure.ac
index 1d7e862d8..0dcaddc0f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,7 @@ AC_CHECK_DECLS([SEM_STAT_ANY],,,[#include <sys/sem.h>])
 
 AC_CHECK_HEADERS_ONCE([ \
     asm/ldt.h \
+    asm/prctl.h \
     cpuid.h \
     emmintrin.h \
     ifaddrs.h \
diff --git a/testcases/kernel/syscalls/arch_prctl/.gitignore b/testcases/kernel/syscalls/arch_prctl/.gitignore
new file mode 100644
index 000000000..24871e249
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/.gitignore
@@ -0,0 +1 @@
+/arch_prctl01
diff --git a/testcases/kernel/syscalls/arch_prctl/Makefile b/testcases/kernel/syscalls/arch_prctl/Makefile
new file mode 100644
index 000000000..272949d57
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) UnionTech Software Technology Co.,Ltd. 2024
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
new file mode 100644
index 000000000..06b3d99b8
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* 
+ * Copyright (c) UnionTech Software Technology Co.,Ltd., 2024
+ * Author: Lu Fei <lufei@uniontech.com>
+ */
+
+/* 
+ * [Description]
+ *
+ * Simple test on arch_prctl to set and get cpuid instruction of test thread.
+ */
+
+# include "tst_test.h"
+# include "lapi/syscalls.h"
+# include <stdlib.h>
+# ifdef HAVE_ASM_PRCTL_H
+# include <asm/prctl.h>
+
+static int arch_prctl_get(int code, unsigned long *addr) {
+	return tst_syscall(__NR_arch_prctl, code, *addr);
+}
+
+static int arch_prctl_set(int code, unsigned long addr) {
+	return tst_syscall(__NR_arch_prctl, code, addr);
+}
+
+static int tc[] = {0,1};
+
+static void run(unsigned int index){
+
+	unsigned long *addr = malloc(sizeof(long));
+
+	TEST(arch_prctl_set(ARCH_SET_CPUID, tc[index]));
+
+	if (TST_RET == 0)
+		tst_res(TPASS, "set %s cpuid",tc[index] ? "enable" : "disable");
+	else
+		tst_res(TFAIL, "failed to set cpuid");
+
+	TEST(arch_prctl_get(ARCH_GET_CPUID, addr));
+
+	if (TST_RET == tc[index])
+		tst_res(TPASS, "get cpuid succeed.");
+	else
+		tst_res(TFAIL, "get cpuid failed.");
+}
+
+static struct tst_test test = {
+    .test = run,
+    .tcnt = 2,
+    .min_kver = "4.11",
+};
+
+#else /* HAVE_ASM_PRCTL_H */
+TST_TEST_TCONF("missing <asm/prctl.h>");
+#endif
-- 
2.39.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [LTP] [PATCH v2] Add case about arch_prctl syscall.
  2024-04-19  7:07 [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
@ 2024-04-19 15:46 ` Cyril Hrubis
  2024-04-21  6:25 ` lufei
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 21+ messages in thread
From: Cyril Hrubis @ 2024-04-19 15:46 UTC (permalink / raw)
  To: lufei; +Cc: ltp

Hi!
First of all do 'make check' in the directory with the test source and
fix all errors and warnings.

> Signed-off-by: Lu Fei <lufei@uniontech.com>
> ---
>  configure.ac                                  |  1 +
>  .../kernel/syscalls/arch_prctl/.gitignore     |  1 +
>  testcases/kernel/syscalls/arch_prctl/Makefile |  8 +++
>  .../kernel/syscalls/arch_prctl/arch_prctl01.c | 56 +++++++++++++++++++

This is missing a runtest entry, i.e. line in the runtest/syscalls file
that tells the test execution framework to run the test.

>  4 files changed, 66 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/arch_prctl/.gitignore
>  create mode 100644 testcases/kernel/syscalls/arch_prctl/Makefile
>  create mode 100644 testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
> 
> diff --git a/configure.ac b/configure.ac
> index 1d7e862d8..0dcaddc0f 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -41,6 +41,7 @@ AC_CHECK_DECLS([SEM_STAT_ANY],,,[#include <sys/sem.h>])
>  
>  AC_CHECK_HEADERS_ONCE([ \
>      asm/ldt.h \
> +    asm/prctl.h \
>      cpuid.h \
>      emmintrin.h \
>      ifaddrs.h \
> diff --git a/testcases/kernel/syscalls/arch_prctl/.gitignore b/testcases/kernel/syscalls/arch_prctl/.gitignore
> new file mode 100644
> index 000000000..24871e249
> --- /dev/null
> +++ b/testcases/kernel/syscalls/arch_prctl/.gitignore
> @@ -0,0 +1 @@
> +/arch_prctl01
> diff --git a/testcases/kernel/syscalls/arch_prctl/Makefile b/testcases/kernel/syscalls/arch_prctl/Makefile
> new file mode 100644
> index 000000000..272949d57
> --- /dev/null
> +++ b/testcases/kernel/syscalls/arch_prctl/Makefile
> @@ -0,0 +1,8 @@
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) UnionTech Software Technology Co.,Ltd. 2024
> +
> +top_srcdir		?= ../../../..
> +
> +include $(top_srcdir)/include/mk/testcases.mk
> +
> +include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
> new file mode 100644
> index 000000000..06b3d99b8
> --- /dev/null
> +++ b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
> @@ -0,0 +1,56 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/* 
> + * Copyright (c) UnionTech Software Technology Co.,Ltd., 2024
> + * Author: Lu Fei <lufei@uniontech.com>
> + */
> +
> +/* 

This has to be /*\ so that the docparse comment gets picked up by the
documentation parser and shows up in docparse/metadata.html

> + * [Description]
> + *
> + * Simple test on arch_prctl to set and get cpuid instruction of test thread.
> + */
> +
> +# include "tst_test.h"
> +# include "lapi/syscalls.h"
> +# include <stdlib.h>
> +# ifdef HAVE_ASM_PRCTL_H
> +# include <asm/prctl.h>

No spaces after # here please.

> +static int arch_prctl_get(int code, unsigned long *addr) {
> +	return tst_syscall(__NR_arch_prctl, code, *addr);
> +}
> +
> +static int arch_prctl_set(int code, unsigned long addr) {
> +	return tst_syscall(__NR_arch_prctl, code, addr);
> +}
> +
> +static int tc[] = {0,1};
> +
> +static void run(unsigned int index){
> +
> +	unsigned long *addr = malloc(sizeof(long));

This does not need to be allocated, we can just do unsigned long addr
and pass &addr to the calls.

> +	TEST(arch_prctl_set(ARCH_SET_CPUID, tc[index]));
> +
> +	if (TST_RET == 0)
> +		tst_res(TPASS, "set %s cpuid",tc[index] ? "enable" : "disable");
> +	else
> +		tst_res(TFAIL, "failed to set cpuid");

This should use TST_EXP_PASS(arch_prctl_set(...))

> +	TEST(arch_prctl_get(ARCH_GET_CPUID, addr));

This as well.

> +	if (TST_RET == tc[index])

This is wrong, the value should be stored the addr parameter, TST_RET
should be 0 on success.


> +		tst_res(TPASS, "get cpuid succeed.");
> +	else
> +		tst_res(TFAIL, "get cpuid failed.");
> +}
> +
> +static struct tst_test test = {
> +    .test = run,
> +    .tcnt = 2,
> +    .min_kver = "4.11",

This should have .supported_archs = {"x86", "x86-64", NULL},

> +};
> +
> +#else /* HAVE_ASM_PRCTL_H */
> +TST_TEST_TCONF("missing <asm/prctl.h>");
> +#endif
> -- 
> 2.39.3
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [LTP] [PATCH v2] Add case about arch_prctl syscall.
  2024-04-19  7:07 [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
  2024-04-19 15:46 ` Cyril Hrubis
@ 2024-04-21  6:25 ` lufei
  2024-04-21  7:15 ` [LTP] (no subject) lufei
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 21+ messages in thread
From: lufei @ 2024-04-21  6:25 UTC (permalink / raw)
  To: chrubis, ltp; +Cc: lufei

Add testcase about arch_prctl syscall.

Signed-off-by: Lu Fei <lufei@uniontech.com>
---
 configure.ac                                  |  1 +
 runtest/syscalls                              |  2 +
 .../kernel/syscalls/arch_prctl/.gitignore     |  1 +
 testcases/kernel/syscalls/arch_prctl/Makefile |  8 +++
 .../kernel/syscalls/arch_prctl/arch_prctl01.c | 52 +++++++++++++++++++
 5 files changed, 64 insertions(+)
 create mode 100644 testcases/kernel/syscalls/arch_prctl/.gitignore
 create mode 100644 testcases/kernel/syscalls/arch_prctl/Makefile
 create mode 100644 testcases/kernel/syscalls/arch_prctl/arch_prctl01.c

diff --git a/configure.ac b/configure.ac
index 1d7e862d8..0dcaddc0f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,7 @@ AC_CHECK_DECLS([SEM_STAT_ANY],,,[#include <sys/sem.h>])
 
 AC_CHECK_HEADERS_ONCE([ \
     asm/ldt.h \
+    asm/prctl.h \
     cpuid.h \
     emmintrin.h \
     ifaddrs.h \
diff --git a/runtest/syscalls b/runtest/syscalls
index 7794f1465..505b4243d 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -31,6 +31,8 @@ alarm05 alarm05
 alarm06 alarm06
 alarm07 alarm07
 
+arch_prctl01 arch_prctl01
+
 bind01 bind01
 bind02 bind02
 bind03 bind03
diff --git a/testcases/kernel/syscalls/arch_prctl/.gitignore b/testcases/kernel/syscalls/arch_prctl/.gitignore
new file mode 100644
index 000000000..24871e249
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/.gitignore
@@ -0,0 +1 @@
+/arch_prctl01
diff --git a/testcases/kernel/syscalls/arch_prctl/Makefile b/testcases/kernel/syscalls/arch_prctl/Makefile
new file mode 100644
index 000000000..272949d57
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) UnionTech Software Technology Co.,Ltd. 2024
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
new file mode 100644
index 000000000..a3d3b35d5
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) UnionTech Software Technology Co.,Ltd., 2024
+ * Author: Lu Fei <lufei@uniontech.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Simple test on arch_prctl to set and get cpuid instruction of test thread.
+ */
+
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include <stdlib.h>
+#ifdef HAVE_ASM_PRCTL_H
+#include <asm/prctl.h>
+
+static int arch_prctl_get(int code, unsigned long *addr)
+{
+	return tst_syscall(__NR_arch_prctl, code, *addr);
+}
+
+static int arch_prctl_set(int code, unsigned long addr)
+{
+	return tst_syscall(__NR_arch_prctl, code, addr);
+}
+
+static void run(unsigned int index)
+{
+	unsigned long *addr = malloc(sizeof(long));
+
+	// index == 0 for disable cpuid, 1 for enable cpuid.
+	TST_EXP_PASS(arch_prctl_set(ARCH_SET_CPUID, index));
+
+	TEST(arch_prctl_get(ARCH_GET_CPUID, addr));
+
+	if (TST_RET == index)
+		tst_res(TPASS, "get cpuid succeed.");
+	else
+		tst_res(TFAIL, "get cpuid failed.");
+}
+
+static struct tst_test test = {
+	.test = run,
+	.tcnt = 2,
+	.min_kver = "4.12",
+};
+
+#else /* HAVE_ASM_PRCTL_H */
+TST_TEST_TCONF("missing <asm/prctl.h>");
+#endif
-- 
2.39.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [LTP] (no subject)
  2024-04-19  7:07 [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
  2024-04-19 15:46 ` Cyril Hrubis
  2024-04-21  6:25 ` lufei
@ 2024-04-21  7:15 ` lufei
  2024-04-21  7:15   ` [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
  2024-04-26  8:36   ` [LTP] (no subject) Cyril Hrubis
  2024-04-23  1:05 ` [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
  2024-04-28  7:44 ` [LTP] (no subject) lufei
  4 siblings, 2 replies; 21+ messages in thread
From: lufei @ 2024-04-21  7:15 UTC (permalink / raw)
  To: chrubis, ltp


Hi Cyril.
Thanks for you quickly response.

Some of your point has been fixed. Some are not:
1. I'm using gcc (GCC) 11.4.1 20230605, `addr` without initialization would output some warnings.
2. I read the manpage of arch_prctl, the ARCH_GET_CPUID seems return the flag, instead of storing `addr`:
```
ARCH_GET_CPUID (since Linux 4.12)
              Return the setting of the flag manipulated by ARCH_SET_CPUID as the result of the system call (1  for  enabled,  0  for
              disabled).  addr is ignored.
```
I'm not sure if this is a problem of my environment. 


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [LTP] [PATCH v2] Add case about arch_prctl syscall.
  2024-04-21  7:15 ` [LTP] (no subject) lufei
@ 2024-04-21  7:15   ` lufei
  2024-04-26  8:36   ` [LTP] (no subject) Cyril Hrubis
  1 sibling, 0 replies; 21+ messages in thread
From: lufei @ 2024-04-21  7:15 UTC (permalink / raw)
  To: chrubis, ltp; +Cc: lufei

Add testcase about arch_prctl syscall.

Signed-off-by: Lu Fei <lufei@uniontech.com>
---
 configure.ac                                  |  1 +
 runtest/syscalls                              |  2 +
 .../kernel/syscalls/arch_prctl/.gitignore     |  1 +
 testcases/kernel/syscalls/arch_prctl/Makefile |  8 +++
 .../kernel/syscalls/arch_prctl/arch_prctl01.c | 52 +++++++++++++++++++
 5 files changed, 64 insertions(+)
 create mode 100644 testcases/kernel/syscalls/arch_prctl/.gitignore
 create mode 100644 testcases/kernel/syscalls/arch_prctl/Makefile
 create mode 100644 testcases/kernel/syscalls/arch_prctl/arch_prctl01.c

diff --git a/configure.ac b/configure.ac
index 1d7e862d8..0dcaddc0f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,7 @@ AC_CHECK_DECLS([SEM_STAT_ANY],,,[#include <sys/sem.h>])
 
 AC_CHECK_HEADERS_ONCE([ \
     asm/ldt.h \
+    asm/prctl.h \
     cpuid.h \
     emmintrin.h \
     ifaddrs.h \
diff --git a/runtest/syscalls b/runtest/syscalls
index 7794f1465..505b4243d 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -31,6 +31,8 @@ alarm05 alarm05
 alarm06 alarm06
 alarm07 alarm07
 
+arch_prctl01 arch_prctl01
+
 bind01 bind01
 bind02 bind02
 bind03 bind03
diff --git a/testcases/kernel/syscalls/arch_prctl/.gitignore b/testcases/kernel/syscalls/arch_prctl/.gitignore
new file mode 100644
index 000000000..24871e249
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/.gitignore
@@ -0,0 +1 @@
+/arch_prctl01
diff --git a/testcases/kernel/syscalls/arch_prctl/Makefile b/testcases/kernel/syscalls/arch_prctl/Makefile
new file mode 100644
index 000000000..272949d57
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) UnionTech Software Technology Co.,Ltd. 2024
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
new file mode 100644
index 000000000..a3d3b35d5
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) UnionTech Software Technology Co.,Ltd., 2024
+ * Author: Lu Fei <lufei@uniontech.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Simple test on arch_prctl to set and get cpuid instruction of test thread.
+ */
+
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include <stdlib.h>
+#ifdef HAVE_ASM_PRCTL_H
+#include <asm/prctl.h>
+
+static int arch_prctl_get(int code, unsigned long *addr)
+{
+	return tst_syscall(__NR_arch_prctl, code, *addr);
+}
+
+static int arch_prctl_set(int code, unsigned long addr)
+{
+	return tst_syscall(__NR_arch_prctl, code, addr);
+}
+
+static void run(unsigned int index)
+{
+	unsigned long *addr = malloc(sizeof(long));
+
+	// index == 0 for disable cpuid, 1 for enable cpuid.
+	TST_EXP_PASS(arch_prctl_set(ARCH_SET_CPUID, index));
+
+	TEST(arch_prctl_get(ARCH_GET_CPUID, addr));
+
+	if (TST_RET == index)
+		tst_res(TPASS, "get cpuid succeed.");
+	else
+		tst_res(TFAIL, "get cpuid failed.");
+}
+
+static struct tst_test test = {
+	.test = run,
+	.tcnt = 2,
+	.min_kver = "4.12",
+};
+
+#else /* HAVE_ASM_PRCTL_H */
+TST_TEST_TCONF("missing <asm/prctl.h>");
+#endif
-- 
2.39.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [LTP] [PATCH v2] Add case about arch_prctl syscall.
  2024-04-19  7:07 [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
                   ` (2 preceding siblings ...)
  2024-04-21  7:15 ` [LTP] (no subject) lufei
@ 2024-04-23  1:05 ` lufei
  2024-04-28  7:44 ` [LTP] (no subject) lufei
  4 siblings, 0 replies; 21+ messages in thread
From: lufei @ 2024-04-23  1:05 UTC (permalink / raw)
  To: ltp; +Cc: lufei

Add testcase about arch_prctl syscall.

Signed-off-by: Lu Fei <lufei@uniontech.com>
---
 configure.ac                                  |  1 +
 runtest/syscalls                              |  2 +
 .../kernel/syscalls/arch_prctl/.gitignore     |  1 +
 testcases/kernel/syscalls/arch_prctl/Makefile |  8 +++
 .../kernel/syscalls/arch_prctl/arch_prctl01.c | 52 +++++++++++++++++++
 5 files changed, 64 insertions(+)
 create mode 100644 testcases/kernel/syscalls/arch_prctl/.gitignore
 create mode 100644 testcases/kernel/syscalls/arch_prctl/Makefile
 create mode 100644 testcases/kernel/syscalls/arch_prctl/arch_prctl01.c

diff --git a/configure.ac b/configure.ac
index 1d7e862d8..0dcaddc0f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,7 @@ AC_CHECK_DECLS([SEM_STAT_ANY],,,[#include <sys/sem.h>])
 
 AC_CHECK_HEADERS_ONCE([ \
     asm/ldt.h \
+    asm/prctl.h \
     cpuid.h \
     emmintrin.h \
     ifaddrs.h \
diff --git a/runtest/syscalls b/runtest/syscalls
index 7794f1465..505b4243d 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -31,6 +31,8 @@ alarm05 alarm05
 alarm06 alarm06
 alarm07 alarm07
 
+arch_prctl01 arch_prctl01
+
 bind01 bind01
 bind02 bind02
 bind03 bind03
diff --git a/testcases/kernel/syscalls/arch_prctl/.gitignore b/testcases/kernel/syscalls/arch_prctl/.gitignore
new file mode 100644
index 000000000..24871e249
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/.gitignore
@@ -0,0 +1 @@
+/arch_prctl01
diff --git a/testcases/kernel/syscalls/arch_prctl/Makefile b/testcases/kernel/syscalls/arch_prctl/Makefile
new file mode 100644
index 000000000..272949d57
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) UnionTech Software Technology Co.,Ltd. 2024
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
new file mode 100644
index 000000000..a3d3b35d5
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) UnionTech Software Technology Co.,Ltd., 2024
+ * Author: Lu Fei <lufei@uniontech.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Simple test on arch_prctl to set and get cpuid instruction of test thread.
+ */
+
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include <stdlib.h>
+#ifdef HAVE_ASM_PRCTL_H
+#include <asm/prctl.h>
+
+static int arch_prctl_get(int code, unsigned long *addr)
+{
+	return tst_syscall(__NR_arch_prctl, code, *addr);
+}
+
+static int arch_prctl_set(int code, unsigned long addr)
+{
+	return tst_syscall(__NR_arch_prctl, code, addr);
+}
+
+static void run(unsigned int index)
+{
+	unsigned long *addr = malloc(sizeof(long));
+
+	// index == 0 for disable cpuid, 1 for enable cpuid.
+	TST_EXP_PASS(arch_prctl_set(ARCH_SET_CPUID, index));
+
+	TEST(arch_prctl_get(ARCH_GET_CPUID, addr));
+
+	if (TST_RET == index)
+		tst_res(TPASS, "get cpuid succeed.");
+	else
+		tst_res(TFAIL, "get cpuid failed.");
+}
+
+static struct tst_test test = {
+	.test = run,
+	.tcnt = 2,
+	.min_kver = "4.12",
+};
+
+#else /* HAVE_ASM_PRCTL_H */
+TST_TEST_TCONF("missing <asm/prctl.h>");
+#endif
-- 
2.39.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [LTP] (no subject)
  2024-04-21  7:15 ` [LTP] (no subject) lufei
  2024-04-21  7:15   ` [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
@ 2024-04-26  8:36   ` Cyril Hrubis
  2024-04-26  9:42     ` 路斐
  1 sibling, 1 reply; 21+ messages in thread
From: Cyril Hrubis @ 2024-04-26  8:36 UTC (permalink / raw)
  To: lufei; +Cc: ltp

Hi!
> Some of your point has been fixed. Some are not:
> 1. I'm using gcc (GCC) 11.4.1 20230605, `addr` without initialization would output some warnings.
> 2. I read the manpage of arch_prctl, the ARCH_GET_CPUID seems return the flag, instead of storing `addr`:
> ```
> ARCH_GET_CPUID (since Linux 4.12)
>               Return the setting of the flag manipulated by ARCH_SET_CPUID as the result of the system call (1  for  enabled,  0  for
>               disabled).  addr is ignored.
> ```

Ah right, if addr is ignored just pass NULL there instead.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [LTP] (no subject)
  2024-04-26  8:36   ` [LTP] (no subject) Cyril Hrubis
@ 2024-04-26  9:42     ` 路斐
  2024-04-26 10:28       ` Cyril Hrubis
  0 siblings, 1 reply; 21+ messages in thread
From: 路斐 @ 2024-04-26  9:42 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

I tried using NULL, but met `TBROK: Test killed by SIGSEGV!`.&nbsp;


And the last time you mentioned in response to using `supported_archs`, this seems not work properly by now, the ltp document(section of writing_tests) says "not applicable".
&nbsp;






 路斐 Fei.Lu
平台测试部 高级测试开发工程师
统信软件
企业官网:www.uniontech.com
联系方式:18501012352
办公地址:西安市雁塔区云水一路与天谷八路口软件新城二期C2-20层



  

&nbsp;
&nbsp;
&nbsp;
------------------&nbsp;Original&nbsp;------------------
From: "Cyril&nbsp;Hrubis"; 
Date: 2024年4月26日(星期五) 上午8:37
To: "lufei"; 
Cc: "ltp"; 
Subject: Re:

&nbsp;
Hi!
&gt; Some of your point has been fixed. Some are not:
&gt; 1. I'm using gcc (GCC) 11.4.1 20230605, `addr` without initialization would output some warnings.
&gt; 2. I read the manpage of arch_prctl, the ARCH_GET_CPUID seems return the flag, instead of storing `addr`:
&gt; ```
&gt; ARCH_GET_CPUID (since Linux 4.12)
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Return the setting of the flag manipulated by ARCH_SET_CPUID as the result of the system call (1&nbsp; for&nbsp; enabled,&nbsp; 0&nbsp; for
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; disabled).&nbsp; addr is ignored.
&gt; ```

Ah right, if addr is ignored just pass NULL there instead.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [LTP] (no subject)
  2024-04-26  9:42     ` 路斐
@ 2024-04-26 10:28       ` Cyril Hrubis
  2024-04-26 12:27         ` 路斐
  0 siblings, 1 reply; 21+ messages in thread
From: Cyril Hrubis @ 2024-04-26 10:28 UTC (permalink / raw)
  To: 路斐; +Cc: ltp

Hi!
> I tried using NULL, but met `TBROK: Test killed by SIGSEGV!`.&nbsp;

That means that the manual page is wrong and the address is not ignored.

> And the last time you mentioned in response to using
> `supported_archs`, this seems not work properly by now, the ltp
> document(section of writing_tests) says "not applicable".

The supported_archs is supposed to work. How did you set it (the value)
and what happened?

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [LTP] (no subject)
  2024-04-26 10:28       ` Cyril Hrubis
@ 2024-04-26 12:27         ` 路斐
  2024-04-26 12:47           ` Jan Stancek
  0 siblings, 1 reply; 21+ messages in thread
From: 路斐 @ 2024-04-26 12:27 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi, Cyril.
Here is my case:


```
[root@rocky arch_prctl]# gcc --version
gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.&nbsp; There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@rocky arch_prctl]# uname -a
Linux rocky 5.14.0-362.18.1.el9_3.0.1.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Feb 11 13:49:23 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

[root@rocky arch_prctl]# cat arch_prctl01.c&nbsp;
// SPDX-License-Identifier: GPL-2.0-or-later
/*
&nbsp;* Copyright (c) UnionTech Software Technology Co.,Ltd., 2024
&nbsp;* Author: Lu Fei <lufei@uniontech.com&gt;
&nbsp;*/


/*\
&nbsp;* [Description]
&nbsp;*
&nbsp;* Simple test on arch_prctl to set and get cpuid instruction of test thread.
&nbsp;*/


#include "tst_test.h"
#include "lapi/syscalls.h"
#include <stdlib.h&gt;
#ifdef HAVE_ASM_PRCTL_H
#include <asm/prctl.h&gt;


static int arch_prctl_get(int code, unsigned long *addr)
{
	return tst_syscall(__NR_arch_prctl, code, *addr);
}


static int arch_prctl_set(int code, unsigned long addr)
{
	return tst_syscall(__NR_arch_prctl, code, addr);
}


static void run(unsigned int index)
{
	unsigned long *addr = malloc(sizeof(long));


	// index == 0 for disable cpuid, 1 for enable cpuid.
	TST_EXP_PASS(arch_prctl_set(ARCH_SET_CPUID, index));


	TEST(arch_prctl_get(ARCH_GET_CPUID, addr));


	if (TST_RET == index)
		tst_res(TPASS, "get cpuid succeed.");
	else
		tst_res(TFAIL, "get cpuid failed.");
}


static struct tst_test test = {
	.test = run,
	.tcnt = 2,
	.min_kver = "4.12",
	.supported_archs = {"x86_64", "x86", NULL},
};


#else /* HAVE_ASM_PRCTL_H */
TST_TEST_TCONF("missing <asm/prctl.h&gt;");
#endif
[root@rocky arch_prctl]# make clean
rm -f -f -r arch_prctl01&nbsp; *.o *.pyc .cache.mk *.dwo .*.dwo
[root@rocky arch_prctl]# make check
CHECK testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
arch_prctl01.c:48:10: warning: bogus scalar initializer
[root@rocky arch_prctl]# make
make -C "/root/Develop/ltp/lib" -f "/root/Develop/ltp/lib/Makefile" all
make[1]: Entering directory '/root/Develop/ltp/lib'
GEN ltp-version.h
make[2]: Nothing to be done for 'all'.
make[2]: Nothing to be done for 'all'.
make[1]: Leaving directory '/root/Develop/ltp/lib'
arch_prctl01.c:48:9: warning: braces around scalar initializer
&nbsp; &nbsp;48 |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.supported_archs = {"x86_64", "x86", NULL},
&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^
arch_prctl01.c:48:9: note: (near initialization for ‘test.supported_archs’)
arch_prctl01.c:48:29: warning: initialization of ‘const char * const*’ from incompatible pointer type ‘char *’ [-Wincompatible-pointer-types]
&nbsp; &nbsp;48 |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.supported_archs = {"x86_64", "x86", NULL},
&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^~~~~~~~
arch_prctl01.c:48:29: note: (near initialization for ‘test.supported_archs’)
arch_prctl01.c:48:39: warning: excess elements in scalar initializer
&nbsp; &nbsp;48 |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.supported_archs = {"x86_64", "x86", NULL},
&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^~~~~
arch_prctl01.c:48:39: note: (near initialization for ‘test.supported_archs’)
arch_prctl01.c:48:46: warning: excess elements in scalar initializer
&nbsp; &nbsp;48 |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.supported_archs = {"x86_64", "x86", NULL},
&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^~~~
arch_prctl01.c:48:46: note: (near initialization for ‘test.supported_archs’)
CC testcases/kernel/syscalls/arch_prctl/arch_prctl01
```







 路斐 Fei.Lu
Uniontech Technology
site: www.uniontech.com
tel: 18501012352
addr: Xi'an China



 

&nbsp;
&nbsp;
&nbsp;
------------------&nbsp;Original&nbsp;------------------
From: &nbsp;"Cyril&nbsp;Hrubis"<chrubis@suse.cz&gt;;
Date: &nbsp;Fri, Apr 26, 2024 06:30 PM
To: &nbsp;"路斐"<lufei@uniontech.com&gt;; 
Cc: &nbsp;"ltp"<ltp@lists.linux.it&gt;; 
Subject: &nbsp;Re: Re:

&nbsp;

Hi!
&gt; I tried using NULL, but met `TBROK: Test killed by SIGSEGV!`.&amp;nbsp;

That means that the manual page is wrong and the address is not ignored.

&gt; And the last time you mentioned in response to using
&gt; `supported_archs`, this seems not work properly by now, the ltp
&gt; document(section of writing_tests) says "not applicable".

The supported_archs is supposed to work. How did you set it (the value)
and what happened?

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [LTP] (no subject)
  2024-04-26 12:27         ` 路斐
@ 2024-04-26 12:47           ` Jan Stancek
  0 siblings, 0 replies; 21+ messages in thread
From: Jan Stancek @ 2024-04-26 12:47 UTC (permalink / raw)
  To: 路斐; +Cc: ltp

On Fri, Apr 26, 2024 at 2:27 PM 路斐 <lufei@uniontech.com> wrote:
>
> Hi, Cyril.
> Here is my case:
>
>
> ```
> [root@rocky arch_prctl]# gcc --version
> gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2)
> Copyright (C) 2021 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.&nbsp; There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
> [root@rocky arch_prctl]# uname -a
> Linux rocky 5.14.0-362.18.1.el9_3.0.1.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Feb 11 13:49:23 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
>
> [root@rocky arch_prctl]# cat arch_prctl01.c&nbsp;
> // SPDX-License-Identifier: GPL-2.0-or-later
> /*
> &nbsp;* Copyright (c) UnionTech Software Technology Co.,Ltd., 2024
> &nbsp;* Author: Lu Fei <lufei@uniontech.com&gt;
> &nbsp;*/
>
>
> /*\
> &nbsp;* [Description]
> &nbsp;*
> &nbsp;* Simple test on arch_prctl to set and get cpuid instruction of test thread.
> &nbsp;*/
>
>
> #include "tst_test.h"
> #include "lapi/syscalls.h"
> #include <stdlib.h&gt;
> #ifdef HAVE_ASM_PRCTL_H
> #include <asm/prctl.h&gt;
>
>
> static int arch_prctl_get(int code, unsigned long *addr)
> {
>         return tst_syscall(__NR_arch_prctl, code, *addr);
                                            ^^
you are de-refencing here, while kernel expects a pointer

> }
>
>
> static int arch_prctl_set(int code, unsigned long addr)
> {
>         return tst_syscall(__NR_arch_prctl, code, addr);
> }
>
>
> static void run(unsigned int index)
> {
>         unsigned long *addr = malloc(sizeof(long));
>
>
>         // index == 0 for disable cpuid, 1 for enable cpuid.
>         TST_EXP_PASS(arch_prctl_set(ARCH_SET_CPUID, index));
>
>
>         TEST(arch_prctl_get(ARCH_GET_CPUID, addr));
>
>
>         if (TST_RET == index)
>                 tst_res(TPASS, "get cpuid succeed.");
>         else
>                 tst_res(TFAIL, "get cpuid failed.");
> }
>
>
> static struct tst_test test = {
>         .test = run,
>         .tcnt = 2,
>         .min_kver = "4.12",
>         .supported_archs = {"x86_64", "x86", NULL},
> };
>
>
> #else /* HAVE_ASM_PRCTL_H */
> TST_TEST_TCONF("missing <asm/prctl.h&gt;");
> #endif
> [root@rocky arch_prctl]# make clean
> rm -f -f -r arch_prctl01&nbsp; *.o *.pyc .cache.mk *.dwo .*.dwo
> [root@rocky arch_prctl]# make check
> CHECK testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
> arch_prctl01.c:48:10: warning: bogus scalar initializer
> [root@rocky arch_prctl]# make
> make -C "/root/Develop/ltp/lib" -f "/root/Develop/ltp/lib/Makefile" all
> make[1]: Entering directory '/root/Develop/ltp/lib'
> GEN ltp-version.h
> make[2]: Nothing to be done for 'all'.
> make[2]: Nothing to be done for 'all'.
> make[1]: Leaving directory '/root/Develop/ltp/lib'
> arch_prctl01.c:48:9: warning: braces around scalar initializer
> &nbsp; &nbsp;48 |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.supported_archs = {"x86_64", "x86", NULL},
> &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^
> arch_prctl01.c:48:9: note: (near initialization for ‘test.supported_archs’)
> arch_prctl01.c:48:29: warning: initialization of ‘const char * const*’ from incompatible pointer type ‘char *’ [-Wincompatible-pointer-types]
> &nbsp; &nbsp;48 |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.supported_archs = {"x86_64", "x86", NULL},
> &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^~~~~~~~
> arch_prctl01.c:48:29: note: (near initialization for ‘test.supported_archs’)
> arch_prctl01.c:48:39: warning: excess elements in scalar initializer
> &nbsp; &nbsp;48 |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.supported_archs = {"x86_64", "x86", NULL},
> &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^~~~~
> arch_prctl01.c:48:39: note: (near initialization for ‘test.supported_archs’)
> arch_prctl01.c:48:46: warning: excess elements in scalar initializer
> &nbsp; &nbsp;48 |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.supported_archs = {"x86_64", "x86", NULL},
> &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^~~~
> arch_prctl01.c:48:46: note: (near initialization for ‘test.supported_archs’)
> CC testcases/kernel/syscalls/arch_prctl/arch_prctl01
> ```
>
>
>
>
>
>
>
>  路斐 Fei.Lu
> Uniontech Technology
> site: www.uniontech.com
> tel: 18501012352
> addr: Xi'an China
>
>
>
>
>
> &nbsp;
> &nbsp;
> &nbsp;
> ------------------&nbsp;Original&nbsp;------------------
> From: &nbsp;"Cyril&nbsp;Hrubis"<chrubis@suse.cz&gt;;
> Date: &nbsp;Fri, Apr 26, 2024 06:30 PM
> To: &nbsp;"路斐"<lufei@uniontech.com&gt;;
> Cc: &nbsp;"ltp"<ltp@lists.linux.it&gt;;
> Subject: &nbsp;Re: Re:
>
> &nbsp;
>
> Hi!
> &gt; I tried using NULL, but met `TBROK: Test killed by SIGSEGV!`.&amp;nbsp;
>
> That means that the manual page is wrong and the address is not ignored.
>
> &gt; And the last time you mentioned in response to using
> &gt; `supported_archs`, this seems not work properly by now, the ltp
> &gt; document(section of writing_tests) says "not applicable".
>
> The supported_archs is supposed to work. How did you set it (the value)
> and what happened?
>
> --
> Cyril Hrubis
> chrubis@suse.cz
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [LTP] (no subject)
  2024-04-19  7:07 [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
                   ` (3 preceding siblings ...)
  2024-04-23  1:05 ` [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
@ 2024-04-28  7:44 ` lufei
  2024-04-28  7:44   ` [LTP] [PATCH] Add case about arch_prctl syscall lufei
  4 siblings, 1 reply; 21+ messages in thread
From: lufei @ 2024-04-28  7:44 UTC (permalink / raw)
  To: jstancek; +Cc: ltp

Thanks a lot.


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [LTP] [PATCH] Add case about arch_prctl syscall.
  2024-04-28  7:44 ` [LTP] (no subject) lufei
@ 2024-04-28  7:44   ` lufei
  2024-04-29 15:02     ` Cyril Hrubis
       [not found]     ` <20240506070336.2711930-1-lufei@uniontech.com>
  0 siblings, 2 replies; 21+ messages in thread
From: lufei @ 2024-04-28  7:44 UTC (permalink / raw)
  To: jstancek, ltp; +Cc: lufei

Add testcase about arch_prctl syscall.

Signed-off-by: Lu Fei <lufei@uniontech.com>
---
 configure.ac                                  |  1 +
 runtest/syscalls                              |  2 +
 .../kernel/syscalls/arch_prctl/.gitignore     |  1 +
 testcases/kernel/syscalls/arch_prctl/Makefile |  8 +++
 .../kernel/syscalls/arch_prctl/arch_prctl01.c | 51 +++++++++++++++++++
 5 files changed, 63 insertions(+)
 create mode 100644 testcases/kernel/syscalls/arch_prctl/.gitignore
 create mode 100644 testcases/kernel/syscalls/arch_prctl/Makefile
 create mode 100644 testcases/kernel/syscalls/arch_prctl/arch_prctl01.c

diff --git a/configure.ac b/configure.ac
index 1d7e862d8..0dcaddc0f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,7 @@ AC_CHECK_DECLS([SEM_STAT_ANY],,,[#include <sys/sem.h>])
 
 AC_CHECK_HEADERS_ONCE([ \
     asm/ldt.h \
+    asm/prctl.h \
     cpuid.h \
     emmintrin.h \
     ifaddrs.h \
diff --git a/runtest/syscalls b/runtest/syscalls
index 7794f1465..505b4243d 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -31,6 +31,8 @@ alarm05 alarm05
 alarm06 alarm06
 alarm07 alarm07
 
+arch_prctl01 arch_prctl01
+
 bind01 bind01
 bind02 bind02
 bind03 bind03
diff --git a/testcases/kernel/syscalls/arch_prctl/.gitignore b/testcases/kernel/syscalls/arch_prctl/.gitignore
new file mode 100644
index 000000000..24871e249
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/.gitignore
@@ -0,0 +1 @@
+/arch_prctl01
diff --git a/testcases/kernel/syscalls/arch_prctl/Makefile b/testcases/kernel/syscalls/arch_prctl/Makefile
new file mode 100644
index 000000000..272949d57
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) UnionTech Software Technology Co.,Ltd. 2024
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
new file mode 100644
index 000000000..5fe7ea131
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) UnionTech Software Technology Co.,Ltd., 2024
+ * Author: Lu Fei <lufei@uniontech.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Simple test on arch_prctl to set and get cpuid instruction of test thread.
+ */
+
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include <stdlib.h>
+#ifdef HAVE_ASM_PRCTL_H
+#include <asm/prctl.h>
+
+static int arch_prctl_get(int code)
+{
+	return tst_syscall(__NR_arch_prctl, code, NULL);
+}
+
+static int arch_prctl_set(int code, unsigned long addr)
+{
+	return tst_syscall(__NR_arch_prctl, code, addr);
+}
+
+static void run(unsigned int index)
+{
+	// index == 0 for disable cpuid, 1 for enable cpuid.
+	TST_EXP_PASS(arch_prctl_set(ARCH_SET_CPUID, index));
+
+	TEST(arch_prctl_get(ARCH_GET_CPUID));
+
+	if (TST_RET == index)
+		tst_res(TPASS, "get cpuid succeed.");
+	else
+		tst_res(TFAIL, "get cpuid failed.");
+}
+
+static struct tst_test test = {
+	.test = run,
+	.tcnt = 2,
+	.min_kver = "4.12",
+	.supported_archs = (const char *const []){"x86_64", "x86", NULL}
+};
+
+#else /* HAVE_ASM_PRCTL_H */
+TST_TEST_TCONF("missing <asm/prctl.h>");
+#endif
-- 
2.39.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [LTP] [PATCH] Add case about arch_prctl syscall.
  2024-04-28  7:44   ` [LTP] [PATCH] Add case about arch_prctl syscall lufei
@ 2024-04-29 15:02     ` Cyril Hrubis
       [not found]     ` <20240506070336.2711930-1-lufei@uniontech.com>
  1 sibling, 0 replies; 21+ messages in thread
From: Cyril Hrubis @ 2024-04-29 15:02 UTC (permalink / raw)
  To: lufei; +Cc: ltp

Hi!
And it looks that limiting the test to x86 or x86_64 CPUs is not enough
for it to run, we will have to check that the CPU has
X86_FEATURE_CPUID_FAULT flag set. Looks like we can actually get that
from the flags field from /proc/cpuinfo, if cpuid_fault is there the
prctl is supposed to work, if not these calls should return ENODEV.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [LTP] [PATCH] Add case about arch_prctl syscall.
       [not found]     ` <20240506070336.2711930-1-lufei@uniontech.com>
@ 2024-05-06  7:03       ` lufei
  2024-05-06  9:53         ` Cyril Hrubis
       [not found]         ` <20240507043235.1692-1-lufei@uniontech.com>
  0 siblings, 2 replies; 21+ messages in thread
From: lufei @ 2024-05-06  7:03 UTC (permalink / raw)
  To: chrubis, ltp; +Cc: lufei

Add testcase about arch_prctl syscall.

Signed-off-by: Lu Fei <lufei@uniontech.com>
---
 configure.ac                                  |  1 +
 runtest/syscalls                              |  2 +
 .../kernel/syscalls/arch_prctl/.gitignore     |  1 +
 testcases/kernel/syscalls/arch_prctl/Makefile |  8 +++
 .../kernel/syscalls/arch_prctl/arch_prctl01.c | 71 +++++++++++++++++++
 5 files changed, 83 insertions(+)
 create mode 100644 testcases/kernel/syscalls/arch_prctl/.gitignore
 create mode 100644 testcases/kernel/syscalls/arch_prctl/Makefile
 create mode 100644 testcases/kernel/syscalls/arch_prctl/arch_prctl01.c

diff --git a/configure.ac b/configure.ac
index 1d7e862d8..0dcaddc0f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,7 @@ AC_CHECK_DECLS([SEM_STAT_ANY],,,[#include <sys/sem.h>])
 
 AC_CHECK_HEADERS_ONCE([ \
     asm/ldt.h \
+    asm/prctl.h \
     cpuid.h \
     emmintrin.h \
     ifaddrs.h \
diff --git a/runtest/syscalls b/runtest/syscalls
index 7794f1465..505b4243d 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -31,6 +31,8 @@ alarm05 alarm05
 alarm06 alarm06
 alarm07 alarm07
 
+arch_prctl01 arch_prctl01
+
 bind01 bind01
 bind02 bind02
 bind03 bind03
diff --git a/testcases/kernel/syscalls/arch_prctl/.gitignore b/testcases/kernel/syscalls/arch_prctl/.gitignore
new file mode 100644
index 000000000..24871e249
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/.gitignore
@@ -0,0 +1 @@
+/arch_prctl01
diff --git a/testcases/kernel/syscalls/arch_prctl/Makefile b/testcases/kernel/syscalls/arch_prctl/Makefile
new file mode 100644
index 000000000..272949d57
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) UnionTech Software Technology Co.,Ltd. 2024
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
new file mode 100644
index 000000000..5b69f7bf8
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) UnionTech Software Technology Co.,Ltd., 2024
+ * Author: Lu Fei <lufei@uniontech.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Simple test on arch_prctl to set and get cpuid instruction of test thread.
+ */
+
+#include "tst_test.h"
+#include "tst_safe_stdio.h"
+#include "lapi/syscalls.h"
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_ASM_PRCTL_H
+#include <asm/prctl.h>
+
+static int arch_prctl_get(int code)
+{
+	return tst_syscall(__NR_arch_prctl, code, NULL);
+}
+
+static int arch_prctl_set(int code, unsigned long addr)
+{
+	return tst_syscall(__NR_arch_prctl, code, addr);
+}
+
+static void run(unsigned int index)
+{
+	FILE *fd;
+	char needed_flag[] = "cpuid_fault";
+	char *line = NULL;
+	size_t len = 0;
+	bool tag = 0;
+
+	fd = SAFE_FOPEN("/proc/cpuinfo", "r");
+
+	while (getline(&line, &len, fd) != -1) {
+		if (strncmp(line, "flag", strlen("flag")) == 0 &&
+				strstr(line, needed_flag) != NULL) {
+			tag = 1;
+			break;
+		}
+	}
+	if (!tag)
+		tst_brk(TCONF, "CPU need %s flag.", needed_flag);
+
+	// index == 0 for disable cpuid, 1 for enable cpuid.
+	TST_EXP_PASS(arch_prctl_set(ARCH_SET_CPUID, index));
+
+	TEST(arch_prctl_get(ARCH_GET_CPUID));
+
+	if (TST_RET == index)
+		tst_res(TPASS, "get cpuid succeed.");
+	else
+		tst_res(TFAIL, "get cpuid failed.");
+}
+
+static struct tst_test test = {
+	.test = run,
+	.tcnt = 2,
+	.min_kver = "4.12",
+	.supported_archs = (const char *const []){"x86_64", "x86", NULL}
+};
+
+#else /* HAVE_ASM_PRCTL_H */
+TST_TEST_TCONF("missing <asm/prctl.h>");
+#endif
-- 
2.39.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [LTP] [PATCH] Add case about arch_prctl syscall.
  2024-05-06  7:03       ` lufei
@ 2024-05-06  9:53         ` Cyril Hrubis
       [not found]         ` <20240507043235.1692-1-lufei@uniontech.com>
  1 sibling, 0 replies; 21+ messages in thread
From: Cyril Hrubis @ 2024-05-06  9:53 UTC (permalink / raw)
  To: lufei; +Cc: ltp

Hi!
> +static void run(unsigned int index)
> +{
> +	FILE *fd;

Please do not call FILE * pointer fd, that is confusing since fd is
usually a file descriptor. FILE * pointer is usually just call f.

> +	char needed_flag[] = "cpuid_fault";

I would include the space before flag name just to be extra careful we
do not match anything that has this as a substring. E.g. if in the
future they add something that would be named "no_cpuid_fault" this
would still match strstr(line, "cpuid_fault") but not
strstr(line, " cpuid_fault"); Ideally we would check that there is a
space after the string, but we can't just do that with strstr() since
the flag may be actually last in the list. So the only posibility would
be using the pointer from strstr() and checking that the character after
the matched string is also a space.

> +	char *line = NULL;
> +	size_t len = 0;
> +	bool tag = 0;
> +
> +	fd = SAFE_FOPEN("/proc/cpuinfo", "r");
> +
> +	while (getline(&line, &len, fd) != -1) {
> +		if (strncmp(line, "flag", strlen("flag")) == 0 &&
                                      ^
				      why not just whole "flags" ?
> +				strstr(line, needed_flag) != NULL) {
> +			tag = 1;
> +			break;
> +		}
> +	}

This whole check for flag should be done in the test setup so that we do
not parse the /proc/cpuinfo on each test iteration (-i command line
option).

> +	if (!tag)
> +		tst_brk(TCONF, "CPU need %s flag.", needed_flag);

Why don't we check that the prctl() returns ENODEV when the flag is not
present. That is a valid testcase as well.

> +	// index == 0 for disable cpuid, 1 for enable cpuid.
> +	TST_EXP_PASS(arch_prctl_set(ARCH_SET_CPUID, index));
> +
> +	TEST(arch_prctl_get(ARCH_GET_CPUID));
> +
> +	if (TST_RET == index)
> +		tst_res(TPASS, "get cpuid succeed.");
> +	else
> +		tst_res(TFAIL, "get cpuid failed.");
> +}
> +
> +static struct tst_test test = {
> +	.test = run,
> +	.tcnt = 2,
> +	.min_kver = "4.12",
> +	.supported_archs = (const char *const []){"x86_64", "x86", NULL}
> +};
> +
> +#else /* HAVE_ASM_PRCTL_H */
> +TST_TEST_TCONF("missing <asm/prctl.h>");
> +#endif
> -- 
> 2.39.3
> 

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [LTP] [PATCH] Add case about arch_prctl syscall.
       [not found]         ` <20240507043235.1692-1-lufei@uniontech.com>
@ 2024-05-07  4:32           ` lufei
  2024-05-07 12:50             ` Cyril Hrubis
       [not found]             ` <20240508015852.3362-1-lufei@uniontech.com>
  0 siblings, 2 replies; 21+ messages in thread
From: lufei @ 2024-05-07  4:32 UTC (permalink / raw)
  To: chrubis, ltp; +Cc: lufei

Add testcase about arch_prctl syscall.

Signed-off-by: Lu Fei <lufei@uniontech.com>
---
 configure.ac                                  |   1 +
 runtest/syscalls                              |   2 +
 .../kernel/syscalls/arch_prctl/.gitignore     |   1 +
 testcases/kernel/syscalls/arch_prctl/Makefile |   8 ++
 .../kernel/syscalls/arch_prctl/arch_prctl01.c | 103 ++++++++++++++++++
 5 files changed, 115 insertions(+)
 create mode 100644 testcases/kernel/syscalls/arch_prctl/.gitignore
 create mode 100644 testcases/kernel/syscalls/arch_prctl/Makefile
 create mode 100644 testcases/kernel/syscalls/arch_prctl/arch_prctl01.c

diff --git a/configure.ac b/configure.ac
index 1d7e862d8..0dcaddc0f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,7 @@ AC_CHECK_DECLS([SEM_STAT_ANY],,,[#include <sys/sem.h>])
 
 AC_CHECK_HEADERS_ONCE([ \
     asm/ldt.h \
+    asm/prctl.h \
     cpuid.h \
     emmintrin.h \
     ifaddrs.h \
diff --git a/runtest/syscalls b/runtest/syscalls
index 7794f1465..505b4243d 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -31,6 +31,8 @@ alarm05 alarm05
 alarm06 alarm06
 alarm07 alarm07
 
+arch_prctl01 arch_prctl01
+
 bind01 bind01
 bind02 bind02
 bind03 bind03
diff --git a/testcases/kernel/syscalls/arch_prctl/.gitignore b/testcases/kernel/syscalls/arch_prctl/.gitignore
new file mode 100644
index 000000000..24871e249
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/.gitignore
@@ -0,0 +1 @@
+/arch_prctl01
diff --git a/testcases/kernel/syscalls/arch_prctl/Makefile b/testcases/kernel/syscalls/arch_prctl/Makefile
new file mode 100644
index 000000000..272949d57
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) UnionTech Software Technology Co.,Ltd. 2024
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
new file mode 100644
index 000000000..cce204f2d
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
@@ -0,0 +1,103 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) UnionTech Software Technology Co.,Ltd., 2024
+ * Author: Lu Fei <lufei@uniontech.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Simple test on arch_prctl to set and get cpuid instruction of test thread.
+ */
+
+#include "tst_test.h"
+#include "tst_safe_stdio.h"
+#include "lapi/syscalls.h"
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#ifdef HAVE_ASM_PRCTL_H
+#include <asm/prctl.h>
+
+static int arch_prctl_get(int code)
+{
+	return tst_syscall(__NR_arch_prctl, code, NULL);
+}
+
+static int arch_prctl_set(int code, unsigned long addr)
+{
+	return tst_syscall(__NR_arch_prctl, code, addr);
+}
+
+static struct tcase {
+	const int input;
+	int set_exp;
+	int get_exp;
+	const int tst_errno;
+} tcases[] = {
+	{0, 0, 0, ENODEV},
+	{1, 0, 1, ENODEV},
+};
+
+static void setup(void)
+{
+	FILE *f;
+	char flag_mid[] = " cpuid_fault ";
+	char flag_end[] = " cpuid_fault\n";
+	char *line = NULL;
+	size_t len = 0;
+	bool tag = 0;
+
+	f = SAFE_FOPEN("/proc/cpuinfo", "r");
+
+	while (getline(&line, &len, f) != -1)
+		if (strncmp(line, "flags", strlen("flags")) == 0 &&
+				(strstr(line, flag_mid) != NULL ||
+				 strstr(line, flag_end) != NULL)) {
+			tag = 1;
+			break;
+		}
+	if (!tag)
+		for (unsigned long i = 0; i < ARRAY_SIZE(tcases); i++) {
+			tcases[i].set_exp = -1;
+			// get default value
+			tcases[i].get_exp = 1;
+		}
+}
+
+static void run(unsigned int index)
+{
+	struct tcase tc = tcases[index];
+
+	TEST(arch_prctl_set(ARCH_SET_CPUID, tc.input));
+
+	if (TST_RET == tc.set_exp)
+		if (tc.set_exp == -1)
+			tst_res((TST_ERR == tc.tst_errno ? TPASS : TFAIL),
+				"set cpuid, expect: %s, get: %s",
+				tst_strerrno(tc.tst_errno),
+				tst_strerrno(TST_ERR));
+		else
+			tst_res(TPASS, "set cpuid succeed.");
+	else
+		tst_res(TFAIL, "set cpuid failed.");
+
+	TEST(arch_prctl_get(ARCH_GET_CPUID));
+
+	if (TST_RET == tc.get_exp)
+		tst_res(TPASS, "get cpuid succeed.");
+	else
+		tst_res(TFAIL, "get cpuid failed.");
+}
+
+static struct tst_test test = {
+	.test = run,
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.min_kver = "4.12",
+	.supported_archs = (const char *const []){"x86_64", "x86", NULL}
+};
+
+#else /* HAVE_ASM_PRCTL_H */
+TST_TEST_TCONF("missing <asm/prctl.h>");
+#endif
-- 
2.39.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [LTP] [PATCH] Add case about arch_prctl syscall.
  2024-05-07  4:32           ` lufei
@ 2024-05-07 12:50             ` Cyril Hrubis
  2024-05-08  2:29               ` 路斐
       [not found]             ` <20240508015852.3362-1-lufei@uniontech.com>
  1 sibling, 1 reply; 21+ messages in thread
From: Cyril Hrubis @ 2024-05-07 12:50 UTC (permalink / raw)
  To: lufei; +Cc: ltp

Hi!
> +static void run(unsigned int index)
> +{
> +	struct tcase tc = tcases[index];
> +
> +	TEST(arch_prctl_set(ARCH_SET_CPUID, tc.input));
> +
> +	if (TST_RET == tc.set_exp)
> +		if (tc.set_exp == -1)
> +			tst_res((TST_ERR == tc.tst_errno ? TPASS : TFAIL),
> +				"set cpuid, expect: %s, get: %s",
> +				tst_strerrno(tc.tst_errno),
> +				tst_strerrno(TST_ERR));
> +		else
> +			tst_res(TPASS, "set cpuid succeed.");
> +	else
> +		tst_res(TFAIL, "set cpuid failed.");

This is kind of ugly, why can't we just do:

	if (tag)
		TST_EXP_PASS(arch_prctl_set(ARCH_SET_CPUID, index));
	else
		TST_EXP_FAIL(arch_prctl_set(ARCH_SET_CPUID, index), ENODEV);

> +	TEST(arch_prctl_get(ARCH_GET_CPUID));
> +
> +	if (TST_RET == tc.get_exp)
> +		tst_res(TPASS, "get cpuid succeed.");
> +	else
> +		tst_res(TFAIL, "get cpuid failed.");


We have to check the errno here as well, just branch on the tag as well:

	if (tag) {
		TEST(arch_prctl_get(ARCH_GET_CPUID));

		if (TST_RET == index)
			tst_res(TPASS, "...");
		else
			tst_res(FAIL, "...");
	} else {
		TST_EXP_FAIL(arch_prctl_get(ARCH_GET_CPUID), ENODEV);
	}

Generally the use of TST_EXP_FAIL() is prefered whenever possible.

> +}
> +
> +static struct tst_test test = {
> +	.test = run,
> +	.setup = setup,
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.min_kver = "4.12",
> +	.supported_archs = (const char *const []){"x86_64", "x86", NULL}
> +};
> +
> +#else /* HAVE_ASM_PRCTL_H */
> +TST_TEST_TCONF("missing <asm/prctl.h>");
> +#endif
> -- 
> 2.39.3
> 

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [LTP] [PATCH] Add case about arch_prctl syscall.
       [not found]             ` <20240508015852.3362-1-lufei@uniontech.com>
@ 2024-05-08  1:58               ` lufei
  2024-05-09 10:27                 ` Cyril Hrubis
  0 siblings, 1 reply; 21+ messages in thread
From: lufei @ 2024-05-08  1:58 UTC (permalink / raw)
  To: ltp; +Cc: lufei

Add testcase about arch_prctl syscall.

Signed-off-by: Lu Fei <lufei@uniontech.com>
---
 configure.ac                                  |  1 +
 runtest/syscalls                              |  2 +
 .../kernel/syscalls/arch_prctl/.gitignore     |  1 +
 testcases/kernel/syscalls/arch_prctl/Makefile |  8 ++
 .../kernel/syscalls/arch_prctl/arch_prctl01.c | 82 +++++++++++++++++++
 5 files changed, 94 insertions(+)
 create mode 100644 testcases/kernel/syscalls/arch_prctl/.gitignore
 create mode 100644 testcases/kernel/syscalls/arch_prctl/Makefile
 create mode 100644 testcases/kernel/syscalls/arch_prctl/arch_prctl01.c

diff --git a/configure.ac b/configure.ac
index 1d7e862d8..0dcaddc0f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,7 @@ AC_CHECK_DECLS([SEM_STAT_ANY],,,[#include <sys/sem.h>])
 
 AC_CHECK_HEADERS_ONCE([ \
     asm/ldt.h \
+    asm/prctl.h \
     cpuid.h \
     emmintrin.h \
     ifaddrs.h \
diff --git a/runtest/syscalls b/runtest/syscalls
index 7794f1465..505b4243d 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -31,6 +31,8 @@ alarm05 alarm05
 alarm06 alarm06
 alarm07 alarm07
 
+arch_prctl01 arch_prctl01
+
 bind01 bind01
 bind02 bind02
 bind03 bind03
diff --git a/testcases/kernel/syscalls/arch_prctl/.gitignore b/testcases/kernel/syscalls/arch_prctl/.gitignore
new file mode 100644
index 000000000..24871e249
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/.gitignore
@@ -0,0 +1 @@
+/arch_prctl01
diff --git a/testcases/kernel/syscalls/arch_prctl/Makefile b/testcases/kernel/syscalls/arch_prctl/Makefile
new file mode 100644
index 000000000..272949d57
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) UnionTech Software Technology Co.,Ltd. 2024
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
new file mode 100644
index 000000000..e30b5667a
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) UnionTech Software Technology Co.,Ltd., 2024
+ * Author: Lu Fei <lufei@uniontech.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Simple test on arch_prctl to set and get cpuid instruction of test thread.
+ */
+
+#include "tst_test.h"
+#include "tst_safe_stdio.h"
+#include "lapi/syscalls.h"
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_ASM_PRCTL_H
+#include <asm/prctl.h>
+
+static int arch_prctl_get(int code)
+{
+	return tst_syscall(__NR_arch_prctl, code, NULL);
+}
+
+static int arch_prctl_set(int code, unsigned long addr)
+{
+	return tst_syscall(__NR_arch_prctl, code, addr);
+}
+
+static bool tag;
+
+static void setup(void)
+{
+	FILE *f;
+	char flag_mid[] = " cpuid_fault ";
+	char flag_end[] = " cpuid_fault\n";
+	char *line = NULL;
+	size_t len = 0;
+
+	tag = false;
+
+	f = SAFE_FOPEN("/proc/cpuinfo", "r");
+
+	while (getline(&line, &len, f) != -1)
+		if (strncmp(line, "flags", strlen("flags")) == 0 &&
+				(strstr(line, flag_mid) != NULL ||
+				 strstr(line, flag_end) != NULL)) {
+			tag = true;
+			break;
+		}
+}
+
+static void run(unsigned int index)
+{
+	if (tag)
+		TST_EXP_PASS(arch_prctl_set(ARCH_SET_CPUID, index));
+	else
+		TST_EXP_FAIL(arch_prctl_set(ARCH_SET_CPUID, index), ENODEV);
+
+	// if cpu has cpuid_fault flag, ARCH_GET_CPUID returns what has been
+	// set: index, otherwise, returns default status: 1
+	int exp = tag ? index : 1;
+
+	TEST(arch_prctl_get(ARCH_GET_CPUID));
+	if (TST_RET == exp)
+		tst_res(TPASS, "get cpuid succeed.");
+	else
+		tst_res(TFAIL, "get wrong cpuid status");
+}
+
+static struct tst_test test = {
+	.test = run,
+	.setup = setup,
+	.tcnt = 2,
+	.min_kver = "4.12",
+	.supported_archs = (const char *const []){"x86_64", "x86", NULL}
+};
+
+#else /* HAVE_ASM_PRCTL_H */
+TST_TEST_TCONF("missing <asm/prctl.h>");
+#endif
-- 
2.39.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [LTP] [PATCH] Add case about arch_prctl syscall.
  2024-05-07 12:50             ` Cyril Hrubis
@ 2024-05-08  2:29               ` 路斐
  0 siblings, 0 replies; 21+ messages in thread
From: 路斐 @ 2024-05-08  2:29 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi, Cyril.&nbsp;
Thanks again very much.


As written in man page,&nbsp;ENODEV seems only for ARCH_SET_CPUID, so I didn't use TST_EXP_FAIL in ARCH_GET_CPUID check. ARCH_GET_CPUID always success with returning cpuid status, I've tested this on a Intel&nbsp;J1900 machine witch has no cpuid_fault flag. I've resent the patch.

Lu Fei
site:www.uniontech.com
tel:(+86)18501012352
addr: Xi'an, China&nbsp;



&nbsp;
&nbsp;
------------------&nbsp;Original&nbsp;------------------
From: &nbsp;"Cyril&nbsp;Hrubis"<chrubis@suse.cz&gt;;
Date: &nbsp;Tue, May 7, 2024 12:51 PM
To: &nbsp;"lufei"<lufei@uniontech.com&gt;; 
Cc: &nbsp;"ltp"<ltp@lists.linux.it&gt;; "jstancek"<jstancek@redhat.com&gt;; 
Subject: &nbsp;Re: [PATCH] Add case about arch_prctl syscall.

&nbsp;

Hi!
&gt; +static void run(unsigned int index)
&gt; +{
&gt; +	struct tcase tc = tcases[index];
&gt; +
&gt; +	TEST(arch_prctl_set(ARCH_SET_CPUID, tc.input));
&gt; +
&gt; +	if (TST_RET == tc.set_exp)
&gt; +		if (tc.set_exp == -1)
&gt; +			tst_res((TST_ERR == tc.tst_errno ? TPASS : TFAIL),
&gt; +				"set cpuid, expect: %s, get: %s",
&gt; +				tst_strerrno(tc.tst_errno),
&gt; +				tst_strerrno(TST_ERR));
&gt; +		else
&gt; +			tst_res(TPASS, "set cpuid succeed.");
&gt; +	else
&gt; +		tst_res(TFAIL, "set cpuid failed.");

This is kind of ugly, why can't we just do:

	if (tag)
		TST_EXP_PASS(arch_prctl_set(ARCH_SET_CPUID, index));
	else
		TST_EXP_FAIL(arch_prctl_set(ARCH_SET_CPUID, index), ENODEV);

&gt; +	TEST(arch_prctl_get(ARCH_GET_CPUID));
&gt; +
&gt; +	if (TST_RET == tc.get_exp)
&gt; +		tst_res(TPASS, "get cpuid succeed.");
&gt; +	else
&gt; +		tst_res(TFAIL, "get cpuid failed.");


We have to check the errno here as well, just branch on the tag as well:

	if (tag) {
		TEST(arch_prctl_get(ARCH_GET_CPUID));

		if (TST_RET == index)
			tst_res(TPASS, "...");
		else
			tst_res(FAIL, "...");
	} else {
		TST_EXP_FAIL(arch_prctl_get(ARCH_GET_CPUID), ENODEV);
	}

Generally the use of TST_EXP_FAIL() is prefered whenever possible.

&gt; +}
&gt; +
&gt; +static struct tst_test test = {
&gt; +	.test = run,
&gt; +	.setup = setup,
&gt; +	.tcnt = ARRAY_SIZE(tcases),
&gt; +	.min_kver = "4.12",
&gt; +	.supported_archs = (const char *const []){"x86_64", "x86", NULL}
&gt; +};
&gt; +
&gt; +#else /* HAVE_ASM_PRCTL_H */
&gt; +TST_TEST_TCONF("missing <asm/prctl.h&gt;");
&gt; +#endif
&gt; -- 
&gt; 2.39.3
&gt; 

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [LTP] [PATCH] Add case about arch_prctl syscall.
  2024-05-08  1:58               ` lufei
@ 2024-05-09 10:27                 ` Cyril Hrubis
  0 siblings, 0 replies; 21+ messages in thread
From: Cyril Hrubis @ 2024-05-09 10:27 UTC (permalink / raw)
  To: lufei; +Cc: ltp

Hi!
Applied, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2024-05-09 10:29 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-19  7:07 [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
2024-04-19 15:46 ` Cyril Hrubis
2024-04-21  6:25 ` lufei
2024-04-21  7:15 ` [LTP] (no subject) lufei
2024-04-21  7:15   ` [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
2024-04-26  8:36   ` [LTP] (no subject) Cyril Hrubis
2024-04-26  9:42     ` 路斐
2024-04-26 10:28       ` Cyril Hrubis
2024-04-26 12:27         ` 路斐
2024-04-26 12:47           ` Jan Stancek
2024-04-23  1:05 ` [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
2024-04-28  7:44 ` [LTP] (no subject) lufei
2024-04-28  7:44   ` [LTP] [PATCH] Add case about arch_prctl syscall lufei
2024-04-29 15:02     ` Cyril Hrubis
     [not found]     ` <20240506070336.2711930-1-lufei@uniontech.com>
2024-05-06  7:03       ` lufei
2024-05-06  9:53         ` Cyril Hrubis
     [not found]         ` <20240507043235.1692-1-lufei@uniontech.com>
2024-05-07  4:32           ` lufei
2024-05-07 12:50             ` Cyril Hrubis
2024-05-08  2:29               ` 路斐
     [not found]             ` <20240508015852.3362-1-lufei@uniontech.com>
2024-05-08  1:58               ` lufei
2024-05-09 10:27                 ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox