qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v1 0/2] s390x/kvm: legacy_s390_alloc() fixes
@ 2018-06-28 11:38 David Hildenbrand
  2018-06-28 11:38 ` [Qemu-devel] [PATCH v1 1/2] s390x/kvm: legacy_s390_alloc() only supports one allocation David Hildenbrand
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: David Hildenbrand @ 2018-06-28 11:38 UTC (permalink / raw)
  To: qemu-s390x
  Cc: qemu-devel, Richard Henderson, Alexander Graf, Cornelia Huck,
	Christian Borntraeger, Thomas Huth, David Hildenbrand

Two patches for legacy_s390_alloc(), only relevant under old z/VM versions.

Patch #1 is relevant when trying to allocate memory for more than one
memory region. Patch #2 is only for completeness, to make it behave
more similar to qemu_anon_ram_alloc().

David Hildenbrand (2):
  s390x/kvm: legacy_s390_alloc() only supports one allocation
  s390x/kvm: indicate alignment in legacy_s390_alloc()

 target/s390x/kvm.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

-- 
2.17.1

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

* [Qemu-devel] [PATCH v1 1/2] s390x/kvm: legacy_s390_alloc() only supports one allocation
  2018-06-28 11:38 [Qemu-devel] [PATCH v1 0/2] s390x/kvm: legacy_s390_alloc() fixes David Hildenbrand
@ 2018-06-28 11:38 ` David Hildenbrand
  2018-06-28 12:42   ` [Qemu-devel] [qemu-s390x] " Christian Borntraeger
  2018-06-28 11:38 ` [Qemu-devel] [PATCH v1 2/2] s390x/kvm: indicate alignment in legacy_s390_alloc() David Hildenbrand
  2018-06-28 15:22 ` [Qemu-devel] [PATCH v1 0/2] s390x/kvm: legacy_s390_alloc() fixes Cornelia Huck
  2 siblings, 1 reply; 5+ messages in thread
From: David Hildenbrand @ 2018-06-28 11:38 UTC (permalink / raw)
  To: qemu-s390x
  Cc: qemu-devel, Richard Henderson, Alexander Graf, Cornelia Huck,
	Christian Borntraeger, Thomas Huth, David Hildenbrand

We always allocate at a fixed address, a second allocation can therefore
of course never work. We would simply overwrite mappings.

This can e.g. happen in s390_memory_init(), if trying to allocate more
than > 8TB. Let's just bail out, as there is no need for supporting it
(legacy handling for z/VM).

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 target/s390x/kvm.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
index ac370da281..bbac3454e3 100644
--- a/target/s390x/kvm.c
+++ b/target/s390x/kvm.c
@@ -752,12 +752,20 @@ int kvm_s390_mem_op(S390CPU *cpu, vaddr addr, uint8_t ar, void *hostbuf,
  */
 static void *legacy_s390_alloc(size_t size, uint64_t *align, bool shared)
 {
-    void *mem;
+    static void *mem;
+
+    if (mem) {
+        /* we only support one allocation, which is enough for initial ram */
+        return NULL;
+    }
 
     mem = mmap((void *) 0x800000000ULL, size,
                PROT_EXEC|PROT_READ|PROT_WRITE,
                MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
-    return mem == MAP_FAILED ? NULL : mem;
+    if (mem == MAP_FAILED) {
+        mem = NULL;
+    }
+    return mem;
 }
 
 static uint8_t const *sw_bp_inst;
-- 
2.17.1

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

* [Qemu-devel] [PATCH v1 2/2] s390x/kvm: indicate alignment in legacy_s390_alloc()
  2018-06-28 11:38 [Qemu-devel] [PATCH v1 0/2] s390x/kvm: legacy_s390_alloc() fixes David Hildenbrand
  2018-06-28 11:38 ` [Qemu-devel] [PATCH v1 1/2] s390x/kvm: legacy_s390_alloc() only supports one allocation David Hildenbrand
@ 2018-06-28 11:38 ` David Hildenbrand
  2018-06-28 15:22 ` [Qemu-devel] [PATCH v1 0/2] s390x/kvm: legacy_s390_alloc() fixes Cornelia Huck
  2 siblings, 0 replies; 5+ messages in thread
From: David Hildenbrand @ 2018-06-28 11:38 UTC (permalink / raw)
  To: qemu-s390x
  Cc: qemu-devel, Richard Henderson, Alexander Graf, Cornelia Huck,
	Christian Borntraeger, Thomas Huth, David Hildenbrand

Let's do this for completeness reason, although we don't support e.g.
PCDIMM/NVDIMM, which would use the alignment for placing the memory
region in guest physical memory. But maybe someday we would want to
support something like this - then we don't forget about this if
allowing multiple allocations in legacy_s390_alloc().

Use the same alignment as we would set in qemu_anon_ram_alloc(). Our
fixed address satisfies this alignment (1MB). This implicitly sets the
alignment of the underlying memory region.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 target/s390x/kvm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
index bbac3454e3..22e13080a5 100644
--- a/target/s390x/kvm.c
+++ b/target/s390x/kvm.c
@@ -765,6 +765,9 @@ static void *legacy_s390_alloc(size_t size, uint64_t *align, bool shared)
     if (mem == MAP_FAILED) {
         mem = NULL;
     }
+    if (mem && align) {
+        *align = QEMU_VMALLOC_ALIGN;
+    }
     return mem;
 }
 
-- 
2.17.1

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

* Re: [Qemu-devel] [qemu-s390x] [PATCH v1 1/2] s390x/kvm: legacy_s390_alloc() only supports one allocation
  2018-06-28 11:38 ` [Qemu-devel] [PATCH v1 1/2] s390x/kvm: legacy_s390_alloc() only supports one allocation David Hildenbrand
@ 2018-06-28 12:42   ` Christian Borntraeger
  0 siblings, 0 replies; 5+ messages in thread
From: Christian Borntraeger @ 2018-06-28 12:42 UTC (permalink / raw)
  To: David Hildenbrand, qemu-s390x
  Cc: Thomas Huth, Cornelia Huck, Alexander Graf, qemu-devel,
	Richard Henderson



On 06/28/2018 01:38 PM, David Hildenbrand wrote:
> We always allocate at a fixed address, a second allocation can therefore
> of course never work. We would simply overwrite mappings.
> 
> This can e.g. happen in s390_memory_init(), if trying to allocate more
> than > 8TB. Let's just bail out, as there is no need for supporting it
> (legacy handling for z/VM).
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>

> ---
>  target/s390x/kvm.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
> index ac370da281..bbac3454e3 100644
> --- a/target/s390x/kvm.c
> +++ b/target/s390x/kvm.c
> @@ -752,12 +752,20 @@ int kvm_s390_mem_op(S390CPU *cpu, vaddr addr, uint8_t ar, void *hostbuf,
>   */
>  static void *legacy_s390_alloc(size_t size, uint64_t *align, bool shared)
>  {
> -    void *mem;
> +    static void *mem;
> +
> +    if (mem) {
> +        /* we only support one allocation, which is enough for initial ram */
> +        return NULL;
> +    }
>  
>      mem = mmap((void *) 0x800000000ULL, size,
>                 PROT_EXEC|PROT_READ|PROT_WRITE,
>                 MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
> -    return mem == MAP_FAILED ? NULL : mem;
> +    if (mem == MAP_FAILED) {
> +        mem = NULL;
> +    }
> +    return mem;
>  }
>  
>  static uint8_t const *sw_bp_inst;
> 

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

* Re: [Qemu-devel] [PATCH v1 0/2] s390x/kvm: legacy_s390_alloc() fixes
  2018-06-28 11:38 [Qemu-devel] [PATCH v1 0/2] s390x/kvm: legacy_s390_alloc() fixes David Hildenbrand
  2018-06-28 11:38 ` [Qemu-devel] [PATCH v1 1/2] s390x/kvm: legacy_s390_alloc() only supports one allocation David Hildenbrand
  2018-06-28 11:38 ` [Qemu-devel] [PATCH v1 2/2] s390x/kvm: indicate alignment in legacy_s390_alloc() David Hildenbrand
@ 2018-06-28 15:22 ` Cornelia Huck
  2 siblings, 0 replies; 5+ messages in thread
From: Cornelia Huck @ 2018-06-28 15:22 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-s390x, qemu-devel, Richard Henderson, Alexander Graf,
	Christian Borntraeger, Thomas Huth

On Thu, 28 Jun 2018 13:38:15 +0200
David Hildenbrand <david@redhat.com> wrote:

> Two patches for legacy_s390_alloc(), only relevant under old z/VM versions.

Those teddy bears are really looking a bit scruffy... but the patches
look sane.

> 
> Patch #1 is relevant when trying to allocate memory for more than one
> memory region. Patch #2 is only for completeness, to make it behave
> more similar to qemu_anon_ram_alloc().
> 
> David Hildenbrand (2):
>   s390x/kvm: legacy_s390_alloc() only supports one allocation
>   s390x/kvm: indicate alignment in legacy_s390_alloc()
> 
>  target/s390x/kvm.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 

Thanks, applied.

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

end of thread, other threads:[~2018-06-28 15:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-28 11:38 [Qemu-devel] [PATCH v1 0/2] s390x/kvm: legacy_s390_alloc() fixes David Hildenbrand
2018-06-28 11:38 ` [Qemu-devel] [PATCH v1 1/2] s390x/kvm: legacy_s390_alloc() only supports one allocation David Hildenbrand
2018-06-28 12:42   ` [Qemu-devel] [qemu-s390x] " Christian Borntraeger
2018-06-28 11:38 ` [Qemu-devel] [PATCH v1 2/2] s390x/kvm: indicate alignment in legacy_s390_alloc() David Hildenbrand
2018-06-28 15:22 ` [Qemu-devel] [PATCH v1 0/2] s390x/kvm: legacy_s390_alloc() fixes Cornelia Huck

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).