[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 09/39] xen/riscv: implement virtual APLIC MMIO emulation
- To: Jan Beulich <jbeulich@xxxxxxxx>
- From: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
- Date: Thu, 10 Sep 2026 16:24:06 +0200
- Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Content-Language:References:Cc:To:Subject:From:User-Agent:MIME-Version:Date:Message-ID"
- Cc: Romain Caritey <Romain.Caritey@xxxxxxxxxxxxx>, Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>, Zheng Zhang <zhangzheng@xxxxxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
- Delivery-date: Thu, 10 Sep 2026 14:24:12 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 9/10/26 1:14 PM, Jan Beulich wrote:
On 10.09.2026 12:37, Oleksii Kurochko wrote:
On 9/9/26 4:26 PM, Jan Beulich wrote:
On 27.08.2026 17:20, Oleksii Kurochko wrote:
+uint32_t aplic_msi_target_gen(const struct vcpu *target_vcpu,
+ uint32_t base_val)
+{
+ unsigned int guest_id = vcpu_guest_file_id(target_vcpu);
+ unsigned long hart_field = aplic_hart_field(target_vcpu->processor);
What guarantees target_vcpu's ->processor field to be meaningful at this
point?
Good question. Considering the places where it is called, I would expect
target_vcpu->processor to have something meaningful, since it is called
from a place that can only be reached when the guest is running.
Even without that, I don't think there is a big issue here, as
->processor is initialized to 0 at allocation time. This means that the
target register will be configured in such a way that CPU 0 will handle
such IRQs.
I may not have been explicit enough then: Whether the guest (as a whole)
is running is of no interest. If the specific vCPU is running, all is fine.
If the specific vCPU is in the process of being moved to a different CPU,
and if you read ->processor just before the new value is put there, is
all going to be fine as well? I doubt that.
You're right, and it's worse than a stale CPU number: v->processor is
updated by the scheduler (sched_unit_migrate_finish()) before
sched_move_irqs() -> imsic_migrate_vcpu() moves the interrupt file, so a
concurrent vAPLIC TARGET write can combine the new CPU with the old
guest file index (an MSI into someone else's file, which
aplic_reconfigure_target(), which is introduced later in this patch
series, won't catch), or compute a correct old target but write it after
aplic_reconfigure_target() (the function which is called during
migration to re-target irqs to new pCPU) has already scanned.
In v3 I'll (a) stop using ->processor and take the (guest_file_id,
vsfile_cpu) pair, which imsic_update_state() updates atomically under
vsfile_lock, and (b) do the snapshot plus the h/w TARGET write under
aplic.lock, which aplic_reconfigure_target() also holds. As
imsic_update_state() completes before aplic_reconfigure_target() (also
that could be checked in this patch series and is introduced a little
bit later. Probably I have to re-order some patches again) takes the
lock, the emulated write either happens before the scan (and gets fixed
up, or skipped as already correct) or after it (and sees the new location).
Any better option I have now?
~ Oleksii
|