From patchwork Fri Sep 4 10:45:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 11756631 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5120618 for ; Fri, 4 Sep 2020 10:46:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A3DCD2087C for ; Fri, 4 Sep 2020 10:46:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599216407; bh=mIOES2oHYEYo5N/ys71QEEfVp16YdoOph7z6Wrougfk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=hBM/92+CrEyvzCfHpl2e9FUj+sEcrb8sxgwlxHTkfJdzvwu9p2xh9UMeOkPEt/eos 7FzSYgvH7aGEYzZkq8oEVWNI2lIBm1GOZ/SZLZr7T4FQZ5a7lslKUu+e9PuKmsKzq5 Lix7uVS1hSYGtr7ZNNOTGQ8ZIYtyWn++SgVnXXl8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730066AbgIDKqm (ORCPT ); Fri, 4 Sep 2020 06:46:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:58820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729582AbgIDKqD (ORCPT ); Fri, 4 Sep 2020 06:46:03 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A4D882087C; Fri, 4 Sep 2020 10:46:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599216362; bh=mIOES2oHYEYo5N/ys71QEEfVp16YdoOph7z6Wrougfk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PDUxXl55pS8P0i2mXv8eXiPFRnDlSsjvAB+5QhghbY4LOy55VUh4gNHr+qKYIqp2C ZQ0aCYrmuGeToF3qJsRxuR0V4jHl+tYvra5QyGZkSMc84716glwQPrjmrWNUEZ56ZU zccPHA1SUcz94hNN9twx6JN82PZz34Y5Twp2LR7c= Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kE9EH-0098oH-4r; Fri, 04 Sep 2020 11:46:01 +0100 From: Marc Zyngier To: Paolo Bonzini Cc: Alexandru Elisei , Andrew Jones , Eric Auger , Gavin Shan , Steven Price , kernel-team@android.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Subject: [PATCH 2/9] KVM: arm64: pvtime: Fix potential loss of stolen time Date: Fri, 4 Sep 2020 11:45:23 +0100 Message-Id: <20200904104530.1082676-3-maz@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200904104530.1082676-1-maz@kernel.org> References: <20200904104530.1082676-1-maz@kernel.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: pbonzini@redhat.com, alexandru.elisei@arm.com, drjones@redhat.com, eric.auger@redhat.com, gshan@redhat.com, steven.price@arm.com, kernel-team@android.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Andrew Jones We should only check current->sched_info.run_delay once when updating stolen time. Otherwise there's a chance there could be a change between checks that we miss (preemption disabling comes after vcpu request checks). Signed-off-by: Andrew Jones Signed-off-by: Marc Zyngier Link: https://lore.kernel.org/r/20200804170604.42662-3-drjones@redhat.com --- arch/arm64/kvm/pvtime.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/pvtime.c b/arch/arm64/kvm/pvtime.c index c3ef4ebd6846..95f9580275b1 100644 --- a/arch/arm64/kvm/pvtime.c +++ b/arch/arm64/kvm/pvtime.c @@ -13,6 +13,7 @@ void kvm_update_stolen_time(struct kvm_vcpu *vcpu) { struct kvm *kvm = vcpu->kvm; + u64 last_steal = vcpu->arch.steal.last_steal; u64 steal; __le64 steal_le; u64 offset; @@ -24,8 +25,8 @@ void kvm_update_stolen_time(struct kvm_vcpu *vcpu) /* Let's do the local bookkeeping */ steal = vcpu->arch.steal.steal; - steal += current->sched_info.run_delay - vcpu->arch.steal.last_steal; - vcpu->arch.steal.last_steal = current->sched_info.run_delay; + vcpu->arch.steal.last_steal = READ_ONCE(current->sched_info.run_delay); + steal += vcpu->arch.steal.last_steal - last_steal; vcpu->arch.steal.steal = steal; steal_le = cpu_to_le64(steal);