Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1176555rbb; Mon, 26 Feb 2024 00:44:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWgS3OSx+Ko2Qncx2smDUGJaTxrQPKRVSfc9dwlqQ+o5htjVopMw0MK4AcNUyZNkw53lzAB6d2Hbym1ps8xexVR5NOqEkO+BmPpzMdhKA== X-Google-Smtp-Source: AGHT+IGI56a/knEVnhhWcuAmTkHZcBmNHVF7LqlUk7fBKL8OwAdmnh+hrBngJzunWfSaKgpGyBL1 X-Received: by 2002:a05:6102:f0f:b0:470:547b:6f98 with SMTP id v15-20020a0561020f0f00b00470547b6f98mr5052673vss.18.1708937044157; Mon, 26 Feb 2024 00:44:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708937044; cv=pass; d=google.com; s=arc-20160816; b=oT6y2oBTlHN6jDA3dPquhFc3MfVUnXI0XWEpqNgf4wabiZzfp5J1HMIRQ0BW2x7wz/ NijZYErDjyl8VKq2M9FV2pAEImFdqaePj1humTb6k8Qr0URF1WmAOrZJfNyFeItYSFFq +n1Teggn1ANvmA4LFdOACQfvLeWe4Wvl3pxPO/gWj1AtJF4DfVEDog45NeZ5929f9aIW WQL4oZ2Bs9GscKBiC1zuMHeVGPcu632xNNVgCyJ3EQDOgHmCFZaGoZZfVWk1kJ2aGcr5 i2a1eYWaakZryudnF+MCTZr5VLLy4Aacc21c5d5mMCZ0VwmDOMpTNpGXphqibd0kDjrc g+Nw== 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=rKr05kun9Ca/Es/b/4++SeTR3+NrUXt1CWs368DBPIhSwu1z/81BowGAYPdDSFCVzr q9H6QFAzxbX6qz+LrZKm7pZbmzGpyvhH4S3ECQREhSUexNDcJhPEEeUoMBUlLCJHOv5m IWXRk1q4yA5SBOwdV8q1kuIBL4XurWT24CUrYdkDh7zINgM7LbUm++1EQlXuEMmoFKR2 DJARaw3eJnsUDj/68Atru+9UT21nhOP8HdFUz9XbHPtOzztP1zuM7yN7OGoFT1a2PGYv iCrrOPTHIz7sF6TQ0inHP9BZFf+QPUm/PngT6xvVXiODiS6pW0ZmXpApR6T6OqEAYb8r qQtw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Lb72AzBs; 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-80812-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80812-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id vy6-20020a05620a490600b00787cc06dc29si2846458qkn.319.2024.02.26.00.44.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 00:44:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80812-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Lb72AzBs; 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-80812-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80812-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D56081C218E8 for ; Mon, 26 Feb 2024 08:44:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6378B5FF05; Mon, 26 Feb 2024 08:28:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Lb72AzBs" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 35B665F853; Mon, 26 Feb 2024 08:28:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936098; cv=none; b=qWXeDc0bX5k7xghLPNS/7Ve2TKI2TWspeanuKomPC3PXnQw6W7u01ZwkmTdbO3e97yMhFLeauECIkkAiRKgSF5kVtFTRaOC98mfsJAUmOo+ssY+YDvw+QHNs7VANamyLOP24KsX15zOEu1IlYNAB9ArJh17HOniNALPXhoTprMk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936098; c=relaxed/simple; bh=/QQnC6NuR+jveGFHm7lY9Jr4kJQvgq3Qc9nLEe3cDso=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IdI3TIPqChpP/iokltpRsSNrb2NWaZis22YZlkr+bFaSw4jrStJsvtAqREh99vXI4m7/qJ8T4R9RRryh7Kh445bAE/qjm78BahwsOiRhJEqfrRkFcjremKFUMZWDhYtxbXwug62fOqiBVALyVXzTRJ3l8M8U0Bh0XeqMp9ooBTI= 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=Lb72AzBs; arc=none smtp.client-ip=192.198.163.13 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=1708936096; x=1740472096; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/QQnC6NuR+jveGFHm7lY9Jr4kJQvgq3Qc9nLEe3cDso=; b=Lb72AzBs6KSkDvVgrO7QyqpivCvt1HSLoGV3o6ud0CDDhv7GDaK9EgRx 4OoAvEJkGs0zf/sJnXZm8HWYm1d1HjijIvITNN+FnM5f5GhHvvTlUkWRL r/eNTG4yPqPfj3zZZZHqbvZAGOHJW+B8G/4TfffA2MdMIvaCZhrcq2TpB XR6BBfgY9ti2cqYMXXRs5wHJU9OHmTUt9oCWH11IyzMUFFZt4Ozuct4Lb 5SSzxjHhmLYtvVbO1XKNzgQm8hmR7MMLgrJymcwkNi14ZJ6A1ynEC0vwk WS75WXtfcy5RQlYRpqe8y47JjayMDIbrX8iEaabVhZB2P5JBWMmNLHHe7 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="6155382" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="6155382" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:28:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="6615809" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:28:11 -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 v19 051/130] KVM: x86/mmu: Add Suppress VE bit to shadow_mmio_mask/shadow_present_mask Date: Mon, 26 Feb 2024 00:25:53 -0800 Message-Id: <29a80b4fef28dad24e6366f2f707fec5266875da.1708933498.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