Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C878C282E1 for ; Thu, 25 Apr 2019 13:15:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CCF2C20679 for ; Thu, 25 Apr 2019 13:15:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727061AbfDYNPv (ORCPT ); Thu, 25 Apr 2019 09:15:51 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:43750 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726845AbfDYNPv (ORCPT ); Thu, 25 Apr 2019 09:15:51 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2412415A2; Thu, 25 Apr 2019 06:15:51 -0700 (PDT) Received: from big-swifty.misterjones.org (c02v53d0hv2r.cambridge.arm.com [10.1.37.80]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 70C5E3F5C1; Thu, 25 Apr 2019 06:15:49 -0700 (PDT) Date: Thu, 25 Apr 2019 14:15:53 +0100 Message-ID: <86tvem9qeu.wl-marc.zyngier@arm.com> From: Marc Zyngier To: Andre Przywara Cc: Christoffer Dall , , , Subject: Re: [PATCH] KVM: arm/arm64: Don't emulate virtual timers on userspace ioctls In-Reply-To: <20190425125740.238036-1-andre.przywara@arm.com> References: <20190425125740.238036-1-andre.przywara@arm.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 EasyPG/1.0.0 Emacs/26 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Organization: ARM Ltd MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Thu, 25 Apr 2019 13:57:40 +0100, Andre Przywara wrote: > > From: Christoffer Dall > > When a VCPU never runs before a guest exists, but we set timer registers > up via ioctls, the associated hrtimer might never get cancelled. > > Since we moved vcpu_load/put into the arch-specific implementations and > only have load/put for KVM_RUN, we won't ever have a scheduled hrtimer > for emulating a timer when modifying the timer state via an ioctl from > user space. All we need to do is make sure that we pick up the right > state when we load the timer state next time userspace calls KVM_RUN > again. > > We also do not need to worry about this interacting with the bg_timer, > because if we were in WFI from the guest, and somehow ended up in a > kvm_arm_timer_set_reg, it means that: > > 1. the VCPU thread has received a signal, > 2. we have called vcpu_load when being scheduled in again, > 3. we have called vcpu_put when we returned to userspace for it to issue > another ioctl > > And therefore will not have a bg_timer programmed and the event is > treated as a spurious wakeup from WFI if userspace decides to run the > vcpu again even if there are not virtual interrupts. > > This fixes stray virtual timer interrupts triggered by an expiring > hrtimer, which happens after a failed live migration, for instance. > > Signed-off-by: Christoffer Dall > Reported-by: Andre Przywara > Tested-by: Andre Przywara > Signed-off-by: Andre Przywara Fixes: bee038a674875 ("KVM: arm/arm64: Rework the timer code to use a timer_map") Applied to -master. Thanks, M. -- Jazz is not dead, it just smell funny.