Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp67904lqp; Fri, 12 Apr 2024 10:36:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWi9AUKyAaoT9Hl88jPHjuhbeVD28EXaFY8MJgJNLySMDuKxuGk5/Vo1uM9n31Tcm5W66iJRERRDsjVdJVz6uK+wW0KtqPOnDYodk651w== X-Google-Smtp-Source: AGHT+IHAu6Sp6P9fW934xRhRKodGwdsmwRgejNG+00MRz5m6h9JXQaEqujhHBnDLB2Zgo2ULWl8W X-Received: by 2002:a17:907:5c1:b0:a52:2d83:1483 with SMTP id wg1-20020a17090705c100b00a522d831483mr2642481ejb.53.1712943406782; Fri, 12 Apr 2024 10:36:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712943406; cv=pass; d=google.com; s=arc-20160816; b=T0zDqnsSJPRrkWUXlMXQTCcidQSA/wB+cCdPyCA661PEF6xbOUTMB2aDc2SN/5ykKz Z6czAw2IF8iU+ZVB/p4nZcRpwra6OoKbdX9c5epKZ3NnZMlM9SPtjdhqONgtAAI5X/px UkHTCO7VOhx28y5cGw8ljgg7xYwkFqeDcxKwpq0oJj20c0mT6Mq7dcRGZ7ha2yjYECdo yAZKFyqnY+fg2CiAB8gyLBiRWtgc2Ew1deWIUYevlF9EiF/BB7969V1jmHSk4D/m93oN bnDMt7cYmJERWL02JohTIWpCuYmqPhvlr9JucTI/LzCIUjm1pzS5IEBDQVXlrhtLdfE4 XI0g== 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=HoJ35V3bK7vtXA0X0O/SFsr03fV4u8Q785/HuzrDGNA=; fh=uNHc+9rgYI3X/GDXN9kUpCMkEi2tyrh1IZT2BSZdqn8=; b=Bq87GjHToFRI0UPND49t0yDXSgxiXQbvWeJhUEs5z4/0tZ4ze/plczRQrTQwaYXbSq Myg7GvZ9H4b4IcpTDtkxEk4bnqF2MhcIBWHPPzmeO3ck/Qpf1kcjBp6obkYXpfUPnzEQ GYVBlm46aENlEiRZX8b2BAj9yPdRw8vRXgxt6Rg/fbhG1X9tI3hYm/repks5RdLctGm9 TifuKMB2wpPqYhbgvJjx+TGC9qDj3GaeOFnjg5aaAPj9LxQGx4aAN4OoohtrTVTbSbJ8 Q3uIrOjXLUcxY/6th0aTznlnp6idGwC/TwmIr3phlB9EZf9Zas4UW2UekLS0H91yjjFx V+1g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="J1/IHz/u"; 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-143137-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143137-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id jz7-20020a170906bb0700b00a51d9c747cdsi1821948ejb.124.2024.04.12.10.36.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 10:36:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143137-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="J1/IHz/u"; 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-143137-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143137-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4BF2F1F22D30 for ; Fri, 12 Apr 2024 17:36:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65B9D15098B; Fri, 12 Apr 2024 17:35:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="J1/IHz/u" 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 7E5AE14E2F9 for ; Fri, 12 Apr 2024 17:35:39 +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=1712943341; cv=none; b=NPPjeu/sNES3SgHATLJCn2sAWMVhr3H8pyCjqBZQLIzVmuvlSXXa9OWv+ua+mxieXkeX/RN4VgSn7GKjQybw7Kd2Qjg2X9FZiSCS7V9VUR0CAMiPwUPPUstQBv8fK34fVWJnmc/vhr9vdxE8bO5bJtWtZQcqN7bGYKYxKDb6mCg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712943341; c=relaxed/simple; bh=cRh3sCBdYdnEY4iJS5esOzxtTwTnGj6KPOCuuhvLsh8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QRQhDFXIh6Qfxt6IgDTwQMCXbfnCN2e4guvuE54nNi+Ao01Z93o0p06ztxesL0i9TmAm/e1LPR+cf0oxrRXaOFIp8O3Wn+iDwFk3XyqM5Rc0DgXyt3wZKFEvY1jb64/OSHBBKXr6amvLWsjfkmzaQRHJQ9P+HCGRs1c6mScQXh8= 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=J1/IHz/u; 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=1712943338; 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=HoJ35V3bK7vtXA0X0O/SFsr03fV4u8Q785/HuzrDGNA=; b=J1/IHz/uTDMt5r3pt/pdb01KPluydgAIjwwThzKr0uM6wKc59GHPWoNtOLLy3EUx0JYk8/ gJulzJ5uDIace/ZH9swE3mdDyWl16bWudlKkdy55KIrIR2CoIDvUfihuOXBU8uClxYMIyP bzbnXvzfwcUSFyd+SP1tSyhn+lMojbA= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-20-Esz3XpneNnyVEafpkas1fw-1; Fri, 12 Apr 2024 13:35:34 -0400 X-MC-Unique: Esz3XpneNnyVEafpkas1fw-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 AD3EC29AB3F3; 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 81801492BC7; Fri, 12 Apr 2024 17:35:33 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Sean Christopherson , Isaku Yamahata , Binbin Wu , Xiaoyao Li Subject: [PATCH 03/10] KVM: x86/mmu: Allow non-zero value for non-present SPTE and removed SPTE Date: Fri, 12 Apr 2024 13:35:25 -0400 Message-ID: <20240412173532.3481264-4-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: Sean Christopherson For TD guest, the current way to emulate MMIO doesn't work any more, as KVM is not able to access the private memory of TD guest and do the emulation. Instead, TD guest expects to receive #VE when it accesses the MMIO and then it can explicitly make hypercall to KVM to get the expected information. To achieve this, the TDX module always enables "EPT-violation #VE" in the VMCS control. And accordingly, for the MMIO spte for the shared GPA, 1. KVM needs to set "suppress #VE" bit for the non-present SPTE so that EPT violation happens on TD accessing MMIO range. 2. On EPT violation, KVM sets the MMIO spte to clear "suppress #VE" bit so the TD guest can receive the #VE instead of EPT misconfiguration unlike VMX case. For the shared GPA that is not populated yet, EPT violation need to be triggered when TD guest accesses such shared GPA. The non-present SPTE value for shared GPA should set "suppress #VE" bit. Add "suppress #VE" bit (bit 63) to SHADOW_NONPRESENT_VALUE and REMOVED_SPTE. Unconditionally set the "suppress #VE" bit (which is bit 63) for both AMD and Intel as: 1) AMD hardware doesn't use this bit when present bit is off; 2) for normal VMX guest, KVM never enables the "EPT-violation #VE" in VMCS control and "suppress #VE" bit is ignored by hardware. Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata Reviewed-by: Binbin Wu Reviewed-by: Xiaoyao Li Message-Id: Signed-off-by: Paolo Bonzini --- arch/x86/kvm/mmu/spte.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h index 0f4ec2859474..465fa283326b 100644 --- a/arch/x86/kvm/mmu/spte.h +++ b/arch/x86/kvm/mmu/spte.h @@ -149,7 +149,21 @@ static_assert(MMIO_SPTE_GEN_LOW_BITS == 8 && MMIO_SPTE_GEN_HIGH_BITS == 11); #define MMIO_SPTE_GEN_MASK GENMASK_ULL(MMIO_SPTE_GEN_LOW_BITS + MMIO_SPTE_GEN_HIGH_BITS - 1, 0) +/* + * Non-present SPTE value needs to set bit 63 for TDX, in order to suppress + * #VE and get EPT violations on non-present PTEs. We can use the + * same value also without TDX for both VMX and SVM: + * + * For SVM NPT, for non-present spte (bit 0 = 0), other bits are ignored. + * For VMX EPT, bit 63 is ignored if #VE is disabled. (EPT_VIOLATION_VE=0) + * bit 63 is #VE suppress if #VE is enabled. (EPT_VIOLATION_VE=1) + */ +#ifdef CONFIG_X86_64 +#define SHADOW_NONPRESENT_VALUE BIT_ULL(63) +static_assert(!(SHADOW_NONPRESENT_VALUE & SPTE_MMU_PRESENT_MASK)); +#else #define SHADOW_NONPRESENT_VALUE 0ULL +#endif extern u64 __read_mostly shadow_host_writable_mask; extern u64 __read_mostly shadow_mmu_writable_mask; -- 2.43.0