Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4117654rwb; Sun, 7 Aug 2022 15:33:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR7NawU9OadtNO5f2YHUjP6HWeZO7HTK5yjHju8+7qtjbaPyuttx10W6kqbGpzMJfmh69eTN X-Received: by 2002:a17:903:11d0:b0:16b:80cf:5d9 with SMTP id q16-20020a17090311d000b0016b80cf05d9mr16264846plh.91.1659911598072; Sun, 07 Aug 2022 15:33:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659911598; cv=none; d=google.com; s=arc-20160816; b=bqyGAO8PbWKs0B1yz9SQH2YwfOL62YModiuesW+ugnCsaJ9WHifT+lsT3krazs44q3 un/3nz8Q4YTj44CEV8/PyuMBbHN6NzAV5QFiye3PPiWz+E9amXZ6JQt4Xy+zJ0g1E61t BpEJfcaW6y0xb4wxVBdLwdDul48RvrCjm5M6I6dQ45JjQABRIFCsTwslWmyWtktuP+0d 7dnYo3TkuNq5bUwORQJbqOcMiGyXQVs5yIkMSdXoJpN2CKJbJXT7w9/F1RGYy0lNGMFX Yzxr6qPCONbM87+iz0JMcqDEIT0Q5SpiZBAib4g9BG8p/WayVHZ1tV7bYJbIlhMjVYbc faFg== 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=Gk4m2fQ8sZYp8e1Vo47cArS7c1wt6X9TddNWXY42pdc=; b=FM8smWwxQ9pAZqNcXv6IZCMRrya/x0U+++4+f8nqosOyhqZgYl26d1SwFJuykYZ9eo GEEpcEYrmbM+YIn7htoM1kPsZbkmGv2vuhH7cBYOxJoXF3cCgH8VwkokhPXV9Z+iWHES zgy0iIczQWawT1B3eLEG3EdZ7xztvXfyyAAH9u7uElFWrODPA27MDVFqK2UZOKAMTDus Qsyv/tfE5mlN07zNEkaYb69LPcn5xaqm01bHZHJikA3KNCfb7CEoObT/8aKI5SFZaF4Q RDBc2FO2otoMM0K4H3/mKy4Fy/p78Hh4du7AKe7lrS4o33uOCGNj/0mHVLHgPy5/vSx1 vJvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=i2WpGgtt; 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 pj13-20020a17090b4f4d00b001f524e93cfasi5466192pjb.184.2022.08.07.15.33.04; Sun, 07 Aug 2022 15:33:18 -0700 (PDT) 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=i2WpGgtt; 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 S242045AbiHGWIp (ORCPT + 99 others); Sun, 7 Aug 2022 18:08:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236353AbiHGWEQ (ORCPT ); Sun, 7 Aug 2022 18:04:16 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24D62A1B8; Sun, 7 Aug 2022 15:02:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659909773; x=1691445773; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k6cZI6jTX8Oqp1jM6hl6qJQGlsOsKL64eoE1RnV0eI4=; b=i2WpGgttFp3T9Qi8wa6ue23HfumEYlECrxFdDP3Ro47uWyBnT1IuC6xy 5JPY9FtBrECLrBTi5j3bNLrSionI1ZIlmVJYQpGc1xnlJyyrPoJNgiGcI l04fAYr9Po5PvcZWFUj1S6pgbHBCCh7bGJSW6McSaOp+/bAsA66bfHisW D872F56D01W+L2W5MJe/VFp8Rnj1REFgWH+KNVwg+eD2+gSVsQiWaJwp8 2D/C/9eRXVmbyOp8qUpX0lgeTVQ+uMpjUpyXyHY+0bLYTKxUa4Y4Dqdtr 7j0l0FttgUC1jjeM3U76UcxHqU5kjLAt9cjUBWdWM9IOrvPZ0Aw1Pn98J w==; X-IronPort-AV: E=McAfee;i="6400,9594,10432"; a="270240380" X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="270240380" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2022 15:02:41 -0700 X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="663682708" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2022 15:02:41 -0700 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 Subject: [PATCH v8 080/103] KVM: VMX: Modify NMI and INTR handlers to take intr_info as function argument Date: Sun, 7 Aug 2022 15:02:05 -0700 Message-Id: <570701a5b7a78c46948d1f00f4f486615a66fcfb.1659854790.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=-5.0 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_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 418b1d1a2219..4ff998bf374b 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6773,28 +6773,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; @@ -6814,9 +6813,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