Skip to contentSkip to conversation

Failure as Operation not permitted on aarch64 machine

Virtio-fs Masayoshi Mizuma 2 participants 4 messages Jul 19, 2019 – Jul 26, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hello,

I would appreciate if you could help me to resolve following failure.

I tried to use virtio-fs on aarch64 [1], however, qemu [2] failed to boot as Operation not permitted.

---

  # ./virtiofsd -o vhost_user_socket=/tmp/vhostqemu -o source=/tmp/share -o cache=none &
  # qemu-system-aarch64 -machine virt,accel=kvm,gic-version=3 -cpu host -smp 8 ... [3]

UEFI firmware starting.
kvm_set_phys_mem: error registering slot: Operation not permitted
---

Quoted 1 line

From the ftrace log, the error happened because kvm_set_user_memory_region()

returned as -1 (EPERM).

---
qemu-system-aar-28381 [003] .... 6683.601097: tracing_mark_write: kvm_set_user_memory Slot#3 flags=0x0 gpa=0x8000000000 size=0x40000000 ua=0xfffe0ba00000 ret=-1
---

kvm_set_user_memory_region() returned -1 because kvm_arch_prepare_memory_region() in kernel returned as -EPERM.

   ---
   int kvm_arch_prepare_memory_region(struct kvm *kvm,
                                   struct kvm_memory_slot *memslot,
                                   const struct kvm_userspace_memory_region *mem,
                                   enum kvm_mr_change change)
   {
   ...
                   if (writable && !(vma->vm_flags & VM_WRITE)) {
                           ret = -EPERM;
                           break;
                   }
   ---

Actually, the /proc/PID/maps showed ua=0xfffe0ba00000 didn't have PROT_WRITE.

---
...
014b0000-014f0000 rw-p 00000000 00:00 0
1c840000-1d470000 rw-p 00000000 00:00 0 [heap]
fffe0ba00000-fffe4ba00000 ---p 00000000 00:00 0 <=== fffe4ba00000-fffe4ba10000 ---p 00000000 00:00 0 fffe4bc00000-fffe4fc00000 rw-p 00000000 00:00 0 fffe4fc00000-fffe4fc10000 ---p 00000000 00:00 0 fffe4fe00000-fffe53e00000 rw-p 00000000 00:00 0 fffe53e00000-fffe53e10000 ---p 00000000 00:00 0
...
---

I'm not sure why ua=0xfffe0ba00000 didn't have PROT_WRITE because the memory was allocated by qemu_anon_ram_alloc() and it should set PROT_READ | PROT_WRITE.

---
qemu-system-aar-28372 [022] .... 6674.795027: tracing_mark_write: qemu_anon_ram_alloc size 1073741824 ptr 0xfffe0ba00000
---

qemu boots successfully if I remove "-device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=myfs", so I suppose the option is related to the failure...

[1]: host kernel is 5.2.0.
guest kernel is https://github.com/rhvgoyal/linux/, branch: virtio-fs-dev-5.1.

[2]: I got the qemu from:
https://gitlab.com/virtio-fs/qemu.git

[3]: Qemu option is:

$QEMU -machine virt,accel=kvm,gic-version=3 \
	-cpu host \
	-smp 8 \
        -m 4G,maxmem=4G \
	-object memory-backend-file,id=mem,size=4G,mem-path=/dev/shm,share=on \
	-numa node,memdev=mem \
        -drive file=/usr/share/AAVMF/AAVMF_CODE.fd,if=pflash,format=raw,unit=0,readonly=on \
        -drive file=$VARS,if=pflash,format=raw,unit=1 \
	-chardev socket,id=char0,path=/tmp/vhostqemu \
	-device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=myfs \
	-nographic \
	-serial mon:stdio \
	--trace events=/tmp/qemu-trace-events \
	-drive if=virtio,file=/var/lib/libvirt/images/guest.qcow2

Thanks,
Masa

#1 lore raw
Quoted 1 line · * Masayoshi Mizuma ([email protected]) wrote:

Hello,

Hi Masa,

Quoted 15 lines

I would appreciate if you could help me to resolve following failure.

I tried to use virtio-fs on aarch64 [1], however, qemu [2] failed to boot as Operation not permitted.

---

  # ./virtiofsd -o vhost_user_socket=/tmp/vhostqemu -o source=/tmp/share -o cache=none &
  # qemu-system-aarch64 -machine virt,accel=kvm,gic-version=3 -cpu host -smp 8 ... [3]

UEFI firmware starting.
kvm_set_phys_mem: error registering slot: Operation not permitted
---

Quoted 1 line

From the ftrace log, the error happened because kvm_set_user_memory_region()

Quoted 8 lines

returned as -1 (EPERM).

---
qemu-system-aar-28381 [003] .... 6683.601097: tracing_mark_write: kvm_set_user_memory Slot#3 flags=0x0 gpa=0x8000000000 size=0x40000000 ua=0xfffe0ba00000 ret=-1
---

kvm_set_user_memory_region() returned -1 because kvm_arch_prepare_memory_region() in kernel returned as -EPERM.

Right, yes we know this is a problem on aarch64; for aarch we disable the DAX mode; if you check out our -dev branches and apply the following hack to the kernel:

fs/fuse/virtio_fs.c +1 -1
index 3f3c018571ee..60a9724f9c71 100644
@@ -541,7 +541,7 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs)
                                           (u8)VIRTIO_FS_SHMCAP_ID_CACHE);
        if (!have_cache) {
                dev_err(&vdev->dev, "%s: No cache capability\n", __func__);
-               return -ENXIO;
+               return 0;
        } else {
                dev_notice(&vdev->dev, "Cache len: 0x%llx @ 0x%llx\n",
                           cache_reg.len, cache_reg.addr);

and start the qemu with:
-device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=myfs,cache-size=0

it should start up for you.

Quoted 28 lines
   ---
   int kvm_arch_prepare_memory_region(struct kvm *kvm,
                                   struct kvm_memory_slot *memslot,
                                   const struct kvm_userspace_memory_region *mem,
                                   enum kvm_mr_change change)
   {
   ...
                   if (writable && !(vma->vm_flags & VM_WRITE)) {
                           ret = -EPERM;
                           break;
                   }
   ---

Actually, the /proc/PID/maps showed ua=0xfffe0ba00000 didn't have PROT_WRITE.

---
...
014b0000-014f0000 rw-p 00000000 00:00 0
1c840000-1d470000 rw-p 00000000 00:00 0 [heap]
fffe0ba00000-fffe4ba00000 ---p 00000000 00:00 0 <=== fffe4ba00000-fffe4ba10000 ---p 00000000 00:00 0 fffe4bc00000-fffe4fc00000 rw-p 00000000 00:00 0 fffe4fc00000-fffe4fc10000 ---p 00000000 00:00 0 fffe4fe00000-fffe53e00000 rw-p 00000000 00:00 0 fffe53e00000-fffe53e10000 ---p 00000000 00:00 0
...
---

Quoted 2 lines

I'm not sure why ua=0xfffe0ba00000 didn't have PROT_WRITE because the memory was allocated by qemu_anon_ram_alloc() and it should set PROT_READ | PROT_WRITE.

Because we explicitly mprotect it later (and in current versions we allocate with PROT_NONE) - on x86 this works fine, but aarch doesn't like it; we've not quite figured the rules why yet.

Dave

Quoted 32 lines

---
qemu-system-aar-28372 [022] .... 6674.795027: tracing_mark_write: qemu_anon_ram_alloc size 1073741824 ptr 0xfffe0ba00000
---

qemu boots successfully if I remove "-device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=myfs", so I suppose the option is related to the failure...

[1]: host kernel is 5.2.0.
guest kernel is https://github.com/rhvgoyal/linux/, branch: virtio-fs-dev-5.1.

[2]: I got the qemu from:
https://gitlab.com/virtio-fs/qemu.git

[3]: Qemu option is:

$QEMU -machine virt,accel=kvm,gic-version=3 \
	-cpu host \
	-smp 8 \
        -m 4G,maxmem=4G \
	-object memory-backend-file,id=mem,size=4G,mem-path=/dev/shm,share=on \
	-numa node,memdev=mem \
        -drive file=/usr/share/AAVMF/AAVMF_CODE.fd,if=pflash,format=raw,unit=0,readonly=on \
        -drive file=$VARS,if=pflash,format=raw,unit=1 \
	-chardev socket,id=char0,path=/tmp/vhostqemu \
	-device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=myfs \
	-nographic \
	-serial mon:stdio \
	--trace events=/tmp/qemu-trace-events \
	-drive if=virtio,file=/var/lib/libvirt/images/guest.qcow2
Quoted 7 lines

Thanks,
Masa

_______________________________________________
Virtio-fs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virtio-fs

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#2 lore raw

Hi Dave,

Quoted 48 lines · Dr. David Alan Gilbert
Quoted 1 line · * Masayoshi Mizuma ([email protected]) wrote:

Hello,

Hi Masa,

Quoted 15 lines

I would appreciate if you could help me to resolve following failure.

I tried to use virtio-fs on aarch64 [1], however, qemu [2] failed to boot as Operation not permitted.

---

  # ./virtiofsd -o vhost_user_socket=/tmp/vhostqemu -o source=/tmp/share -o cache=none &
  # qemu-system-aarch64 -machine virt,accel=kvm,gic-version=3 -cpu host -smp 8 ... [3]

UEFI firmware starting.
kvm_set_phys_mem: error registering slot: Operation not permitted
---

Quoted 1 line

From the ftrace log, the error happened because kvm_set_user_memory_region()

Quoted 8 lines

returned as -1 (EPERM).

---
qemu-system-aar-28381 [003] .... 6683.601097: tracing_mark_write: kvm_set_user_memory Slot#3 flags=0x0 gpa=0x8000000000 size=0x40000000 ua=0xfffe0ba00000 ret=-1
---

kvm_set_user_memory_region() returned -1 because kvm_arch_prepare_memory_region() in kernel returned as -EPERM.

Right, yes we know this is a problem on aarch64; for aarch we disable the DAX mode; if you check out our -dev branches and apply the following hack to the kernel:

fs/fuse/virtio_fs.c +1 -1
index 3f3c018571ee..60a9724f9c71 100644
@@ -541,7 +541,7 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs)
                                           (u8)VIRTIO_FS_SHMCAP_ID_CACHE);
        if (!have_cache) {
                dev_err(&vdev->dev, "%s: No cache capability\n", __func__);
-               return -ENXIO;
+               return 0;
        } else {
                dev_notice(&vdev->dev, "Cache len: 0x%llx @ 0x%llx\n",
                           cache_reg.len, cache_reg.addr);
Quoted 4 lines

and start the qemu with:
-device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=myfs,cache-size=0

it should start up for you.

Thanks and the cache-size=0 option works for me!
qemu boots successfully and I can mount the myfs.

Thanks!
Masa

Quoted 80 lines
Quoted 29 lines
   ---
   int kvm_arch_prepare_memory_region(struct kvm *kvm,
                                   struct kvm_memory_slot *memslot,
                                   const struct kvm_userspace_memory_region *mem,
                                   enum kvm_mr_change change)
   {
   ...
                   if (writable && !(vma->vm_flags & VM_WRITE)) {
                           ret = -EPERM;
                           break;
                   }
   ---

Actually, the /proc/PID/maps showed ua=0xfffe0ba00000 didn't have PROT_WRITE.

---
...
014b0000-014f0000 rw-p 00000000 00:00 0
1c840000-1d470000 rw-p 00000000 00:00 0 [heap]
fffe0ba00000-fffe4ba00000 ---p 00000000 00:00 0 <=== fffe4ba00000-fffe4ba10000 ---p 00000000 00:00 0 fffe4bc00000-fffe4fc00000 rw-p 00000000 00:00 0 fffe4fc00000-fffe4fc10000 ---p 00000000 00:00 0 fffe4fe00000-fffe53e00000 rw-p 00000000 00:00 0 fffe53e00000-fffe53e10000 ---p 00000000 00:00 0
...
---

Quoted 2 lines

I'm not sure why ua=0xfffe0ba00000 didn't have PROT_WRITE because the memory was allocated by qemu_anon_ram_alloc() and it should set PROT_READ | PROT_WRITE.

Because we explicitly mprotect it later (and in current versions we allocate with PROT_NONE) - on x86 this works fine, but aarch doesn't like it; we've not quite figured the rules why yet.

Dave

Quoted 32 lines

---
qemu-system-aar-28372 [022] .... 6674.795027: tracing_mark_write: qemu_anon_ram_alloc size 1073741824 ptr 0xfffe0ba00000
---

qemu boots successfully if I remove "-device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=myfs", so I suppose the option is related to the failure...

[1]: host kernel is 5.2.0.
guest kernel is https://github.com/rhvgoyal/linux/, branch: virtio-fs-dev-5.1.

[2]: I got the qemu from:
https://gitlab.com/virtio-fs/qemu.git

[3]: Qemu option is:

$QEMU -machine virt,accel=kvm,gic-version=3 \
	-cpu host \
	-smp 8 \
        -m 4G,maxmem=4G \
	-object memory-backend-file,id=mem,size=4G,mem-path=/dev/shm,share=on \
	-numa node,memdev=mem \
        -drive file=/usr/share/AAVMF/AAVMF_CODE.fd,if=pflash,format=raw,unit=0,readonly=on \
        -drive file=$VARS,if=pflash,format=raw,unit=1 \
	-chardev socket,id=char0,path=/tmp/vhostqemu \
	-device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=myfs \
	-nographic \
	-serial mon:stdio \
	--trace events=/tmp/qemu-trace-events \
	-drive if=virtio,file=/var/lib/libvirt/images/guest.qcow2
Quoted 7 lines

Thanks,
Masa

_______________________________________________
Virtio-fs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virtio-fs

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#3 lore raw
Quoted 51 lines · * Masayoshi Mizuma ([email protected]) wrote:

Hi Dave,

Quoted 48 lines · Dr. David Alan Gilbert
Quoted 1 line · * Masayoshi Mizuma ([email protected]) wrote:

Hello,

Hi Masa,

Quoted 15 lines

I would appreciate if you could help me to resolve following failure.

I tried to use virtio-fs on aarch64 [1], however, qemu [2] failed to boot as Operation not permitted.

---

  # ./virtiofsd -o vhost_user_socket=/tmp/vhostqemu -o source=/tmp/share -o cache=none &
  # qemu-system-aarch64 -machine virt,accel=kvm,gic-version=3 -cpu host -smp 8 ... [3]

UEFI firmware starting.
kvm_set_phys_mem: error registering slot: Operation not permitted
---

Quoted 1 line

From the ftrace log, the error happened because kvm_set_user_memory_region()

Quoted 8 lines

returned as -1 (EPERM).

---
qemu-system-aar-28381 [003] .... 6683.601097: tracing_mark_write: kvm_set_user_memory Slot#3 flags=0x0 gpa=0x8000000000 size=0x40000000 ua=0xfffe0ba00000 ret=-1
---

kvm_set_user_memory_region() returned -1 because kvm_arch_prepare_memory_region() in kernel returned as -EPERM.

Right, yes we know this is a problem on aarch64; for aarch we disable the DAX mode; if you check out our -dev branches and apply the following hack to the kernel:

fs/fuse/virtio_fs.c +1 -1
index 3f3c018571ee..60a9724f9c71 100644
@@ -541,7 +541,7 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs)
                                           (u8)VIRTIO_FS_SHMCAP_ID_CACHE);
        if (!have_cache) {
                dev_err(&vdev->dev, "%s: No cache capability\n", __func__);
-               return -ENXIO;
+               return 0;
        } else {
                dev_notice(&vdev->dev, "Cache len: 0x%llx @ 0x%llx\n",
                           cache_reg.len, cache_reg.addr);
Quoted 7 lines
Quoted 4 lines

and start the qemu with:
-device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=myfs,cache-size=0

it should start up for you.

Thanks and the cache-size=0 option works for me!
qemu boots successfully and I can mount the myfs.

That's great; our dev world has that fix in, so it'll be in our next release as well.

Dave

Quoted 83 lines

Thanks!
Masa

Quoted 80 lines
Quoted 29 lines
   ---
   int kvm_arch_prepare_memory_region(struct kvm *kvm,
                                   struct kvm_memory_slot *memslot,
                                   const struct kvm_userspace_memory_region *mem,
                                   enum kvm_mr_change change)
   {
   ...
                   if (writable && !(vma->vm_flags & VM_WRITE)) {
                           ret = -EPERM;
                           break;
                   }
   ---

Actually, the /proc/PID/maps showed ua=0xfffe0ba00000 didn't have PROT_WRITE.

---
...
014b0000-014f0000 rw-p 00000000 00:00 0
1c840000-1d470000 rw-p 00000000 00:00 0 [heap]
fffe0ba00000-fffe4ba00000 ---p 00000000 00:00 0 <=== fffe4ba00000-fffe4ba10000 ---p 00000000 00:00 0 fffe4bc00000-fffe4fc00000 rw-p 00000000 00:00 0 fffe4fc00000-fffe4fc10000 ---p 00000000 00:00 0 fffe4fe00000-fffe53e00000 rw-p 00000000 00:00 0 fffe53e00000-fffe53e10000 ---p 00000000 00:00 0
...
---

Quoted 2 lines

I'm not sure why ua=0xfffe0ba00000 didn't have PROT_WRITE because the memory was allocated by qemu_anon_ram_alloc() and it should set PROT_READ | PROT_WRITE.

Because we explicitly mprotect it later (and in current versions we allocate with PROT_NONE) - on x86 this works fine, but aarch doesn't like it; we've not quite figured the rules why yet.

Dave

Quoted 32 lines

---
qemu-system-aar-28372 [022] .... 6674.795027: tracing_mark_write: qemu_anon_ram_alloc size 1073741824 ptr 0xfffe0ba00000
---

qemu boots successfully if I remove "-device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=myfs", so I suppose the option is related to the failure...

[1]: host kernel is 5.2.0.
guest kernel is https://github.com/rhvgoyal/linux/, branch: virtio-fs-dev-5.1.

[2]: I got the qemu from:
https://gitlab.com/virtio-fs/qemu.git

[3]: Qemu option is:

$QEMU -machine virt,accel=kvm,gic-version=3 \
	-cpu host \
	-smp 8 \
        -m 4G,maxmem=4G \
	-object memory-backend-file,id=mem,size=4G,mem-path=/dev/shm,share=on \
	-numa node,memdev=mem \
        -drive file=/usr/share/AAVMF/AAVMF_CODE.fd,if=pflash,format=raw,unit=0,readonly=on \
        -drive file=$VARS,if=pflash,format=raw,unit=1 \
	-chardev socket,id=char0,path=/tmp/vhostqemu \
	-device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=myfs \
	-nographic \
	-serial mon:stdio \
	--trace events=/tmp/qemu-trace-events \
	-drive if=virtio,file=/var/lib/libvirt/images/guest.qcow2
Quoted 7 lines

Thanks,
Masa

_______________________________________________
Virtio-fs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virtio-fs

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK