Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp737418pxu; Fri, 11 Dec 2020 13:05:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwTuMuumGMFgE+KJyDkp3M5ea4mh0naSHYmR4ckeWYZKh8OVUNSMdmdr/BBqQeQ0uveUQr0 X-Received: by 2002:aa7:d41a:: with SMTP id z26mr13906952edq.267.1607720712888; Fri, 11 Dec 2020 13:05:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607720712; cv=none; d=google.com; s=arc-20160816; b=Pb5e6IzW4EILT4SeUmpyc6egjqyMF5j5PTWstd49kTPr7Av3Y4rnS5x7HHg8KR1eZk yuiPWEZfxG/BI034R6gBOnsTOmaHB9nmjTxQlnRrqRm5Ef+5NTVyvOuRQLfMGpL/ZU/f v/wzpsE9ryEqpm8TXkZNrL6l3SiQSIfhAfydHBD7ZQ54XKcELJTXqad+rnki9eUGBo62 IX52QXz/oL3mD737igrol790OYhgNc8MSzv8S8FkPMnqEWrz+qkXTP/RyEK/nmIkGVQN IpW3Lo0I2YmE1bfC90pQtwfS6QkhqV/2qVRbIJxjON0vqov4UGukV2uDS0pypb1Tta1c qCBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=et/f3RjbZyuZ9JQ6heD+AHbTOUp1bUm1tRV1afS0ffo=; b=N2SilZGhdCoAK2FzOgmzXwY9J32pkJC4GLkj2AoGpOawLt7FUpjXL4waYw10+sOH3s kpn6VQ1nPeq+W/Pd7bpRcqCBOtGjbb4VwPlKg5+TB8kiOLENdJOxMwa5ZndqOIa1tOTR rDabp5/F8ZmuaBn9k36tLLsK7tp+BnqTZTM5fEKlLUCNkJDZBWjCtVWmX/UAWVRmQBLp JvsBs2ugLk9igNj1T1MvaOLVhzcLYU0u3tSjJUfEAuC21Xzp339GbZmIxERe7Nk/K9lC Ws7mSi4CDXYoqbHqeuYbtLjfsrBXQUXCLhcM4ucdemhZB9gzMNj10zYB+DQfTLuii28c 3a7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=v19m+I06; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cz22si5544455edb.241.2020.12.11.13.04.48; Fri, 11 Dec 2020 13:05:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=v19m+I06; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392495AbgLJSOR (ORCPT + 99 others); Thu, 10 Dec 2020 13:14:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392768AbgLJSOG (ORCPT ); Thu, 10 Dec 2020 13:14:06 -0500 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C40D1C06179C for ; Thu, 10 Dec 2020 10:13:25 -0800 (PST) Received: by mail-lj1-x243.google.com with SMTP id s11so7751478ljp.4 for ; Thu, 10 Dec 2020 10:13:25 -0800 (PST) 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=et/f3RjbZyuZ9JQ6heD+AHbTOUp1bUm1tRV1afS0ffo=; b=v19m+I06m7joT/AcjLb0tMF6lAJ5V8z+FKPko5snmNCFHTPv3bdEHyAb+gPnz4se2R +INSchsHDnXs6CHDwyr1OX9D7lgsQLp0+HpPcFPNqyTm2K0h1yTcKG2yEcdN7vKYkDxZ /r5QdIJlQZDG0tU68JwmcZR5S+hOa0hDvt1zdO/fcLCeGHukWpFmaF2PxrCHxWjHeiE0 gaBxJ0NFtD5oc7137LS/skmzqx28uL8EH24BWt9F/nsw2pVhq6uhRBMeYbwhLkauiQ4g kiZ0QTjeICTynLVhctWqyARIy3ebvmQcwkfwaIqdz4p+gTYl4zTCqUoRiuFb3GKZl3vD QPGQ== 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=et/f3RjbZyuZ9JQ6heD+AHbTOUp1bUm1tRV1afS0ffo=; b=H4aVGqmsj+KTrSRZggFOyhhP19Yj+1QrHczPd76iUzSxMu0HpKwjSqTh0utl/K0dOa b4DCOYABY44rju+RkwWiv8jeEU3pFLrFUzfzPRY0PKdoPxvRrGGunJTDq57f0vg/5FL1 Qu5/7Mlz/DohLOzPn2BP0IXZ7wwRYb6cpbr/yBvuKbpIvm4QEgSGoBv3erGcwDJzEg4W 8NJLY4n6Pgi4AlFAxk8RASG4rNUEFHFdkkO7slqYEXtpyZwxJ/irJE27j6Fvm29hEO5m oT7p9sJWjw/Q3k12o3oL5cyXnsyZrKT/Q33pgxuqe8+xkuIH+6INZ6Tu+3g/27QnSCGF c40Q== X-Gm-Message-State: AOAM532CY50fZt7xuSXHDwlXKmVL+msCDm8/3RdXg6WJoXsn3EyaAQO8 3xU9BSngKmT6H6K9MQ8OtBGSjtxP2ClWnNRiZqccrw== X-Received: by 2002:a2e:961a:: with SMTP id v26mr3699249ljh.314.1607624003934; Thu, 10 Dec 2020 10:13:23 -0800 (PST) MIME-Version: 1.0 References: <9389c1198da174bcc9483d6ebf535405aa8bdb45.camel@redhat.com> In-Reply-To: From: Oliver Upton Date: Thu, 10 Dec 2020 12:13:12 -0600 Message-ID: Subject: Re: [PATCH v2 1/3] KVM: x86: implement KVM_{GET|SET}_TSC_STATE To: Paolo Bonzini Cc: Andy Lutomirski , Maxim Levitsky , Thomas Gleixner , Marcelo Tosatti , kvm list , "H. Peter Anvin" , Jonathan Corbet , Jim Mattson , Wanpeng Li , "open list:KERNEL SELFTEST FRAMEWORK" , Vitaly Kuznetsov , Sean Christopherson , open list , Ingo Molnar , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Joerg Roedel , Borislav Petkov , Shuah Khan , Andrew Jones , "open list:DOCUMENTATION" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 10, 2020 at 12:05 PM Paolo Bonzini wrote: > > On 10/12/20 18:59, Oliver Upton wrote: > > However, I don't believe we can assume the guest's TSCs to be synchronized, > > even if sane guests will never touch them. In this case, I think a per-vCPU > > ioctl is still warranted, allowing userspace to get at the guest CPU adjust > > component of Thomas' equation below (paraphrased): > > > > TSC guest CPU = host tsc base + guest base offset + guest CPU adjust > > Right now that would be: > > - KVM_GET_TSC_STATE (vm) returns host tsc base + guest base offset (plus > the associated time) > > - KVM_GET_MSR *without* KVM_X86_QUIRK_TSC_HOST_ACCESS for guest CPU adjust > > and the corresponding SET ioctls. What am *I* missing? > > > Alternatively, a write from userspace to the guest's IA32_TSC_ADJUST with > > KVM_X86_QUIRK_TSC_HOST_ACCESS could have the same effect, but that seems to be > > problematic for a couple reasons. First, depending on the guest's CPUID the > > TSC_ADJUST MSR may not even be available, meaning that the guest could've used > > IA32_TSC to adjust the TSC (eww). > > Indeed, the host should always be able to read/write IA32_TSC and > IA32_TSC_ADJUST. So long as it is guaranteed that guest manipulations of IA32_TSC are reflected in IA32_TSC_ADJUST even if it isn't in the guest's CPUID, then this seems OK. I think having clear documentation on this subject is also necessary, as we're going to rely on the combination of KVM_{GET,SET}_TSC_STATE, disabling KVM_X86_QUIRK_TSC_HOST_ACCESS, and userspace reading/writing a possibly hidden MSR to pull this off right. -- Thanks, Oliver > Thanks, > > Paolo > > > Second, userspace replaying writes to IA32_TSC > > (in the case IA32_TSC_ADJUST doesn't exist for the guest) seems_very_ > > unlikely to work given all the magic handling that KVM does for > > writes to it. > > > > Is this roughly where we are or have I entirely missed the mark?:-) >