virtiofs: Relax DAX window protection for ppc
PATCH 1/1 virtiofs: Relax DAX window protection for ppc
When setting up the DAX window during the virtiofs driver probe inside the guest, the Linux arch-specific function arch_add_memory is called, which on ppc tries to do a cache flush [1] of the recently added memory. At this point the window is mmap'ed PROT_NONE by QEMU, which causes the following:
<snip>
[ 10.136703] virtio_fs virtio0: Cache len: 0x80000000 @ 0x210000000000 [ 10.165106] radix-mmu: Mapped 0xc000210000000000-0xc000210080000000 with 1.00 GiB pages
error: kvm run failed Bad address
NIP c000000000072350 LR c000000000072304 CTR 0000000001000000 XER 0000000020040000 CPU#0
MSR 8000000002009033 HID0 0000000000000000 HF 8000000000000000 iidx 3 didx 3 TB 00000000 00000000 DECR 0
GPR00 c000000000072304 c0000000fa383100 c000000001190300 0000000000000000 GPR04 0000000000000001 0000000000000000 c0000000fa383208 0000000000000080 GPR08 c000210000000000 000000008000007f 0000000001000000 6874697720303030 <snip>
The problem is the same for the memory device removal path (e.g. during filesystem unmount).
Since powerpc expects the memory to be accessible during device addition/removal, this patch makes the DAX window readable at creation and after virtio-fs unmap.
1 - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fb5924fd
--- hw/virtio/vhost-user-fs.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
hw/virtio/vhost-user-fs.c +14 -3
@@ -24,6 +24,16 @@#include "exec/address-spaces.h" #include "trace.h" +/* +* The powerpc kernel code expects the memory to be accessible during +* addition/removal. +*/ +#if defined(TARGET_PPC64 ) && defined(CONFIG_LINUX ) +#define DAX_WINDOW_PROT PROT_READ +#else +#define DAX_WINDOW_PROT PROT_NONE +#endif +uint64_t vhost_user_fs_slave_map (struct vhost_dev *dev,VhostUserFSSlaveMsg *sm,int fd) {
@@ -133,8 +143,8 @@ uint64_t vhost_user_fs_slave_unmap(struct vhost_dev *dev, VhostUserFSSlaveMsg *scontinue ; } - ptr =mmap (cache_host + sm->c_offset[i], sm->len[i], -PROT_NONE ,MAP_PRIVATE |MAP_ANONYMOUS |MAP_FIXED ,-1 ,0 ); + ptr =mmap (cache_host + sm->c_offset[i], sm->len[i],DAX_WINDOW_PROT , +MAP_PRIVATE |MAP_ANONYMOUS |MAP_FIXED ,-1 ,0 );if (ptr != (cache_host + sm->c_offset[i])) { res = -errno; fprintf(stderr, "%s: mmap failed (%s) [%d] %"
@@ -485,8 +495,9 @@ static void vuf_device_realize(DeviceState *dev, Error **errp)if (fs->conf.cache_size) {/* Anonymous, private memory is not counted as overcommit */ - cache_ptr =mmap (NULL , fs->conf.cache_size,PROT_NONE , + cache_ptr =mmap (NULL , fs->conf.cache_size,DAX_WINDOW_PROT ,MAP_ANONYMOUS |MAP_PRIVATE ,-1 ,0 ); +if (cache_ptr ==MAP_FAILED ) {error_setg (errp,"Unable to mmap blank cache" );return ;
Signature · 1 line
2.23.0
Quoted 21 lines · * Fabiano Rosas ([email protected]) wrote:
When setting up the DAX window during the virtiofs driver probe inside the guest, the Linux arch-specific function
arch_add_memoryis called, which on ppc tries to do a cache flush [1] of the recently added memory. At this point the window is mmap'edPROT_NONEby QEMU, which causes the following:<snip>
[ 10.136703] virtio_fs virtio0: Cache len: 0x80000000 @ 0x210000000000 [ 10.165106] radix-mmu: Mapped 0xc000210000000000-0xc000210080000000 with 1.00 GiB pageserror: kvm run failed Bad address
NIPc000000000072350LRc000000000072304CTR 0000000001000000 XER 0000000020040000 CPU#0
MSR 8000000002009033 HID0 0000000000000000 HF 8000000000000000 iidx 3 didx 3 TB 00000000 00000000 DECR 0
GPR00c000000000072304c0000000fa383100c0000000011903000000000000000000 GPR04 0000000000000001 0000000000000000c0000000fa3832080000000000000080 GPR08c000210000000000000000008000007f0000000001000000 6874697720303030 <snip>The problem is the same for the memory device removal path (e.g. during filesystem unmount).
Quoted 7 lines
Since powerpc expects the memory to be accessible during device addition/removal, this patch makes the DAX window readable at creation and after virtio-fs unmap.
1 - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fb5924fd
Signed-off-by Fabiano Rosas <[email protected]>
Thanks, I'll do a pull after the tree opens again.
Dave
Quoted 50 lines
--- hw/virtio/vhost-user-fs.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)hw/virtio/vhost-user-fs.c +14
-3@@ -24,6 +24,16 @@#include "exec/address-spaces.h" #include "trace.h" +/* +* The powerpc kernel code expects the memory to be accessible during +* addition/removal. +*/ +#if defined(TARGET_PPC64 ) && defined(CONFIG_LINUX ) +#define DAX_WINDOW_PROT PROT_READ +#else +#define DAX_WINDOW_PROT PROT_NONE +#endif +uint64_t vhost_user_fs_slave_map (struct vhost_dev *dev,VhostUserFSSlaveMsg *sm,int fd) {@@ -133,8 +143,8 @@ uint64_t vhost_user_fs_slave_unmap(struct vhost_dev *dev, VhostUserFSSlaveMsg *scontinue ; } - ptr =mmap (cache_host + sm->c_offset[i], sm->len[i], -PROT_NONE ,MAP_PRIVATE |MAP_ANONYMOUS |MAP_FIXED ,-1 ,0 ); + ptr =mmap (cache_host + sm->c_offset[i], sm->len[i],DAX_WINDOW_PROT , +MAP_PRIVATE |MAP_ANONYMOUS |MAP_FIXED ,-1 ,0 );if (ptr != (cache_host + sm->c_offset[i])) { res = -errno; fprintf(stderr, "%s: mmap failed (%s) [%d] %"@@ -485,8 +495,9 @@ static void vuf_device_realize(DeviceState *dev, Error **errp)if (fs->conf.cache_size) {/* Anonymous, private memory is not counted as overcommit */ - cache_ptr =mmap (NULL , fs->conf.cache_size,PROT_NONE , + cache_ptr =mmap (NULL , fs->conf.cache_size,DAX_WINDOW_PROT ,MAP_ANONYMOUS |MAP_PRIVATE ,-1 ,0 ); +if (cache_ptr ==MAP_FAILED ) {error_setg (errp,"Unable to mmap blank cache" );return ;Signature · 1 line
2.23.0
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK