From patchwork Thu Dec 14 15:45:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10112591 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3811160352 for ; Thu, 14 Dec 2017 15:51:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1852929EBE for ; Thu, 14 Dec 2017 15:51:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 154F429EC8; Thu, 14 Dec 2017 15:51:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2F39729D16 for ; Thu, 14 Dec 2017 15:50:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Vgjem+WECJqVkYVNkdoDk7i/2iXuB7SMZkcXz3exS2c=; b=iCKSzPD1GMtzvr 74GMm/OmyqLzoyuWt5Wpd75zzgCiFfAu8BPUavjQT8VE01WDSUilv5+wBPwMH75mie2S6gNVfVQtg bS8807d/3CMuct2fS+Bo+H27FKizjhH3PpOowy+BzGPkFHFw2xnibqqLdnb62Lc/eddBd8PhyqG4e EoVY45x5VHSw6ngaI4QxEL/fzFNzXO5lha9EiRynce4IOXi7/m1JsZTulfW1lUI3Ai4hFxwiitS8G d1KmwjJqaJFQ+j0WmPSxf4pGhUKW83hPh9YQpMr2XC3GBx+UP+iYR7SQELS04FMtEiUJv0z9n97Md tyDxTpGtxEeg/o45bWjA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ePVm7-0007d0-EJ; Thu, 14 Dec 2017 15:50:19 +0000 Received: from casper.infradead.org ([85.118.1.10]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ePVm5-0007LX-FO for linux-arm-kernel@bombadil.infradead.org; Thu, 14 Dec 2017 15:50:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=DJaH2smtE+EcBMK68hyK2tgsaRJNtwYTfVa0u7k8s0U=; b=VKiHeFRQ/9K3QOlqmrXW6oCGU5 4FXo04dohQOFDBFbLC1ZMs+2q+f/lB/3OuXoA++3C9xoEelvIbScw5oVkbY1v/MMoOSZxto/jya8C ZKKc9lumR2GQS8kAPF0o/ccOSxXPhWoLGhCdfMCX1ged98oi0pZwN9yv63YaJwwBrrJHcFPBBCMgF S2uitQq7cRb08IlYPXjz0tAv6JAa3OHzMUvz0mxNfcVzfaRyJNjXm5StDWffTgW414UCktpJ0cigR 7sygjvBQFL+HPW0cSlr+XZuQi3ySS6034OAHIS8ji8EyOOJTmOipabMPsEtxFepqved6CtHggx5uU KB0aJV/w==; Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ePVhi-0004C8-Gc for linux-arm-kernel@lists.infradead.org; Thu, 14 Dec 2017 15:45:48 +0000 Received: by mail-wm0-x242.google.com with SMTP id r78so12207260wme.5 for ; Thu, 14 Dec 2017 07:45:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=DJaH2smtE+EcBMK68hyK2tgsaRJNtwYTfVa0u7k8s0U=; b=ijDpS7h81+QzSMVbEu7NFwnIe1NBYIIFweSnWcYwLf0h2Q849i3uqEmwCauTnJiMSt zFucEd2vqz7KnQgJXn+3mLLu2DxoKeDGhwqcngVE2yGPxsUhxZfvBK+IRAzjYShOP54o F/sFe/sJxI2or8BWUyiXCAGH4qUY3MRi3QsWc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=DJaH2smtE+EcBMK68hyK2tgsaRJNtwYTfVa0u7k8s0U=; b=SJz15fADGyIxwRnJYdGfGVnXgqKPdeDXXdhReDqIjRs3vaONHjAVMHYMoxNzb3XPY5 ScikV/ZbrPBj4IFivOSDbhglpapn/ooZlmX4kAUrehpqTFi4iMZAPqU26iYUfQvDQlxr eK//eEpnom0k1f0L1e4k7myYB8istLVuZikvMlDI5/p98liYCy2QogDrKKnK7tJyFpkN CuHpQGp+ZICC3BVw4tlo3/nrTw5wcW7dZ4wupZXdQhmtKIzN3W4cIecCdJD7nlavzgth zgUEL/nfJAqfPL/x6o2U80i2enEgQrsCRLAry9t+Cd0RaZTpL1WPjLX4KI0CAyKVUGQ6 p+KQ== X-Gm-Message-State: AKGB3mKI59BH8r4q4ZZE97v4aEGeCiFMOCZrj373o8bIdP2n7EuiDXWD NF+DiAmsjhh68QXYxc5wO+l+/Q== X-Google-Smtp-Source: ACJfBovz5XB0Q6qr1/gdR5vofcbeKBYuV9qIYsjNScB9IZ6GbZhjV2gzKInnzDXNUDvret461g3kuA== X-Received: by 10.80.148.163 with SMTP id s32mr13009653eda.74.1513266324425; Thu, 14 Dec 2017 07:45:24 -0800 (PST) Received: from localhost (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id u21sm3431136edl.54.2017.12.14.07.45.23 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 14 Dec 2017 07:45:23 -0800 (PST) Date: Thu, 14 Dec 2017 16:45:18 +0100 From: Christoffer Dall To: Jia He Subject: Re: [PATCH] KVM: arm/arm64: don't set vtimer->cnt_ctl in kvm_arch_timer_handler Message-ID: <20171214154518.GX910@cbox> References: <1513148407-2611-1-git-send-email-hejianet@gmail.com> <20171213091803.GQ910@cbox> <20171214130954.GV910@cbox> <5615f3e1-756e-0537-f0b6-20ae8626ac87@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5615f3e1-756e-0537-f0b6-20ae8626ac87@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171214_154546_581616_F6F254AD X-CRM114-Status: GOOD ( 36.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier , Jia He , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Dec 14, 2017 at 11:28:04PM +0800, Jia He wrote: > > On 12/14/2017 9:09 PM, Christoffer Dall Wrote: > >On Thu, Dec 14, 2017 at 12:57:54PM +0800, Jia He wrote: > >Hi Jia, > > > >>I have tried your newer level-mapped-v7 branch, but bug is still there. > >> > >>There is no special load in both host and guest. The guest (kernel > >>4.14) is often hanging when booting > >> > >>the guest kernel log > >> > >>[ OK ] Reached target Remote File Systems. > >>Starting File System Check on /dev/mapper/fedora-root... > >>[ OK ] Started File System Check on /dev/mapper/fedora-root. > >>Mounting /sysroot... > >>[ 2.670764] SGI XFS with ACLs, security attributes, no debug enabled > >>[ 2.678180] XFS (dm-0): Mounting V5 Filesystem > >>[ 2.740364] XFS (dm-0): Ending clean mount > >>[ OK ] Mounted /sysroot. > >>[ OK ] Reached target Initrd Root File System. > >>Starting Reload Configuration from the Real Root... > >>[ 61.288215] INFO: rcu_sched detected stalls on CPUs/tasks: > >>[ 61.290791] 1-...!: (0 ticks this GP) idle=574/0/0 softirq=5/5 fqs=1 > >>[ 61.293664] (detected by 0, t=6002 jiffies, g=-263, c=-264, q=39760) > >>[ 61.296480] Task dump for CPU 1: > >>[ 61.297938] swapper/1 R running task 0 0 1 0x00000020 > >>[ 61.300643] Call trace: > >>[ 61.301260] __switch_to+0x6c/0x78 > >>[ 61.302095] cpu_number+0x0/0x8 > >>[ 61.302867] rcu_sched kthread starved for 6000 jiffies! > >>g18446744073709551353 c18446744073709551352 f0x0 RCU_GP_WAIT_FQS(3) > >>->state=0x402 ->cpu=1 > >>[ 61.305941] rcu_sched I 0 8 2 0x00000020 > >>[ 61.307250] Call trace: > >>[ 61.307854] __switch_to+0x6c/0x78 > >>[ 61.308693] __schedule+0x268/0x8f0 > >>[ 61.309545] schedule+0x2c/0x88 > >>[ 61.310325] schedule_timeout+0x84/0x3b8 > >>[ 61.311278] rcu_gp_kthread+0x4d4/0x7d8 > >>[ 61.312213] kthread+0x134/0x138 > >>[ 61.313001] ret_from_fork+0x10/0x1c > >> > >>Maybe my previous patch is not perfect enough, thanks for your comments. > >> > >>I digged it futher more, do you think below code logic is possibly > >>problematic? > >> > >> > >>vtimer_save_state           (vtimer->loaded = false, cntv_ctl is 0) > >> > >>kvm_arch_timer_handler        (read cntv_ctl and set vtimer->cnt_ctl = 0) > >> > >>vtimer_restore_state            (write vtimer->cnt_ctl to cntv_ctl, > >>then cntv_ctl will > >> > >>                        be 0 forever) > >> > >> > >>If above analysis is reasonable > >Yes, I think there's something there if the hardware doesn't retire the > >signal fast enough... > > > >>how about below patch? already > >>tested in my arm64 server. > >> > >>diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c > >>index f9555b1..ee6dd3f 100644 > >>--- a/virt/kvm/arm/arch_timer.c > >>+++ b/virt/kvm/arm/arch_timer.c > >>@@ -99,7 +99,7 @@ static irqreturn_t kvm_arch_timer_handler(int irq, > >>void *dev_id) > >>         } > >>         vtimer = vcpu_vtimer(vcpu); > >> > >>-       if (!vtimer->irq.level) { > >>+       if (vtimer->loaded && !vtimer->irq.level) { > >>                 vtimer->cnt_ctl = read_sysreg_el0(cntv_ctl); > >>                 if (kvm_timer_irq_can_fire(vtimer)) > >>                         kvm_timer_update_irq(vcpu, true, vtimer); > >> > >There's nothing really wrong with that patch, I just didn't think it > >would be necessary, as we really shouldn't see interrupts if the timer > >is not loaded. Can you confirm that a WARN_ON(!vtimer->loaded) in > >kvm_arch_timer_handler() gives you a splat? > Please see the WARN_ON result (without my patch) > [   72.171706] WARNING: CPU: 24 PID: 1768 at > arch/arm64/kvm/../../../virt/kvm/arm/arch_timer.c:101 > kvm_arch_timer_handler+0xc0/0xc8 > > >Also, could you give the following a try (without your patch): > > > >diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c > >index 73d262c4712b..4751255345d1 100644 > >--- a/virt/kvm/arm/arch_timer.c > >+++ b/virt/kvm/arm/arch_timer.c > >@@ -367,6 +367,7 @@ static void vtimer_save_state(struct kvm_vcpu *vcpu) > > /* Disable the virtual timer */ > > write_sysreg_el0(0, cntv_ctl); > >+ isb(); > No luck, the bug is still there > ok, so this is a slightly different approach to what you were trying to do. Can you please give this a try and let me know how it goes? Thanks, -Christoffer diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index 73d262c4712b..544ed15fbbb3 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -46,7 +46,7 @@ static const struct kvm_irq_level default_vtimer_irq = { .level = 1, }; -static bool kvm_timer_irq_can_fire(struct arch_timer_context *timer_ctx); +static bool kvm_timer_irq_can_fire(u32 cnt_ctl); static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level, struct arch_timer_context *timer_ctx); static bool kvm_timer_should_fire(struct arch_timer_context *timer_ctx); @@ -94,6 +94,7 @@ static irqreturn_t kvm_arch_timer_handler(int irq, void *dev_id) { struct kvm_vcpu *vcpu = *(struct kvm_vcpu **)dev_id; struct arch_timer_context *vtimer; + u32 cnt_ctl; if (!vcpu) { pr_warn_once("Spurious arch timer IRQ on non-VCPU thread\n"); @@ -101,8 +102,8 @@ static irqreturn_t kvm_arch_timer_handler(int irq, void *dev_id) } vtimer = vcpu_vtimer(vcpu); - vtimer->cnt_ctl = read_sysreg_el0(cntv_ctl); - if (kvm_timer_irq_can_fire(vtimer)) + cnt_ctl = read_sysreg_el0(cntv_ctl); + if (kvm_timer_irq_can_fire(cnt_ctl)) kvm_timer_update_irq(vcpu, true, vtimer); if (unlikely(!irqchip_in_kernel(vcpu->kvm))) @@ -148,10 +149,10 @@ static u64 kvm_timer_compute_delta(struct arch_timer_context *timer_ctx) return 0; } -static bool kvm_timer_irq_can_fire(struct arch_timer_context *timer_ctx) +static bool kvm_timer_irq_can_fire(u32 cnt_ctl) { - return !(timer_ctx->cnt_ctl & ARCH_TIMER_CTRL_IT_MASK) && - (timer_ctx->cnt_ctl & ARCH_TIMER_CTRL_ENABLE); + return !(cnt_ctl & ARCH_TIMER_CTRL_IT_MASK) && + (cnt_ctl & ARCH_TIMER_CTRL_ENABLE); } /* @@ -164,10 +165,10 @@ static u64 kvm_timer_earliest_exp(struct kvm_vcpu *vcpu) struct arch_timer_context *vtimer = vcpu_vtimer(vcpu); struct arch_timer_context *ptimer = vcpu_ptimer(vcpu); - if (kvm_timer_irq_can_fire(vtimer)) + if (kvm_timer_irq_can_fire(vtimer->cnt_ctl)) min_virt = kvm_timer_compute_delta(vtimer); - if (kvm_timer_irq_can_fire(ptimer)) + if (kvm_timer_irq_can_fire(ptimer->cnt_ctl)) min_phys = kvm_timer_compute_delta(ptimer); /* If none of timers can fire, then return 0 */ @@ -231,7 +232,7 @@ static bool kvm_timer_should_fire(struct arch_timer_context *timer_ctx) { u64 cval, now; - if (!kvm_timer_irq_can_fire(timer_ctx)) + if (!kvm_timer_irq_can_fire(timer_ctx->cnt_ctl)) return false; cval = timer_ctx->cnt_cval; @@ -306,7 +307,7 @@ static void phys_timer_emulate(struct kvm_vcpu *vcpu) * don't need to have a soft timer scheduled for the future. If the * timer cannot fire at all, then we also don't need a soft timer. */ - if (kvm_timer_should_fire(ptimer) || !kvm_timer_irq_can_fire(ptimer)) { + if (kvm_timer_should_fire(ptimer) || !kvm_timer_irq_can_fire(ptimer->cnt_ctl)) { soft_timer_cancel(&timer->phys_timer, NULL); return; } @@ -367,6 +368,7 @@ static void vtimer_save_state(struct kvm_vcpu *vcpu) /* Disable the virtual timer */ write_sysreg_el0(0, cntv_ctl); + isb(); vtimer->loaded = false; out: @@ -398,7 +400,8 @@ void kvm_timer_schedule(struct kvm_vcpu *vcpu) * If both timers are not capable of raising interrupts (disabled or * masked), then there's no more work for us to do. */ - if (!kvm_timer_irq_can_fire(vtimer) && !kvm_timer_irq_can_fire(ptimer)) + if (!kvm_timer_irq_can_fire(vtimer->cnt_ctl) && + !kvm_timer_irq_can_fire(ptimer->cnt_ctl)) return; /*