1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
/* SPDX-License-Identifier: MIT */
/*
* Description: Run a failing futex wait command followed up a POLL_ADD
* on a fifo.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <linux/futex.h>
#include <linux/poll.h>
#include <unistd.h>
#include "liburing.h"
#include "helpers.h"
#ifndef FUTEX2_SIZE_U32
#define FUTEX2_SIZE_U32 0x02
#endif
int main(int argc, char *argv[])
{
struct io_uring_sqe *sqe;
struct io_uring_cqe *cqe;
struct io_uring ring;
int ret, pipe;
if (argc > 1)
return T_EXIT_SKIP;
/*
* Setup a FIFO for polling. FIFOs are interesting because they end
* up using two wait queue entries for poll, hitting double poll
* in io_uring.
*/
ret = mkfifo("fifo", 0644);
if (ret < 0) {
perror("mkfifo");
return 1;
}
pipe = open("fifo", O_RDWR);
if (pipe < 0) {
perror("open fifo");
ret = T_EXIT_FAIL;
goto err;
}
ret = io_uring_queue_init(64, &ring, 0);
if (ret) {
ret = T_EXIT_FAIL;
goto err;
}
/*
* Submit invalid futex wait, will error inline.
*/
sqe = io_uring_get_sqe(&ring);
io_uring_prep_futex_wait(sqe, NULL, 0, FUTEX_BITSET_MATCH_ANY, FUTEX2_SIZE_U32, 0);
sqe->user_data = 1;
io_uring_submit(&ring);
ret = io_uring_wait_cqe(&ring, &cqe);
if (ret) {
fprintf(stderr, "wait %d \n", ret);
ret = T_EXIT_FAIL;
goto err_ring;
}
if (cqe->res != -EFAULT) {
if (cqe->res == -EINVAL) {
ret = T_EXIT_SKIP;
goto err_ring;
}
fprintf(stderr, "Unexpected futex return: %d\n", cqe->res);
ret = T_EXIT_FAIL;
goto err_ring;
}
io_uring_cqe_seen(&ring, cqe);
ret = io_uring_register_files(&ring, &pipe, 1);
if (ret < 0) {
fprintf(stderr, "io_uring register files failed \n");
ret = T_EXIT_FAIL;
goto err_ring;
}
/*
* Submit poll request for POLLIN on the fifo
*/
sqe = io_uring_get_sqe(&ring);
io_uring_prep_poll_add(sqe, 0, POLLIN);
sqe->flags |= IOSQE_FIXED_FILE;
sqe->user_data = 2;
io_uring_submit(&ring);
/*
* Trigger the poll request
*/
ret = write(pipe, "FIFO test\n", 10);
if (ret < 0)
perror("fifo write");
ret = io_uring_wait_cqe(&ring, &cqe);
if (ret) {
fprintf(stderr, "wait %d \n", ret);
ret = T_EXIT_FAIL;
}
io_uring_cqe_seen(&ring, cqe);
err_ring:
io_uring_queue_exit(&ring);
err:
if (pipe != -1)
close(pipe);
unlink("fifo");
return ret;
}
|