Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4052006pxv; Tue, 13 Jul 2021 09:37:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyp3YJor71TCwFqtgImxA26MhQTRiBeuPV770onu/Oeq9BsCQGLQRHWBpe9xU6E3DuJQ/b/ X-Received: by 2002:a17:907:968a:: with SMTP id hd10mr6372942ejc.393.1626194268747; Tue, 13 Jul 2021 09:37:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626194268; cv=none; d=google.com; s=arc-20160816; b=qSl1rsg6EMxyKWSIt4o8pKZwoXTGKzTxaqrbxzzQN9xvGabUqwi3YUtDjQ5y32V4QD R4uecaGuv9ct6dV5AlqctL+aG69c7HVj2kv0PlUnMPKR0NzPOmZRbDPgM0IQ2P7UntPH RyLehU3UKpyjnxt1d0Kvv+hEwXh2nw5Zs1EiNd4zDN2n7tgFEYsaV51G/Jc1RaHLV04X Rbugqn5W7hzE6mH2NcSo/LDg23pL1xDnPM7qW742a7iZj+u2msfLUscD2arbYIvIkNS1 afbTP7PJ72cNeO7T7gryO9m3AlYNKtcmRgC0L9c8VuolikqHxxvb0Y2yzr2fkPd+q8mf 8mbg== 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=9wqr9l9rn3Fb1zwRgcq5bBwnS7s/+k7U1KQtXn6qui4=; b=rvXbKtVFrWMZV4fjtI/a5n/VgHlW3T8dJr0Zn72X/kvYLiXjNx/3bTVvayxEbEYBDU thfeSdrfuWPVRRc8kC1OMZl43/Kc6l8bKypjMyYYHsdeCMkoPvZQ+QKQy2pzUwSRtIbO MU6qOyNIyWUEagQErQ48bdQw/1+R/9/rrqPIhId150OSEhpoxjxufOzhq1HG1Ly+EGD8 1s5/7Gv2/5iMZ0FhdVWLBBb9HBrW8fvgxDOMc/JQmHySGg9mZyq1dzADqDE5WEVSCy9F OWzOb+QtF657REOnJKEitjyuun/6ln/tZDbJHWm+0ooymINFANoAuXZFlOLq3RW11+45 ZVyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=nHyxyZ6R; 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 la12si18630928ejc.560.2021.07.13.09.37.26; Tue, 13 Jul 2021 09:37:48 -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=nHyxyZ6R; 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 S235515AbhGMQig (ORCPT + 99 others); Tue, 13 Jul 2021 12:38:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235568AbhGMQiZ (ORCPT ); Tue, 13 Jul 2021 12:38:25 -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 0FBE6C05BD27 for ; Tue, 13 Jul 2021 09:34:44 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id g3-20020a256b030000b0290551bbd99700so27772689ybc.6 for ; Tue, 13 Jul 2021 09:34:44 -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=9wqr9l9rn3Fb1zwRgcq5bBwnS7s/+k7U1KQtXn6qui4=; b=nHyxyZ6RG/ToM4hIEqA3tiRylNSegnO7fPS5sd0Ve+8Qw880sTF7kgOUiU9kNgQ29G wUevBqSs4gBv5jWgJHhBNmyh4Jz3mWRMqMm1Ahsi5Qnxm1K3ktrIAr+dLUnZqf4Q9Bcl abrHmLYx+HE0RSb/IF5nhllPhH2vQWWxWgwQ6ySsajYq6COWqsenGs8KK4IcGKngjKWi 0NB8m1B4JxYNBieaOiskZvdxGIx37GjtMinJNliqxcaj8tpJv1qdAJHNvs1Eq3pjM5kc 9aVQTDvJDJkfPmG6LvljWeXAafy9URMevKsJCaSTkHSoEiuBEn6MwpPetpILrrLJ5KDF j41g== 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=9wqr9l9rn3Fb1zwRgcq5bBwnS7s/+k7U1KQtXn6qui4=; b=ewsGY/2Y7CssQpCwrJnTzVYiqunaSiRru7g6kBmuuX3CCX/uYlw9N9KbvZB8r3Oe/y VlO/HKiRlxpNoK2yLBC+52osHD2rmV8knoxbP8YcEfyON6zNopt68EIKl3VJKTOixkgX WxIIn6wxE/3lsSWu7ysSp/zICclad0tCeYIWs7bIHTQsHw4Gqz6/sK0YV4L9KHqmQS0O 9rmusCzrGBQ0c+kDMBm1n/du7wUoFQM5V0RAErKatciXk8MoSaZo58W+VYjP7cjFqgMW Gh6Q7H5wqUmmWFz32zWv8JBtK0FV9qcdX/TX1qBUya96OuZa1dQmmFgPPZFPb3bntOWU VxHw== X-Gm-Message-State: AOAM530H/l99KsZ2Tr0xRLnX1ozRAFOM4dimFBT0FgXCWP9ix7FTkaAr gf2KT/C0i2WWXzBOWI8+RV+MpthKjZc= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:825e:11a1:364b:8109]) (user=seanjc job=sendgmr) by 2002:a25:abcc:: with SMTP id v70mr6892084ybi.216.1626194083200; Tue, 13 Jul 2021 09:34:43 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 13 Jul 2021 09:33:14 -0700 In-Reply-To: <20210713163324.627647-1-seanjc@google.com> Message-Id: <20210713163324.627647-37-seanjc@google.com> Mime-Version: 1.0 References: <20210713163324.627647-1-seanjc@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v2 36/46] KVM: x86: Move setting of sregs during vCPU RESET/INIT to common x86 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, Reiji Watanabe Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move the setting of CR0, CR4, EFER, RFLAGS, and RIP from vendor code to common x86. VMX and SVM now have near-identical sequences, the only difference being that VMX updates the exception bitmap. Updating the bitmap on SVM is unnecessary, but benign. Unfortunately it can't be left behind in VMX due to the need to update exception intercepts after the control registers are set. Reviewed-by: Reiji Watanabe Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/svm.c | 6 ------ arch/x86/kvm/vmx/vmx.c | 9 --------- arch/x86/kvm/x86.c | 8 ++++++++ 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 251b230b2fef..ea4bea428078 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1262,12 +1262,6 @@ static void init_vmcb(struct kvm_vcpu *vcpu) init_sys_seg(&save->ldtr, SEG_TYPE_LDT); init_sys_seg(&save->tr, SEG_TYPE_BUSY_TSS16); - svm_set_cr0(vcpu, X86_CR0_NW | X86_CR0_CD | X86_CR0_ET); - svm_set_cr4(vcpu, 0); - svm_set_efer(vcpu, 0); - kvm_set_rflags(vcpu, X86_EFLAGS_FIXED); - vcpu->arch.regs[VCPU_REGS_RIP] = 0x0000fff0; - if (npt_enabled) { /* Setup VMCB for Nested Paging */ control->nested_ctl |= SVM_NESTED_CTL_NP_ENABLE; diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 555235d6c17e..ef92ec40d3d9 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -4454,9 +4454,6 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) vmcs_write64(GUEST_IA32_DEBUGCTL, 0); } - kvm_set_rflags(vcpu, X86_EFLAGS_FIXED); - kvm_rip_write(vcpu, 0xfff0); - vmcs_writel(GUEST_GDTR_BASE, 0); vmcs_write32(GUEST_GDTR_LIMIT, 0xffff); @@ -4484,12 +4481,6 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) kvm_make_request(KVM_REQ_APIC_PAGE_RELOAD, vcpu); - vmx_set_cr0(vcpu, X86_CR0_NW | X86_CR0_CD | X86_CR0_ET); - vmx_set_cr4(vcpu, 0); - vmx_set_efer(vcpu, 0); - - vmx_update_exception_bitmap(vcpu); - vpid_sync_context(vmx->vpid); if (init_event) vmx_clear_hlt(vcpu); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 6a11ec5d38ac..3aa952edd5f4 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10870,6 +10870,14 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) static_call(kvm_x86_vcpu_reset)(vcpu, init_event); + kvm_set_rflags(vcpu, X86_EFLAGS_FIXED); + kvm_rip_write(vcpu, 0xfff0); + + static_call(kvm_x86_set_cr0)(vcpu, X86_CR0_NW | X86_CR0_CD | X86_CR0_ET); + static_call(kvm_x86_set_cr4)(vcpu, 0); + static_call(kvm_x86_set_efer)(vcpu, 0); + static_call(kvm_x86_update_exception_bitmap)(vcpu); + /* * Reset the MMU context if paging was enabled prior to INIT (which is * implied if CR0.PG=1 as CR0 will be '0' prior to RESET). Unlike the -- 2.32.0.93.g670b81a890-goog