Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3454403rwb; Fri, 30 Sep 2022 04:00:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6vo0ZV3Fe0xssgCG+psxQqJPE+WbpUqXqxnmmzSQXdfMA1wK5HOuoQJ1IozMZf88/YmyBg X-Received: by 2002:a05:6a00:1503:b0:540:e2c7:2387 with SMTP id q3-20020a056a00150300b00540e2c72387mr8496765pfu.48.1664535608701; Fri, 30 Sep 2022 04:00:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664535608; cv=none; d=google.com; s=arc-20160816; b=Ms2iSAGETJlVERO+kfa2/Pmk0BSE4vuJX8kDqCR7JE4cW0m6D1sNu/eoEzBT3gK+vB m40sewtAVHVc1kFcX0G61jRrHR5gYgaC0ypMHMp9NbkNL/FEQLAA34ltjZQN8h0xEaaH +FcbCBU7C2yj9+3o9fRd//CTgTJJWP5f92DKXYZBikLl4VaggjafuTJ/u0UmJOY6uAe9 rRuSzfw2MifeaUMDikPztRw2BpPXPmcNTs6NvGRdRCv/KrBpNK5S64lbZpqtm0WqQeRj 0QoNXC+mn9ZpdVT9oPjg4gbXwcY8nHtcCIKbdzcyxSqbvwLTt0BtKihCIhGG4WMq0KHq tY2w== 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=xeDvZMxAKnyB6rRcIkd2vFkUgw2k4lOj3WSBJjehHOE=; b=rR06S4hbsF929/utQwzlTfSlqHMkOORnF5DS7ycz+O1fdTVyG2PFK9ZeogMTr6JKgi TKW9aIacskyX0BLnqeLyqvcOXqENQlf6l43C1UwUoNX+noz/p5O7fHS81u4A7q2I/U70 /uAW0oeEYp13VP/SCed64emGsarBH5BY3ZZm8llVAMUh+6PiDEzSx0yNyQqnhrbNMuyD mB+seA9CHScyR/gXewjMNEjiaPLUpIV1L8EvlsXa5xGDW+BWROkDhWcCSGLT62fW69+/ fr+tTMLB3UpIVcZ4fdhVMUZHEyshDxz8/uoRT7x98lzx+uDm1qY16N75k2BDk1lkGSPS fTvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JVOs6PWQ; 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 j18-20020a634a52000000b00438b79bcf26si2596902pgl.151.2022.09.30.03.59.57; Fri, 30 Sep 2022 04:00:08 -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=JVOs6PWQ; 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 S232035AbiI3KXg (ORCPT + 99 others); Fri, 30 Sep 2022 06:23:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231609AbiI3KTK (ORCPT ); Fri, 30 Sep 2022 06:19:10 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2951418B5E0; Fri, 30 Sep 2022 03:19:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664533146; x=1696069146; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kZLhfSmzVTvaaeQgEQOarnShUJcRUFoMTeqFZRT01qQ=; b=JVOs6PWQLX+TFstpIywrt0UxDdYfO3LnRy4+xbWlY6G3TcSEdcmlBQKm +Fgf9sHgFl3CWUmxxCI9wvJhYIyK3VguPaQu49QdaHJREVUKE1GZQ8MVs F2QYHcSyax3AR90MvqrYWllpH5VYcbEyuBddgjC1elTPiOy1BdEUzKJ// 7jaYMrRiUeNniIhZfy13AlFCJWZzBL8ivzLK5DHyA7QjzaaOwskwu41+f hZaZ8/3mzwOHT2vc/7oce3XnVlmskuThovftwgH+S9uXnl9OJKvhxs7cU 4DKW8pii7KEbcFgu3FhHPEWtSAPCBqdGzEx/oo0ucV5sASbPubP+KieA8 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="300875877" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="300875877" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 03:19:05 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="726807767" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="726807767" 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; 30 Sep 2022 03:19:05 -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 , Sean Christopherson Subject: [PATCH v9 081/105] KVM: VMX: Modify NMI and INTR handlers to take intr_info as function argument Date: Fri, 30 Sep 2022 03:18:15 -0700 Message-Id: <6792a020d525fe3eedf814ece75265f44c82def2.1664530908.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.5 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 4a8c398bb69a..ab0f2b87b5b4 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6837,28 +6837,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; @@ -6878,9 +6877,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