2019-12-25 02:22:04

by Miaohe Lin

[permalink] [raw]
Subject: [PATCH] KVM: nvmx: retry writing guest memory after page fault injected

From: Miaohe Lin <[email protected]>

We should retry writing guest memory when kvm_write_guest_virt_system()
failed and page fault is injected in handle_vmread().

Signed-off-by: Miaohe Lin <[email protected]>
---
arch/x86/kvm/vmx/nested.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 8edefdc9c0cb..c1ec9f25a417 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -4799,8 +4799,10 @@ static int handle_vmread(struct kvm_vcpu *vcpu)
instr_info, true, len, &gva))
return 1;
/* _system ok, nested_vmx_check_permission has verified cpl=0 */
- if (kvm_write_guest_virt_system(vcpu, gva, &value, len, &e))
+ if (kvm_write_guest_virt_system(vcpu, gva, &value, len, &e)) {
kvm_inject_page_fault(vcpu, &e);
+ return 1;
+ }
}

return nested_vmx_succeed(vcpu);
--
2.19.1


2019-12-26 00:24:15

by Liran Alon

[permalink] [raw]
Subject: Re: [PATCH] KVM: nvmx: retry writing guest memory after page fault injected



> On 25 Dec 2019, at 4:21, linmiaohe <[email protected]> wrote:
>
> From: Miaohe Lin <[email protected]>
>
> We should retry writing guest memory when kvm_write_guest_virt_system()
> failed and page fault is injected in handle_vmread().
>
> Signed-off-by: Miaohe Lin <[email protected]>

Patch fix seems correct to me:
Reviewed-by: Liran Alon <[email protected]>

However, I suggest to rephrase commit title & message as follows:

"""
KVM: nVMX: vmread should not set rflags to specify success in case of #PF

In case writing to vmread destination operand result in a #PF, vmread should
not call nested_vmx_succeed() to set rflags to specify success. Similar to as
done in for VMPTRST (See handle_vmptrst()).
"""

In addition, it will be appreciated if you would also submit kvm-unit-test that verifies this condition.

-Liran

> ---
> arch/x86/kvm/vmx/nested.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index 8edefdc9c0cb..c1ec9f25a417 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -4799,8 +4799,10 @@ static int handle_vmread(struct kvm_vcpu *vcpu)
> instr_info, true, len, &gva))
> return 1;
> /* _system ok, nested_vmx_check_permission has verified cpl=0 */
> - if (kvm_write_guest_virt_system(vcpu, gva, &value, len, &e))
> + if (kvm_write_guest_virt_system(vcpu, gva, &value, len, &e)) {
> kvm_inject_page_fault(vcpu, &e);
> + return 1;
> + }
> }
>
> return nested_vmx_succeed(vcpu);
> --
> 2.19.1
>

2019-12-26 02:32:31

by Miaohe Lin

[permalink] [raw]
Subject: Re: [PATCH] KVM: nvmx: retry writing guest memory after page fault injected

Hi,

Liran Alon <[email protected]> wrote:
>> On 25 Dec 2019, at 4:21, linmiaohe <[email protected]> wrote:
>>
>> From: Miaohe Lin <[email protected]>
>>
>> We should retry writing guest memory when
>> kvm_write_guest_virt_system() failed and page fault is injected in handle_vmread().
>>
>> Signed-off-by: Miaohe Lin <[email protected]>
>
>Patch fix seems correct to me:
>Reviewed-by: Liran Alon <[email protected]>

Thanks for your review.

>However, I suggest to rephrase commit title & message as follows:
>
>"""
>KVM: nVMX: vmread should not set rflags to specify success in case of #PF
>
>In case writing to vmread destination operand result in a #PF, vmread should not call nested_vmx_succeed() to set rflags to specify success. Similar to as done in for VMPTRST (See handle_vmptrst()).
>"""

Thanks for your sueestion, I would rephrase commit title & message accordingly.

>
>In addition, it will be appreciated if you would also submit kvm-unit-test that verifies this condition.

I'd like to submit kvm-unit-test that verifies this condition, but I am not familiar with the kvm-unit-test code yet and
also not in my recent todo list. So such a patch may come late. It would be appreciated too if you could submit this
kvm-unit-test patch. :)
Thanks again.

2019-12-26 02:36:18

by Wanpeng Li

[permalink] [raw]
Subject: Re: [PATCH] KVM: nvmx: retry writing guest memory after page fault injected

On Thu, 26 Dec 2019 at 10:32, linmiaohe <[email protected]> wrote:
>
> Hi,
>
> Liran Alon <[email protected]> wrote:
> >> On 25 Dec 2019, at 4:21, linmiaohe <[email protected]> wrote:
> >>
> >> From: Miaohe Lin <[email protected]>
> >>
> >> We should retry writing guest memory when
> >> kvm_write_guest_virt_system() failed and page fault is injected in handle_vmread().
> >>
> >> Signed-off-by: Miaohe Lin <[email protected]>
> >
> >Patch fix seems correct to me:
> >Reviewed-by: Liran Alon <[email protected]>
>
> Thanks for your review.
>
> >However, I suggest to rephrase commit title & message as follows:
> >
> >"""
> >KVM: nVMX: vmread should not set rflags to specify success in case of #PF
> >
> >In case writing to vmread destination operand result in a #PF, vmread should not call nested_vmx_succeed() to set rflags to specify success. Similar to as done in for VMPTRST (See handle_vmptrst()).
> >"""
>
> Thanks for your sueestion, I would rephrase commit title & message accordingly.
>
> >
> >In addition, it will be appreciated if you would also submit kvm-unit-test that verifies this condition.
>
> I'd like to submit kvm-unit-test that verifies this condition, but I am not familiar with the kvm-unit-test code yet and
> also not in my recent todo list. So such a patch may come late. It would be appreciated too if you could submit this
> kvm-unit-test patch. :)

Hmm, did you verify your own patch? Please give the testcase.

2019-12-26 03:10:23

by Miaohe Lin

[permalink] [raw]
Subject: Re: [PATCH] KVM: nvmx: retry writing guest memory after page fault injected

Hi,

Wanpeng Li <[email protected]> wrote:
> On Thu, 26 Dec 2019 at 10:32, linmiaohe <[email protected]> wrote:
> >
> > >
> > >In addition, it will be appreciated if you would also submit kvm-unit-test that verifies this condition.
> >
> > I'd like to submit kvm-unit-test that verifies this condition, but I
> > am not familiar with the kvm-unit-test code yet and also not in my
> > recent todo list. So such a patch may come late. It would be
> > appreciated too if you could submit this kvm-unit-test patch. :)
>
> Hmm, did you verify your own patch? Please give the testcase.
>

I'am sorry but this is a code inspection path. And I think this fix is correct from the code logic and
this behavior is similar as handle_vmwrite, handle_vmptrst, handle_invept and so on. Thanks!