1 /******************************************************************************
3 * Copyright © International Business Machines Corp., 2009
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
11 * 1. Block a thread using FUTEX_WAIT
12 * 2. Attempt to use FUTEX_CMP_REQUEUE_PI on the futex from 1.
13 * 3. The kernel must detect the mismatch and return -EINVAL.
16 * Darren Hart <dvhart@linux.intel.com>
19 * 2009-Nov-9: Initial version by Darren Hart <dvhart@linux.intel.com>
21 *****************************************************************************/
30 #include "futextest.h"
33 #define TEST_NAME "futex-requeue-pi-mismatched-ops"
35 futex_t f1
= FUTEX_INITIALIZER
;
36 futex_t f2
= FUTEX_INITIALIZER
;
39 void usage(char *prog
)
41 printf("Usage: %s\n", prog
);
42 printf(" -c Use color\n");
43 printf(" -h Display this help message\n");
44 printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
45 VQUIET
, VCRITICAL
, VINFO
);
48 void *blocking_child(void *arg
)
50 child_ret
= futex_wait(&f1
, f1
, NULL
, FUTEX_PRIVATE_FLAG
);
53 error("futex_wait\n", errno
);
55 return (void *)&child_ret
;
58 int main(int argc
, char *argv
[])
64 while ((c
= getopt(argc
, argv
, "chv:")) != -1) {
70 usage(basename(argv
[0]));
73 log_verbosity(atoi(optarg
));
76 usage(basename(argv
[0]));
82 ksft_print_msg("%s: Detect mismatched requeue_pi operations\n",
85 if (pthread_create(&child
, NULL
, blocking_child
, NULL
)) {
86 error("pthread_create\n", errno
);
90 /* Allow the child to block in the kernel. */
94 * The kernel should detect the waiter did not setup the
95 * q->requeue_pi_key and return -EINVAL. If it does not,
96 * it likely gave the lock to the child, which is now hung
99 ret
= futex_cmp_requeue_pi(&f1
, f1
, &f2
, 1, 0, FUTEX_PRIVATE_FLAG
);
101 if (errno
== EINVAL
) {
103 * The kernel correctly detected the mismatched
104 * requeue_pi target and aborted. Wake the child with
107 ret
= futex_wake(&f1
, 1, FUTEX_PRIVATE_FLAG
);
110 } else if (ret
< 0) {
111 error("futex_wake\n", errno
);
114 error("futex_wake did not wake the child\n", 0);
118 error("futex_cmp_requeue_pi\n", errno
);
121 } else if (ret
> 0) {
122 fail("futex_cmp_requeue_pi failed to detect the mismatch\n");
125 error("futex_cmp_requeue_pi found no waiters\n", 0);
129 pthread_join(child
, NULL
);
135 /* If the kernel crashes, we shouldn't return at all. */
136 print_result(TEST_NAME
, ret
);