All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Christoffer Dall <c.dall@virtualopensystems.com>
Cc: android-virt@lists.cs.columbia.edu, kvm@vger.kernel.org,
	Marc.Zyngier@arm.com, catalin.marinas@arm.com,
	tech@virtualopensystems.com, peter.maydell@linaro.org
Subject: Re: [PATCH v5 11/13] ARM: KVM: Support SMP hosts
Date: Mon, 12 Dec 2011 16:30:47 +0200	[thread overview]
Message-ID: <4EE61017.3090106@redhat.com> (raw)
In-Reply-To: <20111211102529.21693.62306.stgit@localhost>

On 12/11/2011 12:25 PM, Christoffer Dall wrote:
> In order to support KVM on a SMP host, it is necessary to initialize the
> hypervisor on all CPUs, mostly by making sure each CPU gets its own
> hypervisor stack and runs the HYP init code.
>
> We also take care of some missing locking of modifications to the
> hypervisor page tables and ensure synchronized consistency between
> virtual IRQ masks and wait_for_interrupt flags on the VPUs.
>
> Note that this code doesn't handle CPU hotplug yet.
> Note that this code doesn't support SMP guests.
>
> WARNING: This code is in development and guests do not fully boot on SMP
> hosts yet.

Damn, I just reviewed all that breakage.

>  
>  	/* Misc. fields */
> +	spinlock_t irq_lock;
> +	u32 virt_irq;		/* HCR exception mask */
>  	u32 wait_for_interrupts;

Better to use atomics, IMO.

> @@ -464,13 +466,27 @@ static int kvm_arch_vm_ioctl_irq_line(struct kvm *kvm,
>  
>  	trace_kvm_irq_line(irq_level->irq % 2, irq_level->level, vcpu_idx);
>  
> +	spin_lock(&vcpu->arch.irq_lock);
>  	if (irq_level->level) {
>  		vcpu->arch.virt_irq |= mask;
> +
> +		/*
> +		 * Note that we grab the wq.lock before clearing the wfi flag
> +		 * since this ensures that a concurrent call to kvm_vcpu_block
> +		 * will either sleep before we grab the lock, in which case we
> +		 * wake it up, or will never sleep due to
> +		 * kvm_arch_vcpu_runnable being true (iow. this avoids having
> +		 * to grab the irq_lock in kvm_arch_vcpu_runnable).
> +		 */
> +		spin_lock(&vcpu->wq.lock);
>  		vcpu->arch.wait_for_interrupts = 0;
> +
>  		if (waitqueue_active(&vcpu->wq))
> -			wake_up_interruptible(&vcpu->wq);
> +			__wake_up_locked(&vcpu->wq, TASK_INTERRUPTIBLE);
> +		spin_unlock(&vcpu->wq.lock);
>  	} else
>  		vcpu->arch.virt_irq &= ~mask;
> +	spin_unlock(&vcpu->arch.irq_lock);

This looks overly complicated with two levels of locks.  x86 gets by
with no locks, and a much more complicated interrupt architecture.

My recommendation is:
  wait_for_interrupts is managed solely by the vcpu thread
  KVM_IRQ_LINE does a set_bit(, virt_irq) for the appropriate irq type,
then IPI/wakeups the vcpu to make it examine both wait_for_interrupts
and virt_irq.


> +
> +static void cpu_init_hyp_mode(void *vector)
> +{
> +	unsigned long hyp_stack_ptr;
> +	void *stack_page;
> +
> +	stack_page = __get_cpu_var(kvm_arm_hyp_stack_page);
> +	hyp_stack_ptr = (unsigned long)stack_page + PAGE_SIZE;
> +
> +	cpu_set_vector(vector);
> +
> +	/*
> +	 * Call initialization code
> +	 */
> +	asm volatile (
> +		"mov	r0, %[pgd_ptr]\n\t"
> +		"mov	r1, %[stack_ptr]\n\t"
> +		"hvc	#0\n\t" : :
> +		[pgd_ptr] "r" (virt_to_phys(kvm_hyp_pgd)),
> +		[stack_ptr] "r" (hyp_stack_ptr) :
> +		"r0", "r1");
> +}

(slightly nicer is to allocate hyp_stack_ptr and pgd_ptr to "register
asm("r0")" and "register asm("r1")" to avoid the extra mov instruction)

> @@ -522,47 +573,42 @@ static int init_hyp_mode(void)
>  		return -ENOMEM;
>  
>  	/*
> -	 * Allocate stack page for Hypervisor-mode
> +	 * Allocate stack pages for Hypervisor-mode
>  	 */
> -	kvm_arm_hyp_stack_page = (void *)__get_free_page(GFP_KERNEL);
> -	if (!kvm_arm_hyp_stack_page) {
> -		err = -ENOMEM;
> -		goto out_free_pgd;
> -	}
> +	for_each_possible_cpu(cpu) {
> +		void *stack_page;
>  
> -	hyp_stack_ptr = (unsigned long)kvm_arm_hyp_stack_page + PAGE_SIZE;
> +		stack_page = (void *)__get_free_page(GFP_KERNEL);

Best to allocate this (and other per-cpu state) on the cpu's node.

> +		if (!stack_page) {
> +			err = -ENOMEM;
> +			goto out_free_pgd;
> +		}
> +
> +		per_cpu(kvm_arm_hyp_stack_page, cpu) = stack_page;
> +	}
>  
>  	init_phys_addr = virt_to_phys(__kvm_hyp_init);
>  	init_end_phys_addr = virt_to_phys(__kvm_hyp_init_end);
> +	BUG_ON(init_phys_addr & 0x1f);
>  
>  	/*
> -	 * Create identity mapping
> +	 * Create identity mapping for the init code.
>  	 */
>  	hyp_identity_mapping_add(kvm_hyp_pgd,
>  				 (unsigned long)init_phys_addr,
>  				 (unsigned long)init_end_phys_addr);
>  
> +	for_each_online_cpu(cpu) {
> +		smp_call_function_single(cpu, cpu_init_hyp_mode,
> +					 (void *)(long)init_phys_addr, 1);
> +	}

Need similar code for cpu hotplug.  See kvm_cpu_hotplug() and
kvm_arch_hardware_enable() which do all this for you.


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


  reply	other threads:[~2011-12-12 14:31 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-11 10:24 [PATCH v5 00/13] KVM/ARM Implementation Christoffer Dall
2011-12-11 10:24 ` [PATCH v5 01/13] ARM: KVM: Initial skeleton to compile KVM support Christoffer Dall
2011-12-11 10:24 ` [PATCH v5 02/13] ARM: KVM: Hypervisor identity mapping Christoffer Dall
2011-12-11 10:24 ` [PATCH v5 03/13] ARM: KVM: Add hypervisor inititalization Christoffer Dall
2011-12-11 10:24 ` [PATCH v5 04/13] ARM: KVM: Memory virtualization setup Christoffer Dall
2011-12-12 14:40   ` Avi Kivity
2011-12-12 15:09     ` [Android-virt] " Christoffer Dall
2011-12-12 15:15       ` Avi Kivity
2011-12-12 15:25         ` Peter Maydell
2011-12-12 15:49           ` Avi Kivity
2011-12-12 17:40             ` Christoffer Dall
2011-12-13 17:10             ` Antonios Motakis
2011-12-13 17:13               ` Christoffer Dall
2011-12-11 10:24 ` [PATCH v5 05/13] ARM: KVM: Inject IRQs and FIQs from userspace Christoffer Dall
2011-12-11 15:18   ` Jan Kiszka
2011-12-11 16:03     ` Peter Maydell
2011-12-11 19:30       ` Christoffer Dall
2011-12-11 19:48         ` Peter Maydell
2011-12-11 20:07           ` [Android-virt] " Christoffer Dall
2011-12-11 20:25             ` Peter Maydell
2011-12-11 21:36               ` Christoffer Dall
2011-12-11 22:12                 ` Peter Maydell
2011-12-11 22:35                   ` Peter Maydell
2011-12-11 22:53                     ` Christoffer Dall
2011-12-11 23:01                       ` Jan Kiszka
2011-12-12 16:31                         ` Peter Maydell
2011-12-12 17:40                           ` Avi Kivity
2011-12-29  1:29                             ` Christoffer Dall
2012-02-09  1:15                             ` Peter Maydell
2011-12-12 11:06             ` Marc Zyngier
2011-12-12 12:54               ` Christoffer Dall
2011-12-12  6:35           ` Alexander Graf
2011-12-11 19:16     ` Christoffer Dall
2011-12-12 13:28   ` Avi Kivity
2011-12-12 14:38     ` [Android-virt] " Christoffer Dall
2011-12-12 14:50       ` Avi Kivity
2011-12-12 15:11         ` Christoffer Dall
2011-12-12 15:16           ` Avi Kivity
2011-12-11 10:24 ` [PATCH v5 06/13] ARM: KVM: World-switch implementation Christoffer Dall
2011-12-11 10:25 ` [PATCH v5 07/13] ARM: KVM: Emulation framework and CP15 emulation Christoffer Dall
2011-12-12 13:44   ` Avi Kivity
2011-12-12 16:17     ` Christoffer Dall
2011-12-11 10:25 ` [PATCH v5 08/13] ARM: KVM: Handle guest faults in KVM Christoffer Dall
2011-12-12 15:05   ` Avi Kivity
2011-12-12 19:53     ` Christoffer Dall
2011-12-13  9:45       ` Avi Kivity
2011-12-13 13:10         ` [Android-virt] " Christoffer Dall
2011-12-13 13:17           ` Marc Zyngier
2011-12-13 13:23           ` Avi Kivity
2011-12-13 13:44             ` Christoffer Dall
2011-12-13 14:27               ` Avi Kivity
2011-12-11 10:25 ` [PATCH v5 09/13] ARM: KVM: Handle I/O aborts Christoffer Dall
2011-12-12 13:54   ` Avi Kivity
2011-12-12 14:56     ` [Android-virt] " Christoffer Dall
2011-12-11 10:25 ` [PATCH v5 10/13] ARM: KVM: Guest wait-for-interrupts (WFI) support Christoffer Dall
2011-12-12 14:12   ` Avi Kivity
2011-12-12 16:20     ` Christoffer Dall
2011-12-12 17:44       ` Avi Kivity
2011-12-12 19:21         ` [Android-virt] " Christoffer Dall
2011-12-13  9:41           ` Avi Kivity
2011-12-11 10:25 ` [PATCH v5 11/13] ARM: KVM: Support SMP hosts Christoffer Dall
2011-12-12 14:30   ` Avi Kivity [this message]
2011-12-12 17:37     ` Christoffer Dall
2011-12-12 17:56       ` Avi Kivity
2011-12-12 19:38         ` [Android-virt] " Christoffer Dall
     [not found]         ` <CAEDV+gJ=zeDpfp0kS2uBvmgRMyCpsV1LitjKR66R4W9Y3VGgWw@mail.gmail.com>
     [not found]           ` <4EE71CF1.5080705@redhat.com>
2011-12-13 13:36             ` Christoffer Dall
2011-12-13 14:17               ` Avi Kivity
2011-12-13 14:36                 ` Christoffer Dall
2011-12-13 14:17               ` Marc Zyngier
2011-12-19  6:15   ` Antonios Motakis
2011-12-19 14:57     ` [Android-virt] " Christoffer Dall
2011-12-19 15:19       ` Marc Zyngier
2011-12-19 15:30         ` Antonios Motakis
2011-12-19 15:37           ` Marc Zyngier
2011-12-19 15:40             ` Christoffer Dall
2011-12-19 15:42               ` Antonios Motakis
2011-12-19 15:45                 ` Marc Zyngier
     [not found]                   ` <CAEDV+gL929Hpa=PncVWeHRNAa5fBuorNNYFC=iix=PO+5aO2cg@mail.gmail.com>
2011-12-19 17:19                     ` Peter Maydell
2011-12-19 17:24                       ` Christoffer Dall
2011-12-19 17:36                         ` Peter Maydell
2011-12-19 17:40                           ` Christoffer Dall
2011-12-11 10:25 ` [PATCH v5 12/13] ARM: KVM: Fix guest view of MPIDR Christoffer Dall
2011-12-12 14:32   ` Avi Kivity
2011-12-12 17:39     ` Christoffer Dall
2011-12-12 17:44       ` Marc Zyngier
2011-12-12 19:43         ` Christoffer Dall
2011-12-13  9:46           ` Avi Kivity
2011-12-13 13:38             ` Christoffer Dall
2011-12-11 10:25 ` [PATCH v5 13/13] ARM: KVM: Support SMP guests Christoffer Dall
2011-12-11 11:32 ` [PATCH v5 00/13] KVM/ARM Implementation Peter Maydell
2011-12-11 19:23   ` Christoffer Dall
2011-12-11 19:27     ` Peter Maydell
2012-01-11 16:48     ` Peter Maydell
2012-01-12  3:29       ` Christoffer Dall
2012-01-12  8:19         ` Peter Maydell
2012-01-12 16:15           ` [Android-virt] " Christoffer Dall
2012-01-20  2:59             ` Christoffer Dall
2012-01-30 22:46               ` Peter Maydell
2012-01-30 23:02                 ` Alexander Graf
2012-01-31 14:39                 ` Antonios Motakis
2012-02-01 12:11                 ` Marc Zyngier
2012-02-01 12:20                   ` Peter Maydell
2012-02-01 13:40                     ` Marc Zyngier
2012-02-01 13:57                       ` Peter Maydell
2012-02-01 13:59                       ` Christoffer Dall

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=4EE61017.3090106@redhat.com \
    --to=avi@redhat.com \
    --cc=Marc.Zyngier@arm.com \
    --cc=android-virt@lists.cs.columbia.edu \
    --cc=c.dall@virtualopensystems.com \
    --cc=catalin.marinas@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=peter.maydell@linaro.org \
    --cc=tech@virtualopensystems.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.