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=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 769F0C4338F for ; Tue, 10 Aug 2021 12:30:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5109960462 for ; Tue, 10 Aug 2021 12:30:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240271AbhHJMbQ (ORCPT ); Tue, 10 Aug 2021 08:31:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:39064 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238518AbhHJMbP (ORCPT ); Tue, 10 Aug 2021 08:31:15 -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 05FEA60F56; Tue, 10 Aug 2021 12:30:54 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mDQuC-0043Ku-4Q; Tue, 10 Aug 2021 13:30:52 +0100 Date: Tue, 10 Aug 2021 13:30:51 +0100 Message-ID: <877dgtbhxg.wl-maz@kernel.org> From: Marc Zyngier To: Oliver Upton Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Paolo Bonzini , Sean Christopherson , Peter Shier , Jim Mattson , David Matlack , Ricardo Koller , Jing Zhang , Raghavendra Rao Anata , James Morse , Alexandru Elisei , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Andrew Jones , Will Deacon , Catalin Marinas Subject: Re: [PATCH v6 00/21] KVM: Add idempotent controls for migrating system counter state In-Reply-To: References: <20210804085819.846610-1-oupton@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: oupton@google.com, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, pbonzini@redhat.com, seanjc@google.com, pshier@google.com, jmattson@google.com, dmatlack@google.com, ricarkol@google.com, jingzhangos@google.com, rananta@google.com, james.morse@arm.com, Alexandru.Elisei@arm.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, drjones@redhat.com, will@kernel.org, catalin.marinas@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Tue, 10 Aug 2021 01:04:38 +0100, Oliver Upton wrote: > > On Wed, Aug 4, 2021 at 3:03 PM Oliver Upton wrote: > > > > On Wed, Aug 4, 2021 at 4:05 AM Oliver Upton wrote: > > > > > > On Wed, Aug 4, 2021 at 1:58 AM Oliver Upton wrote: > > > > > > > > KVM's current means of saving/restoring system counters is plagued with > > > > temporal issues. At least on ARM64 and x86, we migrate the guest's > > > > system counter by-value through the respective guest system register > > > > values (cntvct_el0, ia32_tsc). Restoring system counters by-value is > > > > brittle as the state is not idempotent: the host system counter is still > > > > oscillating between the attempted save and restore. Furthermore, VMMs > > > > may wish to transparently live migrate guest VMs, meaning that they > > > > include the elapsed time due to live migration blackout in the guest > > > > system counter view. The VMM thread could be preempted for any number of > > > > reasons (scheduler, L0 hypervisor under nested) between the time that > > > > it calculates the desired guest counter value and when KVM actually sets > > > > this counter state. > > > > > > > > Despite the value-based interface that we present to userspace, KVM > > > > actually has idempotent guest controls by way of system counter offsets. > > > > We can avoid all of the issues associated with a value-based interface > > > > by abstracting these offset controls in new ioctls. This series > > > > introduces new vCPU device attributes to provide userspace access to the > > > > vCPU's system counter offset. > > > > > > > > Patch 1 addresses a possible race in KVM_GET_CLOCK where > > > > use_master_clock is read outside of the pvclock_gtod_sync_lock. > > > > > > > > Patch 2 adopts Paolo's suggestion, augmenting the KVM_{GET,SET}_CLOCK > > > > ioctls to provide userspace with a (host_tsc, realtime) instant. This is > > > > essential for a VMM to perform precise migration of the guest's system > > > > counters. > > > > > > > > Patches 3-4 are some preparatory changes for exposing the TSC offset to > > > > userspace. Patch 5 provides a vCPU attribute to provide userspace access > > > > to the TSC offset. > > > > > > > > Patches 6-7 implement a test for the new additions to > > > > KVM_{GET,SET}_CLOCK. > > > > > > > > Patch 8 fixes some assertions in the kvm device attribute helpers. > > > > > > > > Patches 9-10 implement at test for the tsc offset attribute introduced in > > > > patch 5. > > Paolo, > > Is there anything else you're waiting to see for the x86 portion of > this series after addressing Sean's comments? There's some work > remaining on the arm64 side, though I believe the two architectures > are now disjoint for this series. I think at this stage it would make sense to split the series in two and drive them independently. Thanks, M. -- Without deviation from the norm, progress is not possible.