From: "Alex Bennée" <alex.bennee@linaro.org>
To: Pranith Kumar <bobby.prani@gmail.com>
Cc: qemu-devel@nongnu.org, Richard Henderson <rth@twiddle.net>,
Peter Maydell <peter.maydell@linaro.org>
Subject: Re: [Qemu-devel] [PATCH v2] mttcg/i386: Patch instruction using async_safe_* framework
Date: Fri, 24 Feb 2017 14:36:14 +0000 [thread overview]
Message-ID: <87tw7jlkpt.fsf@linaro.org> (raw)
In-Reply-To: <87zihbaddl.fsf@gmail.com>
Pranith Kumar <bobby.prani@gmail.com> writes:
> Hi Alex,
>
> Alex Bennée writes:
>
>> Pranith Kumar <bobby.prani@gmail.com> writes:
>>
>>> In mttcg, calling pause_all_vcpus() during execution from the
>>> generated TBs causes a deadlock if some vCPU is waiting for exclusive
>>> execution in start_exclusive(). Fix this by using the aync_safe_*
>>> framework instead of pausing vcpus for patching instructions.
>>>
>
> <...>
>
>>> diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
>>> index 82a4955..11b0d49 100644
>>> --- a/hw/i386/kvmvapic.c
>>>
>>> - resume_all_vcpus();
>>> + g_free(info);
>>> +}
>>> +
>>> +static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
>>> +{
>>> + CPUState *cs = CPU(cpu);
>>> + VAPICHandlers *handlers;
>>> + struct PatchInfo *info;
>>> +
>>> + if (smp_cpus == 1) {
>>> + handlers = &s->rom_state.up;
>>> + } else {
>>> + handlers = &s->rom_state.mp;
>>> + }
>>> +
>>> + info = g_new(struct PatchInfo, 1);
>>> + info->handler = handlers;
>>> + info->ip = ip;
>>>
>>> if (!kvm_enabled()) {
>>> - /* Both tb_lock and iothread_mutex will be reset when
>>> - * longjmps back into the cpu_exec loop. */
>>> - tb_lock();
>>> - tb_gen_code(cs, current_pc, current_cs_base, current_flags, 1);
>>> - cpu_loop_exit_noexc(cs);
>>> + const run_on_cpu_func fn = do_patch_instruction;
>>> +
>>> + async_safe_run_on_cpu(cs, fn, RUN_ON_CPU_HOST_PTR(info));
>>> + cs->exception_index = EXCP_INTERRUPT;
>>> + cpu_loop_exit(cs);
>>> }
>>> +
>>> + pause_all_vcpus();
>>> +
>>> + do_patch_instruction(cs, RUN_ON_CPU_HOST_PTR(info));
>>> +
>>> + resume_all_vcpus();
>>> + g_free(info);
>>
>> I don't know if there is any benefit scheduling this as async work for
>> KVM but I'll leave that up to Paolo to decide. From a TCG point of view
>> I think its good:
>>
>
> We are scheduling this as async work only for non-KVM cases. For KVM, we use
> go to the pause/resume path above and patch it there itself.
No I mean would it be more efficient to do that for KVM as safe work. To
be honest the code to pause_all_vcpus() seems a little hokey given
cpu_stop_current() somehow stops itself while cpu_exit'ing the rest of
the vcpus. But I guess you would involve an additional KVM transition
for the calling thread, I'm not sure hence the deference to the KVM
experts ;-)
>
> Thanks,
--
Alex Bennée
next prev parent reply other threads:[~2017-02-24 14:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-24 5:42 [Qemu-devel] [PATCH v2] mttcg/i386: Patch instruction using async_safe_* framework Pranith Kumar
2017-02-24 6:54 ` Richard Henderson
2017-02-24 10:21 ` Alex Bennée
2017-02-24 14:10 ` Pranith Kumar
2017-02-24 14:36 ` Alex Bennée [this message]
2017-06-07 16:40 ` Pranith Kumar
2017-06-07 18:09 ` Alex Bennée
2017-06-07 18:46 ` Pranith Kumar
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=87tw7jlkpt.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=bobby.prani@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--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).