Skip to content

Commit bacf2c6

Browse files
author
Marc Zyngier
committed
KVM: arm64: GICv4.1: Allow SGIs to switch between HW and SW interrupts
In order to let a guest buy in the new, active-less SGIs, we need to be able to switch between the two modes. Handle this by stopping all guest activity, transfer the state from one mode to the other, and resume the guest. Nothing calls this code so far, but a later patch will plug it into the MMIO emulation. Signed-off-by: Marc Zyngier <maz@kernel.org> Reviewed-by: Zenghui Yu <yuzenghui@huawei.com> Link: https://lore.kernel.org/r/20200304203330.4967-20-maz@kernel.org
1 parent ef1820b commit bacf2c6

3 files changed

Lines changed: 102 additions & 0 deletions

File tree

‎include/kvm/arm_vgic.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ struct vgic_dist {
231231
/* distributor enabled */
232232
bool enabled;
233233

234+
/* Wants SGIs without active state */
235+
bool nassgireq;
236+
234237
struct vgic_irq *spis;
235238

236239
struct vgic_io_device dist_iodev;

‎virt/kvm/arm/vgic/vgic-v4.c‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,104 @@ static irqreturn_t vgic_v4_doorbell_handler(int irq, void *info)
9797
return IRQ_HANDLED;
9898
}
9999

100+
static void vgic_v4_sync_sgi_config(struct its_vpe *vpe, struct vgic_irq *irq)
101+
{
102+
vpe->sgi_config[irq->intid].enabled = irq->enabled;
103+
vpe->sgi_config[irq->intid].group = irq->group;
104+
vpe->sgi_config[irq->intid].priority = irq->priority;
105+
}
106+
107+
static void vgic_v4_enable_vsgis(struct kvm_vcpu *vcpu)
108+
{
109+
struct its_vpe *vpe = &vcpu->arch.vgic_cpu.vgic_v3.its_vpe;
110+
int i;
111+
112+
/*
113+
* With GICv4.1, every virtual SGI can be directly injected. So
114+
* let's pretend that they are HW interrupts, tied to a host
115+
* IRQ. The SGI code will do its magic.
116+
*/
117+
for (i = 0; i < VGIC_NR_SGIS; i++) {
118+
struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, i);
119+
struct irq_desc *desc;
120+
unsigned long flags;
121+
int ret;
122+
123+
raw_spin_lock_irqsave(&irq->irq_lock, flags);
124+
125+
if (irq->hw)
126+
goto unlock;
127+
128+
irq->hw = true;
129+
irq->host_irq = irq_find_mapping(vpe->sgi_domain, i);
130+
131+
/* Transfer the full irq state to the vPE */
132+
vgic_v4_sync_sgi_config(vpe, irq);
133+
desc = irq_to_desc(irq->host_irq);
134+
ret = irq_domain_activate_irq(irq_desc_get_irq_data(desc),
135+
false);
136+
if (!WARN_ON(ret)) {
137+
/* Transfer pending state */
138+
ret = irq_set_irqchip_state(irq->host_irq,
139+
IRQCHIP_STATE_PENDING,
140+
irq->pending_latch);
141+
WARN_ON(ret);
142+
irq->pending_latch = false;
143+
}
144+
unlock:
145+
raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
146+
vgic_put_irq(vcpu->kvm, irq);
147+
}
148+
}
149+
150+
static void vgic_v4_disable_vsgis(struct kvm_vcpu *vcpu)
151+
{
152+
int i;
153+
154+
for (i = 0; i < VGIC_NR_SGIS; i++) {
155+
struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, i);
156+
struct irq_desc *desc;
157+
unsigned long flags;
158+
int ret;
159+
160+
raw_spin_lock_irqsave(&irq->irq_lock, flags);
161+
162+
if (!irq->hw)
163+
goto unlock;
164+
165+
irq->hw = false;
166+
ret = irq_get_irqchip_state(irq->host_irq,
167+
IRQCHIP_STATE_PENDING,
168+
&irq->pending_latch);
169+
WARN_ON(ret);
170+
171+
desc = irq_to_desc(irq->host_irq);
172+
irq_domain_deactivate_irq(irq_desc_get_irq_data(desc));
173+
unlock:
174+
raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
175+
vgic_put_irq(vcpu->kvm, irq);
176+
}
177+
}
178+
179+
/* Must be called with the kvm lock held */
180+
void vgic_v4_configure_vsgis(struct kvm *kvm)
181+
{
182+
struct vgic_dist *dist = &kvm->arch.vgic;
183+
struct kvm_vcpu *vcpu;
184+
int i;
185+
186+
kvm_arm_halt_guest(kvm);
187+
188+
kvm_for_each_vcpu(i, vcpu, kvm) {
189+
if (dist->nassgireq)
190+
vgic_v4_enable_vsgis(vcpu);
191+
else
192+
vgic_v4_disable_vsgis(vcpu);
193+
}
194+
195+
kvm_arm_resume_guest(kvm);
196+
}
197+
100198
/**
101199
* vgic_v4_init - Initialize the GICv4 data structures
102200
* @kvm: Pointer to the VM being initialized

‎virt/kvm/arm/vgic/vgic.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,5 +316,6 @@ void vgic_its_invalidate_cache(struct kvm *kvm);
316316
bool vgic_supports_direct_msis(struct kvm *kvm);
317317
int vgic_v4_init(struct kvm *kvm);
318318
void vgic_v4_teardown(struct kvm *kvm);
319+
void vgic_v4_configure_vsgis(struct kvm *kvm);
319320

320321
#endif

0 commit comments

Comments
 (0)