Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1305895rdh; Fri, 27 Oct 2023 10:07:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGWvRnd2FAxZh/fgJxSnECsBzS5nMYlQs8xM3fJtTpMqNZpP9+l8g+pJ1zCy0L0b+e6o3Lw X-Received: by 2002:a05:6102:10ca:b0:457:c511:8e71 with SMTP id t10-20020a05610210ca00b00457c5118e71mr3018036vsr.30.1698426458423; Fri, 27 Oct 2023 10:07:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698426458; cv=none; d=google.com; s=arc-20160816; b=nWEznSnBJZ23a7jRixwp9m/g+2zTbZDYa33+YrplLYP1x1PTVnsIZL94i4MggFkZw+ edrIKXEOUvgq+yqfTP9/LjBzIkPALnxfao6CtWVCNqJSxSgnk+K62ZMFt0OyCoU+Ja+0 0Y9j4uekLSEXc3Boqw4g+VN45Z7f2DhBZ1AvO9Zc8gYch++cd68qpfp+8xkxm60HnzTx mi2U8Hh4vS6cCQmaE27aEGMwjIAUcOZjk24tBztwkIUEAFTT5/VJljGIxOCg2Brvx3h8 B5zFVOouXl3oknR+STR3OG1i3MQUuRWTIdT668XBQBBnNqG0U0kEt9bgekp5TAP5syIF LlVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NeFWql5pzJCNi+1g4NV899ugGaOEj6hEwQnUibUcn0U=; fh=k582jSlci6uTztoHpzXN2a6Foym20J+xbJc48KNsUhM=; b=dOdwYORi3Pwipi79wP3cfx9wAQxDPkjaHQAFyrmKhwFhe+AAxmWQTFwwSaNtwpNgUg cf3mPg4Dt38WIi0xRg6cNRcS7LVLrWA/vsYWjzJOR0yZH4A5+urwfx7vEJ9Pc6qAq3Xb f3oW0l9PdngBWl8vhzNq///oG71g0pUbKvniRKuHgMbTdyjk/0GtNW6Cj0Jh/xpGuUaa MCuxVjtP4b6fxZE561GDybknpO74SmDL8p4zsCbn8MXq1t8khJhYPNb/WrZccnAkib5b 52f37UizlINHE5ID7K8dsLwG2BKrDfFcw/OWNlpG5CkU+78FK/j1fhe1X/L10ufvHxdp MPLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mhzsi8qR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id a3-20020a67b303000000b004577f65ebabsi316746vsm.576.2023.10.27.10.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 10:07:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mhzsi8qR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 17495813899A; Fri, 27 Oct 2023 10:03:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346554AbjJ0RDK (ORCPT + 99 others); Fri, 27 Oct 2023 13:03:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346313AbjJ0RBo (ORCPT ); Fri, 27 Oct 2023 13:01:44 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66646D64; Fri, 27 Oct 2023 10:01:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698426101; x=1729962101; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tbz3SXJJY7i1djigYQYirkmt+YTKLECJsMGiiTtlipg=; b=mhzsi8qRl9dKKufxxHLRj/zfPp/MuUkphL2MYY6oWbd0wFJOhINfyfx8 RtwWkSIn9nAC0XY1bu5RplNbIUTEtvkiH0vkfPXeV6j4ynGQPtRG2Vk2j jSjQ75LFEJVtSw16ly3TDeTPLlMhmbbzmXuhluRc8b5Bv16D4Pre1nYuS ODZ5A+A3545OQ9NRIp5/twiMpSjIoXnX8ekYA1al6ee38h971iefcbsLH pFhgqODQXbXFU6ENUN8iXsXUeggZ0rYUpioF7QyrZ64VUDoCTWGRuqKNe odbXhk+jA2kxY9R9YE3Gj9MVm7j+tCpIoKyjEH8cgvv/ZNiMzQDHwaQIJ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10876"; a="612148" X-IronPort-AV: E=Sophos;i="6.03,256,1694761200"; d="scan'208";a="612148" 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:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10876"; a="1090988246" X-IronPort-AV: E=Sophos;i="6.03,256,1694761200"; d="scan'208";a="1090988246" 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:21 -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 25/26] vfio/pci: Add accessor for IMS index Date: Fri, 27 Oct 2023 10:00:57 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 27 Oct 2023 10:03:15 -0700 (PDT) A virtual device driver needs to facilitate translation between the guest's MSI-X interrupt and the backing IMS interrupt with which the physical device is programmed. For example, the guest may need to obtain the IMS index from the virtual device driver that it needs to program into descriptors submitted to the device to ensure that the completion interrupts are generated correctly. Introduce vfio_pci_ims_hwirq() to the IMS backend as a helper that returns the IMS interrupt index backing a provided MSI-X interrupt index belonging to a guest. Originally-by: Dave Jiang Signed-off-by: Reinette Chatre --- No changes since RFC V2. drivers/vfio/pci/vfio_pci_intrs.c | 25 +++++++++++++++++++++++++ include/linux/vfio_pci_core.h | 1 + 2 files changed, 26 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index b318a3f671e8..32ebc8fec4c4 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -1163,6 +1163,31 @@ void vfio_pci_ims_release_intr_ctx(struct vfio_pci_intr_ctx *intr_ctx) } EXPORT_SYMBOL_GPL(vfio_pci_ims_release_intr_ctx); +/* + * Return IMS index of IMS interrupt backing MSI-X interrupt @vector + */ +int vfio_pci_ims_hwirq(struct vfio_pci_intr_ctx *intr_ctx, unsigned int vector) +{ + struct vfio_pci_irq_ctx *ctx; + int id = -EINVAL; + + mutex_lock(&intr_ctx->igate); + + if (!intr_ctx->ims_backed_irq) + goto out_unlock; + + ctx = vfio_irq_ctx_get(intr_ctx, vector); + if (!ctx || ctx->emulated) + goto out_unlock; + + id = ctx->ims_id; + +out_unlock: + mutex_unlock(&intr_ctx->igate); + return id; +} +EXPORT_SYMBOL_GPL(vfio_pci_ims_hwirq); + int vfio_pci_set_irqs_ioctl(struct vfio_pci_intr_ctx *intr_ctx, uint32_t flags, unsigned int index, unsigned int start, unsigned int count, void *data) diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h index a3161af791f8..dbc77839ef26 100644 --- a/include/linux/vfio_pci_core.h +++ b/include/linux/vfio_pci_core.h @@ -180,6 +180,7 @@ void vfio_pci_release_intr_ctx(struct vfio_pci_intr_ctx *intr_ctx); int vfio_pci_set_irqs_ioctl(struct vfio_pci_intr_ctx *intr_ctx, uint32_t flags, unsigned int index, unsigned int start, unsigned int count, void *data); +int vfio_pci_ims_hwirq(struct vfio_pci_intr_ctx *intr_ctx, unsigned int vector); void vfio_pci_send_signal(struct vfio_pci_intr_ctx *intr_ctx, unsigned int vector); int vfio_pci_set_emulated(struct vfio_pci_intr_ctx *intr_ctx, unsigned int start, unsigned int count); -- 2.34.1