1 // SPDX-License-Identifier: GPL-2.0-only
3 * POWER Data Stream Control Register (DSCR) fork test
5 * This testcase modifies the DSCR using mtspr, forks and then
6 * verifies that the child process has the correct changed DSCR
9 * When using the privilege state SPR, the instructions such as
10 * mfspr or mtspr are privileged and the kernel emulates them
11 * for us. Instructions using problem state SPR can be executed
12 * directly without any emulation if the HW supports them. Else
13 * they also get emulated by the kernel.
15 * Copyright 2012, Anton Blanchard, IBM Corporation.
16 * Copyright 2015, Anshuman Khandual, IBM Corporation.
20 int dscr_inherit(void)
22 unsigned long i, dscr = 0;
25 SKIP_IF(!have_hwcap2(PPC_FEATURE2_DSCR));
30 for (i = 0; i < COUNT; i++) {
31 unsigned long cur_dscr, cur_dscr_usr;
44 perror("fork() failed");
49 if (waitpid(pid, &status, 0) == -1) {
50 perror("waitpid() failed");
54 if (!WIFEXITED(status)) {
55 fprintf(stderr, "Child didn't exit cleanly\n");
59 if (WEXITSTATUS(status) != 0) {
60 fprintf(stderr, "Child didn't exit cleanly\n");
64 cur_dscr = get_dscr();
65 if (cur_dscr != dscr) {
66 fprintf(stderr, "Kernel DSCR should be %ld "
67 "but is %ld\n", dscr, cur_dscr);
71 cur_dscr_usr = get_dscr_usr();
72 if (cur_dscr_usr != dscr) {
73 fprintf(stderr, "User DSCR should be %ld "
74 "but is %ld\n", dscr, cur_dscr_usr);
83 int main(int argc, char *argv[])
85 return test_harness(dscr_inherit, "dscr_inherit_test");