[PATCH v3 33/59] target/i386/hvf: Use host page alignment in ept_emulation_fault()

Philippe Mathieu-Daudé posted 59 patches 2 weeks, 3 days ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>, Phil Dennis-Jordan <phil@philjordan.eu>, Mads Ynddal <mads@ynddal.dk>, Peter Maydell <peter.maydell@linaro.org>, Alexander Graf <agraf@csgraf.de>, Stefan Hajnoczi <stefanha@redhat.com>
There is a newer version of this series
[PATCH v3 33/59] target/i386/hvf: Use host page alignment in ept_emulation_fault()
Posted by Philippe Mathieu-Daudé 2 weeks, 3 days ago
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/i386/hvf/hvf.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 16febbac48f..c0b2352b988 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -76,7 +76,7 @@
 #include "qemu/main-loop.h"
 #include "qemu/accel.h"
 #include "target/i386/cpu.h"
-#include "exec/target_page.h"
+#include "exec/cpu-common.h"
 
 static Error *invtsc_mig_blocker;
 
@@ -137,9 +137,9 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual)
 
     if (write && slot) {
         if (slot->flags & HVF_SLOT_LOG) {
-            uint64_t dirty_page_start = gpa & ~(TARGET_PAGE_SIZE - 1u);
+            uint64_t dirty_page_start = gpa & qemu_real_host_page_mask();
             memory_region_set_dirty(slot->region, gpa - slot->start, 1);
-            hv_vm_protect(dirty_page_start, TARGET_PAGE_SIZE,
+            hv_vm_protect(dirty_page_start, qemu_real_host_page_size(),
                           HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC);
         }
     }
-- 
2.51.0


Re: [PATCH v3 33/59] target/i386/hvf: Use host page alignment in ept_emulation_fault()
Posted by Richard Henderson 2 weeks, 3 days ago
On 10/28/25 06:42, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   target/i386/hvf/hvf.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
> index 16febbac48f..c0b2352b988 100644
> --- a/target/i386/hvf/hvf.c
> +++ b/target/i386/hvf/hvf.c
> @@ -76,7 +76,7 @@
>   #include "qemu/main-loop.h"
>   #include "qemu/accel.h"
>   #include "target/i386/cpu.h"
> -#include "exec/target_page.h"
> +#include "exec/cpu-common.h"
>   
>   static Error *invtsc_mig_blocker;
>   
> @@ -137,9 +137,9 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual)
>   
>       if (write && slot) {
>           if (slot->flags & HVF_SLOT_LOG) {
> -            uint64_t dirty_page_start = gpa & ~(TARGET_PAGE_SIZE - 1u);
> +            uint64_t dirty_page_start = gpa & qemu_real_host_page_mask();
>               memory_region_set_dirty(slot->region, gpa - slot->start, 1);
> -            hv_vm_protect(dirty_page_start, TARGET_PAGE_SIZE,
> +            hv_vm_protect(dirty_page_start, qemu_real_host_page_size(),
>                             HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC);
>           }
>       }

Call qemu_real_host_page_size once -- page_mask is -size.

We could get away with TARGET_PAGE_SIZE here, due to x86 and it's fixed 4k page size.  But 
it's better for consistency.


Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

Re: [PATCH v3 33/59] target/i386/hvf: Use host page alignment in ept_emulation_fault()
Posted by Peter Maydell 2 weeks, 3 days ago
On Tue, 28 Oct 2025 at 06:06, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  target/i386/hvf/hvf.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
> index 16febbac48f..c0b2352b988 100644
> --- a/target/i386/hvf/hvf.c
> +++ b/target/i386/hvf/hvf.c
> @@ -76,7 +76,7 @@
>  #include "qemu/main-loop.h"
>  #include "qemu/accel.h"
>  #include "target/i386/cpu.h"
> -#include "exec/target_page.h"
> +#include "exec/cpu-common.h"
>
>  static Error *invtsc_mig_blocker;
>
> @@ -137,9 +137,9 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual)
>
>      if (write && slot) {
>          if (slot->flags & HVF_SLOT_LOG) {
> -            uint64_t dirty_page_start = gpa & ~(TARGET_PAGE_SIZE - 1u);
> +            uint64_t dirty_page_start = gpa & qemu_real_host_page_mask();
>              memory_region_set_dirty(slot->region, gpa - slot->start, 1);
> -            hv_vm_protect(dirty_page_start, TARGET_PAGE_SIZE,
> +            hv_vm_protect(dirty_page_start, qemu_real_host_page_size(),
>                            HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC);
>          }
>      }

I guess we're guaranteed that the host page and TARGET_PAGE_SIZE
are the same thing here (so it doesn't matter that we put
the assert in first and then fix this) ?

On that assumption
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
Re: [PATCH v3 33/59] target/i386/hvf: Use host page alignment in ept_emulation_fault()
Posted by Philippe Mathieu-Daudé 1 week, 4 days ago
On 28/10/25 12:28, Peter Maydell wrote:
> On Tue, 28 Oct 2025 at 06:06, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   target/i386/hvf/hvf.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
>> index 16febbac48f..c0b2352b988 100644
>> --- a/target/i386/hvf/hvf.c
>> +++ b/target/i386/hvf/hvf.c
>> @@ -76,7 +76,7 @@
>>   #include "qemu/main-loop.h"
>>   #include "qemu/accel.h"
>>   #include "target/i386/cpu.h"
>> -#include "exec/target_page.h"
>> +#include "exec/cpu-common.h"
>>
>>   static Error *invtsc_mig_blocker;
>>
>> @@ -137,9 +137,9 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual)
>>
>>       if (write && slot) {
>>           if (slot->flags & HVF_SLOT_LOG) {
>> -            uint64_t dirty_page_start = gpa & ~(TARGET_PAGE_SIZE - 1u);
>> +            uint64_t dirty_page_start = gpa & qemu_real_host_page_mask();
>>               memory_region_set_dirty(slot->region, gpa - slot->start, 1);
>> -            hv_vm_protect(dirty_page_start, TARGET_PAGE_SIZE,
>> +            hv_vm_protect(dirty_page_start, qemu_real_host_page_size(),
>>                             HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC);
>>           }
>>       }
> 
> I guess we're guaranteed that the host page and TARGET_PAGE_SIZE
> are the same thing here (so it doesn't matter that we put
> the assert in first and then fix this) ?

Yes, but clearer to re-order before previous patch to avoid
any doubt.

> 
> On that assumption
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

Thanks!