VMCLEAR

Clear Virtual-Machine Control Structure

Opcodes

Hex Mnemonic Encoding Long Mode Legacy Mode Description
66 0F C7 /6 VMCLEAR None None None Copy VMCS data to VMCS region in memory.

Description

This instruction applies to the VMCS whose VMCS region resides at the physical address contained in the instruction operand. The instruction ensures that VMCS data for that VMCS (some of these data may be currently maintained on the processor) are copied to the VMCS region in memory. It also initializes parts of the VMCS region (for example, it sets the launch state of that VMCS to clear). See Chapter 21, "Virtual-Machine Control Structures," in theIntel® 64 and IA-32 Architectures Software Developer's Manual, Volume 3B.

The operand of this instruction is always 64 bits and is always in memory. If the operand is the current-VMCS pointer, then that pointer is made invalid (set to FFFFFFFF_FFFFFFFFH).

Note that the VMCLEAR instruction might not explicitly write any VMCS data to memory; the data may be already resident in memory before the VMCLEAR is executed.

Pseudo Code

IF (register operand) or (not in VMX operation) or (CR0.PE = 0) or (RFLAGS.VM = 1) or (IA32_EFER.LMA = 1 and CS.L = 0)
	#UD;
ELSE
	IF in VMX non-root operation
		VM exit;
	ELSE
		IF CPL > 0
			#GP(0);
		ELSE
			addr = contents of 64-bit in-memory operand;
			IF addr is not 4KB-aligned OR (processor supports Intel 64 architecture and addr sets any bits beyond the physical-address width) OR (processor does not support Intel 64 architecture, addr sets any bits in the range 63:32)
				VMfail(VMCLEAR with invalid physical address);
			ELSE
				IF addr = VMXON pointer
					VMfail(VMCLEAR with VMXON pointer);
				ELSE
					ensure that data for VMCS referenced by the operand is in memory;
					initialize implementation-specific data in VMCS region;
					launch state of VMCS referenced by the operand = "clear"
					IF operand addr = current-VMCS pointer
						current-VMCS pointer = FFFFFFFF_FFFFFFFFH;
					FI;
					VMsucceed;
				FI;
			FI;
		FI;
	FI;
FI;

Flags Affected

See the operation section and Section 5.2.

Exceptions

64-Bit Mode Exceptions

Exception Description
#UD If operand is a register. If not in VMX operation.
#SS(0) If the source operand is in the SS segment and the memory address is in a non-canonical form.
#PF(fault-code) If a page fault occurs in accessing the memory operand.
#GP(0) If the current privilege level is not 0. If the source operand is in the CS, DS, ES, FS, or GS segments and the memory address is in a non-canonical form.

Compatibility Mode Exceptions

Exception Description
#UD The VMCLEAR instruction is not recognized in compatibility mode.

Virtual-8086 Mode Exceptions

Exception Description
#UD The VMCLEAR instruction is not recognized in virtual-8086 mode.

Real-Address Mode Exceptions

Exception Description
#UD A logical processor cannot be in real-address mode while in VMX operation and the VMCLEAR instruction is not recognized outside VMX operation.

Protected Mode Exceptions

Exception Description
#UD If operand is a register. If not in VMX operation.
#SS(0) If the memory operand effective address is outside the SS segment limit. If the SS register contains an unusable segment.
#PF(fault-code) If a page fault occurs in accessing the memory operand.
#GP(0) If the current privilege level is not 0. If the memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit. If the DS, ES, FS, or GS register contains an unusable segment. If the operand is located in an execute-only code segment.