Received: by 2002:ab2:7104:0:b0:1f7:f6c3:9cb1 with SMTP id z4csp22325lql; Tue, 7 May 2024 08:47:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVLLg5WHSkFgAIr7dHvCnO06wUL9FgUfHhNjbrxA4QRrACi4snUM5RMp5MZRJFYc9aUERosj5ZnS4HBrJcCe1PuNxjKcdbM0H0tCex18w== X-Google-Smtp-Source: AGHT+IHrVk2W2G9A5T4spYbG6BN0+oG4jB8Jai8YjKHk1pG2zPFJFDyyxBj+1hgoSSErInGPVNTr X-Received: by 2002:a17:90a:8a0e:b0:2b5:9534:56d6 with SMTP id 98e67ed59e1d1-2b5bc4daf3emr3797505a91.24.1715096822476; Tue, 07 May 2024 08:47:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715096822; cv=pass; d=google.com; s=arc-20160816; b=PaX0fZEQFSvHmKRXZOzHXDtOzgenusvGbjZvMGoJEm2RXJDzRAj6ANP5tWJvzTz+hM O6nPLoWscy/KPDgFbF1XtC9a7Qp7WETNMX+m/Ej0NZ1NDmHtMC8nuICRaU057mk55fzy n6RC/1HwJJVZ4htIWZUQd13VRn3R62wYaavXbj8OdIMhAuj19++S0qMgFTEdnciK3pa4 F9vcu++MLp4JEcy7wDS0BuSmbNps7r4lfPNzLAqxQbpXB/z6GcrKwXPqH5lxj4WSCwcY HLWeNwlXd/RDTFOthjHM7hTLKJLrutqr8UGvLj8/K2APunLc7eqPXX+jsm2QmquFejvw 7yVA== 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=YROXVl7EA7IsDryEHIf1cYujx3PkpU0umqFJu0pWgXk=; b=qQy84yThqzRj50T4EG4y8T1p2FWC3DNAowbjdt3kX52MHedEp/b83OTppOfA8KV8IZ 9IivjW2cr2dwnZIRNWWCuNKp3Kt5uaOkL0ZTZAkh97zZG3Ep4Oul2mQvuoj0pSGnIRnP odTWHLeH83qnEHFiYJFHF9BhxhjNF/sgBVDYqV7XNIGoVCfoSLf8zE7HQ/fDXkwtP9N6 uPoy/5oGgiQyNnKErGwetRhtjkv4N0b4+lSA+HWfofr2C4qJqu5f/jbaRYg3y5ldlsgR GCmkC2Xd7dlYTCJNCUKBZW+dFAjO9WrqWv+6LDBhZQSiyef1v/f+SLCZfuYVJxgLHd9S VS1Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bkCuAjeY; 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-171714-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171714-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 nn14-20020a17090b38ce00b002b4fcfd7253si6136643pjb.16.2024.05.07.08.47.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 08:47:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171714-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=bkCuAjeY; 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-171714-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171714-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 DE16F28633D for ; Tue, 7 May 2024 15:45:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A59716C84B; Tue, 7 May 2024 15:45:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bkCuAjeY" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 0D34316ABCE for ; Tue, 7 May 2024 15:45:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715096707; cv=none; b=jqghYRWQkxTELKyi/adroP7/MUXpdlIROuMqk7ZOayz3Vu/jKybAyKgLzpPdDts5WrdRtuKtWS9O8ua5FrIKlckDVlREVRl87JK67xO/63HZiKjyqDY9IUlTVMJl/eTa+X9I+9hSeNQ5uw9a+pDTmOfj9NXdZvMVJ1cewMrV2P0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715096707; c=relaxed/simple; bh=4HXBDWMcQ63we0cEK0lxOWQf5yGqFZt0BPuAapREAcI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Z9iPnECk6oeWKq+cpVUsFccLc1SNXPNja1Sr3bPil1ibfatov8Mu22ut5N3Wvm3rZ3i3qfNz1b33ki2OXoGPYwHnAJZyHDAkvmFRLc/zhoQERxs/lU9N+t795R3JuzVC6x/bRSOoSep6sv1WKOE8Lbtym6yMRIKtcudVrObDtRA= 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=bkCuAjeY; arc=none smtp.client-ip=170.10.133.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=1715096705; 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=bkCuAjeYN/Dh7iv2sY6HVDBGEOY9mjLb1CI7JEw86Gn1Ka1ac7nXNWMKeS3sgZf+ISiwlX ecLLUBmAZSOq/g41iarvLfeb/FMzjRxSikv44aunpCoARf9kmMKoagRb4vzsXLrS8C6xoJ RMTpHAp4KDgFf0hsXH3nXcSWEA9wPiM= 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-284-tkMVwKYXMVOVqBQaGEr4rw-1; Tue, 07 May 2024 11:45:01 -0400 X-MC-Unique: tkMVwKYXMVOVqBQaGEr4rw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 6B174101A553; Tue, 7 May 2024 15:45:01 +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 4A30BC159AE; Tue, 7 May 2024 15:45:01 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Isaku Yamahata , Xiaoyao Li Subject: [PATCH 4/7] KVM: x86/mmu: Add Suppress VE bit to EPT shadow_mmio_mask/shadow_present_mask Date: Tue, 7 May 2024 11:44:56 -0400 Message-ID: <20240507154459.3950778-5-pbonzini@redhat.com> In-Reply-To: <20240507154459.3950778-1-pbonzini@redhat.com> References: <20240507154459.3950778-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.8 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