Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4726261iob; Sun, 8 May 2022 23:24:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycQpTDth9RmAeQD5WpYiUJSEjMXOyUvz5LXpa4Hkq2oaqh5hS15xlvnz7/B5mUfX/IBtUv X-Received: by 2002:a17:902:c952:b0:15e:9e3d:8e16 with SMTP id i18-20020a170902c95200b0015e9e3d8e16mr15351672pla.51.1652077479332; Sun, 08 May 2022 23:24:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652077479; cv=none; d=google.com; s=arc-20160816; b=sh3KHfBhqAxd0jH6HqJctrGwubFsADujo6hjTmm8JcHPDh62+hGWOzN5NZGuYR1e/j mQ2uEQ+kJbxtc35bRs5j5RqY8q0fEQ4OcyBjOIXPF/0DkQyM0ohI4bceX1QOh1ZYYnUa xtSuWjPpkxnsZTsemcy/IOBHlb/vZKjcPuUJagEhWZYAbAJgrgUmXI2wh9/wwIYBBfHK 6rMpEJ93GCrAD3q2wuOE9E55GOLPEmMSPLhFZd19DKX2UcJgLfx1L2hnBlWnZI7JC1fm 2/gpt/yDWCE0fgQBP2kaNrXuga2ncHU5JnjYY0RwRgzcabxlk8I8OC2zNIHliC2UhYF1 5BXA== 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=A9LgBRz46YM0Wso/5kV/GMfMSl9fBQaB8dOVFrgKs1Q=; b=t8kMLLCyerXa94S7fwe+eftTEOqeZTJWA52vuhaixOM3FgdSp9AeRyehR1BMkyqOob 9PmZgj+Pvb9RCQxys4RfrHKamo7U1uW2DTb96F0Qd+Jwpj3VKMMzfIEYBDZUUXIb6kAh qLAO4HazBTxlg5/iewOdH4XaBTgFqtmOqX6qUjOyuvU2ewdSngC2qOFgmlTlEXck6g6W 3RawvrTpEsm5BVUqBtCxff/BcTdkBgsC5bzMr8cruPqb+wDL0LQNZjV2yoVwZFPzO4kr 0x9T7MQ+IRFthCn0Ti85PqvskCMyJI3xN4m255egtEwxnTPGZaKZ6iSEzJC+Zj+0sozx Xaig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZMSDQxMi; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m4-20020a654c84000000b003816043f159si13083990pgt.846.2022.05.08.23.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 23:24:39 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZMSDQxMi; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F270E13CC5C; Sun, 8 May 2022 23:21:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1385080AbiEESY6 (ORCPT + 99 others); Thu, 5 May 2022 14:24:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383267AbiEESTo (ORCPT ); Thu, 5 May 2022 14:19:44 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DE455DA70; Thu, 5 May 2022 11:15:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651774558; x=1683310558; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8nUU+UGNy7mQEIUhX+nB4yYC3U4K7m46T49yAw5q968=; b=ZMSDQxMiJFYpYHWwVTapqvzFFJ8H91xbrjgC6JMqqEfmKTdohdm9qcw6 1lEflFIpH1KglPfREHR4WlmVXpi8zXTYmOqQaryWXPfTlTaO709TEwaiX Rp4ljyiS4alTdXrQwU4SpVQR14RFTJA9QfhKt0HjW40GVX5xXG4KLyRjh bNmbDK3AuSGuDIj0MNWUQ/Ht1SzVfGavSnnVDf6e2qb/9T7oYg2AnsPQF PH7DcCddpK6gebuDXtG3YrJ8b9EctEiY+iScxkpp557GDvGTpJfGoPp1M 5UmrhN4EwQC2E7a9H8sMPLlohEzEQ6BW5s3NrZ70+r+1Gzc3QRNzfL9Oz Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10338"; a="248113924" X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="248113924" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 11:15:52 -0700 X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="665083433" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 11:15:52 -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: [RFC PATCH v6 081/104] KVM: VMX: Modify NMI and INTR handlers to take intr_info as function argument Date: Thu, 5 May 2022 11:15:15 -0700 Message-Id: <246546b76f01e9eec12910f9eb809a04c02c2ef1.1651774250.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=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 718b38239e03..2bcc4511ee28 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6575,28 +6575,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; @@ -6615,9 +6614,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