qemu-user-static icon indicating copy to clipboard operation
qemu-user-static copied to clipboard

Function not implemented when using libaio

Open martin-g opened this issue 5 years ago • 5 comments

/kind question

Function not implemented when trying to use Linux libaio in foreign architecture.

Steps to reproduce the issue:

  1. On x86_64 machine register QEMU:

    docker run -it --rm --privileged multiarch/qemu-user-static --reset --credential yes --persistent yes

  2. Start a Docker image with foreign CPU architecture, e.g. aarch64

    docker run -it arm64v8/centos:8 bash

  3. Install GCC and libaio

    yum install gcc libaio libaio-devel

  4. Compile the following C program

#include <stdio.h>
#include <errno.h>
#include <libaio.h>
#include <stdlib.h>

struct io_control {
    io_context_t ioContext;
};

int main() {
    int queueSize = 10;

    struct io_control * theControl = (struct io_control *) malloc(sizeof(struct io_control));
    if (theControl == NULL) {
        printf("theControl is NULL");
        return 123;
    }

    int res = io_queue_init(queueSize, &theControl->ioContext);
    io_queue_release(theControl->ioContext);
    free(theControl);
    printf("res is: %d", res);
}
 cat > test.c
    [PASTE]
  ^D

  gcc test.c -o out -laio && ./out

When executed on aarch64 machine or on x86_64 Docker image (e.g. centos:8) it prints res is: 0, i.e. it successfully initialized a LibAIO queue.

But when executed on Docker image with foreign/emulated CPU architecture it prints res is: -38 (ENOSYS). man io_queue_init says that error ENOSYS is returned when "Not implemented."

Environment:

  • QEMU version: I am not sure how to get that information. I use fresh download of multiarch/qemu-user-static Docker image
  • Container application: Docker

Output of docker version

Client:
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.13.8
 Git commit:        afacb8b7f0
 Built:             Wed Mar 11 23:42:35 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.8
  Git commit:       afacb8b7f0
  Built:            Wed Mar 11 22:48:33 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.3.3-0ubuntu2
  GitCommit:        
 runc:
  Version:          spec: 1.0.1-dev
  GitCommit:        
 docker-init:
  Version:          0.18.0
  GitCommit:        

Additional information optionally:

Same happens with Ubuntu (arm64v8/ubuntu:focal).

Any idea what could be the problem ? I've googled a lot but I wasn't able to find any problems related to libaio on QEMU.

Thank you!

martin-g avatar Jun 18 '20 12:06 martin-g

I've tried to strace it but :

usr/bin/strace: ptrace(PTRACE_TRACEME, ...): Function not implemented
/usr/bin/strace: PTRACE_SETOPTIONS: Function not implemented
/usr/bin/strace: detach: waitpid(112): No child processes
/usr/bin/strace: Process 112 detached

Here are the steps to reproduce the problem with strace:

  1. docker run --rm -it --security-opt seccomp:unconfined --security-opt apparmor:unconfined --privileged --cap-add ALL arm64v8/centos:8 bash Note: I used --privileged, disabled seccomp and apparmor, and added all capabilities
  2. yum install -y strace
  3. strace echo Test

Disabling security solves the "Permission denied" problem but then comes the "Not implemented" one.

martin-g avatar Jun 19 '20 13:06 martin-g

@martin-g, this seems to be a missing feature upstream. I suggest to open a report in https://bugs.launchpad.net/qemu.

umarcor avatar Jun 20 '20 16:06 umarcor

Thanks for the response, @umarcor !

One question before I do that: How to find out which version of QEMU is being used by multiarch/qemu-user-static ?

martin-g avatar Jun 21 '20 17:06 martin-g

@martin-g, see https://github.com/multiarch/qemu-user-static/blob/master/.travis.yml#L24-L28

umarcor avatar Jun 22 '20 21:06 umarcor

https://bugs.launchpad.net/qemu/+bug/1884719

martin-g avatar Jun 23 '20 07:06 martin-g