From patchwork Wed Jun 11 16:27:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 31788 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f70.google.com (mail-pb0-f70.google.com [209.85.160.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 36104203C2 for ; Wed, 11 Jun 2014 16:29:36 +0000 (UTC) Received: by mail-pb0-f70.google.com with SMTP id rq2sf19474111pbb.5 for ; Wed, 11 Jun 2014 09:29:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=5TEewRoDUX0hEl//DQdSr1ADGiU/xkEfYeMsX8Bu59s=; b=OrSGm7MuoHB8sV/F2/kWZl4/b78UQQilPtbvxC3fYZZlcMCSccghGv6aFKj+hMCzkP Qw2mP3Ey/K4v0bhzTBh7rfmhmiDcumxTOz/dkRjxMjO+s+8TJmCOuAR0xXZofp/Sptmf ihx4yEXp7tWUUPFQXBDEm9QwBPuNEI6btr0QR7df40Ox9XQ6ZXL71RXbINdW/wT/ako5 Sr02EJ1lDTKSaGvSYGKbpo1/NnJcknql+1Al+Ky44d30G3WiJbeGFcPYdSlIgxx+kFnj t6x5S+SiUhWx8aMVoxYQXV9iabvd/vFUXarxE/ql/nLGt+tcxlihfDawVcylTEoW9C4o 5sVg== X-Gm-Message-State: ALoCoQnxMdwBsR7qUfVcoGu4kdoTewwPFXYjSoQZOKTqb7ZHalWYomeiiKWwTNjRDw+GnhpYL1Qc X-Received: by 10.66.66.163 with SMTP id g3mr5394522pat.3.1402504175554; Wed, 11 Jun 2014 09:29:35 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.108.4 with SMTP id i4ls2586990qgf.78.gmail; Wed, 11 Jun 2014 09:29:35 -0700 (PDT) X-Received: by 10.221.50.70 with SMTP id vd6mr1929701vcb.51.1402504175363; Wed, 11 Jun 2014 09:29:35 -0700 (PDT) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id dm6si13109531vcb.96.2014.06.11.09.29.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Jun 2014 09:29:35 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.174 as permitted sender) client-ip=209.85.128.174; Received: by mail-ve0-f174.google.com with SMTP id us18so9316767veb.5 for ; Wed, 11 Jun 2014 09:29:35 -0700 (PDT) X-Received: by 10.58.56.71 with SMTP id y7mr1255587vep.24.1402504175219; Wed, 11 Jun 2014 09:29:35 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.54.6 with SMTP id vs6csp317036vcb; Wed, 11 Jun 2014 09:29:34 -0700 (PDT) X-Received: by 10.220.190.197 with SMTP id dj5mr39703621vcb.19.1402504174794; Wed, 11 Jun 2014 09:29:34 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id er10si7193473vdc.28.2014.06.11.09.29.34 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 11 Jun 2014 09:29:34 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WulNJ-0007Ob-PU; Wed, 11 Jun 2014 16:27:45 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WulNH-0007MY-Ef for xen-devel@lists.xensource.com; Wed, 11 Jun 2014 16:27:43 +0000 Received: from [85.158.137.68:24006] by server-13.bemta-3.messagelabs.com id 60/29-18692-E7388935; Wed, 11 Jun 2014 16:27:42 +0000 X-Env-Sender: Stefano.Stabellini@citrix.com X-Msg-Ref: server-2.tower-31.messagelabs.com!1402504060!9482473!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5989 invoked from network); 11 Jun 2014 16:27:41 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-2.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 11 Jun 2014 16:27:41 -0000 X-IronPort-AV: E=Sophos;i="5.01,459,1400025600"; d="scan'208";a="142196537" Received: from accessns.citrite.net (HELO FTLPEX01CL02.citrite.net) ([10.9.154.239]) by FTLPIPO02.CITRIX.COM with ESMTP; 11 Jun 2014 16:27:38 +0000 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.79) with Microsoft SMTP Server id 14.3.181.6; Wed, 11 Jun 2014 12:27:37 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1WulN6-0004U7-1X; Wed, 11 Jun 2014 17:27:32 +0100 From: Stefano Stabellini To: Date: Wed, 11 Jun 2014 17:27:12 +0100 Message-ID: <1402504032-13267-6-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-DLP: MIA2 Cc: julien.grall@citrix.com, Ian.Campbell@citrix.com, JBeulich@suse.com, Stefano Stabellini Subject: [Xen-devel] [PATCH v5 6/6] xen/arm: physical irq follow virtual irq X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: stefano.stabellini@eu.citrix.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: Migrate physical irqs to the same physical cpu that is running the vcpu expected to receive the irqs. That is done when enabling irqs, when the guest writes to GICD_ITARGETSR and when Xen migrates a vcpu to a different pcpu. Introduce a new arch specific function, arch_move_irqs, that is empty on x86 and implements the vgic irq migration code on ARM. arch_move_irqs is called by evtchn_move_pirqs. Signed-off-by: Stefano Stabellini CC: JBeulich@suse.com --- Changes in v5: - prettify vgic_move_irqs; - rename vgic_move_irqs to arch_move_irqs; - introduce helper function irq_set_affinity. --- xen/arch/arm/gic.c | 18 ++++++++++++++++-- xen/arch/arm/vgic.c | 42 ++++++++++++++++++++++++++++++++++++------ xen/common/event_channel.c | 2 ++ xen/include/asm-arm/gic.h | 1 + xen/include/asm-x86/irq.h | 2 ++ 5 files changed, 57 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index 82a0be4..a4422fd 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -192,9 +192,23 @@ static void gic_guest_irq_end(struct irq_desc *desc) /* Deactivation happens in maintenance interrupt / via GICV */ } -static void gic_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask) +static void gic_irq_set_affinity(struct irq_desc *desc, const cpumask_t *cpu_mask) { - BUG(); + volatile unsigned char *bytereg; + unsigned int mask; + + if ( desc == NULL || cpumask_empty(cpu_mask) ) + return; + + spin_lock(&gic.lock); + + mask = gic_cpu_mask(cpu_mask); + + /* Set target CPU mask (RAZ/WI on uniprocessor) */ + bytereg = (unsigned char *) (GICD + GICD_ITARGETSR); + bytereg[desc->irq] = mask; + + spin_unlock(&gic.lock); } /* XXX different for level vs edge */ diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c index 2192a8c..696f9f4 100644 --- a/xen/arch/arm/vgic.c +++ b/xen/arch/arm/vgic.c @@ -395,6 +395,17 @@ static struct vcpu *_vgic_get_target_vcpu(struct vcpu *v, unsigned int irq) return v_target; } +struct vcpu *vgic_get_target_vcpu(struct vcpu *v, unsigned int irq) +{ + struct vcpu *v_target; + struct vgic_irq_rank *rank = vgic_rank_irq(v, irq); + + vgic_lock_rank(v, rank); + v_target = _vgic_get_target_vcpu(v, irq); + vgic_unlock_rank(v, rank); + return v_target; +} + static void vgic_migrate_irq(struct vcpu *old, struct vcpu *new, unsigned int irq) { unsigned long flags; @@ -414,15 +425,30 @@ static void vgic_migrate_irq(struct vcpu *old, struct vcpu *new, unsigned int ir spin_unlock_irqrestore(&old->arch.vgic.lock, flags); } -struct vcpu *vgic_get_target_vcpu(struct vcpu *v, unsigned int irq) +static inline void irq_set_affinity(struct irq_desc *desc, + const cpumask_t *cpu_mask) { + if ( desc != NULL ) + desc->handler->set_affinity(desc, cpu_mask); +} + +void arch_move_irqs(struct vcpu *v) +{ + const cpumask_t *cpu_mask = cpumask_of(v->processor); + struct domain *d = v->domain; + struct pending_irq *p; struct vcpu *v_target; - struct vgic_irq_rank *rank = vgic_rank_irq(v, irq); + int i; - vgic_lock_rank(v, rank); - v_target = _vgic_get_target_vcpu(v, irq); - vgic_unlock_rank(v, rank); - return v_target; + for ( i = 32; i < d->arch.vgic.nr_lines; i++ ) + { + v_target = _vgic_get_target_vcpu(v, i); + if ( v_target == v ) + { + p = irq_to_pending(v, i); + irq_set_affinity(p->desc, cpu_mask); + } + } } static void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n) @@ -480,6 +506,7 @@ static void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n) } if ( p->desc != NULL ) { + irq_set_affinity(p->desc, cpumask_of(v_target->processor)); spin_lock_irqsave(&p->desc->lock, flags); p->desc->handler->enable(p->desc); spin_unlock_irqrestore(&p->desc->lock, flags); @@ -667,6 +694,7 @@ static int vgic_distr_mmio_write(struct vcpu *v, mmio_info_t *info) unsigned int irq, target, old_target; unsigned long old_target_mask; struct vcpu *v_target, *v_old; + struct pending_irq *p; target = i % 8; old_target_mask = byte_read(rank->itargets[REG_RANK_INDEX(8, gicd_reg - GICD_ITARGETSR)], 0, i/8); @@ -678,6 +706,8 @@ static int vgic_distr_mmio_write(struct vcpu *v, mmio_info_t *info) v_target = v->domain->vcpu[target]; v_old = v->domain->vcpu[old_target]; vgic_migrate_irq(v_old, v_target, irq); + p = irq_to_pending(v_target, irq); + irq_set_affinity(p->desc, cpumask_of(v_target->processor)); } i += 8 - target; } diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index 6853842..383057c 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -1319,6 +1319,8 @@ void evtchn_move_pirqs(struct vcpu *v) unsigned int port; struct evtchn *chn; + arch_move_irqs(v); + spin_lock(&d->event_lock); for ( port = v->pirq_evtchn_head; port; port = chn->u.pirq.next_port ) { diff --git a/xen/include/asm-arm/gic.h b/xen/include/asm-arm/gic.h index 8f09933..ce18cfe 100644 --- a/xen/include/asm-arm/gic.h +++ b/xen/include/asm-arm/gic.h @@ -229,6 +229,7 @@ int gic_irq_xlate(const u32 *intspec, unsigned int intsize, void gic_clear_lrs(struct vcpu *v); struct vcpu *vgic_get_target_vcpu(struct vcpu *v, unsigned int irq); +void arch_move_irqs(struct vcpu *v); #endif /* __ASSEMBLY__ */ #endif diff --git a/xen/include/asm-x86/irq.h b/xen/include/asm-x86/irq.h index 9066d38..d3c55f3 100644 --- a/xen/include/asm-x86/irq.h +++ b/xen/include/asm-x86/irq.h @@ -197,4 +197,6 @@ void cleanup_domain_irq_mapping(struct domain *); bool_t cpu_has_pending_apic_eoi(void); +static inline void arch_move_irqs(struct vcpu *v) { } + #endif /* _ASM_HW_IRQ_H */