Skip to content

Commit 6bd92b9

Browse files
Ricardo Kolleroupton
authored andcommitted
KVM: arm64: Refactor kvm_arch_commit_memory_region()
Refactor kvm_arch_commit_memory_region() as a preparation for a future commit to look cleaner and more understandable. Also, it looks more like its x86 counterpart (in kvm_mmu_slot_apply_flags()). Signed-off-by: Ricardo Koller <ricarkol@google.com> Reviewed-by: Shaoqin Huang <shahuang@redhat.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Link: https://lore.kernel.org/r/20230426172330.1439644-8-ricarkol@google.com Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 8f5a3eb commit 6bd92b9

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

arch/arm64/kvm/mmu.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,20 +1794,32 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
17941794
const struct kvm_memory_slot *new,
17951795
enum kvm_mr_change change)
17961796
{
1797+
bool log_dirty_pages = new && new->flags & KVM_MEM_LOG_DIRTY_PAGES;
1798+
17971799
/*
17981800
* At this point memslot has been committed and there is an
17991801
* allocated dirty_bitmap[], dirty pages will be tracked while the
18001802
* memory slot is write protected.
18011803
*/
1802-
if (change != KVM_MR_DELETE && new->flags & KVM_MEM_LOG_DIRTY_PAGES) {
1804+
if (log_dirty_pages) {
1805+
1806+
if (change == KVM_MR_DELETE)
1807+
return;
1808+
18031809
/*
1804-
* If we're with initial-all-set, we don't need to write
1805-
* protect any pages because they're all reported as dirty.
1806-
* Huge pages and normal pages will be write protect gradually.
1810+
* Pages are write-protected on either of these two
1811+
* cases:
1812+
*
1813+
* 1. with initial-all-set: gradually with CLEAR ioctls,
18071814
*/
1808-
if (!kvm_dirty_log_manual_protect_and_init_set(kvm)) {
1809-
kvm_mmu_wp_memory_region(kvm, new->id);
1810-
}
1815+
if (kvm_dirty_log_manual_protect_and_init_set(kvm))
1816+
return;
1817+
/*
1818+
* or
1819+
* 2. without initial-all-set: all in one shot when
1820+
* enabling dirty logging.
1821+
*/
1822+
kvm_mmu_wp_memory_region(kvm, new->id);
18111823
}
18121824
}
18131825

0 commit comments

Comments
 (0)