From: Paolo Bonzini <pbonzini@redhat.com>
To: Lara Lazier <laramglazier@gmail.com>, qemu-devel@nongnu.org
Subject: Re: [PATCH] target/i386: Added VGIF feature
Date: Fri, 23 Jul 2021 15:52:53 +0200 [thread overview]
Message-ID: <52adaf59-efaf-a56b-a7b4-624513d43875@redhat.com> (raw)
In-Reply-To: <20210723112753.46047-1-laramglazier@gmail.com>
On 23/07/21 13:27, Lara Lazier wrote:
> @@ -353,9 +358,12 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend)
> tlb_flush(cs);
> break;
> }
> -
> - env->hflags2 |= HF2_GIF_MASK;
> -
> + if (virtual_gif_enabled(env, int_ctl)) {
> + x86_stl_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.int_ctl),
> + int_ctl |= V_GIF_MASK);
> + } else {
> + env->hflags2 |= HF2_GIF_MASK;
> + }
This should not be changed, because it is setting the "real" GIF; vGIF
hasn't taken effect yet.
The CLGI/VMRUN/STGI sequence is there to avoid delivering an interrupt
while the processor state has been partly changed to whatever the guest
wants. VMRUN sets GIF so that it is possible for interrupts (or
NMI/SMI) to cause a vmexit, but the vmexit immediately clears the GIF
again so that it is only handled after the host executes STGI.
> if (int_ctl & V_IRQ_MASK) {
> CPUState *cs = env_cpu(env);
>
> @@ -513,13 +521,31 @@ void helper_vmsave(CPUX86State *env, int aflag)
> void helper_stgi(CPUX86State *env)
> {
> cpu_svm_check_intercept_param(env, SVM_EXIT_STGI, 0, GETPC());
> - env->hflags2 |= HF2_GIF_MASK;
> +
> + CPUState *cs = env_cpu(env);
> + uint32_t int_ctl = x86_ldl_phys(cs,
> + env->vm_vmcb + offsetof(struct vmcb, control.int_ctl));
> + if (virtual_gif_enabled(env, int_ctl) && likely(env->hflags & HF_GUEST_MASK)) {
> + x86_stl_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.int_ctl),
> + int_ctl |= V_GIF_MASK);
No need to use "|=", likewise for "&=" below.
Thanks,
Paolo
> + } else {
> + env->hflags2 |= HF2_GIF_MASK;
> + }
> }
>
> void helper_clgi(CPUX86State *env)
> {
> cpu_svm_check_intercept_param(env, SVM_EXIT_CLGI, 0, GETPC());
> - env->hflags2 &= ~HF2_GIF_MASK;
> +
> + CPUState *cs = env_cpu(env);
> + uint32_t int_ctl = x86_ldl_phys(cs,
> + env->vm_vmcb + offsetof(struct vmcb, control.int_ctl));
> + if (virtual_gif_enabled(env, int_ctl) && likely(env->hflags & HF_GUEST_MASK)) {
> + x86_stl_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.int_ctl),
> + int_ctl &= ~V_GIF_MASK);
> + } else {
> + env->hflags2 &= ~HF2_GIF_MASK;
> + }
> }
>
> bool cpu_svm_has_intercept(CPUX86State *env, uint32_t type)
>
prev parent reply other threads:[~2021-07-23 13:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-23 11:27 [PATCH] target/i386: Added VGIF feature Lara Lazier
2021-07-23 13:52 ` Paolo Bonzini [this message]
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=52adaf59-efaf-a56b-a7b4-624513d43875@redhat.com \
--to=pbonzini@redhat.com \
--cc=laramglazier@gmail.com \
--cc=qemu-devel@nongnu.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).