Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp184860rdb; Mon, 22 Jan 2024 16:51:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IHslvxOMLpeOw9gV4x/cF31Op56nAOs0EbfbFiIz4UATVNuyx5CRndkYBCycRLJu5FmRcdP X-Received: by 2002:a17:90a:4ce5:b0:28e:7b6b:5d0 with SMTP id k92-20020a17090a4ce500b0028e7b6b05d0mr1826197pjh.67.1705971102735; Mon, 22 Jan 2024 16:51:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705971102; cv=pass; d=google.com; s=arc-20160816; b=WCOmxIKMPbxdFHvrsBHjSN9wlAaD/+jJPPdtgw9on9l8Heek6wgu7Dp1JihYeVWtEM 63J8yRLXDms0AKSLLtcQY8S9nF7v4XeTvPve+HRmWdegmqkDDcPoWU7+uv3ujW7AgDs/ fI3aY4VcBNQDOXR+9P5oXpt9LG5E9GrntudBhej2K43A98mCbhDlfEBGmYYNeEfoGXOr bCBPKOIB6VlptnVB9ZqQrXPtar/oGe1Apk6ZdlJZAM9u7njIBWOpegyigZlBEmZX9ano MCS7+g63cdERmRL7ytrY2akgZ2XDQek+wBEJedAFI3AUwVuS9Mu5slwd1F3E1VHmSHOL Gp9g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=alEP129vZW7yLpfnZQaK7izaUPiEGpwuA6qxvUaBIog=; fh=Itbyk7CEvizIrzGEESCqq3I2tZgG1kc/GkVOa3S7Hsg=; b=N/mNY/+j2juqDPfiLFOxjsrnJC2vhBqrcIJrCdfZIem+FMHLo73+cflpipL5OIgBb5 b0uuJ53lp1uwiystq3RKm3ywyCJfLptjGUmPyMBaRC5MKtMchMfLuC56rUsFyLoWswec rzg3RZigytE+EQAv+OpH4ftNc4iecM/LsvgPixZh7F8g7aX8pwFLLcR91jadS6oCwEPb IGwCT7CnO1l8uh4eUFkMKFeFfiRCwd1R2BrGzFqFUhI/pWGZL4s9gXmvBoPXv2nqQ3sH vDSxq1f1GBJ4yC8tUtRCXie+HV9mB/rvNGN2IcfNI3QnC+3xl+PUqIMAJkgxmjVlu2VV fgDw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WiKH8CEO; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34348-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34348-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id v4-20020a17090abb8400b00290cf479691si302296pjr.93.2024.01.22.16.51.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 16:51:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34348-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WiKH8CEO; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34348-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34348-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 033FCB2231E for ; Tue, 23 Jan 2024 00:29:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B98C55FDAF; Mon, 22 Jan 2024 23:55:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WiKH8CEO" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73A8C5F867; Mon, 22 Jan 2024 23:55:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967730; cv=none; b=ZkT9J9VVzL8fwsLdreQHDQvQMWe3ElGter1TAvKpx652fiLQj1XBVyOCqaD4lrmMCUQpahpDz82htQCXCpGGki42Z0U9se1RFwQ5ayOBothhUoa5RXi88IaK/q1tYYqLd+XcCVfzRqQzfZJy8bMsXafJsDz3oUk4W+FHBHAy8pk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967730; c=relaxed/simple; bh=/QQnC6NuR+jveGFHm7lY9Jr4kJQvgq3Qc9nLEe3cDso=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n8fDxqWIdfg1dSywy1RlDEVTiIBR/RUK8hKfud76CSU9XpcbBBS9Ayaw9MJ8sOBBPs1r4BFT6Qba36eXntmJOVT5eB8Zrtc3VawpfSyRraeYyv7w4rz0xi0PHeepl4wwp1HVXJZ1zyggnmlcgJANaLkDwURRCPxb6rrddGgukEY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=WiKH8CEO; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705967728; x=1737503728; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/QQnC6NuR+jveGFHm7lY9Jr4kJQvgq3Qc9nLEe3cDso=; b=WiKH8CEOXmq8vugRqC38PV8Lpd0ppQ9qM3g04Rzs+QW24PegLFaInr2w SqIqAwbb/tGFLj7gJAbMswZYfEA/TZwzhXTdsInvbs4/G8YUXlJ2tqi/A NuJl6uJSQ9rTQCfxXGiCP1msp8G5IBjuLeA7R4In7ngHOTNjGT3zIm8lY 09/jsYSxAz2w1N93/PluqWyozxITj9Eb1XxNDX+s0OOsR3zV8cXk8AegA 1kvUUHZA/qRLLmaTo4SDbBqBMGqte0fkqTsDPgvnbxBXszkpJqeS8K8GB +t+fzSlSzdOcuet9R3iZ8cV7OuQb74aV97dT2tlNdsW/O2b3LvxVRmwK4 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="1243895" X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="1243895" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="819888670" X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="819888670" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:26 -0800 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v18 038/121] KVM: x86/mmu: Add Suppress VE bit to shadow_mmio_mask/shadow_present_mask Date: Mon, 22 Jan 2024 15:53:14 -0800 Message-Id: <97cc616b3563cd8277be91aaeb3e14bce23c3649.1705965635.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Isaku Yamahata To make use of the same value of shadow_mmio_mask and shadow_present_mask for TDX and VMX, add Suppress-VE bit to shadow_mmio_mask and shadow_present_mask so that they can be common for both VMX and TDX. TDX will require shadow_mmio_mask and shadow_present_mask to include VMX_SUPPRESS_VE for shared GPA so that EPT violation is triggered for shared GPA. For VMX, VMX_SUPPRESS_VE doesn't matter for MMIO because the spte value is required to cause EPT misconfig. the additional bit doesn't affect VMX logic to add the bit to shadow_mmio_{value, mask}. Signed-off-by: Isaku Yamahata --- arch/x86/include/asm/vmx.h | 1 + arch/x86/kvm/mmu/spte.c | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index 0e73616b82f3..76ed39541a52 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -513,6 +513,7 @@ enum vmcs_field { #define VMX_EPT_IPAT_BIT (1ull << 6) #define VMX_EPT_ACCESS_BIT (1ull << 8) #define VMX_EPT_DIRTY_BIT (1ull << 9) +#define VMX_EPT_SUPPRESS_VE_BIT (1ull << 63) #define VMX_EPT_RWX_MASK (VMX_EPT_READABLE_MASK | \ VMX_EPT_WRITABLE_MASK | \ VMX_EPT_EXECUTABLE_MASK) diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c index 4a599130e9c9..02a466de2991 100644 --- a/arch/x86/kvm/mmu/spte.c +++ b/arch/x86/kvm/mmu/spte.c @@ -429,7 +429,9 @@ void kvm_mmu_set_ept_masks(bool has_ad_bits, bool has_exec_only) shadow_dirty_mask = has_ad_bits ? VMX_EPT_DIRTY_BIT : 0ull; shadow_nx_mask = 0ull; shadow_x_mask = VMX_EPT_EXECUTABLE_MASK; - shadow_present_mask = has_exec_only ? 0ull : VMX_EPT_READABLE_MASK; + /* VMX_EPT_SUPPRESS_VE_BIT is needed for W or X violation. */ + shadow_present_mask = + (has_exec_only ? 0ull : VMX_EPT_READABLE_MASK) | VMX_EPT_SUPPRESS_VE_BIT; /* * EPT overrides the host MTRRs, and so KVM must program the desired * memtype directly into the SPTEs. Note, this mask is just the mask @@ -446,7 +448,7 @@ void kvm_mmu_set_ept_masks(bool has_ad_bits, bool has_exec_only) * of an EPT paging-structure entry is 110b (write/execute). */ kvm_mmu_set_mmio_spte_mask(VMX_EPT_MISCONFIG_WX_VALUE, - VMX_EPT_RWX_MASK, 0); + VMX_EPT_RWX_MASK | VMX_EPT_SUPPRESS_VE_BIT, 0); } EXPORT_SYMBOL_GPL(kvm_mmu_set_ept_masks); -- 2.25.1