Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2718972pxv; Sun, 11 Jul 2021 23:43:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMaL5oERbtWHf5MitKuVBfOcsxtXcdfUTbNvo4oGymz58w7vR80s6iSqnL22B1gfOkfjwy X-Received: by 2002:a05:6402:406:: with SMTP id q6mr62860066edv.149.1626072232823; Sun, 11 Jul 2021 23:43:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626072232; cv=none; d=google.com; s=arc-20160816; b=atdtZaGUfApZ5oxi2Y1Siv75yALrEP8PiRWRfgllvWfhnJ89DSry1bDWE2fy7wQAeW BXWvrNXWH6gxXl4kIWJrsfsxf3kYngZpCvFOUsGdTgVruEo4neVtRYkHBhUttGsY8qLi vAVMhF8eCBYOlCcNrJEcT1etqU1EOpNthowClhkSJRjaLR5/E0cryy93f8JKNDMFHtvu kuionxz29yI8ADMud9snKXOEyff5WYNYnw8DQRLjHo5CJiXuMu9G7+2HyidOc8OrRQJj MgK7+Ru4C61I11n11SkRl75Olymqlvux4SwfmfRDO4szG8An/5FRisYCP5K/7sVT8V5m es1w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=I/P/y4EUxQccvbt1a3KNLcRBFUmWv+F+DtEiV/nkPZo=; b=QQyEgPD4UdvtUMzhJYjo6bWTTfkx8LT2hU1k/Yabh6GZdcCypW9IGzW0guKFnQfZ2A 9ETNPjX57hHdFhM3io8tADbkY5YTDT5sqL2FIreePzSuyyfvGMWjtkAWUQrpREyUNI41 YssHXV4a4sd0ub8uhrVK1PpdlLXgehuKBqHx5j+xH1gn/t1T9aJtGKQHPoVAM0neM++V ms5XkyDvLE2NRn9jvQXz1evPV2d0A+d8F+G5c69GHrniUrVgHeOwWCE6j6d1BHwCzrxD VQYgPyjzwzTGTBS6rcbIkgQD8CiFMbKHk5IgP22QC4u1CZNIrY+va+zpmRuA1ttClmA7 UWkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pPlYMJ6t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d10si13689064ejr.696.2021.07.11.23.43.30; Sun, 11 Jul 2021 23:43:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pPlYMJ6t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238148AbhGLGmN (ORCPT + 99 others); Mon, 12 Jul 2021 02:42:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:55268 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237629AbhGLGem (ORCPT ); Mon, 12 Jul 2021 02:34:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 923FA610A6; Mon, 12 Jul 2021 06:31:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626071462; bh=/TVaHVcHZcvaaIlw/BKSTFLWJXxQwafAJaqeoYu64xY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pPlYMJ6tQ6pAC0vJzAnccXSKienSO9B9fW1JC5tuHCpfCk+wKDICa5H6GiJLo9tJ1 f+1BZSL1ppmUGqRZl2y5Q7N9ZpdcNA/K0fCTu7GiSRVemzssN1DtomRMqavH1069iK gsoIcKTygC/d+MhzSzQU34wKwcuXhbS8j3f3Z1kk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.10 063/593] KVM: x86/mmu: Treat NX as used (not reserved) for all !TDP shadow MMUs Date: Mon, 12 Jul 2021 08:03:43 +0200 Message-Id: <20210712060850.113581613@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson commit 112022bdb5bc372e00e6e43cb88ee38ea67b97bd upstream. Mark NX as being used for all non-nested shadow MMUs, as KVM will set the NX bit for huge SPTEs if the iTLB mutli-hit mitigation is enabled. Checking the mitigation itself is not sufficient as it can be toggled on at any time and KVM doesn't reset MMU contexts when that happens. KVM could reset the contexts, but that would require purging all SPTEs in all MMUs, for no real benefit. And, KVM already forces EFER.NX=1 when TDP is disabled (for WP=0, SMEP=1, NX=0), so technically NX is never reserved for shadow MMUs. Fixes: b8e8c8303ff2 ("kvm: mmu: ITLB_MULTIHIT mitigation") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Message-Id: <20210622175739.3610207-3-seanjc@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/mmu/mmu.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4133,7 +4133,15 @@ static void reset_rsvds_bits_mask_ept(st void reset_shadow_zero_bits_mask(struct kvm_vcpu *vcpu, struct kvm_mmu *context) { - bool uses_nx = context->nx || + /* + * KVM uses NX when TDP is disabled to handle a variety of scenarios, + * notably for huge SPTEs if iTLB multi-hit mitigation is enabled and + * to generate correct permissions for CR0.WP=0/CR4.SMEP=1/EFER.NX=0. + * The iTLB multi-hit workaround can be toggled at any time, so assume + * NX can be used by any non-nested shadow MMU to avoid having to reset + * MMU contexts. Note, KVM forces EFER.NX=1 when TDP is disabled. + */ + bool uses_nx = context->nx || !tdp_enabled || context->mmu_role.base.smep_andnot_wp; struct rsvd_bits_validate *shadow_zero_check; int i;