From nobody Fri Jan 2 05:47:55 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1697437791; cv=none; d=zohomail.com; s=zohoarc; b=HVarWJs1+cAkza5AEFBCMWkbXl3HFqv/yFkso2mX/xi3vpuhYMTwgfceTj28KIFwjIcx/YQJfYO858gfiknmkFU8zFsXLDiID+vgL/1HRIEqsKdUSJQJ/Mp0kGML13a5qArgXzizt+N574px63P0LjyQhdj5SNul0HMMmkU/yKk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697437791; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8tpUjw2e6RaQIlbcZjjZ8I3SSuNLz9AsXteBGTzqAdM=; b=fS96I4jF6LcSGVPqGpeLFc8tkTIEcreKefDC8vf298l2FyMHm6t32wlrxg9szkyeNqhgxXL/pHEWih8DY55RNHpdtubj5jfMsz6h50Ulo/AKezY+hRcHckuQkWenBVftEcrFVDni1pkUodvDZ0XngFtMqwvgNVqOZn2pHqIVWTM= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1697437790992499.07046305573294; Sun, 15 Oct 2023 23:29:50 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.617236.959695 (Exim 4.92) (envelope-from ) id 1qsH6G-0007th-Fy; Mon, 16 Oct 2023 06:29:12 +0000 Received: by outflank-mailman (output) from mailman id 617236.959695; Mon, 16 Oct 2023 06:29:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsH6G-0007tZ-DI; Mon, 16 Oct 2023 06:29:12 +0000 Received: by outflank-mailman (input) for mailman id 617236; Mon, 16 Oct 2023 06:29:11 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsH6F-0005UW-Pb for xen-devel@lists.xenproject.org; Mon, 16 Oct 2023 06:29:11 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5048defb-6bed-11ee-9b0e-b553b5be7939; Mon, 16 Oct 2023 08:29:09 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1EBCC218B5; Mon, 16 Oct 2023 06:29:09 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E5189138EF; Mon, 16 Oct 2023 06:29:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8u1dNjTYLGW1QQAAMHmgww (envelope-from ); Mon, 16 Oct 2023 06:29:08 +0000 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: 5048defb-6bed-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1697437749; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8tpUjw2e6RaQIlbcZjjZ8I3SSuNLz9AsXteBGTzqAdM=; b=ReDNizVbt2fmpKu+czbKT0Et+d2e92d6zBjU3MD2xixkt1HI5Edp1Bb5QYIGdpPGmgF4a/ 6NyRMZ2XKxGDOn+Kn5BzIxzqVAeFlX0kzKbwqMHNgtSBwt/yiSXkDqegZeYfQBG7sGv++X UnL4M1NcPJuO2iSi4rbzjNDvQ2og6uY= From: Juergen Gross To: linux-kernel@vger.kernel.org Cc: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , xen-devel@lists.xenproject.org Subject: [PATCH 6/7] xen/events: modify internal [un]bind interfaces Date: Mon, 16 Oct 2023 08:28:30 +0200 Message-Id: <20231016062831.20630-7-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231016062831.20630-1-jgross@suse.com> References: <20231016062831.20630-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -6.10 X-Spamd-Result: default: False [-6.10 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[5]; NEURAL_HAM_LONG(-3.00)[-1.000]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1697437792337100001 Content-Type: text/plain; charset="utf-8" Modify the internal bind- and unbind-interfaces to take a struct irq_info parameter. When allocating a new IRQ pass the pointer from the allocating function further up. This will reduce the number of info_for_irq() calls and make the code more efficient. Signed-off-by: Juergen Gross Reviewed-by: Oleksandr Tyshchenko --- drivers/xen/events/events_base.c | 252 +++++++++++++++---------------- 1 file changed, 121 insertions(+), 131 deletions(-) diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_b= ase.c index 58e5549ee1db..47a33d3cbfcb 100644 --- a/drivers/xen/events/events_base.c +++ b/drivers/xen/events/events_base.c @@ -325,7 +325,6 @@ static void delayed_free_irq(struct work_struct *work) =20 /* Constructors for packed IRQ information. */ static int xen_irq_info_common_setup(struct irq_info *info, - unsigned irq, enum xen_irq_type type, evtchn_port_t evtchn, unsigned short cpu) @@ -340,23 +339,22 @@ static int xen_irq_info_common_setup(struct irq_info = *info, info->mask_reason =3D EVT_MASK_REASON_EXPLICIT; raw_spin_lock_init(&info->lock); =20 - ret =3D set_evtchn_to_irq(evtchn, irq); + ret =3D set_evtchn_to_irq(evtchn, info->irq); if (ret < 0) return ret; =20 - irq_clear_status_flags(irq, IRQ_NOREQUEST|IRQ_NOAUTOEN); + irq_clear_status_flags(info->irq, IRQ_NOREQUEST | IRQ_NOAUTOEN); =20 return xen_evtchn_port_setup(evtchn); } =20 -static int xen_irq_info_evtchn_setup(unsigned irq, +static int xen_irq_info_evtchn_setup(struct irq_info *info, evtchn_port_t evtchn, struct xenbus_device *dev) { - struct irq_info *info =3D info_for_irq(irq); int ret; =20 - ret =3D xen_irq_info_common_setup(info, irq, IRQT_EVTCHN, evtchn, 0); + ret =3D xen_irq_info_common_setup(info, IRQT_EVTCHN, evtchn, 0); info->u.interdomain =3D dev; if (dev) atomic_inc(&dev->event_channels); @@ -364,49 +362,36 @@ static int xen_irq_info_evtchn_setup(unsigned irq, return ret; } =20 -static int xen_irq_info_ipi_setup(unsigned cpu, - unsigned irq, - evtchn_port_t evtchn, - enum ipi_vector ipi) +static int xen_irq_info_ipi_setup(struct irq_info *info, unsigned int cpu, + evtchn_port_t evtchn, enum ipi_vector ipi) { - struct irq_info *info =3D info_for_irq(irq); - info->u.ipi =3D ipi; =20 - per_cpu(ipi_to_irq, cpu)[ipi] =3D irq; + per_cpu(ipi_to_irq, cpu)[ipi] =3D info->irq; =20 - return xen_irq_info_common_setup(info, irq, IRQT_IPI, evtchn, 0); + return xen_irq_info_common_setup(info, IRQT_IPI, evtchn, 0); } =20 -static int xen_irq_info_virq_setup(unsigned cpu, - unsigned irq, - evtchn_port_t evtchn, - unsigned virq) +static int xen_irq_info_virq_setup(struct irq_info *info, unsigned int cpu, + evtchn_port_t evtchn, unsigned int virq) { - struct irq_info *info =3D info_for_irq(irq); - info->u.virq =3D virq; =20 - per_cpu(virq_to_irq, cpu)[virq] =3D irq; + per_cpu(virq_to_irq, cpu)[virq] =3D info->irq; =20 - return xen_irq_info_common_setup(info, irq, IRQT_VIRQ, evtchn, 0); + return xen_irq_info_common_setup(info, IRQT_VIRQ, evtchn, 0); } =20 -static int xen_irq_info_pirq_setup(unsigned irq, - evtchn_port_t evtchn, - unsigned pirq, - unsigned gsi, - uint16_t domid, - unsigned char flags) +static int xen_irq_info_pirq_setup(struct irq_info *info, evtchn_port_t ev= tchn, + unsigned int pirq, unsigned int gsi, + uint16_t domid, unsigned char flags) { - struct irq_info *info =3D info_for_irq(irq); - info->u.pirq.pirq =3D pirq; info->u.pirq.gsi =3D gsi; info->u.pirq.domid =3D domid; info->u.pirq.flags =3D flags; =20 - return xen_irq_info_common_setup(info, irq, IRQT_PIRQ, evtchn, 0); + return xen_irq_info_common_setup(info, IRQT_PIRQ, evtchn, 0); } =20 static void xen_irq_info_cleanup(struct irq_info *info) @@ -450,20 +435,16 @@ int irq_evtchn_from_virq(unsigned int cpu, unsigned i= nt virq, return irq; } =20 -static enum ipi_vector ipi_from_irq(unsigned irq) +static enum ipi_vector ipi_from_irq(struct irq_info *info) { - struct irq_info *info =3D info_for_irq(irq); - BUG_ON(info =3D=3D NULL); BUG_ON(info->type !=3D IRQT_IPI); =20 return info->u.ipi; } =20 -static unsigned virq_from_irq(unsigned irq) +static unsigned int virq_from_irq(struct irq_info *info) { - struct irq_info *info =3D info_for_irq(irq); - BUG_ON(info =3D=3D NULL); BUG_ON(info->type !=3D IRQT_VIRQ); =20 @@ -530,13 +511,9 @@ static bool pirq_needs_eoi_flag(unsigned irq) return info->u.pirq.flags & PIRQ_NEEDS_EOI; } =20 -static void bind_evtchn_to_cpu(evtchn_port_t evtchn, unsigned int cpu, +static void bind_evtchn_to_cpu(struct irq_info *info, unsigned int cpu, bool force_affinity) { - struct irq_info *info =3D evtchn_to_info(evtchn); - - BUG_ON(info =3D=3D NULL); - if (IS_ENABLED(CONFIG_SMP) && force_affinity) { struct irq_data *data =3D irq_get_irq_data(info->irq); =20 @@ -544,7 +521,7 @@ static void bind_evtchn_to_cpu(evtchn_port_t evtchn, un= signed int cpu, irq_data_update_effective_affinity(data, cpumask_of(cpu)); } =20 - xen_evtchn_port_bind_to_cpu(evtchn, cpu, info->cpu); + xen_evtchn_port_bind_to_cpu(info->evtchn, cpu, info->cpu); =20 channels_on_cpu_dec(info); info->cpu =3D cpu; @@ -759,23 +736,24 @@ static struct irq_info *xen_irq_init(unsigned int irq) return info; } =20 -static inline int __must_check xen_allocate_irq_dynamic(void) +static struct irq_info *xen_allocate_irq_dynamic(void) { int irq =3D irq_alloc_desc_from(0, -1); + struct irq_info *info =3D NULL; =20 if (irq >=3D 0) { - if (!xen_irq_init(irq)) { + info =3D xen_irq_init(irq); + if (!info) xen_irq_free_desc(irq); - irq =3D -1; - } } =20 - return irq; + return info; } =20 -static int __must_check xen_allocate_irq_gsi(unsigned gsi) +static struct irq_info *xen_allocate_irq_gsi(unsigned int gsi) { int irq; + struct irq_info *info; =20 /* * A PV guest has no concept of a GSI (since it has no ACPI @@ -792,18 +770,15 @@ static int __must_check xen_allocate_irq_gsi(unsigned= gsi) else irq =3D irq_alloc_desc_at(gsi, -1); =20 - if (!xen_irq_init(irq)) { + info =3D xen_irq_init(irq); + if (!info) xen_irq_free_desc(irq); - irq =3D -1; - } =20 - return irq; + return info; } =20 -static void xen_free_irq(unsigned irq) +static void xen_free_irq(struct irq_info *info) { - struct irq_info *info =3D info_for_irq(irq); - if (WARN_ON(!info)) return; =20 @@ -894,7 +869,7 @@ static unsigned int __startup_pirq(unsigned int irq) goto err; =20 info->evtchn =3D evtchn; - bind_evtchn_to_cpu(evtchn, 0, false); + bind_evtchn_to_cpu(info, 0, false); =20 rc =3D xen_evtchn_port_setup(evtchn); if (rc) @@ -960,10 +935,9 @@ int xen_irq_from_gsi(unsigned gsi) } EXPORT_SYMBOL_GPL(xen_irq_from_gsi); =20 -static void __unbind_from_irq(unsigned int irq) +static void __unbind_from_irq(struct irq_info *info, unsigned int irq) { - evtchn_port_t evtchn =3D evtchn_from_irq(irq); - struct irq_info *info =3D info_for_irq(irq); + evtchn_port_t evtchn; =20 if (!info) { xen_irq_free_desc(irq); @@ -976,6 +950,8 @@ static void __unbind_from_irq(unsigned int irq) return; } =20 + evtchn =3D info->evtchn; + if (VALID_EVTCHN(evtchn)) { unsigned int cpu =3D info->cpu; struct xenbus_device *dev; @@ -985,10 +961,10 @@ static void __unbind_from_irq(unsigned int irq) =20 switch (info->type) { case IRQT_VIRQ: - per_cpu(virq_to_irq, cpu)[virq_from_irq(irq)] =3D -1; + per_cpu(virq_to_irq, cpu)[virq_from_irq(info)] =3D -1; break; case IRQT_IPI: - per_cpu(ipi_to_irq, cpu)[ipi_from_irq(irq)] =3D -1; + per_cpu(ipi_to_irq, cpu)[ipi_from_irq(info)] =3D -1; break; case IRQT_EVTCHN: dev =3D info->u.interdomain; @@ -1002,7 +978,7 @@ static void __unbind_from_irq(unsigned int irq) xen_irq_info_cleanup(info); } =20 - xen_free_irq(irq); + xen_free_irq(info); } =20 /* @@ -1018,24 +994,24 @@ static void __unbind_from_irq(unsigned int irq) int xen_bind_pirq_gsi_to_irq(unsigned gsi, unsigned pirq, int shareable, char *name) { - int irq; + struct irq_info *info; struct physdev_irq irq_op; int ret; =20 mutex_lock(&irq_mapping_update_lock); =20 - irq =3D xen_irq_from_gsi(gsi); - if (irq !=3D -1) { + ret =3D xen_irq_from_gsi(gsi); + if (ret !=3D -1) { pr_info("%s: returning irq %d for gsi %u\n", - __func__, irq, gsi); + __func__, ret, gsi); goto out; } =20 - irq =3D xen_allocate_irq_gsi(gsi); - if (irq < 0) + info =3D xen_allocate_irq_gsi(gsi); + if (!info) goto out; =20 - irq_op.irq =3D irq; + irq_op.irq =3D info->irq; irq_op.vector =3D 0; =20 /* Only the privileged domain can do this. For non-priv, the pcifront @@ -1043,20 +1019,19 @@ int xen_bind_pirq_gsi_to_irq(unsigned gsi, * this in the priv domain. */ if (xen_initial_domain() && HYPERVISOR_physdev_op(PHYSDEVOP_alloc_irq_vector, &irq_op)) { - xen_free_irq(irq); - irq =3D -ENOSPC; + xen_free_irq(info); + ret =3D -ENOSPC; goto out; } =20 - ret =3D xen_irq_info_pirq_setup(irq, 0, pirq, gsi, DOMID_SELF, + ret =3D xen_irq_info_pirq_setup(info, 0, pirq, gsi, DOMID_SELF, shareable ? PIRQ_SHAREABLE : 0); if (ret < 0) { - __unbind_from_irq(irq); - irq =3D ret; + __unbind_from_irq(info, info->irq); goto out; } =20 - pirq_query_unmask(irq); + pirq_query_unmask(info->irq); /* We try to use the handler with the appropriate semantic for the * type of interrupt: if the interrupt is an edge triggered * interrupt we use handle_edge_irq. @@ -1073,16 +1048,18 @@ int xen_bind_pirq_gsi_to_irq(unsigned gsi, * is the right choice either way. */ if (shareable) - irq_set_chip_and_handler_name(irq, &xen_pirq_chip, + irq_set_chip_and_handler_name(info->irq, &xen_pirq_chip, handle_fasteoi_irq, name); else - irq_set_chip_and_handler_name(irq, &xen_pirq_chip, + irq_set_chip_and_handler_name(info->irq, &xen_pirq_chip, handle_edge_irq, name); =20 + ret =3D info->irq; + out: mutex_unlock(&irq_mapping_update_lock); =20 - return irq; + return ret; } =20 #ifdef CONFIG_PCI_MSI @@ -1104,6 +1081,7 @@ int xen_bind_pirq_msi_to_irq(struct pci_dev *dev, str= uct msi_desc *msidesc, int pirq, int nvec, const char *name, domid_t domid) { int i, irq, ret; + struct irq_info *info; =20 mutex_lock(&irq_mapping_update_lock); =20 @@ -1112,12 +1090,13 @@ int xen_bind_pirq_msi_to_irq(struct pci_dev *dev, s= truct msi_desc *msidesc, goto out; =20 for (i =3D 0; i < nvec; i++) { - if (!xen_irq_init(irq + i)) + info =3D xen_irq_init(irq + i); + if (!info) goto error_irq; =20 irq_set_chip_and_handler_name(irq + i, &xen_pirq_chip, handle_edge_irq, = name); =20 - ret =3D xen_irq_info_pirq_setup(irq + i, 0, pirq + i, 0, domid, + ret =3D xen_irq_info_pirq_setup(info, 0, pirq + i, 0, domid, i =3D=3D 0 ? 0 : PIRQ_MSI_GROUP); if (ret < 0) goto error_irq; @@ -1129,9 +1108,12 @@ int xen_bind_pirq_msi_to_irq(struct pci_dev *dev, st= ruct msi_desc *msidesc, out: mutex_unlock(&irq_mapping_update_lock); return irq; + error_irq: - while (nvec--) - __unbind_from_irq(irq + nvec); + while (nvec--) { + info =3D info_for_irq(irq + nvec); + __unbind_from_irq(info, irq + nvec); + } mutex_unlock(&irq_mapping_update_lock); return ret; } @@ -1167,7 +1149,7 @@ int xen_destroy_irq(int irq) } } =20 - xen_free_irq(irq); + xen_free_irq(info); =20 out: mutex_unlock(&irq_mapping_update_lock); @@ -1183,8 +1165,7 @@ EXPORT_SYMBOL_GPL(xen_pirq_from_irq); static int bind_evtchn_to_irq_chip(evtchn_port_t evtchn, struct irq_chip *= chip, struct xenbus_device *dev) { - int irq; - int ret; + int ret =3D -ENOMEM; struct irq_info *info; =20 if (evtchn >=3D xen_evtchn_max_channels()) @@ -1195,17 +1176,16 @@ static int bind_evtchn_to_irq_chip(evtchn_port_t ev= tchn, struct irq_chip *chip, info =3D evtchn_to_info(evtchn); =20 if (!info) { - irq =3D xen_allocate_irq_dynamic(); - if (irq < 0) + info =3D xen_allocate_irq_dynamic(); + if (!info) goto out; =20 - irq_set_chip_and_handler_name(irq, chip, + irq_set_chip_and_handler_name(info->irq, chip, handle_edge_irq, "event"); =20 - ret =3D xen_irq_info_evtchn_setup(irq, evtchn, dev); + ret =3D xen_irq_info_evtchn_setup(info, evtchn, dev); if (ret < 0) { - __unbind_from_irq(irq); - irq =3D ret; + __unbind_from_irq(info, info->irq); goto out; } /* @@ -1215,16 +1195,17 @@ static int bind_evtchn_to_irq_chip(evtchn_port_t ev= tchn, struct irq_chip *chip, * affinity setting is not invoked on them so nothing would * bind the channel. */ - bind_evtchn_to_cpu(evtchn, 0, false); + bind_evtchn_to_cpu(info, 0, false); } else { WARN_ON(info->type !=3D IRQT_EVTCHN); - irq =3D info->irq; } =20 + ret =3D info->irq; + out: mutex_unlock(&irq_mapping_update_lock); =20 - return irq; + return ret; } =20 int bind_evtchn_to_irq(evtchn_port_t evtchn) @@ -1243,18 +1224,19 @@ static int bind_ipi_to_irq(unsigned int ipi, unsign= ed int cpu) { struct evtchn_bind_ipi bind_ipi; evtchn_port_t evtchn; - int ret, irq; + struct irq_info *info; + int ret; =20 mutex_lock(&irq_mapping_update_lock); =20 - irq =3D per_cpu(ipi_to_irq, cpu)[ipi]; + ret =3D per_cpu(ipi_to_irq, cpu)[ipi]; =20 - if (irq =3D=3D -1) { - irq =3D xen_allocate_irq_dynamic(); - if (irq < 0) + if (ret =3D=3D -1) { + info =3D xen_allocate_irq_dynamic(); + if (!info) goto out; =20 - irq_set_chip_and_handler_name(irq, &xen_percpu_chip, + irq_set_chip_and_handler_name(info->irq, &xen_percpu_chip, handle_percpu_irq, "ipi"); =20 bind_ipi.vcpu =3D xen_vcpu_nr(cpu); @@ -1263,25 +1245,25 @@ static int bind_ipi_to_irq(unsigned int ipi, unsign= ed int cpu) BUG(); evtchn =3D bind_ipi.port; =20 - ret =3D xen_irq_info_ipi_setup(cpu, irq, evtchn, ipi); + ret =3D xen_irq_info_ipi_setup(info, cpu, evtchn, ipi); if (ret < 0) { - __unbind_from_irq(irq); - irq =3D ret; + __unbind_from_irq(info, info->irq); goto out; } /* * Force the affinity mask to the target CPU so proc shows * the correct target. */ - bind_evtchn_to_cpu(evtchn, cpu, true); + bind_evtchn_to_cpu(info, cpu, true); + ret =3D info->irq; } else { - struct irq_info *info =3D info_for_irq(irq); + info =3D info_for_irq(ret); WARN_ON(info =3D=3D NULL || info->type !=3D IRQT_IPI); } =20 out: mutex_unlock(&irq_mapping_update_lock); - return irq; + return ret; } =20 static int bind_interdomain_evtchn_to_irq_chip(struct xenbus_device *dev, @@ -1349,22 +1331,23 @@ int bind_virq_to_irq(unsigned int virq, unsigned in= t cpu, bool percpu) { struct evtchn_bind_virq bind_virq; evtchn_port_t evtchn =3D 0; - int irq, ret; + struct irq_info *info; + int ret; =20 mutex_lock(&irq_mapping_update_lock); =20 - irq =3D per_cpu(virq_to_irq, cpu)[virq]; + ret =3D per_cpu(virq_to_irq, cpu)[virq]; =20 - if (irq =3D=3D -1) { - irq =3D xen_allocate_irq_dynamic(); - if (irq < 0) + if (ret =3D=3D -1) { + info =3D xen_allocate_irq_dynamic(); + if (!info) goto out; =20 if (percpu) - irq_set_chip_and_handler_name(irq, &xen_percpu_chip, + irq_set_chip_and_handler_name(info->irq, &xen_percpu_chip, handle_percpu_irq, "virq"); else - irq_set_chip_and_handler_name(irq, &xen_dynamic_chip, + irq_set_chip_and_handler_name(info->irq, &xen_dynamic_chip, handle_edge_irq, "virq"); =20 bind_virq.virq =3D virq; @@ -1379,10 +1362,9 @@ int bind_virq_to_irq(unsigned int virq, unsigned int= cpu, bool percpu) BUG_ON(ret < 0); } =20 - ret =3D xen_irq_info_virq_setup(cpu, irq, evtchn, virq); + ret =3D xen_irq_info_virq_setup(info, cpu, evtchn, virq); if (ret < 0) { - __unbind_from_irq(irq); - irq =3D ret; + __unbind_from_irq(info, info->irq); goto out; } =20 @@ -1390,22 +1372,26 @@ int bind_virq_to_irq(unsigned int virq, unsigned in= t cpu, bool percpu) * Force the affinity mask for percpu interrupts so proc * shows the correct target. */ - bind_evtchn_to_cpu(evtchn, cpu, percpu); + bind_evtchn_to_cpu(info, cpu, percpu); + ret =3D info->irq; } else { - struct irq_info *info =3D info_for_irq(irq); + info =3D info_for_irq(ret); WARN_ON(info =3D=3D NULL || info->type !=3D IRQT_VIRQ); } =20 out: mutex_unlock(&irq_mapping_update_lock); =20 - return irq; + return ret; } =20 static void unbind_from_irq(unsigned int irq) { + struct irq_info *info; + mutex_lock(&irq_mapping_update_lock); - __unbind_from_irq(irq); + info =3D info_for_irq(irq); + __unbind_from_irq(info, irq); mutex_unlock(&irq_mapping_update_lock); } =20 @@ -1739,11 +1725,11 @@ void rebind_evtchn_irq(evtchn_port_t evtchn, int ir= q) BUG_ON(info->type =3D=3D IRQT_UNBOUND); =20 info->irq =3D irq; - (void)xen_irq_info_evtchn_setup(irq, evtchn, NULL); + (void)xen_irq_info_evtchn_setup(info, evtchn, NULL); =20 mutex_unlock(&irq_mapping_update_lock); =20 - bind_evtchn_to_cpu(evtchn, info->cpu, false); + bind_evtchn_to_cpu(info, info->cpu, false); =20 /* Unmask the event channel. */ enable_irq(irq); @@ -1777,7 +1763,7 @@ static int xen_rebind_evtchn_to_cpu(struct irq_info *= info, unsigned int tcpu) * it, but don't do the xenlinux-level rebind in that case. */ if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_vcpu, &bind_vcpu) >=3D 0) - bind_evtchn_to_cpu(evtchn, tcpu, false); + bind_evtchn_to_cpu(info, tcpu, false); =20 do_unmask(info, EVT_MASK_REASON_TEMPORARY); =20 @@ -1928,7 +1914,7 @@ static void restore_pirqs(void) if (rc) { pr_warn("xen map irq failed gsi=3D%d irq=3D%d pirq=3D%d rc=3D%d\n", gsi, irq, pirq, rc); - xen_free_irq(irq); + xen_free_irq(info); continue; } =20 @@ -1942,13 +1928,15 @@ static void restore_cpu_virqs(unsigned int cpu) { struct evtchn_bind_virq bind_virq; evtchn_port_t evtchn; + struct irq_info *info; int virq, irq; =20 for (virq =3D 0; virq < NR_VIRQS; virq++) { if ((irq =3D per_cpu(virq_to_irq, cpu)[virq]) =3D=3D -1) continue; + info =3D info_for_irq(irq); =20 - BUG_ON(virq_from_irq(irq) !=3D virq); + BUG_ON(virq_from_irq(info) !=3D virq); =20 /* Get a new binding from Xen. */ bind_virq.virq =3D virq; @@ -1959,9 +1947,9 @@ static void restore_cpu_virqs(unsigned int cpu) evtchn =3D bind_virq.port; =20 /* Record the new mapping. */ - (void)xen_irq_info_virq_setup(cpu, irq, evtchn, virq); + xen_irq_info_virq_setup(info, cpu, evtchn, virq); /* The affinity mask is still valid */ - bind_evtchn_to_cpu(evtchn, cpu, false); + bind_evtchn_to_cpu(info, cpu, false); } } =20 @@ -1969,13 +1957,15 @@ static void restore_cpu_ipis(unsigned int cpu) { struct evtchn_bind_ipi bind_ipi; evtchn_port_t evtchn; + struct irq_info *info; int ipi, irq; =20 for (ipi =3D 0; ipi < XEN_NR_IPIS; ipi++) { if ((irq =3D per_cpu(ipi_to_irq, cpu)[ipi]) =3D=3D -1) continue; + info =3D info_for_irq(irq); =20 - BUG_ON(ipi_from_irq(irq) !=3D ipi); + BUG_ON(ipi_from_irq(info) !=3D ipi); =20 /* Get a new binding from Xen. */ bind_ipi.vcpu =3D xen_vcpu_nr(cpu); @@ -1985,9 +1975,9 @@ static void restore_cpu_ipis(unsigned int cpu) evtchn =3D bind_ipi.port; =20 /* Record the new mapping. */ - (void)xen_irq_info_ipi_setup(cpu, irq, evtchn, ipi); + xen_irq_info_ipi_setup(info, cpu, evtchn, ipi); /* The affinity mask is still valid */ - bind_evtchn_to_cpu(evtchn, cpu, false); + bind_evtchn_to_cpu(info, cpu, false); } } =20 --=20 2.35.3