Skip to content

Commit b072cbf

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Discard dirty page tracking on readonly memslot
For readonly memslot such as UEFI BIOS or UEFI var space, guest cannot write this memory space directly. So it is not necessary to track dirty pages for readonly memslot. Here we make such optimization in function kvm_arch_commit_memory_region(). Signed-off-by: Bibo Mao <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 2f56f9e commit b072cbf

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

arch/loongarch/kvm/mmu.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,17 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
444444
enum kvm_mr_change change)
445445
{
446446
int needs_flush;
447+
u32 old_flags = old ? old->flags : 0;
448+
u32 new_flags = new ? new->flags : 0;
449+
bool log_dirty_pages = new_flags & KVM_MEM_LOG_DIRTY_PAGES;
450+
451+
/* Only track memslot flags changed */
452+
if (change != KVM_MR_FLAGS_ONLY)
453+
return;
454+
455+
/* Discard dirty page tracking on readonly memslot */
456+
if ((old_flags & new_flags) & KVM_MEM_READONLY)
457+
return;
447458

448459
/*
449460
* If dirty page logging is enabled, write protect all pages in the slot
@@ -454,9 +465,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
454465
* MOVE/DELETE: The old mappings will already have been cleaned up by
455466
* kvm_arch_flush_shadow_memslot()
456467
*/
457-
if (change == KVM_MR_FLAGS_ONLY &&
458-
(!(old->flags & KVM_MEM_LOG_DIRTY_PAGES) &&
459-
new->flags & KVM_MEM_LOG_DIRTY_PAGES)) {
468+
if (!(old_flags & KVM_MEM_LOG_DIRTY_PAGES) && log_dirty_pages) {
460469
spin_lock(&kvm->mmu_lock);
461470
/* Write protect GPA page table entries */
462471
needs_flush = kvm_mkclean_gpa_pt(kvm, new->base_gfn,

0 commit comments

Comments
 (0)