From: Paolo Bonzini <pbonzini@redhat.com>
To: Roman Bolshakov <r.bolshakov@yadro.com>, qemu-devel@nongnu.org
Cc: Eduardo Habkost <ehabkost@redhat.com>,
Claudio Fontana <cfontana@suse.de>,
Cameron Esfahani <dirty@apple.com>,
Richard Henderson <rth@twiddle.net>
Subject: Re: [PATCH v3] i386: hvf: Implement CPU kick
Date: Thu, 2 Jul 2020 14:42:45 +0200 [thread overview]
Message-ID: <fa29e532-a891-cf61-a8a2-af5e36e7834f@redhat.com> (raw)
In-Reply-To: <20200702105721.75333-1-r.bolshakov@yadro.com>
On 02/07/20 12:57, Roman Bolshakov wrote:
> There's still a small chance of kick loss, on user-to-kernel border
> between atomic_mb_set's just before the entry to hv_vcpu_run and just
> after it.
Good point, but we can fix it.
> -static void dummy_signal(int sig)
> +static void hvf_handle_ipi(int sig)
> {
> + CPUState *cpu = pthread_getspecific(hvf_cpu);
You can use current_cpu here. If it's NULL, just return (it's a
per-thread variable).
> + X86CPU *x86_cpu = X86_CPU(cpu);
> + CPUX86State *env = &x86_cpu->env;
> +
> + if (!atomic_xchg(&env->hvf_in_guest, false)) {
Here, thinking more about it, we need not write hvf_in_guest, so:
/* Write cpu->exit_request before reading env->hvf_in_guest. */
smp_mb();
if (!atomic_read(&env->hvf_in_guest)) {
...
}
> + wvmcs(cpu->hvf_fd, VMCS_PIN_BASED_CTLS,
> + rvmcs(cpu->hvf_fd, VMCS_PIN_BASED_CTLS)
> + | VMCS_PIN_BASED_CTLS_VMX_PREEMPT_TIMER);
> + }
> }
>
> int hvf_init_vcpu(CPUState *cpu)
> @@ -631,7 +650,9 @@ int hvf_vcpu_exec(CPUState *cpu)
> return EXCP_HLT;
> }
>
> + atomic_mb_set(&env->hvf_in_guest, true);
> hv_return_t r = hv_vcpu_run(cpu->hvf_fd);
> + atomic_mb_set(&env->hvf_in_guest, false);
And here you can do instead:
atomic_set(&env->hvf_in_guest, true);
/* Read cpu->exit_request after writing env->hvf_in_guest. */
smp_mb();
if (atomic_read(&cpu->exit_request)) {
qemu_mutex_lock_iothread();
atomic_set(&env->hvf_in_guest, false);
return EXCP_INTERRUPT;
}
hv_return_t r = hv_vcpu_run(cpu->hvf_fd);
atomic_store_release(&env->hvf_in_guest, false);
This matching "write A/smp_mb()/read B" and "write B/smp_mb()/read A" is
a very common idiom for lock-free signaling between threads.
Paolo
next prev parent reply other threads:[~2020-07-02 12:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-02 10:57 [PATCH v3] i386: hvf: Implement CPU kick Roman Bolshakov
2020-07-02 12:42 ` Paolo Bonzini [this message]
2020-07-13 9:39 ` Roman Bolshakov
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=fa29e532-a891-cf61-a8a2-af5e36e7834f@redhat.com \
--to=pbonzini@redhat.com \
--cc=cfontana@suse.de \
--cc=dirty@apple.com \
--cc=ehabkost@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=r.bolshakov@yadro.com \
--cc=rth@twiddle.net \
/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).