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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8202C282E7 for ; Fri, 12 Aug 2022 06:27:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237106AbiHLG0o (ORCPT ); Fri, 12 Aug 2022 02:26:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233840AbiHLG0Q (ORCPT ); Fri, 12 Aug 2022 02:26:16 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4485C89CF1 for ; Thu, 11 Aug 2022 23:26:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660285572; 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=IPdDqhne4x6G2lLU0p73M/Ml6BV2ff81inMt9zmg0oQ=; b=CF7F/2AzHcNCltHEPchSGVia293NykibvRqjFYWnXM90zT6LBJSzmFKAZOv3fp4oC+Al1D d6E0qLY4cxqm6/b90uuYyw1ryEerI9rKOMANfQWeP/yWaxL42+O+kaggW2oyTvLIPSSmvD l20FpG1EtEaM+fva+anf3BvrFXx6eLk= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-13-kHfKNj6uOxy9b1DVKnYDhw-1; Fri, 12 Aug 2022 02:26:08 -0400 X-MC-Unique: kHfKNj6uOxy9b1DVKnYDhw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1F8B0296A62F; Fri, 12 Aug 2022 06:26:08 +0000 (UTC) Received: from starship (unknown [10.40.192.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76A7D492C3B; Fri, 12 Aug 2022 06:26:03 +0000 (UTC) Message-ID: <084f4de105d24f22513c14a83c2254add31f5928.camel@redhat.com> Subject: Re: [PATCH v3 03/13] KVM: x86: emulator: introduce emulator_recalc_and_set_mode From: Maxim Levitsky To: "Yang, Weijiang" , "kvm@vger.kernel.org" Cc: Borislav Petkov , Dave Hansen , "linux-kernel@vger.kernel.org" , Wanpeng Li , Ingo Molnar , "Christopherson,, Sean" , "x86@kernel.org" , Jim Mattson , Kees Cook , Thomas Gleixner , "H. Peter Anvin" , Joerg Roedel , Vitaly Kuznetsov , Paolo Bonzini In-Reply-To: <2e191acd-0b71-784a-2c14-6e78351788cc@intel.com> References: <20220803155011.43721-1-mlevitsk@redhat.com> <20220803155011.43721-4-mlevitsk@redhat.com> <2e191acd-0b71-784a-2c14-6e78351788cc@intel.com> Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Fri, 12 Aug 2022 09:25:04 +0300 User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2022-08-11 at 23:33 +0800, Yang, Weijiang wrote: > On 8/3/2022 11:50 PM, Maxim Levitsky wrote: > > [...] > > +static inline int emulator_recalc_and_set_mode(struct x86_emulate_ctxt *ctxt) > > +{ > > + u64 efer; > > + struct desc_struct cs; > > + u16 selector; > > + u32 base3; > > + > > + ctxt->ops->get_msr(ctxt, MSR_EFER, &efer); > > + > > + if (!ctxt->ops->get_cr(ctxt, 0) & X86_CR0_PE) { Ouch, thanks for catching this!! I wonder how I didn't catch this in unit tests.... (I'll check on this Sunday) Best regards, Maxim Levitsky > Shouldn't this be: !(ctxt->ops->get_cr(ctxt, 0) & X86_CR0_PE) ? > > + /* Real mode. cpu must not have long mode active */ > > + if (efer & EFER_LMA) > > + return X86EMUL_UNHANDLEABLE; > > + ctxt->mode = X86EMUL_MODE_REAL; > > + return X86EMUL_CONTINUE; > > + } > > + > [...] > > -- > > 2.26.3 > >