Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1795248pxy; Fri, 23 Apr 2021 17:54:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9FOV7U0ieb+KtcWj+2DH9ErmCMnRVR1Z001xcjr9hwsGcq8GqQQ13L3RgMOGkhAs5ByCP X-Received: by 2002:a50:fe81:: with SMTP id d1mr7719817edt.308.1619225681900; Fri, 23 Apr 2021 17:54:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619225681; cv=none; d=google.com; s=arc-20160816; b=mcL650AjbJV58PfcAIZsILCyUe1EFQDIBJhXCYCSEAO4kfUIkTEPltNirNJEd/zIZh UqFkeOqcAAEveh6Kq5YAmJysR/DaBMwBuLN9gVJWUpPE1/0BWsLUZIk126NNc9h1cx4a SimoASOQeXqSgF7C5Nbk3C5HZKpkQvuH1sN2Xk1zYsRTcOKPo7SRD28BD4xOfCoO48sm k9V9dakDBVw833JfFyZZrCuidJG/6Cysr51oByyS8NBs8PBCIwLFdD3cU1nfg0/sF2ZO lHISQngu7hEKjwMp/iJm7Oq5hJa0SNSt/1ucHM+Uhf7g3RyMIBTOGr/CqVLZUnEas769 Ilsg== 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:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=ybux/4YslnMEYEZsvkcGPcqviW6S9OYK5jonptQyC4I=; b=kksxhlMakekRmNnqGyPISR/LQ9/+akULw6P/AKaNbyeK8neexasvPUW3cdH6xSbWhJ h0m/yoalIQcQgJQJHRQxNl1r4Rt2gfeSCGyG4JgQccnr7BIBmWNYqGZOES+4KL0ItwGF gvQg37ikW751ST0OOxLdkEli4qi46/O8wDhVLH/prV6A2t+TH5fycw5sIuSbyZpVQ9vd DjeUjSqy57uHYw4EsXIEjLZ3YnLI1BxBLoPYGqpJ3mFFVVIkoKI/yyPxo5BtyRy5m+FQ uGX8MWg7/2j2hAvfkh+4Bh6ajVendZYf84dHh5WybRw/HBNCvQCYZGF2sdxxHHQKTDaC T7hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=n131qTWJ; 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 l1si6447094edq.496.2021.04.23.17.54.19; Fri, 23 Apr 2021 17:54:41 -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=n131qTWJ; 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 S244340AbhDXAvp (ORCPT + 99 others); Fri, 23 Apr 2021 20:51:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244476AbhDXAts (ORCPT ); Fri, 23 Apr 2021 20:49:48 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DF3FC061364 for ; Fri, 23 Apr 2021 17:47:42 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id s2-20020a5b07420000b02904eb842efc40so26198052ybq.3 for ; Fri, 23 Apr 2021 17:47:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=ybux/4YslnMEYEZsvkcGPcqviW6S9OYK5jonptQyC4I=; b=n131qTWJCuWa04F4oe/3zu7xSR7HCmvR/RjU/3fY9RqKUdbO5EOJoN1M9/J4pd8A6J 1E1lRubsGs7E2kBG1YxPkF4VPlN1Jn7mZd1l3+UUvHisjWJB+6SmEHaumw3zglONg9vX 0NAgrjMgC5gAYnf89al/eiJPhFA/YwcYdoOe9Fd1TeBFkivvrtYlj3JC5WqB9C1kdObb OJZB4Yc2GB22sYAlYhzmfBz1r94xKrkPOgxFoON73t6nw9+6Yp+YtB20u768tvdkz310 Pi7Wun0oZc0rel4564fvhXVkolzMGmGXIldyNEeX0NWOr450PnCTWY97ha2lJ4xyfQTK f/4w== 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:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=ybux/4YslnMEYEZsvkcGPcqviW6S9OYK5jonptQyC4I=; b=WMr6lOzI8FyAxvivQ0L10tjEw0lj+h0nTkpU0U/hFe54XQriYWHoSYnh0LMHWhb2Z9 ICPV7RA8MCV39JRQzXCXAflDM94TIS1JEsqyaWvThSwZ2J3Zy4Kw/e8FMRCrJ0D3j1UK KdumoqdgWm922bDXd8tTY0yMXuAl6WjDBF9cpUVZtDXEjHWTT9RwM3uCHoR4dfTXW+X7 BToSfCvRBuPyYX5imCdi8IrDyk4k1FHgwRvS+TypkF3cNUdS7K1emBdHIGKZZaKRZZnf 9Xr0M1gcZFyvmDlNdJWmxkVI/599jVBbcqX6JlNA8ZIihN/MbF0WtmkYz3rV+EgPbCa8 x6cw== X-Gm-Message-State: AOAM532UGba7zZMHXiX2hRTftOlAfbD99bXVGGD/bkHgsleIjrxWWkdV XLIf6zH3MvYkIIPHrqrl+ZP0s2ANlbI= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:ad52:3246:e190:f070]) (user=seanjc job=sendgmr) by 2002:a25:8143:: with SMTP id j3mr9160217ybm.237.1619225261741; Fri, 23 Apr 2021 17:47:41 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 23 Apr 2021 17:46:21 -0700 In-Reply-To: <20210424004645.3950558-1-seanjc@google.com> Message-Id: <20210424004645.3950558-20-seanjc@google.com> Mime-Version: 1.0 References: <20210424004645.3950558-1-seanjc@google.com> X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog Subject: [PATCH 19/43] KVM: x86: Move EDX initialization at vCPU RESET to common code 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move the EDX initialization at vCPU RESET, which is now identical between VMX and SVM, into common code. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 5 ----- arch/x86/kvm/svm/svm.c | 13 ------------- arch/x86/kvm/vmx/vmx.c | 6 ------ arch/x86/kvm/x86.c | 13 +++++++++++++ 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 3e5fc80a35c8..2b9799366dad 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1701,11 +1701,6 @@ static inline unsigned long read_msr(unsigned long msr) } #endif -static inline u32 get_rdx_init_val(void) -{ - return 0x600; /* P6 family */ -} - static inline void kvm_inject_gp(struct kvm_vcpu *vcpu, u32 error_code) { kvm_queue_exception_e(vcpu, GP_VECTOR, error_code); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 271b6def087f..5c12ba725186 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1283,25 +1283,12 @@ static void init_vmcb(struct kvm_vcpu *vcpu) static void svm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) { struct vcpu_svm *svm = to_svm(vcpu); - u32 dummy; - u32 eax = 1; svm->spec_ctrl = 0; svm->virt_spec_ctrl = 0; init_vmcb(vcpu); - /* - * Fall back to KVM's default Family/Model/Stepping if no CPUID match - * is found. Note, it's impossible to get a match at RESET since KVM - * emulates RESET before exposing the vCPU to userspace, i.e. it's - * impossible for kvm_cpuid() to find a valid entry on RESET. But, go - * through the motions in case that's ever remedied, and to be pedantic. - */ - if (!kvm_cpuid(vcpu, &eax, &dummy, &dummy, &dummy, true)) - eax = get_rdx_init_val(); - kvm_rdx_write(vcpu, eax); - if (kvm_vcpu_apicv_active(vcpu) && !init_event) avic_update_vapic_bar(svm, APIC_DEFAULT_PHYS_BASE); } diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 40a4ac23d54f..805888541142 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -4490,7 +4490,6 @@ static void init_vmcs(struct vcpu_vmx *vmx) static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) { struct vcpu_vmx *vmx = to_vmx(vcpu); - u32 eax, dummy; u64 cr0; if (!init_event) @@ -4501,11 +4500,6 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) vmx->msr_ia32_umwait_control = 0; - eax = 1; - if (!kvm_cpuid(vcpu, &eax, &dummy, &dummy, &dummy, true)) - eax = get_rdx_init_val(); - kvm_rdx_write(vcpu, eax); - vmx->hv_deadline_tsc = -1; kvm_set_cr8(vcpu, 0); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index b87193190a73..167c650d1187 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10416,6 +10416,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) { unsigned long old_cr0 = kvm_read_cr0(vcpu); unsigned long old_cr4 = kvm_read_cr4(vcpu); + u32 eax, dummy; kvm_lapic_reset(vcpu, init_event); @@ -10482,6 +10483,18 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) vcpu->arch.regs_avail = ~0; vcpu->arch.regs_dirty = ~0; + /* + * Fall back to KVM's default Family/Model/Stepping of 0x600 (P6/Athlon) + * if no CPUID match is found. Note, it's impossible to get a match at + * RESET since KVM emulates RESET before exposing the vCPU to userspace, + * i.e. it'simpossible for kvm_cpuid() to find a valid entry on RESET. + * But, go through the motions in case that's ever remedied. + */ + eax = 1; + if (!kvm_cpuid(vcpu, &eax, &dummy, &dummy, &dummy, true)) + eax = 0x600; + kvm_rdx_write(vcpu, eax); + vcpu->arch.ia32_xss = 0; static_call(kvm_x86_vcpu_reset)(vcpu, init_event); -- 2.31.1.498.g6c1eba8ee3d-goog