From patchwork Fri Nov 25 14:57:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 13056038 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 BBCC2C43219 for ; Fri, 25 Nov 2022 15:06:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229947AbiKYPG1 (ORCPT ); Fri, 25 Nov 2022 10:06:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229891AbiKYPGZ (ORCPT ); Fri, 25 Nov 2022 10:06:25 -0500 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1331F2D1C2; Fri, 25 Nov 2022 07:06:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669388785; x=1700924785; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Uv8WuEazzgbSx4/bAjBoWshididqsR5SPzHsqjDyIts=; b=COJt46Yaq/Zp47Pnois1o6iv2jTrOxIQ2XoQjsrEpSxzIM4aC4G2ZAhc OXy4B/hUUvFdWgwKsW5tiiTVKvAEh8Tvu2MqFJx5/sWR9RMtCBOquTPlC xl7GbV37kci3VPN2bjyqvFx+ENfJL+j+CvJB76GsZr2zzcP2621mkBFp0 YW5iANo0VIO1Xzp6CpP1r1wxmcZJnCVCRCqTCuHx0d/Jc7bqmlsSpaxtG 1fQVfznhhKqt+aWxe2Il+Xkk5XMcT+4mYIqfHwzM8vsVodJMri+XjsYGc af9t9RhuAcALhwtc+d7d2lCNaboF7q3wicqzA0Jgo13d1IXIix1uYDQZE g==; X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="302069142" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="302069142" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:24 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="593240204" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="593240204" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:22 -0800 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, hang.yuan@intel.com, piotr.uminski@intel.com, Zhu Lingshan , stable@vger.kernel.org Subject: [PATCH V2 01/12] vDPA/ifcvf: decouple hw features manipulators from the adapter Date: Fri, 25 Nov 2022 22:57:13 +0800 Message-Id: <20221125145724.1129962-2-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221125145724.1129962-1-lingshan.zhu@intel.com> References: <20221125145724.1129962-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This commit gets rid of ifcvf_adapter in hw features related functions in ifcvf_base. Then these functions are more rubust and de-coupling from the ifcvf_adapter layer. So these functions could be invoded once the device is probed, even before the adapter is allocaed. Signed-off-by: Zhu Lingshan Cc: stable@vger.kernel.org --- drivers/vdpa/ifcvf/ifcvf_base.c | 9 ++------- drivers/vdpa/ifcvf/ifcvf_base.h | 1 + drivers/vdpa/ifcvf/ifcvf_main.c | 1 + 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_base.c b/drivers/vdpa/ifcvf/ifcvf_base.c index 3e4486bfa0b7..7a7e6ba66f88 100644 --- a/drivers/vdpa/ifcvf/ifcvf_base.c +++ b/drivers/vdpa/ifcvf/ifcvf_base.c @@ -220,10 +220,8 @@ u64 ifcvf_get_features(struct ifcvf_hw *hw) int ifcvf_verify_min_features(struct ifcvf_hw *hw, u64 features) { - struct ifcvf_adapter *ifcvf = vf_to_adapter(hw); - if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)) && features) { - IFCVF_ERR(ifcvf->pdev, "VIRTIO_F_ACCESS_PLATFORM is not negotiated\n"); + IFCVF_ERR(hw->pdev, "VIRTIO_F_ACCESS_PLATFORM is not negotiated\n"); return -EINVAL; } @@ -301,14 +299,11 @@ static void ifcvf_set_features(struct ifcvf_hw *hw, u64 features) static int ifcvf_config_features(struct ifcvf_hw *hw) { - struct ifcvf_adapter *ifcvf; - - ifcvf = vf_to_adapter(hw); ifcvf_set_features(hw, hw->req_features); ifcvf_add_status(hw, VIRTIO_CONFIG_S_FEATURES_OK); if (!(ifcvf_get_status(hw) & VIRTIO_CONFIG_S_FEATURES_OK)) { - IFCVF_ERR(ifcvf->pdev, "Failed to set FEATURES_OK status\n"); + IFCVF_ERR(hw->pdev, "Failed to set FEATURES_OK status\n"); return -EIO; } diff --git a/drivers/vdpa/ifcvf/ifcvf_base.h b/drivers/vdpa/ifcvf/ifcvf_base.h index f5563f665cc6..e1fe947d61b7 100644 --- a/drivers/vdpa/ifcvf/ifcvf_base.h +++ b/drivers/vdpa/ifcvf/ifcvf_base.h @@ -89,6 +89,7 @@ struct ifcvf_hw { u16 nr_vring; /* VIRTIO_PCI_CAP_DEVICE_CFG size */ u32 cap_dev_config_size; + struct pci_dev *pdev; }; struct ifcvf_adapter { diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index f9c0044c6442..28c82d796c90 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -842,6 +842,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) vf = &adapter->vf; vf->dev_type = get_dev_type(pdev); vf->base = pcim_iomap_table(pdev); + vf->pdev = pdev; adapter->pdev = pdev; adapter->vdpa.dma_dev = &pdev->dev; From patchwork Fri Nov 25 14:57:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 13056039 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 DE14FC4167B for ; Fri, 25 Nov 2022 15:06:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230025AbiKYPGb (ORCPT ); Fri, 25 Nov 2022 10:06:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229957AbiKYPG3 (ORCPT ); Fri, 25 Nov 2022 10:06:29 -0500 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5921E31DE7; Fri, 25 Nov 2022 07:06:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669388788; x=1700924788; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NGYzFwtP4Q2IeOFdkbC+DFqWio0Q5Y8YrDc4RNGvhPo=; b=Smif7umKlskwTJH1z/YEn1z7IP6r9PnAI/oW3l5clCCY4O+nvLowNBYS Tids7Joo4AysrVRTx7ho2hfyUUZrE9gcdH10xyLm6Zt+wzq+R/Gz/xAyf nHXI1Sn1t6dxI620e4jqP7izXVQjPFF+bKiE7JTWmZqH5Fcoc5PANPg+Y CBF9utsKvTGd9yAsMdFzKi+XzJ6GUkoqWPMDgj8Wo9tOfUqWHctuvCG1V bH05ikZX93DthAzZhYx/ElB7tWCU4baBlvT64hcnsi9DrXoteTgh9mcy5 BIQWath9Rzg2n7LndPNgfktY7s+ensY0VX4NU76nttDw1rDQH7PtBPZSl w==; X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="302069166" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="302069166" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:27 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="593240215" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="593240215" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:25 -0800 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, hang.yuan@intel.com, piotr.uminski@intel.com, Zhu Lingshan , stable@vger.kernel.org Subject: [PATCH V2 02/12] vDPA/ifcvf: decouple config space ops from the adapter Date: Fri, 25 Nov 2022 22:57:14 +0800 Message-Id: <20221125145724.1129962-3-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221125145724.1129962-1-lingshan.zhu@intel.com> References: <20221125145724.1129962-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This commit decopules the config space ops from the adapter layer, so these functions can be invoked once the device is probed. Signed-off-by: Zhu Lingshan Cc: stable@vger.kernel.org --- drivers/vdpa/ifcvf/ifcvf_base.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_base.c b/drivers/vdpa/ifcvf/ifcvf_base.c index 7a7e6ba66f88..3ec5ca3aefe1 100644 --- a/drivers/vdpa/ifcvf/ifcvf_base.c +++ b/drivers/vdpa/ifcvf/ifcvf_base.c @@ -10,11 +10,6 @@ #include "ifcvf_base.h" -struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw) -{ - return container_of(hw, struct ifcvf_adapter, vf); -} - u16 ifcvf_set_vq_vector(struct ifcvf_hw *hw, u16 qid, int vector) { struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg; @@ -37,8 +32,6 @@ u16 ifcvf_set_config_vector(struct ifcvf_hw *hw, int vector) static void __iomem *get_cap_addr(struct ifcvf_hw *hw, struct virtio_pci_cap *cap) { - struct ifcvf_adapter *ifcvf; - struct pci_dev *pdev; u32 length, offset; u8 bar; @@ -46,17 +39,14 @@ static void __iomem *get_cap_addr(struct ifcvf_hw *hw, offset = le32_to_cpu(cap->offset); bar = cap->bar; - ifcvf= vf_to_adapter(hw); - pdev = ifcvf->pdev; - if (bar >= IFCVF_PCI_MAX_RESOURCE) { - IFCVF_DBG(pdev, + IFCVF_DBG(hw->pdev, "Invalid bar number %u to get capabilities\n", bar); return NULL; } - if (offset + length > pci_resource_len(pdev, bar)) { - IFCVF_DBG(pdev, + if (offset + length > pci_resource_len(hw->pdev, bar)) { + IFCVF_DBG(hw->pdev, "offset(%u) + len(%u) overflows bar%u's capability\n", offset, length, bar); return NULL; @@ -92,6 +82,7 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev) IFCVF_ERR(pdev, "Failed to read PCI capability list\n"); return -EIO; } + hw->pdev = pdev; while (pos) { ret = ifcvf_read_config_range(pdev, (u32 *)&cap, @@ -230,13 +221,11 @@ int ifcvf_verify_min_features(struct ifcvf_hw *hw, u64 features) u32 ifcvf_get_config_size(struct ifcvf_hw *hw) { - struct ifcvf_adapter *adapter; u32 net_config_size = sizeof(struct virtio_net_config); u32 blk_config_size = sizeof(struct virtio_blk_config); u32 cap_size = hw->cap_dev_config_size; u32 config_size; - adapter = vf_to_adapter(hw); /* If the onboard device config space size is greater than * the size of struct virtio_net/blk_config, only the spec * implementing contents size is returned, this is very @@ -251,7 +240,7 @@ u32 ifcvf_get_config_size(struct ifcvf_hw *hw) break; default: config_size = 0; - IFCVF_ERR(adapter->pdev, "VIRTIO ID %u not supported\n", hw->dev_type); + IFCVF_ERR(hw->pdev, "VIRTIO ID %u not supported\n", hw->dev_type); } return config_size; From patchwork Fri Nov 25 14:57:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 13056040 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 A809AC4332F for ; Fri, 25 Nov 2022 15:06:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229957AbiKYPGc (ORCPT ); Fri, 25 Nov 2022 10:06:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229891AbiKYPGb (ORCPT ); Fri, 25 Nov 2022 10:06:31 -0500 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D2E63AC13; Fri, 25 Nov 2022 07:06:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669388790; x=1700924790; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GfW1grE+W1yxIIEcRuvloaY402+gBkQ0YBkYnxhRSLg=; b=il0ZuTuorqTQCKssNUK6z03O3nEeefM+QKOc3P6CBYyIhQvOYJoQrKJ6 H+f44VhtO6PcYBWKJLfOJnBtPncFI5bGcplXHmMgD5sMrPVLDCPqPbqP+ txPVIavApAFi9jbpvvEvuFQlSxr87L4UsI7vO5BsnWbO88EdsSNvIaBlM OC8tw16yPYIc+m0ad3HzF9lQZUE/vrXcx8qhnkf4fxz2fDrfFlmH7EzfR OUWa/fJxjp3Qt7rl83kcmBumM896P/4weUIykT38g8gbrlpzX13IHX9Y2 kxPX5epEzF/xuSC2ArCBOm5aXlwX32CKV+B48R23UxiJCkF/aWCJbtPdG A==; X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="302069182" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="302069182" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:30 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="593240230" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="593240230" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:27 -0800 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, hang.yuan@intel.com, piotr.uminski@intel.com, Zhu Lingshan , stable@vger.kernel.org Subject: [PATCH V2 03/12] vDPA/ifcvf: alloc the mgmt_dev before the adapter Date: Fri, 25 Nov 2022 22:57:15 +0800 Message-Id: <20221125145724.1129962-4-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221125145724.1129962-1-lingshan.zhu@intel.com> References: <20221125145724.1129962-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This commit reverses the order of allocating the management device and the adapter. So that it would be possible to move the allocation of the adapter to dev_add(). Signed-off-by: Zhu Lingshan Cc: stable@vger.kernel.org --- drivers/vdpa/ifcvf/ifcvf_main.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index 28c82d796c90..306a57c05509 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -831,22 +831,30 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) } pci_set_master(pdev); + ifcvf_mgmt_dev = kzalloc(sizeof(struct ifcvf_vdpa_mgmt_dev), GFP_KERNEL); + if (!ifcvf_mgmt_dev) { + IFCVF_ERR(pdev, "Failed to alloc memory for the vDPA management device\n"); + return -ENOMEM; + } adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa, dev, &ifc_vdpa_ops, 1, 1, NULL, false); if (IS_ERR(adapter)) { IFCVF_ERR(pdev, "Failed to allocate vDPA structure"); - return PTR_ERR(adapter); + ret = PTR_ERR(adapter); + goto err; } + adapter->pdev = pdev; + adapter->vdpa.dma_dev = &pdev->dev; + adapter->vdpa.mdev = &ifcvf_mgmt_dev->mdev; + ifcvf_mgmt_dev->adapter = adapter; + vf = &adapter->vf; vf->dev_type = get_dev_type(pdev); vf->base = pcim_iomap_table(pdev); vf->pdev = pdev; - adapter->pdev = pdev; - adapter->vdpa.dma_dev = &pdev->dev; - ret = ifcvf_init_hw(vf, pdev); if (ret) { IFCVF_ERR(pdev, "Failed to init IFCVF hw\n"); @@ -859,16 +867,6 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) vf->hw_features = ifcvf_get_hw_features(vf); vf->config_size = ifcvf_get_config_size(vf); - ifcvf_mgmt_dev = kzalloc(sizeof(struct ifcvf_vdpa_mgmt_dev), GFP_KERNEL); - if (!ifcvf_mgmt_dev) { - IFCVF_ERR(pdev, "Failed to alloc memory for the vDPA management device\n"); - return -ENOMEM; - } - - ifcvf_mgmt_dev->mdev.ops = &ifcvf_vdpa_mgmt_dev_ops; - ifcvf_mgmt_dev->mdev.device = dev; - ifcvf_mgmt_dev->adapter = adapter; - dev_type = get_dev_type(pdev); switch (dev_type) { case VIRTIO_ID_NET: @@ -883,12 +881,11 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto err; } + ifcvf_mgmt_dev->mdev.ops = &ifcvf_vdpa_mgmt_dev_ops; + ifcvf_mgmt_dev->mdev.device = dev; ifcvf_mgmt_dev->mdev.max_supported_vqs = vf->nr_vring; ifcvf_mgmt_dev->mdev.supported_features = vf->hw_features; - adapter->vdpa.mdev = &ifcvf_mgmt_dev->mdev; - - ret = vdpa_mgmtdev_register(&ifcvf_mgmt_dev->mdev); if (ret) { IFCVF_ERR(pdev, From patchwork Fri Nov 25 14:57:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 13056041 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 B9E0DC43219 for ; Fri, 25 Nov 2022 15:06:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230222AbiKYPGf (ORCPT ); Fri, 25 Nov 2022 10:06:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229778AbiKYPGe (ORCPT ); Fri, 25 Nov 2022 10:06:34 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 612814047A; Fri, 25 Nov 2022 07:06:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669388793; x=1700924793; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HOdj0oUK3WbeLxjf51f9tIDc5rxKdwxZGte7o/oQccQ=; b=UnY5/AwL9H6LKT/z4LyqjENRgq8ulnB5WfF7p+5g56S9X88TBWJeR6f+ cDqcGUvP7oM6aFMzgRI2v5/L5+M1ma3YrYzNMbBRjTvLJKLa9cIiBrg1d 9EAGCEYhhclO0QMYjBeyL/WVLk5ssVnHHzO4dsyMbefZJQlyMz3Ejd8Lr d6eLM70GKbaoXU7Q6/fMrY4YkOw1WDF7HvVPsMt7x/aQPBzylMWFb1rHG z0gd0xcQcN6QdbuG4+HQ987Mlc7nsoKhge7QQ1d6fmP4AI5rJRdJwsj+y hgVxcZ2b6URAAKZQSA18eoVSYBma6wOBVRHSFXeuy+M/TtA2ZNP0hjRHc w==; X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="294880995" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="294880995" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:32 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="593240249" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="593240249" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:30 -0800 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, hang.yuan@intel.com, piotr.uminski@intel.com, Zhu Lingshan , stable@vger.kernel.org Subject: [PATCH V2 04/12] vDPA/ifcvf: decouple vq IRQ releasers from the adapter Date: Fri, 25 Nov 2022 22:57:16 +0800 Message-Id: <20221125145724.1129962-5-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221125145724.1129962-1-lingshan.zhu@intel.com> References: <20221125145724.1129962-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This commit decouples the IRQ releasers from the adapter, so that these functions could be safely invoked once probe Signed-off-by: Zhu Lingshan Cc: stable@vger.kernel.org --- drivers/vdpa/ifcvf/ifcvf_main.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index 306a57c05509..7dac0285b71d 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -69,10 +69,9 @@ static void ifcvf_free_irq_vectors(void *data) pci_free_irq_vectors(data); } -static void ifcvf_free_per_vq_irq(struct ifcvf_adapter *adapter) +static void ifcvf_free_per_vq_irq(struct ifcvf_hw *vf) { - struct pci_dev *pdev = adapter->pdev; - struct ifcvf_hw *vf = &adapter->vf; + struct pci_dev *pdev = vf->pdev; int i; for (i = 0; i < vf->nr_vring; i++) { @@ -83,10 +82,9 @@ static void ifcvf_free_per_vq_irq(struct ifcvf_adapter *adapter) } } -static void ifcvf_free_vqs_reused_irq(struct ifcvf_adapter *adapter) +static void ifcvf_free_vqs_reused_irq(struct ifcvf_hw *vf) { - struct pci_dev *pdev = adapter->pdev; - struct ifcvf_hw *vf = &adapter->vf; + struct pci_dev *pdev = vf->pdev; if (vf->vqs_reused_irq != -EINVAL) { devm_free_irq(&pdev->dev, vf->vqs_reused_irq, vf); @@ -95,14 +93,12 @@ static void ifcvf_free_vqs_reused_irq(struct ifcvf_adapter *adapter) } -static void ifcvf_free_vq_irq(struct ifcvf_adapter *adapter) +static void ifcvf_free_vq_irq(struct ifcvf_hw *vf) { - struct ifcvf_hw *vf = &adapter->vf; - if (vf->msix_vector_status == MSIX_VECTOR_PER_VQ_AND_CONFIG) - ifcvf_free_per_vq_irq(adapter); + ifcvf_free_per_vq_irq(vf); else - ifcvf_free_vqs_reused_irq(adapter); + ifcvf_free_vqs_reused_irq(vf); } static void ifcvf_free_config_irq(struct ifcvf_adapter *adapter) @@ -126,8 +122,9 @@ static void ifcvf_free_config_irq(struct ifcvf_adapter *adapter) static void ifcvf_free_irq(struct ifcvf_adapter *adapter) { struct pci_dev *pdev = adapter->pdev; + struct ifcvf_hw *vf = &adapter->vf; - ifcvf_free_vq_irq(adapter); + ifcvf_free_vq_irq(vf); ifcvf_free_config_irq(adapter); ifcvf_free_irq_vectors(pdev); } From patchwork Fri Nov 25 14:57:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 13056042 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 47B20C43217 for ; Fri, 25 Nov 2022 15:06:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230007AbiKYPGi (ORCPT ); Fri, 25 Nov 2022 10:06:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230203AbiKYPGg (ORCPT ); Fri, 25 Nov 2022 10:06:36 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FC413D928; Fri, 25 Nov 2022 07:06:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669388796; x=1700924796; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lNFpEw8fOUanfxMRuET0eEJRiZaA7AVu47NX0D5CI2k=; b=lo7GVBtoCOCw8Am0s8dbsV7U0YfGoGF5beXTIrLPOXWYngtvubKi5X40 KHU5zBNNP5AHpMRQI2NdcbROT+haWFfHA33faur7tEqZyU0WAq+nbSGVY n7fip5SA1IryLEtQGX/HjPYtTStJrPAJ1Xnl0Oqpb/Xr8Cx1unE9exrw6 l0BCNSmXznMgi/TiPy2i7PhPr+DL8HxB1PfXNqaZe7CmetCKV7QWdHJuQ kmVVJoRPGh4xE6m9Rfrj27XxQ6YuaohZF32EBK8c9nCWxFw3shy2bTZIz jiMZ29hf/AwdpMV7zvQDc/70s7Um0wjNRef+zLLGnIanUjFpBjfvKkhIW w==; X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="294881008" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="294881008" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:36 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="593240258" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="593240258" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:32 -0800 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, hang.yuan@intel.com, piotr.uminski@intel.com, Zhu Lingshan , stable@vger.kernel.org Subject: [PATCH V2 05/12] vDPA/ifcvf: decouple config IRQ releaser from the adapter Date: Fri, 25 Nov 2022 22:57:17 +0800 Message-Id: <20221125145724.1129962-6-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221125145724.1129962-1-lingshan.zhu@intel.com> References: <20221125145724.1129962-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This commit decouples config IRQ releaser from the adapter, so that it could be invoked once probe or in err handlers. ifcvf_free_irq() works on ifcvf_hw in this commit Signed-off-by: Zhu Lingshan Cc: stable@vger.kernel.org --- drivers/vdpa/ifcvf/ifcvf_main.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index 7dac0285b71d..c635f78f5c4c 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -101,10 +101,9 @@ static void ifcvf_free_vq_irq(struct ifcvf_hw *vf) ifcvf_free_vqs_reused_irq(vf); } -static void ifcvf_free_config_irq(struct ifcvf_adapter *adapter) +static void ifcvf_free_config_irq(struct ifcvf_hw *vf) { - struct pci_dev *pdev = adapter->pdev; - struct ifcvf_hw *vf = &adapter->vf; + struct pci_dev *pdev = vf->pdev; if (vf->config_irq == -EINVAL) return; @@ -119,13 +118,12 @@ static void ifcvf_free_config_irq(struct ifcvf_adapter *adapter) } } -static void ifcvf_free_irq(struct ifcvf_adapter *adapter) +static void ifcvf_free_irq(struct ifcvf_hw *vf) { - struct pci_dev *pdev = adapter->pdev; - struct ifcvf_hw *vf = &adapter->vf; + struct pci_dev *pdev = vf->pdev; ifcvf_free_vq_irq(vf); - ifcvf_free_config_irq(adapter); + ifcvf_free_config_irq(vf); ifcvf_free_irq_vectors(pdev); } @@ -187,7 +185,7 @@ static int ifcvf_request_per_vq_irq(struct ifcvf_adapter *adapter) return 0; err: - ifcvf_free_irq(adapter); + ifcvf_free_irq(vf); return -EFAULT; } @@ -221,7 +219,7 @@ static int ifcvf_request_vqs_reused_irq(struct ifcvf_adapter *adapter) return 0; err: - ifcvf_free_irq(adapter); + ifcvf_free_irq(vf); return -EFAULT; } @@ -262,7 +260,7 @@ static int ifcvf_request_dev_irq(struct ifcvf_adapter *adapter) return 0; err: - ifcvf_free_irq(adapter); + ifcvf_free_irq(vf); return -EFAULT; @@ -317,7 +315,7 @@ static int ifcvf_request_config_irq(struct ifcvf_adapter *adapter) return 0; err: - ifcvf_free_irq(adapter); + ifcvf_free_irq(vf); return -EFAULT; } @@ -508,7 +506,7 @@ static int ifcvf_vdpa_reset(struct vdpa_device *vdpa_dev) if (status_old & VIRTIO_CONFIG_S_DRIVER_OK) { ifcvf_stop_datapath(adapter); - ifcvf_free_irq(adapter); + ifcvf_free_irq(vf); } ifcvf_reset_vring(adapter); From patchwork Fri Nov 25 14:57:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 13056043 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 0AA05C43219 for ; Fri, 25 Nov 2022 15:06:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230221AbiKYPGm (ORCPT ); Fri, 25 Nov 2022 10:06:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230226AbiKYPGk (ORCPT ); Fri, 25 Nov 2022 10:06:40 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C19B63D902; Fri, 25 Nov 2022 07:06:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669388798; x=1700924798; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zqB4VxUbSoa1/R9X/q+uEbSpkhAAKXG6Dh8P3V04QaE=; b=PmMGVOGB175mpQSOg7tZ39oTyX78K6NpXozkpRKCM53+EVZTEQmvu3tj RAKTirOK4uGvgi8BILQ7UkpNwIUCeCsEncO+zKJOF5ytx+6PBk4iOCUxC qLlF2anuK2ZWzmhye9oYcgiINSojMzhqhvq4NXNd0ggjyJ/eOn4g7WEFN +ZXt9tGuKt1lsPqMNwevIVIooRAAMnYPC7I6fqMJFe2rAh3M1NFy5g7+l rIle/sm3Wz0Uw0f/wpq9ZQvuhJQwaVzoVQhrirDBVasnZh6M35vslCIqh cScp5PhhaZqBMqdWXY0bFj2g11BzX3ab94caP5Ucx0G01hIEN1BoJ6JQH g==; X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="294881018" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="294881018" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:38 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="593240265" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="593240265" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:36 -0800 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, hang.yuan@intel.com, piotr.uminski@intel.com, Zhu Lingshan , stable@vger.kernel.org Subject: [PATCH V2 06/12] vDPA/ifcvf: decouple vq irq requester from the adapter Date: Fri, 25 Nov 2022 22:57:18 +0800 Message-Id: <20221125145724.1129962-7-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221125145724.1129962-1-lingshan.zhu@intel.com> References: <20221125145724.1129962-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This commit decouples the vq irq requester from the adapter, so that these functions can be invoked since probe. Signed-off-by: Zhu Lingshan Cc: stable@vger.kernel.org --- drivers/vdpa/ifcvf/ifcvf_main.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index c635f78f5c4c..ee9c22975119 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -155,10 +155,9 @@ static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) return ret; } -static int ifcvf_request_per_vq_irq(struct ifcvf_adapter *adapter) +static int ifcvf_request_per_vq_irq(struct ifcvf_hw *vf) { - struct pci_dev *pdev = adapter->pdev; - struct ifcvf_hw *vf = &adapter->vf; + struct pci_dev *pdev = vf->pdev; int i, vector, ret, irq; vf->vqs_reused_irq = -EINVAL; @@ -190,10 +189,9 @@ static int ifcvf_request_per_vq_irq(struct ifcvf_adapter *adapter) return -EFAULT; } -static int ifcvf_request_vqs_reused_irq(struct ifcvf_adapter *adapter) +static int ifcvf_request_vqs_reused_irq(struct ifcvf_hw *vf) { - struct pci_dev *pdev = adapter->pdev; - struct ifcvf_hw *vf = &adapter->vf; + struct pci_dev *pdev = vf->pdev; int i, vector, ret, irq; vector = 0; @@ -266,15 +264,14 @@ static int ifcvf_request_dev_irq(struct ifcvf_adapter *adapter) } -static int ifcvf_request_vq_irq(struct ifcvf_adapter *adapter) +static int ifcvf_request_vq_irq(struct ifcvf_hw *vf) { - struct ifcvf_hw *vf = &adapter->vf; int ret; if (vf->msix_vector_status == MSIX_VECTOR_PER_VQ_AND_CONFIG) - ret = ifcvf_request_per_vq_irq(adapter); + ret = ifcvf_request_per_vq_irq(vf); else - ret = ifcvf_request_vqs_reused_irq(adapter); + ret = ifcvf_request_vqs_reused_irq(vf); return ret; } @@ -341,7 +338,7 @@ static int ifcvf_request_irq(struct ifcvf_adapter *adapter) return ret; } - ret = ifcvf_request_vq_irq(adapter); + ret = ifcvf_request_vq_irq(vf); if (ret) return ret; From patchwork Fri Nov 25 14:57:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 13056044 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 8075CC46467 for ; Fri, 25 Nov 2022 15:06:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230203AbiKYPGq (ORCPT ); Fri, 25 Nov 2022 10:06:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230227AbiKYPGn (ORCPT ); Fri, 25 Nov 2022 10:06:43 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A57102DA92; Fri, 25 Nov 2022 07:06:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669388801; x=1700924801; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lRb74Ed4w5JOXpI/O/j8nJXYHPcznwfk4WiJ395xlf8=; b=Kum0WM8T6nGfGp57UqNYDr78n3lszXN0TPQFEuuhljQCBtnln2ntl1t6 EgclUiXBg7n7gWO0A1DZWvDP6kujPrMe2BXLYrP5e49jIpZjhH9GNQ19H ZjuXDJtuCsRimsXkUC2ZmbxCd0pXzM9/Mj7hw01SbdPMJrgAa/5RXbCHu E9oSOzMWL5SVCfeA1VKeFTdN47KCM0j9fuojge2ZITyV6YCsbzKT6N4Gx lgvJ0kRKqCtZJT06MVvnyxpk0XU9fV7Q3g8ytRIXwgVmPGEF9F+Fnbi8v HQd2UK84WOgfHF7KQ9o/YD+mlyCy2MQPOYxDwXa85w9MUnA8HFX9oPMp7 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="294881026" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="294881026" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:41 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="593240281" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="593240281" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:38 -0800 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, hang.yuan@intel.com, piotr.uminski@intel.com, Zhu Lingshan , stable@vger.kernel.org Subject: [PATCH V2 07/12] vDPA/ifcvf: decouple config/dev IRQ requester and vectors allocator from the adapter Date: Fri, 25 Nov 2022 22:57:19 +0800 Message-Id: <20221125145724.1129962-8-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221125145724.1129962-1-lingshan.zhu@intel.com> References: <20221125145724.1129962-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This commit decouples the config irq requester, the device shared irq requester and the MSI vectors allocator from the adapter. So they can be safely invoked since probe before the adapter is allocated. Signed-off-by: Zhu Lingshan Cc: stable@vger.kernel.org --- drivers/vdpa/ifcvf/ifcvf_main.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index ee9c22975119..8320bdacace8 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -132,10 +132,9 @@ static void ifcvf_free_irq(struct ifcvf_hw *vf) * It returns the number of allocated vectors, negative * return value when fails. */ -static int ifcvf_alloc_vectors(struct ifcvf_adapter *adapter) +static int ifcvf_alloc_vectors(struct ifcvf_hw *vf) { - struct pci_dev *pdev = adapter->pdev; - struct ifcvf_hw *vf = &adapter->vf; + struct pci_dev *pdev = vf->pdev; int max_intr, ret; /* all queues and config interrupt */ @@ -222,10 +221,9 @@ static int ifcvf_request_vqs_reused_irq(struct ifcvf_hw *vf) return -EFAULT; } -static int ifcvf_request_dev_irq(struct ifcvf_adapter *adapter) +static int ifcvf_request_dev_irq(struct ifcvf_hw *vf) { - struct pci_dev *pdev = adapter->pdev; - struct ifcvf_hw *vf = &adapter->vf; + struct pci_dev *pdev = vf->pdev; int i, vector, ret, irq; vector = 0; @@ -276,10 +274,9 @@ static int ifcvf_request_vq_irq(struct ifcvf_hw *vf) return ret; } -static int ifcvf_request_config_irq(struct ifcvf_adapter *adapter) +static int ifcvf_request_config_irq(struct ifcvf_hw *vf) { - struct pci_dev *pdev = adapter->pdev; - struct ifcvf_hw *vf = &adapter->vf; + struct pci_dev *pdev = vf->pdev; int config_vector, ret; if (vf->msix_vector_status == MSIX_VECTOR_PER_VQ_AND_CONFIG) @@ -322,7 +319,7 @@ static int ifcvf_request_irq(struct ifcvf_adapter *adapter) struct ifcvf_hw *vf = &adapter->vf; int nvectors, ret, max_intr; - nvectors = ifcvf_alloc_vectors(adapter); + nvectors = ifcvf_alloc_vectors(vf); if (nvectors <= 0) return -EFAULT; @@ -333,7 +330,7 @@ static int ifcvf_request_irq(struct ifcvf_adapter *adapter) if (nvectors == 1) { vf->msix_vector_status = MSIX_VECTOR_DEV_SHARED; - ret = ifcvf_request_dev_irq(adapter); + ret = ifcvf_request_dev_irq(vf); return ret; } @@ -342,7 +339,7 @@ static int ifcvf_request_irq(struct ifcvf_adapter *adapter) if (ret) return ret; - ret = ifcvf_request_config_irq(adapter); + ret = ifcvf_request_config_irq(vf); if (ret) return ret; From patchwork Fri Nov 25 14:57:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 13056045 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 3AA82C43217 for ; Fri, 25 Nov 2022 15:06:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230292AbiKYPGt (ORCPT ); Fri, 25 Nov 2022 10:06:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230226AbiKYPGo (ORCPT ); Fri, 25 Nov 2022 10:06:44 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4F6A429A3; Fri, 25 Nov 2022 07:06:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669388803; x=1700924803; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sc7yv6l7w+mdzUT7XAZNvCklCr0OubkKRD1No7y/EJw=; b=CwbWYN700bMLz9hiFeOYaSKqPAak5YM7mm2F0+u+NlwyGaNme2NwvGGz Vrr5uGPzkSxQhEtLG+ti+/TkY7pWUAJ6Lfqb+rurL2hjAKsSblUr5QvC5 AHgEvw0+00yQGXJKQrDBsnii7bS4ceS+Q/XlfkazWRMtKQifHRcugvOjB 0gQh3snOuQamBkFkLhGTwJNcQqHR3F3hHdzsGUj4YCWzl8YZcT5NNdudj KfElkPCoDN0L6r7vAkZt9gN0kKxfF2qu+no26wnw68iv7emiB1Wxp/x6n r4jL8oYElExjJJ15J3BRXTlhUOviWepKmDkICPJFs927ieEE5uq9J4gke A==; X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="294881040" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="294881040" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:43 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="593240289" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="593240289" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:41 -0800 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, hang.yuan@intel.com, piotr.uminski@intel.com, Zhu Lingshan , stable@vger.kernel.org Subject: [PATCH V2 08/12] vDPA/ifcvf: ifcvf_request_irq works on ifcvf_hw Date: Fri, 25 Nov 2022 22:57:20 +0800 Message-Id: <20221125145724.1129962-9-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221125145724.1129962-1-lingshan.zhu@intel.com> References: <20221125145724.1129962-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org All ifcvf_request_irq's callees are refactored to work on ifcvf_hw, so it should be decoupled from the adapter as well Signed-off-by: Zhu Lingshan Cc: stable@vger.kernel.org --- drivers/vdpa/ifcvf/ifcvf_main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index 8320bdacace8..cb3df395d3fb 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -314,9 +314,8 @@ static int ifcvf_request_config_irq(struct ifcvf_hw *vf) return -EFAULT; } -static int ifcvf_request_irq(struct ifcvf_adapter *adapter) +static int ifcvf_request_irq(struct ifcvf_hw *vf) { - struct ifcvf_hw *vf = &adapter->vf; int nvectors, ret, max_intr; nvectors = ifcvf_alloc_vectors(vf); @@ -468,7 +467,7 @@ static void ifcvf_vdpa_set_status(struct vdpa_device *vdpa_dev, u8 status) if ((status & VIRTIO_CONFIG_S_DRIVER_OK) && !(status_old & VIRTIO_CONFIG_S_DRIVER_OK)) { - ret = ifcvf_request_irq(adapter); + ret = ifcvf_request_irq(vf); if (ret) { status = ifcvf_get_status(vf); status |= VIRTIO_CONFIG_S_FAILED; From patchwork Fri Nov 25 14:57:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 13056046 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 9325AC43217 for ; Fri, 25 Nov 2022 15:07:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230258AbiKYPHA (ORCPT ); Fri, 25 Nov 2022 10:07:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230264AbiKYPGs (ORCPT ); Fri, 25 Nov 2022 10:06:48 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB2294219C; Fri, 25 Nov 2022 07:06:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669388806; x=1700924806; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tGKyZdK+/g+LspCoOlXFm4pHY90Rxp2oIWc2gtPMg2Y=; b=oF9LM0vGuP9PO2VmagPkN1tlczoCnxSLPoFd2L8KwZtKF+M4mu5Xwxkb n5xIWxRlwljyAsephcmPsvEFuCJBbyy64n+I6NF+BJI+w8vP9pUtDwVr+ PYPooyD7qW6WA+/3sVs0zQqxuOySzrO48JKnVD7OlFnKYR9PS1me4li71 KUtQpkAYbg1aJMnuo7TwU3snN4synFzVvCxtH8+6kbClVGwXYWOzFUTcx 72kCNOzjkEHNqSNSbHg+xQW7817rjQmFJy3l8xHuvUJHf2MQ9KR1FKzqd liLv4CL43ct1AmYFBfrXynCCBLQmbuEyQf71LMHsv9fG+hdi7p5leg/kw g==; X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="294881049" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="294881049" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:46 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="593240292" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="593240292" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:43 -0800 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, hang.yuan@intel.com, piotr.uminski@intel.com, Zhu Lingshan , stable@vger.kernel.org Subject: [PATCH V2 09/12] vDPA/ifcvf: manage ifcvf_hw in the mgmt_dev Date: Fri, 25 Nov 2022 22:57:21 +0800 Message-Id: <20221125145724.1129962-10-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221125145724.1129962-1-lingshan.zhu@intel.com> References: <20221125145724.1129962-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This commit allocates the hw structure in the management device structure. So the hardware can be initialized once the management device is allocated in probe. Signed-off-by: Zhu Lingshan Cc: stable@vger.kernel.org --- drivers/vdpa/ifcvf/ifcvf_base.h | 5 +++-- drivers/vdpa/ifcvf/ifcvf_main.c | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_base.h b/drivers/vdpa/ifcvf/ifcvf_base.h index e1fe947d61b7..25bd4e927b27 100644 --- a/drivers/vdpa/ifcvf/ifcvf_base.h +++ b/drivers/vdpa/ifcvf/ifcvf_base.h @@ -39,7 +39,7 @@ #define IFCVF_INFO(pdev, fmt, ...) dev_info(&pdev->dev, fmt, ##__VA_ARGS__) #define ifcvf_private_to_vf(adapter) \ - (&((struct ifcvf_adapter *)adapter)->vf) + (((struct ifcvf_adapter *)adapter)->vf) /* all vqs and config interrupt has its own vector */ #define MSIX_VECTOR_PER_VQ_AND_CONFIG 1 @@ -95,7 +95,7 @@ struct ifcvf_hw { struct ifcvf_adapter { struct vdpa_device vdpa; struct pci_dev *pdev; - struct ifcvf_hw vf; + struct ifcvf_hw *vf; }; struct ifcvf_vring_lm_cfg { @@ -110,6 +110,7 @@ struct ifcvf_lm_cfg { struct ifcvf_vdpa_mgmt_dev { struct vdpa_mgmt_dev mdev; + struct ifcvf_hw vf; struct ifcvf_adapter *adapter; struct pci_dev *pdev; }; diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index cb3df395d3fb..b6f5f7a3a767 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -402,7 +402,7 @@ static struct ifcvf_hw *vdpa_to_vf(struct vdpa_device *vdpa_dev) { struct ifcvf_adapter *adapter = vdpa_to_adapter(vdpa_dev); - return &adapter->vf; + return adapter->vf; } static u64 ifcvf_vdpa_get_device_features(struct vdpa_device *vdpa_dev) @@ -750,7 +750,7 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name, return -EOPNOTSUPP; adapter = ifcvf_mgmt_dev->adapter; - vf = &adapter->vf; + vf = adapter->vf; pdev = adapter->pdev; vdpa_dev = &adapter->vdpa; @@ -838,10 +838,11 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) adapter->vdpa.mdev = &ifcvf_mgmt_dev->mdev; ifcvf_mgmt_dev->adapter = adapter; - vf = &adapter->vf; + vf = &ifcvf_mgmt_dev->vf; vf->dev_type = get_dev_type(pdev); vf->base = pcim_iomap_table(pdev); vf->pdev = pdev; + adapter->vf = vf; ret = ifcvf_init_hw(vf, pdev); if (ret) { From patchwork Fri Nov 25 14:57:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 13056049 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 1AF45C43219 for ; Fri, 25 Nov 2022 15:08:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229599AbiKYPIw (ORCPT ); Fri, 25 Nov 2022 10:08:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230254AbiKYPGv (ORCPT ); Fri, 25 Nov 2022 10:06:51 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B97627CFB; Fri, 25 Nov 2022 07:06:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669388809; x=1700924809; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Xejal7SbyM3CZJX6CDhwfTq2ZC4W7X99THWP2G/YoKU=; b=WuVyL8k+/aieG1/YrTeAqhUKpwgKREyB1mxelzm+kgb1Ej8dgIjoMIYj 2DRMtl0cIlEj8z5w6oh32zZQjp/lPSUtjC23vj6gEMejvfhM2scKK5oH1 mS3ecX5YNog7EniEhYna/lUnCTKFao+Zm8p19FX7RhOy3ZrRTauHoscvb o+V5guML9cguZe9o0NOTF3IOsDi5xe85HNkccWR03iAalL0g/a4wOYV/d io/qFvt450b+z114yYsOMebb/J2YlQta2sjw8ueceOZpwpi8AfDHNTntR 9IFLbEgs/57/H86ZhYsjS9funHg+8Ok/8lVHDWpkcsDo2JqDJxbj/Bmik A==; X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="294881059" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="294881059" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:49 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="593240298" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="593240298" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:46 -0800 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, hang.yuan@intel.com, piotr.uminski@intel.com, Zhu Lingshan , stable@vger.kernel.org Subject: [PATCH V2 10/12] vDPA/ifcvf: allocate the adapter in dev_add() Date: Fri, 25 Nov 2022 22:57:22 +0800 Message-Id: <20221125145724.1129962-11-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221125145724.1129962-1-lingshan.zhu@intel.com> References: <20221125145724.1129962-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The adapter is the container of the vdpa_device, this commits allocate the adapter in dev_add() rather than in probe(). So that the vdpa_device() could be re-created when the userspace creates the vdpa device, and free-ed in dev_del() Signed-off-by: Zhu Lingshan Cc: stable@vger.kernel.org --- drivers/vdpa/ifcvf/ifcvf_main.c | 34 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index b6f5f7a3a767..4450ddb53806 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -746,12 +746,20 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name, int ret; ifcvf_mgmt_dev = container_of(mdev, struct ifcvf_vdpa_mgmt_dev, mdev); - if (!ifcvf_mgmt_dev->adapter) - return -EOPNOTSUPP; + vf = &ifcvf_mgmt_dev->vf; + pdev = vf->pdev; + adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa, + &pdev->dev, &ifc_vdpa_ops, 1, 1, NULL, false); + if (IS_ERR(adapter)) { + IFCVF_ERR(pdev, "Failed to allocate vDPA structure"); + return PTR_ERR(adapter); + } - adapter = ifcvf_mgmt_dev->adapter; - vf = adapter->vf; - pdev = adapter->pdev; + ifcvf_mgmt_dev->adapter = adapter; + adapter->pdev = pdev; + adapter->vdpa.dma_dev = &pdev->dev; + adapter->vdpa.mdev = mdev; + adapter->vf = vf; vdpa_dev = &adapter->vdpa; if (name) @@ -769,7 +777,6 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name, return 0; } - static void ifcvf_vdpa_dev_del(struct vdpa_mgmt_dev *mdev, struct vdpa_device *dev) { struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; @@ -788,7 +795,6 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) { struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; struct device *dev = &pdev->dev; - struct ifcvf_adapter *adapter; struct ifcvf_hw *vf; u32 dev_type; int ret, i; @@ -825,24 +831,10 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) return -ENOMEM; } - adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa, - dev, &ifc_vdpa_ops, 1, 1, NULL, false); - if (IS_ERR(adapter)) { - IFCVF_ERR(pdev, "Failed to allocate vDPA structure"); - ret = PTR_ERR(adapter); - goto err; - } - - adapter->pdev = pdev; - adapter->vdpa.dma_dev = &pdev->dev; - adapter->vdpa.mdev = &ifcvf_mgmt_dev->mdev; - ifcvf_mgmt_dev->adapter = adapter; - vf = &ifcvf_mgmt_dev->vf; vf->dev_type = get_dev_type(pdev); vf->base = pcim_iomap_table(pdev); vf->pdev = pdev; - adapter->vf = vf; ret = ifcvf_init_hw(vf, pdev); if (ret) { From patchwork Fri Nov 25 14:57:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 13056047 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 EB3D7C4167B for ; Fri, 25 Nov 2022 15:07:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230299AbiKYPHB (ORCPT ); Fri, 25 Nov 2022 10:07:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230307AbiKYPGx (ORCPT ); Fri, 25 Nov 2022 10:06:53 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97C09429B6 for ; Fri, 25 Nov 2022 07:06:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669388811; x=1700924811; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=K6MLOac5x03nQbMI3Jm3nrQy7Pwz2Jj+yd6eNvVvvJY=; b=Eqb8D/d/dCKORuoXxyc401J1fDdMte7uCVKaJZ5UaYgDElLXN8akFGF9 /2JaxRogKIcjS1otgyfDF6EAmrlWfDx/qFCydtVuyZThg+TnY91IdYSLX tMp2VIIFPrkFg/rsWDr/5VqxIuq2JTpQIUqZueAvBwF1ZkXBmnzIRWVbW n7PcpQojcIT9a7rBNYtSZ04Bf9x2rzEVIXbr/uFvU2OLTpIwL/ixovO3b h1PdBU9/SBcqdJ4uY8dNTJuDRss16i9jVH/8Wg2BjBqThBXjU0L2MCT24 93gjNBMHorpWsFNefV9wLfg1XRCjxaLvj4JIdWIiqGlNV3XmkayD3F9pj A==; X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="294881066" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="294881066" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:51 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="593240303" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="593240303" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:49 -0800 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, hang.yuan@intel.com, piotr.uminski@intel.com, Zhu Lingshan Subject: [PATCH V2 11/12] vDPA/ifcvf: retire ifcvf_private_to_vf Date: Fri, 25 Nov 2022 22:57:23 +0800 Message-Id: <20221125145724.1129962-12-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221125145724.1129962-1-lingshan.zhu@intel.com> References: <20221125145724.1129962-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This commit retires ifcvf_private_to_vf, because the vf is already a member of the adapter, so it could be easily addressed by adapter->vf. Signed-off-by: Zhu Lingshan --- drivers/vdpa/ifcvf/ifcvf_base.h | 3 --- drivers/vdpa/ifcvf/ifcvf_main.c | 10 +++++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_base.h b/drivers/vdpa/ifcvf/ifcvf_base.h index 25bd4e927b27..d41e255c581b 100644 --- a/drivers/vdpa/ifcvf/ifcvf_base.h +++ b/drivers/vdpa/ifcvf/ifcvf_base.h @@ -38,9 +38,6 @@ #define IFCVF_DBG(pdev, fmt, ...) dev_dbg(&pdev->dev, fmt, ##__VA_ARGS__) #define IFCVF_INFO(pdev, fmt, ...) dev_info(&pdev->dev, fmt, ##__VA_ARGS__) -#define ifcvf_private_to_vf(adapter) \ - (((struct ifcvf_adapter *)adapter)->vf) - /* all vqs and config interrupt has its own vector */ #define MSIX_VECTOR_PER_VQ_AND_CONFIG 1 /* all vqs share a vector, and config interrupt has a separate vector */ diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index 4450ddb53806..5fb3580594d5 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -346,9 +346,9 @@ static int ifcvf_request_irq(struct ifcvf_hw *vf) return 0; } -static int ifcvf_start_datapath(void *private) +static int ifcvf_start_datapath(struct ifcvf_adapter *adapter) { - struct ifcvf_hw *vf = ifcvf_private_to_vf(private); + struct ifcvf_hw *vf = adapter->vf; u8 status; int ret; @@ -362,9 +362,9 @@ static int ifcvf_start_datapath(void *private) return ret; } -static int ifcvf_stop_datapath(void *private) +static int ifcvf_stop_datapath(struct ifcvf_adapter *adapter) { - struct ifcvf_hw *vf = ifcvf_private_to_vf(private); + struct ifcvf_hw *vf = adapter->vf; int i; for (i = 0; i < vf->nr_vring; i++) @@ -377,7 +377,7 @@ static int ifcvf_stop_datapath(void *private) static void ifcvf_reset_vring(struct ifcvf_adapter *adapter) { - struct ifcvf_hw *vf = ifcvf_private_to_vf(adapter); + struct ifcvf_hw *vf = adapter->vf; int i; for (i = 0; i < vf->nr_vring; i++) { From patchwork Fri Nov 25 14:57:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 13056048 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 633A3C4332F for ; Fri, 25 Nov 2022 15:07:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230226AbiKYPHP (ORCPT ); Fri, 25 Nov 2022 10:07:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230271AbiKYPHM (ORCPT ); Fri, 25 Nov 2022 10:07:12 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF4FB31DC6 for ; Fri, 25 Nov 2022 07:07:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669388830; x=1700924830; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L7+kRJxim+tXndxTiW57BfxqYjmCXRG7PwELl1gNbb4=; b=bu4W9MtPzisblU0b3H98lrzU/xo4ZLslvXRRTMyjUPtkJJU1zkSGAgty xTgu3ZX5Hlmzeor13n7e+0kZJdkNofIpPJsmBBh28jfZjeZB9QX4yA121 mrNZFlPy1PKgLLxhtWcv3FY8pLAIjMXV7MIJssGnCZPNFK1eWsKDtUN3j X7sGobQHmciP2CEPWrb3bovUo5Y+C3UOQLWZPlEmo1iXqZ/4rw42qxQiq y6Xj2lbv8rHikxjOT0ez0D+bAekb7nXNZtrkIS/TnrEHziAY9a9vYayVy ApWSK6K+gnB2yjXG3UEfVcJoy6OTrhwVV7yoHd5J4DhT9O90QpgvhJRKm g==; X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="294881077" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="294881077" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:53 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10542"; a="593240306" X-IronPort-AV: E=Sophos;i="5.96,193,1665471600"; d="scan'208";a="593240306" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.193.73]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2022 07:06:51 -0800 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, hang.yuan@intel.com, piotr.uminski@intel.com, Zhu Lingshan Subject: [PATCH V2 12/12] vDPA/ifcvf: implement features provisioning Date: Fri, 25 Nov 2022 22:57:24 +0800 Message-Id: <20221125145724.1129962-13-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221125145724.1129962-1-lingshan.zhu@intel.com> References: <20221125145724.1129962-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This commit implements features provisioning for ifcvf, that means: 1)checkk whether the provisioned features are supported by the management device 2)vDPA device only presents selected feature bits Examples: a)The management device supported features: $ vdpa mgmtdev show pci/0000:01:00.5 pci/0000:01:00.5: supported_classes net max_supported_vqs 9 dev_features MTU MAC MRG_RXBUF CTRL_VQ MQ ANY_LAYOUT VERSION_1 ACCESS_PLATFORM b)Provision a vDPA device with all supported features: $ vdpa dev add name vdpa0 mgmtdev pci/0000:01:00.5 $ vdpa/vdpa dev config show vdpa0 vdpa0: mac 00:e8:ca:11:be:05 link up link_announce false max_vq_pairs 4 mtu 1500 negotiated_features MRG_RXBUF CTRL_VQ MQ VERSION_1 ACCESS_PLATFORM c)Provision a vDPA device with a subset of the supported features: $ vdpa dev add name vdpa0 mgmtdev pci/0000:01:00.5 device_features 0x300020020 $ vdpa dev config show vdpa0 mac 00:e8:ca:11:be:05 link up link_announce false negotiated_features CTRL_VQ VERSION_1 ACCESS_PLATFORM Signed-off-by: Zhu Lingshan --- drivers/vdpa/ifcvf/ifcvf_base.c | 2 +- drivers/vdpa/ifcvf/ifcvf_base.h | 3 +++ drivers/vdpa/ifcvf/ifcvf_main.c | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_base.c b/drivers/vdpa/ifcvf/ifcvf_base.c index 3ec5ca3aefe1..5563b3a773c7 100644 --- a/drivers/vdpa/ifcvf/ifcvf_base.c +++ b/drivers/vdpa/ifcvf/ifcvf_base.c @@ -206,7 +206,7 @@ u64 ifcvf_get_hw_features(struct ifcvf_hw *hw) u64 ifcvf_get_features(struct ifcvf_hw *hw) { - return hw->hw_features; + return hw->dev_features; } int ifcvf_verify_min_features(struct ifcvf_hw *hw, u64 features) diff --git a/drivers/vdpa/ifcvf/ifcvf_base.h b/drivers/vdpa/ifcvf/ifcvf_base.h index d41e255c581b..c20d1c40214e 100644 --- a/drivers/vdpa/ifcvf/ifcvf_base.h +++ b/drivers/vdpa/ifcvf/ifcvf_base.h @@ -19,6 +19,7 @@ #include #include #include +#include #define N3000_DEVICE_ID 0x1041 #define N3000_SUBSYS_DEVICE_ID 0x001A @@ -75,6 +76,8 @@ struct ifcvf_hw { u32 dev_type; u64 req_features; u64 hw_features; + /* provisioned device features */ + u64 dev_features; struct virtio_pci_common_cfg __iomem *common_cfg; void __iomem *dev_cfg; struct vring_info vring[IFCVF_MAX_QUEUES]; diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index 5fb3580594d5..cc826bfd3866 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -743,6 +743,7 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name, struct vdpa_device *vdpa_dev; struct pci_dev *pdev; struct ifcvf_hw *vf; + u64 device_features; int ret; ifcvf_mgmt_dev = container_of(mdev, struct ifcvf_vdpa_mgmt_dev, mdev); @@ -762,6 +763,17 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name, adapter->vf = vf; vdpa_dev = &adapter->vdpa; + device_features = vf->hw_features; + if (config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) { + if (config->device_features & ~device_features) { + IFCVF_ERR(pdev, "The provisioned features 0x%llx are not supported by this device with features 0x%llx\n", + config->device_features, device_features); + return -EINVAL; + } + device_features &= config->device_features; + } + vf->dev_features = device_features; + if (name) ret = dev_set_name(&vdpa_dev->dev, "%s", name); else @@ -866,6 +878,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) ifcvf_mgmt_dev->mdev.device = dev; ifcvf_mgmt_dev->mdev.max_supported_vqs = vf->nr_vring; ifcvf_mgmt_dev->mdev.supported_features = vf->hw_features; + ifcvf_mgmt_dev->mdev.config_attr_mask = (1 << VDPA_ATTR_DEV_FEATURES); ret = vdpa_mgmtdev_register(&ifcvf_mgmt_dev->mdev); if (ret) {