|
27 | 27 | #include "irq.h"
|
28 | 28 | #include "svm.h"
|
29 | 29 |
|
30 |
| -/* AVIC GATAG is encoded using VM and VCPU IDs */ |
31 |
| -#define AVIC_VCPU_ID_BITS 8 |
32 |
| -#define AVIC_VCPU_ID_MASK ((1 << AVIC_VCPU_ID_BITS) - 1) |
| 30 | +/* |
| 31 | + * Encode the arbitrary VM ID and the vCPU's default APIC ID, i.e the vCPU ID, |
| 32 | + * into the GATag so that KVM can retrieve the correct vCPU from a GALog entry |
| 33 | + * if an interrupt can't be delivered, e.g. because the vCPU isn't running. |
| 34 | + * |
| 35 | + * For the vCPU ID, use however many bits are currently allowed for the max |
| 36 | + * guest physical APIC ID (limited by the size of the physical ID table), and |
| 37 | + * use whatever bits remain to assign arbitrary AVIC IDs to VMs. Note, the |
| 38 | + * size of the GATag is defined by hardware (32 bits), but is an opaque value |
| 39 | + * as far as hardware is concerned. |
| 40 | + */ |
| 41 | +#define AVIC_VCPU_ID_MASK AVIC_PHYSICAL_MAX_INDEX_MASK |
33 | 42 |
|
34 |
| -#define AVIC_VM_ID_BITS 24 |
35 |
| -#define AVIC_VM_ID_NR (1 << AVIC_VM_ID_BITS) |
36 |
| -#define AVIC_VM_ID_MASK ((1 << AVIC_VM_ID_BITS) - 1) |
| 43 | +#define AVIC_VM_ID_SHIFT HWEIGHT32(AVIC_PHYSICAL_MAX_INDEX_MASK) |
| 44 | +#define AVIC_VM_ID_MASK (GENMASK(31, AVIC_VM_ID_SHIFT) >> AVIC_VM_ID_SHIFT) |
37 | 45 |
|
38 |
| -#define AVIC_GATAG(x, y) (((x & AVIC_VM_ID_MASK) << AVIC_VCPU_ID_BITS) | \ |
| 46 | +#define AVIC_GATAG(x, y) (((x & AVIC_VM_ID_MASK) << AVIC_VM_ID_SHIFT) | \ |
39 | 47 | (y & AVIC_VCPU_ID_MASK))
|
40 |
| -#define AVIC_GATAG_TO_VMID(x) ((x >> AVIC_VCPU_ID_BITS) & AVIC_VM_ID_MASK) |
| 48 | +#define AVIC_GATAG_TO_VMID(x) ((x >> AVIC_VM_ID_SHIFT) & AVIC_VM_ID_MASK) |
41 | 49 | #define AVIC_GATAG_TO_VCPUID(x) (x & AVIC_VCPU_ID_MASK)
|
42 | 50 |
|
| 51 | +static_assert(AVIC_GATAG(AVIC_VM_ID_MASK, AVIC_VCPU_ID_MASK) == -1u); |
| 52 | + |
43 | 53 | static bool force_avic;
|
44 | 54 | module_param_unsafe(force_avic, bool, 0444);
|
45 | 55 |
|
|
0 commit comments