ignore-single-mmap.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "../config-host.h"
  2. /* SPDX-License-Identifier: MIT */
  3. /*
  4. * 6.10-rc merge window had a bug where the rewritten mmap support caused
  5. * rings allocated with > 1 page, but asking for smaller mappings, would
  6. * cause -EFAULT to be returned rather than a successful map. This hit
  7. * applications either using an ancient liburing with IORING_FEAT_SINGLE_MMAP
  8. * support, or application just ignoring that feature flag and still doing
  9. * 3 mmap operations to map the ring.
  10. */
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <unistd.h>
  14. #include "../src/syscall.h"
  15. #include "liburing.h"
  16. #include "helpers.h"
  17. #define ENTRIES 128
  18. int main(int argc, char *argv[])
  19. {
  20. struct io_uring_params p = { };
  21. void *ptr;
  22. int fd;
  23. if (argc > 1)
  24. return T_EXIT_SKIP;
  25. fd = __sys_io_uring_setup(ENTRIES, &p);
  26. if (fd < 0)
  27. return T_EXIT_SKIP;
  28. if (!(p.features & IORING_FEAT_SINGLE_MMAP)) {
  29. close(fd);
  30. return T_EXIT_SKIP;
  31. }
  32. ptr = __sys_mmap(0, ENTRIES * sizeof(unsigned), PROT_READ | PROT_WRITE,
  33. MAP_SHARED | MAP_POPULATE, fd,
  34. IORING_OFF_SQ_RING);
  35. if (!IS_ERR(ptr)) {
  36. close(fd);
  37. return T_EXIT_PASS;
  38. }
  39. fprintf(stderr, "ring sqe array mmap: %d\n", PTR_ERR(ptr));
  40. return T_EXIT_FAIL;
  41. }