Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1794308pxy; Fri, 23 Apr 2021 17:52:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynvzLAR/DpetKow1KYEIjwygCyKXJCHOH8issq9rl215RVxtpAG77AFdU9/frZGmyj5po4 X-Received: by 2002:a05:6402:37a:: with SMTP id s26mr7601055edw.159.1619225558831; Fri, 23 Apr 2021 17:52:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619225558; cv=none; d=google.com; s=arc-20160816; b=wIt6vD2JyhcmtFwxPI7YcVj6fdoUoEUYaZfshWnreUpT+xMv+fl7BSXOFz8a8SsHSz jmIXx2XDykwJCEcKxQLY4VOFoeDUwOmwTJZFy/82vHdJD8zn5++x1Y8bEg05B5dr8Y7n Bx6qYv33MxGVLQ0+gbLGLFkgaTVi5Bdm4NmNnQB1uNNzpo/nSou4zuB3NeHypyY7Hy3D L5sEv6n57qLGbpdo90pAAVuGrltpt0qIrdE7Ag0sUA4jMJpc6kuD8chMjMa5fO7ynjom z6N+A+APDT3si4G5TtQwdDGorog63Sq7SUTgLwc+aY9s/jtjJsMkySeORcmtKlz8Mb6G dKbQ== 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=NZdv+AGbcKGuCnoG8O16om5C2kLzm+MyJDxYqgfhwLA=; b=Of/oGDtvEdx8b27+TiyocfF2UOjCvgUkfhEa+39k1z3vfE1GPmhkeXYVgCw+BK6ObR zTNA3pXU12RUQ6bFGwUktt2d27m3KCTMdkY0QonRVMsyroz+lmOb13yT0OxGAX1eg2CY EbuWkYamGH4EUrMhhg1xP4WpmWVdhLj33UcopZaOpS/SfHh10xbTBPg7mMWMek3CK+tI 0p8sa1fda48B2nAbC/T5s6HFHgiRzY72zJ+Gsmxd4t64Mk8sCm0ngO7cO972pkcGeSUH eEg4vZoCsDY86sAdUPJyTUANVAvU8iK1eMJMqiM0RgVjYQZ6PWrqhPFfV250MCkbR+yR 2YIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mf8daJbN; 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 dd21si6256705edb.45.2021.04.23.17.52.15; Fri, 23 Apr 2021 17:52:38 -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=mf8daJbN; 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 S244169AbhDXAvh (ORCPT + 99 others); Fri, 23 Apr 2021 20:51:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244262AbhDXAtj (ORCPT ); Fri, 23 Apr 2021 20:49:39 -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 58BBCC06174A for ; Fri, 23 Apr 2021 17:47:40 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id v63-20020a252f420000b02904ecfc17c803so15027762ybv.18 for ; Fri, 23 Apr 2021 17:47:40 -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=NZdv+AGbcKGuCnoG8O16om5C2kLzm+MyJDxYqgfhwLA=; b=mf8daJbNL2+OfvIgSL+41PtaksanbJRRqTdAYgYF/QdSjD42oJvxk44BDMRtD1W37p HcrJChZUXCNY4kJ94XHe+ZcoL4C/IRyDvUpZCcOhRJkdzQWEhfKRcmYJHDLtzc9AH1DM mr+SDmg4+cRDOFfsJq01xVEVATH1UMRq5WgW3de58q+dQwdP5A5+oPZNiDtUoPY0vQ6W CxeqLA6hODY9xdGQJJmOvQw/I4mT2oY97Sy8oPky6wTmUvsDayPmW6Hf/2jPSv3r9FcX oQMEMVYg+3givAO8GRo8clPvE0RstBCsB4TEMg2P7o/pw3XdI4LujyiHdF3w0IQU4RyY WhlQ== 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=NZdv+AGbcKGuCnoG8O16om5C2kLzm+MyJDxYqgfhwLA=; b=gwYobSDT+kMUcKs0r1n9n30a8J6NEJJ5oXHrj6AMUHoRuymjbvvVyj6y2PjtQTTFDS 54LG6gW/uNVOorlgYnWD5H6b+HJzqcuwN6WvfR6ji0bmopTHuHcYaz+zQ6dom8b139Zs AWrm5UMWfTmSNX1BCFpGW9HYqRf6crT3qFEMn6UDhyZw2Q/5Wy1aByo5Hn2c+Y82SaHE CWW55XqFsD2HWNDGTAOFhofOccidpaMPi5qIiqtlM9Be3MSjGT/51dSGHAIeAvDJB6DZ /qg0ssmo3S4BpYicDcHA6i6qbRyHMG9gUJyrzXx7vclV1htHzJ26qlcKTEyhV8tfs+hq DfeA== X-Gm-Message-State: AOAM5310D/Mt2PE1mVzCT1BrUE7FGBpNMn+rpU4igbe7dGWMbUbFajkx bUg1Pkv+zoQbg8qAaoQYB/+EU14oyxg= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:ad52:3246:e190:f070]) (user=seanjc job=sendgmr) by 2002:a25:9ac7:: with SMTP id t7mr9678756ybo.58.1619225259641; Fri, 23 Apr 2021 17:47:39 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 23 Apr 2021 17:46:20 -0700 In-Reply-To: <20210424004645.3950558-1-seanjc@google.com> Message-Id: <20210424004645.3950558-19-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 18/43] KVM: x86: Consolidate APIC base RESET initialization 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 Consolidate the APIC base RESET logic, which is currently spread out across both x86 and vendor code. For an in-kernel APIC, the vendor code is redundant. But for a userspace APIC, KVM relies on the vendor code to initialize vcpu->arch.apic_base. Hoist the vcpu->arch.apic_base initialization above the !apic check so that it applies to both flavors of APIC emulation, and delete the vendor code. Signed-off-by: Sean Christopherson --- arch/x86/kvm/lapic.c | 14 ++++++++------ arch/x86/kvm/svm/svm.c | 6 ------ arch/x86/kvm/vmx/vmx.c | 7 ------- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index b1366df46d1d..07cfa4d181da 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2307,18 +2307,20 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event) struct kvm_lapic *apic = vcpu->arch.apic; int i; - if (!apic) - return; - - /* Stop the timer in case it's a reset to an active apic */ - hrtimer_cancel(&apic->lapic_timer.timer); - if (!init_event) { vcpu->arch.apic_base = APIC_DEFAULT_PHYS_BASE | MSR_IA32_APICBASE_ENABLE; if (kvm_vcpu_is_reset_bsp(vcpu)) vcpu->arch.apic_base |= MSR_IA32_APICBASE_BSP; + } + if (!apic) + return; + + /* Stop the timer in case it's a reset to an active apic */ + hrtimer_cancel(&apic->lapic_timer.timer); + + if (!init_event) { apic->base_address = MSR_IA32_APICBASE_ENABLE; kvm_apic_set_xapic_id(apic, vcpu->vcpu_id); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 6c73ea3d20c6..271b6def087f 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1289,12 +1289,6 @@ static void svm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) svm->spec_ctrl = 0; svm->virt_spec_ctrl = 0; - if (!init_event) { - vcpu->arch.apic_base = APIC_DEFAULT_PHYS_BASE | - MSR_IA32_APICBASE_ENABLE; - if (kvm_vcpu_is_reset_bsp(vcpu)) - vcpu->arch.apic_base |= MSR_IA32_APICBASE_BSP; - } init_vmcb(vcpu); /* diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index fa14e9a74b96..40a4ac23d54f 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -4509,13 +4509,6 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) vmx->hv_deadline_tsc = -1; kvm_set_cr8(vcpu, 0); - if (!init_event) { - vcpu->arch.apic_base = APIC_DEFAULT_PHYS_BASE | - MSR_IA32_APICBASE_ENABLE; - if (kvm_vcpu_is_reset_bsp(vcpu)) - vcpu->arch.apic_base |= MSR_IA32_APICBASE_BSP; - } - vmx_segment_cache_clear(vmx); seg_setup(VCPU_SREG_CS); -- 2.31.1.498.g6c1eba8ee3d-goog