From patchwork Tue Apr 6 17:18:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12185593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F9D2C433B4 for ; Tue, 6 Apr 2021 17:18:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6FFF3610E8 for ; Tue, 6 Apr 2021 17:18:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346842AbhDFRSc (ORCPT ); Tue, 6 Apr 2021 13:18:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244425AbhDFRSZ (ORCPT ); Tue, 6 Apr 2021 13:18: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 1E329C06174A for ; Tue, 6 Apr 2021 10:18:17 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id l132so8049519ybl.23 for ; Tue, 06 Apr 2021 10:18:17 -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=oivDkQlUDQSvSEYmPed6OfkcBD+Dvdh/iwh7GoMJjX4=; b=ggRtauV+tbl//nJw9paxByj4LnhMRWjJS7yrReiQAs3GvtMi2oMAS3yC1IFT/CoHGe RbHKiJ1H2D6MEi7QYMNkil9+Aerk0FiECYeaBlD1QcAbi4iwn9qABTyT+fbass/ZEKZK 3O42kT5OWCcSyNhlMLf8w3yu9VoxhzkZCASbdbh7Oux8hBaJRF3a1sV/BRnoro+fNLqL i4VaQRGWV/vRQ9Upp4+ARASsJyVGOZ+KYidRi4jgR08qmw6WiN5ol62J7MEE08WTqx5i tlJuZeYrMa/TcwXLNfLfk3XjGLKtoWUnYWpdeNyjNrxXxGTs90da8KmBkWR/SRjHyngM YnGA== 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=oivDkQlUDQSvSEYmPed6OfkcBD+Dvdh/iwh7GoMJjX4=; b=jskhY+gu7xns92h6jMmZYcuCojmEUkbed+XOGh+Vw+z7OvNtntMdGyt4EJdsoMiJJc hHFuOeojbTuxNDM6AmztaqgcW5b56Bi2VEHGnL8SpAN9TiBfODKfX2UdWuesB6yLKzAp 7Y1pIksUWHgv3+K7PuTniyHYTl/G5zl11sFOpTTAdcE/LaMHFPJaVX8JNPO/I4Ol1gEc Tux353NurD5F4yYSHZPt9gYXm+miH2aBo32VayK32ph6Qd9jng2DCNNGmotRkwHtPdzh PU02BjNIxK2z22OLGhMCYdrZ4dZ/xvn3TNhCOlnc5kvorFCQyQ8GvJHCekgF0rjdSuHU jjVQ== X-Gm-Message-State: AOAM530uaIy3DLPymnTsJtr/GqmVYYJk8iPjeHyURI+cGh9Q9ruB5eVN cTiAJGbLnWH+CQ+FDkeBgpuH539rbaE= X-Google-Smtp-Source: ABdhPJy4XKdA8GBJ3EDloaxSOG3D2OJARqprhnA3IlBhScNJSqLb4bKe9aTcFxXnCIMiMduIFXARkNbXC8Q= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:24a1:90fb:182b:777c]) (user=seanjc job=sendgmr) by 2002:a05:6902:100d:: with SMTP id w13mr21865678ybt.489.1617729496367; Tue, 06 Apr 2021 10:18:16 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 6 Apr 2021 10:18:08 -0700 In-Reply-To: <20210406171811.4043363-1-seanjc@google.com> Message-Id: <20210406171811.4043363-2-seanjc@google.com> Mime-Version: 1.0 References: <20210406171811.4043363-1-seanjc@google.com> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog Subject: [PATCH 1/4] KVM: SVM: Don't set current_vmcb->cpu when switching vmcb 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, Cathy Avery , Maxim Levitsky Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Do not update the new vmcb's last-run cpu when switching to a different vmcb. If the vCPU is migrated between its last run and a vmcb switch, e.g. for nested VM-Exit, then setting the cpu without marking the vmcb dirty will lead to KVM running the vCPU on a different physical cpu with stale clean bit settings. vcpu->cpu current_vmcb->cpu hardware pre_svm_run() cpu0 cpu0 cpu0,clean kvm_arch_vcpu_load() cpu1 cpu0 cpu0,clean svm_switch_vmcb() cpu1 cpu1 cpu0,clean pre_svm_run() cpu1 cpu1 kaboom Simply delete the offending code; unlike VMX, which needs to update the cpu at switch time due to the need to do VMPTRLD, SVM only cares about which cpu last ran the vCPU. Fixes: af18fa775d07 ("KVM: nSVM: Track the physical cpu of the vmcb vmrun through the vmcb") Cc: Cathy Avery Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/svm.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 48b396f33bee..89619cc52cf4 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1311,14 +1311,6 @@ void svm_switch_vmcb(struct vcpu_svm *svm, struct kvm_vmcb_info *target_vmcb) svm->current_vmcb = target_vmcb; svm->vmcb = target_vmcb->ptr; svm->vmcb_pa = target_vmcb->pa; - - /* - * Track the physical CPU the target_vmcb is running on - * in order to mark the VMCB dirty if the cpu changes at - * its next vmrun. - */ - - svm->current_vmcb->cpu = svm->vcpu.cpu; } static int svm_create_vcpu(struct kvm_vcpu *vcpu) From patchwork Tue Apr 6 17:18:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12185595 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38F08C43460 for ; Tue, 6 Apr 2021 17:18:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0822D61002 for ; Tue, 6 Apr 2021 17:18:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346852AbhDFRSd (ORCPT ); Tue, 6 Apr 2021 13:18:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346831AbhDFRS1 (ORCPT ); Tue, 6 Apr 2021 13:18:27 -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 782C9C061760 for ; Tue, 6 Apr 2021 10:18:19 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id y13so20911641ybk.20 for ; Tue, 06 Apr 2021 10:18:19 -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=yLZTnU9cqw3ugS9i8+TrsosQylEqmKTBM3OlilpSf6c=; b=YpSwZEHHLLTtgR0FpOxpJHDZCHkZZJk6RhRcM4ILFt4NJbSeU/D7axZjywHZdKU/1j eKTNEJDXBtAjZxvHTLlyR17DOkGLsy0YjP7+zLpv8p477LH2H/2uJu+uT37YMdeT3dAV jO2gFCWeKBJE3d4org+LzU1BOrU/xVzXoUyf3ltVmj97YLxz79rTM3KhCWR2bU0IamQ2 38eLP3q4NxfN+bc1zS7FLdcVHGa7ttAAj1gPwWMpwTfTpYXrfKjOK4yBzYMKi7/53p/G QVZvo0XWXm37r9UPSVOw97zkOfN6KFnlWv8QHLIxMoS24LtxwTElOLaDxdMqODYoyfZ6 r8pg== 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=yLZTnU9cqw3ugS9i8+TrsosQylEqmKTBM3OlilpSf6c=; b=chqrN3iO+fmx73AjQydlfBDBdvSejVfJYsFgY39icuSuDcxPJEuhwvQc+vz+GblbUZ B0kZIqhcNC2c36+pwtUmDRr8Uq2kNrzGos8VgzsigGCJaE3cRml77VapN9ofHsOboIRT WJ6//y0vmdbtip8MIMFErTfbFrAiXez++2RcwV6tX+sxgPuHH6+tOIPcEsli6Ty+QocO a+FfG4n8m6zxux0QLaqgfBodzBxhc6EmhAAmKaTfeDoTWnmAxk5J92FJEhx+r4OEm9IQ 4GQ4WD+gVSLCWsJH+49KXFgy0Ug3tasT4G1U95OUfVWH7mizlkPhJ+6TJ/hgirw9cnSx k/4w== X-Gm-Message-State: AOAM532CNrINqUQlyH0zf3Ku/qpk4gW4IO/jnE+O1vLUs3FbtgG1PLCv p6YUPF+XsUI8os2n/GX4A3tlcCPpJSA= X-Google-Smtp-Source: ABdhPJwwcyHR7qEPnOuE7Zl/tt5TJGgkBdhlyoSHJHFOCKlxMpzYCqrxpb677LKQjmza7uUavefRH57VMeY= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:24a1:90fb:182b:777c]) (user=seanjc job=sendgmr) by 2002:a25:e782:: with SMTP id e124mr45913646ybh.262.1617729498766; Tue, 06 Apr 2021 10:18:18 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 6 Apr 2021 10:18:09 -0700 In-Reply-To: <20210406171811.4043363-1-seanjc@google.com> Message-Id: <20210406171811.4043363-3-seanjc@google.com> Mime-Version: 1.0 References: <20210406171811.4043363-1-seanjc@google.com> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog Subject: [PATCH 2/4] KVM: SVM: Drop vcpu_svm.vmcb_pa 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, Cathy Avery , Maxim Levitsky Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Remove vmcb_pa from vcpu_svm and simply read current_vmcb->pa directly in the one path where it is consumed. Unlike svm->vmcb, use of the current vmcb's address is very limited, as evidenced by the fact that its use can be trimmed to a single dereference. Opportunistically add a comment about using vmcb01 for VMLOAD/VMSAVE, at first glance using vmcb01 instead of vmcb_pa looks wrong. No functional change intended. Cc: Maxim Levitsky Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/svm.c | 12 +++++++++--- arch/x86/kvm/svm/svm.h | 1 - 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 89619cc52cf4..f62c56adf7c9 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1310,7 +1310,6 @@ void svm_switch_vmcb(struct vcpu_svm *svm, struct kvm_vmcb_info *target_vmcb) { svm->current_vmcb = target_vmcb; svm->vmcb = target_vmcb->ptr; - svm->vmcb_pa = target_vmcb->pa; } static int svm_create_vcpu(struct kvm_vcpu *vcpu) @@ -3704,6 +3703,7 @@ static fastpath_t svm_exit_handlers_fastpath(struct kvm_vcpu *vcpu) static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); + unsigned long vmcb_pa = svm->current_vmcb->pa; /* * VMENTER enables interrupts (host state), but the kernel state is @@ -3726,12 +3726,18 @@ static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu) lockdep_hardirqs_on(CALLER_ADDR0); if (sev_es_guest(vcpu->kvm)) { - __svm_sev_es_vcpu_run(svm->vmcb_pa); + __svm_sev_es_vcpu_run(vmcb_pa); } else { struct svm_cpu_data *sd = per_cpu(svm_data, vcpu->cpu); + /* + * Use a single vmcb (vmcb01 because it's always valid) for + * context switching guest state via VMLOAD/VMSAVE, that way + * the state doesn't need to be copied between vmcb01 and + * vmcb02 when switching vmcbs for nested virtualization. + */ vmload(svm->vmcb01.pa); - __svm_vcpu_run(svm->vmcb_pa, (unsigned long *)&vcpu->arch.regs); + __svm_vcpu_run(vmcb_pa, (unsigned long *)&vcpu->arch.regs); vmsave(svm->vmcb01.pa); vmload(__sme_page_pa(sd->save_area)); diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 02f8ece8c741..2173fe985104 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -112,7 +112,6 @@ struct svm_nested_state { struct vcpu_svm { struct kvm_vcpu vcpu; struct vmcb *vmcb; - unsigned long vmcb_pa; struct kvm_vmcb_info vmcb01; struct kvm_vmcb_info *current_vmcb; struct svm_cpu_data *svm_data; From patchwork Tue Apr 6 17:18:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12185599 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24167C433B4 for ; Tue, 6 Apr 2021 17:18:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F2615613E8 for ; Tue, 6 Apr 2021 17:18:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346867AbhDFRSh (ORCPT ); Tue, 6 Apr 2021 13:18:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346839AbhDFRSb (ORCPT ); Tue, 6 Apr 2021 13:18:31 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8F56C061762 for ; Tue, 6 Apr 2021 10:18:21 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id d1so20918182ybj.15 for ; Tue, 06 Apr 2021 10:18:21 -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=PjN3/+CiJF7LjddLu0WlwqBKWxCNAjyRsPNQzrdepeU=; b=KRWA6BOSF919JQ+Gdji4g50Dz2V9xSb2Dz+VjpOND2wNu73lE8WKJuek0AZ5JLOZBJ xkcCFkR3+ZrlR14quktT2Y1+pS7gvmFSGwCdlD6nraBZe0nyLyOVFQeBgJ+U3sACOM+c VWm85UyLNAQv4NCXE0AAbU1LLlw8+MpF/mHHhaZKL6Qo6eKvp1m7741PAtHgHmANGGf2 B2a8zvvSCL9v2apY0sK+o1w9XAFh7xXXJX0+4SJY0F90lSMGBHEqWbnROt/phL5qKXpI pZAbJQk5LOV1wqngr1bvkHByNk94YI53wVWjGKQpGFw8UoPmLCB5Qw4OZwW7MntOY4E8 GaiQ== 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=PjN3/+CiJF7LjddLu0WlwqBKWxCNAjyRsPNQzrdepeU=; b=PvSv20ms/gn859ehG0AaMj+znse5ToIlyvOmxSylvAM/6+POUO53az6hMuek9c3zEw F6FVzZweVuUjK07x+BeoRRVCrB0BOfWLF9GxmSFzLbyssBrslTs/C66cjvLv+AVpvQPW MYJk8CqFetNSLT4Bcfr8bTngWuVqxkqPmdgCGpw5+KGbVbnriJIk57sue4SRDaweva5K pizg9O0+vGhYB0+8AW+jhCz/s6CQzOJUVko5iBziSGJBRukrUCiERIZgt8CCANSeg3cs 88jCcaNnnsxJsieKeWtCVWkh2V18Z8zl304Q7hzOUJ/JY2Q4KomLPw1S9IzTVqNZ8KYQ 8fUA== X-Gm-Message-State: AOAM531jAVdVvgFZD5zEEsXJpAgDT3/7F+DhtrLAKJ6TSKNa3DPmkyto PIFe+8PNs8fH5Ax08Banx16X3xXNvJ0= X-Google-Smtp-Source: ABdhPJyoaJnUQ+rpKHVGbmB0BKh1rZ4am9NKg94pOuxpWVA8sQL+f7DaycWHql6NCffKq0QOYvewHEbZ93Q= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:24a1:90fb:182b:777c]) (user=seanjc job=sendgmr) by 2002:a25:d07:: with SMTP id 7mr25050822ybn.135.1617729501092; Tue, 06 Apr 2021 10:18:21 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 6 Apr 2021 10:18:10 -0700 In-Reply-To: <20210406171811.4043363-1-seanjc@google.com> Message-Id: <20210406171811.4043363-4-seanjc@google.com> Mime-Version: 1.0 References: <20210406171811.4043363-1-seanjc@google.com> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog Subject: [PATCH 3/4] KVM: SVM: Add a comment to clarify what vcpu_svm.vmcb points at 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, Cathy Avery , Maxim Levitsky Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add a comment above the declaration of vcpu_svm.vmcb to call out that it is simply a shorthand for current_vmcb->ptr. The myriad accesses to svm->vmcb are quite confusing without this crucial detail. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/svm.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 2173fe985104..b230950c1aa6 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -111,6 +111,7 @@ struct svm_nested_state { struct vcpu_svm { struct kvm_vcpu vcpu; + /* vmcb always points at current_vmcb->ptr, it's purely a shorthand. */ struct vmcb *vmcb; struct kvm_vmcb_info vmcb01; struct kvm_vmcb_info *current_vmcb; From patchwork Tue Apr 6 17:18:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12185597 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D758FC43460 for ; Tue, 6 Apr 2021 17:18:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B6FB4610E8 for ; Tue, 6 Apr 2021 17:18:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346861AbhDFRSg (ORCPT ); Tue, 6 Apr 2021 13:18:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346844AbhDFRSc (ORCPT ); Tue, 6 Apr 2021 13:18:32 -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 45575C0613D7 for ; Tue, 6 Apr 2021 10:18:24 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id x7so7684807ybs.10 for ; Tue, 06 Apr 2021 10:18:24 -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=AHeQvzzn66sWUva8JNr2h2SQ2HWMOsEyIwLZ7XmPEdo=; b=YETEvBs8rD6Dmh61b2NAoq1qfFjNVFIq9fVXm2Hfc5cx+aUOTDP/FcUFAxayIKqf13 76ibDd1lermChzptEwnAh/LQFrI6N+rwx4ekcOYdM2+Z5E2HyrMbqjPt2QWJGrqSCpE1 aX7zbi49N9k2lIIYMvOyGdmbnC8vauunxwf2vjAJ329IUqz3T8oOJ5xmxfEzwACtl+ij pkXLJ0sUz+pRFqFtsUUhzfevKLaT7ykOAvPzO2Ec2UlkMqxXTlUD3NHSNfIoMIiytR/c wnHjO5UFSIi7aQr7WC7sKfdfeUQDyr2f2olexN1i2NdAE2qEuEDe7gFCC+lng7k/7+zW JG5A== 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=AHeQvzzn66sWUva8JNr2h2SQ2HWMOsEyIwLZ7XmPEdo=; b=apnixJ/PoNIBY0DcyHAUKPcXBz2u4ktpRT5cDJkAFkkTQKhe9OMos3r6euMgSCNXSN YTaaSmYcyS1m8VBgVuWdxGkVa4O4v7o09Hq1FkD/Okt/LbmfOQup99eVJZfBAVeUVujv I3uaQdTvfcOdn9cpcHYUF15nvTfGLDLLda2a8s6Tp71yXiGMsO5zrFjuC4y1gUpmOGLk zC0OGJht88b+10UPH9Fm7wQab3/zKKili3R0RAu12g7kysJj2GX7CHYdhbaoX7oQC5RY QWygF2DeQgXFG9q8jtWHI/xRnkAKcUZoRKpxTlK9/HVWpNAx6o7dGiCOl9sZmlxEAiGV FJ7w== X-Gm-Message-State: AOAM533cjclc3pEdBb3g7ctMZu2cdEicmIeSulul6YDcbWXpAV6AF1cB pX6alyCVgNcjznuSh6d0W1EflFV+giM= X-Google-Smtp-Source: ABdhPJxbslvhhYvMOQ089wkXN1xaK5LEt/wkL5quSTis4uoo6YzzSrWcVv5TAYj4iW+o/zFSjf5u02tfKoU= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:24a1:90fb:182b:777c]) (user=seanjc job=sendgmr) by 2002:a25:bad0:: with SMTP id a16mr44857414ybk.441.1617729503442; Tue, 06 Apr 2021 10:18:23 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 6 Apr 2021 10:18:11 -0700 In-Reply-To: <20210406171811.4043363-1-seanjc@google.com> Message-Id: <20210406171811.4043363-5-seanjc@google.com> Mime-Version: 1.0 References: <20210406171811.4043363-1-seanjc@google.com> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog Subject: [PATCH 4/4] KVM: SVM: Enhance and clean up the vmcb tracking comment in pre_svm_run() 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, Cathy Avery , Maxim Levitsky Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Explicitly document why a vmcb must be marked dirty and assigned a new asid when it will be run on a different cpu. The "what" is relatively obvious, whereas the "why" requires reading the APM and/or KVM code. Opportunistically remove a spurious period and several unnecessary newlines in the comment. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/svm.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index f62c56adf7c9..afc275ba5d59 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3336,11 +3336,10 @@ static void pre_svm_run(struct kvm_vcpu *vcpu) struct vcpu_svm *svm = to_svm(vcpu); /* - * If the previous vmrun of the vmcb occurred on - * a different physical cpu then we must mark the vmcb dirty. - * and assign a new asid. - */ - + * If the previous vmrun of the vmcb occurred on a different physical + * cpu, then mark the vmcb dirty and assign a new asid. Hardware's + * vmcb clean bits are per logical CPU, as are KVM's asid assignments. + */ if (unlikely(svm->current_vmcb->cpu != vcpu->cpu)) { svm->current_vmcb->asid_generation = 0; vmcb_mark_all_dirty(svm->vmcb);