mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Angus Chen <angus.chen@jaguarmicro.com>
To: mst@redhat.com, jasowang@redhat.com
Cc: virtualization@lists.linux-foundation.org,
	linux-kernel@vger.kernel.org,
	Angus Chen <angus.chen@jaguarmicro.com>
Subject: [PATCH v2] vdpa/vp_vdpa: Check queue number of vdpa device from add_config
Date: Thu,  8 Jun 2023 17:01:24 +0800	[thread overview]
Message-ID: <20230608090124.1807-1-angus.chen@jaguarmicro.com> (raw)

When add virtio_pci vdpa device,check the vqs number of device cap
and max_vq_pairs from add_config.
Simply starting from failing if the provisioned #qp is not
equal to the one that hardware has.

Signed-off-by: Angus Chen <angus.chen@jaguarmicro.com>
---
v1: Use max_vqs from add_config
v2: Just return fail if max_vqs from add_config is not same as device
	cap. Suggested by jason.

 drivers/vdpa/virtio_pci/vp_vdpa.c | 35 ++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
index 281287fae89f..c1fb6963da12 100644
--- a/drivers/vdpa/virtio_pci/vp_vdpa.c
+++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
@@ -480,32 +480,39 @@ static int vp_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
 	u64 device_features;
 	int ret, i;
 
-	vp_vdpa = vdpa_alloc_device(struct vp_vdpa, vdpa,
-				    dev, &vp_vdpa_ops, 1, 1, name, false);
-
-	if (IS_ERR(vp_vdpa)) {
-		dev_err(dev, "vp_vdpa: Failed to allocate vDPA structure\n");
-		return PTR_ERR(vp_vdpa);
+	if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP)) {
+		if (add_config->net.max_vq_pairs != (v_mdev->max_supported_vqs / 2)) {
+			dev_err(&pdev->dev, "max vqs 0x%x should be equal to 0x%x which device has\n",
+				add_config->net.max_vq_pairs*2, v_mdev->max_supported_vqs);
+			return -EINVAL;
+		}
 	}
 
-	vp_vdpa_mgtdev->vp_vdpa = vp_vdpa;
-
-	vp_vdpa->vdpa.dma_dev = &pdev->dev;
-	vp_vdpa->queues = vp_modern_get_num_queues(mdev);
-	vp_vdpa->mdev = mdev;
-
 	device_features = vp_modern_get_features(mdev);
 	if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) {
 		if (add_config->device_features & ~device_features) {
-			ret = -EINVAL;
 			dev_err(&pdev->dev, "Try to provision features "
 				"that are not supported by the device: "
 				"device_features 0x%llx provisioned 0x%llx\n",
 				device_features, add_config->device_features);
-			goto err;
+			return -EINVAL;
 		}
 		device_features = add_config->device_features;
 	}
+
+	vp_vdpa = vdpa_alloc_device(struct vp_vdpa, vdpa,
+				    dev, &vp_vdpa_ops, 1, 1, name, false);
+
+	if (IS_ERR(vp_vdpa)) {
+		dev_err(dev, "vp_vdpa: Failed to allocate vDPA structure\n");
+		return PTR_ERR(vp_vdpa);
+	}
+
+	vp_vdpa_mgtdev->vp_vdpa = vp_vdpa;
+
+	vp_vdpa->vdpa.dma_dev = &pdev->dev;
+	vp_vdpa->queues = v_mdev->max_supported_vqs;
+	vp_vdpa->mdev = mdev;
 	vp_vdpa->device_features = device_features;
 
 	ret = devm_add_action_or_reset(dev, vp_vdpa_free_irq_vectors, pdev);
-- 
2.25.1


             reply	other threads:[~2023-06-08  9:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-08  9:01 Angus Chen [this message]
2023-06-08 19:44 ` Michael S. Tsirkin
2023-06-09  0:42   ` Angus Chen
2023-06-09 16:12     ` Michael S. Tsirkin
2023-06-09  2:30   ` Jason Wang
2023-06-26  2:30 ` Jason Wang
2023-06-26  2:42   ` Angus Chen
2023-06-26  2:51     ` Jason Wang
2023-06-26  3:02       ` Angus Chen
2023-06-26  3:08         ` Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230608090124.1807-1-angus.chen@jaguarmicro.com \
    --to=angus.chen@jaguarmicro.com \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®