Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp68744lqp; Fri, 12 Apr 2024 10:38:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUnWZKkDouEZSwgy0lYVDU4oJat7e9ztOF6u70nOOczKJ+ye+/i3aS9M5tQP2r12pN1MNMcAfo76M5iG7+9VUaSvQA5CoFnWW1y9E2j8g== X-Google-Smtp-Source: AGHT+IGJZR33cywVtXkee8Q1VoseESG/N59fDURZA68hBQitkIXVPh+Au/anhWLqwAbK9+csxx7l X-Received: by 2002:a17:902:cec4:b0:1e4:55d8:e15f with SMTP id d4-20020a170902cec400b001e455d8e15fmr8680030plg.32.1712943500349; Fri, 12 Apr 2024 10:38:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712943500; cv=pass; d=google.com; s=arc-20160816; b=JDWuPTrMyyj9j+BAlwUxvWdGXW6BaqVr2eXLhzfBK3GVdIlotpsV5mm2Y8X9CKNzf3 Qs1yG7otfnrxYJxyRFYR+JUCzwUIerllNvLJsCwXJhgEi09gvpaw4PEu5gfHzCpiGJ8T oonOHEBw942N4oAkpYnBoCCtIL/BxnH93PdtiCKhMFlnU24JZRfEjkoovlYBluiXh0Fl blWnKrRfYB2vkH4YTwbnL9ax8Itxa3UU7inA+/hhzFg2u2WTOYPzb1LTXsljci6Ns4eP qYaimiWSD6pBUIAWRDRexWHiWYzXZQvJVkPtc81ODjwX85AuVQ34X9gRQmdH4wQ/hXF6 H2Gg== 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=MMoankSPnsr51NzQw3GN0rThmSlkSJ5vluBsBS+Wb58=; fh=YROXVl7EA7IsDryEHIf1cYujx3PkpU0umqFJu0pWgXk=; b=uFdJqFvL2tCaNdvdYhsPFsUW351p4xmAi6urFP4D6GFf251h6HKzXDrjq1g3VMzMlC BZTp+ctkj3xiB0cZX2PBeT1pDWyb8ujC22kS6Ozm4hmqwgCWPQL5+jGA4Gqdd40GJZvp Dw1apW5w3OjHOoU3q+cpW8RIrBiWFEjRxN2c/dfSRY/x6Lk4QHbHUT4nbj79Y1hFtBSB rNFYe8+c+FW3zyLpAKNv2pCym44aLdHImtAFUnSGDvX0I6fTfECoPDq4z6Mh5VkzVSCt xmL9DLvnj/bquYeLVFdCqA/xSnkeqA22coVCAvl/BvpjOBvxdxKkAlMkMtzli1dBNnBn pqOw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="EpTusK/v"; 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-143141-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143141-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. [139.178.88.99]) by mx.google.com with ESMTPS id p2-20020a170902e74200b001e29483faccsi3637603plf.635.2024.04.12.10.38.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 10:38:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143141-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="EpTusK/v"; 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-143141-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143141-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 6FCBE2849D5 for ; Fri, 12 Apr 2024 17:38:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A358F152DEE; Fri, 12 Apr 2024 17:35:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EpTusK/v" 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 AAC1A14F120 for ; Fri, 12 Apr 2024 17:35:40 +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=1712943342; cv=none; b=L3JNoTeG+DStpzNmzadTJzSh7UyaVIXdhuCiQ/v7wLls+4gXX37xc1QkQCFEfLveBf73uULjzpZrEVs0S1B0mhASmRd1E81ajtaswyKBATM0bCyISqjf/hhrN2UQn4kotuqMOLVlmyY/ZaLk+rrECx2coF0gWkaY036X0suH6X8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712943342; c=relaxed/simple; bh=1B/zUTkP+xSjtPWcsP8oG3U9mKuxHuCkDO5ODjKdKFc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AKKOmM2WHA1rqcqC8q1Ta582vppabmpz+tIy5d6GezFhRAyZQ5RJg9KQvTW02XVXQgnUrrizyPxhHoiYlRueg7gLnjmpWULkGnTtZCCeJ2zD/iMY0Rh7wKZTdox/b/T2sxkaIwY0wYBEupYXPykw6iyOZQcD2Lir/Qd106rD3QM= 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=EpTusK/v; 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=1712943339; 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=MMoankSPnsr51NzQw3GN0rThmSlkSJ5vluBsBS+Wb58=; b=EpTusK/vHZ7vMqT11GgO+DcHeHo0ZXp4FW98/w88q9qgOaERD68zDuGBQDP0Xs/fIL1Nyh U9YFH4EsBRl01zwEUI5P3S76LNLoBe18BYWxtrx6pQFeX5VHljH1vgp/slrpq5ry+MxaSV rHI2lthgkzBGUrZhFexp89lpd9251eA= 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-665-zw4_kvqcO7-rgx4dU9lCjQ-1; Fri, 12 Apr 2024 13:35:34 -0400 X-MC-Unique: zw4_kvqcO7-rgx4dU9lCjQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 D718280021A; Fri, 12 Apr 2024 17:35:33 +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 B58A1492BC7; Fri, 12 Apr 2024 17:35:33 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Isaku Yamahata , Xiaoyao Li Subject: [PATCH 04/10] KVM: x86/mmu: Add Suppress VE bit to EPT shadow_mmio_mask/shadow_present_mask Date: Fri, 12 Apr 2024 13:35:26 -0400 Message-ID: <20240412173532.3481264-5-pbonzini@redhat.com> In-Reply-To: <20240412173532.3481264-1-pbonzini@redhat.com> References: <20240412173532.3481264-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.9 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 6c7ab3aa6aa7..d97c4725c0b7 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