On Wed, May 14, 2008 at 11:30 PM, Daniel Baluta <daniel.baluta@xxxxxxxxx> wrote: > Hello , > > Can you guide me to a deeper understanding of the paravirt ops. > > This article > > http://lwn.net/Articles/194543/ > > is pretty short and it dates since August 8, 2006. > > Thank-you , > Daniel. > Starting point is at setup_arch() (arch/x86/kernel/setup_32.c): #ifdef CONFIG_KVM_CLOCK kvmclock_init(); #endif #ifdef CONFIG_VMI /* * Must be after max_low_pfn is determined, and before kernel * pagetables are setup. */ vmi_init(); #endif kvm_guest_init(); >From above we can see the different virtualization technology is being initialized - VMI and KVM....etc. Next is arch/x86/kernel/vmi_32.c (API invented by VMWare). One example structure is this: static struct { void (*cpuid)(void /* non-c */); void (*_set_ldt)(u32 selector); void (*set_tr)(u32 selector); void (*write_idt_entry)(struct desc_struct *, int, u32, u32); void (*write_gdt_entry)(struct desc_struct *, int, u32, u32); void (*write_ldt_entry)(struct desc_struct *, int, u32, u32); void (*set_kernel_stack)(u32 selector, u32 sp0); void (*allocate_page)(u32, u32, u32, u32, u32); void (*release_page)(u32, u32); void (*set_pte)(pte_t, pte_t *, unsigned); void (*update_pte)(pte_t *, unsigned); void (*set_linear_mapping)(int, void *, u32, u32); void (*_flush_tlb)(int); void (*set_initial_ap_state)(int, int); void (*halt)(void); void (*set_lazy_mode)(int mode); } vmi_ops; And inside this file are like (from activate_vmi()): para_wrap(pv_cpu_ops.cpuid, vmi_cpuid, cpuid, CPUID); para_fill(pv_cpu_ops.clts, CLTS); para_fill(pv_cpu_ops.get_debugreg, GetDR); para_fill(pv_cpu_ops.set_debugreg, SetDR); para_fill(pv_cpu_ops.read_cr0, GetCR0); para_fill(pv_mmu_ops.read_cr2, GetCR2); para_fill(pv_mmu_ops.read_cr3, GetCR3); para_fill(pv_cpu_ops.read_cr4, GetCR4); para_fill(pv_cpu_ops.write_cr0, SetCR0); para_fill(pv_mmu_ops.write_cr2, SetCR2); para_fill(pv_mmu_ops.write_cr3, SetCR3); para_fill(pv_cpu_ops.write_cr4, SetCR4); para_fill(pv_irq_ops.save_fl, GetInterruptMask); para_fill(pv_irq_ops.restore_fl, SetInterruptMask); para_fill(pv_irq_ops.irq_disable, DisableInterrupts What are these? Just take a look at include/asm-x86/paravirt.h - which provides the mapping between the paravirtualized guest OS's resources vs the actual system resources. Eg: struct pv_cpu_ops { /* hooks for various privileged instructions */ unsigned long (*read_cr0)(void);===> Executing inside the hypervisor, this is the function actually called, if the guest OS issued a "read CR0" assembly instruction. void (*write_cr0)(unsigned long); unsigned long (*read_cr4_safe)(void); unsigned long (*read_cr4)(void); void (*write_cr4)(unsigned long); void (*load_tr_desc)(void); void (*load_gdt)(const struct desc_ptr *); void (*load_idt)(const struct desc_ptr *); void (*store_gdt)(struct desc_ptr *); void (*store_idt)(struct desc_ptr *); void (*set_ldt)(const void *desc, unsigned entries); unsigned long (*store_tr)(void); void (*load_tls)(struct thread_struct *t, unsigned int cpu); void (*write_ldt_entry)(struct desc_struct *ldt, int entrynum, const void *desc); The other resources inside paravirt.h is easy to deduce. Essentially pv_cpu_ops provides the base structure for the different technologies like KVM/Xen/VMI etc. -- Regards, Peter Teoh -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ