From patchwork Thu Nov 17 14:32:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 21691 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp433790wrr; Thu, 17 Nov 2022 06:36:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf7wJEkUy0vFpQcuqai6xWrMwnc4ilYvMmY3hi0lb2R6NYxeSURautVp6kWmV06jPhSqrdCK X-Received: by 2002:a17:902:9b89:b0:186:b46d:da5e with SMTP id y9-20020a1709029b8900b00186b46dda5emr3048038plp.92.1668695780734; Thu, 17 Nov 2022 06:36:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668695780; cv=none; d=google.com; s=arc-20160816; b=xq3qIxUqcm3/gCESmS3bG3C0Wl1UwRD0TtydhzKBgFi6RbpdhhmG5YBcebX+s3/kGy uJkkViug+SUFcs6iuxRxyGlzXmh5B8JD+wfAifXPbhe6rV5Ze08M7maSqZ9/Lrszj2ng V7yM9PaIVfnotIPY3XuZLSP9uqo03zNaM1CgAmQT3EKknjCa7HFt3/PPmU2ABaspqM05 V9EIA48FkJbTotwTH04esAnqwr8y0RSa6bqLRn05eVKlUdSf9H+m0YQOxP9EOpewqjLD h52mVo8X7Zob2yp1LhVu+80siSHaKErNffz/J+zMUUOt3ZNJKROmQRMBcVPsqx8Ty17e reIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lTfKFD0cFY/1sVq1cxqtG2BQAiBGe959F/rhRBmBw68=; b=d0dze1jR7K494W3Rn6ZyxbXbAMuAc+S9S12ADkHigoLQEBg6iphz+31/W6wCf54lkX D4kbiYj+5a2FFWXr1u/2K88kJGheNIHpHf1Gc2MBaLX+yy9wm/9VdW29+rZglFpU8dVq u6suKQPWWzT8FU/68H7QxVuRPpUjJuRkCZfkWf91vjWrUhS0ExlWGXU9jSKGFm+fzk63 30tiNe3eoMv9OhvuyP4X+KoTHFGLET64c3DJaiXndGbSs/coNy3AMNTEfJpW+HoAqYwR Cgwc/WZcvQtU4C7FV1+qiZ0cqCEnnuXE3kkg4X02HZ3IeKAZVWNZ84b3xTPIMOTK1aV9 8vnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JykR1XYl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p18-20020a170902e75200b00188e9ec511bsi1209269plf.113.2022.11.17.06.36.07; Thu, 17 Nov 2022 06:36:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JykR1XYl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240520AbiKQOfl (ORCPT + 99 others); Thu, 17 Nov 2022 09:35:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240426AbiKQOea (ORCPT ); Thu, 17 Nov 2022 09:34:30 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B15791144B for ; Thu, 17 Nov 2022 06:33:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668695607; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lTfKFD0cFY/1sVq1cxqtG2BQAiBGe959F/rhRBmBw68=; b=JykR1XYlSvuXzNBceI6HVo7HiJXJKlkOCyBHaqVFap4ZtO/ChDcsqUWro4YlL4Ril1sdTV uMshvV1hUJ88+ozrZuGk805o9Ox9Y0SksDeFKGurucDfqLtR/cImEQs4MYGoPRBPtcZDYJ HwFRdardFmlDfi5CiluQn8fUyx8VsNk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-127-3XWKG39ROWm9iWhpwhjDNw-1; Thu, 17 Nov 2022 09:33:24 -0500 X-MC-Unique: 3XWKG39ROWm9iWhpwhjDNw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C51CD887402; Thu, 17 Nov 2022 14:32:54 +0000 (UTC) Received: from amdlaptop.tlv.redhat.com (dhcp-4-238.tlv.redhat.com [10.35.4.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F09B2166B29; Thu, 17 Nov 2022 14:32:51 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Paolo Bonzini , Ingo Molnar , "H. Peter Anvin" , Dave Hansen , linux-kernel@vger.kernel.org, Peter Zijlstra , Thomas Gleixner , Sandipan Das , Daniel Sneddon , Jing Liu , Josh Poimboeuf , Wyes Karny , Borislav Petkov , Babu Moger , Pawan Gupta , Sean Christopherson , Jim Mattson , x86@kernel.org, Maxim Levitsky Subject: [PATCH 02/13] KVM: nSVM: don't call nested_sync_control_from_vmcb02 on each VM exit Date: Thu, 17 Nov 2022 16:32:31 +0200 Message-Id: <20221117143242.102721-3-mlevitsk@redhat.com> In-Reply-To: <20221117143242.102721-1-mlevitsk@redhat.com> References: <20221117143242.102721-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749754347041022995?= X-GMAIL-MSGID: =?utf-8?q?1749754347041022995?= Calling nested_sync_control_from_vmcb02 on each VM exit (nested or not), was an attempt to keep the int_ctl field in the vmcb12 cache up to date on each VM exit. However all other fields in the vmcb12 cache are not kept up to date, therefore for consistency it is better to do this on a nested VM exit only. No functional change intended. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 17 ++++++++--------- arch/x86/kvm/svm/svm.c | 2 -- arch/x86/kvm/svm/svm.h | 1 - 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 43cc4a5d22e012..91a51e75717dca 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -407,11 +407,12 @@ void nested_copy_vmcb_save_to_cache(struct vcpu_svm *svm, * Synchronize fields that are written by the processor, so that * they can be copied back into the vmcb12. */ -void nested_sync_control_from_vmcb02(struct vcpu_svm *svm) +static void nested_sync_control_from_vmcb02(struct vcpu_svm *svm, + struct vmcb *vmcb12) { u32 mask; - svm->nested.ctl.event_inj = svm->vmcb->control.event_inj; - svm->nested.ctl.event_inj_err = svm->vmcb->control.event_inj_err; + vmcb12->control.event_inj = svm->vmcb->control.event_inj; + vmcb12->control.event_inj_err = svm->vmcb->control.event_inj_err; /* Only a few fields of int_ctl are written by the processor. */ mask = V_IRQ_MASK | V_TPR_MASK; @@ -431,8 +432,8 @@ void nested_sync_control_from_vmcb02(struct vcpu_svm *svm) if (nested_vgif_enabled(svm)) mask |= V_GIF_MASK; - svm->nested.ctl.int_ctl &= ~mask; - svm->nested.ctl.int_ctl |= svm->vmcb->control.int_ctl & mask; + vmcb12->control.int_ctl &= ~mask; + vmcb12->control.int_ctl |= svm->vmcb->control.int_ctl & mask; } /* @@ -985,13 +986,11 @@ int nested_svm_vmexit(struct vcpu_svm *svm) if (vmcb12->control.exit_code != SVM_EXIT_ERR) nested_save_pending_event_to_vmcb12(svm, vmcb12); + nested_sync_control_from_vmcb02(svm, vmcb12); + if (svm->nrips_enabled) vmcb12->control.next_rip = vmcb02->control.next_rip; - vmcb12->control.int_ctl = svm->nested.ctl.int_ctl; - vmcb12->control.event_inj = svm->nested.ctl.event_inj; - vmcb12->control.event_inj_err = svm->nested.ctl.event_inj_err; - if (!kvm_pause_in_guest(vcpu->kvm)) { vmcb01->control.pause_filter_count = vmcb02->control.pause_filter_count; vmcb_mark_dirty(vmcb01, VMCB_INTERCEPTS); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 527f18d8cc4489..03acbe8ff34edb 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4016,8 +4016,6 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu) svm->next_rip = 0; if (is_guest_mode(vcpu)) { - nested_sync_control_from_vmcb02(svm); - /* Track VMRUNs that have made past consistency checking */ if (svm->nested.nested_run_pending && svm->vmcb->control.exit_code != SVM_EXIT_ERR) diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 199a2ecef1cec6..f5383104d00580 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -618,7 +618,6 @@ void nested_copy_vmcb_control_to_cache(struct vcpu_svm *svm, struct vmcb_control_area *control); void nested_copy_vmcb_save_to_cache(struct vcpu_svm *svm, struct vmcb_save_area *save); -void nested_sync_control_from_vmcb02(struct vcpu_svm *svm); void nested_vmcb02_compute_g_pat(struct vcpu_svm *svm); void svm_switch_vmcb(struct vcpu_svm *svm, struct kvm_vmcb_info *target_vmcb);