Skip to content

Commit 198b257

Browse files
donshengwenlingz
authored andcommitted
hv: add function to check if using posted interrupt is possible for vm
Add platform_caps.c to maintain platform related information Set platform_caps.pi to true if all iommus are posted interrupt capable, false otherwise If lapic passthru is not configured and platform_caps.pi is true, the vm may be able to use posted interrupt for a ptdev, if the ptdev's IRQ is single-destination Tracked-On: #4506 Signed-off-by: dongshen <dongsheng.x.zhang@intel.com> Reviewed-by: Eddie Dong <eddie.dong@Intel.com>
1 parent 1bc7699 commit 198b257

File tree

6 files changed

+50
-0
lines changed

6 files changed

+50
-0
lines changed

hypervisor/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ HW_C_SRCS += arch/x86/ioapic.c
229229
HW_C_SRCS += arch/x86/lapic.c
230230
HW_C_SRCS += arch/x86/cpu.c
231231
HW_C_SRCS += arch/x86/cpu_caps.c
232+
HW_C_SRCS += arch/x86/platform_caps.c
232233
HW_C_SRCS += arch/x86/security.c
233234
HW_C_SRCS += arch/x86/mmu.c
234235
HW_C_SRCS += arch/x86/e820.c

hypervisor/arch/x86/guest/vm.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <sbuf.h>
3232
#include <pci_dev.h>
3333
#include <vacpi.h>
34+
#include <platform_caps.h>
3435

3536
vm_sw_loader_t vm_sw_loader;
3637

@@ -115,6 +116,20 @@ bool is_rt_vm(const struct acrn_vm *vm)
115116
return ((vm_config->guest_flags & GUEST_FLAG_RT) != 0U);
116117
}
117118

119+
/**
120+
* @brief VT-d PI posted mode can possibly be used for PTDEVs assigned
121+
* to this VM if platform supports VT-d PI AND lapic passthru is not configured
122+
* for this VM.
123+
* However, as we can only post single destination IRQ, so meeting these 2 conditions
124+
* does not necessarily mean posted mode will be used for all PTDEVs belonging
125+
* to the VM, unless the IRQ is single-destination for the specific PTDEV
126+
* @pre vm != NULL
127+
*/
128+
bool is_pi_capable(const struct acrn_vm *vm)
129+
{
130+
return (platform_caps.pi && (!is_lapic_pt_configured(vm)));
131+
}
132+
118133
static struct acrn_vm *get_highest_severity_vm(void)
119134
{
120135
uint16_t vm_id, highest_vm_id = 0U;

hypervisor/arch/x86/platform_caps.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (C) 2020 Intel Corporation. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#include <types.h>
8+
#include <platform_caps.h>
9+
10+
struct platform_caps_x86 platform_caps = {.pi = true};

hypervisor/arch/x86/vtd.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <vm_config.h>
2424
#include <pci.h>
2525
#include <vm.h>
26+
#include <platform_caps.h>
2627

2728
#define DBG_IOMMU 0
2829

@@ -208,6 +209,7 @@ static inline uint16_t vmid_to_domainid(uint16_t vm_id)
208209

209210
static int32_t dmar_register_hrhd(struct dmar_drhd_rt *dmar_unit);
210211
static struct dmar_drhd_rt *device_to_dmaru(uint8_t bus, uint8_t devfun);
212+
211213
static int32_t register_hrhd_units(void)
212214
{
213215
struct dmar_drhd_rt *drhd_rt;
@@ -226,6 +228,10 @@ static int32_t register_hrhd_units(void)
226228
if (ret != 0) {
227229
break;
228230
}
231+
232+
if ((iommu_cap_pi(drhd_rt->cap) == 0U) || (!is_apicv_advanced_feature_supported())) {
233+
platform_caps.pi = false;
234+
}
229235
}
230236

231237
return ret;

hypervisor/include/arch/x86/guest/vm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ void vrtc_init(struct acrn_vm *vm);
263263

264264
bool is_lapic_pt_configured(const struct acrn_vm *vm);
265265
bool is_rt_vm(const struct acrn_vm *vm);
266+
bool is_pi_capable(const struct acrn_vm *vm);
266267
bool has_rt_vm(void);
267268
bool is_highest_severity_vm(const struct acrn_vm *vm);
268269
bool vm_hide_mtrr(const struct acrn_vm *vm);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (C) 2020 Intel Corporation. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef PLATFORM_CAPS_H
8+
#define PLATFORM_CAPS_H
9+
10+
struct platform_caps_x86 {
11+
/* true if posted interrupt is supported by all IOMMUs */
12+
bool pi;
13+
};
14+
15+
extern struct platform_caps_x86 platform_caps;
16+
17+
#endif /* PLATFORM_CAPS_H */

0 commit comments

Comments
 (0)