From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.21 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796198693; b=CRm0QwD5BtDOCi/7+cYNDHPTjJWOpV/DKe5vg3hWVy08fWk+avOYAUcspS1+hlvc0edK ah9oMPpA1ZsGlDG3CoZTtL22XMFI7Xl+Gye1PVEiUAyKnmN5hK71LKh8qM/cuscTnwrrL +1jUfbpDxHYqAEuJ8IwGMoJZ9MclnYetLYuRP2R8VHDVCuFfRrrhVdqxKcWR5UuiU3N9a Kvno54wunDOthOyTGHvUcSWZ+ETHxm5+QbO16ahm05f4cRYBWmSyxWqoB7xFA/eK6+3nB qfaFGYu7l3/cFzTsqh6RID9VTaXxSLbMgztrtJtXzclZycVZRhwJV++nlahDTb25l7g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796198693; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=eO0yHY91EsX4bLBIP6d3A7wvn/GBh20y3WYQhcahF+c=; b=vxO6Tj2QVfB3WdmO3p8/Lqadlpvj4+kzpwvqlREYPv0fLWYHmhtbq1kSdwMGIqOdpiJv lpd72ofhfaGTMmKroRrE+1KKfYKT4Mpv+q3FcndW9Op272IZUrflwdu5bqjYN0AwV5VEw Lgm/iyMLxrySs/jZrhvln++YSkmp0jPihHMf/tktyks6RUtszCycI0I2EvEaXw1urwlk2 +jlr4m2w+hLM4F7Xd+McrChSXIwn9fVTnoYExinHac4IEyKakVMrwq64xC3Vu2j6izyeD mOSFXqfsqk+EJ2JBMQHiis7nlGaABCVoP1fxcB+Jbwua3K9Cygur5xXyBKdZUmAzLJQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=EsOUsFPk; arc=none smtp.remote-ip=198.175.65.21 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9B30606A329; Wed, 2 Dec 2026 08:04:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A9B30606A329 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=EsOUsFPk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796198693; x=1827734693; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eO0yHY91EsX4bLBIP6d3A7wvn/GBh20y3WYQhcahF+c=; b=EsOUsFPkrr0OBUytdQFao5z3omEXzwszA0aD6Iq59T6/ebuniF4Q/HQd hXhgF7LcYxntF+pnD4a2agK2nFmYHAd990NivsagG9eOpZG95vc61KD9x ShWyZxe7ZNENeLO5XrkOMMyiHkyqiYCYKj0SUnSFnPp9VcFTbpsczXnMq RUTVAPfsXZMFkLnhN30GyZ+HGEo9eHRgyd6MAsP8gokyslsxLkqQBVpUm AMIOFzUToB1C6/05jm/nmrDQ99hNUChdQRRRGFdFyIYC88MLZuaz/dR9Q +gjhTkjJVvNAGHXJCPCa6VjPhd236U5SIiyDUHkNPoE/610zdlZhHJqAk w==; X-CSE-ConnectionGUID: s4lC0YEbSbKyvHyyMbX7aQ== X-CSE-MsgGUID: p3tcfkauQt+VlejLBgr7bg== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5211616" X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="5211616" Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 00:04:42 -0800 X-CSE-ConnectionGUID: nyfqaIS+Rieitp6/Hg4Uxw== X-CSE-MsgGUID: 65KSSy6rTKW/BPZjhTHvxA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="15428626" Received: from sohilmeh.sc.intel.com ([172.25.103.65]) by fmviesa013.fm.intel.com with ESMTP; 02 Dec 2026 00:04:42 -0800 From: Sohil Mehta To: kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Shuah Khan , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Xin Li , Peter Zijlstra , Andrew Cooper , Tom Lendacky , Nikunj A Dadhania , Shivansh Dhiman , Neeraj Upadhyay , David Woodhouse , Chao Gao , Binbin Wu , Maciej Wieczor-Retman , "Chang S . Bae" , Sohil Mehta , Yosry Ahmed , David Matlack , x86@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH 2/4] KVM: nVMX: Don't drop an L1-injected INT1 whose delivery is interrupted Date: Wed, 2 Dec 2026 00:02:22 -0800 Message-ID: <20261202080224.4165883-3-sohil.mehta@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261202080224.4165883-1-sohil.mehta@intel.com> References: <20261202080224.4165883-1-sohil.mehta@intel.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Currently, KVM doesn't inject a privileged software exception itself, but L1 can inject an INT1 into L2. If a VM-exit interrupts the delivery of the INT1, KVM drops it, as it requeues only hardware and software exceptions. For example, a delivery is interrupted when it touches an IDT or stack page that isn't mapped yet. If KVM handles the VM-exit itself, L2 then resumes without the INT1. If L1 handles it, L1 doesn't find the INT1 in the IDT-vectoring information and can't re-inject it. Handle an INT1 the way KVM handles a software exception, which also needs its instruction length. Requeue it with its length, re-inject it with its own event type, and report it to L1 with that type and length. Check the event type before the vector, as L1 can inject a privileged software exception with any vector. When the INT1 goes through a task gate, KVM emulates the task switch. Clear the requeued INT1 there, so that KVM doesn't inject it twice. And leave a queued INT1 out of the vCPU events, as the uAPI doesn't provide a mechanism to carry its length. Signed-off-by: Sohil Mehta --- Patch 3 relies on this patch, as it makes KVM inject an ICEBP's #DB as a privileged software exception. Without this patch, KVM would inject that #DB as a hardware exception with RIP still on the ICEBP. The guest would then execute the ICEBP forever, and patch 4's test would hang. No Fixes tag, as KVM has dropped this event type ever since nested VMX started passing L1's injected events through to L2. --- arch/x86/kvm/vmx/nested.c | 13 ++++++++++--- arch/x86/kvm/vmx/vmx.c | 12 ++++++++++-- arch/x86/kvm/x86.c | 11 ++++++----- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 1a98f28651f7..6cb07873998d 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3970,12 +3970,17 @@ static void vmcs12_save_pending_event(struct kvm_vcpu *vcpu, nr = vcpu->arch.exception.vector; idt_vectoring = nr | VECTORING_INFO_VALID_MASK; - if (kvm_exception_is_soft(nr)) { + if (vcpu->arch.exception.event_type == EVENT_TYPE_PRIV_SWEXC) { + vmcs12->vm_exit_instruction_len = + vcpu->arch.event_exit_inst_len; + idt_vectoring |= INTR_TYPE_PRIV_SW_EXCEPTION; + } else if (kvm_exception_is_soft(nr)) { vmcs12->vm_exit_instruction_len = vcpu->arch.event_exit_inst_len; idt_vectoring |= INTR_TYPE_SOFT_EXCEPTION; - } else + } else { idt_vectoring |= INTR_TYPE_HARD_EXCEPTION; + } if (vcpu->arch.exception.has_error_code) { idt_vectoring |= VECTORING_INFO_DELIVER_CODE_MASK; @@ -4085,7 +4090,9 @@ static void nested_vmx_inject_exception_vmexit(struct kvm_vcpu *vcpu) intr_info |= INTR_INFO_DELIVER_CODE_MASK; } - if (kvm_exception_is_soft(ex->vector)) + if (ex->event_type == EVENT_TYPE_PRIV_SWEXC) + intr_info |= INTR_TYPE_PRIV_SW_EXCEPTION; + else if (kvm_exception_is_soft(ex->vector)) intr_info |= INTR_TYPE_SOFT_EXCEPTION; else intr_info |= INTR_TYPE_HARD_EXCEPTION; diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index a6c0e8ccdfad..fdc531a61fd3 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1973,12 +1973,18 @@ void vmx_inject_exception(struct kvm_vcpu *vcpu) WARN_ON_ONCE(vmx->vt.emulation_required); - if (kvm_exception_is_soft(ex->vector)) { + /* L1 can inject a privileged software exception with any vector. */ + if (ex->event_type == EVENT_TYPE_PRIV_SWEXC) { + vmcs_write32(VM_ENTRY_INSTRUCTION_LEN, + vmx->vcpu.arch.event_exit_inst_len); + intr_info |= INTR_TYPE_PRIV_SW_EXCEPTION; + } else if (kvm_exception_is_soft(ex->vector)) { vmcs_write32(VM_ENTRY_INSTRUCTION_LEN, vmx->vcpu.arch.event_exit_inst_len); intr_info |= INTR_TYPE_SOFT_EXCEPTION; - } else + } else { intr_info |= INTR_TYPE_HARD_EXCEPTION; + } vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, intr_info); @@ -5946,6 +5952,7 @@ static int handle_task_switch(struct kvm_vcpu *vcpu) vmcs_read32(IDT_VECTORING_ERROR_CODE); } fallthrough; + case INTR_TYPE_PRIV_SW_EXCEPTION: case INTR_TYPE_SOFT_EXCEPTION: kvm_clear_exception_queue(vcpu); break; @@ -7185,6 +7192,7 @@ static void __vmx_complete_interrupts(struct kvm_vcpu *vcpu, */ vmx_set_nmi_mask(vcpu, false); break; + case INTR_TYPE_PRIV_SW_EXCEPTION: case INTR_TYPE_SOFT_EXCEPTION: vcpu->arch.event_exit_inst_len = vmcs_read32(instr_len_field); fallthrough; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c27813bde407..b58518a777de 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3010,12 +3010,13 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu, memset(events, 0, sizeof(*events)); /* - * The API doesn't provide the instruction length for software - * exceptions, so don't report them. As long as the guest RIP - * isn't advanced, we should expect to encounter the exception - * again. + * The API doesn't provide the instruction length that software + * exceptions and INT1 need, so don't report them. As long as the + * guest RIP isn't advanced, we should expect to encounter the + * exception again. */ - if (!kvm_exception_is_soft(ex->vector)) { + if (!kvm_exception_is_soft(ex->vector) && + ex->event_type != EVENT_TYPE_PRIV_SWEXC) { events->exception.injected = ex->injected; events->exception.pending = ex->pending; /* -- 2.43.0