Archive for the ‘Virtualization’ Category

After one of my previous blog post about C++, I had to know the way how I can include my assembly code into my C++ file. I used to code with assembly for my graduation project in my college, mainly about Hypervisors. My first step was about to know the CPUID of the Microprocessor (I work on Intel Microprocessor). Then to see if the VMX is turned on or not.

I usually code C++ on Ubuntu and I had to code some basic things with the assembly, I faced a lot of problems that’s why I want to share it with you.

There are several ways to include them together:

  • The first one is to compile each file differentially and then link them together (I think this is the easiest way). Here is a link I found very nice explaining so.
  • The second way is to include the assembly code in your C++ code.
    • For coding on windows platform, will need you to define that this function or this instruction is done by the assembly code by just writing __asm { assembly code goes here } before the instruction. Like in this link
    • For coding on Linux platform, to include the assembly language in it, it will be a little different you have to write __asm__ volatile { assembly code goes here }

      PS: coding assembly on the Linux platform is a little strange, actually I am sure of the reason, I think it is related how the AT&T labs made it possible. For example for moving a values from registers to another you have to write down % before it. “movl %EAX, %EBX“.

So let’s get into a very simple code:

Mov eax, 10

Mov ebx 10

Add eax, ebx


And here is the C++ code and the assembly included in:

        __asm__ volatile{“movl $10, %eax;”

“movl $10, %EBX;”

“addl %ebx, %eax”}


One of the major problems I faced was this error: “operand number out of range”, that will be for the reason that each platform will require a different syntax to include your assembly in it. Please if you face any problem, please let me know so I can help you J


Based on the latest Blog posts about Virtualization on Intel Microprocessor, and the VMM (Virtual Machine Monitor) the Hypervisor is the main component for the Virtualization. The Hypervisor most likely is called the VMM (Virtual Machine Manager), I think that this is the component that is managing the Virtual Machine Monitor of the processor to gain 3 main things:

  1. Equivalence, for executing the applications running on the guest OS as it is running on a normal PC
  2. Hardware Resource Control, this feature mainly prevents the guest OS from changing or accessing any kind of the configuration system
  3. Efficiency, that means that all the instructions of the guest OS must be executed simply and in an easy way without any interfering of the Hypervisor or the Virtual Machine Monitor.

Types of Hypervisor:

  • Bare metal Hypervisor

    The bare metal is the hypervisor that can control directly the Hardware resources and can easily manage the resources for different Guests that want to run their applications.

  • Hosted Hypervisor


    The hosted Hypervisor is a hosted hypervisor on an operating system that acts like an application that the operating systems executes its instructions.


Posted: July 24, 2012 in Live in a Cloudy World, Virtualization

Diving more in Intel Platform after one of my blog post about Virtualization on Intel Platform, I will post today about the VMCS; Virtual Machine Control Data Structure. The operation-root and the transitions between the VMM and the Guest OS are controlled by the data structure called VMCS. As each Virtual Machine runs on different logical processor (Virtual Processor) and for each logical processor, you can have several Virtual Machines on it, so for each Virtual Machine a 64-bits VMCS pointer is assigned. The logical processor associates a part of the memory called VMCS Region where the VMCS Pointer is its reference.

For the logical processor, it might have multiple VMCSs, the VMCS can set a virtual machine to be active or to be inactive. However to executes the required instructions, the VM must be active and current. No more than one Virtual Machine can be active in the same time

For each Virtual Machine running a logical processor, it may have 3 main things defining how it will run on the processor:

  • Whether to be active or inactive
  • To be current and not current
  • To be launched or clear.

Let’s take the first one, after the VMX operation (VMXON) is executed to launch the VM, the active VM is maintained its state on the memory, or the processor or even on both of them. The logical processor can’t handle more than one active VM, the others remain inactive.

The logical processor only executes one VM instruction per time, so for the active processor to simply arrange the turn for the VM to execute its function, the VM must be set to current to be able to execute its function, after that it will move to not current, so others can move to the current VM.

Finally the last thing, (this is part is hard to find on the internet, only the explained part was about the active, inactive part and the current and not current part. The only source available was through Intel developer system manual) the launch and the clear status of the VM, once the VM is moved to the current state, an operation called VMLaunch that simply controls the instructions executed with each VMCS.

I got this image from the Intel Book, it is a very good way to explain the sequence or how the VM works on the logical processor.

Guest VM

Posted: July 24, 2012 in Live in a Cloudy World, Virtualization

Continue on my previous blog posts, Virtualization on Intel Platform and the VMM (Virtual Machine Monitor), I will continue writing this time on the Guest VM. Just to summarize that the VMM acts as a host that mainly control the hardware resources. The Guest VM is a guest software environment that supports all what is related to the software and kernel that can control and executes its functions on the abstracted resources. Each Guest VM runs in an independent way with no relation with any other VM.

Talking about Virtualization on Intel Platforms, the first thing you need to know and to understand before starting developing on the Intel Processor is the VMM (the Virtual Machine Monitor). This is the responsible for managing the guest Virtual Machines. It presents the guest VM with an abstraction of the processor. it is also able to retain the hardware resources. The VMM starts by the operation of the VMXON and ends by the command of the VMXOFF. For the VM can start by the command VMLAUNCH or VMRESUME, the VMM then lose controls on the VM and can regain it when a VMEXIT command is used. Will follow this blog post with another one related to the VMM and interruption handling after I cover the guest software, VMX operations, VMX Transitions and the VMCS Region.


Posted: June 23, 2012 in Virtualization

Designing an application for the clients, you will always have to put into considerations how their data and application will be maintained. You will also have to put in mind that your application can be customized for your clients, from the user interface to some process and removed or added new functionalities. The multi-tenancy concept is how you can create multiple instance of your application for different clients in a way that each client can access his own customizable application and can only access his own data.

There are a lot of benefits for the Multi-Tenancy, in the past for hosting an application that multiple clients can use; they had to host each client’s application on separate hardware. With multi-tenancy, they all share the same application and they can make some changes in it according to their needs, which reduce the infrastructure cost and increase the level of security to make sure their data is not merged with others.

Starting to build my own cloud from scratch, as I am Microsoft Student Partner, I will start by the platform Windows Azure built on, which is Intel Microprocessor. I will start by how the Virtualization is executed on the processor level. I am sure every developer, especially those who develop using C/C++ languages are familiar with what is the data structure and why are we using it in our application. For the virtual machines, there are some structures that you have to know about, Virtual Machine Control data Structure (VMCS), you won’t find the VMCS, and the processor must have the VMX extension to allow you as developer to be able to build VMs on it or play with its internals.

The VMX extensions allow you to build 2 kinds of VMs on the processor, the first called the VMM (Virtual Machine Monitor) and the second is the Guest OS. We can know from their names that the VMM is made for the full control of the infrastructure and the hardware platform; it acts as it is the host. The Guest VM acts like a stack for the guest OS and applications, it acts and executes normally as an application with no VMM using the shared resources. Just to point out that each VM runs independently than the other VMs sharing the same resources.

So how that works and what the VMM can do to the Guest application?

The main 2 transactions made between the VMM and the guest VM is when the guest VM starts or when it exits. When the VMM send the instruction VMLAUNCH or VMRESUME, it does something like releasing the guest VM and it regains back control on it when this guest VM exits.

for the Processor, each logical processor can handle only one VM at a time that doesn’t mean that It cannot support more than that but each VM has something called the launch state which defines which VM is active and which is inactive. For the actives one, the logical processor executes the VM with the current state.