From: Yanan Wang <firstname.lastname@example.org>
Marc Zyngier <email@example.com>,
Catalin Marinas <firstname.lastname@example.org>,
Will Deacon <email@example.com>, James Morse <firstname.lastname@example.org>,
"Julien Thierry" <email@example.com>,
Suzuki K Poulose <firstname.lastname@example.org>,
Gavin Shan <email@example.com>,
Quentin Perret <firstname.lastname@example.org>
Cc: <email@example.com>, <firstname.lastname@example.org>,
Yanan Wang <email@example.com>
Subject: [PATCH v2 0/3] RFC: Solve several problems in stage 2 translation
Date: Wed, 16 Dec 2020 20:28:41 +0800 [thread overview]
Message-ID: <firstname.lastname@example.org> (raw)
Hi, this is the second version, thanks for reading.
Procedures of hyp stage 1 mapping and guest stage 2 mapping are different, but
they are tied closely by function kvm_set_valid_leaf_pte(). So separate them by
To avoid unnecessary update and small loops, add prejudgement in the translation
fault handler: Skip updating the PTE with break-before-make if we are trying to
recreate the exact same mapping or only change the access permissions. Actually,
change of permissions will be handled through the relax_perms path next time if
(1) If there are some vCPUs accessing the same GPA at the same time and the leaf
PTE is not set yet, then they will all cause translation faults and the first vCPU
holding mmu_lock will set valid leaf PTE, and the others will later update the old
PTE with a new one if they are different.
(2) When changing a leaf entry or a table entry with break-before-make, if there
are some vCPUs accessing the same GPA just catch the moment when the target PTE
is set invalid in a BBM procedure coincidentally, they will all cause translation
faults and will later update the old PTE with a new one if they are different.
The worst case can be like this: vCPU A causes a translation fault with RW prot and
sets the leaf PTE with RW permissions, and then the next vCPU B with RO prot updates
the PTE back to RO permissions with break-before-make. And the BBM-invalid moment
may trigger more unnecessary translation faults, then some useless small loops might
occur which could lead to vCPU stuck.
We now mark the page dirty and set the bitmap before calling fault handlers in
user_mem_abort(), and we might end up having spurious dirty pages if update of
permissions or mapping has failed. So, mark the page dirty only if the fault is
Let the guest directly enter again but not return to userspace if we were trying
to recreate the same mapping or only change access permissions with BBM, which is
not permitted in the mapping path.
Changes from v1:
- Make part of the diff as an independent patch (PATCH1/3),
and add Will's Signed-off-by.
- Use *return -EPERM* way when changing permissions only in the mapping path.
- Add a new patch (PATCH3/3).
Yanan Wang (3):
KVM: arm64: Decouple partial code of hyp stage 1 mapping and guest
stage 2 mapping
KVM: arm64: Add prejudgement for relaxing permissions only case in
stage2 translation fault handler
KVM: arm64: Mark the page dirty only if the fault is handled
arch/arm64/kvm/hyp/pgtable.c | 78 ++++++++++++++++++++----------------
arch/arm64/kvm/mmu.c | 18 +++++++--
2 files changed, 58 insertions(+), 38 deletions(-)
next reply other threads:[~2020-12-16 12:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-16 12:28 Yanan Wang [this message]
2020-12-16 12:28 ` [PATCH v2 1/3] KVM: arm64: Decouple partial code of hyp stage 1 mapping and guest stage 2 mapping Yanan Wang
2020-12-16 12:28 ` [PATCH v2 2/3] KVM: arm64: Add prejudgement for relaxing permissions only case in stage2 translation fault handler Yanan Wang
2021-01-13 15:44 ` Will Deacon
2021-01-14 9:28 ` wangyanan (Y)
2020-12-16 12:28 ` [PATCH v2 3/3] KVM: arm64: Mark the page dirty only if the fault is handled successfully Yanan Wang
2021-01-13 15:51 ` Will Deacon
2021-01-14 9:28 ` wangyanan (Y)
2020-12-28 2:46 ` [PATCH v2 0/3] RFC: Solve several problems in stage 2 translation wangyanan (Y)
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:
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
* 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).