Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2124145pxb; Wed, 9 Feb 2022 11:20:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzYPxzsYA1FpId/3GnvOjgsoFNr62GEdfsE4y6XdBq/BKrJypI553tuD4y+vKIs6WrM+Sm+ X-Received: by 2002:a17:903:1210:: with SMTP id l16mr3670777plh.63.1644434426697; Wed, 09 Feb 2022 11:20:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644434426; cv=none; d=google.com; s=arc-20160816; b=Eu7eeh/gUaDx/VYNgUxOnmJn9JEbhbGXjSv+j1aZpmgNL23EKqLEYu228OmR77rsUC fUVHFetPugXMSF9n0sEqUOq7YQj4PUDspUnmZ1qbWrMIWt0QLr/YX00Q+0HQqFq7uWlr G0ZZ0ByjVboCKX3w0yCs0Xvo0ZlueWDSrUjn8563YD7EOtxgzUHjeoSre43/mCQneR58 wnHsSBAgrkMfFJM4Yh0cRd5q7jeFDJ3tJtleXS07sDwKTeyuZ6A1b36xGrPfzxOH5DxA BtyoF0LfDoytF3vILsY/Q41RfyFHA45j4rkkiDh8qpoRK2p1rO00IqXAGfNrkz/1/ZDf XWrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jEqL6PLWr+bZ/5j2l/zElDfsDQbZUnnUlRxHORnTr6s=; b=psHOP4LLWxUJhEU2ShOkYtR5WiRWacG0t29+T0NNVo0p0592cIzl77QM3ujiW4l3/S BgjgCuWruM5RyglcDjQou25d5km1Qi6+TYmrVoy7EimSkv/xCDPliSW2zOO79CcNTuyS Qh6U9DVrJ6tyLGDttPqg1nOEtJsUGdXQ+isghTDA63UVIBkjZwLCO0a8NnMrNmzaJzes djT9Y1lIsrfdylKtUp20Deqnl/gs9eZ2H+UQeZnFBfdgZWsAc3hp6do7+NtG78MTRJC9 1ViCbXPA7OFHCk4X01bv8sRZxAaloDyM78sI6GJALWQNS58mkuify/+rbCGB0ewu/2uy 65BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ivtfcwTE; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id b17si5411719plh.225.2022.02.09.11.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 11:20:26 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ivtfcwTE; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 80465C1DF824; Wed, 9 Feb 2022 11:16:44 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237675AbiBIRAz (ORCPT + 99 others); Wed, 9 Feb 2022 12:00:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237535AbiBIRAp (ORCPT ); Wed, 9 Feb 2022 12:00:45 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C2246C05CB8E for ; Wed, 9 Feb 2022 09:00:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644426047; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jEqL6PLWr+bZ/5j2l/zElDfsDQbZUnnUlRxHORnTr6s=; b=ivtfcwTEYb6XbxMi3EouTnlNO4IPsqekza5vYAnc2zVvErhfsyWm3VgxUIvSZvIPRup11b WUrPIsWaLbde1cRRGIcRoUDXlreMLaEPN4FCrDmJV41KFBAnZFRB9icgvg6WkmBCEOGXa5 RJpIzycnqnUcrL1hUpt2LIOK61HocoU= 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-574-YSjKLW7EP7yxonBU0a_7RQ-1; Wed, 09 Feb 2022 12:00:42 -0500 X-MC-Unique: YSjKLW7EP7yxonBU0a_7RQ-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 649588145E2; Wed, 9 Feb 2022 17:00:41 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B5657D499; Wed, 9 Feb 2022 17:00:29 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: vkuznets@redhat.com, mlevitsk@redhat.com, dmatlack@google.com, seanjc@google.com, stable@vger.kernel.org Subject: [PATCH 01/12] KVM: x86: host-initiated EFER.LME write affects the MMU Date: Wed, 9 Feb 2022 12:00:09 -0500 Message-Id: <20220209170020.1775368-2-pbonzini@redhat.com> In-Reply-To: <20220209170020.1775368-1-pbonzini@redhat.com> References: <20220209170020.1775368-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 9a9006226501..5e1298aef9e2 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; -- 2.31.1