Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2244448rbb; Tue, 27 Feb 2024 16:05:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWsktyFbgOwtysUw6PL4FXeFi1NdfL/Fn8a8Me9JujwEl8RafkEwc+X0JSyhEO7zlHHjJ5IUHT32Jjf1+XFkbCJdXcI/fnNlpWdjLp1iw== X-Google-Smtp-Source: AGHT+IGE12cw/bIG9Bs/dLZoEBhE8gLpfHdLIH2mDqm8NQSU65rHBV25nohLK3BcqpzmEV0b4FFz X-Received: by 2002:a05:6a20:ce4d:b0:1a0:dc4f:ed1b with SMTP id id13-20020a056a20ce4d00b001a0dc4fed1bmr4231633pzb.51.1709078715554; Tue, 27 Feb 2024 16:05:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709078715; cv=pass; d=google.com; s=arc-20160816; b=MRj4/Jgwd5HEbIEanmaOG7Wh11cAA5HOltX4yIrctwKWC02Y+r3CYUuFfB+jiLnFvf Z36ACBmxFNLQYkEUEFcjOT8BKQPeO7yCqtO9Ltjp8XcJBWk3IC5ruBFNReJIIA27Rbhr XsTE/71UqTHh3dksBbiOsGzMCNImZfqCTrUh+Zp1Bz1V/zNBU1E5F74jVYQ+5JPk4P3k UqCAsF8M0d96p4kxua6MzdEV0x0swXCpykEdvIlDwwtAJTwc8lfZSGD2aNvuwkW38zsz FbDnXmQvMzLHgiijy46R8C/r7VWLeNIfIQuCa4aNOawFyVIB+Xafw60zQMtrzBYtQeTR RO5w== 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=fGS3MxnywIk2P3LLbijhge2gtItFefuPKT0i/X1AVBM=; fh=miuXyzfw5j8qsOURKCmYrSiXirUlKyDkR37pPJ+5+/s=; b=UGEbpixlBX2R++pb6A5ykZlp9v2GiiHBuI6niXhM2uIXo6A57/78thiXZU1N6KUauI wI/v8yO1T02eI+yBbIaORbse9I0PgOrBKVZRFJdIPoZVlGGG2BsXpK312Lk8pqbHl4l6 tDZHtBo82yIXWzrRR8s3Z1gY1Bf3U59IVDEzecOnqHY28F21EdBDSqU8neyJNqSH/Pi+ DD83wzihugdUL1ZC9Db8hmXQZPguJuaXTEGFX/K0qK0uRPSeg+7zanmY+zV2jmtvFiLU HjhfYjgr2JUyuUThscEDQ9rZrqV/NnKxBBYqwCW+QdOZ+1d+47stN/tz1OWDXzEaCDHj Dx4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="C/WRFAsj"; 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-84202-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84202-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id y16-20020a63fa10000000b005dc42014e30si6283650pgh.692.2024.02.27.16.05.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 16:05:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84202-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="C/WRFAsj"; 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-84202-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84202-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A31DAB2C395 for ; Tue, 27 Feb 2024 23:27:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5486C5EE78; Tue, 27 Feb 2024 23:21:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="C/WRFAsj" 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 C933B5786A for ; Tue, 27 Feb 2024 23:21:08 +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=1709076072; cv=none; b=VD3zSsSSPQkQVqo4277ZcsZf5+un+m6OAQFKAo8FcMLsUzj37TYDPQCaaNbNheyz7kKZCzk/CXKykshuLYawIpX3u5o3NoXQAl9LFdCw8Y3QgrokyfdrgBL5SKnacrQ9v2kqFoLDMC6QkcnFuGsTF7VgWjyHH6EKamUEJPceO5w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709076072; c=relaxed/simple; bh=AJ+B0FrHSNRu31IBbfmm1tYsIiofE/NifalgqPDy/Ng=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=fayO6sZaOvpZw33xsmilidcYw/6EVtSBk1su8eZnQSRMWmlJNf2GOPN46aUPctIxpq+ZV993lQ1KbAVHQMS0Nh68Dgl0aP/v3xtVvv1iE/qotsPkhjvnKM2/p51jcbHEeV5oNjcTG97+hagfco4/w0Ku95COT2eLcPXYhAY0FJM= 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=C/WRFAsj; 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=1709076067; 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=fGS3MxnywIk2P3LLbijhge2gtItFefuPKT0i/X1AVBM=; b=C/WRFAsj15Zy+2PtLsniaboCeKPetWhKp80UoPfpM+D7S8QEqGOGP/B0XbNSZhuBVjmlxX ACO4RxSZ+N1B0kaH5lnRyNzYqVvG+MSFrXs1rzLblNBjgbBBG7uL8h9lJ+UzpTE+I80wmR IUWvkOct6PZCELACLWu4aSZjjAgdwvA= 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-622-gpFf_sLQNOebo87RdrLyXA-1; Tue, 27 Feb 2024 18:21:03 -0500 X-MC-Unique: gpFf_sLQNOebo87RdrLyXA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 F33C13C13A87; Tue, 27 Feb 2024 23:21:02 +0000 (UTC) Received: from virtlab511.virt.lab.eng.bos.redhat.com (virtlab511.virt.lab.eng.bos.redhat.com [10.19.152.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id C65294EA55; Tue, 27 Feb 2024 23:21:02 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com, michael.roth@amd.com, isaku.yamahata@intel.com, thomas.lendacky@amd.com Subject: [PATCH 09/21] KVM: VMX: Modify NMI and INTR handlers to take intr_info as function argument Date: Tue, 27 Feb 2024 18:20:48 -0500 Message-Id: <20240227232100.478238-10-pbonzini@redhat.com> In-Reply-To: <20240227232100.478238-1-pbonzini@redhat.com> References: <20240227232100.478238-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.5 From: Sean Christopherson TDX uses different ABI to get information about VM exit. Pass intr_info to the NMI and INTR handlers instead of pulling it from vcpu_vmx in preparation for sharing the bulk of the handlers with TDX. When the guest TD exits to VMM, RAX holds status and exit reason, RCX holds exit qualification etc rather than the VMCS fields because VMM doesn't have access to the VMCS. The eventual code will be VMX: - get exit reason, intr_info, exit_qualification, and etc from VMCS - call NMI/INTR handlers (common code) TDX: - get exit reason, intr_info, exit_qualification, and etc from guest registers - call NMI/INTR handlers (common code) Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata Reviewed-by: Paolo Bonzini Message-Id: <0396a9ae70d293c9d0b060349dae385a8a4fbcec.1705965635.git.isaku.yamahata@intel.com> Signed-off-by: Paolo Bonzini --- arch/x86/kvm/vmx/vmx.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 3d8a7e4c8e37..8aedfe0fd78c 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7000,24 +7000,22 @@ static void handle_nm_fault_irqoff(struct kvm_vcpu *vcpu) rdmsrl(MSR_IA32_XFD_ERR, vcpu->arch.guest_fpu.xfd_err); } -static void handle_exception_irqoff(struct vcpu_vmx *vmx) +static void handle_exception_irqoff(struct kvm_vcpu *vcpu, u32 intr_info) { - u32 intr_info = vmx_get_intr_info(&vmx->vcpu); - /* if exit due to PF check for async PF */ if (is_page_fault(intr_info)) - vmx->vcpu.arch.apf.host_apf_flags = kvm_read_and_reset_apf_flags(); + vcpu->arch.apf.host_apf_flags = kvm_read_and_reset_apf_flags(); /* if exit due to NM, handle before interrupts are enabled */ else if (is_nm_fault(intr_info)) - handle_nm_fault_irqoff(&vmx->vcpu); + handle_nm_fault_irqoff(vcpu); /* Handle machine checks before interrupts are enabled */ else if (is_machine_check(intr_info)) kvm_machine_check(); } -static void handle_external_interrupt_irqoff(struct kvm_vcpu *vcpu) +static void handle_external_interrupt_irqoff(struct kvm_vcpu *vcpu, + u32 intr_info) { - u32 intr_info = vmx_get_intr_info(vcpu); unsigned int vector = intr_info & INTR_INFO_VECTOR_MASK; gate_desc *desc = (gate_desc *)host_idt_base + vector; @@ -7040,9 +7038,9 @@ void vmx_handle_exit_irqoff(struct kvm_vcpu *vcpu) return; if (vmx->exit_reason.basic == EXIT_REASON_EXTERNAL_INTERRUPT) - handle_external_interrupt_irqoff(vcpu); + handle_external_interrupt_irqoff(vcpu, vmx_get_intr_info(vcpu)); else if (vmx->exit_reason.basic == EXIT_REASON_EXCEPTION_NMI) - handle_exception_irqoff(vmx); + handle_exception_irqoff(vcpu, vmx_get_intr_info(vcpu)); } /* -- 2.39.0