From patchwork Fri Oct 27 17:00:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 13438650 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8713BC25B70 for ; Fri, 27 Oct 2023 17:02:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346366AbjJ0RCC (ORCPT ); Fri, 27 Oct 2023 13:02:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232296AbjJ0RBm (ORCPT ); Fri, 27 Oct 2023 13:01:42 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4CD2D48; Fri, 27 Oct 2023 10:01:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698426097; x=1729962097; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jAVKFX+vaV6MZ7MbRQwvQO7Qe37BB/mxkHKB6ZjkpCk=; b=MvTqs5TSbsZ394BMBLoEgBhlqlrW/3EW+C2mUtjddyVDqBlSc1jRxnJG jp8Ajk/ROAcoG13iPoGWfHdNvkkFQHnR8wzVteDqXuNi0++GPnzWUbv6C XqlVqnwdw+D3hUwHaWh4fyTlw/NXz2RJOCqQZl7CVu5+sCOHoxtdSm2I7 bA+RnvQiD3wDQphzB8RqXbE9ZDYzz092utHk8RvA21QhLRAR/lyzVdDWX g5+9miz/2o5NZZuWbi6nANUM7V6+P6rbHZtCzJOkqFYp2l01BJqm2tXKa O7FdxJ1eqebLzIi71eZpSwmuWTmZVamnoziLquU3dLltEfnJ0x5nX7BMH A==; X-IronPort-AV: E=McAfee;i="6600,9927,10876"; a="612078" X-IronPort-AV: E=Sophos;i="6.03,256,1694761200"; d="scan'208";a="612078" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Oct 2023 10:01:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10876"; a="1090988220" X-IronPort-AV: E=Sophos;i="6.03,256,1694761200"; d="scan'208";a="1090988220" Received: from rchatre-ws.ostc.intel.com ([10.54.69.144]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Oct 2023 10:01:19 -0700 From: Reinette Chatre To: jgg@nvidia.com, yishaih@nvidia.com, shameerali.kolothum.thodi@huawei.com, kevin.tian@intel.com, alex.williamson@redhat.com Cc: kvm@vger.kernel.org, dave.jiang@intel.com, jing2.liu@intel.com, ashok.raj@intel.com, fenghua.yu@intel.com, tom.zanussi@linux.intel.com, reinette.chatre@intel.com, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [RFC PATCH V3 19/26] vfio/pci: Store Linux IRQ number in per-interrupt context Date: Fri, 27 Oct 2023 10:00:51 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The Linux IRQ number is a property shared among all interrupt backends but not all interrupt management backends have a simple query for it. pci_irq_vector() can be used to obtain the Linux IRQ number of a MSI-X interrupt but there is no such query for IMS interrupts. The Linux IRQ number is needed during interrupt free as well as during register of IRQ bypass producer. It is unnecessary to query the Linux IRQ number at each stage, the number can be stored at the time the interrupt is allocated and obtained from its per-interrupt context when needed. Signed-off-by: Reinette Chatre --- Changes since RFC V2: - New patch drivers/vfio/pci/vfio_pci_intrs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 8d84e7d62594..fd0713dc9f81 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -29,6 +29,7 @@ struct vfio_pci_irq_ctx { char *name; bool masked; struct irq_bypass_producer producer; + int virq; }; static bool irq_is(struct vfio_pci_intr_ctx *intr_ctx, int type) @@ -431,10 +432,11 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_intr_ctx *intr_ctx, if (ctx && ctx->trigger) { irq_bypass_unregister_producer(&ctx->producer); - irq = pci_irq_vector(pdev, vector); + irq = ctx->virq; cmd = vfio_pci_memory_lock_and_enable(vdev); - free_irq(irq, ctx->trigger); + free_irq(ctx->virq, ctx->trigger); vfio_pci_memory_unlock_and_restore(vdev, cmd); + ctx->virq = 0; /* Interrupt stays allocated, will be freed at MSI-X disable. */ kfree(ctx->name); ctx->name = NULL; @@ -488,8 +490,10 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_intr_ctx *intr_ctx, if (ret) goto out_put_eventfd_ctx; + ctx->virq = irq; + ctx->producer.token = trigger; - ctx->producer.irq = irq; + ctx->producer.irq = ctx->virq; ret = irq_bypass_register_producer(&ctx->producer); if (unlikely(ret)) { dev_info(&pdev->dev,