From nobody Sun Nov 2 22:42:20 2025 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=1746550979; cv=none; d=zohomail.com; s=zohoarc; b=dW2zCGNY4uR8HxHIrebet//zGB4NhWuctqFO8mximogpYS37gbM57AOOQ0aTVLy3+TgsdDeFB7D198hLTKE3zPbijmWwaeRL/1vlX3WrUlN4Eiik72jmirp0qHiX4IO0OBAFZDrz5QT6RqYXhoT7arAfXHOLieM/zYkX80GA7p0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746550979; h=Content-Type: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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=74wiABz14bkw2Z/ZaZ483gmJiMxC4gHcocH3VFNYNbQ=; b=XgxcVzKJdoXb7R6SSs9dJLB+Zsu0TmTZcMcN55s5QCj8d3to53BS/U5YSG5N9hQK1Xwm9CldzbIPU+WTwNTtBlPg7ujFuYpOpml3X4QN8QfkuD79Bp4wRooByyB63hWLbeZoDammlSj61B5xV1sX6MWaX+N3cAstTA/OQpOAHmc= 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 1746550979832912.8663416229896; Tue, 6 May 2025 10:02:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.977742.1364713 (Exim 4.92) (envelope-from ) id 1uCLge-0005jR-L7; Tue, 06 May 2025 17:02:32 +0000 Received: by outflank-mailman (output) from mailman id 977742.1364713; Tue, 06 May 2025 17:02:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uCLge-0005jK-IA; Tue, 06 May 2025 17:02:32 +0000 Received: by outflank-mailman (input) for mailman id 977742; Tue, 06 May 2025 17:02:31 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uCLWh-00058E-Ar for xen-devel@lists.xenproject.org; Tue, 06 May 2025 16:52:15 +0000 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [2a00:1450:4864:20::62c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7450c7d3-2a9a-11f0-9eb4-5ba50f476ded; Tue, 06 May 2025 18:52:11 +0200 (CEST) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-ace98258d4dso866837866b.2 for ; Tue, 06 May 2025 09:52:11 -0700 (PDT) Received: from fedora.. (user-109-243-69-225.play-internet.pl. [109.243.69.225]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ad1891a3cb9sm740295366b.60.2025.05.06.09.52.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 May 2025 09:52:10 -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" X-Inumbo-ID: 7450c7d3-2a9a-11f0-9eb4-5ba50f476ded DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746550331; x=1747155131; 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; bh=74wiABz14bkw2Z/ZaZ483gmJiMxC4gHcocH3VFNYNbQ=; b=MBkhhV87eQ6bgaluAlm3NUhVI2I0x3LOURr+fUAZSXLD17RlMNOM0TFE1bLRihbuCj /aJDV3M4oBQrdywhmpfGMYfZ7rpZ0YUfYByHjBE9duXEzk4HqMXAi8akTPpavw45d4KB qPO1yAXRgCnSBk8nUTlDDXErgBrI1v04d3okFLwpBStC8NNdD4ylEGLGkgILiCeePBsF denSCbXPGlDX6vj/TK6FGdY4erhyClBX5B3ZppeeDGxwrcNZa8c08Reys4DgRulyNdna 1EqhwH9FNDtpuQ7ODoURI68dku4cHNWWN7x47LtAQ5YzxwxRtlgn3x/MrpnJDEGRFfm4 pCnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746550331; x=1747155131; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=74wiABz14bkw2Z/ZaZ483gmJiMxC4gHcocH3VFNYNbQ=; b=Fl6vlptdQgRLqYXwNSDxgM4emYHS5vOH1MTc7J/1qTub3EBrJusytrFflP97F7B65F b1PV6jEV8DYpUexpfTgRyIhrq3Qwuvhj+GRVlTiKZsOgiaI+BWYNjzZEs/bu/MTmTerC l4fhBIJOKZ+KgtwVJlJz2IhD+AL5tETlIe2HUdfxvPv01OlBv4Y6eoyOGe5kzi3CH1lY MfEewK0XUMlSmu1JCNc52lJ8/pet+WnL/j491jQnw+etKNLthEY5oKEVvWHaZIJ2Fxwf CzRbxiezCiWs9egzQTrHj/ZNfbPHNbBevk7t9fwuWvp/vYiqBL2xRgr6k/pCqDk8PkUm Vfdw== X-Gm-Message-State: AOJu0Yx1YcBH9MXIh7y5g/DHJ98xGq87dzSwWBWFcAS+tSU0IpjxhdfA GCDdsL7eaqJQDc+qoHeEeRKe+1QQYNhrDny+kAYb4KQgDoxvKDn6GFUdmg== X-Gm-Gg: ASbGnctv3poAlvvredZkrlTfCHi1pXcLMlZ+GzmgxEFCXvGiEciMUaEYAW/+uErI56e y4lx78mlytoHzQlvbAvmkWkj9nB3nMximrNhfGVbaRaEokoiohMut5IxWeJYqEkUvm6YBTKBbyC Hzv0NtU7ERevCIiLmVkJ2nVltKEVLSOmzR/HuTDhLpXUoG2p2dcBBRtJLQaolo/Lavx8gJK5Upu QPPZW2N4ojF+LIbPi3UJRszMTk7j3QWgZymh7XG6ZeJk14MzkkjvwcYEj21TxMMIGVwHw5xPe5F Hts8oMcDDnlweK0ejGIMmq6UU9xEa/TFyb+28bYCsjrZIeEpmLKwkCn+mky7zA6icfJWLZ9qbHU NsP7QM/tgrg== X-Google-Smtp-Source: AGHT+IFblu95xoNtRnG4Tji7qi8R+0NxWxbkXy0mdy5QOgL2ttB1oJu0kBzpaskg/5IPpBcIaP9wCA== X-Received: by 2002:a17:907:1c12:b0:ace:3732:8a86 with SMTP id a640c23a62f3a-ad1e8d053a9mr17933666b.41.1746550330549; Tue, 06 May 2025 09:52:10 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Romain Caritey Subject: [PATCH v2 15/16] xen/riscv: implement setup_irq() Date: Tue, 6 May 2025 18:51:45 +0200 Message-ID: <6f17bbf0eb6240d7389d389f0973af6fda5cce29.1746530883.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1746550981336019000 Introduce support for IRQ setup on RISC-V by implementing setup_irq() and __setup_irq(), adapted and extended from an initial implementation by [1]. __setup_irq() does the following: - Sets up an IRQ action. - Validates that shared IRQs have non-NULL `dev_id` and are only used when existing handlers allow sharing. - Uses smp_wmb() to enforce memory ordering after assigning desc->action to ensure visibility before enabling the IRQ. - Supports multi-action setups via CONFIG_IRQ_HAS_MULTIPLE_ACTION. setup_irq() does the following: - Converts IRQ number to descriptor and acquires its lock. - Rejects registration if the IRQ is already assigned to a guest domain, printing an error. - Delegates the core setup to __setup_irq(). - On first-time setup, disables the IRQ, routes it to Xen using intc_route_irq_to_xen(), sets default CPU affinity (current CPU), calls the handler=E2=80=99s startup routine, and finally enables the IR= Q. irq_set_affinity() invokes set_affinity() callback from the IRQ handler if present. Defined IRQ_NO_PRIORITY as default priority used when routing IRQs to Xen. [1] https://gitlab.com/xen-project/people/olkur/xen/-/commit/7390e2365828b8= 3e27ead56b03114a56e3699dd5 Co-developed-by: Romain Caritey Signed-off-by: Oleksii Kurochko --- Changes in V2: - Added implenmtation of aplic_set_irq_type() as it is going to be used in this commit. And also, update the implementation of it. Make default case of switch to do panic(). - Move all forward declaration up in asm/irq.h. - s/__setup_irq/_setup_irq. - Code style fixes. - Update commit message. - use smp_wmb() instead of smp_mb() in _setup_irq(). - Drop irq_set_affinity(). - Use plain C operator instead if {clear,set}_bit() for desc->status as it is always used under spinlock(). - Drop set_bit(_IRQ_DISABLED, &desc->status) in setup_irq() as in the case when IRQ is setuped for a first time, desc->status should be already set to IRQ_DISABLED in init_one_irq_desc(). ---- xen/arch/riscv/include/asm/irq.h | 2 + xen/arch/riscv/irq.c | 84 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/xen/arch/riscv/include/asm/irq.h b/xen/arch/riscv/include/asm/= irq.h index 1a05c5ff88..d35fac0a86 100644 --- a/xen/arch/riscv/include/asm/irq.h +++ b/xen/arch/riscv/include/asm/irq.h @@ -9,6 +9,8 @@ =20 #define NR_IRQS 1024 =20 +#define IRQ_NO_PRIORITY 0 + /* TODO */ #define nr_irqs 0U #define nr_static_irqs 0 diff --git a/xen/arch/riscv/irq.c b/xen/arch/riscv/irq.c index 056bdf3ca8..969e22395d 100644 --- a/xen/arch/riscv/irq.c +++ b/xen/arch/riscv/irq.c @@ -7,6 +7,7 @@ */ =20 #include +#include #include #include #include @@ -58,6 +59,89 @@ int platform_get_irq(const struct dt_device_node *device= , int index) return dt_irq.irq; } =20 +static int _setup_irq(struct irq_desc *desc, unsigned int irqflags, + struct irqaction *new) +{ + bool shared =3D irqflags & IRQF_SHARED; + + ASSERT(new !=3D NULL); + + /* + * Sanity checks: + * - if the IRQ is marked as shared + * - dev_id is not NULL when IRQF_SHARED is set + */ + if ( desc->action !=3D NULL && (!(desc->status & IRQF_SHARED) || !shar= ed) ) + return -EINVAL; + if ( shared && new->dev_id =3D=3D NULL ) + return -EINVAL; + + if ( shared ) + desc->status |=3D IRQF_SHARED; + +#ifdef CONFIG_IRQ_HAS_MULTIPLE_ACTION + new->next =3D desc->action; +#endif + + desc->action =3D new; + smp_wmb(); + + return 0; +} + +int setup_irq(unsigned int irq, unsigned int irqflags, struct irqaction *n= ew) +{ + int rc; + unsigned long flags; + struct irq_desc *desc =3D irq_to_desc(irq); + bool disabled; + + spin_lock_irqsave(&desc->lock, flags); + + disabled =3D (desc->action =3D=3D NULL); + + if ( desc->status & IRQ_GUEST ) + { + spin_unlock_irqrestore(&desc->lock, flags); + /* + * TODO: would be nice to have functionality to print which domain= owns + * an IRQ. + */ + printk(XENLOG_ERR "ERROR: IRQ %u is already in use by a domain\n",= irq); + return -EBUSY; + } + + rc =3D _setup_irq(desc, irqflags, new); + if ( rc ) + goto err; + + /* First time the IRQ is setup */ + if ( disabled ) + { + /* Route interrupt to xen */ + intc_route_irq_to_xen(desc, IRQ_NO_PRIORITY); + + /* + * We don't care for now which CPU will receive the + * interrupt. + * + * TODO: Handle case where IRQ is setup on different CPU than + * the targeted CPU and the priority. + */ + desc->handler->set_affinity(desc, cpumask_of(smp_processor_id())); + + desc->handler->startup(desc); + + /* Enable irq */ + desc->status &=3D ~IRQ_DISABLED; + } + + err: + spin_unlock_irqrestore(&desc->lock, flags); + + return rc; +} + int arch_init_one_irq_desc(struct irq_desc *desc) { desc->arch.type =3D IRQ_TYPE_INVALID; --=20 2.49.0