WO2017121273A1 - Method and device for processing i/o request under kvm virtualization - Google Patents

Method and device for processing i/o request under kvm virtualization Download PDF

Info

Publication number
WO2017121273A1
WO2017121273A1 PCT/CN2017/070151 CN2017070151W WO2017121273A1 WO 2017121273 A1 WO2017121273 A1 WO 2017121273A1 CN 2017070151 W CN2017070151 W CN 2017070151W WO 2017121273 A1 WO2017121273 A1 WO 2017121273A1
Authority
WO
WIPO (PCT)
Prior art keywords
channel
request
virtual machine
simulation
eventfd
Prior art date
Application number
PCT/CN2017/070151
Other languages
French (fr)
Chinese (zh)
Inventor
张献涛
丁圣阁
田双太
Original Assignee
阿里巴巴集团控股有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 阿里巴巴集团控股有限公司 filed Critical 阿里巴巴集团控股有限公司
Publication of WO2017121273A1 publication Critical patent/WO2017121273A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/01Input arrangements or combined input and output arrangements for interaction between user and computer
    • G06F3/03Arrangements for converting the position or the displacement of a member into a coded form
    • G06F3/033Pointing devices displaced or positioned by the user, e.g. mice, trackballs, pens or joysticks; Accessories therefor
    • G06F3/038Control and interface arrangements therefor, e.g. drivers or device-embedded control circuitry
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45579I/O management, e.g. providing access to device drivers or storage

Definitions

  • the present application relates to the technical field of KVM virtualization, and in particular to a method for processing an I/O request under KVM virtualization and a device for processing an I/O request under KVM virtualization.
  • Virtual Machine is a complete computer system that is simulated by software and has complete hardware system functions and runs in a completely isolated environment. With virtual machine software, one or more virtual computers can be simulated on a single physical computer. Virtual machines can work like real computers, such as installing an operating system, installing applications, accessing network resources, and more. Usually, the physical computer where the virtual machine is located is called the host, and the virtual machine itself is called the virtual machine (Guest).
  • KVM Kernel-based Virtual Machine
  • Linux Linux's own scheduler for management.
  • KVM virtualization requires hardware support (such as Intel VT technology or AMD). VT technology).
  • the virtual machine when the virtual machine generates I/O operations, it supports VMX (Virtual Machine eXtensions, which is an x86 instruction set virtualization extension implemented by Intel) or SVM (Secure Virtual Machine, which is an amd implementation).
  • VMX Virtual Machine eXtensions, which is an x86 instruction set virtualization extension implemented by Intel
  • SVM Secure Virtual Machine, which is an amd implementation.
  • the virtualization extension of the x86 instruction set the extended CPU will stop executing, exit the non-root mode, and enter the root mode to execute the KVM code.
  • KVM knows that the virtual machine needs to perform I/O operations according to the reason of the exit, so it exits from the kernel state to the QEMU process in the user state.
  • the QEMU process maps a KVM space during initialization.
  • the KVM puts the I/O request in it before exiting.
  • the QEMU gets the I/O request, it distributes it to the corresponding I/O analog device, I/O.
  • QEMU calls the IOCTL to enter the KVM kernel state.
  • the KVM is slightly processed, it enters the non-root mode and continues to run the vCPU (virtual processor).
  • QEMU When simulating vCPU, QEMU enters the KVM kernel state through a vCPU IOCTL. When an I/O request occurs, it must exit the kernel state and return to the VCPU thread of the QEMU user state for simulation. Therefore, the I/O simulation must be CPU emulation is in the same process and cannot support multiple device emulation processes.
  • KVM's existing eventfd-based I / O notification mechanism can only be applied to write requests, and does not care about the data written, only concerned with the scene of the written address, such as the Virtio device's queue notification register write access. This mechanism does not pass the actual address and length of the I/O request access, nor can it pass the data from the read operation to the KVM.
  • embodiments of the present application have been proposed in order to provide a method for processing I/O requests under KVM virtualization that overcomes the above problems or at least partially solves the above problems, and a corresponding KVM virtualization processing I/ O request device.
  • the present application discloses a method for processing an I/O request under KVM virtualization, the method comprising:
  • the I/O request sent by the virtual machine is intercepted by the kernel virtual machine KVM, and the information of the I/O channel corresponding to the I/O request is determined, wherein the I/O channel has a corresponding buffer, and the I/O
  • the information of the O channel includes an eventfd file descriptor
  • the event of the corresponding I/O channel is monitored, and an I/O request is obtained from the buffer of the corresponding I/O channel, and the I/O request is executed.
  • An I/O simulation wherein the user state process includes a first device emulation process and a second device emulation process independent of the first device emulation process.
  • the method further includes:
  • an I/O address interval is bound to the I/O channel based on a file descriptor of the I/O channel.
  • the I/O request includes an I/O address
  • the step of intercepting an I/O request sent by the virtual machine by the kernel virtual machine KVM, and determining information of the I/O channel corresponding to the I/O request include:
  • the address interval of the I/O channel includes an address subinterval of a plurality of I/O analog devices
  • Determining, in the user state process, a corresponding I/O channel according to the eventfd, and acquiring an I/O request from a buffer of the corresponding I/O channel, performing the I/O request The steps of the I/O simulation include:
  • determining a corresponding I/O channel according to the eventfd, and acquiring an I/O request from the buffer of the corresponding I/O channel, for the I Before /O requests to perform the I/O simulation steps it also includes:
  • determining a corresponding I/O channel according to the eventfd and acquiring an I/O request from the buffer of the corresponding I/O channel, for the I After the /O request to perform the I/O simulation steps, it also includes:
  • the I/O request includes a read request, and the I/O request is distributed to the I/O analog device, and the I/O request is performed by the I/O analog device.
  • the steps of the /O simulation are:
  • the method further includes:
  • the I/O request is a read request
  • the data corresponding to the read request is read out from the buffer, and is read into a corresponding member variable in the vCPU structure
  • the present application also discloses an apparatus for processing an I/O request under KVM virtualization, the apparatus comprising:
  • An I/O channel determining module configured to intercept, by the kernel virtual machine KVM, an I/O request sent by the virtual machine to determine information of an I/O channel corresponding to the I/O request, where the I/O channel has Corresponding buffer, the information of the I/O channel includes an eventfd file descriptor;
  • a buffer write module configured to write the I/O request into a buffer of a corresponding I/O channel
  • An event notification module configured to notify the user state process corresponding to the I/O channel by using the eventfd;
  • An I/O simulation module configured to: in the user state process, listen to an event of the corresponding I/O channel according to the eventfd, and obtain an I/O request from a buffer of the corresponding I/O channel, Performing an I/O simulation on the I/O request, wherein the user state process includes a first device emulation process and a second device emulation process independent of the first device emulation process.
  • the device further comprises:
  • a virtual machine creating module configured to create a virtual machine by using the first device simulation process, and obtain a file descriptor of the virtual machine
  • a vCPU creation module configured to: use the first device simulation process, create a virtual processor vCPU based on a file descriptor of the virtual machine, and obtain a file descriptor of the vCPU;
  • An eventfd creation module is configured to create an eventfd file descriptor by using the second device simulation process
  • An I/O channel creation module configured to simulate a process by using the second device, create an I/O channel based on a file descriptor of the virtual machine, and bind the I/O channel to the eventfd file descriptor Determining, obtaining a file descriptor of the I/O channel;
  • a monitoring module configured to monitor the eventfd file descriptor by using the second device simulation process
  • a buffer mapping module configured to simulate the process by using the second device, based on a file description of the I/O channel a buffer for mapping the I/O channel to the user mode process
  • An address interval binding module is configured to bind an I/O address interval to the I/O channel based on a file descriptor of the I/O channel by using the second device simulation process.
  • the I/O request includes an I/O address
  • the I/O channel determining module includes:
  • An I/O request intercepting submodule for intercepting I/O requests from a virtual machine's vCPU thread through a kernel virtual machine KVM and an Intel VT-d hardware technology
  • An I/O address extraction submodule configured to extract a corresponding I/O address from the I/O request
  • a first I/O channel determining submodule configured to determine an I/O address interval to which the I/O address belongs, and determine a corresponding I/O channel by using the I/O address interval, and acquire the I/ Information about the I/O channel corresponding to the O channel.
  • the address interval of the I/O channel includes an address subinterval of a plurality of I/O analog devices
  • the I/O simulation module includes:
  • a second I/O channel determining submodule configured to determine, according to the eventfd, a corresponding I/O channel in the user state process
  • An I/O request reading submodule configured to obtain an I/O request from a buffer of the corresponding I/O channel
  • An I/O analog device determining submodule configured to determine a corresponding I/O analog device according to an I/O address in the I/O request
  • a distribution submodule configured to distribute the I/O request to the I/O simulation device, and perform I/O simulation on the I/O request by using the I/O simulation device.
  • the device further comprises:
  • Suspending a module for suspending the vCPU thread after the userfest process corresponding to the I/O channel is notified by using the eventfd.
  • the device further comprises:
  • a wake-up module configured to wake up the suspended vCPU thread after performing I/O simulation on the I/O request.
  • the I/O request includes a read request
  • the distribution sub-module is further configured to:
  • the device further comprises:
  • a data reading module configured to: when the I/O request is a read request, read data corresponding to the read request from a buffer, and read the corresponding member variable into the vCPU structure, The data is subjected to corresponding analog processing.
  • the I/O request can be delivered through the I/O channel.
  • the KVM intercepts the I/O request sent by the virtual machine
  • the I/O channel corresponding to the I/O request can be determined, and the I/O channel is determined.
  • /O request is written into the buffer of the corresponding I/O channel, and then the user state process corresponding to the I/O channel is notified by eventfd, and the user state process listens to the eventfd event notification, and the I/O channel corresponding to the eventfd Get an I/O request in the buffer and perform an I/O simulation on the I/O request.
  • the application can realize the distribution of I/O requests in the kernel state, and can support multiple device simulation processes for a single virtual machine, thereby improving the efficiency of I/O simulation.
  • Embodiment 1 is a flow chart showing the steps of Embodiment 1 of a method for distributing an I/O request under KVM virtualization according to the present application;
  • FIG. 2 is a flow chart of steps of a second embodiment of a method for distributing an I/O request in a KVM virtualization process according to the present application;
  • FIG. 3 is a flow chart of steps of a KVM initialization process in Embodiment 2 of a method for distributing an I/O request in a KVM virtualization process according to the present application;
  • FIG. 4 is a structural block diagram of an embodiment of an apparatus for processing an I/O request under the KVM virtualization of the present application.
  • FIG. 1 a flow chart of a first embodiment of a method for distributing an I/O request in a KVM virtualization process of the present application is shown, which may specifically include the following steps:
  • Step 101 The I/O request sent by the virtual machine is intercepted by the kernel virtual machine KVM, and the information of the I/O channel corresponding to the I/O request is determined, where the I/O channel has a corresponding buffer.
  • the information of the I/O channel includes an event notification to create an eventfd file descriptor.
  • Step 102 Write the I/O request into a buffer of a corresponding I/O channel.
  • Step 103 The eventfd is used to notify a user state process corresponding to the I/O channel.
  • Step 104 In the user state process, according to the eventfd, the event of the corresponding I/O channel is monitored, and an I/O request is obtained from the buffer of the corresponding I/O channel, and the I/O request is performed. O requests to perform an I/O simulation.
  • the user state process includes a first device simulation process and a second device simulation process that is independent of the first device simulation process.
  • an I/O request can be delivered through an I/O channel, when the KVM intercepts the virtual machine.
  • the I/O channel corresponding to the I/O request can be determined, and the I/O request is written into the buffer of the corresponding I/O channel, and then the user corresponding to the I/O channel is notified by eventfd.
  • the state process after the user state process listens to the eventfd event notification, reads the I/O request from the buffer of the I/O channel corresponding to the eventfd, and performs I/O simulation on the I/O request.
  • the application can realize the distribution of I/O requests in the kernel state, and can support multiple device simulation processes for a single virtual machine, thereby improving the efficiency of I/O simulation.
  • KVM Kernel-based Virtual Machine
  • Linux kernel an open source virtualization solution based on Linux environment.
  • the idea of KVM is to add a virtual machine management module based on the Linux kernel, and reuse the well-established process scheduling, memory management, I/O management and other parts of the Linux kernel to make it a hypervisor that can support the running of virtual machines. .
  • KVM is a fully virtualized solution based on hardware-assisted virtualization technology (eg Intel's VT-x or AMD-V).
  • the virtual machine operating system can be run directly in the KVM virtual machine without modification.
  • Each virtual machine Ability to enjoy independent virtual hardware resources: network cards, disks, graphics adapters, and more.
  • KVM can be compiled into the kernel as a separate module, or it can be loaded as a kernel module after the Linux system is booted.
  • the KVM API is accessed via the /dev/kvm device.
  • /dev/kvm is a character device that can be manipulated using common system calls such as open, close, IOCTL, and so on. Because the implementation function of the KVM character device does not include write, read, etc., all operations on the KVM are implemented by the IOCTL sending the corresponding control word.
  • the user space API provided by KVM is functionally divided into three types, namely system instruction, VM instruction, and vCPU instruction.
  • the system instruction is for the global parameter setting of the virtualization system and the control operation for the virtual machine creation; the VM instruction controls the specific VM virtual machine, such as performing memory setting, creating a vCPU, etc.; the vCPU instruction is performed for a specific vCPU. Parameter setting (MRU register read/write, interrupt control, etc.).
  • user space can be controlled by different user mode simulators, so that device I/Os of the same virtual machine can be simulated in different user state processes, and multiple device simulation processes for a single virtual machine can be supported.
  • the different user mode process may include a first device simulation process and a second device simulation process.
  • the first device simulation process may be a QEMU (full name Quick Emulator) process
  • the second The device simulation process can simulate a process for an I/O device that is independent of the QEMU process.
  • the second device simulation process can be referred to as a DEMU (Dedicated Emulator) process or a DEMU.
  • QEMU is an open source simulator and virtual machine monitor (VMM), users can install QEMU through the package manager of different Linux distributions.
  • QEMU simulates the hardware device of the virtual machine in the host user mode.
  • QEMU When QEMU is used as the system simulator, it can simulate a virtual machine that can run the operating system independently.
  • Each virtual machine corresponds to a QEMU process in the host (Host), and virtual The vCPU of the machine corresponds to one thread of the QEMU process.
  • the QEMU process and the DEMU process can be created by executing the binary executable files of QEMU and DEMU, and the two processes can be started by a script or a libvirt tool.
  • the initialization process is first performed before the I/O request is processed.
  • the module_init macro In the platform-related KVM module, the module_init macro officially enters the initialization phase of the KVM, and performs related hardware initialization preparation. Enter the kvm_init function in kvm_main.c for formal initialization.
  • the initialization process may at least include the following steps:
  • Sub-step S1 Create a virtual machine by using the first device simulation process to obtain a file descriptor of the virtual machine.
  • the interaction interface between the KVM and the user space process is /dev/kvm
  • the operation of the KVM API is started by opening the /dev/kvm device file.
  • an fd for the kvm subsystem can be obtained.
  • File descriptor Further operations on the file descriptor are then performed by the IOCTL system instructions.
  • the IOCTL system instructions can include the KVM_CREATE_VM instruction, which creates a virtual machine VM with the KVM_CREATE_VM instruction.
  • An fd file descriptor can be obtained by calling anon_inode_getfd as a file descriptor of the virtual machine, ie vm_fd, which points to the newly created virtual machine in the kernel space, and then controls the behavior of the virtual machine according to the descriptor.
  • the vm IOCTL system call implements control of the virtual machine. Most of the parameters of the vm IOCTL control instruction need to be operated from the vm_fd returned by KVM_CREATE_VM. The operations involved are mainly for the virtual machine, such as configuring memory and configuring vCPU.
  • mmap corresponds to the physical address of the guest operating system GUEST OS, and the address space of the GUEST OS can be read/written directly, and the IOCTL is used to send the KVM. Control word.
  • a corresponding universal unique identifier UUID may be set for the created virtual machine to identify the virtual machine by using the UUID.
  • the creation process of the virtual machine is essentially the creation and initialization process of the KVM structure.
  • the kvm_dev_IOCTL_create_vm function creates the KVM structure by calling the kvm_create_vm function.
  • the KVM structure saves the context and other related states of the virtual machine running.
  • it can include vCPU (virtual processor, CPU in virtual machine), memory, APIC (Advanced Programmable Interrupt Controller), IRQ.
  • the information of the (Interrupt Request), the MMU (Memory Management Unit), and the Event Event Management is applied to the embodiment of the present application.
  • the KVM structure may further include a UUID of the virtual machine.
  • the initialization process of the KVM structure may include: initializing a KVM memslot structure, a Bus bus structure information, a scru read/write lock information, an eventfd event notification information, an mmu memory management structure information, and the like.
  • the virtual machine's KVM structure After the virtual machine's KVM structure is created, it can be added to the global linked list vm_list.
  • the creation of a virtual machine may be completed by using a QEMU process.
  • Step S2 Using the first device simulation process, create a virtual processor vCPU based on the file descriptor of the virtual machine, and obtain a file descriptor of the vCPU.
  • the newly created virtual machine does not have a vCPU and needs to be configured through subsequent IOCTL instructions.
  • the KVM_CREATE_vCPU instruction is invoked by the IOCTL, and the vCPU can be created for the virtual machine corresponding to the vm_fd.
  • the entry function address is in the kvm_vm_IOCTL function.
  • the program flow is selected to enter the kvm_vm_IOCTL_create_vCPU function for processing, and the vCPU is returned.
  • the file descriptor fd, vCPU_fd, in the KVM virtualization environment, hardware virtualization uses vCPU_fd to describe the vCPU.
  • the data structure corresponding to vCPU is kvm_vCPU.
  • the creation process of vCPU is essentially the creation and initialization process of kvm_vCPU structure. It can include the following process: call kvm_arch_vCPU_create function to create a kvm_vCPU structure; call kvm_arch_vCPU_setup function to data in kvm_vCPU The structure is initialized; the file descriptor vCPU_fd corresponding to the current vCPU is created, and the kvm_vCPU is added to the vCPU array of the KVM.
  • the creation of the vCPU may be completed by using a QEMU process, and each vCPU corresponds to one vCPU thread.
  • Step S3 using the second device simulation process to create an eventfd file descriptor.
  • the DEMF process can call the standard Linux system API eventfd() to create an eventfd file descriptor.
  • eventfd() is the system interface provided by the Linux system.
  • the function prototype is int eventfd (unsigned int initval, int flags).
  • Calling this function user state process can obtain an eventfd file descriptor and create an eventfd in the kernel.
  • the mechanism used by the object to implement wait and notification is mainly used for user state mutual notification and notification of kernel mode to user mode.
  • the eventfd object can contain a 64-bit integer variable as a counter, the parameters passed in the function prototype. Initval is used to initialize this counter.
  • the eventfd file descriptor is used to reference the eventfd object in user mode. The user state process can perform read, write, poll, and select operations on the eventfd file descriptor.
  • Step S4 using the second device simulation process, creating an I/O channel based on the virtual machine file descriptor, and binding the I/O channel with the eventfd file descriptor to obtain the I/ The file descriptor of the O channel.
  • the DEMU process may also be used to create one or more I/O channels of the virtual machine.
  • the DEMU process can obtain the UUID of the current virtual machine, and then find the UUID of the virtual machine in the global linked list vm_list. If the search succeeds, the corresponding KVM structure is obtained, thereby obtaining the file descriptor vm_fd of the virtual machine, and then An I/O channel can be created for the virtual machine corresponding to the vm_fd by the new IOCTL instruction (for example, the KVM_CREATE_IOCH instruction).
  • the new IOCTL instruction for example, the KVM_CREATE_IOCH instruction.
  • each vm_fd can mount multiple I / O_fd.
  • the creation process of the I/O channel is essentially the process of creating and initializing the structure of the I/O channel.
  • the structure of the I/O channel may include: an eventfd for notification of the kernel state to the user state;
  • the group stores the buffer of the I/O request and its protection lock; a linked list that holds all the I/O address spaces that this channel is responsible for.
  • the KVM structure corresponding to each virtual machine may further add a linked list for storing all I/O channels registered on the virtual machine.
  • each I/O simulation process only needs one and corresponds to one I/O channel.
  • Sub-step S5 monitoring the eventfd file descriptor by using the second device simulation process.
  • the poll or select method may be used on the eventfd file descriptor in the process main loop. Once the eventfd file descriptor is found to have an I/O to be processed, the relevant processing function is called to implement the monitoring of the eventfd.
  • Step S6 The second device emulation process is used to map a buffer of the I/O channel for the user state process based on a file descriptor of the I/O channel.
  • KVM allocates a buffer to the newly created I/O channel in the kernel state. Subsequently, the user mode program can use the mmap() system call on the file descriptor of the I/O channel to map the I/O.
  • the buffer of the channel which can be accessed by user-mode processes.
  • the buffer also has a protection lock to ensure mutual access to the buffer for read and write access.
  • Step S7 using the second device simulation process, binding an I/O address interval to the I/O channel based on a file descriptor of the I/O channel.
  • the DEMU process can also use the file descriptor of the I/O channel to monitor
  • the I/O channel is bound to the I/O address range. Different I/O channels have different I/O address ranges. For example, for I/O address range 1 to 1000, you can bind 1 to 300 to I/. O channel A, binds 301 to 1000 to I/O channel B.
  • the address range of the I/O channel may further include multiple address sub-intervals, each of which corresponds to an I/O analog device (an IO simulation process can simulate multiple IO analog devices), each I/O analog devices only simulate requests that fall within their address range.
  • the address range of I/O channel A is 1 to 300, where 1 to 100 can correspond to I/O analog device 1, 101 to 200 can correspond to I/O analog device 2, and 201 to 300 can correspond to I/O simulation. Device 3.
  • an independent DEMU process is added, and the two function as a user state simulator can share a part of the underlying data structure of the virtual machine.
  • the embodiment of the present application may specifically include the following steps:
  • Step 201 The I/O request sent by the virtual processor vCPU thread of the virtual machine is intercepted by the kernel virtual machine KVM, and the information of the I/O channel corresponding to the I/O request is determined.
  • the KVM can intercept the virtual machine's I/O operations and determine the corresponding I/O channel information based on the intercepted I/O operations.
  • step 201 may include the following sub-steps:
  • Sub-step 1 Intercept the I/O request from the virtual machine's virtual processor vCPU thread through the kernel virtual machine KVM and Intel VT-d hardware technology.
  • KVM runs a vCPU thread in kernel space non-root mode.
  • the sensitive instruction will trigger the VM exit operation of the Intel VT-d hardware technology, and enter the KVM corresponding to the root mode. Processing function.
  • the VM Entry is triggered, and the virtual machine enters the guest guest mode, that is, the non-root mode.
  • a privileged instruction or an external event such as an I/O access, an operation of a control register, an MSR read/write packet arrives, etc., is executed in a virtual machine (Guest mode)
  • a VM Exit can be triggered (triggered by hardware).
  • the current CPU exits from the guest mode (non-root non-root mode), switches to the root root mode, and the control of the current CPU is transferred to the KVM, which is processed by the KVM.
  • the VM_EXIT_REASON field in the VMCS is read to obtain the cause of the VM Exit.
  • the KVM knows that the virtual machine needs to perform I/O operations according to the reason of the exit.
  • Sub-step 2 Extract the corresponding I/O address from the I/O request.
  • the I/O request may carry the address information of the virtual machine that issues the I/O request, and after obtaining the I/O request, the corresponding I/O address may be extracted from the I/O request.
  • Sub-step 3 Determine the I/O address range to which the I/O address belongs.
  • Sub-step 4 determining a corresponding I/O channel by using the I/O address interval, and acquiring information of an I/O channel corresponding to the I/O channel.
  • the I/O channel Since the I/O channel has an I/O address interval, it can first determine which address interval the I/O address of the I/O request belongs to, and then determine the corresponding I/O channel according to the matched address interval, and determine the I/. Information about the buffer corresponding to the O channel, the eventfd file descriptor, and so on.
  • Step 202 Write the I/O request into a buffer of a corresponding I/O channel.
  • the KVM After determining the I/O channel channel corresponding to the I/O request, the KVM can write the I/O request into the buffer of the corresponding I/O channel, thereby completing the distribution of the I/O request in the KVM.
  • Step 203 The eventfd is used to notify a user state process corresponding to the I/O channel.
  • the user space when the I/O request is written into the buffer of the corresponding I/O channel in the kernel space, the user space does not know about this, so the kernel space needs to send a notification to the user space through eventfd, the user state process. By listening to the eventfd, it is known that an I/O request is written in the buffer of its corresponding I/O channel.
  • Step 204 suspending the vCPU thread.
  • the I/O simulation thread since the I/O request is uploaded to the buffer of the I/O channel through the I/O channel, the I/O simulation thread performs I/O simulation, and the I/O simulation thread and the vCPU thread can It is in a different process, so there is no need to exit the vCPU thread when an I/O request occurs. At this time, only the vCPU thread needs to be suspended, and wait for the user state process to complete the I/O request and then wake it up.
  • Step 205 In the user state process, according to the eventfd, the event of the corresponding I/O channel is monitored, and an I/O request is obtained from the buffer of the corresponding I/O channel, and the I/O request is performed. O requests to perform an I/O simulation.
  • the user state process can listen to the eventfd event notification, and the corresponding processing function is called to perform I/O simulation through the user state process, wherein the I/O simulation mainly refers to The I/O operation performed by the virtual machine obtains a corresponding processing result through the simulation behavior of the software.
  • step 205 may include the following sub-steps:
  • Sub-step 1 In the user state process, the corresponding I/O channel is determined according to the eventfd.
  • the I/O channel corresponding to the eventfd can be determined according to the correspondence between the eventfd and the I/O channel.
  • Sub-step 2 Obtain an I/O request from the buffer of the corresponding I/O channel.
  • the I/O request can be further read from the buffer of the I/O channel that has been mapped.
  • Sub-step 3 Determine the corresponding I/O analog device according to the I/O address in the I/O request.
  • Sub-step 4 Distributing the I/O request to the I/O analog device, and performing I/O simulation on the I/O request by the I/O analog device.
  • the address space of the I/O channel includes an address subinterval of one or more I/O analog devices, after the user state process obtains the I/O request, it can be based on the I/O address carried in the I/O request. Determining an address subinterval to which the I/O address belongs, and determining a corresponding I/O analog device according to the address subinterval, and distributing the I/O request to the corresponding I/O analog device to complete I/ Further secondary distribution of O requests.
  • the I/O analog device After the I/O analog device obtains the I/O request, it performs I/O simulation on the I/O request.
  • the I/O emulation device corresponding to the request may write the data corresponding to the read request into a buffer of the I/O channel, thereby completing the user space. I/O simulation in .
  • the I/O emulation device corresponding to the request may write the data corresponding to the write request into a corresponding location, for example, written in the host.
  • Step 206 waking up the suspended vCPU thread.
  • the user state process calls the new IOCTL instruction in the file descriptor of the I/O channel to enter the KVM kernel state, wake up the suspended vCPU thread, and continue to run the vCPU thread to reach the vCPU thread and I/.
  • the data corresponding to the read request may be read out from the buffer and read into a corresponding member variable in the vCPU structure. In the middle, and through the original I / O simulation code for subsequent simulation processing.
  • eventfd combined with the use of the buffer, can pass the actual address and length of the I / O request access in the buffer, and pass the data obtained by the read operation to the KVM through the buffer, overcoming the shortcomings of the prior art.
  • the VM Enter can be triggered by a hardware instruction (such as VMLAUNCH), and the guest mode is re-entered to enter the virtual machine running environment to continue running.
  • a hardware instruction such as VMLAUNCH
  • the device driver accesses the MMIO control register of the virtual VGA device to read the state of the analog device.
  • the register-mapped address access triggers an EPT page fault, and the CPU exits the non-root mode into root mode and executes the KVM code.
  • KVM judges the reason for the exit to be an I/O request, finds the corresponding I/O channel according to the I/O request, copies the I/O request to the corresponding buffer of the I/O channel, and then sends a notification to the vCPU thread with eventfd. Go to sleep.
  • the QEMU main loop finds the event notification in eventfd, finds the corresponding I/O channel and reads the I/O request from the corresponding buffer, and finds that the request address is in the BAR1 interval of the virtual VGA device in the client physical address layout, so Call the corresponding processing function of the VGA device to simulate the I/O request, write the value of this register back to the buffer, and then wake up the sleeping vCPU thread through the IOCTL instruction.
  • the vCPU thread After the vCPU thread wakes up, it reads the register value data from the buffer and updates it to the corresponding location of the vCPU context, then enters the non-root mode to continue executing the vCPU context.
  • the read register operation at the driver code completes the simulation.
  • the embodiment of the present application provides a basis for implementing a device simulation program independent of QEMU under KVM virtualization, and solves the device simulation requirements unique to some vendors.
  • the embodiment of the present application implements the distribution of I/O requests in the KVM kernel module, and provides a control interface to the user state, so that the device I/O of the same virtual machine can be simulated in different processes.
  • FIG. 4 a structural block diagram of an apparatus for processing an I/O request in a KVM virtualization process of the present application is shown. Specifically, the following modules may be included:
  • the I/O channel determining module 401 is configured to intercept, by the kernel virtual machine KVM, an I/O request sent by the virtual machine, and determine information of an I/O channel corresponding to the I/O request, where the I/O channel Having a corresponding buffer, the information of the I/O channel includes an eventfd file descriptor;
  • a buffer write module 402 configured to write the I/O request into a buffer of a corresponding I/O channel
  • the event notification module 403 is configured to notify the user state process corresponding to the I/O channel by using the eventfd;
  • the I/O simulation module 404 is configured to: in the user state process, listen to an event of the corresponding I/O channel according to the eventfd, and obtain an I/O request from a buffer of the corresponding I/O channel. Performing an I/O simulation on the I/O request.
  • the user state process includes a first device simulation process and a second device simulation process that is independent of the first device simulation process.
  • the device may further include:
  • a virtual machine creating module configured to create a virtual machine by using the first device simulation process, and obtain a file descriptor of the virtual machine
  • a vCPU creation module configured to: use the first device simulation process, create a virtual processor vCPU based on a file descriptor of the virtual machine, and obtain a file descriptor of the vCPU;
  • An eventfd creation module is configured to create an eventfd file descriptor by using the second device simulation process
  • An I/O channel creation module configured to simulate a process by using the second device, create an I/O channel based on a file descriptor of the virtual machine, and bind the I/O channel to the eventfd file descriptor Determining, obtaining a file descriptor of the I/O channel;
  • a monitoring module configured to monitor the eventfd file descriptor
  • a buffer mapping module configured to: use the second device simulation process to map a buffer of the I/O channel for the user state process based on a file descriptor of the I/O channel;
  • An address interval binding module is configured to bind an I/O address interval to the I/O channel based on a file descriptor of the I/O channel by using the second device simulation process.
  • the I/O request includes an I/O address
  • the I/O channel determining module 401 may include the following submodules:
  • An I/O request intercepting submodule for intercepting I/O requests from a virtual machine's vCPU thread through a kernel virtual machine KVM and an Intel VT-d hardware technology
  • An I/O address extraction submodule configured to extract a corresponding I/O address from the I/O request
  • a first I/O channel determining submodule configured to determine an I/O address interval to which the I/O address belongs, and determine a corresponding I/O channel by using the I/O address interval, and acquire the I/ Information about the I/O channel corresponding to the O channel.
  • the address range of the I/O channel includes an address subinterval of a plurality of I/O analog devices
  • the I/O simulation module 404 can include the following sub-modules:
  • a second I/O channel determining submodule configured to determine, according to the eventfd, a corresponding I/O channel in the user state process
  • An I/O request reading submodule configured to obtain an I/O request from a buffer of the corresponding I/O channel
  • An I/O analog device determining submodule configured to determine a corresponding I/O analog device according to an I/O address in the I/O request
  • a distribution submodule configured to distribute the I/O request to the I/O simulation device, and perform I/O simulation on the I/O request by using the I/O simulation device.
  • the device further includes:
  • Suspending a module for suspending the vCPU thread after the userfest process corresponding to the I/O channel is notified by using the eventfd.
  • the device further includes:
  • a wake-up module configured to wake up the suspended vCPU thread after performing I/O simulation on the I/O request.
  • the I/O request includes a read request
  • the distribution sub-module is further configured to:
  • the device further includes:
  • a data reading module configured to: when the I/O request is a read request, read data corresponding to the read request from a buffer, and read the corresponding member variable into the vCPU structure, The data is subjected to corresponding analog processing.
  • the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment.
  • embodiments of the embodiments of the present application can be provided as a method, apparatus, or computer program product. Therefore, the embodiments of the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Moreover, embodiments of the present application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) including computer usable program code.
  • computer-usable storage media including but not limited to disk storage, CD-ROM, optical storage, etc.
  • the computer device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
  • the memory may include non-persistent memory, random access memory (RAM), and/or non-volatile memory in a computer readable medium, such as read only memory (ROM) or flash memory.
  • RAM random access memory
  • ROM read only memory
  • Memory is an example of a computer readable medium.
  • Computer readable media includes both permanent and non-persistent, removable and non-removable media.
  • Information storage can be implemented by any method or technology. The information can be computer readable instructions, data structures, modules of programs, or other data.
  • Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory. (ROM), electrically erasable programmable read only memory (EEPROM), flash memory or other memory technology, compact disk read only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, Magnetic tape cartridges, magnetic tape storage or other magnetic storage devices or any other non-transportable media can be used to store information that can be accessed by a computing device.
  • computer readable media does not include non-persistent computer readable media, such as modulated data signals and carrier waves.
  • Embodiments of the present application are described with reference to flowcharts and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the present application. It will be understood that each flow and/or block of the flowchart illustrations and/or FIG.
  • These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processor or other programmable data processing terminal device to produce a machine such that instructions are executed by a processor of a computer or other programmable data processing terminal device
  • Means are provided for implementing the functions specified in one or more of the flow or in one or more blocks of the flow chart.
  • the computer program instructions can also be stored in a computer readable memory that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer readable memory produce an article of manufacture comprising the instruction device.
  • the instruction device implements the functions specified in one or more blocks of the flowchart or in a flow or block of the flowchart.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Human Computer Interaction (AREA)
  • Debugging And Monitoring (AREA)

Abstract

Provided are a method and device for processing an I/O request under KVM virtualization. The method comprises: intercepting, by means of a kernel-based virtual machine (KVM), an I/O request transmitted by a virtual machine, and determining information of an I/O channel corresponding to the I/O request, wherein the I/O channel has a corresponding buffer zone, and the information of the I/O channel includes a file descriptor for an event notification (eventfd) (101); writing the I/O request into the buffer zone of the corresponding I/O channel (102); using the eventfd to notify the I/O channel of a corresponding user mode process (103); and in the user mode process, monitoring, according to the eventfd, an event of the corresponding I/O channel, acquiring the I/O request from the buffer zone of the corresponding I/O channel, and executing I/O simulation on the I/O request (104), wherein the user mode process includes a first device simulation process and a second device simulation process that is independent from the first device simulation process. The method can realize distribution of I/O requests in a kernel mode, and can support multiple device simulation processes for a single virtual machine, thereby improving an I/O simulation efficiency.

Description

一种KVM虚拟化下处理I/O请求的方法和装置Method and device for processing I/O request under KVM virtualization
本申请要求2016年01月12日递交的申请号为201610019289.0、发明名称为“一种KVM虚拟化下处理I/O请求的方法和装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。The present application claims priority to Chinese Patent Application No. 201610019289.0, entitled "A Method and Apparatus for Processing I/O Requests under KVM Virtualization", filed on January 12, 2016, the entire contents of which are incorporated by reference. In this application.
技术领域Technical field
本申请涉及KVM虚拟化的技术领域,特别是涉及一种KVM虚拟化下处理I/O请求的方法和一种KVM虚拟化下处理I/O请求的装置。The present application relates to the technical field of KVM virtualization, and in particular to a method for processing an I/O request under KVM virtualization and a device for processing an I/O request under KVM virtualization.
背景技术Background technique
虚拟机(Virtual Machine)是指通过软件模拟的、具有完整硬件系统功能的,运行在一个完全隔离环境中的完整计算机系统。通过虚拟机软件,可以在一台物理计算机上模拟出一台或多台虚拟的计算机。虚拟机可以像真正的计算机那样进行工作,例如可以安装操作系统、安装应用程序、访问网络资源等等。通常,虚拟机所在的物理计算机称为宿主机(Host),虚拟机自身称为虚拟机(Guest)。Virtual Machine is a complete computer system that is simulated by software and has complete hardware system functions and runs in a completely isolated environment. With virtual machine software, one or more virtual computers can be simulated on a single physical computer. Virtual machines can work like real computers, such as installing an operating system, installing applications, accessing network resources, and more. Usually, the physical computer where the virtual machine is located is called the host, and the virtual machine itself is called the virtual machine (Guest).
KVM(Kernel-based Virtual Machine)即内核模式的虚拟机的简称,是一个开源的系统虚拟化模块,它使用Linux自身的调度器进行管理,KVM的虚拟化需要硬件支持(如Intel VT技术或者AMD VT技术)。KVM (Kernel-based Virtual Machine) is an open source system virtualization module that uses Linux's own scheduler for management. KVM virtualization requires hardware support (such as Intel VT technology or AMD). VT technology).
在现有技术中,在KVM虚拟化中,当虚拟机发生I/O操作时,支持VMX(Virtual Machine eXtensions,是intel实现的x86指令集虚拟化扩展)或者SVM(Secure Virtual Machine,是amd实现的x86指令集的虚拟化扩展)扩展的CPU就会停止执行,退出非根模式,进入根模式执行KVM代码。KVM根据退出的原因得知虚拟机需要进行I/O操作,于是从内核态退出至用户态的QEMU进程。In the prior art, in the KVM virtualization, when the virtual machine generates I/O operations, it supports VMX (Virtual Machine eXtensions, which is an x86 instruction set virtualization extension implemented by Intel) or SVM (Secure Virtual Machine, which is an amd implementation). The virtualization extension of the x86 instruction set) the extended CPU will stop executing, exit the non-root mode, and enter the root mode to execute the KVM code. KVM knows that the virtual machine needs to perform I/O operations according to the reason of the exit, so it exits from the kernel state to the QEMU process in the user state.
QEMU进程在初始化的时候映射了一块KVM的空间,KVM在退出前把I/O请求放在其中,QEMU从中拿到I/O请求之后将其分发给相应的I/O模拟设备,I/O模拟设备执行I/O模拟以后,QEMU重新调用IOCTL进入KVM内核态,KVM稍作处理后进入非根模式继续运行vCPU(虚拟处理器)。The QEMU process maps a KVM space during initialization. The KVM puts the I/O request in it before exiting. After the QEMU gets the I/O request, it distributes it to the corresponding I/O analog device, I/O. After the analog device performs the I/O simulation, QEMU calls the IOCTL to enter the KVM kernel state. After the KVM is slightly processed, it enters the non-root mode and continues to run the vCPU (virtual processor).
然而,发明人在实施上述I/O请求的模拟过程中,发现如下问题:However, the inventor found the following problems in the simulation of implementing the above I/O request:
1、模拟vCPU的时候QEMU通过一个vCPU的IOCTL进入到KVM内核态,发生I/O请求的时候要退出内核态回到QEMU用户态的VCPU线程进行模拟,因此,I/O模拟必须和 CPU模拟在同一个进程中,无法支持多个设备模拟进程。1. When simulating vCPU, QEMU enters the KVM kernel state through a vCPU IOCTL. When an I/O request occurs, it must exit the kernel state and return to the VCPU thread of the QEMU user state for simulation. Therefore, the I/O simulation must be CPU emulation is in the same process and cannot support multiple device emulation processes.
2、KVM已有的基于eventfd的I/O通知机制只能应用于写请求,且对所写数据不关心,只关心所写地址的场景,例如Virtio设备的队列通知寄存器写访问。这种机制不能传递I/O请求访问的实际地址和长度,也无法将读操作得到的数据传递给KVM。2, KVM's existing eventfd-based I / O notification mechanism can only be applied to write requests, and does not care about the data written, only concerned with the scene of the written address, such as the Virtio device's queue notification register write access. This mechanism does not pass the actual address and length of the I/O request access, nor can it pass the data from the read operation to the KVM.
3、如果要在不同线程中实现CPU模拟和设备I/O模拟,现在缺乏一种机制来同步IO模拟线程和VCPU线程。3. If you want to implement CPU emulation and device I/O emulation in different threads, there is currently no mechanism to synchronize IO emulation threads and VCPU threads.
发明内容Summary of the invention
鉴于上述问题,提出了本申请实施例以便提供一种克服上述问题或者至少部分地解决上述问题的一种KVM虚拟化下处理I/O请求的方法和相应的一种KVM虚拟化下处理I/O请求的装置。In view of the above problems, embodiments of the present application have been proposed in order to provide a method for processing I/O requests under KVM virtualization that overcomes the above problems or at least partially solves the above problems, and a corresponding KVM virtualization processing I/ O request device.
为了解决上述问题,本申请公开了一种KVM虚拟化下处理I/O请求的方法,所述方法包括:In order to solve the above problem, the present application discloses a method for processing an I/O request under KVM virtualization, the method comprising:
通过内核虚拟机KVM拦截虚拟机发出的I/O请求,确定与所述I/O请求对应的I/O通道的信息,其中,所述I/O通道具有对应的缓冲区,所述I/O通道的信息包括eventfd文件描述符;The I/O request sent by the virtual machine is intercepted by the kernel virtual machine KVM, and the information of the I/O channel corresponding to the I/O request is determined, wherein the I/O channel has a corresponding buffer, and the I/O The information of the O channel includes an eventfd file descriptor;
将所述I/O请求写入对应的I/O通道的缓冲区中;Writing the I/O request into a buffer of a corresponding I/O channel;
采用所述eventfd通知所述I/O通道对应的用户态进程;Notifying the user state process corresponding to the I/O channel by using the eventfd;
在所述用户态进程中,根据所述eventfd监听对应的I/O通道的事件,并从所述对应的I/O通道的缓冲区中获取I/O请求,对所述I/O请求执行I/O模拟,其中,所述用户态进程包括第一设备模拟进程以及与所述第一设备模拟进程独立的第二设备模拟进程。In the user state process, according to the eventfd, the event of the corresponding I/O channel is monitored, and an I/O request is obtained from the buffer of the corresponding I/O channel, and the I/O request is executed. An I/O simulation, wherein the user state process includes a first device emulation process and a second device emulation process independent of the first device emulation process.
优选地,所述在所述通过内核虚拟机KVM拦截虚拟机发出的I/O请求,确定与所述I/O请求对应的I/O通道的信息的步骤之前,还包括:Preferably, before the step of intercepting the I/O request sent by the virtual machine by the kernel virtual machine KVM and determining the information of the I/O channel corresponding to the I/O request, the method further includes:
采用所述第一设备模拟进程创建虚拟机,获得所述虚拟机的文件描述符;Creating a virtual machine by using the first device simulation process to obtain a file descriptor of the virtual machine;
采用所述第一设备模拟进程,基于所述虚拟机的文件描述符,创建虚拟处理器vCPU,获得所述vCPU的文件描述符;Using the first device simulation process, creating a virtual processor vCPU based on the file descriptor of the virtual machine, and obtaining a file descriptor of the vCPU;
采用所述第二设备模拟进程,创建eventfd文件描述符;Using the second device simulation process to create an eventfd file descriptor;
采用所述第二设备模拟进程,基于所述虚拟机的文件描述符,创建I/O通道,并将 所述I/O通道与所述eventfd文件描述符绑定,获得所述I/O通道的文件描述符;Using the second device simulation process to create an I/O channel based on the file descriptor of the virtual machine, and Binding the I/O channel to the eventfd file descriptor to obtain a file descriptor of the I/O channel;
采用所述第二设备模拟进程,对所述eventfd文件描述符进行监听;Using the second device simulation process to monitor the eventfd file descriptor;
采用所述第二设备模拟进程,基于所述I/O通道的文件描述符,为所述用户态进程映射所述I/O通道的缓冲区;Using the second device simulation process to map a buffer of the I/O channel for the user state process based on a file descriptor of the I/O channel;
采用所述第二设备模拟进程,基于所述I/O通道的文件描述符,为所述I/O通道绑定I/O地址区间。Using the second device emulation process, an I/O address interval is bound to the I/O channel based on a file descriptor of the I/O channel.
优选地,所述I/O请求包括I/O地址,所述通过内核虚拟机KVM拦截虚拟机发出的I/O请求,确定与所述I/O请求对应的I/O通道的信息的步骤包括:Preferably, the I/O request includes an I/O address, and the step of intercepting an I/O request sent by the virtual machine by the kernel virtual machine KVM, and determining information of the I/O channel corresponding to the I/O request include:
通过内核虚拟机KVM及Intel VT-d硬件技术拦截虚拟机的vCPU线程发出的I/O请求;Intercepting I/O requests from virtual machine vCPU threads through kernel virtual machine KVM and Intel VT-d hardware technology;
从所述I/O请求中提取对应的I/O地址;Extracting a corresponding I/O address from the I/O request;
确定所述I/O地址所属的I/O地址区间;Determining an I/O address interval to which the I/O address belongs;
通过所述I/O地址区间确定对应的I/O通道,并获取所述I/O通道对应的I/O通道的信息。And determining, by the I/O address interval, a corresponding I/O channel, and acquiring information of the I/O channel corresponding to the I/O channel.
优选地,所述I/O通道的地址区间包括多个I/O模拟设备的地址子区间;Preferably, the address interval of the I/O channel includes an address subinterval of a plurality of I/O analog devices;
所述在所述用户态进程中,根据所述eventfd确定对应的I/O通道,并从所述对应的I/O通道的缓冲区中获取I/O请求,对所述I/O请求执行I/O模拟的步骤包括:Determining, in the user state process, a corresponding I/O channel according to the eventfd, and acquiring an I/O request from a buffer of the corresponding I/O channel, performing the I/O request The steps of the I/O simulation include:
在所述用户态进程中,根据所述eventfd确定对应的I/O通道;In the user state process, determining a corresponding I/O channel according to the eventfd;
从所述对应的I/O通道的缓冲区中获取I/O请求;Obtaining an I/O request from a buffer of the corresponding I/O channel;
依据所述I/O请求中的I/O地址确定对应的I/O模拟设备;Determining a corresponding I/O analog device according to the I/O address in the I/O request;
将所述I/O请求分发至所述I/O模拟设备中,通过所述I/O模拟设备对所述I/O请求进行I/O模拟。Distributing the I/O request to the I/O analog device, and performing I/O simulation on the I/O request by the I/O analog device.
优选地,在所述在所述用户态进程中,根据所述eventfd确定对应的I/O通道,并从所述对应的I/O通道的缓冲区中获取I/O请求,对所述I/O请求执行I/O模拟的步骤之前,还包括:Preferably, in the user state process, determining a corresponding I/O channel according to the eventfd, and acquiring an I/O request from the buffer of the corresponding I/O channel, for the I Before /O requests to perform the I/O simulation steps, it also includes:
挂起所述vCPU线程。Suspend the vCPU thread.
优选地,在所述在所述用户态进程中,根据所述eventfd确定对应的I/O通道,并从所述对应的I/O通道的缓冲区中获取I/O请求,对所述I/O请求执行I/O模拟的步骤之后,还包括:Preferably, in the user state process, determining a corresponding I/O channel according to the eventfd, and acquiring an I/O request from the buffer of the corresponding I/O channel, for the I After the /O request to perform the I/O simulation steps, it also includes:
唤醒所述挂起的vCPU线程。 Wake up the suspended vCPU thread.
优选地,所述I/O请求包括读请求,所述将所述I/O请求分发至所述I/O模拟设备中,通过所述I/O模拟设备对所述I/O请求进行I/O模拟的步骤为:Preferably, the I/O request includes a read request, and the I/O request is distributed to the I/O analog device, and the I/O request is performed by the I/O analog device. The steps of the /O simulation are:
将所述读请求分发至所述I/O模拟设备中,通过所述I/O模拟设备将所述读请求对应的数据写入所述I/O通道的缓冲区中。And distributing the read request to the I/O analog device, and writing, by the I/O analog device, data corresponding to the read request into a buffer of the I/O channel.
优选地,所述方法还包括:Preferably, the method further includes:
若所述I/O请求为读请求,将所述读请求对应的数据从缓冲区中读出,读入到vCPU结构体中相应的成员变量中;If the I/O request is a read request, the data corresponding to the read request is read out from the buffer, and is read into a corresponding member variable in the vCPU structure;
对所述数据进行对应的模拟处理。Corresponding simulation processing is performed on the data.
本申请还公开了一种KVM虚拟化下处理I/O请求的装置,所述的装置包括:The present application also discloses an apparatus for processing an I/O request under KVM virtualization, the apparatus comprising:
I/O通道确定模块,用于通过内核虚拟机KVM拦截虚拟机发出的I/O请求,确定与所述I/O请求对应的I/O通道的信息,其中,所述I/O通道具有对应的缓冲区,所述I/O通道的信息包括eventfd文件描述符;An I/O channel determining module, configured to intercept, by the kernel virtual machine KVM, an I/O request sent by the virtual machine to determine information of an I/O channel corresponding to the I/O request, where the I/O channel has Corresponding buffer, the information of the I/O channel includes an eventfd file descriptor;
缓冲区写入模块,用于将所述I/O请求写入对应的I/O通道的缓冲区中;a buffer write module, configured to write the I/O request into a buffer of a corresponding I/O channel;
事件通知模块,用于采用所述eventfd通知所述I/O通道对应的用户态进程;An event notification module, configured to notify the user state process corresponding to the I/O channel by using the eventfd;
I/O模拟模块,用于在所述用户态进程中,根据所述eventfd监听对应的I/O通道的事件,并从所述对应的I/O通道的缓冲区中获取I/O请求,对所述I/O请求执行I/O模拟,其中,所述用户态进程包括第一设备模拟进程以及与所述第一设备模拟进程独立的第二设备模拟进程。An I/O simulation module, configured to: in the user state process, listen to an event of the corresponding I/O channel according to the eventfd, and obtain an I/O request from a buffer of the corresponding I/O channel, Performing an I/O simulation on the I/O request, wherein the user state process includes a first device emulation process and a second device emulation process independent of the first device emulation process.
优选地,所述装置还包括:Preferably, the device further comprises:
虚拟机创建模块,用于采用所述第一设备模拟进程创建虚拟机,获得所述虚拟机的文件描述符;a virtual machine creating module, configured to create a virtual machine by using the first device simulation process, and obtain a file descriptor of the virtual machine;
vCPU创建模块,用于采用所述第一设备模拟进程,基于所述虚拟机的文件描述符,创建虚拟处理器vCPU,获得所述vCPU的文件描述符;a vCPU creation module, configured to: use the first device simulation process, create a virtual processor vCPU based on a file descriptor of the virtual machine, and obtain a file descriptor of the vCPU;
eventfd创建模块,用于采用所述第二设备模拟进程,创建eventfd文件描述符;An eventfd creation module is configured to create an eventfd file descriptor by using the second device simulation process;
I/O通道创建模块,用于采用所述第二设备模拟进程,基于所述虚拟机的文件描述符,创建I/O通道,并将所述I/O通道与所述eventfd文件描述符绑定,获得所述I/O通道的文件描述符;An I/O channel creation module, configured to simulate a process by using the second device, create an I/O channel based on a file descriptor of the virtual machine, and bind the I/O channel to the eventfd file descriptor Determining, obtaining a file descriptor of the I/O channel;
监听模块,用于采用所述第二设备模拟进程,对所述eventfd文件描述符进行监听;a monitoring module, configured to monitor the eventfd file descriptor by using the second device simulation process;
缓冲区映射模块,用于采用所述第二设备模拟进程,基于所述I/O通道的文件描述 符,为所述用户态进程映射所述I/O通道的缓冲区;a buffer mapping module, configured to simulate the process by using the second device, based on a file description of the I/O channel a buffer for mapping the I/O channel to the user mode process;
地址区间绑定模块,用于采用所述第二设备模拟进程,基于所述I/O通道的文件描述符,为所述I/O通道绑定I/O地址区间。An address interval binding module is configured to bind an I/O address interval to the I/O channel based on a file descriptor of the I/O channel by using the second device simulation process.
优选地,所述I/O请求包括I/O地址,所述I/O通道确定模块包括:Preferably, the I/O request includes an I/O address, and the I/O channel determining module includes:
I/O请求拦截子模块,用于通过内核虚拟机KVM及Intel VT-d硬件技术拦截虚拟机的vCPU线程发出的I/O请求;An I/O request intercepting submodule for intercepting I/O requests from a virtual machine's vCPU thread through a kernel virtual machine KVM and an Intel VT-d hardware technology;
I/O地址提取子模块,用于从所述I/O请求中提取对应的I/O地址;An I/O address extraction submodule, configured to extract a corresponding I/O address from the I/O request;
第一I/O通道确定子模块,用于确定所述I/O地址所属的I/O地址区间,并通过所述I/O地址区间确定对应的I/O通道,并获取所述I/O通道对应的I/O通道的信息。a first I/O channel determining submodule, configured to determine an I/O address interval to which the I/O address belongs, and determine a corresponding I/O channel by using the I/O address interval, and acquire the I/ Information about the I/O channel corresponding to the O channel.
优选地,所述I/O通道的地址区间包括多个I/O模拟设备的地址子区间;Preferably, the address interval of the I/O channel includes an address subinterval of a plurality of I/O analog devices;
所述I/O模拟模块包括:The I/O simulation module includes:
第二I/O通道确定子模块,用于在所述用户态进程中,根据所述eventfd确定对应的I/O通道;a second I/O channel determining submodule, configured to determine, according to the eventfd, a corresponding I/O channel in the user state process;
I/O请求读取子模块,用于从所述对应的I/O通道的缓冲区中获取I/O请求;An I/O request reading submodule, configured to obtain an I/O request from a buffer of the corresponding I/O channel;
I/O模拟设备确定子模块,用于依据所述I/O请求中的I/O地址确定对应的I/O模拟设备;An I/O analog device determining submodule, configured to determine a corresponding I/O analog device according to an I/O address in the I/O request;
分发子模块,用于将所述I/O请求分发至所述I/O模拟设备中,通过所述I/O模拟设备对所述I/O请求进行I/O模拟。And a distribution submodule, configured to distribute the I/O request to the I/O simulation device, and perform I/O simulation on the I/O request by using the I/O simulation device.
优选地,所述装置还包括:Preferably, the device further comprises:
挂起模块,用于在采用所述eventfd通知所述I/O通道对应的用户态进程以后,挂起所述vCPU线程。Suspending a module, for suspending the vCPU thread after the userfest process corresponding to the I/O channel is notified by using the eventfd.
优选地,所述装置还包括:Preferably, the device further comprises:
唤醒模块,用于在对所述I/O请求执行I/O模拟以后,唤醒所述挂起的vCPU线程。And a wake-up module, configured to wake up the suspended vCPU thread after performing I/O simulation on the I/O request.
优选地,所述I/O请求包括读请求,所述分发子模块还用于:Preferably, the I/O request includes a read request, and the distribution sub-module is further configured to:
将所述读请求分发至所述I/O模拟设备中,通过所述I/O模拟设备将所述读请求对应的数据写入所述I/O通道的缓冲区中。And distributing the read request to the I/O analog device, and writing, by the I/O analog device, data corresponding to the read request into a buffer of the I/O channel.
优选地,所述装置还包括:Preferably, the device further comprises:
数据读出模块,用于在所述I/O请求为读请求时,将所述读请求对应的数据从缓冲区中读出,读入到vCPU结构体中相应的成员变量中,对所述数据进行对应的模拟处理。 a data reading module, configured to: when the I/O request is a read request, read data corresponding to the read request from a buffer, and read the corresponding member variable into the vCPU structure, The data is subjected to corresponding analog processing.
本申请实施例包括以下优点:Embodiments of the present application include the following advantages:
在本申请实施例中,可以通过I/O通道来传递I/O请求,当KVM拦截虚拟机发出的I/O请求以后,可以确定该I/O请求对应的I/O通道,并将I/O请求写入对应的I/O通道的缓冲区中,随后通过eventfd通知I/O通道对应的用户态进程,用户态进程监听到eventfd事件通知以后,从该eventfd对应的I/O通道的缓冲区中获取I/O请求,并对该I/O请求执行I/O模拟。本申请可以在内核态中实现I/O请求的分发,针对单个虚拟机可以支持多个设备模拟进程,提高了I/O模拟的效率。In the embodiment of the present application, the I/O request can be delivered through the I/O channel. After the KVM intercepts the I/O request sent by the virtual machine, the I/O channel corresponding to the I/O request can be determined, and the I/O channel is determined. /O request is written into the buffer of the corresponding I/O channel, and then the user state process corresponding to the I/O channel is notified by eventfd, and the user state process listens to the eventfd event notification, and the I/O channel corresponding to the eventfd Get an I/O request in the buffer and perform an I/O simulation on the I/O request. The application can realize the distribution of I/O requests in the kernel state, and can support multiple device simulation processes for a single virtual machine, thereby improving the efficiency of I/O simulation.
附图说明DRAWINGS
图1是本申请的一种KVM虚拟化下分发I/O请求的方法实施例一的步骤流程图;1 is a flow chart showing the steps of Embodiment 1 of a method for distributing an I/O request under KVM virtualization according to the present application;
图2是本申请的一种KVM虚拟化下分发I/O请求的方法实施例二的步骤流程图;2 is a flow chart of steps of a second embodiment of a method for distributing an I/O request in a KVM virtualization process according to the present application;
图3是本申请的一种KVM虚拟化下分发I/O请求的方法实施例二中的KVM初始化流程的步骤流程图;3 is a flow chart of steps of a KVM initialization process in Embodiment 2 of a method for distributing an I/O request in a KVM virtualization process according to the present application;
图4是本申请的种KVM虚拟化下处理I/O请求的装置实施例的结构框图。4 is a structural block diagram of an embodiment of an apparatus for processing an I/O request under the KVM virtualization of the present application.
具体实施方式detailed description
为使本申请的上述目的、特征和优点能够更加明显易懂,下面结合附图和具体实施方式对本申请作进一步详细的说明。The above described objects, features and advantages of the present application will become more apparent and understood.
参照图1,示出了本申请的一种KVM虚拟化下分发I/O请求的方法实施例一的步骤流程图,具体可以包括如下步骤:Referring to FIG. 1 , a flow chart of a first embodiment of a method for distributing an I/O request in a KVM virtualization process of the present application is shown, which may specifically include the following steps:
步骤101,通过内核虚拟机KVM拦截虚拟机发出的I/O请求,确定与所述I/O请求对应的I/O通道的信息,其中,所述I/O通道具有对应的缓冲区,所述I/O通道的信息包括事件通知创建eventfd文件描述符。Step 101: The I/O request sent by the virtual machine is intercepted by the kernel virtual machine KVM, and the information of the I/O channel corresponding to the I/O request is determined, where the I/O channel has a corresponding buffer. The information of the I/O channel includes an event notification to create an eventfd file descriptor.
步骤102,将所述I/O请求写入对应的I/O通道的缓冲区中。Step 102: Write the I/O request into a buffer of a corresponding I/O channel.
步骤103,采用所述eventfd通知所述I/O通道对应的用户态进程。Step 103: The eventfd is used to notify a user state process corresponding to the I/O channel.
步骤104,在所述用户态进程中,根据所述eventfd监听对应的I/O通道的事件,并从所述对应的I/O通道的缓冲区中获取I/O请求,对所述I/O请求执行I/O模拟。Step 104: In the user state process, according to the eventfd, the event of the corresponding I/O channel is monitored, and an I/O request is obtained from the buffer of the corresponding I/O channel, and the I/O request is performed. O requests to perform an I/O simulation.
其中,所述用户态进程包括第一设备模拟进程以及与所述第一设备模拟进程独立的第二设备模拟进程。The user state process includes a first device simulation process and a second device simulation process that is independent of the first device simulation process.
在本申请实施例中,可以通过I/O通道来传递I/O请求,当KVM拦截虚拟机发出的 I/O请求以后,可以确定该I/O请求对应的I/O通道,并将I/O请求写入对应的I/O通道的缓冲区中,随后通过eventfd通知I/O通道对应的用户态进程,用户态进程监听到eventfd事件通知以后,从该eventfd对应的I/O通道的缓冲区中读取I/O请求,并对该I/O请求执行I/O模拟。本申请可以在内核态中实现I/O请求的分发,针对单个虚拟机可以支持多个设备模拟进程,提高了I/O模拟的效率。In the embodiment of the present application, an I/O request can be delivered through an I/O channel, when the KVM intercepts the virtual machine. After the I/O request, the I/O channel corresponding to the I/O request can be determined, and the I/O request is written into the buffer of the corresponding I/O channel, and then the user corresponding to the I/O channel is notified by eventfd. The state process, after the user state process listens to the eventfd event notification, reads the I/O request from the buffer of the I/O channel corresponding to the eventfd, and performs I/O simulation on the I/O request. The application can realize the distribution of I/O requests in the kernel state, and can support multiple device simulation processes for a single virtual machine, thereby improving the efficiency of I/O simulation.
参照图2,示出了本申请的一种KVM虚拟化下处理I/O请求的方法实施例二的步骤流程图。其中,KVM(Kernel-based Virtual Machine,内核模式的虚拟机)是一个基于Linux环境的开源虚拟化解决方案。KVM的思想是在Linux内核的基础上添加虚拟机管理模块,重用Linux内核中已经完善的进程调度、内存管理、I/O管理等部分,使之成为一个可以支持运行虚拟机的超级管理程序Hypervisor。Referring to FIG. 2, a flow chart of steps of a second embodiment of a method for processing an I/O request under KVM virtualization according to the present application is shown. Among them, KVM (Kernel-based Virtual Machine) is an open source virtualization solution based on Linux environment. The idea of KVM is to add a virtual machine management module based on the Linux kernel, and reuse the well-established process scheduling, memory management, I/O management and other parts of the Linux kernel to make it a hypervisor that can support the running of virtual machines. .
KVM是基于硬件辅助虚拟化技术(例如:Intel的VT-x或者AMD-V)的全虚拟化解决方案,虚拟机操作系统能够不经过修改直接在KVM的虚拟机中运行,每一台虚拟机能够享有独立的虚拟硬件资源:网卡、磁盘、图形适配器等。KVM is a fully virtualized solution based on hardware-assisted virtualization technology (eg Intel's VT-x or AMD-V). The virtual machine operating system can be run directly in the KVM virtual machine without modification. Each virtual machine Ability to enjoy independent virtual hardware resources: network cards, disks, graphics adapters, and more.
KVM可以作为单独的模块编译进内核中,也可以作为内核模块在Linux系统启动完成之后加载。KVM can be compiled into the kernel as a separate module, or it can be loaded as a kernel module after the Linux system is booted.
KVM的API是通过/dev/kvm设备进行访问的。/dev/kvm是一个字符型设备,其可以使用常见的系统调用如open、close、IOCTL等指令进行操作。因为KVM的字符型设备的实现函数中,没有包含write、read等操作,所以所有对KVM的操作都是通过IOCTL发送相应的控制字实现的。The KVM API is accessed via the /dev/kvm device. /dev/kvm is a character device that can be manipulated using common system calls such as open, close, IOCTL, and so on. Because the implementation function of the KVM character device does not include write, read, etc., all operations on the KVM are implemented by the IOCTL sending the corresponding control word.
KVM所提供的用户空间API从功能上划分,可以分为三种类型,分别为system指令、VM指令以及vCPU指令。其中,system指令针对虚拟化系统的全局性参数设置和用于虚拟机创建等控制操作;VM指令针对具体的VM虚拟机进行控制,如进行内存设置、创建vCPU等;vCPU指令针对具体的vCPU进行参数设置(MRU寄存器读写、中断控制等)。The user space API provided by KVM is functionally divided into three types, namely system instruction, VM instruction, and vCPU instruction. The system instruction is for the global parameter setting of the virtualization system and the control operation for the virtual machine creation; the VM instruction controls the specific VM virtual machine, such as performing memory setting, creating a vCPU, etc.; the vCPU instruction is performed for a specific vCPU. Parameter setting (MRU register read/write, interrupt control, etc.).
在发明实施例中,可以通过不同的用户态模拟器来控制用户空间,从而可以在不同的用户态进程中模拟同一台虚拟机的设备I/O,支持针对单个虚拟机的多个设备模拟进程。该不同的用户态进程可以包括第一设备模拟进程以及第二设备模拟进程,作为本申请实施例的一种优选示例,第一设备模拟进程可以为QEMU(全称Quick Emulator)进程,所述第二设备模拟进程可以为独立于QEMU进程的I/O设备模拟进程,为方便后续的描述,可以将该第二设备模拟进程称为DEMU(Dedicated Emulator)进程或DEMU。 In an embodiment of the invention, user space can be controlled by different user mode simulators, so that device I/Os of the same virtual machine can be simulated in different user state processes, and multiple device simulation processes for a single virtual machine can be supported. . The different user mode process may include a first device simulation process and a second device simulation process. As a preferred example of the embodiment of the present application, the first device simulation process may be a QEMU (full name Quick Emulator) process, and the second The device simulation process can simulate a process for an I/O device that is independent of the QEMU process. To facilitate subsequent description, the second device simulation process can be referred to as a DEMU (Dedicated Emulator) process or a DEMU.
其中,QEMU是一款开源的模拟器及虚拟机监管器(Virtual Machine Monitor,VMM),用户可以通过不同Linux发行版所带有的软件包管理器来安装QEMU。QEMU在主机用户态模拟虚拟机的硬件设备,QEMU作为系统模拟器时,可以模拟出一台能够独立运行操作系统的虚拟机,每个虚拟机对应主机(Host)中的一个QEMU进程,而虚拟机的vCPU对应QEMU进程的一个线程。Among them, QEMU is an open source simulator and virtual machine monitor (VMM), users can install QEMU through the package manager of different Linux distributions. QEMU simulates the hardware device of the virtual machine in the host user mode. When QEMU is used as the system simulator, it can simulate a virtual machine that can run the operating system independently. Each virtual machine corresponds to a QEMU process in the host (Host), and virtual The vCPU of the machine corresponds to one thread of the QEMU process.
在具体实现中,可以通过执行QEMU和DEMU的二进制可执行文件来创建QEMU进程与DEMU进程,并可以通过脚本或者libvirt工具启动这两个进程。In a specific implementation, the QEMU process and the DEMU process can be created by executing the binary executable files of QEMU and DEMU, and the two processes can be started by a script or a libvirt tool.
应用于本申请实施例,在对I/O请求进行处理之前,首先执行初始化流程。在平台相关的KVM模块中通过module_init宏正式进入KVM的初始化阶段,并且执行相关的硬件初始化准备。进入kvm_main.c中的kvm_init函数进行正式的初始化工作。Applied to the embodiment of the present application, the initialization process is first performed before the I/O request is processed. In the platform-related KVM module, the module_init macro officially enters the initialization phase of the KVM, and performs related hardware initialization preparation. Enter the kvm_init function in kvm_main.c for formal initialization.
参考图3的KVM初始化流程的步骤流程图,所述初始化流程至少可以包括如下步骤:Referring to the flowchart of the steps of the KVM initialization process of FIG. 3, the initialization process may at least include the following steps:
子步骤S1,采用所述第一设备模拟进程创建虚拟机,获得所述虚拟机的文件描述符。Sub-step S1: Create a virtual machine by using the first device simulation process to obtain a file descriptor of the virtual machine.
具体的,KVM同用户空间进程的交互接口为/dev/kvm,对于KVM API的操作是从打开/dev/kvm设备文件开始的,通过使用系统调用open方法之后,可以获得针对kvm subsystem的一个fd文件描述符。然后通过IOCTL系统指令针对该文件描述符进行进一步的操作。Specifically, the interaction interface between the KVM and the user space process is /dev/kvm, and the operation of the KVM API is started by opening the /dev/kvm device file. After using the system call open method, an fd for the kvm subsystem can be obtained. File descriptor. Further operations on the file descriptor are then performed by the IOCTL system instructions.
IOCTL系统指令可以包括KVM_CREATE_VM指令,通过KVM_CREATE_VM指令,即可创建一个虚拟机VM。通过调用anon_inode_getfd可以获得一fd文件描述符,作为虚拟机的文件描述符,即vm_fd,该vm_fd指向内核空间中该新创建的虚拟机,然后根据该描述符来控制虚拟机的行为。The IOCTL system instructions can include the KVM_CREATE_VM instruction, which creates a virtual machine VM with the KVM_CREATE_VM instruction. An fd file descriptor can be obtained by calling anon_inode_getfd as a file descriptor of the virtual machine, ie vm_fd, which points to the newly created virtual machine in the kernel space, and then controls the behavior of the virtual machine according to the descriptor.
vm IOCTL系统调用实现了对虚拟机的控制。vm IOCTL控制指令的参数大多需要从KVM_CREATE_VM中返回的vm_fd来进行操作,涉及的操作主要针对该虚拟机进行控制,如配置内存、配置vCPU等。The vm IOCTL system call implements control of the virtual machine. Most of the parameters of the vm IOCTL control instruction need to be operated from the vm_fd returned by KVM_CREATE_VM. The operations involved are mainly for the virtual machine, such as configuring memory and configuring vCPU.
针对VM的文件操作中,提供了IOCTL和mmap两个操作函数,其中mmap对应着客户操作系统GUEST OS的物理地址,可以直接对GUEST OS的地址空间进行读/写,IOCTL则用于发送KVM的控制字。For the file operation of the VM, two operation functions, IOCTL and mmap, are provided, wherein mmap corresponds to the physical address of the guest operating system GUEST OS, and the address space of the GUEST OS can be read/written directly, and the IOCTL is used to send the KVM. Control word.
应用于本申请实施例,还可以对该创建的虚拟机设置对应的通用唯一识别码UUID,以通过该UUID识别虚拟机。In the embodiment of the present application, a corresponding universal unique identifier UUID may be set for the created virtual machine to identify the virtual machine by using the UUID.
虚拟机的创建过程实质为KVM结构体的创建和初始化过程,在创建虚拟机时,kvm_dev_IOCTL_create_vm函数通过调用kvm_create_vm函数对KVM结构体进行创建。 The creation process of the virtual machine is essentially the creation and initialization process of the KVM structure. When creating the virtual machine, the kvm_dev_IOCTL_create_vm function creates the KVM structure by calling the kvm_create_vm function.
KVM结构体保存了虚拟机运行的上下文及其他相关状态,例如,可以包括vCPU(虚拟处理器,虚拟机内的CPU)、内存、APIC(Advanced Programmable Interrupt Controller,高级可编程中断控制器)、IRQ(Interrupt Request,中断请求)、MMU(Memory Management Unit,内存管理单元)、Event事件管理等信息,应用于本申请实施例,该KVM结构体还可以包括虚拟机的UUID。The KVM structure saves the context and other related states of the virtual machine running. For example, it can include vCPU (virtual processor, CPU in virtual machine), memory, APIC (Advanced Programmable Interrupt Controller), IRQ. The information of the (Interrupt Request), the MMU (Memory Management Unit), and the Event Event Management is applied to the embodiment of the present application. The KVM structure may further include a UUID of the virtual machine.
KVM结构体的初始化过程,可以包括:初始化KVM的memslot结构体、Bus总线结构体信息、scru读/写锁信息、eventfd事件通知信息、mmu内存管理结构体信息等。The initialization process of the KVM structure may include: initializing a KVM memslot structure, a Bus bus structure information, a scru read/write lock information, an eventfd event notification information, an mmu memory management structure information, and the like.
虚拟机的KVM结构体创建完成以后,可以将其加入到全局链表vm_list中。After the virtual machine's KVM structure is created, it can be added to the global linked list vm_list.
在本申请实施例中,可以使用QEMU进程完成虚拟机的创建。In the embodiment of the present application, the creation of a virtual machine may be completed by using a QEMU process.
步骤S2,采用所述第一设备模拟进程,基于所述虚拟机的文件描述符,创建虚拟处理器vCPU,获得所述vCPU的文件描述符。Step S2: Using the first device simulation process, create a virtual processor vCPU based on the file descriptor of the virtual machine, and obtain a file descriptor of the vCPU.
具体的,全新创建的虚拟机没有vCPU,需要通过后续的IOCTL指令进行配置。在获得vm_fd之后,通过IOCTL调用KVM_CREATE_vCPU指令,可以对该vm_fd对应的虚拟机创建vCPU,其入口函数地址在kvm_vm_IOCTL函数中,通过switch之后,程序流程将选择进入kvm_vm_IOCTL_create_vCPU函数中进行处理,返回该vCPU对应的文件描述符fd,即vCPU_fd,在KVM虚拟化环境中,硬件虚拟化使用vCPU_fd来描述vCPU。Specifically, the newly created virtual machine does not have a vCPU and needs to be configured through subsequent IOCTL instructions. After obtaining vm_fd, the KVM_CREATE_vCPU instruction is invoked by the IOCTL, and the vCPU can be created for the virtual machine corresponding to the vm_fd. The entry function address is in the kvm_vm_IOCTL function. After the switch, the program flow is selected to enter the kvm_vm_IOCTL_create_vCPU function for processing, and the vCPU is returned. The file descriptor fd, vCPU_fd, in the KVM virtualization environment, hardware virtualization uses vCPU_fd to describe the vCPU.
在KVM中,vCPU对应的数据结构体为kvm_vCPU,vCPU的创建过程实质为kvm_vCPU结构体的创建和初始化过程,可以包括如下过程:调用kvm_arch_vCPU_create函数创建一个kvm_vCPU结构体;调用kvm_arch_vCPU_setup函数对kvm_vCPU中的数据结构进行初始化;创建当前vCPU对应的文件描述符vCPU_fd,并且将kvm_vCPU添加入KVM的vCPU数组中。In KVM, the data structure corresponding to vCPU is kvm_vCPU. The creation process of vCPU is essentially the creation and initialization process of kvm_vCPU structure. It can include the following process: call kvm_arch_vCPU_create function to create a kvm_vCPU structure; call kvm_arch_vCPU_setup function to data in kvm_vCPU The structure is initialized; the file descriptor vCPU_fd corresponding to the current vCPU is created, and the kvm_vCPU is added to the vCPU array of the KVM.
在本申请实施例中,可以使用QEMU进程完成vCPU的创建,每个vCPU对应一个vCPU线程。In the embodiment of the present application, the creation of the vCPU may be completed by using a QEMU process, and each vCPU corresponds to one vCPU thread.
步骤S3,采用所述第二设备模拟进程,创建eventfd文件描述符。Step S3, using the second device simulation process to create an eventfd file descriptor.
应用于本申请实施例,可以采用DEMU进程调用标准的Linux系统API eventfd()来创建eventfd文件描述符。具体来说,eventfd()是Linux系统提供的系统接口,函数原型是int eventfd(unsigned int initval,int flags),调用这个函数用户态进程可以获取一个eventfd文件描述符,同时在内核中创建一个eventfd对象用于实现等待和通知的机制,主要用于用户态互相通知,和内核态向用户态的通知。Applied to the embodiment of the present application, the DEMF process can call the standard Linux system API eventfd() to create an eventfd file descriptor. Specifically, eventfd() is the system interface provided by the Linux system. The function prototype is int eventfd (unsigned int initval, int flags). Calling this function user state process can obtain an eventfd file descriptor and create an eventfd in the kernel. The mechanism used by the object to implement wait and notification is mainly used for user state mutual notification and notification of kernel mode to user mode.
eventfd对象中可以包含一个64位的整形变量作为计数器,函数原型中传入的参数 initval用于初始化这个计数器。eventfd文件描述符用于用户态引用eventfd对象,用户态进程可以对eventfd文件描述符进行read,write,poll,select操作。The eventfd object can contain a 64-bit integer variable as a counter, the parameters passed in the function prototype. Initval is used to initialize this counter. The eventfd file descriptor is used to reference the eventfd object in user mode. The user state process can perform read, write, poll, and select operations on the eventfd file descriptor.
步骤S4,采用所述第二设备模拟进程,基于所述虚拟机文件描述符,创建I/O通道,并将所述I/O通道与所述eventfd文件描述符绑定,获得所述I/O通道的文件描述符。Step S4, using the second device simulation process, creating an I/O channel based on the virtual machine file descriptor, and binding the I/O channel with the eventfd file descriptor to obtain the I/ The file descriptor of the O channel.
应用于本申请实施例,还可以采用DEMU进程来创建虚拟机的一个或多个I/O通道。Applied to the embodiment of the present application, the DEMU process may also be used to create one or more I/O channels of the virtual machine.
具体来说,DEMU进程可以获得当前虚拟机的UUID,然后在全局链表vm_list中查找该虚拟机的UUID,若查找成功,则获得对应的KVM结构体,从而获得虚拟机的文件描述符vm_fd,之后,可以通过vm_fd新增的IOCTL指令(例如,KVM_CREATE_IOCH指令)对该vm_fd对应的虚拟机创建I/O通道。创建I/O通道的时候,会生成I/O通道与eventfd的绑定关系,随后返回I/O通道的文件描述符,即I/O_fd,I/O通道的文件描述符提供IOCLT指令给用户态进程,每个vm_fd可挂载多个I/O_fd。Specifically, the DEMU process can obtain the UUID of the current virtual machine, and then find the UUID of the virtual machine in the global linked list vm_list. If the search succeeds, the corresponding KVM structure is obtained, thereby obtaining the file descriptor vm_fd of the virtual machine, and then An I/O channel can be created for the virtual machine corresponding to the vm_fd by the new IOCTL instruction (for example, the KVM_CREATE_IOCH instruction). When the I/O channel is created, the binding relationship between the I/O channel and eventfd is generated, and then the file descriptor of the I/O channel is returned, that is, I/O_fd, and the file descriptor of the I/O channel provides the IOCLT instruction to the user. State processes, each vm_fd can mount multiple I / O_fd.
在KVM中,I/O通道的创建过程实质为I/O通道的结构体的创建和初始化过程,I/O通道的结构体可以包括:一个eventfd,用于内核态向用户态的通知;一组存放I/O请求的缓冲区及其保护锁;一个保存所有此通道负责传递的I/O地址空间的链表。In KVM, the creation process of the I/O channel is essentially the process of creating and initializing the structure of the I/O channel. The structure of the I/O channel may include: an eventfd for notification of the kernel state to the user state; The group stores the buffer of the I/O request and its protection lock; a linked list that holds all the I/O address spaces that this channel is responsible for.
应用于本申请实施例,在虚拟环境中,每个虚拟机对应的KVM结构体还可以新增一个链表,用于保存所有注册在该虚拟机上的I/O通道。Applicable to the embodiment of the present application, in the virtual environment, the KVM structure corresponding to each virtual machine may further add a linked list for storing all I/O channels registered on the virtual machine.
需要说明的是,每个I/O模拟进程仅需要且对应一个I/O通道。It should be noted that each I/O simulation process only needs one and corresponds to one I/O channel.
子步骤S5,采用所述第二设备模拟进程,对所述eventfd文件描述符进行监听。Sub-step S5, monitoring the eventfd file descriptor by using the second device simulation process.
在具体实现中,可以在进程主循环中对eventfd文件描述符使用poll或者select方法,一旦发现该eventfd文件描述符有待处理的I/O,就调用相关的处理函数,以实现对eventfd的监听。In a specific implementation, the poll or select method may be used on the eventfd file descriptor in the process main loop. Once the eventfd file descriptor is found to have an I/O to be processed, the relevant processing function is called to implement the monitoring of the eventfd.
步骤S6,采用所述第二设备模拟进程,基于所述I/O通道的文件描述符,为所述用户态进程映射所述I/O通道的缓冲区。Step S6: The second device emulation process is used to map a buffer of the I/O channel for the user state process based on a file descriptor of the I/O channel.
在具体实现中,KVM会在内核态为全新创建的I/O通道分配一段缓冲区,随后,用户态程序可以对I/O通道的文件描述符使用mmap()系统调用,映射该I/O通道的缓冲区,则用户态进程可以访问该缓冲区。In a specific implementation, KVM allocates a buffer to the newly created I/O channel in the kernel state. Subsequently, the user mode program can use the mmap() system call on the file descriptor of the I/O channel to map the I/O. The buffer of the channel, which can be accessed by user-mode processes.
所述缓冲区还具有保护锁,以保证对该缓冲区读写访问互斥性。The buffer also has a protection lock to ensure mutual access to the buffer for read and write access.
步骤S7,采用所述第二设备模拟进程,基于所述I/O通道的文件描述符,为所述I/O通道绑定I/O地址区间。Step S7, using the second device simulation process, binding an I/O address interval to the I/O channel based on a file descriptor of the I/O channel.
应用本申请实施例,还可以采用DEMU进程通过I/O通道的文件描述符为需要监听 的I/O通道绑定I/O地址区间,不同的I/O通道具有不同的I/O地址区间,例如,针对I/O地址区间1~1000,可以将1~300绑定给I/O通道A,将301~1000绑定给I/O通道B。Applying the embodiment of the present application, the DEMU process can also use the file descriptor of the I/O channel to monitor The I/O channel is bound to the I/O address range. Different I/O channels have different I/O address ranges. For example, for I/O address range 1 to 1000, you can bind 1 to 300 to I/. O channel A, binds 301 to 1000 to I/O channel B.
在具体实现中,该I/O通道的地址区间还可以包括多个地址子区间,每个地址子区间对应一个I/O模拟设备(一个IO模拟进程可以模拟多个IO模拟设备),每个I/O模拟设备只模拟落在其地址区间范围内的请求。例如,I/O通道A的地址区间为1~300,其中,1~100可以对应I/O模拟设备1,101~200可以对应I/O模拟设备2,201~300可以对应I/O模拟设备3。In a specific implementation, the address range of the I/O channel may further include multiple address sub-intervals, each of which corresponds to an I/O analog device (an IO simulation process can simulate multiple IO analog devices), each I/O analog devices only simulate requests that fall within their address range. For example, the address range of I/O channel A is 1 to 300, where 1 to 100 can correspond to I/O analog device 1, 101 to 200 can correspond to I/O analog device 2, and 201 to 300 can correspond to I/O simulation. Device 3.
在本申请实施例中,在原有的QEMU进程的基础上,新增独立的DEMU进程,两者作为用户态模拟器,能够共享虚拟机的一部分底层数据结构。In the embodiment of the present application, on the basis of the original QEMU process, an independent DEMU process is added, and the two function as a user state simulator can share a part of the underlying data structure of the virtual machine.
在完成初始化流程以后,如图2所示,本申请实施例具体可以包括如下步骤:After the initialization process is completed, as shown in FIG. 2, the embodiment of the present application may specifically include the following steps:
步骤201,通过内核虚拟机KVM拦截虚拟机的虚拟处理器vCPU线程发出的I/O请求,确定与所述I/O请求对应的I/O通道的信息。Step 201: The I/O request sent by the virtual processor vCPU thread of the virtual machine is intercepted by the kernel virtual machine KVM, and the information of the I/O channel corresponding to the I/O request is determined.
KVM可以拦截虚拟机的I/O操作,并根据拦截的I/O操作确定对应的I/O通道的信息。The KVM can intercept the virtual machine's I/O operations and determine the corresponding I/O channel information based on the intercepted I/O operations.
在本申请实施例的一种优选实施例中,步骤201可以包括如下子步骤:In a preferred embodiment of the embodiment of the present application, step 201 may include the following sub-steps:
子步骤1:通过内核虚拟机KVM及Intel VT-d硬件技术拦截虚拟机的虚拟处理器vCPU线程发出的I/O请求。Sub-step 1: Intercept the I/O request from the virtual machine's virtual processor vCPU thread through the kernel virtual machine KVM and Intel VT-d hardware technology.
在具体实现中,KVM在内核空间非根模式下运行vCPU线程,当vCPU线程发起I/O请求时,该敏感指令将会触发Intel VT-d硬件技术的VM exit操作,进入根模式下KVM相应的处理函数。In a specific implementation, KVM runs a vCPU thread in kernel space non-root mode. When the vCPU thread initiates an I/O request, the sensitive instruction will trigger the VM exit operation of the Intel VT-d hardware technology, and enter the KVM corresponding to the root mode. Processing function.
具体的,当虚拟机运行时(虚拟机的运行通过/dev/kvm设备IOCTL vCPU接口的KVM_RUN指令实现),触发VM Entry,使虚拟机进入客户Guest模式,即non root模式。而当在虚拟机中(Guest模式)执行特权指令或者外部事件,比如I/O访问,对控制寄存器的操作,MSR的读写数据包到达等时,可以触发(由硬件触发)VM Exit,使当前CPU从Guest模式(非根non-root模式)退出,切换到根root模式,当前CPU的控制权随之转交给KVM,由KVM进行相应的处理。Specifically, when the virtual machine is running (the virtual machine is running through the KVM_RUN instruction of the /dev/kvm device IOCTL vCPU interface), the VM Entry is triggered, and the virtual machine enters the guest guest mode, that is, the non-root mode. When a privileged instruction or an external event, such as an I/O access, an operation of a control register, an MSR read/write packet arrives, etc., is executed in a virtual machine (Guest mode), a VM Exit can be triggered (triggered by hardware). The current CPU exits from the guest mode (non-root non-root mode), switches to the root root mode, and the control of the current CPU is transferred to the KVM, which is processed by the KVM.
KVM取得控制权以后,通过读取VMCS中VM_EXIT_REASON字段得到引起VM Exit的原因,KVM根据退出的原因得知虚拟机需要进行I/O操作。After the KVM obtains control, the VM_EXIT_REASON field in the VMCS is read to obtain the cause of the VM Exit. The KVM knows that the virtual machine needs to perform I/O operations according to the reason of the exit.
子步骤2:从所述I/O请求中提取对应的I/O地址。 Sub-step 2: Extract the corresponding I/O address from the I/O request.
I/O请求中可以携带发出I/O请求的虚拟机的地址信息,当获得I/O请求以后,可以从该I/O请求中提取对应的I/O地址。The I/O request may carry the address information of the virtual machine that issues the I/O request, and after obtaining the I/O request, the corresponding I/O address may be extracted from the I/O request.
子步骤3:确定所述I/O地址所属的I/O地址区间。Sub-step 3: Determine the I/O address range to which the I/O address belongs.
子步骤4:通过所述I/O地址区间确定对应的I/O通道,并获取所述I/O通道对应的I/O通道的信息。Sub-step 4: determining a corresponding I/O channel by using the I/O address interval, and acquiring information of an I/O channel corresponding to the I/O channel.
由于I/O通道具有I/O地址区间,因此可以首先判断该I/O请求的I/O地址属于哪个地址区间,然后根据匹配的地址区间确定对应的I/O通道,并确定该I/O通道对应的缓冲区、eventfd文件描述符等信息。Since the I/O channel has an I/O address interval, it can first determine which address interval the I/O address of the I/O request belongs to, and then determine the corresponding I/O channel according to the matched address interval, and determine the I/. Information about the buffer corresponding to the O channel, the eventfd file descriptor, and so on.
步骤202,将所述I/O请求写入对应的I/O通道的缓冲区中。Step 202: Write the I/O request into a buffer of a corresponding I/O channel.
确定该I/O请求对应的I/O通道通道以后,KVM可以将该I/O请求写入该对应的I/O通道的缓冲区中,从而在KVM中完成I/O请求的分发。After determining the I/O channel channel corresponding to the I/O request, the KVM can write the I/O request into the buffer of the corresponding I/O channel, thereby completing the distribution of the I/O request in the KVM.
步骤203,采用所述eventfd通知所述I/O通道对应的用户态进程。Step 203: The eventfd is used to notify a user state process corresponding to the I/O channel.
在具体实现中,在内核空间中将I/O请求写入对应的I/O通道的缓冲区时,用户空间对此并不知情,因此需要内核空间通过eventfd向用户空间发出通知,用户态进程通过监听该eventfd从而获知其对应的I/O通道的缓冲区中写入了I/O请求。In the specific implementation, when the I/O request is written into the buffer of the corresponding I/O channel in the kernel space, the user space does not know about this, so the kernel space needs to send a notification to the user space through eventfd, the user state process. By listening to the eventfd, it is known that an I/O request is written in the buffer of its corresponding I/O channel.
步骤204,挂起所述vCPU线程。 Step 204, suspending the vCPU thread.
应用于本申请实施例,由于I/O请求通过I/O通道上传到I/O通道的缓冲区中,由I/O模拟线程进行I/O模拟,而I/O模拟线程与vCPU线程可以处于不同的进程中,因此发生I/O请求的时候无需退出vCPU线程,此时只需要挂起vCPU线程,并等待用户态进程的完成I/O请求后再将其唤醒。Applicable to the embodiment of the present application, since the I/O request is uploaded to the buffer of the I/O channel through the I/O channel, the I/O simulation thread performs I/O simulation, and the I/O simulation thread and the vCPU thread can It is in a different process, so there is no need to exit the vCPU thread when an I/O request occurs. At this time, only the vCPU thread needs to be suspended, and wait for the user state process to complete the I/O request and then wake it up.
步骤205,在所述用户态进程中,根据所述eventfd监听对应的I/O通道的事件,并从所述对应的I/O通道的缓冲区中获取I/O请求,对所述I/O请求执行I/O模拟。Step 205: In the user state process, according to the eventfd, the event of the corresponding I/O channel is monitored, and an I/O request is obtained from the buffer of the corresponding I/O channel, and the I/O request is performed. O requests to perform an I/O simulation.
当内核态向用户态发出eventfd事件通知时,用户态进程可以监听到eventfd事件通知,相应的处理函数被调用,通过用户态进程进行I/O模拟,其中,I/O模拟主要指的是针对虚拟机进行的I/O操作,通过软件的模拟行为使其获得一个对应的处理结果。When the kernel state issues an eventfd event notification to the user state, the user state process can listen to the eventfd event notification, and the corresponding processing function is called to perform I/O simulation through the user state process, wherein the I/O simulation mainly refers to The I/O operation performed by the virtual machine obtains a corresponding processing result through the simulation behavior of the software.
在本申请实施例的一种优选实施例中,步骤205可以包括如下子步骤:In a preferred embodiment of the embodiment of the present application, step 205 may include the following sub-steps:
子步骤1:在所述用户态进程中,根据所述eventfd确定对应的I/O通道。Sub-step 1: In the user state process, the corresponding I/O channel is determined according to the eventfd.
由于eventfd与I/O通道是绑定的,当用户态进程监听到eventfd进程注册的函数被调用以后,可以根据eventfd与I/O通道的对应关系,确定与eventfd对应的I/O通道。 Since the eventfd is bound to the I/O channel, after the user state process listens to the function registered by the eventfd process, the I/O channel corresponding to the eventfd can be determined according to the correspondence between the eventfd and the I/O channel.
子步骤2:从所述对应的I/O通道的缓冲区中获取I/O请求。Sub-step 2: Obtain an I/O request from the buffer of the corresponding I/O channel.
当确定I/O通道以后,可以进一步从已经映射的该I/O通道的缓冲区中读出I/O请求。After determining the I/O channel, the I/O request can be further read from the buffer of the I/O channel that has been mapped.
子步骤3:依据所述I/O请求中的I/O地址确定对应的I/O模拟设备。Sub-step 3: Determine the corresponding I/O analog device according to the I/O address in the I/O request.
子步骤4:将所述I/O请求分发至所述I/O模拟设备中,通过所述I/O模拟设备对所述I/O请求进行I/O模拟。Sub-step 4: Distributing the I/O request to the I/O analog device, and performing I/O simulation on the I/O request by the I/O analog device.
由于I/O通道的地址空间中包含一个或多个I/O模拟设备的地址子区间,当用户态进程获得I/O请求以后,可以根据该I/O请求中携带的I/O地址,确定该I/O地址所属的地址子区间,并根据该地址子区间确定对应的I/O模拟设备,以及将该I/O请求分发至该对应的I/O模拟设备中,以完成I/O请求的进一步二次分发。Since the address space of the I/O channel includes an address subinterval of one or more I/O analog devices, after the user state process obtains the I/O request, it can be based on the I/O address carried in the I/O request. Determining an address subinterval to which the I/O address belongs, and determining a corresponding I/O analog device according to the address subinterval, and distributing the I/O request to the corresponding I/O analog device to complete I/ Further secondary distribution of O requests.
I/O模拟设备获得I/O请求以后,对该I/O请求进行I/O模拟。After the I/O analog device obtains the I/O request, it performs I/O simulation on the I/O request.
在一种实施方式中,若该I/O请求为读请求,则该请求对应的I/O模拟设备可以将该读请求对应的数据写入I/O通道的缓冲区中,从而完成用户空间中的I/O模拟。In an implementation manner, if the I/O request is a read request, the I/O emulation device corresponding to the request may write the data corresponding to the read request into a buffer of the I/O channel, thereby completing the user space. I/O simulation in .
在另一种实施方式中,若该I/O请求为写请求,则该请求对应的I/O模拟设备可以将该写请求对应的数据写入对应的位置中,例如写入到了主机中的一个镜像文件中,从而完成用户空间中的I/O模拟。In another implementation manner, if the I/O request is a write request, the I/O emulation device corresponding to the request may write the data corresponding to the write request into a corresponding location, for example, written in the host. An image file that completes the I/O simulation in user space.
步骤206,唤醒所述挂起的vCPU线程。 Step 206, waking up the suspended vCPU thread.
I/O模拟完成后,用户态进程调用I/O通道的文件描述符中的新增IOCTL指令进入KVM内核态,唤醒该挂起的vCPU线程,以继续运行vCPU线程,达到vCPU线程与I/O模拟线程的同步,也就是说,用户态向内核态的通知是通过对vCPU线程的挂起与唤醒来实现的。After the I/O simulation is completed, the user state process calls the new IOCTL instruction in the file descriptor of the I/O channel to enter the KVM kernel state, wake up the suspended vCPU thread, and continue to run the vCPU thread to reach the vCPU thread and I/. O simulates the synchronization of threads, that is, the notification of the user state to the kernel state is achieved by suspending and waking up the vCPU thread.
在一种实施方式中,若该I/O请求为读请求,在唤醒vCPU线程之后,还可以将该读请求对应的数据从缓冲区中读出,读入到vCPU结构体中相应的成员变量中,并通过原有的I/O模拟代码进行后续的模拟处理。In an embodiment, if the I/O request is a read request, after the vCPU thread is woken up, the data corresponding to the read request may be read out from the buffer and read into a corresponding member variable in the vCPU structure. In the middle, and through the original I / O simulation code for subsequent simulation processing.
eventfd的使用结合缓冲区的使用,可以在缓冲区中传递I/O请求访问的实际地址和长度,并将读操作得到的数据通过缓冲区传递给KVM,克服现有技术的缺陷。The use of eventfd combined with the use of the buffer, can pass the actual address and length of the I / O request access in the buffer, and pass the data obtained by the read operation to the KVM through the buffer, overcoming the shortcomings of the prior art.
在对I/O请求处理完成以后,可以通过硬件指令(如VMLAUNCH),触发VM Enter,重新进入到Guest模式,从而进入虚拟机运行环境中继续运行。After the processing of the I/O request is completed, the VM Enter can be triggered by a hardware instruction (such as VMLAUNCH), and the guest mode is re-entered to enter the virtual machine running environment to continue running.
为了使本领域技术人员能够更好地理解本申请实施例,以下通过一个具体实例对本 申请实施例加以示例性说明,但应该理解的是,本申请实施例并不限于此。In order to enable those skilled in the art to better understand the embodiments of the present application, the following The application examples are exemplified, but it should be understood that the embodiments of the present application are not limited thereto.
虚拟机在运行时,设备驱动会访问虚拟VGA设备的MMIO控制寄存器来读取模拟设备的状态。该寄存器映射的地址访问触发EPT页错误,CPU退出非根模式进入根模式,执行KVM代码。While the virtual machine is running, the device driver accesses the MMIO control register of the virtual VGA device to read the state of the analog device. The register-mapped address access triggers an EPT page fault, and the CPU exits the non-root mode into root mode and executes the KVM code.
KVM判断退出原因得知是I/O请求,根据I/O请求查找对应的I/O通道,将I/O请求拷贝到I/O通道相应的缓冲区中,然后用eventfd发出通知后vCPU线程进入睡眠。KVM judges the reason for the exit to be an I/O request, finds the corresponding I/O channel according to the I/O request, copies the I/O request to the corresponding buffer of the I/O channel, and then sends a notification to the vCPU thread with eventfd. Go to sleep.
QEMU主循环发现eventfd中的事件通知,找到相应的I/O通道并从相应的缓冲区中读出I/O请求,发现该请求地址处于客户机物理地址布局中虚拟VGA设备的BAR1区间,于是调用VGA设备相应的处理函数对I/O请求进行模拟,把该寄存器的值写回到缓冲区中,然后通过IOCTL指令唤醒睡眠的vCPU线程。The QEMU main loop finds the event notification in eventfd, finds the corresponding I/O channel and reads the I/O request from the corresponding buffer, and finds that the request address is in the BAR1 interval of the virtual VGA device in the client physical address layout, so Call the corresponding processing function of the VGA device to simulate the I/O request, write the value of this register back to the buffer, and then wake up the sleeping vCPU thread through the IOCTL instruction.
vCPU线程被唤醒后从缓冲区中读出寄存器值数据,并将其更新到vCPU上下文的相应位置,然后进入非根模式继续执行vCPU上下文。After the vCPU thread wakes up, it reads the register value data from the buffer and updates it to the corresponding location of the vCPU context, then enters the non-root mode to continue executing the vCPU context.
驱动代码处的读寄存器操作全部完成模拟。The read register operation at the driver code completes the simulation.
本申请实施例在KVM虚拟化下实现独立于QEMU的设备模拟程序提供了基础,解决了一些厂商特有的设备模拟需求。The embodiment of the present application provides a basis for implementing a device simulation program independent of QEMU under KVM virtualization, and solves the device simulation requirements unique to some vendors.
另外,本申请实施例在KVM内核模块中实现I/O请求的分发,并向用户态提供控制接口,从而可以在不同的进程中模拟同一台虚拟机的设备I/O。In addition, the embodiment of the present application implements the distribution of I/O requests in the KVM kernel module, and provides a control interface to the user state, so that the device I/O of the same virtual machine can be simulated in different processes.
需要说明的是,对于方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本申请实施例并不受所描述的动作顺序的限制,因为依据本申请实施例,某些步骤可以采用其他顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作并不一定是本申请实施例所必须的。It should be noted that, for the method embodiments, for the sake of simple description, they are all expressed as a series of action combinations, but those skilled in the art should understand that the embodiments of the present application are not limited by the described action sequence, because In accordance with embodiments of the present application, certain steps may be performed in other sequences or concurrently. In the following, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required in the embodiments of the present application.
参照图4,示出了本申请的一种KVM虚拟化下处理I/O请求的装置实施例的结构框图,具体可以包括如下模块:Referring to FIG. 4, a structural block diagram of an apparatus for processing an I/O request in a KVM virtualization process of the present application is shown. Specifically, the following modules may be included:
I/O通道确定模块401,用于通过内核虚拟机KVM拦截虚拟机发出的I/O请求,确定与所述I/O请求对应的I/O通道的信息,其中,所述I/O通道具有对应的缓冲区,所述I/O通道的信息包括eventfd文件描述符; The I/O channel determining module 401 is configured to intercept, by the kernel virtual machine KVM, an I/O request sent by the virtual machine, and determine information of an I/O channel corresponding to the I/O request, where the I/O channel Having a corresponding buffer, the information of the I/O channel includes an eventfd file descriptor;
缓冲区写入模块402,用于将所述I/O请求写入对应的I/O通道的缓冲区中;a buffer write module 402, configured to write the I/O request into a buffer of a corresponding I/O channel;
事件通知模块403,用于采用所述eventfd通知所述I/O通道对应的用户态进程;The event notification module 403 is configured to notify the user state process corresponding to the I/O channel by using the eventfd;
I/O模拟模块404,用于在所述用户态进程中,根据所述eventfd监听对应的I/O通道的事件,并从所述对应的I/O通道的缓冲区中获取I/O请求,对所述I/O请求执行I/O模拟。The I/O simulation module 404 is configured to: in the user state process, listen to an event of the corresponding I/O channel according to the eventfd, and obtain an I/O request from a buffer of the corresponding I/O channel. Performing an I/O simulation on the I/O request.
其中,所述用户态进程包括第一设备模拟进程以及与所述第一设备模拟进程独立的第二设备模拟进程。The user state process includes a first device simulation process and a second device simulation process that is independent of the first device simulation process.
在本申请实施例的一种优选实施例中,所述装置还可以包括:In a preferred embodiment of the embodiment of the present application, the device may further include:
虚拟机创建模块,用于采用所述第一设备模拟进程创建虚拟机,获得所述虚拟机的文件描述符;a virtual machine creating module, configured to create a virtual machine by using the first device simulation process, and obtain a file descriptor of the virtual machine;
vCPU创建模块,用于采用所述第一设备模拟进程,基于所述虚拟机的文件描述符,创建虚拟处理器vCPU,获得所述vCPU的文件描述符;a vCPU creation module, configured to: use the first device simulation process, create a virtual processor vCPU based on a file descriptor of the virtual machine, and obtain a file descriptor of the vCPU;
eventfd创建模块,用于采用所述第二设备模拟进程,创建eventfd文件描述符;An eventfd creation module is configured to create an eventfd file descriptor by using the second device simulation process;
I/O通道创建模块,用于采用所述第二设备模拟进程,基于所述虚拟机的文件描述符,创建I/O通道,并将所述I/O通道与所述eventfd文件描述符绑定,获得所述I/O通道的文件描述符;An I/O channel creation module, configured to simulate a process by using the second device, create an I/O channel based on a file descriptor of the virtual machine, and bind the I/O channel to the eventfd file descriptor Determining, obtaining a file descriptor of the I/O channel;
监听模块,用于对所述eventfd文件描述符进行监听;a monitoring module, configured to monitor the eventfd file descriptor;
缓冲区映射模块,用于采用所述第二设备模拟进程,基于所述I/O通道的文件描述符,为所述用户态进程映射所述I/O通道的缓冲区;a buffer mapping module, configured to: use the second device simulation process to map a buffer of the I/O channel for the user state process based on a file descriptor of the I/O channel;
地址区间绑定模块,用于采用所述第二设备模拟进程,基于所述I/O通道的文件描述符,为所述I/O通道绑定I/O地址区间。An address interval binding module is configured to bind an I/O address interval to the I/O channel based on a file descriptor of the I/O channel by using the second device simulation process.
在本申请实施例的一种优选实施例中,所述I/O请求包括I/O地址,所述I/O通道确定模块401可以包括如下子模块:In a preferred embodiment of the embodiment of the present application, the I/O request includes an I/O address, and the I/O channel determining module 401 may include the following submodules:
I/O请求拦截子模块,用于通过内核虚拟机KVM及Intel VT-d硬件技术拦截虚拟机的vCPU线程发出的I/O请求;An I/O request intercepting submodule for intercepting I/O requests from a virtual machine's vCPU thread through a kernel virtual machine KVM and an Intel VT-d hardware technology;
I/O地址提取子模块,用于从所述I/O请求中提取对应的I/O地址;An I/O address extraction submodule, configured to extract a corresponding I/O address from the I/O request;
第一I/O通道确定子模块,用于确定所述I/O地址所属的I/O地址区间,并通过所述I/O地址区间确定对应的I/O通道,并获取所述I/O通道对应的I/O通道的信息。a first I/O channel determining submodule, configured to determine an I/O address interval to which the I/O address belongs, and determine a corresponding I/O channel by using the I/O address interval, and acquire the I/ Information about the I/O channel corresponding to the O channel.
在本申请实施例的一种优选实施例中,所述I/O通道的地址区间包括多个I/O模拟设备的地址子区间; In a preferred embodiment of the embodiment of the present application, the address range of the I/O channel includes an address subinterval of a plurality of I/O analog devices;
所述I/O模拟模块404可以包括如下子模块:The I/O simulation module 404 can include the following sub-modules:
第二I/O通道确定子模块,用于在所述用户态进程中,根据所述eventfd确定对应的I/O通道;a second I/O channel determining submodule, configured to determine, according to the eventfd, a corresponding I/O channel in the user state process;
I/O请求读取子模块,用于从所述对应的I/O通道的缓冲区中获取I/O请求;An I/O request reading submodule, configured to obtain an I/O request from a buffer of the corresponding I/O channel;
I/O模拟设备确定子模块,用于依据所述I/O请求中的I/O地址确定对应的I/O模拟设备;An I/O analog device determining submodule, configured to determine a corresponding I/O analog device according to an I/O address in the I/O request;
分发子模块,用于将所述I/O请求分发至所述I/O模拟设备中,通过所述I/O模拟设备对所述I/O请求进行I/O模拟。And a distribution submodule, configured to distribute the I/O request to the I/O simulation device, and perform I/O simulation on the I/O request by using the I/O simulation device.
在本申请实施例的一种优选实施例中,所述装置还包括:In a preferred embodiment of the embodiment of the present application, the device further includes:
挂起模块,用于在采用所述eventfd通知所述I/O通道对应的用户态进程以后,挂起所述vCPU线程。Suspending a module, for suspending the vCPU thread after the userfest process corresponding to the I/O channel is notified by using the eventfd.
在本申请实施例的一种优选实施例中,所述装置还包括:In a preferred embodiment of the embodiment of the present application, the device further includes:
唤醒模块,用于在对所述I/O请求执行I/O模拟以后,唤醒所述挂起的vCPU线程。And a wake-up module, configured to wake up the suspended vCPU thread after performing I/O simulation on the I/O request.
在本申请实施例的一种优选实施例中,所述I/O请求包括读请求,所述分发子模块还用于:In a preferred embodiment of the embodiment of the present application, the I/O request includes a read request, and the distribution sub-module is further configured to:
将所述读请求分发至所述I/O模拟设备中,通过所述I/O模拟设备将所述读请求对应的数据写入所述I/O通道的缓冲区中。And distributing the read request to the I/O analog device, and writing, by the I/O analog device, data corresponding to the read request into a buffer of the I/O channel.
在本申请实施例的一种优选实施例中,所述装置还包括:In a preferred embodiment of the embodiment of the present application, the device further includes:
数据读出模块,用于在所述I/O请求为读请求时,将所述读请求对应的数据从缓冲区中读出,读入到vCPU结构体中相应的成员变量中,对所述数据进行对应的模拟处理。a data reading module, configured to: when the I/O request is a read request, read data corresponding to the read request from a buffer, and read the corresponding member variable into the vCPU structure, The data is subjected to corresponding analog processing.
对于装置实施例而言,由于其与方法实施例基本相似,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment.
本说明书中的各个实施例均采用递进的方式描述,每个实施例重点说明的都是与其他实施例的不同之处,各个实施例之间相同相似的部分互相参见即可。The various embodiments in the present specification are described in a progressive manner, and each embodiment focuses on differences from other embodiments, and the same similar parts between the various embodiments can be referred to each other.
本领域内的技术人员应明白,本申请实施例的实施例可提供为方法、装置、或计算机程序产品。因此,本申请实施例可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请实施例可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。 Those skilled in the art will appreciate that embodiments of the embodiments of the present application can be provided as a method, apparatus, or computer program product. Therefore, the embodiments of the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Moreover, embodiments of the present application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) including computer usable program code.
在一个典型的配置中,所述计算机设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括非持续性的电脑可读媒体(transitory media),如调制的数据信号和载波。In a typical configuration, the computer device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory. The memory may include non-persistent memory, random access memory (RAM), and/or non-volatile memory in a computer readable medium, such as read only memory (ROM) or flash memory. Memory is an example of a computer readable medium. Computer readable media includes both permanent and non-persistent, removable and non-removable media. Information storage can be implemented by any method or technology. The information can be computer readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory. (ROM), electrically erasable programmable read only memory (EEPROM), flash memory or other memory technology, compact disk read only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, Magnetic tape cartridges, magnetic tape storage or other magnetic storage devices or any other non-transportable media can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include non-persistent computer readable media, such as modulated data signals and carrier waves.
本申请实施例是参照根据本申请实施例的方法、终端设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理终端设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理终端设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。Embodiments of the present application are described with reference to flowcharts and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the present application. It will be understood that each flow and/or block of the flowchart illustrations and/or FIG. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processor or other programmable data processing terminal device to produce a machine such that instructions are executed by a processor of a computer or other programmable data processing terminal device Means are provided for implementing the functions specified in one or more of the flow or in one or more blocks of the flow chart.
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理终端设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。The computer program instructions can also be stored in a computer readable memory that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer readable memory produce an article of manufacture comprising the instruction device. The instruction device implements the functions specified in one or more blocks of the flowchart or in a flow or block of the flowchart.
这些计算机程序指令也可装载到计算机或其他可编程数据处理终端设备上,使得在计算机或其他可编程终端设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程终端设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device such that a series of operational steps are performed on the computer or other programmable terminal device to produce computer-implemented processing, such that the computer or other programmable terminal device The instructions executed above provide steps for implementing the functions specified in one or more blocks of the flowchart or in a block or blocks of the flowchart.
尽管已描述了本申请实施例的优选实施例,但本领域内的技术人员一旦得知了基本创造性概念,则可对这些实施例做出另外的变更和修改。所以,所附权利要求意欲解释为包括优选实施例以及落入本申请实施例范围的所有变更和修改。 While a preferred embodiment of the embodiments of the present application has been described, those skilled in the art can make further changes and modifications to the embodiments once they are aware of the basic inventive concept. Therefore, the appended claims are intended to be interpreted as including all the modifications and the modifications
最后,还需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者终端设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者终端设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者终端设备中还存在另外的相同要素。Finally, it should also be noted that in this context, relational terms such as first and second are used merely to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply these entities. There is any such actual relationship or order between operations. Furthermore, the terms "comprises" or "comprising" or "comprising" or any other variations are intended to encompass a non-exclusive inclusion, such that a process, method, article, or terminal device that includes a plurality of elements includes not only those elements but also Other elements that are included, or include elements inherent to such a process, method, article, or terminal device. An element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or terminal device that comprises the element, without further limitation.
以上对本申请所提供的一种KVM虚拟化下处理I/O请求的方法和一种KVM虚拟化下处理I/O请求的装置,进行了详细介绍,本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想;同时,对于本领域的一般技术人员,依据本申请的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本申请的限制。 The method for processing I/O requests under KVM virtualization provided by the present application and a device for processing I/O requests under KVM virtualization are described in detail. In this paper, specific examples are applied to the principle of the present application. The description of the above embodiments is only for helping to understand the method of the present application and its core ideas; at the same time, for those skilled in the art, according to the idea of the present application, in the specific implementation and application scope There are variations, and the contents of this specification should not be construed as limiting the application.

Claims (16)

  1. 一种KVM虚拟化下处理I/O请求的方法,其特征在于,所述的方法包括:A method for processing an I/O request under KVM virtualization, characterized in that the method comprises:
    通过内核虚拟机KVM拦截虚拟机发出的I/O请求,确定与所述I/O请求对应的I/O通道的信息,其中,所述I/O通道具有对应的缓冲区,所述I/O通道的信息包括eventfd文件描述符;The I/O request sent by the virtual machine is intercepted by the kernel virtual machine KVM, and the information of the I/O channel corresponding to the I/O request is determined, wherein the I/O channel has a corresponding buffer, and the I/O The information of the O channel includes an eventfd file descriptor;
    将所述I/O请求写入对应的I/O通道的缓冲区中;Writing the I/O request into a buffer of a corresponding I/O channel;
    采用所述eventfd通知所述I/O通道对应的用户态进程;Notifying the user state process corresponding to the I/O channel by using the eventfd;
    在所述用户态进程中,根据所述eventfd监听对应的I/O通道的事件,并从所述对应的I/O通道的缓冲区中获取I/O请求,对所述I/O请求执行I/O模拟,其中,所述用户态进程包括第一设备模拟进程以及与所述第一设备模拟进程独立的第二设备模拟进程。In the user state process, according to the eventfd, the event of the corresponding I/O channel is monitored, and an I/O request is obtained from the buffer of the corresponding I/O channel, and the I/O request is executed. An I/O simulation, wherein the user state process includes a first device emulation process and a second device emulation process independent of the first device emulation process.
  2. 根据权利要求1所述的方法,其特征在于,所述在所述通过内核虚拟机KVM拦截虚拟机发出的I/O请求,确定与所述I/O请求对应的I/O通道的信息的步骤之前,还包括:The method according to claim 1, wherein the intercepting the I/O request sent by the virtual machine by the kernel virtual machine KVM determines the information of the I/O channel corresponding to the I/O request. Before the step, it also includes:
    采用所述第一设备模拟进程创建虚拟机,获得所述虚拟机的文件描述符;Creating a virtual machine by using the first device simulation process to obtain a file descriptor of the virtual machine;
    采用所述第一设备模拟进程,基于所述虚拟机的文件描述符,创建虚拟处理器vCPU,获得所述vCPU的文件描述符;Using the first device simulation process, creating a virtual processor vCPU based on the file descriptor of the virtual machine, and obtaining a file descriptor of the vCPU;
    采用所述第二设备模拟进程,创建eventfd文件描述符;Using the second device simulation process to create an eventfd file descriptor;
    采用所述第二设备模拟进程,基于所述虚拟机的文件描述符,创建I/O通道,并将所述I/O通道与所述eventfd文件描述符绑定,获得所述I/O通道的文件描述符;Using the second device simulation process, creating an I/O channel based on the file descriptor of the virtual machine, and binding the I/O channel to the eventfd file descriptor to obtain the I/O channel File descriptor
    采用所述第二设备模拟进程,对所述eventfd文件描述符进行监听;Using the second device simulation process to monitor the eventfd file descriptor;
    采用所述第二设备模拟进程,基于所述I/O通道的文件描述符,为所述用户态进程映射所述I/O通道的缓冲区;Using the second device simulation process to map a buffer of the I/O channel for the user state process based on a file descriptor of the I/O channel;
    采用所述第二设备模拟进程,基于所述I/O通道的文件描述符,为所述I/O通道绑定I/O地址区间。Using the second device emulation process, an I/O address interval is bound to the I/O channel based on a file descriptor of the I/O channel.
  3. 根据权利要求2所述的方法,其特征在于,所述I/O请求包括I/O地址,所述通过内核虚拟机KVM拦截虚拟机发出的I/O请求,确定与所述I/O请求对应的I/O通道的信息的步骤包括:The method according to claim 2, wherein the I/O request includes an I/O address, and the I/O request sent by the virtual machine is intercepted by the kernel virtual machine KVM, and the I/O request is determined. The steps of the corresponding I/O channel information include:
    通过内核虚拟机KVM及Intel VT-d硬件技术拦截虚拟机的vCPU线程发出的I/O请求; Intercepting I/O requests from virtual machine vCPU threads through kernel virtual machine KVM and Intel VT-d hardware technology;
    从所述I/O请求中提取对应的I/O地址;Extracting a corresponding I/O address from the I/O request;
    确定所述I/O地址所属的I/O地址区间;Determining an I/O address interval to which the I/O address belongs;
    通过所述I/O地址区间确定对应的I/O通道,并获取所述I/O通道对应的I/O通道的信息。And determining, by the I/O address interval, a corresponding I/O channel, and acquiring information of the I/O channel corresponding to the I/O channel.
  4. 根据权利要求3所述的方法,其特征在于,所述I/O通道的地址区间包括多个I/O模拟设备的地址子区间;The method according to claim 3, wherein the address interval of the I/O channel comprises an address subinterval of a plurality of I/O analog devices;
    所述在所述用户态进程中,根据所述eventfd确定对应的I/O通道,并从所述对应的I/O通道的缓冲区中获取I/O请求,对所述I/O请求执行I/O模拟的步骤包括:Determining, in the user state process, a corresponding I/O channel according to the eventfd, and acquiring an I/O request from a buffer of the corresponding I/O channel, performing the I/O request The steps of the I/O simulation include:
    在所述用户态进程中,根据所述eventfd确定对应的I/O通道;In the user state process, determining a corresponding I/O channel according to the eventfd;
    从所述对应的I/O通道的缓冲区中获取I/O请求;Obtaining an I/O request from a buffer of the corresponding I/O channel;
    依据所述I/O请求中的I/O地址确定对应的I/O模拟设备;Determining a corresponding I/O analog device according to the I/O address in the I/O request;
    将所述I/O请求分发至所述I/O模拟设备中,通过所述I/O模拟设备对所述I/O请求进行I/O模拟。Distributing the I/O request to the I/O analog device, and performing I/O simulation on the I/O request by the I/O analog device.
  5. 根据权利要求3或4所述的方法,其特征在于,在所述在所述用户态进程中,根据所述eventfd确定对应的I/O通道,并从所述对应的I/O通道的缓冲区中获取I/O请求,对所述I/O请求执行I/O模拟的步骤之前,还包括:The method according to claim 3 or 4, wherein in the user state process, a corresponding I/O channel is determined according to the eventfd, and buffering from the corresponding I/O channel Before the step of obtaining an I/O request in the zone and performing an I/O simulation on the I/O request, the method further includes:
    挂起所述vCPU线程。Suspend the vCPU thread.
  6. 根据权利要求5所述的方法,其特征在于,在所述在所述用户态进程中,根据所述eventfd确定对应的I/O通道,并从所述对应的I/O通道的缓冲区中获取I/O请求,对所述I/O请求执行I/O模拟的步骤之后,还包括:The method according to claim 5, wherein in the user state process, a corresponding I/O channel is determined according to the eventfd, and from a buffer of the corresponding I/O channel After obtaining the I/O request and performing the I/O simulation on the I/O request, the method further includes:
    唤醒所述挂起的vCPU线程。Wake up the suspended vCPU thread.
  7. 根据权利要求4所述的方法,其特征在于,所述I/O请求包括读请求,所述将所述I/O请求分发至所述I/O模拟设备中,通过所述I/O模拟设备对所述I/O请求进行I/O模拟的步骤为:The method of claim 4 wherein said I/O request comprises a read request, said I/O request being distributed to said I/O analog device, said I/O simulation The steps for the device to perform I/O simulation on the I/O request are:
    将所述读请求分发至所述I/O模拟设备中,通过所述I/O模拟设备将所述读请求对应的数据写入所述I/O通道的缓冲区中。And distributing the read request to the I/O analog device, and writing, by the I/O analog device, data corresponding to the read request into a buffer of the I/O channel.
  8. 根据权利要求7所述的方法,其特征在于,所述方法还包括:The method of claim 7, wherein the method further comprises:
    若所述I/O请求为读请求,将所述读请求对应的数据从缓冲区中读出,读入到vCPU结构体中相应的成员变量中;If the I/O request is a read request, the data corresponding to the read request is read out from the buffer, and is read into a corresponding member variable in the vCPU structure;
    对所述数据进行对应的模拟处理。 Corresponding simulation processing is performed on the data.
  9. 一种KVM虚拟化下处理I/O请求的装置,其特征在于,所述的装置包括:An apparatus for processing an I/O request under KVM virtualization, characterized in that the apparatus comprises:
    I/O通道确定模块,用于通过内核虚拟机KVM拦截虚拟机发出的I/O请求,确定与所述I/O请求对应的I/O通道的信息,其中,所述I/O通道具有对应的缓冲区,所述I/O通道的信息包括eventfd文件描述符;An I/O channel determining module, configured to intercept, by the kernel virtual machine KVM, an I/O request sent by the virtual machine to determine information of an I/O channel corresponding to the I/O request, where the I/O channel has Corresponding buffer, the information of the I/O channel includes an eventfd file descriptor;
    缓冲区写入模块,用于将所述I/O请求写入对应的I/O通道的缓冲区中;a buffer write module, configured to write the I/O request into a buffer of a corresponding I/O channel;
    事件通知模块,用于采用所述eventfd通知所述I/O通道对应的用户态进程;An event notification module, configured to notify the user state process corresponding to the I/O channel by using the eventfd;
    I/O模拟模块,用于在所述用户态进程中,根据所述eventfd监听对应的I/O通道的事件,并从所述对应的I/O通道的缓冲区中获取I/O请求,对所述I/O请求执行I/O模拟,其中,所述用户态进程包括第一设备模拟进程以及与所述第一设备模拟进程独立的第二设备模拟进程。An I/O simulation module, configured to: in the user state process, listen to an event of the corresponding I/O channel according to the eventfd, and obtain an I/O request from a buffer of the corresponding I/O channel, Performing an I/O simulation on the I/O request, wherein the user state process includes a first device emulation process and a second device emulation process independent of the first device emulation process.
  10. 根据权利要求9所述的装置,其特征在于,还包括:The device according to claim 9, further comprising:
    虚拟机创建模块,用于采用所述第一设备模拟进程创建虚拟机,获得所述虚拟机的文件描述符;a virtual machine creating module, configured to create a virtual machine by using the first device simulation process, and obtain a file descriptor of the virtual machine;
    vCPU创建模块,用于采用所述第一设备模拟进程,基于所述虚拟机的文件描述符,创建虚拟处理器vCPU,获得所述vCPU的文件描述符;a vCPU creation module, configured to: use the first device simulation process, create a virtual processor vCPU based on a file descriptor of the virtual machine, and obtain a file descriptor of the vCPU;
    eventfd创建模块,用于采用所述第二设备模拟进程,创建eventfd文件描述符;An eventfd creation module is configured to create an eventfd file descriptor by using the second device simulation process;
    I/O通道创建模块,用于采用所述第二设备模拟进程,基于所述虚拟机的文件描述符,创建I/O通道,并将所述I/O通道与所述eventfd文件描述符绑定,获得所述I/O通道的文件描述符;An I/O channel creation module, configured to simulate a process by using the second device, create an I/O channel based on a file descriptor of the virtual machine, and bind the I/O channel to the eventfd file descriptor Determining, obtaining a file descriptor of the I/O channel;
    监听模块,用于采用所述第二设备模拟进程,对所述eventfd文件描述符进行监听;a monitoring module, configured to monitor the eventfd file descriptor by using the second device simulation process;
    缓冲区映射模块,用于采用所述第二设备模拟进程,基于所述I/O通道的文件描述符,为所述用户态进程映射所述I/O通道的缓冲区;a buffer mapping module, configured to: use the second device simulation process to map a buffer of the I/O channel for the user state process based on a file descriptor of the I/O channel;
    地址区间绑定模块,用于采用所述第二设备模拟进程,基于所述I/O通道的文件描述符,为所述I/O通道绑定I/O地址区间。An address interval binding module is configured to bind an I/O address interval to the I/O channel based on a file descriptor of the I/O channel by using the second device simulation process.
  11. 根据权利要求10所述的装置,其特征在于,所述I/O请求包括I/O地址,所述I/O通道确定模块包括:The apparatus according to claim 10, wherein the I/O request comprises an I/O address, and the I/O channel determining module comprises:
    I/O请求拦截子模块,用于通过内核虚拟机KVM及Intel VT-d硬件技术拦截虚拟机的vCPU线程发出的I/O请求;An I/O request intercepting submodule for intercepting I/O requests from a virtual machine's vCPU thread through a kernel virtual machine KVM and an Intel VT-d hardware technology;
    I/O地址提取子模块,用于从所述I/O请求中提取对应的I/O地址; An I/O address extraction submodule, configured to extract a corresponding I/O address from the I/O request;
    第一I/O通道确定子模块,用于确定所述I/O地址所属的I/O地址区间,并通过所述I/O地址区间确定对应的I/O通道,并获取所述I/O通道对应的I/O通道的信息。a first I/O channel determining submodule, configured to determine an I/O address interval to which the I/O address belongs, and determine a corresponding I/O channel by using the I/O address interval, and acquire the I/ Information about the I/O channel corresponding to the O channel.
  12. 根据权利要求11所述的装置,其特征在于,所述I/O通道的地址区间包括多个I/O模拟设备的地址子区间;The apparatus according to claim 11, wherein the address range of the I/O channel comprises an address subinterval of a plurality of I/O analog devices;
    所述I/O模拟模块包括:The I/O simulation module includes:
    第二I/O通道确定子模块,用于在所述用户态进程中,根据所述eventfd确定对应的I/O通道;a second I/O channel determining submodule, configured to determine, according to the eventfd, a corresponding I/O channel in the user state process;
    I/O请求读取子模块,用于从所述对应的I/O通道的缓冲区中获取I/O请求;An I/O request reading submodule, configured to obtain an I/O request from a buffer of the corresponding I/O channel;
    I/O模拟设备确定子模块,用于依据所述I/O请求中的I/O地址确定对应的I/O模拟设备;An I/O analog device determining submodule, configured to determine a corresponding I/O analog device according to an I/O address in the I/O request;
    分发子模块,用于将所述I/O请求分发至所述I/O模拟设备中,通过所述I/O模拟设备对所述I/O请求进行I/O模拟。And a distribution submodule, configured to distribute the I/O request to the I/O simulation device, and perform I/O simulation on the I/O request by using the I/O simulation device.
  13. 根据权利要求11或12所述的装置,其特征在于,还包括:The device according to claim 11 or 12, further comprising:
    挂起模块,用于在采用所述eventfd通知所述I/O通道对应的用户态进程以后,挂起所述vCPU线程。Suspending a module, for suspending the vCPU thread after the userfest process corresponding to the I/O channel is notified by using the eventfd.
  14. 根据权利要求13所述的装置,其特征在于,还包括:The device according to claim 13, further comprising:
    唤醒模块,用于在对所述I/O请求执行I/O模拟以后,唤醒所述挂起的vCPU线程。And a wake-up module, configured to wake up the suspended vCPU thread after performing I/O simulation on the I/O request.
  15. 根据权利要求12所述的装置,其特征在于,所述I/O请求包括读请求,所述分发子模块还用于:The apparatus according to claim 12, wherein the I/O request comprises a read request, and the distribution sub-module is further configured to:
    将所述读请求分发至所述I/O模拟设备中,通过所述I/O模拟设备将所述读请求对应的数据写入所述I/O通道的缓冲区中。And distributing the read request to the I/O analog device, and writing, by the I/O analog device, data corresponding to the read request into a buffer of the I/O channel.
  16. 根据权利要求15所述的装置,其特征在于,所述装置还包括:The device according to claim 15, wherein the device further comprises:
    数据读出模块,用于在所述I/O请求为读请求时,将所述读请求对应的数据从缓冲区中读出,读入到vCPU结构体中相应的成员变量中,对所述数据进行对应的模拟处理。 a data reading module, configured to: when the I/O request is a read request, read data corresponding to the read request from a buffer, and read the corresponding member variable into the vCPU structure, The data is subjected to corresponding analog processing.
PCT/CN2017/070151 2016-01-12 2017-01-04 Method and device for processing i/o request under kvm virtualization WO2017121273A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201610019289.0 2016-01-12
CN201610019289.0A CN106970821B (en) 2016-01-12 2016-01-12 Method and device for processing I/O request under KVM virtualization

Publications (1)

Publication Number Publication Date
WO2017121273A1 true WO2017121273A1 (en) 2017-07-20

Family

ID=59310750

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/070151 WO2017121273A1 (en) 2016-01-12 2017-01-04 Method and device for processing i/o request under kvm virtualization

Country Status (2)

Country Link
CN (1) CN106970821B (en)
WO (1) WO2017121273A1 (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110955631A (en) * 2018-09-26 2020-04-03 上海瑾盛通信科技有限公司 File access tracking method and device, storage medium and terminal
CN115460470A (en) * 2022-08-19 2022-12-09 武汉烽火技术服务有限公司 Multicast data forwarding method, device, equipment and readable storage medium
CN116361033A (en) * 2023-04-04 2023-06-30 亿咖通(湖北)技术有限公司 Communication method, electronic device, and storage medium
CN116401020A (en) * 2023-06-07 2023-07-07 四川大学 KVM virtual machine I/O filter framework implementation method, system and storage medium

Families Citing this family (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107807843B (en) * 2017-10-26 2019-05-24 北京百度网讯科技有限公司 I/O request processing method, equipment and computer-readable medium in virtual machine
CN109002363A (en) * 2018-06-21 2018-12-14 郑州云海信息技术有限公司 A kind of event-handling method, device, equipment and readable storage medium storing program for executing
CN109033328B (en) * 2018-07-19 2022-08-02 郑州云海信息技术有限公司 Access request processing method, device, equipment and readable storage medium
CN109271244A (en) * 2018-09-11 2019-01-25 郑州云海信息技术有限公司 A kind of process management method and device of Nonvolatile memory reservoir
CN109976877B (en) * 2019-03-22 2021-05-04 优刻得科技股份有限公司 Method, device and storage medium for realizing request by using virtio driver
CN111428240B (en) * 2020-03-20 2021-10-15 安芯网盾(北京)科技有限公司 Method and device for detecting illegal access of memory of software
CN112162830B (en) * 2020-10-30 2021-11-09 北京易捷思达科技发展有限公司 Quick starting method of virtual machine, storage medium and terminal
CN113342554B (en) * 2021-08-02 2022-01-04 阿里云计算有限公司 IO multiplexing method, medium, device and operating system
CN114791854B (en) * 2022-05-11 2023-03-24 科东(广州)软件科技有限公司 Scheduling method, device, equipment and storage medium of user-state virtual machine task
CN116841697B (en) * 2023-07-21 2024-05-07 芯华章智能科技(上海)有限公司 Method for processing MMIO request, electronic device and storage medium
CN118349368A (en) * 2024-05-14 2024-07-16 哈尔滨工业大学 Real-time-oriented construction method of interruptible mutual exclusive lock of virtualization platform, electronic equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080104589A1 (en) * 2006-11-01 2008-05-01 Mccrory Dave Dennis Adaptive, Scalable I/O Request Handling Architecture in Virtualized Computer Systems and Networks
CN101706757A (en) * 2009-09-21 2010-05-12 中国科学院计算技术研究所 I/O system and working method facing multi-core platform and distributed virtualization environment
CN101968746A (en) * 2010-09-02 2011-02-09 北京航空航天大学 Method for implementing organizational architecture mode of kernel-based virtual machine (KVM)
CN104104705A (en) * 2013-04-11 2014-10-15 阿里巴巴集团控股有限公司 Access method and device of distributed storage system
CN104503825A (en) * 2014-12-29 2015-04-08 西安电子科技大学 Mixed type equipment virtualization method based on KVM (Kernel-based Virtual Machine)

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102073535B (en) * 2011-01-11 2013-09-18 华中科技大学 Hardware counter virtualization-based performance analysis method for multiple virtual machines

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080104589A1 (en) * 2006-11-01 2008-05-01 Mccrory Dave Dennis Adaptive, Scalable I/O Request Handling Architecture in Virtualized Computer Systems and Networks
CN101706757A (en) * 2009-09-21 2010-05-12 中国科学院计算技术研究所 I/O system and working method facing multi-core platform and distributed virtualization environment
CN101968746A (en) * 2010-09-02 2011-02-09 北京航空航天大学 Method for implementing organizational architecture mode of kernel-based virtual machine (KVM)
CN104104705A (en) * 2013-04-11 2014-10-15 阿里巴巴集团控股有限公司 Access method and device of distributed storage system
CN104503825A (en) * 2014-12-29 2015-04-08 西安电子科技大学 Mixed type equipment virtualization method based on KVM (Kernel-based Virtual Machine)

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110955631A (en) * 2018-09-26 2020-04-03 上海瑾盛通信科技有限公司 File access tracking method and device, storage medium and terminal
CN110955631B (en) * 2018-09-26 2023-01-03 上海瑾盛通信科技有限公司 File access tracking method and device, storage medium and terminal
CN115460470A (en) * 2022-08-19 2022-12-09 武汉烽火技术服务有限公司 Multicast data forwarding method, device, equipment and readable storage medium
CN115460470B (en) * 2022-08-19 2024-03-26 烽火通信科技股份有限公司 Multicast data forwarding method, device, equipment and readable storage medium
CN116361033A (en) * 2023-04-04 2023-06-30 亿咖通(湖北)技术有限公司 Communication method, electronic device, and storage medium
CN116361033B (en) * 2023-04-04 2023-12-29 亿咖通(湖北)技术有限公司 Communication method, electronic device, and storage medium
CN116401020A (en) * 2023-06-07 2023-07-07 四川大学 KVM virtual machine I/O filter framework implementation method, system and storage medium
CN116401020B (en) * 2023-06-07 2023-08-11 四川大学 KVM virtual machine I/O filter framework implementation method, system and storage medium

Also Published As

Publication number Publication date
CN106970821A (en) 2017-07-21
CN106970821B (en) 2021-02-02

Similar Documents

Publication Publication Date Title
WO2017121273A1 (en) Method and device for processing i/o request under kvm virtualization
US11868792B2 (en) Dynamic device virtualization for use by guest user processes based on observed behaviors of native device drivers
US10534735B2 (en) Direct access to a hardware device for virtual machines of a virtualized computer system
US7853744B2 (en) Handling interrupts when virtual machines have direct access to a hardware device
US11487523B2 (en) Updating machine emulator
US20120054740A1 (en) Techniques For Selectively Enabling Or Disabling Virtual Devices In Virtual Environments
US20120266165A1 (en) Combined virtual graphics device
JP2009506462A (en) Hierarchical virtualization using a multi-layered virtualization mechanism
TW201120752A (en) Improving nested virtualization performance in a computer system
US10620963B2 (en) Providing fallback drivers for IO devices in a computing system
JP2009537897A (en) Booting the hypervisor under a running operating system
US9898307B2 (en) Starting application processors of a virtual machine
US10963280B2 (en) Hypervisor post-write notification of control and debug register updates
Kanda et al. SIGMA system: A multi-OS environment for embedded systems
Im et al. On-Demand Virtualization for Post-Copy OS Migration in Bare-Metal Cloud
CN108196945B (en) Inter-core communication method and device and virtualization equipment
US11513825B2 (en) System and method for implementing trusted execution environment on PCI device
TWI733745B (en) Method and device for processing I/O request under core mode virtual machine (KVM) virtualization
Im et al. On-demand virtualization for live migration in bare metal cloud
WO2013189180A1 (en) Method and device for disabling interruption in virtualization system
Liu et al. Research on Hardware I/O Passthrough in Computer Virtualization
Kawakami et al. Generalize IoT device's client application with virtual machine
Ambika et al. A Novel Framework for Hypervisor Design
表祐志 Computer Systems Management with a Para Pass-through Virtual Machine Monitor

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17738087

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 17738087

Country of ref document: EP

Kind code of ref document: A1