qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Yan-Jie Wang <ubzeme@gmail.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Roman Bolshakov <r.bolshakov@yadro.com>,
	Alexander Graf <agraf@csgraf.de>,
	Cameron Esfahani <dirty@apple.com>,
	Yan-Jie Wang <ubzeme@gmail.com>
Subject: [PATCH v3 0/9] Many improvements to HVF memory-related codes
Date: Wed,  2 Mar 2022 21:04:08 +0800	[thread overview]
Message-ID: <20220302130417.18551-1-ubzeme@gmail.com> (raw)

changes in v3:
* Fix last two patches which contain mistakes:
 - hvf: only consider directly writeable memory regions for
    dirty-tracking
 - hvf: remove the need to lookup memory slots when clearing dirty-bits

changes in v2:
* Rebase to the current master.
* Correct a mistake in "hvf: simplify data structures and codes of
  memory related functions" patch
* add two patches for HVF memory listener. The changes are
 - only consider directly writeable memory regions for dirty-tracking
 - in `hvf_log_clear`, use provided `section` (MemoryRegionSection)
   from the caller to determine the pages that need to write-protected
   instead of calling hvf_set_dirty_tracking to write-protect the memory
   slots that contains the pages whose dirty-bits are cleared.

----------

I recently bought a Mac with M1 Pro chip, and use QEMU to setup a Linux
virtual machine.  QEMU crashed when I started a VM with HVF accelerator
enabled and with the device, bochs-display, added.

After digging into the source code, I found that dirty-tracking in HVF
did not work properly, which made QEMU crashed. Therefore I made this
series of patches to fix the problem.

Followings are the summary of the changes that these patches make:
 1. Move HVF memory-related functions and codes into a new file
    hvf-mem.c
 2. Simplify the logics of adding and removing memory regions in HVF
    memory listener
 3. Fix HVF dirty-tracking logics for both Intel and Apple Silicon Macs
 4. Use GTree and dynamically-allocated structures to store HVF memory
    slots instead of fixed-size arrays. This makes memory slots more
    scalable. It is inspired by the recent changes in Linux kernel
    (v5.17) that use red-black trees instead of arrays to store
    in-kernel KVM memory slots.
 5. Add a lock to protect the data structures of HVF memory slots

Patches have been tested on Apple Silicon Macs and Intel Macs.

Yan-Jie Wang (9):
  hvf: move memory related functions from hvf-accel-ops.c to hvf-mem.c
  hvf: simplify data structures and codes of memory related functions
  hvf: use correct data types for addresses in memory related functions
  hvf: rename struct hvf_slot to HVFSlot
  hvf: fix memory dirty-tracking
  hvf: add a lock for memory related functions
  hvf: use GTree to store memory slots instead of fixed-size array
  hvf: only consider directly writeable memory regions for
    dirty-tracking
  hvf: remove the need to lookup memory slots when clearing dirty-bits

 accel/hvf/hvf-accel-ops.c | 221 +-----------------------
 accel/hvf/hvf-mem.c       | 343 ++++++++++++++++++++++++++++++++++++++
 accel/hvf/meson.build     |   1 +
 include/sysemu/hvf_int.h  |  18 +-
 target/arm/hvf/hvf.c      |   5 +
 target/i386/hvf/hvf.c     |  25 +--
 6 files changed, 359 insertions(+), 254 deletions(-)
 create mode 100644 accel/hvf/hvf-mem.c

-- 
2.32.0 (Apple Git-132)



             reply	other threads:[~2022-03-02 13:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-02 13:04 Yan-Jie Wang [this message]
2022-03-02 13:04 ` [PATCH v3 1/9] hvf: move memory related functions from hvf-accel-ops.c to hvf-mem.c Yan-Jie Wang
2022-03-18 11:46   ` Peter Maydell
2022-03-02 13:04 ` [PATCH v3 2/9] hvf: simplify data structures and codes of memory related functions Yan-Jie Wang
2022-03-18 12:09   ` Peter Maydell
2022-03-02 13:04 ` [PATCH v3 3/9] hvf: use correct data types for addresses in " Yan-Jie Wang
2022-03-18 12:10   ` Peter Maydell
2022-03-02 13:04 ` [PATCH v3 4/9] hvf: rename struct hvf_slot to HVFSlot Yan-Jie Wang
2022-03-18 12:11   ` Peter Maydell
2022-03-02 13:04 ` [PATCH v3 5/9] hvf: fix memory dirty-tracking Yan-Jie Wang
2022-03-18 13:09   ` Peter Maydell
2022-03-02 13:04 ` [PATCH v3 6/9] hvf: add a lock for memory related functions Yan-Jie Wang
2022-03-18 12:11   ` Peter Maydell
2022-03-02 13:04 ` [PATCH v3 7/9] hvf: use GTree to store memory slots instead of fixed-size array Yan-Jie Wang
2022-03-18 12:58   ` Peter Maydell
2022-03-02 13:04 ` [PATCH v3 8/9] hvf: only consider directly writeable memory regions for dirty-tracking Yan-Jie Wang
2022-03-02 13:04 ` [PATCH v3 9/9] hvf: remove the need to lookup memory slots when clearing dirty-bits Yan-Jie Wang

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=20220302130417.18551-1-ubzeme@gmail.com \
    --to=ubzeme@gmail.com \
    --cc=agraf@csgraf.de \
    --cc=dirty@apple.com \
    --cc=peter.maydell@linaro.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).