From patchwork Mon Jan 14 22:02:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 1973891 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 2FEE6DF2E1 for ; Mon, 14 Jan 2013 22:05:54 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Tus7Q-0007or-B4; Mon, 14 Jan 2013 22:03:00 +0000 Received: from mail-ie0-f182.google.com ([209.85.223.182]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Tus7M-0007oI-Ae for linux-arm-kernel@lists.infradead.org; Mon, 14 Jan 2013 22:02:57 +0000 Received: by mail-ie0-f182.google.com with SMTP id s9so5999305iec.13 for ; Mon, 14 Jan 2013 14:02:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:cc:content-type:x-gm-message-state; bh=Egi0B0u+ErWn569n592yXLbOcMx8ZJDuOAKCghNW3Jo=; b=ec0DIadrd6SCx/dAEo25MApXUH45+KAvSCvZAmCEkjFD+JwcrQsEqSKGDQWe8vibqq lf8gZvZLQgeWcu1owSJgH7xDSblopxHPxek3Y78P8RMcDNTriRGGErkT78uYBE+9hzAz cZLp8Y4iHT24p77eSBiDy3JUtH3GQK4dcIwEAcGKMbpmATTJuq98AsiLBg1uVBoKzBm0 LDr1d1DA/ooQlkP6AqKTHSnCKtDCaVy2C/gDtXD01SS9L7fjVLF//uUa1oXaRcudK8SP C9lWSxjs3ptL+9DSqcIx7DJZwK5kX8TJG9vDYX2XL/ASXCdoYs7ptQPWLR0vcoi4R86T NAcw== MIME-Version: 1.0 Received: by 10.50.36.198 with SMTP id s6mr39013igj.23.1358200975266; Mon, 14 Jan 2013 14:02:55 -0800 (PST) Received: by 10.64.37.70 with HTTP; Mon, 14 Jan 2013 14:02:55 -0800 (PST) X-Originating-IP: [72.80.83.148] In-Reply-To: <20130114154231.GG18935@mudshark.cambridge.arm.com> References: <20130108184116.46558.3558.stgit@ubuntu> <20130108184211.46558.74646.stgit@ubuntu> <20130114154231.GG18935@mudshark.cambridge.arm.com> Date: Mon, 14 Jan 2013 17:02:55 -0500 Message-ID: Subject: Re: [PATCH v5 07/12] ARM: KVM: VGIC virtual CPU interface management From: Christoffer Dall To: Will Deacon X-Gm-Message-State: ALoCoQn/lMgGynTJAZ8lgQjMClVuwRaPLsAcoTQJkTROtQy3xZb2RGlgEkcKAXkZCa8UmCLGg0i1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130114_170256_588937_DAD765A1 X-CRM114-Status: GOOD ( 23.48 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.223.182 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Marc Zyngier , "linux-arm-kernel@lists.infradead.org" , "kvm@vger.kernel.org" , "kvmarm@lists.cs.columbia.edu" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org On Mon, Jan 14, 2013 at 10:42 AM, Will Deacon wrote: > On Tue, Jan 08, 2013 at 06:42:11PM +0000, Christoffer Dall wrote: >> From: Marc Zyngier >> >> Add VGIC virtual CPU interface code, picking pending interrupts >> from the distributor and stashing them in the VGIC control interface >> list registers. >> >> Signed-off-by: Marc Zyngier >> Signed-off-by: Christoffer Dall >> --- >> arch/arm/include/asm/kvm_vgic.h | 30 ++++ >> arch/arm/kvm/vgic.c | 327 +++++++++++++++++++++++++++++++++++++++ >> 2 files changed, 356 insertions(+), 1 deletion(-) >> >> diff --git a/arch/arm/include/asm/kvm_vgic.h b/arch/arm/include/asm/kvm_vgic.h >> index 9ff0d9c..b3133c4 100644 >> --- a/arch/arm/include/asm/kvm_vgic.h >> +++ b/arch/arm/include/asm/kvm_vgic.h >> @@ -110,8 +110,33 @@ struct vgic_dist { >> }; >> >> struct vgic_cpu { >> +#ifdef CONFIG_KVM_ARM_VGIC >> + /* per IRQ to LR mapping */ >> + u8 vgic_irq_lr_map[VGIC_NR_IRQS]; >> + >> + /* Pending interrupts on this VCPU */ >> + DECLARE_BITMAP( pending_percpu, VGIC_NR_PRIVATE_IRQS); >> + DECLARE_BITMAP( pending_shared, VGIC_NR_SHARED_IRQS); >> + >> + /* Bitmap of used/free list registers */ >> + DECLARE_BITMAP( lr_used, 64); >> + >> + /* Number of list registers on this CPU */ >> + int nr_lr; >> + >> + /* CPU vif control registers for world switch */ >> + u32 vgic_hcr; >> + u32 vgic_vmcr; >> + u32 vgic_misr; /* Saved only */ >> + u32 vgic_eisr[2]; /* Saved only */ >> + u32 vgic_elrsr[2]; /* Saved only */ >> + u32 vgic_apr; >> + u32 vgic_lr[64]; /* A15 has only 4... */ > > Have a #define for the maximum number of list registers. > >> +#endif >> }; >> >> +#define LR_EMPTY 0xff >> + >> struct kvm; >> struct kvm_vcpu; >> struct kvm_run; >> @@ -119,9 +144,14 @@ struct kvm_exit_mmio; >> >> #ifdef CONFIG_KVM_ARM_VGIC >> int kvm_vgic_set_addr(struct kvm *kvm, unsigned long type, u64 addr); >> +void kvm_vgic_sync_to_cpu(struct kvm_vcpu *vcpu); >> +void kvm_vgic_sync_from_cpu(struct kvm_vcpu *vcpu); > > Same comment as for the arch timer (flush/sync). > >> +int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu); >> bool vgic_handle_mmio(struct kvm_vcpu *vcpu, struct kvm_run *run, >> struct kvm_exit_mmio *mmio); >> >> +#define irqchip_in_kernel(k) (!!((k)->arch.vgic.vctrl_base)) >> + >> #else >> static inline int kvm_vgic_hyp_init(void) >> { >> diff --git a/arch/arm/kvm/vgic.c b/arch/arm/kvm/vgic.c >> index bd2bd7f..58237d5 100644 >> --- a/arch/arm/kvm/vgic.c >> +++ b/arch/arm/kvm/vgic.c >> @@ -152,6 +152,34 @@ static int vgic_irq_is_enabled(struct kvm_vcpu *vcpu, int irq) >> return vgic_bitmap_get_irq_val(&dist->irq_enabled, vcpu->vcpu_id, irq); >> } >> >> +static int vgic_irq_is_active(struct kvm_vcpu *vcpu, int irq) >> +{ >> + struct vgic_dist *dist = &vcpu->kvm->arch.vgic; >> + >> + return vgic_bitmap_get_irq_val(&dist->irq_active, vcpu->vcpu_id, irq); >> +} >> + >> +static void vgic_irq_set_active(struct kvm_vcpu *vcpu, int irq) >> +{ >> + struct vgic_dist *dist = &vcpu->kvm->arch.vgic; >> + >> + vgic_bitmap_set_irq_val(&dist->irq_active, vcpu->vcpu_id, irq, 1); >> +} >> + >> +static void vgic_irq_clear_active(struct kvm_vcpu *vcpu, int irq) >> +{ >> + struct vgic_dist *dist = &vcpu->kvm->arch.vgic; >> + >> + vgic_bitmap_set_irq_val(&dist->irq_active, vcpu->vcpu_id, irq, 0); >> +} >> + >> +static int vgic_dist_irq_is_pending(struct kvm_vcpu *vcpu, int irq) >> +{ >> + struct vgic_dist *dist = &vcpu->kvm->arch.vgic; >> + >> + return vgic_bitmap_get_irq_val(&dist->irq_state, vcpu->vcpu_id, irq); >> +} >> + >> static void vgic_dist_irq_set(struct kvm_vcpu *vcpu, int irq) >> { >> struct vgic_dist *dist = &vcpu->kvm->arch.vgic; >> @@ -711,7 +739,30 @@ static void vgic_dispatch_sgi(struct kvm_vcpu *vcpu, u32 reg) >> >> static int compute_pending_for_cpu(struct kvm_vcpu *vcpu) >> { >> - return 0; >> + struct vgic_dist *dist = &vcpu->kvm->arch.vgic; >> + unsigned long *pending, *enabled, *pend_percpu, *pend_shared; >> + unsigned long pending_private, pending_shared; >> + int vcpu_id; >> + >> + vcpu_id = vcpu->vcpu_id; >> + pend_percpu = vcpu->arch.vgic_cpu.pending_percpu; >> + pend_shared = vcpu->arch.vgic_cpu.pending_shared; >> + >> + pending = vgic_bitmap_get_cpu_map(&dist->irq_state, vcpu_id); >> + enabled = vgic_bitmap_get_cpu_map(&dist->irq_enabled, vcpu_id); >> + bitmap_and(pend_percpu, pending, enabled, VGIC_NR_PRIVATE_IRQS); >> + >> + pending = vgic_bitmap_get_shared_map(&dist->irq_state); >> + enabled = vgic_bitmap_get_shared_map(&dist->irq_enabled); >> + bitmap_and(pend_shared, pending, enabled, VGIC_NR_SHARED_IRQS); >> + bitmap_and(pend_shared, pend_shared, >> + vgic_bitmap_get_shared_map(&dist->irq_spi_target[vcpu_id]), >> + VGIC_NR_SHARED_IRQS); >> + >> + pending_private = find_first_bit(pend_percpu, VGIC_NR_PRIVATE_IRQS); >> + pending_shared = find_first_bit(pend_shared, VGIC_NR_SHARED_IRQS); >> + return (pending_private < VGIC_NR_PRIVATE_IRQS || >> + pending_shared < VGIC_NR_SHARED_IRQS); >> } >> >> /* >> @@ -737,6 +788,280 @@ static void vgic_update_state(struct kvm *kvm) >> } >> } >> >> +#define LR_CPUID(lr) \ >> + (((lr) & GICH_LR_PHYSID_CPUID) >> GICH_LR_PHYSID_CPUID_SHIFT) >> +#define MK_LR_PEND(src, irq) \ >> + (GICH_LR_PENDING_BIT | ((src) << GICH_LR_PHYSID_CPUID_SHIFT) | (irq)) >> +/* >> + * Queue an interrupt to a CPU virtual interface. Return true on success, >> + * or false if it wasn't possible to queue it. >> + */ >> +static bool vgic_queue_irq(struct kvm_vcpu *vcpu, u8 sgi_source_id, int irq) >> +{ >> + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; >> + int lr; >> + >> + /* Sanitize the input... */ >> + BUG_ON(sgi_source_id & ~7); >> + BUG_ON(sgi_source_id && irq > 15); > > You can use your new NR_SGIS definition here. > This should address the remaining comments: commit 43957095ec5476beb198f4c4630dfc3e2f3951db Author: Christoffer Dall Date: Mon Jan 14 16:59:38 2013 -0500 KVM: ARM: vgic: Define VGIC_MAX_LRS Define maximum number of link registers we can handle instead of using literals in the code. If an architecture reports more link registers than we support, only use the number we can support. Signed-off-by: Christoffer Dall --- Thanks, -Christoffer diff --git a/arch/arm/include/asm/kvm_vgic.h b/arch/arm/include/asm/kvm_vgic.h index 1ace491..f9d1977 100644 --- a/arch/arm/include/asm/kvm_vgic.h +++ b/arch/arm/include/asm/kvm_vgic.h @@ -33,6 +33,7 @@ #define VGIC_NR_PRIVATE_IRQS (VGIC_NR_SGIS + VGIC_NR_PPIS) #define VGIC_NR_SHARED_IRQS (VGIC_NR_IRQS - VGIC_NR_PRIVATE_IRQS) #define VGIC_MAX_CPUS KVM_MAX_VCPUS +#define VGIC_MAX_LRS 64 /* Sanity checks... */ #if (VGIC_MAX_CPUS > 8) @@ -120,7 +121,7 @@ struct vgic_cpu { DECLARE_BITMAP( pending_shared, VGIC_NR_SHARED_IRQS); /* Bitmap of used/free list registers */ - DECLARE_BITMAP( lr_used, 64); + DECLARE_BITMAP( lr_used, VGIC_MAX_LRS); /* Number of list registers on this CPU */ int nr_lr; @@ -132,7 +133,7 @@ struct vgic_cpu { u32 vgic_eisr[2]; /* Saved only */ u32 vgic_elrsr[2]; /* Saved only */ u32 vgic_apr; - u32 vgic_lr[64]; /* A15 has only 4... */ + u32 vgic_lr[VGIC_MAX_LRS]; #endif }; diff --git a/arch/arm/kvm/vgic.c b/arch/arm/kvm/vgic.c index a0d283c..90a99fd 100644 --- a/arch/arm/kvm/vgic.c +++ b/arch/arm/kvm/vgic.c @@ -1345,6 +1345,8 @@ int kvm_vgic_hyp_init(void) vgic_nr_lr = readl_relaxed(vgic_vctrl_base + GICH_VTR); vgic_nr_lr = (vgic_nr_lr & 0x1f) + 1; + if (vgic_nr_lr > VGIC_MAX_LRS) + vgic_nr_lr = VGIC_MAX_LRS; /* TODO: Clear remaining LRs */ ret = create_hyp_io_mappings(vgic_vctrl_base, vgic_vctrl_base + resource_size(&vctrl_res),