Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2620182rdg; Mon, 16 Oct 2023 09:35:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+GG0j7uW803Hf7Ti1TXmOERTIjLY8DMOiidPKgrQke5xjTibq8IWeDGcFL9JuVeBvlfnt X-Received: by 2002:a05:6a00:b8b:b0:68f:d1a7:1a3a with SMTP id g11-20020a056a000b8b00b0068fd1a71a3amr41909400pfj.8.1697474108906; Mon, 16 Oct 2023 09:35:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697474108; cv=none; d=google.com; s=arc-20160816; b=ffYZ2HtrDQ2AnR1Pf7OhnCqvO79jl1jf5vgv2yuN0xswQyklHxdBAVJr2CkdfnCPl5 2KRLeIWzti9+linr7fAD3G6UjbYASHm9F3/0kw7coh2fgEyU9jI7/Cne+Yz7O+inYPx0 sQHFBq32DFs29+fu1+BH5gCapUWfZwlX61hGbkuT/BVqMdRbj58BJ5IzHM2mkIehMwLA 2iXgJB8NG9mnu9yryhxTY49KFLE0XQrWy+5p9dwXpALRQ7SOTxyvuZOskRJZzluNco+6 1oUbkhdSgFbKsP2y6XGqBiyM7R9oe+3ehcvU6P/hnj5CgQRYuJCLmeN3pOvzVqz+qHNR w+sQ== 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=alEP129vZW7yLpfnZQaK7izaUPiEGpwuA6qxvUaBIog=; fh=lRdU2Q/1zx5DcPdZuWBjshA5VT5Oc9cEhB1tCFiV0Nw=; b=x+eKfa3OU9wgzgQZnWZEIiNvmG2XiUBIk8KjJgbX9a/oPXPNwSA13ac0szR9+B/gb6 S/14D45b4dB9MOlwdbuLRWpIdl+gkCEJ8Cxi97J66TrhHuKjQ1wwp8UZS5Zp898XOe+5 EvTmIXebJ97zL8CiMB7iq9UVqzbpYyTCnc1fvczhT5V9cdvg7UHDrzHxdCYhfnu7nPV/ JY2anhFGbHe72Acy7/ymdUWEnSjmpaEAubm6pxK2mdHa1xQ7czGYOd8Z3BOUeyJEY0t8 G9+S/36mEP2gkyxk4VyXwh7vmLEPu9Xyzm53bqp6M45xIUYuG/tenrpCFnh3xt33/yCp YYag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TCy2E1fe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id b123-20020a62cf81000000b0068a85532963si145370pfg.160.2023.10.16.09.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:35:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TCy2E1fe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id A752D8041948; Mon, 16 Oct 2023 09:35:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234253AbjJPQeb (ORCPT + 99 others); Mon, 16 Oct 2023 12:34:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234135AbjJPQdu (ORCPT ); Mon, 16 Oct 2023 12:33:50 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EE237EC3; Mon, 16 Oct 2023 09:23:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697473386; x=1729009386; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/QQnC6NuR+jveGFHm7lY9Jr4kJQvgq3Qc9nLEe3cDso=; b=TCy2E1feL1nTrgIFZccfLu7teKoTixr9lUvoH2unOoGUNQIRpcGmtfpn aO7JY6efsUTOwqdrrqQvmYxfqZ165jEpwiknlHnE11vrQtOCdm5Igqwwa mboV5O3zJGjAveyKvuhxrLpC3187b+IrdRA7vCXuwUwy2r7Ywpf15g88c s/7vPKVs7ensYuSTF6EW7+M6l87jo2lM2fHowkLMI+Hy9TCfa7CaddvCp CksJZpjTaOOzfihHv9eh3uS3cm3aajGiXSosmvqj2akUWmXRjx4nkXVlJ qxMaMpC3b3WJ6JRklO79nBOio01dIXagNWn/YaBujpkvMc6gSxZ+FuE6A A==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="365826055" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="365826055" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:15:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="1087126113" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="1087126113" 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; 16 Oct 2023 09:15:37 -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 v16 034/116] KVM: x86/mmu: Add Suppress VE bit to shadow_mmio_mask/shadow_present_mask Date: Mon, 16 Oct 2023 09:13:46 -0700 Message-Id: <636b8a6b783e54924fc9e12816758926d71ba62c.1697471314.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=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 16 Oct 2023 09:35:05 -0700 (PDT) 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