From: Leon Romanovsky <leon@kernel.org>
To: Xiong Weimin <15927021679@163.com>
Cc: "Michael S . Tsirkin" <mst@redhat.com>,
"David Hildenbrand" <david@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Stefano Garzarella" <sgarzare@redhat.com>,
"Thomas Monjalon" <thomas@monjalon.net>,
"David Marchand" <david.marchand@redhat.com>,
"Luca Boccassi" <bluca@debian.org>,
"Kevin Traynor" <ktraynor@redhat.com>,
"Christian Ehrhardt" <christian.ehrhardt@canonical.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Xueming Li" <xuemingl@nvidia.com>,
"Maxime Coquelin" <maxime.coquelin@redhat.com>,
"Chenbo Xia" <chenbox@nvidia.com>,
"Bruce Richardson" <bruce.richardson@intel.com>,
kvm@vger.kernel.org, virtualization@lists.linux.dev,
netdev@vger.kernel.org, xiongweimin <xiongweimin@kylinos.cn>
Subject: Re: [PATCH 01/10] drivers/infiniband/hw/virtio: Initial driver for virtio RDMA devices
Date: Sun, 21 Dec 2025 11:11:54 +0200 [thread overview]
Message-ID: <20251221091154.GE13030@unreal> (raw)
In-Reply-To: <20251218091050.55047-2-15927021679@163.com>
On Thu, Dec 18, 2025 at 05:09:41PM +0800, Xiong Weimin wrote:
> From: xiongweimin <xiongweimin@kylinos.cn>
>
> This commit introduces a new driver for RDMA over virtio, enabling
> RDMA capabilities in virtualized environments. The driver consists
> of the following main components:
>
> 1. Driver registration with the virtio subsystem and device discovery.
> 2. Device probe and remove handlers for managing the device lifecycle.
> 3. Initialization of the InfiniBand device attributes by reading the
> virtio configuration space, including conversion from little-endian
> to CPU byte order and capability mapping.
> 4. Setup of virtqueues for:
> - Control commands (no callback)
> - Completion queues (with callback for CQ events)
> - Send and receive queues for queue pairs (no callbacks)
> 5. Integration with the network device layer for RoCE support.
> 6. Registration with the InfiniBand core subsystem.
> 7. Comprehensive error handling during initialization and a symmetric
> teardown process.
>
> Key features:
> - Support for multiple virtqueues based on device capabilities (max_cq, max_qp)
> - Fast doorbell optimization when notify_offset_multiplier equals PAGE_SIZE
> - Safe resource management with rollback on failure
>
> Signed-off-by: Xiong Weimin <xiongweimin@kylinos.cn>
<...>
> +/**
> + * vrdma_init_netdev - Attempt to find paired virtio-net device on same PCI slot
> + * @vrdev: The vRDMA device
> + *
> + * WARNING: This is a non-standard hack for development/emulation environments.
> + * Do not use in production or upstream drivers.
I'm impressed how much AI advanced in code generation. Please recheck
everything that was generated.
> + *
> + * Returns 0 on success, or negative errno.
> + */
> +int vrdma_init_netdev(struct vrdma_dev *vrdev)
> +{
> + struct pci_dev *pdev_net;
> + struct virtio_pci_device *vp_dev;
> + struct virtio_pci_device *vnet_pdev;
> + void *priv;
> + struct net_device *netdev;
> +
> + if (!vrdev || !vrdev->vdev) {
> + pr_err("%s: invalid vrdev or vdev\n", __func__);
> + return -EINVAL;
> + }
> +
> + vp_dev = to_vp_device(vrdev->vdev);
> +
> + /* Find the PCI device at function 0 of the same slot */
> + pdev_net = pci_get_slot(vp_dev->pci_dev->bus,
> + PCI_DEVFN(PCI_SLOT(vp_dev->pci_dev->devfn), 0));
> + if (!pdev_net) {
> + pr_err("Failed to find PCI device at fn=0 of slot %x\n",
> + PCI_SLOT(vp_dev->pci_dev->devfn));
> + return -ENODEV;
> + }
> +
> + /* Optional: Validate it's a known virtio-net device */
> + if (pdev_net->vendor != PCI_VENDOR_ID_REDHAT_QUMRANET ||
> + pdev_net->device != 0x1041) {
> + pr_warn("PCI device %04x:%04x is not expected virtio-net (1041) device\n",
> + pdev_net->vendor, pdev_net->device);
> + pci_dev_put(pdev_net);
> + return -ENODEV;
> + }
> +
> + /* Get the virtio_pci_device from drvdata */
> + vnet_pdev = pci_get_drvdata(pdev_net);
> + if (!vnet_pdev || !vnet_pdev->vdev.priv) {
> + pr_err("No driver data or priv for virtio-net device\n");
> + pci_dev_put(pdev_net);
> + return -ENODEV;
> + }
> +
> + priv = vnet_pdev->vdev.priv;
> + vrdev->netdev = priv - ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
> + netdev = vrdev->netdev;
> +
> + if (!netdev || !netdev->netdev_ops) {
> + pr_err("Invalid net_device retrieved from virtio-net\n");
> + pci_dev_put(pdev_net);
> + return -ENODEV;
> + }
> +
> + /* Hold reference so netdev won't disappear */
> + dev_hold(netdev);
> +
> + pci_dev_put(pdev_net); /* Release reference from pci_get_slot */
> +
> + return 0;
> +}
AI was right here. It is awful hack.
Thanks
next prev parent reply other threads:[~2025-12-21 9:12 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-18 9:09 Implement initial driver for virtio-RDMA device(kernel) Xiong Weimin
2025-12-18 9:09 ` [PATCH 01/10] drivers/infiniband/hw/virtio: Initial driver for virtio RDMA devices Xiong Weimin
2025-12-21 9:11 ` Leon Romanovsky [this message]
2025-12-18 9:09 ` [PATCH 02/10] drivers/infiniband/hw/virtio: add vrdma_exec_verbs_cmd to construct verbs sgs using virtio Xiong Weimin
2025-12-18 9:09 ` [PATCH 03/10] drivers/infiniband/hw/virtio: Implement core device and key resource management Xiong Weimin
2025-12-18 9:09 ` [PATCH 04/10] drivers/infiniband/hw/virtio: Implement MR, GID, ucontext and AH resource management verbs Xiong Weimin
2025-12-18 9:09 ` [PATCH 05/10] drivers/infiniband/hw/virtio: Implement memory mapping and MR scatter-gather support Xiong Weimin
2025-12-18 9:09 ` [PATCH 06/10] drivers/infiniband/hw/virtio: Implement port management and QP modification verbs Xiong Weimin
2025-12-18 9:09 ` [PATCH 07/10] drivers/infiniband/hw/virtio: Implement Completion Queue (CQ) polling support Xiong Weimin
2025-12-18 9:09 ` [PATCH 08/10] drivers/infiniband/hw/virtio: Implement send/receive verb support Xiong Weimin
2025-12-18 9:09 ` [PATCH 09/10] drivers/infiniband/hw/virtio: Implement P_key, QP query and user MR resource management verbs Xiong Weimin
2025-12-18 9:09 ` [PATCH 10/10] drivers/infiniband/hw/virtio: Add completion queue notification support Xiong Weimin
2025-12-18 16:30 ` Implement initial driver for virtio-RDMA device(kernel) Leon Romanovsky
2025-12-19 2:27 ` 熊伟民
[not found] ` <6ef11502.4847.19b34677a76.Coremail.15927021679@163.com>
2025-12-21 8:46 ` Leon Romanovsky
2025-12-23 1:16 ` Jason Wang
2025-12-24 9:31 ` 熊伟民
2025-12-25 2:13 ` 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=20251221091154.GE13030@unreal \
--to=leon@kernel.org \
--cc=15927021679@163.com \
--cc=bluca@debian.org \
--cc=bruce.richardson@intel.com \
--cc=chenbox@nvidia.com \
--cc=christian.ehrhardt@canonical.com \
--cc=david.marchand@redhat.com \
--cc=david@redhat.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=ktraynor@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=maxime.coquelin@redhat.com \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=sgarzare@redhat.com \
--cc=thomas@monjalon.net \
--cc=virtualization@lists.linux.dev \
--cc=xiongweimin@kylinos.cn \
--cc=xuanzhuo@linux.alibaba.com \
--cc=xuemingl@nvidia.com \
/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;
as well as URLs for NNTP newsgroup(s).