Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/cpumf: Improve guest detection heuristics

commit e22cf8ca6f75 ("s390/cpumf: rework program parameter setting
to detect guest samples") requires guest changes to get proper
guest/host. We can do better: We can use the primary asn value,
which is set on all Linux variants to compare this with the host
pp value.
We now have the following cases:
1. Guest using PP
host sample: gpp == 0, asn == hpp --> host
guest sample: gpp != 0 --> guest
2. Guest not using PP
host sample: gpp == 0, asn == hpp --> host
guest sample: gpp == 0, asn != hpp --> guest

As soon as the host no longer sets CR4, we must back out
this heuristics - let's add a comment in switch_to.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Reviewed-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>

authored by

Christian Borntraeger and committed by
Martin Schwidefsky
b1685ab9 5d7eccec

+7 -3
+1
arch/s390/kernel/entry.S
··· 186 186 stg %r5,__LC_THREAD_INFO # store thread info of next 187 187 stg %r15,__LC_KERNEL_STACK # store end of kernel stack 188 188 lg %r15,__THREAD_ksp(%r1) # load kernel stack of next 189 + /* c4 is used in guest detection: arch/s390/kernel/perf_cpum_sf.c */ 189 190 lctl %c4,%c4,__TASK_pid(%r3) # load pid to control reg. 4 190 191 mvc __LC_CURRENT_PID(4,%r0),__TASK_pid(%r3) # store pid of next 191 192 lmg %r6,%r15,__SF_GPRS(%r15) # load gprs of next task
+6 -3
arch/s390/kernel/perf_cpum_sf.c
··· 1022 1022 /* 1023 1023 * A non-zero guest program parameter indicates a guest 1024 1024 * sample. 1025 - * Note that some early samples might be misaccounted to 1026 - * the host. 1025 + * Note that some early samples or samples from guests without 1026 + * lpp usage would be misaccounted to the host. We use the asn 1027 + * value as a heuristic to detect most of these guest samples. 1028 + * If the value differs from the host hpp value, we assume 1029 + * it to be a KVM guest. 1027 1030 */ 1028 - if (sfr->basic.gpp) 1031 + if (sfr->basic.gpp || sfr->basic.prim_asn != (u16) sfr->basic.hpp) 1029 1032 sde_regs->in_guest = 1; 1030 1033 1031 1034 overflow = 0;