Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp212602lqb; Tue, 16 Apr 2024 13:21:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXy+Z8J6MIBQHMlAV/3Yb8gp7DobHTgXDJMF6bpwClJQmk/1V75gbScNvmTRYzVsswMzzm0kqSAKi3iy5eNGQR1QK9o9/yMNyQ1x6bsCg== X-Google-Smtp-Source: AGHT+IGcOsi3eic4QPGWbehMwdQpJmPb/XwRu9AxF9X9wKsqjCZJIdjZ0FaXJKA5Y7k+ktMZzcSi X-Received: by 2002:a05:6a20:c886:b0:1a9:f2a5:6838 with SMTP id hb6-20020a056a20c88600b001a9f2a56838mr8758217pzb.18.1713298912201; Tue, 16 Apr 2024 13:21:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713298912; cv=pass; d=google.com; s=arc-20160816; b=zF+fN+hPf79nDUryMw65T7a9fpwa2yeGFQLb0+2gjU+LWIPCV8JeymJgp8r7A1MzCs LI9xpP8Vxrk5/rNCXvZ7CKjuC4cJZ7Kfls1OsNS66vofpTHKsZJAV0jdhXDqe3NKTlKT 40/ceg17uXDEX8LJjafx9F81f5UNbuw/xwyHwilRWySwwHsHA+CiFeADprt41k0XWHGf wWmDFmuN4Kbf4mK4NSH0PXPnKT7q9+ocTGifbOoXQI/FLye/IVL8yETmO0pI5pTGiOlr 9j69n/bHzi5GbFTBW8gv5HqEtNRHzmnmq5uAPRYQlHWCbZtOLdLwFy/1h3Gi+iDJgsrD di2w== 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=iRVZJpf95iM8a2spygqO8CfFJRsMsampTCJH+nL0n8M=; fh=kM0aiaSc/0bcKmeaNecUcPBkSFAAdFQ8DFGcHuH09bk=; b=ZwmE7UGZd8GnTTXZ1DHMT5ivunvDiiKVlVNziU6zYLUogo6d6hd9g70KzpJVfgcMRp 7n3powOra0EEAYLOgwgH2Z5CU/jDWavbi0IGW7/oW/Qbq6CIXe3nTOvM2mlDd0pOjfqF R93TotHhilnHDu6ab56cuJnsO6/zLKNN8bWYVms6Hf2KBCPxQZhn4yIDhwG+LWPT9fnU alcYKNVYLYBJIxczz30iSdDZHtlSxarql5rG4GaRgKf3YtkGzOPvbkFTzp26OLbrwtI5 4zpc6+n1WIV+SXpFA+KRA+YfJTeG8p/q527d2Qmru0TpfTzunNI29Lhqn9dqsz+NncmH CMmg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hPel3WWO; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-147509-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147509-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id v4-20020a634644000000b005dc962cfb64si10030383pgk.89.2024.04.16.13.21.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 13:21:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147509-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hPel3WWO; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-147509-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147509-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id DC6492831C2 for ; Tue, 16 Apr 2024 20:21:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7CBC013C681; Tue, 16 Apr 2024 20:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hPel3WWO" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 81CA313A248 for ; Tue, 16 Apr 2024 20:19:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713298784; cv=none; b=PT6XjMkPaMI95F14rVkiKlMxGtnLGy1gfuPrOg51zPJ7oosVdVr4UYWY86zMN4hPu61edA2+pP/WWZmK67uAONVKImDwK4LMu2ojPLpsdGTMGOW6RFBzcBaB98loVV7x3PeKshgFJrS8DM9U+Oa7Li+5s49Rdu/jxQZh3wNvPqM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713298784; c=relaxed/simple; bh=4HXBDWMcQ63we0cEK0lxOWQf5yGqFZt0BPuAapREAcI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IEU2LiDPmzsBttMEhY7YUXiqpv99anPBjOxZyJ+TbTMdRkKhWnzRiZbmCHWi5b1DmcNsJ/+DU8E+qgBjw+fIZXpn4Ww4tg5FMn41xJPDzTnzkJ54od+Sf11A8hVHaLxVMXkcIiUuRXgI3w1WE9AY5iiofX6P03G9GCbTOw6++mI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=hPel3WWO; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713298781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iRVZJpf95iM8a2spygqO8CfFJRsMsampTCJH+nL0n8M=; b=hPel3WWOjkbTgavmivlURu6Ep49REFrFcWXobjNi569EByYGdLQgMyTZWZr4QXimwLP/Xb ZDJr9fGqvJoQ2nKv41P1KRlQjEGzRDv/MWCku8Fw6BzxqcRvwjWPqHE/kpL/McQVIXxwM0 lH4pmicqVUoBA0bLODurLEPk0JHBIXA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-179-BEDDcJnVMe21fh3BL0OStQ-1; Tue, 16 Apr 2024 16:19:38 -0400 X-MC-Unique: BEDDcJnVMe21fh3BL0OStQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9171D8F7E20; Tue, 16 Apr 2024 20:19:37 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 650CD18209F; Tue, 16 Apr 2024 20:19:37 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, xiaoyao.li@intel.com, binbin.wu@linux.intel.com, chao.gao@intel.com Subject: [PATCH v2 04/10] KVM: x86/mmu: Add Suppress VE bit to EPT shadow_mmio_mask/shadow_present_mask Date: Tue, 16 Apr 2024 16:19:29 -0400 Message-ID: <20240416201935.3525739-5-pbonzini@redhat.com> In-Reply-To: <20240416201935.3525739-1-pbonzini@redhat.com> References: <20240416201935.3525739-1-pbonzini@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 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 defined so as to cause EPT misconfig. Signed-off-by: Isaku Yamahata Message-Id: <97cc616b3563cd8277be91aaeb3e14bce23c3649.1705965635.git.isaku.yamahata@intel.com> Reviewed-by: Xiaoyao Li Signed-off-by: Paolo Bonzini --- 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 4dba17363008..ac6da0a5f5e6 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -514,6 +514,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 768aaeddf5fa..0a0e83859c27 100644 --- a/arch/x86/kvm/mmu/spte.c +++ b/arch/x86/kvm/mmu/spte.c @@ -413,7 +413,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 @@ -430,7 +432,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.43.0