Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp249590rwb; Tue, 25 Jul 2023 15:21:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlG4awKoVB+/PVoig2OFjD/O28mpI4YlZzXA2uBcs61J4Q/Mnxi5FZNqzs1c8NLfjsJ54GFm X-Received: by 2002:a2e:9cd3:0:b0:2b9:514d:64c1 with SMTP id g19-20020a2e9cd3000000b002b9514d64c1mr92344ljj.8.1690323683491; Tue, 25 Jul 2023 15:21:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690323683; cv=none; d=google.com; s=arc-20160816; b=XZd5nhVe94yZYAUA4HViFvVbbf/CNOZM10jmt6IA1BMyFvge/L6BY79FEeC4HcAAdZ 7zMGNeM/yMeA3DkgbRpzbbUHwWXROeXj/0bVN41vi8YG6yQ855dy/96A0lMJoSaXhtHi IMs7R7ZDYHty2TdglZ1BUzNlStcX7kG159YgRO1Hj5evz+TskgoTD8FIZJvrmZzfX6vf JT2fn/wdIK/jiQlzel8qh4BR8vibBN4XCWl6+3Ppnby+tbYGtV8NpEX6FJKeyYG6ZktM kbAMJ+eP3avtTBwrFtQ95gKmVCFm3l402lkfjvTH7xfm4WHO4LPIboirbLlDLkmGxlEw GAfg== 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=/xwYo+RvxYhYeJLsBzShC3L9Eqwb86fHUEdr3s3QyT8=; fh=juxwNcA6iKwLISFgUCNwdoIYC0NKLUseq3xZdq25RR4=; b=xQUaw1Rmy5gtgNsclxVQ6YEbHZSO1CHxyNXdZWgTtQVTHMgoXw202Sftx7YspycSxE IiPlevpfHuST9VndgUk6CM4HtTuxZR69/3zArCsFiSESByeXekgaOcfzPoNaeByNyVXm gtHfx7BtW0EAg60Z/gCKm1fnsg0XHJanyaanpyzJAYmatcGfZe7neMJ8APTeQpNAXgRo I9y/IRuoMj+MhO7MzPCmMOT8A5UVmrZTpt+GoLlVTcp6ka+VkidErC6WV2lh6yUTocw7 lsBP4bZ+lAW1s2JvLAESOQUO+1WYFMmc6OddYb1kyve6u4FfKTfP1h1fv1DmtHqjwFxS 67Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WMUMRw7N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xo17-20020a170907bb9100b00992aea2c6a6si7941707ejc.977.2023.07.25.15.20.57; Tue, 25 Jul 2023 15:21:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WMUMRw7N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232146AbjGYWSu (ORCPT + 99 others); Tue, 25 Jul 2023 18:18:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232260AbjGYWQs (ORCPT ); Tue, 25 Jul 2023 18:16:48 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 524283A89; Tue, 25 Jul 2023 15:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690323356; x=1721859356; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rMN2DEXHYJg4BrG9HywFW+dJdkWtkQ+SIXgNGj4Zeac=; b=WMUMRw7NWl7j58VdYCFtdDJcAE8WNVU87dmqsu4mv3z/I50vIZYhAbXi ldBHBW2J8YSALFajKsjnR5xnfB44S0DzTW+dWr1V+wo6Xyjw5l/48lK80 lna6HYAYnE8FHo91ZPEK5bFDsHXk9ApiEDawNOR+lGZs1goH3vMDyBgva aDVJNgrBoRAXB49TtIUaV6U3V1MsFdnWGoemVhgQQNQcBmmeJOJlZ5FxO teThQYzeuloaaV/oY2heNJvHPaoUaueIjKLL6eoEAXBBJgLOzIZ96Bw6A +SS8gAIaKn4sLQXSigRUuPQM2oEWBEaLssSQgd2d5va6ssfXO+meU9SPe A==; X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="357863223" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="357863223" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:15:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="1056938895" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="1056938895" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:15:33 -0700 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 , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v15 034/115] KVM: x86/mmu: Add Suppress VE bit to shadow_mmio_mask/shadow_present_mask Date: Tue, 25 Jul 2023 15:13:45 -0700 Message-Id: <0c46520f8f0ec9e3867cc79d61e49550e0043f12.1690322424.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 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 0d02c4aafa6f..3066ca5ca246 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 cf2c6426a6fc..778fbaec1887 100644 --- a/arch/x86/kvm/mmu/spte.c +++ b/arch/x86/kvm/mmu/spte.c @@ -431,7 +431,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 @@ -448,7 +450,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