From: "Alex Bennée" <alex.bennee@linaro.org>
To: Julien Thierry <julien.thierry@arm.com>
Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org,
marc.zyngier@arm.com, open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 3/3] kvm: arm64: handle single-step of userspace mmio instructions
Date: Mon, 13 Nov 2017 14:39:11 +0000 [thread overview]
Message-ID: <87fu9itf8w.fsf@linaro.org> (raw)
In-Reply-To: <b3f76167-50e4-5f25-9ec2-16f07de0fd32@arm.com>
Julien Thierry <julien.thierry@arm.com> writes:
> Hi Alex,
>
> On 09/11/17 17:00, Alex Bennée wrote:
>> The system state of KVM when using userspace emulation is not complete
>> until we return into KVM_RUN. To handle mmio related updates we wait
>> until they have been committed and then schedule our KVM_EXIT_DEBUG.
>>
>> The kvm_arm_handle_step_debug() helper tells us if we need to return
>> and sets up the exit_reason for us.
>>
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>>
>> ---
>> v2
>> - call helper directly from kvm_arch_vcpu_ioctl_run
>> ---
>> virt/kvm/arm/arm.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c
>> index 95cba0799828..2991adfaca9d 100644
>> --- a/virt/kvm/arm/arm.c
>> +++ b/virt/kvm/arm/arm.c
>> @@ -625,6 +625,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
>> ret = kvm_handle_mmio_return(vcpu, vcpu->run);
>> if (ret)
>> return ret;
>> + if (kvm_arm_handle_step_debug(vcpu, vcpu->run))
>> + return 1;
>> +
>
> In the previous patch, kvm_arch_vcpu_ioctl_run return 0 when telling
> userspace about a debug exception. Shouldn't this branch return 0
> instead of 1?
Probably - although in practice it makes no difference. In QEMU for
example the test is if (run_ret < 0) to handle errors. Otherwise success
is assumed.
> Returning on non-zero for kvm_handle_mmio_return is done because it
> means there was an error. This is not the case for
> kvm_arm_handle_step_debug.
>
> The description in the comment of kvm_arch_vcpu_ioctl_run is not very
> clear whether non-zero result should be used for errors or if only the
> negative values are treated as such, and positive values seems to be
> generally used to keep the vcpu going. So, I thought it might make
> sense to always return the same value upon debug exceptions.
There is a subtle mis-match between what gets passed back to the ioctl
and what terminates the while() loop later on. As far as the ioctl is
concerned it's 0 success and - error. Once you get to the while loop
you'll only ever exit once ret is no longer > 0.
Anyway for consistency we should certainly return 0, I'll fix it on the
next iteration.
>
> Cheers,
--
Alex Bennée
WARNING: multiple messages have this Message-ID (diff)
From: alex.bennee@linaro.org (Alex Bennée)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 3/3] kvm: arm64: handle single-step of userspace mmio instructions
Date: Mon, 13 Nov 2017 14:39:11 +0000 [thread overview]
Message-ID: <87fu9itf8w.fsf@linaro.org> (raw)
In-Reply-To: <b3f76167-50e4-5f25-9ec2-16f07de0fd32@arm.com>
Julien Thierry <julien.thierry@arm.com> writes:
> Hi Alex,
>
> On 09/11/17 17:00, Alex Benn?e wrote:
>> The system state of KVM when using userspace emulation is not complete
>> until we return into KVM_RUN. To handle mmio related updates we wait
>> until they have been committed and then schedule our KVM_EXIT_DEBUG.
>>
>> The kvm_arm_handle_step_debug() helper tells us if we need to return
>> and sets up the exit_reason for us.
>>
>> Signed-off-by: Alex Benn?e <alex.bennee@linaro.org>
>>
>> ---
>> v2
>> - call helper directly from kvm_arch_vcpu_ioctl_run
>> ---
>> virt/kvm/arm/arm.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c
>> index 95cba0799828..2991adfaca9d 100644
>> --- a/virt/kvm/arm/arm.c
>> +++ b/virt/kvm/arm/arm.c
>> @@ -625,6 +625,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
>> ret = kvm_handle_mmio_return(vcpu, vcpu->run);
>> if (ret)
>> return ret;
>> + if (kvm_arm_handle_step_debug(vcpu, vcpu->run))
>> + return 1;
>> +
>
> In the previous patch, kvm_arch_vcpu_ioctl_run return 0 when telling
> userspace about a debug exception. Shouldn't this branch return 0
> instead of 1?
Probably - although in practice it makes no difference. In QEMU for
example the test is if (run_ret < 0) to handle errors. Otherwise success
is assumed.
> Returning on non-zero for kvm_handle_mmio_return is done because it
> means there was an error. This is not the case for
> kvm_arm_handle_step_debug.
>
> The description in the comment of kvm_arch_vcpu_ioctl_run is not very
> clear whether non-zero result should be used for errors or if only the
> negative values are treated as such, and positive values seems to be
> generally used to keep the vcpu going. So, I thought it might make
> sense to always return the same value upon debug exceptions.
There is a subtle mis-match between what gets passed back to the ioctl
and what terminates the while() loop later on. As far as the ioctl is
concerned it's 0 success and - error. Once you get to the while loop
you'll only ever exit once ret is no longer > 0.
Anyway for consistency we should certainly return 0, I'll fix it on the
next iteration.
>
> Cheers,
--
Alex Benn?e
next prev parent reply other threads:[~2017-11-13 14:39 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-09 17:00 [PATCH v2 0/3] KVM: arm64: single step emulation instructions Alex Bennée
2017-11-09 17:00 ` Alex Bennée
2017-11-09 17:00 ` [PATCH v2 1/3] kvm: arm debug: introduce helper for single-step Alex Bennée
2017-11-09 17:00 ` Alex Bennée
2017-11-09 17:00 ` Alex Bennée
2017-11-10 7:47 ` [PATCH] fixup! " Alex Bennée
2017-11-10 7:47 ` Alex Bennée
2017-11-10 7:47 ` Alex Bennée
2017-11-13 9:32 ` [PATCH v2 1/3] " Julien Thierry
2017-11-13 9:32 ` Julien Thierry
2017-11-13 9:32 ` Julien Thierry
2017-11-09 17:00 ` [PATCH v2 2/3] kvm: arm64: handle single-stepping trapped instructions Alex Bennée
2017-11-09 17:00 ` Alex Bennée
2017-11-09 17:00 ` Alex Bennée
2017-11-13 11:02 ` Julien Thierry
2017-11-13 11:02 ` Julien Thierry
2017-11-09 17:00 ` [PATCH v2 3/3] kvm: arm64: handle single-step of userspace mmio instructions Alex Bennée
2017-11-09 17:00 ` Alex Bennée
2017-11-09 17:00 ` Alex Bennée
2017-11-13 11:04 ` Julien Thierry
2017-11-13 11:04 ` Julien Thierry
2017-11-13 14:39 ` Alex Bennée [this message]
2017-11-13 14:39 ` Alex Bennée
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fu9itf8w.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=christoffer.dall@linaro.org \
--cc=julien.thierry@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.zyngier@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.