Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp865088pxy; Thu, 22 Apr 2021 15:40:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwktOaj3/6uZfO4Uy3mMNgO6GVjlgJBsP9SWhsMbHZR6wgKTXDPO17Ho/Yldtsyqq9qFVXB X-Received: by 2002:a17:903:10a:b029:eb:1fd1:ca0 with SMTP id y10-20020a170903010ab02900eb1fd10ca0mr1026804plc.71.1619131207693; Thu, 22 Apr 2021 15:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619131207; cv=none; d=google.com; s=arc-20160816; b=n796CPIOcJ+t/6qmA9kmHZN82HO77tCuygknQFQxezdQZXnaR8m0ZyO+jbjU3+TLzI KWlGOVWfM3sQAdygwVFSfQikENlsNZ/kvJpcxTWx1x85FLJ/WzjkqGIay13V99wXBoot E64RAOhLw4bJVvMjZuoson79TxjgnRZOYyQlGBbMhWP2DM9h+/AgmF+Y1z57hyyRvVEy 1f+MNUsNokb2FS8lq0FafYx87kIjW18lHJa4NwvAacBvBXYI2ZXoaCSwJDRdoSQEnTwy CrR3PZPA/mAD6ZEWMLWOw0mOcUcVC/Cog42ToZl44f63ta+us6fiJ1M4FO57LAAysTyK HCYQ== 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=DUlDwcgwPAcRYMvT6n0zmQZ02FrFSLFm4jKgBTz17LU=; b=kFBJp12aKJpsW5ibAOTSDwASVg9WVibmABJq/Vs0WVlqkGpyw/WC8rxhCjSA15x37k VnxyvoyKVrKv4YyEcLPRC7PZXk6upUpAGlVKknbhgDllRl3MyTHHugvSsXKEtDOdq9RQ IzqcfKT2DWMM1AgFAqn+/mLwkPKvYQ5GLt64H2U4mwORDk5tH61rUDtcOInBfzI1xE3Q RbAs+P0gf5hBJ/62iaDWnVHcUJpQLKbAkTtt77e75rubKDWzC3ehUF8Fp2ffkCLkle1X zdz/mPZ6q7eILxm6PwUL7sWr+n4YugR0EYN/VgIEuIaU5wuq4frhEvB3zpy5RHNq8aDP CRFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Cw8D18+L; 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 e8si4773032pfi.119.2021.04.22.15.39.53; Thu, 22 Apr 2021 15:40:07 -0700 (PDT) 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=Cw8D18+L; 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 S237047AbhDVWj7 (ORCPT + 99 others); Thu, 22 Apr 2021 18:39:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235502AbhDVWj7 (ORCPT ); Thu, 22 Apr 2021 18:39:59 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA25EC06174A for ; Thu, 22 Apr 2021 15:39:23 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id h15so15088574pfv.2 for ; Thu, 22 Apr 2021 15:39: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=DUlDwcgwPAcRYMvT6n0zmQZ02FrFSLFm4jKgBTz17LU=; b=Cw8D18+LB+KggXJC3Hs7OS36Q58sjfTflgjQhQVcB9h78s6y35jRdKlqU4zsPFg4F6 pauiG4kgb/tk6UMTiawgychtg2BRhGZAQ1p7iSqS2dbuOqqpEykK7yoJYv6NINA6/GNO pF1RFPp0jpJX0UJ8BzE9xlRkIfI23O6jSnpGPDBoSIBf32ExAiXZVm5UBA+eA/tYaMYI Y0QH0appUDGgAU/iCvtSaHHcH49M53u9lJ2gwQ5sZwuMMeSPnFPgHzjIBqv3BeSfYRlJ xvechPdEmgyOqG07nK6+N0VIL0Nl+KiqVFKLAixAcFi59f6mO2+kI8ivDP62z3e3QyGL Ydng== 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=DUlDwcgwPAcRYMvT6n0zmQZ02FrFSLFm4jKgBTz17LU=; b=SNogohPumx8Z9eBndkHoaJKm3+5NlzONiLohvNx5Fka/5YCG83AYET9DC4LFNP0DuE gGYrCHbv/dWVh840Kb740h0xqC262N7bH9HxgIQHWu/OeKQwd4ebF7+rBxCV5B8bXcG3 fdW6bQOVehEDuPrkOPrpE2/75evXxlCCCGYkJ8G3ErZvQ/qrJwYtSxVOk4AS3wr8WNql YJu8lWqi65ctKfePsEIbOsz3RjABNLAUOTOYnBh2z8XJjhv5PJ+3/ZVZLnSp0J1tRkTh FS0nqOP2zLlojXuKvEigVw2U99+5qrPEAMqvkC6z7tzfArfYOkKPOHLL9LLhOOYLSwgZ wkwg== X-Gm-Message-State: AOAM533PSFCU6/DSlhBIWLZnx2tD30TfjbrrQa5yfAW4co7lp4Prg0JZ NGZx+4ALnfOGthG86V43MSkswG+JWzgAPEd3/G+nLw== X-Received: by 2002:a63:4f50:: with SMTP id p16mr913749pgl.40.1619131163259; Thu, 22 Apr 2021 15:39:23 -0700 (PDT) MIME-Version: 1.0 References: <20210422001736.3255735-1-seanjc@google.com> In-Reply-To: From: Reiji Watanabe Date: Thu, 22 Apr 2021 15:39:07 -0700 Message-ID: Subject: Re: [PATCH v2] KVM: SVM: Delay restoration of host MSR_TSC_AUX until return to userspace To: Sean Christopherson Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Tom Lendacky Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > All in all, I think we want this: > > case MSR_TSC_AUX: > if (!boot_cpu_has(X86_FEATURE_RDTSCP)) > return 1; > > if (!msr_info->host_initiated && > !guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP)) > return 1; > > /* > * TSC_AUX is usually changed only during boot and never read > * directly. Intercept TSC_AUX instead of exposing it to the > * guest via direct_access_msrs, and switch it via user return. > */ > preempt_disable(); > r = kvm_set_user_return_msr(TSC_AUX_URET_SLOT, data, -1ull); > preempt_enable(); > if (r) > return 1; > > /* > * Bits 63:32 are dropped by AMD CPUs, but are reserved on > * Intel CPUs. AMD's APM has incomplete and conflicting info > * on the architectural behavior; emulate current hardware as > * doing so ensures migrating from AMD to Intel won't explode. > */ > svm->tsc_aux = (u32)data; > break; Thank you for the explanation. I understand and the code above looks good to me. (I would assume we want to check the msr_info->host_initiated and guest_cpuid_has in svm_get_msr as well) Thanks, Reiji