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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6FDEC433F5 for ; Fri, 24 Sep 2021 16:43:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C0CAD6124B for ; Fri, 24 Sep 2021 16:43:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343643AbhIXQpE (ORCPT ); Fri, 24 Sep 2021 12:45:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29795 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233969AbhIXQo7 (ORCPT ); Fri, 24 Sep 2021 12:44:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632501806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xrd9wID+O6lXydA/auUdyoLz8h/dNJ6woqTmdu062kc=; b=hMAmEt4Gqd3tuMia+U0dQiHb7nCR/qkuPH/OpzLfMHgBzGUqWoUXcQYapq2qCwiaMEtrJm GiMlPCoTsTnL4za8JLiRVSbh6kX1Sgt2vPerQ6/R8qHwVRa0YqibTZfhm7vI+ItAEzOGqW B1UOwKpF93UtDI3sIF1PekKRPPS4hiU= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-202-ctTK7b3CNfGKyVLRkNXybg-1; Fri, 24 Sep 2021 12:43:24 -0400 X-MC-Unique: ctTK7b3CNfGKyVLRkNXybg-1 Received: by mail-ed1-f70.google.com with SMTP id m30-20020a50999e000000b003cdd7680c8cso10831574edb.11 for ; Fri, 24 Sep 2021 09:43:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=Xrd9wID+O6lXydA/auUdyoLz8h/dNJ6woqTmdu062kc=; b=fEyKtRQiZILkEXmML8MTx9tJDMSONOoIT2BrWnqCgYVogL30XJwNw89xcoRj3kF4Bl wygr/h/5NalMflf1heMJn7I8oDRoXs4djZjJjM2zz6t9BRDYmrpcLNr2n68j1hS3gUYl ZUVtfRDXxkCtZe/I9fHiV93e6TsD8AnulknH1H6oIkf0yztDiM+wBqKmATZd9HnO0laK D4VkieTTQptoV6U1T9UW14CZWLqJcxtf96Ipz2UQxjpFSaggvgso85wzdeeEg8kaHk+V VRTF4cAjWygL0xYXTPpb2/in1mOHvJ81JuPM+tSe/5LypCINL7HBqb8zFTpBriShU9iO t9DA== X-Gm-Message-State: AOAM532uYpaKaw/D/T3riM+n1YqnbSh7Mai8OsI4C9TcbitmqcEJa9Ql IHSndfmrxVewP3z+fPdVUZPnyGfMV9kRkDMfUab4/wXpJb8Xw/GlC/TE1sgVFMz2suiLQ0UA2WC UE3CyIZYtkXHb X-Received: by 2002:a17:906:32c9:: with SMTP id k9mr12526948ejk.218.1632501803387; Fri, 24 Sep 2021 09:43:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycJysgKh7IfROIXy7X+AKIfF9Ahyp8Cqy6RCpIsmYlwjlA3xpaOkwlN4ADHD6VhHck9ohNyA== X-Received: by 2002:a17:906:32c9:: with SMTP id k9mr12526912ejk.218.1632501803170; Fri, 24 Sep 2021 09:43:23 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id x7sm6009332ede.86.2021.09.24.09.43.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Sep 2021 09:43:22 -0700 (PDT) Message-ID: Date: Fri, 24 Sep 2021 18:43:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: [PATCH v8 0/7] KVM: x86: Add idempotent controls for migrating system counter state Content-Language: en-US To: Oliver Upton , kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: 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, Andrew Jones , Will Deacon , Catalin Marinas References: <20210916181538.968978-1-oupton@google.com> From: Paolo Bonzini In-Reply-To: <20210916181538.968978-1-oupton@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On 16/09/21 20:15, Oliver Upton wrote: > KVM's current means of saving/restoring system counters is plagued with > temporal issues. On x86, we migrate the guest's system counter by-value > through the respective guest's IA32_TSC value. 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 the TSC offset. > We can avoid all of the issues associated with a value-based interface > by abstracting these offset controls in a new device attribute. This > series introduces new vCPU device attributes to provide userspace access > to the vCPU's system counter offset. > > Patches 1-2 are Paolo's refactorings around locking and the > KVM_{GET,SET}_CLOCK ioctls. > > Patch 3 cures a race where use_master_clock is read outside of the > pvclock lock in the KVM_GET_CLOCK ioctl. > > Patch 4 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. > > Patch 5 does away with the pvclock spin lock in favor of a sequence > lock based on the tsc_write_lock. The original patch is from Paolo, I > touched it up a bit to fix a deadlock and some unused variables that > caused -Werror to scream. > > Patch 6 extracts the TSC synchronization tracking code in a way that it > can be used for both offset-based and value-based TSC synchronization > schemes. > > Finally, patch 7 implements a vCPU device attribute which allows VMMs to > get at the TSC offset of a vCPU. > > This series was tested with the new KVM selftests for the KVM clock and > system counter offset controls on Haswell hardware. Kernel was built > with CONFIG_LOCKDEP given the new locking changes/lockdep assertions > here. > > Note that these tests are mailed as a separate series due to the > dependencies in both x86 and arm64. > > Applies cleanly to 5.15-rc1 > > v8: http://lore.kernel.org/r/20210816001130.3059564-1-oupton@google.com > > v7 -> v8: > - Rebased to 5.15-rc1 > - Picked up Paolo's version of the series, which includes locking > changes > - Make KVM advertise KVM_CAP_VCPU_ATTRIBUTES > > Oliver Upton (4): > KVM: x86: Fix potential race in KVM_GET_CLOCK > 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 > > Paolo Bonzini (3): > kvm: x86: abstract locking around pvclock_update_vm_gtod_copy > KVM: x86: extract KVM_GET_CLOCK/KVM_SET_CLOCK to separate functions > kvm: x86: protect masterclock with a seqcount > > Documentation/virt/kvm/api.rst | 42 ++- > Documentation/virt/kvm/devices/vcpu.rst | 57 +++ > arch/x86/include/asm/kvm_host.h | 12 +- > arch/x86/include/uapi/asm/kvm.h | 4 + > arch/x86/kvm/x86.c | 458 ++++++++++++++++-------- > include/uapi/linux/kvm.h | 7 +- > 6 files changed, 419 insertions(+), 161 deletions(-) > Queued, thanks. Paolo 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15843C433EF for ; Fri, 24 Sep 2021 16:43:31 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 710D1610D1 for ; Fri, 24 Sep 2021 16:43:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 710D1610D1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 0239F4AC78; Fri, 24 Sep 2021 12:43:30 -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=@redhat.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 vaYhDtAHB75h; Fri, 24 Sep 2021 12:43:28 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 9F68D4B08D; Fri, 24 Sep 2021 12:43:28 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 1AEDE4B086 for ; Fri, 24 Sep 2021 12:43:27 -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 8qYUvR+DuACy for ; Fri, 24 Sep 2021 12:43:26 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mm01.cs.columbia.edu (Postfix) with ESMTP id F3BD44AC78 for ; Fri, 24 Sep 2021 12:43:25 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632501805; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xrd9wID+O6lXydA/auUdyoLz8h/dNJ6woqTmdu062kc=; b=Jnx3hbkaA34G/FRK4jiDkbOpHMMxs2dOFq/Y8+pxhMfMGzgm+/CEcCpL2UgoTKkVilY/nY lejcTMyVmjJy7HmBquCQsDQ0YTH2CNnstMTz1eqOJNe+y8081CB6n6BmxPAnaCN33Hfizc 9UQ++0N2JdJ6Gg86D2zA5jsRf8ZwXRs= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-584-axArCNxONKS9LUSNlM8TYA-1; Fri, 24 Sep 2021 12:43:24 -0400 X-MC-Unique: axArCNxONKS9LUSNlM8TYA-1 Received: by mail-ed1-f69.google.com with SMTP id h6-20020a50c386000000b003da01adc065so10847466edf.7 for ; Fri, 24 Sep 2021 09:43:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=Xrd9wID+O6lXydA/auUdyoLz8h/dNJ6woqTmdu062kc=; b=4c9EHQ/QNuI7CgSQ4YEaLHMuxXJsX5i4USTtTOObkRkiCLQPfqEYW9PLr9XpEZ0z3L zRPB+rRotsFJQ0PNKLD9fBFfrF+9FytXJDvkJuNtO5IbOhiQy/OjGk9jCHgiUiGjEo01 s8jacwGm5TX90jOnXI9CfjxN1Mk+Cth0mEjGTqAJVA9cQyYt11ctl2zSXTLADr93+WO1 NOsDR7f41Q4n5WQEKHM68ZOKYVMd8+bkK8ykdtrhxUVec0ElomDMjC9Ghq7iWENDvLSP GToSLSbR/xo011PHrP4FmmW2PkuH0yHDO8AXhSb23mHaJn3qOPKHX4QNZHfLrkdt7MiS pLiA== X-Gm-Message-State: AOAM533Y+YzhuTjDT+93QYz8UPc0cDTwVRL4lOFVv4MIaOHBUrRzVngn SKLKgfZ75JD+aA/74T/fbz8Etdg1V++TAgyMFnKxWCqy/32pX2pNHyrXC8f7m4G1Lab5AvHd6eQ YF6VrxVb/72aA6hf2uvPVbEf0 X-Received: by 2002:a17:906:32c9:: with SMTP id k9mr12526946ejk.218.1632501803387; Fri, 24 Sep 2021 09:43:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycJysgKh7IfROIXy7X+AKIfF9Ahyp8Cqy6RCpIsmYlwjlA3xpaOkwlN4ADHD6VhHck9ohNyA== X-Received: by 2002:a17:906:32c9:: with SMTP id k9mr12526912ejk.218.1632501803170; Fri, 24 Sep 2021 09:43:23 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id x7sm6009332ede.86.2021.09.24.09.43.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Sep 2021 09:43:22 -0700 (PDT) Message-ID: Date: Fri, 24 Sep 2021 18:43:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: [PATCH v8 0/7] KVM: x86: Add idempotent controls for migrating system counter state To: Oliver Upton , kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu References: <20210916181538.968978-1-oupton@google.com> From: Paolo Bonzini In-Reply-To: <20210916181538.968978-1-oupton@google.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Cc: Catalin Marinas , Will Deacon , Peter Shier , Marc Zyngier , David Matlack , 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On 16/09/21 20:15, Oliver Upton wrote: > KVM's current means of saving/restoring system counters is plagued with > temporal issues. On x86, we migrate the guest's system counter by-value > through the respective guest's IA32_TSC value. 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 the TSC offset. > We can avoid all of the issues associated with a value-based interface > by abstracting these offset controls in a new device attribute. This > series introduces new vCPU device attributes to provide userspace access > to the vCPU's system counter offset. > > Patches 1-2 are Paolo's refactorings around locking and the > KVM_{GET,SET}_CLOCK ioctls. > > Patch 3 cures a race where use_master_clock is read outside of the > pvclock lock in the KVM_GET_CLOCK ioctl. > > Patch 4 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. > > Patch 5 does away with the pvclock spin lock in favor of a sequence > lock based on the tsc_write_lock. The original patch is from Paolo, I > touched it up a bit to fix a deadlock and some unused variables that > caused -Werror to scream. > > Patch 6 extracts the TSC synchronization tracking code in a way that it > can be used for both offset-based and value-based TSC synchronization > schemes. > > Finally, patch 7 implements a vCPU device attribute which allows VMMs to > get at the TSC offset of a vCPU. > > This series was tested with the new KVM selftests for the KVM clock and > system counter offset controls on Haswell hardware. Kernel was built > with CONFIG_LOCKDEP given the new locking changes/lockdep assertions > here. > > Note that these tests are mailed as a separate series due to the > dependencies in both x86 and arm64. > > Applies cleanly to 5.15-rc1 > > v8: http://lore.kernel.org/r/20210816001130.3059564-1-oupton@google.com > > v7 -> v8: > - Rebased to 5.15-rc1 > - Picked up Paolo's version of the series, which includes locking > changes > - Make KVM advertise KVM_CAP_VCPU_ATTRIBUTES > > Oliver Upton (4): > KVM: x86: Fix potential race in KVM_GET_CLOCK > 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 > > Paolo Bonzini (3): > kvm: x86: abstract locking around pvclock_update_vm_gtod_copy > KVM: x86: extract KVM_GET_CLOCK/KVM_SET_CLOCK to separate functions > kvm: x86: protect masterclock with a seqcount > > Documentation/virt/kvm/api.rst | 42 ++- > Documentation/virt/kvm/devices/vcpu.rst | 57 +++ > arch/x86/include/asm/kvm_host.h | 12 +- > arch/x86/include/uapi/asm/kvm.h | 4 + > arch/x86/kvm/x86.c | 458 ++++++++++++++++-------- > include/uapi/linux/kvm.h | 7 +- > 6 files changed, 419 insertions(+), 161 deletions(-) > Queued, thanks. Paolo _______________________________________________ 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C8D4C433EF for ; Fri, 24 Sep 2021 16:45:38 +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 2A85360EE7 for ; Fri, 24 Sep 2021 16:45:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2A85360EE7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vPL9U0eHDCF8bbHDTehDiUz8hkL2FQ0fVFn+P9HezAo=; b=XVWEBAYBs/jqVo uE86EtcWVHqRBSo73R935GY9pTakMrEDuUOvWCiYEAjJaytK1DLp1vgs3urcm0E/RgUULvfBP6aYD a54qPCXoRxEN8cWy4qjPnNoqHR+NmKs997zN1A9OzflvQO2UBrXia4i3fxVYZrx8WFKOf5QAgy7hr GVVkdwPHBMtI6B/Hl39i3luu/+14Gj2vqTC2J8KLofa9KQpkdlM+Z4VAg8aJW4TYO/jmBZ0zeV5L/ 84P5oNDlXMgHWoDuELin7dzwMa+/z4kHupsg0qj7gwnEtD40/9HXVOz+HdmLk30Y8O0OHJwDKIAfI 7xXGhA2Xcfubpo7X97tg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mToIN-00F7mS-Vt; Fri, 24 Sep 2021 16:43:32 +0000 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mToIJ-00F7l9-6S for linux-arm-kernel@lists.infradead.org; Fri, 24 Sep 2021 16:43:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632501806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xrd9wID+O6lXydA/auUdyoLz8h/dNJ6woqTmdu062kc=; b=hMAmEt4Gqd3tuMia+U0dQiHb7nCR/qkuPH/OpzLfMHgBzGUqWoUXcQYapq2qCwiaMEtrJm GiMlPCoTsTnL4za8JLiRVSbh6kX1Sgt2vPerQ6/R8qHwVRa0YqibTZfhm7vI+ItAEzOGqW B1UOwKpF93UtDI3sIF1PekKRPPS4hiU= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-61-3BLajSw7P1GymXSC_jAJPQ-1; Fri, 24 Sep 2021 12:43:25 -0400 X-MC-Unique: 3BLajSw7P1GymXSC_jAJPQ-1 Received: by mail-ed1-f72.google.com with SMTP id r11-20020aa7cfcb000000b003d4fbd652b9so10835728edy.14 for ; Fri, 24 Sep 2021 09:43:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=Xrd9wID+O6lXydA/auUdyoLz8h/dNJ6woqTmdu062kc=; b=uvocZw9ky60gZQ67Z48q2Fci502VdAhg9irC17BLbPBAsue4kyUPeAKAwZLjFzbSM+ lWxhpSlob8gdqYUWomsgZjl+i3tiHBp/Gsq+zNc6ZufvF2SL/BTDT5s/jQXO4/RQpbeZ VGk1I4URBi96DJt9nRwEi1sAPlPepsMe/sAZUjhfEvKRvDIEDT6lj+U+PyxDTQFMHJIY x49QNJ20Qn01XUujYDVPv48TST37jWmnqdUrWM6TijIAdBWuQrz33UewH/Y9vOBfW1ri 4MD1sBw/A0BdFtddNjxw63BZezKtl6i0iXkSm1sP1X5wI7kvafma1GNbv6VpgSlnHTv1 /3IQ== X-Gm-Message-State: AOAM5321fSQUuJtq2gK/fhSrI/Mn0CVGznsod0sI9Wq/Kwitxw1OSRT7 RgWKTU2ixaH5z5w8w7S3YD5+Ojcw17GCU+vMt1IOiS2d8c9aXLy/Yn6EUjCP6+lNsot3lUzg8mK lwoD7HJ3fZ+z19NeZtAYaURn/pUFC2IsqTPQ= X-Received: by 2002:a17:906:32c9:: with SMTP id k9mr12526936ejk.218.1632501803384; Fri, 24 Sep 2021 09:43:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycJysgKh7IfROIXy7X+AKIfF9Ahyp8Cqy6RCpIsmYlwjlA3xpaOkwlN4ADHD6VhHck9ohNyA== X-Received: by 2002:a17:906:32c9:: with SMTP id k9mr12526912ejk.218.1632501803170; Fri, 24 Sep 2021 09:43:23 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id x7sm6009332ede.86.2021.09.24.09.43.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Sep 2021 09:43:22 -0700 (PDT) Message-ID: Date: Fri, 24 Sep 2021 18:43:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: [PATCH v8 0/7] KVM: x86: Add idempotent controls for migrating system counter state To: Oliver Upton , kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: 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, Andrew Jones , Will Deacon , Catalin Marinas References: <20210916181538.968978-1-oupton@google.com> From: Paolo Bonzini In-Reply-To: <20210916181538.968978-1-oupton@google.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210924_094327_359168_493A2F7D X-CRM114-Status: GOOD ( 26.26 ) 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 16/09/21 20:15, Oliver Upton wrote: > KVM's current means of saving/restoring system counters is plagued with > temporal issues. On x86, we migrate the guest's system counter by-value > through the respective guest's IA32_TSC value. 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 the TSC offset. > We can avoid all of the issues associated with a value-based interface > by abstracting these offset controls in a new device attribute. This > series introduces new vCPU device attributes to provide userspace access > to the vCPU's system counter offset. > > Patches 1-2 are Paolo's refactorings around locking and the > KVM_{GET,SET}_CLOCK ioctls. > > Patch 3 cures a race where use_master_clock is read outside of the > pvclock lock in the KVM_GET_CLOCK ioctl. > > Patch 4 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. > > Patch 5 does away with the pvclock spin lock in favor of a sequence > lock based on the tsc_write_lock. The original patch is from Paolo, I > touched it up a bit to fix a deadlock and some unused variables that > caused -Werror to scream. > > Patch 6 extracts the TSC synchronization tracking code in a way that it > can be used for both offset-based and value-based TSC synchronization > schemes. > > Finally, patch 7 implements a vCPU device attribute which allows VMMs to > get at the TSC offset of a vCPU. > > This series was tested with the new KVM selftests for the KVM clock and > system counter offset controls on Haswell hardware. Kernel was built > with CONFIG_LOCKDEP given the new locking changes/lockdep assertions > here. > > Note that these tests are mailed as a separate series due to the > dependencies in both x86 and arm64. > > Applies cleanly to 5.15-rc1 > > v8: http://lore.kernel.org/r/20210816001130.3059564-1-oupton@google.com > > v7 -> v8: > - Rebased to 5.15-rc1 > - Picked up Paolo's version of the series, which includes locking > changes > - Make KVM advertise KVM_CAP_VCPU_ATTRIBUTES > > Oliver Upton (4): > KVM: x86: Fix potential race in KVM_GET_CLOCK > 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 > > Paolo Bonzini (3): > kvm: x86: abstract locking around pvclock_update_vm_gtod_copy > KVM: x86: extract KVM_GET_CLOCK/KVM_SET_CLOCK to separate functions > kvm: x86: protect masterclock with a seqcount > > Documentation/virt/kvm/api.rst | 42 ++- > Documentation/virt/kvm/devices/vcpu.rst | 57 +++ > arch/x86/include/asm/kvm_host.h | 12 +- > arch/x86/include/uapi/asm/kvm.h | 4 + > arch/x86/kvm/x86.c | 458 ++++++++++++++++-------- > include/uapi/linux/kvm.h | 7 +- > 6 files changed, 419 insertions(+), 161 deletions(-) > Queued, thanks. Paolo _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel