From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 590EBC63793 for ; Thu, 22 Jul 2021 15:42:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 428B061279 for ; Thu, 22 Jul 2021 15:42:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232586AbhGVPCG (ORCPT ); Thu, 22 Jul 2021 11:02:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230343AbhGVPCF (ORCPT ); Thu, 22 Jul 2021 11:02:05 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FB41C061575 for ; Thu, 22 Jul 2021 08:42:40 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id m16so9142649lfg.13 for ; Thu, 22 Jul 2021 08:42:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ANvQO69/axclvlEpOBS3JYuVDXJ+POO8G/3hSlcgFno=; b=ZCQIvI4CvSnxNpx6lz8iiRE9/A0ehdWfvnifDXdKU5GRMYs5au4LS8oXXzExqmnzdQ 0VZJJ98I26UL9irET8phzbbWjxkz/itByeXcfPUhxKCjq8BgQeTmDXpvZrGcnQyi0iLn 0m7HVs1Zn7d67nQGFkRmeMRmdwDc6/1WOf7TEJ8ruDEYQSCKBw/G/wfyoD1D8CoUnmOX VOiYiEEiNrYjmlOFG/eqPWN0sFMS0iXgSWR0nuDZCoO5e51tK5FP1Awpu/kuPcGhYrIK 5Kr/JF9Xfaq8ogw8guhDye8k/+O7l+GQUyJfHR1sSImISI0OBsmA+7I0/DTPOOrXlPgQ G6EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ANvQO69/axclvlEpOBS3JYuVDXJ+POO8G/3hSlcgFno=; b=rnspe+HuwnqzfRdljKwrlRuOqNCOgWPKYL1+JelVbvZW64wAhJDuu28IAHpStxk1rl nw6/D4KXUR6j/hbMYpNJTCV5fB1ovUI2TOdIFV+prJVgUSfKVPi52/Y0qEalGoBiUwrD oGOhTCxYdIMyuXgn5JBHE65qUclCOtZjt3OhzFD9vqPVz7grfSC/H65Q6H1tsG5UeslX adpN+JoaYYR8p39RC3r0TMMQ6oSs7oG7j30X6DEDc0JhRT+Lquz6KK56R+A3BTHeMfV9 k4x2iJ2zeYH6OvZhoSyeCAnKZ/8h4z7TByqtu59Kn+xROro8fhBLCrhth47M2sT2HV+G h/RA== X-Gm-Message-State: AOAM532wfPUQjaYmGgmbZd8friDS18B8lJAfzvpjtns1pLUIuIL/9672 1Bitr5iGnhhgemwpklylQAEuB1JGBCs4n1jQPFro9Q== X-Google-Smtp-Source: ABdhPJzic6y0tc96cyVlm1JL6/pJubrETKp8vY7wnwkX0MfRUL8ys308oj6FoydX4iDwhZmV4nZUXQ2juj4W/TRGsAY= X-Received: by 2002:ac2:555b:: with SMTP id l27mr86978lfk.57.1626968558415; Thu, 22 Jul 2021 08:42:38 -0700 (PDT) MIME-Version: 1.0 References: <20210716212629.2232756-1-oupton@google.com> <20210721152808.lsnphkl3urz6bu3v@gator> In-Reply-To: <20210721152808.lsnphkl3urz6bu3v@gator> From: Oliver Upton Date: Thu, 22 Jul 2021 08:42:27 -0700 Message-ID: Subject: Re: [PATCH v2 00/12] KVM: Add idempotent controls for migrating system counter state To: Andrew Jones Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Marc Zyngier , Raghavendra Rao Anata , Peter Shier , Sean Christopherson , David Matlack , Paolo Bonzini , linux-arm-kernel@lists.infradead.org, Jim Mattson Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Wed, Jul 21, 2021 at 8:28 AM Andrew Jones wrote: > > On Fri, Jul 16, 2021 at 09:26:17PM +0000, 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 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 2-3 add support for x86 by shoehorning the new controls into the > > pre-existing synchronization heuristics. > > > > Patches 4-5 implement a test for the new additions to > > KVM_{GET,SET}_CLOCK. > > > > Patches 6-7 implement at test for the tsc offset attribute introduced in > > patch 3. > > > > Patch 8 adds a device attribute for the arm64 virtual counter-timer > > offset. > > > > Patch 9 extends the test from patch 7 to cover the arm64 virtual > > counter-timer offset. > > > > Patch 10 adds a device attribute for the arm64 physical counter-timer > > offset. Currently, this is implemented as a synthetic register, forcing > > the guest to trap to the host and emulating the offset in the fast exit > > path. Later down the line we will have hardware with FEAT_ECV, which > > allows the hypervisor to perform physical counter-timer offsetting in > > hardware (CNTPOFF_EL2). > > > > Patch 11 extends the test from patch 7 to cover the arm64 physical > > counter-timer offset. > > > > Patch 12 introduces a benchmark to measure the overhead of emulation in > > patch 10. > > > > Physical counter benchmark > > -------------------------- > > > > The following data was collected by running 10000 iterations of the > > benchmark test from Patch 6 on an Ampere Mt. Jade reference server, A 2S > > machine with 2 80-core Ampere Altra SoCs. Measurements were collected > > for both VHE and nVHE operation using the `kvm-arm.mode=` command-line > > parameter. > > > > nVHE > > ---- > > > > +--------------------+--------+---------+ > > | Metric | Native | Trapped | > > +--------------------+--------+---------+ > > | Average | 54ns | 148ns | > > | Standard Deviation | 124ns | 122ns | > > | 95th Percentile | 258ns | 348ns | > > +--------------------+--------+---------+ > > > > VHE > > --- > > > > +--------------------+--------+---------+ > > | Metric | Native | Trapped | > > +--------------------+--------+---------+ > > | Average | 53ns | 152ns | > > | Standard Deviation | 92ns | 94ns | > > | 95th Percentile | 204ns | 307ns | > > +--------------------+--------+---------+ > > > > This series applies cleanly to the following commit: > > > > 1889228d80fe ("KVM: selftests: smm_test: Test SMM enter from L2") > > > > v1 -> v2: > > - Reimplemented as vCPU device attributes instead of a distinct ioctl. > > - Added the (realtime, host_tsc) instant support to > > KVM_{GET,SET}_CLOCK > > - Changed the arm64 implementation to broadcast counter offset values > > to all vCPUs in a guest. This upholds the architectural expectations > > of a consistent counter-timer across CPUs. > > - Fixed a bug with traps in VHE mode. We now configure traps on every > > transition into a guest to handle differing VMs (trapped, emulated). > > > > Oops, I see there's a v3 of this series. I'll switch to reviewing that. I > think my comments / r-b's apply to that version as well though. Hey Drew, Thanks for the review. I'll address your comments from both v2 and v3 in the next series. -- Thanks, Oliver From mboxrd@z Thu Jan 1 00:00:00 1970 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=-3.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 7A5AEC63797 for ; Thu, 22 Jul 2021 15:42:44 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id EEF5F6120C for ; Thu, 22 Jul 2021 15:42:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EEF5F6120C Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 7E0B24A3B4; Thu, 22 Jul 2021 11:42:43 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@google.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ans10XZVTiJD; Thu, 22 Jul 2021 11:42:42 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 50DD94081C; Thu, 22 Jul 2021 11:42:42 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id B1D1E406D3 for ; Thu, 22 Jul 2021 11:42:41 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 61hdvhU6FPug for ; Thu, 22 Jul 2021 11:42:40 -0400 (EDT) Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 4E519402DB for ; Thu, 22 Jul 2021 11:42:40 -0400 (EDT) Received: by mail-lf1-f45.google.com with SMTP id 8so9150792lfp.9 for ; Thu, 22 Jul 2021 08:42:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ANvQO69/axclvlEpOBS3JYuVDXJ+POO8G/3hSlcgFno=; b=ZCQIvI4CvSnxNpx6lz8iiRE9/A0ehdWfvnifDXdKU5GRMYs5au4LS8oXXzExqmnzdQ 0VZJJ98I26UL9irET8phzbbWjxkz/itByeXcfPUhxKCjq8BgQeTmDXpvZrGcnQyi0iLn 0m7HVs1Zn7d67nQGFkRmeMRmdwDc6/1WOf7TEJ8ruDEYQSCKBw/G/wfyoD1D8CoUnmOX VOiYiEEiNrYjmlOFG/eqPWN0sFMS0iXgSWR0nuDZCoO5e51tK5FP1Awpu/kuPcGhYrIK 5Kr/JF9Xfaq8ogw8guhDye8k/+O7l+GQUyJfHR1sSImISI0OBsmA+7I0/DTPOOrXlPgQ G6EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ANvQO69/axclvlEpOBS3JYuVDXJ+POO8G/3hSlcgFno=; b=dincwr8PnORWkUlGaELZ7AKxJZPm41H4iyK14OCquBEaveebLSVYCQY46+vq4yBrGX IpdMmEGi6LzOjTR/D7kzos72IDxCbgNSScsHq75CTixzfx/jpmwOdF25BFx/pyV4OO14 NsoSqKRh6NeKzQCvPDCTSA8nANvQY3QiM9e8gRpjipdoNej7o2YVGhc0ufhfxlsm/TP/ HwJUA7qZ52yHGM8I8+1ynnRzZCs+sfZX7jSvYCLOou0Wv+LPrM2htYdDFVmqmUVHb7Vc gR0+rysxvUnQec4P0i+xp8puVYDvo3kipfRsaHonLGvoyJGeQAiwvK3lGZF/XDropVla PQVQ== X-Gm-Message-State: AOAM5312AgNEMrwImOPmMVwqg2x20ZHI2GI8IYFfNsNmbpb10T7Sdod2 Qa2EN6LJxViRumb1dkIEjV/EBqqxU6dqEdyO31Z0qA== X-Google-Smtp-Source: ABdhPJzic6y0tc96cyVlm1JL6/pJubrETKp8vY7wnwkX0MfRUL8ys308oj6FoydX4iDwhZmV4nZUXQ2juj4W/TRGsAY= X-Received: by 2002:ac2:555b:: with SMTP id l27mr86978lfk.57.1626968558415; Thu, 22 Jul 2021 08:42:38 -0700 (PDT) MIME-Version: 1.0 References: <20210716212629.2232756-1-oupton@google.com> <20210721152808.lsnphkl3urz6bu3v@gator> In-Reply-To: <20210721152808.lsnphkl3urz6bu3v@gator> From: Oliver Upton Date: Thu, 22 Jul 2021 08:42:27 -0700 Message-ID: Subject: Re: [PATCH v2 00/12] KVM: Add idempotent controls for migrating system counter state To: Andrew Jones Cc: kvm@vger.kernel.org, Marc Zyngier , Raghavendra Rao Anata , Peter Shier , Sean Christopherson , David Matlack , Paolo Bonzini , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, Jim Mattson X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Wed, Jul 21, 2021 at 8:28 AM Andrew Jones wrote: > > On Fri, Jul 16, 2021 at 09:26:17PM +0000, 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 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 2-3 add support for x86 by shoehorning the new controls into the > > pre-existing synchronization heuristics. > > > > Patches 4-5 implement a test for the new additions to > > KVM_{GET,SET}_CLOCK. > > > > Patches 6-7 implement at test for the tsc offset attribute introduced in > > patch 3. > > > > Patch 8 adds a device attribute for the arm64 virtual counter-timer > > offset. > > > > Patch 9 extends the test from patch 7 to cover the arm64 virtual > > counter-timer offset. > > > > Patch 10 adds a device attribute for the arm64 physical counter-timer > > offset. Currently, this is implemented as a synthetic register, forcing > > the guest to trap to the host and emulating the offset in the fast exit > > path. Later down the line we will have hardware with FEAT_ECV, which > > allows the hypervisor to perform physical counter-timer offsetting in > > hardware (CNTPOFF_EL2). > > > > Patch 11 extends the test from patch 7 to cover the arm64 physical > > counter-timer offset. > > > > Patch 12 introduces a benchmark to measure the overhead of emulation in > > patch 10. > > > > Physical counter benchmark > > -------------------------- > > > > The following data was collected by running 10000 iterations of the > > benchmark test from Patch 6 on an Ampere Mt. Jade reference server, A 2S > > machine with 2 80-core Ampere Altra SoCs. Measurements were collected > > for both VHE and nVHE operation using the `kvm-arm.mode=` command-line > > parameter. > > > > nVHE > > ---- > > > > +--------------------+--------+---------+ > > | Metric | Native | Trapped | > > +--------------------+--------+---------+ > > | Average | 54ns | 148ns | > > | Standard Deviation | 124ns | 122ns | > > | 95th Percentile | 258ns | 348ns | > > +--------------------+--------+---------+ > > > > VHE > > --- > > > > +--------------------+--------+---------+ > > | Metric | Native | Trapped | > > +--------------------+--------+---------+ > > | Average | 53ns | 152ns | > > | Standard Deviation | 92ns | 94ns | > > | 95th Percentile | 204ns | 307ns | > > +--------------------+--------+---------+ > > > > This series applies cleanly to the following commit: > > > > 1889228d80fe ("KVM: selftests: smm_test: Test SMM enter from L2") > > > > v1 -> v2: > > - Reimplemented as vCPU device attributes instead of a distinct ioctl. > > - Added the (realtime, host_tsc) instant support to > > KVM_{GET,SET}_CLOCK > > - Changed the arm64 implementation to broadcast counter offset values > > to all vCPUs in a guest. This upholds the architectural expectations > > of a consistent counter-timer across CPUs. > > - Fixed a bug with traps in VHE mode. We now configure traps on every > > transition into a guest to handle differing VMs (trapped, emulated). > > > > Oops, I see there's a v3 of this series. I'll switch to reviewing that. I > think my comments / r-b's apply to that version as well though. Hey Drew, Thanks for the review. I'll address your comments from both v2 and v3 in the next series. -- Thanks, Oliver _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm From mboxrd@z Thu Jan 1 00:00:00 1970 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=-5.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 BCF46C63793 for ; Thu, 22 Jul 2021 15:44:18 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8DD19610D2 for ; Thu, 22 Jul 2021 15:44:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8DD19610D2 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=L4y7aQt3NTNQZHleGpnYoDMFfhLax8yjHX9miSyeX48=; b=Xnp4sopE/xcV+H vY/lkaEQsN92/m5d6r91NFoIaCioX3Xw4+yT5k6GGpA8Frjf8y+an4Eix2257eqyA+bQLinpa/BIY FBPqWFTA9h2Llp9pcKg7VH0AYN/b9GkydUvJNCFa7riSJCLkl4atBlWJWFfH0/uZtEPBXGV25QlCx PMGxFf7KHU8eY1aYzxLSqDff0x8YxyUzy3lDQBY60avMBYCramDekTdxDgGIwuBiMWvtTtVaNpZP7 CUBJA5MkRMBAuSpStLhD3Os3vjADunXASSnYbUcmiCFKTtDTGTyg+gYPbWya2HLhbRTi0CeSH42Q7 y7ae11daOtbPxY6WQURw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6aqV-0020pN-Nj; Thu, 22 Jul 2021 15:42:47 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6aqR-0020nH-Gj for linux-arm-kernel@lists.infradead.org; Thu, 22 Jul 2021 15:42:45 +0000 Received: by mail-lf1-x129.google.com with SMTP id b26so9206276lfo.4 for ; Thu, 22 Jul 2021 08:42:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ANvQO69/axclvlEpOBS3JYuVDXJ+POO8G/3hSlcgFno=; b=ZCQIvI4CvSnxNpx6lz8iiRE9/A0ehdWfvnifDXdKU5GRMYs5au4LS8oXXzExqmnzdQ 0VZJJ98I26UL9irET8phzbbWjxkz/itByeXcfPUhxKCjq8BgQeTmDXpvZrGcnQyi0iLn 0m7HVs1Zn7d67nQGFkRmeMRmdwDc6/1WOf7TEJ8ruDEYQSCKBw/G/wfyoD1D8CoUnmOX VOiYiEEiNrYjmlOFG/eqPWN0sFMS0iXgSWR0nuDZCoO5e51tK5FP1Awpu/kuPcGhYrIK 5Kr/JF9Xfaq8ogw8guhDye8k/+O7l+GQUyJfHR1sSImISI0OBsmA+7I0/DTPOOrXlPgQ G6EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ANvQO69/axclvlEpOBS3JYuVDXJ+POO8G/3hSlcgFno=; b=qeH31fKXFxX27R2SDF7S/k9Eaz9Dh9zASUJ1j6AqUe2zT+Z/nbUDsQMcl3AwFK8/0F msDlAWvHgZXSKDitVOIGzQwjvYCDLUwc7HFIrheKkOJnl+hGnYFcodlD0wjO++4OTmou QjM3Z3QPpS5u2RmX5skC2QVdMUk1AvFMD3IMlc3zskCwnnn3Z2BtuRE3iRKzLL1pHLft KGWC0UmO/DamBXSzttAt9mapIYwCpaLn8n/b0vwBYIiQKJ4n3sxuAOqWpJ42qFitdIYP WPqmRUnnJTvHIi3szpDCQfkc4Ef6ugnSzu4SRTkjzRd+DuGXx6fupAMmHUmH+PoZy27u a/3A== X-Gm-Message-State: AOAM5327/YijvVt6s2H7kvy1ks1EuJ5PQhjZqLdkGb0z1YzAbbum1qCF eZpBBEH08wuApEj7TYd4WF8KhcR8x82LLaBVRniJVg== X-Google-Smtp-Source: ABdhPJzic6y0tc96cyVlm1JL6/pJubrETKp8vY7wnwkX0MfRUL8ys308oj6FoydX4iDwhZmV4nZUXQ2juj4W/TRGsAY= X-Received: by 2002:ac2:555b:: with SMTP id l27mr86978lfk.57.1626968558415; Thu, 22 Jul 2021 08:42:38 -0700 (PDT) MIME-Version: 1.0 References: <20210716212629.2232756-1-oupton@google.com> <20210721152808.lsnphkl3urz6bu3v@gator> In-Reply-To: <20210721152808.lsnphkl3urz6bu3v@gator> From: Oliver Upton Date: Thu, 22 Jul 2021 08:42:27 -0700 Message-ID: Subject: Re: [PATCH v2 00/12] KVM: Add idempotent controls for migrating system counter state To: Andrew Jones Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Marc Zyngier , Raghavendra Rao Anata , Peter Shier , Sean Christopherson , David Matlack , Paolo Bonzini , linux-arm-kernel@lists.infradead.org, Jim Mattson X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210722_084243_601034_A3906AC0 X-CRM114-Status: GOOD ( 33.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Jul 21, 2021 at 8:28 AM Andrew Jones wrote: > > On Fri, Jul 16, 2021 at 09:26:17PM +0000, 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 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 2-3 add support for x86 by shoehorning the new controls into the > > pre-existing synchronization heuristics. > > > > Patches 4-5 implement a test for the new additions to > > KVM_{GET,SET}_CLOCK. > > > > Patches 6-7 implement at test for the tsc offset attribute introduced in > > patch 3. > > > > Patch 8 adds a device attribute for the arm64 virtual counter-timer > > offset. > > > > Patch 9 extends the test from patch 7 to cover the arm64 virtual > > counter-timer offset. > > > > Patch 10 adds a device attribute for the arm64 physical counter-timer > > offset. Currently, this is implemented as a synthetic register, forcing > > the guest to trap to the host and emulating the offset in the fast exit > > path. Later down the line we will have hardware with FEAT_ECV, which > > allows the hypervisor to perform physical counter-timer offsetting in > > hardware (CNTPOFF_EL2). > > > > Patch 11 extends the test from patch 7 to cover the arm64 physical > > counter-timer offset. > > > > Patch 12 introduces a benchmark to measure the overhead of emulation in > > patch 10. > > > > Physical counter benchmark > > -------------------------- > > > > The following data was collected by running 10000 iterations of the > > benchmark test from Patch 6 on an Ampere Mt. Jade reference server, A 2S > > machine with 2 80-core Ampere Altra SoCs. Measurements were collected > > for both VHE and nVHE operation using the `kvm-arm.mode=` command-line > > parameter. > > > > nVHE > > ---- > > > > +--------------------+--------+---------+ > > | Metric | Native | Trapped | > > +--------------------+--------+---------+ > > | Average | 54ns | 148ns | > > | Standard Deviation | 124ns | 122ns | > > | 95th Percentile | 258ns | 348ns | > > +--------------------+--------+---------+ > > > > VHE > > --- > > > > +--------------------+--------+---------+ > > | Metric | Native | Trapped | > > +--------------------+--------+---------+ > > | Average | 53ns | 152ns | > > | Standard Deviation | 92ns | 94ns | > > | 95th Percentile | 204ns | 307ns | > > +--------------------+--------+---------+ > > > > This series applies cleanly to the following commit: > > > > 1889228d80fe ("KVM: selftests: smm_test: Test SMM enter from L2") > > > > v1 -> v2: > > - Reimplemented as vCPU device attributes instead of a distinct ioctl. > > - Added the (realtime, host_tsc) instant support to > > KVM_{GET,SET}_CLOCK > > - Changed the arm64 implementation to broadcast counter offset values > > to all vCPUs in a guest. This upholds the architectural expectations > > of a consistent counter-timer across CPUs. > > - Fixed a bug with traps in VHE mode. We now configure traps on every > > transition into a guest to handle differing VMs (trapped, emulated). > > > > Oops, I see there's a v3 of this series. I'll switch to reviewing that. I > think my comments / r-b's apply to that version as well though. Hey Drew, Thanks for the review. I'll address your comments from both v2 and v3 in the next series. -- Thanks, Oliver _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel