From patchwork Mon Feb 26 08:26:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 206429 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1947931dyb; Mon, 26 Feb 2024 01:00:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXLv8rVMEPXD900VkKZPEnVGySH1DqUZmxOWqL7KSDo1zmOjNEJIjPg9vwMUTGsVjyevWIUk4INbTi+RdAX0ALueg+4PA== X-Google-Smtp-Source: AGHT+IFMEhC9Sjk1NMGuDAzY9jgbPEr/TNsGj6g7rU6K8spyupUTbbeROp+41JtnmO5z0UGZs07g X-Received: by 2002:a05:6358:190a:b0:17a:e9db:bc10 with SMTP id w10-20020a056358190a00b0017ae9dbbc10mr8100794rwm.20.1708938051521; Mon, 26 Feb 2024 01:00:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708938051; cv=pass; d=google.com; s=arc-20160816; b=bQM24P20XGrn9FOU2PE1K3ZTDVPn74ntHHwHrtA0BXFpA93vtfahd2JbtFrt6/w/DC qmJoYdAl8SHgN59+2Ac8Q7yGxj6xzKLFxmimQIT73ytcRKxXy+axyxJ9UjhbKC+E8o6f tpmN2eNcb/TMa+DTBjdQ7/N5XIIRKh916mqx4XdgdxJmnWKuEfSq+0oq70Qm9fsZRiF5 W8B4tgESnDnUb2ojrtAjImjKfP4uWIhRWx+9hDv9qyqAFrihAti0wy/kr8dUdLtjbdNe t1bQvvv56sE+/osa621ev4+B+3S1lZPSpnD8YrjKmaXarz3f+Rzl8BlEz0jL9mzrdB44 5YEg== 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=lbSIDA9fm/d5RylOEIthdAVSf5LBrnbNYA6h4+mlx9M=; fh=ka1BjeomumTXa1Vhgkzg2yK2f13tB8VguFI2e9zPJ3c=; b=GfvNQGemlwcRxDDps6sHzopOpfthYBOrUch00fzVF4nfrL5rIaaChjggqEg1DzTNWV NPnjDoQVydz9457lRouzq/voLjZZjQsm5USX+XxvPQvNNCzyhSCYtK1E8UNEtPwmZjle nZDpCzGpj5CqDiLnXjKE9Rgh0uH8R+wk0dBL/C67jrNQ0EY3PLHs8U31wzs2i+PilKV2 iU6YJ7NrZtQm2zGXhw0Uw94Kf32YT0I5iv5UhgZAmfpIF6BTzIoqidaKz8VJGsc9KHUH UNDzEotVR1Zd6qlOLyUjHr5ytsbhf2s+uIsMSSvd7bdx+DVTPa0cyjZUz54U/hyUuqeH lhgA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YHiUh41i; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-80857-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80857-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id w7-20020a631607000000b005dc1b73dd16si3290312pgl.372.2024.02.26.01.00.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:00:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80857-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=@intel.com header.s=Intel header.b=YHiUh41i; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-80857-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80857-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 8466E2835CE for ; Mon, 26 Feb 2024 09:00:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D418F7E788; Mon, 26 Feb 2024 08:28:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YHiUh41i" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 6687B7BAF1; Mon, 26 Feb 2024 08:28:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936135; cv=none; b=qLP2DJ4Rp4CGJr1d4fHPWqeElBWuzuq8a5gHPv/WE4un+cXdCIg4ODQocNDwH8BvuwywgK+aeiZ+ezQuzA5TCfbiBGl6Jmd4s++NXumbZ1FbyGnCJnVh9sFSi3BMYChZrwmUr/vm3hp+BW6XOU02ZvUsWf2o88Z7wxNXeMG9/JU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936135; c=relaxed/simple; bh=2YsbYPL8eW8m04NLRwFz+0vexIk0QRL8LnEfWGvgIaY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=swdb7nH3RrE8mM2aO4FwgNrwBk8zATLjopBeH82pZg20V0NTosqs17mkG+5zPyGKabM7zLzw2DmdSm0jWhso3l689jCBhJ88sw/vnhGoK37JsTlDWUcY7WczNsWvgy1Dnb00eeO7TlqIkpzmj7x8UVLVbuuG3zkB6k4TTcgu13Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=YHiUh41i; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708936134; x=1740472134; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2YsbYPL8eW8m04NLRwFz+0vexIk0QRL8LnEfWGvgIaY=; b=YHiUh41iVHt3A45l0yrwWaJQ8i+6Rg2zayw1UdLHCfbKPNzRp6PdlYIn XGJDkNWifihtGHg/wz+A0ykIDRQWBA4YUTYfmv3nt8O5548F9bSpWPIxy 1NUEEwJ/tkE0Cye4ShGn+5HgjhZM0jH5IfzXqcDwe1cecOzFzKAQMyyuf XKYILB6ctY3EbCHH7zuJPytbrSTYSWR6YpxcDpIw3F7GB60mtivWELx7G 7abM3Kbj9jDmbD3KCi8vslmpByS0khULR7nQPbIaGt5cfivxLfSBg96ll OAdiu7Nm+vNbcA3U7C5PrXkK3SIrzX14G1TYlFTHVHNPht4s03AqI8JtL Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="3069576" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="3069576" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:28:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="11272664" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:28:52 -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 , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Sean Christopherson Subject: [PATCH v19 095/130] KVM: VMX: Modify NMI and INTR handlers to take intr_info as function argument Date: Mon, 26 Feb 2024 00:26:37 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791951426172830475 X-GMAIL-MSGID: 1791951426172830475 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 | 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 1349ec438837..29d891e0795e 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6912,24 +6912,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; @@ -6952,9 +6950,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)); } /*