qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] hvf: Avoid mapping regions < PAGE_SIZE as ram
@ 2021-10-25 13:21 Alexander Graf
  2021-10-25 13:26 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Graf @ 2021-10-25 13:21 UTC (permalink / raw)
  To: Cameron Esfahani
  Cc: Paolo Bonzini, Roman Bolshakov, Philippe Mathieu-Daudé,
	qemu-devel

HVF has generic memory listener code that adds all RAM regions as HVF RAM
regions. However, HVF can only handle page aligned, page granule regions.

So let's ignore regions that are not page aligned and sized. They will be
trapped as MMIO instead.

Signed-off-by: Alexander Graf <agraf@csgraf.de>

---

v1 -> v2:

  - Use QEMU_IS_ALIGNED()
---
 accel/hvf/hvf-accel-ops.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index 2b2c411076..54457c76c2 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -122,6 +122,7 @@ static void hvf_set_phys_mem(MemoryRegionSection *section, bool add)
     MemoryRegion *area = section->mr;
     bool writeable = !area->readonly && !area->rom_device;
     hv_memory_flags_t flags;
+    uint64_t page_size = qemu_real_host_page_size;
 
     if (!memory_region_is_ram(area)) {
         if (writeable) {
@@ -135,6 +136,12 @@ static void hvf_set_phys_mem(MemoryRegionSection *section, bool add)
         }
     }
 
+    if (!QEMU_IS_ALIGNED(int128_get64(section->size), page_size) ||
+        !QEMU_IS_ALIGNED(section->offset_within_address_space, page_size)) {
+        /* Not page aligned, so we can not map as RAM */
+        add = false;
+    }
+
     mem = hvf_find_overlap_slot(
             section->offset_within_address_space,
             int128_get64(section->size));
-- 
2.30.1 (Apple Git-130)



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

* Re: [PATCH v2] hvf: Avoid mapping regions < PAGE_SIZE as ram
  2021-10-25 13:21 [PATCH v2] hvf: Avoid mapping regions < PAGE_SIZE as ram Alexander Graf
@ 2021-10-25 13:26 ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-10-25 13:26 UTC (permalink / raw)
  To: Alexander Graf, Cameron Esfahani
  Cc: Paolo Bonzini, Roman Bolshakov, qemu-devel

On 10/25/21 15:21, Alexander Graf wrote:
> HVF has generic memory listener code that adds all RAM regions as HVF RAM
> regions. However, HVF can only handle page aligned, page granule regions.
> 
> So let's ignore regions that are not page aligned and sized. They will be
> trapped as MMIO instead.
> 
> Signed-off-by: Alexander Graf <agraf@csgraf.de>
> 
> ---
> 
> v1 -> v2:
> 
>   - Use QEMU_IS_ALIGNED()
> ---
>  accel/hvf/hvf-accel-ops.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
> index 2b2c411076..54457c76c2 100644
> --- a/accel/hvf/hvf-accel-ops.c
> +++ b/accel/hvf/hvf-accel-ops.c
> @@ -122,6 +122,7 @@ static void hvf_set_phys_mem(MemoryRegionSection *section, bool add)
>      MemoryRegion *area = section->mr;
>      bool writeable = !area->readonly && !area->rom_device;
>      hv_memory_flags_t flags;
> +    uint64_t page_size = qemu_real_host_page_size;
>  
>      if (!memory_region_is_ram(area)) {
>          if (writeable) {
> @@ -135,6 +136,12 @@ static void hvf_set_phys_mem(MemoryRegionSection *section, bool add)
>          }
>      }
>  
> +    if (!QEMU_IS_ALIGNED(int128_get64(section->size), page_size) ||
> +        !QEMU_IS_ALIGNED(section->offset_within_address_space, page_size)) {
> +        /* Not page aligned, so we can not map as RAM */
> +        add = false;
> +    }
> +
>      mem = hvf_find_overlap_slot(
>              section->offset_within_address_space,
>              int128_get64(section->size));
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



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

end of thread, other threads:[~2021-10-25 13:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-25 13:21 [PATCH v2] hvf: Avoid mapping regions < PAGE_SIZE as ram Alexander Graf
2021-10-25 13:26 ` Philippe Mathieu-Daudé

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