From patchwork Thu Mar 15 20:30:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 131871 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp1579632ljb; Thu, 15 Mar 2018 13:33:43 -0700 (PDT) X-Google-Smtp-Source: AG47ELsMOzvAlgPez/zCEH1kBMDbqKVI14b2P1vXwrqmnYAJPKCVcGLrF23b0YC43m2mrbLlZMOA X-Received: by 10.107.23.131 with SMTP id 125mr10230453iox.130.1521146023676; Thu, 15 Mar 2018 13:33:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521146023; cv=none; d=google.com; s=arc-20160816; b=GXRkTkEz8OhsJce2cbcr2nk01xzgyqcAXh4lXFO0/gCHUTxH5DwlP7ixKovxoH8hib ga9z+gIQzHjYrjPgcmKdPQkjPX+8iGg/WxKb5T7Yy4fxxNYK0P2vV/Np/h8Mn5GJLbBg TkgDEJqCXuD7cjuOTaRkdtSUgwYjc6PGm9uiILSBBF3tr8E50Ru6grENW99DL6D9y0Tt +CFuvx7suofGcDgBRYhY8ad9raWyBX8v4GgQwuiGTdris9kF0qHP5DMpozrVtLBt8J6t qNYmTXPdEMx2xKbJ1q7Oz/NnTGBvBoPS+kCwrNcl4wpDfRy8dcNCuTyTaW/8oQ27jyxb 3vWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=u1xjyGI/n1hqSnBoVCIBPPwfx4gOR/JCl/xY0CbXFXs=; b=Ta7y8wEgpwmP+YwBVzbnp3H6RtdyThVx1qoUWWiSsigWzHxbnmtKlGPimenbZHWJ2D v2dnfF+5dyYeIlBoZOaZva8iYDhF0MB5fVpzFaKmpq3rXJxMCISaJkdFDdeRaZsmDxpm 0Q/3//T/54lr4GfvfKT2zTt1l2lYv5zt5B8TZF7XSjZKxkm5ldYwTpWWzRFA4euyO+L7 6dWuNxyRd+e3wWDvSHSNJcd/Dq2a6oLcfujwcNNx6Qlo1IPpszT6n8Oc+fiMMd4NG8l3 248I/18HfWFqNDEjBYMQJ3HvTyFViAA24SN5xMaKr9Af2In9gAYiAw1eXC5eIg3Nr4LB SYPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=hvnUdvcy; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id t23si2876486ite.171.2018.03.15.13.33.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Mar 2018 13:33:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=hvnUdvcy; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ewZX0-0003Eq-2U; Thu, 15 Mar 2018 20:31:22 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ewZWy-0003CO-C8 for xen-devel@lists.xenproject.org; Thu, 15 Mar 2018 20:31:20 +0000 X-Inumbo-ID: cd1efcee-288f-11e8-9728-bc764e045a96 Received: from mail-wm0-x229.google.com (unknown [2a00:1450:400c:c09::229]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id cd1efcee-288f-11e8-9728-bc764e045a96; Thu, 15 Mar 2018 21:31:13 +0100 (CET) Received: by mail-wm0-x229.google.com with SMTP id h21so12792476wmd.1 for ; Thu, 15 Mar 2018 13:31:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=y1FNti5TGshWEY2xim0iYqRUcBfbshFTFC06RrB0aLA=; b=hvnUdvcyK3MOp3HfRn8EFQeee+P5YVPtOxMzCRZ9vBKjX1F+imTqEgZIcHknSIlhDW 16yvYR7VyzVnxfwHgAS5eeJzgP873WnU1R3EsVfROdinILXwmZLIo79EtjkNPLaK5ZQs JqnTDSXBtwy735u1R4Sbbx4c4p2cTq1JNfl+M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=y1FNti5TGshWEY2xim0iYqRUcBfbshFTFC06RrB0aLA=; b=p/fYDThw0j64YTsePwJCQ6SL+PAkTe4sQw9MWBdee8IybRrzwfrqZXEM/vQ85Hq4o+ vckLUJ9BM87nEModr+jU7wRkEYAaej3sCN9bkb/TreGGaraq1IPWY05FKhuUhRnUPNsl HRqbiLLoqV/ZyPpZ1gRegQRtR0uQBgCjPMxnrJ3ayNlaT1YsKSDiwdvrBXJAFN0mclU7 HwbB+8C5ThIq44xGwTI73+FFKJqXMmSi0+TEf8r/RbCizrDpF6J6UwFIKMKhS48Fvn/c cz/WZcLXRw4lNSQy9jWJrZ1R+eoNFzx7Xkt5StCk/nKmA8pQBHbm/i1gH8nn+1dGESJ1 R1bw== X-Gm-Message-State: AElRT7EJr9bUVexvxmCJ3D3M9fL9ZSDf4Hu1j23hnshRC86OxTvZSV1K SBBKAlUIGRjpzKrUoNQzDXLXjQ== X-Received: by 10.28.207.201 with SMTP id f192mr5647112wmg.81.1521145877136; Thu, 15 Mar 2018 13:31:17 -0700 (PDT) Received: from e104803-lin.lan (mail.andrep.de. [217.160.17.100]) by smtp.gmail.com with ESMTPSA id w125sm3217102wmw.20.2018.03.15.13.31.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Mar 2018 13:31:16 -0700 (PDT) From: Andre Przywara To: Stefano Stabellini , Julien Grall Date: Thu, 15 Mar 2018 20:30:16 +0000 Message-Id: <20180315203050.19791-12-andre.przywara@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180315203050.19791-1-andre.przywara@linaro.org> References: <20180315203050.19791-1-andre.przywara@linaro.org> Cc: xen-devel@lists.xenproject.org Subject: [Xen-devel] [PATCH v2 11/45] ARM: timer: Handle level triggered IRQs correctly X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The ARM Generic Timer uses a level-sensitive interrupt semantic. We easily catch when the line goes high, as this triggers the hardware IRQ. However we have to sync the state of the interrupt condition at certain points to catch when the line goes low and we can remove the vtimer vIRQ from the vGIC (and the LR). The VGIC in Xen so far only implemented edge triggered vIRQs, really, so we need to add new functionality to re-sample the interrupt state. Do this only when the new VGIC is in use. Signed-off-by: Andre Przywara --- Changelog v1 ... v2: - restrict to new VGIC - add TODO: comment xen/arch/arm/time.c | 36 ++++++++++++++++++++++++++++++++++++ xen/arch/arm/traps.c | 11 +++++++++++ xen/include/xen/timer.h | 2 ++ 3 files changed, 49 insertions(+) diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c index c11fcfeadd..c0ae781ecd 100644 --- a/xen/arch/arm/time.c +++ b/xen/arch/arm/time.c @@ -263,6 +263,42 @@ static void vtimer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs) vgic_inject_irq(current->domain, current, current->arch.virt_timer.irq, true); } +/** + * vtimer_sync() - update the state of the virtual timer after a guest run + * @vcpu: The VCPU to sync the arch timer state + * + * After returning from a guest, update the state of the virtual interrupt + * line, to model the level triggered interrupt correctly. + * If the guest has handled a timer interrupt, the virtual interrupt line + * needs to be lowered explicitly. vgic_inject_irq() takes care of that. + */ +void vtimer_sync(struct vcpu *vcpu) +{ + struct vtimer *vtimer = &vcpu->arch.virt_timer; + uint32_t vtimer_ctl = READ_SYSREG32(CNTV_CTL_EL0); + bool level; + + /* + * Technically the mask should include the CNTx_CTL_MASK bit here, + * to catch if the timer interrupt is masked. However Xen always masks + * the timer upon entering the hypervisor, leaving it up to the guest + * to un-mask it. So we would always read a "low" level, despite the + * condition being actually "high". + * Ignoring the mask bit solves this (for now). + * Another possible check would be to compare the value of CNTVCT_EL0 + * against vtimer->cval and derive the interrupt state from that. + */ + vtimer_ctl &= (CNTx_CTL_ENABLE | CNTx_CTL_PENDING); + level = (vtimer_ctl == (CNTx_CTL_ENABLE | CNTx_CTL_PENDING)); + + /* + * TODO: The proper fix for this is to make vtimer vIRQ hardware mapped, + * but this requires reworking the arch timer to implement this. + */ + + vgic_inject_irq(vcpu->domain, vcpu, vtimer->irq, level); +} + /* * Arch timer interrupt really ought to be level triggered, since the * design of the timer/comparator mechanism is based around that diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 7411bff7a7..46464d7bb9 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -2024,6 +2024,17 @@ static void enter_hypervisor_head(struct cpu_user_regs *regs) if ( current->arch.hcr_el2 & HCR_VA ) current->arch.hcr_el2 = READ_SYSREG(HCR_EL2); +#ifdef CONFIG_NEW_VGIC + /* + * We need to update the state of our emulated devices using level + * triggered interrupts before syncing back the VGIC state. + * + * TODO: Investigate whether this is necessary to do on every + * trap and how it can be optimised. + */ + vtimer_sync(current); +#endif + vgic_sync_from_lrs(current); } } diff --git a/xen/include/xen/timer.h b/xen/include/xen/timer.h index 4513260b0d..eddbbf3903 100644 --- a/xen/include/xen/timer.h +++ b/xen/include/xen/timer.h @@ -94,6 +94,8 @@ DECLARE_PER_CPU(s_time_t, timer_deadline); /* Arch-defined function to reprogram timer hardware for new deadline. */ int reprogram_timer(s_time_t timeout); +void vtimer_sync(struct vcpu *vcpu); + /* Calculate the aligned first tick time for a given periodic timer. */ s_time_t align_timer(s_time_t firsttick, uint64_t period);