Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp3807506pxy; Tue, 4 May 2021 10:19:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSN9Y6cJdI9Wfx3Fn2RcFHZUuE6tDy5pPYEQ2LIdyVbh1O44kywJorMyumeduCdvw1rKNc X-Received: by 2002:a17:902:d2c3:b029:ed:764e:d1f4 with SMTP id n3-20020a170902d2c3b02900ed764ed1f4mr27033021plc.84.1620148755898; Tue, 04 May 2021 10:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620148755; cv=none; d=google.com; s=arc-20160816; b=At7vImmo0httGZoS0B3sSgeRznChFfjrM5lMX2rgNtFijwRBKRPu4dr8ThyRgPzcmf Jz6vafGKuKNn+OjilqG0PWEbMH8ZvEUB7abpIuZaICXxW8IOmT+kgS48uDvSOdjgAzBP UFCnk5FEeUulB6u0I+ohCcA7GeIFPjQOZVO20AwTLefoDXLwqFFdXNpPjp7MWjupHuYJ c49+2jaEzatzz2z0Bb0UwAozNeEs0ZoDY69VeZi9/FCV1xqq5WVo1tZuLTf5OwOV2TQC 8VJHyOFcyi8mF8z6Xinb2lt2mB04eKs5bdxCHSM4cp76fmdTSyvtsT8RrEwpnRm5vL9B oZtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :reply-to:dkim-signature; bh=2xWZdvogf0ze6g50j9Z7ywuPrceLwwW3g11yg2g3TOs=; b=02C2zR3noncHC283z4Vw4wvtoJvRZgsB1lYRbyaKgnIcXuVtUKaqTFGGmeQ6vPanp6 qTK+23Ol5nuhFmg9IquRpkTTLdywYzn+oYPtrM6w1mib7QOFRJwkEuM9aQuDYNU+SvBH c6VnbvoA9yMjsgi5jDQxa7d57ysfzKbIlU8mLPSGYMGvi47ag4p1To21GxP3BqE5VtUE rAWfJv3KV8ufeqX9dL2aVdjiDo0TQICHJ5ygzJVlHwsYknnKFjvrpzswXvYRFOkmSOCM PpW8/S7i1SqulxAbd8vzulBvzPX5nYDT3ugKAMVXhdvfQn5+Uvex0U0e85/Gz3+ggrXP Urxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SmbCPjuS; 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 lr3si17301379pjb.110.2021.05.04.10.19.02; Tue, 04 May 2021 10:19:15 -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=SmbCPjuS; 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 S232034AbhEDRSi (ORCPT + 99 others); Tue, 4 May 2021 13:18:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231683AbhEDRSi (ORCPT ); Tue, 4 May 2021 13:18:38 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76BE5C061574 for ; Tue, 4 May 2021 10:17:43 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id g184-20020a3784c10000b02902e385de9adaso8027329qkd.3 for ; Tue, 04 May 2021 10:17:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:message-id:mime-version:subject:from:to:cc; bh=2xWZdvogf0ze6g50j9Z7ywuPrceLwwW3g11yg2g3TOs=; b=SmbCPjuSQLSJNYSCAdiifnXtT/H2AqQdTpZINcEF/GfIcUtCzvYZjSYKvxQr4162hD kj9ZAGJTnxgB3dSb0COCqb10XIlyOqpmfOj5LZcjJB8vHUp+siIFwCfaViiQ5IV3++xp xrVcVf8esLJnkhfNGkLSdivxNqkxVFWaXP5fbP63rQ+8AW3I0lNo2g/f5ypcM/ij+pYI 5Z/iIv0+hgMICMEkPSt1Pkrk62Ji5SooQ33z8NC9lcbU8EiW7tRJ8M6BFvJXEpvdifJT RKhi+zeuiI2+Wj1RfEzML/Eolp6rKf+/Sg+yu5osyK9toW9SL4x055MzPOj0z2sr19uc 6lqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:date:message-id:mime-version:subject :from:to:cc; bh=2xWZdvogf0ze6g50j9Z7ywuPrceLwwW3g11yg2g3TOs=; b=pHipjtfQjkuK3sGGUnth+CKmiplUPhT1blxFXW6ycau50KcP8dV6At9tImNkGnJ4Zi tUoi7jJKGQZKDYIgL5ZNkDh5HMH5jnEuOvL7gz4WhVD/MEU9OqTbHOKo0Pw9afWyP354 V4zEP/UURPt9Zo/e2Bc9yIUMlnHrYytFKWMxh5UWKCdVx0oZrkkJS2Mrr4DBoSGQlVMw 9IwKJAyk/x4LBZ0V1jKa1x4UkQ5XpT/0BrUB0YOp5gIS2S2jI08wYntcFJSylFxkyI2m HZEZFFEKQMOiByBzQIsDp5ffQJz1D+5GqgA2wYhn9MFaJaR/UAAQio6ITM5OHfIIzluH ffHA== X-Gm-Message-State: AOAM533dIg9DMWPHWWaOKsE5F210woR26AwtDQO5i9LILmJ3Y0squvWB vWgfz0VJ23v7VtlhW7nkWIEQX/pC+4Y= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:df57:48cb:ea33:a156]) (user=seanjc job=sendgmr) by 2002:a0c:c488:: with SMTP id u8mr26264785qvi.47.1620148662633; Tue, 04 May 2021 10:17:42 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 4 May 2021 10:17:19 -0700 Message-Id: <20210504171734.1434054-1-seanjc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.31.1.527.g47e6f16901-goog Subject: [PATCH 00/15] KVM: x86: RDPID/RDTSCP fixes and uret MSR cleanups From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Xiaoyao Li , Reiji Watanabe Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a continuation of a less ambitious effort to unify MSR_TSC_AUX handling across SVM and VMX. Reiji pointed out that MSR_TSC_AUX exists if RDTSCP *or* RDPID is supported, and things went downhill from there. The first half of this series fixes a variety of RDTSCP and RDPID related bugs. The second half of the series cleans up VMX's user return MSR framework and consolidates more of the uret logic into common x86. The last two patches leverage the uret MSR cleanups to move MSR_TSC_AUX handling to common x86 and add sanity checks to guard against misreporting of RDPID and/or RDTSCP support. This will conflict with my vCPU RESET/INIT cleanup series. Feel free to punt the conflicts to me. Other "fun" things to tackle: - The kernel proper also botches RDPID vs. RDTSCP, as MSR_TSC_AUX is configured if RDTSCP is supported, but is consumed if RDPID is supported. I'll send this fix separately. - Commit 844d69c26d83 ("KVM: SVM: Delay restoration of host MSR_TSC_AUX until return to userspace") unwittingly fixed a bug where KVM would write MSR_TSC_AUX with the guest's value when svm->guest_state_loaded is false, which could lead to running the host with the guest's value. The bug only exists in 5.12 (maybe 5.11 too?), so crafting a fix for stable won't be too awful. Sean Christopherson (15): KVM: VMX: Do not adverise RDPID if ENABLE_RDTSCP control is unsupported KVM: x86: Emulate RDPID only if RDTSCP is supported KVM: SVM: Inject #UD on RDTSCP when it should be disabled in the guest KVM: x86: Move RDPID emulation intercept to its own enum KVM: VMX: Disable preemption when probing user return MSRs KVM: SVM: Probe and load MSR_TSC_AUX regardless of RDTSCP support in host KVM: x86: Add support for RDPID without RDTSCP KVM: VMX: Configure list of user return MSRs at module init KVM: VMX: Use flag to indicate "active" uret MSRs instead of sorting list KVM: VMX: Use common x86's uret MSR list as the one true list KVM: VMX: Disable loading of TSX_CTRL MSR the more conventional way KVM: x86: Export the number of uret MSRs to vendor modules KVM: x86: Move uret MSR slot management to common x86 KVM: x86: Tie Intel and AMD behavior for MSR_TSC_AUX to guest CPU model KVM: x86: Hide RDTSCP and RDPID if MSR_TSC_AUX probing failed arch/x86/include/asm/kvm_host.h | 9 +- arch/x86/kvm/cpuid.c | 18 ++- arch/x86/kvm/emulate.c | 2 +- arch/x86/kvm/kvm_emulate.h | 1 + arch/x86/kvm/svm/svm.c | 50 +++----- arch/x86/kvm/vmx/vmx.c | 217 ++++++++++++++++---------------- arch/x86/kvm/vmx/vmx.h | 12 +- arch/x86/kvm/x86.c | 101 ++++++++++++--- 8 files changed, 245 insertions(+), 165 deletions(-) -- 2.31.1.527.g47e6f16901-goog