From patchwork Fri Feb 9 14:39:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 127815 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp679472ljc; Fri, 9 Feb 2018 06:41:51 -0800 (PST) X-Google-Smtp-Source: AH8x227EJlPOc1wJDXhxy0OTG8t6EeB2J/9yGVYA5Pk+4SxUb8BCRKWnXGzsYRJD0XA96TDNkJsf X-Received: by 10.36.44.9 with SMTP id i9mr3781047iti.153.1518187311042; Fri, 09 Feb 2018 06:41:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518187311; cv=none; d=google.com; s=arc-20160816; b=YzJDzH6kn+vBf2lRTGJ6gAfeJP2SS0kL1Niph8F05xrfL6BhTfHyaJbklPl3qxSO12 1aB5XMCAxSFQ7F6rhVodV06f/1kgZf6h88J/d06BlYNLlHX6R7ULAv8T+qK9YHG+Bqqo LIrEo0gQoOtxABoVGW0JO184O9wYFdviiZMAOiHaK+77Kyjp6EopuUmf4DmuVtOmJXS7 yZua6xz6tQCgbLXBS7T9eOdsTOE1XiDL2JeyR/CD7BdPYo56asAslWgfeCMp8Z3+Z2ac VI7qJQDnUodvYQ9DKT5NzQuXYOZIN/O3w8Xo87LwJ+2N1KYqE9lbDkl4bcZkqqXmhZjj AuGQ== 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:references:in-reply-to:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=xbLjyoGXLABeSkfIbRwB47LnYKBY1xU1TZ0+vZwclSQ=; b=T5LNELasSbFBnf+62VCpQF3BZ2fSXuMrKkh5sdU5xGiI4iJI/v+DtJrOZWIU80oo3C 5K0F9mJM/jzKq0qIWNA1dqBg+B0kuBqY9FBKjEm1FFu54mD7s9LSyQox8YqquC5eILp1 ZHbGx7V1UHRvYtyvR4rRHwF4Z8evNueqjZtWXp64tZYXvx5kSHa27ncQSS3vCUFT9esP pN5QQhITjUAtv3pMiTvT8ia1tnKVzNasS98/jZBE0KCYAGMxmCyVFsU2MNMo12ea2BsU wFZuV8dL8bWI4awkijunOgSMvrRC7jdDf7q8pJzbLMjsf8wJzHbiA+KK+yON8nao7w1h YfcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=L6SVT3Zx; 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 u2si1741686ith.12.2018.02.09.06.41.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Feb 2018 06:41:51 -0800 (PST) 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=L6SVT3Zx; 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 1ek9qR-0000UO-8N; Fri, 09 Feb 2018 14:40:07 +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 1ek9qP-0000Ne-R4 for xen-devel@lists.xenproject.org; Fri, 09 Feb 2018 14:40:05 +0000 X-Inumbo-ID: 0c631725-0da7-11e8-ba59-bc764e045a96 Received: from mail-wr0-x234.google.com (unknown [2a00:1450:400c:c0c::234]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 0c631725-0da7-11e8-ba59-bc764e045a96; Fri, 09 Feb 2018 15:39:36 +0100 (CET) Received: by mail-wr0-x234.google.com with SMTP id t94so8459960wrc.5 for ; Fri, 09 Feb 2018 06:40:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=uZBXrt72VQo2DzAzCJ2M5Scv5oiHNsZRgu2JeoTWvfw=; b=L6SVT3ZxqCtdb1IrFdKPATJ40o9kUFYAxq9/FRkIlpKOHFM+jXb0YWCWwHhEGye3Ap 0ogM7h1QIluMUgZPc/vBqaTyB4oDgqnd4eqfoIcXu4wjF/yDx4zRtSopj7woSsEcHjg+ aAh4ku9S+4bH9BXcr0c9JTIwI9NVfiDKpycYY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=uZBXrt72VQo2DzAzCJ2M5Scv5oiHNsZRgu2JeoTWvfw=; b=j8cvRvHSBQPp7JrFdo33wotzB9Hp1lXRa51StC5pmlLGjoDNnSZFKi/MhLd1VpIpxa vOiJBUAwpi5YvQ7qVbtNsa3of1lvsVpFlx7Zc5R89ZLhh/ZVGVOrMontZNiBTljwFcLa Xjfw9EFg7/0xecxx9wzAC+HN2Iwrq6oGRu8MY+5SdI239dNIZae8pDIQkZmFAMg0tH/b iA7DMpCJcC1xfNKF1DzouyWgVoyTr1QU2WbKLLXkCksn2io4xZaIqYFAWc6lGT2Blq4t LHoVm5gyioxQN7tTxFfhp1pG6vWnTtw/ta5AoJMv/kTnT8J7Fv4GIdzVb2vVN7l6n2hy DNCw== X-Gm-Message-State: APf1xPAFghpBIqE/sn9EFGQqH+DC44I3Tsm7sLg5lWCYeV22aWxKZChk 5iGdantyY4bpnHt5kCOcZBjWgQ== X-Received: by 10.223.197.13 with SMTP id q13mr2500401wrf.235.1518187203066; Fri, 09 Feb 2018 06:40:03 -0800 (PST) Received: from e104803-lin.lan (mail.andrep.de. [217.160.17.100]) by smtp.gmail.com with ESMTPSA id b35sm2552229wra.13.2018.02.09.06.40.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Feb 2018 06:40:02 -0800 (PST) From: Andre Przywara To: Stefano Stabellini , Julien Grall , xen-devel@lists.xenproject.org Date: Fri, 9 Feb 2018 14:39:05 +0000 Message-Id: <20180209143937.28866-18-andre.przywara@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180209143937.28866-1-andre.przywara@linaro.org> References: <20180209143937.28866-1-andre.przywara@linaro.org> Subject: [Xen-devel] [RFC PATCH 17/49] 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. Signed-off-by: Andre Przywara --- xen/arch/arm/time.c | 34 ++++++++++++++++++++++++++++++++++ xen/arch/arm/traps.c | 1 + xen/include/xen/timer.h | 2 ++ 3 files changed, 37 insertions(+) diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c index c11fcfeadd..98ebb4305d 100644 --- a/xen/arch/arm/time.c +++ b/xen/arch/arm/time.c @@ -263,6 +263,40 @@ 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; + bool level; + + vtimer->ctl = READ_SYSREG32(CNTV_CTL_EL0); + vtimer->cval = READ_SYSREG64(CNTV_CVAL_EL0); + + /* + * Technically we should mask with 0x7 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". Igoring 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. + * + * TODO: The proper fix for this is to make vtimer vIRQ hardware mapped, + * but this requires reworking the arch timer to implement this. + */ + level = (vtimer->ctl & 0x5) == (CNTx_CTL_ENABLE | CNTx_CTL_PENDING); + + 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 1cba7e584d..2d770a14a5 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -2024,6 +2024,7 @@ 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); + vtimer_sync(current); gic_clear_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);