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.1 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 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 4C5F6C433EF for ; Sun, 12 Sep 2021 10:34:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 347C760235 for ; Sun, 12 Sep 2021 10:34:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235001AbhILKfN (ORCPT ); Sun, 12 Sep 2021 06:35:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32833 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232555AbhILKfH (ORCPT ); Sun, 12 Sep 2021 06:35:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631442833; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vvMzth+IF5FLsBCqQ5vuYZZ9lz8yM7mDVyzxWe/Vzhg=; b=XNMzExQG72BYpYB/+l0GfSwvLNDvFWzCfQd1gKB/RTlw9gaf02i0f8I6KPMyu4IWVXDU0s IKaJg1Y6K4J+y2SDZvlvRODsw3zYD5HtTVepHAQ2XaEn4N7p0T12zzjr8MSPDJ6sQoJDxY DXFYDQ4dmd7YZu9nRqYQhEQMji9qBVs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-527-JC6lQXnvOCWa28R-2FyZkQ-1; Sun, 12 Sep 2021 06:33:50 -0400 X-MC-Unique: JC6lQXnvOCWa28R-2FyZkQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D93E980196C; Sun, 12 Sep 2021 10:33:48 +0000 (UTC) Received: from starship (unknown [10.35.206.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id A70406A8FC; Sun, 12 Sep 2021 10:33:44 +0000 (UTC) Message-ID: Subject: Re: [PATCH v2 2/3] KVM: x86: force PDPTRs reload on SMM exit From: Maxim Levitsky To: Sean Christopherson Cc: kvm@vger.kernel.org, Joerg Roedel , Thomas Gleixner , Jim Mattson , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Wanpeng Li , Paolo Bonzini , Borislav Petkov , "H. Peter Anvin" , Ingo Molnar , Vitaly Kuznetsov Date: Sun, 12 Sep 2021 13:33:43 +0300 In-Reply-To: References: <20210823114618.1184209-1-mlevitsk@redhat.com> <20210823114618.1184209-3-mlevitsk@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2021-09-09 at 00:55 +0000, Sean Christopherson wrote: > On Mon, Aug 23, 2021, Maxim Levitsky wrote: > > KVM_REQ_GET_NESTED_STATE_PAGES is also used with VM entries that happen > > on exit from SMM mode, and in this case PDPTRS must be always reloaded. > > > > Thanks to Sean Christopherson for pointing this out. > > > > Fixes: 0f85722341b0 ("KVM: nVMX: delay loading of PDPTRs to KVM_REQ_GET_NESTED_STATE_PAGES") > > > > Signed-off-by: Maxim Levitsky > > --- > > arch/x86/kvm/vmx/vmx.c | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > > index fada1055f325..4194fbf5e5d6 100644 > > --- a/arch/x86/kvm/vmx/vmx.c > > +++ b/arch/x86/kvm/vmx/vmx.c > > @@ -7504,6 +7504,13 @@ static int vmx_leave_smm(struct kvm_vcpu *vcpu, const char *smstate) > > } > > > > if (vmx->nested.smm.guest_mode) { > > + > > + /* Exit from the SMM to the non root mode also uses > > Just "Exit from SMM to non-root mode", i.e. drop the "the". > > Multi-line comments should look like: > > /* > * Exit from SMM ... > > though oddly checkpatch doesn't complain about that. > > That said, for the comment, it'd be more helpful to explain why the PDPTRs should > not come from userspace. Something like: > > /* > * Always reload the guest's version of the PDPTRs when exiting > * from SMM to non-root. If KVM_SET_SREGS2 stuffs PDPTRs while > * SMM is active, that state is specifically for SMM context. > * On RSM, all guest state is pulled from its architectural > * location, whatever that may be. > */ > > Though typing that makes me wonder if this is fixing the wrong thing. It seems > like pdptrs_from_userspace shouldn't be set when SMM is active, though I suppose > there's a potential ordering issue between KVM_SET_SREGS2 and KVM_SET_VCPU_EVENTS. > Bummer. > > > + * the KVM_REQ_GET_NESTED_STATE_PAGES request, > > + * but in this case the pdptrs must be always reloaded > > + */ > > + vcpu->arch.pdptrs_from_userspace = false; > > + > > ret = nested_vmx_enter_non_root_mode(vcpu, false); > > if (ret) > > return ret; > > -- > > 2.26.3 > > I went with your suggestion in the patch 3, and dropped this patch. Thanks! Best regards, Maxim Levitsky