QEMU-Devel Archive on lore.kernel.org
 help / color / 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	[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, back to index

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

QEMU-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/qemu-devel/0 qemu-devel/git/0.git
	git clone --mirror https://lore.kernel.org/qemu-devel/1 qemu-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 qemu-devel qemu-devel/ https://lore.kernel.org/qemu-devel \
		qemu-devel@nongnu.org
	public-inbox-index qemu-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.nongnu.qemu-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git