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=NBedIdO9fzGT2jZ2MyUg2bAqiV99h4Z7FZ2uMvkT3yVgU16UmPrQ2iAhLDYvm1thO8V5 q1auB0suiS2I4GKl5NGZHW7fFE7mnU2YJxW7fqrhhAAg/77hzs/w3w8ABr94nbscKh8h/ UFscUHYq6Kz+bacSu1D1rUqQb1nWfzv8G9Bcdfip1j96A+xD7KpZ9qUfIaDsBCzlzGid0 viBCJqACB9wLmrAW97Fq2YKjLWA+X4Fl0FsFchUNJfqvPMqIMzqUoZ79Xmhj/8fw6eqik Z7eddV9V4g6I49zmVfjfDVaNrIOZCJOV3vZsQ6YsWw6XkL853kNiKhk7clKX/hB3xVw== 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:MIME-Version:Content-Transfer-Encoding; bh=RSB4HGTIkr4vnxeAF3l+PAbFzvT313/rwNxuHoasGXw=; b=XR9C0QeYezi7gsPAJYkUZAxdq5VorkLmCkyyqR8VlLfzEXNYtNqQAU2bfk7l/9LYDXSk Sncd8Tzed6/7dHs29cIOJV4Ue7Zd2vDmUnNA+L9JU5zxTxaaz0g25GJ2XmkC4/oVo1vjb x/FJBVfKkhFLf0z6mZT0NmBXWGFTUX8SzSIglDEf2/EHb1GaqUwoPMYc3U6HjHWPRUZfe 1vb+rfoTeuUOsUPsfNF5rls3raJx28TuhcceVR21V4VAnjTGkxksYZmBiG7W1h00SL1+E qNILUuF2KXuvGcYX3pLgkPTtlm8UY73zzsNk+iZy+XWuhcWZoJO1ZsMdtn/u0qN2ecA== 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="Ift05g/P"; 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 8DC8F606A327; Wed, 2 Dec 2026 08:04:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8DC8F606A327 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=Ift05g/P 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:mime-version: content-transfer-encoding; bh=RSB4HGTIkr4vnxeAF3l+PAbFzvT313/rwNxuHoasGXw=; b=Ift05g/PWQYtfrrRShqunvKjX/144Kmd507kObVrVQEfKzLyXS2vZczG CwC2w6BHGZmi3TxQL7wcaylLmqh3jZLuiYRq+F8ziplBjqV40R+NWIkJh Sx+v23nwucCJBSV9778DjjH9HvIMrpuVULQzqPyxlW2C/B8/xF3v87KSR lpNipdfyk81Bu3hUpWFRaecH0vRViipcl9h+AJCfa0u0SpEEe0PWOj6l1 dIcQTgzqXROMzqEpahvRmzIpVCBgWfEaXzMaqQSo2ueepPAe7G4nbGREh uA2sS4RLfnl0jStt8Hk3lju3gB7GsjQxInT48wBiLNT2MIE2Clid6Ih9w w==; X-CSE-ConnectionGUID: 2Dx+1+6BTZqYy7qOQ0oTxg== X-CSE-MsgGUID: aGJDlb6fSUKz5/B7hvQuAg== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5211601" X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="5211601" 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: X/euPXF/Se6Sox6eSUKinw== X-CSE-MsgGUID: yzMXrdYbS0qSbPbe7boPSQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="15428619" Received: from sohilmeh.sc.intel.com ([172.25.103.65]) by fmviesa013.fm.intel.com with ESMTP; 02 Dec 2026 00:04:41 -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 0/4] KVM: VMX: Handle the #DB of an ICEBP as a privileged software exception Date: Wed, 2 Dec 2026 00:02:20 -0800 Message-ID: <20261202080224.4165883-1-sohil.mehta@intel.com> X-Mailer: git-send-email 2.43.0 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 TL;DR ----- This series tracks the event type of a queued exception, and uses it to requeue and re-inject a privileged software exception as one. This lays groundwork for FRED guest support [1] and fixes nested-VMX edge cases. Background ---------- David's int1_fred_test [2] found the issue by checking the event type in the FRED stack frame. The issue isn't specific to FRED but it becomes highly visible with FRED virtualization. ICEBP (INT1) generates a #DB with the event type of a privileged software exception. KVM loses that type in two ways. It re-injects the #DB of an intercepted ICEBP as a hardware exception. And it drops a privileged software exception altogether if a VM-exit interrupts its delivery. The existing impact described below is limited, but it's still worth addressing. As fixing this seems necessary [3] for the upcoming FRED guest support, I am posting it separately for easier review and merge. Impact ------ Without FRED, a guest can't see the event type through the IDT, so currently only nested guests are affected: - If the delivery of an ICEBP's #DB to L2 causes a VM-exit to L1, L1 finds a hardware exception in the IDT-vectoring information, with no instruction length and L2's RIP already past the ICEBP. An L1 that re-injects that event still delivers the #DB with the right return RIP. - An INT1 that L1 injects into L2 is dropped if a VM-exit interrupts its delivery. KVM doesn't re-inject it, and if the VM-exit goes to L1, L1 doesn't find it in the IDT-vectoring information. If L1 injected it at an ICEBP, L2 re-executes the ICEBP and takes the #DB late. Otherwise, the #DB is lost. Neither issue breaks a common L1. An L1 normally injects an INT1 only to re-inject the #DB of an ICEBP, at the ICEBP, where a dropped INT1 is only delayed. So the series has no Fixes tags. However, with upcoming FRED guest support [1], every ICEBP in a FRED guest shows event type 3 instead of 5 in the FRED stack frame. Unlike the IDT, FRED gives the guest the type of every event. Linux's FRED entry code dispatches on the type before the vector, so KVM should deliver the type that bare metal would. Currently, Linux sends both types of #DB to the same handler, but other guests may not. Patches ------- Patch 1 adds the event type to the queued exception, with no functional change. Patch 2 uses the event type to requeue a privileged software exception whose delivery is interrupted, rather than drop it, and to inject it with its own type and length. Patch 3 builds on that to fix the other issue. KVM now re-injects the #DB of an intercepted ICEBP as a privileged software exception, and VM-entry advances RIP past the ICEBP, as Andy Cooper suggested [4]. Patch 4 adds a nested VMX selftest for both fixes. It doesn't need FRED. AI was used for the initial prototype but the patches were heavily modified before submission. The series has no dependencies and is based on kvm-x86-next (kvm-x86-next-2026.11.11). Testing ------- Tested the series on a Clearwater Forest system (with ept=1 and ept=0): New L2 ICEBP selftest: It passes. Without patch 3, L1 sees a hardware exception for the ICEBP's #DB. Without patch 2, L2 loops on the ICEBP and the test hangs. Throwaway save/restore selftest: It saves and restores a vCPU while the #DB of an ICEBP is in flight, and checks that the guest takes exactly one #DB. It passes. If KVM reported the queued INT1 in the vCPU events, the guest would take the #DB twice. I can post it if anyone wants it upstream. KVM unit tests: The debug, realmode, vmx and i386 taskswitch tests show no regressions. They cover ICEBP with single-step and other paths that the series touches. KVM selftests: They show no regressions. David's FRED event type test [2]: It passes with the FRED guest support series on top. Notes/Opens ----------- Save/restore: The vCPU events uAPI carries neither the event type nor the instruction length, so patch 2 leaves a queued INT1 out, like INT3 and INTO, and the guest re-executes the ICEBP. In a rare case, an INT1 that L1 injects at a RIP without an ICEBP can be lost across save/restore. It's the same as a software exception that L1 injects. Adding the type and length to the uAPI would fix both, but that doesn't seem worth a uAPI change. vm86: Without unrestricted guest, KVM runs a real-mode guest in vm86 mode and forwards the #DB of an ICEBP to it without advancing RIP, so the guest executes the ICEBP forever. This predates the series, as fd2a445a94d2 ("KVM: VMX: Advance rip to after an ICEBP instruction") advanced RIP only outside vm86 mode. The series leaves vm86 mode alone, as nothing queues a privileged software exception there today. I can post a fix separately if someone says it's worth it. SVM: SVM can inject a privileged software exception only for FRED guests. So for now, SVM keeps injecting a hardware exception for the #DB of an ICEBP. The SVM FRED series [5] asked for a generic fix for KVM-injected INT1s. Now, SVM FRED can inject type 5 based on the event type that this series adds. Links ----- [1]: https://lore.kernel.org/lkml/20260911213659.2025974-1-sohil.mehta@intel.com/ [2]: https://lore.kernel.org/all/7f93eb25874ddd13a1ad6e3c75785f11041c8b7f.camel@infradead.org/ [3]: https://lore.kernel.org/lkml/fcfea4a5e25a9f828de317cc2c0b133eabd91745.camel@infradead.org/ [4]: https://lore.kernel.org/all/f4cb5f8e-caf5-4513-9538-edaaea20de2d@citrix.com/ [5]: https://lore.kernel.org/all/20260925114017.2208531-1-shivansh.dhiman@amd.com/ Sohil Mehta (4): KVM: x86: Track the event type of a queued exception KVM: nVMX: Don't drop an L1-injected INT1 whose delivery is interrupted KVM: VMX: Re-inject an ICEBP #DB as a privileged software exception KVM: selftests: Test how L1 sees the #DB of an ICEBP in L2 arch/x86/include/asm/kvm_host.h | 2 + arch/x86/kvm/svm/svm.c | 2 +- arch/x86/kvm/vmx/nested.c | 13 +- arch/x86/kvm/vmx/vmx.c | 52 ++++-- arch/x86/kvm/x86.c | 50 +++-- arch/x86/kvm/x86.h | 14 +- tools/testing/selftests/kvm/Makefile.kvm | 1 + tools/testing/selftests/kvm/include/x86/vmx.h | 7 + .../selftests/kvm/x86/vmx_icebp_test.c | 174 ++++++++++++++++++ 9 files changed, 277 insertions(+), 38 deletions(-) create mode 100644 tools/testing/selftests/kvm/x86/vmx_icebp_test.c base-commit: cbe54fc3462b3949ab27b9ae81fb9ddb509040c7 -- 2.43.0