qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Richard Henderson <richard.henderson@linaro.org>,
	qemu-devel@nongnu.org, Phil Dennis-Jordan <phil@philjordan.eu>
Cc: imammedo@redhat.com, peterx@redhat.com
Subject: Re: [PATCH 2/8] accel/hvf: check exit_request before running the vCPU
Date: Mon, 11 Aug 2025 09:06:14 +0200	[thread overview]
Message-ID: <c5dabb13-0817-44c2-838a-e89b380a8861@redhat.com> (raw)
In-Reply-To: <e3f3a5cc-66aa-4e58-95bf-6f8648bf84ad@linaro.org>

On 8/10/25 01:09, Richard Henderson wrote:
> On 8/9/25 04:58, Paolo Bonzini wrote:
>> This is done by all other accelerators, but was missing for
>> Hypervisor.framework.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>   target/arm/hvf/hvf.c  | 4 ++++
>>   target/i386/hvf/hvf.c | 4 ++++
>>   2 files changed, 8 insertions(+)
>>
>> diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
>> index b77db99079e..478bc75fee6 100644
>> --- a/target/arm/hvf/hvf.c
>> +++ b/target/arm/hvf/hvf.c
>> @@ -1927,6 +1927,10 @@ int hvf_vcpu_exec(CPUState *cpu)
>>       flush_cpu_state(cpu);
>>       bql_unlock();
>> +    /* Corresponding store-release is in cpu_exit. */
>> +    if (qatomic_load_acquire(&cpu->exit_request)) {
>> +        hv_vcpus_exit(&cpu->accel->fd, 1);
>> +    }
>>       r = hv_vcpu_run(cpu->accel->fd);
> 
> This looks odd.
> 
> hv_vcpus_exit: "Forces an immediate exit of a set of vCPUs of the VM".
> 
> But we know for a fact fd isn't running, because that's to start in the 
> next line.  I suppose this must set a flag so that the kernel's 
> hv_vcpu_run exits immediately with CANCELED?
> 
> Does executing of hv_vcpu_run buy us anything else?  Is it less 
> confusing to simply return 0, modulo bql fiddling?
> 
>> diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
>> index 8445cadecec..b7c4b849cdf 100644
>> --- a/target/i386/hvf/hvf.c
>> +++ b/target/i386/hvf/hvf.c
>> @@ -749,6 +749,10 @@ int hvf_vcpu_exec(CPUState *cpu)
>>               return EXCP_HLT;
>>           }
>> +        /* Corresponding store-release is in cpu_exit. */
>> +        if (qatomic_load_acquire(&cpu->exit_request)) {
>> +            hv_vcpu_interrupt(&cpu->accel->fd, 1);
>> +        }
>>           hv_return_t r = hv_vcpu_run_until(cpu->accel->fd, 
>> HV_DEADLINE_FOREVER);
>>           assert_hvf_ok(r);
> 
> This, similarly, I guess returns EXCP_INTERRUPT.  Is that better or 
> worse than 0?

The advantage is that you can reuse the code for when another thread 
kicks you out of the execution loop.  For x86, for example, the effects 
of hvf_inject_interrupts() are undone by hv_vcpu_run() + hvf_store_events().

But on second thought this patch is not needed.  The kick is handled 
completely by Apple code and that's where any synchronization must 
happen.  In fact, there should be no need for hvf_kick_vcpu_thread() to 
call cpus_kick_thread() even (though I'd leave it to more HVF-literate 
people like Phil to do that).

Paolo



  reply	other threads:[~2025-08-11  7:07 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-08 18:58 [PATCH 0/8] accel, cpus: clean up cpu->exit_request Paolo Bonzini
2025-08-08 18:58 ` [PATCH 1/8] accel: use store_release/load_acquire for cross-thread exit_request Paolo Bonzini
2025-08-09 22:41   ` Richard Henderson
2025-08-11 19:31   ` Peter Xu
2025-08-08 18:58 ` [PATCH 2/8] accel/hvf: check exit_request before running the vCPU Paolo Bonzini
2025-08-08 21:28   ` Philippe Mathieu-Daudé
2025-08-09 23:09   ` Richard Henderson
2025-08-11  7:06     ` Paolo Bonzini [this message]
2025-08-08 18:59 ` [PATCH 3/8] accel: use atomic accesses for exit_request Paolo Bonzini
2025-08-08 21:04   ` Philippe Mathieu-Daudé
2025-08-09 23:10   ` Richard Henderson
2025-08-11 14:49   ` Alex Bennée
2025-08-11 19:33   ` Peter Xu
2025-08-08 18:59 ` [PATCH 4/8] accel/tcg: introduce tcg_kick_vcpu_thread Paolo Bonzini
2025-08-08 21:15   ` Philippe Mathieu-Daudé
2025-08-09 23:16     ` Richard Henderson
2025-08-09 23:26   ` Richard Henderson
2025-08-11  6:10     ` Paolo Bonzini
2025-08-11  8:33       ` Philippe Mathieu-Daudé
2025-08-11 13:34         ` Philippe Mathieu-Daudé
2025-08-08 18:59 ` [PATCH 5/8] cpus: remove TCG-ism from cpu_exit() Paolo Bonzini
2025-08-08 21:17   ` Philippe Mathieu-Daudé
2025-08-09 23:17   ` Richard Henderson
2025-08-08 18:59 ` [PATCH 6/8] cpus: properly kick CPUs out of inner execution loop Paolo Bonzini
2025-08-11 12:56   ` Alex Bennée
2025-08-08 18:59 ` [PATCH 7/8] tcg/user: do not set exit_request gratuitously Paolo Bonzini
2025-08-08 21:21   ` Philippe Mathieu-Daudé
2025-08-08 21:45     ` Paolo Bonzini
2025-08-08 18:59 ` [PATCH 8/8] accel: make all calls to qemu_wait_io_event look the same Paolo Bonzini
2025-08-08 21:24   ` Philippe Mathieu-Daudé
2025-08-09 23:34   ` Richard Henderson

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=c5dabb13-0817-44c2-838a-e89b380a8861@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=peterx@redhat.com \
    --cc=phil@philjordan.eu \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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).