Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp913027pxb; Wed, 1 Sep 2021 12:32:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWmHHO3phmSe2YGsaEuHzJTJY76yagYUvCxxI5duk3NTJ9MvyZL//6MR1ye99U3SPwCfBV X-Received: by 2002:a17:906:4bd6:: with SMTP id x22mr1215959ejv.270.1630524751802; Wed, 01 Sep 2021 12:32:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630524751; cv=none; d=google.com; s=arc-20160816; b=mUNHTQhUs2nuok1m8wqD52dDxTYtdVIdxFwvqhvLzsu8BMPeJvpVnT3a2Xn3V/29Rl z7dXSyM5R8GyUvE11NM47TMriAaEbDGCQlM59VHwUo/rcfBvPAukhCxEklAHtxkJZU0a +009BevjpPBM/UGzLPe0ibicPaI65wuUYOzs+P/nvN/ALEPn8rcQWVXwB0MWoki2lhj1 2D8VtENdycvHNnGMMmncedOdkhpGlaN1E5TPFoJPfEaPW26xjCqfbf8p4ve7WPG+atpV Fs9c/nVEZDq4ZoQz6LHT63TQL7DACn0dj9mbB2TyOZgUsplAZv61CV0JZ8saBh2pdPK3 8+nw== 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=Te4dJ9mkAGunFHO7psndPKa2tU0r/lYRH+r46bU+YtY=; b=j9zvupi1kOTFB3vIpMeDSRLjNkzIipO/cVaDvX1j1PDPMvHwskRzuW3VKL0L7n2Q81 nnUlcrD9WMFfnyf4Td7/UcZT9S9IF0L0EyvN8vwufahgCfT0RIrUI+L8kYRfBMGfGDdf ldllRUjKmUQsiHFTk5jkYeFCye/gs6vz21O6bugvTOYbvHTeL8/VNCeTtR3mNSSctFy/ XcQGANsVX4SJaH59j+Q6Bn7SD+KUzPA1X7hJFSZSJhFN9jCrcn7mE5uQYd+boeDuLZoW ITBaS4IAqAws5vk2ZN4lvWDUamaMt+jjW6QMjAokXmJFXrO2Mi6gQHWUCKLFtSLyMipT SEtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nePXJuow; 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 bv8si649860ejb.87.2021.09.01.12.31.49; Wed, 01 Sep 2021 12:32:31 -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=nePXJuow; 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 S245070AbhIAMcZ (ORCPT + 99 others); Wed, 1 Sep 2021 08:32:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:33880 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244845AbhIAMb1 (ORCPT ); Wed, 1 Sep 2021 08:31:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4CE5761027; Wed, 1 Sep 2021 12:30:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1630499430; bh=X7f1X3xLhlkt2ACIPCt4Bkeku+N5/nP8p10Ow3NpR50=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nePXJuowOPBgYD6Um34gun8J6jStIX8s7MRU66K+hfwTn78N1a7y0s4YcKQItjfNM iCG8/BRuz9f8h/kb+d1UB2LK5DSEHMucys50405frKxZfhqiNX/zCel2sc2yL8049Y bcYm1N0mh6cSHKJDpUPIZmXFXIT+plLCbTDSkiLI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Sudip Mukherjee Subject: [PATCH 4.19 31/33] KVM: x86/mmu: Treat NX as used (not reserved) for all !TDP shadow MMUs Date: Wed, 1 Sep 2021 14:28:20 +0200 Message-Id: <20210901122251.807288061@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210901122250.752620302@linuxfoundation.org> References: <20210901122250.752620302@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 [sudip: use old path and adjust context] Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/mmu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -4557,7 +4557,16 @@ 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 || context->base_role.smep_andnot_wp; + /* + * 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->base_role.smep_andnot_wp; struct rsvd_bits_validate *shadow_zero_check; int i;