KVM: arm64: Dirty logging fixes/cleanups
Subsystems (3)
v2 cover KVM: arm64: Dirty logging fixes/cleanups
Hi,
These are two fixes/cleanups I found when reading the code. It fixes dirty logging detection in ring-only mode and updates a stale comment. Please view the patches for more detail.
* Changes from v1 ([1]):
- Keep memslot_is_logging() and use kvm_slot_dirty_track_enabled() in it. This preserves the RO memslot check.
- Change patch 2 to updating the stale comment only, the original change is obsolete now.
- Collect Reviewed-by and Tested-by tags from Fuad (thanks!).
Thanks!
[1]: https://lore.kernel.org/kvmarm/[email protected]/
Wei-Lin Chang (2):
KVM: arm64: Fix dirty logging detection in ring-only mode
KVM: arm64: Remove stale remark on canonical IPA alignment
arch/arm64/kvm/mmu.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/2 KVM: arm64: Fix dirty logging detection in ring-only mode
When checking whether a memslot has dirty logging enabled, the KVM_MEM_LOG_DIRTY_PAGES flag is the source of truth. Previously in memslot_is_logging() we were testing the dirty bitmap only and did not consider dirty ring.
With the ring and no bitmap, a logged memslot can still get block mappings, so guest writes to most of a block are never logged and a migration can copy stale memory.
Fix this by using kvm_slot_dirty_track_enabled() instead which checks KVM_MEM_LOG_DIRTY_PAGES, within memslot_is_logging().
--- arch/arm64/kvm/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/mmu.c +1 -1
@@ -176,7 +176,7 @@ static int kvm_mmu_split_huge_pages(struct kvm *kvm, phys_addr_t addr,static bool memslot_is_logging (struct kvm_memory_slot *memslot) { -return memslot->dirty_bitmap && !(memslot->flags &KVM_MEM_READONLY ); +return kvm_slot_dirty_track_enabled (memslot) && !(memslot->flags &KVM_MEM_READONLY ); }static int pkvm_flush_remote_tlbs (struct kvm *kvm)
Signature · 1 line
2.43.0
Re: [PATCH v2 1/2] KVM: arm64: Fix dirty logging detection in ring-only mode
Quoted 12 lines · Wei-Lin Chang
When checking whether a memslot has dirty logging enabled, the
KVM_MEM_LOG_DIRTY_PAGESflag is the source of truth. Previously inmemslot_is_logging()we were testing the dirty bitmap only and did not consider dirty ring.With the ring and no bitmap, a logged memslot can still get block mappings, so guest writes to most of a block are never logged and a migration can copy stale memory.
Fix this by using
kvm_slot_dirty_track_enabled()instead which checksKVM_MEM_LOG_DIRTY_PAGES, withinmemslot_is_logging().
Quoted 9 lines
Fixes 9cb1096f8590 ("KVM: arm64: Enable ring-based dirty memory tracking")Reviewed-by Fuad Tabba <[email protected]>Tested-by Fuad Tabba <[email protected]>Signed-off-by Wei-Lin Chang <[email protected]>--- arch/arm64/kvm/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Re: [PATCH v2 1/2] KVM: arm64: Fix dirty logging detection in ring-only mode
In reply to Wei-Lin ChangQuoted 37 lines · Wei-Lin Chang
When checking whether a memslot has dirty logging enabled, the
KVM_MEM_LOG_DIRTY_PAGESflag is the source of truth. Previously inmemslot_is_logging()we were testing the dirty bitmap only and did not consider dirty ring.With the ring and no bitmap, a logged memslot can still get block mappings, so guest writes to most of a block are never logged and a migration can copy stale memory.
Fix this by using
kvm_slot_dirty_track_enabled()instead which checksKVM_MEM_LOG_DIRTY_PAGES, withinmemslot_is_logging().Fixes 9cb1096f8590 ("KVM: arm64: Enable ring-based dirty memory tracking")Reviewed-by Fuad Tabba <[email protected]>Tested-by Fuad Tabba <[email protected]>Signed-off-by Wei-Lin Chang <[email protected]>--- arch/arm64/kvm/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/kvm/mmu.c +1
-1@@ -176,7 +176,7 @@ static int kvm_mmu_split_huge_pages(struct kvm *kvm, phys_addr_t addr,static bool memslot_is_logging (struct kvm_memory_slot *memslot) { -return memslot->dirty_bitmap && !(memslot->flags &KVM_MEM_READONLY ); +return kvm_slot_dirty_track_enabled (memslot) && !(memslot->flags &KVM_MEM_READONLY ); }static int pkvm_flush_remote_tlbs (struct kvm *kvm)Signature · 1 line
2.43.0
Awesome, thanks for taking the suggestion!
Leo
PATCH v2 2/2 KVM: arm64: Remove stale remark on canonical IPA alignment
In reply to Wei-Lin ChangCommit 3b8ce2b5132ae ("KVM: arm64: Use a variable for the canonical IPA in kvm_s2_fault_map()") created a variable to store the canonical IPA, instead of calculating it when needed. It moved the aligning just before mark_page_dirty_in_slot() to an earlier place but did not update the comment.
Remove the stale part of the comment.
--- arch/arm64/kvm/mmu.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
arch/arm64/kvm/mmu.c +1 -5
@@ -2232,11 +2232,7 @@ static int kvm_s2_fault_map(const struct kvm_s2_fault_desc *s2fd,kvm_fault_unlock (kvm);kfree (mapping); -/* -* Mark the page dirty only if the fault is handled successfully, -* making sure we adjust the canonical IPA if the mapping size has -* been updated (via a THP upgrade, for example). -*/ +/* Mark the page dirty only if the fault is handled successfully. */ if (writable && !ret)mark_page_dirty_in_slot (kvm, s2fd->memslot,gpa_to_gfn (canonical_ipa));
Signature · 1 line
2.43.0
Re: [PATCH v2 2/2] KVM: arm64: Remove stale remark on canonical IPA alignment
Quoted 10 lines · Wei-Lin Chang
Commit
3b8ce2b5132ae("KVM: arm64: Use a variable for the canonical IPA inkvm_s2_fault_map()") created a variable to store the canonical IPA, instead of calculating it when needed. It moved the aligning just beforemark_page_dirty_in_slot()to an earlier place but did not update the comment.Remove the stale part of the comment.
Signed-off-by Wei-Lin Chang <[email protected]>
Cheers,
/fuad
Re: [PATCH v2 2/2] KVM: arm64: Remove stale remark on canonical IPA alignment
In reply to Wei-Lin ChangQuoted 6 lines · Wei-Lin Chang
Commit
3b8ce2b5132ae("KVM: arm64: Use a variable for the canonical IPA inkvm_s2_fault_map()") created a variable to store the canonical IPA, instead of calculating it when needed. It moved the aligning just beforemark_page_dirty_in_slot()to an earlier place but did not update the comment.
Quoted 7 lines
Remove the stale part of the comment.
Signed-off-by Wei-Lin Chang <[email protected]>--- arch/arm64/kvm/mmu.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
Re: [PATCH v2 2/2] KVM: arm64: Remove stale remark on canonical IPA alignment
In reply to Wei-Lin ChangQuoted 33 lines · Wei-Lin Chang
Commit
3b8ce2b5132ae("KVM: arm64: Use a variable for the canonical IPA inkvm_s2_fault_map()") created a variable to store the canonical IPA, instead of calculating it when needed. It moved the aligning just beforemark_page_dirty_in_slot()to an earlier place but did not update the comment.Remove the stale part of the comment.
Signed-off-by Wei-Lin Chang <[email protected]>--- arch/arm64/kvm/mmu.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)arch/arm64/kvm/mmu.c +1
-5@@ -2232,11 +2232,7 @@ static int kvm_s2_fault_map(const struct kvm_s2_fault_desc *s2fd,kvm_fault_unlock (kvm);kfree (mapping); -/* -* Mark the page dirty only if the fault is handled successfully, -* making sure we adjust the canonical IPA if the mapping size has -* been updated (via a THP upgrade, for example). -*/ +/* Mark the page dirty only if the fault is handled successfully. */ if (writable && !ret)mark_page_dirty_in_slot (kvm, s2fd->memslot,gpa_to_gfn (canonical_ipa));Signature · 1 line
2.43.0
Quoted 10 lines · Wei-Lin Chang
These are two fixes/cleanups I found when reading the code. It fixes dirty logging detection in ring-only mode and updates a stale comment. Please view the patches for more detail.
* Changes from v1 ([1]):
- Keep
memslot_is_logging()and usekvm_slot_dirty_track_enabled()in it. This preserves the RO memslot check.[...]
Applied to fixes, thanks!
[1/2] KVM: arm64: Fix dirty logging detection in ring-only mode
commit: 98b2eab9345c502cb13ef2e347ab5a6c288db482
[2/2] KVM: arm64: Remove stale remark on canonical IPA alignment
commit: 4bc0c9cd84767a978046c3b2a73dc932bdb8d9f9Cheers,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.