[09/21] KVM: VMX: Modify NMI and INTR handlers to take intr_info as function argument
Message ID | 20240227232100.478238-10-pbonzini@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-84202-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3025766dyb; Tue, 27 Feb 2024 15:30:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWsb/sULLnuupEQp5UGdwO9xO9tE/EuyONPVhg9mj9zc8BT7KRy5bXWqtVsGTplPRXJCVAKkaRadCDm5hYZ6O0ZCOq67g== X-Google-Smtp-Source: AGHT+IGnC+6NrQvnCPt6TwQgRwCIT7FHBMOZLBq8MfXSQfhnbySOiat+vlraUFkMN2adGiuDekXF X-Received: by 2002:a17:90a:c20d:b0:29a:12c9:9ca9 with SMTP id e13-20020a17090ac20d00b0029a12c99ca9mr7061249pjt.47.1709076640890; Tue, 27 Feb 2024 15:30:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709076640; cv=pass; d=google.com; s=arc-20160816; b=Y/RN5viY/sAiKUZz426a3kficQo8zUZ1iEtmKWEuFhUc6CqsdVWgrjWN9+Ad9/CS5Y fAaC9Xc01Bc2j6sVtzrPm/L9gjfXZJRV4/xknjBLQ3tWtl9cN3xBKgezw48tzGhjK4Xw gZZaLFNrLzZoQHvKN2u3REmS1JA3arfk8w8gY9HiHpCChBrMqYZSttrUMDTRN2IMNiPK D78zIxUsEx+ewPd11i1aWjAqbKg7KlDUTEnaRh5Irlx0GwO3qTojpF8IHOqNgDpnM55k d10Mdc/l1pl3thAixa3OeFFjQrVhIQyGw8k+jJJqKUa3r0TyYA9i/vPe4Viu8LCbZ41D j6oQ== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84202-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id rj4-20020a17090b3e8400b002994aca0f01si178321pjb.39.2024.02.27.15.30.40 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 15:30:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84202-ouuuleilei=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="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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84202-ouuuleilei=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 C3D6628FDB7 for <ouuuleilei@gmail.com>; Tue, 27 Feb 2024 23:29:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9FEF45F86E; Tue, 27 Feb 2024 23:21:19 +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 <linux-kernel@vger.kernel.org>; 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 <pbonzini@redhat.com> 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: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792096748195610389 X-GMAIL-MSGID: 1792096748195610389 |
Series |
TDX/SNP part 1 of n, for 6.9
|
|
Commit Message
Paolo Bonzini
Feb. 27, 2024, 11:20 p.m. UTC
From: Sean Christopherson <seanjc@google.com> 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 <seanjc@google.com> Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <0396a9ae70d293c9d0b060349dae385a8a4fbcec.1705965635.git.isaku.yamahata@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- arch/x86/kvm/vmx/vmx.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
Comments
On 2/28/2024 7:20 AM, Paolo Bonzini wrote: > From: Sean Christopherson <seanjc@google.com> > > 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 <seanjc@google.com> > Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com> > Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> > Message-Id: <0396a9ae70d293c9d0b060349dae385a8a4fbcec.1705965635.git.isaku.yamahata@intel.com> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> > --- > 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)); > } > > /*
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)); } /*