qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@csgraf.de>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Roman Bolshakov <r.bolshakov@yadro.com>,
	qemu-arm@nongnu.org, Cameron Esfahani <dirty@apple.com>
Subject: [PATCH] hvf: arm: Add simple dirty bitmap tracking
Date: Thu,  3 Feb 2022 15:23:20 +0100	[thread overview]
Message-ID: <20220203142320.33022-1-agraf@csgraf.de> (raw)

The actual tracking of dirty bitmap updates is happening in architecture code.
So far, the aarch64 hvf code has not updated QEMU's dirty bitmap at all. The
net result of that is that the VGA device's framebuffer would not update.

This patch adds simplistic dirty bitmap updates. Unfortunately hvf can only set
permissions per full region, so we have to mark the complete region as dirty
when only a single byte was modified inside.

We also handle the write protect update logic before we handle any writes.
This allows us to even handle non-ISV instructions on dirty logging enabled
memory regions: Once we flip the region to writable again, we just rerun
the trapping instruction.

Signed-off-by: Alexander Graf <agraf@csgraf.de>
---
 target/arm/hvf/hvf.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 0dc96560d3..92ad0d29c4 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1163,6 +1163,28 @@ int hvf_vcpu_exec(CPUState *cpu)
             break;
         }
 
+        /*
+         * Dirty log updates work without isv as well. We just run the write
+         * again with write permissions set. So handle them before the assert.
+         */
+        if (iswrite) {
+            uint64_t gpa = hvf_exit->exception.physical_address;
+            hvf_slot *slot = hvf_find_overlap_slot(gpa, 1);
+
+            if (slot && slot->flags & HVF_SLOT_LOG) {
+                /*
+                 * HVF can only set a full region's permissions, so let's just
+                 * mark the full region as dirty.
+                 */
+                memory_region_set_dirty(slot->region, 0, slot->size);
+                hv_vm_protect(slot->start, slot->size, HV_MEMORY_READ |
+                              HV_MEMORY_WRITE | HV_MEMORY_EXEC);
+
+                /* Run the same instruction again, without write faulting */
+                break;
+            }
+        }
+
         assert(isv);
 
         if (iswrite) {
-- 
2.32.0 (Apple Git-132)



             reply	other threads:[~2022-02-03 14:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03 14:23 Alexander Graf [this message]
2022-02-15 19:27 ` [PATCH] hvf: arm: Add simple dirty bitmap tracking Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220203142320.33022-1-agraf@csgraf.de \
    --to=agraf@csgraf.de \
    --cc=dirty@apple.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=r.bolshakov@yadro.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).