All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: oritw@il.ibm.com
Cc: kvm@vger.kernel.org, benami@il.ibm.com, abelg@il.ibm.com,
	muli@il.ibm.com, aliguori@us.ibm.com, mdday@us.ibm.com
Subject: Re: [PATCH 3/7] Nested VMX patch 3 implements vmptrld and vmptrst
Date: Wed, 16 Dec 2009 16:32:31 +0200	[thread overview]
Message-ID: <4B28EF7F.7080204@redhat.com> (raw)
In-Reply-To: <1260470309-7166-4-git-send-email-oritw@il.ibm.com>

On 12/10/2009 08:38 PM, oritw@il.ibm.com wrote:
>
> +
> +
>   struct __attribute__ ((__packed__)) level_state {
>   	/* Has the level1 guest done vmclear? */
>   	bool vmclear;
> +
> +	u64 io_bitmap_a;
> +	u64 io_bitmap_b;
> +	u64 msr_bitmap;
> +
> +	bool first_launch;
>   };
>    

Please keep things naturally aligned.

>   /*
> @@ -122,6 +255,8 @@ struct nested_vmx {
>   	gpa_t current_vmptr;
>   	/* Level 1 state for switching to level 2 and back */
>   	struct level_state *l1_state;
> +	/* Level 1 shadow vmcs for switching to level 2 and back */
> +	struct shadow_vmcs *l1_shadow_vmcs;
>   	/* list of vmcs for each l2 guest created by l1 */
>   	struct list_head l2_vmcs_list;
>   	/* l2 page corresponding to the current vmcs set by l1 */
> @@ -187,10 +322,7 @@ static struct page *nested_get_page(struct kvm_vcpu *vcpu,
>   {
>   	struct page *vmcs_page = NULL;
>
> -	down_read(&current->mm->mmap_sem);
>   	vmcs_page = gfn_to_page(vcpu->kvm, vmcs_addr>>  PAGE_SHIFT);
> -	up_read(&current->mm->mmap_sem);
>    

Fold this into the patch that introduced the problem.

> -
>   	if (is_error_page(vmcs_page)) {
>   		printk(KERN_ERR "%s error allocating page 0x%llx\n",
>   		       __func__, vmcs_addr);
> @@ -832,13 +964,14 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
>
>   	if (per_cpu(current_vmcs, cpu) != vmx->vmcs) {
>   		u8 error;
> -
>   		per_cpu(current_vmcs, cpu) = vmx->vmcs;
> +
>    

Please avoid pointless whitespace changes.

>   		asm volatile (__ex(ASM_VMX_VMPTRLD_RAX) "; setna %0"
>   			      : "=g"(error) : "a"(&phys_addr), "m"(phys_addr)
>   			      : "cc");
> +
>   		if (error)
> -			printk(KERN_ERR "kvm: vmptrld %p/%llx fail\n",
> +			printk(KERN_ERR "kvm: vmptrld %p/%llx failed\n",
>   			       vmx->vmcs, phys_addr);
>    

Fold.

> +
>   static int create_l1_state(struct kvm_vcpu *vcpu)
>   {
>   	struct vcpu_vmx *vmx = to_vmx(vcpu);
> @@ -1441,10 +1587,75 @@ static int create_l1_state(struct kvm_vcpu *vcpu)
>   	} else
>   		return 0;
>
> +	vmx->nested.l1_shadow_vmcs = kzalloc(PAGE_SIZE, GFP_KERNEL);
> +	if (!vmx->nested.l1_shadow_vmcs) {
> +		printk(KERN_INFO "%s could not allocate memory for l1_shadow vmcs\n",
> +		       __func__);
> +		kfree(vmx->nested.l1_state);
> +		return -ENOMEM;
> +	}
> +
>   	INIT_LIST_HEAD(&(vmx->nested.l2_vmcs_list));
>   	return 0;
>   }
>
> +static struct vmcs *alloc_vmcs(void);
> +int create_l2_state(struct kvm_vcpu *vcpu)
> +{
> +	struct vcpu_vmx *vmx = to_vmx(vcpu);
> +	struct vmcs *l2_vmcs;
> +
> +	if (!nested_map_current(vcpu)) {
> +		printk(KERN_ERR "%s error mapping  level 2 page", __func__);
> +		return -ENOMEM;
> +	}
> +
> +	l2_vmcs = nested_get_current_vmcs(vcpu);
> +	if (!l2_vmcs) {
> +		struct nested_vmcs_list *new_l2_guest =
> +			(struct nested_vmcs_list *)
> +			kmalloc(sizeof(struct nested_vmcs_list), GFP_KERNEL);
> +
> +		if (!new_l2_guest) {
> +			printk(KERN_ERR "%s error could not allocate memory for a new l2 guest list item",
> +			       __func__);
> +			nested_unmap_current(vcpu);
> +			return -ENOMEM;
> +		}
>    

Can the list grow without bounds?

> +
> +		l2_vmcs = alloc_vmcs();
> +
> +		if (!l2_vmcs) {
> +			printk(KERN_ERR "%s error could not allocate memory for l2_vmcs",
> +			       __func__);
> +			kfree(new_l2_guest);
> +			nested_unmap_current(vcpu);
> +			return -ENOMEM;
> +		}
> +
> +		new_l2_guest->vmcs_addr = vmx->nested.current_vmptr;
> +		new_l2_guest->l2_vmcs   = l2_vmcs;
> +		list_add(&(new_l2_guest->list),&(vmx->nested.l2_vmcs_list));
> +	}
> +
> +	if (cpu_has_vmx_msr_bitmap())
> +		vmx->nested.current_l2_page->l2_state.msr_bitmap =
> +			vmcs_read64(MSR_BITMAP);
> +	else
> +		vmx->nested.current_l2_page->l2_state.msr_bitmap = 0;
> +
> +	vmx->nested.current_l2_page->l2_state.io_bitmap_a =
> +		vmcs_read64(IO_BITMAP_A);
> +	vmx->nested.current_l2_page->l2_state.io_bitmap_b =
> +		vmcs_read64(IO_BITMAP_B);
>    

Don't understand why these reads are needed.

> +
> +	vmx->nested.current_l2_page->l2_state.first_launch = true;
> +
> +	nested_unmap_current(vcpu);
> +
> +	return 0;
> +}
> +
>   

> @@ -3633,8 +3849,9 @@ static int handle_vmon(struct kvm_vcpu *vcpu)
>   		return 1;
>   	}
>
> -	if (create_l1_state(vcpu)) {
> -		printk(KERN_ERR "%s create_l1_state failed\n", __func__);
> +	r = create_l1_state(vcpu);
> +	if (r) {
> +		printk(KERN_ERR "%s create_l1_state failed: %d\n", __func__, r);
>    

Move this to the original patch.

>   		kvm_queue_exception(vcpu, UD_VECTOR);
>   		return 1;
>   	}
> @@ -3645,6 +3862,63 @@ static int handle_vmon(struct kvm_vcpu *vcpu)
>   	return 1;
>   }
>
> +static int handle_vmptrld(struct kvm_vcpu *vcpu)
> +{
> +	struct vcpu_vmx *vmx = to_vmx(vcpu);
> +	u64 guest_vmcs_addr;
> +	gva_t vmcs_gva;
> +	unsigned long exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
> +	u32 vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO);
> +	int r = 0;
> +
> +	if (!nested_vmx_check_permission(vcpu))
> +		return 1;
> +
> +	vmcs_gva = get_vmx_mem_address(vcpu, exit_qualification,
> +				       vmx_instruction_info);
> +
> +	if (read_guest_vmcs_gpa(vcpu, vmcs_gva,&guest_vmcs_addr))
> +		return 1;
> +
> +	if (vmx->nested.current_vmptr != guest_vmcs_addr) {
> +		vmx->nested.current_vmptr = guest_vmcs_addr;
> +		r = create_l2_state(vcpu);
> +		if (r) {
> +			printk(KERN_ERR "%s create_l2_state failed: %d\n",
> +			       __func__, r);
> +			return 1;
> +		}
> +	}
> +
> +	clear_rflags_cf_zf(vcpu);
> +	skip_emulated_instruction(vcpu);
> +	return 1;
>    

No set_rflags() on error?

-- 
error compiling committee.c: too many arguments to function


  parent reply	other threads:[~2009-12-16 14:32 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-10 18:38 Nested VMX support v4 oritw
2009-12-10 18:38 ` [PATCH 1/7] Nested VMX patch 1 implements vmon and vmoff oritw
2009-12-10 18:38   ` [PATCH 2/7] Nested VMX patch 2 implements vmclear oritw
2009-12-10 18:38     ` [PATCH 3/7] Nested VMX patch 3 implements vmptrld and vmptrst oritw
2009-12-10 18:38       ` [PATCH 4/7] Nested VMX patch 4 implements vmread and vmwrite oritw
2009-12-10 18:38         ` [PATCH 5/7] Nested VMX patch 5 Simplify fpu handling oritw
2009-12-10 18:38           ` [PATCH 6/7] Nested VMX patch 6 implements vmlaunch and vmresume oritw
2009-12-10 18:38             ` [PATCH 7/7] Nested VMX patch 7 handling of nested guest exits oritw
2009-12-17 13:46               ` Avi Kivity
2009-12-17 10:10             ` [PATCH 6/7] Nested VMX patch 6 implements vmlaunch and vmresume Avi Kivity
2009-12-17  9:10           ` [PATCH 5/7] Nested VMX patch 5 Simplify fpu handling Avi Kivity
2009-12-16 14:44         ` [PATCH 4/7] Nested VMX patch 4 implements vmread and vmwrite Avi Kivity
2009-12-16 14:32       ` Avi Kivity [this message]
2009-12-16 13:59     ` [PATCH 2/7] Nested VMX patch 2 implements vmclear Avi Kivity
2009-12-28 14:57     ` Gleb Natapov
2009-12-16 13:34   ` [PATCH 1/7] Nested VMX patch 1 implements vmon and vmoff Avi Kivity
2009-12-20 14:20   ` Gleb Natapov
2009-12-20 14:23     ` Avi Kivity
2009-12-20 14:25       ` Gleb Natapov
2009-12-20 17:08     ` Andi Kleen
2009-12-20 19:04       ` Avi Kivity
2009-12-21 15:52         ` Muli Ben-Yehuda
2009-12-21 16:00           ` Avi Kivity
2009-12-17 13:49 ` Nested VMX support v4 Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B28EF7F.7080204@redhat.com \
    --to=avi@redhat.com \
    --cc=abelg@il.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=benami@il.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=mdday@us.ibm.com \
    --cc=muli@il.ibm.com \
    --cc=oritw@il.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.