Skip to content

linux-user: Qemu doesn't support `set_robust_list` used by glibc robust mutex implementation

Host environment

  • Operating system: Ubuntu 22.04.3 LTS
  • OS/kernel version: Linux 5.15.0-101-generic
  • Architecture: x86_64
  • QEMU flavor: qemu-riscv64-static
  • QEMU version: 8.2.2
  • QEMU command line: qemu-riscv64-static ./set_robust_list

Emulated/Virtualized environment

  • Operating system: Ubuntu 22.04.3 LTS
  • OS/kernel version: (userspace only)
  • Architecture: RISC-V 64

Description of problem

It seems that syscall set_robust_list is not implemented on Qemu for any Linux platform: link

Steps to reproduce

  1. Use below toy program set_robust_list.c and compile it without optimizations like:
    gcc -Wall -W -Wextra -std=gnu17 -pedantic set_robust_list.c -o set_robust_list
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <linux/futex.h>
#include <syscall.h>

int main(void)
{
#ifdef __NR_set_robust_list
    struct robust_list_head head;
    size_t len = sizeof(struct robust_list_head);

    // This call to set_robust_list function should fail
    int err = syscall(__NR_set_robust_list, &head, -1);
    if (err < 0)
        perror("1st set_robust_list error");
    else
        puts("1st set_robust_list OK");

    // This call to set_robust_list function should be sucessful
    err = syscall(__NR_set_robust_list, &head, len);
    if (err < 0)
        perror("2nd set_robust_list error");
    else
        puts("2nd set_robust_list OK");
#else
    puts("No set_robust_list support");
#endif
    exit(0);
}
  1. Run program on Qemu and compare output with output from x64 build. In my case it looks like:
root@AMDC4705:/runtime/set_robust_list# ./set_robust_list
1st set_robust_list error: Invalid argument
2nd set_robust_list OK
root@AMDC4705:/runtime/set_robust_list# ./set_robust_list-riscv
1st set_robust_list error: Function not implemented
2nd set_robust_list error: Function not implemented

Additional information

Working set_robust_list on Linux is quite important in context of named robust mutexes. In NPTL set_robust_list is used internally at ld.so initialization time to perform following check: link

When syscall fails, later pthread_mutex_init (with PTHREAD_MUTEX_ROBUST + PTHREAD_PROCESS_SHARED attributes) end up with ENOTSUP error link.

In dotnet we use robust mutexes for process synchronization purpose. Although there are other available techniques like named semaphores or file locks, robust mutexes are better locking option in case of unexpected process death.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information