From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB0D23603D2 for ; Fri, 15 May 2026 00:50:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778806251; cv=none; b=FVqJuMSYAWRb75GiqYGGdHp2OzupmyUaALTUjlrf6vvd8bhuNR4s7aVo+NRtALGxMmO0LjhpKlq+tLJSccTopMvIQiFcwFZNO5oXYLHidZhPGQVTt+7aRV1NXIkTY0duPCQYTm2zIZTkIfXVD/aQkKhr2E8FfEBa/S4ymtdDJ/g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778806251; c=relaxed/simple; bh=h7Upm6hanRPa8t4Q5yy6PC2p8UsW/PSB9wgvmGa0/80=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=cmOiczYSPRnncDMEiWnxx9NX38vCe5+zVL38kQ/6RGIEZjRlNHsxrShI3XoGGY6QdJKhObTYu6Sha19TpGG5SJb7YVpzhISTx89VG437tfFQl5Z1mtmMUq761EHK5w22+HvaczDJhI0oN4QinbRdDZ6gcLCIdxqJz0o59WKtjrg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Z5xqTjaF; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Z5xqTjaF" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-c8294d8c48eso3188070a12.0 for ; Thu, 14 May 2026 17:50:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778806242; x=1779411042; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XHCf4Mys3KBnvWizfXSQ9VTTMoqyl00aLYdh0iKDKZg=; b=Z5xqTjaFxqw/lgfQO3LRdR+i7zVcBPP/RUVm8zGPwvpWVuCjK2n4/YG2FyQgWSGDQ9 Oc0Go6hBWw0uhwWBWWzZIvHjgF+IjbRUzW80r6Or86J2Dh9dj0brumUwO7RluK1JW9ry NoAD6cpKy4FocBfyH4hmYwsw/B/BW/PeRyrlQSPPdzOK7egSjdVYBKyfdpt7yFr73O74 /GSjnOYDl6R/dG5yZDaUAvOMDht7tTUJPiCfii7YL7gm9HiLzKW8omy4z3W9sHsdVTL8 siuz9yEgFenJEc0Sz+JuMDXspRrp385YzTQSY4uoFY1RJCtV1XP4Ysp8QTN8S3qu5Ldd madQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778806242; x=1779411042; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XHCf4Mys3KBnvWizfXSQ9VTTMoqyl00aLYdh0iKDKZg=; b=eLyFI9LjXCNHKo5SM3hH36432lDib2ta3gHzgK9CxCW2XCn8J8Mm5fydTmEveaYVhQ wdkQNu69TmOcVM84CwBJFOIetNsDAIeNBd204EX5+N4Q3GoTSC3wx1lh0P6USX1GzRtx tCRLB42AEKeJjzHmDHFqb+m/mq2OtpaZ+2j2nMy31XJHuqYWRUJf71dK0WL56MDHQkvx YT1icExkobH6v04BWG4n2E5ZPS+3gIwpJHIKfTkh2p6at9hQKMyz/aHUivXCH79fuyqt U/TYq7CIM0troNbx6MRg02007+mvhi7CI04TBcTTszP6vAq4AwV9GUg0nJJf9dmrXJVs o87A== X-Gm-Message-State: AOJu0YwXxboXr7zpgGJW+bUHb8u1kBTQMaJ/qffaWH5RlLbhAjQycFMG 7w3cBiDHG897TzTvYQX6l6hMDCNvqzmsgEzyi474edbAtEabuXjPw9O9R6afubqulxiqPLkj/4o AyqiuNQ== X-Received: from pfmm23.prod.google.com ([2002:a05:6a00:2497:b0:82f:6a88:310b]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1709:b0:82f:9aa:d63d with SMTP id d2e1a72fcca58-83f33d3337amr1669440b3a.49.1778806241653; Thu, 14 May 2026 17:50:41 -0700 (PDT) Date: Thu, 14 May 2026 17:50:41 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260107235724.28101-1-aidan@aktech.ai> <20260107235724.28101-2-aidan@aktech.ai> Message-ID: Subject: Re: [PATCH v1 1/1] KVM: x86: Merge pending debug causes when vectoring #DB From: Sean Christopherson To: Aidan Khoury Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Aidan Khoury , Nick Peterson Content-Type: text/plain; charset="us-ascii" On Wed, May 13, 2026, Sean Christopherson wrote: > On Wed, Jan 07, 2026, Aidan Khoury wrote: > So while I don't exactly love the idea, I think this? Compile tested only at > this point, I'll try to properly test it tomorrow. Confirmed the below works, once I remembered how to configure debug breakpoints. I'll plan on sending a v2 on your behalf, along with a KVM-Unit-Test testcase. > --- > arch/x86/include/asm/kvm-x86-ops.h | 1 + > arch/x86/include/asm/kvm_host.h | 1 + > arch/x86/kvm/vmx/main.c | 9 +++++++++ > arch/x86/kvm/vmx/vmx.c | 6 ++++++ > arch/x86/kvm/vmx/x86_ops.h | 1 + > arch/x86/kvm/x86.c | 8 ++++++++ > 6 files changed, 26 insertions(+) > > diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h > index b0269325646c..3e04a7ecbb47 100644 > --- a/arch/x86/include/asm/kvm-x86-ops.h > +++ b/arch/x86/include/asm/kvm-x86-ops.h > @@ -51,6 +51,7 @@ KVM_X86_OP(get_gdt) > KVM_X86_OP(set_gdt) > KVM_X86_OP(sync_dirty_debug_regs) > KVM_X86_OP(set_dr7) > +KVM_X86_OP_OPTIONAL_RET0(get_pending_dbg_exceptions) > KVM_X86_OP(cache_reg) > KVM_X86_OP(get_rflags) > KVM_X86_OP(set_rflags) > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index 271bdd109a98..eaac6ba59591 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -1834,6 +1834,7 @@ struct kvm_x86_ops { > void (*set_gdt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt); > void (*sync_dirty_debug_regs)(struct kvm_vcpu *vcpu); > void (*set_dr7)(struct kvm_vcpu *vcpu, unsigned long value); > + unsigned long (*get_pending_dbg_exceptions)(struct kvm_vcpu *vcpu); > void (*cache_reg)(struct kvm_vcpu *vcpu, enum kvm_reg reg); > unsigned long (*get_rflags)(struct kvm_vcpu *vcpu); > void (*set_rflags)(struct kvm_vcpu *vcpu, unsigned long rflags); > diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c > index 83d9921277ea..a0e67471bff1 100644 > --- a/arch/x86/kvm/vmx/main.c > +++ b/arch/x86/kvm/vmx/main.c > @@ -470,6 +470,14 @@ static void vt_set_dr7(struct kvm_vcpu *vcpu, unsigned long val) > vmx_set_dr7(vcpu, val); > } > > +static unsigned long vt_get_pending_dbg_exceptions(struct kvm_vcpu *vcpu) > +{ > + if (WARN_ON_ONCE(is_td_vcpu(vcpu))) > + return 0; > + > + return vmx_get_pending_dbg_exceptions(vcpu); > +} > + > static void vt_sync_dirty_debug_regs(struct kvm_vcpu *vcpu) > { > /* > @@ -928,6 +936,7 @@ struct kvm_x86_ops vt_x86_ops __initdata = { > .get_gdt = vt_op(get_gdt), > .set_gdt = vt_op(set_gdt), > .set_dr7 = vt_op(set_dr7), > + .get_pending_dbg_exceptions = vt_op(get_pending_dbg_exceptions), > .sync_dirty_debug_regs = vt_op(sync_dirty_debug_regs), > .cache_reg = vt_op(cache_reg), > .get_rflags = vt_op(get_rflags), > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 3a47a21dd499..7f84644a5c49 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -5822,6 +5822,12 @@ void vmx_set_dr7(struct kvm_vcpu *vcpu, unsigned long val) > vmcs_writel(GUEST_DR7, val); > } > > +unsigned long vmx_get_pending_dbg_exceptions(struct kvm_vcpu *vcpu) > +{ > + return vmcs_readl(GUEST_PENDING_DBG_EXCEPTIONS) & > + (DR6_RTM | DR6_BS | DR_TRAP_BITS); > +} > + > static int handle_tpr_below_threshold(struct kvm_vcpu *vcpu) > { > kvm_apic_update_ppr(vcpu); > diff --git a/arch/x86/kvm/vmx/x86_ops.h b/arch/x86/kvm/vmx/x86_ops.h > index 409858074246..5cfbd4e66f08 100644 > --- a/arch/x86/kvm/vmx/x86_ops.h > +++ b/arch/x86/kvm/vmx/x86_ops.h > @@ -75,6 +75,7 @@ void vmx_set_idt(struct kvm_vcpu *vcpu, struct desc_ptr *dt); > void vmx_get_gdt(struct kvm_vcpu *vcpu, struct desc_ptr *dt); > void vmx_set_gdt(struct kvm_vcpu *vcpu, struct desc_ptr *dt); > void vmx_set_dr7(struct kvm_vcpu *vcpu, unsigned long val); > +unsigned long vmx_get_pending_dbg_exceptions(struct kvm_vcpu *vcpu); > void vmx_sync_dirty_debug_regs(struct kvm_vcpu *vcpu); > void vmx_cache_reg(struct kvm_vcpu *vcpu, enum kvm_reg reg); > unsigned long vmx_get_rflags(struct kvm_vcpu *vcpu); > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 72ba1fc1bed2..8b32ab11f888 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -868,6 +868,14 @@ static void kvm_multiple_exception(struct kvm_vcpu *vcpu, unsigned int nr, > vcpu->arch.exception.vector = nr; > vcpu->arch.exception.error_code = error_code; > vcpu->arch.exception.has_payload = has_payload; > + /* > + * VMX records deferred debug causes (B0-B3, enabled breakpoint, > + * BS, RTM) in the vmcs.PENDING_DBG_EXCEPTIONS field. Merge any > + * pending causes into the exception payload so the guest may > + * see all accumulated reasons in DR6 when the #DB is vectored. > + */ > + if (nr == DB_VECTOR && has_payload) > + payload |= kvm_x86_call(get_pending_dbg_exceptions)(vcpu); > vcpu->arch.exception.payload = payload; > return; > } > > base-commit: b72a08c022f2dae4bca6f4edde5fe8012a02aefa > --