Skip to content

Commit 107c550

Browse files
npigginmpe
authored andcommitted
powerpc/pseries: Add KVM guest doorbell restrictions
KVM guests have certain restrictions and performance quirks when using doorbells. This patch moves the EPAPR KVM guest test so it can be shared with PSERIES, and uses that in doorbell setup code to apply the KVM guest quirks and improves IPI performance for two cases: - PowerVM guests may now use doorbells even if they are secure. - KVM guests no longer use doorbells if XIVE is available. There is a valid complaint that "KVM guest" is not a very reasonable thing to test for, it's preferable for the hypervisor to advertise particular behaviours to the guest so they could change if the hypervisor implementation or configuration changes. However in this case we were already assuming a KVM guest worst case, so this patch is about containing those quirks. If KVM later advertises fast doorbells, we should test for that and override the quirks. Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Tested-by: Cédric Le Goater <clg@kaod.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20200726035155.1424103-4-npiggin@gmail.com
1 parent 5b06d16 commit 107c550

5 files changed

Lines changed: 53 additions & 41 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ extern int ibm_nmi_interlock_token;
132132

133133
extern unsigned int __start___fw_ftr_fixup, __stop___fw_ftr_fixup;
134134

135+
#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_KVM_GUEST)
136+
bool is_kvm_guest(void);
137+
#else
138+
static inline bool is_kvm_guest(void) { return false; }
139+
#endif
140+
135141
#ifdef CONFIG_PPC_PSERIES
136142
void pseries_probe_fw_features(void);
137143
#else

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

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,15 @@
88
#ifndef __POWERPC_KVM_PARA_H__
99
#define __POWERPC_KVM_PARA_H__
1010

11-
#include <uapi/asm/kvm_para.h>
12-
13-
#ifdef CONFIG_KVM_GUEST
14-
15-
#include <linux/of.h>
16-
17-
static inline int kvm_para_available(void)
18-
{
19-
struct device_node *hyper_node;
20-
21-
hyper_node = of_find_node_by_path("/hypervisor");
22-
if (!hyper_node)
23-
return 0;
11+
#include <asm/firmware.h>
2412

25-
if (!of_device_is_compatible(hyper_node, "linux,kvm"))
26-
return 0;
27-
28-
return 1;
29-
}
30-
31-
#else
13+
#include <uapi/asm/kvm_para.h>
3214

3315
static inline int kvm_para_available(void)
3416
{
35-
return 0;
17+
return IS_ENABLED(CONFIG_KVM_GUEST) && is_kvm_guest();
3618
}
3719

38-
#endif
39-
4020
static inline unsigned int kvm_arch_para_features(void)
4121
{
4222
unsigned long r;

‎arch/powerpc/kernel/Makefile‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ obj-y := cputable.o syscalls.o \
4545
signal.o sysfs.o cacheinfo.o time.o \
4646
prom.o traps.o setup-common.o \
4747
udbg.o misc.o io.o misc_$(BITS).o \
48-
of_platform.o prom_parse.o
48+
of_platform.o prom_parse.o firmware.o
4949
obj-y += ptrace/
5050
obj-$(CONFIG_PPC64) += setup_64.o \
51-
paca.o nvram_64.o firmware.o note.o \
52-
syscall_64.o
51+
paca.o nvram_64.o note.o syscall_64.o
5352
obj-$(CONFIG_COMPAT) += sys_ppc32.o signal_32.o
5453
obj-$(CONFIG_VDSO32) += vdso32/
5554
obj-$(CONFIG_PPC_WATCHDOG) += watchdog.o

‎arch/powerpc/kernel/firmware.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,27 @@
1111

1212
#include <linux/export.h>
1313
#include <linux/cache.h>
14+
#include <linux/of.h>
1415

1516
#include <asm/firmware.h>
1617

18+
#ifdef CONFIG_PPC64
1719
unsigned long powerpc_firmware_features __read_mostly;
1820
EXPORT_SYMBOL_GPL(powerpc_firmware_features);
21+
#endif
22+
23+
#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_KVM_GUEST)
24+
bool is_kvm_guest(void)
25+
{
26+
struct device_node *hyper_node;
27+
28+
hyper_node = of_find_node_by_path("/hypervisor");
29+
if (!hyper_node)
30+
return 0;
31+
32+
if (!of_device_is_compatible(hyper_node, "linux,kvm"))
33+
return 0;
34+
35+
return 1;
36+
}
37+
#endif

‎arch/powerpc/platforms/pseries/smp.c‎

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -210,24 +210,32 @@ static __init void pSeries_smp_probe(void)
210210
if (!cpu_has_feature(CPU_FTR_SMT))
211211
return;
212212

213-
/*
214-
* KVM emulates doorbells by disabling FSCR[MSGP] so msgsndp faults
215-
* to the hypervisor which then reads the instruction from guest
216-
* memory. This can't be done if the guest is secure, so don't use
217-
* doorbells in secure guests.
218-
*
219-
* Under PowerVM, FSCR[MSGP] is enabled so doorbells could be used
220-
* by secure guests if we distinguished this from KVM.
221-
*/
222-
if (is_secure_guest())
223-
return;
213+
if (is_kvm_guest()) {
214+
/*
215+
* KVM emulates doorbells by disabling FSCR[MSGP] so msgsndp
216+
* faults to the hypervisor which then reads the instruction
217+
* from guest memory, which tends to be slower than using XIVE.
218+
*/
219+
if (xive_enabled())
220+
return;
221+
222+
/*
223+
* XICS hcalls aren't as fast, so we can use msgsndp (which
224+
* also helps exercise KVM emulation), however KVM can't
225+
* emulate secure guests because it can't read the instruction
226+
* out of their memory.
227+
*/
228+
if (is_secure_guest())
229+
return;
230+
}
224231

225232
/*
226-
* The guest can use doobells for SMT sibling IPIs, which stay in
227-
* the core rather than going to the interrupt controller. This
228-
* tends to be slower under KVM where doorbells are emulated, but
229-
* faster for PowerVM where they're enabled.
233+
* Under PowerVM, FSCR[MSGP] is enabled as guest vCPU siblings are
234+
* gang scheduled on the same physical core, so doorbells are always
235+
* faster than the interrupt controller, and they can be used by
236+
* secure guests.
230237
*/
238+
231239
ic_cause_ipi = smp_ops->cause_ipi;
232240
smp_ops->cause_ipi = dbell_or_ic_cause_ipi;
233241
}

0 commit comments

Comments
 (0)