qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtiofs: Relax DAX window protection for ppc
@ 2019-12-02 20:26 Fabiano Rosas
  2019-12-03 10:07 ` Dr. David Alan Gilbert
  0 siblings, 1 reply; 2+ messages in thread
From: Fabiano Rosas @ 2019-12-02 20:26 UTC (permalink / raw)
  To: virtio-fs; +Cc: qemu-ppc, qemu-devel, stefanha, dgilbert

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

Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>
---
 hw/virtio/vhost-user-fs.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c
index 455e97beea..92958797d0 100644
--- a/hw/virtio/vhost-user-fs.c
+++ b/hw/virtio/vhost-user-fs.c
@@ -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 *s
             continue;
         }
 
-        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;
-- 
2.23.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] virtiofs: Relax DAX window protection for ppc
  2019-12-02 20:26 [PATCH] virtiofs: Relax DAX window protection for ppc Fabiano Rosas
@ 2019-12-03 10:07 ` Dr. David Alan Gilbert
  0 siblings, 0 replies; 2+ messages in thread
From: Dr. David Alan Gilbert @ 2019-12-03 10:07 UTC (permalink / raw)
  To: Fabiano Rosas; +Cc: virtio-fs, qemu-ppc, qemu-devel, stefanha

* Fabiano Rosas (farosas@linux.ibm.com) wrote:
> 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
> 
> Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

Thanks, I'll do a pull after the tree opens again.

Dave

> ---
>  hw/virtio/vhost-user-fs.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c
> index 455e97beea..92958797d0 100644
> --- a/hw/virtio/vhost-user-fs.c
> +++ b/hw/virtio/vhost-user-fs.c
> @@ -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 *s
>              continue;
>          }
>  
> -        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;
> -- 
> 2.23.0
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-03 10:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-02 20:26 [PATCH] virtiofs: Relax DAX window protection for ppc Fabiano Rosas
2019-12-03 10:07 ` Dr. David Alan Gilbert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).