Skip to content

Commit eacc56b

Browse files
legoaterpaulusmack
authored andcommitted
KVM: PPC: Book3S HV: XIVE: Introduce a new capability KVM_CAP_PPC_IRQ_XIVE
The user interface exposes a new capability KVM_CAP_PPC_IRQ_XIVE to let QEMU connect the vCPU presenters to the XIVE KVM device if required. The capability is not advertised for now as the full support for the XIVE native exploitation mode is not yet available. When this is case, the capability will be advertised on PowerNV Hypervisors only. Nested guests (pseries KVM Hypervisor) are not supported. Internally, the interface to the new KVM device is protected with a new interrupt mode: KVMPPC_IRQ_XIVE. Signed-off-by: Cédric Le Goater <clg@kaod.org> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
1 parent 90c7379 commit eacc56b

8 files changed

Lines changed: 268 additions & 41 deletions

File tree

‎Documentation/virtual/kvm/api.txt‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4504,6 +4504,15 @@ struct kvm_sync_regs {
45044504
struct kvm_vcpu_events events;
45054505
};
45064506

4507+
6.75 KVM_CAP_PPC_IRQ_XIVE
4508+
4509+
Architectures: ppc
4510+
Target: vcpu
4511+
Parameters: args[0] is the XIVE device fd
4512+
args[1] is the XIVE CPU number (server ID) for this vcpu
4513+
4514+
This capability connects the vcpu to an in-kernel XIVE device.
4515+
45074516
7. Capabilities that can be enabled on VMs
45084517
------------------------------------------
45094518

‎arch/powerpc/include/asm/kvm_host.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ struct kvmppc_passthru_irqmap {
453453
#define KVMPPC_IRQ_DEFAULT 0
454454
#define KVMPPC_IRQ_MPIC 1
455455
#define KVMPPC_IRQ_XICS 2 /* Includes a XIVE option */
456+
#define KVMPPC_IRQ_XIVE 3 /* XIVE native exploitation mode */
456457

457458
#define MMIO_HPTE_CACHE_SIZE 4
458459

‎arch/powerpc/include/asm/kvm_ppc.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,14 @@ extern int kvmppc_xive_set_irq(struct kvm *kvm, int irq_source_id, u32 irq,
594594
int level, bool line_status);
595595
extern void kvmppc_xive_push_vcpu(struct kvm_vcpu *vcpu);
596596

597+
static inline int kvmppc_xive_enabled(struct kvm_vcpu *vcpu)
598+
{
599+
return vcpu->arch.irq_type == KVMPPC_IRQ_XIVE;
600+
}
601+
602+
extern int kvmppc_xive_native_connect_vcpu(struct kvm_device *dev,
603+
struct kvm_vcpu *vcpu, u32 cpu);
604+
extern void kvmppc_xive_native_cleanup_vcpu(struct kvm_vcpu *vcpu);
597605
extern void kvmppc_xive_native_init_module(void);
598606
extern void kvmppc_xive_native_exit_module(void);
599607

@@ -621,6 +629,11 @@ static inline int kvmppc_xive_set_irq(struct kvm *kvm, int irq_source_id, u32 ir
621629
int level, bool line_status) { return -ENODEV; }
622630
static inline void kvmppc_xive_push_vcpu(struct kvm_vcpu *vcpu) { }
623631

632+
static inline int kvmppc_xive_enabled(struct kvm_vcpu *vcpu)
633+
{ return 0; }
634+
static inline int kvmppc_xive_native_connect_vcpu(struct kvm_device *dev,
635+
struct kvm_vcpu *vcpu, u32 cpu) { return -EBUSY; }
636+
static inline void kvmppc_xive_native_cleanup_vcpu(struct kvm_vcpu *vcpu) { }
624637
static inline void kvmppc_xive_native_init_module(void) { }
625638
static inline void kvmppc_xive_native_exit_module(void) { }
626639

‎arch/powerpc/kvm/book3s_xive.c‎

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,6 @@ static int xive_select_target(struct kvm *kvm, u32 *server, u8 prio)
380380
return -EBUSY;
381381
}
382382

383-
static u32 xive_vp(struct kvmppc_xive *xive, u32 server)
384-
{
385-
return xive->vp_base + kvmppc_pack_vcpu_id(xive->kvm, server);
386-
}
387-
388383
static u8 xive_lock_and_mask(struct kvmppc_xive *xive,
389384
struct kvmppc_xive_src_block *sb,
390385
struct kvmppc_xive_irq_state *state)
@@ -430,8 +425,8 @@ static u8 xive_lock_and_mask(struct kvmppc_xive *xive,
430425
*/
431426
if (xd->flags & OPAL_XIVE_IRQ_MASK_VIA_FW) {
432427
xive_native_configure_irq(hw_num,
433-
xive_vp(xive, state->act_server),
434-
MASKED, state->number);
428+
kvmppc_xive_vp(xive, state->act_server),
429+
MASKED, state->number);
435430
/* set old_p so we can track if an H_EOI was done */
436431
state->old_p = true;
437432
state->old_q = false;
@@ -486,8 +481,8 @@ static void xive_finish_unmask(struct kvmppc_xive *xive,
486481
*/
487482
if (xd->flags & OPAL_XIVE_IRQ_MASK_VIA_FW) {
488483
xive_native_configure_irq(hw_num,
489-
xive_vp(xive, state->act_server),
490-
state->act_priority, state->number);
484+
kvmppc_xive_vp(xive, state->act_server),
485+
state->act_priority, state->number);
491486
/* If an EOI is needed, do it here */
492487
if (!state->old_p)
493488
xive_vm_source_eoi(hw_num, xd);
@@ -563,7 +558,7 @@ static int xive_target_interrupt(struct kvm *kvm,
563558
kvmppc_xive_select_irq(state, &hw_num, NULL);
564559

565560
return xive_native_configure_irq(hw_num,
566-
xive_vp(xive, server),
561+
kvmppc_xive_vp(xive, server),
567562
prio, state->number);
568563
}
569564

@@ -951,7 +946,7 @@ int kvmppc_xive_set_mapped(struct kvm *kvm, unsigned long guest_irq,
951946
* which is fine for a never started interrupt.
952947
*/
953948
xive_native_configure_irq(hw_irq,
954-
xive_vp(xive, state->act_server),
949+
kvmppc_xive_vp(xive, state->act_server),
955950
state->act_priority, state->number);
956951

957952
/*
@@ -1027,7 +1022,7 @@ int kvmppc_xive_clr_mapped(struct kvm *kvm, unsigned long guest_irq,
10271022

10281023
/* Reconfigure the IPI */
10291024
xive_native_configure_irq(state->ipi_number,
1030-
xive_vp(xive, state->act_server),
1025+
kvmppc_xive_vp(xive, state->act_server),
10311026
state->act_priority, state->number);
10321027

10331028
/*
@@ -1049,7 +1044,7 @@ int kvmppc_xive_clr_mapped(struct kvm *kvm, unsigned long guest_irq,
10491044
}
10501045
EXPORT_SYMBOL_GPL(kvmppc_xive_clr_mapped);
10511046

1052-
static void kvmppc_xive_disable_vcpu_interrupts(struct kvm_vcpu *vcpu)
1047+
void kvmppc_xive_disable_vcpu_interrupts(struct kvm_vcpu *vcpu)
10531048
{
10541049
struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu;
10551050
struct kvm *kvm = vcpu->kvm;
@@ -1166,7 +1161,7 @@ int kvmppc_xive_connect_vcpu(struct kvm_device *dev,
11661161
xc->xive = xive;
11671162
xc->vcpu = vcpu;
11681163
xc->server_num = cpu;
1169-
xc->vp_id = xive_vp(xive, cpu);
1164+
xc->vp_id = kvmppc_xive_vp(xive, cpu);
11701165
xc->mfrr = 0xff;
11711166
xc->valid = true;
11721167

@@ -1883,6 +1878,43 @@ static int kvmppc_xive_create(struct kvm_device *dev, u32 type)
18831878
return 0;
18841879
}
18851880

1881+
int kvmppc_xive_debug_show_queues(struct seq_file *m, struct kvm_vcpu *vcpu)
1882+
{
1883+
struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu;
1884+
unsigned int i;
1885+
1886+
for (i = 0; i < KVMPPC_XIVE_Q_COUNT; i++) {
1887+
struct xive_q *q = &xc->queues[i];
1888+
u32 i0, i1, idx;
1889+
1890+
if (!q->qpage && !xc->esc_virq[i])
1891+
continue;
1892+
1893+
seq_printf(m, " [q%d]: ", i);
1894+
1895+
if (q->qpage) {
1896+
idx = q->idx;
1897+
i0 = be32_to_cpup(q->qpage + idx);
1898+
idx = (idx + 1) & q->msk;
1899+
i1 = be32_to_cpup(q->qpage + idx);
1900+
seq_printf(m, "T=%d %08x %08x...\n", q->toggle,
1901+
i0, i1);
1902+
}
1903+
if (xc->esc_virq[i]) {
1904+
struct irq_data *d = irq_get_irq_data(xc->esc_virq[i]);
1905+
struct xive_irq_data *xd =
1906+
irq_data_get_irq_handler_data(d);
1907+
u64 pq = xive_vm_esb_load(xd, XIVE_ESB_GET);
1908+
1909+
seq_printf(m, "E:%c%c I(%d:%llx:%llx)",
1910+
(pq & XIVE_ESB_VAL_P) ? 'P' : 'p',
1911+
(pq & XIVE_ESB_VAL_Q) ? 'Q' : 'q',
1912+
xc->esc_virq[i], pq, xd->eoi_page);
1913+
seq_puts(m, "\n");
1914+
}
1915+
}
1916+
return 0;
1917+
}
18861918

18871919
static int xive_debug_show(struct seq_file *m, void *private)
18881920
{
@@ -1908,7 +1940,6 @@ static int xive_debug_show(struct seq_file *m, void *private)
19081940

19091941
kvm_for_each_vcpu(i, vcpu, kvm) {
19101942
struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu;
1911-
unsigned int i;
19121943

19131944
if (!xc)
19141945
continue;
@@ -1918,33 +1949,8 @@ static int xive_debug_show(struct seq_file *m, void *private)
19181949
xc->server_num, xc->cppr, xc->hw_cppr,
19191950
xc->mfrr, xc->pending,
19201951
xc->stat_rm_h_xirr, xc->stat_vm_h_xirr);
1921-
for (i = 0; i < KVMPPC_XIVE_Q_COUNT; i++) {
1922-
struct xive_q *q = &xc->queues[i];
1923-
u32 i0, i1, idx;
19241952

1925-
if (!q->qpage && !xc->esc_virq[i])
1926-
continue;
1927-
1928-
seq_printf(m, " [q%d]: ", i);
1929-
1930-
if (q->qpage) {
1931-
idx = q->idx;
1932-
i0 = be32_to_cpup(q->qpage + idx);
1933-
idx = (idx + 1) & q->msk;
1934-
i1 = be32_to_cpup(q->qpage + idx);
1935-
seq_printf(m, "T=%d %08x %08x... \n", q->toggle, i0, i1);
1936-
}
1937-
if (xc->esc_virq[i]) {
1938-
struct irq_data *d = irq_get_irq_data(xc->esc_virq[i]);
1939-
struct xive_irq_data *xd = irq_data_get_irq_handler_data(d);
1940-
u64 pq = xive_vm_esb_load(xd, XIVE_ESB_GET);
1941-
seq_printf(m, "E:%c%c I(%d:%llx:%llx)",
1942-
(pq & XIVE_ESB_VAL_P) ? 'P' : 'p',
1943-
(pq & XIVE_ESB_VAL_Q) ? 'Q' : 'q',
1944-
xc->esc_virq[i], pq, xd->eoi_page);
1945-
seq_printf(m, "\n");
1946-
}
1947-
}
1953+
kvmppc_xive_debug_show_queues(m, vcpu);
19481954

19491955
t_rm_h_xirr += xc->stat_rm_h_xirr;
19501956
t_rm_h_ipoll += xc->stat_rm_h_ipoll;

‎arch/powerpc/kvm/book3s_xive.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ static inline struct kvmppc_xive_src_block *kvmppc_xive_find_source(struct kvmpp
198198
return xive->src_blocks[bid];
199199
}
200200

201+
static inline u32 kvmppc_xive_vp(struct kvmppc_xive *xive, u32 server)
202+
{
203+
return xive->vp_base + kvmppc_pack_vcpu_id(xive->kvm, server);
204+
}
205+
201206
/*
202207
* Mapping between guest priorities and host priorities
203208
* is as follow.
@@ -248,5 +253,11 @@ extern int (*__xive_vm_h_ipi)(struct kvm_vcpu *vcpu, unsigned long server,
248253
extern int (*__xive_vm_h_cppr)(struct kvm_vcpu *vcpu, unsigned long cppr);
249254
extern int (*__xive_vm_h_eoi)(struct kvm_vcpu *vcpu, unsigned long xirr);
250255

256+
/*
257+
* Common Xive routines for XICS-over-XIVE and XIVE native
258+
*/
259+
void kvmppc_xive_disable_vcpu_interrupts(struct kvm_vcpu *vcpu);
260+
int kvmppc_xive_debug_show_queues(struct seq_file *m, struct kvm_vcpu *vcpu);
261+
251262
#endif /* CONFIG_KVM_XICS */
252263
#endif /* _KVM_PPC_BOOK3S_XICS_H */

0 commit comments

Comments
 (0)