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 3D0F3C433F5 for ; Wed, 23 Feb 2022 13:41:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241001AbiBWNmY (ORCPT ); Wed, 23 Feb 2022 08:42:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241002AbiBWNlL (ORCPT ); Wed, 23 Feb 2022 08:41:11 -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 ESMTP id 1403FAC05F for ; Wed, 23 Feb 2022 05:40:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645623643; 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=rdW/Vnhl8SCwM1k5GnCkUAynoacHPuSD7Amvkwo2DqI=; b=gJc7hVW+mKtJI/Dsba37eiTrYQqhF19IYTP7htsxhrP0xzVBtk4mBa+qU2NIuGnz6qE/2J DonXBuCt9BzWeVh4EfUxO979ROHFW6PaI+SELW3L9+dV1UJK38QHtZTh05ktjLJ8A2O0Ys G80wxuuZZO0idXd+ellcZyNQ8Pgakxk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-253-D6l8P-rjOD-hiXsIZlGJFg-1; Wed, 23 Feb 2022 08:40:39 -0500 X-MC-Unique: D6l8P-rjOD-hiXsIZlGJFg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8DDAE801AAD; Wed, 23 Feb 2022 13:40:38 +0000 (UTC) Received: from starship (unknown [10.40.195.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id E926784978; Wed, 23 Feb 2022 13:40:31 +0000 (UTC) Message-ID: Subject: Re: [PATCH v2 01/18] KVM: x86: host-initiated EFER.LME write affects the MMU From: Maxim Levitsky To: Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com, stable@vger.kernel.org Date: Wed, 23 Feb 2022 15:40:30 +0200 In-Reply-To: <20220217210340.312449-2-pbonzini@redhat.com> References: <20220217210340.312449-1-pbonzini@redhat.com> <20220217210340.312449-2-pbonzini@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.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2022-02-17 at 16:03 -0500, Paolo Bonzini wrote: > While the guest runs, EFER.LME cannot change unless CR0.PG is clear, and therefore > EFER.NX is the only bit that can affect the MMU role. However, set_efer accepts > a host-initiated change to EFER.LME even with CR0.PG=1. In that case, the > MMU has to be reset. > > Fixes: 11988499e62b ("KVM: x86: Skip EFER vs. guest CPUID checks for host-initiated writes") > Cc: stable@vger.kernel.org > Signed-off-by: Paolo Bonzini > --- > arch/x86/kvm/mmu.h | 1 + > arch/x86/kvm/x86.c | 2 +- > 2 files changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h > index 51faa2c76ca5..a5a50cfeffff 100644 > --- a/arch/x86/kvm/mmu.h > +++ b/arch/x86/kvm/mmu.h > @@ -48,6 +48,7 @@ > X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_PKE) > > #define KVM_MMU_CR0_ROLE_BITS (X86_CR0_PG | X86_CR0_WP) > +#define KVM_MMU_EFER_ROLE_BITS (EFER_LME | EFER_NX) > > static __always_inline u64 rsvd_bits(int s, int e) > { > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index d3da64106685..99a58c25f5c2 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -1647,7 +1647,7 @@ static int set_efer(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > } > > /* Update reserved bits */ > - if ((efer ^ old_efer) & EFER_NX) > + if ((efer ^ old_efer) & KVM_MMU_EFER_ROLE_BITS) > kvm_mmu_reset_context(vcpu); > > return 0; It makes sense. I am just curios, is there a report of failure due to this issue? I can imagine something like this breaking nested migration of 32 bit guests and such and/or smm and such. Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky