Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp559432rwb; Thu, 12 Jan 2023 09:18:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXtcGgCQcjcvn1dXQ/73L2j8jB5wcIztX+FqKRlijpgGhKBw6+erbxNOoG40qFaegBGSN79j X-Received: by 2002:a05:6402:5407:b0:47e:d7ea:d980 with SMTP id ev7-20020a056402540700b0047ed7ead980mr62850048edb.14.1673543919026; Thu, 12 Jan 2023 09:18:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673543919; cv=none; d=google.com; s=arc-20160816; b=xgmcejkdhwpVhMBf3Qzxgd0e08aXRTvYQWuDEolm7bRhBicmu9s073jfxPmqtg09c8 bet8jC5VqyYzyXa2R9lh1COoLNtzB2M28i9rjt0KZwvr0Wzqe1VcNxkRpg93hFgDXZsi M2zjN+lVxlRb/vnvdtTQ55Qas/7CWMLgmQtdyWTuC5U93UvV6YnyskYcTd4HXwhEKX0r eLKEQywGZV3JJTcf+N6ye/ELVQKD3s+CM+eos/ZxwiewfuOEYhKES+BCjIjUVO9wsdOV eGGvCT+a+O0h/nfaVIFlEgjqA2a8DHVck5TKFvKMXj5KlhS5Kq6jDXqJ9Wbe9BtBK8Nh 1ahw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2GDu7IxAZMgjaY2wH+0Jek/zS8fhh+NWHMOviWMIIKk=; b=v1KFKYjc1r5ZX7v0hziNAKHNOumpeMtZkYTaKY5WvqQP9B2KDwoioXjmuISRZWamrj S7r+7Pq93qNcc+U4PLEh6FnY5acMglVbn3xz/T7MV8ApL/MaWESduR2uc9Y+OMBHI8Gr l5iXH1IGUZA1hSVOTVaD1euu+AVREqtWQG9qXzvXah2eDcf4049mwe1ZWvdolW5Dj5Pf UIy2zEwhEiQGGSaXdjAq0DBkqyDEF0uMDcyVSjn8g5ucQqbtujwV3ZO0eUrT0RrKpw2y OKIyMGMNlX1mUMIzF0kDDcUVUzQrUFxbVoOtYT+wo5mXYvTsOzFLf2NPfBSsadfyysMH elRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bfXukyS2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i23-20020a0564020f1700b0046f9bcabfe6si978172eda.601.2023.01.12.09.18.22; Thu, 12 Jan 2023 09:18:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bfXukyS2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240221AbjALQie (ORCPT + 50 others); Thu, 12 Jan 2023 11:38:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234936AbjALQhR (ORCPT ); Thu, 12 Jan 2023 11:37:17 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DB22BC83; Thu, 12 Jan 2023 08:33:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673541219; x=1705077219; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hHXfZWBO3i3gmjASuR43Qbpq072vooXyFmyTXZZjivc=; b=bfXukyS2bO62gH+JZSabaSeVp2tpSDNCly+wTcL9APv55HBKlYZ9+e7X 2BKSSfvZJIv8PSuv/oj7gXU7mtHgiGekCUszm68ykOLNFwGzJWr5TLL36 5xW90Czz/A/USi1mXLAfsGOXFf9cYhwV3WN+f5M1gFMYVT4dtRL8TerJy 3VCjgQSPjZw4hRROWSEkeDTG7E05QibKJRr+7baZdG7meLMGo+Nlj1km6 1TPCDVSUIuHyMIYqAnrXIKChzNMxlVC7sKrjMVfcfG7Y3ZJvg2U8IpzEJ I36LRxYjc8zY0jlOxlWv6RjZejHgcxtPBrNSySzvTJqc0AUISkZ1V32nE w==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="386089666" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="386089666" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:34 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="726372511" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="726372511" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:34 -0800 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack , Sean Christopherson Subject: [PATCH v11 081/113] KVM: VMX: Modify NMI and INTR handlers to take intr_info as function argument Date: Thu, 12 Jan 2023 08:32:29 -0800 Message-Id: <8fb7861e935b0558bff2948abbb572c83aec40dd.1673539699.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/x86/kvm/vmx/vmx.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 051952544375..63cff4d02211 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6919,28 +6919,27 @@ 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_nmi_irqoff(struct vcpu_vmx *vmx) +static void handle_exception_nmi_irqoff(struct kvm_vcpu *vcpu, u32 intr_info) { const unsigned long nmi_entry = (unsigned long)asm_exc_nmi_noist; - 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(); /* We need to handle NMIs before interrupts are enabled */ else if (is_nmi(intr_info)) - handle_interrupt_nmi_irqoff(&vmx->vcpu, nmi_entry); + handle_interrupt_nmi_irqoff(vcpu, nmi_entry); } -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; @@ -6960,9 +6959,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_nmi_irqoff(vmx); + handle_exception_nmi_irqoff(vcpu, vmx_get_intr_info(vcpu)); } /* -- 2.25.1