Skip to content

Commit f771b55

Browse files
npigginmpe
authored andcommitted
KVM: PPC: Use KVM_CAP_PPC_AIL_MODE_3
Use KVM_CAP_PPC_AIL_MODE_3 to advertise the capability to set the AIL resource mode to 3 with the H_SET_MODE hypercall. This capability differs between processor types and KVM types (PR, HV, Nested HV), and affects guest-visible behaviour. QEMU will implement a cap-ail-mode-3 to control this behaviour[1], and use the KVM CAP if available to determine KVM support[2]. [1] https://lists.nongnu.org/archive/html/qemu-ppc/2022-02/msg00437.html [2] https://lists.nongnu.org/archive/html/qemu-ppc/2022-02/msg00439.html Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Reviewed-by: Fabiano Rosas <farosas@linux.ibm.com> [mpe: Rebase onto 93b7180 from kvm-ppc-cap-210 branch, add EXPORT_SYMBOL] Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20220222064727.2314380-4-npiggin@gmail.com
1 parent 839d893 commit f771b55

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

arch/powerpc/include/asm/setup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ void setup_panic(void);
2828
#define ARCH_PANIC_TIMEOUT 180
2929

3030
#ifdef CONFIG_PPC_PSERIES
31+
extern bool pseries_reloc_on_exception(void);
3132
extern bool pseries_enable_reloc_on_exc(void);
3233
extern void pseries_disable_reloc_on_exc(void);
3334
extern void pseries_big_endian_exceptions(void);
3435
void __init pseries_little_endian_exceptions(void);
3536
#else
37+
static inline bool pseries_reloc_on_exception(void) { return false; }
3638
static inline bool pseries_enable_reloc_on_exc(void) { return false; }
3739
static inline void pseries_disable_reloc_on_exc(void) {}
3840
static inline void pseries_big_endian_exceptions(void) {}

arch/powerpc/kvm/powerpc.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,23 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
705705
r = 1;
706706
break;
707707
#endif
708+
case KVM_CAP_PPC_AIL_MODE_3:
709+
r = 0;
710+
/*
711+
* KVM PR, POWER7, and some POWER9s don't support AIL=3 mode.
712+
* The POWER9s can support it if the guest runs in hash mode,
713+
* but QEMU doesn't necessarily query the capability in time.
714+
*/
715+
if (hv_enabled) {
716+
if (kvmhv_on_pseries()) {
717+
if (pseries_reloc_on_exception())
718+
r = 1;
719+
} else if (cpu_has_feature(CPU_FTR_ARCH_207S) &&
720+
!cpu_has_feature(CPU_FTR_P9_RADIX_PREFETCH_BUG)) {
721+
r = 1;
722+
}
723+
}
724+
break;
708725
default:
709726
r = 0;
710727
break;

arch/powerpc/platforms/pseries/setup.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,14 @@ static void pseries_lpar_idle(void)
353353
pseries_idle_epilog();
354354
}
355355

356+
static bool pseries_reloc_on_exception_enabled;
357+
358+
bool pseries_reloc_on_exception(void)
359+
{
360+
return pseries_reloc_on_exception_enabled;
361+
}
362+
EXPORT_SYMBOL_GPL(pseries_reloc_on_exception);
363+
356364
/*
357365
* Enable relocation on during exceptions. This has partition wide scope and
358366
* may take a while to complete, if it takes longer than one second we will
@@ -377,6 +385,7 @@ bool pseries_enable_reloc_on_exc(void)
377385
" on exceptions: %ld\n", rc);
378386
return false;
379387
}
388+
pseries_reloc_on_exception_enabled = true;
380389
return true;
381390
}
382391

@@ -404,7 +413,9 @@ void pseries_disable_reloc_on_exc(void)
404413
break;
405414
mdelay(get_longbusy_msecs(rc));
406415
}
407-
if (rc != H_SUCCESS)
416+
if (rc == H_SUCCESS)
417+
pseries_reloc_on_exception_enabled = false;
418+
else
408419
pr_warn("Warning: Failed to disable relocation on exceptions: %ld\n",
409420
rc);
410421
}

0 commit comments

Comments
 (0)