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=-18.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 A161DC636CB for ; Fri, 16 Jul 2021 21:29:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77F5E613EB for ; Fri, 16 Jul 2021 21:29:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236100AbhGPVcW (ORCPT ); Fri, 16 Jul 2021 17:32:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235208AbhGPVcU (ORCPT ); Fri, 16 Jul 2021 17:32:20 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC9D0C06175F for ; Fri, 16 Jul 2021 14:29:23 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id h9so15896943ljm.5 for ; Fri, 16 Jul 2021 14:29:23 -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=rG0QzRVn0xvgBNRpL2thyKE3h6hzU4e3t1z4e1/od60=; b=gGIJ35R95kAzj9vkH0r/wUr9FG5xyFairDEwjCtTS6XF7MTM+ucxhHOQhzSMKQjqYg OdINZFXiXRtuYOEroMB80J80YmqiuwOPy9/zKZIUdpr+aTqhJqzRtxjQZ7rJB2mUOf7Y grZ7SxTZ+6oRLRj+hEAvevMMNvFrSV9i1Op1YLVBoAGXYeO68HeuCg3930vm5JsiOeDi llGy+htXFEOiQHAk4LEFIrYRcQRYqV/PSobtBsWshBumu7qhauwi4kD8dUSw/NDqQe6D jTsxPn7hNm06Za4RdI5LsGQacJI/7Gw/ME6ZCaeysK3zirRDxw4TjpMGBPm/NI/kc2hL RepA== 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=rG0QzRVn0xvgBNRpL2thyKE3h6hzU4e3t1z4e1/od60=; b=NkVLDDIlD1mpKXXHmcI+vtaeCEQiygoiFtpwfl5msSySng4QbG3yU1RF7qUldCjfjf LRzn3lhFhRrqWaArCKhfeKR7ouRIhDwyy4B1naMiFrKzKynDYQj8jKutTj5nK/+6wgAh Ajfm45vPn3jBKvoZKvavADiDpBSB8vHlSpbZUxqzicrsvLSAxej9mQemnbMfywJh8yzm 5i/VDwgdGudv2C5rez7jOoMLHdrk5hu8XAFWYCtvegR7ClgwVaiYkWWS2WD9zckJSfX4 OTueEtWfHBvjr36qaSHWwU5iflXY8f0DnEmTj7sWnbUxNGUW8luUA7xgjCgzl6jM2AEB JCTA== X-Gm-Message-State: AOAM533lWf3Dj/L4EjSElcPn2X7yZgqcG0HRaLJmapSzLRZEoVVzaRDy SwRhA/B+NyVj5msvYH/5Rb3uRj21uoVb63p8ihom3dzcUTDMnA== X-Google-Smtp-Source: ABdhPJxENIN3EeY5PxUXqLG9ZyFnAWt1M4SR05S23JywwbrbBG6I4jdTp/okqwweP3Y+G+B9/JOFHjNv2x7WVVZlCsY= X-Received: by 2002:a2e:9059:: with SMTP id n25mr10854878ljg.314.1626470961626; Fri, 16 Jul 2021 14:29:21 -0700 (PDT) MIME-Version: 1.0 References: <20210716212629.2232756-1-oupton@google.com> In-Reply-To: <20210716212629.2232756-1-oupton@google.com> From: Oliver Upton Date: Fri, 16 Jul 2021 14:29:10 -0700 Message-ID: Subject: Re: [PATCH v2 00/12] KVM: Add idempotent controls for migrating system counter state To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: Paolo Bonzini , Sean Christopherson , Marc Zyngier , 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Fri, Jul 16, 2021 at 2:26 PM 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: https://lore.kernel.org/kvm/20210608214742.1897483-1-oupton@google.com/ > 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). > > Oliver Upton (12): > KVM: x86: Report host tsc and realtime values in KVM_GET_CLOCK > KVM: x86: Refactor tsc synchronization code > KVM: x86: Expose TSC offset controls to userspace > tools: arch: x86: pull in pvclock headers > selftests: KVM: Add test for KVM_{GET,SET}_CLOCK > selftests: KVM: Add helpers for vCPU device attributes > selftests: KVM: Introduce system counter offset test > KVM: arm64: Allow userspace to configure a vCPU's virtual offset > selftests: KVM: Add support for aarch64 to system_counter_offset_test > KVM: arm64: Provide userspace access to the physical counter offset > selftests: KVM: Test physical counter offsetting > selftests: KVM: Add counter emulation benchmark > > Documentation/virt/kvm/api.rst | 42 +- > Documentation/virt/kvm/locking.rst | 11 + > arch/arm64/include/asm/kvm_host.h | 1 + > arch/arm64/include/asm/kvm_hyp.h | 2 - > arch/arm64/include/asm/sysreg.h | 1 + > arch/arm64/include/uapi/asm/kvm.h | 2 + > arch/arm64/kvm/arch_timer.c | 118 ++++- > arch/arm64/kvm/arm.c | 4 +- > arch/arm64/kvm/hyp/include/hyp/switch.h | 23 + > arch/arm64/kvm/hyp/include/hyp/timer-sr.h | 26 ++ > arch/arm64/kvm/hyp/nvhe/switch.c | 2 - > arch/arm64/kvm/hyp/nvhe/timer-sr.c | 21 +- > arch/arm64/kvm/hyp/vhe/timer-sr.c | 27 ++ > arch/x86/include/asm/kvm_host.h | 4 + > arch/x86/include/uapi/asm/kvm.h | 4 + > arch/x86/kvm/x86.c | 421 ++++++++++++++---- > include/kvm/arm_arch_timer.h | 2 - > include/uapi/linux/kvm.h | 7 +- > tools/arch/x86/include/asm/pvclock-abi.h | 48 ++ > tools/arch/x86/include/asm/pvclock.h | 103 +++++ > tools/testing/selftests/kvm/.gitignore | 3 + > tools/testing/selftests/kvm/Makefile | 4 + > .../kvm/aarch64/counter_emulation_benchmark.c | 215 +++++++++ > .../selftests/kvm/include/aarch64/processor.h | 24 + > .../testing/selftests/kvm/include/kvm_util.h | 11 + > tools/testing/selftests/kvm/lib/kvm_util.c | 38 ++ > .../kvm/system_counter_offset_test.c | 206 +++++++++ > .../selftests/kvm/x86_64/kvm_clock_test.c | 210 +++++++++ > 28 files changed, 1447 insertions(+), 133 deletions(-) > create mode 100644 arch/arm64/kvm/hyp/include/hyp/timer-sr.h > create mode 100644 tools/arch/x86/include/asm/pvclock-abi.h > create mode 100644 tools/arch/x86/include/asm/pvclock.h > create mode 100644 tools/testing/selftests/kvm/aarch64/counter_emulation_benchmark.c > create mode 100644 tools/testing/selftests/kvm/system_counter_offset_test.c > create mode 100644 tools/testing/selftests/kvm/x86_64/kvm_clock_test.c > > -- > 2.32.0.402.g57bb445576-goog > 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=-8.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 8609FC12002 for ; Fri, 16 Jul 2021 21:29:28 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id E685D613C0 for ; Fri, 16 Jul 2021 21:29:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E685D613C0 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 75C264A1AF; Fri, 16 Jul 2021 17:29:27 -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 6xGYI7oeo+bY; Fri, 16 Jul 2021 17:29:26 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 2B1114AC78; Fri, 16 Jul 2021 17:29:26 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id F13214A4A0 for ; Fri, 16 Jul 2021 17:29:24 -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 KL46sHNs7gFF for ; Fri, 16 Jul 2021 17:29:23 -0400 (EDT) Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 88A1E4A1AF for ; Fri, 16 Jul 2021 17:29:23 -0400 (EDT) Received: by mail-lj1-f175.google.com with SMTP id q4so15828392ljp.13 for ; Fri, 16 Jul 2021 14:29:23 -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=rG0QzRVn0xvgBNRpL2thyKE3h6hzU4e3t1z4e1/od60=; b=gGIJ35R95kAzj9vkH0r/wUr9FG5xyFairDEwjCtTS6XF7MTM+ucxhHOQhzSMKQjqYg OdINZFXiXRtuYOEroMB80J80YmqiuwOPy9/zKZIUdpr+aTqhJqzRtxjQZ7rJB2mUOf7Y grZ7SxTZ+6oRLRj+hEAvevMMNvFrSV9i1Op1YLVBoAGXYeO68HeuCg3930vm5JsiOeDi llGy+htXFEOiQHAk4LEFIrYRcQRYqV/PSobtBsWshBumu7qhauwi4kD8dUSw/NDqQe6D jTsxPn7hNm06Za4RdI5LsGQacJI/7Gw/ME6ZCaeysK3zirRDxw4TjpMGBPm/NI/kc2hL RepA== 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=rG0QzRVn0xvgBNRpL2thyKE3h6hzU4e3t1z4e1/od60=; b=RH8zhEP3OKijAsyZ5M0km33eZEitwPWXOWR7ZzUzHXeRgAaAdDz76Vt6LK3UXS7LqX +aX7+Hiy2c4SfEfKvwMbiYHFCHCnUULvaDV9Ng/Ag4D9t40ebfaaWeLdOLrEn4CzCrqw BHCpWOWDkkn3ClpgNbOq/8izsmVI25qJiEu7HVTuArFAa1FjtAOL5mLYUGiXNeKSZU+k CZ7VQZOOAOxtAJCzDNxmiDQdFpurysbOCXqF/hsjxZzSgBsTtHfpyIeby7BF15jo2FKS t+D0b0DKxMp10aVwpOPYxj/4my8AusIj6ctv+mBh5mzfTAOONbmB2glWU2xUOVddK1eF ufcw== X-Gm-Message-State: AOAM531/tOyVt2Yv6j+3Cu91WbuuHAswcXb+s971MlyFLH7xFAYtDFVI x4ZGLeTXzI8268cRXLYgy+1+KLc4p/dzXMCHnefnlw== X-Google-Smtp-Source: ABdhPJxENIN3EeY5PxUXqLG9ZyFnAWt1M4SR05S23JywwbrbBG6I4jdTp/okqwweP3Y+G+B9/JOFHjNv2x7WVVZlCsY= X-Received: by 2002:a2e:9059:: with SMTP id n25mr10854878ljg.314.1626470961626; Fri, 16 Jul 2021 14:29:21 -0700 (PDT) MIME-Version: 1.0 References: <20210716212629.2232756-1-oupton@google.com> In-Reply-To: <20210716212629.2232756-1-oupton@google.com> From: Oliver Upton Date: Fri, 16 Jul 2021 14:29:10 -0700 Message-ID: Subject: Re: [PATCH v2 00/12] KVM: Add idempotent controls for migrating system counter state To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: Marc Zyngier , Raghavendra Rao Anata , Peter Shier , Sean Christopherson , David Matlack , Paolo Bonzini , 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 Fri, Jul 16, 2021 at 2:26 PM 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: https://lore.kernel.org/kvm/20210608214742.1897483-1-oupton@google.com/ > 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). > > Oliver Upton (12): > KVM: x86: Report host tsc and realtime values in KVM_GET_CLOCK > KVM: x86: Refactor tsc synchronization code > KVM: x86: Expose TSC offset controls to userspace > tools: arch: x86: pull in pvclock headers > selftests: KVM: Add test for KVM_{GET,SET}_CLOCK > selftests: KVM: Add helpers for vCPU device attributes > selftests: KVM: Introduce system counter offset test > KVM: arm64: Allow userspace to configure a vCPU's virtual offset > selftests: KVM: Add support for aarch64 to system_counter_offset_test > KVM: arm64: Provide userspace access to the physical counter offset > selftests: KVM: Test physical counter offsetting > selftests: KVM: Add counter emulation benchmark > > Documentation/virt/kvm/api.rst | 42 +- > Documentation/virt/kvm/locking.rst | 11 + > arch/arm64/include/asm/kvm_host.h | 1 + > arch/arm64/include/asm/kvm_hyp.h | 2 - > arch/arm64/include/asm/sysreg.h | 1 + > arch/arm64/include/uapi/asm/kvm.h | 2 + > arch/arm64/kvm/arch_timer.c | 118 ++++- > arch/arm64/kvm/arm.c | 4 +- > arch/arm64/kvm/hyp/include/hyp/switch.h | 23 + > arch/arm64/kvm/hyp/include/hyp/timer-sr.h | 26 ++ > arch/arm64/kvm/hyp/nvhe/switch.c | 2 - > arch/arm64/kvm/hyp/nvhe/timer-sr.c | 21 +- > arch/arm64/kvm/hyp/vhe/timer-sr.c | 27 ++ > arch/x86/include/asm/kvm_host.h | 4 + > arch/x86/include/uapi/asm/kvm.h | 4 + > arch/x86/kvm/x86.c | 421 ++++++++++++++---- > include/kvm/arm_arch_timer.h | 2 - > include/uapi/linux/kvm.h | 7 +- > tools/arch/x86/include/asm/pvclock-abi.h | 48 ++ > tools/arch/x86/include/asm/pvclock.h | 103 +++++ > tools/testing/selftests/kvm/.gitignore | 3 + > tools/testing/selftests/kvm/Makefile | 4 + > .../kvm/aarch64/counter_emulation_benchmark.c | 215 +++++++++ > .../selftests/kvm/include/aarch64/processor.h | 24 + > .../testing/selftests/kvm/include/kvm_util.h | 11 + > tools/testing/selftests/kvm/lib/kvm_util.c | 38 ++ > .../kvm/system_counter_offset_test.c | 206 +++++++++ > .../selftests/kvm/x86_64/kvm_clock_test.c | 210 +++++++++ > 28 files changed, 1447 insertions(+), 133 deletions(-) > create mode 100644 arch/arm64/kvm/hyp/include/hyp/timer-sr.h > create mode 100644 tools/arch/x86/include/asm/pvclock-abi.h > create mode 100644 tools/arch/x86/include/asm/pvclock.h > create mode 100644 tools/testing/selftests/kvm/aarch64/counter_emulation_benchmark.c > create mode 100644 tools/testing/selftests/kvm/system_counter_offset_test.c > create mode 100644 tools/testing/selftests/kvm/x86_64/kvm_clock_test.c > > -- > 2.32.0.402.g57bb445576-goog > _______________________________________________ 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=-9.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 7FFA7C12002 for ; Fri, 16 Jul 2021 21:50:06 +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 492F86109E for ; Fri, 16 Jul 2021 21:50:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 492F86109E 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=GENL5/pjQn9tD7dGUyorovbXJMmTeL1uSLiKKiRUa60=; b=fuydrkPmVQ50/w vK9JDX/7ONpTMej651fsXlm2B4Pqky7D78FwTaqfHVrXpSc7UtLhgLBX4MKzSvIiF/qO26+SRem0Q 04qFlZUAhugBVm+7kvoqGkqK3xKNKg+GJmZfckTyk62bWopfMLuYDVJlujHVYH8m6q1QTMdaxt047 bIb8kBl7lRl61fnTS1haWaPAKuuHjapeAij36wjA6xXq+K67EivhrmUjVoMWNzIGExtFDrkUcqgpF A++W1Yms972oXPm1atbAMt3mf1oEJIzvGk+RrYfcf6xC+wqIvo36emxUVBe1dvXgavgWL004Nskx/ g9fwixMTT1OGGeyWU0YQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m4VgZ-005QwU-Pa; Fri, 16 Jul 2021 21:47:56 +0000 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m4VOf-005Jfg-OD for linux-arm-kernel@lists.infradead.org; Fri, 16 Jul 2021 21:29:27 +0000 Received: by mail-lj1-x22f.google.com with SMTP id t20so118797ljd.2 for ; Fri, 16 Jul 2021 14:29:23 -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=rG0QzRVn0xvgBNRpL2thyKE3h6hzU4e3t1z4e1/od60=; b=gGIJ35R95kAzj9vkH0r/wUr9FG5xyFairDEwjCtTS6XF7MTM+ucxhHOQhzSMKQjqYg OdINZFXiXRtuYOEroMB80J80YmqiuwOPy9/zKZIUdpr+aTqhJqzRtxjQZ7rJB2mUOf7Y grZ7SxTZ+6oRLRj+hEAvevMMNvFrSV9i1Op1YLVBoAGXYeO68HeuCg3930vm5JsiOeDi llGy+htXFEOiQHAk4LEFIrYRcQRYqV/PSobtBsWshBumu7qhauwi4kD8dUSw/NDqQe6D jTsxPn7hNm06Za4RdI5LsGQacJI/7Gw/ME6ZCaeysK3zirRDxw4TjpMGBPm/NI/kc2hL RepA== 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=rG0QzRVn0xvgBNRpL2thyKE3h6hzU4e3t1z4e1/od60=; b=a3k832KS2/VB9q/P9eZByCAbJdt3NKavqyR7m4qHi+uhERNxH6jGE3eTwR1QAXwvyZ QmQgeZ/Ohp4rtWAx7ndaEEsEBkQ1IKlXjRFLY1L//wyfe/YhR+m754Bfp/Ssife5Gy35 AF9Jy9+65gH6OL1Zd9OSLnrCx+X5qyJHGseNAwOvpZhZ80wUl/56fv1wp4xrY9W5GiZd 8edhaENuyw/ysnzYbZkmDcv8lhK+ACJpwAWAxw2xF+hfLhWaYcxYO3u6nna8FI4O3cbu vY8lWcaiiZQuAWzDhQPPEnWB0WthEvz5oXR7ggv3h9eDBCi0gS6vanMC2huEM9iEJ6rU kC6g== X-Gm-Message-State: AOAM532aNQ+WTkwA5hpJE6rehDwNorAIUFDxswdBEB6UCTXiOD0r6CNE UKmUo5evwYnReCHcn1+hVq3gWfO9MUm6RGp0FW0Egw== X-Google-Smtp-Source: ABdhPJxENIN3EeY5PxUXqLG9ZyFnAWt1M4SR05S23JywwbrbBG6I4jdTp/okqwweP3Y+G+B9/JOFHjNv2x7WVVZlCsY= X-Received: by 2002:a2e:9059:: with SMTP id n25mr10854878ljg.314.1626470961626; Fri, 16 Jul 2021 14:29:21 -0700 (PDT) MIME-Version: 1.0 References: <20210716212629.2232756-1-oupton@google.com> In-Reply-To: <20210716212629.2232756-1-oupton@google.com> From: Oliver Upton Date: Fri, 16 Jul 2021 14:29:10 -0700 Message-ID: Subject: Re: [PATCH v2 00/12] KVM: Add idempotent controls for migrating system counter state To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: Paolo Bonzini , Sean Christopherson , Marc Zyngier , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210716_142925_864630_65C288AB X-CRM114-Status: GOOD ( 30.99 ) 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 Fri, Jul 16, 2021 at 2:26 PM 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: https://lore.kernel.org/kvm/20210608214742.1897483-1-oupton@google.com/ > 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). > > Oliver Upton (12): > KVM: x86: Report host tsc and realtime values in KVM_GET_CLOCK > KVM: x86: Refactor tsc synchronization code > KVM: x86: Expose TSC offset controls to userspace > tools: arch: x86: pull in pvclock headers > selftests: KVM: Add test for KVM_{GET,SET}_CLOCK > selftests: KVM: Add helpers for vCPU device attributes > selftests: KVM: Introduce system counter offset test > KVM: arm64: Allow userspace to configure a vCPU's virtual offset > selftests: KVM: Add support for aarch64 to system_counter_offset_test > KVM: arm64: Provide userspace access to the physical counter offset > selftests: KVM: Test physical counter offsetting > selftests: KVM: Add counter emulation benchmark > > Documentation/virt/kvm/api.rst | 42 +- > Documentation/virt/kvm/locking.rst | 11 + > arch/arm64/include/asm/kvm_host.h | 1 + > arch/arm64/include/asm/kvm_hyp.h | 2 - > arch/arm64/include/asm/sysreg.h | 1 + > arch/arm64/include/uapi/asm/kvm.h | 2 + > arch/arm64/kvm/arch_timer.c | 118 ++++- > arch/arm64/kvm/arm.c | 4 +- > arch/arm64/kvm/hyp/include/hyp/switch.h | 23 + > arch/arm64/kvm/hyp/include/hyp/timer-sr.h | 26 ++ > arch/arm64/kvm/hyp/nvhe/switch.c | 2 - > arch/arm64/kvm/hyp/nvhe/timer-sr.c | 21 +- > arch/arm64/kvm/hyp/vhe/timer-sr.c | 27 ++ > arch/x86/include/asm/kvm_host.h | 4 + > arch/x86/include/uapi/asm/kvm.h | 4 + > arch/x86/kvm/x86.c | 421 ++++++++++++++---- > include/kvm/arm_arch_timer.h | 2 - > include/uapi/linux/kvm.h | 7 +- > tools/arch/x86/include/asm/pvclock-abi.h | 48 ++ > tools/arch/x86/include/asm/pvclock.h | 103 +++++ > tools/testing/selftests/kvm/.gitignore | 3 + > tools/testing/selftests/kvm/Makefile | 4 + > .../kvm/aarch64/counter_emulation_benchmark.c | 215 +++++++++ > .../selftests/kvm/include/aarch64/processor.h | 24 + > .../testing/selftests/kvm/include/kvm_util.h | 11 + > tools/testing/selftests/kvm/lib/kvm_util.c | 38 ++ > .../kvm/system_counter_offset_test.c | 206 +++++++++ > .../selftests/kvm/x86_64/kvm_clock_test.c | 210 +++++++++ > 28 files changed, 1447 insertions(+), 133 deletions(-) > create mode 100644 arch/arm64/kvm/hyp/include/hyp/timer-sr.h > create mode 100644 tools/arch/x86/include/asm/pvclock-abi.h > create mode 100644 tools/arch/x86/include/asm/pvclock.h > create mode 100644 tools/testing/selftests/kvm/aarch64/counter_emulation_benchmark.c > create mode 100644 tools/testing/selftests/kvm/system_counter_offset_test.c > create mode 100644 tools/testing/selftests/kvm/x86_64/kvm_clock_test.c > > -- > 2.32.0.402.g57bb445576-goog > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel