Re: [PATCH] KVM: X86: clear page flags when freeing kvm mmapping page

From: Paolo Bonzini
Date: Tue Oct 10 2017 - 12:10:47 EST


On 10/10/2017 17:39, peng.hao2@xxxxxxxxxx wrote:
>>HowÂdidÂyouÂknowÂthatÂthisÂwasÂaÂkvm_runÂpage,ÂandÂwhyÂisÂitÂtheÂright
>>thingÂtoÂclearÂtheÂflags?
>
> first ÂI can't repeat this "bad page report". But I add print message to
> trace. I found that Âkvm_run page is freed Âwith page flags
> PG_dirty and PG_referenced. I Âdon't think it is right status for
> freed page.

That would be the symptom, not the cause. So it would not be the right
thing to clear the flags.

> second, kvm_run page is mmaped in qemu with fd ofÂ"kvm-vcpu". It has
> special mmap function(kvm_vcpu_mmap),but when munmap is calledÂ
> the kvm_run page goes into general munmap route.it is not suitable for
> kvm_run page that is set dirty in munmap route.

There are many many cases where .mmap and .fault are defined but .munmap
isn't, and none of them calls ClearPageDirty or ClearPageReferenced; see
for example kernel/relay.c (whose only user is blktrace).

Can the page be dirty in those cases? If not, what makes KVM different?

Since you cannot reproduce the failure, this patch is basically
untested. You need to dig deeper into what's happening, and provide a
better justification for what you are doing. But generally, it's a bad
sign if you're doing something special that no other device in the
kernel is doing.

Paolo