# US 2016/0253196 A1 · Optimized extended context management for virtual machines

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2016/0253196 A1
- Document ID: US20160253196A1
- Status: Published application
- Kind: A1
- Application number: 14/634,164
- Filed: 2015-02-27
- Published: 2016-09-01
- Earliest claimed: 2015-02-27
- Assignees: Red Hat, Inc.
- Applicants: Red Hat, Inc.
- Inventors: Henri van Riel; Marcelo Tosatti
- Web page: https://patentgrep.com/patent/US20160253196A1

## CPC

- G06F 9/45558: {Hypervisor-specific management and integration aspects}
- G06F 9/461: {Saving or restoring of program or task context}
- G06F 9/4812: {by interrupt, e.g. masked}
- G06F 9/485: {Task life-cycle, e.g. stopping, restarting, resuming execution (G06F9/4881 takes precedence)}
- G06F 9/5016: {the resource being the memory}
- G06F 2009/45575: {Starting, stopping, suspending or resuming virtual machine instances}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Optimized extended context management for virtual machines is disclosed. An example system includes a memory, processor, VM, and kernel, which executes the VM using guest space, stores a guest state in an extended state register, which the VM has access to, receives an instruction, saves the guest state, and determines whether the kernel is configured to handle the process using kernel space. If so, the process is handled using kernel space without using user space, and if not, a user state in the extended state register is restored, the process is handled using user space, an updated user state is stored in the extended state register, the updated user state is saved, and the guest state is restored in the extended state register. Finally, execution of the VM using the guest space is resumed.

## Claims

### Claim 1

A system comprising:
a memory;
one or more processors, in communication with the memory;
one or more virtual machines executing on the one or more processors; and
a kernel executing on the one or more processors to:
execute a virtual machine using a guest space;
store a guest state in an extended state register based on the execution of the virtual machine, wherein the virtual machine has access to the extended state register;
receive an instruction for handling a process outside of the guest space;
save a copy of the guest state in a reserve memory outside the extended state register;
determine whether the kernel is configured to handle the process using a kernel space;
responsive to determining that the kernel is configured to handle the process using the kernel space:
handle the process using the kernel space without using a user space;
after handling the process using the kernel space, resume execution of the virtual machine using the guest space; and
responsive to determining that the kernel is not configured to handle the process using the kernel space:
restore a user state in the extended state register;
handle the process using the user space;
store an updated user state in the extended state register;
save a copy of the updated user state in the reserve memory outside the extended state register;
after handling the process using the user space and saving the copy of the updated user state, restore the guest state in the extended state register;
after restoring the guest state in the extended state register, resume execution of the virtual machine using the guest space.

### Claim 2 (depends on 1)

The system of claim 1, wherein the kernel includes a hypervisor and a context switch module.

### Claim 3 (depends on 1)

The system of claim 1, wherein the kernel includes a kernel-based virtual machine (KVM).

### Claim 4 (depends on 1)

The system of claim 1, wherein the extended state register includes a floating point unit register (FPU register).

### Claim 5 (depends on 1)

The system of claim 1, wherein the extended state register includes a vector register.

### Claim 6 (depends on 1)

The system of claim 1, wherein the extended state register includes an FPU register and a vector register.

### Claim 7 (depends on 1)

The system of claim 1, wherein the instruction is a virtual machine exit instruction.

### Claim 8 (depends on 1)

The system of claim 1, wherein the instruction is an interrupt.

### Claim 9 (depends on 1)

The system of claim 1, wherein the extended state register is not overwritten during the handling of the process using the kernel space.

### Claim 10 (depends on 1)

The system of claim 1, wherein the reserve memory includes a first memory location for the guest state and a second different memory location for the updated user state.

### Claim 11 (depends on 1)

The system of claim 1, wherein the kernel further executes to:
track the user state and the guest state in the extended state register over a period of time, where the user state and the guest state both relate to a task;
stop execution of a different task;
receive an instruction to resume handling the task;
restore one of the user state of the task and the guest state of the task based on previous usage of the user state and the guest state;
determine whether the task is being handled in one of user space and guest space;
ensure access to one of the user state and the guest state is enabled; and
handle the task with access to the extended state register enabled.

### Claim 12

A method comprising:
executing a virtual machine using a guest space;
storing a guest state in an extended state register based on the execution of the virtual machine, wherein the virtual machine has access to the extended state register;
receiving an instruction for handling a process outside of the guest space;
saving a copy of the guest state in a reserve memory outside the extended state register;
determining whether a kernel is configured to handle the process using a kernel space;
responsive to determining that the kernel is configured to handle the process using the kernel space:
handling the process using the kernel space without using a user space;
after handling the process using the kernel space, resuming execution of the virtual machine using the guest space; and
responsive to determining that the kernel is not configured to handle the process using the kernel space:
restoring a user state in the extended state register;
handling the process using the user space;
storing an updated user state in the extended state register;
saving a copy of the updated user state in the reserve memory outside the extended state register;
after handling the process using the user space and saving the copy of the updated user state, restoring the guest state in the extended state register;
after restoring the guest state in the extended state register, resuming execution of the virtual machine using the guest space.

### Claim 13 (depends on 12)

The method of claim 12, wherein the guest state includes a guest floating point unit state.

### Claim 14 (depends on 12)

The method of claim 12, wherein the guest state includes a guest vector state.

### Claim 15 (depends on 12)

The method of claim 12, wherein the guest state includes guest floating point unit state and a guest vector state.

### Claim 16 (depends on 12)

The method of claim 12, wherein the instruction is at least one of a virtual machine exit instruction and an interrupt.

### Claim 17 (depends on 12)

The method of claim 12, wherein the extended state register is not overwritten during the handling of the process using the kernel space.

### Claim 18 (depends on 12)

The method of claim 12, wherein the reserve memory includes a first memory location for the guest state and a second different memory location for the updated user state.

### Claim 19 (depends on 12)

The method of claim 12, further comprising:
tracking the user state and the guest state in the extended state register over a period of time, where the user state and the guest state both relate to a task;
stopping execution of a different task;
receiving an instruction to resume handling the task;
restoring one of the user state of the task and the guest state of the task based on previous usage of the user state and the guest state;
determining whether the task is being handled in one of user space and guest space;
ensuring access to one of the user state and the guest state is enabled; and
handling the task with access to the extended state register enabled.

### Claim 20

A computer-readable storage medium storing executable instructions which, when executed by a computer system, cause the computer system to:
execute a virtual machine using a guest space;
store a guest state in an extended state register based on the execution of the virtual machine, wherein the virtual machine has access to the extended state register;
receive an instruction for handling a process outside of the guest space;
save a copy of the guest state in a reserve memory outside the extended state register;
determine whether a kernel is configured to handle the process using a kernel space;
responsive to determining that the kernel is configured to handle the process using the kernel space:
handle the process using the kernel space without using a user space;
after handling the process using the kernel space, resume execution of the virtual machine using the guest space; and
responsive to determining that the kernel is not configured to handle the process using the kernel space:
restore a user state in the extended state register;
handle the process using the user space;
store an updated user state in the extended state register;
save a copy of the updated user state in the reserve memory outside the extended state register;
after handling the process using the user space and saving the copy of the updated user state, restore the guest state in the extended state register;
after restoring the guest state in the extended state register, resume execution of the virtual machine using the guest space.
