From nobody Thu Sep 24 18:59:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1790159254; cv=none; d=zohomail.com; s=zohoarc; b=cOcJc7Cv3p4ohKTt1JNYt4WAnSRaIrkNFlo93GsRxmFb4Yw6fCE9dCpbWmDLkzoihcyMSyfdNcKV96FavrH3nElgsMs5zFIMD2veFDvfuJRLCrgUgX9JCBkDCDkX514cfWTmcPNuJ9oY86XRB7LxJu2o+QBxuMypHnuip4iARA8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790159254; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VdRGXbL3r1ReXwiz3W+ag2f41ewb62moUHap2/8mMZo=; b=fp1wKPUTdOxr2aL4eMbQ8M70tkl67sJgLyN6aAW8iy/dcIoIflZnCOL7jCHnkajSymjle2EuYk0knryi0/h6VSp9NWc9hzeCQflg1O0jfXNZqVrPKY0qcMJQzJCouE7HNALL9dbJ9v1ktc8iFOCLFRNyCwKMcDYN95GO/QN2lM4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1790159253995271.63552930230003; Wed, 23 Sep 2026 03:27:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1430100.1652671 (Exim 4.92) (envelope-from ) id 1x9KBr-00025S-4u; Wed, 23 Sep 2026 10:27:03 +0000 Received: by outflank-mailman (output) from mailman id 1430100.1652671; Wed, 23 Sep 2026 10:27:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1x9KBr-00025L-1L; Wed, 23 Sep 2026 10:27:03 +0000 Received: by outflank-mailman (input) for mailman id 1430100; Wed, 23 Sep 2026 10:27:01 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) id 1x9KBo-0001sd-Vf for xen-devel@lists.xenproject.org; Wed, 23 Sep 2026 10:27:01 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1x9KBo-00Cn1P-CU for xen-devel@lists.xenproject.org; Wed, 23 Sep 2026 12:27:00 +0200 Received: from [10.42.69.6] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6ab3a974-2eae-0a2a0a5409dd-0a2a4506a1fe-4 for ; Wed, 23 Sep 2026 12:27:00 +0200 Received: from [74.125.225.76] (helo=mail-wr2-f12.google.com) by tlsNG-16d1c6.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6ab3a974-195a-0a2a45060019-4a7de14c9bca-3 for ; Wed, 23 Sep 2026 12:27:00 +0200 Received: by mail-wr2-f12.google.com with SMTP id ffacd0b85a97d-482f633ecdeso637768f8f.2 for ; Wed, 23 Sep 2026 03:27:00 -0700 (PDT) Received: from fedora (user-109-243-71-234.play-internet.pl. [109.243.71.234]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fe0c50da7sm32786515e9.3.2026.09.23.03.26.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2026 03:26:59 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790159220; x=1790764020; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=VdRGXbL3r1ReXwiz3W+ag2f41ewb62moUHap2/8mMZo=; b=DI6grSujbFj1SE7Uvq5rjIsZD+F3dZoTOxkDlpVKKzX1WwOr+y0B8HG7TrwS9Mfzry h1Zd46glg+WA7BzH0FYw1SUlDFkItDXkZFFPMv1nwzCksGiHDWkOjSxpNMzIKAkMu8tU ys1+L1HPrcwPGxMHDGrX0JwUPwqufTowUoZ/LLs971O7PdEtBDifGxqmVDyO6+cf+vl+ GObac/P89lntm7w9081PiIC3DnKc7MEJ6wbZVtdI0ye2OG7Isze4gLaIrZhDg3cujHEo 9FdIq6ibh4bCKFa50LAAs9RuRfWhvkOxuexuH7AxOHBjVq47Fhu4JqprG6+eaxLO+PIa SuIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790159220; x=1790764020; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=VdRGXbL3r1ReXwiz3W+ag2f41ewb62moUHap2/8mMZo=; b=bzpjaYQq3EDUkS3ZWAifkuc99u7zimcvzsagT21Y1GYh9r162JECKgdbzsen0z81It S+Ye8pz1Qd4SNdMnjQDSuTfjSC8v111843wV6E1lI8lW5sP30L4dEwRdU9UTqXvJGhIS WCFCRJP5mjQ1Qpx7h0CuNXQhtsYAwpEeryji3CjUNlXcuKLctK+57OwxiNC+/I1zOl5T XzHmHQ7UpJJPoFQMfQkegpIs3/5/hmSRV2OzLzookHE4HlkS5kp8WrE0IQlBxm5n3RUQ Ecpp3gK9EYD2rmEXdtsw+ulXasNiZMdPi8qQazPLSewyFHdgc+7zoqCmTHhQh/B6mNty E61g== X-Gm-Message-State: AFuF++kaqfttpIWbSOZ1v8eTsFKG2ZIbQBz0Kq81KZGtCUkJgYQolMMD IDtxqxKCiOrAPHsOHTJ7UXpWdqRIQImhcTYvH5Iui3uMx8MA75uHLFi5Yg/W6w== X-Gm-Gg: AYBFou25k3qtPcuieHZL8Tt9LxB471KCiy5yYcsf/8iv9O3P48Sz1HW0J4qBSzSVDVh RrGiTm62gFd0rz2Rei57VljkmEwXwVHTs8Xi09hinhZiv3dmCIf5Iw/eeF9sMu5g5Su6YCsICDW iOtzxFMUXwNBUVTJQRog+ovCWwW2PR5dJv4cLN/QnVOgl0L64KYTIqa1bo+AldhBW744/UK4l8w RRrlHEyaMNcUWZWQ6b8+u+VlwCtMPaIbesnMeDolcd5oznzf4aWeEsz44RErPOm7Hgkv5AxgI2E AMA9UKHSLBqjC0Vd+GVFURJuaPA/jOfx6/BzEFG28DVPrEPNvxgm7lAkCVNdpANBnbLSsdr8r/i 7Ewob1RrLLdQ7xNwuK6qywuVGjAijTtTlxBHDUEK0cZ6eMmet/TnDUrhqetbOoB/4DkqMdXla3d eE7ew1CUoLjq621eMVt8vQPUZG0WKAmbjkK8Q+CSadJs/pPhZXrKTG21pMSWb8FpxOpsVgdWeaN xl/JXRaMgkmc4Ylx7g7U6rzUVOrKNIDT6OXKY/t X-Received: by 2002:a05:600c:3512:b0:49c:fc6c:be0d with SMTP id 5b1f17b1804b1-49fdf12b393mr30224995e9.19.1790159219441; Wed, 23 Sep 2026 03:26:59 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Romain Caritey , Baptiste Le Duc , Zheng Zhang , Oleksii Kurochko , Alistair Francis , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , "Daniel P. Smith" Subject: [PATCH v10 1/5] xen/riscv: implement IRQ routing for device passthrough Date: Wed, 23 Sep 2026 12:26:45 +0200 Message-ID: <99d3f072b0c4b97e2ebac8b227bd57f90e780605.1790158750.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-16d1c6/1790159220-F440377B-F5CD01AC/10/73395122804 X-purgate-type: spam X-purgate-size: 31425 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1790159255821158500 Content-Type: text/plain; charset="utf-8" dom0less device passthrough requires granting guest domains access to device interrupts. Introduce map_device_irqs_to_domain() to enumerate a DT node's interrupt properties, skipping those not owned by the primary interrupt controller (as at the moment I haven't seen usages of it), and map_irq_to_domain() to grant domain access and configure Xen's interrupt descriptor accordingly. Sharing IRQ between domains is rejected. Both map_irq_to_domain() and map_device_irqs_to_domain() are marked __overlay_init, mirroring Arm: without CONFIG_OVERLAY_DTB this expands to __init, so the functions are init-only and need no XSM check; with CONFIG_OVERLAY_DTB they become runtime-callable, but the only runtime entry point is dt_overlay_domctl(), which performs the XSM checks at the domctl layer. RISC-V does not wire up DT overlay yet, so today these are strictly __init; if/when overlay support is added, the domctl-level XSM gating must be added together with it, as on Arm. route_irq_to_guest() and release_guest_irq() manage irq_desc ownership for guest-assigned interrupts. Each assignment carries a small irq_guest structure as irqaction::dev_id, recording the owning domain and virtual IRQ number which is 1:1 mapped to physical IRQ number. A per-domain vIRQ allocation bitmap (used_irqs in struct vintc), managed by vintc_reserve_virq(), prevents the same vIRQ being claimed twice. Host and guest interrupts may differ in some operations, EOI timing in particular: a host IRQ is completed once Xen's handler runs, whereas a passthrough IRQ must defer the physical completion until the guest issues its own EOI, otherwise a still-asserted level line would immediately retrigger and storm. Hence a separate guest hw_irq_controller instance, aplic_guest_irq_type, rather than an alias of the host one. Its callbacks are BUG_ON("unimplemented") for now. The only interrupt controller configuration supported so far is APLIC in MSI mode together with IMSIC, where guest interrupts are delivered by hardware straight to the guest's interrupt file, bypassing do_IRQ() and thereby Xen entirely. The _IRQ_GUEST branch in do_IRQ() is left as BUG() for the same reason. Real callbacks, .end() in particular, become necessary once a platform without direct IMSIC delivery has to be supported, where Xen traps the interrupt and injects it into the guest itself. Signed-off-by: Oleksii Kurochko --- Changes in v10: - Rename aplic_guest back to aplic_guest_irq_type, for consistency with aplic_xen_irq_type, and give it a distinct typename ("aplic-guest"). - Replace the remaining test_bit()/__set_bit() on desc->status with plain bit operations, as the v9 changelog claimed. The wait loop in irq_release_action() keeps test_bit(): the loop must re-read desc->status on every iteration because another CPU may clear IRQ_INPROGRESS. The volatile read performed by test_bit() prevents the compiler from hoisting the read out of the loop, which would otherwise leave the loop spinning forever on a stale value. cpu_relax() is not a compiler barrier, so it cannot provide this guarantee by itself. - Actually drop the init. of info->action.free_on_release, as the v9 changelog claimed. - Prefix the remaining "already used by ..." messages in route_irq_to_guest() with %pd, as the v9 changelog claimed. - release_guest_irq(): reword the comment above irq_detach_action() to say that a concurrent release "will see" IRQ_GUEST cleared, as with desc->lock held no racing check can occur. - Drop Arm change from this patch. - Update the description of the host/guest hw_irq_controller split: the two no longer share any callback. - Re-wrap an over-long comment in domain_vaplic_init(). --- Changes in v9: - s/aplic_guest_irq_type/aplic_guest + introduce stubs for callbacks instead of re-using callbacks used for Xen itself. - Correct the comment above action member of struct irq_guest. - Drop test_bit() from ASSERT() in irq_get_guest_info(). - Use bit operations instead of __clear_bit() in irq_detach_action(). - Fomrat do () while () in irq_release_action() according to code style. - Update the comment above irq_release_action() and inside (before smp_rmb(= )). - Make an argument of release_guest_irq() pointer to const. - Drop init. of info->action.free_on_release as it will be false because of= how info is allocated. - Align comments in printk() inside route_irq_to_guest(). - Move smp_rmb() after the wait loop in irq_release_action() (inside it, it ordered nothing useful) and spin with cpu_relax(). --- Changes in v8: - vintc_reserve_virq(): return an error code instead of a bool: 0 on success, -EEXIST when the vIRQ has already been reserved (which legitimately happens for an IRQ shared between devices) and -ERANGE when the vIRQ is outside the range the vINTC provides. Document the function and its return values. - vintc_reserve_virq(): mark it __overlay_init, as its only caller map_irq_to_domain() is __overlay_init too. Add the and includes this needs. - map_irq_to_domain(): check the return value of vintc_reserve_virq() and propagate anything but -EEXIST. Otherwise the IRQ would end up routed to the domain without domain_vintc_deinit() ever releasing it again. Update the stale comment accordingly. - domain_vintc_deinit(): only walk used_irqs and free it if it has actually been allocated. domain_vintc_init() can fail after the vINTC itself has been allocated, leaving used_irqs NULL. - irq.c: split the body of release_irq() into two helpers: irq_detach_action(), which removes the action matching dev_id from desc->action with desc->lock held, and irq_release_action(), which waits for a handler still running on another CPU and frees the action with desc->lock dropped. Both document the locking rules they rely on. release_irq() is now just a wrapper around the two. - release_guest_irq(): use irq_detach_action()/irq_release_action() instead of open-coding __clear_bit(_IRQ_GUEST, ...) followed by release_irq(), which looked the action up by dev_id a second time. - release_guest_irq(): drop the -EBUSY restriction that only allowed unrouting from a dying domain. Detaching the action under desc->lock now closes the window this was working around. - route_irq_to_guest(): on the intc_route_irq_to_guest() failure path, detach the action while desc->lock is still held and only release it after the lock has been dropped, instead of dropping the lock first and calling release_irq(). - route_irq_to_guest(): initialise desc at its declaration. - irq_get_guest_info(): use ASSERT(desc->action) instead of ASSERT(desc->action !=3D NULL). --- Changes in v7: - Build device.c as device.init.o: everything it provides is __overlay_init, which is plain __init as long as CONFIG_OVERLAY_DTB stays Arm-only. Unlike Arm, which picks device.o/device.init.o based on that config, RISC-V cannot enable it, so the choice is unconditional for now. - Don't have release_irq() free the guest IRQ info anymore: set free_on_release =3D false and free 'info' explicitly in release_guest_irq(), i.e. reinstate the xvfree() dropped in v5. The action stays embedded in struct irq_guest, so a single allocation still covers both, but it no longer has to be the structure's first member: the offsetof() BUILD_BUG_ON and the xvfree() of a pointer that merely happened to coincide with the allocation base are gone. The ->dev_id concern from v5 doesn't apply: release_irq() clears desc->action under desc->lock and waits for in-flight handling before returning, so nothing can observe ->dev_id once 'info' is freed. - Move 'action' to the end of struct irq_guest and reword its comment accordingly. - Use xvzalloc() instead of xvmalloc() for struct irq_guest, so that the embedded action is fully initialized (action.handler was left uninitialized before). - route_irq_to_guest(): free 'info' via the common free_info label when intc_route_irq_to_guest() fails, now that release_irq() no longer frees it. - Drop a stray blank line ahead of release_irq(). --- Changes in v6: - size nr_virqs as guest_aplic_num_sources + 1 to reserve APLIC's 1-indexed source 0, so the highest source/irq could be reserved. --- Changes in v5: - add early -EINVAL return in route_irq_to_guest() if domain is dying - use __clear_bit() instead of clear_bit() in release_guest_irq() since desc->lock is already held - remove irq_get_domain() wrapper; inline irq_get_guest_info(desc)->d at its single call site - reword IRQ_GUEST comment in do_IRQ() for clarity - move XVFREE(used_irqs) before the switch so it is freed prior to variant-specific vintc teardown - fix missing space in dt_dprintk() format string split across lines - Drop 'inline' for irq_get_guest_info() and leave it only static. - Drop xfree(info) from release_guest_irq() to avoid a potential dangling-pointer issue with the ->dev_id field. Now that 'struct irqaction action;' is embedded into 'struct irq_guest', 'info' will be freed as part of release_irq() at the end. --- Changes in v4: - Update the commit message. - Mark map_irq_to_domain() and map_device_irqs_to_domain() as __overlay_init (mirroring Arm) and include . - Fix grammar in the controller-skip comment ("IRQ" -> "IRQs"). - Drop the redundant 'base' local in guest_imsic_make_reg_property(); use GUEST_IMSIC_S_BASE directly. - Rename vintc::irq_nums -> nr_virqs and update all users. - Guard domain_vintc_deinit() against a NULL d->arch.vintc. - Use smp_rmb() instead of smp_mb() in release_irq()'s wait loop and document how it pairs with the spin_unlock() in do_IRQ(). - In release_guest_irq(), reject live unrouting from a non-dying domain (-EBUSY) and clear _IRQ_GUEST under desc->lock so a concurrent release for the same IRQ bails out instead of double-freeing 'info'. - Tidy spurious whitespace in release_irq()'s spin_lock/unlock calls. --- Changes in v3: - Drop extraneous "to" from "Unable to permit to %pd" message. - Move res/irq/rirq to loop scope; use nirq as declaration initializer. - Hoist irq_ranges check before the loop (it is loop-invariant). - Remove spurious forward declarations (struct dt_device_node, struct rangeset) from intc.h; remove all three from setup.h. - Use __set_bit() instead of set_bit() in intc_route_irq_to_guest() since desc->lock is always held on every write path for desc->status. - Use XVFREE() instead of xvfree() in domain_vintc_deinit(). - Rename allocated_irqs -> used_irqs in struct vintc. - Fix dangling desc->action in release_irq()'s !IRQ_HAS_MULTIPLE_ACTION path by nulling *action_ptr after saving the action pointer. - Use true (not 1) for free_on_release in route_irq_to_guest(). - Use %pd for domain printing in route_irq_to_guest() error paths. - Introduce release_guest_irq() to pair with route_irq_to_guest() and plug the irq_guest info leak; call it from domain_vintc_deinit() for each vIRQ recorded in used_irqs. --- Changes in v2: - Rework IRQ mapping in more common (similar approach to Arm). --- --- xen/arch/riscv/Makefile | 1 + xen/arch/riscv/aplic.c | 31 ++++ xen/arch/riscv/device.c | 100 ++++++++++++ xen/arch/riscv/include/asm/intc.h | 9 ++ xen/arch/riscv/include/asm/irq.h | 5 + xen/arch/riscv/intc.c | 60 +++++++ xen/arch/riscv/irq.c | 260 ++++++++++++++++++++++++++++++ xen/arch/riscv/vaplic.c | 10 ++ 8 files changed, 476 insertions(+) create mode 100644 xen/arch/riscv/device.c diff --git a/xen/arch/riscv/Makefile b/xen/arch/riscv/Makefile index 511ced09ec7e..665ec2693335 100644 --- a/xen/arch/riscv/Makefile +++ b/xen/arch/riscv/Makefile @@ -1,6 +1,7 @@ obj-y +=3D aia.o obj-y +=3D aplic.o obj-y +=3D cpufeature.o +obj-y +=3D device.init.o obj-y +=3D domain.o obj-y +=3D domain-build.init.o obj-$(CONFIG_DOM0LESS_BOOT) +=3D dom0less-build.init.o diff --git a/xen/arch/riscv/aplic.c b/xen/arch/riscv/aplic.c index c2d7183e1852..17c96177a3b1 100644 --- a/xen/arch/riscv/aplic.c +++ b/xen/arch/riscv/aplic.c @@ -325,9 +325,40 @@ static const hw_irq_controller aplic_xen_irq_type =3D { .set_affinity =3D aplic_set_irq_affinity, }; =20 +static unsigned int cf_check aplic_guest_irq_startup(struct irq_desc *desc) +{ + BUG_ON("unimplemented"); +} + +/* + * Shared by ->shutdown(), ->enable(), ->disable() and ->end(), which have + * no state. + */ +static void cf_check aplic_guest_irq_stub(struct irq_desc *desc) +{ + BUG_ON("unimplemented"); +} + +static void cf_check aplic_guest_set_irq_affinity(struct irq_desc *desc, + const cpumask_t *mask) +{ + BUG_ON("unimplemented"); +} + +static const hw_irq_controller aplic_guest_irq_type =3D { + .typename =3D "aplic-guest", + .startup =3D aplic_guest_irq_startup, + .shutdown =3D aplic_guest_irq_stub, + .enable =3D aplic_guest_irq_stub, + .disable =3D aplic_guest_irq_stub, + .end =3D aplic_guest_irq_stub, + .set_affinity =3D aplic_guest_set_irq_affinity, +}; + static const struct intc_hw_operations aplic_ops =3D { .info =3D &aplic_info, .host_irq_type =3D &aplic_xen_irq_type, + .guest_irq_type =3D &aplic_guest_irq_type, .handle_interrupt =3D aplic_handle_interrupt, .set_irq_type =3D aplic_set_irq_type, }; diff --git a/xen/arch/riscv/device.c b/xen/arch/riscv/device.c new file mode 100644 index 000000000000..fc41c075c772 --- /dev/null +++ b/xen/arch/riscv/device.c @@ -0,0 +1,100 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include +#include +#include +#include +#include +#include + +#include + +int __overlay_init map_irq_to_domain(struct domain *d, unsigned int irq, + bool need_mapping, const char *devnam= e) +{ + int res; + + res =3D irq_permit_access(d, irq); + if ( res ) + { + printk(XENLOG_ERR "Unable to permit %pd access to IRQ %u\n", d, ir= q); + return res; + } + + if ( need_mapping ) + { + /* + * -EEXIST merely means that the IRQ has already been reserved, wh= ich + * legitimately happens when the IRQ is shared between devices. Any + * other failure has to be fatal: the IRQ would otherwise be route= d to + * the domain without domain_vintc_deinit() ever releasing it agai= n. + */ + res =3D vintc_reserve_virq(d, irq); + if ( res && (res !=3D -EEXIST) ) + { + printk(XENLOG_ERR "Unable to reserve vIRQ %u for %pd\n", irq, = d); + return res; + } + + res =3D route_irq_to_guest(d, irq, irq, devname); + if ( res < 0 ) + { + printk(XENLOG_ERR "Unable to map IRQ%u to %pd\n", irq, d); + return res; + } + } + + dt_dprintk(" - IRQ: %u\n", irq); + + return 0; +} + +int __overlay_init map_device_irqs_to_domain(struct domain *d, + struct dt_device_node *dev, + bool need_mapping, + struct rangeset *irq_ranges) +{ + unsigned int i, nirq =3D dt_number_of_irq(dev); + + if ( irq_ranges ) + return -EOPNOTSUPP; + + /* Give permission and map IRQs */ + for ( i =3D 0; i < nirq; i++ ) + { + int res, irq; + struct dt_raw_irq rirq; + + res =3D dt_device_get_raw_irq(dev, i, &rirq); + if ( res ) + { + printk(XENLOG_ERR "Unable to retrieve irq %u for %s\n", + i, dt_node_full_name(dev)); + return res; + } + + /* + * Don't map IRQs that have no physical meaning + * ie: IRQs whose controller is not APLIC/IMSIC/PLIC. + */ + if ( rirq.controller !=3D dt_interrupt_controller ) + { + dt_dprintk("irq %u not connected to primary controller. Connec= ted to %s\n", + i, dt_node_full_name(rirq.controller)); + continue; + } + + irq =3D platform_get_irq(dev, i); + if ( irq < 0 ) + { + printk("Unable to get irq %u for %s\n", i, dt_node_full_name(d= ev)); + return irq; + } + + res =3D map_irq_to_domain(d, irq, need_mapping, dt_node_name(dev)); + if ( res ) + return res; + } + + return 0; +} diff --git a/xen/arch/riscv/include/asm/intc.h b/xen/arch/riscv/include/asm= /intc.h index 6fc0e620e937..1bfba7c6155b 100644 --- a/xen/arch/riscv/include/asm/intc.h +++ b/xen/arch/riscv/include/asm/intc.h @@ -15,6 +15,7 @@ enum intc_variant { }; =20 struct cpu_user_regs; +struct domain; struct irq_desc; struct kernel_info; struct vcpu; @@ -34,6 +35,9 @@ struct intc_hw_operations { /* hw_irq_controller to enable/disable/eoi host irq */ const struct hw_interrupt_type *host_irq_type; =20 + /* hw_irq_controller to enable/disable/eoi guest irq */ + const struct hw_interrupt_type *guest_irq_type; + /* Set IRQ type */ void (*set_irq_type)(struct irq_desc *desc, unsigned int type); /* Set IRQ priority */ @@ -63,6 +67,8 @@ struct vintc_ops { }; =20 struct vintc { + unsigned int nr_virqs; + unsigned long *used_irqs; /* Callbacks invoked during domain construction only. */ const struct vintc_init_ops *init_ops; /* Runtime callbacks used for the lifetime of the guest. */ @@ -76,10 +82,13 @@ void register_intc_ops(const struct intc_hw_init_ops *i= nit_ops); void intc_init(void); =20 void intc_route_irq_to_xen(struct irq_desc *desc, unsigned int priority); +int intc_route_irq_to_guest(struct irq_desc *desc, unsigned int priority); =20 void intc_handle_external_irqs(struct cpu_user_regs *regs); =20 int domain_vintc_init(struct domain *d); void domain_vintc_deinit(struct domain *d); =20 +int vintc_reserve_virq(const struct domain *d, unsigned int virq); + #endif /* ASM__RISCV__INTERRUPT_CONTOLLER_H */ diff --git a/xen/arch/riscv/include/asm/irq.h b/xen/arch/riscv/include/asm/= irq.h index 62648bdc4252..57e814d90cf4 100644 --- a/xen/arch/riscv/include/asm/irq.h +++ b/xen/arch/riscv/include/asm/irq.h @@ -52,6 +52,11 @@ void init_IRQ(void); =20 void do_IRQ(struct cpu_user_regs *regs, unsigned int irq); =20 +int route_irq_to_guest(struct domain *d, unsigned int virq, + unsigned int irq, const char *devname); + +int release_guest_irq(const struct domain *d, unsigned int virq); + #endif /* ASM__RISCV__IRQ_H */ =20 /* diff --git a/xen/arch/riscv/intc.c b/xen/arch/riscv/intc.c index f5c8af6ddea4..810d126e263d 100644 --- a/xen/arch/riscv/intc.c +++ b/xen/arch/riscv/intc.c @@ -3,11 +3,15 @@ #include #include #include +#include +#include #include #include #include #include +#include #include +#include =20 #include #include @@ -78,6 +82,22 @@ void intc_route_irq_to_xen(struct irq_desc *desc, unsign= ed int priority) intc_set_irq_priority(desc, priority); } =20 +int intc_route_irq_to_guest(struct irq_desc *desc, + unsigned int priority) +{ + ASSERT(spin_is_locked(&desc->lock)); + + ASSERT(intc_hw_ops->guest_irq_type); + + desc->handler =3D intc_hw_ops->guest_irq_type; + desc->status |=3D IRQ_GUEST; + + intc_set_irq_type(desc, desc->arch.type); + intc_set_irq_priority(desc, priority); + + return 0; +} + int __init make_intc_domU_node(struct kernel_info *kinfo) { const struct vintc *vintc =3D kinfo->bd.d->arch.vintc; @@ -101,6 +121,15 @@ int domain_vintc_init(struct domain *d) break; } =20 + if ( !ret ) + { + d->arch.vintc->used_irqs =3D + xvzalloc_array(unsigned long, + BITS_TO_LONGS(d->arch.vintc->nr_virqs)); + if ( !d->arch.vintc->used_irqs ) + ret =3D -ENOMEM; + } + return ret; } =20 @@ -108,6 +137,20 @@ void domain_vintc_deinit(struct domain *d) { const enum intc_variant variant =3D intc_hw_ops->info->hw_variant; =20 + if ( !d->arch.vintc ) + return; + + if ( d->arch.vintc->used_irqs ) + { + unsigned int virq; + + for ( virq =3D 0; virq < d->arch.vintc->nr_virqs; virq++ ) + if ( test_bit(virq, d->arch.vintc->used_irqs) ) + release_guest_irq(d, virq); + + XVFREE(d->arch.vintc->used_irqs); + } + switch ( variant ) { case INTC_APLIC: @@ -118,3 +161,20 @@ void domain_vintc_deinit(struct domain *d) break; } } + +/* + * Mark @virq as used by @d so that domain_vintc_deinit() knows that it ha= s to + * be released. + * + * Returns 0 on success, -EEXIST if @virq has already been reserved, which + * legitimately happens when an IRQ is shared between devices, and -ERANGE= if + * @virq is outside the range of the interrupt sources the vINTC provides. + */ +int __overlay_init vintc_reserve_virq(const struct domain *d, + unsigned int virq) +{ + if ( virq >=3D d->arch.vintc->nr_virqs ) + return -ERANGE; + + return test_and_set_bit(virq, d->arch.vintc->used_irqs) ? -EEXIST : 0; +} diff --git a/xen/arch/riscv/irq.c b/xen/arch/riscv/irq.c index b5066fc3e981..74a4e31f16be 100644 --- a/xen/arch/riscv/irq.c +++ b/xen/arch/riscv/irq.c @@ -12,11 +12,27 @@ #include #include #include +#include #include +#include =20 #include #include =20 +/* Describe an IRQ assigned to a guest */ +struct irq_guest +{ + struct domain *d; + unsigned int virq; + /* + * The action of a guest IRQ has the same lifetime as this structure, = so + * embed it here to have both covered by a single allocation. Conseque= ntly + * it must not be freed on its own, which is why free_on_release is le= ft + * false for it (see irq_release_action()). + */ + struct irqaction action; +}; + static irq_desc_t irq_desc[NR_IRQS]; =20 struct irq_desc *irq_to_desc(unsigned int irq) @@ -198,6 +214,14 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int i= rq) if ( desc->handler->ack ) desc->handler->ack(desc); =20 + if ( desc->status & IRQ_GUEST ) + /* + * With APLIC + IMSIC, guest interrupts bypass Xen and are deliver= ed + * directly to the guest. Without IMSIC, interrupts would be trapp= ed + * by Xen and would need injecting into the guest here. + */ + panic("unimplemented"); + if ( desc->status & IRQ_DISABLED ) goto out; =20 @@ -227,3 +251,239 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int = irq) spin_unlock(&desc->lock); irq_exit(); } + +static struct irq_guest *irq_get_guest_info(struct irq_desc *desc) +{ + ASSERT(spin_is_locked(&desc->lock)); + ASSERT(desc->status & IRQ_GUEST); + ASSERT(desc->action); + + return desc->action->dev_id; +} + +/* + * Detach the action registered with 'dev_id' from 'desc' and, if it was t= he + * last one, shut the interrupt down. + * + * To be called with desc->lock held, which is still held upon return. The + * detached action is returned (NULL if 'dev_id' had no action registered)= and + * has to be handed to irq_release_action() once the lock has been dropped. + */ +static struct irqaction *irq_detach_action(struct irq_desc *desc, + const void *dev_id) +{ + struct irqaction *action, **action_ptr =3D &desc->action; + + ASSERT(spin_is_locked(&desc->lock)); + +#ifdef CONFIG_IRQ_HAS_MULTIPLE_ACTION + for ( ;; ) + { + action =3D *action_ptr; + if ( !action || (action->dev_id =3D=3D dev_id) ) + break; + + action_ptr =3D &action->next; + } +#else + action =3D *action_ptr; +#endif + + if ( !action ) + { + printk(XENLOG_WARNING "Trying to free already-free IRQ %u\n", + desc->irq); + return NULL; + } + + /* Found it - remove it from the action list */ +#ifdef CONFIG_IRQ_HAS_MULTIPLE_ACTION + *action_ptr =3D action->next; +#else + *action_ptr =3D NULL; +#endif + + /* If this was the last action, shut down the IRQ */ + if ( !desc->action ) + { + desc->handler->shutdown(desc); + desc->status &=3D ~IRQ_GUEST; + } + + return action; +} + +/* + * Complete the release of an action detached by irq_detach_action(). + * + * To be called with desc->lock dropped: the lock cannot be held all the w= ay + * through, as waiting for a handler still running on another CPU to compl= ete + * requires do_IRQ() to be able to acquire the very same lock. + * + * Once this function has returned, the action (and hence any object embed= ding + * it) is no longer referenced by anyone and may be freed. + */ +static void irq_release_action(const struct irq_desc *desc, + struct irqaction *action) +{ + /* Wait to make sure it's not being used on another CPU. */ + while ( test_bit(_IRQ_INPROGRESS, &desc->status) ) + cpu_relax(); + + /* + * IRQ_INPROGRESS is cleared in do_IRQ() after re-acquiring desc->lock, + * and lock acquisition implies a full barrier, so the handler's acces= ses + * are ordered before the clearing becomes visible here. The barrier b= elow + * adds the missing load-load ordering (the loop's exit branch already + * prevents the store in xvfree() from becoming visible early), so that + * having observed the bit cleared we also see whatever the handler di= d on + * that CPU. Only then is it safe to free the action. + */ + smp_rmb(); + + if ( action->free_on_release ) + xvfree(action); +} + +void release_irq(unsigned int irq, const void *dev_id) +{ + struct irq_desc *desc =3D irq_to_desc(irq); + struct irqaction *action; + unsigned long flags; + + spin_lock_irqsave(&desc->lock, flags); + action =3D irq_detach_action(desc, dev_id); + spin_unlock_irqrestore(&desc->lock, flags); + + if ( action ) + irq_release_action(desc, action); +} + +int release_guest_irq(const struct domain *d, unsigned int virq) +{ + struct irq_desc *desc =3D irq_to_desc(virq); + struct irqaction *action; + struct irq_guest *info; + unsigned long flags; + int ret =3D -EINVAL; + + spin_lock_irqsave(&desc->lock, flags); + + if ( !(desc->status & IRQ_GUEST) ) + goto unlock_err; + + info =3D irq_get_guest_info(desc); + if ( d !=3D info->d ) + goto unlock_err; + + /* + * Detaching the action happens with desc->lock still held, so that a + * concurrent release_guest_irq() for the same IRQ will see IRQ_GUEST + * already cleared and bail out, rather than capturing the same 'info'= and + * double-freeing it below. + */ + action =3D irq_detach_action(desc, info); + + spin_unlock_irqrestore(&desc->lock, flags); + + if ( action ) + irq_release_action(desc, action); + + xvfree(info); + + return 0; + + unlock_err: + spin_unlock_irqrestore(&desc->lock, flags); + return ret; +} + +/* Route an IRQ to a specific guest */ +int route_irq_to_guest(struct domain *d, unsigned int virq, + unsigned int irq, const char *devname) +{ + struct irq_guest *info; + struct irq_desc *desc =3D irq_to_desc(irq); + unsigned long flags; + int retval =3D 0; + + if ( d->is_dying ) + return -EINVAL; + + info =3D xvzalloc(struct irq_guest); + if ( !info ) + return -ENOMEM; + + info->d =3D d; + info->virq =3D virq; + + info->action.dev_id =3D info; + info->action.name =3D devname; + + spin_lock_irqsave(&desc->lock, flags); + + /* + * If the IRQ is already used by someone + * - If it's the same domain -> Xen doesn't need to update the IRQ de= sc. + * For safety check if we are not trying to assign the IRQ to a + * different vIRQ. + * - Otherwise -> For now, don't allow the IRQ to be shared between + * Xen and domains. + */ + if ( desc->action !=3D NULL ) + { + if ( desc->status & IRQ_GUEST ) + { + struct domain *ad =3D irq_get_guest_info(desc)->d; + + if ( d !=3D ad ) + { + printk(XENLOG_G_ERR "%pd: IRQ %u is already used by %pd\n", + d, irq, ad); + retval =3D -EBUSY; + } + else if ( irq_get_guest_info(desc)->virq !=3D virq ) + { + printk(XENLOG_G_ERR + "%pd: IRQ %u is already assigned to vIRQ %u\n", + d, irq, irq_get_guest_info(desc)->virq); + retval =3D -EBUSY; + } + } + else + { + printk(XENLOG_G_ERR "%pd: IRQ %u is already used by Xen\n", + d, irq); + retval =3D -EBUSY; + } + goto out; + } + + retval =3D _setup_irq(desc, 0, &info->action); + if ( retval ) + goto out; + + retval =3D intc_route_irq_to_guest(desc, IRQ_NO_PRIORITY); + if ( retval ) + { + struct irqaction *action =3D irq_detach_action(desc, info); + + spin_unlock_irqrestore(&desc->lock, flags); + + if ( action ) + irq_release_action(desc, action); + + goto free_info; + } + + spin_unlock_irqrestore(&desc->lock, flags); + + return 0; + + out: + spin_unlock_irqrestore(&desc->lock, flags); + free_info: + xvfree(info); + + return retval; +} diff --git a/xen/arch/riscv/vaplic.c b/xen/arch/riscv/vaplic.c index a529a5b1dc49..6fbdc07805fd 100644 --- a/xen/arch/riscv/vaplic.c +++ b/xen/arch/riscv/vaplic.c @@ -113,6 +113,16 @@ int domain_vaplic_init(struct domain *d) =20 vaplic->regs.domaincfg =3D APLIC_DOMAINCFG_RO; =20 + /* + * APLIC source 0 is reserved; sources are numbered + * 1..guest_aplic_num_sources and used directly as indices into used_i= rqs. + * Size the bitmap to guest_aplic_num_sources + 1 so the highest sourc= e has + * a valid slot (index 0 stays unused). Without the +1, + * vintc_reserve_virq() can't record the top source, so + * domain_vintc_deinit() never releases it. + */ + d->arch.vintc->nr_virqs =3D guest_aplic_num_sources + 1; + return 0; } =20 --=20 2.55.0 From nobody Thu Sep 24 18:59:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1790159248; cv=none; d=zohomail.com; s=zohoarc; b=ei503k5pgcV6ZRipGDfclxRcXCkfwHLYA6KDFxDtx/2vKx+y+tob6fAVut7VnGbpT66kWv1HfaYcSmBKqjmG7d/Lf5O4E9roqLt9P/tAqwmv/tKfujfuOOmLrhBZy2accN3f48TS4gt0p0LufqMdurvwulIUfj3bwoEkpTZd/rg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790159248; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KpfnDxVNKFDlD58v4ZzoleMMovfePdIbFSWKYF746yM=; b=OCK/s/SvIXE5IkavnJLMfZ/9H9M7VPL+ruq8xJJRdYHJ1pqly9VA/tpAGpX2jxgvy7Q4EyTPPww8n7erpKGLYh0QJGCBZ7Ww6jcxqgWC12pxEuKmHX+h2JVsMqrV6TaHJ/DGAhh7Qbow0v5sUQvo51X4cH+jZoJeVprNj1dzRB0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1790159248143728.4202621647981; Wed, 23 Sep 2026 03:27:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1430101.1652676 (Exim 4.92) (envelope-from ) id 1x9KBr-00028k-FF; Wed, 23 Sep 2026 10:27:03 +0000 Received: by outflank-mailman (output) from mailman id 1430101.1652676; Wed, 23 Sep 2026 10:27:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1x9KBr-00027s-9p; Wed, 23 Sep 2026 10:27:03 +0000 Received: by outflank-mailman (input) for mailman id 1430101; Wed, 23 Sep 2026 10:27:01 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) id 1x9KBp-0001sj-Li for xen-devel@lists.xenproject.org; Wed, 23 Sep 2026 10:27:01 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1x9KBp-007M7V-2U for xen-devel@lists.xenproject.org; Wed, 23 Sep 2026 12:27:01 +0200 Received: from [10.42.69.10] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6ab3a960-bab6-0a2a0a5309dd-0a2a450ac28c-44 for ; Wed, 23 Sep 2026 12:27:01 +0200 Received: from [74.125.225.140] (helo=mail-wm2-f12.google.com) by tlsNG-4011c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6ab3a974-f2d2-0a2a450a0019-4a7de18cdc8b-3 for ; Wed, 23 Sep 2026 12:27:01 +0200 Received: by mail-wm2-f12.google.com with SMTP id 5b1f17b1804b1-49ce364488dso2283075e9.0 for ; Wed, 23 Sep 2026 03:27:00 -0700 (PDT) Received: from fedora (user-109-243-71-234.play-internet.pl. [109.243.71.234]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fe0c50da7sm32786515e9.3.2026.09.23.03.26.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2026 03:27:00 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790159220; x=1790764020; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=KpfnDxVNKFDlD58v4ZzoleMMovfePdIbFSWKYF746yM=; b=ScppvQDyDGmncMdd9XvG8KiDrviatoabM5d7iRY7h+Xpx3iNTQLrZr9D7zc3hGnann zg0Pd0A6dZwI4CWjK/8vNblfcH9cenVr3O3TXOwH4xG6/jk8RWaIZmHuhUm10d7vg/oX Sun0OLub4ZddlovpdNSweodw19oaNisOVN1PKMIwqeyW/nebLQ75m5NqymkW4QshZ1yA C7n38bd2/CZkoh/y7U6Qi2LvI0FZKkK3AKsvYq6eyNHlFlcFOvanq9wp/8IDIa2SfBpb VktxSqSOk75+uFFz/1M26GxB7cz26KDzCup54zAgQVIJvJKOKktdvuEm/Fef3J9o+Oe5 XrKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790159220; x=1790764020; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=KpfnDxVNKFDlD58v4ZzoleMMovfePdIbFSWKYF746yM=; b=cc23gIjQZFKY0pAnmOv6yu731PXjcBkMgm4Ig0c3W3mxRJgJKpeRu4Axyrbvsqp0lL QFcMCAB54zLDARQzZZO9Uo4mECu83Xv0pn2+rzqzMLJ9IcDjCP7sl3UJvJ0TZR8k0BPY thKzM0lji+tP1ibE8EE71dksL3uGTZsVaaGWqhh9L3OzB4XFNB7M7a53+liEXzC5dvaA UgXqfXf+agT55GJ7T+Um6YTovKOE2dH6vqKRbrneYeeWtQwF+iW4rNMZsiwKmv6I22BY CjwKBmozxf6e222IIE/Ud1iRtwXXfQWp0F7jCqqNAV2qOmCkJ86eHnDm8JCb+2sE4KeQ S01g== X-Gm-Message-State: AFuF++lCF5Y8xepYN5WLZiEyKBjMU1BVeWFlj+p+bQKLeK2pM+mYtAgR MgSld+CXgDqezda3Ztrw8H8H/f2cO3OOdXZafa6HFSrhGQe6+RBgdo1ZU2Da3w== X-Gm-Gg: AYBFou19eOfC+h8mj+BSVZDCy3QkRiOsqAJsRmCzfqy8+npco9xnwq16kdNox1gYI37 tbUd12OWVs4d6/fSjWMfvhPxnoi75z9zGaDk7IDENv6tSz58yJcbzzhQfIywog0OkGICakqaDjD YeqcQGopai97C9tY6P5Bq8QuAZHnthVz6bRHFMHalmsEyFinEyCiuvSCPV83ktvMU6qxWy/dmtV Q4AQ5T5E1SjA6qeXAZcaPDoxsXqxCYoXDXGLzRKVxdzj52RcfexKU5pqMoQahhryMT0oCR87hyz TCQljqaO3tLPXxHwfGV80kVFB5hnpNbnYCoLv5XRAmequATrZEqwcXzal4GO72oh+qWI5iOLgoS l2s39/8k4c8XMS4Tmn2b43gfsquLBEL5wHPIeHw+GBcweabb6MktfrxHrzxhiJJ/Iu4F9Ic3R/3 oMWv3Izu2RPfxl4Uz8itfPrl+nnGD9xcLjYdiDzWgJcM/gqH7SZrcGt7HX4lubzNO9zPn/34Ehq jTxgHAiFhjArqIhOMtsN/kNVNARjmI/8hJcHxSjgbHtgN+JcpE= X-Received: by 2002:a05:600d:8491:10b0:49f:ce79:7a8d with SMTP id 5b1f17b1804b1-49fde4acce8mr22118605e9.17.1790159220516; Wed, 23 Sep 2026 03:27:00 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Romain Caritey , Baptiste Le Duc , Zheng Zhang , Oleksii Kurochko , Alistair Francis , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v10 2/5] xen/riscv: implement init_intc_phandle() Date: Wed, 23 Sep 2026 12:26:46 +0200 Message-ID: <1867ae29fb0f1819c3e75cbea4132b2ebd04cc62.1790158750.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-4011c0/1790159221-532D8CFC-936C456C/10/73395122804 X-purgate-type: spam X-purgate-size: 1379 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1790159249860158500 Content-Type: text/plain; charset="utf-8" Implement init_intc_phandle() to read phandle of interrupt controller node and save it in kernel->phandle_intc for the future usage during creation of guest interrupt controller node. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v4-10: - Nothing changed. Only rebase. --- --- xen/arch/riscv/dom0less-build.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/xen/arch/riscv/dom0less-build.c b/xen/arch/riscv/dom0less-buil= d.c index 4cc00012aa8d..a1fa51b996a7 100644 --- a/xen/arch/riscv/dom0less-build.c +++ b/xen/arch/riscv/dom0less-build.c @@ -4,9 +4,26 @@ #include #include #include +#include =20 #include =20 +int __init init_intc_phandle(struct kernel_info *kinfo, const char *name, + const int node_next, const void *pfdt) +{ + if ( dt_node_cmp(name, "intc") =3D=3D 0 ) + { + uint32_t phandle_intc =3D fdt_get_phandle(pfdt, node_next); + + if ( phandle_intc !=3D 0 ) + kinfo->phandle_intc =3D phandle_intc; + + return 0; + } + + return 1; +} + int __init make_arch_nodes(struct kernel_info *kinfo) { /* No RISC-V specific nodes need to be made, at the moment. */ --=20 2.55.0 From nobody Thu Sep 24 18:59:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1790159251; cv=none; d=zohomail.com; s=zohoarc; b=Wu46hhaEkST/HtMLzXTWCU6F4tzTmALlxK6XqBRxAbrKSgD4UYHELKrlMSZgltTULMxp4z5RZXQcCJO0HAeaB4Pr6anzJGlKnUyUuRCv4An6X94b8zfkKLg3bA75C2ZGSr8a8Wgx+m5/+vOYYQdZaR/uZcrYyW8pZ+f/Zzdb+Yo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790159251; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=q4vFq/LEYOvho2Vznc9H6m0hLeL8wfPz9BeDI8XZDT0=; b=l5neVh+z6KhtPyl2Wk4sKkq6TZH8suaj1z8m6DC9yrSCr4vSGSlG292Thr4KR9KvyaQbY5nXaefBwT3cZr75bbRsHlz+jQzPDlfG4UBS9VKWlOAa25AbR6fzWjAp0mRdxBFg9fUGO+bVVUe4/ZTnWTG94AWfF6MUaewEhUPSz+0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 179015925180976.03076700632687; Wed, 23 Sep 2026 03:27:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1430102.1652681 (Exim 4.92) (envelope-from ) id 1x9KBr-0002Hr-QZ; Wed, 23 Sep 2026 10:27:03 +0000 Received: by outflank-mailman (output) from mailman id 1430102.1652681; Wed, 23 Sep 2026 10:27:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1x9KBr-0002G5-N1; Wed, 23 Sep 2026 10:27:03 +0000 Received: by outflank-mailman (input) for mailman id 1430102; Wed, 23 Sep 2026 10:27:02 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) id 1x9KBq-00023I-Pp for xen-devel@lists.xenproject.org; Wed, 23 Sep 2026 10:27:02 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1x9KBq-007MAJ-6X for xen-devel@lists.xenproject.org; Wed, 23 Sep 2026 12:27:02 +0200 Received: from [10.42.69.9] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6ab3a968-8faa-0a2a0a5109dd-0a2a45099624-14 for ; Wed, 23 Sep 2026 12:27:02 +0200 Received: from [74.125.225.140] (helo=mail-wm2-f12.google.com) by tlsNG-bad1c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6ab3a976-be1a-0a2a45090019-4a7de18c8dcb-3 for ; Wed, 23 Sep 2026 12:27:02 +0200 Received: by mail-wm2-f12.google.com with SMTP id 5b1f17b1804b1-49d097b4939so3821375e9.0 for ; Wed, 23 Sep 2026 03:27:02 -0700 (PDT) Received: from fedora (user-109-243-71-234.play-internet.pl. [109.243.71.234]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fe0c50da7sm32786515e9.3.2026.09.23.03.27.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2026 03:27:01 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790159222; x=1790764022; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=q4vFq/LEYOvho2Vznc9H6m0hLeL8wfPz9BeDI8XZDT0=; b=BBrJ+HWItGxxNhR01VY6fHbdWvWiQ18l/qw+U7cdUshN/W8VWhrRyBDe9gQwRE59HJ MNyi8swF6yQAs7wLLcLSX/uhICe+sMn1ZUB0mQFKGGNWRavAfxmboBeRjp8hWU1SRSrA OEhrNKZPuprfj84jvq9xQjhwzALe+CaJ+cZVEDWcsdxSErVH3avGuLOArMY6w+NmYPmc TzPFmF6cXi2Wn/d0ilmUM/wMv8CgV2wj1tsfY8ZzbyNTD9nUIggLsSB1tC9Cldxfl/Pd y4UHNRj1pga49o5bWm07r87dMsFo1/C4cWEkBn/kre3i06vh2Flm9Wjuc1rDjIHue2LF sPFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790159222; x=1790764022; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=q4vFq/LEYOvho2Vznc9H6m0hLeL8wfPz9BeDI8XZDT0=; b=0PD2CgMZJE7sKzuvkeAaWqJznaGghupV/jmkBQu+y/ueiA8UsClhZgNGSSwX5iIAc9 XtFCKXQlb+sZ7mPWYBQeGbe4OupyGBDOB0kYVuuuqn7J4qrkCIJ/7OqfvjMTVpD6Hnmf hXA2ak0NWrY0b6eCptEYK4BEO0YtUEwhTmpZEwffiELZ2zJoQ+qlDt0ah/v9ZpbKnk0e RHNObGHa1GmgMeop9M1XFgMKyOCJClejie03LXO1NT9rosA2aJoILpAbWARlnGYEV5KV 8GO0XFomDYsM9zh3wPOzMODeqc9KFnSBfDCPkdC6NrI7hUbtHaI7lYt4jQin2lezVVui 1x6w== X-Gm-Message-State: AFuF++nn8/yFVeeBegszRgL8432BDh/cN+dxgAm7HrA1SkF3KqE+SWSk p772fdKlOhbp9l3ybG+xbcCNRCryieXedkXT+xPqfzIBwqmPxmDjPQGvCcH2VQ== X-Gm-Gg: AYBFou3lf8t7uWZLdDY438pmvaz81u/S62iq9AUian7j6mKcaK+DUE+nmA4zVcG4fKP DF8Hs4le01n4R7Fxo1ybkMQGHzJuToMnzdDyVRo1xhfDTloKrBRcZyyPq59Czc/Jvuq19KolvgE oc4RpTUO8LmTsiBRhzYYLQFYXAzUbOJjRdi4pcZDpBXZrPcHNpHsrNXZdM1CDDS4ljBJvm5H07L yuNryWtcvciEz4QR9tqxBypPPqF74hAk0pnzTWbwpKzFYX4nb1jUqt+6udWBakVYw4jlJ+iEbu1 k6t/FM1WQb1xBpSfMF9JVWEaCitMmb1w2T2ET0iXmhJBO4WB3R3lq34Lm/U5yRlSD+tDRZv3yUC y8TucWuTDU2AG+5rBSV/wW3IAvJ8yS9G5X1e+xi60+JSMaveQ1RAoamSbvCfq4ELlUPV89hQXM5 U5hREWDvwAK/SbLiD4U/Rm+2vgNFYC9DvfmpzXmO8TYgh43eTwlnxBbE8k0EH6AlV+DE/YOp2+X IPperWReF5afcpPbfZJ3fwhjGZbzVPUOcjE2j4g X-Received: by 2002:a05:600c:8a0a:20b0:49e:719e:e215 with SMTP id 5b1f17b1804b1-49fdf13b2f2mr18342355e9.26.1790159221661; Wed, 23 Sep 2026 03:27:01 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Romain Caritey , Baptiste Le Duc , Zheng Zhang , Oleksii Kurochko , Alistair Francis , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v10 3/5] xen/riscv: initialize RCU, scheduler, and system domains in start_xen() Date: Wed, 23 Sep 2026 12:26:47 +0200 Message-ID: <715c9d8947e99d50cd09aace8aff8eaf3cd4a2f0.1790158750.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-bad1c0/1790159222-BE6DA034-A0385B0D/10/73395122804 X-purgate-type: spam X-purgate-size: 1561 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1790159253577158500 Content-Type: text/plain; charset="utf-8" Wire up the missing early-boot initialization steps in start_xen(). The scheduler must be initialized prior to do_initcalls() because cpupool_create_pool() is called during initcalls; without it, BUG_ON(IS_ERR(pool)) is triggered inside cpupool_create_pool(). Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v4-10: - Nothing changed. Only rebase. --- Changes in v3: - Add Acked-by: Jan Beulich . --- Changes in v2: - New patch. Several patches were folded into one. --- --- xen/arch/riscv/setup.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 07f46ac3ce27..05f93a74c9d3 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -6,9 +6,12 @@ #include #include #include +#include #include #include #include +#include +#include #include #include #include @@ -160,12 +163,21 @@ void __init noreturn start_xen(unsigned long bootcpu_= id, =20 timer_init(); =20 + rcu_init(); + + setup_system_domains(); + local_irq_enable(); =20 console_init_postirq(); =20 guest_mm_init(); =20 + scheduler_init(); + set_current(idle_vcpu[0]); + + do_initcalls(); + printk("All set up\n"); =20 machine_halt(); --=20 2.55.0 From nobody Thu Sep 24 18:59:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1790159240; cv=none; d=zohomail.com; s=zohoarc; b=EbXK23amwzDlV/bwklwlvSNvC0tJ5/NPw80t4pVPF+/aDXKzOOUORvwITcH8x7pJqAYJZQcnsrBiWowVlhGfpT7Iqbrps84os1tDATvIIm/BoXR2EHH9O6NuzDilJvSNadohL4OoMRDCwWqM1Du1j0N7fz/GfE9yUH/Kf+TWdrA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790159240; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5kx8u+4+gN/f3jyrEZQ5/Z1zPXMqe+olQFMfcDsueDo=; b=NZi1Ivhm+7MsXrNy2c/0zsgNqx1rlwF7inNE1AkJTtPuDPBA8MAhUqsceLLD7urvyDzCYXpso9foo27lZTxfeK7EcOHLWkmskDn8qdFiCkhzM4/Lo04c0GtFfQDVMEMEq4ez+dHF26Q6qngce3oKK5dUrOi8yaH4sZdJxo7cI/c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1790159240617864.1932327511639; Wed, 23 Sep 2026 03:27:20 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1430103.1652697 (Exim 4.92) (envelope-from ) id 1x9KBu-0002ik-23; Wed, 23 Sep 2026 10:27:06 +0000 Received: by outflank-mailman (output) from mailman id 1430103.1652697; Wed, 23 Sep 2026 10:27:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1x9KBt-0002iZ-Ul; Wed, 23 Sep 2026 10:27:05 +0000 Received: by outflank-mailman (input) for mailman id 1430103; Wed, 23 Sep 2026 10:27:04 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) id 1x9KBr-0002Hw-V6 for xen-devel@lists.xenproject.org; Wed, 23 Sep 2026 10:27:03 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1x9KBr-00Cn1P-Az for xen-devel@lists.xenproject.org; Wed, 23 Sep 2026 12:27:03 +0200 Received: from [10.42.69.6] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6ab3a974-2eae-0a2a0a5409dd-0a2a4506a1fe-12 for ; Wed, 23 Sep 2026 12:27:03 +0200 Received: from [74.125.225.76] (helo=mail-wr2-f12.google.com) by tlsNG-16d1c6.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6ab3a977-195a-0a2a45060019-4a7de14cdc18-3 for ; Wed, 23 Sep 2026 12:27:03 +0200 Received: by mail-wr2-f12.google.com with SMTP id ffacd0b85a97d-482f6356256so271340f8f.1 for ; Wed, 23 Sep 2026 03:27:03 -0700 (PDT) Received: from fedora (user-109-243-71-234.play-internet.pl. [109.243.71.234]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fe0c50da7sm32786515e9.3.2026.09.23.03.27.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2026 03:27:02 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790159223; x=1790764023; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=5kx8u+4+gN/f3jyrEZQ5/Z1zPXMqe+olQFMfcDsueDo=; b=Bana6F6Unq8kmsd8fa29mucl0S7hcJ+oQWnNczEAlv05nTJotwZ2+PXY0FbNlXMn2Z ozoIMEAPxLgMltbvtmBbP50ZnBAfirbgamZ/E+dlFgVQy1pT9Pg9W08n1wLsW4dRTzrO lfZamerfMKX/LpSlg4VImzUlpZaEL3zk8JOgsmtwCmwNL/TiN5rnd7Nnxbi7M5Y48RIt 1ey0HzDRGDTSK2+VUiieLHeZQkT/I4JuvGzFALirQs4Ez9ZRZ18zTrUY9/P01GjXm32B wKWa7Ob3i0a4X3+/XsEhSq3I5OrcFMh44m3ofjbtGfq1zklOPvDPaP5YDe1vL6jmcnjU pMGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790159223; x=1790764023; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=5kx8u+4+gN/f3jyrEZQ5/Z1zPXMqe+olQFMfcDsueDo=; b=xoeSGuNfNwGBjowYiv8KydXuDLYwx/gzVMehVFTxXbl2Sl2uOuaN/TTwJe14i/eyAe NoU1gJb7Q18EhVoaMVnUcXry1hG3PjMPJTjzk/NLEhdMPXOeI7oeqzbzEBcTHBbJ1fQG Loq4S0bOmZ3lWCq5sfP36ngYRl+DXjLKwzDZ3q+4H2JbRFetuyVKXWQmfwOYYKBdrFQF +xL+IEu9rgYik4h2Yf97U2xKG0t+UWC7JkhTHGy+AaySbVl1TyWY6gX1OljcNfq2DLLv SN6O63+z7sTUwoImNJ5pnLTkKDPFcJN1NjASQclu/n7JmpYY/g3jOUABg3P0PHrzN4oP rcMA== X-Gm-Message-State: AFuF++lT0MYo3wUSioV70qIeCjRLWJTXQm4yfcM/fCfB61pb4tYtMsOA tsdNCx4IBpf4V9+xsiStysnsmQyRI5hHZiNoW+7EZ3tXOKzRUOlSWmSlpevzCg== X-Gm-Gg: AYBFou0/I6a0o6cXpsc0+2gnrAZegfs4QJChejjLsNlver3aTWhNgduLCXQSy6iUBI7 4reqvElN3tPE45hIy6uMTNxV+JJablC3CftYDQ0N5GzBPpfLt+yPhPJU7IbQmzOFpgCjGjadn+F Ea21m3WCSVDYvmds2ulg3DOom7HpJwRZ1bjWPJFTGRNnTNbEHekMdWHb8DfSZuKRzLt23BUKmwx T/TKdw8rSbPN3SZNIfQO6Arv1Fqf41kWzTyZhB/n2qwPI6lqzfeVlQipOgtup6Iuxau72tv8UYI waCxUHulC7NKI7pWHvQEoUPvZoBqo0ssemiZ5MlXhiTsA9Q9xksn1egTZvFjo1XLPkD3GOlJYka ZSCobKQLTvN1FxgNjtck7mdKEHjVRM1n2xJrzwO0CRbzXHLz0X1RzYBRnf9qIMBCQTT6+f+SnA6 nlXlEpMUdjQW9MpCyWhkwAFOG4eIu9LsusgWQprMuJnQbJIaCpLbYox5zhVMlTCaVPbVKi5t2cG Wl/YcanB91rG3JIjQGSl9QjPa4/ksHKJRdCgswJ X-Received: by 2002:a05:600c:c491:b0:49c:f13e:e4d with SMTP id 5b1f17b1804b1-49fde4972e0mr28673935e9.10.1790159222733; Wed, 23 Sep 2026 03:27:02 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Romain Caritey , Baptiste Le Duc , Zheng Zhang , Oleksii Kurochko , Alistair Francis , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v10 4/5] xen/riscv: provide init_vuart() Date: Wed, 23 Sep 2026 12:26:48 +0200 Message-ID: <38e68bf92ed375d644d89e474b23e6b767356ea3.1790158750.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-16d1c6/1790159223-FEC7777B-DE04DC65/10/73395122804 X-purgate-type: spam X-purgate-size: 1392 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1790159242391158500 Content-Type: text/plain; charset="utf-8" For debug purpose is enough to have only print messages from guest what is now implemented in vsbi_legacy_ecall_handler(). For full guesst console support it will better to have something similar to [1], thereby there is nothing specific should be done, at least, for now and init_vuart() is provided to make dom0less code buildable. [1] https://lore.kernel.org/xen-devel/alpine.DEB.2.22.394.2602041533440.317= 5371@ubuntu-linux-20-04-desktop/ Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v3-v10: - Nothing changed. Only rebase. --- Changes in v2: - Add Acked-by: Jan Beulich . --- --- xen/arch/riscv/dom0less-build.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xen/arch/riscv/dom0less-build.c b/xen/arch/riscv/dom0less-buil= d.c index a1fa51b996a7..d1a51b92936a 100644 --- a/xen/arch/riscv/dom0less-build.c +++ b/xen/arch/riscv/dom0less-build.c @@ -8,6 +8,14 @@ =20 #include =20 +int __init init_vuart(struct domain *d, struct kernel_info *kinfo, + const struct dt_device_node *node) +{ + /* Nothing to do at the moment */ + + return 0; +} + int __init init_intc_phandle(struct kernel_info *kinfo, const char *name, const int node_next, const void *pfdt) { --=20 2.55.0 From nobody Thu Sep 24 18:59:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1790159253; cv=none; d=zohomail.com; s=zohoarc; b=KAG3q1T3JQbskjtTl+cquKXgRPZb4e5MZK0A9X68NLQnghqihZiLFwtUXFVx2VyIAznH4FcbBSZ041CH4IcI3XXQaibHDyimaCWfJcuuhCmFaDrcbHEQz8Yrtv+hZqLZJ2oWfgzUag/7J3+ryAXabtrmDDzVoq82oO/szZvSCjo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790159253; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8WcnksmCgRRRAB+VvLfDA0qN9GynfiODcVrvICZ2zO0=; b=NF+dXgwTAlnRJS5p15nFcmf0TdpuILMHXWfV6e5db7A7/z5G2Hj6DRpTBwNbOsS1xXeN1DYL2DOu5MwbmGIP4iqvnluK0yEKlTCVgxDUrCyP+bj9K4/tWRMc40vtkPp4BC0K2KPUBHVS0AN7n36z44s/0GLwi4uNczbSOzKmFC0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1790159253770827.2325048054139; Wed, 23 Sep 2026 03:27:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1430104.1652707 (Exim 4.92) (envelope-from ) id 1x9KBv-0002wj-A8; Wed, 23 Sep 2026 10:27:07 +0000 Received: by outflank-mailman (output) from mailman id 1430104.1652707; Wed, 23 Sep 2026 10:27:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1x9KBv-0002w5-5e; Wed, 23 Sep 2026 10:27:07 +0000 Received: by outflank-mailman (input) for mailman id 1430104; Wed, 23 Sep 2026 10:27:05 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) id 1x9KBt-0002gB-2U for xen-devel@lists.xenproject.org; Wed, 23 Sep 2026 10:27:05 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1x9KBs-007MCr-FZ for xen-devel@lists.xenproject.org; Wed, 23 Sep 2026 12:27:04 +0200 Received: from [10.42.69.7] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6ab3a96e-bab6-0a2a0a5309dd-0a2a4507ddb8-38 for ; Wed, 23 Sep 2026 12:27:04 +0200 Received: from [74.125.225.76] (helo=mail-wr2-f12.google.com) by tlsNG-ef75cf.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6ab3a978-b4ea-0a2a45070019-4a7de14cf61e-3 for ; Wed, 23 Sep 2026 12:27:04 +0200 Received: by mail-wr2-f12.google.com with SMTP id ffacd0b85a97d-485b1d2874fso324962f8f.0 for ; Wed, 23 Sep 2026 03:27:04 -0700 (PDT) Received: from fedora (user-109-243-71-234.play-internet.pl. [109.243.71.234]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fe0c50da7sm32786515e9.3.2026.09.23.03.27.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2026 03:27:03 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790159224; x=1790764024; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=8WcnksmCgRRRAB+VvLfDA0qN9GynfiODcVrvICZ2zO0=; b=MlvEgJFAqzeyKvAkNzYBMnC7k8qUwhzzv5WksCYekbS+S8QnQv3LjQTBhfvJWx/pPO agB+r+n+o9SuaOyLLBNFPUHO9LwZ69r5hou67MYszhRzGeioigbtC4ovmlaWcr8byvX/ BtqX8Bw5/iju2FmLTenYNB8jeLSZbbYJG3WxEToQSf780L9kvoSv2HrwEW9a++YQdsN9 lVxOk6NGUDjRSlha9YSeRnPANKjj6x6l4y9mUamRxFqA4HLc/62rEsqPPx1+CVy10NK7 aThtOct8JybQ5QEgjt1AyE/mNmaYz2S6EOhdbkb+z9+JSepFtqWL5TxSbCs61VeSnR1O r47A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790159224; x=1790764024; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=8WcnksmCgRRRAB+VvLfDA0qN9GynfiODcVrvICZ2zO0=; b=Qn7jkfQfC4rz3XoVXfqki3qwFuvZuzlWyL/GXwEMH0UeDB7EcFjfm06rAIF0Klb505 0aHGrO8pRnRyCGI4ICvgICenxBEwlg/26373DeTdRQaF8i06UEFj1ugXEqk01QDB6HUc po5OfLDj4tNsEtmCeeFtj8JKanJB8feUQTC1yQnB6/12PoCa9yRFv3Mbe4Z5bLk3ZEEG s7IW/YedryX4w+rFi+rjiUpSstqvsabsEywQVPdG8QKzAnLjIAjR1eqWH2MoJtZgyma4 CUF5uDniAEgbhjEufAnFKxaIXT5Gmfn6JyCl+z9OhZ7WQv7HSrjgQdm+7jE/PTM7N/d9 CBkw== X-Gm-Message-State: AFuF++kzm6j5Hj4BvNp3y8z+k15j438N8sGMYzt8DcEFcbQraDx/x3cE Hu9/G0smqWHZSlDUTYdYBKB/Fah1qtJKm2MP0EmKh7YTiQE7QgIqKZqOgRjs3A== X-Gm-Gg: AYBFou04cwQfBHyN50n8mPUiGLtI9qNu9EAL3G7MG9vjPXlarkwkbBJx8BM3yyUgGMw 6G9fDaQO3+zC+8jr2kosozLrYSn/N41Q9iFZHGwTy7V91lKttv38NyxeUswExH+8XEym5BEveHx JUZO9mu+Ho30wopFPyfXCE9soYN0+3Mnpuyc/MjF9fLf/IvZV9pd/2yn5lHEwPOZ/3/QGJF/9XQ 2BdwqfJk22XNfcU1fLsBci6zNoie+POYwIh5A1KVOXEqlfi3rdzoAoJF3qvT0oTJxm2Nb5wkTjx A1Iag2V/gmS7ltDwdF57xbuIBSnL8ej7SD1JD0VPSCkiJhgQxKz7eeM7p8o/uQrHeCZrODe+Vx3 5AVze8P+Vr9BxDAjbsF8DsHnqviOt3hO7HhJUfxGw3+fKQpHtGJtpdXVb7hPCahMOiIUl0k/lYV mZXcNF5kwwKsrqAwatW46oQk9sDpcXlLO7b0sHuWDm657Exu/vEZGpLt9RJzKoGjQzI+Q5c5xSh NHbSZNmfe04+j6cfNExq282SkJcbzWv33/82F/c X-Received: by 2002:a05:600c:1988:b0:49b:8f5e:51fb with SMTP id 5b1f17b1804b1-49fdf3571f9mr25058195e9.3.1790159223841; Wed, 23 Sep 2026 03:27:03 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Romain Caritey , Baptiste Le Duc , Zheng Zhang , Oleksii Kurochko , Alistair Francis , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v10 5/5] xen/riscv: add initial dom0less infrastructure support Date: Wed, 23 Sep 2026 12:26:49 +0200 Message-ID: X-Mailer: git-send-email 2.55.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ef75cf/1790159224-37AD0AE4-3655A5EC/10/73395122804 X-purgate-type: spam X-purgate-size: 7401 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1790159255796158500 Content-Type: text/plain; charset="utf-8" Enable dom0less support for RISC-V by selecting HAS_DOM0LESS and providing the minimal architecture hooks required by the common dom0less infrastructure. Add stub implementations for architecture-specific helpers used when building domains from the device tree. These allow the generic dom0less code to build and let a basic DomU be constructed on RISC-V. construct_hwdom() and make_hypervisor_node() are still stubs returning an error: Dom0/hwdom construction isn't supported yet, and the hypervisor node generation (needed by domains with DOM0LESS_ENHANCED_NO_XS set) is not implemented. Both are marked with a TODO and are not reached by the currently supported configurations. Provide missing helpers and definitions required by the domain construction code, including domain bitness helpers and the p2m_set_allocation() prototype. Additionally define the guest magic memory region (GUEST_MAGIC_BASE / GUEST_MAGIC_SIZE) in asm/guest-layout.h. The base is arbitrary; the only constraint is that the region must not overlap guest RAM or the emulated device regions. It is placed in the unused gap below GUEST_RAM0_BASE (0x80000000); the constraints are documented next to the #define-s. A separate region for grant tables will be introduced at the same time as the introduction of the grant table for RISC-V. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v8-v10: - Nothing changed. Only rebase. --- Changes in v6-7: - Acked-by: Jan Beulich . --- Changes in v5: - Reword the comment above defintion of GUEST_MAGIC_BASE. - Shrunk the size of GUEST_MAGIC_SIZE to 2Mb as looking on the Arm only 4 pages are used and there is no technical reason to have 16Mb for that region. (Maybe in case of Arm it is connected that Arm has these definitions in public header so more space is reserved to not "break" public API in future) - Update the commit message with a remark about grant table region in guest-layout.h. --- Changes in v4: - Reword the description: the stubs do not let dom0less fully "run" since construct_hwdom() and make_hypervisor_node() return an error; spell out these limitations instead. - Add a TODO comment to construct_hwdom() explaining that Dom0/hwdom construction isn't supported yet. - Add a TODO comment to make_hypervisor_node() explaining that returning an error breaks building of domains with DOM0LESS_ENHANCED_NO_XS set, and why that is harmless for now. - Document the constraints on GUEST_MAGIC_BASE/GUEST_MAGIC_SIZE next to the #define-s and drop the QEMU-based justification (QEMU is not involved); the base is simply an arbitrary non-overlapping address. Changes in v3: - Add /* Nothing specific to do for now */ comment to arch_handle_passthrough_prop(). - Use _ULL() instead of xen_mk_ullong() for GUEST_MAGIC_BASE and GUEST_MAGIC_SIZE (xen_mk_ullong() is intended for public headers only). - Fix GUEST_MAGIC_BASE from 0x39000000 to 0x79000000 to avoid the QEMU RISC-V virt machine PCIE_ECAM range. - Drop CONFIG_STATIC_MEMORY=3Dn from the CI randconfig; now redundant since STATIC_MEMORY depends on HAS_STATIC_MEMORY which RISC-V does not select. Changes in v2: - Move declaration of p2m_set_allocation() to p2m-common.h. - Add __initdata for max_init_domid and drop initalizer for it. - Add CONFIG_STATIC_MEMORY=3Dn to CI's randconfig to avoid compilation error because of guest_physmap_add_pages() isn't provided. --- xen/arch/riscv/Kconfig | 2 ++ xen/arch/riscv/dom0less-build.c | 7 ++++++ xen/arch/riscv/domain-build.c | 28 +++++++++++++++++++++++ xen/arch/riscv/include/asm/guest-layout.h | 12 ++++++++++ 4 files changed, 49 insertions(+) diff --git a/xen/arch/riscv/Kconfig b/xen/arch/riscv/Kconfig index 48520588fe40..d8a348c0cf07 100644 --- a/xen/arch/riscv/Kconfig +++ b/xen/arch/riscv/Kconfig @@ -6,6 +6,8 @@ config RISCV select GENERIC_BUG_FRAME select GENERIC_UART_INIT select HAS_DEVICE_TREE_DISCOVERY + select HAS_DOM0LESS + select HAS_DOMAIN_TYPE select HAS_EX_TABLE select HAS_PMAP select HAS_UBSAN diff --git a/xen/arch/riscv/dom0less-build.c b/xen/arch/riscv/dom0less-buil= d.c index d1a51b92936a..0801d7e25059 100644 --- a/xen/arch/riscv/dom0less-build.c +++ b/xen/arch/riscv/dom0less-build.c @@ -102,3 +102,10 @@ int __init arch_parse_dom0less_node(struct dt_device_n= ode *node, =20 return 0; } + +int __init arch_handle_passthrough_prop(struct kernel_info *kinfo, + struct dt_device_node *node) +{ + /* Nothing specific to do for now */ + return 0; +} diff --git a/xen/arch/riscv/domain-build.c b/xen/arch/riscv/domain-build.c index d7613721db95..1e3abe259ccd 100644 --- a/xen/arch/riscv/domain-build.c +++ b/xen/arch/riscv/domain-build.c @@ -156,9 +156,37 @@ int __init make_cpus_node(const struct domain *d, stru= ct kernel_info *kinfo) return fdt_end_node(fdt); } =20 +int __init construct_hwdom(struct kernel_info *kinfo, + const struct dt_device_node *node) +{ + /* + * TODO: Dom0/hwdom construction isn't supported on RISC-V yet, so this + * is a stub returning an error. It must be implemented before a hardw= are + * domain can be built from the device tree. + */ + + return -EOPNOTSUPP; +} + int __init make_timer_node(const struct kernel_info *kinfo) { /* There is no need for timer node for RISC-V. */ =20 return 0; } + +int __init make_hypervisor_node(struct domain *d, + const struct kernel_info *kinfo, + int addrcells, int sizecells) +{ + /* + * TODO: Generating the hypervisor node isn't implemented yet. Returni= ng + * an error here breaks building of any domain (DomU included) whose + * dom0less_feature has DOM0LESS_ENHANCED_NO_XS set. This is harmless = for + * now because Dom0/hwdom construction isn't supported on RISC-V yet + * either, and no RISC-V DomU sets that flag, so this path is never ta= ken. + * It must be implemented before DOM0LESS_ENHANCED_NO_XS is used. + */ + + return -EOPNOTSUPP; +} diff --git a/xen/arch/riscv/include/asm/guest-layout.h b/xen/arch/riscv/inc= lude/asm/guest-layout.h index 90603f06bb91..ceed9125e7e2 100644 --- a/xen/arch/riscv/include/asm/guest-layout.h +++ b/xen/arch/riscv/include/asm/guest-layout.h @@ -32,4 +32,16 @@ #define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE, GUEST_RAM1_BASE } #define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE, GUEST_RAM1_SIZE } =20 +/* + * The guest magic region holds the Xen-reserved pages mapped into the + * guest's physical address space. The only real constraint on + * GUEST_MAGIC_BASE/SIZE is that the region must not overlap guest RAM + * (the GUEST_RAMx banks) or the emulated device regions defined above; + * the exact base is otherwise arbitrary. Here it is placed in the unused = gap + * below GUEST_RAM0_BASE (0x80000000), but a hole after a RAM bank would w= ork + * equally well. + */ +#define GUEST_MAGIC_BASE _UL(0x79000000) +#define GUEST_MAGIC_SIZE _UL(0x00200000) + #endif /* ASM_RISCV_GUEST_LAYOUT_H */ --=20 2.55.0