lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251221091154.GE13030@unreal>
Date: Sun, 21 Dec 2025 11:11:54 +0200
From: Leon Romanovsky <leon@...nel.org>
To: Xiong Weimin <15927021679@....com>
Cc: "Michael S . Tsirkin" <mst@...hat.com>,
	David Hildenbrand <david@...hat.com>,
	Jason Wang <jasowang@...hat.com>,
	Stefano Garzarella <sgarzare@...hat.com>,
	Thomas Monjalon <thomas@...jalon.net>,
	David Marchand <david.marchand@...hat.com>,
	Luca Boccassi <bluca@...ian.org>,
	Kevin Traynor <ktraynor@...hat.com>,
	Christian Ehrhardt <christian.ehrhardt@...onical.com>,
	Xuan Zhuo <xuanzhuo@...ux.alibaba.com>,
	Eugenio Pérez <eperezma@...hat.com>,
	Xueming Li <xuemingl@...dia.com>,
	Maxime Coquelin <maxime.coquelin@...hat.com>,
	Chenbo Xia <chenbox@...dia.com>,
	Bruce Richardson <bruce.richardson@...el.com>, kvm@...r.kernel.org,
	virtualization@...ts.linux.dev, netdev@...r.kernel.org,
	xiongweimin <xiongweimin@...inos.cn>
Subject: Re: [PATCH 01/10] drivers/infiniband/hw/virtio: Initial driver for
 virtio RDMA devices

On Thu, Dec 18, 2025 at 05:09:41PM +0800, Xiong Weimin wrote:
> From: xiongweimin <xiongweimin@...inos.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@...inos.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ