Re: [PATCH 03/11] KVM: x86: fast emulate repeat string write instructions

Xiao Guangrong
2011-07-27T09:34:31Z

On 07/27/2011 03:51 PM, Gleb Natapov wrote:
> On Wed, Jul 27, 2011 at 02:32:43PM +0800, Xiao Guangrong wrote:
>> On 07/27/2011 12:26 PM, Gleb Natapov wrote:
>>> On Wed, Jul 27, 2011 at 09:47:52AM +0800, Xiao Guangrong wrote:
>>>> On 07/26/2011 08:27 PM, Gleb Natapov wrote:
>>>>> On Tue, Jul 26, 2011 at 07:26:46PM +0800, Xiao Guangrong wrote:
>>>>>> We usually use repeat string instructions to clear the page, for example,
>>>>> By "we" do you mean Linux guest?
>>>>>
>>>>
>>>> I do not know other guests except linux, but, generally rep instruction is
>>>> not used to update a page table which is been using.
>>>>
>>>>>> we call memset to clear a page table, stosb is used in this function, and
>>>>>> repeated for 1024 times, that means we should occupy mmu lock for 1024 times
>>>>>> and walking shadow page cache for 1024 times, it is terrible
>>>>>>
>>>>>> In fact, if it is the repeat string instructions emulated and it is not a
>>>>>> IO/MMIO access, we can zap all the corresponding shadow pages and return to the
>>>>>> guest, then the mapping can became writable and directly write the page
>>>>>>
>>>>
>>>>
>>>>> So this patch does two independent things as far as I can see. First it
>>>>> stops reentering guest if rep instruction is done on memory and second
>>>>
>>>> No.
>>>> Oppositely, it enters guest as soon as possible if rep instruction is done
>>>> on memory ;-)
>>> Oops. Indeed. I read it other way around. So why not just return
>>> X86EMUL_UNHANDLEABLE from emulator_write_emulated_onepage() which should
>>> have the same effect?
>>>
>>
>> It seams not, the count register(RCX) is not decreased, and redundant work
>> need to be done by handling EMULATION_FAILED.
> The only difference is that with your approach one rep is emulated and then
> control goes back to a guest. With EMULATION_FAILED kvm returns to a guest
> immediately, so RCX shouldn't be decreased. There shouldn't a be big difference
> performance wise and if there is it is likely on EMULATION_FAILED side.
> Last but not least emulate.c knows nothing about the hack.
>

Umm. it is reasonable, i'll update this patch. Thanks, Gleb!