Skip to content

Commit 3b0f1d0

Browse files
Kai Huangbonzini
authored andcommitted
KVM: Rename kvm_arch_mmu_write_protect_pt_masked to be more generic for log dirty
We don't have to write protect guest memory for dirty logging if architecture supports hardware dirty logging, such as PML on VMX, so rename it to be more generic. Signed-off-by: Kai Huang <[email protected]> Reviewed-by: Xiao Guangrong <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent b0165f1 commit 3b0f1d0

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

arch/arm/kvm/mmu.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot)
10811081
}
10821082

10831083
/**
1084-
* kvm_arch_mmu_write_protect_pt_masked() - write protect dirty pages
1084+
* kvm_mmu_write_protect_pt_masked() - write protect dirty pages
10851085
* @kvm: The KVM pointer
10861086
* @slot: The memory slot associated with mask
10871087
* @gfn_offset: The gfn offset in memory slot
@@ -1091,7 +1091,7 @@ void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot)
10911091
* Walks bits set in mask write protects the associated pte's. Caller must
10921092
* acquire kvm_mmu_lock.
10931093
*/
1094-
void kvm_arch_mmu_write_protect_pt_masked(struct kvm *kvm,
1094+
static void kvm_mmu_write_protect_pt_masked(struct kvm *kvm,
10951095
struct kvm_memory_slot *slot,
10961096
gfn_t gfn_offset, unsigned long mask)
10971097
{
@@ -1102,6 +1102,20 @@ void kvm_arch_mmu_write_protect_pt_masked(struct kvm *kvm,
11021102
stage2_wp_range(kvm, start, end);
11031103
}
11041104

1105+
/*
1106+
* kvm_arch_mmu_enable_log_dirty_pt_masked - enable dirty logging for selected
1107+
* dirty pages.
1108+
*
1109+
* It calls kvm_mmu_write_protect_pt_masked to write protect selected pages to
1110+
* enable dirty logging for them.
1111+
*/
1112+
void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm,
1113+
struct kvm_memory_slot *slot,
1114+
gfn_t gfn_offset, unsigned long mask)
1115+
{
1116+
kvm_mmu_write_protect_pt_masked(kvm, slot, gfn_offset, mask);
1117+
}
1118+
11051119
static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
11061120
struct kvm_memory_slot *memslot, unsigned long hva,
11071121
unsigned long fault_status)

arch/x86/kvm/mmu.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ static bool __rmap_write_protect(struct kvm *kvm, unsigned long *rmapp,
12161216
}
12171217

12181218
/**
1219-
* kvm_arch_mmu_write_protect_pt_masked - write protect selected PT level pages
1219+
* kvm_mmu_write_protect_pt_masked - write protect selected PT level pages
12201220
* @kvm: kvm instance
12211221
* @slot: slot to protect
12221222
* @gfn_offset: start of the BITS_PER_LONG pages we care about
@@ -1225,7 +1225,7 @@ static bool __rmap_write_protect(struct kvm *kvm, unsigned long *rmapp,
12251225
* Used when we do not need to care about huge page mappings: e.g. during dirty
12261226
* logging we do not have any such mappings.
12271227
*/
1228-
void kvm_arch_mmu_write_protect_pt_masked(struct kvm *kvm,
1228+
static void kvm_mmu_write_protect_pt_masked(struct kvm *kvm,
12291229
struct kvm_memory_slot *slot,
12301230
gfn_t gfn_offset, unsigned long mask)
12311231
{
@@ -1241,6 +1241,23 @@ void kvm_arch_mmu_write_protect_pt_masked(struct kvm *kvm,
12411241
}
12421242
}
12431243

1244+
/**
1245+
* kvm_arch_mmu_enable_log_dirty_pt_masked - enable dirty logging for selected
1246+
* PT level pages.
1247+
*
1248+
* It calls kvm_mmu_write_protect_pt_masked to write protect selected pages to
1249+
* enable dirty logging for them.
1250+
*
1251+
* Used when we do not need to care about huge page mappings: e.g. during dirty
1252+
* logging we do not have any such mappings.
1253+
*/
1254+
void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm,
1255+
struct kvm_memory_slot *slot,
1256+
gfn_t gfn_offset, unsigned long mask)
1257+
{
1258+
kvm_mmu_write_protect_pt_masked(kvm, slot, gfn_offset, mask);
1259+
}
1260+
12441261
static bool rmap_write_protect(struct kvm *kvm, u64 gfn)
12451262
{
12461263
struct kvm_memory_slot *slot;

include/linux/kvm_host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ int kvm_get_dirty_log(struct kvm *kvm,
615615
int kvm_get_dirty_log_protect(struct kvm *kvm,
616616
struct kvm_dirty_log *log, bool *is_dirty);
617617

618-
void kvm_arch_mmu_write_protect_pt_masked(struct kvm *kvm,
618+
void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm,
619619
struct kvm_memory_slot *slot,
620620
gfn_t gfn_offset,
621621
unsigned long mask);

virt/kvm/kvm_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ int kvm_get_dirty_log_protect(struct kvm *kvm,
10591059
dirty_bitmap_buffer[i] = mask;
10601060

10611061
offset = i * BITS_PER_LONG;
1062-
kvm_arch_mmu_write_protect_pt_masked(kvm, memslot, offset,
1062+
kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot, offset,
10631063
mask);
10641064
}
10651065

0 commit comments

Comments
 (0)