On Tue, Dec 13, 2022, Lai Jiangshan wrote: > From: Lai Jiangshan <jiangshan.ljs@xxxxxxxxxxxx> > > FNAME(is_self_change_mapping) has two functionalities. > > If the fault is on a huge page but at least one of the pagetable on > the walk is also on the terminal huge page, disable the huge page > mapping for the fault. > > If the fault is modifying at least one of the pagetable on the walk, > set something to tell the emulator. This should be two patches, one to move the arch.write_fault_to_shadow_pgtable handling and one to drop the hugepage adjustment. I also want to rework the handling of write_fault_to_shadow_pgtable as prep work. Every time I look at that flag it takes me an eternity to remember exactly how KVM guarantees x86_emulate_instruction() won't get false positives. I.e. I always forget why it's ok to not clear vcpu->arch.write_fault_to_shadow_pgtable after every VM-Exit. Unless I've missed something, we can use an EMULTYPE flag to communicate to the emulator that the #PF emulation is on a self-referential write to a shadow page. That allows dropping write_fault_to_shadow_pgtable from vcpu->arch and sidesteps the whole "how do we avoid false positives?" question. Testing now, if everything looks good, I'll post v2 with all three patches.