Skip to content

Commit d83c36d

Browse files
committed
KVM: nVMX: Add a helper to get highest pending from Posted Interrupt vector
Add a helper to retrieve the highest pending vector given a Posted Interrupt descriptor. While the actual operation is straightforward, it's surprisingly easy to mess up, e.g. if one tries to reuse lapic.c's find_highest_vector(), which doesn't work with PID.PIR due to the APIC's IRR and ISR component registers being physically discontiguous (they're 4-byte registers aligned at 16-byte intervals). To make PIR handling more consistent with respect to IRR and ISR handling, return -1 to indicate "no interrupt pending". Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 92c1e3c commit d83c36d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "mmu.h"
1313
#include "nested.h"
1414
#include "pmu.h"
15+
#include "posted_intr.h"
1516
#include "sgx.h"
1617
#include "trace.h"
1718
#include "vmx.h"
@@ -3899,8 +3900,8 @@ static int vmx_complete_nested_posted_interrupt(struct kvm_vcpu *vcpu)
38993900
if (!pi_test_and_clear_on(vmx->nested.pi_desc))
39003901
return 0;
39013902

3902-
max_irr = find_last_bit((unsigned long *)vmx->nested.pi_desc->pir, 256);
3903-
if (max_irr != 256) {
3903+
max_irr = pi_find_highest_vector(vmx->nested.pi_desc);
3904+
if (max_irr > 0) {
39043905
vapic_page = vmx->nested.virtual_apic_map.hva;
39053906
if (!vapic_page)
39063907
goto mmio_needed;

arch/x86/kvm/vmx/posted_intr.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22
#ifndef __KVM_X86_VMX_POSTED_INTR_H
33
#define __KVM_X86_VMX_POSTED_INTR_H
4+
5+
#include <linux/find.h>
46
#include <asm/posted_intr.h>
57

68
void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu);
@@ -12,4 +14,12 @@ int vmx_pi_update_irte(struct kvm *kvm, unsigned int host_irq,
1214
uint32_t guest_irq, bool set);
1315
void vmx_pi_start_assignment(struct kvm *kvm);
1416

17+
static inline int pi_find_highest_vector(struct pi_desc *pi_desc)
18+
{
19+
int vec;
20+
21+
vec = find_last_bit((unsigned long *)pi_desc->pir, 256);
22+
return vec < 256 ? vec : -1;
23+
}
24+
1525
#endif /* __KVM_X86_VMX_POSTED_INTR_H */

0 commit comments

Comments
 (0)