Virtual machine virtual network architecture, control method and data transmission method
By setting up the vhost-ebpf module and QEMU virtual machine in the host kernel space layer, the virtual network data flow path is simplified, solving the problems of high cost, poor performance, and poor flexibility of virtual network solutions, and achieving a more efficient, stable and flexible virtual network. performance.
Patent Information
- Application Number
- CN202410872380.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-01
- Publication Date
- 2024-10-18
AI Technical Summary
Existing virtual network solutions have problems such as high cost, poor performance, and poor flexibility, especially in data-intensive and real-time applications, which affects bandwidth, latency, and throughput performance.
The physical network card, network card driver, vhost-ebpf module and QEMU virtual machine are set up in the host kernel space layer, and data reception and transmission are realized through the ebpf program and poll module, simplifying the data flow path, avoiding physical network card exclusivity and context switching, and enhancing flexibility. .
It improves virtual network performance, shortens the data flow path, improves stability and flexibility, ensures efficient use of physical resources, and avoids the problem of physical network cards being monopolized.
Smart Images

Figure CN118802417A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of virtual network technology, and specifically provides a virtual machine virtual network architecture, a control method and a data transmission method. Background Art
[0002] Virtualized networks are widely used in data centers, cloud computing and other fields. Efficient virtual network performance directly affects application response speed and various aspects of user experience, including bandwidth, latency, throughput, packet loss rate, etc.
[0003] High bandwidth is very important for data-intensive applications (such as video streaming and file transfer) because it determines the speed and efficiency of data transmission. Low latency is critical for real-time applications (such as online games and video conferencing) because high latency will lead to longer response times and affect user experience. Packet loss will cause data retransmission and reduce overall network performance, which has a particularly large impact on real-time data transmission and high reliability applications (such as financial transactions and telemedicine). To improve the performance of virtual networks, the three main solutions currently used in the industry all have some problems: 1. passthrough Figure 1 : is a structural block diagram of the passthrough solution in the background technology of the present invention. Figure 1 As shown in the figure, the physical network card NIC uses the vfio driver passthrough to the virtual machine guest OS. The entire data flow path is short, and the bandwidth, throughput, and latency all have good performance. However, this technology will cause the physical network card to be exclusively occupied by the virtual machine, making it impossible to use physical resources reasonably and efficiently, and lacking flexibility. Although the physical network card PF is virtualized into multiple VFs for passthrough through SR-IOV network devices, the flexibility problem can be solved to a certain extent, but the cost is high.
[0004] 2. vhost-net Figure 2 It is a structural block diagram of the vhost-net solution in the background technology of the present invention. Figure 2 As shown in the figure, for the vhost-net solution, the virtual network of the virtual machine offloads data transmission and reception to the vhost-net module in the kernel space of the host machine, which is specifically proxied by the vhost worker thread. The data passes through the host network protocol stack and is then forwarded to the tap through vswith. The data enters the vring queue through the vhost-net module. The vhost-net and the virtio_net driver in the virtual machine notify each other through kvm, including interrupt injection; the data flow path of the vhost-net solution is very long, which affects the performance of throughput and latency, and is not robust enough. When system resources begin to become tight, it is also more susceptible to interference, which causes jitter.
[0005] 3. vhost-user Figure 3 It is a structural block diagram of the vhost-user solution in the background technology of the present invention. Figure 3 As shown in the figure, for the vhost-user solution, the virtual network of the virtual machine offloads data transmission and reception to the dpdk app in the user space, which is responsible for proxy forwarding the data of the virtio_net driver in the guest. The notification between the dpdk app and the virtio_net driver in the guest is still notified by the kvm, including interrupt injection. Although the vhost-user solution shortens the data flow path, it consumes more system resources. After the network card is bound to the dpdk app, the CPU usage rate will reach 100%. In addition, once the network card is bound to the dpdk app, it will not be visible to the traditional network subsystem of the host machine, and the flexibility is insufficient.
[0006] Accordingly, the art needs a new virtual network architecture solution to solve the above problems. Summary of the invention
[0007] In order to overcome the above defects, the present invention is proposed to solve the technical problems of high cost, poor performance and poor flexibility in the existing virtual network solutions.
[0008] In a first aspect, the present invention provides a virtual network architecture for a virtual machine, including a physical network card, a network card driver, a vhost-ebpf module, a first vring module, and a QEMU virtual machine arranged in a host kernel space layer, wherein the QEMU virtual machine includes a virtio_net device and a virtio_net_driver; The vhost-ebpf module includes the ebpf program and the first poll module. The ebpf program is used to receive data packets from the network card driver and write them into the first vring module; The first poll module is used to sense the data to be sent by the first vring module, read the data to be sent from the first vring module, and send it from the physical network card NIC through the network card driver; The virtio_net_driver includes a second vring module and a second poll module. The first vring module and the second vring module jointly implement a shared data queue between the QEMU virtual machine and the host machine, including a data receiving queue and a data sending queue; The second poll module is used to sense the data to be read in the second vring module; The virtio_net device is used to inform the vhost-ebpf module of the address information of the second vring module.
[0009] Furthermore, the ebpf program is also used to filter and forward the received and sent data.
[0010] Furthermore, the virtio_net_driver is set in the virtual machine operating system.
[0011] In a second aspect, the present invention provides a virtual network control method for a virtual machine, which is used in the virtual network architecture, comprising the steps of: The host kernel loads the vhost-ebpf module; The host kernel loads the vhost-ebpf module; The vhost-ebpf module detects the relevant interfaces of the network card driver, performs filtering processing on the data received from the network card driver, and writes the processed data into the first vring module; The QEMU virtual machine starts, simulates the virtio_net device, and configures the characteristic value for the virtio_net device; The virtio_net device and the virtio_net driver negotiate characteristic values through virito / pci; The virtio_net driver creates a second vring module based on the negotiated feature values; The virtio_net device informs the vhost-ebpf module about the address information of the second vring module.
[0012] Further, the virtio_net device informs the vhost-ebpf module of address information about the second vring module, including: The virtio_net device sends the memory layout information of the QEMU virtual machine to the vhost-ebpf module through the ioctl / vhost protocol; The vhost-ebpf module obtains address information of the second vring module from the memory layout information.
[0013] In a third aspect, the present invention provides a virtual machine virtual network data transmission method, which is used in the virtual network architecture, including a virtual machine receiving data process, wherein the virtual machine receiving data process includes the steps of: The vhost-ebpf module receives data packets from the network card driver through the ebpf program, filters the data packets and writes the data into the first vring module; The virtio_net driver polls the second vring module through the second poll module to see if there is new data, and reads from the second vring module if there is new data.
[0014] Furthermore, the virtual network data transmission method further includes a process of a virtual machine sending data, wherein the process of a virtual machine sending data includes the steps of: The virtio_net driver writes the data to the second vring module; The vhost-ebpf module polls the first vring module through the first poll module to see if there is new data. If there is, it reads from the first vring module, filters and processes through the ebpf program, and calls the network card driver to send it from the physical network card.
[0015] Working principle and beneficial effects of the present invention: In the technical solution of the present invention, when the virtual machine receives data, the host kernel senses the network card driver through the ebpf program, writes the data into the first vring module, and the host user senses the second vring module through the second poll module. When the virtual machine sends data, the host kernel senses the first vring module through the first poll module, and the host user writes data to the second vring module.
[0016] The host kernel and host user do not use kvm notifications, but their own poll modules. This not only shortens the data flow path, but also the backend modules are all in the host kernel, so there is no need for context switching. In addition, since ebpf technology uses kernel network card driver detection, it will not make the physical network card invisible, nor will it be exclusively used by the virtual machine, ensuring its flexibility. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The disclosure of the present invention will become more easily understood with reference to the accompanying drawings. It is easy for those skilled in the art to understand that these drawings are only for illustrative purposes and are not intended to limit the scope of protection of the present invention. In addition, similar numbers in the figures are used to represent similar components, among which: Figure 1 It is a structural block diagram of the passthrough solution in the background technology of the present invention; Figure 2 It is a structural block diagram of the vhost-net solution in the background technology of the present invention; Figure 3 It is a structural block diagram of the vhost-user solution in the background technology of the present invention; Figure 4 It is a schematic diagram of a virtual network architecture of a virtual machine of the present invention; Figure 5 It is a flow chart of data processing of a virtual machine virtual network architecture of the present invention. DETAILED DESCRIPTION
[0018] Some embodiments of the present invention are described below with reference to the accompanying drawings. It should be understood by those skilled in the art that these embodiments are only used to explain the technical principles of the present invention and are not intended to limit the protection scope of the present invention. Example 1
[0019] Figure 4 Schematic diagram of a virtual network architecture of a virtual machine of the present invention. Figure 4 As shown, a virtual network architecture of a virtual machine in this embodiment includes a physical network card NIC set in the host kernel space layer host kernel, a network card driver Driver, a vhost-ebpf module, a first vring module and a QEMU virtual machine set in the host user space host user, as follows.
[0020] 1. Host kernel The host kernel is the host kernel space layer, which includes the physical network card NIC, the network card driver Driver, the vhost-ebpf module and the first vring module.
[0021] Among them, the vhost-ebpf module includes the ebpf program and the first poll module: The ebpf program is used to perform detection functions on the kernel, sense the network card driver Driver, receive data packets from the network card driver Driver, filter the data packets, and write them into the first vring module.
[0022] The first poll module is used to sense the data to be sent by the first vring module and read the data to be sent from the first vring module. After the ebpf program filters the data to be sent, it is sent from the physical network card NIC through the network card driver Driver. The data to be sent is the data received by the kernel.
[0023] The filtering and forwarding of the received and sent data by the ebpf program can be achieved by matching rules. The filter rule is used to filter data, and any data that does not match the rule is discarded. The forward rule is used to forward data, and all matching data is forwarded to the specified virtual machine or physical network card through the forward rule. The above "writing to the first vring module" and "sending from the physical network card NIC through the network card driver Driver" are the forwarding operations of the ebpf program.
[0024] 2. host user Host user, that is, the host user space layer, includes a virtual machine formed by simulating the processor application software QEMU (hereinafter referred to as QUEM virtual machine). The QEMU virtual machine includes virtio_net device and virtio_net_driver. The virtio_net_driver is set in the virtual machine operating system.
[0025] Among them, virtio_net_driver includes a second vring module and a second poll module, and virtio_netdevice is used to inform the vhost-ebpf module of the address information of the second vring module.
[0026] Specifically, the virtio_net device sends the memory layout information of the QEMU virtual machine to the vhost-ebpf module through the ioctl / vhost protocol; then the vhost-ebpf module obtains the address information of the second vring module from the memory layout information.
[0027] The first vring module and the second vring module jointly implement a shared data queue between the QEMU virtual machine and the host machine, including a data receiving queue and a data sending queue. The QEMU virtual machine directly writes data into the second vring module to send it.
[0028] Both the first vring module and the second vring module are composed of a pair of descriptor rings and available / used rings, and have the same physical memory area, but the first vring module is configured in the host machine and the second vring module is configured in the virtual machine. Therefore, when the first vring module and the second vring module perform data transmission, the data is written into the shared memory, that is, the above-mentioned shared data queue, and can be obtained by the other vring.
[0029] The second poll module is used to sense the data to be read in the second vring module, where the data to be read is the data received by the QEMU virtual machine.
[0030] Through the virtual network architecture composed above, analogous to vhost-net, this embodiment offloads the work of sending and receiving data to the vhost-ebpf module of the host kernel, which acts as the agent for data sending and receiving, and is called the backend in paravirtualization technology. The front end corresponding to the backend is the virtio_net driver.
[0031] When the virtual machine receives data, the backend perceives it through the detection of the network card driver by the ebpf program, and writes the data into the first vring module. The frontend perceives it through the second poll module polling the second vring module.
[0032] When the virtual machine sends data, the backend senses the first vring module through the first poll module, and the frontend writes data to the second vring module.
[0033] The front-end and back-end do not use kvm notifications, but their own poll modules. This not only shortens the data flow path, but also the back-end modules are all in the host kernel, so there is no need for context switching. In addition, since ebpf technology uses kernel network card driver detection, it will not cause the physical network card to be invisible, nor will it be exclusively used by the virtual machine, ensuring its flexibility. Example 2
[0034] Figure 5 This is a flow chart of data processing of a virtual machine virtual network architecture of the present invention. Figure 5 As shown, a virtual machine virtual network control method in this embodiment is used for a virtual network architecture, and includes the following steps A1-A6.
[0035] Step A1: The host kernel loads the vhost-ebpf module, which is vhost-ebpf driver load in the figure. After loading, a path / dev / vhost-ebpf is generated.
[0036] Step A2: the vhost-ebpf module detects the relevant interface of the network card driver, performs filtering processing on the data packets received from the network card driver, and writes the processed data into the first vring module; Step A3: The QEMU virtual machine starts, simulates the virtio_net device, and configures the feature value feature bit for the virtio_net device; Step A4: The virtio_net device and the virtio_net driver negotiate characteristic values through virito / pci; Step A5: The virtio_net driver creates a second vring module according to the negotiated feature value; Step A6: virtio_net device informs the vhost-ebpf module of the address information of the second vring module. Specifically, the virtio_net device sends the memory layout information of the QEMU virtual machine to the vhost-ebpf module through the ioctl / vhost protocol; then the vhost-ebpf module obtains the address information of the second vring module from the memory layout information. Example 3
[0037] like Figure 5 As shown, a virtual machine virtual network data transmission method in this embodiment is used in a virtual network architecture, including a virtual machine receiving data process and a virtual machine sending data process.
[0038] 1. The process of the virtual machine receiving data The vhost-ebpf module receives the packet header from the network card driver through the ebpf program, filters the packet and writes the data into the first vring module; The virtio_net driver polls the second vring module through the second poll module to see if there is new data, and reads from the second vring module if there is; In this embodiment, when data is received by the physical network card NIC, the corresponding network card driver Driver will call the relevant trace point to send it to the network protocol stack. The ebpf program can track the trace point to sense and obtain the data, and then write the data into the first vring module, and finally receive it by the virtual machine. This method does not need to monopolize the network card, and it is still visible to the host, ensuring flexibility.
[0039] 2. The process of sending data by the virtual machine The virtio_net driver writes the data to the second vring module; vhost-ebpf polls the first vring module through the first poll module to see if there is new data. If there is, it reads from the first vring module, filters and processes through the ebpf program, and then calls the network card driver Driver to send from the physical network card NIC.
[0040] Through the above embodiments, the virtual network architecture proposed by the present invention can shorten the path of data flow from the physical network card NIC to the virtual machine, improve network performance, and make the performance higher, more stable and robust. It solves the problem that the existing virtualized network technology solution monopolizes the physical network card, so that physical resources are fully and efficiently used. It solves the problem that the existing virtualized network technology solution is invisible to the traditional network subsystem of the host machine, and enhances flexibility.
[0041] Here are some terms involved in the present invention.
[0042] KVM: KVM is a module for implementing hardware virtualization on the Linux operating system. It turns the Linux kernel into a type 1 (bare metal) virtual machine monitor (hypervisor).
[0043] QEMU: QEMU is a general-purpose open source emulator and virtual machine monitor. It can perform emulation of multiple hardware platforms and integrates with KVM to achieve high-performance virtualization.
[0044] GUEST OS: Guest OS refers to the operating system running in a virtual machine. Each Guest OS believes that it has exclusive use of the underlying hardware, but in fact, the virtual machine monitor is responsible for resource scheduling.
[0045] HOST: In a virtualized environment, Host refers to the physical machine or operating system that runs the hypervisor and hosts the virtual machines.
[0046] EBPF: eBPF is a powerful kernel technology that allows users to run sandboxed programs in the kernel. eBPF can be used for network monitoring, performance analysis, and security purposes.
[0047] VIRTIO: Virtio is a virtualization standard used to provide efficient I / O between virtual machines and hosts. It defines a set of common devices and interfaces to facilitate different virtualization platforms to implement high-performance virtualization devices.
[0048] VHOST: Vhost is a mechanism to accelerate Virtio. By moving the processing of Virtio devices from user space to kernel space, Vhost improves I / O performance.
[0049] VRING: Vring is a data structure of Virtio, which is used to manage I / O buffers between Virtio devices and virtual machines. It consists of a pair of descriptor rings and available / used rings.
[0050] VIRTIO_NET DRIVER: Virtual network card driver, a Virtio driver for virtual network card devices. Complying with the virtio specification, it allows the Guest OS to communicate with the virtual network device through the Virtio interface.
[0051] VIRTIO_NET DEVICE: A virtual network card device that complies with the Virtio standard. It is simulated by QEMU and contains the characteristic values and configuration space of the virtual network card device. It can be used to communicate with the virtual network card driver.
[0052] So far, the technical solutions of the present invention have been described in conjunction with the preferred embodiments shown in the accompanying drawings. However, it is easy for those skilled in the art to understand that the protection scope of the present invention is obviously not limited to these specific embodiments. Without departing from the principle of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will fall within the protection scope of the present invention.
Claims
1. A virtual machine virtual network architecture, characterized in that: It includes a physical network card, a network card driver, a vhost-ebpf module, a first vring module and a QEMU virtual machine arranged in a host kernel space layer, wherein the QEMU virtual machine includes a virtio_net device and a virtio_net_driver; The vhost-ebpf module includes the ebpf program and the first poll module. The ebpf program is used to receive data packets from the network card driver and write them into the first vring module; The first poll module is used to sense the data to be sent by the first vring module, read the data to be sent from the first vring module, and send it from the physical network card NIC through the network card driver; The virtio_net_driver includes a second vring module and a second poll module. The first vring module and the second vring module jointly implement a shared data queue between the QEMU virtual machine and the host machine, including a data receiving queue and a data sending queue; The second poll module is used to sense the data to be read in the second vring module; The virtio_net device is used to inform the vhost-ebpf module of the address information of the second vring module.
2. A virtual machine virtual network architecture according to claim 1, characterized in that: The ebpf program is also used to filter and forward received and sent data.
3. A virtual machine virtual network architecture according to claim 1, characterized in that: The virtio_net_driver is set in the virtual machine operating system.
4. A virtual network control method for a virtual machine, used in the virtual network architecture described in any one of claims 1 to 3, characterized in that: Includes steps: The host kernel loads the vhost-ebpf module; The vhost-ebpf module detects the relevant interfaces of the network card driver, performs filtering processing on the data received from the network card driver, and writes the processed data into the first vring module; The QEMU virtual machine starts, simulates the virtio_net device, and configures the characteristic value for the virtio_net device; The virtio_net device and the virtio_net driver negotiate characteristic values through virito / pci; The virtio_net driver creates a second vring module based on the negotiated feature values; The virtio_net device informs the vhost-ebpf module about the address information of the second vring module.
5. A virtual machine virtual network control method according to claim 4, characterized in that: The virtio_netdevice informs the vhost-ebpf module of the address information of the second vring module, including: The virtio_net device sends the memory layout information of the QEMU virtual machine to the vhost-ebpf module through the ioctl / vhost protocol; The vhost-ebpf module obtains address information of the second vring module from the memory layout information.
6. A virtual machine virtual network data transmission method, used in the virtual network architecture described in any one of claims 1-3, characterized in that: The method includes a process of a virtual machine receiving data, wherein the process of a virtual machine receiving data includes the steps of: The vhost-ebpf module receives data packets from the network card driver through the ebpf program, filters the data packets and writes the data into the first vring module; The virtio_net driver polls the second vring module through the second poll module to see if there is new data, and reads from the second vring module if there is new data.
7. A virtual machine virtual network data transmission method according to claim 6, characterized in that: The process also includes a virtual machine sending data, wherein the virtual machine sending data process includes the steps of: The virtio_net driver writes the data to the second vring module; The vhost-ebpf module polls the first vring module through the first poll module to see if there is new data. If there is, it reads from the first vring module, filters and processes through the ebpf program, and calls the network card driver to send it from the physical network card.
Citation Information
Cited By
Communication method and device of virtual machine, storage medium and electronic device
CN121433814A
Virtual large language model LLM device
CN121562760A
A large language model (LLM) device
CN121562760B
VTCM equipment virtualization optimization method and system, terminal and medium
CN122019059A
