From mboxrd@z Thu Jan 1 00:00:00 1970 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=-16.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable 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 66120C432BE for ; Tue, 27 Jul 2021 15:25:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4ACEF61B3E for ; Tue, 27 Jul 2021 15:25:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237082AbhG0PZp (ORCPT ); Tue, 27 Jul 2021 11:25:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40090 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232642AbhG0PXh (ORCPT ); Tue, 27 Jul 2021 11:23:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627399413; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=K9vnN9wL7bbivI7Hwt9tBs1nCKBEhS3YAOrtS2yFzAo=; b=LFev05ijJeQz4As0rMtduLuwQ94jfcTx2On64DdVaDIPxtPGuItcTTtKxQMBdH85jxaDix Bh1Nc44c4B3eOcQ/pk/YIHpVAG4KLs5rT1C66YVzCIjzKd8WNwEuDE/tVev+3Z37hnKZX+ +olfLgp9Ml+7589wMfavV0+6hztZpaY= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-287-k3CfWqRVNiGUIwPaMcI_6A-1; Tue, 27 Jul 2021 11:23:32 -0400 X-MC-Unique: k3CfWqRVNiGUIwPaMcI_6A-1 Received: by mail-ed1-f71.google.com with SMTP id de5-20020a0564023085b02903bb92fd182eso3443829edb.8 for ; Tue, 27 Jul 2021 08:23:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=K9vnN9wL7bbivI7Hwt9tBs1nCKBEhS3YAOrtS2yFzAo=; b=OfPz0VSq2X4btSAjUlExnmbj06SKgTisxq1En3znCzxKuSpxsr485mkaSXoNe6TEF5 I6T+CKmQhSt5f/6ZbIr+v4ncgVZVT1FFzMty6wUt1cVyrsLrlIr0cV97PB8RIFo6WPlV C/r6G62l2nU+UtC56yhDoiOB6sCUoTgLEPdeOicwQCb1/OzRq9EqKrr+06gA17Y32E7C pbSPReoVGccMxAfjSVce9Nfq1KYKIcBtSH2KiZVOTzDMeN1sQLrjBvk54gRmpeCIXRNq Ozf6BR6EQHnUsPDftrK0dULD7JYrA5Fki79XK5sL6UrRUbk4CMNWdSUwt9SaHzJyGgqB rpEw== X-Gm-Message-State: AOAM531PqwmRWEyo6kctTUthchC4uyVZqP39n6HtFfY4LcTJnEqHeCBs gg7nihlO51wTWasOmvpza+RsnMG0M6mbp8/IYX9UnNFtzpQv0K0IyyZR4VtPZmf/EIxBQ7CFu4j VQwnkIAcZvcqBFbx53pfHMk5V X-Received: by 2002:aa7:c956:: with SMTP id h22mr27834807edt.378.1627399411348; Tue, 27 Jul 2021 08:23:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziLlMRBKgJ1MU+hRRcFdLOJqyAASXy4lbQBYorQQKdWpyIS4+ytKilfOPL91Ubb5c5gfus2A== X-Received: by 2002:aa7:c956:: with SMTP id h22mr27834785edt.378.1627399411116; Tue, 27 Jul 2021 08:23:31 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id l17sm1391591edt.52.2021.07.27.08.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jul 2021 08:23:30 -0700 (PDT) From: Vitaly Kuznetsov To: Paolo Bonzini Cc: Dan Carpenter , Vineeth Pillai , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH] KVM: SVM: delay svm_vcpu_init_msrpm after svm->vmcb is initialized In-Reply-To: <20210726165843.1441132-1-pbonzini@redhat.com> References: <20210726165843.1441132-1-pbonzini@redhat.com> Date: Tue, 27 Jul 2021 17:23:29 +0200 Message-ID: <87zgu76ary.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Paolo Bonzini writes: > Right now, svm_hv_vmcb_dirty_nested_enlightenments has an incorrect > dereference of vmcb->control.reserved_sw before the vmcb is checked > for being non-NULL. The compiler is usually sinking the dereference > after the check; instead of doing this ourselves in the source, > ensure that svm_hv_vmcb_dirty_nested_enlightenments is only called > with a non-NULL VMCB. > > Reported-by: Dan Carpenter > Cc: Vineeth Pillai > Signed-off-by: Paolo Bonzini > [Untested for now due to issues with my AMD machine. - Paolo] At least this doesn't seem to break kvm-amd on bare metal, so Tested-by: Vitaly Kuznetsov > --- > arch/x86/kvm/svm/svm.c | 4 ++-- > arch/x86/kvm/svm/svm_onhyperv.h | 2 +- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index 9a6987549e1b..4bcb95bb8ed7 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -1406,8 +1406,6 @@ static int svm_create_vcpu(struct kvm_vcpu *vcpu) > goto error_free_vmsa_page; > } > > - svm_vcpu_init_msrpm(vcpu, svm->msrpm); > - > svm->vmcb01.ptr = page_address(vmcb01_page); > svm->vmcb01.pa = __sme_set(page_to_pfn(vmcb01_page) << PAGE_SHIFT); > > @@ -1419,6 +1417,8 @@ static int svm_create_vcpu(struct kvm_vcpu *vcpu) > svm_switch_vmcb(svm, &svm->vmcb01); > init_vmcb(vcpu); > > + svm_vcpu_init_msrpm(vcpu, svm->msrpm); > + > svm_init_osvw(vcpu); > vcpu->arch.microcode_version = 0x01000065; > > diff --git a/arch/x86/kvm/svm/svm_onhyperv.h b/arch/x86/kvm/svm/svm_onhyperv.h > index 9b9a55abc29f..c53b8bf8d013 100644 > --- a/arch/x86/kvm/svm/svm_onhyperv.h > +++ b/arch/x86/kvm/svm/svm_onhyperv.h > @@ -89,7 +89,7 @@ static inline void svm_hv_vmcb_dirty_nested_enlightenments( > * as we mark it dirty unconditionally towards end of vcpu > * init phase. > */ > - if (vmcb && vmcb_is_clean(vmcb, VMCB_HV_NESTED_ENLIGHTENMENTS) && > + if (vmcb_is_clean(vmcb, VMCB_HV_NESTED_ENLIGHTENMENTS) && > hve->hv_enlightenments_control.msr_bitmap) > vmcb_mark_dirty(vmcb, VMCB_HV_NESTED_ENLIGHTENMENTS); > } -- Vitaly